/**
  *
  * @return type
  */
 public function getFilterImap()
 {
     $format = "d-M-Y";
     // prepare value
     $value = (array) $this->_getDateValues($this->_operator, $this->_value);
     $timezone = Tinebase_Helper::array_value('timezone', $this->_options);
     $timezone = $timezone ? $timezone : Tinebase_Core::getUserTimezone();
     foreach ($value as &$date) {
         $date = new Tinebase_DateTime($date);
         // should be in user timezone
         $date->setTimezone(new DateTimeZone($timezone));
     }
     switch ($this->_operator) {
         case 'within':
         case 'inweek':
             $value[1]->add(new DateInterval('P1D'));
             // before is not inclusive, so we have to add a day
             $return = "SINCE {$value[0]->format($format)} BEFORE {$value[1]->format($format)}";
             break;
         case 'before':
             $return = "BEFORE {$value[0]->format($format)}";
             break;
         case 'after':
             $return = "SINCE {$value[0]->format($format)}";
             break;
         case 'equals':
             $return = "ON {$value[0]->format($format)}";
     }
     return $return;
 }
示例#2
0
 /**
  * returns array with the filter settings of this filter
  * - convert value to user timezone
  *
  * @param  bool $_valueToJson resolve value for json api?
  * @return array
  */
 public function toArray($_valueToJson = false)
 {
     $result = parent::toArray($_valueToJson);
     if ($this->_operator != 'within' && $this->_operator != 'inweek' && $_valueToJson == true) {
         $date = new Tinebase_DateTime($result['value']);
         $date->setTimezone(Tinebase_Core::get(Tinebase_Core::USERTIMEZONE));
         $result['value'] = $date->toString(Tinebase_Record_Abstract::ISO8601LONG);
     }
     return $result;
 }
 /**
  * appends sql to given select statement
  *
  * @param Zend_Db_Select                $_select
  * @param Tinebase_Backend_Sql_Abstract $_backend
  * 
  * @todo to be removed once we split filter model / backend
  */
 public function appendFilterSql($_select, $_backend)
 {
     $now = new Tinebase_DateTime();
     $now->setHour(0)->setMinute(0)->setSecond(0);
     $db = Tinebase_Core::getDb();
     if ($this->_value == 1) {
         $_select->where($db->quoteInto('(' . $db->quoteIdentifier('employment_end') . ' >= ? ', $now, 'datetime') . ' OR ' . $db->quoteIdentifier('employment_end') . ' IS NULL )');
         $_select->where($db->quoteInto('( ' . $db->quoteIdentifier('employment_begin') . ' <= ? ', $now, 'datetime') . ' OR ( ' . $db->quoteIdentifier('employment_begin') . ' IS NULL ))');
     } else {
         $_select->where($db->quoteInto($db->quoteIdentifier('employment_end') . ' < ? ', $now, 'datetime'));
         $_select->orWhere($db->quoteInto($db->quoteIdentifier('employment_begin') . ' > ? ', $now, 'datetime'));
     }
 }
 /**
  * @see 0011156: big files can't be uploaded
  */
 public function testCreateTempFileWithBigSize()
 {
     $size = (double) (3.8 * 1024.0 * 1024.0 * 1024.0);
     $tempFile = new Tinebase_Model_TempFile(array('id' => '123', 'session_id' => 'abc', 'time' => Tinebase_DateTime::now()->get(Tinebase_Record_Abstract::ISO8601LONG), 'path' => '/tmp/tmpfile', 'name' => 'tmpfile', 'type' => 'unknown', 'error' => 0, 'size' => $size));
     $createdTempFile = $this->_instance->create($tempFile);
     $this->assertEquals(4080218931.0, $createdTempFile->size);
 }
 /**
  * @see Tinebase_Setup_DemoData_Abstract
  * 
  */
 protected function _beforeCreate()
 {
     $this->_ccController = Sales_Controller_CostCenter::getInstance();
     $this->_taController = Timetracker_Controller_Timeaccount::getInstance();
     $this->_taController->sendNotifications(FALSE);
     $this->_tsController = Timetracker_Controller_Timesheet::getInstance();
     $this->_tsController->sendNotifications(FALSE);
     $this->_tsController->doContainerACLChecks(false);
     $this->_contractController = Sales_Controller_Contract::getInstance();
     $contracts = $this->_contractController->getAll();
     $developmentString = self::$_de ? 'Entwicklung' : 'Development';
     $this->_contractsDevelopment = $contracts->filter('title', '/.' . $developmentString . '/', TRUE);
     $this->_contractsMarketing = $contracts->filter('title', '/.Marketing/', TRUE);
     $this->_loadCostCentersAndDivisions();
     if (Tinebase_Application::getInstance()->isInstalled('HumanResources')) {
         $this->_empController = HumanResources_Controller_Employee::getInstance();
         $filter = new HumanResources_Model_EmployeeFilter(array());
         $this->_employees = $this->_empController->search($filter);
     }
     // set start date to start date of june 1st before last year
     $date = Tinebase_DateTime::now();
     $this->_startDate = $date->subMonth(3)->setTime(8, 0, 0);
     // set clearedDate almost a month after
     $this->_clearedDate = clone $this->_startDate;
     $this->_clearedDate->addMonth(1)->subDay(2);
 }
