Ejemplo n.º 1
0
 /**
  * get article
  *
  * @param BoardPermissionHandler $boardPermission board permission
  * @param string                 $menuUrl         first segment
  * @param string                 $id              document id
  * @return mixed
  */
 public function get(BoardPermissionHandler $boardPermission, $menuUrl, $id)
 {
     if (Gate::denies(BoardPermissionHandler::ACTION_READ, new Instance($boardPermission->name($this->instanceId)))) {
         throw new AccessDeniedHttpException();
     }
     /** @var UserInterface $user */
     $user = Auth::user();
     /** @var Board $item */
     $item = $this->handler->getModel($this->config)->find($id);
     $this->handler->setModelConfig($item, $this->config);
     $visible = false;
     if ($item->display == Document::DISPLAY_VISIBLE) {
         $visible = true;
     }
     if ($item->display == Document::DISPLAY_SECRET) {
         if ($this->isManager == true) {
             $visible = true;
         } elseif ($user->getId() == $item->getAuthor()->getId()) {
             $visible = true;
         }
         if ($visible === false) {
             throw new SecretDocumentHttpException();
         }
     }
     if ($visible === true) {
         $this->handler->incrementReadCount($item, $user);
     }
     $showCategoryItem = null;
     if ($this->config->get('category')) {
         $boardCategory = $item->boardCategory;
         if ($boardCategory) {
             $showCategoryItem = $boardCategory->categoryItem;
         }
     }
     return XePresenter::makeApi(['item' => $item, 'visible' => $visible, 'showCategoryItem' => $showCategoryItem]);
 }