Commit 082ef09f2497c683be44997dd57066f3266fb32d
1 parent
41d73e63
Implement the near-backend parts of simple conditional metadata
management. git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@3752 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
1 changed file
with
68 additions
and
6 deletions
presentation/lookAndFeel/knowledgeTree/administration/docfieldmanagement/conditional/ajaxSimpleConditionals.php
| 1 | <?php | 1 | <?php |
| 2 | -require_once("../../../../../config/dmsDefaults.php"); | 2 | +require_once("../../../../../../config/dmsDefaults.php"); |
| 3 | require_once(KT_DIR . "/presentation/Html.inc"); | 3 | require_once(KT_DIR . "/presentation/Html.inc"); |
| 4 | require_once(KT_LIB_DIR . "/templating/templating.inc.php"); | 4 | require_once(KT_LIB_DIR . "/templating/templating.inc.php"); |
| 5 | require_once(KT_LIB_DIR . "/documentmanagement/DocumentField.inc"); | 5 | require_once(KT_LIB_DIR . "/documentmanagement/DocumentField.inc"); |
| @@ -8,9 +8,12 @@ require_once(KT_LIB_DIR . "/util/ktutil.inc"); | @@ -8,9 +8,12 @@ require_once(KT_LIB_DIR . "/util/ktutil.inc"); | ||
| 8 | require_once(KT_LIB_DIR . "/dispatcher.inc.php"); | 8 | require_once(KT_LIB_DIR . "/dispatcher.inc.php"); |
| 9 | $sectionName = "Administration"; | 9 | $sectionName = "Administration"; |
| 10 | require_once(KT_DIR . "/presentation/webpageTemplate.inc"); | 10 | require_once(KT_DIR . "/presentation/webpageTemplate.inc"); |
| 11 | + | ||
| 11 | require_once(KT_LIB_DIR . "/metadata/fieldset.inc.php"); | 12 | require_once(KT_LIB_DIR . "/metadata/fieldset.inc.php"); |
| 13 | +require_once(KT_LIB_DIR . '/metadata/fieldbehaviour.inc.php'); | ||
| 12 | 14 | ||
| 13 | -class AjaxConditionalAdminDispatcher extends KTDispatcher { | 15 | +class AjaxConditionalAdminDispatcher extends KTStandardDispatcher { |
| 16 | + var $bAutomaticTransaction = true; | ||
| 14 | function do_main() { | 17 | function do_main() { |
| 15 | return "Ajax Error."; | 18 | return "Ajax Error."; |
| 16 | } | 19 | } |
| @@ -23,6 +26,8 @@ class AjaxConditionalAdminDispatcher extends KTDispatcher { | @@ -23,6 +26,8 @@ class AjaxConditionalAdminDispatcher extends KTDispatcher { | ||
| 23 | 26 | ||
| 24 | function do_storeRelationship() { | 27 | function do_storeRelationship() { |
| 25 | // handle the store, and DON'T give a 500 ;) does not act on the information. | 28 | // handle the store, and DON'T give a 500 ;) does not act on the information. |
| 29 | + global $default; | ||
| 30 | + $default->log->error(http_build_query($_REQUEST)); | ||
| 26 | $parent_field = KTUtil::arrayGet($_REQUEST, 'parent_field'); | 31 | $parent_field = KTUtil::arrayGet($_REQUEST, 'parent_field'); |
| 27 | $parent_lookup = KTUtil::arrayGet($_REQUEST, 'parent_lookup'); | 32 | $parent_lookup = KTUtil::arrayGet($_REQUEST, 'parent_lookup'); |
| 28 | $child_lookups = KTUtil::arrayGet($_REQUEST, 'child_lookups'); | 33 | $child_lookups = KTUtil::arrayGet($_REQUEST, 'child_lookups'); |
| @@ -33,31 +38,88 @@ class AjaxConditionalAdminDispatcher extends KTDispatcher { | @@ -33,31 +38,88 @@ class AjaxConditionalAdminDispatcher extends KTDispatcher { | ||
| 33 | // field_id:[lookup_id, lookup_id], | 38 | // field_id:[lookup_id, lookup_id], |
| 34 | // field_id:[lookup_id, lookup_id], | 39 | // field_id:[lookup_id, lookup_id], |
| 35 | // } | 40 | // } |
| 41 | + | ||
| 42 | + $oParentInstance = KTMetadataUtil::getOrCreateValueInstanceForLookup($parent_lookup); | ||
| 43 | + $iBehaviourId = $oParentInstance->getBehaviourId(); | ||
| 44 | + $oParentMetadata =& MetaData::get($oParentInstance->getFieldValueId()); | ||
| 45 | + if (is_null($iBehaviourId)) { | ||
| 46 | + $oBehaviour =& KTFieldBehaviour::createFromArray(array( | ||
| 47 | + 'name' => 'autoinstance' . $oParentInstance->getId(), | ||
| 48 | + 'humanname' => 'Auto instance' . $oParentMetadata->getName(), | ||
| 49 | + 'fieldid' => $oParentInstance->getFieldId(), | ||
| 50 | + )); | ||
| 51 | + } else { | ||
| 52 | + $oBehaviour =& KTFieldBehaviour::get($iBehaviourId); | ||
| 53 | + } | ||
| 54 | + if (PEAR::isError($oBehaviour)) { | ||
| 55 | + var_dump($oBehaviour); | ||
| 56 | + return $oBehaviour; | ||
| 57 | + } | ||
| 58 | + $iBehaviourId = $oBehaviour->getId(); | ||
| 59 | + $oParentInstance->setBehaviourId($iBehaviourId); | ||
| 60 | + $oParentInstance->update(); | ||
| 36 | 61 | ||
| 37 | - | ||
| 38 | - print "not implemented."; | ||
| 39 | - exit(1); | 62 | + $sTable = KTUtil::getTableName('field_behaviour_options'); |
| 63 | + $aOptions = array('noid' => true); | ||
| 64 | + | ||
| 65 | + foreach ($child_lookups as $iFieldId => $aLookups) { | ||
| 66 | + foreach ($aLookups as $iLookupId) { | ||
| 67 | + $oValueInstance =& KTMetadataUtil::getOrCreateValueInstanceForLookup($iLookupId); | ||
| 68 | + if (PEAR::isError($oValueInstance)) { | ||
| 69 | + var_dump($oValueInstance); | ||
| 70 | + return $oValueInstance; | ||
| 71 | + } | ||
| 72 | + $res = DBUtil::autoInsert($sTable, array( | ||
| 73 | + 'behaviour_id' => $iBehaviourId, | ||
| 74 | + 'field_id' => $iFieldId, | ||
| 75 | + 'instance_id' => $oValueInstance->getId(), | ||
| 76 | + ), $aOptions); | ||
| 77 | + if (PEAR::isError($res)) { | ||
| 78 | + var_dump($res); | ||
| 79 | + return $res; | ||
| 80 | + } | ||
| 81 | + } | ||
| 82 | + } | ||
| 40 | } | 83 | } |
| 41 | 84 | ||
| 42 | // do you want the fieldset_id here? | 85 | // do you want the fieldset_id here? |
| 43 | function do_updateActiveFields() { | 86 | function do_updateActiveFields() { |
| 87 | + global $default; | ||
| 88 | + $default->log->error(http_build_query($_REQUEST)); | ||
| 44 | $active_field = KTUtil::arrayGet($_REQUEST, 'active_field'); // field which is "active". | 89 | $active_field = KTUtil::arrayGet($_REQUEST, 'active_field'); // field which is "active". |
| 45 | $fieldset_id = KTUtil::arrayGet($_REQUEST, 'fieldset_id'); | 90 | $fieldset_id = KTUtil::arrayGet($_REQUEST, 'fieldset_id'); |
| 46 | 91 | ||
| 47 | // REMEMBER TO SET CONTENT-TYPE application/xml | 92 | // REMEMBER TO SET CONTENT-TYPE application/xml |
| 48 | $oTemplating =& KTTemplating::getSingleton(); | 93 | $oTemplating =& KTTemplating::getSingleton(); |
| 49 | $oTemplate =& $oTemplating->loadTemplate('ktcore/metadata/conditional/ajax_simple_update_active_fields'); | 94 | $oTemplate =& $oTemplating->loadTemplate('ktcore/metadata/conditional/ajax_simple_update_active_fields'); |
| 50 | - | 95 | + $oTemplate->setData(array( |
| 96 | + 'aFieldIds' => KTMetadataUtil::getChildFieldIds($active_field), | ||
| 97 | + )); | ||
| 98 | + header("Content-Type: application/xml"); | ||
| 99 | + print $oTemplate->render(); | ||
| 100 | + exit(0); | ||
| 51 | } | 101 | } |
| 52 | 102 | ||
| 53 | // do you want the fieldset_id here? | 103 | // do you want the fieldset_id here? |
| 54 | function do_updateActiveLookups() { | 104 | function do_updateActiveLookups() { |
| 105 | + global $default; | ||
| 106 | + $default->log->error(http_build_query($_REQUEST)); | ||
| 55 | $active_field = KTUtil::arrayGet($_REQUEST, 'active_field'); // field which is "active". | 107 | $active_field = KTUtil::arrayGet($_REQUEST, 'active_field'); // field which is "active". |
| 56 | $selected_lookup = KTUtil::arrayGet($_REQUEST, 'selected_lookup'); // selected value in said field. | 108 | $selected_lookup = KTUtil::arrayGet($_REQUEST, 'selected_lookup'); // selected value in said field. |
| 57 | 109 | ||
| 58 | // REMEMBER TO SET CONTENT-TYPE application/xml | 110 | // REMEMBER TO SET CONTENT-TYPE application/xml |
| 59 | $oTemplating =& KTTemplating::getSingleton(); | 111 | $oTemplating =& KTTemplating::getSingleton(); |
| 60 | $oTemplate =& $oTemplating->loadTemplate('ktcore/metadata/conditional/ajax_simple_update_active_lookups'); | 112 | $oTemplate =& $oTemplating->loadTemplate('ktcore/metadata/conditional/ajax_simple_update_active_lookups'); |
| 113 | + | ||
| 114 | + $aFieldLookups = KTMetadataUtil::getNextValuesForLookup($selected_lookup); | ||
| 115 | + | ||
| 116 | + $oTemplate->setData(array( | ||
| 117 | + 'aFieldLookups' => $aFieldLookups, | ||
| 118 | + )); | ||
| 119 | + | ||
| 120 | + header("Content-Type: application/xml"); | ||
| 121 | + print $oTemplate->render(); | ||
| 122 | + exit(0); | ||
| 61 | } | 123 | } |
| 62 | 124 | ||
| 63 | } | 125 | } |