TopSlider.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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', 'published_from', 'published_to'], 'required'],
  30. [['post_id', 'is_active'], 'integer'],
  31. [['published_from', 'published_to'], 'safe'],
  32. ];
  33. }
  34. /**
  35. * {@inheritdoc}
  36. */
  37. public function attributeLabels()
  38. {
  39. return [
  40. 'id' => 'ID',
  41. 'post_id' => 'Post ID',
  42. 'published_from' => 'В слайдере с',
  43. 'published_to' => 'В слайдере по',
  44. 'is_active' => 'активна',
  45. ];
  46. }
  47. public function getPost()
  48. {
  49. return $this->hasOne(News::class,['id'=>'post_id']);
  50. }
  51. /**
  52. * {@inheritdoc}
  53. * @return TopSliderQuery the active query used by this AR class.
  54. */
  55. public static function find()
  56. {
  57. return new TopSliderQuery(get_called_class());
  58. }
  59. public function beforeSave($insert)
  60. {
  61. $this->published_from = date("Y-m-d H:i:s",strtotime($this->published_from));
  62. $this->published_to = date("Y-m-d H:i:s",strtotime($this->published_to));
  63. return parent::beforeSave($insert);
  64. }
  65. }