123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- <?php
- namespace App\Services\Course;
- use App\Contracts\Repositories\Course\ChapterRepository;
- use App\Repositories\Criteria\Course\ChapterCriteria;
- use App\Repositories\Eloquent\Course\ChapterRepositoryEloquent;
- use App\Repositories\Presenters\Course\ChapterPresenter;
- use Illuminate\Http\Request;
- class ChapterService
- {
- /**
- * @var ChapterRepositoryEloquent
- */
- private $chapterRepository;
- /**
- * ChapterService constructor.
- *
- * @param ChapterRepositoryEloquent $chapterRepositoryEloquent
- */
- public function __construct(ChapterRepositoryEloquent $chapterRepositoryEloquent)
- {
- $this->chapterRepository = $chapterRepositoryEloquent;
- }
- /**
- * @param Request $request
- *
- * @return mixed
- * @throws \Prettus\Repository\Exceptions\RepositoryException
- */
- public function handleList(Request $request)
- {
- $this->chapterRepository->pushCriteria(new ChapterCriteria($request));
- $this->chapterRepository->setPresenter(ChapterPresenter::class);
- return $this->chapterRepository->searchChaptersByPage();
- }
- /**
- * @param $id
- *
- * @return \Illuminate\Database\Eloquent\Model
- */
- public function handleProfile($id)
- {
- $this->chapterRepository->setPresenter(ChapterPresenter::class);
- return $this->chapterRepository->searchChapterBy($id);
- }
- /**
- * @param array $data
- *
- * @return mixed
- * @throws \Prettus\Validator\Exceptions\ValidatorException
- */
- public function handleStore($data)
- {
- $chapter = $this->chapterRepository->create($data);
- return $chapter;
- }
- /**
- * @param array $data
- *
- * @return mixed
- * @throws \Prettus\Validator\Exceptions\ValidatorException
- */
- public function handleUpdate($data)
- {
- $chapter = $this->chapterRepository->update($data, $data['id']);
- return $chapter;
- }
- /**
- * @param Request $request
- *
- * @return mixed
- * @throws \Prettus\Validator\Exceptions\ValidatorException
- */
- public function handleDelete($id)
- {
- return $this->chapterRepository->delete($id);
- }
- /**
- * 批量删除
- * @param $ids
- * @return mixed
- */
- public function handleBatchDelete($ids)
- {
- return $this->chapterRepository->whereIn('id', $ids)->delete();
- }
- /**
- * 选项
- * @param Request $request
- * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator|\Illuminate\Support\Collection|mixed
- * @throws \Prettus\Repository\Exceptions\RepositoryException
- */
- public function handleSelectOptions(Request $request)
- {
- $this->chapterRepository->pushCriteria(new ChapterCriteria($request));
- return $this->chapterRepository->all(['id', 'title']);
- }
- /**
- * @param Request $request
- *
- * @return mixed
- * @throws \Prettus\Repository\Exceptions\RepositoryException
- */
- public function handleAll(Request $request)
- {
- $this->chapterRepository->pushCriteria(new ChapterCriteria($request));
- $this->chapterRepository->setPresenter(ChapterPresenter::class);
- return $this->chapterRepository->get();
- }
- }
|