BookChapter.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace common\modules\book\models;
  3. use common\behaviors\CommentBehavior;
  4. use common\behaviors\PositionBehavior;
  5. use Yii;
  6. use yii\behaviors\TimestampBehavior;
  7. /**
  8. * This is the model class for table "{{%book_chapter}}".
  9. *
  10. * @property integer $id
  11. * @property integer $book_id
  12. * @property integer $catalog_id
  13. * @property integer $chapter_name
  14. * @property string $chapter_body
  15. * @property integer $pid
  16. * @property integer $created_at
  17. * @property integer $updated_at
  18. * @property Book $book
  19. */
  20. class BookChapter extends \yii\db\ActiveRecord
  21. {
  22. /**
  23. * @inheritdoc
  24. */
  25. public static function tableName()
  26. {
  27. return '{{%book_chapter}}';
  28. }
  29. /**
  30. * @inheritdoc
  31. */
  32. public function rules()
  33. {
  34. return [
  35. [['book_id', 'chapter_name'], 'required'],
  36. [['book_id', 'pid'], 'integer'],
  37. [['chapter_name', 'chapter_body'], 'string'],
  38. ];
  39. }
  40. /**
  41. * @inheritdoc
  42. */
  43. public function attributeLabels()
  44. {
  45. return [
  46. 'id' => 'ID',
  47. 'book_id' => '书',
  48. 'chapter_name' => '章节标题',
  49. 'chapter_body' => '章节正文',
  50. 'pid' => 'Pid',
  51. 'created_at' => '创建于',
  52. 'updated_at' => '更新于',
  53. 'sort' => '排序'
  54. ];
  55. }
  56. public function behaviors()
  57. {
  58. return [
  59. TimestampBehavior::className(),
  60. [
  61. 'class' => PositionBehavior::className(),
  62. 'positionAttribute' => 'sort',
  63. 'groupAttributes' => ['book_id', 'pid']
  64. ],
  65. [
  66. 'class' => CommentBehavior::className()
  67. ]
  68. ];
  69. }
  70. public function getBook()
  71. {
  72. return $this->hasOne(Book::className(), ['id' => 'book_id']);
  73. }
  74. public function getSons()
  75. {
  76. return $this->hasMany(self::className(), ['pid' => 'id']);
  77. }
  78. }