⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bulkaction.php

📁 PHP 知识管理系统(基于树结构的知识管理系统), 英文原版的PHP源码。
💻 PHP
📖 第 1 页 / 共 2 页
字号:

        foreach($this->oActiveEntityList->getDocumentIds() as $iId) {
            $oDocument =& Document::get($iId);
            if(!PEAR::isError($oDocument)) {
                $sName = $oDocument->getName();
            } else {
                $sName = _kt('Error fetching document name');
            }

            $res = $this->perform_action($oDocument);

            //check for shortcut notice
            $notice = null;
            if($oDocument->isSymbolicLink()){
            	$notice = _kt("Shortcut");
            }

            if(PEAR::isError($res)) {
                $this->aActionResults['documents'][] = array($sName, $res->getMessage(), $notice);
            } else {
                $this->aActionResults['documents'][] = array($sName, _kt('Success'), $notice);
            }
        }

        foreach($this->oActiveEntityList->getFolderIds() as $iId) {
            $oFolder =& Folder::get($iId);
            if(!PEAR::isError($oFolder)) {
                $sName = $oFolder->getName();
            } else {
                $sName = _kt('Error fetching folder name');
            }

            $res = $this->perform_action($oFolder);

        	//check for shortcut notice
            $notice = null;
            if($oFolder->isSymbolicLink()){
            	$notice = _kt("Shortcut");
            }

            if(PEAR::isError($res)) {
                $this->aActionResults['folders'][] = array($sName, $res->getMessage(), $notice);
            } else {
                $this->aActionResults['folders'][] = array($sName, _kt('Success'), $notice);
            }
        }
    }



    // list persistance
    // fetch existing lists
    function get_lists() {
        $this->oEntityList = KTEntityList::retrieveList(KTUtil::arrayGet($_REQUEST, 'fListCode', null));
        $this->oActiveEntityList = KTEntityList::retrieveList(KTUtil::arrayGet($_REQUEST, 'fActiveListCode', null));
        if(PEAR::isError($this->oActiveEntityList)) {
            $this->oActiveEntityList = null;
        }
    }

    // persist
    function store_lists() {
        $this->persistParams(array('fListCode', 'fActiveListCode', 'fFolderId', 'fReturnData', 'fReturnAction'));
    }

    /**
     * Get the return url based on the return action and data
     */
    function getReturnUrl()
    {
        $sReturnAction = $_REQUEST['fReturnAction'];
        $sReturnData = $_REQUEST['fReturnData'];
        $sAction = 'main';
        $qs = '';

        switch ($sReturnAction){
            case 'browse':
                $sReturnData = (empty($sReturnData)) ? $_REQUEST['fFolderId'] : $sReturnData;
                $sTargetUrl = KTBrowseUtil::getUrlForFolder(Folder::get($sReturnData));
                break;
            case 'simpleSearch':
                $sTargetUrl = KTBrowseUtil::getSimpleSearchBaseUrl();
                $extra = 'fSearchableText='.$sReturnData;
                break;
            case 'booleanSearch':
                $sTargetUrl = KTBrowseUtil::getBooleanSearchBaseUrl();
                $sAction = 'performSearch';
                $extra = 'boolean_search_id='.$sReturnData;
                break;
            case 'search2':
                $sTargetUrl = KTBrowseUtil::getSearchResultURL();
                $sAction = 'searchResults';
                break;
            default:
                $sTargetUrl = $sReturnAction;
                $sAction = '';
        }

        $qs = (!empty($sAction))? 'action='.$sAction : '';
        $qs .= (!empty($extra))? '&'.$extra : '';
        $sTargetUrl = KTUtil::addQueryString($sTargetUrl, $qs);

        return $sTargetUrl;
    }

    // forms
    // form to list the entites after checking each one
    function form_listing() {
        $sListCode = $this->oEntityList->getCode();
        $sActiveListCode = $this->oActiveEntityList->getCode();

        $sTargetUrl = $this->getReturnUrl();

        $oForm = new KTForm;
        $oForm->setOptions(array(
            'identifier' => 'ktcore.actions.bulk.listing.form',
            'submit_label' => _kt('Continue'),
            'targeturl' => $this->getURL(),
            'action' => 'collectinfo',
            'fail_action' => 'main',
            'cancel_url' => $sTargetUrl,
            'noframe' => true,
            'extraargs' => array('fListCode' => $sListCode,
                                 'fActiveListCode' => $sActiveListCode,
                                 'fFolderId' => $this->oFolder->getId(),
                                 'fReturnAction' => KTUtil::arrayGet($_REQUEST, 'fReturnAction'),
                                 'fReturnData' => KTUtil::arrayGet($_REQUEST, 'fReturnData'),
                                 ),
            'context' => $this,
        ));
        return $oForm;
    }

    // form to show on action completion, and list results
    function form_complete() {
        $sReturnAction = KTUtil::arrayGet($_REQUEST, 'fReturnAction');
        $sReturnData = KTUtil::arrayGet($_REQUEST, 'fReturnData');
        $sAction = 'main';

        switch ($sReturnAction){
            case 'browse':
                $sReturnData = (empty($sReturnData)) ? $_REQUEST['fFolderId'] : $sReturnData;
                $sTargetUrl = KTBrowseUtil::getUrlForFolder(Folder::get($sReturnData));
                break;
            case 'simpleSearch': // do we use this?
                $sTargetUrl = KTBrowseUtil::getSimpleSearchBaseUrl();
                $extraargs = array('fSearchableText'=>$sReturnData);
                break;
            case 'booleanSearch': // do we use this?
                $sTargetUrl = KTBrowseUtil::getBooleanSearchBaseUrl();
                $sAction = 'performSearch';
                $extraargs = array('boolean_search_id'=>$sReturnData);
                break;
            case 'search2':
                $sTargetUrl = KTBrowseUtil::getSearchResultURL();
                $sAction = 'refresh';
                break;
            default:
                $sTargetUrl = $sReturnAction;
                $sAction = '';
        }

        $oForm = new KTForm;
        $oForm->setOptions(array(
            'identifier' => 'ktcore.actions.bulk.complete.form',
            'submit_label' => _kt('Return'),
            'targeturl' => $sTargetUrl,
            'context' => $this,
            'action' => $sAction,
            'extraargs' => $extraargs,
            'noframe' => true,
        ));
        return $oForm;
    }


    // main entry point - checks the entity list and displays lists
    function do_main() {
        // get entities (using the checkboxes atm)
        $aFolders = KTUtil::arrayGet($_REQUEST, 'selection_f' , array());
        $aDocuments = KTUtil::arrayGet($_REQUEST, 'selection_d' , array());
        $this->oEntityList = new KTEntityList($aDocuments, $aFolders);

        // gives us $this->aFailed
        $iActiveCount = $this->check_entities();

    	$oTemplating =& KTTemplating::getSingleton();
    	$oTemplate = $oTemplating->loadTemplate('ktcore/bulk_action_listing');

        $this->store_lists();

        return $oTemplate->render(array('context' => $this,
                                        'form' => $this->form_listing(),
                                        'failed' => $this->aFailed,
                                        'active' => $this->oActiveEntityList,
                                        'activecount' => $iActiveCount,
                                        'failedform' => $this->form_complete(),
                                        'folders' => $this->_getNames($this->oActiveEntityList->getFolderIds(), 'Folder'),
                                        'documents' => $this->_getNames($this->oActiveEntityList->getDocumentIds(), 'Document')));

    }

    // override to add a screen to get a reason, or whatever
    // remember to pass to perform action next, and call the super's method
    function do_collectinfo() {
        $this->store_lists();
        return $this->do_performaction();
    }

    // perform the action itself, and list results (completion action)
    function do_performaction() {
        $this->get_lists();
        $this->aPersistParams = array();
        $this->perform_action_on_list();

	$oTemplating =& KTTemplating::getSingleton();
	$oTemplate = $oTemplating->loadTemplate('ktcore/bulk_action_complete');
        return $oTemplate->render(array('context' => $this,
                                        'list' => $this->aActionResults,
                                        'form' => $this->form_complete()));
    }






    // main overrides

    // override to do the actual action, on an individual entity
    function perform_action($oEntity) {
        return PEAR::raiseError(_kt('Action component not implemented'));
    }

    // check an individual entity - this should be overrided with additional
    // checks required for the specific action, but should always call its
    // parent implementation
    function check_entity($oEntity) {
        $oPermission =& KTPermission::getByName($this->_sPermission);
        if(PEAR::isError($oPermission)) {
            return true;
        }

        // basic document checks

        // TODO: check if this is appropriate
        //       should probably store the 'equivalent' action (ie. document.delete)
        //       and check that, rather than add a new list of actions to the workflow
        //       section
        if(is_a($oEntity, 'Document')) {
            if(!KTWorkflowUtil::actionEnabledForDocument($oEntity, $this->sName)) {
                return PEAR::raiseError(_kt('Action is disabled by workflow'));
            }
            $status = $oEntity->getStatusID();
            if($status==DELETED||$status==ARCHIVED) {
                return PEAR::raiseError(_kt('Document is archived or deleted'));
            }
        }

        // admin check
        if($this->bAllowInAdminMode) {
            if(KTBrowseUtil::inAdminMode($this->oUser, null)) {
                return true;
            }
        }

        if(!KTPermissionUtil::userHasPermissionOnItem($this->oUser, $oPermission, $oEntity)) {
            return PEAR::raiseError(_kt('You do not have the required permissions'));
        }

        return true;
    }


}

