public function testNoItemsRaisesError()
 {
     $test = new OphTrOperationbooking_Operation_EROD_Rule();
     $test->subspecialty_id = $this->subspecialties('subspecialty1')->id;
     $this->assertFalse($test->validate());
     $errs = $test->getErrors();
     $this->assertArrayHasKey('items', $errs);
 }
예제 #2
0
 public function actionAddERODRule()
 {
     $errors = array();
     $erod = new OphTrOperationbooking_Operation_EROD_Rule();
     if (!empty($_POST)) {
         $erod->subspecialty_id = @$_POST['OphTrOperationbooking_Operation_EROD_Rule']['subspecialty_id'];
         $posted_items = array();
         $posted_by_firm = array();
         if (@$_POST['Firms']) {
             foreach ($_POST['Firms'] as $posted_firm_id) {
                 if (!Firm::model()->findByPk($posted_firm_id)) {
                     throw new CHttpException('invalid firm id posted');
                 }
                 $item = new OphTrOperationbooking_Operation_EROD_Rule_Item();
                 $item->item_type = 'firm';
                 $item->item_id = $posted_firm_id;
                 $posted_items[] = $item;
                 $posted_by_firm[$posted_firm_id] = $item;
             }
         }
         $erod->items = $posted_items;
         $transaction = Yii::app()->db->beginTransaction();
         try {
             if (!$erod->save()) {
                 $errors = $erod->getErrors();
             } else {
                 foreach ($posted_items as $posted_item) {
                     $posted_item->erod_rule_id = $erod->id;
                     if (!$posted_item->save()) {
                         $errors = array_merge($errors, $item->getErrors());
                         throw new Exception();
                     }
                 }
                 if (empty($errors)) {
                     $transaction->commit();
                     Audit::add('admin', 'create', $erod->id, null, array('module' => 'OphTrOperationbooking', 'model' => 'OphTrOperationbooking_Operation_EROD_Rule'));
                     $this->redirect(array('/OphTrOperationbooking/admin/viewERODRules'));
                 }
             }
         } catch (Exception $e) {
             $transaction->rollback();
             throw $e;
         }
     }
     $this->render('/admin/editerodrule', array('erod' => $erod, 'errors' => $errors));
 }