/** * createPageDocument * * @param string $pageId page instance id * @param string $pageTitle page title * @param string $locale locale * * @return string * @throws \Exception */ public function createPageDocument($pageId, $pageTitle, $locale) { $doc = new Document(); $doc->instanceId = $pageId; $doc->type = PageModule::getId(); $doc->title = $pageTitle; $doc->locale = $locale; /** @var UserInterface $user */ $user = $this->auth->user(); $doc->writer = $user->getDisplayName(); $doc->user()->associate($user); $doc->format = Document::FORMAT_HTML; XeDB::beginTransaction(); try { $this->document->put($doc); } catch (\Exception $e) { XeDB::rollback(); throw $e; } XeDB::commit(); return $doc->id; }
/** * create file * * @param string $content file content * @param string $path directory for saved * @param string $name saved name * @param string|null $disk disk for saved * @param string|null $originId original file id * @param UserInterface $user user instance * @return File */ public function create($content, $path, $name, $disk = null, $originId = null, UserInterface $user = null) { $id = $this->keygen->generate(); $path = $this->makePath($id, $path); $tempFile = $this->tempFiles->create($content); $disk = $disk ?: $this->distributor->allot($tempFile); $user = $user ?: $this->auth->user(); if (!$this->files->store($content, $path . '/' . $name, $disk)) { throw new WritingFailException(); } $file = $this->createModel(); $file->id = $id; $file->userId = $user->getId(); $file->disk = $disk; $file->path = $path; $file->filename = $name; $file->clientname = $name; $file->mime = $tempFile->getMimeType(); $file->size = $tempFile->getSize(); if ($originId !== null) { $file->originId = $originId; } $file->save(); $tempFile->destroy(); return $file; }
/** * create * * @param string $widgetId widget id * @param array $args to create widget html arguments * * @return mixed * @throws Exception */ public function render($widgetId, $args = []) { $currentUserRating = $this->guard->user()->getRating(); try { $instance = $this->getInstance($widgetId, $args); if (in_array($currentUserRating, $instance::$ratingWhiteList)) { $ret = $instance->render(); 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 ''; } } }