Pagination class added, not tested yet :D
--HG-- branch : quitta-gsoc-2013
This commit is contained in:
parent
bc62611305
commit
9a2ff7c7d0
3 changed files with 95 additions and 5 deletions
|
@ -34,6 +34,7 @@ class Gui_Elements{
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static function make_table_with_key_is_id( $inputList, $funcArray, $idFunction){
|
public static function make_table_with_key_is_id( $inputList, $funcArray, $idFunction){
|
||||||
$result = Array();
|
$result = Array();
|
||||||
foreach($inputList as $element){
|
foreach($inputList as $element){
|
||||||
|
@ -44,6 +45,7 @@ class Gui_Elements{
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static function time_elapsed_string($ptime){
|
public static function time_elapsed_string($ptime){
|
||||||
global $TIME_FORMAT;
|
global $TIME_FORMAT;
|
||||||
$ptime = DateTime::createFromFormat($TIME_FORMAT, $ptime)->getTimestamp();
|
$ptime = DateTime::createFromFormat($TIME_FORMAT, $ptime)->getTimestamp();
|
||||||
|
@ -74,5 +76,4 @@ class Gui_Elements{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -0,0 +1,89 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class Pagination{
|
||||||
|
|
||||||
|
private $element_array;
|
||||||
|
private $last;
|
||||||
|
private $current;
|
||||||
|
|
||||||
|
function __construct($query,$db,$nrDisplayed,$resultClass) {
|
||||||
|
if (!(isset($_GET['pagenum']))){
|
||||||
|
$this->current= 1;
|
||||||
|
}else{
|
||||||
|
$this->current= $_GET['pagenum'];
|
||||||
|
}
|
||||||
|
|
||||||
|
//Here we count the number of results
|
||||||
|
$db = new DBLayer($db);
|
||||||
|
$rows = $db->executeWithoutParams($query)->rowCount();
|
||||||
|
|
||||||
|
//the array hat will contain all users
|
||||||
|
|
||||||
|
if($rows > 0){
|
||||||
|
//This is the number of results displayed per page
|
||||||
|
$page_rows = $nrDisplayed;
|
||||||
|
|
||||||
|
//This tells us the page number of our last page
|
||||||
|
$this->last = ceil($rows/$page_rows);
|
||||||
|
|
||||||
|
//this makes sure the page number isn't below one, or more than our maximum pages
|
||||||
|
if ($this->current< 1)
|
||||||
|
{
|
||||||
|
$this->current= 1;
|
||||||
|
}else if ($this->current> $this->last) {
|
||||||
|
$this->current= $this->last;
|
||||||
|
}
|
||||||
|
|
||||||
|
//This sets the range to display in our query
|
||||||
|
$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);
|
||||||
|
|
||||||
|
$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);
|
||||||
|
$this->element_array[] = $element;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function getLast(){
|
||||||
|
return $this->last;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function getElements(){
|
||||||
|
return $this->element_array;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function getPagination($nrOfLinks){
|
||||||
|
$pageLinks = Array();
|
||||||
|
if ($this->last <= $nrOfLinks){
|
||||||
|
for($var = 1; $var <= $this->last; $var++){
|
||||||
|
$pageLinks[] = $var;
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
$pageLinks[] = 1;
|
||||||
|
$offset = (ceil($nrOfLinks/2)-1);
|
||||||
|
$startpoint = $this->current - $offset;
|
||||||
|
$endpoint = $this->current + $offset;
|
||||||
|
if($startpoint < 2){
|
||||||
|
$startpoint = 2;
|
||||||
|
$endpoint = $startpoint + $nrOfLinks - 2;
|
||||||
|
}else if($endpoint > $this->last){
|
||||||
|
$endpoint = $this->last;
|
||||||
|
$startpoint = $this->last - $nrOfLinks -2;
|
||||||
|
}
|
||||||
|
for($var = $startpoint; $var <= $endpoint; $var++){
|
||||||
|
$pageLinks[] = $var;
|
||||||
|
}
|
||||||
|
$pageLinks[] = $this->last;
|
||||||
|
}
|
||||||
|
return $pageLinks;
|
||||||
|
}
|
||||||
|
}
|
|
@ -7,7 +7,7 @@ class Users{
|
||||||
* @takes $array with username,password and email
|
* @takes $array with username,password and email
|
||||||
* @return string Info: Returns a string, if input data is valid then "success" is returned, else an array with errors
|
* @return string Info: Returns a string, if input data is valid then "success" is returned, else an array with errors
|
||||||
*/
|
*/
|
||||||
public function check_Register($values){
|
public static function check_Register($values){
|
||||||
// check values
|
// check values
|
||||||
if ( isset( $values["Username"] ) and isset( $values["Password"] ) and isset( $values["ConfirmPass"] ) and isset( $values["Email"] ) ){
|
if ( isset( $values["Username"] ) and isset( $values["Password"] ) and isset( $values["ConfirmPass"] ) and isset( $values["Email"] ) ){
|
||||||
$user = Users::checkUser( $values["Username"] );
|
$user = Users::checkUser( $values["Username"] );
|
||||||
|
@ -156,7 +156,7 @@ class Users{
|
||||||
* @takes $email
|
* @takes $email
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public function checkEmail( $email )
|
public static function checkEmail( $email )
|
||||||
{
|
{
|
||||||
if ( isset( $email ) ){
|
if ( isset( $email ) ){
|
||||||
if ( !Users::validEmail( $email ) ){
|
if ( !Users::validEmail( $email ) ){
|
||||||
|
@ -243,7 +243,7 @@ class Users{
|
||||||
* @takes $length, which is by default 2
|
* @takes $length, which is by default 2
|
||||||
* @return a random salt of 2 chars
|
* @return a random salt of 2 chars
|
||||||
*/
|
*/
|
||||||
public function generateSALT( $length = 2 )
|
public static function generateSALT( $length = 2 )
|
||||||
{
|
{
|
||||||
// start with a blank salt
|
// start with a blank salt
|
||||||
$salt = "";
|
$salt = "";
|
||||||
|
@ -284,7 +284,7 @@ class Users{
|
||||||
* @takes $array with name,pass and mail
|
* @takes $array with name,pass and mail
|
||||||
* @return ok if it's get correctly added to the shard, else return lib offline and put in libDB, if libDB is also offline return liboffline.
|
* @return ok if it's get correctly added to the shard, else return lib offline and put in libDB, if libDB is also offline return liboffline.
|
||||||
*/
|
*/
|
||||||
public function createUser($values, $user_id){
|
public static function createUser($values, $user_id){
|
||||||
try {
|
try {
|
||||||
//make connection with and put into shard db
|
//make connection with and put into shard db
|
||||||
$dbs = new DBLayer("shard");
|
$dbs = new DBLayer("shard");
|
||||||
|
|
Loading…
Reference in a new issue