protected function generateCalendar(sfWebRequest $request) { $this->setTemplate('index'); $old_error_level = error_reporting(); error_reporting($old_error_level & ~(E_STRICT | E_DEPRECATED)); include_once 'Calendar/Month/Weekdays.php'; $this->year = (int) $request->getParameter('year', date('Y')); $this->month = (int) $request->getParameter('month', date('n')); $this->add_schedule = $this->year < date('Y') || $this->year > date('Y') + 1 ? false : true; $first_day = sprintf('%04d-%02d-01', $this->year, $this->month); $end_day = sprintf('%04d-%02d-%02d', $this->year, $this->month, date('t', strtotime($first_day))); if ($this->is_community) { if ('all' === $this->calendar_show_flag || 'only_community_event' === $this->calendar_show_flag) { $event_list = opCalendarPluginExtension::getMyCommunityEventByStartDayToEndDayInCommunity($this->community, $first_day, $end_day); } } else { $birth_list = $this->isSelf ? opCalendarPluginExtension::getScheduleBirthMemberByMonths(array($this->month)) : array(); $event_list = $this->isSelf ? opCalendarPluginExtension::getMyCommunityEventByStartDayToEndDay($first_day, $end_day) : array(); } $Month = new Calendar_Month_Weekdays($this->year, $this->month, 1); $Month->build(); $this->calendar = array(); $row = 0; $col = 0; $this->dayofweek = array('class' => array('mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun'), 'item' => array('Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun')); while ($Day = $Month->fetch()) { if ($Day->isFirst()) { $row++; $col = 0; } $item = array('dayofweek_class_name' => $this->dayofweek['class'][$col], 'dayofweek_item_name' => $this->dayofweek['item'][$col]); $scheduleTable = Doctrine::getTable('Schedule'); if ($Day->isEmpty()) { $this->calendar[$row][$col++] = $item; } else { $day = $Day->thisDay(); $month_day = sprintf('%02d-%02d', $this->month, $day); $year_month_day = sprintf('%04d-%s', $this->year, $month_day); $is_today = (int) date('Y') === $this->year && (int) date('n') === $this->month && (int) date('d') === $day; $schedules = array(); if ($this->is_community) { if ('all' === $this->calendar_show_flag || 'only_member_schedule' === $this->calendar_show_flag) { $schedules = $scheduleTable->getScheduleByThisDayAndMemberInCommunity($this->community, $this->year, $this->month, $day); } } else { $schedules = $scheduleTable->getScheduleByThisDayAndMember($this->year, $this->month, $day, $this->member); } $item += array('day' => $day, 'today' => $is_today, 'births' => isset($birth_list[$month_day]) ? $birth_list[$month_day] : array(), 'events' => isset($event_list[$year_month_day]) ? $event_list[$year_month_day] : array(), 'schedules' => $schedules, 'holidays' => Doctrine::getTable('Holiday')->getByYearAndMonthAndDay($this->year, $this->month, $day)); $this->calendar[$row][$col++] = $item; } } $this->ym = array('year_disp' => $this->year, 'month_disp' => $this->month, 'year_prev' => date('Y', $Month->prevMonth(true)), 'month_prev' => date('n', $Month->prevMonth(true)), 'year_next' => date('Y', $Month->nextMonth(true)), 'month_next' => date('n', $Month->nextMonth(true))); error_reporting($old_error_level); }
public function setup() { parent::setup(); $this->generateDateTime(); $user = sfContext::getInstance()->getUser(); $members = opCalendarPluginExtension::getAllowedFriendMember($user->getMember()); $this->setWidget('title', new sfWidgetFormInput()); $cul = $user->getCulture(); $dateItems = array('culture' => $cul, 'month_format' => 'number', 'years' => $this->dateTime['years']); if ('ja_JP' === $cul) { $dateItems['format'] = '%year%年%month%月%day%日'; } $dateObj = new sfWidgetFormI18nDate($dateItems); $this->setWidget('start_date', $dateObj); $this->setWidget('end_date', $dateObj); $timeItems = array('with_seconds' => false, 'minutes' => $this->dateTime['minutes']); if ('ja_JP' === $cul) { $timeItems['format'] = '%hour%時%minute%分'; } $timeObj = new sfWidgetFormTime($timeItems); $this->setWidget('start_time', $timeObj); $this->setWidget('end_time', $timeObj); $this->setWidget('public_flag', new sfWidgetFormChoice(array('choices' => Doctrine::getTable('Schedule')->getPublicFlags(), 'expanded' => true))); $this->setWidget('schedule_member', new sfWidgetFormSelectCheckbox(array('choices' => $members))); $this->setDefault('schedule_member', $this->getDefaultSheduleMembers()); $this->validatorSchema['title'] = new opValidatorString(array('trim' => true)); $this->validatorSchema['public_flag'] = new sfValidatorChoice(array('choices' => array_keys(Doctrine::getTable('Schedule')->getPublicFlags()))); $this->validatorSchema['schedule_member'] = new sfValidatorChoice(array('choices' => array_keys($members), 'multiple' => true)); $this->mergePostValidator(new sfValidatorCallback(array('callback' => array($this, 'validateEndDate')), array('invalid' => 'You can not set the end date before start date'))); $this->mergePostValidator(new sfValidatorCallback(array('callback' => array($this, 'validateResourceLock')), array('invalid' => 'There is not the resource that you can use'))); $this->mergePostValidator(new sfValidatorCallback(array('callback' => array($this, 'validateClosedSchedule')), array('invalid' => 'A closed schedule cannot set a resource'))); $this->useFields(array('title', 'start_date', 'start_time', 'end_date', 'end_time', 'body', 'public_flag', 'schedule_member')); if (!$this->isNew()) { $scheduleResourceLocks = $this->getObject()->ScheduleResourceLocks; } $count = Doctrine_Core::getTable('ScheduleResource')->createQuery()->count(); if (!$count) { sfConfig::set('app_schedule_resource_list_max', 0); } $max = (int) sfConfig::get('app_schedule_resource_list_max', 5); for ($i = 1; $i <= $max; $i++) { $key = 'schedule_resource_lock_' . $i; if (isset($scheduleResourceLocks[$i - 1])) { $scheduleResourceLock = $scheduleResourceLocks[$i - 1]; } else { $scheduleResourceLock = new ScheduleResourceLock(); $scheduleResourceLock->setSchedule($this->getObject()); } $scheduleResourceLockForm = new ScheduleResourceLockForm($scheduleResourceLock); $scheduleResourceLockForm->getWidgetSchema()->setFormFormatterName('list'); $this->embedForm($key, $scheduleResourceLockForm, '<ul id="schedule_resource_lock_' . $key . '">%content%</ul>'); } }
private function getCalendar($w = 0, $community = null) { $old_error_level = error_reporting(); error_reporting($old_error_level & ~(E_STRICT | E_DEPRECATED)); include_once 'Calendar/Week.php'; $time = strtotime($w . ' week'); $Week = new Calendar_Week(date('Y', $time), date('m', $time), date('d', $time), 1); $Week->build(); $dayofweek = array('class' => array('mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun'), 'item' => array('Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun')); $calendar = array(); $i = 0; while ($Day = $Week->fetch()) { $y = $Day->thisYear(); $m = $Day->thisMonth(); $d = $Day->thisDay(); $item = array('year' => $y, 'month' => $m, 'day' => $d, 'today' => 0 === $w && (int) date('d') === $d, 'dayofweek_class_name' => $dayofweek['class'][$i], 'dayofweek_item_name' => $dayofweek['item'][$i], 'holidays' => Doctrine::getTable('Holiday')->getByYearAndMonthAndDay($y, $m, $d)); if (null === $community) { // member home or profile home calendar. $item['births'] = $this->isSelf ? opCalendarPluginExtension::getScheduleBirthMemberByTargetDay($m, $d) : array(); $item['events'] = $this->isSelf ? opCalendarPluginExtension::getMyCommunityEventByTargetDay($y, $m, $d) : array(); $item['schedules'] = Doctrine::getTable('Schedule')->getScheduleByThisDayAndMember($y, $m, $d, $this->member); } else { // community home calendar. $item['events'] = array(); $item['schedules'] = array(); if ('all' === $this->calendar_show_flag || 'only_community_event' === $this->calendar_show_flag) { // only open to all sns member schedule. $item['events'] = opCalendarPluginExtension::getMyCommunityEventByTargetDayInCommunity($community, $y, $m, $d); } if ('all' === $this->calendar_show_flag || 'only_member_schedule' === $this->calendar_show_flag) { // only open to all sns member schedule. $item['schedules'] = Doctrine::getTable('Schedule')->getScheduleByThisDayAndMemberInCommunity($community, $y, $m, $d, $this->member); } } $calendar[$i++] = $item; } error_reporting($old_error_level); return $calendar; }
private static function getMyId() { if (is_null(self::$myId)) { self::$myId = sfContext::getInstance()->getUser()->getMemberId(); } return self::$myId; }