use Galerie\Model\GalerieArrayTable;
use Galerie\Model\GalerieATable;
+use Galerie\Model\GalerieBTable;
class Module implements
AutoloaderProviderInterface,
$sm->get('Zend\Db\Adapter\Adapter')
);
},
+ 'Galerie\Model\GalerieBTable' => function($sm) {
+ return new GalerieBTable(
+ $sm->get('Zend\Db\Adapter\Adapter')
+ );
+ },
),
);
}
return $this->_galerieATable;
}
+ private function _getGalerieBTable()
+ {
+ if (!$this->_galerieBTable) {
+ $sm = $this->getServiceLocator();
+ $this->_galerieBTable = $sm->get('Galerie\Model\GalerieBTable');
+ }
+ return $this->_galerieBTable;
+ }
+
public function indexAction()
{
return new ViewModel(array(
'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),
));
}
--- /dev/null
+<?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($data)
+ {
+ 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;
+ }
+
+}
--- /dev/null
+<?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
+ )
+ );
+ }
+
+}
<p>vue <em>back-office</em> d’une <strong>galerie</strong> : <?php echo $this->translate('index', 'galerie'); ?></p>
-<p>Affichage des galeries avec GalerieArray (test du fetchAll) :</p>
+
+<h1>GalerieArray</h1>
+<h2>test de fetchAll()</h2>
<pre><?php echo $GalerieArray_all->count(); ?></pre>
<pre><?php print_r($GalerieArray_all->toArray()); ?></pre>
-<p>Affichage d'une galerie avec GalerieArray (test du getGalerie) :</p>
+<h2>test de getGalerie</h2>
<pre><?php print_r($GalerieArray_one); ?></pre>
<p>Identifiant : <?php echo $GalerieArray_one['id']; ?></p>
-
-
-<p>Affichage des galeries avec GalerieA (test du fetchAll) :</p>
+<h1>GalerieA</h1>
+<h2>test de fetchAll()</h2>
<pre><?php echo $GalerieA_all->count(); ?></pre>
<pre><?php print_r($GalerieA_all->toArray()); ?></pre>
-<p>Affichage d'une galerie avec GalerieA (test du getGalerie) :</p>
+<h2>test de getGalerie</h2>
<pre><?php print_r($GalerieA_one); ?></pre>
<p>Identifiant : <?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 : <?php echo $GalerieB_one->getId(); ?></p>