WorklistManager::saveWorklistDefinition PHP Method

saveWorklistDefinition() public method

public saveWorklistDefinition ( WorklistDefinition $definition ) : boolean
$definition WorklistDefinition
return boolean
    public function saveWorklistDefinition(WorklistDefinition $definition)
    {
        if (!$this->canUpdateWorklistDefinition($definition)) {
            $this->addError('cannot save Definition that is un-editable');
            return false;
        }
        $action = $definition->isNewRecord ? 'create' : 'update';
        $transaction = $this->startTransaction();
        try {
            if (!$definition->save()) {
                $this->addModelErrors($definition->getErrors());
                throw new Exception("Couldn't save definition");
            }
            $this->audit(self::$AUDIT_TARGET_AUTO, $action, array('worklist_definition_id' => $definition->id));
            if ($transaction) {
                $transaction->commit();
            }
        } catch (Exception $e) {
            $this->addError($e->getMessage());
            if ($transaction) {
                $transaction->rollback();
            }
            return false;
        }
        return true;
    }

Usage Example

 /**
  * Create or Edit a WorklistDefinition.
  *
  * @param null $id
  *
  * @throws CHttpException
  */
 public function actionDefinitionUpdate($id = null)
 {
     $definition = $this->manager->getWorklistDefinition($id);
     if (!$definition) {
         throw new CHttpException(404, 'Worklist definition could not be ' . ($id ? 'found' : 'created'));
     }
     if (!$this->manager->canUpdateWorklistDefinition($definition)) {
         throw new CHttpException(409, 'Cannot change mappings for un-editable Definition');
     }
     if (isset($_POST['WorklistDefinition'])) {
         $definition->attributes = $_POST['WorklistDefinition'];
         if (!$this->manager->saveWorklistDefinition($definition)) {
             $errors = $definition->getErrors();
         } else {
             $this->flashMessage('success', 'Worklist Definition saved');
             return $this->redirect(array('/worklistAdmin/definitions'));
         }
     }
     $this->render('//admin/worklists/definition_edit', array('definition' => $definition, 'errors' => @$errors));
 }