You are here

class cmfcCalendarV1 in Calendar Systems 5

Same name and namespace in other branches
  1. 8 calendar/v1/calendarV1.class.inc.php \cmfcCalendarV1
  2. 8.2 calendar/v1/calendarV1.class.inc.php \cmfcCalendarV1
  3. 6.3 calendar/v1/calendarV1.class.inc.php \cmfcCalendarV1
  4. 6 calendar/v1/calendarV1.class.inc.php \cmfcCalendarV1
  5. 7.3 calendar/v1/calendarV1.class.inc.php \cmfcCalendarV1
  6. 7 calendar/v1/calendarV1.class.inc.php \cmfcCalendarV1
  7. 7.2 calendar/v1/calendarV1.class.inc.php \cmfcCalendarV1

Hierarchy

Expanded class hierarchy of cmfcCalendarV1

File

calendar/v1/calendarV1.class.inc.php, line 23

View source
class cmfcCalendarV1 extends cmfcClassesCore {
  var $_name;
  var $_language;
  var $_timeZoneName;
  var $_timeZoneInfo;
  var $_defaultError = CMF_CalendarV1_Error;
  var $_messagesValue = array(
    CMF_CalendarV1_Ok => 'no error',
    CMF_CalendarV1_Error => 'unkown error',
    CMF_CalendarV1_Does_No_Exsists => 'template "%internalName%" does not exists',
  );
  function __construct($options) {
    $this
      ->setOptions($options);
  }
  function factory($options) {
    if ($options['name'] == 'iranian') {
      require_once dirname(__FILE__) . '/calendarSystems/iranian.class.inc.php';
      return new cmfcCalendarV1Iranian($options);
    }
    if ($options['name'] == 'gregorian') {
      require_once dirname(__FILE__) . '/calendarSystems/gregorian.class.inc.php';
      return new cmfcCalendarV1Gregorian($options);
    }
  }
  function setOption($name, $value, $merge = false) {
    if ($name == 'timeZoneOffset') {
      $this
        ->setTimeZoneOffset($value);
    }
    return parent::setOption($name, $value, $merge);
  }
  function setTimeZoneOffset($offset) {

    /*
    echo timezone_name_from_abbr($countryShortName);
    echo $countryShortName;
    $timezone = new DateTimeZone($countryShortName);
    $this->_timeZoneInfo=reset($timezone->getTransitions());
    cmfcHtml::printr($this->_timeZoneInfo);
    */
    if (!empty($offset)) {
      list($hour, $minute) = explode(':', $offset);
      $offset = abs($hour) * 60 * 60 + $minute * 60;
      if ($hour < 0) {
        $offset = $offset * -1;
      }
    }
    $this->_timeZoneInfo['offset'] = $offset;
  }
  function infoArrayToTimestamp() {
  }
  function timestampToInfoArray() {
  }
  function strToTimestamp($string) {
  }
  function gregorianStrToTimestamp($str) {
    return strtotime($str);
  }
  function timestampToStr($format, $timestamp) {
  }

