Esempio n. 1
0
 /**
  * get document
  *
  * @param string $id         document id
  * @param string $instanceId instance id
  * @return ItemEntity
  */
 public function get($id, $instanceId = null)
 {
     $doc = $this->document->get($id, $instanceId);
     if ($doc->userId === '') {
         $doc->setAuthor($this->auth->makeGuest());
     } else {
         $doc->setAuthor($this->member->find($doc->getUserId()));
     }
     $entity = $this->makeItem($doc);
     $this->shortIdGenerator->associate($entity);
     $this->slug->associate($entity);
     return $entity;
 }
 /**
  * create
  *
  * @param string $widgetId widget id
  * @param array  $args     to create widget html arguments
  *
  * @return mixed
  * @throws Exception
  */
 public function create($widgetId, $args = [])
 {
     $currentUserRating = $this->guard->user()->getRating();
     try {
         $instance = $this->getInstance($widgetId);
         if (in_array($currentUserRating, $instance::$ratingWhiteList)) {
             $ret = $instance->render($args);
             if ($ret instanceof Renderable) {
                 $ret = $ret->render();
             }
             return $ret;
         } else {
             return '';
         }
     } catch (Exception $e) {
         if (in_array($currentUserRating, static::$displayErrorRatings)) {
             return $this->view->make('widget.error', ['message' => $e->getMessage()])->render();
         } else {
             return '';
         }
     }
 }
 /**
  * Add new comment
  *
  * @param CommentEntity              $comment comment object
  * @param MemberEntityInterface|null $user    user instance
  * @return CommentEntity
  * @throws InvalidObjectException
  */
 public function add(CommentEntity $comment, MemberEntityInterface $user = null)
 {
     if ($comment->instanceId === null || $comment->targetId === null) {
         throw new InvalidObjectException();
     }
     if (isset($comment->targetAuthorId)) {
         unset($comment->targetAuthorId);
     }
     /** @var MemberEntityInterface $user */
     $user = $user ?: $this->auth->user();
     $comment->userId = $user->getId();
     if (isset($comment->writer) === false) {
         $comment->writer = $user->getDisplayName();
     }
     $config = $this->configs->get($this->getConfigKey($comment->instanceId));
     if ($config->get('useWysiwyg') === true) {
         $comment->html = 1;
     }
     // for 계층 모델
     if (isset($comment->parentId) === true) {
         if (!($parent = $this->get($comment->parentId))) {
             throw new InvalidObjectException();
         }
         $this->setReply($comment, $parent);
     }
     $added = $this->repo->insert($comment);
     return $this->member->associate($added);
 }
Esempio n. 4
0
 /**
  * get author
  * $author 가 null 로 넘어 온 경우 $auth 를 통해 로그인 사용자 정보를 획득
  *
  * @param MemberEntityInterface $author user instance
  * @return MemberEntityInterface
  * @throws Exceptions\LoginRequiredException
  */
 protected function getUser(MemberEntityInterface $author = null)
 {
     if ($author === null) {
         $author = $this->auth->user();
     }
     $this->invalid($author);
     return $author;
 }
Esempio n. 5
0
 /**
  * file upload to storage
  *
  * @param UploadedFile $uploaded uploaded file instance
  * @param string       $path     be saved path
  * @param string|null  $name     be saved file name
  * @param string|null  $disk     disk name (ex. local, ftp, s3 ...)
  * @return File
  * @throws InvalidFileException
  */
 public function upload(UploadedFile $uploaded, $path, $name = null, $disk = null)
 {
     if ($uploaded->isValid() === false) {
         throw new InvalidFileException();
     }
     $name = $name ?: $this->makeFilename($uploaded->getClientOriginalName());
     $id = $this->keygen->generate();
     $file = $this->files->store(file_get_contents($uploaded->getPathname()), $this->makePathname($id, $path, $name), $disk);
     $file->id = $id;
     $file->userId = $this->auth->user()->getId();
     $file->clientname = $uploaded->getClientOriginalName();
     return $this->repo->insert($file);
 }