. */ namespace SP\Modules\Web\Controllers; use SP\Core\Acl\Acl; use SP\Core\Acl\UnauthorizedActionException; use SP\Core\Events\Event; use SP\Http\JsonResponse; use SP\Modules\Web\Controllers\Helpers\Grid\TrackGrid; use SP\Modules\Web\Controllers\Traits\ItemTrait; use SP\Modules\Web\Controllers\Traits\JsonTrait; use SP\Services\Track\TrackService; /** * Class TrackController * * @package SP\Modules\Web\Controllers */ final class TrackController extends ControllerBase { use JsonTrait, ItemTrait; /** * @var TrackService */ protected $trackService; /** * Search action * * @return bool * @throws \DI\DependencyException * @throws \DI\NotFoundException * @throws \SP\Core\Exceptions\ConstraintException * @throws \SP\Core\Exceptions\QueryException * @throws UnauthorizedActionException */ public function searchAction() { if (!$this->acl->checkUserAccess(Acl::TRACK_SEARCH)) { throw new UnauthorizedActionException(UnauthorizedActionException::ERROR); } $this->view->addTemplate('datagrid-table', 'grid'); $this->view->assign('index', $this->request->analyzeInt('activetab', 0)); $this->view->assign('data', $this->getSearchGrid()); return $this->returnJsonResponseData(['html' => $this->render()]); } /** * getSearchGrid * * @return $this * @throws \DI\DependencyException * @throws \DI\NotFoundException * @throws \SP\Core\Exceptions\ConstraintException * @throws \SP\Core\Exceptions\QueryException */ protected function getSearchGrid() { $itemSearchData = $this->getSearchData($this->configData->getAccountCount(), $this->request); $itemsGridHelper = $this->dic->get(TrackGrid::class); return $itemsGridHelper->updatePager($itemsGridHelper->getGrid($this->trackService->search($itemSearchData)), $itemSearchData); } /** * Unlocks a track * * @param int $id * * @return bool * @throws UnauthorizedActionException */ public function unlockAction($id) { if (!$this->acl->checkUserAccess(Acl::TRACK_UNLOCK)) { throw new UnauthorizedActionException(UnauthorizedActionException::ERROR); } try { $this->trackService->unlock($id); $this->eventDispatcher->notifyEvent('unlock.track', new Event($this)); return $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Track desbloqueado')); } catch (\Exception $e) { processException($e); return $this->returnJsonResponseException($e); } } /** * Clears tracks * * @return bool * @throws UnauthorizedActionException */ public function clearAction() { if (!$this->acl->checkUserAccess(Acl::TRACK_CLEAR)) { throw new UnauthorizedActionException(UnauthorizedActionException::ERROR); } try { $this->trackService->clear(); $this->eventDispatcher->notifyEvent('clear.track', new Event($this)); return $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Tracks limpiados')); } catch (\Exception $e) { processException($e); return $this->returnJsonResponseException($e); } } /** * @throws \DI\DependencyException * @throws \DI\NotFoundException * @throws \SP\Services\Auth\AuthException */ protected function initialize() { $this->checkLoggedIn(); $this->trackService = $this->dic->get(TrackService::class); } }