public function addAction() { $form = new BrandForm(); $request = $this->getRequest(); if ($request->isPost()) { $brand = new Brand(); $form->setInputFilter($brand->getInputFilter()); $data = $request->getPost()->toArray(); $form->setData($data); if ($form->isValid()) { $fileService = $this->getServiceLocator()->get('Admin\\Service\\FileService'); $fileService->setDestination($this->config['component']['brand']['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 : ""; $brand->exchangeArray($data); $this->getBrandTable()->save($brand); return $this->redirect()->toRoute('admin/brand'); } } return array('form' => $form, 'config' => $this->config); }
public function save(Brand $brand) { $data = array('name' => $brand->getName(), 'image' => $brand->getImage(), 'background_image' => $brand->getBackgroundImage(), 'description' => $brand->getDescription()); $id = (int) $brand->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 true; } 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 true; } else { return false; } } }