Example #1
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')));
 }
Example #2
0
 /**
  * {@inheritDoc}
  */
 protected function toEntity(array $post)
 {
     $entity = new PostEntity();
     $entity->setId($post['id'], PostEntity::FILTER_INT)->setLangId($post['lang_id'], PostEntity::FILTER_INT)->setWebPageId($post['web_page_id'], PostEntity::FILTER_INT)->setCategoryTitle($this->categoryMapper->fetchNameById($post['category_id']), PostEntity::FILTER_HTML)->setTitle($post['title'], PostEntity::FILTER_HTML)->setName($post['name'], PostEntity::FILTER_HTML)->setCategoryId($post['category_id'], PostEntity::FILTER_INT)->setIntroduction($post['introduction'], PostEntity::FILTER_SAFE_TAGS)->setFull($post['full'], PostEntity::FILTER_SAFE_TAGS)->setTimestamp($post['timestamp'], PostEntity::FILTER_INT)->setPublished($post['published'], PostEntity::FILTER_BOOL)->setComments($post['comments'], PostEntity::FILTER_BOOL)->setSeo($post['seo'], PostEntity::FILTER_BOOL)->setSlug($this->webPageManager->fetchSlugByWebPageId($post['web_page_id']))->setKeywords($post['keywords'], PostEntity::FILTER_HTML)->setMetaDescription($post['meta_description'], PostEntity::FILTER_HTML)->setDate(date($this->getTimeFormat(), $entity->getTimestamp()))->setPermanentUrl('/module/blog/post/' . $entity->getId())->setUrl($this->webPageManager->surround($entity->getSlug(), $entity->getLangId()))->setViewsCount($post['views'], PostEntity::FILTER_INT);
     return $entity;
 }
Example #3
0
 /**
  * Returns an array of categories with count of posts
  * 
  * @return array
  */
 public function getAllCategoriesWithCount()
 {
     return $this->prepareResults($this->categoryMapper->fetchAllBasic());
 }