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

Documentation generated on Fri, 11 Nov 2011 04:01:11 +0900 by phpDocumentor 1.4.3