From 35b74c94580e8e6d713c704d6603df0d7bc8acd6 Mon Sep 17 00:00:00 2001 From: osaajani Date: Wed, 13 Nov 2019 06:13:55 +0100 Subject: [PATCH] update command and contact controller to user standard --- .createDatabase.sql.swp | Bin 16384 -> 0 bytes controllers/internals/Command.php | 4 +- controllers/internals/Contact.php | 139 +++++++----------------------- models/Contact.php | 24 ++++++ 4 files changed, 58 insertions(+), 109 deletions(-) delete mode 100644 .createDatabase.sql.swp diff --git a/.createDatabase.sql.swp b/.createDatabase.sql.swp deleted file mode 100644 index 90714080d8a9f4811e106ac7168a8f6ebf1feb0b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 16384 zcmeI3TWl0n7{`w&!Ya2wqQCpWH?M9k)4zT|HtMt4Y<<6#O4f&EGp$Afk@|$eWQ(=SmfRzoY?Zk^S>|}LTPPqD zn4|(3tG8~=eA3+1XfO4u#~-6h7RM%eGI5wtKqw#-5DEwdgaSeVp@2|8DDYoYz)H^| zyD{)txxv4h`@FB{^ZwlTw%q65qW0WZ@gWot3J3*+0zv_yfKWgvAQTV^2nB=!LII(` zJ*a@J5V8{ETFVOnc>h0~|9`cRkT1b;a1a~-8DN4iSPhnd-xd&Z7MuV_!JFVP*Z~GW z477rkfPfqG(Fg1Wd%!DTGuQ<1dXlUFf6XK0XK)4_1}}g$parZ3i@*YK<6%O+2PeUP zkOg7zJa`s71D1oO;O0Yw`~*G&N5CGi8O#T_U4+~MH^HCaTks9|02~B6!Dg@y+?-3u zWpDxf2u^{Izya_wcnNfZzvo~M;4-)bPJ$1?KClaPg8;boAR%vqqu>bG4s;L%O<*aQ z4c?tiNEECGUEoPj1!jS(4-oP-_ylx=dB6qcf(t0z`~W@%Z-Lz)2^NEeU;+3Q_x?Kg z9J~+q0Ta9kxLtIBJ8Z75urJ^VZ=#*jCR(E^?porKm6WQ{wou3~d4e<;iqc@r??;1~ zFx0d~H+aI{b)IldV?%>`WV0rxSiZ5TWn>%0rYiA_$qecX;)I2hs)}O|^~9o~xG(4p zO93euttB-Czj~q)je6Sr67_Z12TL1$k!XY_^i)dL6hhps#MKcBOTM+i;i<&UL_bq9 zNv61ISn80%QqU_!XnwCfT^b6~cF8Z{{9aGQ>uHzxo>*5qzhZ6=DJ7DYN%ded!&)>s zrNCSZ*O|@<=g%4+8bIlp_ZfO7?U;49y{mfybFP${u%i+-2f^$SI&1-5XFy2%x}|kY z=$a)bEQgZ0efP4G!$TZpcojFw+?8ii&8gdZS&J;MV;Ng@SntF~Cu zL$e)cE#(f@J=)K4uj(*S+s$%kJ|6E@diD-qUgYR2<;-(FYRGu*>g31t?RP_(yj|E2 zx?=xH_#H7V*~*wy3dRC8)fsJ@rf0S4T3W5Jq&mP1rtmMlvWn+nb>Y#BhhK*$=8w|C zA@kOm>p0+xYm$mh=k zp6mC51n2=C@ElkH=78(S>Cc1XU=VBt%fX}I5%3*y`4iwh@EXuS06Ya2gFleJUjdiE zMQ|FN0*AmLhyy>kja>c;xCAbO)8G_11O|Z&0^lFa^%rmrTm_$k)8Gv-2)2Muz%^M5 zeuq9h-#-J6fg@lS$btbNHlct}Kqw#-5DEwd#-#x2ti04(9L*7zf`0=v^P!cy^^U#9 z=uoO@92ey=up`iQWsGEgNKGZ9J$I>V70+feC(h@r6H73%tfybsx5c+-n4z+vP09^GDWTT6((7ZRc0@u9Li- zwC06KC>Y=1@%!3q?1ksXdmG+7v}+xJ1NgC zk#V9PKy|C1Ct!RzPw(m&?d*o69(^ZdMNVV5amO8T?4w=#=>~57meq;a8u>JEMIkW VsKxEP5`wV-B<$t9R%MFz{{k0|UtRzJ diff --git a/controllers/internals/Command.php b/controllers/internals/Command.php index 4970b8c..4ae7abc 100755 --- a/controllers/internals/Command.php +++ b/controllers/internals/Command.php @@ -66,12 +66,12 @@ namespace controllers\internals; */ public function update_for_user(int $id_user, int $id, string $name, string $script, bool $admin) { - $command = [ + $datas = [ 'name' => $name, 'script' => $script, 'admin' => $admin, ]; - return $this->model_command->update_for_user($id_user, $id, $command); + return $this->model_command->update_for_user($id_user, $id, $datas); } } diff --git a/controllers/internals/Contact.php b/controllers/internals/Contact.php index 05119b3..19e4796 100755 --- a/controllers/internals/Contact.php +++ b/controllers/internals/Contact.php @@ -11,123 +11,50 @@ namespace controllers\internals; - /** - * Classe des contactes. - */ - class Contact extends \descartes\InternalController + class Contact extends StandardController { - private $model_contact; - private $internal_event; - - public function __construct(\PDO $bdd) - { - $this->model_contact = new \models\Contact($bdd); - $this->internal_event = new \controllers\internals\Event($bdd); - } + protected $model = false; /** - * List contacts for a user - * @param int $id_user : user id - * @param mixed(int|bool) $nb_entry : Number of entry to return - * @param mixed(int|bool) $page : Pagination, will offset $nb_entry * $page results - * @return array + * Get the model for the Controller + * @return \descartes\Model */ - public function list($id_user, $nb_entry = null, $page = null) + protected function get_model () : \descartes\Model { - return $this->model_contact->list_for_user($id_user, $nb_entry, $nb_entry * $page); - } - - /** - * Return a contact - * @param $id : contact id - * @return array - */ - public function get($id) - { - return $this->model_contact->get($id); - } + $this->model = $this->model ?? new \models\Contact($this->$bdd); + return $this->model; + } - /** - * Cette fonction retourne une liste des contactes sous forme d'un tableau. - * @param int $id_user : user id - * @param array int $ids : Les ids des entrées à retourner - * @return array : La liste des contactes - */ - public function gets_for_user($id_user, $ids) - { - //Recupération des contactes - return $this->model_contact->gets_for_user($id_user, $ids); - } - - /** - * Cette fonction retourne un contact par son numéro de tel. - * - * @param string $number : Le numéro du contact - * - * @return array : Le contact - */ - public function get_by_number($number) - { - //Recupération des contactes - return $this->model_contact->get_by_number($number); - } - - /** * Return a contact for a user by a number * @param int $id_user : user id * @param string $number : Contact number * @return array */ - public function get_by_number_and_user($number, $id_user) + public function get_by_number_and_user(int $id_user, string $number,) { - //Recupération des contactes - return $this->model_contact->get_by_number_and_user($number, $id_user); + return $this->model_contact->get_by_number_and_user($id_user, $number); } + /** - * Cette fonction retourne un contact par son name. - * - * @param string $name : Le name du contact - * - * @return array : Le contact + * Return a contact by his name for a user + * @param int $id_user : User id + * @param string $name : Contact name + * @return array */ - public function get_by_name($name) + public function get_by_name_and_user(int $id_user, string $name) { - //Recupération des contactes - return $this->model_contact->get_by_name($name); + return $this->model_contact->get_by_name_and_user($id_user, $name); } - /** - * Cette fonction permet de compter le nombre de contacts. - * - * @return int : Le nombre d'entrées dans la table - */ - public function count() - { - return $this->model_contact->count(); - } /** - * Cette fonction va supprimer un contact. - * - * @param array $id : L'id du contact à supprimer - * - * @return int : Le nombre de contact supprimées; - */ - public function delete($id) - { - return $this->model_contact->delete($id); - } - - /** - * Cette fonction insert une nouvelle contacte. - * - * @param int $id_user : user id - * @param mixed $number - * @param mixed $name - * - * @return mixed bool|int : false si echec, sinon l'id de la nouvelle contacte insérée + * Create a new command + * @param int $id_user : User id + * @param string $number : Contact number + * @param string $name : Contact name + * @return mixed bool|int : False if cannot create contact, id of the new contact else */ public function create($id_user, $number, $name) { @@ -148,24 +75,22 @@ namespace controllers\internals; return $result; } + /** - * Cette fonction met à jour une série de contactes. - * - * @param mixed $id - * @param int $id_user : user id - * @param mixed $number - * @param mixed $name - * - * @return int : le nombre de ligne modifiées + * Update a contact + * @param int $id_user : User id + * @param int $id : Command id + * @param string $number : Contact number + * @param string $name : Contact name + * @return int : number of modified rows */ - public function update($id, $id_user, $number, $name) + public function update_for_user(int $id_user, int $id, string $number, string $name) { - $contact = [ - 'id_user' => $id_user, + $datas = [ 'number' => $number, 'name' => $name, ]; - return $this->model_contact->update($id, $contact); + return $this->model_contact->update_for_user($id_user, $id, $datas); } } diff --git a/models/Contact.php b/models/Contact.php index f058dff..02c12b2 100755 --- a/models/Contact.php +++ b/models/Contact.php @@ -18,4 +18,28 @@ namespace models; * @return string */ protected function get_table_name() : string { return 'contact'; } + + + /** + * Return a contact by his number for a user + * @param int $id_user : User id + * @param string $number : Contact number + * @return array + */ + public function get_by_number_and_user (int $id_user, string $number) + { + return $this->_select($this->get_table_name(), ['id_user' => $id_user, 'number' => $number]); + } + + + /** + * Return a contact by his name for a user + * @param int $id_user : User id + * @param string $name : Contact name + * @return array + */ + public function get_by_name_and_user (int $id_user, string $name) + { + return $this->_select($this->get_table_name(), ['id_user' => $id_user, 'name' => $name]); + } }