Esempio n. 1
0
 /**
  * Adds an album
  * 
  * @param array $input Raw input data
  * @return boolean
  */
 public function add(array $input)
 {
     $input = $this->prepareInput($input);
     $form =& $input['data']['album'];
     // Default empty values
     $form['web_page_id'] = '';
     $form['cover'] = '';
     // If we have a cover, then we need to upload it
     if (!empty($input['files']['file'])) {
         $file =& $input['files']['file'];
         $this->filterFileInput($file);
         // Override empty cover's value now
         $form['cover'] = $file[0]->getName();
     }
     if ($this->albumMapper->insert(ArrayUtils::arrayWithout($form, array('slug', 'menu')))) {
         $id = $this->getLastId();
         // If there's a file, then it needs to uploaded as a cover
         if (!empty($input['files']['file'])) {
             $this->albumPhoto->upload($id, $input['files']['file']);
         }
         $this->track('Album "%s" has been created', $form['name']);
         if ($this->webPageManager->add($this->getLastId(), $form['slug'], 'Photogallery', 'Photogallery:Album@showAction', $this->albumMapper)) {
             // Do the work in case menu widget was injected
             if ($this->hasMenuWidget()) {
                 $this->addMenuItem($this->webPageManager->getLastId(), $form['name'], $input);
             }
         }
         return true;
     } else {
         return false;
     }
 }