Beispiel #1
0
 public function actionAddRaw()
 {
     Yii::app()->clientScript->registerCoreScript('jquery.ui');
     if (isset($_POST['rawID'])) {
         if (!RecipeRaw::model()->findByAttributes(array("RawID" => $_POST['rawID'], "RecipeID" => $_POST['recipeID']))) {
             $model = new RecipeRaw();
             $model->RawID = $_POST['rawID'];
             $model->RecipeID = $_POST['recipeID'];
             $model->Quantity = $_POST['quantity'];
             $model->Type = $_POST['type'];
             if ($model->save()) {
                 $modelIngredients = RecipeRaw::model()->findAllByAttributes(array("RecipeID" => $model->RecipeID));
                 echo $this->renderPartial("_ingredients", array('modelIngredients' => $modelIngredients));
             } else {
                 echo "<span id='error'>Error a&ntilde;adiendo el ingrediente. Vuelve a intentarlo. <span style='display:none;'>";
                 echo print_r($model->Errors) . "</span></span>";
             }
         } else {
             $modelIngredients = RecipeRaw::model()->findAllByAttributes(array("RecipeID" => $model->RecipeID));
             echo $this->renderPartial("_ingredients", array('modelIngredients' => $modelIngredients));
             echo "<span id='error'>Esta materia prima ya existe en la receta</span>";
         }
     } else {
         echo "<span id='error'>No se ha enviado ninguna materia prima</span>";
     }
 }