Beispiel #1
0
 public static function set_panel($f3, $ingredientId = null)
 {
     $has_allergy = $f3->get('has_allergy_orm');
     $results = Allergy::map_to_id($f3);
     $ingAllergies = array();
     $allergyString = "";
     // Get selected allergies from db
     if ($ingredientId) {
         $arr_has_allergy = $has_allergy->find(array('ingredient_id = ?', $ingredientId));
         foreach ($arr_has_allergy as $value) {
             $ingAllergies[] = $value->allergy_id;
         }
     }
     $allergyString = implode(",", $ingAllergies);
     $f3->set('allergies', $results);
     $f3->set('inputAllergyValue', $allergyString);
 }
Beispiel #2
0
# DATABASE RELATION-MAPPERS
$f3->set('DB', new DB\SQL('mysql:host=localhost;dbname=MealDB', 'root', ''));
$DB = $f3->get('DB');
$f3->set('meal_orm', new DB\SQL\Mapper($DB, 'MEAL'));
$f3->set('ingredient_orm', new DB\SQL\Mapper($DB, 'INGREDIENT'));
$f3->set('menu_orm', new DB\SQL\Mapper($DB, 'MENU'));
$f3->set('has_ingredient_orm', new DB\SQL\Mapper($DB, 'HAS_INGREDIENT'));
$f3->set('allergy_orm', new DB\SQL\Mapper($DB, 'ALLERGY'));
$f3->set('has_allergy_orm', new DB\SQL\Mapper($DB, 'HAS_ALLERGY'));
# ORM VIEWS
$f3->set('meal_overview_orm', new DB\SQL\Mapper($DB, 'MEAL_OVERVIEW'));
$f3->set('meal_ingredients_orm', new DB\SQL\Mapper($DB, 'MEAL_INGREDIENTS'));
$f3->set('ingredient_overview_orm', new DB\SQL\Mapper($DB, 'INGREDIENT_OVERVIEW'));
# GLOBAL VALUES
$f3->set('g_menus', $f3->get('menu_orm')->find());
$f3->set('g_allergies', Allergy::map_to_id($f3));
$f3->set('g_meal_name', 'annos');
#PÄÄAUKEAMA
$f3->route('GET /', function ($f3) {
    $auth = $_SERVER['PHP_AUTH_USER'];
    if (!isset($auth)) {
        $f3->reroute("/login");
    }
    $f3->set("title", "Ateriajärjestelmä");
    $f3->set("content", "main.htm");
    echo Template::instance()->render("layout.htm");
});
$f3->route('GET /asetukset', function () {
    echo 'Tänne asetukset';
});
# MENU
Beispiel #3
0
 function edit_food($f3, $params)
 {
     $category = new DB\SQL\Mapper($f3->get('DB'), 'CATEGORY');
     $menu = new DB\SQL\Mapper($f3->get('DB'), 'MENU');
     $meal = $f3->get('meal_orm');
     $id = $f3->get('PARAMS.id');
     $mealInst = $meal->load(array("id=?", $id));
     if ($meal->dry()) {
         $f3->reroute("/annos/luo");
     }
     $m_list = $menu->find();
     $c_list = $category->find();
     $a_list = Allergy::map_to_id($f3);
     $f3->set("meal", $mealInst);
     $f3->set("allergies", $a_list);
     $f3->set("categories", $c_list);
     $f3->set("menus", $m_list);
     $f3->set("id", $id);
     $f3->set("title", $mealInst->name);
     $f3->set('content', 'food_form.htm');
     echo Template::instance()->render('layout.htm');
 }
Beispiel #4
0
 function show_all($f3)
 {
     $orm = new DB\SQL\Mapper($f3->get('DB'), 'INGREDIENT_OVERVIEW');
     $page = $f3->get('PARAMS.page');
     $record_count = $orm->count();
     $result_number = 20;
     $page_count = ceil($record_count / $result_number);
     if (!isset($page) || $page <= 0) {
         $f3->reroute("/ainesosa/listaa/sivu/1");
     } else {
         if ($page > $page_count) {
             $f3->reroute("/ainesosa/listaa/sivu/" . $page_count);
         }
     }
     $page--;
     $result = $orm->find(array(), array('limit' => $result_number, 'offset' => $page * $result_number));
     $allergy_arr = array();
     foreach ($result as $ingredient) {
         $id = $ingredient->id;
         $string_allergies = $ingredient->allergies;
         $allergy_arr[$id] = array_filter(explode(',', trim($string_allergies)));
     }
     $f3->set('allergies', Allergy::map_to_id($f3));
     $f3->set('result', $result);
     $f3->set('page_count', $page_count);
     $f3->set('cur_page', $page + 1);
     $f3->set('allergy_arr', $allergy_arr);
     $f3->set("content", "ingredient_list.htm");
     $f3->set("title", "Ainesosat");
     echo Template::instance()->render("layout.htm");
 }