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

Revision 22097, 4.9 KB checked in by Seasoft, 11 years ago (diff)

#1964 (LC_Page_FrontParts_Bloc_Calendar#lfGetCalendar 月の算出に誤り)
#1669 (変数の初期化漏れ)
#1905 (typo修正・ソース整形・ソースコメントの改善)
#1684 (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-2012 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_EX_REALDIR . 'page_extends/frontparts/bloc/LC_Page_FrontParts_Bloc_Ex.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_Ex {
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        // 休日取得取得
67        $this->arrHoliday = $this->lfGetHoliday();
68        // 定休日取得取得
69        $this->arrRegularHoliday = $this->lfGetRegularHoliday();
70        // カレンダーデータ取得
71        $this->arrCalendar = $this->lfGetCalendar(2);
72
73
74    }
75
76    /**
77     * デストラクタ.
78     *
79     * @return void
80     */
81    function destroy() {
82        parent::destroy();
83    }
84
85    /**
86     * カレンダー情報取得.
87     *
88     * @param integer $disp_month 表示する月数
89     * @return array カレンダー情報の配列を返す
90     */
91    function lfGetCalendar($disp_month = 1) {
92        $arrCalendar = array();
93        $today = date('Y/m/d');
94
95        for ($j = 0; $j <= $disp_month - 1; $j++) {
96            $time = mktime(0, 0, 0, date('n') + $j, 1);
97            $year = date('Y', $time);
98            $month = date('n', $time);
99
100            $objMonth = new Calendar_Month_Weekdays($year, $month, 0);
101            $objMonth->build();
102            $i = 0;
103            while ($objDay = $objMonth->fetch()) {
104                $arrCalendar[$j][$i]['in_month']    = $month == $objDay->month;
105                $arrCalendar[$j][$i]['first']       = $objDay->first;
106                $arrCalendar[$j][$i]['last']        = $objDay->last;
107                $arrCalendar[$j][$i]['empty']       = $objDay->empty;
108                $arrCalendar[$j][$i]['year']        = $year;
109                $arrCalendar[$j][$i]['month']       = $month;
110                $arrCalendar[$j][$i]['day']         = $objDay->day;
111                $arrCalendar[$j][$i]['holiday']     = $this->lfCheckHoliday($year, $month, $objDay->day);
112                $arrCalendar[$j][$i]['today']       = $today === sprintf('%04d/%02d/%02d', $year, $month, $objDay->day);
113
114                $i++;
115            }
116        }
117
118        return $arrCalendar;
119    }
120
121    /**
122     * 休日取得.
123     *
124     * @return array $arrHoliday 休日情報の配列を返す
125     */
126    function lfGetHoliday() {
127        $objQuery = SC_Query_Ex::getSingletonInstance();
128        $objQuery->setOrder('rank DESC');
129
130        $where = 'del_flg <> 1';
131        $arrRet = $objQuery->select('month, day', 'dtb_holiday', $where);
132        foreach ($arrRet AS $key=>$val) {
133            $arrHoliday[$val['month']][] = $val['day'];
134        }
135        return $arrHoliday;
136    }
137
138    /**
139     * 定休日取得.
140     *
141     * @return array $arrRegularHoliday 定休日情報の配列を返す
142     */
143    function lfGetRegularHoliday() {
144        $arrInfo = SC_Helper_DB_Ex::sfGetBasisData();
145        $arrRegularHoliday = explode('|', $arrInfo['regular_holiday_ids']);
146        return $arrRegularHoliday;
147    }
148
149    /**
150     * 休日チェック取得.
151     *
152     * @param integer $year 年
153     * @param integer $month 月
154     * @param integer $day 日
155     * @return boolean 休日の場合trueを返す
156     */
157    function lfCheckHoliday($year, $month, $day) {
158        if (!empty($this->arrHoliday[$month])) {
159            if (in_array($day, $this->arrHoliday[$month])) {
160                return true;
161            }
162        }
163        if (!empty($this->arrRegularHoliday)) {
164            $day = date('w', mktime(0,0,0 ,$month, $day, $year));
165            if (in_array($day, $this->arrRegularHoliday)) {
166                return true;
167            }
168        }
169        return false;
170    }
171
172}
Note: See TracBrowser for help on using the repository browser.