generic pagination with debugging for testing it atm

--HG--
branch : quitta-gsoc-2013
hg/feature/sse2
Quitta 11 years ago
parent 9a2ff7c7d0
commit 845da81ad4

@ -38,47 +38,52 @@ class Pagination{
$max = 'limit ' .($this->current- 1) * $page_rows .',' .$page_rows; $max = 'limit ' .($this->current- 1) * $page_rows .',' .$page_rows;
//This is your query again, the same one... the only difference is we add $max into it //This is your query again, the same one... the only difference is we add $max into it
$data = $dbl->executeWithoutParams($query . $max); $data = $db->executeWithoutParams($query . " " . $max);
$this->element_array = Array(); $this->element_array = Array();
//This is where we put the results in a resultArray to be sent to smarty //This is where we put the results in a resultArray to be sent to smarty
while($row = $data->fetch(PDO::FETCH_ASSOC)){ while($row = $data->fetch(PDO::FETCH_ASSOC)){
$element = new $resultClass(); $element = new $resultClass();
$element.set($row); $element->set($row);
$this->element_array[] = $element; $this->element_array[] = $element;
} }
} }
} }
function getLast(){ public function getLast(){
return $this->last; return $this->last;
} }
function getElements(){ public function getElements(){
return $this->element_array; return $this->element_array;
} }
function getPagination($nrOfLinks){ public function getLinks($nrOfLinks){
$pageLinks = Array(); $pageLinks = Array();
$pageLinks[] = 1;
//if amount of showable links is greater than the amount of pages: show all!
if ($this->last <= $nrOfLinks){ if ($this->last <= $nrOfLinks){
for($var = 1; $var <= $this->last; $var++){ for($var = 2; $var <= $this->last; $var++){
$pageLinks[] = $var; $pageLinks[] = $var;
} }
}else{ }else{
$pageLinks[] = 1; $offset = ($nrOfLinks-3)/2 ;
$offset = (ceil($nrOfLinks/2)-1); print "<font color='purple'>offset:" . $offset . "</font>";
$startpoint = $this->current - $offset; $startpoint = $this->current - $offset;
$endpoint = $this->current + $offset; $endpoint = $this->current + $offset;
print "<font color='blue'>startpointX:" . $startpoint . "</font>";
if($startpoint < 2){ if($startpoint < 2){
$startpoint = 2; $startpoint = 2;
$endpoint = $startpoint + $nrOfLinks - 2; $endpoint = $startpoint + $nrOfLinks - 3;
}else if($endpoint > $this->last){ }else if($endpoint > $this->last-1){
$endpoint = $this->last; $endpoint = $this->last-1;
$startpoint = $this->last - $nrOfLinks -2; $startpoint = $endpoint - ($nrOfLinks -3);
} }
print "<font color='blue'>startpoint:" . $startpoint . "</font>";
print "<font color='orange'>endpoint:" . $endpoint . "</font>";
for($var = $startpoint; $var <= $endpoint; $var++){ for($var = $startpoint; $var <= $endpoint; $var++){
$pageLinks[] = $var; $pageLinks[] = $var;
} }

@ -0,0 +1,83 @@
<?php
class Querycache{
private $SID;
private $type;
private $query;
private $db;
////////////////////////////////////////////Functions////////////////////////////////////////////////////
////////////////////////////////////////////Methods////////////////////////////////////////////////////
public function __construct() {
}
//set values
public function set($values) {
$this->setSID($values['SID']);
$this->setType($values['type']);
$this->setQuery($values['query']);
$this->setDb($values['db']);
}
//return constructed element based on SID
public function load_With_SID( $id) {
$dbl = new DBLayer("lib");
$statement = $dbl->execute("SELECT * FROM ams_querycache WHERE SID=:id", array('id' => $id));
$row = $statement->fetch();
$this->set($row);
}
//update private data to DB.
public function update(){
$dbl = new DBLayer("lib");
$query = "UPDATE ams_querycache SET type= :t, query = :q, db = :d WHERE SID=:id";
$values = Array('id' => $this->getSID(), 't' => $this->getType(), 'q' => $this->getQuery(), 'd' => $this->getDb());
$statement = $dbl->execute($query, $values);
}
////////////////////////////////////////////Getters////////////////////////////////////////////////////
public function getSID(){
return $this->SID;
}
public function getType(){
return $this->type;
}
public function getQuery(){
return $this->query;
}
public function getDb(){
return $this->db;
}
////////////////////////////////////////////Setters////////////////////////////////////////////////////
public function setSID($s){
$this->SID = $s;
}
public function setType($t){
$this->type = $t;
}
public function setQuery($q){
$this->query= $q;
}
public function setDb($d){
$this->db= $d;
}
}

@ -19,7 +19,7 @@ $cfg['db']['lib']['name'] = 'ryzom_ams_lib';
$cfg['db']['lib']['user'] = 'shard'; $cfg['db']['lib']['user'] = 'shard';
$cfg['db']['lib']['pass'] = ''; $cfg['db']['lib']['pass'] = '';
$cfg['db']['shard']['host'] = 'localhost'; $cfg['db']['shard']['host'] = 'localhosti';
$cfg['db']['shard']['port'] = '3306'; $cfg['db']['shard']['port'] = '3306';
$cfg['db']['shard']['name'] = 'nel'; $cfg['db']['shard']['name'] = 'nel';
$cfg['db']['shard']['user'] = 'shard'; $cfg['db']['shard']['user'] = 'shard';

@ -3,52 +3,20 @@
function libuserlist(){ function libuserlist(){
if(Ticket_User::isAdmin($_SESSION['ticket_user'])){ if(Ticket_User::isAdmin($_SESSION['ticket_user'])){
//This checks to see if there is a page number. If not, it will set it to page 1
if (!(isset($_GET['pagenum']))){
$pagenum = 1;
}else{
$pagenum = $_GET['pagenum'];
}
//Here we count the number of results
$dbl = new DBLayer("lib");
$rows = $dbl->executeWithoutParams("SELECT * FROM ams_querycache")->rowCount();
//the array hat will contain all users
$pageResult['liblist'] = Array();
if($rows > 0){
//This is the number of results displayed per page
$page_rows = 2;
//This tells us the page number of our last page
$last = ceil($rows/$page_rows);
//this makes sure the page number isn't below one, or more than our maximum pages
if ($pagenum < 1)
{
$pagenum = 1;
}else if ($pagenum > $last) {
$pagenum = $last;
}
//This sets the range to display in our query $pagination = new Pagination("SELECT * FROM ams_querycache","lib",1,"Querycache");
$max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows; print "<font color='red'>1 elements / page </font><br/>";
print "<font color='green'>7 links max</font>";
//This is your query again, the same one... the only difference is we add $max into it print "<br/><br/>";
$data = $dbl->executeWithoutParams("SELECT * FROM ams_querycache $max"); print "last page=";
print_r($pagination->getLast());
//This is where we put the results in a resultArray to be sent to smarty print "<br/>----------------------------------------------<br/>";
print "elements:";
$i = 0; print_r($pagination->getElements());
while($row = $data->fetch(PDO::FETCH_ASSOC)){ print "<br/>----------------------------------------------<br/>";
$decode = json_decode($row['query']); print "links:";
$pageResult['liblist'][$i]['id'] = $row['SID']; print_r($pagination->getLinks(7));
$pageResult['liblist'][$i]['type'] = $row['type']; exit;
//$pageResult['liblist'][$i]['name'] = $decode[0];
//$pageResult['liblist'][$i]['mail'] = $decode[2];
$i++;
}
}
//check if shard is online //check if shard is online
try{ try{

@ -1,6 +1,6 @@
<?php <?php
//error_reporting(E_ALL); error_reporting(E_ALL);
//ini_set('display_errors', 'on'); ini_set('display_errors', 'on');
require( '../config.php' ); require( '../config.php' );
require( '../../ams_lib/libinclude.php' ); require( '../../ams_lib/libinclude.php' );
session_start(); session_start();

Loading…
Cancel
Save