ktworkflowtriggers.inc.php

来自「PHP 知识管理系统(基于树结构的知识管理系统), 英文原版的PHP源码。」· PHP 代码 · 共 671 行 · 第 1/2 页

PHP
671
字号
            return _kt('This trigger has no configuration.');
        }
        // the actual permissions are stored in the array.
        $perms = array();
        if (empty($this->aConfig) || is_null($this->aConfig['group_id'])) {
             return _kt('No group is required to perform this transition');
        }
        $oGroup = Group::get($this->aConfig['group_id']);
        if (PEAR::isError($oGroup)) {
            return _kt('The group required for this trigger has been deleted, so anyone can perform this action.');
        } else {
            return sprintf(_kt('The user must be a member of the group "<strong>%s</strong>".'), htmlentities($oGroup->getName(), ENT_NOQUOTES, 'UTF-8'));
        }
    }
}


class ConditionGuardTrigger extends KTWorkflowTrigger {
    var $sNamespace = 'ktcore.workflowtriggers.conditionguard';
    var $sFriendlyName;
    var $sDescription;
    var $oTriggerInstance;
    var $aConfig = array();

    // generic requirements - both can be true
    var $bIsGuard = true;
    var $bIsAction = false;

    function ConditionGuardTrigger() {
        $this->sFriendlyName = _kt('Conditional Restrictions');
        $this->sDescription = _kt('Prevents this transition from occuring if the condition specified is not met for the document.');
    }

    // override the allow transition hook.
    function allowTransition($oDocument, $oUser) {
        if (!$this->isLoaded()) {
            return true;
        }

        $iConditionId = $this->aConfig['condition_id'];
        $oCondition = KTSavedSearch::get($this->aConfig['condition_id']);
        if (PEAR::isError($oCondition)) {
            return true; // fail safe for cases where the role is deleted.
        }
        return KTSearchUtil::testConditionOnDocument($iConditionId, $oDocument);
    }

    function displayConfiguration($args) {
        // permissions
        $aKeyedConditions = array();
        $aConditions = KTSavedSearch::getConditions();
        foreach ($aConditions as $oCondition) { $aKeyedConditions[$oCondition->getId()] = $oCondition->getName(); }

        $oTemplating =& KTTemplating::getSingleton();
		$oTemplate = $oTemplating->loadTemplate('ktcore/workflowtriggers/condition');
		$aTemplateData = array(
              'context' => $this,
              'conditions' => $aKeyedConditions,
              'current_condition' => KTUtil::arrayGet($this->aConfig, 'condition_id'),
              'args' => $args,
		);
		return $oTemplate->render($aTemplateData);
    }

    function saveConfiguration() {
        $condition_id = KTUtil::arrayGet($_REQUEST, 'condition_id', null);
        $oCondition = KTSavedSearch::get($condition_id);
        if (PEAR::isError($oCondition)) {
            // silenty ignore
            $condition_id = null;
            // $_SESSION['ktErrorMessages'][] = _kt('Unable to use the group you specified.');
        }

        $config = array();
        $config['condition_id'] = $condition_id;

        $this->oTriggerInstance->setConfig($config);
        $res = $this->oTriggerInstance->update();

        return $res;
    }

    function getConfigDescription() {
        if (!$this->isLoaded()) {
            return _kt('This trigger has no configuration.');
        }
        // the actual permissions are stored in the array.
        $perms = array();
        if (empty($this->aConfig) || is_null($this->aConfig['condition_id'])) {
             return _kt('No condition must be fulfilled before this transition becomes available.');
        }
        $oCondition = KTSavedSearch::get($this->aConfig['condition_id']);
        if (PEAR::isError($oCondition)) {
            return _kt('The condition required for this trigger has been deleted, so it is always available.');
        } else {
            return sprintf(_kt('The document must match condition "<strong>%s</strong>".'), htmlentities($oCondition->getName(), ENT_NOQUOTES, 'UTF-8'));
        }
    }
}


class BaseCopyActionTrigger extends KTWorkflowTrigger {
    var $sNamespace;
    var $sFriendlyName;
    var $sDescription;
    var $oTriggerInstance;
    var $aConfig = array();

