Пример #1
0
 public function indexAction()
 {
     if ($this->getRequest()->isGet()) {
         // get
         $countryTable = new CountryTable($this->getServiceLocator()->get('country-table-gateway'));
         $data = $countryTable->fetchAll(0, 30);
         $this->data = new CountryList();
         $this->data->exchangeArray($data);
     } else {
         if ($this->getRequest()->isPost()) {
             // post
             // check if POST message is a JSON object
             if ($this->getRequest()->getHeader('Content-Type')->getFieldValue() === "application/json") {
                 $countryTable = new CountryTable($this->getServiceLocator()->get('country-table-gateway'));
                 $newCountry = new Country();
                 $newCountry->exchangeArray(json_decode($this->getRequest()->getContent()));
                 try {
                     $countryTable->saveCountry($newCountry);
                 } catch (\Exception $e) {
                     $this->code = Response::STATUS_CODE_409;
                     // conflict : duplicate data
                 }
             } else {
                 $this->code = Response::STATUS_CODE_406;
                 // Only accept JSON object
             }
         } else {
             $this->code = Response::STATUS_CODE_405;
             // 405
         }
     }
     return $this->parseResponse();
 }
Пример #2
0
 public function indexAction()
 {
     $authService = $this->getServiceLocator()->get('auth-service');
     if (!$authService->hasIdentity()) {
         // not connected
         $this->redirect()->toRoute('apic-admin/default', ['controller' => 'login', 'action' => 'index']);
     } else {
         $countryTable = new CountryTable($this->getServiceLocator()->get('country-table-gateway'));
         $data = $countryTable->fetchAll(0, 30);
         $countryList = new CountryList();
         $countryList->exchangeArray($data);
         $viewContent = compact('countryList');
         //TODO add alert message and type from redirection
         return new ViewModel($viewContent);
     }
 }