/** * tests the corret handling of the usertimezone in the date filter */ public function testDateIntervalFilter() { $taController = Timetracker_Controller_Timeaccount::getInstance(); $tsController = Timetracker_Controller_Timesheet::getInstance(); $dateString = '2014-07-14 00:15:00'; $date = new Tinebase_DateTime($dateString, Tinebase_Core::getUserTimezone()); $ta = $taController->create(new Timetracker_Model_Timeaccount(array('number' => '123', 'title' => 'test'))); $r = new Timetracker_Model_Timesheet(array('timeaccount_id' => $ta->getId(), 'account_id' => Tinebase_Core::getUser()->getId(), 'description' => 'lazy boring', 'start_date' => $date, 'duration' => 30)); $r->setTimezone('UTC'); $ts = $tsController->create($r); $filter = new Timetracker_Model_TimesheetFilter(array()); $dateFilter = new Tinebase_Model_Filter_DateMock(array('field' => 'start_date', 'operator' => "within", "value" => "weekThis")); $dateFilter::$testDate = $date; $filter->addFilter($dateFilter); $results = $tsController->search($filter); $this->assertEquals(1, $results->count()); }
/** * create tine timesheet * * @param Timetracker_Model_Timesheet $_record * @param string $_timeaccountId * @return Timetracker_Model_Timesheet * */ protected function _createTimesheet($_record, $_timeaccountId) { $_record->timeaccount_id = $_timeaccountId; // check if user is available try { Tinebase_User::getInstance()->getUserById($_record->account_id); } catch (Tinebase_Exception_NotFound $enf) { //echo " Couldn't find user with id " . $_record->account_id . "\n"; return NULL; } if ($_record->isValid()) { Timetracker_Controller_Timesheet::getInstance()->create($_record); } else { echo " Timesheet invalid: " . print_r($_record->getValidationErrors(), true) . "\n"; return NULL; } $this->_counters['timesheets']++; }
/** * get Timesheet (create timeaccount as well) * * @param array fields data * @param boolean force creation of the record * @return Timetracker_Model_Timesheet */ protected function _getTimesheet($_data = array(), $_forceCreation = false) { $defaultData = array('account_id' => Tinebase_Core::getUser()->getId(), 'description' => 'blabla', 'duration' => 30, 'timeaccount_id' => NULL, 'start_date' => NULL); $data = array_replace($defaultData, $_data); if ($data['timeaccount_id'] === NULL) { $timeaccount = Timetracker_Controller_Timeaccount::getInstance()->create($this->_getTimeaccount()); $data['timeaccount_id'] = $timeaccount->getId(); } if ($data['start_date'] === NULL) { $data['start_date'] = Tinebase_DateTime::now()->toString('Y-m-d'); } $ts = new Timetracker_Model_Timesheet($data, TRUE); if ($_forceCreation) { $tsRec = $this->_json->saveTimesheet($ts->toArray()); $this->_lastCreatedRecord = $tsRec; } return $ts; }