<?php

namespace app\models\base;

use Yii;

/**
 * This is the model class for table "news_topic_relation".
 *
 * @property int $news_id
 * @property int $topic_id
 */
class NewsTopicRelation extends BaseFrontendClass
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'news_topic_relation';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['news_id', 'topic_id'], 'integer'],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'news_id' => 'News ID',
            'topic_id' => 'Topic ID',
        ];
    }

    /**
     * {@inheritdoc}
     * @return NewsTopicRelationQuery the active query used by this AR class.
     */
    public static function find()
    {
        return new NewsTopicRelationQuery(get_called_class());
    }

	/**
     * {@inheritdoc}
     * @return status
     */
    public function saveNewsTopics($id, $topics)
    {
		$status = true;
		foreach( $topics as $item ){
			$status &= $this->db->createCommand()->insert(NewsTopicRelation::tableName(), [
				'news_id' => $id,
				'topic_id' => $item,
			])->execute();
		}
        return $status;
    }

}
