2 namespace Galerie\Model;
4 use Zend\Db\Adapter\Adapter;
5 use Zend\Db\ResultSet\ResultSet;
6 use Zend\Db\TableGateway\TableGatewayInterface;
9 use Custom\Model\Entity;
11 class GalerieInfoTable implements TableGatewayInterface
15 protected $resultSetPrototype;
18 public function __construct(Adapter $adapter) {
19 // Gestion de l'adaptateur
20 if (!$adapter instanceof Adapter) {
21 throw new Exception\RuntimeException('GalerieInfoTable does not have an valid Adapter parameter');
23 $this->adapter = $adapter;
25 // Utilisation du patron de conception Prototype
26 // pour la création des objets ResultSet
27 $this->resultSetPrototype = new ResultSet();
28 $this->resultSetPrototype->setArrayObjectPrototype(
32 // Initialisation de l'outil de création de requête
33 $this->sql = new Sql($this->adapter, $this->getTable());
37 public function getTable()
39 return 'gallery'; // Table centrale de la requête
43 public function select($where = null)
45 $select = $this->sql->select()
46 ->columns(array('name', 'description'))
47 ->join('user', 'gallery.id_user = user.id', array(
48 'username' => new \Zend\Db\Sql\Expression("user.firstname || ' ' || user.lastname")
50 ->join('photo', 'gallery.id = photo.id_gallery', array(
51 'nb' => new \Zend\Db\Sql\Expression('count(photo.id)')
64 $select->where($where);
67 // prepare and execute
68 $statement = $this->sql->prepareStatementForSqlObject($select);
69 $result = $statement->execute();
72 $resultSet = clone $this->resultSetPrototype;
73 $resultSet->initialize($result);
78 public function insert($set) {
79 throw new \Exception('insert is not allowed');
82 public function update($set, $where = null) {
83 throw new \Exception('update is not allowed');
86 public function delete($where) {
87 throw new \Exception('delete is not allowed');