/** * Recursively traverses a fieldset from the behaviour assigned to * the master field and thereafter subsequent fields uncovering the * fields that should be filled in given the columns/fields that * have already be filled in, and providing the values for them * based on the behaviours specified by the existing values in their * parent fields (in combination with _their_ parent fields). */ function _getNextForBehaviour($oBehaviour, $aCurrentSelections) { /* * GENERAL GAME PLAN * * For this behaviour, get the fields that this behaviour * affects. Also get the values that this behaviour prescribes * for those fields. * * Then, for each of the next fields, check if they are already * filled in. * * If not, leave that field in the set of values that need to be * filled in, and move on to the next field for this behaviour. * * If it is filled in, remove the field from the set of values * to be filled in. But add the set of fields and values that * the choice of value in this field prescribe (using a * recursive call to this function). */ $oBehaviour =& KTUtil::getObject('KTFieldBehaviour', $oBehaviour); if (PEAR::isError($oBehaviour)) { return array(); } $GLOBALS['default']->log->debug('KTMetadataUtil::_getNextForBehaviour, behaviour is ' . $oBehaviour->getId()); $aValues = KTMetadataUtil::getNextValuesForBehaviour($oBehaviour); $iFieldId = $oBehaviour->getFieldId(); $aNextFields = KTMetadataUtil::getChildFieldIds($iFieldId); $GLOBALS['default']->log->debug('KTMetadataUtil::_getNextForBehaviour, next fields for ' . $iFieldId . ' are: ' . print_r($aNextFields, true)); foreach ($aNextFields as $iThisFieldId) { if (!in_array($iThisFieldId, array_keys($aCurrentSelections))) { $GLOBALS['default']->log->debug('KTMetadataUtil::_getNextForBehaviour, field ' . $iThisFieldId . ' is not selected'); } else { $GLOBALS['default']->log->debug('KTMetadataUtil::_getNextForBehaviour, field ' . $iThisFieldId . ' is selected'); unset($aValues[$iThisFieldId]); // here we need a Lookup field. if (!is_a($aCurrentSelections[$iThisFieldId], 'MetaData')) { $oL = MetaData::getByValueAndDocumentField($aCurrentSelections[$iThisFieldId], $iThisFieldId); } else { $oL = $aCurrentSelections[$iThisFieldId]; } $oInstance = KTValueInstance::getByLookupAndParentBehaviour($oL, $oBehaviour); if (is_null($oInstance)) { // somehow an invalid value hit us here. continue; } $GLOBALS['default']->log->debug('KTMetadataUtil::_getNextForBehaviour, instance is ' . print_r($oInstance, true)); $nextBehaviour = $oInstance->getBehaviourId(); // may be NULL if (!is_null($nextBehaviour)) { $oChildBehaviour =& KTFieldBehaviour::get($nextBehaviour); $GLOBALS['default']->log->debug('KTMetadataUtil::_getNextForBehaviour, field ' . $iThisFieldId . ' is not selected'); $aMyValues = KTMetadataUtil::_getNextForBehaviour($oChildBehaviour, $aCurrentSelections); $GLOBALS['default']->log->debug('KTMetadataUtil::_getNextForBehaviour, values are ' . print_r($aMyValues, true)); foreach ($aMyValues as $k => $v) { $aValues[$k] = $v; } } } } $GLOBALS['default']->log->debug('KTMetadataUtil::_getNextForBehaviour, final values are ' . print_r($aValues, true)); // now we need to clean this up: remove no-value entries. $temp = $aValues; foreach ($temp as $k => $v) { if (empty($v)) { unset($aValues[$k]); } } return $aValues; }
function do_getAssignedList() { $parent_behaviour = KTUtil::arrayGet($_REQUEST, 'parent_behaviour'); //$fieldset_id = KTUtil::arrayGet($_REQUEST, 'fieldset_id'); // $oFieldset =& $this->oValidator->validateFieldset(KTUtil::arrayGet($_REQUEST, 'fieldset_id')); $field_id = KTUtil::arrayGet($_REQUEST, 'field_id'); $oField =& $this->oValidator->validateField(KTUtil::arrayGet($_REQUEST, 'field_id')); header('Content-type: application/xml'); $oTemplating =& KTTemplating::getSingleton(); $oTemplate =& $oTemplating->loadTemplate('ktcore/metadata/conditional/ajax_complex_get_item_list'); $aValues = array(); $aBehaviours = array(); foreach ($oField->getEnabledValues() as $oValue) { if (empty($parent_behaviour)) { $oInstance = KTValueInstance::getByLookupSingle($oValue); if (!empty($oInstance)) { if (is_null($aBehaviours[$oInstance->getBehaviourId()])) { $aBehaviours[$oInstance->getBehaviourId()] = KTFieldBehaviour::get($oInstance->getBehaviourId()); } $aValues[$oInstance->getId()] = $oValue->getName() . ' - ' . $aBehaviours[$oInstance->getBehaviourId()]->getName(); } // No parent behaviour (thus master column), so any // instance will do to prevent showing this value continue; } $iInstanceId = KTValueInstance::getByLookupAndParentBehaviour($oValue, $parent_behaviour, array('ids' => true)); if (!empty($iInstanceId)) { $oInstance = KTValueInstance::get($iInstanceId); //print $oInstance->getBehaviourId() . ' - '; //continue; $behaviour_id = $oInstance->getBehaviourId(); if (is_null($behaviour_id)) { $aValues[$oInstance->getId()] = $oValue->getName(); } else { if (is_null($aBehaviours[$behaviour_id])) { $aBehaviours[$behaviour_id] = KTFieldBehaviour::get($behaviour_id); } $aValues[$oInstance->getId()] = $oValue->getName() . ' - ' . $aBehaviours[$behaviour_id]->getName(); } } } $aData = array('values' => $aValues); $oTemplate->setData($aData); return $oTemplate->render(); }