Example #1
0
 public function init(Website $website, Request $request)
 {
     $this->installedWidgets = $website->getWidgets();
     $widgetRepo = new WidgetRepository($website);
     $widgetId = $request->getParamInt(0);
     if ($widgetId === 0) {
         // New widget
         $this->placedWidget = $this->getNewWidget($website, $request);
     } else {
         $this->placedWidget = $widgetRepo->getPlacedWidget($widgetId);
     }
     if ($request->hasRequestValue("submit") && Validate::requestToken($request)) {
         // Use incoming data
         $widgetDefinition = $this->installedWidgets->getDefinition($this->placedWidget);
         $data = $widgetDefinition->parseData($website, $widgetId);
         $this->placedWidget->setData($data);
         if ($this->isValid($data)) {
             // Save widget
             $widgetRepo->savePlacedWidget($this->placedWidget);
             $this->addSaveMessage($this->placedWidget, $website->getText());
         }
     }
     $this->requestToken = RequestToken::generateNew();
     $this->requestToken->saveToSession();
 }
Example #2
0
 public function init(Website $website, Request $request)
 {
     $this->installedWidgets = $website->getWidgets();
     $this->siteTitle = $website->getConfig()->get(Config::OPTION_SITE_TITLE);
     $widgetsRepo = new WidgetRepository($website);
     $this->widgets = $widgetsRepo->getWidgetsInDocumentWithId(self::DOCUMENT_ID);
     $this->editLinks = $website->isLoggedInAsStaff(true);
 }
Example #3
0
 public function init(Website $website, Request $request)
 {
     $isStaff = $website->isLoggedInAsStaff();
     $id = $request->getParamInt(0);
     $this->editLinks = $website->isLoggedInAsStaff(true);
     // Load document
     $documentRepo = new DocumentRepository($website->getDatabase(), $isStaff);
     $this->document = $documentRepo->getDocument($id);
     // Load document widgets
     $this->widgetLoader = $website->getWidgets();
     $widgetRepo = new WidgetRepository($website);
     $this->widgets = $widgetRepo->getWidgetsInDocumentWithId($id);
 }
Example #4
0
 public function init(Website $website, Request $request)
 {
     $this->installedWidgets = $website->getWidgets();
     $widgetId = $request->getParamInt(0, 0);
     $widgetRepo = new WidgetRepository($website);
     $this->placedWidget = $widgetRepo->getPlacedWidget($widgetId);
     if (Validate::requestToken($request)) {
         $widgetRepo->deletePlacedWidget($this->placedWidget);
         $text = $website->getText();
         $text->addMessage($text->t("main.widget") . ' ' . $text->t("editor.is_deleted"), Link::of($text->getUrlPage("edit_document", $this->placedWidget->getDocumentId()), $text->t("main.ok")));
     } else {
         $this->requestToken = RequestToken::generateNew();
         $this->requestToken->saveToSession();
     }
 }
Example #5
0
 public function init(Website $website, Request $request)
 {
     $id = $request->getParamInt(0, 0);
     // Load document
     $documentRepo = new DocumentRepository($website->getDatabase(), true);
     $user = $website->getAuth()->getCurrentUser();
     // ^ this is never null, as the required rank for this page is moderator
     $this->document = $this->retrieveDocument($website, $documentRepo, $id, $user);
     // Load document widgets
     $this->widgetLoader = $website->getWidgets();
     $widgetRepo = new WidgetRepository($website);
     $this->widgets = $widgetRepo->getWidgetsInDocumentWithId($id);
     // Check for edits
     $this->saveData($website->getText(), $request, $this->document, $documentRepo);
     // Store new request token
     $this->requestToken = RequestToken::generateNew();
     $this->requestToken->saveToSession();
 }
Example #6
0
 private function moveWidget(WidgetRepository $repo, $moveUp)
 {
     $delta = $moveUp ? -1 : 1;
     $documentId = $this->placedWidget->getDocumentId();
     $allWidgetsInDocument = array_values($repo->getWidgetsInDocumentWithId($documentId));
     $iterationStartPos = $moveUp ? 1 : 0;
     $iterationEndPos = $moveUp ? count($allWidgetsInDocument) : count($allWidgetsInDocument) - 1;
     $madeChanges = false;
     for ($i = $iterationStartPos; $i < $iterationEndPos; $i++) {
         $placedWidget = $allWidgetsInDocument[$i];
         if ($this->placedWidget->getId() == $placedWidget->getId()) {
             // Swap
             // Moving up:   place widget above here, then place desired
             //              widget in the (now free) slot above
             // Moving down: place widget below here, then place desired
             //              widget in the (now free) slot below
             $allWidgetsInDocument[$i] = $allWidgetsInDocument[$i + $delta];
             $allWidgetsInDocument[$i + $delta] = $this->placedWidget;
             $madeChanges = true;
             break;
         }
     }
     if ($madeChanges) {
         for ($i = 0; $i < count($allWidgetsInDocument); $i++) {
             $placedWidget = $allWidgetsInDocument[$i];
             $placedWidget->setPriority(count($allWidgetsInDocument) - $i);
             $repo->savePlacedWidget($placedWidget);
         }
     }
 }
Example #7
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());
 }