Inheritance: extends BaseActiveRecord
示例#1
0
 /**
  * Update the mapping specification for an automatic worklist definition.
  *
  * @param WorklistDefinitionMapping $mapping
  * @param $key
  * @param string $values
  *
  * @return bool
  */
 public function updateWorklistDefinitionMapping(WorklistDefinitionMapping $mapping, $key, $values, $display = true)
 {
     $values = strlen($values) ? explode(',', $values) : array();
     $definition = $mapping->worklist_definition;
     if (!$this->canUpdateWorklistDefinition($definition)) {
         $this->addError('Cannot update mapping for un-editable Worklist Definition');
         return false;
     }
     if (!$definition->validateMappingKey($key, $mapping->id)) {
         $this->addError("Mapping key {$key} already exists for definition");
         return false;
     }
     $mapping->key = $key;
     if (!$display) {
         $mapping->display_order = null;
     } elseif (!$mapping->display_order) {
         $mapping->display_order = $definition->getNextDisplayOrder();
     }
     $transaction = $this->startTransaction();
     try {
         if (!$mapping->save()) {
             throw new Exception('Could not save mapping');
         }
         if (!$mapping->updateValues($values)) {
             throw new Exception('Could not save mapping values');
         }
         $this->audit(self::$AUDIT_TARGET_AUTO, 'mapping-update');
         if ($transaction) {
             $transaction->commit();
         }
     } catch (Exception $e) {
         $this->addError($e->getMessage());
         echo $e->getMessage();
         if ($transaction) {
             $transaction->rollback();
         }
         return false;
     }
     return true;
 }
 /**
  * Delete a definition mapping.
  *
  * @param $id
  *
  * @throws CHttpException
  */
 public function actionDefinitionMappingDelete($id)
 {
     if (!($mapping = WorklistDefinitionMapping::model()->findByPk($id))) {
         throw new CHttpException(404, 'Worklist Definition Mapping not found.');
     }
     if (!$this->manager->canUpdateWorklistDefinition($mapping->worklist_definition)) {
         throw new CHttpException(409, 'Cannot delete mapping for un-editable Definition');
     }
     if ($mapping->delete()) {
         $this->flashMessage('success', 'Mapping removed.');
     } else {
         $this->flashMessage('error', 'Cannot delete mapping.');
     }
     $this->redirect(array('/worklistAdmin/definitionMappings/' . $mapping->worklist_definition_id));
 }