  /**
   * For supporting timezone , use this class date and time functions like phpDate
   */
  function countDown($infoArray) {

    //$currentDate=$this->timestampToInfoArray();
    $toTimestamp = $this
      ->infoArrayToTimestamp($infoArray);
    $fromTimestamp = $this
      ->phpTime();
    $r = $this
      ->dateTimeDiff($toTimestamp, $fromTimestamp);
    $r['toTimestamp'] = $toTimestamp;
    $r['fromTimestamp'] = $fromTimestamp;
    return $r;
  }
  function infoArrayToInfoArray($array) {
    $ts = $this
      ->infoArrayToTimestamp($array);
    return $this
      ->timestampToInfoArray($ts);
  }
  function phpGetDate($timestamp = null) {
    if (is_null($timestamp)) {
      if (!empty($this->_timeZoneInfo)) {
        $timestamp = gmmktime() + $this->_timeZoneInfo['offset'];
        $r = array(
          'seconds' => gmdate('s', $timestamp),
          'minutes' => gmdate('i', $timestamp),
          'hours' => gmdate('H', $timestamp),
          'mday' => gmdate('d', $timestamp),
          'wday' => gmdate('w', $timestamp),
          'mon' => gmdate('m', $timestamp),
          'year' => gmdate('Y', $timestamp),
          'yday' => gmdate('z', $timestamp),
          'weekday' => gmdate('l', $timestamp),
          'month' => gmdate('M', $timestamp),
          '0' => $timestamp,
        );
      }
      else {
        $timestamp = mktime();
        $r = getdate($timestamp);
      }
    }
    else {
      $r = getdate($timestamp);
    }
    return $r;
  }
  function phpDate($format, $timestamp = null) {
    if (is_null($timestamp) or empty($timestamp)) {
      if (!empty($this->_timeZoneInfo)) {
        $timestamp = gmmktime() + $this->_timeZoneInfo['offset'];
        $r = gmdate($format, $timestamp);
      }
      else {
        $timestamp = mktime();
        $r = date($format, $timestamp);
      }
    }
    else {
      $r = date($format, $timestamp);
    }
    return $r;
  }
  function phpTime() {
    if (!empty($this->_timeZoneInfo)) {
      $timestamp = gmmktime() + $this->_timeZoneInfo['offset'];
    }
    else {
      $timestamp = mktime();
    }
    return $timestamp;
  }
  function getYmdwMonthAsNavigationalArray($options) {
    if (empty($options['columnsHorizontal'])) {
      $options['columnsHorizontal'] = 6;
    }
    if (empty($options['columnsVertical'])) {
      $options['columnsVertical'] = 5;
    }
    if (isset($options['secondaryCalendar'])) {
      $secondaryCalendar = self::factory(array(
        'name' => $options['secondaryCalendar'],
      ));
    }
    $table = array();
    $currentMonth = $this
      ->timestampToInfoArray();
    if (is_null($options['year'])) {
      $options['year'] = $currentMonth['year'];
    }
    if (is_null($options['month'])) {
      $options['month'] = $currentMonth['month'];
    }
    if (is_null($options['day'])) {
      $options['day'] = 1;
    }
    else {
      $selectedDay = $options['day'];
    }
    $previousMonth = $this
      ->infoArrayToInfoArray(array(
      'year' => $options['year'],
      'month' => $options['month'] - 1,
      'day' => $options['day'],
    ));
    $activeMonth = $this
      ->infoArrayToInfoArray(array(
      'year' => $options['year'],
      'month' => $options['month'],
      'day' => $options['day'],
    ));
    $nextMonth = $this
      ->infoArrayToInfoArray(array(
      'year' => $options['year'],
      'month' => $options['month'] + 1,
      'day' => $options['day'],
    ));
    $table['currentMonth'] = $currentMonth;
    $table['activeMonth'] = $activeMonth;
    $table['nextMonth'] = $nextMonth;
    $table['previousMonth'] = $previousMonth;
    foreach ($this->_weeksName as $x => $weekName) {

      //for ($x=1;$x<=$options['columnsHorizontal'];$x++) {
      $table['weekDays'][$x] = array(
        'number' => $x,
        'name' => $weekName,
        'shortName' => '',
      );
    }
    $dayNumber = 1;
    $monthStarted = false;
    for ($y = 1; $y <= $options['columnsVertical']; $y++) {
      for ($x = 0; $x <= $options['columnsHorizontal']; $x++) {
        $value = array();

        //echo $activeMonth['monthFirstDayWeekday'].'-'.$x.'<br />';
        if (($x == $activeMonth['monthFirstDayWeekday'] or $y > 1 or $monthStarted == true) and $dayNumber <= $activeMonth['monthDaysNumber']) {
          $monthStarted = true;
          $value['status'] = array();
          $value['day'] = $dayNumber;
          if ($dayNumber == $selectedDay) {
            $value['status'][] = 'selected';
          }
          if ($dayNumber == $currentMonth['day'] and $currentMonth['month'] == $activeMonth['month'] and $currentMonth['year'] == $activeMonth['year']) {
            $value['status'][] = 'today';
          }
          if (in_array($x, $this->_weekDaysHoliday)) {
            $value['status'][] = 'holiday';
          }
          if (isset($secondaryCalendar)) {
            $__activeMonth = $activeMonth;
            $__activeMonth['day'] = $dayNumber;
            $value['secondaryCalendar'] = $secondaryCalendar
              ->timestampToInfoArray($this
              ->infoArrayToTimestamp($__activeMonth));
          }
          if ($y == 5 and $x == 6 and $activeMonth['monthDaysNumber'] > $dayNumber) {
            $options['columnsVertical']++;
          }
          $dayNumber++;
        }
        $table['days'][$y][$x] = $value;
      }
    }
    return $table;
  }