class KTBulkDocumentAction extends KTBulkAction {
    function check_entity($oEntity) {
        if(!is_a($oEntity, 'Document')) {
            return false;
        }
        return parent::check_entity($oEntity);
    }
}

class KTBulkFolderAction extends KTBulkAction {
    function check_entity($oEntity) {
        if(!is_a($oEntity, 'Folder')) {
            return false;
        }
        return parent::check_entity($oEntity);
    }
}



// util class for bulk actions

class KTBulkActionUtil {
    function getBulkActionInfo($slot = 'bulkaction') {
        $oRegistry =& KTActionRegistry::getSingleton();
        return $oRegistry->getActions($slot);
    }

    function getAllBulkActions($slot = 'bulkaction') {
        $aObjects = array();

        foreach (KTBulkActionUtil::getBulkActionInfo($slot) as $aAction) {
            list($sClassName, $sPath, $sName, $sPlugin) = $aAction;
            $oRegistry =& KTPluginRegistry::getSingleton();
            $oPlugin =& $oRegistry->getPlugin($sPlugin);
            if (!empty($sPath)) {
                require_once($sPath);
            }
            $aObjects[] = new $sClassName(null, null, $oPlugin);
        }
        return $aObjects;
    }

    function getBulkActionsByNames($aNames, $slot = 'bulkaction', $oUser = null) {
        $aObjects = array();
        foreach (KTBulkActionUtil::getBulkActionInfo($slot) as $aAction) {
            list($sClassName, $sPath, $sName, $sPlugin) = $aAction;
            $oRegistry =& KTPluginRegistry::getSingleton();
            $oPlugin =& $oRegistry->getPlugin($sPlugin);
            if (!in_array($sName, $aNames)) {
                continue;
            }
            if (!empty($sPath)) {
                require_once($sPath);
            }
            $aObjects[] = new $sClassName(null, $oUser, $oPlugin);
        }
        return $aObjects;
    }
}

?>

⌨️ 快捷键说明

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