    // generic requirements - both can be true
    var $bIsGuard = false;
    var $bIsAction = true;

    var $isCopy;

    function BaseCopyActionTrigger($namespace, $friendlyName, $description, $isCopy) {
    	$this->sNamespace = $namespace;
    	$this->sFriendlyName = $friendlyName;
    	$this->sDescription = $description;
    	$this->isCopy = $isCopy;
    }

    // perform more expensive checks -before- performTransition.
    function precheckTransition($oDocument, $oUser) {
        $iFolderId = KTUtil::arrayGet($this->aConfig, 'folder_id');
        $oFolder = Folder::get($iFolderId);
        if (PEAR::isError($oFolder)) {
        	if ($this->isCopy)
            	return PEAR::raiseError(_kt('The folder to which this document should be copied does not exist.  Cancelling the transition - please contact a system administrator.'));
            else
	            return PEAR::raiseError(_kt('The folder to which this document should be moved does not exist.  Cancelling the transition - please contact a system administrator.'));
        }

        return true;
    }

    function performTransition($oDocument, $oUser) {

        $iFolderId = KTUtil::arrayGet($this->aConfig, 'folder_id');
        $oToFolder = Folder::get($iFolderId);
        if (PEAR::isError($oFolder)) {
        	if ($this->isCopy)
	            return PEAR::raiseError(_kt('The folder to which this document should be copied does not exist.  Cancelling the transition - please contact a system administrator.'));
            else
            	return PEAR::raiseError(_kt('The folder to which this document should be moved does not exist.  Cancelling the transition - please contact a system administrator.'));
        }

        if ($this->isCopy)
        	return KTDocumentUtil::copy($oDocument, $oToFolder);
        else
	        return KTDocumentUtil::move($oDocument, $oToFolder, $oUser);
    }

    function displayConfiguration($args) {
        $oTemplating =& KTTemplating::getSingleton();
		$oTemplate = $oTemplating->loadTemplate('ktcore/workflowtriggers/moveaction');

        require_once(KT_LIB_DIR . '/browse/DocumentCollection.inc.php');
        require_once(KT_LIB_DIR . '/browse/columnregistry.inc.php');

        $collection = new AdvancedCollection;
        $oColumnRegistry = KTColumnRegistry::getSingleton();
        $aColumns = array();
        $aColumns[] = $oColumnRegistry->getColumn('ktcore.columns.singleselection');
        $aColumns[] = $oColumnRegistry->getColumn('ktcore.columns.title');

        $collection->addColumns($aColumns);

        $aOptions = $collection->getEnvironOptions(); // extract data from the environment


        $qsFrag = array();
        foreach ($args as $k => $v) {
            if ($k == 'action') { $v = 'editactiontrigger'; } // horrible hack - we really need iframe embedding.
            $qsFrag[] = sprintf('%s=%s',urlencode($k), urlencode($v));
        }
        $qs = implode('&',$qsFrag);
        $aOptions['result_url'] = KTUtil::addQueryStringSelf($qs);
        $aOptions['show_documents'] = false;

        $fFolderId = KTUtil::arrayGet($_REQUEST, 'fFolderId', KTUtil::arrayGet($this->aConfig, 'folder_id', 1));

		$oFolder = Folder::get($fFolderId);
        if(PEAR::isError($oFolder))
		{
			$iRoot = 1;
			$oFolder = Folder::get($iRoot);
			$fFolderId = 1;
			
		}

        $collection->setOptions($aOptions);
        $collection->setQueryObject(new BrowseQuery($fFolderId, $this->oUser));
        $collection->setColumnOptions('ktcore.columns.singleselection', array(
            'rangename' => 'folder_id',
            'show_folders' => true,
            'show_documents' => false,
        ));

        $collection->setColumnOptions('ktcore.columns.title', array(
            'direct_folder' => false,
            'folder_link' => $aOptions['result_url'],
        ));

		
        $aBreadcrumbs = array();
        $folder_path_names = $oFolder->getPathArray();
        $folder_path_ids = explode(',', $oFolder->getParentFolderIds());
        $folder_path_ids[] = $oFolder->getId();
        if ($folder_path_ids[0] == 0) {
            array_shift($folder_path_ids);
            array_shift($folder_path_names);
        }

        foreach (range(0, count($folder_path_ids) - 1) as $index) {
            $id = $folder_path_ids[$index];
            $qsFrag2 = $qsFrag;
            $qsFrag2[] = sprintf('fFolderId=%d', $id);
            $qs2 = implode('&',$qsFrag2);
            $url = KTUtil::addQueryStringSelf($qs2);
            $aBreadcrumbs[] = sprintf('<a href="%s">%s</a>', $url, htmlentities($folder_path_names[$index], ENT_NOQUOTES, 'UTF-8'));
        }

        $sBreadcrumbs = implode(' &raquo; ', $aBreadcrumbs);

		$aTemplateData = array(
              'context' => $this,
              'breadcrumbs' => $sBreadcrumbs,
              'collection' => $collection,
              'args' => $args,
		);
		return $oTemplate->render($aTemplateData);
    }

