Exemplo n.º 1
0
 /**
  * resolve tag ids to tag record
  * 
  * @todo find a generic solution for this!
  */
 protected function _resolveClientRecordTags()
 {
     if (!$this->_clientRecord->has('tags') || empty($this->_clientRecord->tags)) {
         return;
     }
     $tags = new Tinebase_Record_RecordSet('Tinebase_Model_Tag');
     foreach ($this->_clientRecord->tags as $tag) {
         if (is_string($tag)) {
             $tag = Tinebase_Tags::getInstance()->get($tag);
         }
         $tags->addRecord($tag);
     }
     $this->_clientRecord->tags = $tags;
 }
 /**
  * creates recordsets for depedent records or records instead of arrays for records on record fields
  * and sets timezone of these records to utc
  *
  * @param Tinebase_Record_Abstract $record
  */
 protected function _dependentRecordsFromJson(&$record)
 {
     $config = $record::getConfiguration();
     if ($config) {
         $recordsFields = $config->recordsFields;
         if ($recordsFields) {
             foreach (array_keys($recordsFields) as $property) {
                 $rcn = $recordsFields[$property]['config']['recordClassName'];
                 if ($record->has($property) && $record->{$property} && is_array($record->{$property})) {
                     $recordSet = new Tinebase_Record_RecordSet($rcn);
                     foreach ($record->{$property} as $recordArray) {
                         if (is_array($recordArray)) {
                             $srecord = new $rcn(array(), true);
                             $srecord->setFromJsonInUsersTimezone($recordArray);
                             $recordSet->addRecord($srecord);
                         } else {
                             if (Tinebase_Core::isLogLevel(Zend_Log::ERR)) {
                                 Tinebase_Core::getLogger()->err(__METHOD__ . '::' . __LINE__ . ' Record array expected, got: ' . $recordArray);
                             }
                             throw new Tinebase_Exception_InvalidArgument('Record array expected');
                         }
                         $record->{$property} = $recordSet;
                     }
                 }
             }
         }
     }
 }
 /**
  * resolves container_id property
  * 
  * @param Tinebase_Record_Abstract $_record
  * @param string $_containerProperty
  */
 public static function resolveContainerOfRecord($_record, $_containerProperty = 'container_id')
 {
     if (!$_record instanceof Tinebase_Record_Abstract) {
         return;
     }
     if (!$_record->has($_containerProperty) || empty($_record->{$_containerProperty})) {
         return;
     }
     try {
         $container = Tinebase_Container::getInstance()->getContainerById($_record->{$_containerProperty});
     } catch (Tinebase_Exception_NotFound $tenf) {
         if (Tinebase_Core::isLogLevel(Zend_Log::NOTICE)) {
             Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . ' ' . $tenf);
         }
         return;
     }
     $container->resolveGrantsAndPath();
     $_record->{$_containerProperty} = $container;
 }
 /**
  * sets record modification data and protects it from spoofing
  * 
  * @param   Tinebase_Record_Abstract $_newRecord record from user data
  * @param   string                    $_action    one of {create|update|delete}
  * @param   Tinebase_Record_Abstract $_curRecord record from storage
  * @throws  Tinebase_Exception_InvalidArgument
  */
 public static function setRecordMetaData($_newRecord, $_action, $_curRecord = NULL)
 {
     // disable validation as this is slow and we are setting valid data here
     $bypassFilters = $_newRecord->bypassFilters;
     $_newRecord->bypassFilters = TRUE;
     list($currentAccountId, $currentTime) = self::getCurrentAccountIdAndTime();
     // spoofing protection
     $_newRecord->created_by = $_curRecord ? $_curRecord->created_by : NULL;
     $_newRecord->creation_time = $_curRecord ? $_curRecord->creation_time : NULL;
     $_newRecord->last_modified_by = $_curRecord ? $_curRecord->last_modified_by : NULL;
     $_newRecord->last_modified_time = $_curRecord ? $_curRecord->last_modified_time : NULL;
     if ($_newRecord->has('is_deleted')) {
         $_newRecord->is_deleted = $_curRecord ? $_curRecord->is_deleted : 0;
         $_newRecord->deleted_time = $_curRecord ? $_curRecord->deleted_time : NULL;
         $_newRecord->deleted_by = $_curRecord ? $_curRecord->deleted_by : NULL;
     }
     switch ($_action) {
         case 'create':
             $_newRecord->created_by = $currentAccountId;
             $_newRecord->creation_time = $currentTime;
             if ($_newRecord->has('seq')) {
                 $_newRecord->seq = 1;
             }
             break;
         case 'update':
             $_newRecord->last_modified_by = $currentAccountId;
             $_newRecord->last_modified_time = $currentTime;
             self::increaseRecordSequence($_newRecord, $_curRecord);
             break;
         case 'delete':
             $_newRecord->deleted_by = $currentAccountId;
             $_newRecord->deleted_time = $currentTime;
             $_newRecord->is_deleted = true;
             self::increaseRecordSequence($_newRecord, $_curRecord);
             break;
         default:
             throw new Tinebase_Exception_InvalidArgument('Action must be one of {create|update|delete}.');
             break;
     }
     $_newRecord->bypassFilters = $bypassFilters;
 }