public static function getElements($varName, $intParentId, $blnGetOne = FALSE, $blnRecursive = FALSE) { $objCms = PCMS_Client::getInstance(); if (!is_array($varName)) { if (empty($varName)) { $varName = array(); } else { $varName = explode(",", $varName); } } $strSql = "SELECT pcms_element.* FROM pcms_element, pcms_element_schedule\n\t\t\t\t\t\tWHERE pcms_element.parentId = '%s'\n\t\t\t\t\t\tAND pcms_element.active = '1' "; $strSql .= count($varName) > 1 || count($varName) > 0 && !empty($varName[0]) ? "AND pcms_element.apiName IN ('%s') " : ""; $strSql .= "AND pcms_element.accountId = '%s'\n\t\t\t\t\t\tAND pcms_element.id IN (SELECT elementId FROM pcms_element_language\n\t\t\t\t\t\t\tWHERE languageId = '%s'\n\t\t\t\t\t\t\tAND active = '1')\n\t\t\t\t\t\tAND pcms_element.id = pcms_element_schedule.elementId\n\t\t\t\t\t\tAND pcms_element_schedule.startDate <= '%s'\n\t\t\t\t\t\tAND pcms_element_schedule.endDate >= '%s'\n\t\t\t\t\t\tORDER BY pcms_element.sort"; if (count($varName) > 1 || count($varName) > 0 && !empty($varName[0])) { $strSql = sprintf($strSql, $intParentId, implode("','", $varName), PCMS_Client::getAccount()->getId(), $objCms->getLanguage()->getId(), self::toMysql(), self::toMysql()); } else { $strSql = sprintf($strSql, $intParentId, PCMS_Client::getAccount()->getId(), $objCms->getLanguage()->getId(), self::toMysql(), self::toMysql()); } $objElements = Element::select($strSql); if ($blnGetOne) { if ($objElements->count() > 0) { $objElement = new __Element($objElements->current()); return $objElement; } else { $objReturn = NULL; } } else { $objReturn = new __Elements(); } foreach ($objElements as $objElement) { $objReturn->addObject(new __Element($objElement)); if ($blnRecursive === TRUE) { $objChilds = __Elements::getElements($varName, $objElement->getId(), $blnGetOne, $blnRecursive); if ($blnGetOne) { if (is_object($objChilds->getElement())) { return $objChilds; } } else { foreach ($objChilds as $objChild) { $objReturn->addObject($objChild); } } } } //*** Find elements recursivly that are no direct child elements. if ($blnRecursive === TRUE) { $strSql = "SELECT pcms_element.* FROM pcms_element, pcms_element_schedule\n\t\t\t\t\tWHERE pcms_element.parentId = '%s'\n\t\t\t\t\tAND pcms_element.active = '1'\n\t\t\t\t\tAND pcms_element.apiName NOT IN ('%s')\n\t\t\t\t\tAND pcms_element.accountId = '%s'\n\t\t\t\t\tAND pcms_element.id = pcms_element_schedule.elementId\n\t\t\t\t\tAND pcms_element_schedule.startDate <= '%s'\n\t\t\t\t\tAND pcms_element_schedule.endDate >= '%s'\n\t\t\t\t\tORDER BY pcms_element.sort"; $objElements = Element::select(sprintf($strSql, $intParentId, implode("','", $varName), PCMS_Client::getAccount()->getId(), self::toMysql(), self::toMysql())); foreach ($objElements as $objElement) { $objChilds = __Elements::getElements($varName, $objElement->getId(), $blnGetOne, $blnRecursive); if (is_object($objChilds)) { if ($blnGetOne) { return $objChilds; } else { foreach ($objChilds as $objChild) { $objReturn->addObject($objChild); } } } } } return $objReturn; }
public function addConditions(__Element &$objSubject) { $objConditions = $objSubject->getElementsByTemplate("Condition"); foreach ($objConditions as $objCondition) { try { $strProperty = $objCondition->getField("Property")->getHtmlValue(); $strValue = $objCondition->getField("Value")->getHtmlValue(); $blnValue = $strValue == "true" ? true : false; $strConstValue = $objCondition->getField("Type")->getHtmlValue(); if (defined($strConstValue)) { $constType = constant($strConstValue); } else { throw new Exception("Tried to get undefined constant '{$strConstValue}'. From element {$objCondition->getId()}", E_ERROR); } $arrComparisons = array(); $objCmsComparisons = $objCondition->getElementsByTemplate("Comparison"); foreach ($objCmsComparisons as $objCmsComparison) { $objComparisonSubject = $objCmsComparison->getField("Subject")->getElement(); if (is_object($objComparisonSubject)) { $objComparisonSubjectElement = $this->getFormElementById($objComparisonSubject->getId()); //*** Get the comparison's value $varValue = $objCmsComparison->getField("Value")->getHtmlValue(); $objValue = $objCmsComparison->getField("Value")->getElement(); if (is_object($objValue) && $objValue->getTemplateName() == "ListOption") { // If the comparison's value is a deeplink to a list option, overwrite $varValue $varValue = $objValue->getField("Value")->getHtmlValue(); } array_push($arrComparisons, new VF_Comparison($objComparisonSubjectElement, constant($objCmsComparison->getField("Comparison")->getHtmlValue()), $varValue)); } else { throw new Exception("Failed to load comparison: {$objCmsComparison->getId()}", E_ERROR); } } $objFormSubject = $this->getFormElementById($objSubject->getId()); if (is_object($objFormSubject)) { $objFormSubject->addCondition($strProperty, $blnValue, $arrComparisons, $constType); } } catch (Exception $e) { throw new Exception("Failed to add condition to field {$objSubject->getId()}. Error: " . $e->getMessage(), 1); } } }