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); }
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); }
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(); }
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); } } }