Commit 38cd7e242e817ecf9b58d190ca80ed6c2fc97ba3
1 parent
54c2a572
Beginning implementation of conditional complex edit.
git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@3792 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
1 changed file
with
74 additions
and
6 deletions
presentation/lookAndFeel/knowledgeTree/administration/docfieldmanagement/conditional/ajaxComplexConditionals.php
| ... | ... | @@ -8,9 +8,12 @@ require_once(KT_LIB_DIR . "/util/ktutil.inc"); |
| 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"); | |
| 14 | +require_once(KT_LIB_DIR . "/metadata/valueinstance.inc.php"); | |
| 12 | 15 | |
| 13 | -class AjaxConditionalAdminDispatcher extends KTDispatcher { | |
| 16 | +class AjaxConditionalAdminDispatcher extends KTStandardDispatcher { | |
| 14 | 17 | function do_main() { |
| 15 | 18 | return "Ajax Error: no action specified."; |
| 16 | 19 | } |
| ... | ... | @@ -26,12 +29,31 @@ class AjaxConditionalAdminDispatcher extends KTDispatcher { |
| 26 | 29 | // get the list of free items for a given column, under a certain parent behaviour. |
| 27 | 30 | function do_getItemList() { |
| 28 | 31 | $parent_behaviour = KTUtil::arrayGet($_REQUEST, 'parent_behaviour'); |
| 29 | - $fieldset_id = KTUtil::arrayGet($_REQUEST, 'fieldset_id'); // | |
| 32 | + //$fieldset_id = KTUtil::arrayGet($_REQUEST, 'fieldset_id'); // | |
| 33 | + $oFieldset =& $this->oValidator->validateFieldset(KTUtil::arrayGet($_REQUEST, 'fieldset_id')); | |
| 30 | 34 | $field_id = KTUtil::arrayGet($_REQUEST, 'field_id'); |
| 35 | + $oField =& $this->oValidator->validateField(KTUtil::arrayGet($_REQUEST, 'field_id')); | |
| 31 | 36 | |
| 32 | 37 | header('Content-type: application/xml'); |
| 33 | 38 | $oTemplating =& KTTemplating::getSingleton(); |
| 34 | 39 | $oTemplate =& $oTemplating->loadTemplate('ktcore/metadata/conditional/ajax_complex_get_item_list'); |
| 40 | + | |
| 41 | + $sMetadataTable = KTUtil::getTableName('metadata'); | |
| 42 | + $sVITable = KTUtil::getTableName('field_value_instances'); | |
| 43 | + $aQuery = array( | |
| 44 | + "SELECT M.id AS id, M.name AS name FROM $sMetadataTable AS M LEFT JOIN $sVITable AS V ON M.id = V.field_value_id WHERE M.document_field_id = ? AND V.id IS NULL", | |
| 45 | + array($field_id), | |
| 46 | + ); | |
| 47 | + $aRows = DBUtil::getResultArray($aQuery); | |
| 48 | + $aValues = array(); | |
| 49 | + foreach ($aRows as $aRow) { | |
| 50 | + $aValues[$aRow['id']] = $aRow['name']; | |
| 51 | + } | |
| 52 | + $aData = array( | |
| 53 | + 'values' => $aValues, | |
| 54 | + ); | |
| 55 | + $oTemplate->setData($aData); | |
| 56 | + | |
| 35 | 57 | return $oTemplate->render(); |
| 36 | 58 | } |
| 37 | 59 | |
| ... | ... | @@ -39,31 +61,67 @@ class AjaxConditionalAdminDispatcher extends KTDispatcher { |
| 39 | 61 | $parent_behaviour = KTUtil::arrayGet($_REQUEST, 'parent_behaviour'); |
| 40 | 62 | $fieldset_id = KTUtil::arrayGet($_REQUEST, 'fieldset_id'); |
| 41 | 63 | $field_id = KTUtil::arrayGet($_REQUEST, 'field_id'); |
| 64 | + | |
| 65 | + $aBehaviours =& KTFieldBehaviour::getByField($field_id); | |
| 42 | 66 | |
| 43 | 67 | header('Content-type: application/xml'); |
| 44 | 68 | $oTemplating =& KTTemplating::getSingleton(); |
| 45 | 69 | $oTemplate =& $oTemplating->loadTemplate('ktcore/metadata/conditional/ajax_complex_get_behaviour_list'); |
| 70 | + $oTemplate->setData(array( | |
| 71 | + 'aBehaviours' => $aBehaviours, | |
| 72 | + )); | |
| 46 | 73 | return $oTemplate->render(); |
| 47 | 74 | } |
| 48 | 75 | |
| 49 | 76 | function do_getActiveFields() { |
| 77 | + $GLOBALS['default']->log->error(print_r($_REQUEST, true)); | |
| 50 | 78 | $parent_behaviour = KTUtil::arrayGet($_REQUEST, 'parent_behaviour'); |
| 51 | - $fieldset_id = KTUtil::arrayGet($_REQUEST, 'fieldset_id'); // | |
| 79 | + // $fieldset_id = KTUtil::arrayGet($_REQUEST, 'fieldset_id'); // | |
| 80 | + $oFieldset =& $this->oValidator->validateFieldset(KTUtil::arrayGet($_REQUEST, 'fieldset_id')); | |
| 81 | + | |
| 82 | + if (empty($parent_behaviour)) { | |
| 83 | + $aFieldIds = array($oFieldset->getMasterFieldId()); | |
| 84 | + } else { | |
| 85 | + $oBehaviour =& $this->oValidator->validateBehaviour($parent_behaviour); | |
| 86 | + $iActiveFieldId = $oBehaviour->getFieldId(); | |
| 87 | + $aFieldIds = KTMetadataUtil::getChildFieldIds($iActiveFieldId); | |
| 88 | + } | |
| 89 | + | |
| 90 | + $oTemplate =& $this->oValidator->validateTemplate('ktcore/metadata/conditional/ajax_complex_get_active_fields'); | |
| 91 | + $oTemplate->setData(array( | |
| 92 | + 'aFieldIds' => $aFieldIds, | |
| 93 | + )); | |
| 94 | + $GLOBALS['default']->log->error(print_r(KTMetadataUtil::getChildFieldIds($iActiveFieldId), true)); | |
| 52 | 95 | |
| 53 | 96 | header('Content-type: application/xml'); |
| 54 | - $oTemplating =& KTTemplating::getSingleton(); | |
| 55 | - $oTemplate =& $oTemplating->loadTemplate('ktcore/metadata/conditional/ajax_complex_get_active_fields'); | |
| 97 | + /// header('Content-type: text/plain'); | |
| 56 | 98 | return $oTemplate->render(); |
| 57 | 99 | } |
| 58 | 100 | |
| 59 | 101 | /** storage methods */ |
| 60 | 102 | function do_createBehaviourAndAssign() { |
| 103 | + $GLOBALS['default']->log->error(print_r($_REQUEST, true)); | |
| 104 | + $GLOBALS['default']->log->error(print_r($_SESSION, true)); | |
| 61 | 105 | $parent_behaviour = KTUtil::arrayGet($_REQUEST, 'parent_behaviour'); |
| 62 | 106 | $fieldset_id = KTUtil::arrayGet($_REQUEST, 'fieldset_id'); |
| 63 | 107 | $field_id = KTUtil::arrayGet($_REQUEST, 'field_id'); |
| 64 | 108 | $behaviour_name = KTUtil::arrayGet($_REQUEST, 'behaviour_name'); |
| 65 | 109 | $lookups_to_assign = KTUtil::arrayGet($_REQUEST, 'lookups_to_assign'); // array |
| 66 | - | |
| 110 | + | |
| 111 | + $oBehaviour =& KTFieldBehaviour::createFromArray(array( | |
| 112 | + 'name' => $behaviour_name, | |
| 113 | + 'humanname' => $behaviour_name, | |
| 114 | + 'fieldid' => $field_id, | |
| 115 | + )); | |
| 116 | + | |
| 117 | + foreach ($lookups_to_assign as $iLookupId) { | |
| 118 | + $res = $oValueInstance =& KTValueInstance::createFromArray(array( | |
| 119 | + 'fieldid' => $field_id, | |
| 120 | + 'behaviourid' => $oBehaviour->getId(), | |
| 121 | + 'fieldvalueid' => abs($iLookupId), | |
| 122 | + )); | |
| 123 | + } | |
| 124 | + | |
| 67 | 125 | header('Content-type: application/xml'); |
| 68 | 126 | $oTemplating =& KTTemplating::getSingleton(); |
| 69 | 127 | $oTemplate =& $oTemplating->loadTemplate('ktcore/metadata/conditional/ajax_complex_create_behaviour_and_assign'); |
| ... | ... | @@ -76,6 +134,16 @@ class AjaxConditionalAdminDispatcher extends KTDispatcher { |
| 76 | 134 | $field_id = KTUtil::arrayGet($_REQUEST, 'field_id'); |
| 77 | 135 | $behaviour_name = KTUtil::arrayGet($_REQUEST, 'behaviour_id'); |
| 78 | 136 | $lookups_to_assign = KTUtil::arrayGet($_REQUEST, 'lookups_to_assign'); // array |
| 137 | + | |
| 138 | + $oBehaviour =& $this->oValidator->validateBehaviour($parent_behaviour); | |
| 139 | + | |
| 140 | + foreach ($lookups_to_assign as $iLookupId) { | |
| 141 | + $res = $oValueInstance =& KTValueInstance::createFromArray(array( | |
| 142 | + 'fieldid' => $field_id, | |
| 143 | + 'behaviourid' => $oBehaviour->getId(), | |
| 144 | + 'fieldvalueid' => abs($iLookupId), | |
| 145 | + )); | |
| 146 | + } | |
| 79 | 147 | |
| 80 | 148 | header('Content-type: application/xml'); |
| 81 | 149 | $oTemplating =& KTTemplating::getSingleton(); | ... | ... |