/**
  * Can be used in actionDisplay like actions
  * @param \GO\Base\Db\ActiveRecord $model the model to render display data for
  * @param array $extraFields the extra fields that should be attached to the data array as key => value
  * @return \GO\Base\Data\JsonResponse Response object
  */
 public function renderDisplay($model, $extraFields = array())
 {
     $response = array('data' => array(), 'success' => true);
     $response['data'] = array_merge_recursive($extraFields, $model->getAttributes('html'));
     if (!empty($model->user)) {
         $response['data']['username'] = $model->user->name;
     }
     if (!empty($model->mUser)) {
         $response['data']['musername'] = $model->mUser->name;
     }
     //$response['data'] = $model->getAttributes('html');
     //$response['data']['model'] = $model->className();
     $response['data']['permission_level'] = $model->getPermissionLevel();
     $response['data']['write_permission'] = \GO\Base\Model\Acl::hasPermission($response['data']['permission_level'], \GO\Base\Model\Acl::WRITE_PERMISSION);
     $response['data']['customfields'] = array();
     if (!isset($response['data']['workflow']) && \GO::modules()->workflow) {
         $response = $this->_processWorkflowDisplay($model, $response);
     }
     if ($model->customfieldsRecord) {
         $response = $this->_processCustomFieldsDisplay($model, $response);
     }
     if ($model->hasLinks()) {
         $response = $this->_processLinksDisplay($model, $response);
         if (!isset($response['data']['events']) && \GO::modules()->calendar) {
             $response = $this->_processEventsDisplay($model, $response);
         }
         if (!isset($response['data']['tasks']) && \GO::modules()->tasks) {
             $response = $this->_processTasksDisplay($model, $response);
         }
     }
     if (\GO::modules()->files && !isset($response['data']['files'])) {
         $response = $this->_processFilesDisplay($model, $response);
     }
     if (\GO::modules()->comments) {
         $response = $this->_processCommentsDisplay($model, $response);
     }
     if (\GO::modules()->lists) {
         $response = \GO\Lists\ListsModule::displayResponse($model, $response);
     }
     $this->fireEvent('display', array(&$this, &$response, &$model));
     return new \GO\Base\Data\JsonResponse($response);
 }
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
 public function getAttributes($outputType = null)
 {
     $attr = parent::getAttributes($outputType);
     $attr['encrypted'] = $this->getEncrypted();
     if ($attr['encrypted']) {
         $attr['content'] = '';
     }
     $attr['decrypted'] = $this->_decrypted;
     $attr['password'] = "";
     return $attr;
 }
Exemple #4
0
 public function getAttributes($outputType = 'formatted')
 {
     $attr = parent::getAttributes($outputType);
     $attr['name'] = $this->getName();
     return $attr;
 }