Source for file AppManager.php

Documentation is available at AppManager.php

  1. <?php
  2. // vim: foldmethod=marker
  3. /**
  4.  *  AppManager.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: 8597f7b203277766746ef8b89bf562b82c8e6663 $
  10.  */
  11.  
  12. /** アプリケーションオブジェクト状態: 使用可能 */
  13. define('OBJECT_STATE_ACTIVE'0);
  14. /** アプリケーションオブジェクト状態: 使用不可 */
  15. define('OBJECT_STATE_INACTIVE'100);
  16.  
  17.  
  18. /** アプリケーションオブジェクトソートフラグ: 昇順 */
  19. define('OBJECT_SORT_ASC'0);
  20. /** アプリケーションオブジェクトソートフラグ: 降順 */
  21. define('OBJECT_SORT_DESC'1);
  22.  
  23.  
  24. /** アプリケーションオブジェクトインポートオプション: NULLプロパティ無変換 */
  25. define('OBJECT_IMPORT_IGNORE_NULL'1);
  26.  
  27. /** アプリケーションオブジェクトインポートオプション: NULLプロパティ→空文字列変換 */
  28. define('OBJECT_IMPORT_CONVERT_NULL'2);
  29.  
  30.  
  31. // {{{ Ethna_AppManager
  32. /**
  33.  *  アプリケーションマネージャのベースクラス
  34.  *
  35.  *  @author     Masaki Fujimoto <fujimoto@php.net>
  36.  *  @access     public
  37.  *  @package    Ethna
  38.  */
  39. {
  40.     /**#@+
  41.      *  @access private
  42.      */
  43.  
  44.     /** @protected    object  Ethna_Backend       backendオブジェクト */
  45.     protected $backend;
  46.  
  47.     /** @protected    object  Ethna_Config        設定オブジェクト */
  48.     protected $config;
  49.  
  50.     /**  @protected    object  Ethna_DB      DBオブジェクト */
  51.     protected $db;
  52.  
  53.     /** @protected    object  Ethna_I18N          i18nオブジェクト */
  54.     protected $i18n;
  55.  
  56.     /** @protected    object  Ethna_ActionForm    アクションフォームオブジェクト */
  57.     protected $action_form;
  58.  
  59.     /** @protected    object  Ethna_ActionForm    アクションフォームオブジェクト(省略形) */
  60.     protected $af;
  61.  
  62.     /** @protected    object  Ethna_Session       セッションオブジェクト */
  63.     protected $session;
  64.  
  65.     /**#@-*/
  66.  
  67.     /**
  68.      *  Ethna_AppManagerのコンストラクタ
  69.      *
  70.      *  @access public
  71.      *  @param  object  Ethna_Backend   $backend   backendオブジェクト
  72.      */
  73.     public function __construct($backend)
  74.     {
  75.         // 基本オブジェクトの設定
  76.         $this->backend = $backend;
  77.         $this->config = $backend->getConfig();
  78.         $this->i18n = $backend->getI18N();
  79.         $this->action_form = $backend->getActionForm();
  80.         $this->af = $this->action_form;
  81.         $this->session = $backend->getSession();
  82.  
  83.         $db_list $backend->getDBList();
  84.         if (Ethna::isError($db_list== false{
  85.             foreach ($db_list as $elt{
  86.                 $varname $elt['varname'];
  87.                 $this->$varname $elt['db'];
  88.             }
  89.         }
  90.     }
  91.  
  92.     /**
  93.      *  属性の一覧を返す
  94.      *
  95.      *  @access public
  96.      *  @param  string  $attr_name  属性の名前(変数名)
  97.      *  @return array   属性値一覧
  98.      */
  99.     function getAttrList($attr_name)
  100.     {
  101.         $varname $attr_name "_list";
  102.         return $this->$varname;
  103.     }
  104.  
  105.     /**
  106.      *  属性の表示名を返す
  107.      *
  108.      *  @access public
  109.      *  @param  string  $attr_name  属性の名前(変数名)
  110.      *  @param  mixed   $id         属性ID
  111.      *  @return string  属性の表示名
  112.      */
  113.     function getAttrName($attr_name$id)
  114.     {
  115.         $varname $attr_name "_list";
  116.         if (is_array($this->$varname== false{
  117.             return null;
  118.         }
  119.         $list $this->$varname;
  120.         if (isset($list[$id]== false{
  121.             return null;
  122.         }
  123.         return $list[$id]['name'];
  124.     }
  125.  
  126.     /**
  127.      *  属性の表示名(詳細)を返す
  128.      *
  129.      *  @access public
  130.      *  @param  string  $attr_name  属性の名前(変数名)
  131.      *  @param  mixed   $id         属性ID
  132.      *  @return string  属性の詳細表示名
  133.      */
  134.     function getAttrLongName($attr_name$id)
  135.     {
  136.         $varname $attr_name "_list";
  137.         if (is_array($this->$varname== false{
  138.             return null;
  139.         }
  140.         $list $this->$varname;
  141.         if (isset($list[$id]['long_name']== false{
  142.             return null;
  143.         }
  144.  
  145.         return $list[$id]['long_name'];
  146.     }
  147.  
  148.     /**
  149.      *  オブジェクトの一覧を返す
  150.      *
  151.      *  @access public
  152.      *  @param  string  $class  Ethna_AppObjectの継承クラス名
  153.      *  @param  array   $filter     検索条件
  154.      *  @param  array   $order      検索結果ソート条件
  155.      *  @param  int     $offset     検索結果取得オフセット
  156.      *  @param  int     $count      検索結果取得数
  157.      *  @return mixed   array(0 => 検索条件にマッチした件数, 1 => $offset, $countにより指定された件数のオブジェクトID一覧) Ethna_Error:エラー
  158.      *  @todo   パフォーマンス対策(1オブジェクトの占有メモリが多い場合)
  159.      */
  160.     function getObjectList($class$filter null,
  161.                            $order null$offset null$count null)
  162.     {
  163.         global $_ETHNA_APP_MANAGER_OL_CACHE;
  164.  
  165.         $object_list array();
  166.         $class_name sprintf("%s_%s"$this->backend->getAppId()$class);
  167.  
  168.         // キャッシュチェック
  169.         $cache_class strtolower($class_name);
  170.         if (is_array($_ETHNA_APP_MANAGER_OL_CACHE== false
  171.             || array_key_exists($cache_class$_ETHNA_APP_MANAGER_OL_CACHE== false{
  172.             $_ETHNA_APP_MANAGER_OL_CACHE[$cache_classarray();
  173.         }
  174.         $cache_key serialize(array($filter$order$offset$count));
  175.         if (array_key_exists($cache_key$_ETHNA_APP_MANAGER_OL_CACHE[$cache_class])) {
  176.             list($length$prop_list)
  177.                 = $_ETHNA_APP_MANAGER_OL_CACHE[$cache_class][$cache_key];
  178.         else {
  179.             // キャッシュ更新
  180.             $tmp new $class_name($this->backend);
  181.             list($length$prop_list)
  182.                 = $tmp->searchProp(null$filter$order$offset$count);
  183.             $_ETHNA_APP_MANAGER_OL_CACHE[$cache_class][$cache_key]
  184.                 = array($length$prop_list);
  185.         }
  186.  
  187.         foreach ($prop_list as $prop{
  188.             $object new $class_name($this->backendnullnull$prop);
  189.             $object_list[$object;
  190.         }
  191.  
  192.         return array($length$object_list);
  193.     }
  194.  
  195.     /**
  196.      *  オブジェクトプロパティの一覧を返す
  197.      *
  198.      *  getObjectList()メソッドは条件にマッチするIDを元にEthna_AppObjectを生成する
  199.      *  ためコストがかかる。こちらはプロパティのみをSELECTするので低コストでデータ
  200.      *  を取得することが可能。
  201.      *
  202.      *  @access public
  203.      *  @param  string  $class      Ethna_AppObjectの継承クラス名
  204.      *  @param  array   $keys       取得するプロパティ一覧(nullなら全て)
  205.      *  @param  array   $filter     検索条件
  206.      *  @param  array   $order      検索結果ソート条件
  207.      *  @param  int     $offset     検索結果取得オフセット
  208.      *  @param  int     $count      検索結果取得数
  209.      *  @return mixed   array(0 => 検索条件にマッチした件数,
  210.      *                         1 => $offset, $countにより指定された件数のプロパティ一覧)
  211.      *                   Ethna_Error:エラー
  212.      */
  213.     function getObjectPropList($class$keys null$filter null,
  214.                                $order null$offset null$count null)
  215.     {
  216.         global $_ETHNA_APP_MANAGER_OPL_CACHE;
  217.  
  218.         $prop_list array();
  219.         $class_name sprintf("%s_%s"$this->backend->getAppId()$class);
  220.  
  221.         // キャッシュチェック
  222.         $cache_class strtolower($class_name);
  223.         if (is_array($_ETHNA_APP_MANAGER_OPL_CACHE== false
  224.             || array_key_exists($cache_class$_ETHNA_APP_MANAGER_OPL_CACHE== false{
  225.             $_ETHNA_APP_MANAGER_OPL_CACHE[$cache_classarray();
  226.         }
  227.         $cache_key serialize(array($filter$order$offset$count));
  228.         if (array_key_exists($cache_key$_ETHNA_APP_MANAGER_OPL_CACHE[$cache_class])) {
  229.             // skip
  230.         else {
  231.             // キャッシュ更新
  232.             $tmp new $class_name($this->backend);
  233.             $_ETHNA_APP_MANAGER_OPL_CACHE[$cache_class][$cache_key]
  234.                 = $tmp->searchProp($keys$filter$order$offset$count);
  235.         }
  236.  
  237.         return $_ETHNA_APP_MANAGER_OPL_CACHE[$cache_class][$cache_key];
  238.     }
  239.  
  240.     /**
  241.      *  オブジェクトプロパティを返す
  242.      *
  243.      *  getObjectPropList()メソッドの簡易版で、$filterにより結果が1エントリに
  244.      *  制限される場合(プライマリキーでの検索等)に利用する
  245.      *
  246.      *  @access public
  247.      *  @param  string  $class      Ethna_AppObjectの継承クラス名
  248.      *  @param  array   $keys       取得するプロパティ一覧
  249.      *  @param  array   $filter     検索条件
  250.      *  @return mixed   array:プロパティ一覧 null:エントリなし Ethna_Error:エラー
  251.      */
  252.     function getObjectProp($class$keys null$filter null)
  253.     {
  254.         global $_ETHNA_APP_MANAGER_OP_CACHE;
  255.  
  256.         $prop_list array();
  257.         $class_name sprintf("%s_%s"$this->backend->getAppId()$class);
  258.  
  259.         // キャッシュチェック
  260.         $cache_class strtolower($class_name);
  261.         if (is_array($_ETHNA_APP_MANAGER_OP_CACHE== false
  262.             || array_key_exists($cache_class$_ETHNA_APP_MANAGER_OP_CACHE== false{
  263.             $_ETHNA_APP_MANAGER_OP_CACHE[$cache_classarray();
  264.         }
  265.         $cache_key serialize(array($filter));
  266.         if (array_key_exists($cache_key$_ETHNA_APP_MANAGER_OP_CACHE[$cache_class])) {
  267.             // skip
  268.         else {
  269.             // キャッシュ更新
  270.             $tmp new $class_name($this->backend);
  271.             list($prop$tmp->searchProp($keys$filter);
  272.             $_ETHNA_APP_MANAGER_OP_CACHE[$cache_class][$cache_key]
  273.                 = count($prop$prop[0null;
  274.         }
  275.  
  276.         return $_ETHNA_APP_MANAGER_OP_CACHE[$cache_class][$cache_key];
  277.     }
  278. }
  279. // }}}

Documentation generated on Fri, 11 Nov 2011 03:57:33 +0900 by phpDocumentor 1.4.3