Ajout du modèle GalerieInfo model_end
authorSébastien CHAZALLET <s.chazallet@gmail.com>
Wed, 7 Nov 2012 10:13:12 +0000 (11:13 +0100)
committerSébastien CHAZALLET <s.chazallet@gmail.com>
Wed, 7 Nov 2012 10:13:12 +0000 (11:13 +0100)
module/Galerie/Module.php
module/Galerie/src/Galerie/Controller/IndexController.php
module/Galerie/src/Galerie/Model/GalerieCTable3.php
module/Galerie/src/Galerie/Model/GalerieInfo.php [new file with mode: 0644]
module/Galerie/src/Galerie/Model/GalerieInfoTable.php [new file with mode: 0644]
module/Galerie/view/galerie/index/index.phtml

index 99cad87..e5089b4 100644 (file)
@@ -18,6 +18,7 @@ use Galerie\Model\GalerieBTable;
 use Galerie\Model\GalerieCTable;
 use Galerie\Model\GalerieCTable2;
 use Galerie\Model\GalerieCTable3;
+use Galerie\Model\GalerieInfoTable;
 
 
 class Module implements
@@ -85,6 +86,11 @@ class Module implements
                         $sm->get('Zend\Db\Adapter\Adapter')
                     );
                 },
+                'Galerie\Model\GalerieInfoTable' => function($sm) {
+                    return new GalerieInfoTable(
+                        $sm->get('Zend\Db\Adapter\Adapter')
+                    );
+                },
             ),
         );
     }
index 90c0954..09ff09e 100644 (file)
@@ -14,6 +14,7 @@ class IndexController extends AbstractActionController
     private $_galerieCTable;
     private $_galerieCTable2;
     private $_galerieCTable3;
+    private $_galerieInfoTable;
 
 
     private function _getGalerieArrayTable()
@@ -70,6 +71,15 @@ class IndexController extends AbstractActionController
         return $this->_galerieCTable3;
     }
 
+    private function _getGalerieInfoTable()
+    {
+        if (!$this->_galerieInfoTable) {
+            $sm = $this->getServiceLocator();
+            $this->_galerieInfoTable = $sm->get('Galerie\Model\GalerieInfoTable');
+        }
+        return $this->_galerieInfoTable;
+    }
+
 
     public function indexAction() 
     { 
@@ -86,6 +96,9 @@ class IndexController extends AbstractActionController
             'GalerieC2_one' => $this->_getGalerieCTable2()->getGalerie(1),
             'GalerieC3_all' => $this->_getGalerieCTable3()->all(),
             'GalerieC3_one' => $this->_getGalerieCTable3()->get(1),
+            'GalerieInfo_all' => $this->_getGalerieInfoTable()->select(),
+            'GalerieInfo_one' => $this->_getGalerieInfoTable()->select(array('gallery.id' => 1))->current(),
+            'GalerieInfo_usr' => $this->_getGalerieInfoTable()->select(array('gallery.id_user' => 1)),
         )); 
     } 
 
index ce2a8f3..753a613 100644 (file)
@@ -42,4 +42,37 @@ class GalerieCTable3 extends Manager
         ));
     }
 
+
+    // Fonctionnalités supplémentaires
+
+    public function get_by_owner($id_user)
+    {
+        return $this->select(array(
+            'id_user' => (int) $id_user,
+        ));
+    }
+
+    public function delete_by_owner($id_user)
+    {
+        $this->delete(array(
+            'id_user' => (int) $id_user,
+        ));
+    }
+
+    public function get_by_name($name)
+    {
+        // la colonne 'name' est UNIQUE
+        return $this->one(array(
+            'name' => name,
+        ));
+    }
+
+    public function find_by_name($name)
+    {
+        // la colonne 'name' est UNIQUE
+        return $this->any(array(
+            'name' => name,
+        ));
+    }
+
 }
