Commit e5f266b74bb52682a5959aecfac1b2fdb3c8d3e7

Authored by nbm
1 parent 119da48a

Implement getNext (tell me the next fields and values based on what I

have now in conditional metadata).

Add removeFieldOrdering, which removes all field ordering for a
fieldset.  Add setMasterField for conditional fieldsets, which sets the
start field for conditional metadata.


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@3771 c91229c3-7414-0410-bfa2-8a42b809f60b
lib/metadata/metadatautil.inc.php
... ... @@ -28,6 +28,8 @@
28 28 require_once(KT_LIB_DIR . "/ktentity.inc");
29 29 require_once(KT_LIB_DIR . '/documentmanagement/MetaData.inc');
30 30 require_once(KT_LIB_DIR . '/metadata/valueinstance.inc.php');
  31 +require_once(KT_LIB_DIR . '/metadata/fieldset.inc.php');
  32 +require_once(KT_LIB_DIR . '/metadata/fieldbehaviour.inc.php');
31 33  
32 34 class KTMetadataUtil {
33 35 // {{{ getNext
... ... @@ -37,17 +39,42 @@ class KTMetadataUtil {
37 39 * keys set to newly uncovered fields, and the contents an array of
38 40 * the value instances that are available to choose in those fields.
39 41 */
40   - function getNext($iFieldSetId, $aCurrentSelections) {
  42 + function getNext($oFieldset, $aCurrentSelections) {
  43 + $oFieldset =& KTUtil::getObject('KTFieldset', $oFieldset);
  44 +
41 45 if (empty($aCurrentSelections)) {
42   - return array();
  46 + $oField =& DocumentField::get($oFieldset->getMasterFieldId());
  47 + return array($oField->getId() => array('field' => $oField, 'values' => $oField->getValues()));
  48 + }
  49 +
  50 + $aReturn = array();
  51 +
  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 + );
  66 + }
43 67 }
  68 + return $aReturn;
44 69 }
45 70 // }}}
46 71  
47 72 // {{{ getStartFields
48   - function getStartFields($iFieldSetId) {
49   - return DocumentField::getList();
50   -
  73 + function getMasterField($oFieldset) {
  74 + $oFieldset =& KTUtil::getObject('KTFieldset', $oFieldset);
  75 + if ($oFieldset->getMasterField()) {
  76 + return DocumentField::get($oFieldset->getMasterField());
  77 + }
51 78 }
52 79 // }}}
53 80  
... ... @@ -139,6 +166,18 @@ class KTMetadataUtil {
139 166 }
140 167 // }}}
141 168  
  169 + // {{{ removeFieldOrdering
  170 + function removeFieldOrdering($oFieldset) {
  171 + $iFieldsetId = KTUtil::getId($oFieldset);
  172 + $sTable = KTUtil::getTableName('field_orders');
  173 + $aQuery = array(
  174 + "DELETE FROM $sTable WHERE fieldset_id = ?",
  175 + array($iFieldsetId),
  176 + );
  177 + return DBUtil::runQuery($aQuery);
  178 + }
  179 + // }}}
  180 +
142 181 // {{{ getParentFieldId
143 182 function getParentFieldId($oField) {
144 183 $sTable = KTUtil::getTableName('field_orders');
... ...