source: branches/version-2_12-dev/data/class/pages/admin/system/LC_Page_Admin_System_Masterdata.php @ 21689

Revision 21689, 6.8 KB checked in by h_yoshimoto, 12 years ago (diff)

#1692 インスタンスを呼び出す処理を統一

  • 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-2011 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_EX_REALDIR . 'page_extends/admin/LC_Page_Admin_Ex.php';
26
27/**
28 * マスターデータ管理 のページクラス.
29 *
30 * @package Page
31 * @author LOCKON CO.,LTD.
32 * @version $Id$
33 */
34class LC_Page_Admin_System_Masterdata extends LC_Page_Admin_Ex {
35
36    // }}}
37    // {{{ functions
38
39    /**
40     * Page を初期化する.
41     *
42     * @return void
43     */
44    function init() {
45        parent::init();
46        $this->tpl_mainpage = 'system/masterdata.tpl';
47        $this->tpl_subno = 'masterdata';
48        $this->tpl_mainno = 'system';
49        $this->tpl_maintitle = 'システム設定';
50        $this->tpl_subtitle = 'マスターデータ管理';
51    }
52
53    /**
54     * Page のプロセス.
55     *
56     * @return void
57     */
58    function process() {
59        $this->action();
60        $this->sendResponse();
61    }
62
63    /**
64     * Page のアクション.
65     *
66     * @return void
67     */
68    function action() {
69        // フックポイント.
70        $objPlugin = SC_Helper_Plugin_Ex::getSingletonInstance($this->plugin_activate_flg);
71        $objPlugin->doAction('lc_page_admin_system_masterdata_action_start', array($this));
72
73        $this->arrMasterDataName = $this->getMasterDataNames(array('mtb_pref', 'mtb_zip', 'mtb_constants'));
74        $masterData = new SC_DB_MasterData_Ex();
75
76        switch ($this->getMode()) {
77            case 'edit':
78                // POST 文字列の妥当性チェック
79                $this->masterDataName = $this->checkMasterDataName($_POST, $this->arrMasterDataName);
80                $this->errorMessage = $this->checkUniqueID($_POST);
81
82                if (empty($this->errorMessage)) {
83                    // 取得したデータからマスターデータを生成
84                    $this->registMasterData($_POST, $masterData, $this->masterDataName);
85                    $this->tpl_onload = "window.alert('マスターデータの設定が完了しました。');";
86                }
87                // FIXME break 入れ忘れと思われる。そうでないなら、要コメント。
88
89            case 'show':
90                // POST 文字列の妥当性チェック
91                $this->masterDataName = $this->checkMasterDataName($_POST, $this->arrMasterDataName);
92
93                // DB からマスターデータを取得
94                $this->arrMasterData =
95                    $masterData->getDbMasterData($this->masterDataName);
96                break;
97
98            default:
99                break;
100        }
101        // フックポイント.
102        $objPlugin = SC_Helper_Plugin_Ex::getSingletonInstance($this->plugin_activate_flg);
103        $objPlugin->doAction('lc_page_admin_system_masterdata_action_end', array($this));
104    }
105
106    /**
107     * デストラクタ.
108     *
109     * @return void
110     */
111    function destroy() {
112        parent::destroy();
113    }
114
115    /**
116     * マスターデータ名チェックを行う
117     *
118     * @access private
119     * @param array $_POST値
120     * @param array $arrMasterDataName  マスターデータテーブル名のリスト
121     * @return string $master_data_name 選択しているマスターデータのテーブル名
122     */
123    function checkMasterDataName(&$arrParams, &$arrMasterDataName) {
124
125        if (in_array($arrParams['master_data_name'], $arrMasterDataName)) {
126            $master_data_name = $arrParams['master_data_name'];
127            return $master_data_name;
128        } else {
129            SC_Utils_Ex::sfDispError('');
130        }
131
132    }
133
134    /**
135     * マスターデータ名を配列で取得する.
136     *
137     * @access private
138     * @param array $ignores 取得しないマスターデータ名の配列
139     * @return array マスターデータ名の配列
140     */
141    function getMasterDataNames($ignores = array()) {
142        $dbFactory = SC_DB_DBFactory_Ex::getInstance();
143        $arrMasterDataName = $dbFactory->findTableNames('mtb_');
144
145        $i = 0;
146        foreach ($arrMasterDataName as $val) {
147            foreach ($ignores as $ignore) {
148                if ($val == $ignore) {
149                    unset($arrMasterDataName[$i]);
150                }
151            }
152            $i++;
153        }
154        return $arrMasterDataName;
155    }
156
157    /**
158     * ID の値がユニークかチェックする.
159     *
160     * 重複した値が存在する場合はエラーメッセージを表示する.
161     *
162     * @access private
163     * @return void|string エラーが発生した場合はエラーメッセージを返す.
164     */
165    function checkUniqueID(&$arrParams) {
166
167        $arrId = $arrParams['id'];
168        for ($i = 0; $i < count($arrId); $i++) {
169
170            $id = $arrId[$i];
171            // 空の値は無視
172            if ($arrId[$i] != '') {
173                for ($j = $i + 1; $j < count($arrId); $j++) {
174                    if ($id == $arrId[$j]) {
175                        return $id . ' が重複しているため登録できません.';
176                    }
177                }
178            }
179        }
180    }
181
182    /**
183     * マスターデータの登録.
184     *
185     * @access private{
186     * @param array  $arrParams $_POST値
187     * @param object $masterData SC_DB_MasterData_Ex()
188     * @param string $master_data_name 登録対象のマスターデータのテーブル名
189     * @return void
190     */
191    function registMasterData($arrParams, &$masterData, $master_data_name) {
192
193        $arrTmp = array();
194        foreach ($arrParams['id'] as $key => $val) {
195
196            // ID が空のデータは生成しない
197            if ($val != '') {
198                $arrTmp[$val] = $arrParams['name'][$key];
199            }
200        }
201
202        // マスターデータを更新
203        $masterData->objQuery =& SC_Query_Ex::getSingletonInstance();
204        $masterData->objQuery->begin();
205        $masterData->deleteMasterData($master_data_name, false);
206        // TODO カラム名はメタデータから取得した方が良い
207        $masterData->registMasterData($master_data_name, array('id', 'name', 'rank'), $arrTmp, false);
208        $masterData->objQuery->commit();
209
210    }
211}
Note: See TracBrowser for help on using the repository browser.