Esempio n. 1
0
 /**
  * Updates a post
  * 
  * @param array $input Raw input data
  * @return boolean Depending on success
  */
 public function update(array $input)
 {
     $form = $this->prepareInput($input);
     $post =& $form['data']['post'];
     // Allow to remove a cover, only it case it exists and checkbox was checked
     if (isset($post['remove_cover']) && !empty($post['cover'])) {
         // Remove a cover, but not a dir itself
         $this->imageManager->delete($post['id'], $post['cover']);
         $post['cover'] = '';
     } else {
         // Do the check only in case cover doesn't need to be removed
         if (!empty($form['files'])) {
             // If we have a previous cover, then we gotta remove it
             if (!empty($post['cover'])) {
                 // Remove previous one
                 $this->imageManager->delete($post['id'], $post['cover']);
             }
             $file = $form['files']['file'];
             // Before we start uploading a file, we need to filter its base name
             $this->filterFileInput($file);
             $this->imageManager->upload($post['id'], $file);
             // Now override cover's value with file's base name we currently have from user's input
             $post['cover'] = $file[0]->getName();
         }
     }
     // Update a record itself now
     $this->postMapper->update(ArrayUtils::arrayWithout($post, array('date', 'slug', 'remove_cover')));
     // Update a slug
     $this->webPageManager->update($post['web_page_id'], $post['slug']);
     // And finally now just track it
     $this->track('Post "%s" has been updated', $post['name']);
     return true;
 }
Esempio n. 2
0
 /**
  * Updates a category
  * 
  * @param array $input Raw input data
  * @return boolean
  */
 public function update(array $input)
 {
     $input = $this->prepareInput($input);
     $category =& $input['data']['category'];
     // Allow to remove a cover, only it case it exists and checkbox was checked
     if (isset($category['remove_cover'])) {
         // Remove a cover, but not a dir itself
         $this->imageManager->delete($category['id']);
         $category['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($category['cover'])) {
                 if (!$this->imageManager->delete($category['id'], $category['cover'])) {
                     // If failed, then exit this method immediately
                     return false;
                 }
             }
             // And now upload a new one
             $this->filterFileInput($file);
             $category['cover'] = $file[0]->getName();
             $this->imageManager->upload($category['id'], $file);
         }
     }
     $this->webPageManager->update($category['web_page_id'], $category['slug']);
     if ($this->hasMenuWidget() && isset($input['menu'])) {
         $this->updateMenuItem($category['web_page_id'], $category['name'], $input['menu']);
     }
     $this->track('Category "%s" has been updated', $category['name']);
     return $this->categoryMapper->update(ArrayUtils::arrayWithout($category, array('menu', 'slug', 'remove_cover')));
 }
Esempio n. 3
0
 /**
  * Updates a post
  * 
  * @param array $input Raw input data
  * @return boolean
  */
 public function update(array $input)
 {
     $input = $this->prepareInput($input);
     $this->webPageManager->update($input['web_page_id'], $input['slug']);
     $this->track('Post "%s" has been updated', $input['name']);
     return $this->postMapper->update(ArrayUtils::arrayWithout($input, array('date', 'slug')));
 }
Esempio n. 4
0
 /**
  * Updates a page
  * 
  * @param array $input Raw input data
  * @return boolean
  */
 public function update(array $input)
 {
     $input = $this->prepareInput($input);
     $page =& $input['page'];
     $this->webPageManager->update($page['web_page_id'], $page['slug'], $page['controller']);
     if ($this->hasMenuWidget() && isset($input['menu'])) {
         $this->updateMenuItem($page['web_page_id'], $page['name'], $input['menu']);
     }
     $this->track('The page "%s" has been updated', $page['name']);
     return $this->pageMapper->update(ArrayUtils::arrayWithout($page, array('controller', 'makeDefault', 'slug', 'menu')));
 }