示例#6
0
 /**
  * the constructor
  *
  * @param  mixed                    $_requestBody
  * @param  Syncope_Model_Device  $_device
  * @param  string                   $_policyKey
  */
 public function __construct($_requestBody, Syncope_Model_IDevice $_device, $_policyKey)
 {
     $this->_policyKey = $_policyKey;
     $this->_device = $_device;
     $this->_deviceBackend = Syncope_Registry::get('deviceBackend');
     $this->_folderBackend = Syncope_Registry::get('folderStateBackend');
     $this->_syncStateBackend = Syncope_Registry::get('syncStateBackend');
     $this->_contentStateBackend = Syncope_Registry::get('contentStateBackend');
     if (Syncope_Registry::isRegistered('loggerBackend')) {
         $this->_logger = Syncope_Registry::get('loggerBackend');
     }
     if ($this->_skipValidatePolicyKey !== true && $this->_policyKey === null) {
         #throw new Syncope_Exception_PolicyKeyMissing();
     }
     if ($this->_skipValidatePolicyKey !== true && ($this->_policyKey === 0 || $this->_device->policykey != $this->_policyKey)) {
         #throw new Syncope_Exception_ProvisioningNeeded();
     }
     // should we wipe the mobile phone?
     if ($this->_skipValidatePolicyKey !== true && !empty($this->_policyKey) && $this->_device->remotewipe >= Syncope_Command_Provision::REMOTEWIPE_REQUESTED) {
         throw new Syncope_Exception_ProvisioningNeeded();
     }
     $this->_inputDom = $_requestBody;
     $this->_syncTimeStamp = new DateTime(null, new DateTimeZone('UTC'));
     if ($this->_logger instanceof Zend_Log) {
         $this->_logger->debug(__METHOD__ . '::' . __LINE__ . " sync timestamp: " . $this->_syncTimeStamp->format('Y-m-d H:i:s'));
     }
     // 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';
 }
