Ignore:
Timestamp:
Feb 28, 2016, 10:54:30 AM (8 years ago)
Author:
chronos
Message:
  • Modified: Use object oriented approach for page drawing using Application class.
  • Added: SQL updated will be automatic using UpdateTrace.php file.
  • Added: Use generic setup page at URL /setup for SQL structure update.
  • Modified: Update Common package to newer version.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Packages/Common/Common.php

    r61 r69  
    1010include_once(dirname(__FILE__).'/VarDumper.php');
    1111include_once(dirname(__FILE__).'/Error.php');
     12include_once(dirname(__FILE__).'/Base.php');
     13include_once(dirname(__FILE__).'/Application.php');
     14include_once(dirname(__FILE__).'/AppModule.php');
     15include_once(dirname(__FILE__).'/Config.php');
     16include_once(dirname(__FILE__).'/Page.php');
     17include_once(dirname(__FILE__).'/Locale.php');
     18include_once(dirname(__FILE__).'/Update.php');
     19include_once(dirname(__FILE__).'/Setup.php');
     20include_once(dirname(__FILE__).'/Table.php');
    1221
    1322class PackageCommon
     
    1524  var $Name;
    1625  var $Version;
     26  var $ReleaseDate;
    1727  var $License;
    1828  var $Creator;
     
    2232  {
    2333    $this->Name = 'Common';
    24     $this->Version = '1.1';
     34    $this->Version = '1.2';
     35    $this->ReleaseDate = strtotime('2016-01-22');
    2536    $this->Creator = 'Chronos';
    2637    $this->License = 'GNU/GPL';
     
    2839  }
    2940}
     41
     42class Paging
     43{
     44  var $TotalCount;
     45  var $ItemPerPage;
     46  var $Around;
     47  var $SQLLimit;
     48  var $Page;
     49
     50  function __construct(System $System)
     51  {
     52    $this->ItemPerPage = $System->Config['Web']['ItemsPerPage'];
     53    $this->Around = $System->Config['Web']['VisiblePagingItems'];
     54  }
     55
     56  function Show()
     57  {
     58    $QueryItems = GetQueryStringArray($_SERVER['QUERY_STRING']);
     59
     60    $Result = '';
     61    if(array_key_exists('all', $QueryItems))
     62    {
     63      $PageCount = 1;
     64      $ItemPerPage = $this->TotalCount;
     65    } else
     66    {
     67      $ItemPerPage = $this->ItemPerPage;
     68      $Around = round($this->Around / 2);
     69      $PageCount = floor($this->TotalCount / $ItemPerPage) + 1;
     70    }
     71
     72    if(!array_key_exists('Page', $_SESSION)) $_SESSION['Page'] = 0;
     73    if(array_key_exists('page', $_GET)) $_SESSION['Page'] = $_GET['page'] * 1;
     74    if($_SESSION['Page'] < 0) $_SESSION['Page'] = 0;
     75    if($_SESSION['Page'] >= $PageCount) $_SESSION['Page'] = $PageCount - 1;
     76    $CurrentPage = $_SESSION['Page'];
     77
     78    $Result .= 'Počet položek: <strong>'.$this->TotalCount.'</strong> &nbsp; Stránky: ';
     79
     80    $Result = '';
     81    if($PageCount > 1)
     82    {
     83      if($CurrentPage > 0)
     84      {
     85        $QueryItems['page'] = 0;
     86        $Result.= '<a href="?'.SetQueryStringArray($QueryItems).'">&lt;&lt;</a> ';
     87        $QueryItems['page'] = ($CurrentPage - 1);
     88        $Result.= '<a href="?'.SetQueryStringArray($QueryItems).'">&lt;</a> ';
     89      }
     90      $PagesMax = $PageCount - 1;
     91      $PagesMin = 0;
     92      if($PagesMax > ($CurrentPage + $Around)) $PagesMax = $CurrentPage + $Around;
     93      if($PagesMin < ($CurrentPage - $Around))
     94      {
     95        $Result.= ' ... ';
     96        $PagesMin = $CurrentPage - $Around;
     97      }
     98      for($i = $PagesMin; $i <= $PagesMax; $i++)
     99      {
     100        if($i == $CurrentPage) $Result.= '<strong>'.($i + 1).'</strong> ';
     101        else {
     102         $QueryItems['page'] = $i;
     103         $Result .= '<a href="?'.SetQueryStringArray($QueryItems).'">'.($i + 1).'</a> ';
     104        }
     105      }
     106      if($PagesMax < ($PageCount - 1)) $Result .= ' ... ';
     107      if($CurrentPage < ($PageCount - 1))
     108      {
     109        $QueryItems['page'] = ($CurrentPage + 1);
     110        $Result.= '<a href="?'.SetQueryStringArray($QueryItems).'">&gt;</a> ';
     111        $QueryItems['page'] = ($PageCount - 1);
     112        $Result.= '<a href="?'.SetQueryStringArray($QueryItems).'">&gt;&gt;</a>';
     113      }
     114    }
     115    $QueryItems['all'] = '1';
     116    if($PageCount > 1) $Result.= ' <a href="?'.SetQueryStringArray($QueryItems).'">Vše</a>';
     117
     118    $Result = '<div style="text-align: center">'.$Result.'</div>';
     119    $this->SQLLimit = ' LIMIT '.$CurrentPage * $ItemPerPage.', '.$ItemPerPage;
     120    $this->Page = $CurrentPage;
     121    return($Result);
     122  }
     123}
Note: See TracChangeset for help on using the changeset viewer.