source: branches/version-2_12-dev/data/class/pages/frontparts/bloc/LC_Page_FrontParts_Bloc_Calendar.php @ 21738

Revision 21738, 5.6 KB checked in by habu, 12 years ago (diff)

#1746 カレンダーに本日がいつであるかが、わかるマークの機能を追加して欲しい

  • 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
25define('CALENDAR_ROOT', DATA_REALDIR.'module/Calendar'.DIRECTORY_SEPARATOR);
26require_once CLASS_REALDIR . 'pages/frontparts/bloc/LC_Page_FrontParts_Bloc.php';
27
28/**
29 * Calendar のページクラス.
30 *
31 * @package Page
32 * @author LOCKON CO.,LTD.
33 * @version $ $
34 */
35class LC_Page_FrontParts_Bloc_Calendar extends LC_Page_FrontParts_Bloc {
36
37    // }}}
38    // {{{ functions
39
40    /**
41     * Page を初期化する.
42     *
43     * @return void
44     */
45    function init() {
46        parent::init();
47    }
48
49    /**
50     * Page のプロセス.
51     *
52     * @return void
53     */
54    function process() {
55        $this->action();
56        $this->sendResponse();
57    }
58
59    /**
60     * Page のアクション.
61     *
62     * @return void
63     */
64    function action() {
65        // フックポイント.
66        $objPlugin = SC_Helper_Plugin_Ex::getSingletonInstance($this->plugin_activate_flg);
67        $objPlugin->doAction('LC_Page_FrontParts_Bloc_Calafterar_action_before', array($this));
68
69        // 休日取得取得
70        $this->arrHoliday = $this->lfGetHoliday();
71        // 定休日取得取得
72        $this->arrRegularHoliday = $this->lfGetRegularHoliday();
73        // カレンダーデータ取得
74        $this->arrCalendar = $this->lfGetCalendar(2);
75
76        // フックポイント.
77        $objPlugin = SC_Helper_Plugin_Ex::getSingletonInstance($this->plugin_activate_flg);
78        $objPlugin->doAction('LC_Page_FrontParts_Bloc_Calafterar_action_after', array($this));
79    }
80
81    /**
82     * デストラクタ.
83     *
84     * @return void
85     */
86    function destroy() {
87        parent::destroy();
88    }
89
90    /**
91     * カレンダー情報取得.
92     *
93     * @param integer $disp_month 表示する月数
94     * @return array $arrCalendar カレンダー情報の配列を返す
95     */
96    function lfGetCalendar($disp_month = 1) {
97
98        $today = date("Y/m/d");
99        for ($j = 0; $j <= $disp_month-1; ++$j) {
100            $year = date('Y');
101            $month = date('n') + $j;
102            if ($month > 12) {
103                $month = $month%12;
104                $year = $year + $month%12;
105            }
106
107            $objMonth = new Calendar_Month_Weekdays($year, $month, 0);
108            $objMonth->build();
109            $i = 0;
110            while ($objDay = $objMonth->fetch()) {
111                if ($month == $objDay->month) {
112                    $arrCalendar[$j][$i]['in_month'] = true;
113                } else {
114                    $arrCalendar[$j][$i]['in_month'] = false;
115                }
116                $arrCalendar[$j][$i]['first'] = $objDay->first;
117                $arrCalendar[$j][$i]['last'] = $objDay->last;
118                $arrCalendar[$j][$i]['empty'] = $objDay->empty;
119                $arrCalendar[$j][$i]['year'] = $year;
120                $arrCalendar[$j][$i]['month'] = $month;
121                $arrCalendar[$j][$i]['day'] = $objDay->day;
122                if ($this->lfCheckHoliday($year, $month, $objDay->day)) {
123                    $arrCalendar[$j][$i]['holiday'] = true;
124                } else {
125                    $arrCalendar[$j][$i]['holiday'] = false;
126                }
127
128                if ($today === sprintf("%04d/%02d/%02d", $year, $month, $objDay->day)) {
129                    $arrCalendar[$j][$i]['today'] = true;
130                }
131
132                ++$i;
133            }
134        }
135
136        return $arrCalendar;
137    }
138
139    /**
140     * 休日取得.
141     *
142     * @return array $arrHoliday 休日情報の配列を返す
143     */
144    function lfGetHoliday() {
145        $objQuery = SC_Query_Ex::getSingletonInstance();
146        $objQuery->setOrder('rank DESC');
147
148        $where = 'del_flg <> 1';
149        $arrRet = $objQuery->select('month, day', 'dtb_holiday', $where);
150        foreach ($arrRet AS $key=>$val) {
151            $arrHoliday[$val['month']][] = $val['day'];
152        }
153        return $arrHoliday;
154    }
155
156    /**
157     * 定休日取得.
158     *
159     * @return array $arrRegularHoliday 定休日情報の配列を返す
160     */
161    function lfGetRegularHoliday() {
162        $arrInfo = SC_Helper_DB_Ex::sfGetBasisData();
163        $arrRegularHoliday = explode('|', $arrInfo['regular_holiday_ids']);
164        return $arrRegularHoliday;
165    }
166
167    /**
168     * 休日チェック取得.
169     *
170     * @param integer $year 年
171     * @param integer $month 月
172     * @param integer $day 日
173     * @return boolean 休日の場合trueを返す
174     */
175    function lfCheckHoliday($year, $month, $day) {
176        if (!empty($this->arrHoliday[$month])) {
177            if (in_array($day, $this->arrHoliday[$month])) {
178                return true;
179            }
180        }
181        if (!empty($this->arrRegularHoliday)) {
182            $day = date('w', mktime(0,0,0 ,$month, $day, $year));
183            if (in_array($day, $this->arrRegularHoliday)) {
184                return true;
185            }
186        }
187        return false;
188    }
189
190}
Note: See TracBrowser for help on using the repository browser.