示例#1
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     //
     $ingredient = new Ingredient();
     $ingredient->title = Input::get('title');
     $ingredient->save();
     return Redirect::to('ingredient');
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Ingredient();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Ingredient'])) {
         $model->attributes = $_POST['Ingredient'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }
 /**
  * Validates data submitted in the add form. If the validation fails,
  * displays the add page. Otherwise, creates a new ingredient, saves it to 
  * the database and redirects to the add page.
  */
 public static function add()
 {
     $params = $_POST;
     $attributes = array('ingredient_name' => $params['ingredient_name'], 'ingredient_type' => $params['ingredient_type'], 'price' => $params['price']);
     $validator = self::ingredient_validator($attributes);
     if ($validator->validate()) {
         $ingredient = new Ingredient($attributes);
         $ingredient->save();
         Redirect::to($params['redirect'], array('message' => 'Ainesosa lisätty!'));
     } else {
         View::make('ingredient/add.html', array('errors' => $validator->errors(), 'ingredient' => $attributes));
     }
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     //
     $ingr = new Ingredient();
     //Get the name of the ingredient
     $name = Input::get('ingrName');
     $ingr->ingredient_name = $name;
     $category = Input::get('category');
     $ingr->category = $category;
     $price = Input::get('price');
     $ingr->price = $price;
     $size = Input::get('size');
     $ingr->size = $size;
     $stock = Input::get('curr_stock');
     $ingr->current_stock = $stock;
     $ingr->save();
     return Redirect::to('ingredient');
 }
示例#5
0
<?php

require_once '../models/DB.php';
require_once '../models/Ingredient.php';
$ing = new Ingredient();
$ing->name = $_POST['name'];
$ing->save($dbh);
header("Content-type: text/json");
echo json_encode($ing);
示例#6
0
		public static function add($name, $isVeg, $isAll, $side)
		{
			global $db;
			$ing = Ingredient::getByName($name);
			if( $ing )
			{
				return $ing;
			}
			else
			{
				$ing = new Ingredient(null, $name, $isVeg, $isAll, $side);
				return $ing->save();
			}
		}
 public static function editIngredients($ingredients, $id, $ingredient_ids, $amounts, $units)
 {
     $i = 0;
     foreach ($ingredients as $ingredient) {
         $ingredient = strtolower($ingredient);
         if (Ingredient::alreadyInArchive($ingredient) > 0) {
             $ingredient_id = Ingredient::alreadyInArchive($ingredient);
             $old_ingredient_id = $ingredient_ids[$i];
             $newDrinkIngredient = new DrinkIngredient();
             $newDrinkIngredient->setIngredient_id($ingredient_id);
             $newDrinkIngredient->setDrink_id($id);
             $newDrinkIngredient->setAmount($amounts[$i]);
             $newDrinkIngredient->setUnit($units[$i]);
             $newDrinkIngredient->update($old_ingredient_id);
         } else {
             $newIngredient = new Ingredient();
             $newIngredient->setIngredient_name($ingredient);
             $ingredient_id = $newIngredient->save();
             $old_ingredient_id = $ingredient_ids[$i];
             $newDrinkIngredient = new DrinkIngredient();
             $newDrinkIngredient->setIngredient_id($ingredient_id);
             $newDrinkIngredient->setDrink_id($id);
             $newDrinkIngredient->setAmount($amounts[$i]);
             $newDrinkIngredient->setUnit($units[$i]);
             $newDrinkIngredient->update($old_ingredient_id);
         }
         $i++;
     }
 }