예제 #1
0
 /**
  * Creates an array for an month.
  *
  * @param array $args Date.
  *
  * @return array 2 dimensional array.
  * e.g.: array[0][YYYY-MM-DD] = NULL;
  *
  */
 function arrayForMonthView($args)
 {
     if (!isset($args['month']) || !isset($args['year'])) {
         return LogUtil::registerError(_MODARGSERROR);
     }
     if (!ModUtil::apiFunc('TimeIt', 'user', 'checkDate', $args)) {
         return LogUtil::registerError(_MODARGSERROR . _TIMEIT_INVALIDDATE);
     }
     $array = array();
     $year = $args['year'];
     $month = $args['month'];
     $firstDayOfWeek = isset($args['firstDayOfWeek']) && (int) $args['firstDayOfWeek'] >= 0 && (int) $args['firstDayOfWeek'] <= 6 ? (int) $args['firstDayOfWeek'] : (int) ModUtil::getVar('TimeIt', 'firstWeekDay');
     // 0 = Sun 1 = Mo ...
     // calc first day of week in the first week of the month
     $timestampFirstDayOfMonth = gmmktime(0, 0, 0, (int) $month, 1, (int) $year);
     $day1 = (gmdate('w', $timestampFirstDayOfMonth) - $firstDayOfWeek) % 7;
     if ($day1 < 0) {
         $day1 += 7;
     }
     $timestamp = strtotime('-' . $day1 . ' days', $timestampFirstDayOfMonth);
     $daysInMonth = DateUtil::getDaysInMonth((int) $month, (int) $year);
     // create array
     $lastDayInMonthFound = false;
     for ($week = 0; $week < 6; $week++) {
         for ($day = 1; $day <= 7; $day++) {
             $dayNum = date('j', $timestamp);
             //$array[$week][DateUtil::getDatetime($timestamp, DATEONLYFORMAT_FIXED)] = NULL;
             $array[$week][gmdate('Y-m-d', $timestamp)] = null;
             if ($dayNum == $daysInMonth && $week > 0) {
                 $lastDayInMonthFound = true;
             }
             $timestamp += 86400;
         }
         if ($lastDayInMonthFound) {
             break;
         }
     }
     return $array;
 }
예제 #2
0
 /**
  * Displays all available events.
  *
  * @return string HTML Code
  */
 public function view()
 {
     // check object type
     $objectType = FormUtil::getPassedValue('ot', 'event', 'GET');
     $this->throwNotFoundUnless(in_array($objectType, TimeIt_Util::getObjectTypes('view')), $this->__f('Unkown object type %s.', DataUtil::formatForDisplay($objectType)));
     // load filter
     $filter = TimeIt_Filter_Container::getFilterFormGETPOST($objectType);
     $this->view->assign('modvars', ModUtil::getVar('TimeIt'));
     // vars
     $tpl = null;
     $theme = null;
     $domain = $this->serviceManager->getService('timeit.manager.' . $objectType);
     // load the data
     if ($objectType == 'event') {
         $calendarId = (int) FormUtil::getPassedValue('cid', ModUtil::getVar('TimeIt', 'defaultCalendar'), 'GETPOST');
         $calendar = $this->serviceManager->getService('timeit.manager.calendar')->getObject($calendarId);
         $this->throwNotFoundIf(empty($calendar), $this->__f('Calendar [%s] not found.', $calendarId));
         $year = (int) FormUtil::getPassedValue('year', date("Y"), 'GETPOST');
         $month = (int) FormUtil::getPassedValue('month', date("n"), 'GETPOST');
         $day = (int) FormUtil::getPassedValue('day', date("j"), 'GETPOST');
         $tpl = FormUtil::getPassedValue('viewType', FormUtil::getPassedValue('viewtype', $calendar['config']['defaultView'], 'GETPOST'), 'GETPOST');
         $firstDayOfWeek = (int) FormUtil::getPassedValue('firstDayOfWeek', -1, 'GETPOST');
         $theme = FormUtil::getPassedValue('template', $calendar['config']['defaultTemplate'], 'GETPOST');
         // backward compatibility
         if ($theme == 'default') {
             $theme = 'table';
         }
         // check for a valid $tpl
         if ($tpl != 'year' && $tpl != 'month' && $tpl != 'week' && $tpl != 'day') {
             $tpl = $calendar['config']['defaultView'];
         }
         $tpl = 'month';
         $theme = 'table';
         $this->view->assign('template', $theme);
         $this->view->assign('viewed_day', $day);
         $this->view->assign('viewed_month', $month);
         $this->view->assign('viewed_year', $year);
         $this->view->assign('viewType', $tpl);
         $this->view->assign('calendar', $calendar);
         $this->view->assign('viewed_date', DateUtil::getDatetime(mktime(0, 0, 0, $month, $day, $year), DATEONLYFORMAT_FIXED));
         $this->view->assign('date_today', DateUtil::getDatetime(null, DATEONLYFORMAT_FIXED));
         $this->view->assign('month_startDate', DateUtil::getDatetime(mktime(0, 0, 0, $month, 1, $year), DATEONLYFORMAT_FIXED));
         $this->view->assign('month_endDate', DateUtil::getDatetime(mktime(0, 0, 0, $month, DateUtil::getDaysInMonth($month, $year), $year), DATEONLYFORMAT_FIXED));
         $this->view->assign('filter_obj_url', $filter->toURL());
         $this->view->assign('firstDayOfWeek', $firstDayOfWeek);
         $this->view->assign('selectedCats', array());
         $categories = CategoryRegistryUtil::getRegisteredModuleCategories('TimeIt', 'TimeIt_events');
         foreach ($categories as $property => $cid) {
             $cat = CategoryUtil::getCategoryByID($cid);
             if (isset($cat['__ATTRIBUTES__']['calendarid']) && !empty($cat['__ATTRIBUTES__']['calendarid'])) {
                 if ($cat['__ATTRIBUTES__']['calendarid'] != $calendar['id']) {
                     unset($categories[$property]);
                 }
             }
         }
         $this->view->assign('categories', $categories);
         // load event data
         switch ($tpl) {
             case 'year':
                 $objectData = $domain->getYearEvents($year, $calendar['id'], $firstDayOfWeek);
                 break;
             case 'month':
                 $objectData = $domain->getMonthEvents($year, $month, $day, $calendar['id'], $firstDayOfWeek, $filter);
                 break;
             case 'week':
                 $objectData = $domain->getWeekEvents($year, $month, $day, $calendar['id'], $filter);
                 break;
             case 'day':
                 $objectData = $domain->getDayEvents($year, $month, $day, $calendar['id'], $filter);
                 break;
         }
     }
     // assign the data
     $this->view->assign('objectArray', $objectData);
     // render the html
     return $this->_renderTemplate($this->view, $objectType, 'user', 'view', $theme, $tpl, 'table');
 }