Exemple #1
0
 /**
  * Add a model to the ColumnModel class.
  * 
  * Give this ColumnModel class a model where to get the columns from.
  * The public parameters and the customfield parameters are also set.
  * The $excludeColumns are meant to give up the column names that need to be excluded in the columnModel.
  * 
  * @TODO: The text parameters need to be excluded.
  * 
  * @param \GO\Base\Db\ActiveRecord $model
  * @param Array $excludeColumns 
  */
 public function setColumnsFromModel(\GO\Base\Db\ActiveRecord $model, $excludeColumns = array(), $includeColumns = array())
 {
     $attributes = $model->getColumns();
     foreach (array_keys($attributes) as $colName) {
         if (!in_array($colName, $excludeColumns)) {
             $sortIndex = empty($includeColumns) ? 0 : array_search($colName, $includeColumns);
             if ($sortIndex !== false) {
                 $column = new Column($colName, $model->getAttributeLabel($colName), $sortIndex);
                 $this->addColumn($column);
             }
         }
     }
     if (\GO::modules()->customfields && $model->customfieldsRecord) {
         $cfAttributes = array_keys($model->customfieldsRecord->columns);
         array_shift($cfAttributes);
         //remove model_id column
         foreach ($cfAttributes as $colName) {
             if (!in_array($colName, $excludeColumns)) {
                 $sortIndex = empty($includeColumns) ? 0 : array_search($colName, $includeColumns);
                 if ($sortIndex !== false) {
                     $column = new Column($colName, $model->customfieldsRecord->getAttributeLabel($colName), $sortIndex);
                     $this->addColumn($column);
                 }
             }
         }
     }
 }
 /**
  * Update the model with the given attributes
  *  
  * @param \GO\Base\Db\ActiveRecord $model
  * @param array $data
  * @return Boolean 
  */
 private function _updateModel($model, $data)
 {
     $changeAttributes = array();
     foreach ($data as $attr => $value) {
         if ($value['edit']) {
             $changeAttributes[$value['name']] = $value['value'];
         }
     }
     $model->setAttributes($changeAttributes);
     return $model->save();
 }
 protected function afterSave($wasNew)
 {
     if ($wasNew && $this->checkSlaves) {
         $this->field->checkTreeSelectSlaves();
     }
     return parent::afterSave($wasNew);
 }
Exemple #4
0
 protected function init()
 {
     $this->columns['model_id']['required'] = true;
     $this->columns['model_type_id']['required'] = true;
     $this->columns['category_id']['required'] = \GO\Comments\CommentsModule::commentsRequired();
     return parent::init();
 }
Exemple #5
0
 protected function init()
 {
     $this->columns['text']['gotype'] = 'html';
     $this->columns['time']['gotype'] = 'unixtimestamp';
     $this->columns['vtime']['gotype'] = 'unixtimestamp';
     parent::init();
 }
 protected function afterDelete()
 {
     if (\GO::modules()->isInstalled('log')) {
         Log::create(Log::ACTION_DELETE, 'Removed ' . $this->contact->name . ' from addresslist ' . $this->addresslist->name, $this->className(), $this->contact_id . ':' . $this->addresslist_id);
     }
     return parent::afterDelete();
 }
Exemple #7
0
 protected function init()
 {
     $this->columns['content']['required'] = true;
     //		$this->addDefaultTag('contact:salutation', \GO::t('default_salutation_unknown'));
     $this->addDefaultTag('salutation', \GO::t('default_salutation_unknown'));
     $this->addDefaultTag('date', \GO\Base\Util\Date::get_timestamp(time(), false));
     return parent::init();
 }
Exemple #8
0
 protected function afterSave($wasNew)
 {
     $stmt = $this->group->calendars;
     foreach ($stmt as $calendar) {
         $calendar->acl->addUser($this->user_id, \GO\Base\Model\Acl::DELETE_PERMISSION);
     }
     return parent::afterSave($wasNew);
 }
Exemple #9
0
 protected function afterSave($wasNew)
 {
     if ($this->mainevent) {
         $this->mainevent->touch();
         $this->mainevent->setReminder();
     }
     return parent::afterSave($wasNew);
 }
 public function defaultAttributes()
 {
     $attr = parent::defaultAttributes();
     $attr['modified_user_id'] = \GO::user()->id;
     $attr['mtime'] = time();
     $attr['status'] = 0;
     return $attr;
 }
