Beispiel #1
0
 public function post($manufacturerId)
 {
     $editManufacturer = $this->collection[$manufacturerId]->fetch() ?: new stdClass();
     foreach ($_POST as $k => $v) {
         $editManufacturer->{$k} = $v;
     }
     try {
         v::object()->attribute('name', v::string()->notEmpty()->length(1, 300))->assert($editManufacturer);
         $this->collection->persist($editManufacturer);
         $this->collection->flush();
         if (empty($newManufacturer->manufacturer_featured)) {
             $newManufacturer->manufacturer_featured = null;
         }
         if ($_FILES['files']['error'] != 4) {
             foreach ($_FILES as $file) {
                 $this->uploaderService->setFile($editManufacturer->name, 'files');
                 $image = (object) ['name' => $this->uploaderService->getFile()->getNameWithExtension(), 'title' => $editManufacturer->name, 'type' => $this->uploaderService->getFile()->getMimetype(), 'manufacturer_id' => $editManufacturer->id];
                 $this->imageCollection->persist($image);
                 $this->imageCollection->flush();
                 $this->uploaderService->upload();
             }
         }
         header('HTTP/1.1 303 See Other');
         header('Location: ' . $_SERVER['REQUEST_URI']);
     } catch (NestedValidationExceptionInterface $e) {
         return ['editManufacturer' => $editManufacturer, 'messages' => $e->findMessages(['name' => 'Name must have between 1 and 300 chars', 'enabled' => 'Could not enable manufacturer'])];
     }
 }
Beispiel #2
0
 protected function postEdit($categoryId)
 {
     $editCategory = $this->collection[$categoryId]->fetch() ?: new stdClass();
     foreach ($_POST as $k => $v) {
         $editCategory->{$k} = $v;
     }
     try {
         v::object()->attribute('name', v::string()->notEmpty()->length(1, 300))->attribute('enabled', v::numeric()->between(0, 1, true), false)->assert($editCategory);
         $this->collection->persist($editCategory);
         $this->collection->flush();
         header('HTTP/1.1 303 See Other');
         header('Location: ' . $_SERVER['REQUEST_URI']);
     } catch (NestedValidationExceptionInterface $e) {
         return ['editCategory' => $editCategory, 'messages' => $e->findMessages(['name' => 'Name must have between 1 and 300 chars', 'enabled' => 'Could not enable category'])];
     }
 }
Beispiel #3
0
 public function post($featureId)
 {
     $editFeature = $this->collection[$featureId]->fetch() ?: new stdClass();
     foreach ($_POST as $k => $v) {
         $editFeature->{$k} = $v;
     }
     try {
         v::object()->attribute('name', v::string()->notEmpty()->length(1, 300))->assert($editFeature);
         $this->collection->persist($editFeature);
         $this->collection->flush();
         header('HTTP/1.1 303 See Other');
         header('Location: ' . $_SERVER['REQUEST_URI']);
         return $this->get($featureId);
     } catch (NestedValidationExceptionInterface $e) {
         return ['singleFeature' => $editFeature, 'messages' => $e->findMessages(['name' => 'Name must have between 1 and 300 chars', 'enabled' => 'Could not enable product'])];
     }
 }