Merge pull request #74 from ThomasRubini/difficulty_model_refactor
Difficulty model refactor
This commit is contained in:
commit
0c1da18e72
@ -2,10 +2,37 @@
|
|||||||
|
|
||||||
final class DifficultyModel
|
final class DifficultyModel
|
||||||
{
|
{
|
||||||
|
public $I_ID;
|
||||||
|
public $S_NAME;
|
||||||
|
|
||||||
public function getByID($I_id)
|
|
||||||
|
public function __construct($S_NAME){
|
||||||
|
$this->S_NAME = $S_NAME;
|
||||||
|
}
|
||||||
|
public function insert(){
|
||||||
|
$O_model = Model::get();
|
||||||
|
$stmt = $O_model->prepare("INSERT INTO DIFFICULTY (NAME) VALUES(:name)");
|
||||||
|
$stmt->bindParam("name", $this->S_NAME);
|
||||||
|
$stmt->execute();
|
||||||
|
$this->I_ID = Model::get()->lastInsertId();
|
||||||
|
}
|
||||||
|
public function update()
|
||||||
{
|
{
|
||||||
|
$O_model = Model::get();
|
||||||
|
$stmt = $O_model->prepare("UPDATE DIFFICULTY SET NAME=:name WHERE ID=:id");
|
||||||
|
$stmt->bindParam("id", $this->I_ID);
|
||||||
|
$stmt->bindParam("name", $this->S_NAME);
|
||||||
|
|
||||||
|
}
|
||||||
|
public function delete(){
|
||||||
|
$O_model = Model::get();
|
||||||
|
$stmt = $O_model->prepare("DELETE FROM DIFFICULTY WHERE ID=:id");
|
||||||
|
$stmt->bindParam("id", $this->I_ID);
|
||||||
|
$stmt->execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getByID($I_id)
|
||||||
|
{
|
||||||
$O_model = Model::get();
|
$O_model = Model::get();
|
||||||
$stmt = $O_model->prepare("SELECT * FROM DIFFICULTY WHERE ID=:id");
|
$stmt = $O_model->prepare("SELECT * FROM DIFFICULTY WHERE ID=:id");
|
||||||
$stmt->bindParam("id", $I_id);
|
$stmt->bindParam("id", $I_id);
|
||||||
@ -13,6 +40,26 @@ final class DifficultyModel
|
|||||||
|
|
||||||
$row = $stmt->fetch();
|
$row = $stmt->fetch();
|
||||||
if ($row === false) return null;
|
if ($row === false) return null;
|
||||||
return $row["NAME"];
|
|
||||||
|
$O_diff = new DifficultyModel($row["NAME"]);
|
||||||
|
$O_diff->I_ID = $I_id;
|
||||||
|
return $O_diff;
|
||||||
|
}
|
||||||
|
public static function getByName($S_name){
|
||||||
|
$O_model = Model::get();
|
||||||
|
$stmt = $O_model->prepare("SELECT ID FROM DIFFICULTY WHERE NAME=:name");
|
||||||
|
$stmt->bindParam("name", $S_name);
|
||||||
|
$stmt->execute();
|
||||||
|
|
||||||
|
$row = $stmt->fetch();
|
||||||
|
if ($row === false) return null;
|
||||||
|
return DifficultyModel::getByID($row['ID']);
|
||||||
|
}
|
||||||
|
public static function deleteByID($I_id)
|
||||||
|
{
|
||||||
|
$O_model = Model::get();
|
||||||
|
$stmt = $O_model->prepare("DELETE FROM DIFFICULTY WHERE ID=:id");
|
||||||
|
$stmt->bindParam("id", $I_id);
|
||||||
|
$stmt->execute();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -27,8 +27,7 @@ final class RecipeModel
|
|||||||
|
|
||||||
$A_recipe["AUTHOR_USERNAME"] = UserModel::getByID($A_recipe["AUTHOR_ID"])->S_USERNAME;
|
$A_recipe["AUTHOR_USERNAME"] = UserModel::getByID($A_recipe["AUTHOR_ID"])->S_USERNAME;
|
||||||
|
|
||||||
$O_difficultyModel = new DifficultyModel();
|
$A_recipe["DIFFICULTY_NAME"] = DifficultyModel::getByID($A_recipe["DIFFICULTY_ID"])->S_NAME;
|
||||||
$A_recipe["DIFFICULTY_NAME"] = $O_difficultyModel->getByID($A_recipe["DIFFICULTY_ID"]);
|
|
||||||
|
|
||||||
return $A_recipe;
|
return $A_recipe;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user