Ejemplo n.º 1
0
 /**
  * Return array of options as value-label pairs
  *
  * @return array Format: array(array('value' => '<value>', 'label' => '<label>'), ...)
  */
 public function toOptionArray()
 {
     $options[] = ['label' => '', 'value' => ''];
     $availableOptions = $this->post->getAvailableStatuses();
     foreach ($availableOptions as $key => $value) {
         $options[] = ['label' => $value, 'value' => $key];
     }
     return $options;
 }
Ejemplo n.º 2
0
 public function testRemoveByUrl()
 {
     $this->post->expects($this->exactly(2))->method('checkUrlKey')->willReturn(self::POST_ID);
     $this->post->expects($this->exactly(2))->method('load')->with(self::POST_ID)->willReturn($this->post);
     $this->post->expects($this->once())->method('getId')->willReturn(self::POST_ID);
     $this->postFactory->expects($this->exactly(2))->method('create')->willReturn($this->post);
     $this->post->expects($this->once())->method('getUrlKey')->willReturn(self::URL);
     $actual = $this->postRegistry->retrieveByUrl(self::URL);
     $this->assertSame($this->post, $actual);
     $this->postRegistry->removeByUrl(self::URL);
     $actual = $this->postRegistry->retrieveByUrl(self::URL);
     $this->assertSame($this->post, $actual);
 }
Ejemplo n.º 3
0
 public function prepareResultPost(Action $action, $id = null)
 {
     if ($id !== null && $id !== $this->_post->getId()) {
         $delimiterPosition = strpos($id, '|');
         if ($delimiterPosition) {
             $id = substr($id, 0, $delimiterPosition);
         }
         if (!$this->_post->load($id)) {
             return false;
         }
     }
     if (!$this->_post->getId()) {
         return false;
     }
     /** @var \Magento\Framework\View\Result\Page $resultPage */
     $page = $this->_pageFactory->create();
     $page->addHandle('blog_post_view');
     $page->addPageLayoutHandles(['id' => $this->_post->getId()]);
     $this->_eventManager->dispatch('ism_blog_post_render', ['post' => $this->_post, 'controller_action' => $action]);
     return $page;
 }
Ejemplo n.º 4
0
 /**
  * Check thumbnail and create it if need.
  *
  * @return bool
  */
 public function checkAndCreate()
 {
     if ($this->_mediaDirectory->isFile($this->_cacheDir . $this->_post->getImageUrl())) {
         return true;
     }
     if (!$this->_mediaDirectory->isFile(Upload::UPLOAD_POST_IMAGE_DIR . $this->_post->getImageUrl())) {
         return false;
     }
     $image = $this->_imageFactory->create(array('file' => $this->_mediaDirectory->getAbsolutePath(Upload::UPLOAD_POST_IMAGE_DIR . $this->_post->getImageUrl())));
     $image->setWH(75, 75);
     $image->resize();
     $image->save(DirectoryList::PUB . DIRECTORY_SEPARATOR . DirectoryList::MEDIA . DIRECTORY_SEPARATOR . $this->_cacheDir . $this->_post->getImageUrl());
     return true;
 }
Ejemplo n.º 5
0
 public function push(Post $post)
 {
     $this->postRegistryById[$post->getId()] = $post;
     $this->postRegistryByUrl[$post->getUrlKey()] = $post;
     return $this;
 }