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`.termin_id, `termin`.page_id, `page`.show, `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 `page` ON `page`.page_id = `termin`.page_id INNER JOIN `template` ON `template`.template_id = `termin_lang`.template_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'), ]; } }