Sélection des modèles à garder control_start
authorSébastien CHAZALLET <s.chazallet@gmail.com>
Wed, 7 Nov 2012 10:31:52 +0000 (11:31 +0100)
committerSébastien CHAZALLET <s.chazallet@gmail.com>
Wed, 7 Nov 2012 10:31:52 +0000 (11:31 +0100)
16 files changed:
module/Galerie/Module.php
module/Galerie/src/Galerie/Controller/IndexController.php
module/Galerie/src/Galerie/Model/Galerie.php [new file with mode: 0644]
module/Galerie/src/Galerie/Model/GalerieA.php [deleted file]
module/Galerie/src/Galerie/Model/GalerieATable.php [deleted file]
module/Galerie/src/Galerie/Model/GalerieArray.php [deleted file]
module/Galerie/src/Galerie/Model/GalerieArrayTable.php [deleted file]
module/Galerie/src/Galerie/Model/GalerieB.php [deleted file]
module/Galerie/src/Galerie/Model/GalerieBTable.php [deleted file]
module/Galerie/src/Galerie/Model/GalerieC.php [deleted file]
module/Galerie/src/Galerie/Model/GalerieCTable.php [deleted file]
module/Galerie/src/Galerie/Model/GalerieCTable2.php [deleted file]
module/Galerie/src/Galerie/Model/GalerieCTable3.php [deleted file]
module/Galerie/src/Galerie/Model/GalerieE3Table.php [deleted file]
module/Galerie/src/Galerie/Model/GalerieTable.php [new file with mode: 0644]
module/Galerie/view/galerie/index/index.phtml

index e5089b4..d029076 100644 (file)
@@ -12,12 +12,7 @@ use Zend\EventManager\EventInterface;
 use Zend\Mvc\ModuleRouteListener;
 
 
-use Galerie\Model\GalerieArrayTable;
-use Galerie\Model\GalerieATable;
-use Galerie\Model\GalerieBTable;
-use Galerie\Model\GalerieCTable;
-use Galerie\Model\GalerieCTable2;
-use Galerie\Model\GalerieCTable3;
+use Galerie\Model\GalerieTable;
 use Galerie\Model\GalerieInfoTable;
 
 
