b8847a0cbde5f5032355eebd8f6582091f289114
[zf2.biz/galerie.git] / module / Galerie / src / Galerie / Controller / IndexController.php
1 <?php
2
3 namespace Galerie\Controller; 
4
5 use Zend\Mvc\Controller\AbstractActionController; 
6 use Zend\View\Model\ViewModel;
7
8 class IndexController extends AbstractActionController 
9 {
10
11     private $_galerieTable;
12     private $_galerieInfoTable;
13
14
15     private function _getGalerieTable()
16     {
17         if (!$this->_galerieTable) {
18             $sm = $this->getServiceLocator();
19             $this->_galerieTable = $sm->get('Galerie\Model\GalerieTable');
20         }
21         return $this->_galerieTable;
22     }
23
24     private function _getGalerieInfoTable()
25     {
26         if (!$this->_galerieInfoTable) {
27             $sm = $this->getServiceLocator();
28             $this->_galerieInfoTable = $sm->get('Galerie\Model\GalerieInfoTable');
29         }
30         return $this->_galerieInfoTable;
31     }
32
33
34     public function indexAction() 
35     { 
36         return new ViewModel(array(
37             'galeries' => $this->_getGalerieInfoTable()->all(),
38         )); 
39     } 
40
41     public function editAction() 
42     { 
43         // Récupération de l'objet de travail
44         $id = $this->params()->fromRoute('id', null);
45         $galerie = $this->_getGalerieTable()->any($id);
46
47         // Récupération de l'objet requête
48         $request = $this->getRequest();
49         if ($request->isPost()) {
50             // Validation des données
51
52             if (true) {//TODO: Si les données sont valides
53                 // Sauvegarde des données
54                 // $this->_getGalerieTable()->save(?TODO?);
55
56                 // Redirection 
57                 return $this->redirect()->toRoute('galerie');
58             }
59         }
60         return new ViewModel(array(
61             'id' => $id,
62             'galerie' => $galerie,
63         ));
64     } 
65
66     public function delAction() 
67     { 
68         return $this->redirect()->toRoute('galerie/view', array(
69             'id' => $id,
70         ));
71     } 
72
73     public function viewAction() 
74     {
75         $id = $this->params()->fromRoute('id', null);
76         $galerie = $this->_getGalerieInfoTable()->any($id);
77         return new ViewModel(array(
78             'id' => $id,
79             'galerie' => $galerie,
80         ));
81     } 
82
83