예제 #1
0
 /**
  * @param EditPage $command
  *
  * @return \Sijad\Pages\Page
  *
  * @throws \Flarum\Core\Exception\PermissionDeniedException
  */
 public function handle(EditPage $command)
 {
     $actor = $command->actor;
     $data = $command->data;
     $page = $this->pages->findOrFail($command->pageId, $actor);
     $this->assertAdmin($actor);
     $attributes = array_get($data, 'attributes', []);
     if (isset($attributes['title'])) {
         $page->title = $attributes['title'];
     }
     if (isset($attributes['slug'])) {
         $page->slug = $attributes['slug'];
     }
     if (isset($attributes['content'])) {
         $page->content = $attributes['content'];
     }
     if (isset($attributes['isHidden'])) {
         $page->is_hidden = (bool) $attributes['isHidden'];
     }
     if (isset($attributes['isHtml'])) {
         $page->is_html = (bool) $attributes['isHtml'];
     }
     $page->edit_time = time();
     $this->validator->assertValid($page->getDirty());
     $page->save();
     return $page;
 }
 /**
  * @param CreatePage $command
  *
  * @return Page
  */
 public function handle(CreatePage $command)
 {
     $actor = $command->actor;
     $data = $command->data;
     $this->assertAdmin($actor);
     $page = Page::build(array_get($data, 'attributes.title'), array_get($data, 'attributes.slug'), array_get($data, 'attributes.content'), array_get($data, 'attributes.isHidden'));
     $this->validator->assertValid($page->getAttributes());
     $page->save();
     return $page;
 }