Exemple #11
0
 protected function afterSave($wasNew)
 {
     // Only do this when it's a new model
     if ($wasNew) {
         $this->acl->addGroup(GO::config()->group_everyone);
     }
     return parent::afterSave($wasNew);
 }
Exemple #12
0
 protected function init()
 {
     $this->columns['domain']['unique'] = true;
     $this->columns['total_quota']['gotype'] = 'number';
     $this->columns['default_quota']['gotype'] = 'number';
     $this->columns['max_aliases']['gotype'] = 'number';
     $this->columns['max_mailboxes']['gotype'] = 'number';
     return parent::init();
 }
Exemple #13
0
 protected function beforeSave()
 {
     if ($this->isNew && !empty($this->domain->max_aliases)) {
         if ($this->domain->getSumAliases() >= $this->domain->max_aliases) {
             throw new \Exception('The maximum number of aliases for this domain has been reached.');
         }
     }
     return parent::beforeSave();
 }
Exemple #14
0
 protected function beforeSave()
 {
     $folderModel = Folder::model()->findByPk($this->folder_id);
     $existingBookmarkModel = Bookmark::model()->findSingleByAttributes(array('user_id' => \GO::user()->id, 'folder_id' => $folderModel->id));
     if (!empty($existingBookmarkModel)) {
         throw new \Exception(str_replace('%fn', $folderModel->name, \GO::t('bookmarkAlreadyExists', 'files')));
     }
     return parent::beforeSave();
 }
Exemple #15
0
 public function __get($name)
 {
     $this->_loadFields();
     if (isset(self::$fields[$name])) {
         return $this->getCustomFieldValueByName($name);
     } else {
         return parent::__get($name);
     }
 }
 protected function defaultAttributes()
 {
     $attr = parent::defaultAttributes();
     $findParams = \GO\Base\Db\FindParams::newInstance()->limit(1);
     $stmt = Template::model()->find($findParams);
     if ($template = $stmt->fetch()) {
         $attr['template_id'] = $template->id;
     }
     return $attr;
 }
Exemple #17
0
 protected function afterSave($wasNew)
 {
     if ($this->aclItem) {
         //Add log message for activitylog here
         if (\GO::modules()->isInstalled("log")) {
             \GO\Log\Model\Log::create("acl", $this->aclItem->description, $this->aclItem->className(), $this->aclItem->id);
         }
         $this->aclItem->touch();
     }
     return parent::afterSave($wasNew);
 }
Exemple #18
0
 public function checkDatabase()
 {
     //delete if module is no longer installed. This should happen automatically
     //after module uninstall but in some cases this went wrong.
     $parts = explode('\\', $this->model_name);
     $module = strtolower($parts[1]);
     if ($module != 'base' && !\GO::modules()->isInstalled($module)) {
         $this->delete();
     } else {
         return parent::checkDatabase();
     }
 }
Exemple #19
0
 public function defaultAttributes()
 {
     $attr = parent::defaultAttributes();
     if (PHP_SAPI == 'cli') {
         $attr['user_agent'] = 'cli';
     } else {
         $attr['user_agent'] = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : 'unknown';
     }
     $attr['ip'] = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '';
     $attr['controller_route'] = \GO::router()->getControllerRoute();
     $attr['username'] = \GO::user() ? \GO::user()->username : '******';
     return $attr;
 }
Exemple #20
0
 /**
  * Univeral checker for workflow triggers
  * This function should work for all ActiveRecords
  * 
  * @param \GO\Base\Db\ActiveRecord $model 
  */
 public static function save(&$model, $wasNew)
 {
     if ($wasNew) {
         // Check for a trigger for this model
         $triggers = Model\Trigger::model()->findByAttribute('model_type_id', $model->modelTypeId());
         \GO::debug('CHECK FOR WORKFLOW TRIGGER ON THIS MODEL');
         while ($trigger = $triggers->fetch()) {
             if ($trigger->model_attribute_value == $model->{$trigger->model_attribute}) {
                 \GO::debug('TRIGGER FOUND!, START NEW WORKFLOW PROCESS');
                 $process = Model\Process::model()->findByPk($trigger->process_id);
                 $step = $process->getNextStep();
                 $wfModel = new Model\Model();
                 $wfModel->model_id = $model->id;
                 $wfModel->model_type_id = $model->modelTypeId();
                 $wfModel->process_id = $trigger->process_id;
                 $wfModel->step_id = $step->id;
                 //$wfModel->ctime = 0;
                 $wfModel->due_time = $wfModel->calculateDueTime($step);
                 $wfModel->shift_due_time = 0;
                 $wfModel->save();
             }
         }
     }
 }
