Source for file Ethna_ViewClass.php

Documentation is available at Ethna_ViewClass.php

  1. <?php
  2. // vim: foldmethod=marker
  3. /**
  4.  *  Ethna_ViewClass.php
  5.  *
  6.  *  @author     Masaki Fujimoto <fujimoto@php.net>
  7.  *  @license    http://www.opensource.org/licenses/bsd-license.php The BSD License
  8.  *  @package    Ethna
  9.  *  @version    $Id: Ethna_ViewClass.php 473 2007-07-13 12:50:33Z mumumu-org $
  10.  */
  11.  
  12. // {{{ Ethna_ViewClass
  13. /**
  14.  *  viewクラス
  15.  *
  16.  *  @author     Masaki Fujimoto <fujimoto@php.net>
  17.  *  @access     public
  18.  *  @package    Ethna
  19.  */
  20. {
  21.     /**#@+
  22.      *  @access private
  23.      */
  24.  
  25.     /** @var    object  Ethna_Backend       backendオブジェクト */
  26.     var $backend;
  27.  
  28.     /** @var    object  Ethna_Config        設定オブジェクト    */
  29.     var $config;
  30.  
  31.     /** @var    object  Ethna_I18N          i18nオブジェクト */
  32.     var $i18n;
  33.  
  34.     /** @var    object  Ethna_Logger    ログオブジェクト */
  35.     var $logger;
  36.  
  37.     /** @var    object  Ethna_Plugin    プラグインオブジェクト */
  38.     var $plugin;
  39.  
  40.     /** @var    object  Ethna_ActionError   アクションエラーオブジェクト */
  41.     var $action_error;
  42.  
  43.     /** @var    object  Ethna_ActionError   アクションエラーオブジェクト(省略形) */
  44.     var $ae;
  45.  
  46.     /** @var    object  Ethna_ActionForm    アクションフォームオブジェクト */
  47.     var $action_form;
  48.  
  49.     /** @var    object  Ethna_ActionForm    アクションフォームオブジェクト(省略形) */
  50.     var $af;
  51.  
  52.     /** @var    array   アクションフォームオブジェクト(helper) */
  53.     var $helper_action_form array();
  54.  
  55.     /** @var    array   helperでhtmlのattributeにはしなパラメータの一覧 */
  56.     var $helper_parameter_keys array('default''option''separator');
  57.  
  58.     /** @var    object  Ethna_Session       セッションオブジェクト */
  59.     var $session;
  60.  
  61.     /** @var    string  遷移名 */
  62.     var $forward_name;
  63.  
  64.     /** @var    string  遷移先テンプレートファイル名 */
  65.     var $forward_path;
  66.  
  67.     /**#@-*/
  68.  
  69.     // {{{ Ethna_ViewClass
  70.     /**
  71.      *  Ethna_ViewClassのコンストラクタ
  72.      *
  73.      *  @access public
  74.      *  @param  object  Ethna_Backend   $backend    backendオブジェクト
  75.      *  @param  string  $forward_name   ビューに関連付けられている遷移名
  76.      *  @param  string  $forward_path   ビューに関連付けられているテンプレートファイル名
  77.      */
  78.     function Ethna_ViewClass(&$backend$forward_name$forward_path)
  79.     {
  80.         $c =$backend->getController();
  81.         $this->backend =$backend;
  82.         $this->config =$this->backend->getConfig();
  83.         $this->i18n =$this->backend->getI18N();
  84.         $this->logger =$this->backend->getLogger();
  85.         $this->plugin =$this->backend->getPlugin();
  86.  
  87.         $this->action_error =$this->backend->getActionError();
  88.         $this->ae =$this->action_error;
  89.  
  90.         $this->action_form =$this->backend->getActionForm();
  91.         $this->af =$this->action_form;
  92.  
  93.         $this->session =$this->backend->getSession();
  94.  
  95.         $this->forward_name $forward_name;
  96.         $this->forward_path $forward_path;
  97.  
  98.         foreach (array_keys($this->helper_action_formas $action{
  99.             $this->addActionFormHelper($action);
  100.         }
  101.     }
  102.     // }}}
  103.  
  104.     // {{{ preforward
  105.     /**
  106.      *  画面表示前処理
  107.      *
  108.      *  テンプレートに設定する値でコンテキストに依存しないものは
  109.      *  ここで設定する(例:セレクトボックス等)
  110.      *
  111.      *  @access public
  112.      */
  113.     function preforward()
  114.     {
  115.     }
  116.     // }}}
  117.  
  118.     // {{{ forward
  119.     /**
  120.      *  遷移名に対応する画面を出力する
  121.      *
  122.      *  特殊な画面を表示する場合を除いて特にオーバーライドする必要は無い
  123.      *  (preforward()のみオーバーライドすれば良い)
  124.      *
  125.      *  @access public
  126.      */
  127.     function forward()
  128.     {
  129.         $renderer =$this->_getRenderer();
  130.         $this->_setDefault($renderer);
  131.         $renderer->perform($this->forward_path);
  132.     }
  133.     // }}}
  134.  
  135.     // {{{ addActionFormHelper
  136.     /**
  137.      *  helperアクションフォームオブジェクトを設定する
  138.      *
  139.      *  @access public
  140.      */
  141.     function addActionFormHelper($action)
  142.     {
  143.         if (isset($this->helper_action_form[$action])
  144.             && is_object($this->helper_action_form[$action])) {
  145.             return;
  146.         }
  147.  
  148.         $ctl =Ethna_Controller::getInstance();
  149.         if ($action === $ctl->getCurrentActionName()) {
  150.             $this->helper_action_form[$action=$this->af;
  151.             return;
  152.         }
  153.  
  154.         $form_name $ctl->getActionFormName($action);
  155.         if ($form_name === null{
  156.             $this->logger->log(LOG_WARNING,
  157.                 'action form for the action [%s] not found.'$action);
  158.             return;
  159.         }
  160.  
  161.         $this->helper_action_form[$action=new $form_name($ctl);
  162.     }
  163.     // }}}
  164.  
  165.     // {{{ clearActionFormHelper
  166.     /**
  167.      *  helperアクションフォームオブジェクトを削除する
  168.      *
  169.      *  @access public
  170.      */
  171.     function clearActionFormHelper($action)
  172.     {
  173.         unset($this->helper_action_form[$action]);
  174.     }
  175.     // }}}
  176.  
  177.     // {{{ _getHelperActionForm
  178.     /**
  179.      *  アクションフォームオブジェクト(helper)を取得する
  180.      *  $action === null で $name が指定されているときは、$nameの定義を
  181.      *  含むものを探す
  182.      *
  183.      *  @access protected
  184.      *  @param  string  action  取得するアクション名
  185.      *  @param  string  name    定義されていることを期待するフォーム名
  186.      *  @return object  Ethna_ActionFormまたは継承オブジェクト 
  187.      */
  188.     function &_getHelperActionForm($action null$name null)
  189.     {
  190.         // $action が指定されている場合
  191.         if ($action !== null{
  192.             if (isset($this->helper_action_form[$action])
  193.                 && is_object($this->helper_action_form[$action])) {
  194.                 return $this->helper_action_form[$action];
  195.             else {
  196.                 $this->logger->log(LOG_WARNING,
  197.                     'helper action form for action [%s] not found',
  198.                     $action);
  199.                 return null;
  200.             }
  201.         }
  202.  
  203.         // 最初に $this->af を調べる
  204.         $def $this->af->getDef($name);
  205.         if ($def !== null{
  206.             return $this->af;
  207.         }
  208.  
  209.         // $this->helper_action_form を順に調べる
  210.         foreach (array_keys($this->helper_action_formas $action{
  211.             if (is_object($this->helper_action_form[$action]=== false{
  212.                 continue;
  213.             }
  214.             $af =$this->helper_action_form[$action];
  215.             $def $af->getDef($name);
  216.             if (is_null($def=== false{
  217.                 return $af;
  218.             }
  219.         }
  220.  
  221.         // 見付からなかった
  222.         $this->logger->log(LOG_WARNING,
  223.             'action form defining form [%s] not found'$name);
  224.         return null;
  225.     }
  226.     // }}}
  227.  
  228.     // {{{ getFormName
  229.     /**
  230.      *  指定されたフォーム項目に対応するフォーム名(w/ レンダリング)を取得する
  231.      *
  232.      *  @access public
  233.      */
  234.     function getFormName($name$action$params)
  235.     {
  236.         $af =$this->_getHelperActionForm($action$name);
  237.         if ($af === null{
  238.             return $name;
  239.         }
  240.  
  241.         $def $af->getDef($name);
  242.         if ($def === null || isset($def['name']=== false{
  243.             return $name;
  244.         }
  245.  
  246.         return $def['name'];
  247.     }
  248.     // }}}
  249.  
  250.     // {{{ getFormSubmit
  251.     /**
  252.      *  submitボタンを取得する(送信先アクションで受け取るよう
  253.      *  定義されていないときに、たんにsubmitボタンを作るのに使う)
  254.      *
  255.      *  @access public
  256.      */
  257.     function getFormSubmit($params)
  258.     {
  259.         if (isset($params['type']=== false{
  260.             $params['type''submit';
  261.         }
  262.         return $this->_getFormInput_Html('input'$params);
  263.     }
  264.     // }}}
  265.  
  266.     // {{{ getFormInput
  267.     /**
  268.      *  指定されたフォーム項目に対応するフォームタグを取得する
  269.      *
  270.      *  @access public
  271.      *  @todo   JavaScript対応
  272.      */
  273.     function getFormInput($name$action$params)
  274.     {
  275.         $af =$this->_getHelperActionForm($action$name);
  276.         if ($af === null{
  277.             return '';
  278.         }
  279.  
  280.         $def $af->getDef($name);
  281.         if ($def === null{
  282.             return '';
  283.         }
  284.  
  285.         if (isset($def['form_type']=== false{
  286.             $def['form_type'FORM_TYPE_TEXT;
  287.         }
  288.  
  289.         // 配列フォームが何回呼ばれたかを保存するカウンタ
  290.         if (isset($def['type']&& is_array($def['type'])) {
  291.             static $form_counter array();
  292.             if (isset($form_counter[$action]=== false{
  293.                 $form_counter[$actionarray();
  294.             }
  295.             if (isset($form_counter[$action][$name]=== false{
  296.                 $form_counter[$action][$name0;
  297.             }
  298.             $def['_form_counter'$form_counter[$action][$name]++;
  299.         }
  300.  
  301.         switch ($def['form_type']{
  302.         case FORM_TYPE_BUTTON:
  303.             $input $this->_getFormInput_Button($name$def$params);
  304.             break;
  305.  
  306.         case FORM_TYPE_CHECKBOX:
  307.             $def['option'$this->_getSelectorOptions($af$def$params);
  308.             $input $this->_getFormInput_Checkbox($name$def$params);
  309.             break;
  310.  
  311.         case FORM_TYPE_FILE:
  312.             $input $this->_getFormInput_File($name$def$params);
  313.             break;
  314.  
  315.         case FORM_TYPE_HIDDEN:
  316.             $input $this->_getFormInput_Hidden($name$def$params);
  317.             break;
  318.  
  319.         case FORM_TYPE_PASSWORD:
  320.             $input $this->_getFormInput_Password($name$def$params);
  321.             break;
  322.  
  323.         case FORM_TYPE_RADIO:
  324.             $def['option'$this->_getSelectorOptions($af$def$params);
  325.             $input $this->_getFormInput_Radio($name$def$params);
  326.             break;
  327.  
  328.         case FORM_TYPE_SELECT:
  329.             $def['option'$this->_getSelectorOptions($af$def$params);
  330.             $input $this->_getFormInput_Select($name$def$params);
  331.             break;
  332.  
  333.         case FORM_TYPE_SUBMIT:
  334.             $input $this->_getFormInput_Submit($name$def$params);
  335.             break;
  336.  
  337.         case FORM_TYPE_TEXTAREA:
  338.             $input $this->_getFormInput_Textarea($name$def$params);
  339.             break;
  340.  
  341.         case FORM_TYPE_TEXT:
  342.         default:
  343.             $input $this->_getFormInput_Text($name$def$params);
  344.             break;
  345.         }
  346.  
  347.         return $input;
  348.     }
  349.     // }}}
  350.  
  351.     // {{{ getFormBlock
  352.     /**
  353.      *  フォームタグを取得する(type="form")
  354.      *
  355.      *  @access protected
  356.      */
  357.     function getFormBlock($content$params)
  358.     {
  359.         // method
  360.         if (isset($params['method']=== false{
  361.             $params['method''post';
  362.         }
  363.  
  364.         return $this->_getFormInput_Html('form'$params$contentfalse);
  365.     }
  366.     // }}}
  367.  
  368.     // {{{ _getSelectorOptions
  369.     /**
  370.      *  select, radio, checkbox の選択肢を取得する
  371.      *
  372.      *  @access protected
  373.      */
  374.     function _getSelectorOptions(&$af$def$params)
  375.     {
  376.         // $params, $def の順で調べる
  377.         $source null;
  378.         if (isset($params['option'])) {
  379.             $source $params['option'];
  380.         else if (isset($def['option'])) {
  381.             $source $def['option'];
  382.         }
  383.  
  384.         // 未定義 or 定義済みの場合はそのまま
  385.         if ($source === null{
  386.             return null;
  387.         else if (is_array($source)) {
  388.             return $source;
  389.         }
  390.         
  391.         // 選択肢を取得
  392.         $options null;
  393.         $split array_map("trim"explode(','$source));
  394.         if (count($split=== 1{
  395.             // アクションフォームから取得
  396.             $method_or_property $split[0];
  397.             if (method_exists($af$method_or_property)) {
  398.                 $options $af->$method_or_property();
  399.             else {
  400.                 $options $af->$method_or_property;
  401.             }
  402.         else {
  403.             // マネージャから取得
  404.             $mgr =$this->backend->getManager($split[0]);
  405.             $attr_list $mgr->getAttrList($split[1]);
  406.             if (is_array($attr_list)) {
  407.                 foreach ($attr_list as $key => $val{
  408.                     $options[$key$val['name'];
  409.                 }
  410.             }
  411.         }
  412.  
  413.         if (is_array($options=== false{
  414.             $this->logger->log(LOG_WARNING,
  415.                 'selector option is not valid. [actionform=%s, option=%s]',
  416.                 get_class($af)$source);
  417.             return null;
  418.         }
  419.  
  420.         return $options;
  421.     }
  422.     // }}}
  423.  
  424.     // {{{ _getFormInput_Button
  425.     /**
  426.      *  フォームタグを取得する(type="button")
  427.      *
  428.      *  @access protected
  429.      */
  430.     function _getFormInput_Button($name$def$params)
  431.     {
  432.         $params['type''button';
  433.         
  434.         if (isset($def['type'])) {
  435.             $params['name'is_array($def['type']$name '[]' $name;
  436.         else {
  437.             $params['name'$name;
  438.         }
  439.         if (isset($params['value']=== false{
  440.             if (isset($def['name'])) {
  441.                 $params['value'$def['name'];
  442.             }
  443.         }
  444.         if (isset($params['value']&& is_array($params['value'])) {
  445.             $params['value'$params['value'][0];
  446.         }
  447.  
  448.         return $this->_getFormInput_Html('input'$params);
  449.     }
  450.     // }}}
  451.  
  452.     // {{{ _getFormInput_Checkbox
  453.     /**
  454.      *  チェックボックスタグを取得する(type="check")
  455.      *
  456.      *  @access protected
  457.      */
  458.     function _getFormInput_Checkbox($name$def$params)
  459.     {
  460.         $params['type''checkbox';
  461.         if (isset($def['type'])) {
  462.             $params['name'is_array($def['type']$name '[]' $name;
  463.         else {
  464.             $params['name'$name;
  465.         }
  466.  
  467.         // オプションの一覧(alist)を取得
  468.         if (isset($def['option']&& is_array($def['option'])) {
  469.             $options $def['option'];
  470.         else {
  471.             $options array();
  472.         }
  473.  
  474.         // default値の設定
  475.         if (isset($params['default'])) {
  476.             $current_value $params['default'];
  477.         else if (isset($def['default'])) {
  478.             $current_value $def['default'];
  479.         else {
  480.             $current_value array();
  481.         }
  482.         $current_value array_map('strval'to_array($current_value));
  483.  
  484.         // タグのセパレータ
  485.         if (isset($params['separator'])) {
  486.             $separator $params['separator'];
  487.         else {
  488.             $separator "\n";
  489.         }
  490.  
  491.         $ret array();
  492.         $i 1;
  493.         foreach ($options as $key => $value{
  494.             $params['value'$key;
  495.             $params['id'$name '_' $i++;
  496.  
  497.             // checked
  498.             if (in_array((string) $key$current_valuetrue)) {
  499.                 $params['checked''checked';
  500.             else {
  501.                 unset($params['checked']);
  502.             }
  503.  
  504.             // <input type="checkbox" />
  505.             $input_tag $this->_getFormInput_Html('input'$params);
  506.  
  507.             // <label for="id">..</label>
  508.             $ret[$this->_getFormInput_Html('label'array('for' => $params['id']),
  509.                                                $input_tag $valuefalse);
  510.         }
  511.  
  512.         return implode($separator$ret);
  513.     }
  514.     // }}}
  515.  
  516.     // {{{ _getFormInput_File
  517.     /**
  518.      *  フォームタグを取得する(type="file")
  519.      *
  520.      *  @access protected
  521.      */
  522.     function _getFormInput_File($name$def$params)
  523.     {
  524.         $params['type''file';
  525.         if (isset($def['type'])) {
  526.             $params['name'is_array($def['type']$name '[]' $name;
  527.         else {
  528.             $params['name'$name;
  529.         }
  530.         $params['value''';
  531.  
  532.         return $this->_getFormInput_Html('input'$params);
  533.     }
  534.     // }}}
  535.  
  536.     // {{{ _getFormInput_Hidden
  537.     /**
  538.      *  フォームタグを取得する(type="hidden")
  539.      *
  540.      *  @access protected
  541.      */
  542.     function _getFormInput_Hidden($name$def$params)
  543.     {
  544.         $params['type''hidden';
  545.         if (isset($def['type'])) {
  546.             $params['name'is_array($def['type']$name '[]' $name;
  547.         else {
  548.             $params['name'$name;
  549.         }
  550.  
  551.         // value
  552.         $value '';
  553.         if (isset($params['value'])) {
  554.             $value $params['value'];
  555.         else if (isset($params['default'])) {
  556.             $value $params['default'];
  557.         else if (isset($def['default'])) {
  558.             $value $def['default'];
  559.         }
  560.         if (is_array($value)) {
  561.             if ($def['_form_counter'count($value)) {
  562.                 $params['value'$value[$def['_form_counter']];
  563.             else {
  564.                 $params['value''';
  565.             }
  566.         else {
  567.             $params['value'$value;
  568.         }
  569.  
  570.         return $this->_getFormInput_Html('input'$params);
  571.     }
  572.     // }}}
  573.  
  574.     // {{{ _getFormInput_Password
  575.     /**
  576.      *  フォームタグを取得する(type="password")
  577.      *
  578.      *  @access protected
  579.      */
  580.     function _getFormInput_Password($name$def$params)
  581.     {
  582.         $params['type''password';
  583.         if (isset($def['type'])) {
  584.             $params['name'is_array($def['type']$name '[]' $name;
  585.         else {
  586.             $params['name'$name;
  587.         }
  588.  
  589.         // value
  590.         $value '';
  591.         if (isset($params['value'])) {
  592.             $value $params['value'];
  593.         else if (isset($params['default'])) {
  594.             $value $params['default'];
  595.         else if (isset($def['default'])) {
  596.             $value $def['default'];
  597.         }
  598.         if (is_array($value)) {
  599.             if ($def['_form_counter'count($value)) {
  600.                 $params['value'$value[$def['_form_counter']];
  601.             else {
  602.                 $params['value''';
  603.             }
  604.         else {
  605.             $params['value'$value;
  606.         }
  607.  
  608.         // maxlength
  609.         if (isset($def['max']&& $def['max']{
  610.             $params['maxlength'$def['max'];
  611.         }
  612.  
  613.         return $this->_getFormInput_Html('input'$params);
  614.     }
  615.     // }}}
  616.  
  617.     // {{{ _getFormInput_Radio
  618.     /**
  619.      *  ラジオボタンタグを取得する(type="radio")
  620.      *
  621.      *  @access protected
  622.      */
  623.     function _getFormInput_Radio($name$def$params)
  624.     {
  625.         $params['type''radio';
  626.         if (isset($def['type'])) {
  627.             $params['name'is_array($def['type']$name '[]' $name;
  628.         else {
  629.             $params['name'$name;
  630.         }
  631.  
  632.         // オプションの一覧(alist)を取得
  633.         if (isset($def['option']&& is_array($def['option'])) {
  634.             $options $def['option'];
  635.         else {
  636.             $options array();
  637.         }
  638.  
  639.         // default値の設定
  640.         if (isset($params['default'])) {
  641.             $current_value $params['default'];
  642.         else if (isset($def['default'])) {
  643.             $current_value $def['default'];
  644.         else {
  645.             $current_value null;
  646.         }
  647.  
  648.         // タグのセパレータ
  649.         if (isset($params['separator'])) {
  650.             $separator $params['separator'];
  651.         else {
  652.             $separator "\n";
  653.         }
  654.  
  655.         $ret array();
  656.         $i 1;
  657.         foreach ($options as $key => $value{
  658.             $params['value'$key;
  659.             $params['id'$name '_' $i++;
  660.  
  661.             // checked
  662.             if (strcmp($current_value,$key=== 0{
  663.                 $params['checked''checked';
  664.             else {
  665.                 unset($params['checked']);
  666.             }
  667.  
  668.             // <input type="radio" />
  669.             $input_tag $this->_getFormInput_Html('input'$params);
  670.  
  671.             // <label for="id">..</label>
  672.             $ret[$this->_getFormInput_Html('label'array('for' => $params['id']),
  673.                                                $input_tag $valuefalse);
  674.         }
  675.  
  676.         return implode($separator$ret);
  677.     }
  678.     // }}}
  679.  
  680.     // {{{ _getFormInput_Select
  681.     /**
  682.      *  セレクトボックスタグを取得する(type="select")
  683.      *
  684.      *  @access protected
  685.      */
  686.     function _getFormInput_Select($name$def$params)
  687.     {
  688.         if (isset($def['type'])) {
  689.             $params['name'is_array($def['type']$name '[]' $name;
  690.         else {
  691.             $params['name'$name;
  692.         }
  693.  
  694.         // オプションの一覧(alist)を取得
  695.         if (isset($def['option']&& is_array($def['option'])) {
  696.             $options $def['option'];
  697.         else {
  698.             $options array();
  699.         }
  700.  
  701.         // default値の設定
  702.         if (isset($params['default'])) {
  703.             $current_value $params['default'];
  704.         else if (isset($def['default'])) {
  705.             $current_value $def['default'];
  706.         else {
  707.             $current_value array();
  708.         }
  709.         $current_value array_map('strval'to_array($current_value));
  710.  
  711.         // タグのセパレータ
  712.         if (isset($params['separator'])) {
  713.             $separator $params['separator'];
  714.         else {
  715.             $separator "\n";
  716.         }
  717.  
  718.         // selectタグの中身を作る
  719.         $contents array();
  720.         $selected false;
  721.         foreach ($options as $key => $value{
  722.             $attr array('value' => $key);
  723.             if (in_array((string) $key$current_valuetrue)) {
  724.                 $attr['selected''selected';
  725.                 $selected true;
  726.             }
  727.             $contents[$this->_getFormInput_Html('option'$attr$value);
  728.         }
  729.  
  730.         // 空エントリ
  731.         if (isset($params['emptyoption'])) {
  732.             $attr array('value' => '');
  733.             if ($selected === false{
  734.                 $attr['selected''selected';
  735.             }
  736.             array_unshift($contents,
  737.                           $this->_getFormInput_Html('option',
  738.                                                     $attr,
  739.                                                     $params['emptyoption']));
  740.             unset($params['emptyoption']);
  741.         }
  742.  
  743.         $element $separator implode($separator$contents$separator;
  744.         return $this->_getFormInput_Html('select'$params$elementfalse);
  745.     }
  746.     // }}}
  747.  
  748.     // {{{ _getFormInput_Submit
  749.     /**
  750.      *  フォームタグを取得する(type="submit")
  751.      *
  752.      *  @access protected
  753.      */
  754.     function _getFormInput_Submit($name$def$params)
  755.     {
  756.         $params['type''submit';
  757.         if (isset($def['type'])) {
  758.             $params['name'is_array($def['type']$name '[]' $name;
  759.         else {
  760.             $params['name'$name;
  761.         }
  762.         if (isset($params['value']=== false{
  763.             if (isset($def['name'])) {
  764.                 $params['value'$def['name'];
  765.             }
  766.         }
  767.         if (is_array($params['value'])) {
  768.             $params['value'$params['value'][0];
  769.         }
  770.  
  771.         return $this->_getFormInput_Html('input'$params);
  772.     }
  773.     // }}}
  774.  
  775.     // {{{ _getFormInput_Textarea
  776.     /**
  777.      *  フォームタグを取得する(textarea)
  778.      *
  779.      *  @access protected
  780.      */
  781.     function _getFormInput_Textarea($name$def$params)
  782.     {
  783.         if (isset($def['type'])) {
  784.             $params['name'is_array($def['type']$name '[]' $name;
  785.         else {
  786.             $params['name'$name;
  787.         }
  788.  
  789.         // element
  790.         $element '';
  791.         if (isset($params['value'])) {
  792.             $element $params['value'];
  793.             unset($params['value']);
  794.         else if (isset($params['default'])) {
  795.             $element $params['default'];
  796.         else if (isset($def['default'])) {
  797.             $element $def['default'];
  798.         }
  799.         if (is_array($element)) {
  800.             if ($def['_form_counter'count($element)) {
  801.                 $element $element[$def['_form_counter']];
  802.             else {
  803.                 $element '';
  804.             }
  805.         else {
  806.             $params['value'$element;
  807.         }
  808.  
  809.         return $this->_getFormInput_Html('textarea'$params$element);
  810.     }
  811.     // }}}
  812.  
  813.     // {{{ _getFormInput_Text
  814.     /**
  815.      *  フォームタグを取得する(type="text")
  816.      *
  817.      *  @access protected
  818.      */
  819.     function _getFormInput_Text($name$def$params)
  820.     {
  821.         // type
  822.         $params['type''text';
  823.  
  824.         // name
  825.         if (isset($def['type'])) {
  826.             $params['name'is_array($def['type']$name '[]' $name;
  827.         else {
  828.             $params['name'$name;
  829.         }
  830.  
  831.         // value
  832.         $value '';
  833.         if (isset($params['value'])) {
  834.             $value $params['value'];
  835.         else if (isset($params['default'])) {
  836.             $value $params['default'];
  837.         else if (isset($def['default'])) {
  838.             $value $def['default'];
  839.         }
  840.         if (is_array($value)) {
  841.             if ($def['_form_counter'count($value)) {
  842.                 $params['value'$value[$def['_form_counter']];
  843.             else {
  844.                 $params['value''';
  845.             }
  846.         else {
  847.             $params['value'$value;
  848.         }
  849.  
  850.         // maxlength
  851.         if (isset($def['max']&& $def['max']{
  852.             $params['maxlength'$def['max'];
  853.         }
  854.  
  855.         return $this->_getFormInput_Html('input'$params);
  856.     }
  857.     // }}}
  858.  
  859.     // {{{ _getFormInput_Html
  860.     /**
  861.      *  HTMLタグを取得する
  862.      *
  863.      *  @access protected
  864.      */
  865.     function _getFormInput_Html($tag$attr$element null$escape_element true)
  866.     {
  867.         // 不要なパラメータは消す
  868.         foreach ($this->helper_parameter_keys as $key{
  869.             unset($attr[$key]);
  870.         }
  871.  
  872.         $r "<$tag";
  873.  
  874.         foreach ($attr as $key => $value{
  875.             if ($value === null{
  876.                 $r .= sprintf(' %s'$key);
  877.             else {
  878.                 $r .= sprintf(' %s="%s"'$keyhtmlspecialchars($valueENT_QUOTES));
  879.             }
  880.         }
  881.  
  882.         if ($element === null{
  883.             $r .= ' />';
  884.         else if ($escape_element{
  885.             $r .= sprintf('>%s</%s>'htmlspecialchars($elementENT_QUOTES)$tag);
  886.         else {
  887.             $r .= sprintf('>%s</%s>'$element$tag);
  888.         }
  889.  
  890.         return $r;
  891.     }
  892.     // }}}
  893.  
  894.     // {{{ _getRenderer
  895.     /**
  896.      *  レンダラオブジェクトを取得する
  897.      *
  898.      *  @access protected
  899.      *  @return object  Ethna_Renderer  レンダラオブジェクト
  900.      */
  901.     function &_getRenderer()
  902.     {
  903.         $_ret_object =$this->_getTemplateEngine();
  904.         return $_ret_object;
  905.     }
  906.     // }}}
  907.  
  908.     // {{{ _getTemplateEngine
  909.     /**
  910.      *  レンダラオブジェクトを取得する(そのうち_getRenderer()に統合される予定)
  911.      *
  912.      *  @access protected
  913.      *  @return object  Ethna_Renderer  レンダラオブジェクト
  914.      *  @obsolete
  915.      */
  916.     function &_getTemplateEngine()
  917.     {
  918.         $c =$this->backend->getController();
  919.         $renderer =$c->getRenderer();
  920.  
  921.         $form_array =$this->af->getArray();
  922.         $app_array =$this->af->getAppArray();
  923.         $app_ne_array =$this->af->getAppNEArray();
  924.         $renderer->setPropByRef('form'$form_array);
  925.         $renderer->setPropByRef('app'$app_array);
  926.         $renderer->setPropByRef('app_ne'$app_ne_array);
  927.         $message_list Ethna_Util::escapeHtml($this->ae->getMessageList());
  928.         $renderer->setPropByRef('errors'$message_list);
  929.         if (isset($_SESSION)) {
  930.             $tmp_session Ethna_Util::escapeHtml($_SESSION);
  931.             $renderer->setPropByRef('session'$tmp_session);
  932.         }
  933.         $renderer->setProp('script',
  934.             htmlspecialchars(basename($_SERVER['SCRIPT_NAME'])ENT_QUOTES));
  935.         $renderer->setProp('request_uri',
  936.             isset($_SERVER['REQUEST_URI'])
  937.             ? htmlspecialchars($_SERVER['REQUEST_URI']ENT_QUOTES)
  938.             : '');
  939.         $renderer->setProp('config'$this->config->get());
  940.  
  941.         return $renderer;
  942.     }
  943.     // }}}
  944.  
  945.     // {{{ _setDefault
  946.     /**
  947.      *  共通値を設定する
  948.      *
  949.      *  @access protected
  950.      *  @param  object  Ethna_Renderer  レンダラオブジェクト
  951.      */
  952.     function _setDefault(&$renderer)
  953.     {
  954.     }
  955.     // }}}
  956. }
  957. // }}}
  958. ?>

Documentation generated on Thu, 08 May 2008 00:15:40 +0900 by phpDocumentor 1.4.2