From 3746bf5f6ad145710ee1ec8d944ecf69617ea58e Mon Sep 17 00:00:00 2001 From: CaMer0n Date: Tue, 24 Apr 2012 08:36:35 +0000 Subject: [PATCH] Gallery pagination --- e107_handlers/media_class.php | 19 ++++++++++++++-- e107_plugins/gallery/gallery.php | 22 ++++++++++++++----- e107_plugins/gallery/gallery_style.css | 4 ++++ .../shortcodes/batch/gallery_shortcodes.php | 16 +++++++++++++- .../gallery/templates/gallery_template.php | 3 ++- 5 files changed, 54 insertions(+), 10 deletions(-) diff --git a/e107_handlers/media_class.php b/e107_handlers/media_class.php index 37cc919c8..0fa3891cd 100644 --- a/e107_handlers/media_class.php +++ b/e107_handlers/media_class.php @@ -244,17 +244,32 @@ class e_media return $ret; } + /** + * Return the total number of Images in a particular category + */ + public function countImages($cat) + { + $query = "SELECT media_id FROM #core_media WHERE media_category = '".$cat."' "; + return e107::getDb()->db_Select_gen($query); + } /** * Return an array of Images in a particular category */ - public function getImages($cat,$from='',$amount='') + public function getImages($cat, $from=0, $amount=null) { if(!$cat) return; // TODO check the category is valid. + // TODO check userclasses. $ret = array(); - e107::getDb()->db_Select_gen("SELECT * FROM #core_media WHERE media_category = '".$cat."' ORDER BY media_name"); + $query = "SELECT * FROM #core_media WHERE media_category = '".$cat."' ORDER BY media_name"; + + if($amount) + { + $query .= " LIMIT ".$from." ,".$amount; + } + e107::getDb()->db_Select_gen($query); while($row = e107::getDb()->db_Fetch(mySQL_ASSOC)) { $id = $row['media_id']; diff --git a/e107_plugins/gallery/gallery.php b/e107_plugins/gallery/gallery.php index 221ca2f76..3ccc2981d 100644 --- a/e107_plugins/gallery/gallery.php +++ b/e107_plugins/gallery/gallery.php @@ -73,19 +73,29 @@ class gallery //TODO Shadowbox/Popup support. function showImages($cat) { - $mes = e107::getMessage(); + $mes = e107::getMessage(); + $tp = e107::getParser(); $template = e107::getTemplate('gallery'); - $list = e107::getMedia()->getImages($cat); $sc = e107::getScBatch('gallery',TRUE); + + $sc->total = e107::getMedia()->countImages($cat); + $sc->amount = 9; // TODO Add Pref. + $sc->curCat = $cat; + $sc->from = ($_GET['frm']) ? intval($_GET['frm']) : 0; + + $list = e107::getMedia()->getImages($cat,$sc->from,$sc->amount); - $text = ""; + $inner = ""; + foreach($list as $row) { $sc->setParserVars($row); - $text .= e107::getParser()->parseTemplate($template['LIST_ITEM'],TRUE); + $inner .= $tp->parseTemplate($template['LIST_ITEM'],TRUE); } - - $text = $template['LIST_START'].$text.$template['LIST_END']; + + $text = $tp->parseTemplate($template['LIST_START'],TRUE); + $text .= $inner; + $text .= $tp->parseTemplate($template['LIST_END'],TRUE); e107::getRender()->tablerender("Gallery :: ".str_replace("_"," ",$cat),$mes->render().$text); diff --git a/e107_plugins/gallery/gallery_style.css b/e107_plugins/gallery/gallery_style.css index d398aa8d8..00fdb322d 100644 --- a/e107_plugins/gallery/gallery_style.css +++ b/e107_plugins/gallery/gallery_style.css @@ -22,4 +22,8 @@ .gallery-cat-title { text-align:center; } +.gallery-list-nextprev { text-align:center; } + +.gallery-list-back { } + diff --git a/e107_plugins/gallery/shortcodes/batch/gallery_shortcodes.php b/e107_plugins/gallery/shortcodes/batch/gallery_shortcodes.php index 457eddc66..f7a90b349 100644 --- a/e107_plugins/gallery/shortcodes/batch/gallery_shortcodes.php +++ b/e107_plugins/gallery/shortcodes/batch/gallery_shortcodes.php @@ -10,7 +10,13 @@ if (!defined('e107_INIT')) { exit; } class gallery_shortcodes extends e_shortcode -{ +{ + + public $total = 0; + public $amount = 3; + public $from = 0; + public $curCat = null; + function sc_gallery_caption($parm='') { $text = ""; @@ -46,5 +52,13 @@ class gallery_shortcodes extends e_shortcode return $text; } + function sc_gallery_nextprev($parm='') + { + $url = e_SELF."?cat=".$this->curCat."--AMP--frm=--FROM--"; + $parm = 'total='.$this->total.'&amount='.$this->amount.'¤t='.$this->from.'&url='.$url; // .'&url='.$url; + $text .= e107::getParser()->parseTemplate("{NEXTPREV=".$parm."}"); + return $text; + } + } diff --git a/e107_plugins/gallery/templates/gallery_template.php b/e107_plugins/gallery/templates/gallery_template.php index 6d91097b1..28104ed57 100644 --- a/e107_plugins/gallery/templates/gallery_template.php +++ b/e107_plugins/gallery/templates/gallery_template.php @@ -21,7 +21,8 @@ $GALLERY_TEMPLATE['LIST_ITEM'] = $GALLERY_TEMPLATE['LIST_END'] = " ";