public function loadmoreAction() { if ($datas = $this->getRequest()->getPost()) { try { if (empty($datas['gallery_id'])) { throw new Exception($this->_('An error occurred while loading pictures. Please try later.')); } $offset = !empty($datas['offset']) ? $datas['offset'] : 0; $image = new Media_Model_Gallery_Image(); $image->find($datas['gallery_id']); if (!$image->getId() or $image->getValueId() != $this->getCurrentOptionValue()->getId()) { throw new Exception($this->_('An error occurred while loading pictures. Please try later.')); } $images = $image->setOffset($offset)->getImages(); $html = array(); $image_datas = array(); // $offset--; foreach ($images as $key => $link) { $key += $offset; $html[] = $this->getLayout()->addPartial('row', 'core_view_default', 'media/gallery/image/l1/view/list/li.phtml')->setCurrentImage($image)->setKey($key)->setLink($link)->toHtml(); $image_datas[] = $link->getData(); } $html = array('html' => implode('', $html), 'images' => $image_datas, 'id' => $image->getId()); } catch (Exception $e) { $html = array('error' => 1, 'message' => $e->getMessage()); } $this->_sendHtml($html); } }
public function findAction() { if ($gallery_id = $this->getRequest()->getParam("gallery_id")) { try { $offset = $this->getRequest()->getParam('offset', 0); $data = array("collection" => array()); $image = new Media_Model_Gallery_Image(); $image->find($gallery_id); if (!$image->getId() or $image->getValueId() != $this->getCurrentOptionValue()->getId()) { throw new Exception($this->_('An error occurred while loading pictures. Please try later.')); } $images = $image->setOffset($offset)->getImages(); foreach ($images as $key => $link) { $key += $offset; $data["collection"][] = array("offset" => $link->getOffset(), "gallery_id" => $key, "is_visible" => false, "url" => $link->getImage(), "title" => $link->getTitle(), "description" => $link->getDescription(), "author" => $link->getAuthor()); } if ($image->getTypeId() != "custom") { $data["show_load_more"] = count($data["images"]) > 0; } else { $data["show_load_more"] = $key - $offset + 1 > Media_Model_Gallery_Image_Abstract::DISPLAYED_PER_PAGE - 1 ? true : false; } } catch (Exception $e) { $data = array('error' => 1, 'message' => $e->getMessage()); } $this->_sendHtml($data); } }