Example #1
0
 protected function food()
 {
     if (!$this->session->status()) {
         return $this->_response("Authentication Required", 401);
     }
     $food = new Food();
     if ($this->method == 'GET') {
         if ($this->id) {
             return $food->getById($this->id);
         }
         return $food->getList();
     } else {
         if ($this->method == 'POST') {
             if ($this->data) {
                 return $food->create($this->data);
             }
         } else {
             if ($this->method == 'DELETE') {
                 if ($this->id) {
                     return $food->deleteById($this->id);
                 }
             }
         }
     }
     return "";
 }
Example #2
0
 public function getList()
 {
     $food = new Food();
     $userId = $_SESSION["userId"];
     $result = SQL::query("SELECT * FROM calories WHERE user_id = " . $userId . ";");
     $response = array();
     for ($i = 0; $i < $result->num_rows; $i++) {
         $line = SQL::fetchAssoc($result);
         $foodData = $food->getById($line["food_id"]);
         $line["food_data"] = $foodData;
         array_push($response, $line);
     }
     return $response;
 }