diff --git a/module/Galerie/src/Galerie/Model/GalerieInfo.php b/module/Galerie/src/Galerie/Model/GalerieInfo.php
new file mode 100644 (file)
index 0000000..4adaacd
--- /dev/null
@@ -0,0 +1,28 @@
+<?php
+
+namespace Galerie\Model;
+
+use Custom\Model\Entity;
+
+class GalerieInfo extends Entity
+{
+    public $name;
+    public $description;
+    public $username;
+    public $nb;
+
+
+    protected $columns = array(
+        'name',
+        'description',
+        'username',
+        'nb',
+    );
+
+    protected $updatable_columns = array(
+    );
+
+    protected $primary_columns = array(
+    );
+
+}
diff --git a/module/Galerie/src/Galerie/Model/GalerieInfoTable.php b/module/Galerie/src/Galerie/Model/GalerieInfoTable.php
new file mode 100644 (file)
index 0000000..2acd45d
--- /dev/null
@@ -0,0 +1,90 @@
+<?php
+namespace Galerie\Model;
+
+use Zend\Db\Adapter\Adapter;
+use Zend\Db\ResultSet\ResultSet;
+use Zend\Db\TableGateway\TableGatewayInterface;
+use Zend\Db\Sql\Sql;
+
+use Custom\Model\Entity;
+
+class GalerieInfoTable implements TableGatewayInterface
+{
+
+    protected $adapter;
+    protected $resultSetPrototype;
+    protected $sql;
+
+    public function __construct(Adapter $adapter) {
+        // Gestion de l'adaptateur
+        if (!$adapter instanceof Adapter) {
+            throw new Exception\RuntimeException('GalerieInfoTable does not have an valid Adapter parameter');
+        }
+        $this->adapter = $adapter;
+
+        // Utilisation du patron de conception Prototype
+        // pour la création des objets ResultSet
+        $this->resultSetPrototype = new ResultSet();
+        $this->resultSetPrototype->setArrayObjectPrototype(
+            new GalerieInfo()
+        );
+
+        // Initialisation de l'outil de création de requête
+        $this->sql = new Sql($this->adapter, $this->getTable());
+    }
+
+
+    public function getTable()
+    {
+        return 'gallery'; // Table centrale de la requête
+    }
+
+
+    public function select($where = null)
+    {
+        $select = $this->sql->select()
+            ->columns(array('name', 'description'))
+            ->join('user', 'gallery.id_user = user.id', array(
+                'username' => new \Zend\Db\Sql\Expression("user.firstname || ' ' || user.lastname")
+            ))
+            ->join('photo', 'gallery.id = photo.id_gallery', array(
+                'nb' => new \Zend\Db\Sql\Expression('count(photo.id)')
+            ))
+            ->group(array(
+                'user.lastname',
+                'user.firstname',
+                'gallery.name'
+            ))
+            ->order(array(
+                'user.lastname',
+                'user.firstname',
+                'gallery.name'
+            ));
+        if ($where) {
+            $select->where($where);
+        }
+
+        // prepare and execute
+        $statement = $this->sql->prepareStatementForSqlObject($select);
+        $result = $statement->execute();
+
+        // build result set
+        $resultSet = clone $this->resultSetPrototype;
+        $resultSet->initialize($result);
+
+        return $resultSet;
+    }
+
+    public function insert($set) {
+        throw new \Exception('insert is not allowed');
+    }
+
+    public function update($set, $where = null) {
+        throw new \Exception('update is not allowed');
+    }
+
+    public function delete($where) {
+        throw new \Exception('delete is not allowed');
+    }
+
+}
index 435973d..71ea2ed 100644 (file)
 <p>Identifiant&nbsp;: <?php echo $GalerieC3_one->id; ?></p>
 
 
+<h1>GalerieInfo</h1>
+<h2>test de select()</h2>
+
+<pre><?php echo $GalerieInfo_all->count(); ?></pre>
+<pre><?php print_r($GalerieInfo_all->toArray()); ?></pre>
+
+<pre><?php print_r($GalerieInfo_one); ?></pre>
+
+<pre><?php echo $GalerieInfo_usr->count(); ?></pre>
+<pre><?php print_r($GalerieInfo_usr->toArray()); ?></pre>
+
+