source: branches/version-2_13_0/data/class/helper/SC_Helper_Holiday.php @ 23126

Revision 23126, 4.8 KB checked in by m_uehara, 11 years ago (diff)

#2348 r23116 - r23125 をマージ

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/**
25 * 休日を管理するヘルパークラス.
26 *
27 * @package Helper
28 * @author pineray
29 * @version $Id:$
30 */
31class SC_Helper_Holiday
32{
33    /**
34     * 休日の情報を取得.
35     *
36     * @param  integer $holiday_id  休日ID
37     * @param  boolean $has_deleted 削除された休日も含む場合 true; 初期値 false
38     * @return array
39     */
40    public function get($holiday_id, $has_deleted = false)
41    {
42        $objQuery =& SC_Query_Ex::getSingletonInstance();
43        $where = 'holiday_id = ?';
44        if (!$has_deleted) {
45            $where .= ' AND del_flg = 0';
46        }
47        $arrRet = $objQuery->select('*', 'dtb_holiday', $where, array($holiday_id));
48
49        return $arrRet[0];
50    }
51
52    /**
53     * 休日一覧の取得.
54     *
55     * @param  boolean $has_deleted 削除された休日も含む場合 true; 初期値 false
56     * @return array
57     */
58    public function getList($has_deleted = false)
59    {
60        $objQuery =& SC_Query_Ex::getSingletonInstance();
61        $col = 'holiday_id, title, month, day';
62        $where = '';
63        if (!$has_deleted) {
64            $where .= 'del_flg = 0';
65        }
66        $table = 'dtb_holiday';
67        $objQuery->setOrder('rank DESC');
68        $arrRet = $objQuery->select($col, $table, $where);
69
70        return $arrRet;
71    }
72
73    /**
74     * 休日の登録.
75     *
76     * @param  array    $sqlval
77     * @return multiple 登録成功:休日ID, 失敗:FALSE
78     */
79    public function save($sqlval)
80    {
81        $objQuery =& SC_Query_Ex::getSingletonInstance();
82
83        $holiday_id = $sqlval['holiday_id'];
84        $sqlval['update_date'] = 'CURRENT_TIMESTAMP';
85        // 新規登録
86        if ($holiday_id == '') {
87            // INSERTの実行
88            $sqlval['rank'] = $objQuery->max('rank', 'dtb_holiday') + 1;
89            $sqlval['create_date'] = 'CURRENT_TIMESTAMP';
90            $sqlval['holiday_id'] = $objQuery->nextVal('dtb_holiday_holiday_id');
91            $ret = $objQuery->insert('dtb_holiday', $sqlval);
92        // 既存編集
93        } else {
94            unset($sqlval['creator_id']);
95            unset($sqlval['create_date']);
96            $where = 'holiday_id = ?';
97            $ret = $objQuery->update('dtb_holiday', $sqlval, $where, array($holiday_id));
98        }
99
100        return ($ret) ? $sqlval['holiday_id'] : FALSE;
101    }
102
103    /**
104     * 休日の削除.
105     *
106     * @param  integer $holiday_id 休日ID
107     * @return void
108     */
109    public function delete($holiday_id)
110    {
111        $objDb = new SC_Helper_DB_Ex();
112        // ランク付きレコードの削除
113        $objDb->sfDeleteRankRecord('dtb_holiday', 'holiday_id', $holiday_id, '', true);
114    }
115
116    /**
117     * 休日の表示順をひとつ上げる.
118     *
119     * @param  integer $holiday_id 休日ID
120     * @return void
121     */
122    public function rankUp($holiday_id)
123    {
124        $objDb = new SC_Helper_DB_Ex();
125        $objDb->sfRankUp('dtb_holiday', 'holiday_id', $holiday_id);
126    }
127
128    /**
129     * 休日の表示順をひとつ下げる.
130     *
131     * @param  integer $holiday_id 休日ID
132     * @return void
133     */
134    public function rankDown($holiday_id)
135    {
136        $objDb = new SC_Helper_DB_Ex();
137        $objDb->sfRankDown('dtb_holiday', 'holiday_id', $holiday_id);
138    }
139
140    /**
141     * 同じ日付の休日が存在するか確認.
142     *
143     * @param  integer $month
144     * @param  integer $day
145     * @param  integer $holiday_id
146     * @return boolean 同日付の休日が存在:true
147     */
148    public function isDateExist($month, $day, $holiday_id = NULL)
149    {
150        $objQuery =& SC_Query_Ex::getSingletonInstance();
151        $where = 'del_flg = 0 AND month = ? AND day = ?';
152        $arrVal = array($month, $day);
153        if (!SC_Utils_Ex::isBlank($holiday_id)) {
154            $where .= ' AND holiday_id <> ?';
155            $arrVal[] = $holiday_id;
156        }
157        $arrRet = $objQuery->select('holiday_id, title', 'dtb_holiday', $where, $arrVal);
158
159        return !SC_Utils_Ex::isBlank($arrRet);
160    }
161}
Note: See TracBrowser for help on using the repository browser.