/** * Sets up the fixture. * This method is called before a test is executed. * * @access protected */ protected function setUp() { // initial object $this->objects['TestRecord'] = new Tinebase_Record_DummyRecord(array(), true); $this->objects['TestRecord']->setFromArray(array('id' => '2', 'test_2' => NULL), NULL); // date management $date = new Tinebase_DateTime(); $this->objects['TestRecord']->date_single = clone $date; $this->objects['TestRecord']->date_multiple = array($date); // bypass filters $this->objects['TestRecordBypassFilters'] = new Tinebase_Record_DummyRecord(array('id' => '7', 'test_2' => 'STRING'), true); $this->expectFailure['TestRecord']['testSetId'][] = array('2', '3'); $this->expectFailure['TestRecord']['testSetId'][] = array('30000000', '3000000000000000000000000000'); $this->expectSuccess['TestRecord']['testSetId'][] = array('2', '2'); $this->expectFailure['TestRecordBypassFilters']['testSetIdBypassFilters'][] = array('2', '3'); $this->expectFailure['TestRecordBypassFilters']['testSetIdBypassFilters'][] = array('30000000', '3000000000000000000000000000'); $this->expectSuccess['TestRecordBypassFilters']['testSetIdBypassFilters'][] = array('2', '2'); $this->expectSuccess['TestRecord']['testSetFromArray'][] = array(array('test_1' => '2', 'test_2' => NULL), 'test_1'); $this->expectFailure['TestRecord']['testSetFromArrayException'][] = array('Tinebase_Exception_Record_Validation', array('test_2' => 'string')); $this->expectFailure['TestRecord']['testSetTimezoneException'][] = array('Tinebase_Exception_Record_NotAllowed', 'UTC'); $dummy = array('id' => 2, 'test_2' => '', 'date_single' => $date->get(Tinebase_Record_Abstract::ISO8601LONG), 'date_multiple' => array($date->get(Tinebase_Record_Abstract::ISO8601LONG))); $this->expectSuccess['TestRecord']['testToArray'][] = array($dummy); $this->expectSuccess['TestRecord']['__set'][] = array('test_3', 4); $this->expectSuccess['TestRecord']['__get'][] = array('test_3', 4); $this->expectSuccess['TestRecord']['test__isset'][] = array('id'); $this->expectFailure['TestRecord']['test__isset'][] = array('string'); $this->expectFailure['TestRecord']['test__setException'][] = array('Tinebase_Exception_UnexpectedValue', 'test_100'); $this->expectFailure['TestRecord']['test__getException'][] = array('Tinebase_Exception_UnexpectedValue', 'test_100'); $this->expectFailure['TestRecord']['testOffsetUnset'][] = array('Tinebase_Exception_Record_NotAllowed', 'test_2'); }
/** * the constructor * * @param mixed $_requestBody * @param ActiveSync_Model_Device $_device * @param string $_policyKey */ public function __construct($_requestBody, ActiveSync_Model_Device $_device = null, $_policyKey = null) { if ($this->_skipValidatePolicyKey !== true && $_policyKey === null) { #throw new ActiveSync_Exception_PolicyKeyMissing(); } if ($this->_skipValidatePolicyKey !== true && ($_policyKey === 0 || $_device->policykey != $_policyKey)) { #throw new ActiveSync_Exception_ProvisioningNeeded(); } // should we wipe the mobile phone? if ($this->_skipValidatePolicyKey !== true && !empty($_policyKey) && $_device->remotewipe >= ActiveSync_Command_Provision::REMOTEWIPE_REQUESTED) { throw new ActiveSync_Exception_ProvisioningNeeded(); } $this->_policyKey = $_policyKey; $this->_device = $_device; $this->_inputDom = $_requestBody; $this->_syncTimeStamp = Tinebase_DateTime::now(); if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " sync timestamp: " . $this->_syncTimeStamp->get(Tinebase_Record_Abstract::ISO8601LONG)); } // Creates an instance of the DOMImplementation class $imp = new DOMImplementation(); // Creates a DOMDocumentType instance $dtd = $imp->createDocumentType('AirSync', "-//AIRSYNC//DTD AirSync//EN", "http://www.microsoft.com/"); // Creates a DOMDocument instance $this->_outputDom = $imp->createDocument($this->_defaultNameSpace, $this->_documentElement, $dtd); $this->_outputDom->formatOutput = false; $this->_outputDom->encoding = 'utf-8'; }
/** * adds diff to date and applies dst fix * * @param Tinebase_DateTime $_dateInUTC * @param DateTimeInterval $_diff * @param string $_timezoneForDstFix */ public static function addUTCDateDstFix($_dateInUTC, $_diff, $_timezoneForDstFix) { $_dateInUTC->setTimezone($_timezoneForDstFix); $_dateInUTC->add($_dateInUTC->get('I') ? 1 : 0, Tinebase_DateTime::MODIFIER_HOUR); $_dateInUTC->add($_diff); $_dateInUTC->subHour($_dateInUTC->get('I') ? 1 : 0); $_dateInUTC->setTimezone('UTC'); }
/** * get string representation of first and last days of the week defined by date/week number * * @param Tinebase_DateTime $_date * @param integer $_weekNumber optional * @return array */ protected function _getFirstAndLastDayOfWeek(Tinebase_DateTime $_date, $_weekNumber = NULL) { $firstDayOfWeek = $this->_getFirstDayOfWeek(); if ($_weekNumber !== NULL) { $_date->setWeek($_weekNumber); } $dayOfWeek = $_date->get('w'); // in some locales sunday is last day of the week -> we need to init dayOfWeek with 7 $dayOfWeek = $firstDayOfWeek == 1 && $dayOfWeek == 0 ? 7 : $dayOfWeek; $_date->sub($dayOfWeek - $firstDayOfWeek, Tinebase_DateTime::MODIFIER_DAY); $firstDay = $_date->toString($this->_dateFormat); $_date->add(6, Tinebase_DateTime::MODIFIER_DAY); $lastDay = $_date->toString($this->_dateFormat); $result = array($firstDay, $lastDay); return $result; }
/** * Adds the properly filter according e-mail application * @param Tinebase_DateTime $received */ public static function getPeriodFilter($received) { $mailApplication = self::getMailApplicationName(); if ($mailApplication !== 'Felamimail') { $class = $mailApplication . '_Model_Filter_DateTime'; return new $class('received', 'after', $received->get(Tinebase_Record_Abstract::ISO8601LONG)); } else { return new Tinebase_Model_Filter_DateTime('received', 'after', $received->get(Tinebase_Record_Abstract::ISO8601LONG)); } }
/** * checks deadline of record * * @param Timetracker_Model_Timesheet $_record * @param boolean $_throwException * @return void * @throws Timetracker_Exception_Deadline */ protected function _checkDeadline(Timetracker_Model_Timesheet $_record, $_throwException = TRUE) { // get timeaccount $timeaccount = Timetracker_Controller_Timeaccount::getInstance()->get($_record->timeaccount_id); if (isset($timeaccount->deadline) && $timeaccount->deadline == Timetracker_Model_Timeaccount::DEADLINE_LASTWEEK) { if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) { Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Check if deadline is exceeded for timeaccount ' . $timeaccount->title); } // it is only on monday allowed to add timesheets for last week $date = new Tinebase_DateTime(); $date->setTime(0, 0, 0); $dayOfWeek = $date->get('w'); if ($dayOfWeek >= 2) { // only allow to add ts for this week $date->sub($dayOfWeek, Tinebase_DateTime::MODIFIER_DAY); } else { // only allow to add ts for last week $date->sub($dayOfWeek + 7, Tinebase_DateTime::MODIFIER_DAY); } // convert start date to Tinebase_DateTime $startDate = new Tinebase_DateTime($_record->start_date); if ($date->compare($startDate) >= 0) { if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) { Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Deadline exceeded: ' . $startDate . ' < ' . $date); } if ($this->checkRight(Timetracker_Acl_Rights::MANAGE_TIMEACCOUNTS, FALSE) || Timetracker_Model_TimeaccountGrants::hasGrant($_record->timeaccount_id, Tinebase_Model_Grants::GRANT_ADMIN)) { if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) { Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' User with admin / manage all rights is allowed to save Timesheet even if it exceeds the deadline.'); } } else { if ($_throwException) { throw new Timetracker_Exception_Deadline(); } } } else { if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Valid date: ' . $startDate . ' >= ' . $date); } } } }
/** * test__call(). */ public function test__call() { $now = new Tinebase_DateTime(); $now->setTimezone('Europe/Berlin'); $this->object->date_single = clone $now; $this->object->setTimezone('America/Los_Angeles'); foreach ($this->object as $record) { $this->assertNotEquals($record->date_single->get(Tinebase_Record_Abstract::ISO8601LONG), $now->get(Tinebase_Record_Abstract::ISO8601LONG)); } }
/** * update sync key * * @param ActiveSync_Model_Device $_device * @param Tinebase_DateTime $_counter * @param $_timeStamp * @param $_class * @param $_collectionId * @deprecated * @return void */ public function updateSyncKey(ActiveSync_Model_Device $_device, $_counter, Tinebase_DateTime $_timeStamp, $_class, $_collectionId = NULL, $_keepPreviousSyncKey = true) { $type = $_collectionId !== NULL ? $_class . '-' . $_collectionId : $_class; if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' update synckey to ' . $_counter . ' for type: ' . $type); } $newSyncState = new ActiveSync_Model_SyncState(array('device_id' => $_device->getId(), 'counter' => $_counter, 'type' => $type, 'lastsync' => $_timeStamp->get(Tinebase_Record_Abstract::ISO8601LONG))); try { // check if we need to update synckey timestamps $this->_syncStateBackend->get($newSyncState); $this->_syncStateBackend->update($newSyncState); } catch (ActiveSync_Exception_SyncStateNotFound $asessnf) { // otherwise add new synckey $this->_syncStateBackend->create($newSyncState); } if ($_keepPreviousSyncKey !== true) { // remove all other synckeys $this->_syncStateBackend->deleteOther($newSyncState); } return $newSyncState; }