Esempio n. 5
0
 /**
  * Updates a category
  * 
  * @param array $input Raw input data
  * @return boolean Depending on success
  */
 public function update(array $input)
 {
     $input = $this->prepareInput($input);
     $category =& $input['category'];
     $this->webPageManager->update($category['web_page_id'], $category['slug']);
     // If at least one menu widget it added
     if ($this->hasMenuWidget() && isset($input['menu'])) {
         $this->updateMenuItem($category['web_page_id'], $category['name'], $input['menu']);
     }
     // Track it
     $this->track('Category "%s" has been updated', $category['name']);
     return $this->categoryMapper->update(ArrayUtils::arrayWithout($category, array('slug', 'menu')));
 }
Esempio n. 6
0
 /**
  * Updates a form
  * 
  * @param array $input Raw input data
  * @return boolean
  */
 public function update(array $input)
 {
     $input = $this->prepareInput($input);
     $form = $input['form'];
     if ($this->formMapper->update(ArrayUtils::arrayWithout($form, array('slug', 'menu')))) {
         $this->webPageManager->update($form['web_page_id'], $form['slug']);
         if ($this->hasMenuWidget() && isset($input['menu'])) {
             $this->updateMenuItem($form['web_page_id'], $form['name'], $input['menu']);
         }
         $this->track('Mail form "%s" has been updated', $form['name']);
         return true;
     } else {
         return false;
     }
 }
Esempio n. 7
0
 /**
  * Updates a product
  * 
  * @param array $input Raw input data
  * @return boolean
  */
 public function update(array $input)
 {
     $input = $this->prepareInput($input);
     // Product data
     $product =& $input['data']['product'];
     // Current product id we're dealing with
     $productId = $product['id'];
     // An array of new appended images from a user
     $appendedImages = $input['files']['file'];
     if (!empty($input['files'])) {
         // Array of changed images, representing an id => FileBag instance
         $changedImages = $this->getChangedImages($input['files']);
         // Do we have any changed image?
         if (!empty($changedImages)) {
             foreach ($changedImages as $imageId => $fileBag) {
                 // First of all we need to remove old image
                 if ($this->imageManager->delete($productId, $this->imageMapper->fetchFileNameById($imageId))) {
                     $this->filterFileInput($fileBag);
                     $this->imageManager->upload($productId, $fileBag);
                     $this->imageMapper->updateFileNameById($imageId, $fileBag[0]->getName());
                 }
             }
             // PHP hasn't block scope, so we have to remove it manually
             unset($fileBag);
         }
     }
     // New user appended images
     if (!empty($appendedImages)) {
         // Upload all appended files firstly
         if ($this->imageManager->upload($productId, $appendedImages)) {
             // Then save them
             foreach ($appendedImages as $fileBag) {
                 $this->imageMapper->insert($productId, $fileBag->getName(), 1, 1);
             }
         }
     }
     $photos =& $input['data']['photos'];
     // Do we have images to delete?
     if (isset($photos['toDelete'])) {
         // Grab photo ids we're gonna remove
         $ids = array_keys($photos['toDelete']);
         foreach ($ids as $imageId) {
             // Try to remove on file-system first
             if ($this->imageManager->delete($productId, $this->imageMapper->fetchFileNameById($imageId))) {
                 // If successful, then remove from a storage as well
                 $this->imageMapper->deleteById($imageId);
             }
         }
     }
     if (isset($photos['published'])) {
         // Update photos published state
         foreach ($photos['published'] as $id => $published) {
             $this->imageMapper->updatePublishedById($id, $published);
         }
     }
     if (isset($photos['order'])) {
         // Update photos order
         foreach ($photos['order'] as $id => $order) {
             $this->imageMapper->updateOrderById($id, $order);
         }
     }
     // Update a cover now
     if (isset($photos['cover'])) {
         $product['cover'] = $photos['cover'];
     }
     $this->track('Product "%s" has been updated', $product['name']);
     $this->webPageManager->update($product['web_page_id'], $product['slug']);
     return $this->productMapper->update(ArrayUtils::arrayWithout($product, array('slug')));
 }