ptest/src/M/AdModel.php
2017-01-26 06:45:35 +03:00

209 строки
4.3 KiB
PHP

<?php
/**
* Created by PhpStorm.
* User: Игорь
* Date: 23.01.2017
* Time: 00:20
*/
namespace PTEST\M;
use PFRM\Model;
class AdModel extends Model{
protected $table_id;
protected $table_username;
protected $table_email;
protected $table_homepage;
protected $table_ip;
protected $table_browser;
protected $table_ptext;
protected $table_pdate;
/**
* Получить id
*
* @return integer|null
*/
public function getId() {
return (int) $this->table_id;
}
/**
* Установить имя пользователя
*
* @param string $username имя пользавтеля
*
* @return bool|string true в случае успеха. иначе сообщение с разъяснениями
*/
public function setUserName( $username ) {
if ( preg_match( '/[a-z,\d]{3,}/i', $username ) ) {
$this->table_username = $username;
return true;
} else {
return "Только цифры и буквы латинского алфавита, минимум 3";
}
}
/**
* Получить имя пользователя
*
* @return string
*/
public function getUserName(){
return $this->table_username;
}
/**
* Установка e-mail
*
* @param string $email
*
* @return bool|string true в случае успеха. иначе сообщение с разъяснениями
*/
public function setEmail( $email ) {
if ( preg_match('/.+@.+\..+/i', $email ) ) {
$this->table_email = $email;
return true;
} else {
return "Введите коректный e-mail адрес";
}
}
/**
* Получить e-mail
*
* @return mixed
*/
public function getEmail() {
return $this->table_email;
}
/**
* Установка домашней страницы
*
* @param string $homepage URL
*
* @return bool|string true в случае успеха. иначе сообщение с разъяснениями
*/
public function setHomepage( $homepage ) {
if ( preg_match('|https?://.*\..*|i', $homepage ) ) {
$this->table_homepage = strip_tags( $homepage );
return true;
} else {
return "Введите коректный адрес";
}
}
/**
* Получение домашней страницы
*
* @return mixed
*/
public function getHomepage() {
return $this->table_homepage;
}
/**
* Установка IP адреса
*
* @param mixed $ip
*/
public function setIp( $ip ) {
$this->table_ip = $ip;
}
/**
* Получение IP адреса
*
* @return mixed
*/
public function getIp() {
return $this->table_ip;
}
/**
* Установка данных User-Agent
*
* @param mixed $browser
*/
public function setBrowser( $browser ) {
$this->table_browser = $browser;
}
/**
* Получение данных User-Agent
*
* @return mixed
*/
public function getBrowser() {
return $this->table_browser;
}
/**
* Установка текста
*
* @param mixed $text
*/
public function setText( $text ) {
$this->table_ptext = strip_tags($text);
}
/**
* Получение текста
*
* @return mixed
*/
public function getText() {
return $this->table_ptext;
}
/**
* Установка даты
*
* @param mixed $date
*/
public function setDate( $date ) {
$this->table_pdate = $date;
}
/**
* Получение даты
* @return mixed
*/
public function getDate() {
return $this->table_pdate;
}
/**
* Получение количества страниц
*
* @return int
*/
public function countPages() {
return (int) ceil($this->count()/25);
}
/**
* Получение массива объектов для вывода на страницах
*
* @param integer $page_number номер страницы
* @param string $sort_by сортировка по столбцу
* @param string $order сортировка по возрастанию или убыванию
*
* @return mixed
*/
static public function getForPage( $page_number = 1, $sort_by = 'pdate', $order = 'ASC' ) {
$class_name = __CLASS__;
$offset = ($page_number - 1) * 25;
return $class_name::find(" 1 ORDER BY $sort_by $order LIMIT $offset,25");
}
}