| Current Path : /home/purehotels/public_html/components/com_easyfolderlistingpro/helpers/ |
| Current File : /home/purehotels/public_html/components/com_easyfolderlistingpro/helpers/EFLPPageTable.Class.php |
<?php
/**
* @name EFLPPageTable
* @description
* @author Michael Gilkes (Valor Apps)
* @created Monday, March 24, 2014
* @modified
* @version 1.0
* @copyright Copyright (C) 2012-2016 Michael Albert Gilkes. All rights reserved.
* @license GNU General Public License version 3 or later; see LICENSE
*/
require_once("EFLPTable.Class.php");
class EFLPPageTable extends EFLPTable
{
protected static $per_page_limits = array(0 => 'JALL', 5 => 'J5', 10 => 'J10', 15 => 'J15', 20 => 'J20', 25 => 'J25', 30 => 'J30', 50 => 'J50', 100 => 'J100');
protected $limit_per_page_index;
protected $limit_page;
//max_pages should always be odd. Going to assume this.
protected $max_pages = 7;
protected $first_text = '«';
protected $last_text = '»';
/**
* Constructor used to initialize the parameters, config, files, and other variables related
* to paginated table
*/
public function __construct($id, $parameters = null, $config = null, $icons = null, $files = null, $folders = null)
{
parent::__construct($id, $parameters, $config, $icons, $files, $folders);
//set the default number of files shown per page
$this->setLimitPerPageIndex($parameters['pagelimit']);
//set the current page. starts with 1, not 0
$this->limit_page = 1;
}
/**
* Accurately sets the current page
*/
public function setLimitPage($page)
{
if ($page <= 0)
{
//set lower limit
$this->limit_page = 1;
}
else
{
$last_page = $this->lastPage();
if ($page > $last_page)
{
$this->limit_page = $last_page;
}
else
{
$this->limit_page = $page;
}
}
}
/**
* Calculates the last page
*/
protected function lastPage()
{
$last_page = 1;
//Note: the page index is the number for the page limit
$range = $this->limit_per_page_index;
//if limit_per_page_index is zero (0), then we are showing ALL. So, only 1 page.
if ($range > 0)
{
$total = count($this->files);
$pages = (int) ceil( ((float)$total / $range) );
if ($pages != (int)$total)
{
$last_page = $pages;
}
}
return $last_page;
}
/**
* Sets the limit per page index variable based on the given index value
*/
public function setLimitPerPageIndex($index)
{
$index = (int) $index;
if (array_key_exists($index, EFLPPageTable::$per_page_limits))
{
$this->limit_per_page_index = $index;
}
else
{
$this->limit_per_page_index = 20; //the index 20 is the default, which corresponds to 20 items per page
}
}
/**
* Overrides the parent moethod. Generates the HTML Table code
*/
public function renderHTML()
{
//setup the custom javascript
//$this->setupJavascript();
//return the paginated table html
return parent::renderHTML();
}
/**
* Overrides the parent method to not show the collapse/expand control
*/
protected function addCollapseExpandControl()
{
$html = '';
return $html;
}
/**
* Overrides parent method. Builds the Footer for the table
*/
protected function buildFooter($columns)
{
//set the prefix for the framework
$jsfix = 'jqy';
if ($this->mootools)
{
$jsfix = 'moo';
}
//start footer section
$html = '';
$html.= "\t".'<tfoot>'."\n";
$html.= "\t\t".'<tr';
if ($this->get('tablestyle') == 'standard')
{
$html.= ' style="background-color:'.$this->get('footercolor').';"';
}
//close the table row tag
$html.= '>'."\n";
//open the table data for pagination
$html.= "\t\t\t".'<td colspan="'.$columns.'">'."\n";
$last_page = $this->lastPage();
if ($last_page > 1)
{
//open the pagination div
if ($this->get('tablestyle') == 'standard')
{
$html.= "\t\t\t\t".'<div class="'.self::CLASS_PREFIX.'pagination">'."\n";
}
else //using bootstrap
{
$html.= "\t\t\t\t".'<div class="pagination">'."\n";
$html.= "\t\t\t\t\t".'<ul>'."\n";
}
//handle first arrow
if ($last_page > $this->max_pages && $this->limit_page != 1)
{
$item = '<a href="javascript:void(0);" onclick="eflp_'.$jsfix.'_pagination(\''.$this->listingId.'\', 1, '.$this->limit_per_page_index.');">'.$this->first_text.'</a>';
if ($this->get('tablestyle') != 'standard')
{
//using bootstrap
$item= '<li>'.$item.'</li>';
}
$html.= $item;
}
else //show disabled first arrow
{
if ($this->get('tablestyle') == 'standard')
{
$html.= '<span class="disabled">'.$this->first_text.'</span>';
}
else //using bootstrap
{
$html.= '<li class="disabled"><span>'.$this->first_text.'</span></li>';
}
}
//initialize the start and stop values
$start = 1;
$stop = $this->max_pages;
//reset stop if last page is the same as or less than max page
if ($last_page <= $this->max_pages)
{
$stop = $last_page;
}
else //last page is beyond the range of max_pages
{
//determine the range
$half = (int)floor((float)$this->max_pages / 2.0);
$ideal_start = (int)($last_page - $this->max_pages + 1);
$start = $this->limit_page - $half;
if ($start <= 1)
{
//reset start. stop is already set to max_pages
$start = 1;
}
elseif ($start >= $ideal_start)
{
$start = $ideal_start;
$stop = $last_page;
}
else
{
$stop = $this->limit_page + $half;
}
}
//display the page range
for ($i = $start; $i <= $stop; $i++)
{
if ($this->limit_page == $i)
{
if ($this->get('tablestyle') == 'standard')
{
$html.= '<span class="current">'.$i.'</span>';
}
else //using bootstrap
{
$html.= '<li class="active"><span>'.$i.'</span></li>';
}
}
else
{
$item = '<a href="javascript:void(0);" onclick="eflp_'.$jsfix.'_pagination(\''.$this->listingId.'\', '.$i.', '.$this->limit_per_page_index.');">'.$i.'</a>';
if ($this->get('tablestyle') != 'standard')
{
//using bootstrap
$item = '<li>'.$item.'</li>';
}
$html.= $item;
}
}
//handle last arrow
if ($last_page > $this->max_pages && $this->limit_page != $last_page)
{
$item = '<a href="javascript:void(0);" onclick="eflp_'.$jsfix.'_pagination(\''.$this->listingId.'\', '.$last_page.', '.$this->limit_per_page_index.');">'.$this->last_text.'</a>';
if ($this->get('tablestyle') != 'standard')
{
//using bootstrap
$item = '<li>'.$item.'</li>';
}
$html.= $item;
}
else //show disabled first arrow
{
if ($this->get('tablestyle') == 'standard')
{
$html.= '<span class="disabled">'.$this->last_text.'</span>';
}
else //using bootstrap
{
$html.= '<li class="disabled"><a href="javascript:void(0);">'.$this->last_text.'</a></li>';
}
}
if ($this->get('tablestyle') != 'standard')
{
//using bootstrap, so close the ul tag
$html.= "\t\t\t\t\t".'</ul>'."\n";
}
//close the pagination div
$html.= "\t\t\t\t".'</div>'."\n";
}
if ($this->get('showlimit'))
{
//setup the page options
$html.= "\t\t\t\t".'<div class="'.self::CLASS_PREFIX.'pageoptions">'."\n";
//set the page limit selection
$html.= "\t\t\t\t\t".'<div class="'.self::CLASS_PREFIX.'pagelimit">'.JText::_('PLG_CONTENT_EFLP_DISPLAY_WORD').': '."\n";
$html.= "\t\t\t\t\t\t".'<select id="pagelimit" name="pagelimit" class="inputbox" size="1" onchange="eflp_'.$jsfix.'_pageoptions(\''.$this->listingId.'\', this);">'."\n";
foreach (EFLPPageTable::$per_page_limits as $i => $limit)
{
$html.= "\t\t\t\t\t\t\t".'<option value="'.$i.'"';
if ($i == $this->limit_per_page_index)
{
$html.= ' selected="selected"';
}
$html.= '>'.JText::_($limit).'</option>'."\n";
}
$html.= "\t\t\t\t\t\t".'</select>'."\n";
$html.= "\t\t\t\t\t".'</div>'."\n";
//only show if you have more than 1 page
if ($last_page > 1)
{
$html.= "\t\t\t\t\t".'<div class="'.self::CLASS_PREFIX.'pagelimit">'.JText::sprintf('PLG_CONTENT_EFLP_PAGE_OF_PHRASE', $this->limit_page, $last_page).'</div>'."\n";
}
$html.= "\t\t\t\t".'</div>'."\n";
}
//close the table data with pagination
$html.= "\t\t\t".'</td>'."\n";
//end footer section
$html.= "\t\t".'</tr>'."\n";
$html.= "\t".'</tfoot>'."\n";
return $html;
}
/**
* Overrides parent method. Takes the files array and builds the appropriate listing rows
*/
protected function buildRows($columns)
{
$html = '';
$html.= $this->handlePagedFiles($columns);
return $html;
}
/**
* Method to display the table rows of files in a paginated table.
*/
protected function handlePagedFiles($columns)
{
$html = '';
//count is used to find out the number of rows fo files for this section. It is used for color determination.
$count = 1;
//calculate the index range that we are going to show
$start = $this->findStart();
$stop = $this->findStop();
for ($i = $start; $i <= $stop; $i++)
{
//start the table row
$html.= "\t".'<tr';
//set the colors if the table style is standard
if ($this->get('tablestyle') == 'standard')
{
//set the colour for the odd row
$color = $this->get('oddcolor');
//is the row even
if ($count%2 == 0)
{
//set the colour for the even row
$color = $this->get('evencolor');
}
//set the background color
$html.= ' style="background-color:'.$color.';"';
}
//close the table row
$html.= '>'."\n";
//Add download checkbox here
if ($this->get('multidownload'))
{
//add the checkbox for the file
$html.= "\t\t".'<td>'."\n";
$html.= $this->addCheckbox($i);
$html.= "\t\t".'</td>'."\n";
}
//add the contents based on the headings
foreach ($this->headings as $j => $meta)
{
$html .= "\t\t".'<td>';
if ($meta['type'] == 'name')
{
//format filename
$html.= $this->formatFilename($i);
}
elseif ($meta['type'] == 'relpath')
{
//add the relative path
$html.= $this->files[$i]['relpath'];
}
elseif ($meta['type'] == 'size')
{
//show file size in human readable form
$html.= $this->readableFileSize($this->files[$i]['bytes']);
}
elseif ($meta['type'] == 'date')
{
//get the date type
$datetype = $this->get('datetype');
//display the date/time in human readable form
$html.= $this->readableDateTime($this->files[$i][$datetype]);
}
//close column
$html.= '</td>'."\n";
}
//end the tag
$html.= "\t".'</tr>'."\n";
$count++;
}
if (empty($html)) //there are no files to list
{
if ($this->get('showempty'))
{
//start the table row
$html.= "\t".'<tbody><tr';
//set the colors if the table style is standard
if ($this->get('tablestyle') == 'standard')
{
$html.= ' style="background-color:'.$this->get('oddcolor').';"';
}
//close the opening tr tag
$html.= '>'."\n";
//filename column
$html.= "\t\t".'<td colspan="'.$columns.'" style="">';
//Add the exclamation icon
if ($this->get('icons'))
{
$html .= '<img src="'.$this->config->get('nofilesicon').'" alt="'.JText::_($this->config->get('nofilesalt')).'" /> ';
}
//display the empty message
$html.= '<span class="'.self::CLASS_PREFIX.'empty">'.JText::_('PLG_CONTENT_EFLP_NO_FILES_NOTICE').'</span></td>'."\n";
$html.= "\t".'</tr></tbody>'."\n";
}
}
else
{
$html = "\t".'<tbody>'."\n".$html."\t".'</tbody>'."\n";
}
return $html;
}
/**
* Calculates the start index for the page of files
*/
protected function findStart()
{
$index = 0;
if ($this->limit_per_page_index > 0)
{
//the keys of the per_page_limits relate exactly to the limit range
$range = $this->limit_per_page_index;
$start = ($this->limit_page - 1) * $range;
if ($start > $index)
{
$index = $start;
}
}
return $index;
}
/**
* Calculates the stop index for the page of files
*/
protected function findStop()
{
$index = (count($this->files) - 1);
if ($this->limit_per_page_index > 0)
{
//the keys of the per_page_limits relate exactly to the limit range
$range = $this->limit_per_page_index;
$stop = (($this->limit_page * $range) - 1);
if ($stop < $index)
{
$index = $stop;
}
}
return $index;
}
}