Esempio n. 1
0
 /**
  * main action
  */
 public function mainAction()
 {
     $Ingredients = new ecommerce_recipe_ingredients();
     $Product = new ecommerce_product();
     $recipe_id = $this->GET['recipe_id'];
     $ingredients = array();
     $ingredients['recipe_id'] = $recipe_id;
     /**
      * saving
      */
     if (is_array($_POST['ingredients'])) {
         $current = $Ingredients->listing("recipe_id = {$recipe_id}");
         $keep = array_keys($_POST['ingredients']);
         foreach ($current as $c) {
             if (!in_array($c['id'], $keep)) {
                 $Ingredients->delete($c['id']);
             }
         }
         foreach ($_POST['ingredients'] as $ingredient_id => $item) {
             if (is_numeric($ingredient_id)) {
                 $ingredients['id'] = $ingredient_id;
                 $ingredients['product_variety_id'] = $item['product_variety_id'];
                 $ingredients['quantity'] = $item['quantity'];
                 $ingredients['units'] = $item['units'];
                 $ingredients['notes'] = $item['notes'];
                 $ingredients['group_title'] = $item['group_title'];
                 $Ingredients->update($ingredients);
             } else {
                 unset($ingredients['id']);
                 $ingredients['product_variety_id'] = $item['product_variety_id'];
                 $ingredients['quantity'] = $item['quantity'];
                 $ingredients['units'] = $item['units'];
                 $ingredients['notes'] = $item['notes'];
                 $ingredients['group_title'] = $item['group_title'];
                 $Ingredients->insert($ingredients);
             }
         }
     }
     /**
      * get units
      */
     $units = $Ingredients->getUnits();
     $this->parseUnits($units, false, 'head.unit');
     /**
      * get ingredient list (products)
      */
     $products = $Product->getProductListForDropdown();
     $this->parseIngredients($products);
     /**
      * listing
      */
     $current = $Ingredients->listing("recipe_id = {$recipe_id}");
     foreach ($current as $ingredient) {
         $this->tpl->assign("ITEM", $ingredient);
         $this->parseUnits($units, $ingredient['units']);
         $this->tpl->parse("content.item");
     }
     return true;
 }