Esempio n. 1
0
 function repeatSummary()
 {
     $cfg = JEVConfig::getInstance();
     // i.e. 1 = follow english word order by default
     $grammar = intval(JText::_('JEV_REPEAT_GRAMMAR'));
     // if starttime and end time the same then show no times!
     if ($this->start_date == $this->stop_date) {
         if ($this->start_time != $this->stop_time && !$this->alldayevent()) {
             echo $this->start_date . ', ' . $this->start_time . ' - ' . $this->stop_time_midnightFix;
         } else {
             echo $this->start_date;
         }
     } else {
         // recurring events should have time related to recurrance not range of dates
         if ($this->start_time != $this->stop_time && !($this->reccurtype() > 0)) {
             echo JText::_('JEV_FROM') . '&nbsp;' . $this->start_date . '&nbsp;-&nbsp; ' . $this->start_time . '<br />' . JText::_('JEV_TO') . '&nbsp;' . $this->stop_date . '&nbsp;-&nbsp;' . $this->stop_time_midnightFix . '<br/>';
         } else {
             echo JText::_('JEV_FROM') . '&nbsp;' . $this->start_date . '<br />' . JText::_('JEV_TO') . '&nbsp;' . $this->stop_date . '<br/>';
         }
     }
     if ($this->reccurtype() > 0) {
         switch ($this->reccurtype()) {
             case '1':
                 $reccur = JText::_('JEV_REP_WEEK');
                 break;
             case '2':
                 $reccur = JText::_('JEV_REP_WEEK');
                 break;
             case '3':
                 $reccur = JText::_('JEV_REP_MONTH');
                 break;
             case '4':
                 $reccur = JText::_('JEV_REP_MONTH');
                 break;
             case '5':
                 $reccur = JText::_('JEV_REP_YEAR');
                 break;
         }
         if ($this->reccurday() >= 0 || ($this->reccurtype() == 1 || $this->reccurtype() == 2)) {
             $timeString = "";
             if ($this->start_time != $this->stop_time) {
                 $timeString = $this->start_time . "&nbsp;-&nbsp;" . $this->stop_time_midnightFix . "&nbsp;";
             }
             echo $timeString;
             if (intval($this->reccurday()) < 0) {
                 $event_start_date = JevDate::strtotime($this->startDate());
                 $reccurday = intval(date('w', $event_start_date));
             } else {
                 $reccurday = $this->reccurday();
             }
             if ($this->reccurtype() == 1) {
                 $dayname = JEventsHTML::getDayName($reccurday);
                 echo $dayname . '&nbsp;' . JText::_('JEV_EACHOF') . '&nbsp;' . $reccur;
             } else {
                 if ($this->reccurtype() == 2) {
                     $each = JText::_('JEV_EACH') . '&nbsp;';
                     if ($grammar == 1) {
                         $each = strtolower($each);
                     }
                     $daystring = "";
                     if (JString::strlen($this->reccurweeks()) == 0) {
                         $days = explode("|", $this->reccurweekdays());
                         for ($d = 0; $d < count($days); $d++) {
                             $daystring .= JEventsHTML::getDayName($days[$d]);
                             $daystring .= ($d == 0 ? "," : "") . "&nbsp;";
                         }
                         $weekstring = "";
                     } else {
                         $days = explode("|", $this->reccurweekdays());
                         for ($d = 0; $d < count($days); $d++) {
                             $daystring .= JEventsHTML::getDayName($days[$d]);
                             $daystring .= ($d == 0 ? "," : "") . "&nbsp;";
                         }
                         $weekstring = $this->reccurweeks() == 'pair' ? JText::_('JEV_REP_WEEKPAIR') : ($this->reccurweeks() == 'impair' ? JText::_('JEV_REP_WEEKIMPAIR') : "");
                         if ($weekstring == "") {
                             switch ($grammar) {
                                 case 1:
                                     $weekstring = "- " . JText::_('JEV_REP_WEEK') . " ";
                                     $weekstring .= str_replace("|", ", ", $this->reccurweeks()) . " ";
                                     $weekstring .= strtolower(JText::_('JEV_EACHMONTH'));
                                     break;
                                 default:
                                     $weekstring = str_replace("|", ", ", $this->reccurweeks()) . " ";
                                     $weekstring .= $reccur;
                                     $weekstring .= JText::_('JEV_EACHMONTH');
                                     break;
                             }
                         }
                     }
                     $firstword = true;
                     switch ($grammar) {
                         case 1:
                             echo $daystring . $weekstring;
                             break;
                         default:
                             echo $each . $daystring . $weekstring;
                             break;
                     }
                 } else {
                     echo JText::_('JEV_EACH') . '&nbsp;' . $reccur;
                 }
             }
         } else {
             echo JText::_('JEV_EACH') . '&nbsp;' . $reccur;
         }
     } else {
         if ($this->start_date != $this->stop_date) {
             echo JText::_('JEV_ALLDAYS');
         }
     }
 }
 /**
  * Gets calendar data for use in main calendar and module
  *
  * @param int $year
  * @param int $month
  * @param int $day
  * @param boolean $short - use true for module which only requires knowledge of if dat has an event
  * @param boolean $veryshort - use true for module which only requires dates and nothing about events
  * @return array - calendar data array
  */
 function getCalendarData($year, $month, $day, $short = false, $veryshort = false)
 {
     $data = array();
     $data['year'] = $year;
     $data['month'] = $month;
     $db =& JFactory::getDBO();
     if (!isset($this->myItemid) || is_null($this->myItemid)) {
         $Itemid = JEVHelper::getItemid();
         $this->myItemid = $Itemid;
     }
     include_once JPATH_ADMINISTRATOR . "/components/" . JEV_COM_COMPONENT . "/libraries/colorMap.php";
     $cfg =& JEVConfig::getInstance();
     if (!$veryshort) {
         //$rows = $this->queryModel->listEventsByMonthNEW( $year, $month, 'reccurtype ASC,publish_up');
         $icalrows = $this->queryModel->listIcalEventsByMonth($year, $month);
         // handy for developement in case I comment out part of the above
         if (!isset($rows)) {
             $rows = array();
         }
         if (!isset($icalrows)) {
             $icalrows = array();
         }
         $rows = array_merge($icalrows, $rows);
     } else {
         $rows = array();
     }
     $rowcount = count($rows);
     if (strlen($this->catidsOut) > 0) {
         $cat = "&catids={$this->catidsOut}";
     } else {
         $cat = "";
     }
     $month = intval($month);
     if ($month <= '9') {
         $month = '0' . $month;
     }
     $fieldsetText = "";
     $yearNow = date("Y");
     $monthNow = date("m");
     $dayNow = intval(date("d"));
     if (!$short) {
         if ($year == $yearNow && $month == $monthNow && $day == $dayNow) {
             $fieldsetText = JEventsHTML::getDateFormat($year, $month, $day, 1);
         } else {
             $fieldsetText = JEventsHTML::getDateFormat($year, $month, "", 3);
         }
         $data["fieldsetText"] = $fieldsetText;
     }
     $startday = $cfg->get('com_starday');
     if (!$startday || $startday > 1) {
         $startday = 0;
     }
     $data['startday'] = $startday;
     if (!$short) {
         $data["daynames"] = array();
         for ($i = 0; $i < 7; $i++) {
             $data["daynames"][$i] = JEventsHTML::getDayName(($i + $startday) % 7, true);
         }
     }
     $data["dates"] = array();
     //Start days
     $start = (date('w', JevDate::mktime(0, 0, 0, $month, 1, $year)) - $startday + 7) % 7;
     $base = date('t', JevDate::mktime(0, 0, 0, $month, 0, $year));
     $dayCount = 0;
     $priorMonth = $month - 1;
     $priorYear = $year;
     if ($priorMonth <= 0) {
         $priorMonth += 12;
         $priorYear -= 1;
     }
     for ($a = $start; $a > 0; $a--) {
         $d = intval($base - $a + 1);
         $data["dates"][$dayCount] = array();
         $data["dates"][$dayCount]["monthType"] = "prior";
         $data["dates"][$dayCount]["month"] = $priorMonth;
         $data["dates"][$dayCount]["year"] = $priorYear;
         $data["dates"][$dayCount]['countDisplay'] = 0;
         if ($d <= '9') {
             $do = '0' . $d;
         } else {
             $do = $d;
         }
         $data["dates"][$dayCount]['d'] = $d;
         $data["dates"][$dayCount]['d0'] = $do;
         if ($short) {
             $data["dates"][$dayCount]["events"] = false;
         } else {
             $data["dates"][$dayCount]["events"] = array();
         }
         $cellDate = JevDate::mktime(0, 0, 0, $priorMonth, $d, $priorYear);
         $data["dates"][$dayCount]['cellDate'] = $cellDate;
         $data["dates"][$dayCount]["today"] = false;
         $link = JRoute::_('index.php?option=' . JEV_COM_COMPONENT . '&task=day.listevents&year=' . $priorYear . '&month=' . $priorMonth . '&day=' . $do . $cat . '&Itemid=' . $this->myItemid);
         $data["dates"][$dayCount]["link"] = $link;
         $dayCount++;
     }
     sort($data["dates"]);
     //Current month
     $end = date('t', JevDate::mktime(0, 0, 0, $month + 1, 0, $year));
     for ($d = 1; $d <= $end; $d++) {
         $data["dates"][$dayCount] = array();
         // utility field used to keep track of events displayed in a day!
         $data["dates"][$dayCount]['countDisplay'] = 0;
         $data["dates"][$dayCount]["monthType"] = "current";
         $data["dates"][$dayCount]["month"] = $month;
         $data["dates"][$dayCount]["year"] = $year;
         if ($short) {
             $data["dates"][$dayCount]["events"] = false;
         } else {
             $data["dates"][$dayCount]["events"] = array();
         }
         $t_datenow = JEVHelper::getNow();
         $now_adjusted = $t_datenow->toUnix(true);
         if ($month == JevDate::strftime('%m', $now_adjusted) && $year == JevDate::strftime('%Y', $now_adjusted) && $d == JevDate::strftime('%d', $now_adjusted)) {
             $data["dates"][$dayCount]["today"] = true;
         } else {
             $data["dates"][$dayCount]["today"] = false;
         }
         if ($d <= '9') {
             $do = '0' . $d;
         } else {
             $do = $d;
         }
         $data["dates"][$dayCount]['d'] = $d;
         $data["dates"][$dayCount]['d0'] = $do;
         $link = JRoute::_('index.php?option=' . JEV_COM_COMPONENT . '&task=day.listevents&year=' . $year . '&month=' . $month . '&day=' . $do . $cat . '&Itemid=' . $this->myItemid);
         $data["dates"][$dayCount]["link"] = $link;
         $cellDate = JevDate::mktime(0, 0, 0, $month, $d, $year);
         $data["dates"][$dayCount]['cellDate'] = $cellDate;
         //$data["dates"][$dayCount]['events'] = array();
         if ($rowcount > 0) {
             foreach ($rows as $row) {
                 if ($row->checkRepeatMonth($cellDate, $year, $month)) {
                     if ($short) {
                         $data["dates"][$dayCount]['events'] = true;
                         // I can skip testing all the events since checkRepeatMonth tests for multiday events to make xure they only appear
                         // on secondary days if the multiday flag is set to 1
                         break;
                     } else {
                         $i = count($data["dates"][$dayCount]['events']);
                         $data["dates"][$dayCount]['events'][$i] = $row;
                     }
                 }
             }
         }
         // sort events of this day by time
         if (is_array($data["dates"][$dayCount]['events'])) {
             usort($data["dates"][$dayCount]['events'], array("JEventsDataModel", "_sortEventsByTime"));
         }
         $dayCount++;
     }
     $days = (7 - date('w', JevDate::mktime(0, 0, 0, $month + 1, 1, $year)) + $startday) % 7;
     $d = 1;
     $followMonth = $month + 1;
     $followYear = $year;
     if ($followMonth > 12) {
         $followMonth -= 12;
         $followYear += 1;
     }
     $data["followingMonth"] = array();
     for ($d = 1; $d <= $days; $d++) {
         $data["dates"][$dayCount] = array();
         $data["dates"][$dayCount]["monthType"] = "following";
         $data["dates"][$dayCount]["month"] = $followMonth;
         $data["dates"][$dayCount]["year"] = $followYear;
         $data["dates"][$dayCount]['countDisplay'] = 0;
         if ($d <= '9') {
             $do = '0' . $d;
         } else {
             $do = $d;
         }
         $data["dates"][$dayCount]['d'] = $d;
         $data["dates"][$dayCount]['d0'] = $do;
         if ($short) {
             $data["dates"][$dayCount]["events"] = false;
         } else {
             $data["dates"][$dayCount]["events"] = array();
         }
         $cellDate = JevDate::mktime(0, 0, 0, $followMonth, $d, $followYear);
         $data["dates"][$dayCount]['cellDate'] = $cellDate;
         $data["dates"][$dayCount]["today"] = false;
         $link = JRoute::_('index.php?option=' . JEV_COM_COMPONENT . '&task=day.listevents&year=' . $followYear . '&month=' . $followMonth . '&day=' . $do . $cat . '&Itemid=' . $this->myItemid);
         $data["dates"][$dayCount]["link"] = $link;
         $dayCount++;
     }
     // Week data and links
     $data["weeks"] = array();
     for ($w = 0; $w < 6 && $w * 7 < count($data["dates"]); $w++) {
         $date = $data["dates"][$w * 7]['cellDate'];
         $day = $data["dates"][$w * 7]["d"];
         $month = $data["dates"][$w * 7]["month"];
         $year = $data["dates"][$w * 7]["year"];
         // get week number from second weekday to avoid confusion with week start sunday + 1 day + 3 hours to avoid DST change problems
         $week = intval(JEV_CommonFunctions::jev_strftime("%V", $date + 97200));
         $link = JRoute::_('index.php?option=' . JEV_COM_COMPONENT . '&task=week.listevents&year=' . $year . '&month=' . $month . '&day=' . $day . $cat . '&Itemid=' . $this->myItemid);
         $data["weeks"][$week] = $link;
     }
     return $data;
 }