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

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