/**
  * Builds the Months of the Year.<br>
  * <b>Note:</b> by defining the constant CALENDAR_MONTH_STATE you can
  * control what class of Calendar_Month is built e.g.;
  * <code>
  * require_once 'Calendar/Calendar_Year.php';
  * define ('CALENDAR_MONTH_STATE',CALENDAR_USE_MONTH_WEEKDAYS); // Use Calendar_Month_Weekdays
  * // define ('CALENDAR_MONTH_STATE',CALENDAR_USE_MONTH_WEEKS); // Use Calendar_Month_Weeks
  * // define ('CALENDAR_MONTH_STATE',CALENDAR_USE_MONTH); // Use Calendar_Month
  * </code>
  * It defaults to building Calendar_Month objects.
  * @param array (optional) array of Calendar_Month objects representing selected dates
  * @param int (optional) first day of week (e.g. 0 for Sunday, 2 for Tuesday etc.)
  * @return boolean
  * @access public
  */
 function build($sDates = array(), $firstDay = null)
 {
     require_once CALENDAR_ROOT . 'Factory.php';
     $this->firstDay = $this->defineFirstDayOfWeek($firstDay);
     $monthsInYear = $this->cE->getMonthsInYear($this->thisYear());
     for ($i = 1; $i <= $monthsInYear; $i++) {
         $this->children[$i] = Calendar_Factory::create('Month', $this->year, $i);
     }
     if (count($sDates) > 0) {
         $this->setSelection($sDates);
     }
     return true;
 }
Exemplo n.º 2
0
 function build($events = array(), $firstDay = null)
 {
     $this->year = $this->calendar->year;
     require_once CALENDAR_ROOT . 'Factory.php';
     $this->calendar->firstDay = $this->calendar->defineFirstDayOfWeek($firstDay);
     $monthsInYear = $this->calendar->cE->getMonthsInYear($this->calendar->thisYear());
     for ($i = 1; $i <= $monthsInYear; $i++) {
         $month = Calendar_Factory::create('Month', $this->year, $i);
         $MonthDecorator = new MonthEvent_Decorator($month);
         $MonthDecorator->build($events);
         $this->children[$i] = $MonthDecorator->calendar;
     }
     $this->calendar->children = $this->children;
     return true;
 }
Exemplo n.º 3
0
 /**
  * Gets the value of the following week, according to the requested format
  *
  * @param string $format ['timestamp' | 'n_in_month' | 'n_in_year' | 'array']
  * @return mixed
  * @access public
  */
 function nextWeek($format = 'n_in_month')
 {
     switch (strtolower($format)) {
         case 'int':
         case 'n_in_month':
             return $this->lastWeek ? null : $this->thisWeek('n_in_month') + 1;
             break;
         case 'n_in_year':
             return $this->cE->getWeekNInYear($this->cE->stampToYear($this->nextWeek), $this->cE->stampToMonth($this->nextWeek), $this->cE->stampToDay($this->nextWeek));
             break;
         case 'array':
             return $this->toArray($this->nextWeek);
             break;
         case 'object':
             require_once CALENDAR_ROOT . 'Factory.php';
             return Calendar_Factory::createByTimestamp('Week', $this->nextWeek);
             break;
         case 'timestamp':
         default:
             return $this->nextWeek;
             break;
     }
 }
 function testSelectionCornerCase()
 {
     require_once CALENDAR_ROOT . 'Day.php';
     $selectedDays = array(Calendar_Factory::create('Day', 2003, 12, 28), Calendar_Factory::create('Day', 2003, 12, 29), Calendar_Factory::create('Day', 2003, 12, 30), Calendar_Factory::create('Day', 2003, 12, 31), Calendar_Factory::create('Day', 2004, 01, 01), Calendar_Factory::create('Day', 2004, 01, 02), Calendar_Factory::create('Day', 2004, 01, 03));
     $this->cal = Calendar_Factory::create('Week', 2003, 12, 31, 0);
     $this->cal->build($selectedDays);
     while ($Day = $this->cal->fetch()) {
         $this->assertTrue($Day->isSelected());
     }
     $this->cal = Calendar_Factory::create('Week', 2004, 1, 1, 0);
     $this->cal->build($selectedDays);
     while ($Day = $this->cal->fetch()) {
         $this->assertTrue($Day->isSelected());
     }
 }
 /**
  * Returns the value as an associative array (helper method)
  *
  * @param string $returnType type of date object that return value represents
  * @param string $format     ['int' | 'array' | 'timestamp' | 'object']
  * @param mixed  $stamp      timestamp (depending on Calendar engine being used)
  * @param int    $default    default value (i.e. give me the answer quick)
  *
  * @return mixed
  * @access private
  */
 function returnValue($returnType, $format, $stamp, $default)
 {
     switch (strtolower($format)) {
         case 'int':
             return $default;
         case 'array':
             return $this->toArray($stamp);
             break;
         case 'object':
             include_once CALENDAR_ROOT . 'Factory.php';
             return Calendar_Factory::createByTimestamp($returnType, $stamp);
             break;
         case 'timestamp':
         default:
             return $stamp;
             break;
     }
 }
Exemplo n.º 6
0
 /**
  * Creates an instance of a calendar object, given a type and timestamp
  * @param string type of object to create
  * @param mixed timestamp (depending on Calendar engine being used)
  * @return object subclass of Calendar
  * @access public
  * @static
  */
 function &createByTimestamp($type, $stamp)
 {
     $cE =& Calendar_Engine_Factory::getEngine();
     $y = $cE->stampToYear($stamp);
     $m = $cE->stampToMonth($stamp);
     $d = $cE->stampToDay($stamp);
     $h = $cE->stampToHour($stamp);
     $i = $cE->stampToMinute($stamp);
     $s = $cE->stampToSecond($stamp);
     $cal = Calendar_Factory::create($type, $y, $m, $d, $h, $i, $s);
     return $cal;
 }
Exemplo n.º 7
0
 /**
  * Loads the last event (end) time from the DB. This is the base for all operations on the
  * resultset.
  *
  * This is done under sudo if possible, to avoid problems arising if the last posting
  * is hidden. This keeps up performance, as an execute_unchecked() can be made in this case.
  * If sudo cannot be acquired, the system falls back to excute().
  *
  * This call will put the event on which the last month is based into the request key
  * 'last_event'.
  *
  * @return Calendar_Month The month of the last event or null on failure.
  * @access private
  */
 function _compute_last_month()
 {
     if ($this->_config->get('list_from_master')) {
         $result = fi_kilonkipinat_events_compute_last_event($this->_request_data['master_event_obj']);
     } else {
         $result = fi_kilonkipinat_events_compute_last_event($this->_request_data['content_topic']);
     }
     if ($result) {
         $this->_request_data['last_event'] = $result;
         return Calendar_Factory::createByTimestamp('Month', strtotime($result->end));
     } else {
         $this->_request_data['last_event'] = null;
         return Calendar_Factory::createByTimestamp('Month', time() + 1);
     }
 }