/** * 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; }
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; }
/** * 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()); }
private function retrieveDocument(Website $website, DocumentRepository $documentRepo, $id, User $user) { if ($id === 0) { // New document return Document::createNew("", "", $user); } return $documentRepo->getDocumentOrWidgetArea($website->getWidgets(), $website->getText(), $id); }
public function testInvalidIntroInConstructor() { $invalidIntro = str_repeat("t", Document::INTRO_MAX_LENGTH + 1); $document = Document::createNew("Test Title", $invalidIntro, $this->getTestUser()); $this->assertFalse(Document::isValidIntro($document->getIntro())); }
/** * 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; }