Commit 21c8a9409a7425f629bd42b69cc0d5eac246e947

Authored by Brad Shuttleworth
1 parent 3e936041

merge fix for KEP-70 from preview.


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@5625 c91229c3-7414-0410-bfa2-8a42b809f60b
lib/metadata/metadatautil.inc.php
... ... @@ -533,7 +533,7 @@ class KTMetadataUtil {
533 533 $sTable = KTUtil::getTableName('field_value_instances');
534 534 $sLookupTable = KTUtil::getTableName('metadata_lookup');
535 535 $aQuery = array(
536   - "SELECT COUNT(FVI.id) AS cnt FROM $sTable AS FVI LEFT JOIN $sLookupTable AS ML ON (FVI.field_value_id = ML.id) WHERE FVI.field_id = ?",
  536 + "SELECT COUNT(FVI.id) AS cnt FROM $sTable AS FVI LEFT JOIN $sLookupTable AS ML ON (FVI.field_value_id = ML.id) WHERE FVI.field_id = ? AND ML.disabled = 0",
537 537 array($iMasterFieldId),
538 538 );
539 539 $iCount = DBUtil::getOneResultKey($aQuery, 'cnt');
... ... @@ -551,10 +551,12 @@ class KTMetadataUtil {
551 551 // check that each master-field value has a valueinstance assigned.
552 552 $sTable = KTUtil::getTableName('metadata_lookup');
553 553 $aQuery = array(
554   - "SELECT COUNT(id) AS cnt FROM $sTable WHERE document_field_id = ? AND disabled <> 0 ",
  554 + "SELECT COUNT(id) AS cnt FROM $sTable WHERE document_field_id = ? AND disabled = 0 ",
555 555 array($iMasterFieldId),
556 556 );
557 557 $iValCount = DBUtil::getOneResultKey($aQuery, 'cnt');
  558 +
  559 + // assumes that there cannot be more than 1 value instance for each master-field-value.
558 560 if ($iValCount != $iCount) {
559 561 return PEAR::raiseError(sprintf(_kt('%d values for the Master Field are not assigned to behaviours.'), ($iValCount - $iCount)));
560 562 }
... ...
plugins/ktcore/admin/ajaxComplexConditionals.php
... ... @@ -64,7 +64,7 @@ class AjaxConditionalAdminDispatcher extends KTAdminDispatcher {
64 64 $oTemplate =& $oTemplating->loadTemplate('ktcore/metadata/conditional/ajax_complex_get_item_list');
65 65  
66 66 $aValues = array();
67   - foreach ($oField->getValues() as $oValue) {
  67 + foreach ($oField->getEnabledValues() as $oValue) {
68 68 if (empty($parent_behaviour)) {
69 69 $oInstance = KTValueInstance::getByLookupSingle($oValue);
70 70 if (empty($oInstance)) {
... ... @@ -132,7 +132,7 @@ class AjaxConditionalAdminDispatcher extends KTAdminDispatcher {
132 132  
133 133 $aValues = array();
134 134 $aBehaviours = array();
135   - foreach ($oField->getValues() as $oValue) {
  135 + foreach ($oField->getEnabledValues() as $oValue) {
136 136 if (empty($parent_behaviour)) {
137 137 $oInstance = KTValueInstance::getByLookupSingle($oValue);
138 138 if (!empty($oInstance)) {
... ...
plugins/ktcore/admin/manageConditionals.php
... ... @@ -80,7 +80,7 @@ class ManageConditionalDispatcher extends KTAdminDispatcher {
80 80  
81 81 $oFieldset =& KTFieldset::get($fieldset_id);
82 82 $aFields =& $oFieldset->getFields();
83   -
  83 +
84 84 $this->aBreadcrumbs[] = array(
85 85 'url' => KTUtil::ktLink('admin.php','documents/fieldmanagement','action=edit&fFieldsetId=' . $oFieldset->getId()),
86 86 'name' => $oFieldset->getName()
... ... @@ -102,11 +102,37 @@ class ManageConditionalDispatcher extends KTAdminDispatcher {
102 102 $aChildren[] = $row['child_field_id'];
103 103 $aOrders[$row['parent_field_id']] = $aChildren;
104 104 }
  105 +
  106 + // for useability, they can go in any order
  107 + // but master field should be first. beyond that
  108 + // it can get odd anyway.
  109 +
  110 + $aKeyedFields = array();
  111 + $aOrderedFields = array();
  112 + $aStack = array($oFieldset->getMasterFieldId());
  113 +
  114 + // first, key
  115 + foreach ($aFields as $oField) {
  116 + $aKeyedFields[$oField->getId()] = $oField;
  117 + }
  118 +
  119 + while (!empty($aStack)) {
  120 + $iKey = array_shift($aStack);
  121 + // this shouldn't happen, but avoid it anyway.
  122 + if (!is_null($aKeyedFields[$iKey])) {
  123 + $aOrderedFields[] = $aKeyedFields[$iKey];
  124 + unset($aKeyedFields[$iKey]);
  125 + }
  126 + // add children to stack
  127 + $aStack = kt_array_merge($aStack, $aOrders[$iKey]);
  128 + }
  129 +
  130 +
105 131 $aTemplateData = array(
106 132 "context" => &$this,
107 133 "fieldset_id" => $fieldset_id,
108 134 "ordering" => $aOrders,
109   - "aFields" => $aFields,
  135 + "aFields" => $aOrderedFields,
110 136 "iMasterFieldId" => $oFieldset->getMasterFieldId(),
111 137 );
112 138 return $oTemplate->render($aTemplateData);
... ... @@ -126,7 +152,8 @@ class ManageConditionalDispatcher extends KTAdminDispatcher {
126 152 * FIXME we fake it here with nested arrays...
127 153 */
128 154 $oFieldset =& KTFieldset::get($fieldset_id);
129   - $aFields =& $oFieldset->getFields();
  155 + $aFields =& $oFieldset->getFields();
  156 +
130 157 $this->aBreadcrumbs[] = array(
131 158 'url' => KTUtil::ktLink('admin.php','documents/fieldmanagement','action=edit&fFieldsetId=' . $oFieldset->getId()),
132 159 'name' => $oFieldset->getName()
... ... @@ -149,12 +176,33 @@ class ManageConditionalDispatcher extends KTAdminDispatcher {
149 176 $aOrders[$row['parent_field_id']] = $aChildren;
150 177 }
151 178  
  179 +
  180 + $aKeyedFields = array();
  181 + $aOrderedFields = array();
  182 + $aStack = array($oFieldset->getMasterFieldId());
  183 +
  184 + // first, key
  185 + foreach ($aFields as $oField) {
  186 + $aKeyedFields[$oField->getId()] = $oField;
  187 + }
  188 +
  189 + while (!empty($aStack)) {
  190 + $iKey = array_shift($aStack);
  191 + // this shouldn't happen, but avoid it anyway.
  192 + if (!is_null($aKeyedFields[$iKey])) {
  193 + $aOrderedFields[] = $aKeyedFields[$iKey];
  194 + unset($aKeyedFields[$iKey]);
  195 + }
  196 + // add children to stack
  197 + $aStack = kt_array_merge($aStack, $aOrders[$iKey]);
  198 + }
  199 +
152 200 $this->oPage->setBreadcrumbDetails(_kt('Manage complex conditional'));
153 201 $aTemplateData = array(
154 202 "context" => &$this,
155 203 "fieldset_id" => $fieldset_id,
156 204 "ordering" => $aOrders,
157   - "aFields" => $aFields,
  205 + "aFields" => $aOrderedFields,
158 206 "iMasterFieldId" => $oFieldset->getMasterFieldId(),
159 207 );
160 208 return $oTemplate->render($aTemplateData);
... ...
templates/ktcore/metadata/conditional/editsimple.smarty
... ... @@ -95,7 +95,7 @@ refresh the page.{/i18n}&lt;/p&gt;
95 95 <p class="inactivity_message">{i18n}This field is not controlled by the currently active group.{/i18n}</p>
96 96 <div class="lookup_items">
97 97 <select class="item_list">
98   - {foreach from=$oField->getValues() item=oMetaData}
  98 + {foreach from=$oField->getEnabledValues() item=oMetaData}
99 99 <option value="{$oMetaData->getId()}">{$oMetaData->getName()|escape}</option>
100 100 {/foreach}
101 101 </select>
... ...
templates/ktcore/metadata/editFieldset.smarty
... ... @@ -25,21 +25,6 @@
25 25 {$oWidget->render()}
26 26 {/foreach}
27 27  
28   -{if ($oFieldset->getIsConditional() || $context->haveConditional())}
29   -<div class="field">
30   -<label>{i18n}Conditional{/i18n}</label>
31   -<p class="descriptiveText">
32   -{i18n}A <strong>conditional</strong> fieldset contains only lookup fields. The values for each
33   -field can depend on the user's selections for the others.{/i18n}
34   -</p>
35   -{if $oFieldset->getIsConditional() }
36   - {i18n}Yes{/i18n}
37   -{else}
38   - {i18n}No{/i18n}
39   -{/if}
40   -</div>
41   -{/if}
42   -
43 28 <div class="form_actions">
44 29 <input type="submit" name="submit" value="{i18n}Change{/i18n}" />
45 30 </div>
... ... @@ -65,7 +50,16 @@ field can depend on the user&#39;s selections for the others.{/i18n}
65 50 field can depend on the user's selections for the others.{/i18n}
66 51 </p>
67 52  
68   -
  53 +<div class="field">
  54 +<label>{i18n}Conditional{/i18n}</label>
  55 +<p class="descriptiveText">
  56 +</p>
  57 +{if $oFieldset->getIsConditional() }
  58 + {i18n}Yes{/i18n}
  59 +{else}
  60 + {i18n}No{/i18n}
  61 +{/if}
  62 +</div>
69 63  
70 64 {if $oFieldset->getIsConditional() }
71 65  
... ... @@ -75,6 +69,8 @@ field can depend on the user&#39;s selections for the others.{/i18n}
75 69 <input type="submit" name="submit" value="{i18n}Manage conditional{/i18n}" />
76 70 </form>
77 71  
  72 +<br />
  73 +
78 74 <form action="{$smarty.server.PHP_SELF}" method="POST">
79 75 <input type="hidden" name="fFieldsetId" value="{$oFieldset->getId()}" />
80 76 <input type="hidden" name="action" value="removeConditional" />
... ...