예제 #1
0
 public function saveConditionals(Reasons_ConditionalsModel $conditionalsModel)
 {
     if ($conditionalsRecord = Reasons_ConditionalsRecord::model()->findByAttributes(array('typeId' => $conditionalsModel->typeId))) {
         $conditionalsModel->id = $conditionalsRecord->id;
     } else {
         $conditionalsRecord = new Reasons_ConditionalsRecord();
     }
     $conditionalsRecord->sectionId = $conditionalsModel->sectionId;
     $conditionalsRecord->typeId = $conditionalsModel->typeId;
     $conditionalsRecord->conditionals = $conditionalsModel->conditionals;
     $conditionalsRecord->validate();
     $conditionalsModel->addErrors($conditionalsRecord->getErrors());
     if (!$conditionalsModel->hasErrors()) {
         $transaction = craft()->db->getCurrentTransaction() === null ? craft()->db->beginTransaction() : null;
         try {
             if (!$conditionalsModel->id) {
                 $conditionalsRecord->save();
             } else {
                 $conditionalsRecord->update();
             }
             $conditionalsModel->id = $conditionalsRecord->id;
             if ($transaction !== null) {
                 $transaction->commit();
             }
         } catch (\Exception $e) {
             if ($transaction !== null) {
                 $transaction->rollback();
             }
             throw $e;
         }
         return true;
     }
     return false;
 }
예제 #2
0
 /**
  * @param Reasons_ConditionalsModel $model
  * @return bool
  * @throws \Exception
  */
 public function saveConditionals(Reasons_ConditionalsModel $model)
 {
     $record = new Reasons_ConditionalsRecord();
     $record->fieldLayoutId = $model->fieldLayoutId;
     $record->conditionals = $model->conditionals;
     $record->validate();
     $model->addErrors($record->getErrors());
     if (!$model->hasErrors()) {
         $transaction = craft()->db->getCurrentTransaction() === null ? craft()->db->beginTransaction() : null;
         try {
             $record->save();
             if ($transaction !== null) {
                 $transaction->commit();
             }
         } catch (\Exception $e) {
             if ($transaction !== null) {
                 $transaction->rollback();
             }
             throw $e;
         }
         return true;
     }
     return false;
 }