public function save(Category $category) { $data = array('master_category' => $category->getMasterCategory(), 'singular_name' => $category->getSingularName(), 'plural_name' => $category->getPluralName(), 'image' => $category->getImage(), 'shipping_cost' => $category->getShippingCost(), 'additional_shipping' => $category->getAdditionalShipping(), 'description' => $category->getDescription()); $id = (int) $category->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; } } }
public function addAction() { $form = new CategoryForm(); $request = $this->getRequest(); if ($request->isPost()) { $category = new Category(); $form->setData($request->getPost()); if ($form->isValid()) { $category->exchangeArray($form->getData()); $this->getCategoryTable()->save($category); // Redirect to list of category return $this->redirect()->toRoute('category'); } } return array('form' => $form); }
public function addAction() { $form = $this->getServiceLocator()->get("Admin\\Form\\CategoryForm"); if (count($form->getMasterCategoryList()) == 0) { return $this->redirect()->toRoute('admin/master_category'); } if (count($form->getSerialNameList()) == 0) { return $this->redirect()->toRoute('admin/serial_name'); } if (count($form->getSpecificationList()) == 0) { return $this->redirect()->toRoute('admin/specification'); } $request = $this->getRequest(); if ($request->isPost()) { $category = new Category(); $form->setInputFilter($category->getInputFilter()); $data = $request->getPost()->toArray(); $data['shipping_cost'] = str_replace('.', '', $data['shipping_cost']); $data['additional_shipping'] = str_replace('.', '', $data['additional_shipping']); $form->setData($data); if ($form->isValid()) { $fileService = $this->getServiceLocator()->get('Admin\\Service\\FileService'); $fileService->setDestination($this->config['component']['category']['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 : ""; $category->exchangeArray($data); $categoryId = $this->getCategoryTable()->save($category); $serialName = $data['serial_name']; $specification = $data['specification']; $name = $data['name']; $this->getCategorySerialNameTable()->save($categoryId, $serialName); $this->getCategorySpecificationTable()->save($categoryId, $specification, $name); return $this->redirect()->toRoute('admin/category'); } } return array('form' => $form, 'config' => $this->config); }