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 new placed widget. Won't be saved automatically, save it to a
  * widget repository.
  * @param string $baseDirectory Base directory of all widgets.
  * @param string $dirName Name of the widget.
  * @param Document $document The document the widget is placed in.
  * @return PlacedWidget The placed widget.
  * @throws NotFoundException If no widget exists with the given dirName.
  */
 public static function newPlacedWidget($baseDirectory, $dirName, Document $document)
 {
     $placedWidget = new PlacedWidget($baseDirectory);
     $placedWidget->setDocumentId($document->getId());
     $placedWidget->widgetName = (string) $dirName;
     $placedWidget->id = 0;
     if (!file_exists($placedWidget->getWidgetCodeFile())) {
         throw new NotFoundException();
     }
     return $placedWidget;
 }
Exemplo n.º 3
0
    private function getDocumentEditLinks(Document $document)
    {
        if (!$this->editLinks) {
            return "";
        }
        $text = $this->text;
        return <<<HTML
            <a class="arrow" href="{$text->e($text->getUrlPage("edit_document", $document->getId()))}">
                {$text->t("main.edit")}
            </a>
            <a class="arrow" href="{$text->e($text->getUrlPage("delete_document", $document->getId()))}">
                {$text->t("main.delete")}
            </a>
HTML;
    }
Exemplo n.º 4
0
 /**
  * Deletes a document from the database.
  * @param Document $document The document to delete.
  * @throws NotFoundException If the document was already deleted or never saved.
  * @throws PDOException If a database error occurs.
  */
 public function deleteDocument(Document $document, WidgetRepository $widgetRepo)
 {
     $this->where($this->primaryField, '=', $document->getId())->deleteOneOrFail();
     $widgetRepo->deleteAllPlacedWidgetsInDocument($document->getId());
 }