示例#7
0
 /**
  * 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';
 }
 /**
  * testNextScheduledImport
  */
 public function testNextScheduledImport()
 {
     $cc = Calendar_Controller_Event::getInstance();
     $filter = new Calendar_Model_EventFilter(array(array('field' => 'container_id', 'operator' => 'equals', 'value' => $this->_testCalendar->getId())));
     $all = $cc->search($filter);
     $this->assertEquals(0, $all->count());
     $now = Tinebase_DateTime::now()->subHour(1);
     $record = $this->createScheduledImport();
     // assert setting timestamp to start value
     $this->assertEquals($now->format('YMDHi'), $record->timestamp->format('YMDHi'));
     $record = $this->_uit->runNextScheduledImport();
     // assert updating timestamp after successful run
     $now->addHour(1);
     $this->assertEquals($now->format('YMDHi'), $record->timestamp->format('YMDHi'));
     $all = $cc->search($filter);
     $seq = $all->getFirstRecord()->seq;
     // assert all events have been imported
     $this->assertEquals(7, $all->count());
     // this must not be run, the interval is not exceed
     $ret = $this->_uit->runNextScheduledImport();
     $all = $cc->search($filter);
     $this->assertEquals($seq, $all->getFirstRecord()->seq);
     // setting manual timestamp to force run again
     $record->timestamp = $record->timestamp->subHour(1)->subSecond(1);
     $this->_uit->update($record);
     $ret = $this->_uit->runNextScheduledImport();
     $all = $cc->search($filter);
     $this->assertEquals(7, $all->count());
 }
 /**
  * test a whole call cycle - start, connect, disconnect
  * 
  */
 public function testWholeCall()
 {
     // start call
     $call = $this->_backend->callStarted($this->_objects['call']);
     $this->assertEquals($this->_objects['call']->destination, $call->destination);
     $this->assertTrue(Tinebase_DateTime::now()->sub($call->start)->getTimestamp() >= 0);
     // sleep for 2 secs (ringing...)
     sleep(2);
     // connect call
     $call = $this->_backend->getCall($this->_objects['call']->getId());
     $ringing = $call->ringing;
     $connectedCall = $this->_backend->callConnected($call);
     $this->assertEquals($this->_objects['call']->destination, $connectedCall->destination);
     $this->assertEquals(-1, $call->start->compare($call->connected));
     // sleep for 5 secs (talking...)
     sleep(5);
     // disconnect call
     $call = $this->_backend->getCall($this->_objects['call']->getId());
     $duration = $call->duration;
     $disconnectedCall = $this->_backend->callDisconnected($call);
     $this->assertGreaterThan($duration, $disconnectedCall->duration);
     $this->assertLessThan(10, $disconnectedCall->ringing, 'wrong ringing duration');
     $this->assertLessThan(15, $disconnectedCall->duration, 'wrong duration');
     $this->assertEquals(-1, $disconnectedCall->connected->compare($disconnectedCall->disconnected));
 }
 protected function _onAfterExportRecords($result)
 {
     $user = Tinebase_Core::getUser();
     $this->_docTemplate->setValue('date', Tinebase_DateTime::now()->format('Y-m-d'));
     $this->_docTemplate->setValue('account_n_given', $user->accountFirstName);
     $this->_docTemplate->setValue('account_n_family', $user->accountLastName);
 }
 /**
  * delete user by id
  * 
  * @param string $id
  */
 protected function _deleteUserById($id)
 {
     $where = array($this->_db->quoteIdentifier($this->_propertyMapping['emailUserId']) . ' = ?' => $id, $this->_db->quoteIdentifier($this->_userTable . '.domain') . ' = ?' => $this->_config['domain']);
     if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
         Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . print_r($where, TRUE));
     }
     $this->_db->update($this->_userTable, array('is_deleted' => '1', 'last_modified' => Tinebase_DateTime::now()->getIso()), $where);
 }
 /**
  * testBackslashInDescription
  *
  * @see 0009176: iCal adds another backslash to description field
  */
 public function testBackslashInDescription()
 {
     $event = new Calendar_Model_Event(array('summary' => 'CalDAV test', 'dtstart' => Tinebase_DateTime::now(), 'dtend' => Tinebase_DateTime::now()->addHour(1), 'description' => 'lalala \\\\', 'originator_tz' => 'Europe/Berlin', 'creation_time' => Tinebase_DateTime::now(), 'uid' => Tinebase_Record_Abstract::generateUID(), 'seq' => 1));
     $converter = Calendar_Convert_Event_VCalendar_Factory::factory(Calendar_Convert_Event_VCalendar_Factory::CLIENT_MACOSX);
     $vevent = $converter->fromTine20Model($event)->serialize();
     $convertedEvent = $converter->toTine20Model($vevent);
     $this->assertEquals($event->description, $convertedEvent->description);
 }
 /**
  * Test create a access log and logout to set logout time
  *
  * @see 0010728: Strange error in tine20 log when performing logout from Web
  */
 public function testSetLogout()
 {
     $accessLog = new Tinebase_Model_AccessLog(array('ip' => '127.0.0.1', 'li' => Tinebase_DateTime::now(), 'result' => Zend_Auth_Result::SUCCESS, 'clienttype' => 'unittest', 'login_name' => 'unittest', 'user_agent' => 'phpunit', 'sessionid' => Tinebase_Record_Abstract::generateUID()), true);
     $this->_uit->setSessionId($accessLog);
     $this->_uit->create($accessLog);
     $accessLog = $this->_uit->setLogout();
     $this->assertEquals(Tinebase_DateTime::now()->toString(), $accessLog->lo->toString(), 'logout time mismatch/empty: ' . print_r($accessLog, true));
 }
 /**
  * Sets up the fixture.
  * This method is called before a test is executed.
  *
  * @access protected
  */
 protected function setUp()
 {
     parent::setUp();
     $this->_testContainer = $this->_getPersonalContainer('Crm');
     $this->objects['lead'] = new Crm_Model_Lead(array('lead_name' => 'PHPUnit', 'leadstate_id' => 1, 'leadtype_id' => 1, 'leadsource_id' => 1, 'container_id' => $this->_testContainer->id, 'start' => new Tinebase_DateTime("2007-12-12"), 'description' => 'Lead Description', 'end' => Tinebase_DateTime::now(), 'turnover' => '200000', 'probability' => 70, 'end_scheduled' => Tinebase_DateTime::now()));
     $this->objects['leadWithLink'] = new Crm_Model_Lead(array('lead_name' => 'PHPUnit with contact', 'leadstate_id' => 1, 'leadtype_id' => 1, 'leadsource_id' => 1, 'container_id' => $this->_testContainer->id, 'start' => new Tinebase_DateTime("2007-12-24"), 'description' => 'Lead Description', 'end' => Tinebase_DateTime::now(), 'turnover' => '200000', 'probability' => 50, 'end_scheduled' => Tinebase_DateTime::now()));
     $this->objects['linkedContact'] = new Addressbook_Model_Contact(array('adr_one_countryname' => 'DE', 'adr_one_locality' => 'Hamburg', 'adr_one_postalcode' => '24xxx', 'adr_one_region' => 'Hamburg', 'adr_one_street' => 'Pickhuben 4', 'adr_one_street2' => 'no second street', 'adr_two_countryname' => 'DE', 'adr_two_locality' => 'Hamburg', 'adr_two_postalcode' => '24xxx', 'adr_two_region' => 'Hamburg', 'adr_two_street' => 'Pickhuben 4', 'adr_two_street2' => 'no second street2', 'assistent' => 'Cornelius Weiß', 'bday' => '1975-01-02 03:04:05', 'email' => '*****@*****.**', 'email_home' => '*****@*****.**', 'note' => 'Bla Bla Bla', 'role' => 'Role', 'title' => 'Title', 'url' => 'http://www.tine20.org', 'url_home' => 'http://www.tine20.com', 'n_family' => 'Kneschke', 'n_fileas' => 'Kneschke, Lars', 'n_given' => 'Lars', 'n_middle' => 'no middle name', 'n_prefix' => 'no prefix', 'n_suffix' => 'no suffix', 'org_name' => 'Metaways Infosystems GmbH', 'org_unit' => 'Tine 2.0', 'tel_assistent' => '+49TELASSISTENT', 'tel_car' => '+49TELCAR', 'tel_cell' => '+49TELCELL', 'tel_cell_private' => '+49TELCELLPRIVATE', 'tel_fax' => '+49TELFAX', 'tel_fax_home' => '+49TELFAXHOME', 'tel_home' => '+49TELHOME', 'tel_pager' => '+49TELPAGER', 'tel_work' => '+49TELWORK'));
     $this->objects['linkedTask'] = new Tasks_Model_Task(array('summary' => 'task test'));
     Crm_Controller_Lead::getInstance()->create($this->objects['leadWithLink']);
     $this->objects['linkedContact'] = Addressbook_Controller_Contact::getInstance()->create($this->objects['linkedContact'], FALSE);
 }