Exemple #21
0
 protected function afterSave($wasNew)
 {
     $sentMailingModel = $this->sentMailing;
     if (!empty($sentMailingModel)) {
         $sentNow = $this->sent ? 1 : 0;
         if ($this->isModified('sent')) {
             $sentBefore = $this->getOldAttributeValue('sent') ? 1 : 0;
         } else {
             $sentBefore = $sentNow;
         }
         $sentAdd = $sentNow - $sentBefore;
         $errorNow = $this->has_error ? 1 : 0;
         if ($this->isModified('has_error')) {
             $errorBefore = $this->getOldAttributeValue('has_error') ? 1 : 0;
         } else {
             $errorBefore = $errorNow;
         }
         $errorsAdd = $errorNow - $errorBefore;
         $openedNow = $this->campaigns_opened ? 1 : 0;
         if ($this->isModified('campaigns_opened')) {
             $openedBefore = $this->getOldAttributeValue('campaigns_opened') ? 1 : 0;
         } else {
             $openedBefore = $openedNow;
         }
         $openedAdd = $openedNow - $openedBefore;
         if ($sentAdd != 0 || $errorsAdd != 0 || $openedAdd != 0) {
             //				var_dump($this->contact_id.' , '.$this->sent_mailing_id);
             //				var_dump($sentNow);
             //			var_dump($sentBefore);
             //			exit();
             $sentMailingModel->sent += $sentAdd;
             $sentMailingModel->errors += $errorsAdd;
             $sentMailingModel->opened += $openedAdd;
             $sentMailingModel->save();
         }
     }
     return parent::afterSave($wasNew);
 }
Exemple #22
0
 public static function model($className = __CLASS__)
 {
     return parent::model($className);
 }
Exemple #23
0
 protected function init()
 {
     $this->columns["income"]["gotype"] = "number";
     return parent::init();
 }
Exemple #24
0
 protected function init()
 {
     $this->columns['content']['gotype'] = 'text';
     return parent::init();
 }
Exemple #25
0
 /**
  * Query all modules.
  * 
  * @return \GO\Base\Db\ActiveStatement 
  */
 public function getAll()
 {
     return $this->model->find();
 }
Exemple #26
0
 protected function init()
 {
     $this->columns['name']['unique'] = array("user_id");
     return parent::init();
 }
Exemple #27
0
 protected function afterDuplicate(&$duplicate)
 {
     //		$this->duplicateRelation('_fieldsUnsorted', $duplicate);
     //		$this->duplicateRelation('fields', $duplicate);
     $this->duplicateRelation('_fieldsSortedById', $duplicate);
     return parent::afterDuplicate($duplicate);
 }
Exemple #28
0
 public function checkDatabase()
 {
     if (empty($this->user_id)) {
         $this->user_id = 1;
     }
     if (empty($this->description)) {
         $this->description = 'unknown';
     }
     if ($this->description != 'readonly') {
         $this->addGroup(\GO::config()->group_root, Acl::MANAGE_PERMISSION);
         $this->addUser($this->user_id, Acl::MANAGE_PERMISSION);
     }
     return parent::checkDatabase();
 }
Exemple #29
0
 protected function init()
 {
     $this->columns['name']['unique'] = true;
     return parent::init();
 }
Exemple #30
0
 public function validate()
 {
     $this->_checkQuota();
     if (!empty($this->domain->max_mailboxes) && $this->isNew && $this->domain->getSumMailboxes() >= $this->domain->max_mailboxes) {
         throw new \Exception('The maximum number of mailboxes for this domain has been reached.');
     }
     return parent::validate();
 }