pchart class 및 생성자 작성

에디터 컴포넌트의 기본 class인 pchart.class.php파일에 EditorHandler를 상속받는 pchart class를 작성합니다.

class pchart extends EditorHandler {
}

editorModel::getComponentObject()에서 아래와 같이 에디터 컴포넌트 객체를 생성하시는 부분을 참고하여 생성자 인수를 $editor_sequence와 $component_path를 받는 생성자 pchart를 작성하고 그 인수를 class member variable에 등록합니다.

* XE_ROOT/modules/editor/editor.model.php:388

388                 $eval_str = sprintf('$oComponent = new %s("%s","%s");', $component, $editor_sequence, $class_path);
389                 @eval($eval_str);

class pchart extends EditorHandler {
         function pchart($editor_sequence, $component_path) {
             $this->editor_sequence = $editor_sequence;
             $this->component_path = $component_path;
         }
}

pchart::getPopupContent()와 tpl/popup.html

pchart::getPopupContent() 는 에디터에서 파이차트 컴포넌트를 클릭시 설정창이 뜨는 action입니다. tpl/popup.html 템플릿을 컴파일하여 리턴을 해주면 됩니다.

class pchart extends EditorHandler {

    // editor_sequence 는 에디터에서 필수로 달고 다녀야 함....
    var $editor_sequence = 0;
    var $component_path = '';

    /**
     * @brief editor_sequence과 컴포넌트의 경로를 받음
     **/
    function pchart($editor_sequence, $component_path) {
        $this->editor_sequence = $editor_sequence;
        $this->component_path = $component_path;
    }

    function getPopupContent() {
         // 템플릿을 미리 컴파일해서 컴파일된 소스를 return
        $tpl_path = $this->component_path.'tpl';
        $tpl_file = 'popup.html';

        $oTemplate = &TemplateHandler::getInstance();
        return $oTemplate->compile($tpl_path, $tpl_file);
    }

}

생성자 pchart()와 팝업을 위한 getPopupContent() 를 작성하면 기본적인 골격이 완성 되었습니다. 최종적인 pchart.class.php 는 아래와 같습니다.

<?php
    /**
     * @class  pchart
     * @author sol (sol@ngleader.com)
     * @brief  구글API를 이용한 파이차트 컴포넌트
     **/

    class pchart extends EditorHandler {

        // editor_sequence 는 에디터에서 필수로 달고 다녀야 함....
        var $editor_sequence = 0;
        var $component_path = '';
        var $api_url = 'http://chart.apis.google.com/chart';

        /**
         * @brief editor_sequence과 컴포넌트의 경로를 받음
         **/
        function pchart($editor_sequence, $component_path) {
            $this->editor_sequence = $editor_sequence;
            $this->component_path = $component_path;
        }  

        /**
         * @brief popup window요청시 popup window에 출력할 내용을 추가하면 된다
         **/
        function getPopupContent() {
            // set api_url
            Context::set('api_url',$this->api_url);

            // 템플릿을 미리 컴파일해서 컴파일된 소스를 return
            $tpl_path = $this->component_path.'tpl';
            $tpl_file = 'popup.html';

            $oTemplate = &TemplateHandler::getInstance();
            return $oTemplate->compile($tpl_path, $tpl_file);
        }  

    }  
?>


999

2010.09.08 08:22:04
*.45.10.26

자세한 주석// 설명하나하나에 정말 도움이 됩니다. !! 감사합니다