|
1
|
|
|
<?php
|
|
2
|
|
|
/**
|
|
3
|
|
|
* @author Nikita Melnikov <[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.contact
|
|
8
|
|
|
*
|
|
9
|
|
|
* @property integer $id
|
|
10
|
|
|
* @property integer $contact_id
|
|
11
|
|
|
* @property string $name
|
|
12
|
|
|
* @property integer $position
|
|
13
|
|
|
* @property integer $visible
|
|
14
|
|
|
* @property string $sysname
|
|
15
|
|
|
*
|
|
16
|
|
|
* The followings are the available model relations:
|
|
17
|
|
|
* @property Contact $contact
|
|
18
|
|
|
* @property ContactField[] $contactFields
|
|
19
|
|
|
*/
|
|
20
|
|
|
class ContactGroup extends FActiveRecord
|
|
21
|
|
|
{
|
|
22
|
|
|
protected static $groups = array();
|
|
23
|
|
|
|
|
24
|
3 |
|
public function tableName()
|
|
25
|
|
|
{
|
|
26
|
3 |
|
return '{{contact_group}}';
|
|
27
|
|
|
}
|
|
28
|
|
|
|
|
29
|
13 |
|
public function defaultScope()
|
|
30
|
|
|
{
|
|
31
|
13 |
|
$alias = $this->getTableAlias(false, false);
|
|
32
|
|
|
|
|
33
|
|
|
return array(
|
|
34
|
|
|
'condition' => $alias.'.visible = 1'
|
|
35
|
13 |
|
);
|
|
36
|
|
|
}
|
|
37
|
|
|
|
|
38
|
1 |
|
public function relations()
|
|
39
|
|
|
{
|
|
40
|
|
|
return array(
|
|
41
|
1 |
|
'fields' => array(self::HAS_MANY, 'ContactField', 'group_id', 'order' => 'f.position ASC', 'alias' => 'f'),
|
|
42
|
1 |
|
);
|
|
43
|
|
|
}
|
|
44
|
|
|
|
|
45
|
|
|
/**
|
|
46
|
|
|
* Получение группы полей по системному имени (поле sysname)
|
|
47
|
|
|
*
|
|
48
|
|
|
* @static
|
|
49
|
|
|
*
|
|
50
|
|
|
* @param string $key
|
|
51
|
|
|
*
|
|
52
|
|
|
* @return ContactGroup
|
|
53
|
|
|
*/
|
|
54
|
|
View Code Duplication |
public static function getByKey($key)
|
|
|
|
|
|
|
55
|
|
|
{
|
|
56
|
|
|
if( empty(self::$groups[$key]) )
|
|
57
|
|
|
self::$groups[$key] = self::model()->findByAttributes(array('sysname' => $key));
|
|
58
|
|
|
|
|
59
|
|
|
return self::$groups[$key];
|
|
60
|
|
|
}
|
|
61
|
|
|
} |
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.