コード例 #1
0
 public function save(Specification $specification)
 {
     $data = array('name' => $specification->getName(), 'specification_master' => $specification->getSpecificationMaster(), 'image' => $specification->getImage(), 'meaning' => $specification->getMeaning(), 'general_information' => $specification->getGeneralInformation());
     $id = (int) $specification->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 = $this->getServiceLocator()->get("Admin\\Form\\SpecificationForm");
     $request = $this->getRequest();
     if ($request->isPost()) {
         $specification = new Specification();
         $form->setInputFilter($specification->getInputFilter());
         $data = $request->getPost()->toArray();
         $form->setData($data);
         if ($form->isValid()) {
             $fileService = $this->getServiceLocator()->get('Admin\\Service\\FileService');
             $fileService->setDestination($this->config['component']['specification']['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 : "";
             $specification->exchangeArray($data);
             $this->getSpecificationTable()->save($specification);
             return $this->redirect()->toRoute('admin/specification');
         }
     }
     return array('form' => $form, 'config' => $this->config);
 }