TopSlider.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace app\models\base;
  3. use Yii;
  4. /**
  5. * This is the model class for table "top_slider".
  6. *
  7. * @property int $id
  8. * @property int|null $post_id
  9. * @property string|null $published_from
  10. * @property string|null $published_to
  11. * @property int|null $is_active
  12. * @property News $post
  13. */
  14. class TopSlider extends \yii\db\ActiveRecord
  15. {
  16. /**
  17. * {@inheritdoc}
  18. */
  19. public static function tableName()
  20. {
  21. return 'top_slider';
  22. }
  23. /**
  24. * {@inheritdoc}
  25. */
  26. public function rules()
  27. {
  28. return [
  29. [['post_id', 'is_active'], 'integer'],
  30. [['published_from', 'published_to'], 'safe'],
  31. ];
  32. }
  33. /**
  34. * {@inheritdoc}
  35. */
  36. public function attributeLabels()
  37. {
  38. return [
  39. 'id' => 'ID',
  40. 'post_id' => 'Post ID',
  41. 'published_from' => 'В слайдере с',
  42. 'published_to' => 'В слайдере по',
  43. 'is_active' => 'активна',
  44. ];
  45. }
  46. public function getPost()
  47. {
  48. return $this->hasOne(News::class,['id'=>'post_id']);
  49. }
  50. /**
  51. * {@inheritdoc}
  52. * @return TopSliderQuery the active query used by this AR class.
  53. */
  54. public static function find()
  55. {
  56. return new TopSliderQuery(get_called_class());
  57. }
  58. public function beforeSave($insert)
  59. {
  60. $this->published_from = date("Y-m-d H:i:s",strtotime($this->published_from));
  61. $this->published_to = date("Y-m-d H:i:s",strtotime($this->published_to));
  62. return parent::beforeSave($insert);
  63. }
  64. }