Esempio n. 1
0
 /**
  * Makes a full URL to item row
  * 
  * @param array $row
  * @return string
  */
 protected final function makeUrl(array $row)
 {
     // Special case to not generate home page's url
     if ($row['web_page_id'] == $this->homeWebPageId) {
         return '/';
     }
     if ((bool) $row['has_link']) {
         return $row['link'];
     } else {
         return $this->webPageManager->generate($row['web_page_id']);
     }
 }
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 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. 4
0
 /**
  * Deletes a page by its associated id
  * 
  * @param string $id
  * @return boolean
  */
 private function delete($id)
 {
     $webPageId = $this->pageMapper->fetchWebPageIdById($id);
     $this->menuWidget->deleteAllByWebPageId($webPageId);
     $this->webPageManager->deleteById($webPageId);
     $this->pageMapper->deleteById($id);
     return true;
 }
Esempio n. 5
0
 /**
  * Removes all posts associated with category id
  * 
  * @param string $id Category's id
  * @return boolean
  */
 private function removeAllPostsById($id)
 {
     $webPageIds = $this->postMapper->fetchAllWebPageIdsByCategoryId($id);
     // Remove associated web pages, first
     foreach ($webPageIds as $webPageId) {
         $this->webPageManager->deleteById($webPageId);
     }
     // And then remove all posts
     $this->postMapper->deleteAllByCategoryId($id);
     return true;
 }
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
 /**
  * Removes product's web page
  * 
  * @param string $id Product's id
  * @return boolean
  */
 private function removeWebPageById($id)
 {
     $webPageId = $this->productMapper->fetchWebPageIdById($id);
     return $this->webPageManager->deleteById($webPageId);
 }
Esempio n. 8
0
 /**
  * {@inheritDoc}
  */
 protected function toEntity(array $result)
 {
     $entity = new VirtualEntity();
     $entity->setLangId($result['lang_id'], VirtualEntity::FILTER_INT)->setWebPageId($result['web_page_id'], VirtualEntity::FILTER_INT)->setTitle($this->highlight($result['title']))->setContent($this->filterContent($result['content']))->setUrl($this->webPageManager->getUrl($entity->getWebPageId(), $entity->getLangId()));
     return $entity;
 }
Esempio n. 9
0
 /**
  * Removes an album from web page collection
  * 
  * @param string $albumId
  * @return boolean
  */
 private function removeWebPage($albumId)
 {
     $webPageId = $this->albumMapper->fetchWebPageIdById($albumId);
     return $this->webPageManager->deleteById($webPageId);
 }
Esempio n. 10
0
 /**
  * Extract links from registered services
  * 
  * @return array
  */
 public function collect()
 {
     $raw = $this->webPageManager->fetchAll();
     $data = $this->process($raw);
     return $this->createResult($data);
 }
Esempio n. 11
0
 /**
  * Deletes an announce by its associated id
  * 
  * @param string $id Announce id
  * @return boolean
  */
 private function delete($id)
 {
     $webPageId = $this->announceMapper->fetchWebPageIdById($id);
     $this->webPageManager->deleteById($webPageId);
     return $this->announceMapper->deleteById($id);
 }
Esempio n. 12
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')));
 }
Esempio n. 13
0
 /**
  * {@inheritDoc}
  */
 protected function toEntity(array $category)
 {
     $entity = new VirtualEntity();
     $entity->setId($category['id'])->setLangId($category['lang_id'])->setCount($this->postManager->countAllPublishedByCategoryId($entity->getId()))->setSlug($this->webPageManager->fetchSlugByWebPageId($category['web_page_id']))->setTitle($category['name'] . sprintf(' (%s) ', $entity->getCount()))->setUrl($this->webPageManager->surround($entity->getSlug(), $entity->getLangId()));
     return $entity;
 }