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

Revision 21693, 9.9 KB checked in by h_yoshimoto, 12 years ago (diff)

#1692 フックポイント名を変更

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