StoryRelation.php 1.3 KB

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