123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- <?php
- namespace app\models;
- use app\models\base\NewsTopic;
- use app\models\base\Story;
- use Yii;
- /**
- * This is the model class for table "design".
- *
- * @property int $id id
- * @property int $parent_id ресурсы
- * @property string $type тип ресурса
- * @property int $design вариант отображения
- * @property string|null $title заголовок
- * @property int|null $sort сортировка
- * @property string|null $url URL
- * @property string $active спрятать
- * @property NewsTopic|Story $parent
- */
- class Design extends \yii\db\ActiveRecord
- {
- const WIDE_WIDGET = 1;
- const TEXT_NEWS_WIDGET = 2;
- const TOPIC_WIDGET = 3;
- const IMAGINE_NEWS_WIDGET = 4;
- const COLORFUL_WIDGET = 5;
- const MAY9 = 6;
- const INQUIRER_3 = 7;
- const INQUIRER_WIDE = 8;
- const VIDEO_WIDE = 9;
- public static array $id_to_view_map = [
- self::WIDE_WIDGET=>'index/wide_widget',
- self::TEXT_NEWS_WIDGET=>'index/text_news_widget',
- self::TOPIC_WIDGET=>'index/topic_widget',
- self::IMAGINE_NEWS_WIDGET=>'index/partners_news',
- self::COLORFUL_WIDGET=>'index/colorful_widget',
- self::MAY9=>'index/wide_widget_9may',
- self::INQUIRER_3=>'index/inquirer3',
- self::INQUIRER_WIDE=>'index/inquirer_wide',
- self::VIDEO_WIDE=>'index/wide_widget_video',
- ];
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return 'design';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['parent_id','active','type','design'], 'required'],
- [['parent_id', 'design', 'order'], 'integer'],
- [['active'], 'string'],
- [['type'], 'string', 'max' => 64],
- [['title', 'url'], 'string', 'max' => 255],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'id',
- 'parent_id' => 'ресурсы',
- 'type' => 'тип ресурса',
- 'design' => 'вариант отображения',
- 'title' => 'заголовок',
- 'order' => 'сортировка',
- 'url' => 'URL',
- 'active' => 'спрятать',
- ];
- }
- /**
- * {@inheritdoc}
- * @return status.
- */
- public function Active($id, $state = -1)
- {
- if( $state < 0 ){
- $this->active = ($this->active == 'Y')?'N':'Y';
- }else{
- $this->active = $state;
- }
- return $this->save();
- }
- private $_parent = false;
- /**
- * @return NewsTopic|Story|NULL
- */
- public function getParent()
- {
- if(!$this->_parent){
- switch ($this->type){
- case "topic":
- $this->_parent = NewsTopic::find()->alias("t")->andWhere(["t.id"=>$this->parent_id])->one();
- break;
- default:
- $this->_parent = Story::find()->alias("s")->andWhere(['s.id'=>$this->parent_id])->one();
- }
- }
- return $this->_parent;
- }
- }
|