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

Revision 21420, 8.3 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_Basis_Holiday 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 = 'basis/holiday.tpl';
47        $this->tpl_subno = 'holiday';
48        $this->tpl_maintitle = '基本情報管理';
49        $this->tpl_subtitle = '定休日管理';
50        $this->tpl_mainno = 'basis';
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        $objDb = new SC_Helper_DB_Ex();
70
71        $objDate = new SC_Date_Ex();
72        $this->arrMonth = $objDate->getMonth();
73        $this->arrDay = $objDate->getDay();
74
75        $mode = $this->getMode();
76
77        if (!empty($_POST)) {
78
79            $objFormParam = new SC_FormParam_Ex();
80            $this->lfInitParam($mode, $objFormParam);
81            $objFormParam->setParam($_POST);
82            $objFormParam->convParam();
83            $holiday_id = $objFormParam->getValue('holiday_id');
84
85            $this->arrErr = $this->lfCheckError($mode, $objFormParam);
86            if (!empty($this->arrErr['holiday_id'])) {
87                SC_Utils_Ex::sfDispException();
88                return;
89            }
90
91            $post = $objFormParam->getHashArray();
92        }
93
94        // 要求判定
95        switch($mode) {
96        // 編集処理
97        case 'edit':
98            // POST値の引き継ぎ
99            $this->arrForm = $this->arrForm = $_POST;
100
101            if(count($this->arrErr) <= 0) {
102                // 新規作成
103                if($post['holiday_id'] == "") {
104                    $this->lfInsertClass($this->arrForm, $_SESSION['member_id']);
105                }
106                // 既存編集
107                else {
108                    $this->lfUpdateClass($this->arrForm, $post['holiday_id']);
109                }
110                // 再表示
111                $this->objDisplay->reload();
112            } else {
113                // POSTデータを引き継ぐ
114                $this->tpl_holiday_id = $post['holiday_id'];
115            }
116            break;
117        // 削除
118        case 'delete':
119            $objDb->sfDeleteRankRecord("dtb_holiday", "holiday_id", $post['holiday_id'], "", true);
120            // 再表示
121            $this->objDisplay->reload();
122            break;
123        // 編集前処理
124        case 'pre_edit':
125            // 編集項目を取得する。
126            $arrHolidayData = $this->lfGetHolidayDataByHolidayID($post['holiday_id']);
127
128            // 入力項目にカテゴリ名を入力する。
129            $this->arrForm['title'] = $arrHolidayData[0]['title'];
130            $this->arrForm['month'] = $arrHolidayData[0]['month'];
131            $this->arrForm['day'] = $arrHolidayData[0]['day'];
132            // POSTデータを引き継ぐ
133            $this->tpl_holiday_id = $post['holiday_id'];
134        break;
135        case 'down':
136            $objDb->sfRankDown("dtb_holiday", "holiday_id", $post['holiday_id']);
137            // 再表示
138            $this->objDisplay->reload();
139            break;
140        case 'up':
141            $objDb->sfRankUp("dtb_holiday", "holiday_id", $post['holiday_id']);
142            // 再表示
143            $this->objDisplay->reload();
144            break;
145        default:
146            break;
147        }
148
149        $this->arrHoliday = $this->lfGetHolidayList();
150        // POSTデータを引き継ぐ
151        $this->tpl_holiday_id = $holiday_id;
152    }
153
154    /**
155     * デストラクタ.
156     *
157     * @return void
158     */
159    function destroy() {
160        parent::destroy();
161    }
162
163    function lfGetHolidayDataByHolidayID($holiday_id) {
164        $objQuery =& SC_Query_Ex::getSingletonInstance();
165
166        $where = "holiday_id = ?";
167        return $objQuery->select("title, month, day", "dtb_holiday", $where, array($holiday_id));
168    }
169
170    function lfGetHolidayList() {
171        $objQuery =& SC_Query_Ex::getSingletonInstance();
172
173        $where = "del_flg <> 1";
174        $objQuery->setOrder("rank DESC");
175        return $objQuery->select("holiday_id, title, month, day", "dtb_holiday", $where);
176    }
177
178    /* DBへの挿入 */
179    function lfInsertClass($arrData, $member_id) {
180        $objQuery =& SC_Query_Ex::getSingletonInstance();
181        // INSERTする値を作成する。
182        $sqlval['title'] = $arrData['title'];
183        $sqlval['month'] = $arrData['month'];
184        $sqlval['day'] = $arrData['day'];
185        $sqlval['creator_id'] = $member_id;
186        $sqlval['rank'] = $objQuery->max('rank', "dtb_holiday") + 1;
187        $sqlval['update_date'] = 'CURRENT_TIMESTAMP';
188        $sqlval['create_date'] = 'CURRENT_TIMESTAMP';
189        // INSERTの実行
190        $sqlval['holiday_id'] = $objQuery->nextVal('dtb_holiday_holiday_id');
191        $ret = $objQuery->insert("dtb_holiday", $sqlval);
192        return $ret;
193    }
194
195    /* DBへの更新 */
196    function lfUpdateClass($arrData) {
197        $objQuery =& SC_Query_Ex::getSingletonInstance();
198        // UPDATEする値を作成する。
199        $sqlval['title'] = $arrData['title'];
200        $sqlval['month'] = $arrData['month'];
201        $sqlval['day'] = $arrData['day'];
202        $sqlval['update_date'] = 'CURRENT_TIMESTAMP';
203        $where = "holiday_id = ?";
204        // UPDATEの実行
205        $ret = $objQuery->update("dtb_holiday", $sqlval, $where, array($arrData['holiday_id']));
206        return $ret;
207    }
208
209    function lfInitParam($mode, &$objFormParam)
210    {
211        switch ($mode) {
212            case 'edit':
213                $objFormParam->addParam('タイトル', 'title', STEXT_LEN, 'KVa', array("EXIST_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK"));
214                $objFormParam->addParam('月', 'month', INT_LEN, 'n', array("SELECT_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK"));
215                $objFormParam->addParam('日', 'day', INT_LEN, 'n', array("SELECT_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK"));
216                // breakしない
217            case 'delete':
218            case 'pre_edit':
219            case 'down':
220            case 'up':
221                $objFormParam->addParam('定休日ID', 'holiday_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
222                break;
223            default:
224                break;
225        }
226    }
227
228    /**
229     * 入力エラーチェック
230     *
231     * @param string $mode
232     * @return array
233     */
234    function lfCheckError($mode, &$objFormParam) {
235        $objFormParam->convParam();
236        $arrErr = $objFormParam->checkError();
237        $post = $objFormParam->getHashArray();
238
239        if(!isset($arrErr['date'])) {
240            $objQuery =& SC_Query_Ex::getSingletonInstance();
241            $where = "del_flg = 0 AND month = ? AND day = ?";
242            $arrval = array($post['month'], $post['day']);
243            if (!empty($post['holiday_id'])) {
244                $where .= " AND holiday_id <> ?";
245                $arrval[] = $post['holiday_id'];
246            }
247            $arrRet = $objQuery->select("count(holiday_id) as count", "dtb_holiday", $where, $arrval);
248
249            // 編集中のレコード以外に同じ日付が存在する場合
250            if ($arrRet[0]['count'] > 0) {
251                $arrErr['date'] = "※ 既に同じ日付の登録が存在します。<br>";
252            }
253        }
254        return $arrErr;
255    }
256}
Note: See TracBrowser for help on using the repository browser.