source: branches/comu-ver2/data/class/module/SC_Module.php @ 18701

Revision 18701, 6.9 KB checked in by nanasess, 14 years ago (diff)

Copyright の更新(#601)

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-httpd-php; charset=UTF-8
Line 
1<?php
2/*
3 * This file is part of EC-CUBE
4 *
5 * Copyright(c) 2000-2010 LOCKON CO.,LTD. All Rights Reserved.
6 *
7 * http://www.lockon.co.jp/
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22 */
23
24// {{{ requires
25require_once CLASS_PATH . 'SC_Query.php';
26require_once CLASS_EX_PATH . 'db_extends/SC_DB_MasterData_Ex.php';
27
28/**
29 * モジュールデータ管理クラス.
30 * 各モジュールに固有のデータへのアクセスを担当する.
31 *
32 * @example
33 * $module = new SC_Module('mdl_gmopg', 'GMOPG決済モジュール');
34 * $arrSubData = $module->getSubData();
35 * $module->registerSubData($arrData);
36 * $arrPaymethod = $module->getMasterData('paymethod); // data/cache/mtb_mdl_gmopg_paymethod.php
37 * $module->log('order error!', $debugValue); // data/logs/mdl_gmopg.log
38 *
39 * @package module
40 * @author LOCKON CO.,LTD.
41 * @version $Id$
42 *
43 * TODO モジュールコード周りの改修 命名がばらばらなのを吸収できるように
44 * TODO テーブル拡張, マスターデータ登録, 初期ファイルコピー処理の追加
45 */
46class SC_Module {
47
48    /** モジュール名 */
49    var $moduleName;
50
51    /** モジュールコード */
52    var $moduleCode;
53
54    /** サブデータを保持する */
55    var $subData;
56
57    /** パス定義 */
58    var $classPath    = 'class/';
59    var $templatePath = 'template/';
60    var $installPath  = 'install/';
61
62    /**
63     * コンストラクタ
64     *
65     * @param string $code
66     * @param string $name
67     * @return SC_Module
68     */
69    function SC_Module($code, $name='') {
70        $this->setCode($code);
71        $this->setName($name);
72    }
73
74    function setName($name) {
75        $this->moduleName = strtolower($name);
76    }
77
78    function setCode($code) {
79        $this->moduleCode = $code;
80    }
81
82    /**
83     * モジュール名を返す.
84     *
85     * @return string
86     */
87    function getName() {
88        if (empty($this->moduleName)) {
89            $moduleName = $this->_getName();
90            $this->setName($moduleName);
91            return $moduleName;
92        }
93        return $this->moduleName;
94    }
95
96    /**
97     * DBからモジュール名を取得する
98     *
99     * @return string
100     */
101    function _getName() {
102        $objQuery = new SC_Query;
103        return $objQuery->get('dtb_module', 'module_name', 'module_code = ?', $this->getCode());
104    }
105
106    /**
107     * モジュールコードを返す.
108     *
109     * @param boolean $toUpper 大文字に変換するかどうか.デフォルトはfalse
110     * @return string
111     */
112    function getCode($toUpper = false) {
113        $moduleCode = $this->moduleCode;
114        return $toUpper ? strtoupper($moduleCode) : $moduleCode;
115    }
116
117    /**
118     * モジュールのベースパスを返す
119     *
120     * @return string
121     */
122    function getBasePath() {
123        return MODULE_PATH . $this->getCode() . '/';
124    }
125
126    /**
127     * テンプレートパスを返す
128     *
129     * @return string
130     */
131    function getTemplatePath() {
132        return $this->getBasePath() . $this->templatePath;
133    }
134
135    /**
136     * クラスパスを返す.
137     *
138     * @return string
139     */
140    function getClassPath() {
141        return $this->getBasePath() . $this->classPath;
142    }
143
144    /**
145     * dtb_moduleのsub_dataを取得する.
146     *
147     * @access private
148     * @param booean $force
149     * @return mixed|null
150     */
151    function _getSubData($force = false) {
152        if (isset($this->subData)) return $this->subData;
153
154        $moduleCode = $this->getCode();
155        $objQuery = new SC_Query;
156        $ret = $objQuery->get(
157            'dtb_module', 'sub_data', 'module_code = ?', array($moduleCode)
158        );
159
160        if (isset($ret)) {
161            $this->subData = unserialize($ret);
162            return $this->subData;
163        }
164        return null;
165    }
166
167    /**
168     * dtb_moduleのsub_dataを取得する.
169     *
170     * @param string $key
171     * @param boolean $force
172     * @return mixed|null
173     */
174    function getSubData($key = null, $force = false) {
175        $subData = $this->_getSubData($force);
176        $returnData = null;
177
178        if (is_null($key)) {
179            $returnData = $subData;
180        } else {
181            $returnData = isset($subData[$key])
182                ? $subData[$key]
183                : null;
184        }
185
186        return $returnData;
187    }
188
189    /**
190     * サブデータを登録する.
191     *
192     * @param mixed $data
193     * @param string
194     */
195    function registerSubData($data, $key = null) {
196        $subData = $this->getSubData();
197
198        if (is_null($key)) {
199            $subData = $data;
200        } else {
201            if (is_array($subData)) {
202                $subData[$key] = $data;
203            } else {
204                $subData = array($key => $data);
205            }
206        }
207
208        $arrUpdate = array('sub_data' => serialize($subData));
209
210        $objQuery = new SC_Query;
211        $objQuery->update('dtb_module', $arrUpdate, 'module_code = ?', array($this->getCode()));
212
213        $this->subData = $subData;
214    }
215
216    /**
217     * マスターデータを登録.
218     * 作りかけ...
219     *
220     * @param unknown_type $key
221     * @param unknown_type $value
222     */
223    function registerMasterData($key, $value) {
224        $masterData = new SC_DB_MasterData;
225    }
226
227    /**
228     * マスターデータを取得する.
229     *
230     * キャッシュはmtb_mdl_[name]_[***].phpで保存されるが、
231     * 取得する場合はは$keyに***を指定する.
232     * 例えば、mtb_mdl_gmopg_paymethod.phpにアクセスしたい場合は、
233     * $arrPaymethod = $masterData->getMasterData('paymethod');
234     * で取得できる.
235     *
236     * @param string $key
237     * @return array
238     */
239    function getMasterData($key) {
240        $key = 'mtb_' . $this->getCode() . "_$key";
241        $masterData = new SC_DB_MasterData_Ex;
242        return $masterData->getMasterData($key);
243    }
244
245    /**
246     * ログを出力.
247     *
248     * @param string $msg
249     * @param mixed $data Dumpしたいデータ.デバッグ用.
250     * @param string $suffix
251     */
252    function log($msg, $data = null, $suffix = '') {
253        $path = DATA_PATH . 'logs/' . $this->getCode() . "$suffix.log";
254        GC_Utils::gfPrintLog($msg, $path);
255
256        if (!is_null($data)) {
257            GC_Utils::gfPrintLog(print_r($data, true), $path);
258        }
259    }
260}
261/*
262 * Local variables:
263 * coding: utf-8
264 * End:
265 */
266?>
Note: See TracBrowser for help on using the repository browser.