@@ -56,33 +51,8 @@ class Module implements
     {
         return array(
             'factories' => array(
-                'Galerie\Model\GalerieArrayTable' => function($sm) {
-                    return new GalerieArrayTable(
-                        $sm->get('Zend\Db\Adapter\Adapter')
-                    );
-                },
-                'Galerie\Model\GalerieATable' => function($sm) {
-                    return new GalerieATable(
-                        $sm->get('Zend\Db\Adapter\Adapter')
-                    );
-                },
-                'Galerie\Model\GalerieBTable' => function($sm) {
-                    return new GalerieBTable(
-                        $sm->get('Zend\Db\Adapter\Adapter')
-                    );
-                },
-                'Galerie\Model\GalerieCTable' => function($sm) {
-                    return new GalerieCTable(
-                        $sm->get('Zend\Db\Adapter\Adapter')
-                    );
-                },
-                'Galerie\Model\GalerieCTable2' => function($sm) {
-                    return new GalerieCTable2(
-                        $sm->get('Zend\Db\Adapter\Adapter')
-                    );
-                },
-                'Galerie\Model\GalerieCTable3' => function($sm) {
-                    return new GalerieCTable3(
+                'Galerie\Model\GalerieTable' => function($sm) {
+                    return new GalerieTable(
                         $sm->get('Zend\Db\Adapter\Adapter')
                     );
                 },
index 09ff09e..babaf28 100644 (file)
@@ -8,67 +8,17 @@ use Zend\View\Model\ViewModel;
 class IndexController extends AbstractActionController 
 {
 
-    private $_galerieArrayTable;
-    private $_galerieATable;
-    private $_galerieBTable;
-    private $_galerieCTable;
-    private $_galerieCTable2;
-    private $_galerieCTable3;
+    private $_galerieTable;
     private $_galerieInfoTable;
 
 
-    private function _getGalerieArrayTable()
+    private function _getGalerieTable()
     {
-        if (!$this->_galerieArrayTable) {
+        if (!$this->_galerieTable) {
             $sm = $this->getServiceLocator();
-            $this->_galerieArrayTable = $sm->get('Galerie\Model\GalerieArrayTable');
+            $this->_galerieTable = $sm->get('Galerie\Model\GalerieTable');
         }
-        return $this->_galerieArrayTable;
-    }
-
-    private function _getGalerieATable()
-    {
-        if (!$this->_galerieATable) {
-            $sm = $this->getServiceLocator();
-            $this->_galerieATable = $sm->get('Galerie\Model\GalerieATable');
-        }
-        return $this->_galerieATable;
-    }
-
-    private function _getGalerieBTable()
-    {
-        if (!$this->_galerieBTable) {
-            $sm = $this->getServiceLocator();
-            $this->_galerieBTable = $sm->get('Galerie\Model\GalerieBTable');
-        }
-        return $this->_galerieBTable;
-    }
-
-    private function _getGalerieCTable()
-    {
-        if (!$this->_galerieCTable) {
-            $sm = $this->getServiceLocator();
-            $this->_galerieCTable = $sm->get('Galerie\Model\GalerieCTable');
-        }
-        return $this->_galerieCTable;
-    }
-
-    private function _getGalerieCTable2()
-    {
-        if (!$this->_galerieCTable2) {
-            $sm = $this->getServiceLocator();
-            $this->_galerieCTable2 = $sm->get('Galerie\Model\GalerieCTable2');
-        }
-        return $this->_galerieCTable2;
-    }
-
-    private function _getGalerieCTable3()
-    {
-        if (!$this->_galerieCTable3) {
-            $sm = $this->getServiceLocator();
-            $this->_galerieCTable3 = $sm->get('Galerie\Model\GalerieCTable3');
-        }
-        return $this->_galerieCTable3;
+        return $this->_galerieTable;
     }
 
     private function _getGalerieInfoTable()
@@ -84,18 +34,8 @@ class IndexController extends AbstractActionController
     public function indexAction() 
     { 
         return new ViewModel(array(
-            'GalerieArray_all' => $this->_getGalerieArrayTable()->fetchAll(),
-            'GalerieArray_one' => $this->_getGalerieArrayTable()->getGalerie(1),
-            'GalerieA_all' => $this->_getGalerieATable()->fetchAll(),
-            'GalerieA_one' => $this->_getGalerieATable()->getGalerie(1),
-            'GalerieB_all' => $this->_getGalerieBTable()->fetchAll(),
-            'GalerieB_one' => $this->_getGalerieBTable()->getGalerie(1),
-            'GalerieC_all' => $this->_getGalerieCTable()->fetchAll(),
-            'GalerieC_one' => $this->_getGalerieCTable()->getGalerie(1),
-            'GalerieC2_all' => $this->_getGalerieCTable2()->fetchAll(),
-            'GalerieC2_one' => $this->_getGalerieCTable2()->getGalerie(1),
-            'GalerieC3_all' => $this->_getGalerieCTable3()->all(),
-            'GalerieC3_one' => $this->_getGalerieCTable3()->get(1),
+            'Galerie_all' => $this->_getGalerieTable()->all(),
+            'Galerie_one' => $this->_getGalerieTable()->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)),
diff --git a/module/Galerie/src/Galerie/Model/Galerie.php b/module/Galerie/src/Galerie/Model/Galerie.php
new file mode 100644 (file)
index 0000000..89a3794
--- /dev/null
@@ -0,0 +1,38 @@
+<?php
+
+namespace Galerie\Model;
+
+use Custom\Model\Entity;
+
+class Galerie extends Entity
+{
+    public $id;
+    public $id_user;
+    public $name;
+    public $description;
+    public $created;
+    public $updated;
+
+
+    protected $columns = array(
+        'id',
+        'id_user',
+        'name',
+        'description',
+        'created',
+        'updated',
+    );
+
+    protected $updatable_columns = array(
+        'id_user',
+        'name',
+        'description',
+        'created',
+        'updated',
+    );
+
+    protected $primary_columns = array(
+        'id',
+    );
+
+}
diff --git a/module/Galerie/src/Galerie/Model/GalerieA.php b/module/Galerie/src/Galerie/Model/GalerieA.php
deleted file mode 100644 (file)
index 01686bb..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-<?php
-
-namespace Galerie\Model;
-
-class GalerieA
-{
-    public $id;
-    public $id_user;
-    public $name;
-    public $description;
-    public $created;
-    public $updated;
-
-    public function exchangeArray($data)
-    {
-        $this->id = isset($data['id']) ? $data['id'] : null;
-        $this->id_user = isset($data['is_user']) ? $data['id_user'] : null;
-        $this->name = isset($data['name']) ? $data['name'] : null;
-        $this->description = isset($data['description']) ? $data['description'] : null;
-        $this->created = isset($data['created']) ? $data['created'] : null;
-        $this->updated = isset($data['updated']) ? $data['updated'] : null;
-    }
-
-    public function toArray()
-    {
-        return array(
-            'id' => $this->id,
-            'is_user' => $this->id_user,
-            'name' => $this->name,
-            'description' => $this->description,
-            'created' => $this->created,
-            'updated' => $this->updated,
-        );
-    }
-
-}
diff --git a/module/Galerie/src/Galerie/Model/GalerieATable.php b/module/Galerie/src/Galerie/Model/GalerieATable.php
deleted file mode 100644 (file)
index c857112..0000000
+++ /dev/null
@@ -1,83 +0,0 @@
-<?php
-namespace Galerie\Model;
-
-use Zend\Db\Adapter\Adapter;
-use Zend\Db\ResultSet\ResultSet;
-use Zend\Db\TableGateway\AbstractTableGateway;
-
-
-class GalerieATable extends AbstractTableGateway
-{
-    public $table = 'gallery';
-
-    public function __construct(Adapter $adapter)
-    {
-        // Composition avec l'adaptateur
-        $this->adapter = $adapter;
-
-        // Utilisation du patron de conception Prototype
-        // pour la création des objets ResultSet
-        $this->resultSetPrototype = new ResultSet();
-        $this->resultSetPrototype->setArrayObjectPrototype(
-            new GalerieA()
-        );
-
-        // Initialisation du gestionnaire
-        $this->initialize();
-    }
-
-    public function fetchAll()
-    {
-        return $this->select();
-    }
-
-    public function getGalerie($id)
-    {
-        if ($id === null) {
-            $row = null;
-        } else {
-            $row = $this->select(array(
-                'id' => (int) $id,
-            ))->current();
-        }
-        if (!$row) {
-            throw new \Exception("cannot get row $id in table 'galerie'");
-        }
-        return $row;
-    }
-
-    public function saveGalerie(GalerieA $galerie)
-    {
-        if ($galerie->id === null) {
-            $this->insert(
-                array(
-                    'id_user' => $galerie->id_user,
-                    'name' => $galerie->name,
-                    'description' => $galerie->description,
-                )
-            );
-        } elseif ($this->getGalerie($galerie->id)) {
-            $this->update(
-                array(
-                    'id_user' => $galerie->id_user,
-                    'name' => $galerie->name,
-                    'description' => $galerie->description,
-                ),
-                array(
-                    'id' => $galerie->id,
-                )
-            );
-        } else {
-            throw new \Exception("cannot update row {$galerie->id} in table 'galerie'");
-        }
-    }
-
-    public function deleteGalerie($id)
-    {
-        $this->delete(array(
-                'id' => (int) $id
-            )
-        );
-    }
-
-}
diff --git a/module/Galerie/src/Galerie/Model/GalerieArray.php b/module/Galerie/src/Galerie/Model/GalerieArray.php
deleted file mode 100644 (file)
index 57a0263..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-<?php
-
-namespace Galerie\Model;
-
-class GalerieArray extends \ArrayObject
-{
-}
diff --git a/module/Galerie/src/Galerie/Model/GalerieArrayTable.php b/module/Galerie/src/Galerie/Model/GalerieArrayTable.php
deleted file mode 100644 (file)
index a81d83d..0000000
+++ /dev/null
@@ -1,81 +0,0 @@
-<?php
-namespace Galerie\Model;
-
-use Zend\Db\Adapter\Adapter;
-use Zend\Db\ResultSet\ResultSet;
-use Zend\Db\TableGateway\AbstractTableGateway;
-
-
-class GalerieArrayTable extends AbstractTableGateway
-{
-    public $table = 'gallery';
-
-    public function __construct(Adapter $adapter)
-    {
-        // Composition avec l'adaptateur
-        $this->adapter = $adapter;
-
-        // Utilisation du patron de conception Prototype
-        // pour la création des objets ResultSet
-        $this->resultSetPrototype = new ResultSet();
-        $this->resultSetPrototype->setArrayObjectPrototype(
-            new GalerieArray()
-        );
-
-        // Initialisation du gestionnaire
-        $this->initialize();
-    }
-
-    public function fetchAll()
-    {
-        return $this->select();
-    }
-
-    public function getGalerie($id)
-    {
-        if ($id === null) {
-            $row = null;
-        } else {
-            $row = $this->select(array(
-                'id' => (int) $id,
-            ))->current();
-        }
-        if (!$row) {
-            throw new \Exception("cannot get row $id in table 'galerie'");
-        }
-        return $row;
-    }
-
-    public function saveGalerie(GalerieArray $galerie)
-    {
-        if ($galerie->id === null) {
-            $this->insert(
-                array(
-                    'name' => $galerie->name,
-                    'description' => $galerie->description,
-                )
-            );
-        } elseif ($this->getGalerie($galerie->id)) {
-            $this->update(
-                array(
-                    'name' => $galerie->name,
-                    'description' => $galerie->description,
-                ),
-                array(
-                    'id' => $galerie->id,
-                )
-            );
-        } else {
-            throw new \Exception("cannot update row $galerie->id in table 'galerie'");
-        }
-    }
-
-    public function deleteGalerie($id)
-    {
-        $this->delete(array(
-                'id' => (int) $id
-            )
-        );
-    }
-
-}
diff --git a/module/Galerie/src/Galerie/Model/GalerieB.php b/module/Galerie/src/Galerie/Model/GalerieB.php
deleted file mode 100644 (file)
index a10d540..0000000
+++ /dev/null
@@ -1,104 +0,0 @@
-<?php
-
-namespace Galerie\Model;
-
-class GalerieB
-{
-    protected $id;
-    protected $id_user;
-    protected $name;
-    protected $description;
-    protected $created;
-    protected $updated;
-
-
-    public function exchangeArray($data)
-    {
-        $this->id = isset($data['id']) ? $data['id'] : null;
-        $this->id_user = isset($data['is_user']) ? $data['id_user'] : null;
-        $this->name = isset($data['name']) ? $data['name'] : null;
-        $this->description = isset($data['description']) ? $data['description'] : null;
-        $this->created = isset($data['created']) ? $data['created'] : null;
-        $this->updated = isset($data['updated']) ? $data['updated'] : null;
-    }
-
-    public function toArray()
-    {
-        return array(
-            'id' => $this->id,
-            'is_user' => $this->id_user,
-            'name' => $this->name,
-            'description' => $this->description,
-            'created' => $this->created,
-            'updated' => $this->updated,
-        );
-    }
-
-
-    public function getId()
-    {
-        return $this->id;
-    }
-
-    public function setId($id)
-    {
-        $this->id = $id;
-        return $this;
-    }
-
-    public function getIdUser()
-    {
-        return $this->id_user;
-    }
-
-    public function setIdUser($id_user)
-    {
-        $this->id_user = $id_user;
-        return $this;
-    }
-
-    public function getName()
-    {
-        return $this->name;
-    }
-
-    public function setName($name)
-    {
-        $this->name = $name;
-        return $this;
-    }
-
-    public function getDescription()
-    {
-        return $this->description;
-    }
-
-    public function setDescription ($description)
-    {
-        $this-> description = $description;
-        return $this;
-    }
-
-    public function getCreated()
-    {
-        return $this->created;
-    }
-
-    public function setCreated($created)
-    {
-        $this->created = $created;
-        return $this;
-    }
-
-    public function getUpdated()
-    {
-        return $this->updated;
-    }
-
-    public function setUpdated($updated)
-    {
-        $this->updated = $updated;
-        return $this;
-    }
-
-}
diff --git a/module/Galerie/src/Galerie/Model/GalerieBTable.php b/module/Galerie/src/Galerie/Model/GalerieBTable.php
deleted file mode 100644 (file)
index 6f8a3d8..0000000
+++ /dev/null
@@ -1,82 +0,0 @@
-<?php
-namespace Galerie\Model;
-
-use Zend\Db\Adapter\Adapter;
-use Zend\Db\ResultSet\ResultSet;
-use Zend\Db\TableGateway\AbstractTableGateway;
-
-
-class GalerieBTable extends AbstractTableGateway
-{
-    public $table = 'gallery';
-
-    public function __construct(Adapter $adapter)
-    {
-        // Composition avec l'adaptateur
-        $this->adapter = $adapter;
-
-        // Utilisation du patron de conception Prototype
-        // pour la création des objets ResultSet
-        $this->resultSetPrototype = new ResultSet();
-        $this->resultSetPrototype->setArrayObjectPrototype(
-            new GalerieB()
-        );
-
-        // Initialisation du gestionnaire
-        $this->initialize();
-    }
-
-    public function fetchAll()
-    {
-        return $this->select();
-    }
-
-    public function getGalerie($id)
-    {
-        if ($id === null) {
-            $row = null;
-        } else {
-            $row = $this->select(array(
-                'id' => (int) $id,
-            ))->current();
-        }
-        if (!$row) {
-            throw new \Exception("cannot get row $id in table 'galerie'");
-        }
-        return $row;
-    }
-
-    public function saveGalerie(GalerieA $galerie)
-    {
-        if ($galerie->getId() === null) {
-            $this->insert(
-                array(
-                    'id_user' => $galerie->getName(),
-                    'name' => $galerie->getName(),
-                    'description' => $galerie->getDescription(),
-                )
-            );
-        } elseif ($this->getGalerie($galerie->getId())) {
-            $this->update(
-                array(
-                    'name' => $galerie->getName(),
-                    'description' => $galerie->getDescription(),
-                ),
-                array(
-                    'id' => $galerie->getId(),
-                )
-            );
-        } else {
-            throw new \Exception("cannot update row {$galerie->getId()} in table 'galerie'");
-        }
-    }
-
-    public function deleteGalerie($id)
-    {
-        $this->delete(array(
-                'id' => (int) $id
-            )
-        );
-    }
-
-}
diff --git a/module/Galerie/src/Galerie/Model/GalerieC.php b/module/Galerie/src/Galerie/Model/GalerieC.php
deleted file mode 100644 (file)
index dceb108..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-<?php
-
-namespace Galerie\Model;
-
-use Custom\Model\Entity;
-
-class GalerieC extends Entity
-{
-    public $id;
-    public $id_user;
-    public $name;
-    public $description;
-    public $created;
-    public $updated;
-
-
-    protected $columns = array(
-        'id',
-        'id_user',
-        'name',
-        'description',
-        'created',
-        'updated',
-    );
-
-    protected $updatable_columns = array(
-        'id_user',
-        'name',
-        'description',
-        'created',
-        'updated',
-    );
-
-    protected $primary_columns = array(
-        'id',
-    );
-
-}
diff --git a/module/Galerie/src/Galerie/Model/GalerieCTable.php b/module/Galerie/src/Galerie/Model/GalerieCTable.php
deleted file mode 100644 (file)
index 92dd6ba..0000000
+++ /dev/null
@@ -1,73 +0,0 @@
-<?php
-namespace Galerie\Model;
-
-use Zend\Db\Adapter\Adapter;
-use Zend\Db\ResultSet\ResultSet;
-use Zend\Db\TableGateway\AbstractTableGateway;
-
-
-class GalerieCTable extends AbstractTableGateway
-{
-    public $table = 'gallery';
-
-    public function __construct(Adapter $adapter)
-    {
-        // Composition avec l'adaptateur
-        $this->adapter = $adapter;
-
-        // Utilisation du patron de conception Prototype
-        // pour la création des objets ResultSet
-        $this->resultSetPrototype = new ResultSet();
-        $this->resultSetPrototype->setArrayObjectPrototype(
-            new GalerieC()
-        );
-
-        // Initialisation du gestionnaire
-        $this->initialize();
-    }
-
-    public function fetchAll()
-    {
-        return $this->select();
-    }
-
-    public function getGalerie($id)
-    {
-        if ($id === null) {
-            $row = null;
-        } else {
-            $row = $this->select(array(
-                'id' => (int) $id,
-            ))->current();
-        }
-        if (!$row) {
-            throw new \Exception("cannot get row $id in table 'galerie'");
-        }
-        return $row;
-    }
-
-    public function saveGalerie(GalerieC $galerie)
-    {
-        if ($galerie->id === null) {
-            $this->insert(
-                $galerie->toUpdatableArray()
-            );
-        } elseif ($this->getGalerie($galerie->id)) {
-            $this->update(
-                $galerie->toUpdatableArray(),
-                $galerie->toPrimaryArray()
-            );
-        } else {
-            throw new \Exception("cannot update row {$galerie->id} in table 'galerie'");
-        }
-    }
-
-    public function deleteGalerie($id)
-    {
-        $this->delete(array(
-                'id' => (int) $id
-            )
-        );
-    }
-
-}
diff --git a/module/Galerie/src/Galerie/Model/GalerieCTable2.php b/module/Galerie/src/Galerie/Model/GalerieCTable2.php
deleted file mode 100644 (file)
index 8d3ce70..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-<?php
-namespace Galerie\Model;
-
-use Zend\Db\Adapter\Adapter;
-use Custom\Model\Manager;
-use Custom\Model\Entity;
-
-class GalerieCTable2 extends Manager
-{
-    public $table = 'gallery';
-
-    public function __construct(Adapter $adapter)
-    {
-        parent::__construct($adapter, new GalerieC());
-    }
-
-    public function fetchAll()
-    {
-        return $this->all();
-    }
-
-    public function getGalerie($id)
-    {
-        return $this->one(array(
-            'id' => (int) $id
-        ));
-    }
-
-    protected function is_new(Entity $entity)
-    {
-        return $entity->id === null;
-    }
-
-    protected function extract_primary(Entity $entity)
-    {
-        return array(
-            'id' => (int) $entity->id
-        );
-    }
-
-    public function saveGalerie(Galerie $galerie)
-    {
-        $this->save($galerie);
-    }
-
-    public function deleteGalerie($id)
-    {
-        $this->delete(array(
-            'id' => (int) $id
-        ));
-    }
-
-}
diff --git a/module/Galerie/src/Galerie/Model/GalerieCTable3.php b/module/Galerie/src/Galerie/Model/GalerieCTable3.php
deleted file mode 100644 (file)
index 753a613..0000000
+++ /dev/null
@@ -1,78 +0,0 @@
-<?php
-namespace Galerie\Model;
-
-use Zend\Db\Adapter\Adapter;
-use Custom\Model\Manager;
-use Custom\Model\Entity;
-
-class GalerieCTable3 extends Manager
-{
-    public $table = 'gallery';
-
-    public function __construct(Adapter $adapter)
-    {
-        parent::__construct($adapter, new GalerieC());
-    }
-
-    public function get($id)
-    {
-        return $this->one(array(
-            'id' => (int) $id
-        ));
-    }
-
-    protected function is_new(Entity $entity)
-    {
-        return $entity->id === null;
-    }
-
-    protected function extract_primary(Entity $entity)
-    {
-        return array(
-            'id' => (int) $entity->id
-        );
-    }
-
-    // La méthode save remplace saveGalerie
-
-    public function delete($id)
-    {
-        parent::delete(array(
-            'id' => (int) $id
-        ));
-    }
-
-
-    // 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/GalerieE3Table.php b/module/Galerie/src/Galerie/Model/GalerieE3Table.php
deleted file mode 100644 (file)
index 194cded..0000000
+++ /dev/null
@@ -1,72 +0,0 @@
-<?php
-namespace Galerie\Model
-
-use Zend\Db\Adapter\Adapter;
-use Zend\Db\ResultSet\ResultSet;
-use Zend\Db\TableGateway\AbstractTableGateway;
-
-class GalerieTableE extends AbstractTableGateway
-{
-    public $table = 'galerie';
-
-    public function __construct(Adapter $adapter)
-    {
-        // Composition avec l'adaptateur
-        $this->adapter = $adapter;
-
-        // Utilisation du patron de conception Prototype
-        // pour la création des objets ResultSet
-        $this->resultSetPrototype = new ResultSet();
-        $this->resultSetPrototype->setArrayObjectPrototype(
-            new Galerie()
-        );
-
-        // Initialisation du gestionnaire
-        $this->initialize();
-    }
-
-    public function fetchAll()
-    {
-        return $this->select();
-    }
-
-    public function getGalerie($id)
-    {
-        if ($id === null) {
-            $row = null;
-        } else {
-            $row = $this->select(array(
-                'id' => (int) $id
-            ))->current();
-        }
-        if (!$row) {
-            throw new \Exception("cannot get row $id in table 'galerie'");
-        }
-        return $row;
-    }
-
-    public saveGalerie(Galerie $galerie)
-    {
-        if ($galerie->id === null) {
-            $this->insert(
-                $galerie->toUpdatableArray()
-            );
-        } elseif ($this->getGalerie($galerie->id)) {
-            $this->update(
-                $galerie->toUpdatableArray(),
-                $galerie->toPrimaryArray()
-            );
-        } else {
-            throw new \Exception("cannot update row $galerie->id in table 'galerie'");
-        }
-    }
-
-    public function deleteGalerie($id)
-    {
-        $this->delete(array(
-                'id' => (int) $id
-            )
-        );
-    }
-
-}
diff --git a/module/Galerie/src/Galerie/Model/GalerieTable.php b/module/Galerie/src/Galerie/Model/GalerieTable.php
new file mode 100644 (file)
index 0000000..62ffc62
--- /dev/null
@@ -0,0 +1,78 @@
+<?php
+namespace Galerie\Model;
+
+use Zend\Db\Adapter\Adapter;
+use Custom\Model\Manager;
+use Custom\Model\Entity;
+
+class GalerieTable extends Manager
+{
+    public $table = 'gallery';
+
+    public function __construct(Adapter $adapter)
+    {
+        parent::__construct($adapter, new Galerie());
+    }
+
+    public function get($id)
+    {
+        return $this->one(array(
+            'id' => (int) $id
+        ));
+    }
+
+    protected function is_new(Entity $entity)
+    {
+        return $entity->id === null;
+    }
+
+    protected function extract_primary(Entity $entity)
+    {
+        return array(
+            'id' => (int) $entity->id
+        );
+    }
+
+    // La méthode save remplace saveGalerie
+
+    public function delete($id)
+    {
+        parent::delete(array(
+            'id' => (int) $id
+        ));
+    }
+
+
+    // 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,
+        ));
+    }
+
+}
index 71ea2ed..b32b282 100644 (file)
@@ -1,76 +1,16 @@
 <p>vue <em>back-office</em> d&rsquo;une <strong>galerie</strong>&nbsp;: <?php echo $this->translate('index', 'galerie'); ?></p>
 
 
-<h1>GalerieArray</h1>
+<h1>Galerie</h1>
 <h2>test de fetchAll()</h2>
 
-<pre><?php echo $GalerieArray_all->count(); ?></pre>
-<pre><?php print_r($GalerieArray_all->toArray()); ?></pre>
+<pre><?php echo $Galerie_all->count(); ?></pre>
+<pre><?php print_r($Galerie_all->toArray()); ?></pre>
 
 <h2>test de getGalerie</h2>
 
-<pre><?php print_r($GalerieArray_one); ?></pre>
-<p>Identifiant&nbsp;: <?php echo $GalerieArray_one['id']; ?></p>
-
-
-<h1>GalerieA</h1>
-<h2>test de fetchAll()</h2>
-
-<pre><?php echo $GalerieA_all->count(); ?></pre>
-<pre><?php print_r($GalerieA_all->toArray()); ?></pre>
-
-<h2>test de getGalerie</h2>
-
-<pre><?php print_r($GalerieA_one); ?></pre>
-<p>Identifiant&nbsp;: <?php echo $GalerieA_one->id; ?></p>
-
-
-<h1>GalerieB</h1>
-<h2>test de fetchAll()</h2>
-
-<pre><?php echo $GalerieB_all->count(); ?></pre>
-<pre><?php print_r($GalerieB_all->toArray()); ?></pre>
-
-<h2>test de getGalerie</h2>
-
-<pre><?php print_r($GalerieB_one); ?></pre>
-<p>Identifiant&nbsp;: <?php echo $GalerieB_one->getId(); ?></p>
-
-
-<h1>GalerieC</h1>
-<h2>test de fetchAll()</h2>
-
-<pre><?php echo $GalerieC_all->count(); ?></pre>
-<pre><?php print_r($GalerieC_all->toArray()); ?></pre>
-
-<h2>test de getGalerie</h2>
-
-<pre><?php print_r($GalerieC_one); ?></pre>
-<p>Identifiant&nbsp;: <?php echo $GalerieC_one->id; ?></p>
-
-
-<h1>GalerieC2</h1>
-<h2>test de fetchAll()</h2>
-
-<pre><?php echo $GalerieC2_all->count(); ?></pre>
-<pre><?php print_r($GalerieC2_all->toArray()); ?></pre>
-
-<h2>test de getGalerie</h2>
-
-<pre><?php print_r($GalerieC2_one); ?></pre>
-<p>Identifiant&nbsp;: <?php echo $GalerieC2_one->id; ?></p>
-
-
-<h1>GalerieC3</h1>
-<h2>test de fetchAll()</h2>
-
-<pre><?php echo $GalerieC3_all->count(); ?></pre>
-<pre><?php print_r($GalerieC3_all->toArray()); ?></pre>
-
-<h2>test de getGalerie</h2>
-
-<pre><?php print_r($GalerieC3_one); ?></pre>
-<p>Identifiant&nbsp;: <?php echo $GalerieC3_one->id; ?></p>
+<pre><?php print_r($Galerie_one); ?></pre>
+<p>Identifiant&nbsp;: <?php echo $Galerie_one->id; ?></p>
 
 
 <h1>GalerieInfo</h1>