Example #1
0
 /**
  * Adds a category
  * 
  * @param array $input Raw input data
  * @return boolean
  */
 public function add(array $input)
 {
     $input = $this->prepareInput($input);
     $category =& $input['data']['category'];
     // Cover is always empty by default
     $category['cover'] = '';
     // If we have a cover, then we need to upload it
     if (!empty($input['files']['file'])) {
         $file =& $input['files']['file'];
         // Now filter original file's name
         $this->filterFileInput($file);
         // Override empty cover's value now
         $category['cover'] = $file[0]->getName();
     }
     $category['web_page_id'] = '';
     if ($this->categoryMapper->insert(ArrayUtils::arrayWithout($category, array('slug', 'menu')))) {
         $id = $this->getLastId();
         // If we have a cover, then we need to upload it
         if (!empty($input['files']['file'])) {
             $this->imageManager->upload($id, $input['files']['file']);
         }
         $this->track('Added category "%s"', $category['name']);
         if ($this->webPageManager->add($id, $category['slug'], 'Shop (Categories)', 'Shop:Category@indexAction', $this->categoryMapper)) {
             // Do the work in case menu widget was injected
             if ($this->hasMenuWidget()) {
                 $this->addMenuItem($this->webPageManager->getLastId(), $category['name'], $input['data']);
             }
         }
         return true;
     }
 }