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

Revision 22567, 6.4 KB checked in by shutta, 11 years ago (diff)

#2043 (typo修正・ソース整形・ソースコメントの改善 for 2.12.4)
Zend Framework PHP 標準コーディング規約のコーディングスタイルへ準拠。
classおよびfunctionの開始波括弧「{」のスタイルを修正。

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