From f4f3d9d99305ec7bb9ff99f1a7d3218e090c7e2f Mon Sep 17 00:00:00 2001 From: Charles OLYMPIO <charles.olympio@ensiie.fr> Date: Mon, 20 Nov 2017 00:14:30 +0100 Subject: [PATCH] Ajout des connexions au module User --- .../data/schema.sql | 8 +++ .../src/Controller/ConnexionController.php | 68 +++++++++++++++++++ .../module/User/src/Model/Connexion.php | 18 +++++ .../module/User/src/Model/ConnexionTable.php | 66 ++++++++++++++++++ 4 files changed, 160 insertions(+) create mode 100644 ZendSkeletonApplication-master/module/User/src/Controller/ConnexionController.php create mode 100644 ZendSkeletonApplication-master/module/User/src/Model/Connexion.php create mode 100644 ZendSkeletonApplication-master/module/User/src/Model/ConnexionTable.php diff --git a/ZendSkeletonApplication-master/data/schema.sql b/ZendSkeletonApplication-master/data/schema.sql index 69a4419..d95e820 100644 --- a/ZendSkeletonApplication-master/data/schema.sql +++ b/ZendSkeletonApplication-master/data/schema.sql @@ -9,3 +9,11 @@ CREATE TABLE users ( PRIMARY KEY (id), CONSTRAINT pseudo UNIQUE (pseudo) ) ; + +CREATE TABLE connexions ( + id serial, + pseudo text NOT NULL, + token text NOT NULL, + PRIMARY KEY (id), + CONSTRAINT token UNIQUE (token) +) ; diff --git a/ZendSkeletonApplication-master/module/User/src/Controller/ConnexionController.php b/ZendSkeletonApplication-master/module/User/src/Controller/ConnexionController.php new file mode 100644 index 0000000..9cdefc8 --- /dev/null +++ b/ZendSkeletonApplication-master/module/User/src/Controller/ConnexionController.php @@ -0,0 +1,68 @@ +<?php +namespace User\Controller; + +use User\Model\UserTable; +use Zend\Mvc\Controller\AbstractActionController; +use Zend\View\Model\ViewModel; + +class UserController extends AbstractActionController +{ + // Add this property: + private $table; + + // Add this constructor: + public function __construct(ConnexionTable $table) + { + $this->table = $table; + } + + public function indexAction() + { + return new ViewModel([ + 'users' => $this->table->fetchAll(), + ]); + } + + public function registerAction() + { + } + + public function connectAction() + { + } + + public function getUserAction() + { + } + + public function getUserByNameAction() + { + } + + public function getUserByPseusoAction() + { + } + + public function getRoleAction() + { + } + + public function disconnectAction() + { + } + + public function editAction() + { + } + + public function deleteAction() + { + } + + public function HashPassword() + { + } + + +} + ?> diff --git a/ZendSkeletonApplication-master/module/User/src/Model/Connexion.php b/ZendSkeletonApplication-master/module/User/src/Model/Connexion.php new file mode 100644 index 0000000..ba4266b --- /dev/null +++ b/ZendSkeletonApplication-master/module/User/src/Model/Connexion.php @@ -0,0 +1,18 @@ +<?php +namespace User\Model; + +class Connexion +{ + public $id; + public $pseudo; + public $token; + + public function exchangeArray(array $data) + { + $this->id = !empty($data['id']) ? $data['id'] : null; + $this->pseudo = !empty($data['pseudo']) ? $data['pseudo'] : null; + $this->token = !empty($data['token']) ? $data['token'] : null; + + } +} + ?> diff --git a/ZendSkeletonApplication-master/module/User/src/Model/ConnexionTable.php b/ZendSkeletonApplication-master/module/User/src/Model/ConnexionTable.php new file mode 100644 index 0000000..a3439d7 --- /dev/null +++ b/ZendSkeletonApplication-master/module/User/src/Model/ConnexionTable.php @@ -0,0 +1,66 @@ +<?php +namespace Connexion\Model; + +use RuntimeException; +use Zend\Db\TableGateway\TableGatewayInterface; + +class ConnexionTable +{ + private $tableGateway; + + public function __construct(TableGatewayInterface $tableGateway) + { + $this->tableGateway = $tableGateway; + } + + public function fetchAll() + { + return $this->tableGateway->select(); + } + + public function getConnexion($id) + { + $id = (int) $id; + $rowset = $this->tableGateway->select(['id' => $id]); + $row = $rowset->current(); + if (! $row) { + throw new RuntimeException(sprintf( + 'Could not find row with identifier %d', + $id + )); + } + + return $row; + } + + public function saveConnexion(Connexion $Connexion) + { + $data = [ + 'pseudo' => $Connexion->pseudo, + 'token' => $Connexion->token, + ]; + + $id = (int) $Connexion->id; + + if ($id === 0) { + $this->tableGateway->insert($data); + return; + } + + if (! $this->getConnexion($id)) { + throw new RuntimeException(sprintf( + 'Cannot update Connexion with identifier %d; does not exist', + $id + )); + } + + $this->tableGateway->update($data, ['id' => $id]); + } + + public function deleteConnexion($id) + { + $this->tableGateway->delete(['id' => (int) $id]); + } +} + + ?> -- GitLab