Example #1
0
 /**
  * Updates an album
  * 
  * @param array $input Raw input data
  * @return boolean
  */
 public function update(array $input)
 {
     $input = $this->prepareInput($input);
     $form =& $input['data']['album'];
     // Allow to remove a cover, only it case it exists and checkbox was checked
     if (isset($form['remove_cover'])) {
         // Remove a cover, but not a dir itself
         $this->albumPhoto->delete($form['id']);
         $form['cover'] = '';
     } else {
         if (!empty($input['files']['file'])) {
             $file =& $input['files']['file'];
             // If we have a previous cover's image, then we need to remove it
             if (!empty($form['cover'])) {
                 if (!$this->albumPhoto->delete($form['id'], $form['cover'])) {
                     // If failed, then exit this method immediately
                     return false;
                 }
             }
             // And now upload a new one
             $this->filterFileInput($file);
             $form['cover'] = $file[0]->getName();
             $this->albumPhoto->upload($form['id'], $file);
         }
     }
     $this->webPageManager->update($form['web_page_id'], $form['slug']);
     $this->track('Album "%s" has been updated', $form['name']);
     if ($this->hasMenuWidget()) {
         $this->updateMenuItem($form['web_page_id'], $form['name'], $input['data']['menu']);
     }
     return $this->albumMapper->update(ArrayUtils::arrayWithout($form, array('slug', 'menu', 'remove_cover')));
 }