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
|
8
|
|
|
*
|
9
|
|
|
* @method static TextBlock model(string $class = __CLASS__)
|
10
|
|
|
*
|
11
|
|
|
* @property string $id
|
12
|
|
|
* @property string $location
|
13
|
|
|
* @property string $name
|
14
|
|
|
* @property integer $position
|
15
|
|
|
* @property string $url
|
16
|
|
|
* @property integer $visible
|
17
|
|
|
* @property string $content
|
18
|
|
|
* @property string $img
|
19
|
|
|
*/
|
20
|
|
|
class TextBlock extends FActiveRecord
|
21
|
|
|
{
|
22
|
|
|
public $image;
|
23
|
|
|
|
24
|
6 |
|
public function rules()
|
25
|
|
|
{
|
26
|
|
|
return array(
|
27
|
6 |
|
array('position, visible, auto_created', 'numerical', 'integerOnly' => true),
|
28
|
6 |
|
array('location, name, url', 'length', 'max' => 255),
|
29
|
6 |
|
array('content', 'safe'),
|
30
|
6 |
|
);
|
31
|
|
|
}
|
32
|
|
|
|
33
|
9 |
View Code Duplication |
public function defaultScope()
|
|
|
|
|
34
|
|
|
{
|
35
|
9 |
|
$alias = $this->getTableAlias(false, false);
|
36
|
|
|
|
37
|
|
|
return array(
|
38
|
9 |
|
'condition' => $alias.'.visible=1',
|
39
|
9 |
|
'order' => "{$alias}.location, {$alias}.position",
|
40
|
9 |
|
);
|
41
|
|
|
}
|
42
|
|
|
|
43
|
|
|
/**
|
44
|
|
|
* @return array
|
45
|
|
|
*/
|
46
|
16 |
|
public function getGroupByLocation()
|
47
|
|
|
{
|
48
|
16 |
|
$this->dbCriteria->select = 'location, content, id';
|
49
|
|
|
|
50
|
16 |
|
$command = $this->dbConnection->commandBuilder->createFindCommand($this->tableName(), $this->dbCriteria);
|
51
|
|
|
|
52
|
16 |
|
return CHtml::listData($command->queryAll(), 'id', 'content', 'location');
|
53
|
|
|
}
|
54
|
|
|
|
55
|
|
|
/**
|
56
|
|
|
* @param string $location
|
57
|
|
|
*
|
58
|
|
|
* @return TextBlock[]|array
|
59
|
|
|
*/
|
60
|
8 |
|
public function getByLocation($location)
|
61
|
|
|
{
|
62
|
8 |
|
return $this->findAllByAttributes(array('location' => $location));
|
63
|
|
|
}
|
64
|
|
|
|
65
|
|
|
public function __toString()
|
66
|
|
|
{
|
67
|
|
|
return $this->content;
|
68
|
|
|
}
|
69
|
|
|
|
70
|
3 |
|
protected function afterFind()
|
71
|
|
|
{
|
72
|
3 |
|
$this->image = new FSingleImage($this->img, 'textblock');
|
73
|
3 |
|
parent::afterFind();
|
74
|
|
|
}
|
75
|
|
|
} |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.