Commit 845369a14606df058616d73347fa534db5ca2e87
1 parent
6150dece
Implement getNext for not only the simple case.
git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@3797 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
1 changed file
with
58 additions
and
15 deletions
lib/metadata/metadatautil.inc.php
| @@ -32,6 +32,40 @@ require_once(KT_LIB_DIR . '/metadata/fieldset.inc.php'); | @@ -32,6 +32,40 @@ require_once(KT_LIB_DIR . '/metadata/fieldset.inc.php'); | ||
| 32 | require_once(KT_LIB_DIR . '/metadata/fieldbehaviour.inc.php'); | 32 | require_once(KT_LIB_DIR . '/metadata/fieldbehaviour.inc.php'); |
| 33 | 33 | ||
| 34 | class KTMetadataUtil { | 34 | class KTMetadataUtil { |
| 35 | + | ||
| 36 | + function _getNextForBehaviour($oBehaviour, $aCurrentSelections) { | ||
| 37 | + $oBehaviour =& KTUtil::getObject('KTFieldBehaviour', $oBehaviour); | ||
| 38 | + $GLOBALS['default']->log->debug('KTMetadataUtil::_getNextForBehaviour, behaviour is ' . $oBehaviour->getId()); | ||
| 39 | + | ||
| 40 | + $aValues = KTMetadataUtil::getNextValuesForBehaviour($oBehaviour); | ||
| 41 | + $iFieldId = $oBehaviour->getFieldId(); | ||
| 42 | + $aNextFields = KTMetadataUtil::getChildFieldIds($iFieldId); | ||
| 43 | + $GLOBALS['default']->log->debug('KTMetadataUtil::_getNextForBehaviour, next fields for ' . $iFieldId . ' are: ' . print_r($aNextFields, true)); | ||
| 44 | + | ||
| 45 | + foreach ($aNextFields as $iThisFieldId) { | ||
| 46 | + if (!in_array($iThisFieldId, array_keys($aCurrentSelections))) { | ||
| 47 | + $GLOBALS['default']->log->debug('KTMetadataUtil::_getNextForBehaviour, field ' . $iThisFieldId . ' is not selected'); | ||
| 48 | + | ||
| 49 | + } else { | ||
| 50 | + $GLOBALS['default']->log->debug('KTMetadataUtil::_getNextForBehaviour, field ' . $iThisFieldId . ' is selected'); | ||
| 51 | + unset($aValues[$iThisFieldId]); | ||
| 52 | + | ||
| 53 | + $oInstance = KTValueInstance::getByLookupAndParentBehaviour($aCurrentSelections[$iThisFieldId], $oBehaviour); | ||
| 54 | + $GLOBALS['default']->log->debug('KTMetadataUtil::_getNextForBehaviour, instance is ' . print_r($oInstance, true)); | ||
| 55 | + $oChildBehaviour =& KTFieldBehaviour::get($oInstance->getBehaviourId()); | ||
| 56 | + $GLOBALS['default']->log->debug('KTMetadataUtil::_getNextForBehaviour, field ' . $iThisFieldId . ' is not selected'); | ||
| 57 | + $aMyValues = KTMetadataUtil::_getNextForBehaviour($oChildBehaviour, $aCurrentSelections); | ||
| 58 | + $GLOBALS['default']->log->debug('KTMetadataUtil::_getNextForBehaviour, values are ' . print_r($aMyValues, true)); | ||
| 59 | + foreach ($aMyValues as $k => $v) { | ||
| 60 | + $aValues[$k] = $v; | ||
| 61 | + } | ||
| 62 | + } | ||
| 63 | + } | ||
| 64 | + | ||
| 65 | + $GLOBALS['default']->log->debug('KTMetadataUtil::_getNextForBehaviour, final values are ' . print_r($aValues, true)); | ||
| 66 | + return $aValues; | ||
| 67 | + } | ||
| 68 | + | ||
| 35 | // {{{ getNext | 69 | // {{{ getNext |
| 36 | /** | 70 | /** |
| 37 | * Given a set of selected values (aCurrentSelections) for a given | 71 | * Given a set of selected values (aCurrentSelections) for a given |
| @@ -41,29 +75,29 @@ class KTMetadataUtil { | @@ -41,29 +75,29 @@ class KTMetadataUtil { | ||
| 41 | */ | 75 | */ |
| 42 | function getNext($oFieldset, $aCurrentSelections) { | 76 | function getNext($oFieldset, $aCurrentSelections) { |
| 43 | $oFieldset =& KTUtil::getObject('KTFieldset', $oFieldset); | 77 | $oFieldset =& KTUtil::getObject('KTFieldset', $oFieldset); |
| 78 | + $GLOBALS['default']->log->debug('KTMetadataUtil::getNext, selections are: ' . print_r($aCurrentSelections, true)); | ||
| 44 | 79 | ||
| 45 | if (empty($aCurrentSelections)) { | 80 | if (empty($aCurrentSelections)) { |
| 46 | $oField =& DocumentField::get($oFieldset->getMasterFieldId()); | 81 | $oField =& DocumentField::get($oFieldset->getMasterFieldId()); |
| 47 | return array($oField->getId() => array('field' => $oField, 'values' => $oField->getValues())); | 82 | return array($oField->getId() => array('field' => $oField, 'values' => $oField->getValues())); |
| 48 | } | 83 | } |
| 49 | 84 | ||
| 50 | - $aReturn = array(); | 85 | + $oMasterField =& DocumentField::get($oFieldset->getMasterFieldId()); |
| 86 | + $aSelectedFields = array_keys($aCurrentSelections); | ||
| 87 | + $oValueInstance = KTValueInstance::getByLookupSingle($aCurrentSelections[$oMasterField->getId()]); | ||
| 51 | 88 | ||
| 52 | - foreach ($aCurrentSelections as $iFieldId => $iLookupId) { | ||
| 53 | - $aFieldIds = KTMetadataUtil::getNextValuesForLookup($iLookupId); | ||
| 54 | - foreach ($aFieldIds as $key => $aValueIds) { | ||
| 55 | - if (in_array($key, $aCurrentSelections)) { | ||
| 56 | - continue; | ||
| 57 | - } | ||
| 58 | - $aValues = array(); | ||
| 59 | - foreach ($aValueIds as $iLookupId) { | ||
| 60 | - $aValues[] = MetaData::get($iLookupId); | ||
| 61 | - } | ||
| 62 | - $aReturn[$key] = array( | ||
| 63 | - 'field' => DocumentField::get($key), | ||
| 64 | - 'values' => $aValues, | ||
| 65 | - ); | 89 | + $aValues = KTMetadataUtil::_getNextForBehaviour($oValueInstance->getBehaviourId(), $aCurrentSelections); |
| 90 | + $GLOBALS['default']->log->debug('KTMetadataUtil::getNext, values are ' . print_r($aValues, true)); | ||
| 91 | + $aReturn = array(); | ||
| 92 | + foreach ($aValues as $iFieldId => $aValueIds) { | ||
| 93 | + $aValues = array(); | ||
| 94 | + foreach ($aValueIds as $iLookupId) { | ||
| 95 | + $aValues[] = MetaData::get($iLookupId); | ||
| 66 | } | 96 | } |
| 97 | + $aReturn[$iFieldId] = array( | ||
| 98 | + 'field' => DocumentField::get($iFieldId), | ||
| 99 | + 'values' => $aValues, | ||
| 100 | + ); | ||
| 67 | } | 101 | } |
| 68 | return $aReturn; | 102 | return $aReturn; |
| 69 | } | 103 | } |
| @@ -219,17 +253,26 @@ class KTMetadataUtil { | @@ -219,17 +253,26 @@ class KTMetadataUtil { | ||
| 219 | $oLookup =& KTUtil::getObject('MetaData', $oLookup); | 253 | $oLookup =& KTUtil::getObject('MetaData', $oLookup); |
| 220 | $oInstance =& KTValueInstance::getByLookupSingle($oLookup); | 254 | $oInstance =& KTValueInstance::getByLookupSingle($oLookup); |
| 221 | if (PEAR::isError($oInstance)) { | 255 | if (PEAR::isError($oInstance)) { |
| 256 | + $GLOBALS['default']->log->error('KTMetadataUtil::getNextValuesForLookup, got dud instance id, returned: ' . print_r($oInstance, true)); | ||
| 222 | return $oInstance; | 257 | return $oInstance; |
| 223 | } | 258 | } |
| 224 | if (!is_null($oInstance) && $oInstance->getBehaviourId()) { | 259 | if (!is_null($oInstance) && $oInstance->getBehaviourId()) { |
| 225 | // if we have an instance, and we have a behaviour, return | 260 | // if we have an instance, and we have a behaviour, return |
| 226 | // the actual values for that behaviour. | 261 | // the actual values for that behaviour. |
| 227 | $oBehaviour =& KTFieldBehaviour::get($oInstance->getBehaviourId()); | 262 | $oBehaviour =& KTFieldBehaviour::get($oInstance->getBehaviourId()); |
| 263 | + if (PEAR::isError($oBehaviour)) { | ||
| 264 | + $GLOBALS['default']->log->error('KTMetadataUtil::getNextValuesForLookup, got dud behaviour id, returned: ' . print_r($oBehaviour, true)); | ||
| 265 | + return $res; | ||
| 266 | + } | ||
| 228 | return KTMetadataUtil::getNextValuesForBehaviour($oBehaviour); | 267 | return KTMetadataUtil::getNextValuesForBehaviour($oBehaviour); |
| 229 | } | 268 | } |
| 230 | // No instance or no behaviour, so send an empty array for each | 269 | // No instance or no behaviour, so send an empty array for each |
| 231 | // field that we affect. | 270 | // field that we affect. |
| 232 | $aChildFieldIds = KTMetadataUtil::getChildFieldIds($oLookup->getDocFieldId()); | 271 | $aChildFieldIds = KTMetadataUtil::getChildFieldIds($oLookup->getDocFieldId()); |
| 272 | + if (PEAR::isError($aChildFieldIds)) { | ||
| 273 | + $GLOBALS['default']->log->error('KTMetadataUtil::getNextValuesForLookup, getChildFieldIds returned: ' . print_r($aChildFieldIds, true)); | ||
| 274 | + return $res; | ||
| 275 | + } | ||
| 233 | foreach ($aChildFieldIds as $iFieldId) { | 276 | foreach ($aChildFieldIds as $iFieldId) { |
| 234 | $aValues[$iFieldId] = array(); | 277 | $aValues[$iFieldId] = array(); |
| 235 | } | 278 | } |