/** * @param string $tableName * @param DB $db * @param string $sqlQuery The SQL query to get the data for the table * @param string $cssClass The CSS class the HTML table should have * @param bool $displayInfo Displays information of the entries found (on top of the table) * @param int $pageLimit The limit of entries per page */ public function __construct($tableName, DB $db, $sqlQuery, $cssClass = 'table-data', $displayInfo = true, $pageLimit = 25) { $this->selectable = false; $this->tableName = $tableName; $this->orderBy = null; $this->pageLimit = $pageLimit; $this->currentPage = 1; $this->keywords = null; $this->filtersApplied = false; $this->entityWord = 'entry'; $this->entityWordPlural = 'entries'; $this->sqlQuery = StringUtils::beforeLast($sqlQuery, 'ORDER BY'); if (($orderByStr = StringUtils::afterLast($sqlQuery, 'ORDER BY')) !== null) { $res = preg_split('/\\s+/ims', $orderByStr, -1, PREG_SPLIT_NO_EMPTY); $this->orderBy = array('column' => $res[0], 'sort' => isset($res[1]) ? $res[1] : 'ASC'); } $this->columns = null; $this->options = null; $this->db = $db; $this->cssClass = $cssClass; $this->displayInfo = $displayInfo; $this->sortable = null; }
/** * @return HttpResponse * @throws CMSException * @throws HttpException * @throws \Exception */ public function restoreElementAjax() { list($elementType, $elementID, $elementPageID) = explode('-', $this->httpRequest->getVar('module', 'strip_tags')); $revisionFile = $this->httpRequest->getVar('revision', 'strip_tags'); $cmsPage = $this->pageModel->getPageByID($elementPageID); $moduleModel = new ModuleModel($this->db); $modInstance = $moduleModel->getElementInstanceByID($elementID, $cmsPage); try { $this->db->setListenersMute(true); $this->db->beginTransaction(); $revisionControl = new RevisionControl($this->db); $revisionControl->restoreFromFile($revisionFile); $fileNameParts = explode('.', StringUtils::afterLast($revisionFile, '/')); $this->updateElementRevision($modInstance, $fileNameParts[2]); $this->db->commit(); $this->db->setListenersMute(false); } catch (\Exception $e) { $this->db->setListenersMute(false); $this->db->rollBack(); $this->logger->error('Could not restore element ' . $e->getMessage()); return new HttpResponse(500, 'Could not restore element: ' . $e->getMessage()); } // RENDER ELEMENT AGAIN, SEND BACK if ($modInstance instanceof CmsElementSettingsLoadable) { /** @var CmsElement $modInstance */ $moduleModel->reloadSettings($modInstance, $cmsPage); } $referrerPath = StringUtils::beforeFirst($this->httpRequest->getVar('referrer', 'strip_tags'), '?'); $httpRequestFrontend = clone $this->httpRequest; $httpRequestFrontend->setPath($referrerPath); $httpRequestFrontend->setRequestMethod('GET'); $frontendController = new FrontendController($this->core, $httpRequestFrontend, $this->route); $frontendController->deliverCMSPage(); // @TODO render and replace parent module of this one $newModuleHtml = $modInstance->render($frontendController, $this->moduleView); return new HttpResponse(200, $newModuleHtml); }
public function addedChildElement(DB $db, CmsElement $cmsElement, $dropzoneID, $pageID) { $col = StringUtils::afterLast($dropzoneID, 'column-') + 1; $highestCountStmnt = $db->prepare("SELECT MAX(sort) highval FROM element_column_layout_module WHERE col = ?"); $highestCount = $db->select($highestCountStmnt, array($col)); $stmntInsert = $db->prepare("\n\t\t\tINSERT INTO element_column_layout_module\n\t\t\tSET element_column_layout_IDFK = ?, page_IDFK = ?, element_instance_IDFK = ?, col = ?, sort = ?\n\t\t"); $db->insert($stmntInsert, array($this->ID, $pageID, $cmsElement->getID(), $col, $highestCount[0]->highval + 1)); }