Guest User

/classes/Model.php

a guest
Oct 23rd, 2016
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.36 KB | None | 0 0
  1. <?php
  2.     include_once 'D:\USR\apache\htdocs\s2.localhost\Phoenix_demo\classes\Connection.php';
  3.    
  4.     /**
  5.      * Model
  6.      */
  7.     class Model
  8.     {
  9.         /**
  10.          * Path to changelog
  11.          */
  12.         const CHANGE_LOG = 'D:/USR/apache/htdocs/s2.localhost' . '/Phoenix_demo/changelog.txt';
  13.        
  14.         /**
  15.          * @var class_Connection
  16.          */
  17.         private $db;
  18.        
  19.         /**
  20.          *
  21.          * @var int
  22.          */
  23.         private $numOfQuotes = 6;
  24.         /**
  25.          *
  26.          * @var bool
  27.          */
  28.         private $color_on = true;
  29.        
  30.         /**
  31.          * Получает доступ к БД
  32.          */
  33.         public function __construct($config, $doc_root)
  34.         {
  35.             $this->db = new Connection($config, $doc_root);
  36.         }
  37.        
  38.         /**
  39.          * Цвет цитат на странице
  40.          *
  41.          * @param bool $color_on
  42.          */
  43.        
  44.         /**
  45.          *
  46.          * @param integer $numOfQuotes
  47.          */
  48.         public function setNumOfQuotes($numOfQuotes)
  49.         {
  50.             $this->numOfQuotes = $numOfQuotes;
  51.         }
  52.        
  53.         /**
  54.          *
  55.          * @return integer Number of quotes model currently is set to retrieve
  56.          */
  57.         public function getNumOfQuotes()
  58.         {
  59.             return $this->numOfQuotes;
  60.         }
  61.        
  62.         /**
  63.          *
  64.          * @param bool $color_on If color of quotes is set on
  65.          */
  66.         public function setColor($color_on)
  67.         {
  68.             $this->color_on = $color_on;
  69.         }
  70.        
  71.         /**
  72.          * @return bool $color_on If color of quotes is set on
  73.          */
  74.         public function getColor()
  75.         {
  76.             return $this->color_on;
  77.         }
  78.        
  79.         /**
  80.          *
  81.          * @return array Array of strings, each string a line
  82.          */
  83.         public function getChanges()
  84.         {
  85.             $changes = file(self::CHANGE_LOG, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
  86.             return $changes;
  87.         }
  88.        
  89.         /**
  90.          *
  91.          * @return array Array of strings, each string a citation
  92.          */
  93.         public function getQuotes()
  94.         {
  95.             $min = 0; $max = 0;
  96.             //получает диапазон номеров цитат из БД
  97.             $this->db->fetchInterval($min, $max);
  98.            
  99.             //инициализирует массив цитат  и их число
  100.             $ids[0] = 0;
  101.             $count = $this->numOfQuotes;     
  102.             //для каждой из шести цитат
  103.             for ($i = 0; $i < $count; $i++)
  104.             {
  105.                 do
  106.                 {
  107.                     $temp_id = $this->db->uniqueNum($min, $max, $ids);
  108.                     $ids[$i] = $temp_id;
  109.                     $result = $this->db->fetchQuote($ids[$i]);
  110.                 }
  111.                 while (mysqli_num_rows($result) === 0);
  112.                 $citations[] = mysqli_fetch_array($result)[0];
  113.             }
  114.             return $citations;
  115.         }
  116.     }
Advertisement
Add Comment
Please, Sign In to add comment