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); } } }