Commit 042186db4ddb13e3029fffaf89c2cf273e003d77
1 parent
900465b8
Add document actions and an action registry to register them.
git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@3560 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
2 changed files
with
132 additions
and
0 deletions
lib/actions/actionregistry.inc.php
0 → 100644
| 1 | +<?php | |
| 2 | + | |
| 3 | +class KTActionRegistry { | |
| 4 | + var $actions = array(); | |
| 5 | + // {{{ getSingleton | |
| 6 | + function &getSingleton () { | |
| 7 | + if (!KTUtil::arrayGet($GLOBALS, 'oKTActionRegistry')) { | |
| 8 | + $GLOBALS['oKTActionRegistry'] = new KTActionRegistry; | |
| 9 | + } | |
| 10 | + return $GLOBALS['oKTActionRegistry']; | |
| 11 | + } | |
| 12 | + // }}} | |
| 13 | + | |
| 14 | + function registerAction($slot, $name, $nsname, $path = "") { | |
| 15 | + $this->actions[$slot] = KTUtil::arrayGet($this->actions, $slot, array()); | |
| 16 | + $this->actions[$slot][$nsname] = array($name, $path); | |
| 17 | + } | |
| 18 | + | |
| 19 | + function getActions($slot) { | |
| 20 | + return $this->actions[$slot]; | |
| 21 | + } | |
| 22 | +} | |
| 23 | + | |
| 24 | +?> | ... | ... |
lib/actions/documentaction.inc.php
0 → 100644
| 1 | +<?php | |
| 2 | + | |
| 3 | +require_once(KT_LIB_DIR . '/actions/actionregistry.inc.php'); | |
| 4 | + | |
| 5 | +class KTDocumentAction { | |
| 6 | + var $sName; | |
| 7 | + var $sDescription; | |
| 8 | + var $sDisplayName; | |
| 9 | + | |
| 10 | + var $_sShowPermission; | |
| 11 | + var $_sDisablePermission; | |
| 12 | + | |
| 13 | + var $_bDisabled; | |
| 14 | + var $_sDisabledText = null; | |
| 15 | + | |
| 16 | + function KTDocumentAction($oDocument, $oUser) { | |
| 17 | + $this->oDocument = $oDocument; | |
| 18 | + $this->oUser = $oUser; | |
| 19 | + } | |
| 20 | + | |
| 21 | + function _show() { | |
| 22 | + if (is_null($this->_sShowPermission)) { | |
| 23 | + return true; | |
| 24 | + } | |
| 25 | + $oPermission =& KTPermission::getByName($this->_sShowPermission); | |
| 26 | + if (PEAR::isError($oPermission)) { | |
| 27 | + return true; | |
| 28 | + } | |
| 29 | + return KTPermissionUtil::userHasPermissionOnItem($this->oUser, $oPermission, $this->oDocument); | |
| 30 | + } | |
| 31 | + | |
| 32 | + function _disable() { | |
| 33 | + if ($this->_bDisabled === true) { | |
| 34 | + return true; | |
| 35 | + } | |
| 36 | + if (is_null($this->_sDisablePermission)) { | |
| 37 | + return false; | |
| 38 | + } | |
| 39 | + $oPermission =& KTPermission::getByName($this->_sDisablePermission); | |
| 40 | + if (PEAR::isError($oPermission)) { | |
| 41 | + return false; | |
| 42 | + } | |
| 43 | + $bResult = KTPermissionUtil::userHasPermissionOnItem($this->oUser, $oPermission, $this->oDocument); | |
| 44 | + if ($bResult === false) { | |
| 45 | + $this->_sDisabledText = "Insufficient privileges"; | |
| 46 | + } | |
| 47 | + return !$bResult; | |
| 48 | + } | |
| 49 | + | |
| 50 | + function getURL() { | |
| 51 | + return sprintf("/plugin.php/%s?fDocumentID=%d", $this->sName, $this->oDocument->getID()); | |
| 52 | + } | |
| 53 | + | |
| 54 | + function getInfo() { | |
| 55 | + if ($this->_show() === false) { | |
| 56 | + return null; | |
| 57 | + } | |
| 58 | + | |
| 59 | + $aInfo = array( | |
| 60 | + 'disabled' => $this->_disable(), | |
| 61 | + 'description' => $this->sDescription, | |
| 62 | + 'name' => $this->sDisplayName, | |
| 63 | + 'url' => generateLink($this->getURL(), ""), | |
| 64 | + 'disabled_text' => $this->_sDisabledText, | |
| 65 | + ); | |
| 66 | + return $this->customiseInfo($aInfo); | |
| 67 | + } | |
| 68 | + | |
| 69 | + function customiseInfo($aInfo) { | |
| 70 | + return $aInfo; | |
| 71 | + } | |
| 72 | +} | |
| 73 | + | |
| 74 | +class KTDocumentActionUtil { | |
| 75 | + function getDocumentActions() { | |
| 76 | + $oRegistry =& KTActionRegistry::getSingleton(); | |
| 77 | + return $oRegistry->getActions('documentaction'); | |
| 78 | + } | |
| 79 | + function &getDocumentActionsForDocument($oDocument, $oUser) { | |
| 80 | + $aObjects = array(); | |
| 81 | + foreach (KTDocumentActionUtil::getDocumentActions() as $aAction) { | |
| 82 | + list($sClassName, $sPath) = $aAction; | |
| 83 | + if (!empty($sPath)) { | |
| 84 | + // require_once(KT_DIR . | |
| 85 | + // Or something... | |
| 86 | + } | |
| 87 | + $aObjects[] =& new $sClassName($oDocument, $oUser); | |
| 88 | + } | |
| 89 | + return $aObjects; | |
| 90 | + } | |
| 91 | +} | |
| 92 | + | |
| 93 | +class KTBuiltInDocumentAction extends KTDocumentAction { | |
| 94 | + var $sBuildInAction; | |
| 95 | + function getURL() { | |
| 96 | + return sprintf("/control.php?action=%s&fDocumentID=%d", $this->sBuiltInAction, $this->oDocument->getID()); | |
| 97 | + } | |
| 98 | +} | |
| 99 | + | |
| 100 | +class KTBuiltInDocumentActionSingle extends KTBuiltInDocumentAction { | |
| 101 | + function getURL() { | |
| 102 | + return sprintf("/control.php?action=%s&fDocumentIDs[]=%d&fReturnDocumentID=%d", $this->sBuiltInAction, $this->oDocument->getID(), $this->oDocument->getID()); | |
| 103 | + } | |
| 104 | +} | |
| 105 | + | |
| 106 | +/* require_once(KT_DIR . '/plugins/ktcore/documentaction.inc.php'); */ | |
| 107 | + | |
| 108 | +?> | ... | ... |