1
|
|
|
<?php
|
2
|
|
|
/**
|
3
|
|
|
* @author Sergey Glagolev <[email protected]>
|
4
|
|
|
* @link https://github.com/shogodev/argilla/
|
5
|
|
|
* @copyright Copyright © 2003-2014 Shogo
|
6
|
|
|
* @license http://argilla.ru/LICENSE
|
7
|
|
|
* @package frontend.models.news
|
8
|
|
|
*
|
9
|
|
|
* @method static News model(string $class = __CLASS__)
|
10
|
|
|
* @method News main()
|
11
|
|
|
*
|
12
|
|
|
* @property string $id
|
13
|
|
|
* @property integer $section_id
|
14
|
|
|
* @property integer $position
|
15
|
|
|
* @property string $url
|
16
|
|
|
* @property string $visible
|
17
|
|
|
* @property string $date
|
18
|
|
|
* @property string $notice
|
19
|
|
|
* @property string $name
|
20
|
|
|
* @property string $content
|
21
|
|
|
* @property string $img
|
22
|
|
|
*
|
23
|
|
|
* @property NewsSection $section
|
24
|
|
|
* @property FActiveImage $image
|
25
|
|
|
*/
|
26
|
|
|
class News extends FActiveRecord
|
27
|
|
|
{
|
28
|
|
|
public function behaviors()
|
29
|
|
|
{
|
30
|
|
|
return array(
|
31
|
|
|
'imageBehavior' => array('class' => 'SingleImageBehavior', 'path' => 'news', 'types' => array('pre')),
|
32
|
|
|
);
|
33
|
|
|
}
|
34
|
|
|
|
35
|
|
|
public function defaultScope()
|
36
|
|
|
{
|
37
|
|
|
$alias = $this->getTableAlias(false, false);
|
38
|
|
|
|
39
|
|
|
return array(
|
40
|
|
|
'condition' => $alias.'.visible=1',
|
41
|
|
|
'order' => $alias.'.date DESC, '.$alias.'.position ASC',
|
42
|
|
|
);
|
43
|
|
|
}
|
44
|
|
|
|
45
|
|
|
public function scopes()
|
46
|
|
|
{
|
47
|
|
|
$alias = $this->getTableAlias();
|
48
|
|
|
|
49
|
|
|
return array(
|
50
|
|
|
'main' => array(
|
51
|
|
|
'condition' => $alias.'.main=1',
|
52
|
|
|
'limit' => 1
|
53
|
|
|
)
|
54
|
|
|
);
|
55
|
|
|
}
|
56
|
|
|
|
57
|
|
|
public function relations()
|
58
|
|
|
{
|
59
|
|
|
return array(
|
60
|
|
|
'section' => array(self::BELONGS_TO, 'NewsSection', 'section_id'),
|
61
|
|
|
);
|
62
|
|
|
}
|
63
|
|
|
|
64
|
|
|
/**
|
65
|
|
|
* @param string $format
|
66
|
|
|
*
|
67
|
|
|
* @return string
|
68
|
|
|
*/
|
69
|
|
|
public function getFormatDate($format = 'd.m.Y')
|
70
|
|
|
{
|
71
|
|
|
return DateTime::createFromFormat('Y-m-d', $this->date)->format($format);
|
72
|
|
|
}
|
73
|
|
|
|
74
|
|
|
/**
|
75
|
|
|
* @param string $format
|
76
|
|
|
*
|
77
|
|
|
* @return string
|
78
|
|
|
*/
|
79
|
|
|
public function getFormatDateYii($format = 'dd.MM.y, eeee')
|
80
|
|
|
{
|
81
|
|
|
return Yii::app()->locale->dateFormatter->format($format, DateTime::createFromFormat('Y-m-d', $this->date)->getTimestamp());
|
82
|
|
|
}
|
83
|
|
|
|
84
|
|
|
/**
|
85
|
|
|
* @param bool $absolute
|
86
|
|
|
*
|
87
|
|
|
* @return string
|
88
|
|
|
*/
|
89
|
|
|
public function getUrl($absolute = false)
|
90
|
|
|
{
|
91
|
|
|
return $absolute ? Yii::app()->createAbsoluteUrl('news/one', array('section' => $this->section->url, 'url' => $this->url)) : Yii::app()->createUrl('news/one', array('section' => $this->section->url, 'url' => $this->url));
|
92
|
|
|
}
|
93
|
|
|
} |