/** * Executes a commit after each action. This prevents having too many * manuall commit * * @param string $name The command name * @param KCommandContext $context The command context * * @return boolean Can return both true or false. */ public function execute($name, KCommandContext $context) { $parts = explode('.', $name); $result = $context->result; //after an action save if ($parts[0] == 'after' && $parts[1] != 'cancel') { //if there are not any commitable //skip if (count($this->getRepository()->getSpace()->getCommitables()) == 0) { return; } //do a commit $result = $this->commit(); $type = $result === false ? 'error' : 'success'; $message = $this->_makeStatusMessage($context->action, $type); if ($message) { $this->setMessage($message, $type, true); } if ($result === false) { if ($this->isIdentifiable() && $this->getItem()) { if ($this->getItem()->getErrors()->count()) { throw new AnErrorException($this->getItem()->getErrors(), KHttpResponse::BAD_REQUEST); } } else { $errors = AnHelperArray::getValues($this->getCommitErrors()); throw new AnErrorException($errors, KHttpResponse::BAD_REQUEST); } } } }
/** * Set a list of notifications subscribers * * @param array $subscribers An array of Ids or person objects * * @return void */ public function setSubscribers($subscribers) { //flatten the array $subscribers = AnHelperArray::getValues(KConfig::unbox($subscribers)); $ids = array(); foreach ($subscribers as $subscriber) { if (is($subscriber, 'AnDomainEntityAbstract')) { $ids[] = $subscriber->id; } else { $ids[] = $subscriber; } } $ids = array_unique($ids); if (count($ids) > 0) { $this->set('subscriberIds', AnDomainAttribute::getInstance('set')->setData($ids)); } else { $this->delete(); } return $this; }