CateService.php 936 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace addons\TinyBlog\services;
  3. use common\enums\StatusEnum;
  4. use common\helpers\ArrayHelper;
  5. use addons\TinyBlog\common\models\Cate;
  6. /**
  7. * Class CateService
  8. * @package addons\TinyBlog\services
  9. * @author jianyan74 <751393839@qq.com>
  10. */
  11. class CateService
  12. {
  13. /**
  14. * @return array
  15. */
  16. public function getMapList()
  17. {
  18. return ArrayHelper::map($this->findAll(), 'id', 'title');
  19. }
  20. /**
  21. * @return array|\yii\db\ActiveRecord[]
  22. */
  23. public function findById($id)
  24. {
  25. return Cate::find()
  26. ->where(['id' => $id])
  27. ->andWhere(['status' => StatusEnum::ENABLED])
  28. ->one();
  29. }
  30. /**
  31. * @return array|\yii\db\ActiveRecord[]
  32. */
  33. public function findAll()
  34. {
  35. return Cate::find()
  36. ->where(['status' => StatusEnum::ENABLED])
  37. ->orderBy('sort asc')
  38. ->asArray()
  39. ->all();
  40. }
  41. }
粤ICP备19079148号