public function addAction() { $form = new SpecificationMasterForm(); $request = $this->getRequest(); if ($request->isPost()) { $specificationMaster = new SpecificationMaster(); $form->setInputFilter($specificationMaster->getInputFilter()); $data = $request->getPost()->toArray(); $form->setData($data); if ($form->isValid()) { $fileService = $this->getServiceLocator()->get('Admin\\Service\\FileService'); $fileService->setDestination($this->config['component']['specification_master']['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')); $backgroundImage = $fileService->copy($this->params()->fromFiles('background_image')); $data['image'] = $image ? $image : ""; $data['background_image'] = $backgroundImage ? $backgroundImage : ""; $specificationMaster->exchangeArray($data); $this->getSpecificationMasterTable()->save($specificationMaster); return $this->redirect()->toRoute('admin/specification_master'); } } return array('form' => $form, 'config' => $this->config); }
public function save(SpecificationMaster $specificationMaster) { $data = array('name' => $specificationMaster->getName(), 'image' => $specificationMaster->getImage(), 'description' => $specificationMaster->getDescription()); $id = (int) $specificationMaster->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; } } }