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

Revision 21420, 6.4 KB checked in by Seasoft, 12 years ago (diff)

#1613 (ソース整形・ソースコメントの改善)

  • Zend Framework PHP 標準コーディング規約への準拠を高めた
  • 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        $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     * @access private{
179     * @param array  $arrParams $_POST値
180     * @param object $masterData SC_DB_MasterData_Ex()
181     * @param string $master_data_name 登録対象のマスターデータのテーブル名
182     * @return void
183     */
184    function registMasterData($arrParams, &$masterData, $master_data_name) {
185
186        $arrTmp = array();
187        foreach ($arrParams['id'] as $key => $val) {
188
189            // ID が空のデータは生成しない
190            if ($val != "") {
191                $arrTmp[$val] = $arrParams['name'][$key];
192            }
193        }
194
195        // マスターデータを更新
196        $masterData->objQuery =& SC_Query_Ex::getSingletonInstance();
197        $masterData->objQuery->begin();
198        $masterData->deleteMasterData($master_data_name, false);
199        // TODO カラム名はメタデータから取得した方が良い
200        $masterData->registMasterData($master_data_name,
201                                             array('id', 'name', 'rank'),
202                                             $arrTmp, false);
203        $masterData->objQuery->commit();
204
205    }
206}
Note: See TracBrowser for help on using the repository browser.