Exemplo n.º 1
0
 private function saveData(Text $text, Request $request, Document $document, DocumentRepository $documentRepo)
 {
     if (!$request->hasRequestValue("intro") || !$request->hasRequestValue("title")) {
         return;
     }
     if ($document->isForWidgetArea()) {
         $text->addError($text->t("main.document") . ' ' . $text->t("errors.not_editable"));
         return;
     }
     $document->setIntro($request->getRequestString("intro", ''));
     $document->setTitle($request->getRequestString("title", ''));
     $valid = true;
     if (!Validate::requestToken($request)) {
         $valid = false;
     }
     if (!Validate::stringLength($document->getIntro(), Document::INTRO_MIN_LENGTH, Document::INTRO_MAX_LENGTH)) {
         $text->addError($text->t("documents.intro") . ' ' . Validate::getLastError($text));
         $valid = false;
     }
     if (!Validate::stringLength($document->getTitle(), Document::TITLE_MIN_LENGTH, Document::TITLE_MAX_LENGTH)) {
         $text->addError($text->t("documents.title") . ' ' . Validate::getLastError($text));
         $valid = false;
     }
     if (!$valid) {
         return;
     }
     $isNew = $document->getId() == 0;
     $documentRepo->saveDocument($document);
     if ($isNew) {
         $text->addMessage($text->t("main.document") . ' ' . $text->t("editor.is_created"));
     } else {
         $text->addMessage($text->t("main.document") . ' ' . $text->t("editor.is_edited"));
     }
 }
Exemplo n.º 2
0
 /**
  * Creates a document with the id, title and intro customized for the widget
  * area. (The id of the widget area is equal to the id of the document.)
  * @param InstalledWidgets $installedWidgets The installed widgets object.
  * @param Text $text The text object, for populating the intro field.
  * @param int $widgetArea Id of the widget area and document.
  * @return Document The document.
  * @throws NotFoundException If the theme supports no widget area with the
  * given number.
  */
 public static function createForWidgetArea(InstalledWidgets $installedWidgets, Text $text, $widgetArea)
 {
     $widgetAreas = $installedWidgets->getWidgetAreas();
     if (!isset($widgetAreas[$widgetArea])) {
         throw new NotFoundException();
     }
     // This is a valid widget area, so create a document for it
     $title = $widgetAreas[$widgetArea];
     if (strLen($title) > self::TITLE_MAX_LENGTH) {
         $title = subStr($title, 0, self::TITLE_MAX_LENGTH);
     }
     $intro = $text->tReplaced("documents.created_for_widgets", $title);
     $document = new Document();
     $document->isWidgetArea = true;
     $document->id = (int) $widgetArea;
     $document->setTitle(ucFirst($title));
     $document->setIntro($intro);
     return $document;
 }