ktdocumentactions.php
来自「PHP 知识管理系统(基于树结构的知识管理系统), 英文原版的PHP源码。」· PHP 代码 · 共 1,703 行 · 第 1/5 页
PHP
1,703 行
// FIXME agree on document-duplication rules re: naming, etc.
$this->startTransaction();
// now try update it.
$oNewDoc = KTDocumentUtil::copy($this->oDocument, $data['browse'], $sReason);
if (PEAR::isError($oNewDoc)) {
$this->errorRedirectTo('main', _kt('Failed to copy document: ') . $oNewDoc->getMessage(), sprintf('fDocumentId=%d&fFolderId=%d', $this->oDocument->getId(), $this->oFolder->getId()));
exit(0);
}
$oNewDoc->setName($name);
$oNewDoc->setFilename($filename);
$res = $oNewDoc->update();
if (PEAR::isError($res)) {
return $this->errorRedirectTo('main', _kt('Failed to copy document: ') . $res->getMessage(), sprintf('fDocumentId=%d&fFolderId=%d', $this->oDocument->getId(), $this->oFolder->getId()));
}
$this->commitTransaction();
$_SESSION['KTInfoMessage'][] = _kt('Document copied.');
controllerRedirect('viewDocument', 'fDocumentId=' . $oNewDoc->getId());
exit(0);
}
}
// }}}
// {{{ KTDocumentArchiveAction
class KTDocumentArchiveAction extends KTDocumentAction {
var $sName = 'ktcore.actions.document.archive';
var $_sShowPermission = 'ktcore.permissions.write';
var $_bMutator = true;
function getDisplayName() {
return _kt('Archive');
}
function getInfo() {
if ($this->oDocument->getIsCheckedOut()) {
return null;
}
return parent::getInfo();
}
function form_confirm() {
$oForm = new KTForm;
$oForm->setOptions(array(
'label' => _kt('Are you sure?'),
'description' => _kt('There are shortcuts linking to this document; archiving the document automatically will delete them. Would you like to continue?'),
'action' => 'main',
'fail_action' => 'main',
'cancel_url' => KTBrowseUtil::getUrlForDocument($this->oDocument),
'submit_label' => _kt('Archive Document'),
'context' => &$this,
));
return $oForm;
}
function form_main() {
$oForm = new KTForm;
$oForm->setOptions(array(
'label' => _kt('Archive Document'),
'action' => 'archive',
'fail_action' => 'main',
'cancel_url' => KTBrowseUtil::getUrlForDocument($this->oDocument),
'submit_label' => _kt('Archive Document'),
'context' => &$this,
));
$oForm->setWidgets(array(
array('ktcore.widgets.reason', array(
'label' => _kt('Reason'),
'description' => _kt('Please specify why you are archiving this document. Please bear in mind that you can use a maximum of <strong>250</strong> characters.'),
'name' => 'reason',
)),
));
$oForm->setValidators(array(
array('ktcore.validators.string', array(
'test' => 'reason',
'max_length' => 250,
'output' => 'reason',
)),
));
return $oForm;
}
function do_main() {
//if there are symbolic links linking to this document we need confirmation
if(count($this->oDocument->getSymbolicLinks())>0 && KTutil::arrayGet($_REQUEST,'postReceived') != 1){
$this->redirectTo("confirm");
}
$this->oPage->setBreadcrumbDetails(_kt('Archive Document'));
$oTemplate =& $this->oValidator->validateTemplate('ktcore/action/archive');
$oForm = $this->form_main();
$oTemplate->setData(array(
'context' => &$this,
'form' => $oForm,
));
return $oTemplate->render();
}
function do_confirm(){
$this->oPage->setBreadcrumbDetails(_kt('Confirm archive'));
$oTemplate =& $this->oValidator->validateTemplate('ktcore/action/archive_confirm');
$oForm = $this->form_confirm();
$oTemplate->setData(array(
'context' => &$this,
'form' => $oForm,
));
return $oTemplate->render();
}
function do_archive() {
$oForm = $this->form_main();
$res = $oForm->validate();
$data = $res['results'];
if (!empty($res['errors'])) {
return $oForm->handleError();
}
$sReason = $data['reason'];
$res = KTDocumentUtil::archive($this->oDocument, $sReason);
if(PEAR::isError($res)){
$_SESSION['KTErrorMessage'][] = $res->getMessage();
controllerRedirect('viewDocument', 'fDocumentId=' . $this->oDocument->getId());
exit(0);
}
$_SESSION['KTInfoMessage'][] = _kt('Document archived.');
controllerRedirect('browse', 'fFolderId=' . $this->oDocument->getFolderID());
exit(0);
}
}
// }}}
// {{{ KTDocumentWorkflowAction
class KTDocumentWorkflowAction extends KTDocumentAction {
var $sName = 'ktcore.actions.document.workflow';
var $_sShowPermission = 'ktcore.permissions.read';
var $sHelpPage = 'ktcore/user/workflow.html';
function predispatch() {
$this->persistParams(array('fTransitionId'));
}
function getDisplayName() {
return _kt('Workflow');
}
function getInfo() {
if ($this->oDocument->getIsCheckedOut()) {
return null;
}
return parent::getInfo();
}
function do_main() {
$this->oPage->setBreadcrumbDetails(_kt('workflow'));
$oTemplate =& $this->oValidator->validateTemplate('ktcore/workflow/documentWorkflow');
$oDocument =& $this->oValidator->validateDocument($_REQUEST['fDocumentId']);
$oWorkflow = KTWorkflowUtil::getWorkflowForDocument($oDocument);
$oWorkflowState = KTWorkflowUtil::getWorkflowStateForDocument($oDocument);
$oUser =& User::get($_SESSION['userID']);
// If the document is checked out - set transitions and workflows to empty and set checkedout to true
$bIsCheckedOut = $this->oDocument->getIsCheckedOut();
if ($bIsCheckedOut){
$aTransitions = array();
$aWorkflows = array();
$transition_fields = array();
$bHasPerm = FALSE;
}else{
$aTransitions = KTWorkflowUtil::getTransitionsForDocumentUser($oDocument, $oUser);
$aWorkflows = KTWorkflow::getList('start_state_id IS NOT NULL AND enabled = 1 ');
$bHasPerm = false;
if (KTPermissionUtil::userHasPermissionOnItem($oUser, 'ktcore.permissions.workflow', $oDocument)) {
$bHasPerm = true;
}
$fieldErrors = null;
$transition_fields = array();
if ($aTransitions) {
$aVocab = array();
foreach ($aTransitions as $oTransition) {
if(is_null($oTransition) || PEAR::isError($oTransition)){
continue;
}
$aVocab[$oTransition->getId()] = $oTransition->showDescription();
}
$fieldOptions = array('vocab' => $aVocab);
$transition_fields[] = new KTLookupWidget(_kt('Transition to perform'), _kt('The transition listed will cause the document to change from its current state to the listed destination state.'), 'fTransitionId', null, $this->oPage, true, null, $fieldErrors, $fieldOptions);
$transition_fields[] = new KTTextWidget(
_kt('Reason for transition'), _kt('Describe why this document qualifies to be changed from its current state to the destination state of the transition chosen.'),
'fComments', '',
$this->oPage, true, null, null,
array('cols' => 80, 'rows' => 4));
}
}
$aTemplateData = array(
'oDocument' => $oDocument,
'oWorkflow' => $oWorkflow,
'oState' => $oWorkflowState,
'aTransitions' => $aTransitions,
'aWorkflows' => $aWorkflows,
'transition_fields' => $transition_fields,
'bHasPerm' => $bHasPerm,
'bIsCheckedOut' => $bIsCheckedOut,
);
return $oTemplate->render($aTemplateData);
}
function do_startWorkflow() {
$oDocument =& $this->oValidator->validateDocument($_REQUEST['fDocumentId']);
if (!empty($_REQUEST['fWorkflowId'])) {
$oWorkflow =& $this->oValidator->validateWorkflow($_REQUEST['fWorkflowId']);
} else {
$oWorkflow = null;
}
$res = KTWorkflowUtil::startWorkflowOnDocument($oWorkflow, $oDocument);
if (PEAR::isError($res)) {
$this->errorRedirectToMain($res->message, sprintf('fDocumentId=%s',$oDocument->getId()));
}
$this->successRedirectToMain(_kt('Workflow started'),
array('fDocumentId' => $oDocument->getId()));
exit(0);
}
function do_performTransition() {
$oDocument =& $this->oValidator->validateDocument($_REQUEST['fDocumentId']);
$oTransition =& $this->oValidator->validateWorkflowTransition($_REQUEST['fTransitionId']);
$aErrorOptions = array(
'redirect_to' => array('main', sprintf('fDocumentId=%d', $_REQUEST['fDocumentId'])),
'message' => _kt('You must provide a reason for the transition'),
);
$sComments =& $this->oValidator->validateString($_REQUEST['fComments'], $aErrorOptions);
$oUser =& User::get($_SESSION['userID']);
$res = KTWorkflowUtil::performTransitionOnDocument($oTransition, $oDocument, $oUser, $sComments);
if(!Permission::userHasDocumentReadPermission($oDocument)) {
$this->commitTransaction();
$_SESSION['KTInfoMessage'][] = _kt('Transition performed') . '. ' . _kt('You no longer have permission to view this document');
controllerRedirect('browse', sprintf('fFolderId=%d', $oDocument->getFolderId()));
} else {
$this->successRedirectToMain(_kt('Transition performed'),
array('fDocumentId' => $oDocument->getId()));
}
}
function form_quicktransition() {
$oForm = new KTForm;
if($this->oDocument->getIsCheckedOut()){
$this->addErrorMessage(_kt('The workflow cannot be changed while the document is checked out.'));
}else{
$oForm->setOptions(array(
'identifier' => 'ktcore.workflow.quicktransition',
'label' => _kt('Perform Quick Transition'),
'submit_label' => _kt('Perform Transition'),
'context' => $this,
'action' => 'performquicktransition',
'fail_action' => 'quicktransition',
'cancel_url' => KTBrowseUtil::getUrlForDocument($this->oDocument),
));
$oForm->setWidgets(array(
array('ktcore.widgets.reason', array(
'label' => _kt('Reason'),
'description' => _kt('Specify your reason for performing this action.'),
'important_description' => _kt('Please bear in mind that you can use a maximum of <strong>250</strong> characters.'),
'name' => 'reason',
)),
));
$oForm->setValidators(array(
array('ktcore.validators.string', array(
'test' => 'reason',
'max_length' => 250,
'output' => 'reason',
)),
));
}
return $oForm;
}
function do_quicktransition() {
// make sure this gets through.
$this->persistParams(array('fTransitionId'));
$transition_id = $_REQUEST['fTransitionId'];
$oTransition = KTWorkflowTransition::get($transition_id);
$oForm = $this->form_quicktransition();
return $oForm->renderPage(sprintf(_kt('Perform Transition: %s'), $oTransition->getName()));
}
function do_performquicktransition() {
$oForm = $this->form_quicktransition();
$res = $oForm->validate();
if (!empty($res['errors'])) {
return $oForm->handleError();
}
$this->startTransaction();
$data = $res['results'];
$oTransition = KTWorkflowTransition::get($_REQUEST['fTransitionId']);
$res = KTWorkflowUtil::performTransitionOnDocument($oTransition, $this->oDocument, $this->oUser, $data['reason']);
if(!Permission::userHasDocumentReadPermission($this->oDocument)) {
$this->commitTransaction();
$_SESSION['KTInfoMessage'][] = _kt('Transition performed') . '. ' . _kt('You no longer have permission to view this document');
controllerRedirect('browse', sprintf('fFolderId=%d', $this->oDocument->getFolderId()));
} else {
$this->commitTransaction();
$_SESSION['KTInfoMessage'
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?