Page.php
4.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<?php
namespace common\models;
use Yii;
use common\models\PageLang;
/**
* This is the model class for table "page".
*
* @property integer $page_id
* @property string $date_add
* @property integer $template_id
* @property integer $image_id
* @property integer $show
*/
class Page extends \yii\db\ActiveRecord
{
var $data;
//public $title;
/**
* @inheritdoc
*/
public static function tableName()
{
return 'page';
}
// ==== DATA PAGE LANG ====
public function getData()
{
$this->data = PageLang::find()->where(['page_id' => $this->page_id, 'lang_id' => yii::$app->lang_id])->one();
}
public function getDataByKey($key)
{
if (! $this->data)
{
$this->getData();
}
return isset ($this->data[$key]) ? $this->data[$key] : '';
}
// ==== DATA PAGE LANG FIELD ====
public function getTitle()
{
return $this->getDataByKey('title');
}
public function getMeta_title()
{
return $this->getDataByKey('meta_title');
}
public function getMeta_description()
{
return $this->getDataByKey('meta_description');
}
public function getText()
{
return $this->getDataByKey('text');
}
public function getPage_alias()
{
return $this->getDataByKey('page_alias');
}
// ==== PAGE LANG FILTER FIELD ====
public function findPageLangField($post)
{
if (! $this->data)
{
$this->getData();
}
if (empty ($this->data) || empty ($post))
{
return false;
}
$result = array ();
foreach ($post as $key1 => $row1)
{
foreach ($this->data as $key2 => $row2)
{
if ($key1 == $key2)
{
$result[$key1] = $row1;
}
}
}
return $result;
}
// ==== FRONT ====
static function getPageByUrl ($url)
{
return yii::$app->db->createCommand('
SELECT
`termin`.show, `termin`.termin_id, `termin`.page_id,
`controller`.controller_name,
`template`.template_file
FROM `termin`
INNER JOIN `termin_lang` ON `termin_lang`.termin_id = `termin`.termin_id
AND `termin_lang`.lang_id = '.yii::$app->lang_id.'
AND `termin_lang`.termin_alias = "'.$url.'"
INNER JOIN `template` ON `template`.template_id = `termin`.template_id
INNER JOIN `controller` ON `controller`.controller_id = `template`.controller_id
')->queryOne();
}
static function isShow ($page)
{
return $page['show'] == 1 ? true : false;
}
static function getPageById ($page_id)
{
return yii::$app->db->createCommand('
SELECT *
FROM `termin`
INNER JOIN `termin_lang` ON `termin_lang`.termin_id = `termin`.termin_id
AND `termin_lang`.lang_id = '.yii::$app->lang_id.'
INNER JOIN `page` ON `page`.page_id = `termin`.page_id
INNER JOIN `page_lang` ON `page_lang`.page_id = `page`.page_id
AND `page_lang`.lang_id = '.yii::$app->lang_id.'
WHERE `termin`.termin_id = "'.(int)$page_id.'"
')->queryOne();
}
// ==== YII ====
/**
* @inheritdoc
*/
public function rules()
{
return [
[['date_add', 'template_id', 'image_id', 'show'], 'required'],
[['date_add'], 'safe'],
[['template_id', 'image_id', 'show'], 'integer']
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'page_id' => Yii::t('field', 'page'),
'date_add' => Yii::t('field', 'date_add'),
'template_id' => Yii::t('field', 'template'),
'image_id' => Yii::t('field', 'image'),
'show' => Yii::t('field', 'show'),
'title' => Yii::t('field', 'title'),
'meta_title' => Yii::t('field', 'meta_title'),
'meta_description' => Yii::t('field', 'meta_description'),
'text' => Yii::t('field', 'text'),
'page_alias' => Yii::t('field', 'page_alias'),
'lang_id' => Yii::t('field', 'lang_id'),
];
}
}