示例#15
0
 /**
  * Sets up the fixture.
  * 
  * This method is called before a test is executed.
  */
 protected function setUp()
 {
     $personalContainer = Tinebase_Container::getInstance()->getPersonalContainer(Zend_Registry::get('currentAccount'), 'Crm', Zend_Registry::get('currentAccount'), Tinebase_Model_Grants::GRANT_EDIT);
     if ($personalContainer->count() === 0) {
         $this->_testContainer = Tinebase_Container::getInstance()->addPersonalContainer(Zend_Registry::get('currentAccount')->accountId, 'Crm', 'PHPUNIT');
     } else {
         $this->_testContainer = $personalContainer[0];
     }
     $this->_objects['initialLead'] = new Crm_Model_Lead(array('id' => 120, 'lead_name' => 'PHPUnit', 'leadstate_id' => 1, 'leadtype_id' => 1, 'leadsource_id' => 1, 'container_id' => $this->_testContainer->id, 'start' => Tinebase_DateTime::now(), 'description' => 'Description', 'end' => Tinebase_DateTime::now(), 'turnover' => '200000', 'probability' => 70, 'end_scheduled' => Tinebase_DateTime::now()));
     $this->_objects['updatedLead'] = new Crm_Model_Lead(array('id' => 120, 'lead_name' => 'PHPUnit', 'leadstate_id' => 1, 'leadtype_id' => 1, 'leadsource_id' => 1, 'container_id' => $this->_testContainer->id, 'start' => Tinebase_DateTime::now(), 'description' => 'Description updated', 'end' => NULL, 'turnover' => '200000', 'probability' => 70, 'end_scheduled' => NULL));
     $this->_backend = new Crm_Backend_Lead();
 }
 /**
  * testUpdateProductLifespan
  * 
  * @see 0010766: set product lifespan
  */
 public function testUpdateProductLifespan()
 {
     $product1 = $this->getUit()->create(new Sales_Model_Product(array('name' => 'product activates in future', 'lifespan_start' => Tinebase_DateTime::now()->addDay(1))));
     $product2 = $this->getUit()->create(new Sales_Model_Product(array('name' => 'product lifespan ended', 'lifespan_end' => Tinebase_DateTime::now()->subDay(1))));
     $product3 = $this->getUit()->create(new Sales_Model_Product(array('is_active' => 0, 'name' => 'product lifespan started', 'lifespan_start' => Tinebase_DateTime::now()->subDay(1))));
     $product4 = $this->getUit()->create(new Sales_Model_Product(array('is_active' => 0, 'name' => 'product lifespan not yet ended', 'lifespan_end' => Tinebase_DateTime::now()->addDay(1))));
     $productsToTest = array(array('expectedIsActive' => 0, 'product' => $product1), array('expectedIsActive' => 0, 'product' => $product2), array('expectedIsActive' => 1, 'product' => $product3), array('expectedIsActive' => 1, 'product' => $product4));
     $this->getUit()->updateProductLifespan();
     foreach ($productsToTest as $product) {
         $updatedProduct = $this->getUit()->get($product['product']);
         $this->assertEquals($product['expectedIsActive'], $updatedProduct->is_active, print_r($product['product']->toArray(), true));
     }
 }
 /**
  * Returns the last modification time 
  *
  * @return int 
  */
 public function getLastModified()
 {
     if ($this->_node instanceof Tinebase_Model_Tree_Node) {
         if ($this->_node->last_modified_time instanceof Tinebase_DateTime) {
             $timestamp = $this->_node->last_modified_time->getTimestamp();
         } else {
             $timestamp = $this->_node->creation_time->getTimestamp();
         }
     } else {
         $timestamp = Tinebase_DateTime::now()->getTimestamp();
     }
     return $timestamp;
 }
