예제 #1
0
 public function save(App $app)
 {
     $data = array('name' => $app->getName(), 'image' => $app->getImage(), 'description' => $app->getDescription());
     $id = (int) $app->getId();
     $params = array();
     $params['table'] = $this->tableGateway->getTableName();
     $params['operation'] = 1;
     $params['data'] = json_encode($data);
     if ($id == 0) {
         $this->tableGateway->insert($data);
         $id = $this->tableGateway->getLastInsertValue();
         if ($id) {
             $params['id'] = $id;
             $this->featureSet->getEventManager()->trigger("log.save", $this, $params);
             return $id;
         } else {
             return false;
         }
     } else {
         if ($this->get($id)) {
             $params['id'] = $id;
             $params['operation'] = 2;
             $this->featureSet->getEventManager()->trigger("log.save", $this, $params);
             $this->tableGateway->update($data, array('id' => $id));
             return $id;
         } else {
             return false;
         }
     }
 }
예제 #2
0
 public function addAction()
 {
     $form = new AppForm();
     $request = $this->getRequest();
     if ($request->isPost()) {
         $app = new App();
         $form->setInputFilter($app->getInputFilter());
         $data = $request->getPost()->toArray();
         $form->setData($data);
         if ($form->isValid()) {
             $fileService = $this->getServiceLocator()->get('Admin\\Service\\FileService');
             $fileService->setDestination($this->config['component']['app']['image_path']);
             $fileService->setSize($this->config['file_characteristics']['image']['size']);
             $fileService->setExtension($this->config['file_characteristics']['image']['extension']);
             $image = $fileService->copy($this->params()->fromFiles('image'));
             $data['image'] = $image ? $image : "";
             $app->exchangeArray($data);
             $this->getAppTable()->save($app);
             return $this->redirect()->toRoute('admin/app');
         }
     }
     return array('form' => $form, 'config' => $this->config);
 }