1
0
mirror of https://github.com/e107inc/e107.git synced 2025-01-17 12:48:24 +01:00

Gallery pagination

This commit is contained in:
CaMer0n 2012-04-24 08:36:35 +00:00
parent 72267ae458
commit 3746bf5f6a
5 changed files with 54 additions and 10 deletions

View File

@ -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'];

View File

@ -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);

View File

@ -22,4 +22,8 @@
.gallery-cat-title { text-align:center; }
.gallery-list-nextprev { text-align:center; }
.gallery-list-back { }

View File

@ -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 = "<a href='".e107::getParser()->replaceConstants($this->eParserVars['media_url'])."' rel='external shadowbox' >";
@ -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.'&current='.$this->from.'&url='.$url; // .'&url='.$url;
$text .= e107::getParser()->parseTemplate("{NEXTPREV=".$parm."}");
return $text;
}
}

View File

@ -21,7 +21,8 @@ $GALLERY_TEMPLATE['LIST_ITEM'] =
$GALLERY_TEMPLATE['LIST_END'] =
"</div>
<div class='gallery-list-end' >
<a href='".e_SELF."'>Back to Categories</a>
<div class='gallery-list-nextprev'>{GALLERY_NEXTPREV}</div>
<div class='gallery-list-back'><a href='".e_SELF."'>Back to Categories</a></div>
</div>
";