示例#18
0
 /**
  * try to lock a folder
  *
  * @param  Felamimail_Model_Folder  $_folder  the folder to lock
  * @return bool  true if locking was successful, false if locking was not possible
  */
 public function lockFolder(Felamimail_Model_Folder $_folder)
 {
     $folderData = $_folder->toArray();
     $data = array('cache_timestamp' => Tinebase_DateTime::now()->get(Tinebase_Record_Abstract::ISO8601LONG), 'cache_status' => Felamimail_Model_Folder::CACHE_STATUS_UPDATING);
     $where = array($this->_db->quoteInto($this->_db->quoteIdentifier('id') . ' = ?', $folderData['id']), $this->_db->quoteInto($this->_db->quoteIdentifier('cache_status') . ' = ?', $folderData['cache_status']));
     if (!empty($folderData['cache_timestamp'])) {
         $where[] = $this->_db->quoteInto($this->_db->quoteIdentifier('cache_timestamp') . ' = ?', $folderData['cache_timestamp']);
     }
     $affectedRows = $this->_db->update($this->_tablePrefix . $this->_tableName, $data, $where);
     if ($affectedRows !== 1) {
         return false;
     }
     return true;
 }
示例#19
0
 /**
  * add logout entry to the access log
  *
  * @param string $_sessionId the session id
  * @param string $_ipAddress the ip address the user connects from
  * @return void|Tinebase_Model_AccessLog
  */
 public function setLogout($_sessionId, $_ipAddress = NULL)
 {
     try {
         $loginRecord = $this->_backend->getByProperty($_sessionId, 'sessionid');
     } catch (Tinebase_Exception_NotFound $tenf) {
         Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' Could not find access log login record for session id ' . $_sessionId);
         return;
     }
     $loginRecord->lo = Tinebase_DateTime::now()->get(Tinebase_Record_Abstract::ISO8601LONG);
     if ($_ipAddress !== NULL) {
         $loginRecord->ip = $_ipAddress;
     }
     return $this->update($loginRecord);
 }
 public function testCreateEvent()
 {
     $event = $this->_getEvent();
     $event->creation_time = Tinebase_DateTime::now();
     $persistentEvent = $this->_backend->create($event);
     $event->attendee->cal_event_id = $persistentEvent->getId();
     foreach ($event->attendee as $attender) {
         $this->_backend->createAttendee($attender);
     }
     $loadedPersitentEvent = $this->_backend->get($persistentEvent->getId());
     $this->assertEquals($event->summary, $loadedPersitentEvent->summary);
     $this->_assertAttendee($event->attendee, $loadedPersitentEvent->attendee);
     return $loadedPersitentEvent;
 }
 /**
  * convert date from sent/received
  *
  * @param  string $_dateString
  * @return Zend_Date
  */
 public static function convertDate($_dateString)
 {
     try {
         $date = new Tinebase_DateTime($_dateString ? $_dateString : '@0');
         $date->setTimezone('UTC');
     } catch (Exception $e) {
         // try to fix missing timezone char
         if (preg_match('/UT$/', $_dateString)) {
             $_dateString .= 'C';
         }
         // try some explicit formats
         foreach (self::$dateFormats as $format) {
             $date = DateTime::createFromFormat($format, $_dateString);
             if ($date) {
                 break;
             }
         }
         if (!$date) {
             Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . " Date {$_dateString} could  not be converted to DateTime -> using 1970-01-01 00:00:00.");
             $date = new Tinebase_DateTime('@0');
         }
     }
     return $date;
 }
 /**
  * test start
  * 
  */
 public function testStartCall()
 {
     // remove old call
     try {
         $call = $this->_backend->getCall($this->_objects['call']->getId());
         $backend = Phone_Backend_Factory::factory(Phone_Backend_Factory::CALLHISTORY);
         $backend->delete($this->_objects['call']->getId());
     } catch (Exception $e) {
         // do nothing
     }
     $call = $this->_backend->callStarted($this->_objects['call']);
     $this->assertEquals($this->_objects['call']->destination, $call->destination);
     $this->assertTrue(Tinebase_DateTime::now()->sub($call->start)->getTimestamp() >= 0);
     // sleep for 2 secs (ringing...)
     sleep(2);
 }
 protected function _setReferenceDate()
 {
     // set reference date to the 1st january of last year
     $this->_referenceDate = Tinebase_DateTime::now();
     $this->_referenceDate->setTimezone(Tinebase_Core::getUserTimezone());
     $this->_referenceDate->subYear(1);
     $this->_referenceDate->setDate($this->_referenceDate->format('Y'), 1, 1);
     $this->_referenceDate->setTime(0, 0, 0);
     $this->_referenceYear = $this->_referenceDate->format('Y');
     $this->_lastMonthDays = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
     // find out if year is a leap year
     if ((bool) $this->_referenceDate->format('L')) {
         $this->_isLeapYear = TRUE;
         $this->_lastMonthDays[1] = 29;
     }
 }
