mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-11-14 11:19:07 +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;
|
$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
|
$pagination = new Pagination("SELECT * FROM ams_querycache","lib",1,"Querycache");
|
||||||
$dbl = new DBLayer("lib");
|
print "<font color='red'>1 elements / page </font><br/>";
|
||||||
$rows = $dbl->executeWithoutParams("SELECT * FROM ams_querycache")->rowCount();
|
print "<font color='green'>7 links max</font>";
|
||||||
|
print "<br/><br/>";
|
||||||
//the array hat will contain all users
|
print "last page=";
|
||||||
$pageResult['liblist'] = Array();
|
print_r($pagination->getLast());
|
||||||
if($rows > 0){
|
print "<br/>----------------------------------------------<br/>";
|
||||||
//This is the number of results displayed per page
|
print "elements:";
|
||||||
$page_rows = 2;
|
print_r($pagination->getElements());
|
||||||
|
print "<br/>----------------------------------------------<br/>";
|
||||||
//This tells us the page number of our last page
|
print "links:";
|
||||||
$last = ceil($rows/$page_rows);
|
print_r($pagination->getLinks(7));
|
||||||
|
exit;
|
||||||
//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++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//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…
Reference in a new issue