isValidPageVar($pageVar)) $this->pageVar = $pageVar; //Set resultsPerPage if arg is valid if($this->isValidResultsPerPage($resultsPerPage)) $this->resultsPerPage = $resultsPerPage; //Add items passed $this->add($items); } public function add($items) { //If the item is null, exit function if(is_null($items)) return; //If arg is not an array, make it one if(!is_array($items)) $items = array($items); //Cycle through items passed foreach($items as $item) { //Add them to the $items array if they are valid if($item instanceof paginationData) $this->items[] = $item; } } public function paginate($resultsPerPage="", $pageVar=0, $items=NULL) { //Prevent set function form changing values $this->paginated = true; //Set pageVar if arg is valid if($this->isvalidPageVar($pageVar)) $this->pageVar = $pageVar; //Set parVar to previous value else $pageVar = $this->pageVar; //Set resultsPerPage if arg is valid if($this->isValidResultsPerPage($resultsPerPage)) $this->resultsPerPage = $resultsPerPage; //Set resultsPerPage to previous value else $resultsPerPage = $this->resultsPerPage; //Add any extra items $this->add($items); //Get Page #, Staring Result #, and Ending Result # if(isset($_GET[$pageVar]) && $_GET[$pageVar] > 0) $page = $_GET[$pageVar]; else $page = 1; $result = ($page - 1) * $resultsPerPage + 1; $max = $result + $resultsPerPage; if($max >= count($this->items)) $max = count($this->items); //Are there results? if($resultitems)) { //Cycle through results on current page for(;$result<$max;$result++) { //Show the result $this->items[$result]->display(); } } //Display a "no results" message else echo "No Results found on this page."; } public function navigation() { //Get Pag # if(isset($_GET[$this->pageVar]) && $_GET[$this->pageVar] > 0) $page = $_GET[$this->pageVar]; else $page = 1; //Start Nav echo ''."\n"; } /* Get or set the pageVar field */ public function getPageVar() { return($this->pageVar); } public function setPageVar($pageVar) { if(is_string($pageVar) && !$this->paginated) $this->pageVar = $pageVar; } /* Get or set the resultsPerPage field */ public function getResultsPerPage() { return($this->resultsPerPage); } public function setResultsPerPage($resultsPerPage) { //If the arg is a valid #, set the new value if(is_int($resultsPerPage) && $resultsPerPage>0 && !$this->paginated) $this->resultsPerPage = $resultsPerPage; } private function isValidPageVar($pageVar) { //Return valid if arg is string and is not empty return(!empty($pageVar) && is_string($pageVar)); } private function isValidResultsPerPage($resultsPerPage) { //Return valid if arg is a positive integer return(is_int($resultsPerPage) || $resultsPerPage>0); } } class paginationData { private $program; private $channel; private $airdate; private $exiration; private $episode; private $setReminder; public function __construct($program, $channel, $airdate, $expiration, $episode, $setReminder) { $this->program = $program; $this->channel = $channel; $this->airdate = strtotime($airdate); $this->expiration = $expiration; $this->episode = $episode; $this->setReminder = $setReminder; } //This function shows the data public function display() { if(date('Y-m-d') == date('Y-m-d', $this->airdate)) $dateFormat = 'g:ia'; elseif(date('Y') == date('Y', $this->airdate)) $dateFormat = 'F jS - g:ia'; else $dateFormat = 'F jS, Y - g:ia'; echo ''."\n". ' '.$this->program.''."\n". ' showing on '.$this->channel.''."\n". ' '.date($dateFormat, $this->airdate).''."\n". ' '.$this->episode.''. "\n". ' '.$this->setReminder.''."\n". ''."\n"; } } ?>