namespace wcf\acp\form;
use wcf\data\application\Application;
use wcf\data\application\ApplicationList;
+use wcf\data\box\Box;
+use wcf\data\box\BoxList;
use wcf\data\page\Page;
use wcf\data\page\PageAction;
use wcf\data\page\PageEditor;
*/
public $availableApplications = [];
+ /**
+ * list of available boxes
+ * @var Box[]
+ */
+ public $availableBoxes = [];
+
/**
* page custom URL
* @var string[]
*/
public $metaKeywords = [];
+ /**
+ * list of box ids
+ * @var integer[]
+ */
+ public $boxIDs = [];
+
/**
* @inheritDoc
*/
$applicationList = new ApplicationList();
$applicationList->readObjects();
$this->availableApplications = $applicationList->getObjects();
+
+ // get boxes
+ $boxList = new BoxList();
+ $boxList->sqlOrderBy = 'box.name';
+ $boxList->readObjects();
+ $this->availableBoxes = $boxList->getObjects();
}
/**
if (isset($_POST['content']) && is_array($_POST['content'])) $this->content = ArrayUtil::trim($_POST['content']);
if (isset($_POST['metaDescription']) && is_array($_POST['metaDescription'])) $this->metaDescription = ArrayUtil::trim($_POST['metaDescription']);
if (isset($_POST['metaKeywords']) && is_array($_POST['metaKeywords'])) $this->metaKeywords = ArrayUtil::trim($_POST['metaKeywords']);
+ if (isset($_POST['boxIDs']) && is_array($_POST['boxIDs'])) $this->boxIDs = ArrayUtil::toIntegerArray($_POST['boxIDs']);
}
/**
$this->validateController();
$this->validateCustomUrl();
+
+ $this->validateBoxIDs();
}
/**
}
}
+ /**
+ * Validates box ids.
+ */
+ protected function validateBoxIDs() {
+ foreach ($this->boxIDs as $boxID) {
+ if (!isset($this->availableBoxes[$boxID])) {
+ throw new UserInputException('boxIDs');
+ }
+ }
+ }
+
+ /**
+ * Prepares box to page assignments
+ *
+ * @return mixed[]
+ */
+ protected function getBoxToPage() {
+ $boxToPage = [];
+ foreach ($this->availableBoxes as $box) {
+ if ($box->visibleEverywhere) {
+ if (!in_array($box->boxID, $this->boxIDs)) {
+ $boxToPage[] = [
+ 'boxID' => $box->boxID,
+ 'visible' => 0
+ ];
+ }
+ }
+ else {
+ if (in_array($box->boxID, $this->boxIDs)) {
+ $boxToPage[] = [
+ 'boxID' => $box->boxID,
+ 'visible' => 1
+ ];
+ }
+ }
+ }
+
+ return $boxToPage;
+ }
+
/**
* @inheritDoc
*/
public function save() {
parent::save();
+ // prepare page content
$content = [];
if ($this->isMultilingual) {
foreach (LanguageFactory::getInstance()->getLanguages() as $language) {
'isMultilingual' => $this->isMultilingual,
'identifier' => '',
'controller' => $this->controller
- ]), 'content' => $content]);
+ ]), 'content' => $content, 'boxToPage' => $this->getBoxToPage()]);
/** @var Page $page */
$page = $this->objectAction->executeAction()['returnValues'];
$this->customURL = $this->title = $this->content = $this->metaDescription = $this->metaKeywords = [];
}
+ /**
+ * @inheritDoc
+ */
+ public function readData() {
+ parent::readData();
+
+ // set default values
+ if (empty($_POST)) {
+ foreach ($this->availableBoxes as $box) {
+ if ($box->visibleEverywhere) $this->boxIDs[] = $box->boxID;
+ }
+ }
+ }
+
/**
* @inheritDoc
*/
'content' => $this->content,
'metaDescription' => $this->metaDescription,
'metaKeywords' => $this->metaKeywords,
+ 'boxIDs' => $this->boxIDs,
'availableApplications' => $this->availableApplications,
'availableLanguages' => LanguageFactory::getInstance()->getLanguages(),
'availablePageTypes' => $availablePageTypes,
+ 'availableBoxes' => $this->availableBoxes,
'pageNodeList' => (new PageNodeTree())->getNodeList()
]);
}
);
}
- $this->objectAction = new PageAction(array($this->page), 'update', array('data' => array_merge($this->additionalFields, $data), 'content' => $content));
+ $this->objectAction = new PageAction(array($this->page), 'update', array('data' => array_merge($this->additionalFields, $data), 'content' => $content, 'boxToPage' => $this->getBoxToPage()));
$this->objectAction->executeAction();
}
$this->metaKeywords[$languageID] = $content['metaKeywords'];
$this->customURL[$languageID] = $content['customURL'];
}
+
+ $this->boxIDs = [];
+ foreach ($this->availableBoxes as $box) {
+ if ($box->visibleEverywhere) {
+ if (!in_array($box->boxID, $this->page->getBoxIDs())) {
+ $this->boxIDs[] = $box->boxID;
+ }
+ }
+ else {
+ if (in_array($box->boxID, $this->page->getBoxIDs())) {
+ $this->boxIDs[] = $box->boxID;
+ }
+ }
+ }
}
}
}
}
+ // save box to page assignments
+ if (!empty($this->parameters['boxToPage'])) {
+ $sql = "INSERT INTO wcf".WCF_N."_box_to_page
+ (boxID, pageID, visible)
+ VALUES (?, ?, ?)";
+ $statement = WCF::getDB()->prepareStatement($sql);
+
+ foreach ($this->parameters['boxToPage'] as $boxData) {
+ $statement->execute([
+ $boxData['boxID'],
+ $page->pageID,
+ $boxData['visible']
+ ]);
+ }
+ }
+
return $page;
}
}
}
}
+
+ // save box to page assignments
+ if (!empty($this->parameters['boxToPage'])) {
+ $sql = "DELETE FROM wcf".WCF_N."_box_to_page
+ WHERE pageID = ?";
+ $deleteStatement = WCF::getDB()->prepareStatement($sql);
+
+ $sql = "INSERT INTO wcf".WCF_N."_box_to_page
+ (boxID, pageID, visible)
+ VALUES (?, ?, ?)";
+ $insertStatement = WCF::getDB()->prepareStatement($sql);
+
+ foreach ($this->objects as $page) {
+ $deleteStatement->execute([$page->pageID]);
+
+ foreach ($this->parameters['boxToPage'] as $boxData) {
+ $insertStatement->execute([
+ $boxData['boxID'],
+ $page->pageID,
+ $boxData['visible']
+ ]);
+ }
+ }
+ }
}
/**