  /**
   * Date    : 15-12-2003.
   *
   * Ref: Dates go in "2003-12-31".
   * Ref: Times go in "12:59:13".
   * Ref: mktime(HOUR,MIN,SEC,MONTH,DAY,YEAR).
   *
   * Splits the dates into parts, to be reformatted for mktime.
   * $first_datetime = getdate($first_datetime);
   * $second_datetime = getdate($second_datetime);
   *
   * makes the dates and times into unix timestamps.
   * $first_unix  = mktime($first_datetime['hours'], $first_time_ex[1], $first_time_ex[2], $first_date_ex[1], $first_date_ex[2], $first_date_ex[0]);
   * $second_unix  = mktime($second_time_ex[0], $second_time_ex[1], $second_time_ex[2], $second_date_ex[1], $second_date_ex[2], $second_date_ex[0]);
   * Gets the difference between the two unix timestamps.
   */
  function dateTimeDiff($endTimestamp, $startTimestamp) {
    $timediff = $endTimestamp - $startTimestamp;

    // Works out the days, hours, mins and secs.
    $daysTotal = floor($timediff / (24 * 60 * 60));
    $remain = $timediff % (24 * 60 * 60);
    $hours = floor($remain / (60 * 60));
    $remain = $remain % (60 * 60);
    $mins = floor($remain / 60);
    $remain = $remain % 60;
    $secs = $remain;

    // Returns a pre-formatted string. Can be chagned to an array.
    $result['daysTotal'] = $daysTotal;

    //$result['days']=$days;
    $result['hours'] = $hours;
    $result['minutes'] = $mins;
    $result['seconds'] = $secs;
    return $result;
  }

