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

Revision 20507, 6.3 KB checked in by shutta, 13 years ago (diff)

SC_Queryクラスのclass_extends対応

  • 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_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_subnavi = 'system/subnavi.tpl';
48        $this->tpl_subno = 'masterdata';
49        $this->tpl_mainno = 'system';
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        $this->arrMasterDataName = $this->getMasterDataNames(array("mtb_pref",
70                                                                   "mtb_zip",
71                                                                   "mtb_constants"));
72        $masterData = new SC_DB_MasterData_Ex();
73
74        switch ($this->getMode()) {
75        case "edit":
76            // POST 文字列の妥当性チェック
77            $this->masterDataName = $this->checkMasterDataName($_POST, $this->arrMasterDataName);
78            $this->errorMessage = $this->checkUniqueID($_POST);
79
80            if (empty($this->errorMessage)) {
81                // 取得したデータからマスタデータを生成
82                $this->registMasterData($_POST, $masterData, $this->masterDataName);
83                $this->tpl_onload = "window.alert('マスタデータの設定が完了しました。');";
84            }
85
86        case "show":
87            // POST 文字列の妥当性チェック
88            $this->masterDataName = $this->checkMasterDataName($_POST, $this->arrMasterDataName);
89
90            // DB からマスタデータを取得
91            $this->arrMasterData =
92                $masterData->getDbMasterData($this->masterDataName);
93            break;
94
95        default:
96        }
97    }
98
99    /**
100     * デストラクタ.
101     *
102     * @return void
103     */
104    function destroy() {
105        parent::destroy();
106    }
107
108    /**
109     * マスタデータ名チェックを行う
110     *
111     * @access private
112     * @param array $_POST値
113     * @param array $arrMasterDataName  マスターデータテーブル名のリスト
114     * @return string $master_data_name 選択しているマスターデータのテーブル名
115     */
116    function checkMasterDataName(&$arrParams, &$arrMasterDataName) {
117
118        if (in_array($arrParams['master_data_name'], $arrMasterDataName)) {
119            $master_data_name = $arrParams['master_data_name'];
120            return $master_data_name;
121        } else {
122            SC_Utils_Ex::sfDispError("");
123        }
124
125    }
126
127    /**
128     * マスタデータ名を配列で取得する.
129     *
130     * @access private
131     * @param array $ignores 取得しないマスタデータ名の配列
132     * @return array マスタデータ名の配列
133     */
134    function getMasterDataNames($ignores = array()) {
135        $dbFactory = SC_DB_DBFactory_Ex::getInstance();
136        $arrMasterDataName = $dbFactory->findTableNames("mtb_");
137
138        $i = 0;
139        foreach ($arrMasterDataName as $val) {
140            foreach ($ignores as $ignore) {
141                if ($val == $ignore) {
142                    unset($arrMasterDataName[$i]);
143                }
144            }
145            $i++;
146        }
147        return $arrMasterDataName;
148    }
149
150    /**
151     * ID の値がユニークかチェックする.
152     *
153     * 重複した値が存在する場合はエラーメッセージを表示する.
154     *
155     * @access private
156     * @return void|string エラーが発生した場合はエラーメッセージを返す.
157     */
158    function checkUniqueID(&$arrParams) {
159
160        $arrId = $arrParams['id'];
161        for ($i = 0; $i < count($arrId); $i++) {
162
163            $id = $arrId[$i];
164            // 空の値は無視
165            if ($arrId[$i] != "") {
166                for ($j = $i + 1; $j < count($arrId); $j++) {
167                    if ($id == $arrId[$j]) {
168                        return $id . " が重複しているため登録できません.";
169                    }
170                }
171            }
172        }
173    }
174
175
176    /**
177     * マスターデータの登録.
178     *
179     * @access private{
180     * @param array  $arrParams $_POST値
181     * @param object $masterData SC_DB_MasterData_Ex()
182     * @param string $master_data_name 登録対象のマスターデータのテーブル名
183     * @return void
184     */
185    function registMasterData($arrParams, &$masterData, $master_data_name) {
186
187        $arrTmp = array();
188        foreach ($arrParams['id'] as $key => $val) {
189
190            // ID が空のデータは生成しない
191            if ($val != "") {
192                $arrTmp[$val] = $arrParams['name'][$key];
193            }
194        }
195
196        // マスタデータを更新
197        $masterData->objQuery =& SC_Query_Ex::getSingletonInstance();
198        $masterData->objQuery->begin();
199        $masterData->deleteMasterData($master_data_name, false);
200        // TODO カラム名はメタデータから取得した方が良い
201        $masterData->registMasterData($master_data_name,
202                                             array("id", "name", "rank"),
203                                             $arrTmp, false);
204        $masterData->objQuery->commit();
205
206    }
207}
208?>
Note: See TracBrowser for help on using the repository browser.