Source for file List.php

Documentation is available at List.php

  1. <?php
  2. // vim: foldmethod=marker
  3. /**
  4.  *  List.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: 9fb9c5e0f0abc2ee561ecfd43ce49b68730b4179 $
  10.  */
  11.  
  12. // {{{ Ethna_View_List
  13. /**
  14.  *  リストビュー基底クラスの実装
  15.  *
  16.  *  @author     Masaki Fujimoto <fujimoto@php.net>
  17.  *  @access     public
  18.  *  @package    Ethna
  19.  */
  20. {
  21.     /**#@+
  22.      *  @access protected
  23.      */
  24.  
  25.     /** @protected    int     表示開始オフセット */
  26.     protected $offset = 0;
  27.  
  28.     /** @protected    int     表示件数 */
  29.     protected $count = 25;
  30.  
  31.     /** @protected    array   検索対象項目一覧 */
  32.     protected $search_list = array();
  33.  
  34.     /** @protected    string  検索マネージャクラス名 */
  35.     protected $manager_name = null;
  36.  
  37.     /** @protected    string  表示対象クラス名 */
  38.     protected $class_name = null;
  39.  
  40.     /**#@-*/
  41.  
  42.     /**
  43.      *  遷移前処理
  44.      *
  45.      *  @access public
  46.      */
  47.     public function preforward()
  48.     {
  49.         // 表示オフセット/件数設定
  50.         $this->offset = $this->af->get('offset');
  51.         if ($this->offset == ""{
  52.             $this->offset = 0;
  53.         }
  54.         if (intval($this->af->get('count')) 0{
  55.             $this->count = intval($this->af->get('count'));
  56.         }
  57.  
  58.         // 検索条件
  59.         $filter array();
  60.         $sort array();
  61.         foreach ($this->search_list as $key{
  62.             if ($this->af->get("s_$key"!= ""{
  63.                 $filter[$key$this->af->get("s_$key");
  64.             }
  65.             if ($this->af->get("sort"== $key{
  66.                 $order $this->af->get("order"== "desc" OBJECT_SORT_DESC OBJECT_SORT_ASC;
  67.                 $sort array(
  68.                     $key => $order,
  69.                 );
  70.             }
  71.         }
  72.  
  73.         // 表示項目一覧
  74.         $manager_name $this->manager_name;
  75.         for ($i 0$i 2$i++{
  76.             list($total$obj_list$this->$manager_name->getObjectList($this->class_name$filter$sort$this->offset$this->count);
  77.             if (count($obj_list== && $this->offset >= $total{
  78.                 $this->offset = 0;
  79.                 continue;
  80.             }
  81.             break;
  82.         }
  83.  
  84.         $r array();
  85.         foreach ($obj_list as $obj{
  86.             $value $obj->getNameObject();
  87.             $value $this->_fixNameObject($value$obj);
  88.             $r[$value;
  89.         }
  90.         $list_name sprintf("%s_list"strtolower(preg_replace('/(.)([A-Z])/''\\1_\\2'$this->class_name)));
  91.         $this->af->setApp($list_name$r);
  92.  
  93.         // ナビゲーション
  94.         $this->af->setApp('nav'$this->_getNavigation($total$obj_list));
  95.         $this->af->setAppNE('query'$this->_getQueryParameter());
  96.  
  97.         // 検索オプション
  98.         $this->_setQueryOption();
  99.     }
  100.  
  101.     /**
  102.      *  表示項目を修正する
  103.      *
  104.      *  @access protected
  105.      */
  106.     protected function _fixNameObject($value$obj)
  107.     {
  108.         return $value;
  109.     }
  110.     
  111.     /**
  112.      *  ナビゲーション情報を取得する
  113.      *
  114.      *  @access private
  115.      *  @param  int     $total      検索総件数
  116.      *  @param  array   $list       検索結果
  117.      *  @return array   ナビゲーション情報を格納した配列
  118.      */
  119.     protected function _getNavigation($total&$list)
  120.     {
  121.         $nav array();
  122.         $nav['offset'$this->offset;
  123.         $nav['from'$this->offset + 1;
  124.         if ($total == 0{
  125.             $nav['from'0;
  126.         }
  127.         $nav['to'$this->offset + count($list);
  128.         $nav['total'$total;
  129.         if ($this->offset > 0{
  130.             $prev_offset $this->offset - $this->count;
  131.             if ($prev_offset 0{
  132.                 $prev_offset 0;
  133.             }
  134.             $nav['prev_offset'$prev_offset;
  135.         }
  136.         if ($this->offset + $this->count < $total{
  137.             $next_offset $this->offset + count($list);
  138.             $nav['next_offset'$next_offset;
  139.         }
  140.         $nav['direct_link_list'Ethna_Util::getDirectLinkList($total$this->offset$this->count);
  141.  
  142.         return $nav;
  143.     }
  144.  
  145.     /**
  146.      *  検索項目を生成する
  147.      *
  148.      *  @access protected
  149.      */
  150.     protected function _setQueryOption()
  151.     {
  152.     }
  153.  
  154.     /**
  155.      *  検索内容を格納したGET引数を生成する
  156.      *
  157.      *  @access private
  158.      *  @param  array   $search_list    検索対象一覧
  159.      *  @return string  検索内容を格納したGET引数
  160.      */
  161.     protected function _getQueryParameter()
  162.     {
  163.         $query "";
  164.  
  165.         foreach ($this->search_list as $key{
  166.             $value $this->af->get("s_$key");
  167.             if (is_array($value)) {
  168.                 foreach ($value as $v{
  169.                     $query .= "&s_$key"[]=" urlencode($v);
  170.                 }
  171.             else {
  172.                 $query .= "&s_$key=urlencode($value);
  173.             }
  174.         }
  175.  
  176.         return $query;
  177.     }
  178. }
  179. // }}}

Documentation generated on Fri, 11 Nov 2011 03:58:27 +0900 by phpDocumentor 1.4.3