  /**
   * convert seconds to days,hours,minuts,seconds as array
   * @param integer $seconds
   * @return array
   */
  function secondsToDays($seconds) {
    $days = intval($seconds / 86400);
    $remain = $seconds % 86400;
    $hours = intval($remain / 3600);
    $remain = $remain % 3600;
    $mins = intval($remain / 60);
    $secs = $remain % 60;
    $r = array(
      'days' => $days,
      'hours' => $hours,
      'minutes' => $mins,
      'seconds' => $secs,
    );
    return $r;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
cmfcCalendarV1::$_defaultError property Overrides cmfcClassesCore::$_defaultError
cmfcCalendarV1::$_language property Overrides cmfcClassesCore::$_language
cmfcCalendarV1::$_messagesValue property Overrides cmfcClassesCore::$_messagesValue
cmfcCalendarV1::$_name property
cmfcCalendarV1::$_timeZoneInfo property
cmfcCalendarV1::$_timeZoneName property
cmfcCalendarV1::countDown function * For supporting timezone , use this class date and time functions like phpDate
cmfcCalendarV1::dateTimeDiff function Date : 15-12-2003. 1
cmfcCalendarV1::factory function
cmfcCalendarV1::getYmdwMonthAsNavigationalArray function
cmfcCalendarV1::gregorianStrToTimestamp function
cmfcCalendarV1::infoArrayToInfoArray function
cmfcCalendarV1::infoArrayToTimestamp function 2
cmfcCalendarV1::phpDate function
cmfcCalendarV1::phpGetDate function
cmfcCalendarV1::phpTime function
cmfcCalendarV1::secondsToDays function convert seconds to days,hours,minuts,seconds as array
cmfcCalendarV1::setOption function Overrides cmfcClassesCore::setOption
cmfcCalendarV1::setTimeZoneOffset function
cmfcCalendarV1::strToTimestamp function 2
cmfcCalendarV1::timestampToInfoArray function 2
cmfcCalendarV1::timestampToStr function 2
cmfcCalendarV1::__construct function
cmfcClassesCore::$_commandHandlers property
cmfcClassesCore::$_commandingEnabled property
cmfcClassesCore::$_debugEnabled property
cmfcClassesCore::$_dynamicSystemEnabled property
cmfcClassesCore::$_errorsStack property
cmfcClassesCore::$_observeringEnabled property
cmfcClassesCore::$_observers property
cmfcClassesCore::$_oLog property * PEAR::Log object used for error logging by ErrorStack * * * @access public
cmfcClassesCore::$_options property
cmfcClassesCore::$_oStorage property *
cmfcClassesCore::$_version property
cmfcClassesCore::addCommandHandler function * @example * <code> * $object->addCommandHandler('commandName','functionName') * $object->addCommandHandler('commandName',array(&$myObject,'methodName')) * </code>
cmfcClassesCore::addObserver function Register the reference to an object object
cmfcClassesCore::arrayToProperties function
cmfcClassesCore::clearProperties function
cmfcClassesCore::cmfcClassesCore function * there is no __construct function in php4 or down , so this function is solution , now it's possible * for all chid of this base class to have __construct functions *
cmfcClassesCore::getMessageValue function
cmfcClassesCore::getOption function * works fine in both php4 & 5. but you should use & when you call the function. $b=&$ins->getOption('property')
cmfcClassesCore::getVersion function
cmfcClassesCore::hasCommandHandler function
cmfcClassesCore::isError function Tell whether a value is a PEAR error. Overrides PEAR::isError
cmfcClassesCore::notifyObservers function Calls the update() function using the reference to each registered observer - used by children of Observable
cmfcClassesCore::prependCommandHandler function
cmfcClassesCore::prependObserver function
cmfcClassesCore::propertiesToArray function
cmfcClassesCore::raiseError function conditionally includes PEAR base class and raise an error @example <code> return $this->raiseError('', CMF_Language_Error_Unknown_Short_Name, * PEAR_ERROR_RETURN,NULL, * array('shortName'=>$shortName) … Overrides PEAR::raiseError
cmfcClassesCore::removeCommandHandlers function
cmfcClassesCore::removeObservers function
cmfcClassesCore::resetProperties function * fill all of object variables with their default values except $base_properties * $base_properties=array('local_language_name','db','event_system','configurations','table_name_prefix'); *…
cmfcClassesCore::restoreFromMemento function memento design pattern will load the object previous state @todo - should become complete
cmfcClassesCore::runCommand function * @example * <code> * $this->runCommand('sendEmailAfterActivation',$columnsValues); * </code>
cmfcClassesCore::saveToMemento function memento design pattern will clone the object for adding undo ability. @todo - should become complete
cmfcClassesCore::setLog function
cmfcClassesCore::setOptions function
cmfcClassesCore::setStorage function
PEAR::$_debug property Whether to enable internal debug messages.
PEAR::$_default_error_handler property Default error handler (callback) for this object, if error mode is PEAR_ERROR_CALLBACK.
PEAR::$_default_error_mode property Default error mode for this object.
PEAR::$_default_error_options property Default error options used for this object when error mode is PEAR_ERROR_TRIGGER.
PEAR::$_error_class property Which class to use for error objects.
PEAR::$_expected_errors property An array of expected errors.
PEAR::delExpect function This method deletes all occurences of the specified element from the expected error codes stack.
PEAR::expectError function This method is used to tell which errors you expect to get. Expected errors are always returned with error mode PEAR_ERROR_RETURN. Expected error codes are stored in a stack, and this method pushes a new element onto it. The list of expected errors…
PEAR::getStaticProperty function If you have a class that's mostly/entirely static, and you need static properties, you can use this method to simulate them. Eg. in your method(s) do this: $myVar = &PEAR::getStaticProperty('myclass', 'myVar'); You MUST…
PEAR::loadExtension function OS independant PHP extension load. Remember to take care on the correct extension name for case sensitive OSes.
PEAR::PEAR function Constructor. Registers this object in $_PEAR_destructor_object_list for destructor emulation if a destructor object exists.
PEAR::popErrorHandling function Pop the last error handler used
PEAR::popExpect function This method pops one element off the expected error codes stack.
PEAR::pushErrorHandling function Push a new error handler on top of the error handler options stack. With this you can easily override the actual error handler for some code and restore it later with popErrorHandling.
PEAR::registerShutdownFunc function Use this function to register a shutdown method for static classes.
PEAR::setErrorHandling function Sets how errors generated by this object should be handled. Can be invoked both in objects and statically. If called statically, setErrorHandling sets the default behaviour for all PEAR objects. If called in an object, setErrorHandling sets the…
PEAR::staticPopErrorHandling function
PEAR::staticPushErrorHandling function
PEAR::throwError function Simpler form of raiseError with fewer options. In most cases message, code and userinfo are enough.
PEAR::_checkDelExpect function This method checks unsets an error code if available
PEAR::_PEAR function Destructor (the emulated type of...). Does nothing right now, but is included for forward compatibility, so subclass destructors should always call it.