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

Revision 23605, 6.2 KB checked in by kimoto, 10 years ago (diff)

#2448 typo修正・ソース整形・ソースコメントの改善 for 2.13.3

Scrutinizer Auto-Fixes

This patch was automatically generated as part of the following inspection:
 https://scrutinizer-ci.com/g/nobuhiko/EC-CUBE/inspections/d8722894-69a6-4b1b-898d-43618035c60d

Enabled analysis tools:

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