    function saveConfiguration() {
        $folder_id = KTUtil::arrayGet($_REQUEST, 'folder_id', null);
        $oFolder = Folder::get($folder_id);
        if (PEAR::isError($oFolder)) {
            // silenty ignore
            $folder_id = null;
        }

        $config = array();
        $config['folder_id'] = $folder_id;

        $this->oTriggerInstance->setConfig($config);
        $res = $this->oTriggerInstance->update();

        return $res;
    }

    function getConfigDescription() {
        if (!$this->isLoaded()) {
            return _kt('This trigger has no configuration.');
        }
        // the actual permissions are stored in the array.
        $perms = array();
        if (empty($this->aConfig) || is_null($this->aConfig['folder_id'])) {
             return _kt('<strong>This transition cannot be performed:  no folder has been selected.</strong>');
        }
        $oFolder = Folder::get($this->aConfig['folder_id']);
        if (PEAR::isError($oFolder)) {
            return _kt('<strong>The folder required for this trigger has been deleted, so the transition cannot be performed.</strong>');
        } else {
        	if ($this->isCopy)
	            return sprintf(_kt('The document will be copied to folder "<a href="%s">%s</a>".'), KTBrowseUtil::getUrlForFolder($oFolder), htmlentities($oFolder->getName(), ENT_NOQUOTES, 'UTF-8'));
            else
    	        return sprintf(_kt('The document will be moved to folder "<a href="%s">%s</a>".'), KTBrowseUtil::getUrlForFolder($oFolder), htmlentities($oFolder->getName(), ENT_NOQUOTES, 'UTF-8'));
        }
    }
}


// This is actually the move!
class CopyActionTrigger extends BaseCopyActionTrigger
{
	function CopyActionTrigger()
	{
		parent::BaseCopyActionTrigger(
			'ktcore.workflowtriggers.copyaction',
			_kt('Moves Document'),
			_kt('Moves the document to another folder.'),
			false
		);
	}
}

// This is actually the copy! Note that we keep this naming issue
// so that there are no complications with the upgrade path!
class MoveActionTrigger extends BaseCopyActionTrigger
{
	function MoveActionTrigger()
	{
		parent::BaseCopyActionTrigger(
			'ktcore.workflowtriggers.moveaction',
			_kt('Copies Document'),
			_kt('Copies the document to another folder.'),
			true
		);
	}
}


class CheckoutGuardTrigger extends KTWorkflowTrigger {
    var $sNamespace = 'ktcore.workflowtriggers.checkoutguard';
    var $sFriendlyName;
    var $sDescription;
    var $oTriggerInstance;
    var $aConfig = array();

    // generic requirements - both can be true
    var $bIsGuard = true;
    var $bIsAction = false;

    var $bIsConfigurable = false;

    function CheckoutGuardTrigger() {
        $this->sFriendlyName = _kt('Checkout Guard');
        $this->sDescription = _kt('Prevents a transition from being followed if the document is checked out..');
    }

    // override the allow transition hook.
    function allowTransition($oDocument, $oUser) {
        return (!$oDocument->getIsCheckedOut());
    }


    function getConfigDescription() {
        return _kt('This transition cannot be performed while the document is checked out.');
    }
}



?>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?