Commit c4da14a4ba808c7b9041af79ed1d3ca9dd90b237
1 parent
2bd0b383
Add the ability to set the master field, and restrict the ordering of
fields such that only the master field or a field which is already attached to the master field can affect other fields. git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@3775 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
1 changed file
with
55 additions
and
3 deletions
presentation/lookAndFeel/knowledgeTree/administration/docfieldmanagement/documentFields.php
| ... | ... | @@ -210,17 +210,48 @@ class KTDocumentFieldDispatcher extends KTStandardDispatcher { |
| 210 | 210 | $oTemplating =& KTTemplating::getSingleton(); |
| 211 | 211 | $oTemplate =& $oTemplating->loadTemplate('ktcore/metadata/conditional/manageConditional'); |
| 212 | 212 | $oFieldset =& KTFieldset::get($_REQUEST['fFieldsetId']); |
| 213 | + $iMasterFieldId = $oFieldset->getMasterFieldId(); | |
| 214 | + if (!empty($iMasterFieldId)) { | |
| 215 | + $oMasterField =& DocumentField::get($iMasterFieldId); | |
| 216 | + if (PEAR::isError($oMasterField)) { | |
| 217 | + $oMasterField = null; | |
| 218 | + } | |
| 219 | + } else { | |
| 220 | + $oMasterField = null; | |
| 221 | + } | |
| 213 | 222 | $sTable = KTUtil::getTableName('field_orders'); |
| 214 | 223 | $aQuery = array( |
| 215 | 224 | "SELECT parent_field_id, child_field_id FROM $sTable WHERE fieldset_id = ?", |
| 216 | 225 | array($oFieldset->getId()) |
| 217 | 226 | ); |
| 218 | 227 | $aFieldOrders = DBUtil::getResultArray($aQuery); |
| 228 | + $aFields = $oFieldset->getFields(); | |
| 229 | + | |
| 230 | + $aFreeFieldIds = array(); | |
| 231 | + foreach ($aFields as $oField) { | |
| 232 | + $aFreeFieldIds[] = $oField->getId(); | |
| 233 | + } | |
| 234 | + $aParentFieldIds = array($oMasterField->getId()); | |
| 235 | + foreach ($aFieldOrders as $aRow) { | |
| 236 | + $aParentFieldIds[] = $aRow['child_field_id']; | |
| 237 | + } | |
| 238 | + $aParentFields = array(); | |
| 239 | + foreach (array_unique($aParentFieldIds) as $iId) { | |
| 240 | + $aParentFields[] =& DocumentField::get($iId); | |
| 241 | + } | |
| 242 | + $aFreeFields = array(); | |
| 243 | + foreach ($aFreeFieldIds as $iId) { | |
| 244 | + if (in_array($iId, $aParentFieldIds)) { | |
| 245 | + continue; | |
| 246 | + } | |
| 247 | + $aFreeFields[] =& DocumentField::get($iId); | |
| 248 | + } | |
| 219 | 249 | $oTemplate->setData(array( |
| 220 | 250 | 'oFieldset' => $oFieldset, |
| 221 | - 'free_fields' => $oFieldset->getFields(), | |
| 222 | - 'parent_fields' => $oFieldset->getFields(), | |
| 251 | + 'free_fields' => $aFreeFields, | |
| 252 | + 'parent_fields' => $aParentFields, | |
| 223 | 253 | 'aFieldOrders' => $aFieldOrders, |
| 254 | + 'oMasterField' => $oMasterField, | |
| 224 | 255 | )); |
| 225 | 256 | return $oTemplate; |
| 226 | 257 | } |
| ... | ... | @@ -230,13 +261,16 @@ class KTDocumentFieldDispatcher extends KTStandardDispatcher { |
| 230 | 261 | function do_orderFields() { |
| 231 | 262 | $oFieldset =& KTFieldset::get($_REQUEST['fFieldsetId']); |
| 232 | 263 | $aFreeFieldIds = $_REQUEST['fFreeFieldIds']; |
| 264 | + if (empty($aFreeFieldIds)) { | |
| 265 | + $this->errorRedirectTo('manageConditional', 'No children fields selected', 'fFieldsetId=' . $oFieldset->getId()); | |
| 266 | + } | |
| 233 | 267 | $iParentFieldId = $_REQUEST['fParentFieldId']; |
| 234 | 268 | if (in_array($aParentFieldId, $aFreeFieldIds)) { |
| 235 | 269 | $this->errorRedirectTo('manageConditional', 'Field cannot be its own parent field', 'fFieldsetId=' . $oFieldset->getId()); |
| 236 | 270 | } |
| 237 | 271 | foreach ($aFreeFieldIds as $iChildFieldId) { |
| 238 | 272 | $res = KTMetadataUtil::addFieldOrder($iParentFieldId, $iChildFieldId, $oFieldset); |
| 239 | - $this->oValidator->notError($this, $res, array( | |
| 273 | + $this->oValidator->notError($res, array( | |
| 240 | 274 | 'redirect_to' => array('manageConditional', 'fFieldsetId=' . $oFieldset->getId()), |
| 241 | 275 | 'message' => 'Error adding Fields', |
| 242 | 276 | )); |
| ... | ... | @@ -245,6 +279,24 @@ class KTDocumentFieldDispatcher extends KTStandardDispatcher { |
| 245 | 279 | exit(0); |
| 246 | 280 | } |
| 247 | 281 | // }}} |
| 282 | + | |
| 283 | + // {{{ | |
| 284 | + function do_setMasterField() { | |
| 285 | + $oFieldset =& $this->oValidator->validateFieldset($_REQUEST['fFieldsetId']); | |
| 286 | + $oField =& $this->oValidator->validateField($_REQUEST['fFieldId']); | |
| 287 | + | |
| 288 | + $res = KTMetadataUtil::removeFieldOrdering($oFieldset); | |
| 289 | + $oFieldset->setMasterFieldId($oField->getId()); | |
| 290 | + $res = $oFieldset->update(); | |
| 291 | + | |
| 292 | + $this->oValidator->notError($res, array( | |
| 293 | + 'redirect_to' => array('manageConditional', 'fFieldsetId=' . $oFieldset->getId()), | |
| 294 | + 'message' => 'Error setting master field', | |
| 295 | + )); | |
| 296 | + $this->successRedirectTo('manageConditional', 'Master field set', 'fFieldsetId=' . $oFieldset->getId()); | |
| 297 | + exit(0); | |
| 298 | + } | |
| 299 | + // }}} | |
| 248 | 300 | } |
| 249 | 301 | |
| 250 | 302 | $d =& new KTDocumentFieldDispatcher; | ... | ... |