Exemple #1
0
 protected function afterMergeWith(\GO\Base\Db\ActiveRecord $model)
 {
     //move company employees to this model too.
     if ($model->className() == $this->className()) {
         $stmt = $model->contacts();
         while ($contact = $stmt->fetch()) {
             $contact->company_id = $this->id;
             $contact->save();
         }
     }
     return parent::afterMergeWith($model);
 }
Exemple #2
0
 /**
  * Merge this model with another one of the same type.
  *
  * All attributes of the given model will be applied to this model if they are empty. Textarea's will be concatenated.
  * All links will be moved to this model.
  * Finally the given model will be deleted.
  *
  * @param ActiveRecord $model
  */
 public function mergeWith(ActiveRecord $model, $mergeAttributes = true, $deleteModel = true)
 {
     if (!$this instanceof \GO\Customfields\Model\AbstractCustomFieldsRecord && $model->id == $this->id && $this->className() == $model->className()) {
         return false;
     }
     //copy attributes if models are of the same type.
     if ($mergeAttributes) {
         $attributes = $model->getAttributes('raw');
         //don't copy primary key
         if (is_array($this->primaryKey())) {
             foreach ($this->primaryKey() as $field) {
                 unset($attributes[$field]);
             }
         } else {
             unset($attributes[$this->primaryKey()]);
         }
         unset($attributes['files_folder_id']);
         foreach ($attributes as $name => $value) {
             $isset = isset($this->columns[$name]);
             if ($isset && !empty($value)) {
                 if ($this->columns[$name]['gotype'] == 'textarea') {
                     $this->{$name} .= "\n\n-- merge --\n\n" . $value;
                 } elseif ($this->columns[$name]['gotype'] = 'date' && $value == '0000-00-00') {
                     $this->{$name} = "";
                 } elseif (empty($this->{$name})) {
                     $this->{$name} = $value;
                 }
             }
         }
         $this->save();
         //copy custom fields
         if ($model->customfieldsRecord) {
             $this->customfieldsRecord->mergeWith($model->customfieldsRecord, $mergeAttributes, $deleteModel);
         }
     }
     $model->copyLinks($this);
     //move files.
     if ($deleteModel) {
         $this->_moveFiles($model);
         $this->_moveComments($model);
     } else {
         $this->_copyFiles($model);
         $this->_copyComments($model);
     }
     $this->afterMergeWith($model);
     if ($deleteModel) {
         $model->delete();
     }
 }
Exemple #3
0
 private function _createNewModelFolder(\GO\Base\Db\ActiveRecord $model)
 {
     GO::debug("Create new model folder " . $model->className() . "(ID:" . $model->id . ")");
     $folder = \GO\Files\Model\Folder::model()->findByPath($model->buildFilesPath(), true, array('acl_id' => $model->findAclId(), 'readonly' => 1));
     if (!$folder) {
         throw new \Exception("Failed to create folder " . $model->buildFilesPath());
     }
     //      if (!empty($model->acl_id))
     //          $folder->acl_id = $model->acl_id;
     $folder->acl_id = $model->findAclId();
     $folder->visible = 0;
     $folder->readonly = 1;
     $folder->systemSave = true;
     $folder->save(true);
     return $folder->id;
 }