ktbulkactions.php
来自「PHP 知识管理系统(基于树结构的知识管理系统), 英文原版的PHP源码。」· PHP 代码 · 共 1,282 行 · 第 1/4 页
PHP
1,282 行
}
return true;
}else if(is_a($oEntity, 'Folder')) {
$aDocuments = array();
$aChildFolders = array();
$oFolder = $oEntity;
// Get folder id
$sFolderId = $oFolder->getID();
// Get documents in folder
$sDocuments = $oFolder->getDocumentIDs($sFolderId);
$aDocuments = (!empty($sDocuments)) ? explode(',', $sDocuments) : array();
// Get all the folders within the folder
$sWhereClause = "parent_folder_ids = '{$sFolderId}' OR
parent_folder_ids LIKE '{$sFolderId},%' OR
parent_folder_ids LIKE '%,{$sFolderId},%' OR
parent_folder_ids LIKE '%,{$sFolderId}'";
$aChildFolders = $this->oFolder->getList($sWhereClause);
// Loop through folders and get documents
if(!empty($aChildFolders)){
foreach($aChildFolders as $oChild){
$sChildId = $oChild->getID();
$sChildDocs = $oChild->getDocumentIDs($sChildId);
if (PEAR::isError($res)) {
return false;
}
if(!empty($sChildDocs)){
$aChildDocs = explode(',', $sChildDocs);
$aDocuments = array_merge($aDocuments, $aChildDocs);
}
}
}
// Archive all documents
if(!empty($aDocuments)){
foreach($aDocuments as $sDocumentId){
$oDocument = Document::get($sDocumentId);
if(PEAR::isError($oDocument)){
return $oDocument;
}
$res = KTDocumentUtil::archive($oDocument, $this->sReason);
if(PEAR::isError($res)){
return $res;
}
}
}else {
return PEAR::raiseError(_kt('The folder contains no documents to archive.'));
}
return true;
}
}
}
class KTBrowseBulkExportAction extends KTBulkAction {
var $sName = 'ktcore.actions.bulk.export';
var $_sPermission = 'ktcore.permissions.read';
var $_bMutator = true;
var $bNotifications = true;
function getDisplayName() {
return _kt('Download All');
}
function check_entity($oEntity) {
if((!is_a($oEntity, 'Document')) && (!is_a($oEntity, 'Folder'))) {
return PEAR::raiseError(_kt('Document cannot be exported'));
}
//we need to do an extra folder permission check in case of a shortcut
if(is_a($oEntity,'Folder') && $oEntity->isSymbolicLink()){
if(!KTPermissionUtil::userHasPermissionOnItem($this->oUser, $this->_sPermission, $oEntity->getLinkedFolder())) {
return PEAR::raiseError(_kt('You do not have the required permissions'));
}
}
if(is_a($oEntity, 'Document')){
if(!KTWorkflowUtil::actionEnabledForDocument($oEntity, 'ktcore.actions.document.view')){
return PEAR::raiseError(_kt('Document cannot be exported as it is restricted by the workflow.'));
}
}
return parent::check_entity($oEntity);
}
function do_performaction() {
$folderName = $this->oFolder->getName();
$this->oZip = new ZipFolder($folderName);
$res = $this->oZip->checkConvertEncoding();
$folderurl = $this->getReturnUrl();
$sReturn = sprintf('<p>' . _kt('Return to the original <a href="%s">folder</a>') . "</p>\n", $folderurl);
if(PEAR::isError($res)){
$this->addErrorMessage($res->getMessage());
return $sReturn;
}
$this->startTransaction();
$oKTConfig =& KTConfig::getSingleton();
$this->bNoisy = $oKTConfig->get("tweaks/noisyBulkOperations");
$this->bNotifications = ($oKTConfig->get('export/enablenotifications', 'on') == 'on') ? true : false;
$result = parent::do_performaction();
$sExportCode = $this->oZip->createZipFile();
if(PEAR::isError($sExportCode)){
$this->addErrorMessage($sExportCode->getMessage());
return $sReturn;
}
$oTransaction = KTFolderTransaction::createFromArray(array(
'folderid' => $this->oFolder->getId(),
'comment' => "Bulk export",
'transactionNS' => 'ktstandard.transactions.bulk_export',
'userid' => $_SESSION['userID'],
'ip' => Session::getClientIP(),
));
$this->commitTransaction();
$url = KTUtil::addQueryStringSelf(sprintf('action=downloadZipFile&fFolderId=%d&exportcode=%s', $this->oFolder->getId(), $sExportCode));
$str = sprintf('<p>' . _kt('Your download will begin shortly. If you are not automatically redirected to your download, please click <a href="%s">here</a> ') . "</p>\n", $url);
$str .= sprintf('<p>' . _kt('Once your download is complete, click <a href="%s">here</a> to return to the original folder') . "</p>\n", $folderurl);
//$str .= sprintf("</div></div></body></html>\n");
$str .= sprintf('<script language="JavaScript">
function kt_bulkexport_redirect() {
document.location.href = "%s";
}
callLater(1, kt_bulkexport_redirect);
</script>', $url);
return $str;
}
function perform_action($oEntity) {
if(is_a($oEntity, 'Document')) {
$oDocument = $oEntity;
if($oDocument->isSymbolicLink()){
$oDocument->switchToLinkedCore();
}
if ($this->bNoisy) {
$oDocumentTransaction = new DocumentTransaction($oDocument, "Document part of bulk export", 'ktstandard.transactions.bulk_export', array());
$oDocumentTransaction->create();
}
// fire subscription alerts for the downloaded document - if global config is set
if($this->bNotifications){
$oSubscriptionEvent = new SubscriptionEvent();
$oFolder = Folder::get($oDocument->getFolderID());
$oSubscriptionEvent->DownloadDocument($oDocument, $oFolder);
}
$this->oZip->addDocumentToZip($oDocument);
}else if(is_a($oEntity, 'Folder')) {
$aDocuments = array();
$oFolder = $oEntity;
if($oFolder->isSymbolicLink()){
$oFolder = $oFolder->getLinkedFolder();
}
$sFolderId = $oFolder->getId();
$sFolderDocs = $oFolder->getDocumentIDs($sFolderId);
// Add folder to zip
$this->oZip->addFolderToZip($oFolder);
if(!empty($sFolderDocs)){
$aDocuments = explode(',', $sFolderDocs);
}
// Get all the folders within the current folder
$sWhereClause = "parent_folder_ids = '{$sFolderId}' OR
parent_folder_ids LIKE '{$sFolderId},%' OR
parent_folder_ids LIKE '%,{$sFolderId},%' OR
parent_folder_ids LIKE '%,{$sFolderId}'";
$aFolderList = $this->oFolder->getList($sWhereClause);
$aLinkingFolders = $this->getLinkingEntities($aFolderList);
$aFolderList = array_merge($aFolderList,$aLinkingFolders);
$aFolderObjects = array();
$aFolderObjects[$sFolderId] = $oFolder;
// Export the folder structure to ensure the export of empty directories
if(!empty($aFolderList)){
foreach($aFolderList as $k => $oFolderItem){
if($oFolderItem->isSymbolicLink()){
$oFolderItem = $oFolderItem->getLinkedFolder();
}
if(Permission::userHasFolderReadPermission($oFolderItem)){
// Get documents for each folder
$sFolderItemId = $oFolderItem->getID();
$sFolderItemDocs = $oFolderItem->getDocumentIDs($sFolderItemId);
if(!empty($sFolderItemDocs)){
$aFolderDocs = explode(',', $sFolderItemDocs);
$aDocuments = array_merge($aDocuments, $aFolderDocs);
}
$this->oZip->addFolderToZip($oFolderItem);
$aFolderObjects[$oFolderItem->getId()] = $oFolderItem;
}
}
}
// Add all documents to the export
if(!empty($aDocuments)){
foreach($aDocuments as $sDocumentId){
$oDocument = Document::get($sDocumentId);
if($oDocument->isSymbolicLink()){
$oDocument->switchToLinkedCore();
}
if(Permission::userHasDocumentReadPermission($oDocument)){
if(!KTWorkflowUtil::actionEnabledForDocument($oDocument, 'ktcore.actions.document.view')){
$this->addErrorMessage($oDocument->getName().': '._kt('Document cannot be exported as it is restricted by the workflow.'));
continue;
}
$sDocFolderId = $oDocument->getFolderID();
$oFolder = isset($aFolderObjects[$sDocFolderId]) ? $aFolderObjects[$sDocFolderId] : Folder::get($sDocFolderId);
if ($this->bNoisy) {
$oDocumentTransaction = new DocumentTransaction($oDocument, "Document part of bulk export", 'ktstandard.transactions.bulk_export', array());
$oDocumentTransaction->create();
}
// fire subscription alerts for the downloaded document
if($this->bNotifications){
$oSubscriptionEvent = new SubscriptionEvent();
$oSubscriptionEvent->DownloadDocument($oDocument, $oFolder);
}
$this->oZip->addDocumentToZip($oDocument, $oFolder);
}
}
}
}
return true;
}
function do_downloadZipFile() {
$sCode = $this->oValidator->validateString($_REQUEST['exportcode']);
$folderName = $this->oFolder->getName();
$this->oZip = new ZipFolder($folderName, $sCode);
$res = $this->oZip->downloadZipFile($sCode);
if(PEAR::isError($res)){
$this->addErrorMessage($res->getMessage());
$redirectUrl = $this->getReturnUrl();
redirect($redirectUrl);
}
exit(0);
}
}
class KTBrowseBulkCheckoutAction extends KTBulkAction {
var $sName = 'ktcore.actions.bulk.checkout';
var $_sPermission = 'ktcore.permissions.write';
var $_bMutator = true;
function getDisplayName() {
return _kt('Checkout');
}
function check_entity($oEntity) {
if(is_a($oEntity, 'Document')) {
if($oEntity->getImmutable())
{
return PEAR::raiseError(_kt('Document cannot be checked out as it is immutable'));
}
// Check that the document isn't already checked out
if ($oEntity->getIsCheckedOut()) {
$checkedOutUser = $oEntity->getCheckedOutUserID();
$sUserId = $_SESSION['userID'];
if($checkedOutUser != $sUserId){
$oCheckedOutUser = User::get($checkedOutUser);
return PEAR::raiseError($oEntity->getName().': '._kt('Document has already been checked out by ').$oCheckedOutUser->getName());
}
}
// Check that the checkout action isn't restricted for the document
if(!KTWorkflowUtil::actionEnabledForDocument($oEntity, 'ktcore.actions.document.checkout')){
return PEAR::raiseError($oEntity->getName().': '._kt('Checkout is restricted by the workflow state.'));
}
}else if(!is_a($oEntity, 'Folder')) {
return PEAR::raiseError(_kt('Document cannot be checked out'));
}
//we need to do an extra folder permission check in case of a shortcut
if(is_a($oEntity,'Folder') && $oEntity->isSymbolicLink()){
if(!KTPermissionUtil::userHasPermissionOnItem($this->oUser, $this->_sPermission, $oEntity->getLinkedFolder())) {
return PEAR::raiseError(_kt('You do not have the required permissions'));
}
}
return parent::check_entity($oEntity);
}
function form_collectinfo() {
$cancelUrl = $this->getReturnUrl();
$oForm = new KTForm;
$oForm->setOptions(array(
'identifier' => 'ktcore.actions.bulk.checkout.form',
'label' => _kt('Checkout Items'),
'submit_label' => _kt('Checkout'),
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?