Esempio n. 1
0
 public function actionAddDrug()
 {
     return;
     //disabled OE-4474
     $drug = new Drug('create');
     if (!empty($_POST)) {
         $drug->attributes = $_POST['Drug'];
         if (!$drug->validate()) {
             $errors = $drug->getErrors();
         } else {
             if (!$drug->save()) {
                 throw new Exception("Unable to save drug: " . print_r($drug->getErrors(), true));
             }
             if (isset($_POST['allergies'])) {
                 $posted_allergy_ids = $_POST['allergies'];
                 //add new allergy mappings
                 foreach ($posted_allergy_ids as $asign) {
                     $allergy_assignment = new DrugAllergyAssignment();
                     $allergy_assignment->drug_id = $drug->id;
                     $allergy_assignment->allergy_id = $asign;
                     $allergy_assignment->save();
                 }
             }
             $this->redirect('/admin/drugs/' . ceil($drug->id / $this->items_per_page));
         }
     }
     $this->render('/admin/adddrug', array('drug' => $drug, 'errors' => @$errors));
 }
Esempio n. 2
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     //Validation
     $rules = array('name' => 'required|unique:drugs,name');
     $validator = Validator::make(Input::all(), $rules);
     //process
     if ($validator->fails()) {
         return Redirect::back()->withErrors($validator)->WithInput();
     } else {
         //store
         $drug = new Drug();
         $drug->name = Input::get('name');
         $drug->description = Input::get('description');
         try {
             $drug->save();
             $url = Session::get('SOURCE_URL');
             return Redirect::to($url)->with('message', trans('messages.success-creating-drug'))->with('activedrug', $drug->id);
         } catch (QueryException $e) {
             Log::error($e);
         }
     }
 }