/** * 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'))); }
/** * Removes an album by its associated id * * @param string $albumId * @return boolean */ private function removeAlbumById($albumId) { $this->albumMapper->deleteById($albumId); $this->removeWebPage($albumId); // Grab all photos associated with target album id $photosIds = $this->photoMapper->fetchPhotoIdsByAlbumId($albumId); // Do batch removal if album has at least one photo if (!empty($photosIds)) { foreach ($photosIds as $photoId) { // Remove a photo $this->imageManager->delete($photoId) && $this->photoMapper->deleteById($photoId); } } $this->albumPhoto->delete($albumId); return true; }
/** * Updates a photo * * @param array $input Raw input data * @return boolean */ public function update(array $input) { $data =& $input['data']['photo']; // Upload a photo if present and override it if (!empty($input['files'])) { $input = $this->prepareInput($input); $file =& $input['files']['file']; // First of all, we need to remove old photo on the file-system if ($this->imageManager->delete($data['id'], $data['photo'])) { // And now upload a new one $data['photo'] = $file[0]->getName(); $this->imageManager->upload($data['id'], $file); } else { return false; } } $this->track('The photo "%s" has been updated', $data['name']); return $this->photoMapper->update($data); }