Commit 082ef09f2497c683be44997dd57066f3266fb32d

Authored by Neil Blakey-Milner
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
presentation/lookAndFeel/knowledgeTree/administration/docfieldmanagement/conditional/ajaxSimpleConditionals.php
1 1 <?php
2   -require_once("../../../../../config/dmsDefaults.php");
  2 +require_once("../../../../../../config/dmsDefaults.php");
3 3 require_once(KT_DIR . "/presentation/Html.inc");
4 4 require_once(KT_LIB_DIR . "/templating/templating.inc.php");
5 5 require_once(KT_LIB_DIR . "/documentmanagement/DocumentField.inc");
... ... @@ -8,9 +8,12 @@ require_once(KT_LIB_DIR . &quot;/util/ktutil.inc&quot;);
8 8 require_once(KT_LIB_DIR . "/dispatcher.inc.php");
9 9 $sectionName = "Administration";
10 10 require_once(KT_DIR . "/presentation/webpageTemplate.inc");
  11 +
11 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 17 function do_main() {
15 18 return "Ajax Error.";
16 19 }
... ... @@ -23,6 +26,8 @@ class AjaxConditionalAdminDispatcher extends KTDispatcher {
23 26  
24 27 function do_storeRelationship() {
25 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 31 $parent_field = KTUtil::arrayGet($_REQUEST, 'parent_field');
27 32 $parent_lookup = KTUtil::arrayGet($_REQUEST, 'parent_lookup');
28 33 $child_lookups = KTUtil::arrayGet($_REQUEST, 'child_lookups');
... ... @@ -33,31 +38,88 @@ class AjaxConditionalAdminDispatcher extends KTDispatcher {
33 38 // field_id:[lookup_id, lookup_id],
34 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 85 // do you want the fieldset_id here?
43 86 function do_updateActiveFields() {
  87 + global $default;
  88 + $default->log->error(http_build_query($_REQUEST));
44 89 $active_field = KTUtil::arrayGet($_REQUEST, 'active_field'); // field which is "active".
45 90 $fieldset_id = KTUtil::arrayGet($_REQUEST, 'fieldset_id');
46 91  
47 92 // REMEMBER TO SET CONTENT-TYPE application/xml
48 93 $oTemplating =& KTTemplating::getSingleton();
49 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 103 // do you want the fieldset_id here?
54 104 function do_updateActiveLookups() {
  105 + global $default;
  106 + $default->log->error(http_build_query($_REQUEST));
55 107 $active_field = KTUtil::arrayGet($_REQUEST, 'active_field'); // field which is "active".
56 108 $selected_lookup = KTUtil::arrayGet($_REQUEST, 'selected_lookup'); // selected value in said field.
57 109  
58 110 // REMEMBER TO SET CONTENT-TYPE application/xml
59 111 $oTemplating =& KTTemplating::getSingleton();
60 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 }
... ...