NewsTopicRelation.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace app\models\base;
  3. use Yii;
  4. /**
  5. * This is the model class for table "news_topic_relation".
  6. *
  7. * @property int $news_id
  8. * @property int $topic_id
  9. */
  10. class NewsTopicRelation extends BaseFrontendClass
  11. {
  12. /**
  13. * {@inheritdoc}
  14. */
  15. public static function tableName()
  16. {
  17. return 'news_topic_relation';
  18. }
  19. /**
  20. * {@inheritdoc}
  21. */
  22. public function rules()
  23. {
  24. return [
  25. [['news_id', 'topic_id'], 'integer'],
  26. ];
  27. }
  28. /**
  29. * {@inheritdoc}
  30. */
  31. public function attributeLabels()
  32. {
  33. return [
  34. 'news_id' => 'News ID',
  35. 'topic_id' => 'Topic ID',
  36. ];
  37. }
  38. /**
  39. * {@inheritdoc}
  40. * @return NewsTopicRelationQuery the active query used by this AR class.
  41. */
  42. public static function find()
  43. {
  44. return new NewsTopicRelationQuery(get_called_class());
  45. }
  46. /**
  47. * {@inheritdoc}
  48. * @return status
  49. */
  50. public function saveNewsTopics($id, $topics)
  51. {
  52. $status = true;
  53. foreach( $topics as $item ){
  54. $status &= $this->db->createCommand()->insert(NewsTopicRelation::tableName(), [
  55. 'news_id' => $id,
  56. 'topic_id' => $item,
  57. ])->execute();
  58. }
  59. return $status;
  60. }
  61. }