Advertisement
anton_slim

classes/magazin.class.php

Feb 21st, 2012
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.74 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Created by JetBrains PhpStorm.
  4.  * User: pavel
  5.  * Date: 22.09.11
  6.  * Time: 14:52
  7.  * To change this template use File | Settings | File Templates.
  8.  * Many changes by SLIM (skype: anton_slim)
  9.  */
  10.  
  11. require_once('classes/pdo_mysql.php');
  12.  
  13. class magazin extends mysql
  14. {
  15.     function print_magazin()
  16.     {
  17.         $res = $this->query("SELECT * FROM magazin ORDER BY id DESC");
  18.         echo '<table class="table_border" style="width: 800px;"><tr>
  19.             <th style="width:150px;">Дата</th><th>Кто</th><th>Действие</th><th style="width:50%">Подробно</th>
  20.             </tr>';
  21.         if ($res) {
  22.             foreach($res as $val){
  23.                 echo '<tr><td>'.$val['data'].'</td><td>'.$val['author'].'</td><td><b>'.$val['filter'].'</b></td><td>'.$val['doing'].'</td></tr>';
  24.             }
  25.         }
  26.         echo '</table>';
  27.     }
  28.    
  29.     public function getData($filter, $page, $onPage = 20)
  30.     {
  31.         $q = "SELECT *, DATE_FORMAT(`date`, '%e %M, %Y') as date_str, DATE_FORMAT(`date`, '%H:%i') as hour_str  FROM `magazin` %where% ORDER BY `id` DESC %limitPage%";
  32.         $q = $this->_limitPage($q, $page, $onPage);
  33.         $where = $this->_where($filter);
  34.         $res = $this->query($q, $where);
  35.         return $res;
  36.     }
  37.    
  38.     protected function _limitPage($sql, $page, $rowCount)
  39.     {
  40.         $page     = ($page > 0)     ? $page     : 1;
  41.         $rowCount = ($rowCount > 0) ? $rowCount : 1;
  42.         $sql = str_replace('%limitPage%', 'LIMIT '.( $rowCount * ($page - 1) ).', '. (int)$rowCount, $sql);
  43.         return $sql;
  44.     }
  45.    
  46.     function get_unique_users()
  47.     {
  48.         $res = $this->fetchPairs("SELECT `id_user`, `author` FROM `magazin` GROUP BY `author` ORDER BY `author`");
  49.         return $res;
  50.     }
  51.    
  52.     function get_unique_actions()
  53.     {
  54.         $res = $this->fetchPairs("SELECT `action` FROM `magazin` GROUP BY `action` ORDER BY `action`");
  55.         return $res;
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement