Commit 8fe4a5ca4a6522a549d5d31a839819a42d99d567
1 parent
68a8d905
Make KTDispatcherValidation a proper class, not a utility class. Each
Dispatcher object has a DispatcherValidation object instantiated for it. git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@3749 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
1 changed file
with
39 additions
and
27 deletions
lib/validation/dispatchervalidation.inc.php
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | - | |
| 4 | 3 | class KTDispatcherValidation { |
| 5 | - function &validateFolder (&$this, $iId, $aOptions = null) { | |
| 6 | - return KTDispatcherValidation::validateEntity($this, 'Folder', $iId, $aOptions); | |
| 4 | + function KTDispatcherValidation(&$oDispatcher) { | |
| 5 | + $this->oDispatcher =& $oDispatcher; | |
| 6 | + } | |
| 7 | + | |
| 8 | + function &validateFolder ($iId, $aOptions = null) { | |
| 9 | + return $this->validateEntity('Folder', $iId, $aOptions); | |
| 7 | 10 | } |
| 8 | 11 | |
| 9 | - function &validatePermissionByName (&$this, $iId, $aOptions = null) { | |
| 10 | - KTUtil::meldOptions($aOptions, array( | |
| 12 | + function &validateDocument ($iId, $aOptions = null) { | |
| 13 | + return $this->validateEntity('Document', $iId, $aOptions); | |
| 14 | + } | |
| 15 | + | |
| 16 | + function &validatePermissionByName ($iId, $aOptions = null) { | |
| 17 | + $aOptions = KTUtil::meldOptions($aOptions, array( | |
| 11 | 18 | 'method' => 'getByName', |
| 12 | 19 | )); |
| 13 | - return KTDispatcherValidation::validateEntity($this, 'KTPermission', $iId, $aOptions); | |
| 20 | + return $this->validateEntity('KTPermission', $iId, $aOptions); | |
| 14 | 21 | } |
| 15 | 22 | |
| 16 | - function userHasPermissionOnItem(&$this, $oUser, $oPermission, $oItem, $aOptions) { | |
| 23 | + function userHasPermissionOnItem($oUser, $oPermission, $oItem, $aOptions = null) { | |
| 17 | 24 | require_once(KT_LIB_DIR . '/permissions/permissionutil.inc.php'); |
| 18 | 25 | if (KTPermissionUtil::userHasPermissionOnItem($oUser, $oPermission, $oItem)) { |
| 19 | 26 | return; |
| 20 | 27 | } |
| 21 | - $this->errorPage(_("Insufficient permissions to perform action")); | |
| 28 | + $this->oDispatcher->errorPage(_("Insufficient permissions to perform action")); | |
| 22 | 29 | } |
| 23 | 30 | |
| 24 | - function &validateEntity(&$this, $entity_name, $iId, $aOptions = null) { | |
| 31 | + function &validateEntity($entity_name, $iId, $aOptions = null) { | |
| 25 | 32 | $aOptions = (array)$aOptions; |
| 26 | 33 | |
| 27 | 34 | $aFunc = array($entity_name, KTUtil::arrayGet($aOptions, 'method', 'get')); |
| 28 | 35 | $oEntity =& call_user_func($aFunc, $iId); |
| 29 | 36 | if (PEAR::isError($oEntity) || ($oEntity === false)) { |
| 30 | - $this->errorPage(sprintf("Invalid identifier provided for: %s", $entity_name)); | |
| 37 | + $this->oDispatcher->errorPage(sprintf("Invalid identifier provided for: %s", $entity_name)); | |
| 31 | 38 | } |
| 32 | 39 | return $oEntity; |
| 33 | 40 | } |
| 34 | 41 | |
| 35 | - function notError(&$this, &$res, $aOptions = null) { | |
| 42 | + function notError(&$res, $aOptions = null) { | |
| 36 | 43 | $aOptions = (array)$aOptions; |
| 37 | 44 | if (PEAR::isError($res)) { |
| 38 | 45 | $aOptions = KTUTil::meldOptions($aOptions, array( |
| 39 | 46 | 'exception' => $res, |
| 40 | 47 | )); |
| 41 | - KTDispatcherValidation::handleError($this, $aOptions); | |
| 48 | + $this->handleError($aOptions); | |
| 42 | 49 | } |
| 43 | 50 | } |
| 44 | 51 | |
| 45 | - function notErrorFalse(&$this, &$res, $aOptions = null) { | |
| 52 | + function notErrorFalse(&$res, $aOptions = null) { | |
| 46 | 53 | $aOptions = (array)$aOptions; |
| 47 | 54 | if (PEAR::isError($res) || ($res === false)) { |
| 48 | 55 | $aOptions = KTUTil::meldOptions($aOptions, array( |
| 49 | 56 | 'exception' => $res, |
| 50 | 57 | )); |
| 51 | - KTDispatcherValidation::handleError($this, $aOptions); | |
| 58 | + $this->handleError($aOptions); | |
| 52 | 59 | } |
| 53 | 60 | } |
| 54 | 61 | |
| 55 | - function handleError($this, $aOptions = null) { | |
| 62 | + function handleError($aOptions = null) { | |
| 56 | 63 | $aOptions = (array)$aOptions; |
| 57 | 64 | $aRedirectTo = KTUtil::arrayGet($aOptions, 'redirect_to'); |
| 58 | 65 | $oException = KTUtil::arrayGet($aOptions, 'exception'); |
| ... | ... | @@ -66,33 +73,38 @@ class KTDispatcherValidation { |
| 66 | 73 | } |
| 67 | 74 | if ($aRedirectTo) { |
| 68 | 75 | $aRealRedirectTo = array($aRedirectTo[0], $sMessage, KTUtil::arrayGet($aRedirectTo, 1)); |
| 69 | - call_user_func_array(array($this, 'errorRedirectTo'), $aRealRedirectTo); | |
| 76 | + call_user_func_array(array($this->oDispatcher, this, 'errorRedirectTo'), $aRealRedirectTo); | |
| 70 | 77 | } |
| 71 | - $this->errorPage($sMessage); | |
| 78 | + $this->oDispatcher->errorPage($sMessage); | |
| 72 | 79 | } |
| 73 | 80 | |
| 74 | - function &validateTemplate($this, $sTemplateName, $aOptions = null) { | |
| 81 | + function &validateTemplate($sTemplateName, $aOptions = null) { | |
| 75 | 82 | $oTemplating =& KTTemplating::getSingleton(); |
| 76 | 83 | $oTemplate =& $oTemplating->loadTemplate($sTemplateName); |
| 77 | 84 | $aOptions['message'] = KTUtil::arrayGet($aOptions, 'message', 'Failed to locate template'); |
| 78 | - KTDispatcherValidation::notError($this, $oTemplate, $aOptions); | |
| 85 | + $this->notError($oTemplate, $aOptions); | |
| 79 | 86 | return $oTemplate; |
| 80 | 87 | } |
| 81 | 88 | |
| 82 | - function &validateWorkflow($this, $iId, $aOptions = null) { | |
| 83 | - return KTDispatcherValidation::validateEntity($this, 'KTWorkflow', $iId, $aOptions); | |
| 89 | + function &validateWorkflow($iId, $aOptions = null) { | |
| 90 | + return $this->validateEntity('KTWorkflow', $iId, $aOptions); | |
| 91 | + } | |
| 92 | + | |
| 93 | + function &validateWorkflowState($iId, $aOptions = null) { | |
| 94 | + return $this->validateEntity('KTWorkflowState', $iId, $aOptions); | |
| 84 | 95 | } |
| 85 | 96 | |
| 86 | - function &validateWorkflowState($this, $iId, $aOptions = null) { | |
| 87 | - return KTDispatcherValidation::validateEntity($this, 'KTWorkflowState', $iId, $aOptions); | |
| 97 | + function &validateWorkflowTransition($iId, $aOptions = null) { | |
| 98 | + return $this->validateEntity('KTWorkflowTransition', $iId, $aOptions); | |
| 88 | 99 | } |
| 89 | 100 | |
| 90 | - function &validateWorkflowTransition($this, $iId, $aOptions = null) { | |
| 91 | - return KTDispatcherValidation::validateEntity($this, 'KTWorkflowTransition', $iId, $aOptions); | |
| 101 | + function &validatePermission($iId, $aOptions = null) { | |
| 102 | + return $this->validateEntity('KTPermission', $iId, $aOptions); | |
| 92 | 103 | } |
| 93 | 104 | |
| 94 | - function &validatePermission($this, $iId, $aOptions = null) { | |
| 95 | - return KTDispatcherValidation::validateEntity($this, 'KTPermission', $iId, $aOptions); | |
| 105 | + function &validateLookup($iId, $aOptions = null) { | |
| 106 | + require_once(KT_LIB_DIR . '/documentmanagement/MetaData.inc'); | |
| 107 | + return $this->validateEntity('MetaData', $iId, $aOptions); | |
| 96 | 108 | } |
| 97 | 109 | } |
| 98 | 110 | ... | ... |