diff --git a/class/BackEnd/User/user.class.php b/class/BackEnd/User/user.class.php index 0de8ba56caa7435c6f0bbf023bdf9139133ff59d..a4c4cebc1f2f4b7e1fb741263125d38c20d80acb 100644 --- a/class/BackEnd/User/user.class.php +++ b/class/BackEnd/User/user.class.php @@ -1 +1 @@ -<?php namespace BackEnd\User; require_once 'class/BackEnd/DB/sqlmanager.class.php'; abstract class User { protected $id; protected $name; protected $phone; protected $email; protected $address; protected $password; protected $sql; protected $type; public function __construct(string $field, string $value) { $this->sql=\BackEnd\DB\SQLManager::getInstance()->getSQLInstance(); $bind = array( ':search' => $value ); if($field === 'login') { $result = $this->sql->select("User", "login = :search", $bind); } else if($field === 'id') { $result = $this->sql->select("User", "id = :search", $bind); } else { throw new \Exception('Invalid type to find the user.'); } if(empty($result)) { throw new \Exception('User not found'); } $this->id = $result[0]['id']; $this->name = $result[0]['name']; $this->phone = $result[0]['phone']; $this->email = $result[0]['email']; $this->address = $result[0]['address']; $this->password = $result[0]['password']; $this->type = $result[0]['type']; } public function getId() { return $this->id; } public function getName() { return $this->name; } public function getPhone() { return $this->phone; } public function getEmail() { return $this->email; } public function getAddress() { return $this->address; } public function getPassword() { return $this->password; } public function getLogin() { return $this->login; } public function getType() { return $this->type; } /* No setter for id: we shouldn't change id */ public function setName(string $name) { $this->name = $name; $update = array("name" => $name); $bind = array(":id" => $this->id); $sql->update("User", $update, "id = :id", $bind); } public function setPhone(string $phone) { $this->phone = $phone; $update = array(":phone" => $phone); $bind = array(":id" => $this->id); $sql->update("User", $update, ":id = $id", $bind); } public function setEmail(string $email) { $this->email = $email; $update = array(":email" => $email); $bind = array(":id" => $this->id); $sql->update("User", $update, ":id = $id", $bind); } public function setAddress(string $address) { $this->address = $address; $update = array(":address" => $address); $bind = array(":id" => $this->id); $sql->update("User", $update, ":id = $id", $bind); } public function setPassword(string $password) { $this->password = $password; $update = array(":password" => $password); $bind = array(":id" => $this->id); $sql->update("User", $update, ":id = $id", $bind); } public abstract static function addUser(string $login, string $email, string $password, string $name, string $address, string $phone); } \ No newline at end of file +<?php namespace BackEnd\User; require_once 'class/BackEnd/DB/sqlmanager.class.php'; abstract class User { protected $id; protected $name; protected $phone; protected $email; protected $address; protected $password; protected $sql; protected $type; protected $login; public function __construct(string $field, string $value) { $this->sql=\BackEnd\DB\SQLManager::getInstance()->getSQLInstance(); $bind = array( ':search' => $value ); if($field === 'login') { $result = $this->sql->select("User", "login = :search", $bind); } else if($field === 'id') { $result = $this->sql->select("User", "id = :search", $bind); } else { throw new \Exception('Invalid type to find the user.'); } if(empty($result)) { throw new \Exception('User not found'); } $this->id = $result[0]['id']; $this->name = $result[0]['name']; $this->phone = $result[0]['phone']; $this->email = $result[0]['email']; $this->address = $result[0]['address']; $this->password = $result[0]['password']; $this->type = $result[0]['type']; $this->login = $result[0]['login']; } public function getId() { return $this->id; } public function getName() { return $this->name; } public function getPhone() { return $this->phone; } public function getEmail() { return $this->email; } public function getAddress() { return $this->address; } public function getPassword() { return $this->password; } public function getLogin() { return $this->login; } public function getType() { return $this->type; } /* No setter for id: we shouldn't change id */ public function setName(string $name) { $this->name = $name; $update = array("name" => $name); $bind = array(":id" => $this->id); $sql->update("User", $update, "id = :id", $bind); } public function setPhone(string $phone) { $this->phone = $phone; $update = array(":phone" => $phone); $bind = array(":id" => $this->id); $sql->update("User", $update, ":id = $id", $bind); } public function setEmail(string $email) { $this->email = $email; $update = array(":email" => $email); $bind = array(":id" => $this->id); $sql->update("User", $update, ":id = $id", $bind); } public function setAddress(string $address) { $this->address = $address; $update = array(":address" => $address); $bind = array(":id" => $this->id); $sql->update("User", $update, ":id = $id", $bind); } public function setPassword(string $password) { $this->password = $password; $update = array(":password" => $password); $bind = array(":id" => $this->id); $sql->update("User", $update, ":id = $id", $bind); } public abstract static function addUser(string $login, string $email, string $password, string $name, string $address, string $phone); } \ No newline at end of file