Beispiel #1
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;
 }
Beispiel #2
0
 protected function getChildElements(CmsElement $element, \ArrayObject $elementInstances)
 {
     $childElements = array();
     foreach ($elementInstances as $m) {
         /** @var CmsElement $m */
         if ($m->getParentElementID() != $element->getID()) {
             continue;
         }
         if ($m instanceof LayoutElement) {
             $m->setElements($this->getChildElements($m, $elementInstances));
         }
         $childElements[$m->getID()] = $m;
     }
     return $childElements;
 }
 /**
  * @param CmsElement $cmsElement
  * @param string $revision
  */
 private function updateElementRevision(CmsElement $cmsElement, $revision)
 {
     $stmntSetRev = $this->db->prepare("\n\t\t\tUPDATE cms_element_instance\n\t\t\tSET revision = ?\n\t\t\tWHERE ID = ? AND page_IDFK = ?\n\t\t");
     $this->db->update($stmntSetRev, array($revision, $cmsElement->getID(), $cmsElement->getPageID()));
 }
 public function __construct($ID, $pageID)
 {
     parent::__construct($ID, $pageID, 'element_display_mod');
 }
 public function __construct($ID, $pageID)
 {
     parent::__construct($ID, $pageID, 'element_sitetitle');
 }
 /**
  * @param DB $db
  */
 public function remove(DB $db)
 {
     $stmntRemoveElementSettings = $db->prepare("DELETE FROM " . $this->identifier . " WHERE element_instance_IDFK = ?");
     $db->delete($stmntRemoveElementSettings, array($this->ID));
     parent::remove($db);
 }
 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));
     }
 }
 protected static function getSettingsAsStr(CmsElement $mod)
 {
     if ($mod instanceof CmsElementSettingsLoadable === false) {
         return '(no settings)';
     }
     /** @var CmsElementSettingsLoadable $mod */
     if ($mod->hasSettings() === false) {
         return '(no settings found)';
     }
     $settingsStr = '';
     foreach ($mod->getSettings() as $k => $v) {
         if (in_array($k, array('mod_instance_IDFK'))) {
             continue;
         }
         $value = htmlentities(strip_tags(print_r($v, true)));
         $value = strlen($value) > 254 ? substr($value, 0, 254) . ' [...]' : $value;
         $settingsStr .= $k . ': ' . $value . "\n";
     }
     return $settingsStr;
 }
Beispiel #9
0
 /**
  * @param array $elements
  * @param array $elementInstances
  * @param CmsElement|null $parentElement
  * @return array The elements for the current parent element
  */
 private function createTree(array $elements, array $elementInstances, $parentElement = null)
 {
     $elementTree = array();
     foreach ($elements as $e) {
         // Not interesting yet
         if ($parentElement == null && $e->parent_element_ID != null || $parentElement != null && $e->parent_element_ID != $parentElement->getID()) {
             continue;
         }
         /** @var CmsElement $elementInstance */
         $elementInstance = $elementInstances[$e->ID];
         if ($parentElement !== null) {
             $elementInstance->setParentElement($parentElement);
         }
         $elementInstance->setParentElementID($parentElement != null ? $parentElement->getID() : null);
         if ($elementInstance instanceof LayoutElement) {
             /** @var LayoutElement $elementInstance */
             $subElementTree = $this->createTree($elements, $elementInstances, $elementInstance);
             $elementInstance->setElements($subElementTree);
         }
         $elementTree[$e->ID] = $elementInstance;
     }
     return $elementTree;
 }