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 ""; }
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; }