protected function doTestContentFieldValueComposed($oSubContent) { $sUser = $oSubContent->getContentFieldValue(self::FIELD_USER); $sPassword = $oSubContent->getContentFieldValue(self::FIELD_PASSWORD); $sHost = $oSubContent->getContentFieldValue(self::FIELD_HOST); $sDatabase = $oSubContent->getContentFieldValue(self::FIELD_DATABASE); $sPrefix = $oSubContent->getContentFieldValue(self::FIELD_PREFIX); try { $oDbLinkTest = AnwMysql::getInstance($sUser, $sPassword, $sHost, $sDatabase, $sPrefix); } catch (AnwDbConnectException $e) { $sError = AnwComponent::g_editcontent("err_contentfield_mysqlconnexion_dbconnect", array("details" => $e->getMessage())); throw new AnwInvalidContentFieldValueException($sError); } //print "<br/>Test::user={$sUser}, pwd={$sPassword}, db={$sDatabase}, host={$sHost}, prefix={$sPrefix}<br/>"; }
function getMultiplicityTip($oContentField) { $sTranslation = $oContentField->getFieldLabelPlural(); if ($this->nMin > 0 && $this->nMax < self::UNLIMITED) { if ($this->nMin == $this->nMax) { return AnwComponent::g_editcontent("contentmultiplicity_multiple_tip_fixed", array("count" => $this->nMin, "contentfield" => $sTranslation)); } return AnwComponent::g_editcontent("contentmultiplicity_multiple_tip_between", array("mincount" => $this->nMin, "maxcount" => $this->nMax, "contentfield" => $sTranslation)); } if ($this->nMin > 0) { return AnwComponent::g_editcontent("contentmultiplicity_multiple_tip_greater", array("mincount" => $this->nMin, "contentfield" => $sTranslation)); } if ($this->nMax < self::UNLIMITED) { return AnwComponent::g_editcontent("contentmultiplicity_multiple_tip_lower", array("maxcount" => $this->nMax, "contentfield" => $sTranslation)); } return AnwComponent::g_editcontent("contentmultiplicity_multiple_tip_any", array("contentfield" => $sTranslation)); }
function getSettingsForInitialization() { $oMysqlSettings = $this->cfg(self::CFG_MYSQL); return AnwComponent::g_editcontent("contentfield_mysqlconnexion_collapsed", array('user' => $oMysqlSettings[AnwISettings_mysqlconnexion::FIELD_USER], 'host' => $oMysqlSettings[AnwISettings_mysqlconnexion::FIELD_HOST], 'database' => $oMysqlSettings[AnwISettings_mysqlconnexion::FIELD_DATABASE], 'prefix' => $oMysqlSettings[AnwISettings_mysqlconnexion::FIELD_PREFIX])); }
/** * Special override system for translations. * Below there is an example applied to contentclass_menu. * C means that the string comes from the class (ex: "menuItem" comes from "AnwContentFieldPage_menuItem") * N means that the string comes from the name of the field (ex: "subitems" is the name of a field in "AnwContentFieldPage_menuItem") * Here is the order for looking to translations. * * contentfield_menu_items_subitems_link_title_label * C N N N N * * contentfield_menuItem_subitems_link_title_label * C N N N * * contentfield_menuSubItem_link_title_label * C N N * * contentfield_link_title_label * C N */ protected final function doGetFieldTranslation($sBasePrefix, $sTranslationName, $asParameters, $bFromComponent, $nMaxDeep = -1) { if ($nMaxDeep == -1) { //initialize maxDeep to highest possible value $nHighestDeep = 0; $oTest = $this; while ($oTest->getContainer() instanceof AnwStructuredContentField_composed) { $oTest = $oTest->getContainer(); $nHighestDeep++; } $nMaxDeep = $nHighestDeep; //try last level translation (special case) $sFullTranslationName = $this->baseTranslationName($sBasePrefix, $nMaxDeep, true) . $sTranslationName; //print "<br/>**Max=".$nMaxDeep.": ".$sFullTranslationName."***<br/>"; if ($bFromComponent) { $sTranslation = $this->t_structuredcontentfield($sFullTranslationName, $asParameters, false, ""); } else { $sTranslation = AnwComponent::g_editcontent($sFullTranslationName, $asParameters, false, ""); //instance call required as it's abstract } if ($sTranslation !== "") { return $sTranslation; } } $sFullTranslationName = $this->baseTranslationName($sBasePrefix, $nMaxDeep, false) . $sTranslationName; if ($bFromComponent) { $sTranslation = $this->t_structuredcontentfield($sFullTranslationName, $asParameters, false, ""); } else { $sTranslation = AnwComponent::g_editcontent($sFullTranslationName, $asParameters, false, ""); //instance call required as it's abstract } //print "<br/>**Max=".$nMaxDeep.": ".$sFullTranslationName."***<br/>"; if ($sTranslation === "") { $nMaxDeep--; if ($nMaxDeep >= 0) { $sTranslation = $this->doGetFieldTranslation($sBasePrefix, $sTranslationName, $asParameters, $bFromComponent, $nMaxDeep); } } return $sTranslation; }
/** * Conflicts checker/solver. * When $amSolvedValues is null, it will only check for dependancies problems and throw exceptions. * When $amSolvedValues is not null, it must be an array of misc values, at the same indexes than $aoComponents. * If a solution is found, $amSolvedValues will be reorganized in the correct order. */ private function doCheckOrSolveDependancies($aoComponents, $amSolvedValues = null, $nDepth = 0) { self::debug("solveDependancies() for " . $this->getSourceComponent()->getComponentName()); // search for source/target indices... $nSourceComponentIndice = null; $nTargetComponentIndice = null; foreach ($aoComponents as $i => $oComponent) { if ($nSourceComponentIndice === null && $this->sourceComponentMatches($oComponent)) { $nSourceComponentIndice = $i; } else { if ($nTargetComponentIndice === null && $this->targetComponentMatches($oComponent)) { $nTargetComponentIndice = $i; } } if ($nSourceComponentIndice !== null && $nTargetComponentIndice !== null) { break; } } if ($nSourceComponentIndice === null) { throw new AnwUnexpectedException("Source component not found"); //should never happend } // begin dependancies resolution if ($nTargetComponentIndice !== null) { //the conflicting component has been found... if ($this->mSolution == self::SOLUTION_NONE) { // there is no solution self::debug("conflict between " . $this->getSourceComponent()->getComponentName() . " and " . $this->getTargetComponentName() . " : no solution"); throw new AnwDependancyException(AnwComponent::g_editcontent("dependancy_conflict", array('component1' => $this->getSourceComponent()->getComponentName(), 'component2' => $this->getTargetComponentName()))); } else { // there is a solution, we will try to apply it... $bSolvedValuesWereChanged = false; if ($this->mSolution == self::SOLUTION_LOAD_BEFORE && $nSourceComponentIndice < $nTargetComponentIndice || $this->mSolution == self::SOLUTION_LOAD_AFTER && $nSourceComponentIndice > $nTargetComponentIndice) { // already solved self::debug("conflict between " . $this->getSourceComponent()->getComponentName() . " and " . $this->getTargetComponentName() . " : already solved"); } else { self::debug("conflict between " . $this->getSourceComponent()->getComponentName() . " and " . $this->getTargetComponentName() . " : solvable"); if ($amSolvedValues !== null) { // conflict can be solved by permuting the two components (must permute it in $aoComponents AND $amSolvedValues) list($aoComponents, $amSolvedValues) = AnwUtils::permuteMultipleArrays(array($aoComponents, $amSolvedValues), $nSourceComponentIndice, $nTargetComponentIndice); $bSolvedValuesWereChanged = true; } else { throw new AnwDependancyException(AnwComponent::g_editcontent("dependancy_conflict_unsolved", array('component1' => $this->getSourceComponent()->getComponentName(), 'component2' => $this->getTargetComponentName()))); } } if ($amSolvedValues !== null && $bSolvedValuesWereChanged) { // we have to check again the whole values, to be sure that we didn't break a dependancy while reorganizing $amSolvedValues $nDepth++; if ($nDepth > 3) { // we may be in an infinite dependancies problem... give up! self::debug("amSolvedValues have changed, but nDepth exceeded"); throw new AnwDependancyException(AnwComponent::g_editcontent("dependancy_conflict_exceed", array('component1' => $this->getSourceComponent()->getComponentName(), 'component2' => $this->getTargetComponentName()))); } else { self::debug("amSolvedValues have changed, checking again whole values"); $aoComponents = $this->doCheckOrSolveDependancies($aoComponents, $amSolvedValues, $nDepth); //recursive call } } } } else { //no dependancy problem self::debug("conflict between " . $this->getSourceComponent()->getComponentName() . " and " . $this->getTargetComponentName() . " : no dependancy problem"); } return $amSolvedValues; }
function getRender($bForceFromPost = false) { $sRender = parent::getRender($bForceFromPost); $sConfigFileOverride = $this->getEditableComponent()->getConfigurableFileOverride(); $sRender .= '<div class="explain" style="float:right; width:65%">' . AnwComponent::g_editcontent("editsettings_info", array('filename' => '<span style="font-size:0.8em">' . $sConfigFileOverride . '</span>')) . '</div>'; return $sRender; }
function renderMultipleInputInstance($sInstancesClass, $bIsSortable, $sRenderedInput, $sLabelSingle, $sFieldTip = false) { $sTranslationRemoveButton = AnwComponent::g_editcontent("contentmultiplicity_multiple_contentfield_del", array('fieldname' => $sLabelSingle)); if ($sFieldTip) { $sFieldTip = '<div class="contentfield_tip">' . $sFieldTip . '</div>'; } $HTML = <<<EOF <!-- Begin instance of {$sInstancesClass} --> <div class="contentfield_multiple_instance {$sInstancesClass}"> \t<div class="contentmultiplicity_tools"> \t\t<a class="contentmultiplicity_remove" href="#" onclick="AnwContentFieldMultiple.get('{$sInstancesClass}').removeInstance(this.parentNode.parentNode); return false;">{$sTranslationRemoveButton}</a> EOF; if ($bIsSortable) { //alternative sort to drag&drop $sSrcUp = AnwUtils::pathImg("up.gif"); $sSrcDown = AnwUtils::pathImg("down.gif"); $HTML .= <<<EOF \t\t<a class="contentmultiplicity_sort" href="#" onclick="AnwContentFieldMultiple.get('{$sInstancesClass}').moveUp(this.parentNode.parentNode); return false;"><img alt="up" src="{$this->xQuote($sSrcUp)}"/></a> \t\t<a class="contentmultiplicity_sort" href="#" onclick="AnwContentFieldMultiple.get('{$sInstancesClass}').moveDown(this.parentNode.parentNode); return false;"><img alt="down" src="{$this->xQuote($sSrcDown)}"/></a> EOF; } $HTML .= <<<EOF \t</div> {$sFieldTip} {$sRenderedInput} </div><!-- end contentfield_multiple_instance {$sInstancesClass} --> <!-- End instance of {$sInstancesClass} --> EOF; return $HTML; }
function testValue($sValue) { if (!isset($this->asEnumValues[$sValue])) { $sEnumValues = implode(',', $this->asEnumValues); $sError = AnwComponent::g_editcontent("err_contentfield_enum_values"); throw new AnwInvalidContentFieldValueException($sError); } }
protected static function getTargetLabel($sTarget) { return AnwComponent::g_editcontent("contentfield_link_target" . $sTarget); }