From: Sébastien CHAZALLET Date: Wed, 7 Nov 2012 10:31:52 +0000 (+0100) Subject: Sélection des modèles à garder X-Git-Url: http://git.inspyration.org/?p=zf2.biz%2Fgalerie.git;a=commitdiff_plain;h=a8a6dbc32613045bedebff292f83aedc5380c49c Sélection des modèles à garder --- diff --git a/module/Galerie/Module.php b/module/Galerie/Module.php index e5089b4..d029076 100644 --- a/module/Galerie/Module.php +++ b/module/Galerie/Module.php @@ -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') ); }, diff --git a/module/Galerie/src/Galerie/Controller/IndexController.php b/module/Galerie/src/Galerie/Controller/IndexController.php index 09ff09e..babaf28 100644 --- a/module/Galerie/src/Galerie/Controller/IndexController.php +++ b/module/Galerie/src/Galerie/Controller/IndexController.php @@ -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 index 0000000..89a3794 --- /dev/null +++ b/module/Galerie/src/Galerie/Model/Galerie.php @@ -0,0 +1,38 @@ +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 index c857112..0000000 --- a/module/Galerie/src/Galerie/Model/GalerieATable.php +++ /dev/null @@ -1,83 +0,0 @@ -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 index 57a0263..0000000 --- a/module/Galerie/src/Galerie/Model/GalerieArray.php +++ /dev/null @@ -1,7 +0,0 @@ -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 index a10d540..0000000 --- a/module/Galerie/src/Galerie/Model/GalerieB.php +++ /dev/null @@ -1,104 +0,0 @@ -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 index 6f8a3d8..0000000 --- a/module/Galerie/src/Galerie/Model/GalerieBTable.php +++ /dev/null @@ -1,82 +0,0 @@ -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 index dceb108..0000000 --- a/module/Galerie/src/Galerie/Model/GalerieC.php +++ /dev/null @@ -1,38 +0,0 @@ -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 index 8d3ce70..0000000 --- a/module/Galerie/src/Galerie/Model/GalerieCTable2.php +++ /dev/null @@ -1,53 +0,0 @@ -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 index 753a613..0000000 --- a/module/Galerie/src/Galerie/Model/GalerieCTable3.php +++ /dev/null @@ -1,78 +0,0 @@ -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 index 194cded..0000000 --- a/module/Galerie/src/Galerie/Model/GalerieE3Table.php +++ /dev/null @@ -1,72 +0,0 @@ -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 index 0000000..62ffc62 --- /dev/null +++ b/module/Galerie/src/Galerie/Model/GalerieTable.php @@ -0,0 +1,78 @@ +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/view/galerie/index/index.phtml b/module/Galerie/view/galerie/index/index.phtml index 71ea2ed..b32b282 100644 --- a/module/Galerie/view/galerie/index/index.phtml +++ b/module/Galerie/view/galerie/index/index.phtml @@ -1,76 +1,16 @@

vue back-office d’une galerie : translate('index', 'galerie'); ?>

-

GalerieArray

+

Galerie

test de fetchAll()

-
count(); ?>
-
toArray()); ?>
+
count(); ?>
+
toArray()); ?>

test de getGalerie

-
-

Identifiant :

- - -

GalerieA

-

test de fetchAll()

- -
count(); ?>
-
toArray()); ?>
- -

test de getGalerie

- -
-

Identifiant : id; ?>

- - -

GalerieB

-

test de fetchAll()

- -
count(); ?>
-
toArray()); ?>
- -

test de getGalerie

- -
-

Identifiant : getId(); ?>

- - -

GalerieC

-

test de fetchAll()

- -
count(); ?>
-
toArray()); ?>
- -

test de getGalerie

- -
-

Identifiant : id; ?>

- - -

GalerieC2

-

test de fetchAll()

- -
count(); ?>
-
toArray()); ?>
- -

test de getGalerie

- -
-

Identifiant : id; ?>

- - -

GalerieC3

-

test de fetchAll()

- -
count(); ?>
-
toArray()); ?>
- -

test de getGalerie

- -
-

Identifiant : id; ?>

+
+

Identifiant : id; ?>

GalerieInfo