📄 ktapidocument.inc.php.tmp
字号:
DBUtil::rollback(); return new KTAPI_Error(KTAPI_ERROR_INTERNAL_ERROR,$res ); } $oDocumentTransaction = new DocumentTransaction($this->document, $reason, 'ktcore.transactions.permissions_change'); $res = $oDocumentTransaction->create(); if (($res === false) || PEAR::isError($res)) { DBUtil::rollback(); return new KTAPI_Error(KTAPI_ERROR_INTERNAL_ERROR,$res ); } DBUtil::commit(); } /** * This copies the document to another folder. * * @param KTAPI_Folder $ktapi_target_folder * @param string $reason * @param string $newname * @param string $newfilename * @return KTAPI_Document */ function copy(&$ktapi_target_folder, $reason, $newname=null, $newfilename=null) { assert(!is_null($ktapi_target_folder)); assert(is_a($ktapi_target_folder,'KTAPI_Folder')); if (empty($newname)) { $newname=null; } if (empty($newfilename)) { $newfilename=null; } $user = $this->ktapi->get_user(); if ($this->document->getIsCheckedOut()) { return new PEAR_Error(KTAPI_ERROR_DOCUMENT_CHECKED_OUT); } $target_folder = &$ktapi_target_folder->get_folder(); $result = $this->can_user_access_object_requiring_permission( $target_folder, KTAPI_PERMISSION_WRITE); if (PEAR::isError($result)) { return $result; } $name = $this->document->getName(); $clash = KTDocumentUtil::nameExists($target_folder, $name); if ($clash && !is_null($newname)) { $name = $newname; $clash = KTDocumentUtil::nameExists($target_folder, $name); } if ($clash) { return new PEAR_Error('A document with this title already exists in your chosen folder. Please choose a different folder, or specify a new title for the copied document.'); } $filename=$this->document->getFilename(); $clash = KTDocumentUtil::fileExists($target_folder, $filename); if ($clash && !is_null($newname)) { $filename = $newfilename; $clash = KTDocumentUtil::fileExists($target_folder, $filename); } if ($clash) { return new PEAR_Error('A document with this filename already exists in your chosen folder. Please choose a different folder, or specify a new filename for the copied document.'); } DBUtil::startTransaction(); $new_document = KTDocumentUtil::copy($this->document, $target_folder, $reason); if (PEAR::isError($new_document)) { DBUtil::rollback(); return new KTAPI_Error(KTAPI_ERROR_INTERNAL_ERROR,$new_document ); } $new_document->setName($name); $new_document->setFilename($filename); $res = $new_document->update(); if (PEAR::isError($res)) { DBUtil::rollback(); return new KTAPI_Error(KTAPI_ERROR_INTERNAL_ERROR,$res ); } DBUtil::commit(); // FIXME do we need to refactor all trigger usage into the util function? $oKTTriggerRegistry = KTTriggerRegistry::getSingleton(); $aTriggers = $oKTTriggerRegistry->getTriggers('copyDocument', 'postValidate'); foreach ($aTriggers as $aTrigger) { $sTrigger = $aTrigger[0]; $oTrigger = new $sTrigger; $aInfo = array( 'document' => $new_document, 'old_folder' => $this->ktapi_folder->get_folder(), 'new_folder' => $target_folder, ); $oTrigger->setInfo($aInfo); $ret = $oTrigger->postValidate(); } return KTAPI_Document::get($this->ktapi, $new_document->getId()); } /** * This moves the document to another folder. * * @param KTAPI_Folder $ktapi_target_folder * @param string $reason * @param string $newname * @param string $newfilename */ function move(&$ktapi_target_folder, $reason, $newname=null, $newfilename=null) { assert(!is_null($ktapi_target_folder)); assert(is_a($ktapi_target_folder,'KTAPI_Folder')); if (empty($newname)) { $newname=null; } if (empty($newfilename)) { $newfilename=null; } $user = $this->can_user_access_object_requiring_permission( $this->document, KTAPI_PERMISSION_DOCUMENT_MOVE); if (PEAR::isError($user)) { return $user; } if ($this->document->getIsCheckedOut()) { return new PEAR_Error(KTAPI_ERROR_DOCUMENT_CHECKED_OUT); } $target_folder = $ktapi_target_folder->get_folder(); $result= $this->can_user_access_object_requiring_permission( $target_folder, KTAPI_PERMISSION_WRITE); if (PEAR::isError($result)) { return $result; } if (!KTDocumentUtil::canBeMoved($this->document)) { return new PEAR_Error('Document cannot be moved.'); } $name = $this->document->getName(); $clash = KTDocumentUtil::nameExists($target_folder, $name); if ($clash && !is_null($newname)) { $name = $newname; $clash = KTDocumentUtil::nameExists($target_folder, $name); } if ($clash) { return new PEAR_Error('A document with this title already exists in your chosen folder. Please choose a different folder, or specify a new title for the moved document.'); } $filename=$this->document->getFilename(); $clash = KTDocumentUtil::fileExists($target_folder, $filename); if ($clash && !is_null($newname)) { $filename = $newfilename; $clash = KTDocumentUtil::fileExists($target_folder, $filename); } if ($clash) { return new PEAR_Error('A document with this filename already exists in your chosen folder. Please choose a different folder, or specify a new filename for the moved document.'); } DBUtil::startTransaction(); $res = KTDocumentUtil::move($this->document, $target_folder, $user, $reason); if (PEAR::isError($res)) { DBUtil::rollback(); return new KTAPI_Error(KTAPI_ERROR_INTERNAL_ERROR, $res ); } $this->document->setName($name); $this->document->setFilename($filename); $res = $this->document->update(); if (PEAR::isError($res)) { DBUtil::rollback(); return new KTAPI_Error(KTAPI_ERROR_INTERNAL_ERROR,$res ); } DBUtil::commit(); } /** * This changes the filename of the document. * * @param string $newname */ function renameFile($newname) { $user = $this->can_user_access_object_requiring_permission( $this->document, KTAPI_PERMISSION_WRITE); if (PEAR::isError($user)) { return $user; } $newname = KTUtil::replaceInvalidCharacters($newname); DBUtil::startTransaction(); $res = KTDocumentUtil::rename($this->document, $newname, $user); if (PEAR::isError($res)) { DBUtil::rollback(); return new KTAPI_Error(KTAPI_ERROR_INTERNAL_ERROR,$res ); } DBUtil::commit(); } /** * This changes the document type of the document. * * @param string $newname */ function change_document_type($documenttype) { $user = $this->can_user_access_object_requiring_permission( $this->document, KTAPI_PERMISSION_WRITE); if (PEAR::isError($user)) { return $user; } $doctypeid = KTAPI::get_documenttypeid($documenttype); if (PEAR::isError($doctypeid)) { return $doctypeid; } if ($this->document->getDocumentTypeId() != $doctypeid) { DBUtil::startTransaction(); $this->document->setDocumentTypeId($doctypeid); $res = $this->document->update(); if (PEAR::isError($res)) { DBUtil::rollback(); return new KTAPI_Error(KTAPI_ERROR_INTERNAL_ERROR,$res ); } $metadata = $this->get_packed_metadata(); $oKTTriggerRegistry = KTTriggerRegistry::getSingleton(); $aTriggers = $oKTTriggerRegistry->getTriggers('edit', 'postValidate'); foreach ($aTriggers as $aTrigger) { $sTrigger = $aTrigger[0]; $oTrigger = new $sTrigger; $aInfo = array( "document" => $this->document, "aOptions" => $packed, ); $oTrigger->setInfo($aInfo); $ret = $oTrigger->postValidate(); } DBUtil::commit(); } } /** * This changes the title of the document. * * @param string $newname */ function rename($newname) { $user = $this->can_user_access_object_requiring_permission( $this->document, KTAPI_PERMISSION_WRITE); if (PEAR::isError($user)) { return $user; } $newname = KTUtil::replaceInvalidCharacters($newname); if ($this->document->getName() != $newname) { DBUtil::startTransaction(); $this->document->setName($newname); $res = $this->document->update(); if (PEAR::isError($res)) { DBUtil::rollback(); return new KTAPI_Error(KTAPI_ERROR_INTERNAL_ERROR, $res); } DBUtil::commit(); } } /** * This flags the document as 'archived'. * * @param string $reason */ function archive($reason) { $user = $this->can_user_access_object_requiring_permission( $this->document, KTAPI_PERMISSION_WRITE); if (PEAR::isError($user)) { return $user; } list($permission, $user) = $perm_and_user; DBUtil::startTransaction(); $this->document->setStatusID(ARCHIVED); $res = $this->document->update(); if (($res === false) || PEAR::isError($res)) { DBUtil::rollback(); return new KTAPI_Error(KTAPI_ERROR_INTERNAL_ERROR, $res); } $oDocumentTransaction = new DocumentTransaction($this->document, sprintf(_kt('Document archived: %s'), $reason), 'ktcore.transactions.update'); $oDocumentTransaction->create(); DBUtil::commit(); $oKTTriggerRegistry = KTTriggerRegistry::getSingleton(); $aTriggers = $oKTTriggerRegistry->getTriggers('archive', 'postValidate'); foreach ($aTriggers as $aTrigger) { $sTrigger = $aTrigger[0]; $oTrigger = new $sTrigger; $aInfo = array( 'document' => $this->document, ); $oTrigger->setInfo($aInfo); $ret = $oTrigger->postValidate(); } } /** * This starts a workflow on a document. * * @param string $workflow */ function start_workflow($workflow) { $user = $this->can_user_access_object_requiring_permission( $this->document, KTAPI_PERMISSION_WORKFLOW); if (PEAR::isError($user)) { return $user; } $workflowid = $this->document->getWorkflowId(); if (!empty($workflowid)) { return new PEAR_Error('A workflow is already defined.'); } $workflow = KTWorkflow::getByName($workflow); if (is_null($workflow) || PEAR::isError($workflow)) { return new KTAPI_Error(KTAPI_ERROR_WORKFLOW_INVALID, $workflow); } DBUtil::startTransaction(); $result = KTWorkflowUtil::startWorkflowOnDocument($workflow, $this->document); if (is_null($result) || PEAR::isError($result)) { DBUtil::rollback(); return new KTAPI_Error(KTAPI_ERROR_WORKFLOW_INVALID, $result); } DBUtil::commit(); } /** * This deletes the workflow on the document. * */ function delete_workflow() { $user = $this->can_user_access_object_requiring_permission( $this->document, KTAPI_PERMISSION_WORKFLOW); if (PEAR::isError($user)) { return $user; } $workflowid=$this->document->getWorkflowId(); if (empty($workflowid)) { return new PEAR_Error(KTAPI_ERROR_WORKFLOW_NOT_IN_PROGRESS); } DBUtil::startTransaction(); $result = KTWorkflowUtil::startWorkflowOnDocument(null, $this->document); if (is_null($result) || PEAR::isError($result)) { DBUtil::rollback(); return new KTAPI_Error(KTAPI_ERROR_WORKFLOW_INVALID,$result); } DBUtil::commit(); } /** * This performs a transition on the workflow * * @param string $transition * @param string $reason */ function perform_workflow_transition($transition, $reason) { $user = $this->can_user_access_object_requiring_permission( $this->document, KTAPI_PERMISSION_WORKFLOW); if (PEAR::isError($user)) { return $user; } $workflowid=$this->document->getWorkflowId(); if (empty($workflowid)) { return new PEAR_Error(KTAPI_ERROR_WORKFLOW_NOT_IN_PROGRESS); } $transition = &KTWorkflowTransition::getByName($transition); if (is_null($transition) || PEAR::isError($transition)) { return new KTAPI_Error(KTAPI_ERROR_WORKFLOW_INVALID, $transition); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -