/**
  * @param DB $db The database object
  * @param array $modIDs The IDs of the modules for which the settings should be loaded
  * @param array $pageIDs The nested page IDs context
  * @return array The settings found sorted by module IDs
  */
 public static function getSettingsForElements(DB $db, array $modIDs, array $pageIDs)
 {
     $params = array_merge($modIDs, $pageIDs, $pageIDs);
     $stmntSettings = $db->prepare("\n\t\t\tSELECT element_instance_IDFK, page_IDFK, url\n\t\t\tFROM element_iframe\n\t\t\tWHERE element_instance_IDFK IN (" . DB::createInQuery($modIDs) . ")\n\t\t\tAND page_IDFK IN (" . DB::createInQuery($pageIDs) . ")\n\t\t\tORDER BY FIELD(page_IDFK, " . DB::createInQuery($pageIDs) . ")\n\t\t");
     $resSettings = $db->select($stmntSettings, $params);
     $settingsArr = array();
     foreach ($resSettings as $res) {
         $settingsArr[$res->element_instance_IDFK][$res->page_IDFK] = $res;
     }
     return $settingsArr;
 }
Exemple #2
0
 /**
  * @param string $elementIdentifier
  * @param array $settings
  * @param DB $db
  * @param array $modIDs Module IDs to load settings for
  * @param array $pageIDs Page context IDs
  * @param string $elementInstanceColumn
  * @param string $pageInstanceColumn
  * @return array
  */
 public static function loadCmsElementSettings($elementIdentifier, $settings, DB $db, array $modIDs, array $pageIDs, $elementInstanceColumn = 'element_instance_IDFK', $pageInstanceColumn = 'page_IDFK')
 {
     $params = array_merge($modIDs, $pageIDs, $pageIDs);
     $settingsCols = array();
     foreach ($settings as $col => $as) {
         $settingsCols[] = $col . ' ' . $as;
     }
     $stmntSettings = $db->prepare("\n\t\t\tSELECT " . $elementInstanceColumn . ", " . $pageInstanceColumn . ", " . implode(', ', $settingsCols) . "\n\t\t\tFROM " . $elementIdentifier . "\n\t\t\tWHERE " . $elementInstanceColumn . " IN (" . DB::createInQuery($modIDs) . ")\n\t\t\tAND " . $pageInstanceColumn . " IN (" . DB::createInQuery($pageIDs) . ")\n\t\t\tORDER BY FIELD(" . $pageInstanceColumn . ", " . DB::createInQuery($pageIDs) . ")\n\t\t");
     $resSettings = $db->select($stmntSettings, $params);
     $settingsArr = array();
     foreach ($resSettings as $res) {
         $settingsArr[$res->{$elementInstanceColumn}][$res->{$pageInstanceColumn}] = $res;
     }
     return $settingsArr;
 }
 /**
  * @param DB $db The database object
  * @param array $modIDs The IDs of the modules for which the settings should be loaded
  * @param array $pageIDs The nested page IDs context
  * @return array The settings found sorted by module IDs
  */
 public static function getSettingsForElements(DB $db, array $modIDs, array $pageIDs)
 {
     //try {
     /*$pageIds = array(1);*/
     $params = array_merge($modIDs, $pageIDs, $pageIDs);
     $stmntSettings = $db->prepare("\n\t\t\t\tSELECT mod_instance_IDFK, page_IDFK, east_grid_size, center_grid_size, west_grid_size,\n\t\t\t\t\tnorth_mod_IDFK, south_mod_IDFK, east_mod_IDFK, west_mod_IDFK, center_mod_IDFK\n\t\t\t\tFROM mod_border_layout\n\t\t\t\tWHERE mod_instance_IDFK IN (" . DB::createInQuery($modIDs) . ")\n\t\t\t\tAND page_IDFK IN (" . DB::createInQuery($pageIDs) . ")\n\t\t\t\tORDER BY FIELD(page_IDFK, " . DB::createInQuery($pageIDs) . ")\n\t\t\t");
     $resSettings = $db->select($stmntSettings, $params);
     $settingsArr = array();
     foreach ($resSettings as $res) {
         $settingsArr[$res->mod_instance_IDFK][$res->page_IDFK] = $res;
     }
     return $settingsArr;
     /*} catch(\Exception $e) {
     			return false;
     		}*/
 }
 /**
  * @param string $columnSelector
  * @param mixed $selection
  *
  * @return mixed
  */
 public function renderSql($columnSelector, $selection)
 {
     if ($selection === null) {
         return null;
     }
     $not = $this->compareOperator == '!=' ? ' NOT' : null;
     return $columnSelector . $not . ' IN(' . DB::createInQuery($selection) . ')';
 }
 /**
  * @return string[]
  */
 protected function loadCmsRights()
 {
     $rgs = array();
     foreach ($this->loginPopo->rightgroups as $rg) {
         $rgs[] = $rg->rightgroupIDFK;
     }
     $cmsRights = array();
     if (count($rgs) === 0) {
         return $cmsRights;
     }
     // Lade CMS rights
     $stmntRights = $this->db->prepare("\n\t\t\tSELECT cms_right FROM cms_rightgroup_has_right\n\t\t\tWHERE date_from <= NOW() AND (date_to IS NULL OR date_to >= NOW())\n\t\t\tAND rightgroup_IDFK IN (" . DB::createInQuery($rgs) . ")\n\t\t");
     $resRights = $this->db->select($stmntRights, $rgs);
     foreach ($resRights as $r) {
         $cmsRights[] = $r->cms_right;
     }
     return $cmsRights;
 }
 /**
  * @param array $order
  * @param array|null $keyword
  * @param string|null $categories
  *
  * @return File[]
  */
 public function getAllFiles(array $order, $keyword = null, $categories = null)
 {
     $condStr = array();
     $params = array();
     if ($keyword !== null) {
         $condStr[] = 'filename LIKE ?';
         $params[] = '%' . $keyword . '%';
     }
     if ($categories !== null) {
         $condStr[] = 'category IN(' . DB::createInQuery($categories) . ')';
         $params = array_merge($params, $categories);
     }
     $stmntAllFiles = $this->db->prepare("\n\t\t\tSELECT ID, filenamesys, filename, filetype, filesize, send, otherinfo, category\n\t\t\tFROM file\n\t\t\t" . (count($condStr) > 0 ? ' WHERE ' . implode(' AND ', $condStr) : null) . "\n\t\t\tORDER BY " . $order['column'] . " " . $order['sort']);
     $tmpArr = $this->db->select($stmntAllFiles, $params);
     $files = array();
     foreach ($tmpArr as $f) {
         $f->filepath = $this->savePath . $f->filenamesys . DIRECTORY_SEPARATOR . $f->filename;
         $files[] = self::createFileFromData($f);
     }
     return $files;
 }
Exemple #7
0
 public function getCacheModeByPageID(array $pageIDs)
 {
     $stmntCacheModes = $this->db->prepare("\n\t\t\tSELECT ID, cache_mode\n\t\t\tFROM page\n\t\t\tWHERE ID IN (" . DB::createInQuery($pageIDs) . ")\n\t\t");
     $resCacheModes = $this->db->select($stmntCacheModes, $pageIDs);
     $currentCacheMode = 9;
     foreach ($resCacheModes as $cm) {
         if ($currentCacheMode <= $cm->cache_mode) {
             continue;
         }
         $currentCacheMode = $cm->cache_mode;
     }
     return $currentCacheMode;
 }
Exemple #8
0
 /**
  * @param DB $db The database object
  * @param array $modIDs The IDs of the modules for which the settings should be loaded
  * @param array $pageIDs The nested page IDs context
  * @return array The settings found sorted by module IDs and page IDs
  */
 public static function getSettingsForElements(DB $db, array $modIDs, array $pageIDs)
 {
     $params = array_merge($modIDs, $pageIDs, $pageIDs);
     $stmntSettings = $db->prepare("\n\t\t\tSELECT element_instance_IDFK, page_IDFK, navigation_IDFK, level_from, level_to, mode, class_name, show_active_stages_only\n\t\t\tFROM element_nav\n\t\t\tWHERE element_instance_IDFK IN (" . DB::createInQuery($modIDs) . ")\n\t\t\tAND page_IDFK IN (" . DB::createInQuery($pageIDs) . ")\n\t\t\tORDER BY FIELD (page_IDFK, " . DB::createInQuery($pageIDs) . ")\n\t\t");
     $resSettings = $db->select($stmntSettings, $params);
     $settingsArr = array();
     foreach ($resSettings as $res) {
         $settingsArr[$res->element_instance_IDFK][$res->page_IDFK] = $res;
     }
     return $settingsArr;
 }
 public function update(DB $db, \stdClass $newSettings, $pageID)
 {
     $stmntUpdate = $db->prepare("\n\t\t\tINSERT INTO " . $this->identifier . "\n\t\t\t\tSET element_instance_IDFK = ?, page_IDFK = ?, text = ?\n\t\t\tON DUPLICATE KEY\n\t\t\t\tUPDATE text = ?\n\t\t");
     $db->update($stmntUpdate, array($this->ID, $pageID, $newSettings->text, $newSettings->text));
 }
Exemple #10
0
 /**
  * Creates a new element instance and stores its configuration
  * 
  * @param DB $db
  *
  * @return bool
  * @throws CMSException
  * @throws \Exception
  */
 public function create(DB $db)
 {
     try {
         // For default we create the instance in db... has to be overwritten if the module has any settings
         $stmntModID = $db->prepare("SELECT ID FROM cms_element_available WHERE name = ? AND active = 1");
         $resModID = $db->select($stmntModID, array($this->identifier));
         if (count($resModID) <= 0) {
             throw new CMSException('Could not create module with identifier: "' . $this->identifier . '"');
         }
         $stmntCreateInstance = $db->prepare("\n\t\t\t\tINSERT INTO cms_element_instance SET mod_IDFK = ?, parent_mod_IDFK = ?, creator_IDFK = ?, created = NOW(), page_IDFK = ?\n\t\t\t");
         $this->ID = $db->insert($stmntCreateInstance, array($resModID[0]->ID, $this->parentElement !== null ? $this->parentElement->getID() : null, $this->creatorID, $this->pageID));
     } catch (DBException $e) {
         throw new CMSException('Could not create module cause of DB error: ' . $e->getMessage() . ', Query: ' . $e->getQueryString());
     }
     return true;
 }
 /**
  * Deletes the setting of itself for the current page
  * 
  * @param DB $db
  * @param int $pageID
  */
 public function deleteSettingsSelf(DB $db, $pageID)
 {
     $stmntDelete = $db->prepare("DELETE FROM " . $this->identifier . " WHERE element_instance_IDFK = ? AND page_IDFK = ?");
     $db->delete($stmntDelete, array($this->ID, $pageID));
 }
 public function reorderElements(DB $db, CmsElement $movedCmsElement, $dropZoneID, array $elementOrder)
 {
     // Remove all from column
     $colNo = (int) StringUtils::afterFirst($dropZoneID, 'column-') + 1;
     $this->logger->debug('-- Reorder module in column: ' . $colNo);
     $stmntRemove = $db->prepare("\n\t\t\tDELETE FROM element_column_layout_module WHERE col = ? AND page_IDFK = ? AND element_column_layout_IDFK = ?\n\t\t");
     $deletedElements = $db->delete($stmntRemove, array($colNo, $this->pageID, $this->ID));
     $this->logger->debug('Deleted ' . $deletedElements . ' elements');
     // Remove the element itself (cause of PK crashes)
     $stmntRemoveOriginal = $db->prepare("\n\t\t\tDELETE FROM element_column_layout_module WHERE element_column_layout_IDFK = ? AND page_IDFK = ? AND element_instance_IDFK = ?\n\t\t");
     $deletedOriginal = $db->delete($stmntRemoveOriginal, array($this->ID, $movedCmsElement->getPageID(), $movedCmsElement->getID()));
     $this->logger->debug('Deleted ' . $deletedOriginal . ' original element');
     // Add the new order
     $stmntInsert = $db->prepare("\n\t\t\tINSERT IGNORE INTO element_column_layout_module\n\t\t\t\tSET element_column_layout_IDFK = ?, page_IDFK = ?, col = ?, element_instance_IDFK = ?, sort = ?\n\t\t");
     $stmntUpdate = $db->prepare("UPDATE cms_element_instance SET parent_mod_IDFK = ? WHERE ID = ?");
     $this->logger->debug('Add those modules', array($elementOrder));
     foreach ($elementOrder as $k => $e) {
         $this->logger->debug('Added module: ' . $e);
         $eParts = explode('-', $e);
         if (isset($eParts[0]) === false) {
             continue;
         }
         $db->update($stmntUpdate, array($this->ID, $eParts[0]));
         $db->insert($stmntInsert, array($this->ID, $this->pageID, $colNo, $eParts[0], $k + 1));
     }
 }
 /**
  * @param CmsPage $cmsPage
  * @param bool $useCache
  * @return \ArrayObject The element tree for the current page
  */
 private function generateElementTree(CmsPage $cmsPage, $useCache = false)
 {
     // TODO check if any page inheriting from has changed
     $pageIDs = PageModel::getPageIdsRecursive($cmsPage);
     /*if($useCache === true) {
     			$stmntFetchCache = $this->db->prepare("
     				SELECT pc.ID, pc.cached_elements, pc.cache_time
     				FROM page_cache pc
     				LEFT JOIN page p ON p.ID = pc.ID
     				WHERE pc.cache_time >= p.last_modified
     				AND pc.ID IN(" . DB::createInQuery($pageIDs) . ")
     			");
     
     			$resFetchCache = $this->db->select($stmntFetchCache,
     				$pageIDs
     			);
     
     			if(count($resFetchCache) === count($pageIDs)) {
     				foreach($resFetchCache as $fc) {
     					if($fc->ID != $cmsPage->getID())
     						continue;
     
     					return unserialize($fc->cached_elements);
     				}
     			}
     		}*/
     /*$stmntElements = $this->db->prepare("
     			SELECT ei.ID, ei.mod_IDFK element_ID, ei.page_IDFK page_ID, parent_mod_IDFK parent_element_ID, ea.class, ea.name, ei.revision,
     			IF(ih.element_instance_IDFK IS NULL, 0, 1) hidden
     			FROM cms_element_instance ei
     			LEFT JOIN cms_element_available ea ON ea.ID = ei.mod_IDFK
     			LEFT JOIN cms_element_instance_hidden ih ON ih.element_instance_IDFK = ei.ID AND ih.page_IDFK = ?
     			WHERE ei.page_IDFK IN (" . DB::createInQuery($pageIDs) . ")
     			AND ea.active = 1
     		");
     
     		$resElements = $this->db->select($stmntElements,
     			array_merge(array($cmsPage->getID()), $pageIDs)
     		);*/
     $stmntElements = $this->db->prepare("\n\t\t\tSELECT ei.ID, ei.mod_IDFK element_ID, ei.page_IDFK page_ID, parent_mod_IDFK parent_element_ID, ea.class, ea.name, ei.revision,\n\t\t\tIF(ih.element_instance_IDFK IS NULL, 0, 1) hidden\n\t\t\tFROM cms_element_instance ei\n\t\t\tLEFT JOIN cms_element_available ea ON ea.ID = ei.mod_IDFK\n\t\t\tLEFT JOIN cms_element_instance_hidden ih ON ih.element_instance_IDFK = ei.ID AND ih.page_IDFK IN (" . DB::createInQuery($pageIDs) . ")\n\t\t\tWHERE ei.page_IDFK IN (" . DB::createInQuery($pageIDs) . ")\n\t\t\tAND ea.active = 1\n\t\t");
     $resElements = $this->db->select($stmntElements, array_merge($pageIDs, $pageIDs));
     // Settings und co
     $elementTypes = array();
     $elementInstances = array();
     foreach ($resElements as $e) {
         /** @var CmsElement $elementInstance */
         $elementInstance = new $e->class($e->ID, $e->page_ID, $e->name);
         if ($e->revision !== null) {
             $elementInstance->setRevision($e->revision);
         }
         $elementInstance->setHidden($e->hidden == 1);
         $elementInstances[$e->ID] = $elementInstance;
         $elementTypes[$e->class][] = $e->ID;
     }
     // Load settings for modules
     foreach ($elementTypes as $class => $modIDs) {
         $refClass = new \ReflectionClass($class);
         if ($refClass->isSubclassOf('ch\\metanet\\cms\\common\\CmsElementSettingsLoadable') === false) {
             continue;
         }
         /** @var CmsElementSettingsLoadable $class */
         $settings = $class::getSettingsForElements($this->db, $modIDs, $pageIDs);
         foreach ($settings as $key => $settingEntries) {
             $settingsEntry = $this->combineSettings($settingEntries);
             $elementInstances[$key]->setSettings($settingsEntry);
         }
     }
     $cachedTree = new \ArrayObject($this->createTree($resElements, $elementInstances));
     if ($useCache === true) {
         $cachedTreeSerialized = serialize($cachedTree);
         try {
             $stmntCacheElements = $this->db->prepare("\n\t\t\t\t\tINSERT INTO page_cache SET\n\t\t\t\t\t\tID = ?, cached_elements = ?, cache_time = NOW()\n\t\t\t\t\tON DUPLICATE KEY UPDATE\n\t\t\t\t\t\tcached_elements = ?, cache_time = NOW()\n\t\t\t\t");
             $this->db->insert($stmntCacheElements, array($cmsPage->getID(), $cachedTreeSerialized, $cachedTreeSerialized));
         } catch (\Exception $e) {
             // Cache could not be saved
         }
     }
     return $cachedTree;
 }
 private function getPKColumnsForTable(DB $db, $tableName)
 {
     $stmntPK = $db->prepare("\n\t\t\t\tSELECT k.COLUMN_NAME\n\t\t\t\tFROM information_schema.table_constraints t\n\t\t\t\tLEFT JOIN information_schema.key_column_usage k\n\t\t\t\tUSING(constraint_name, table_schema, table_name)\n\t\t\t\tWHERE t.constraint_type = 'PRIMARY KEY'\n\t\t\t\tAND t.table_schema = DATABASE()\n\t\t\t\tAND t.table_name= ?\n\t\t\t");
     $resPK = $db->select($stmntPK, array($tableName));
     $pkArray = array();
     foreach ($resPK as $pk) {
         $pkArray[] = $pk->COLUMN_NAME;
     }
     return $pkArray;
 }