示例#24
0
 /**
  * Returns an array with all the child nodes
  *
  * @return Sabre_DAV_INode[]
  */
 function getChildren()
 {
     $filterClass = $this->_application->name . '_Model_' . $this->_model . 'Filter';
     $filter = new $filterClass(array(array('field' => 'container_id', 'operator' => 'equals', 'value' => $this->_container->getId()), array('field' => 'period', 'operator' => 'within', 'value' => array('from' => Tinebase_DateTime::now()->subWeek(4), 'until' => Tinebase_DateTime::now()->addYear(4)))));
     /**
      * see http://forge.tine20.org/mantisbt/view.php?id=5122
      * we must use action 'sync' and not 'get' as
      * otherwise the calendar also return events the user only can see because of freebusy
      */
     $objects = $this->_getController()->search($filter, null, false, false, 'sync');
     $children = array();
     foreach ($objects as $object) {
         $children[] = $this->getChild($object);
     }
     return $children;
 }
 /**
  * import one purchase imvoice file
  * 
  * a new invoice with default data will be created and the invoice file will be attached
  * 
  * @param string $name  name of the invoice
  * @param resource $data  binary data of the invoice (aka a pdf)
  * @throws Sabre\DAV\Exception\Forbidden
  * @return Sales_Model_PurchaseInvoice
  */
 public function importPurchaseInvoice($name, $data)
 {
     // create invoice
     $purchaseInvoice = new Sales_Model_PurchaseInvoice(array('number' => '', 'description' => '', 'date' => Tinebase_DateTime::now(), 'discount' => 0, 'due_in' => 0, 'due_at' => Tinebase_DateTime::now(), 'price_gross' => 0, 'price_net' => 0, 'price_tax' => 0, 'sales_tax' => 0));
     $invoice = $this->create($purchaseInvoice);
     // attach invoice file (aka a pdf)
     $attachmentPath = Tinebase_FileSystem_RecordAttachments::getInstance()->getRecordAttachmentPath($purchaseInvoice, TRUE);
     $handle = Tinebase_FileSystem::getInstance()->fopen($attachmentPath . '/' . $name, 'w');
     if (!is_resource($handle)) {
         throw new Sabre\DAV\Exception\Forbidden('Permission denied to create file:' . $attachmentPath . '/' . $name);
     }
     if (is_resource($data)) {
         stream_copy_to_stream($data, $handle);
     }
     Tinebase_FileSystem::getInstance()->fclose($handle);
     return $this->get($purchaseInvoice);
 }
 /**
  * do the import 
  */
 public function import()
 {
     $this->_log->NOTICE(__METHOD__ . '::' . __LINE__ . ' starting egw import for Adressbook');
     $this->_migrationStartTime = Tinebase_DateTime::now();
     $this->_tineRecordBackend = Addressbook_Backend_Factory::factory(Addressbook_Backend_Factory::SQL);
     $estimate = $this->_getEgwRecordEstimate();
     $this->_log->NOTICE(__METHOD__ . '::' . __LINE__ . " found {$estimate} contacts for migration");
     $pageSize = 100;
     $numPages = ceil($estimate / $pageSize);
     for ($page = 1; $page <= $numPages; $page++) {
         $this->_log->info(__METHOD__ . '::' . __LINE__ . " starting migration page {$page} of {$numPages}");
         Tinebase_Core::setExecutionLifeTime($pageSize * 10);
         $recordPage = $this->_getRawEgwRecordPage($page, $pageSize);
         $this->_migrateEgwRecordPage($recordPage);
     }
     $this->_log->NOTICE(__METHOD__ . '::' . __LINE__ . ' ' . ($this->_importResult['totalcount'] - $this->_importResult['failcount']) . ' contacts imported sucessfully ' . ($this->_importResult['failcount'] ? " {$this->_importResult['failcount']} contacts skipped with failures" : ""));
 }
 /**
  * tests for the contract controller
  */
 public function testUpdateContract()
 {
     $contractController = HumanResources_Controller_Contract::getInstance();
     $employeeController = HumanResources_Controller_Employee::getInstance();
     $contractBackend = new HumanResources_Backend_Contract();
     $employee = $employeeController->create($this->_getEmployee('sclever'));
     $testDate = Tinebase_DateTime::now()->setDate(Tinebase_DateTime::now()->format('Y'), 5, 13);
     $inAMonth = clone $testDate;
     $inAMonth->addMonth(1);
     $threeHrAgo = clone $testDate;
     $threeHrAgo->subHour(3);
     $startDate1 = clone $testDate;
     $startDate1->subMonth(2);
     $startDate2 = clone $testDate;
     $startDate2->subMonth(1);
     $edate1 = clone $startDate2;
     $edate1->addYear(1);
     // contract1 in the past, but created a second ago
     $contract1 = $this->_getContract();
     $contract1->employee_id = $employee->getId();
     $contract1->start_date = $startDate1;
     $contract1->creation_time = $testDate;
     $contract1 = $contractBackend->create($contract1);
     $contract2 = $this->_getContract();
     $contract2->employee_id = $employee->getId();
     $contract2->start_date = $startDate2;
     $contract2->end_date = $edate1;
     $contract2 = $contractBackend->create($contract2);
     // account
     $accountInstance = HumanResources_Controller_Account::getInstance();
     $accountInstance->createMissingAccounts();
     $accountFilter = new HumanResources_Model_AccountFilter(array(array('field' => 'year', 'operator' => 'equals', 'value' => $testDate->format('Y'))));
     $accountFilter->addFilter(new Tinebase_Model_Filter_Text(array('field' => 'employee_id', 'operator' => 'equals', 'value' => $employee->getId())));
     $myAccount = $accountInstance->search($accountFilter)->getFirstRecord();
     $firstDayDate = clone $startDate2;
     $firstDayDate->addDay(3);
     $vacation = new HumanResources_Model_FreeTime(array('status' => 'ACCEPTED', 'employee_id' => $employee->getId(), 'account_id' => $myAccount->getId(), 'type' => 'vacation', 'freedays' => array(array('date' => $firstDayDate, 'duration' => 1))));
     $vacation = HumanResources_Controller_FreeTime::getInstance()->create($vacation);
     $newCalendar = $this->_getFeastCalendar(true);
     // LAST ASSERTION, do not add assertions after an expected Exception, they won't be executed
     $this->setExpectedException('HumanResources_Exception_ContractNotEditable');
     $contract2->feast_calendar_id = $newCalendar->getId();
     $contract2 = $contractController->update($contract2);
     // no more assertions here!
 }
 protected function _createCalls()
 {
     $lineId = $this->_phone->lines[0]['id'];
     $phoneId = $this->_phone->getId();
     $d1 = Tinebase_DateTime::now()->subDay()->setTime(12, 00, 00);
     $d2 = clone $d1;
     $d2->addSecond(10);
     $d3 = clone $d2;
     $d3->addMinute(20);
     $i = 1;
     while ($i < 20) {
         $call = array('line_id' => $lineId, 'phone_id' => $phoneId, 'callerid' => $i * 100, 'start' => $d1, 'connected' => $d2, 'disconnected' => $d3, 'duration' => $d3->getTimestamp() - $d2->getTimestamp(), 'ringing' => $i, 'direction' => $i % 2 ? 'in' : 'out', 'source' => '+49123456789', 'destination' => '+44' . $i . $i . $i . $i);
         Phone_Controller_Call::getInstance()->create(new Phone_Model_Call($call));
         $d1->addMinute(20)->subSecond($i);
         $d2->addMinute(20)->addSecond($i);
         $d3->addMinute(20)->addSecond($i * 1);
         $i++;
     }
 }
 /**
  * Sets up the fixture.
  * This method is called before a test is executed.
  *
  * @access protected
  */
 protected function setUp()
 {
     $GLOBALS['Crm_ControllerTest'] = isset($GLOBALS['Crm_ControllerTest']) || array_key_exists('Crm_ControllerTest', $GLOBALS) ? $GLOBALS['Crm_ControllerTest'] : array();
     $personalContainer = Tinebase_Container::getInstance()->getPersonalContainer(Zend_Registry::get('currentAccount'), 'Crm', Zend_Registry::get('currentAccount'), Tinebase_Model_Grants::GRANT_EDIT);
     if ($personalContainer->count() === 0) {
         $this->_testContainer = Tinebase_Container::getInstance()->addPersonalContainer(Zend_Registry::get('currentAccount')->accountId, 'Crm', 'PHPUNIT');
     } else {
         $this->_testContainer = $personalContainer[0];
     }
     $this->_objects['initialLead'] = new Crm_Model_Lead(array('lead_name' => 'PHPUnit', 'leadstate_id' => 1, 'leadtype_id' => 1, 'leadsource_id' => 1, 'container_id' => $this->_testContainer->id, 'start' => Tinebase_DateTime::now(), 'description' => 'Description', 'end' => Tinebase_DateTime::now(), 'turnover' => '200000', 'probability' => 70, 'end_scheduled' => Tinebase_DateTime::now()));
     $this->_objects['updatedLead'] = new Crm_Model_Lead(array('lead_name' => 'PHPUnit', 'leadstate_id' => 1, 'leadtype_id' => 1, 'leadsource_id' => 1, 'container_id' => $this->_testContainer->id, 'start' => Tinebase_DateTime::now(), 'description' => 'Description updated', 'end' => NULL, 'turnover' => '200000', 'probability' => 70, 'end_scheduled' => NULL));
     $addressbookPersonalContainer = Tinebase_Container::getInstance()->getPersonalContainer(Zend_Registry::get('currentAccount'), 'Addressbook', Zend_Registry::get('currentAccount'), Tinebase_Model_Grants::GRANT_EDIT);
     $addressbookContainer = $addressbookPersonalContainer[0];
     $this->_objects['user'] = new Addressbook_Model_Contact(array('adr_one_countryname' => 'DE', 'adr_one_locality' => 'Hamburg', 'adr_one_postalcode' => '24xxx', 'adr_one_region' => 'Hamburg', 'adr_one_street' => 'Pickhuben 4', 'adr_one_street2' => 'no second street', 'adr_two_countryname' => 'DE', 'adr_two_locality' => 'Hamburg', 'adr_two_postalcode' => '24xxx', 'adr_two_region' => 'Hamburg', 'adr_two_street' => 'Pickhuben 4', 'adr_two_street2' => 'no second street2', 'assistent' => 'Cornelius Weiß', 'bday' => '1975-01-02 03:04:05', 'email' => '*****@*****.**', 'email_home' => '*****@*****.**', 'note' => 'Bla Bla Bla', 'container_id' => $addressbookContainer->id, 'role' => 'Role', 'title' => 'Title', 'url' => 'http://www.tine20.org', 'url_home' => 'http://www.tine20.com', 'n_family' => 'Kneschke', 'n_fileas' => 'Kneschke, Lars', 'n_given' => 'Lars', 'n_middle' => 'no middle name', 'n_prefix' => 'no prefix', 'n_suffix' => 'no suffix', 'org_name' => 'Metaways Infosystems GmbH', 'org_unit' => 'Tine 2.0', 'tel_assistent' => '+49TELASSISTENT', 'tel_car' => '+49TELCAR', 'tel_cell' => '+49TELCELL', 'tel_cell_private' => '+49TELCELLPRIVATE', 'tel_fax' => '+49TELFAX', 'tel_fax_home' => '+49TELFAXHOME', 'tel_home' => '+49TELHOME', 'tel_pager' => '+49TELPAGER', 'tel_work' => '+49TELWORK'));
     $tasksPersonalContainer = Tinebase_Container::getInstance()->getPersonalContainer(Zend_Registry::get('currentAccount'), 'Tasks', Zend_Registry::get('currentAccount'), Tinebase_Model_Grants::GRANT_EDIT);
     $tasksContainer = $tasksPersonalContainer[0];
     // create test task
     $this->_objects['task'] = new Tasks_Model_Task(array('container_id' => $tasksContainer->id, 'created_by' => Zend_Registry::get('currentAccount')->getId(), 'creation_time' => Tinebase_DateTime::now(), 'percent' => 70, 'due' => Tinebase_DateTime::now()->addMonth(1), 'summary' => 'phpunit: crm test task'));
     $this->objects['note'] = new Tinebase_Model_Note(array('note_type_id' => 1, 'note' => 'phpunit test note'));
 }
