public function __toString()
 {
     $str = '<article class="category">' . PHP_EOL;
     $str .= '<h1>' . $this->getHierarchy() . '<span class="self">' . $this->getLabel() . '</span></h1>';
     $ingredients = IngredientDAO::getByCategory($this);
     $str .= '<section class="content">';
     $str .= '<div class="subs"><h2>Filtres</h2>';
     if (empty($ingredients)) {
         $str .= '<p class="sad">Aucun filtre applicable.</p>';
     } else {
         $str .= '<ul title="Sous-ingredients">';
         foreach ($ingredients as $ingredient) {
             $str .= '<li><a href="ingredient/' . urlencode($ingredient->getId()) . '">' . $ingredient->getLabel() . '</a></li>';
         }
         $str .= '</ul>';
     }
     $str .= '</div>';
     $str .= '<div class="recipes"><h2>Recettes</h2>';
     if ($recipes = RecipeDAO::getByCategory($this)) {
         $str .= '<ul title="Recettes">';
         foreach ($recipes as $recipe) {
             $str .= '<li><a href="recipe/' . $recipe->getId() . '">' . $recipe->getTitle() . '</a></li>';
         }
         $str .= '</ul>';
     } else {
         $str .= '<p class="sad">Aucune recette à afficher.</p>';
     }
     $str .= '</div>';
     $str .= '</section></article>';
     return $str;
 }
 public function getHierarchy()
 {
     if ($s = IngredientDAO::getByChildIngredient($this)) {
         return $s[0]->getHierarchy() . '<a href="ingredient/' . $s[0]->getLabel() . '">' . $s[0]->getLabel() . '</a> > ';
     }
     return '';
 }
 public function getIngredients()
 {
     $ingredients = array();
     foreach ($this->getData()['index'] as $index) {
         $ingredients[] = IngredientDAO::getById($index);
     }
     return $ingredients;
 }
 public static function getByCategory($category)
 {
     $recipes = array();
     if ($ingredients = IngredientDAO::getByCategory($category)) {
         foreach ($ingredients as $ingredient) {
             $recipes += self::getByIngredient($ingredient);
         }
     }
     return $recipes;
 }
<?php

if (!isset($_GET['id'])) {
    $request->redirect('all');
}
$presenter->data['ingredient'] = IngredientDAO::getById(urldecode(@$_GET['id']));
 /**
  * @author thanhtuan
  * method getMaterial : get a material base on id of material that.
  * @param id : string
  * retun html if succed else return empty string;
  */
 public function getMaterial($id)
 {
     try {
         $dao = new IngredientDAO();
         $arr = $dao->getIngredientInfo($id);
         $data = "";
         if ($arr != null) {
             $tenNL = isset($arr["TenNL"]) ? $arr["TenNL"] : "";
             $tenLoaiNL = isset($arr["TenLoaiNL"]) ? $arr["TenLoaiNL"] : null;
             $soLuong = isset($arr["SoLuong"]) ? $arr["SoLuong"] : "";
             $soLuongMin = isset($arr["SoLuongMin"]) ? $arr["SoLuongMin"] : "";
             $soLuongMax = isset($arr["soLuongMax"]) ? $arr["SoLuongMax"] : "";
             $selectStr = $this->getAllIngredientType($tenLoaiNL);
             $data = $data . "\r\n\t\t\t\t<p>Thay đổi thông tin và nhấp Lưu</p>\r\n\t\t\t\t<table>\r\n\t\t\t\t<tr>\r\n\t\t\t\t<td value='{$id}' id='ingredientId' >Tên nguyên liệu</td>\r\n\t\t\t\t<td><input type='text' title='Tên nguyên liệu' id='nameInput_editIngredient' value='{$tenNL}'></input></td>\r\n\t\t\t\t</tr>\r\n\t\t\t\t<tr>\r\n\t\t\t\t<td>Loại nguyên liệu</td>\r\n\t\t\t\t<td><select id='typeSBox_editIngredient'>{$selectStr}\t\t\t\t\r\n\t\t\t\t</select></td>\r\n\t\t\t\t</tr>\r\n\t\t\t\t<tr>\r\n\t\t\t\t<td>Số lượng</td>\r\n\t\t\t\t<td><input type='text' id='amountInput_editIngredient' value='{$soLuong}'></input></td>\r\n\t\t\t\t</tr>\r\n\t\t\t\t<tr>\r\n\t\t\t\t<td>Số lượng tối thiểu</td>\r\n\t\t\t\t<td><input type='text' id='minAmountInput_editIngredient' value='{$soLuongMin}'></input></td>\r\n\t\t\t\t</tr>\r\n\t\t\t\t<tr>\r\n\t\t\t\t<td>Số lượng tối đa</td>\r\n\t\t\t\t<td><input type='text' id='maxAmountInput_editIngredient' value='{$soLuongMax}'></input></td>\r\n\t\t\t\t</tr>\r\n\t\t\t\t</table>\r\n\t\t\t\t<button onclick='editIngredientButClicked()'>Lưu</button>";
         }
     } catch (Exception $e) {
         echo "Not Connect to database! ";
     }
     return $data;
 }