Commit 21c8a9409a7425f629bd42b69cc0d5eac246e947
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
Showing
5 changed files
with
71 additions
and
25 deletions
lib/metadata/metadatautil.inc.php
| @@ -533,7 +533,7 @@ class KTMetadataUtil { | @@ -533,7 +533,7 @@ class KTMetadataUtil { | ||
| 533 | $sTable = KTUtil::getTableName('field_value_instances'); | 533 | $sTable = KTUtil::getTableName('field_value_instances'); |
| 534 | $sLookupTable = KTUtil::getTableName('metadata_lookup'); | 534 | $sLookupTable = KTUtil::getTableName('metadata_lookup'); |
| 535 | $aQuery = array( | 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 | array($iMasterFieldId), | 537 | array($iMasterFieldId), |
| 538 | ); | 538 | ); |
| 539 | $iCount = DBUtil::getOneResultKey($aQuery, 'cnt'); | 539 | $iCount = DBUtil::getOneResultKey($aQuery, 'cnt'); |
| @@ -551,10 +551,12 @@ class KTMetadataUtil { | @@ -551,10 +551,12 @@ class KTMetadataUtil { | ||
| 551 | // check that each master-field value has a valueinstance assigned. | 551 | // check that each master-field value has a valueinstance assigned. |
| 552 | $sTable = KTUtil::getTableName('metadata_lookup'); | 552 | $sTable = KTUtil::getTableName('metadata_lookup'); |
| 553 | $aQuery = array( | 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 | array($iMasterFieldId), | 555 | array($iMasterFieldId), |
| 556 | ); | 556 | ); |
| 557 | $iValCount = DBUtil::getOneResultKey($aQuery, 'cnt'); | 557 | $iValCount = DBUtil::getOneResultKey($aQuery, 'cnt'); |
| 558 | + | ||
| 559 | + // assumes that there cannot be more than 1 value instance for each master-field-value. | ||
| 558 | if ($iValCount != $iCount) { | 560 | if ($iValCount != $iCount) { |
| 559 | return PEAR::raiseError(sprintf(_kt('%d values for the Master Field are not assigned to behaviours.'), ($iValCount - $iCount))); | 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,7 +64,7 @@ class AjaxConditionalAdminDispatcher extends KTAdminDispatcher { | ||
| 64 | $oTemplate =& $oTemplating->loadTemplate('ktcore/metadata/conditional/ajax_complex_get_item_list'); | 64 | $oTemplate =& $oTemplating->loadTemplate('ktcore/metadata/conditional/ajax_complex_get_item_list'); |
| 65 | 65 | ||
| 66 | $aValues = array(); | 66 | $aValues = array(); |
| 67 | - foreach ($oField->getValues() as $oValue) { | 67 | + foreach ($oField->getEnabledValues() as $oValue) { |
| 68 | if (empty($parent_behaviour)) { | 68 | if (empty($parent_behaviour)) { |
| 69 | $oInstance = KTValueInstance::getByLookupSingle($oValue); | 69 | $oInstance = KTValueInstance::getByLookupSingle($oValue); |
| 70 | if (empty($oInstance)) { | 70 | if (empty($oInstance)) { |
| @@ -132,7 +132,7 @@ class AjaxConditionalAdminDispatcher extends KTAdminDispatcher { | @@ -132,7 +132,7 @@ class AjaxConditionalAdminDispatcher extends KTAdminDispatcher { | ||
| 132 | 132 | ||
| 133 | $aValues = array(); | 133 | $aValues = array(); |
| 134 | $aBehaviours = array(); | 134 | $aBehaviours = array(); |
| 135 | - foreach ($oField->getValues() as $oValue) { | 135 | + foreach ($oField->getEnabledValues() as $oValue) { |
| 136 | if (empty($parent_behaviour)) { | 136 | if (empty($parent_behaviour)) { |
| 137 | $oInstance = KTValueInstance::getByLookupSingle($oValue); | 137 | $oInstance = KTValueInstance::getByLookupSingle($oValue); |
| 138 | if (!empty($oInstance)) { | 138 | if (!empty($oInstance)) { |
plugins/ktcore/admin/manageConditionals.php
| @@ -80,7 +80,7 @@ class ManageConditionalDispatcher extends KTAdminDispatcher { | @@ -80,7 +80,7 @@ class ManageConditionalDispatcher extends KTAdminDispatcher { | ||
| 80 | 80 | ||
| 81 | $oFieldset =& KTFieldset::get($fieldset_id); | 81 | $oFieldset =& KTFieldset::get($fieldset_id); |
| 82 | $aFields =& $oFieldset->getFields(); | 82 | $aFields =& $oFieldset->getFields(); |
| 83 | - | 83 | + |
| 84 | $this->aBreadcrumbs[] = array( | 84 | $this->aBreadcrumbs[] = array( |
| 85 | 'url' => KTUtil::ktLink('admin.php','documents/fieldmanagement','action=edit&fFieldsetId=' . $oFieldset->getId()), | 85 | 'url' => KTUtil::ktLink('admin.php','documents/fieldmanagement','action=edit&fFieldsetId=' . $oFieldset->getId()), |
| 86 | 'name' => $oFieldset->getName() | 86 | 'name' => $oFieldset->getName() |
| @@ -102,11 +102,37 @@ class ManageConditionalDispatcher extends KTAdminDispatcher { | @@ -102,11 +102,37 @@ class ManageConditionalDispatcher extends KTAdminDispatcher { | ||
| 102 | $aChildren[] = $row['child_field_id']; | 102 | $aChildren[] = $row['child_field_id']; |
| 103 | $aOrders[$row['parent_field_id']] = $aChildren; | 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 | $aTemplateData = array( | 131 | $aTemplateData = array( |
| 106 | "context" => &$this, | 132 | "context" => &$this, |
| 107 | "fieldset_id" => $fieldset_id, | 133 | "fieldset_id" => $fieldset_id, |
| 108 | "ordering" => $aOrders, | 134 | "ordering" => $aOrders, |
| 109 | - "aFields" => $aFields, | 135 | + "aFields" => $aOrderedFields, |
| 110 | "iMasterFieldId" => $oFieldset->getMasterFieldId(), | 136 | "iMasterFieldId" => $oFieldset->getMasterFieldId(), |
| 111 | ); | 137 | ); |
| 112 | return $oTemplate->render($aTemplateData); | 138 | return $oTemplate->render($aTemplateData); |
| @@ -126,7 +152,8 @@ class ManageConditionalDispatcher extends KTAdminDispatcher { | @@ -126,7 +152,8 @@ class ManageConditionalDispatcher extends KTAdminDispatcher { | ||
| 126 | * FIXME we fake it here with nested arrays... | 152 | * FIXME we fake it here with nested arrays... |
| 127 | */ | 153 | */ |
| 128 | $oFieldset =& KTFieldset::get($fieldset_id); | 154 | $oFieldset =& KTFieldset::get($fieldset_id); |
| 129 | - $aFields =& $oFieldset->getFields(); | 155 | + $aFields =& $oFieldset->getFields(); |
| 156 | + | ||
| 130 | $this->aBreadcrumbs[] = array( | 157 | $this->aBreadcrumbs[] = array( |
| 131 | 'url' => KTUtil::ktLink('admin.php','documents/fieldmanagement','action=edit&fFieldsetId=' . $oFieldset->getId()), | 158 | 'url' => KTUtil::ktLink('admin.php','documents/fieldmanagement','action=edit&fFieldsetId=' . $oFieldset->getId()), |
| 132 | 'name' => $oFieldset->getName() | 159 | 'name' => $oFieldset->getName() |
| @@ -149,12 +176,33 @@ class ManageConditionalDispatcher extends KTAdminDispatcher { | @@ -149,12 +176,33 @@ class ManageConditionalDispatcher extends KTAdminDispatcher { | ||
| 149 | $aOrders[$row['parent_field_id']] = $aChildren; | 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 | $this->oPage->setBreadcrumbDetails(_kt('Manage complex conditional')); | 200 | $this->oPage->setBreadcrumbDetails(_kt('Manage complex conditional')); |
| 153 | $aTemplateData = array( | 201 | $aTemplateData = array( |
| 154 | "context" => &$this, | 202 | "context" => &$this, |
| 155 | "fieldset_id" => $fieldset_id, | 203 | "fieldset_id" => $fieldset_id, |
| 156 | "ordering" => $aOrders, | 204 | "ordering" => $aOrders, |
| 157 | - "aFields" => $aFields, | 205 | + "aFields" => $aOrderedFields, |
| 158 | "iMasterFieldId" => $oFieldset->getMasterFieldId(), | 206 | "iMasterFieldId" => $oFieldset->getMasterFieldId(), |
| 159 | ); | 207 | ); |
| 160 | return $oTemplate->render($aTemplateData); | 208 | return $oTemplate->render($aTemplateData); |
templates/ktcore/metadata/conditional/editsimple.smarty
| @@ -95,7 +95,7 @@ refresh the page.{/i18n}</p> | @@ -95,7 +95,7 @@ refresh the page.{/i18n}</p> | ||
| 95 | <p class="inactivity_message">{i18n}This field is not controlled by the currently active group.{/i18n}</p> | 95 | <p class="inactivity_message">{i18n}This field is not controlled by the currently active group.{/i18n}</p> |
| 96 | <div class="lookup_items"> | 96 | <div class="lookup_items"> |
| 97 | <select class="item_list"> | 97 | <select class="item_list"> |
| 98 | - {foreach from=$oField->getValues() item=oMetaData} | 98 | + {foreach from=$oField->getEnabledValues() item=oMetaData} |
| 99 | <option value="{$oMetaData->getId()}">{$oMetaData->getName()|escape}</option> | 99 | <option value="{$oMetaData->getId()}">{$oMetaData->getName()|escape}</option> |
| 100 | {/foreach} | 100 | {/foreach} |
| 101 | </select> | 101 | </select> |
templates/ktcore/metadata/editFieldset.smarty
| @@ -25,21 +25,6 @@ | @@ -25,21 +25,6 @@ | ||
| 25 | {$oWidget->render()} | 25 | {$oWidget->render()} |
| 26 | {/foreach} | 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 | <div class="form_actions"> | 28 | <div class="form_actions"> |
| 44 | <input type="submit" name="submit" value="{i18n}Change{/i18n}" /> | 29 | <input type="submit" name="submit" value="{i18n}Change{/i18n}" /> |
| 45 | </div> | 30 | </div> |
| @@ -65,7 +50,16 @@ field can depend on the user's selections for the others.{/i18n} | @@ -65,7 +50,16 @@ field can depend on the user's selections for the others.{/i18n} | ||
| 65 | field can depend on the user's selections for the others.{/i18n} | 50 | field can depend on the user's selections for the others.{/i18n} |
| 66 | </p> | 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 | {if $oFieldset->getIsConditional() } | 64 | {if $oFieldset->getIsConditional() } |
| 71 | 65 | ||
| @@ -75,6 +69,8 @@ field can depend on the user's selections for the others.{/i18n} | @@ -75,6 +69,8 @@ field can depend on the user's selections for the others.{/i18n} | ||
| 75 | <input type="submit" name="submit" value="{i18n}Manage conditional{/i18n}" /> | 69 | <input type="submit" name="submit" value="{i18n}Manage conditional{/i18n}" /> |
| 76 | </form> | 70 | </form> |
| 77 | 71 | ||
| 72 | +<br /> | ||
| 73 | + | ||
| 78 | <form action="{$smarty.server.PHP_SELF}" method="POST"> | 74 | <form action="{$smarty.server.PHP_SELF}" method="POST"> |
| 79 | <input type="hidden" name="fFieldsetId" value="{$oFieldset->getId()}" /> | 75 | <input type="hidden" name="fFieldsetId" value="{$oFieldset->getId()}" /> |
| 80 | <input type="hidden" name="action" value="removeConditional" /> | 76 | <input type="hidden" name="action" value="removeConditional" /> |