示例#30
0
 /**
  * gets the personal calendar of given user
  * 
  * @param  string $_userId
  * @return Tinebase_Model_Container
  */
 protected function _getPersonalCalendar($_userId)
 {
     if (!array_key_exists($_userId, $this->_personalCalendarCache)) {
         // get calendar by preference to ensure its the default personal
         $defaultCalendarId = Tinebase_Core::getPreference('Calendar')->getValueForUser(Calendar_Preference::DEFAULTCALENDAR, $_userId, Tinebase_Acl_Rights::ACCOUNT_TYPE_USER);
         $calendar = Tinebase_Container::getInstance()->getContainerById($defaultCalendarId);
         // detect if container just got created
         $isNewContainer = false;
         if ($calendar->creation_time instanceof DateTime) {
             $isNewContainer = $this->_migrationStartTime->isEarlier($calendar->creation_time);
         }
         if ($isNewContainer && $this->_config->setPersonalCalendarGrants || $this->_config->forcePersonalCalendarGrants) {
             // resolve grants based on user/groupmemberships
             $grants = $this->getGrantsByOwner('Calendar', $_userId);
             Tinebase_Container::getInstance()->setGrants($calendar->getId(), $grants, TRUE);
         }
         $this->_personalCalendarCache[$_userId] = $calendar;
     }
     return $this->_personalCalendarCache[$_userId];
 }