Commit df0c6dfd55990774fccf9f62712db89cbafdacf0

Authored by Neil Blakey-Milner
1 parent f30954e1

Correctly populate field_behaviour_options, and restrict the shown items

to those not in field_behaviour_options already.


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@3794 c91229c3-7414-0410-bfa2-8a42b809f60b
presentation/lookAndFeel/knowledgeTree/administration/docfieldmanagement/conditional/ajaxComplexConditionals.php
@@ -38,16 +38,22 @@ class AjaxConditionalAdminDispatcher extends KTStandardDispatcher { @@ -38,16 +38,22 @@ class AjaxConditionalAdminDispatcher extends KTStandardDispatcher {
38 $oTemplating =& KTTemplating::getSingleton(); 38 $oTemplating =& KTTemplating::getSingleton();
39 $oTemplate =& $oTemplating->loadTemplate('ktcore/metadata/conditional/ajax_complex_get_item_list'); 39 $oTemplate =& $oTemplating->loadTemplate('ktcore/metadata/conditional/ajax_complex_get_item_list');
40 40
41 - $sMetadataTable = KTUtil::getTableName('metadata');  
42 - $sVITable = KTUtil::getTableName('field_value_instances');  
43 - $aQuery = array(  
44 - "SELECT M.id AS id, M.name AS name FROM $sMetadataTable AS M LEFT JOIN $sVITable AS V ON M.id = V.field_value_id WHERE M.document_field_id = ? AND V.id IS NULL",  
45 - array($field_id),  
46 - );  
47 - $aRows = DBUtil::getResultArray($aQuery);  
48 $aValues = array(); 41 $aValues = array();
49 - foreach ($aRows as $aRow) {  
50 - $aValues[$aRow['id']] = $aRow['name']; 42 + foreach ($oField->getValues() as $oValue) {
  43 + if (empty($parent_behaviour)) {
  44 + $oInstance = KTValueInstance::getByLookupSingle($oValue);
  45 + if (empty($oInstance)) {
  46 + $aValues[$oValue->getId()] = $oValue->getName();
  47 + }
  48 + // No parent behaviour (thus master column), so any
  49 + // instance will do to prevent showing this value
  50 + continue;
  51 + }
  52 +
  53 + $iInstanceId = KTValueInstance::getByLookupAndParentBehaviour($oValue, $parent_behaviour, array('ids' => true));
  54 + if (empty($iInstanceId)) {
  55 + $aValues[$oValue->getId()] = $oValue->getName();
  56 + }
51 } 57 }
52 $aData = array( 58 $aData = array(
53 'values' => $aValues, 59 'values' => $aValues,
@@ -114,12 +120,27 @@ class AjaxConditionalAdminDispatcher extends KTStandardDispatcher { @@ -114,12 +120,27 @@ class AjaxConditionalAdminDispatcher extends KTStandardDispatcher {
114 'fieldid' => $field_id, 120 'fieldid' => $field_id,
115 )); 121 ));
116 122
  123 + $aValueInstanceIds = array();
117 foreach ($lookups_to_assign as $iLookupId) { 124 foreach ($lookups_to_assign as $iLookupId) {
118 $res = $oValueInstance =& KTValueInstance::createFromArray(array( 125 $res = $oValueInstance =& KTValueInstance::createFromArray(array(
119 'fieldid' => $field_id, 126 'fieldid' => $field_id,
120 'behaviourid' => $oBehaviour->getId(), 127 'behaviourid' => $oBehaviour->getId(),
121 'fieldvalueid' => abs($iLookupId), 128 'fieldvalueid' => abs($iLookupId),
122 )); 129 ));
  130 + $aValueInstanceIds[] = $res->getId();
  131 + }
  132 +
  133 + if ($parent_behaviour) {
  134 + $oParentBehaviour =& $this->oValidator->validateBehaviour($parent_behaviour);
  135 + $sTable = KTUtil::getTableName('field_behaviour_options');
  136 + $aOptions = array('noid' => true);
  137 + foreach ($aValueInstanceIds as $iId) {
  138 + $res = DBUtil::autoInsert($sTable, array(
  139 + 'behaviour_id' => $oParentBehaviour->getId(),
  140 + 'field_id' => $field_id,
  141 + 'instance_id' => $iId,
  142 + ), $aOptions);
  143 + }
123 } 144 }
124 145
125 header('Content-type: application/xml'); 146 header('Content-type: application/xml');
@@ -137,12 +158,27 @@ class AjaxConditionalAdminDispatcher extends KTStandardDispatcher { @@ -137,12 +158,27 @@ class AjaxConditionalAdminDispatcher extends KTStandardDispatcher {
137 158
138 $oBehaviour =& $this->oValidator->validateBehaviour($parent_behaviour); 159 $oBehaviour =& $this->oValidator->validateBehaviour($parent_behaviour);
139 160
  161 + $aValueInstanceIds = array();
140 foreach ($lookups_to_assign as $iLookupId) { 162 foreach ($lookups_to_assign as $iLookupId) {
141 $res = $oValueInstance =& KTValueInstance::createFromArray(array( 163 $res = $oValueInstance =& KTValueInstance::createFromArray(array(
142 'fieldid' => $field_id, 164 'fieldid' => $field_id,
143 'behaviourid' => $oBehaviour->getId(), 165 'behaviourid' => $oBehaviour->getId(),
144 'fieldvalueid' => abs($iLookupId), 166 'fieldvalueid' => abs($iLookupId),
145 )); 167 ));
  168 + $aValueInstanceIds[] = $res->getId();
  169 + }
  170 +
  171 + if ($parent_behaviour) {
  172 + $oParentBehaviour =& $this->oValidator->validateBehaviour($parent_behaviour);
  173 + $sTable = KTUtil::getTableName('field_behaviour_options');
  174 + $aOptions = array('noid' => true);
  175 + foreach ($aValueInstanceIds as $iId) {
  176 + $res = DBUtil::autoInsert($sTable, array(
  177 + 'behaviour_id' => $oParentBehaviour->getId(),
  178 + 'field_id' => $field_id,
  179 + 'instance_id' => $iId,
  180 + ), $aOptions);
  181 + }
146 } 182 }
147 183
148 header('Content-type: application/xml'); 184 header('Content-type: application/xml');