public function children(Request $request, $id) { if ($request->get('id') === null) { $children = Category::find($id)->getProgenitors(); } else { /** @var CategoryItem $item */ if (!($item = CategoryItem::find($request->get('id')))) { throw new InvalidArgumentHttpException(); } $children = $item->getChildren(); } foreach ($children as $child) { $child->readableWord = xe_trans($child->word); } return XePresenter::makeApi($children->toArray()); }
/** * Convert the model instance to an array. * * @return array */ public function toArray() { return array_merge(parent::toArray(), ['items' => $this->getChildren()]); }
/** * 미리보기 * * @param Request $request request * @param Validator $validator validator * @param BoardPermissionHandler $boardPermission board permission handler * @return mixed */ public function preview(Request $request, Validator $validator, BoardPermissionHandler $boardPermission) { if (Gate::denies(BoardPermissionHandler::ACTION_CREATE, new Instance($boardPermission->name($this->instanceId)))) { throw new AccessDeniedHttpException(); } /** @var UserInterface $user */ $user = Auth::user(); // get rules $this->validate($request, $validator->getCreateRule($user, $this->config)); $content = $request->originAll()['content']; $title = htmlspecialchars($request->originAll()['title'], ENT_COMPAT | ENT_HTML401, 'UTF-8', false); $writer = $user->getDisplayName(); if ($request->get('writer', '') !== '') { $writer = $request->get('writer'); } if ($this->config->get('anonymity') === true) { $writer = $this->config->get('anonymityName'); } if ($request->get('categoryItemId', '') !== '') { } $showCategoryItem = null; if ($request->get('categoryItemId', '') !== '') { $showCategoryItem = CategoryItem::find($request->get('categoryItemId')); } /** @var \Xpressengine\Editor\AbstractEditor $editor */ $editor = XeEditor::get($this->instanceId); $format = $editor->htmlable() ? Board::FORMAT_HTML : Board::FORMAT_NONE; return XePresenter::make('preview', ['config' => $this->config, 'handler' => $this->handler, 'currentDate' => date('Y-m-d H:i:s'), 'title' => $title, 'content' => $content, 'writer' => $writer, 'format' => $format, 'showCategoryItem' => $showCategoryItem]); }
/** * @param string $name * @param array $args */ public function output($name, array $args) { $key = $name . 'ItemId'; if (isset($args[$key]) === false || $args[$key] == '') { return null; } return xe_trans(CategoryItem::find($args[$key])->word); }
/** * Move to another parent CategoryItem * * @param CategoryItem $item item object * @param CategoryItem $parent new parent item object * @return CategoryItem * @throws UnableMoveToSelfException */ public function moveTo(CategoryItem $item, CategoryItem $parent = null) { $oldParent = $item->getParent(); if ($parent !== null) { if ($item->getKey() === $parent->getKey()) { throw new UnableMoveToSelfException(); } if ($oldParent !== null && $oldParent->getKey() == $parent->getKey()) { return; } } if ($oldParent !== null) { $this->unlinkHierarchy($item, $oldParent); $item->{$item->getParentIdName()} = null; } if ($parent !== null) { $this->linkHierarchy($item, $parent); $item->{$item->getParentIdName()} = $parent->getKey(); } $item->save(); // 연관 객체 정보들이 변경 되었으므로 객채를 갱신 함 return $item->newQuery()->find($item->getKey()); }