Пример #1
0
 /**
  * Returns not the IDs of the item, module, user, etc. but real values.
  *
  * @param integer $userId The ID of the user who calls this method.
  *
  * @return array Array with 'user', 'module', 'process', 'description', 'itemId',
  *                          'item', 'projectId', 'details', 'time' and 'project'.
  */
 public function getMessage($userId)
 {
     $messageData = $this->getMessageData($userId);
     $data = array();
     $this->_deleteOutdatedMessages();
     if (true === empty($messageData)) {
         return false;
     }
     $userObject = new Phprojekt_User_User();
     $user = $userObject->find($messageData[0]->actorId);
     $data['user'] = $userObject->displayName;
     $data['module'] = ucfirst(Phprojekt_Module::getModuleName($messageData[0]->moduleId));
     $data['process'] = $messageData[0]->process;
     $data['description'] = Phprojekt::getInstance()->translate($messageData[0]->description);
     $data['itemId'] = $messageData[0]->itemId;
     $data['item'] = $messageData[0]->itemName;
     $data['projectId'] = $messageData[0]->projectId;
     $data['details'] = $messageData[0]->details;
     // Convert time to user timezone
     if ($messageData[0]->process == Phprojekt_Notification::LAST_ACTION_REMIND) {
         $addTime = Phprojekt::getInstance()->getConfig()->remindBefore * 60;
     } else {
         $addTime = 0;
     }
     $data['time'] = date("H:i", Phprojekt_Converter_Time::utcToUser($messageData[0]->validFrom) + $addTime);
     // Convert project name
     $project = new Project_Models_Project();
     $data['project'] = $project->find($data['projectId'])->title;
     return $data;
 }
Пример #2
0
 /**
  * Excludes the given date from this series.
  * Do not call save() after this, or you might reset the rrule to the old value.
  *
  * @param Datetime $date The date to remove
  *
  * @return void
  */
 protected function _excludeDate(Datetime $date)
 {
     // This function distinguishes three cases.
     // 1. This is the first event in the series.
     // 2. This is the last event in the series.
     // 3. Somewhere in between.
     if (empty($this->id)) {
         throw new Exception('Can only exclude dates from saved events');
     }
     $series = clone $this;
     $series->find($this->id);
     $helper = $series->getRruleHelper();
     if (!$helper->containsDate($date)) {
         throw new Exception('Trying to exclude date that is not part of this series');
     }
     $start = new Datetime('@' . Phprojekt_Converter_Time::userToUtc($series->start));
     $end = new Datetime('@' . Phprojekt_Converter_Time::userToUtc($series->end));
     if ($start == $date) {
         // If it's the first in it's series, adjust the start date,
         // remove excluded dates that we skipped while doing that and
         // finally, check if we still need a rrule at all.
         $duration = $start->diff($end);
         $newStart = $helper->firstOccurrenceAfter($start);
         if (is_null($newStart)) {
             throw new Exception('$newStart should not be null');
         }
         $newEnd = clone $newStart;
         $newEnd->add($duration);
         $series->start = Phprojekt_Converter_Time::utcToUser($newStart->format('Y-m-d H:i:s'));
         $series->end = Phprojekt_Converter_Time::utcToUser($newEnd->format('Y-m-d H:i:s'));
         // Delete all obsolete excludes
         $db = $this->getAdapter();
         $where = $db->quoteInto('calendar2_id = ?', $this->id);
         $where .= $db->quoteInto('AND date < ?', $newStart->format('Y-m-d H:i:s'));
         $db->delete('calendar2_excluded_dates', $where);
         // Check if this is still a recurring event
         if ($helper->islastOccurrence($newStart)) {
             $series->rrule = null;
         }
         $series->save();
     } elseif ($helper->isLastOccurrence($date)) {
         // If it's the last in it's series, adjust the Rrule and delete
         // now obsolete excludes.
         $newLast = $helper->lastOccurrenceBefore($date);
         // Check if this is still a recurring event
         if ($helper->isFirstOccurrence($newLast)) {
             $series->rrule = null;
         } else {
             // Adjust the rrule
             $series->rrule = preg_replace('/UNTIL=[^;]*/', "UNTIL={$newLast->format('Ymd\\THis\\Z')}", $series->rrule);
         }
         $series->save();
         // Delete all obsolete excludes
         $db = $this->getAdapter();
         $where = $db->quoteInto('calendar2_id = ?', $this->id);
         $where .= $db->quoteInto('AND date > ?', $newLast->format('Y-m-d H:i:s'));
         $db->delete('calendar2_excluded_dates', $where);
     } else {
         // If it's somewhere in between, just add it to the list of
         // excluded dates.
         $this->getAdapter()->insert('calendar2_excluded_dates', array('calendar2_id' => $this->id, 'date' => $date->format('Y-m-d H:i:s')));
     }
 }
Пример #3
0
 /**
  * Return a value for get, using some validations from the table data.
  *
  * @param string $type  Type of field.
  * @param mixed  $value Value to transform.
  *
  * @return mixed Value of the var.
  */
 public static function get($type, $value)
 {
     switch ($type) {
         case 'float':
             $value = Zend_Locale_Format::toFloat($value, array('precision' => 2));
             break;
         case 'time':
             if (!empty($value)) {
                 $value = date("H:i:s", Phprojekt_Converter_Time::utcToUser($value));
             }
             break;
         case 'datetime':
         case 'timestamp':
             if (!empty($value)) {
                 $value = date("Y-m-d H:i:s", Phprojekt_Converter_Time::utcToUser($value));
             }
             break;
         case 'text':
             // Get html only if the text contain some html code
             if (preg_match("/([\\<])([^\\>]{1,})*([\\>])/i", $value)) {
                 $value = stripslashes($value);
             }
             break;
     }
     return $value;
 }
Пример #4
0
 private function applyICalendarTimes($start, $end, $timezoneID = null)
 {
     $utc = new DateTimezone('UTC');
     $timezone = null;
     $userTimeZone = Phprojekt_User_User::getUserDateTimeZone();
     if ('Z' === substr($start, -1)) {
         $timezone = $utc;
     } else {
         if (!is_null($timezoneID)) {
             $timezone = new DateTimeZone($timezoneID);
         } else {
             $timezone = $userTimeZone;
         }
     }
     // We can't use ->setTimezone with the timezones returned by getUserDateTimeZone, as these are non-standard
     // timezones. Unless we start storing correct timezones, we can't directly set the user timezone, so we go to
     // UTC and convert to usertime from there. Because utcToUser returns a unix timestamp, but ActiveRecords expects
     // a "Y-m-d H:i:s" timestamp, we have to go through Datetime again.
     $start = new Datetime($start, $timezone);
     $start->setTimezone($utc);
     $startTs = Phprojekt_Converter_Time::utcToUser($start->format('Y-m-d H:i:s'));
     $start = new Datetime('@' . $startTs);
     $end = new Datetime($end, $timezone);
     $end->setTimezone($utc);
     $endTs = Phprojekt_Converter_Time::utcToUser($end->format('Y-m-d H:i:s'));
     $end = new Datetime('@' . $endTs);
     if ($start->diff($end)->invert) {
         throw new Sabre_DAV_Exception_BadRequest('Start must be before End');
     }
     $this->_timecard->startDatetime = $start->format('Y-m-d H:i:s');
     if ($start->format('z') == $end->format('z')) {
         // Same day
         $this->_timecard->endTime = $end->format('H:i:s');
     } else {
         $this->_timecard->endTime = '23:59:00';
     }
 }