mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-11-24 16:16:14 +00:00
generic pagination with debugging for testing it atm
This commit is contained in:
parent
31f7435ebb
commit
b6d15957ab
5 changed files with 116 additions and 60 deletions
|
@ -38,47 +38,52 @@ class Pagination{
|
|||
$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
|
||||
$data = $dbl->executeWithoutParams($query . $max);
|
||||
$data = $db->executeWithoutParams($query . " " . $max);
|
||||
|
||||
$this->element_array = Array();
|
||||
//This is where we put the results in a resultArray to be sent to smarty
|
||||
while($row = $data->fetch(PDO::FETCH_ASSOC)){
|
||||
$element = new $resultClass();
|
||||
$element.set($row);
|
||||
$element->set($row);
|
||||
$this->element_array[] = $element;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function getLast(){
|
||||
public function getLast(){
|
||||
return $this->last;
|
||||
}
|
||||
|
||||
|
||||
function getElements(){
|
||||
public function getElements(){
|
||||
return $this->element_array;
|
||||
}
|
||||
|
||||
|
||||
function getPagination($nrOfLinks){
|
||||
public function getLinks($nrOfLinks){
|
||||
$pageLinks = Array();
|
||||
$pageLinks[] = 1;
|
||||
//if amount of showable links is greater than the amount of pages: show all!
|
||||
if ($this->last <= $nrOfLinks){
|
||||
for($var = 1; $var <= $this->last; $var++){
|
||||
for($var = 2; $var <= $this->last; $var++){
|
||||
$pageLinks[] = $var;
|
||||
}
|
||||
}else{
|
||||
$pageLinks[] = 1;
|
||||
$offset = (ceil($nrOfLinks/2)-1);
|
||||
$offset = ($nrOfLinks-3)/2 ;
|
||||
print "<font color='purple'>offset:" . $offset . "</font>";
|
||||
$startpoint = $this->current - $offset;
|
||||
$endpoint = $this->current + $offset;
|
||||
print "<font color='blue'>startpointX:" . $startpoint . "</font>";
|
||||
if($startpoint < 2){
|
||||
$startpoint = 2;
|
||||
$endpoint = $startpoint + $nrOfLinks - 2;
|
||||
}else if($endpoint > $this->last){
|
||||
$endpoint = $this->last;
|
||||
$startpoint = $this->last - $nrOfLinks -2;
|
||||
$endpoint = $startpoint + $nrOfLinks - 3;
|
||||
}else if($endpoint > $this->last-1){
|
||||
$endpoint = $this->last-1;
|
||||
$startpoint = $endpoint - ($nrOfLinks -3);
|
||||
}
|
||||
print "<font color='blue'>startpoint:" . $startpoint . "</font>";
|
||||
print "<font color='orange'>endpoint:" . $endpoint . "</font>";
|
||||
for($var = $startpoint; $var <= $endpoint; $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']['pass'] = '';
|
||||
|
||||
$cfg['db']['shard']['host'] = 'localhost';
|
||||
$cfg['db']['shard']['host'] = 'localhosti';
|
||||
$cfg['db']['shard']['port'] = '3306';
|
||||
$cfg['db']['shard']['name'] = 'nel';
|
||||
$cfg['db']['shard']['user'] = 'shard';
|
||||
|
|
|
@ -3,52 +3,20 @@
|
|||
|
||||
function libuserlist(){
|
||||
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
|
||||
$max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows;
|
||||
|
||||
//This is your query again, the same one... the only difference is we add $max into it
|
||||
$data = $dbl->executeWithoutParams("SELECT * FROM ams_querycache $max");
|
||||
|
||||
//This is where we put the results in a resultArray to be sent to smarty
|
||||
|
||||
$i = 0;
|
||||
while($row = $data->fetch(PDO::FETCH_ASSOC)){
|
||||
$decode = json_decode($row['query']);
|
||||
$pageResult['liblist'][$i]['id'] = $row['SID'];
|
||||
$pageResult['liblist'][$i]['type'] = $row['type'];
|
||||
//$pageResult['liblist'][$i]['name'] = $decode[0];
|
||||
//$pageResult['liblist'][$i]['mail'] = $decode[2];
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
$pagination = new Pagination("SELECT * FROM ams_querycache","lib",1,"Querycache");
|
||||
print "<font color='red'>1 elements / page </font><br/>";
|
||||
print "<font color='green'>7 links max</font>";
|
||||
print "<br/><br/>";
|
||||
print "last page=";
|
||||
print_r($pagination->getLast());
|
||||
print "<br/>----------------------------------------------<br/>";
|
||||
print "elements:";
|
||||
print_r($pagination->getElements());
|
||||
print "<br/>----------------------------------------------<br/>";
|
||||
print "links:";
|
||||
print_r($pagination->getLinks(7));
|
||||
exit;
|
||||
|
||||
//check if shard is online
|
||||
try{
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
//error_reporting(E_ALL);
|
||||
//ini_set('display_errors', 'on');
|
||||
error_reporting(E_ALL);
|
||||
ini_set('display_errors', 'on');
|
||||
require( '../config.php' );
|
||||
require( '../../ams_lib/libinclude.php' );
|
||||
session_start();
|
||||
|
|
Loading…
Reference in a new issue