/** * The file name to use for final storage, minus the extension * * @param string $controller Name of controller (or other id) * @return string */ public function getLongtermFileName($controller) { $date = new \MUtil_Date(); $name[] = $controller; $name[] = $date->toString('YYYY-MM-ddTHH-mm-ss'); $name[] = preg_replace('/[^a-zA-Z0-9_]/', '', $this->currentUser->getLoginName()); $name[] = $this->getOrganizationCode(); return implode('.', array_filter($name)); }
/** * When saving a date by using a string, it should work too */ public function testSetDateFields() { $respondentTrack = $this->loader->getTracker()->getRespondentTrack(1); // $expected = $respondentTrack->getFieldData(); $date = new \MUtil_Date('2010-11-09', 'yyyy-MM-dd'); $expected = array('f__1' => 'newvalue', 'code' => 'newvalue', 'f__2' => $date, 'datecode' => $date); $actual = $respondentTrack->setFieldData(array('code' => 'newvalue', 'datecode' => $date->toString('yyyy-MM-dd'))); $this->assertArrayWithDateMatch($expected, $actual, '', 1, 0); }
/** * Formats an until date for this display * * @param \MUtil_Date $dateTime * @return string */ public function formatUntil(\MUtil_Date $dateTime = null) { if (null === $dateTime) { return $this->_('Survey has no time limit.'); } $days = $dateTime->diffDays(); switch ($days) { case 0: return array(\MUtil_Html::create('strong', $this->_('Warning!!!')), ' ', $this->_('This survey must be answered today!')); case 1: return array(\MUtil_Html::create('strong', $this->_('Warning!!')), ' ', $this->_('This survey can only be answered until tomorrow!')); case 2: return $this->_('Warning! This survey can only be answered for another 2 days!'); default: if ($days <= 14) { return sprintf($this->_('Please answer this survey within %d days.'), $days); } if ($days <= 0) { return $this->_('This survey can no longer be answered.'); } return sprintf($this->_('Please answer this survey before %s.'), $dateTime->toString($this->dateFormat)); } }
/** * Check this respondent track for the number of tokens completed / to do * * @param int $userId Id of the user who takes the action (for logging) * @return int 1 if the track was changed by this code */ public function _checkTrackCount($userId) { $sqlCount = 'SELECT COUNT(*) AS count, SUM(CASE WHEN gto_completion_time IS NULL THEN 0 ELSE 1 END) AS completed FROM gems__tokens INNER JOIN gems__reception_codes ON gto_reception_code = grc_id_reception_code AND grc_success = 1 WHERE gto_id_respondent_track = ?'; $counts = $this->db->fetchRow($sqlCount, $this->_respTrackId); if (!$counts) { $counts = array('count' => 0, 'completed' => 0); } $values['gr2t_count'] = intval($counts['count']); $values['gr2t_completed'] = intval($counts['completed']); if (!$this->_respTrackData['gr2t_end_date_manual']) { $values['gr2t_end_date'] = $this->calculateEndDate(); } if ($values['gr2t_count'] == $values['gr2t_completed']) { if (null === $this->_respTrackData['gr2t_end_date']) { $now = new \MUtil_Date(); $values['gr2t_end_date'] = $now->toString(\Gems_Tracker::DB_DATETIME_FORMAT); } //Handle TrackCompletionEvent, send only changed fields in $values array $this->handleTrackCompletion($values, $userId); } // Remove unchanged values $this->tracker->filterChangesOnly($this->_respTrackData, $values); return $this->_updateTrack($values, $userId); }
/** * Overrule this function to adapt the display of the agenda items for each project * * @see \Gems_Agenda_Appointment->getDisplayString() * * @param array $row Row containing result select * @return string */ public function getAppointmentDisplay(array $row) { $date = new \MUtil_Date($row['gap_admission_time'], 'yyyy-MM-dd HH:mm:ss'); $results[] = $date->toString($this->appointmentDisplayFormat); if ($row['gaa_name']) { $results[] = $row['gaa_name']; } if ($row['gapr_name']) { $results[] = $row['gapr_name']; } if ($row['glo_name']) { $results[] = $row['glo_name']; } return implode($this->_('; '), $results); }
/** * Function to allow the creation of search defaults in code * * @see getSearchFilter() * * @return array */ public function getSearchDefaults() { if (!$this->defaultSearchData) { $inFormat = \MUtil_Model_Bridge_FormBridge::getFixedOption('date', 'dateFormat'); $now = new \MUtil_Date(); $today = $now->toString($inFormat); $this->defaultSearchData = array('datefrom' => $today, 'dateused' => '_gto_valid_from gto_valid_until', 'dateuntil' => $today, 'main_filter' => 'all'); } return parent::getSearchDefaults(); }
/** * Checks whether the survey for this token was completed and processes the result * * @param int $userId The id of the gems user * @return int self::COMPLETION_NOCHANGE || (self::COMPLETION_DATACHANGE | self::COMPLETION_EVENTCHANGE) */ public function checkTokenCompletion($userId) { $result = self::COMPLETION_NOCHANGE; // Some defaults $values['gto_completion_time'] = null; $values['gto_duration_in_sec'] = null; $values['gto_result'] = null; if ($this->inSource()) { $survey = $this->getSurvey(); $values['gto_in_source'] = 1; $startTime = $survey->getStartTime($this); if ($startTime instanceof \MUtil_Date) { // Value from source overrules any set date time $values['gto_start_time'] = $startTime->toString(\Gems_Tracker::DB_DATETIME_FORMAT); } else { // Otherwise use the time kept by Gems. $startTime = $this->getDateTime('gto_start_time'); //What if we have older tokens... where no gto_start_time was set?? if (is_null($startTime)) { $startTime = new \MUtil_Date(); } // No need to set $values['gto_start_time'], it does not change } // If there is a start date there can be a completion date if ($startTime instanceof \MUtil_Date) { if ($survey->isCompleted($this)) { $complTime = $survey->getCompletionTime($this); $setCompletionTime = true; if (!$complTime instanceof \MUtil_Date) { // Token is completed but the source cannot tell the time // // Try to see it was stored already $complTime = $this->getDateTime('gto_completion_time'); if ($complTime instanceof \MUtil_Date) { // Again no need to change a time that did not change unset($values['gto_completion_time']); $setCompletionTime = false; } else { // Well anyhow it was completed now or earlier. Get the current moment. $complTime = new \MUtil_Date(); } } //Set completion time for completion event if ($setCompletionTime) { $values['gto_completion_time'] = $complTime->toString(\Gems_Tracker::DB_DATETIME_FORMAT); //Save the old value $originalCompletionTime = $this->_gemsData['gto_completion_time']; $this->_gemsData['gto_completion_time'] = $values['gto_completion_time']; } // Process any Gems side survey dependent changes if ($changed = $this->handleAfterCompletion()) { // Communicate change $result += self::COMPLETION_EVENTCHANGE; if (\Gems_Tracker::$verbose) { \MUtil_Echo::r($changed, 'Source values for ' . $this->_tokenId . ' changed by event.'); } } if ($setCompletionTime) { //Reset to old value, so changes will be picked up $this->_gemsData['gto_completion_time'] = $originalCompletionTime; } $values['gto_duration_in_sec'] = max($complTime->diffSeconds($startTime), 0); //If the survey has a resultfield, store it if ($resultField = $survey->getResultField()) { $rawAnswers = $this->getRawAnswers(); if (isset($rawAnswers[$resultField])) { // Cast to string, because that is the way the result is stored in the db // not casting to strings means e.g. float results always result in // an update, even when they did not change. $values['gto_result'] = (string) $rawAnswers[$resultField]; // Chunk of text that is too long if ($len = $this->_getResultFieldLength()) { $values['gto_result'] = substr($values['gto_result'], 0, $len); } } } if ($this->project->hasResponseDatabase()) { $this->toResponseDatabase($userId); } } } } else { $values['gto_in_source'] = 0; $values['gto_start_time'] = null; } if ($this->_updateToken($values, $userId)) { // Communicate change $result += self::COMPLETION_DATACHANGE; } return $result; }
/** * Get the filename to use * * @param int $index * @return string */ protected function _getLogFileName($index = null) { switch ($this->_logRotate) { case self::ROTATE_PER_MONTH: if (null === $index) { $now = new \MUtil_Date(); $index = $now->toString(\Zend_Date::MONTH); } elseif ($index < 10) { $index = "0" . $index; } $filename = $this->_logFileRoot . '-mon-' . $index . '.log'; break; case self::ROTATE_PER_MONTH: if (null === $index) { $now = new \MUtil_Date(); $index = $now->toString(\Zend_Date::WEEK); } elseif ($index < 10) { $index = "0" . $index; } $filename = $this->_logFileRoot . '-wk-' . $index . '.log'; break; default: $filename = $this->_logFileRoot; if (!\MUtil_String::endsWith($filename, '.log')) { $filename .= '.log'; } break; } return $filename; }
/** * * @param \MUtil_Date $from Optional date after which the appointment must occur * @param \MUtil_Date $until Optional date before which the appointment must occur * @param boolean $sortAsc Retrieve first or last appointment first * @return \Gems\Agenda\AppointmentSelect */ public function forPeriod(\MUtil_Date $from = null, \MUtil_Date $until = null, $sortAsc = true) { if ($from) { $this->_select->where("gap_admission_time >= ?", $from->toString('yyyy-MM-dd HH:mm:ss')); } if ($until) { $this->_select->where("gap_admission_time <= ?", $until->toString('yyyy-MM-dd HH:mm:ss')); } if ($sortAsc) { $this->order('gap_admission_time ASC'); } else { $this->order('gap_admission_time DESC'); } return $this; }
/** * When saving a date by using a string, it should work too */ public function testSetDateFields() { $trackData = array('gr2t_id_respondent_track' => 1, 'gr2t_id_track' => 1); $respondentTrack = new Gems_Tracker_RespondentTrack($trackData); $respondentTrack->answerRegistryRequest('tracker', $this->tracker); $expected = $respondentTrack->getFieldData(); $date = new MUtil_Date('2010-11-09', 'yyyy-MM-dd'); $expected = array('f__1' => 'newvalue', 'code' => 'newvalue', 'f__2' => $date, 'datecode' => $date); $actual = $respondentTrack->setFieldData(array('code' => 'newvalue', 'datecode' => $date->toString('yyyy-MM-dd'))); $this->assertArrayWithDateMatch($expected, $actual, '', 1, 0); }