Beispiel #1
0
 /**
  * Return URL to item's view page
  *
  * @param Magentostudy_News_Model_News $newsItem
  * @return string
  */
 public function getItemUrl($newsItem)
 {
     return $this->getUrl('*/*/view', array('id' => $newsItem->getId()));
 }
Beispiel #2
0
 /**
  * Return URL for resized News Item Image
  * @param Magentostudy_News_Model_Item $item
  * @param integer                      $width
  * @param integer                      $height
  * @return bool|string
  */
 public function resize(Magentostudy_News_Model_News $item, $width, $height = null)
 {
     if (!$item->getImage()) {
         return false;
     }
     if ($width < self::MIN_WIDTH || $width > self::MAX_WIDTH) {
         return false;
     }
     $width = (int) $width;
     if (!is_null($height)) {
         if ($height < self::MIN_HEIGHT || $height > self::MAX_HEIGHT) {
             return false;
         }
         $height = (int) $height;
     }
     $imageFile = $item->getImage();
     $cacheDir = $this->getBaseDir() . DS . 'cache' . DS . $width;
     $cacheUrl = $this->getBaseUrl() . '/' . 'cache' . '/' . $width . '/';
     $io = new Varien_Io_File();
     $io->checkAndCreateFolder($cacheDir);
     $io->open(['path' => $cacheDir]);
     if ($io->fileExists($imageFile)) {
         return $cacheUrl . $imageFile;
     }
     try {
         $image = new Varien_Image($this->getBaseDir() . DS . $imageFile);
         $image->resize($width, $height);
         $image->save($cacheDir . DS . $imageFile);
         return $cacheUrl . $imageFile;
     } catch (Exception $e) {
         Mage::logException($e);
         return false;
     }
 }
Beispiel #3
0
 /**
  * Return URL to item's view page
  *
  * @param Magentostudy_News_Model_News $newsItem
  * @return string
  */
 public function getItemUrl($newsItem)
 {
     return '/news/index/view?id=' . $newsItem->getId() . '&back=/news';
 }