-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
//require_once("../vendor/autoload.php"); | ||
namespace Model; | ||
use Illuminate\Database\Capsule\Manager as DBC; | ||
|
||
class DatabaseConnector | ||
{ | ||
private $dbc; | ||
|
||
public function __construct() | ||
{ | ||
$this->dbc = new DBC(); | ||
$this->dbc->addConnection(CONNECTION_STRING); | ||
$this->dbc->setAsGlobal(); | ||
$this->dbc->bootEloquent(); | ||
} | ||
|
||
/** | ||
* @return DBC | ||
*/ | ||
public function getDbc() | ||
{ | ||
return $this->dbc; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{https://cdnjs.com/libraries/jquery}[javascript] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?php | ||
|
||
namespace Services; | ||
|
||
use Model; | ||
use Illuminate\Database\Capsule\Manager; | ||
use Illuminate\Support\Collection; | ||
use Model\DatabaseConnector; | ||
|
||
class MealServices | ||
{ | ||
private DatabaseConnector $DBC; | ||
private Manager $connection; | ||
|
||
|
||
|
||
public function __construct() | ||
{ | ||
$this->DBC = new DatabaseConnector(); | ||
$this->connection = $this->DBC->getDbc(); | ||
} | ||
|
||
|
||
/** | ||
* Get All Items in Table | ||
* @return Collection | ||
*/ | ||
function getMeals(): Collection | ||
{ | ||
return $this->connection->table("Meals")->get(); | ||
} | ||
|
||
/** | ||
* Get specific item from table using id | ||
* @param int $id | ||
* @return stdClass|null | ||
*/ | ||
function getProductById(int $id): ?stdClass | ||
{ | ||
if ($id > 0) { | ||
return $this->connection->table("products")->where("id", "=", "$id") | ||
->select(["name","description","price","image"])->first(); | ||
} else { | ||
return null; | ||
} | ||
} | ||
|
||
/** | ||
* Get specific item from table using id | ||
* @param String $name | ||
* @param String $description | ||
* @param int $price | ||
* @param string $img | ||
*/ | ||
function updateTableMeals(int $id,string $name,string $description,int $price ,string $img): int | ||
{ | ||
return $this->connection->table("meal") | ||
->where('id', $id) | ||
->update([ "name" => $name ,"description" =>$description, "price" => $price, "image" =>$img]); | ||
} | ||
|
||
|
||
// insert products : for future plans | ||
/** | ||
* Add new product to database | ||
* @param String $name | ||
* @param String $description | ||
* @param int $price | ||
* @param string $img | ||
* @return bool | ||
*/ | ||
function addProduct(string $name, string $description, int $price, string $img): bool | ||
{ | ||
return $this->connection->table("meal")->insert(['name' => $name, 'description' => $description, 'price'=>$price, 'image'=>$img]); | ||
} | ||
|
||
/** | ||
* Delete product from database | ||
* @param int $id | ||
* @return int | ||
*/ | ||
function deleteProduct(int $id): int | ||
{ | ||
return $this->connection->table("meal") | ||
->where('id', '=', $id)->first()->delete(); | ||
} | ||
|
||
} |