예제 #1
0
 /**
  * Return a value for set, using some validations from the table data.
  *
  * @param string $type  Type of field.
  * @param mixed  $value Value to transform.
  *
  * @return mixed Sanitized value.
  */
 public static function set($type, $value)
 {
     switch ($type) {
         case 'int':
             $value = Cleaner::sanitize('integer', $value, 0);
             break;
         case 'float':
             $value = Cleaner::sanitize('float', $value, 0);
             if ($value !== false) {
                 $value = Zend_Locale_Format::getFloat($value, array('precision' => 2));
             } else {
                 $value = 0;
             }
             break;
         case 'date':
             $value = Cleaner::sanitize('date', $value);
             break;
         case 'time':
             $value = Cleaner::sanitize('time', $value);
             $value = date("H:i:s", Phprojekt_Converter_Time::userToUtc($value));
             break;
         case 'datetime':
         case 'timestamp':
             $value = Cleaner::sanitize('timestamp', $value);
             $value = date("Y-m-d H:i:s", Phprojekt_Converter_Time::userToUtc($value));
             break;
         case 'text':
             if (is_array($value)) {
                 // if given value for a text field is an array, it's from a MultiSelect field
                 $value = implode(',', $value);
             }
             // Run html sanitize only if the text contain some html code
             if (preg_match("/([\\<])([^\\>]{1,})*([\\>])/i", $value)) {
                 $value = Cleaner::sanitize('html', $value);
             } else {
                 $value = Cleaner::sanitize('string', $value);
             }
             break;
         default:
             $value = Cleaner::sanitize('string', $value);
             break;
     }
     return $value;
 }
예제 #2
0
 /**
  * Apply the timezone to one datetime for use it in the database.
  *
  * @param string $dateTime The datetime to transform.
  *
  * @return string Datetime string.
  */
 public function applyTimeZone($dateTime)
 {
     return date("Y-m-d H:i:s", Phprojekt_Converter_Time::userToUtc($dateTime));
 }
예제 #3
0
 /**
  * Defines the datetime from which the generated frontend message is valid.
  *
  * @return string Datetime string.
  */
 public function getCalendarValidFrom()
 {
     $date = Phprojekt_Converter_Time::userToUtc($this->_model->startDatetime);
     $configMin = Phprojekt::getInstance()->getConfig()->remindBefore;
     $configMinInSec = $configMin * 60;
     return date("Y-m-d H:i:s", $date - $configMinInSec);
 }
예제 #4
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')));
     }
 }
예제 #5
0
 /**
  * Converts a timecard join project join module row to a vobject string.
  *
  * @param array $entry
  *
  * @return string
  */
 private function _getDataForEntry(array $entry)
 {
     $v = new Sabre_VObject_Component('vevent');
     if (1 == $entry['project_id']) {
         $v->add('summary', Phprojekt::getInstance()->translate('Unassigned'));
     } else {
         $v->add('summary', $entry['title'] . ' [' . $entry['project_id'] . ']');
     }
     $notes = trim($entry['notes']);
     if (!is_null($entry['module_id'])) {
         if ($notes) {
             $notes .= "\n";
         }
         $notes .= Phprojekt::getInstance()->translate('There is an attachment of type ') . Phprojekt::getInstance()->translate($entry['label']);
     }
     if ($notes) {
         $v->add('description', $notes);
     }
     $start = new DateTime('@' . Phprojekt_Converter_Time::userToUtc($entry['start_datetime']));
     $end = substr($entry['start_datetime'], 0, 11) . $entry['end_time'];
     $end = new DateTime('@' . Phprojekt_Converter_Time::userToUtc($end));
     $v->add('dtstart', $start->format('Ymd\\THis\\Z'));
     $v->add('dtend', $end->format('Ymd\\THis\\Z'));
     $v->add('uid', 'phprojekt-timecard-entry' . $entry['uid']);
     $calendarData = new Sabre_VObject_Component('vcalendar');
     $calendarData->add('version', '2.0');
     $calendarData->add('prodid', 'Phprojekt ' . Phprojekt::getVersion());
     $calendarData->add($v);
     return $calendarData->serialize();
 }
예제 #6
0
 /**
  * Convert the rule and value into a real where clause.
  *
  * @param string $field      Field for filter.
  * @param string $identifier Converted field for filter.
  * @param string $rule       Rule for apply the filter.
  * @param string $keyword    Value used for filter.
  *
  * @return string Where clause.
  */
 private function _convertRule($field, $identifier, $rule, $keyword)
 {
     // Sanitize values
     if ($this->_info['metadata'][$identifier]['DATA_TYPE'] == 'time') {
         // Moving the value to UTC
         $identifier = $this->_record->getTableName() . '.' . $identifier;
         $identifier = Phprojekt::getInstance()->getDb()->quoteIdentifier($identifier);
         $value = Cleaner::sanitize('time', $keyword);
         $k = date("H:i:s", Phprojekt_Converter_Time::userToUtc($value));
         //$identifier = 'TIME(' . $identifier . ')';
     } else {
         if ($this->_info['metadata'][$identifier]['DATA_TYPE'] == 'datetime') {
             $identifier = $this->_record->getTableName() . '.' . $identifier;
             $identifier = Phprojekt::getInstance()->getDb()->quoteIdentifier($identifier);
             if (strstr($keyword, '-')) {
                 // Use it as date
                 $k = Cleaner::sanitize('date', $keyword);
                 $identifier = 'DATE(' . $identifier . ')';
             } else {
                 if (strstr($keyword, ':')) {
                     // Use it as time
                     $value = Cleaner::sanitize('time', $keyword);
                     $k = date("H:i:s", Phprojekt_Converter_Time::userToUtc($value));
                     $identifier = 'TIME(' . $identifier . ')';
                 } else {
                     // Use it as datetime
                     $value = Cleaner::sanitize('timestamp', $keyword);
                     $k = date("Y-m-d H:i:s", Phprojekt_Converter_Time::userToUtc($value));
                 }
             }
         } else {
             $keyword = mb_strtolower($keyword, 'UTF-8');
             $k = $keyword;
             $identifier = $this->_record->getTableName() . '.' . $identifier;
             $identifier = Phprojekt::getInstance()->getDb()->quoteIdentifier($identifier);
         }
     }
     switch ($rule) {
         case 'equal':
             $w = $identifier . ' = ? ';
             break;
         case 'notEqual':
             $w = $identifier . ' != ? ';
             break;
         case 'major':
             $w = $identifier . ' > ? ';
             break;
         case 'majorEqual':
             $w = $identifier . ' >= ? ';
             break;
         case 'minor':
             $w = $identifier . ' < ? ';
             break;
         case 'minorEqual':
             $w = $identifier . ' <= ? ';
             break;
         case 'begins':
             $w = $identifier . ' LIKE ? ';
             $k = $keyword . '%';
             break;
         case 'ends':
             $w = $identifier . ' LIKE ? ';
             $k = '%' . $keyword;
             break;
         case 'notLike':
             $w = $identifier . ' NOT LIKE ? ';
             $k = '%' . $keyword . '%';
             break;
         case 'like':
         default:
             $w = $identifier . ' LIKE ? ';
             $k = '%' . $keyword . '%';
     }
     return Phprojekt::getInstance()->getDb()->quoteInto($w, $k);
 }