📄 ktapidocument.inc.php.tmp
字号:
return $rs; } $sql = "UPDATE documents SET metadata_version=$old_metadata_version WHERE id=$this->documentid"; $rs = DBUtil::runQuery($sql); if (PEAR::isError($rs)) { DBUtil::rollback(); return $rs; } DBUtil::commit(); $this->clearCache(); } /** * This returns a workflow transition * * @return array */ function get_workflow_transitions() { $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 array(); } $result = array(); $transitions = KTWorkflowUtil::getTransitionsForDocumentUser($this->document, $user); if (is_null($transitions) || PEAR::isError($transitions)) { return new KTAPI_Error(KTAPI_ERROR_WORKFLOW_INVALID, $transitions); } foreach($transitions as $transition) { $result[] = $transition->getName(); } return $result; } /** * This returns the current workflow state * * @return string */ function get_workflow_state() { $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); } $result = array(); $state = KTWorkflowUtil::getWorkflowStateForDocument($this->document); if (is_null($state) || PEAR::isError($state)) { return new PEAR_Error(KTAPI_ERROR_WORKFLOW_INVALID); } $statename = $state->getName(); return $statename; } function get_permission_string($document) { $perms = 'R'; if (Permission::userHasDocumentWritePermission($document)) { $perms .= 'W'; $user_id = $_SESSION['userID']; $co_user_id = $document->getCheckedOutUserID(); if (!empty($co_user_id) && ($user_id == $co_user_id)) { $perms .= 'E'; } } return $perms; } /** * This returns detailed information on the document. * * @return array */ function get_detail() { global $default; // make sure we ge tthe latest $this->clearCache(); $config = KTConfig::getSingleton(); $wsversion = $config->get('webservice/version', LATEST_WEBSERVICE_VERSION); $detail = array(); $document = $this->document; // get the document id $detail['document_id'] = (int) $document->getId(); $oem_document_no = null; if ($wsversion >= 2) { $oem_document_no = $document->getOemNo(); } if (empty($oem_document_no)) { $oem_document_no = 'n/a'; } $detail['custom_document_no'] = 'n/a'; $detail['oem_document_no'] = $oem_document_no; // get the title $detail['title'] = $document->getName(); // get the document type $documenttypeid=$document->getDocumentTypeID(); $documenttype = '* unknown *'; if (is_numeric($documenttypeid)) { $dt = DocumentType::get($documenttypeid); if (!is_null($dt) && !PEAR::isError($dt)) { $documenttype=$dt->getName(); } } $detail['document_type'] = $documenttype; // get the filename $detail['filename'] = $document->getFilename(); // get the filesize $detail['filesize'] = (int) $document->getFileSize(); // get the folder id $detail['folder_id'] = (int) $document->getFolderID(); // get the creator $userid = $document->getCreatorID(); $username='n/a'; if (is_numeric($userid)) { $username = '* unknown *'; $user = User::get($userid); if (!is_null($user) && !PEAR::isError($user)) { $username = $user->getName(); } } $detail['created_by'] = $username; // get the creation date $detail['created_date'] = $document->getCreatedDateTime(); // get the checked out user $userid = $document->getCheckedOutUserID(); $username='n/a'; if (is_numeric($userid)) { $username = '* unknown *'; $user = User::get($userid); if (!is_null($user) && !PEAR::isError($user)) { $username = $user->getName(); } } $detail['checked_out_by'] = $username; // get the checked out date list($major, $minor, $fix) = explode('.', $default->systemVersion); if ($major == 3 && $minor >= 5) { $detail['checked_out_date'] = $document->getCheckedOutDate(); } else { $detail['checked_out_date'] = $detail['modified_date']; } if (is_null($detail['checked_out_date'])) $detail['checked_out_date'] = 'n/a'; // get the modified user $userid = $document->getModifiedUserId(); $username='n/a'; if (is_numeric($userid)) { $username = '* unknown *'; $user = User::get($userid); if (!is_null($user) && !PEAR::isError($user)) { $username = $user->getName(); } } $detail['modified_by'] = $detail['updated_by'] = $username; // get the modified date $detail['updated_date'] = $detail['modified_date'] = $document->getLastModifiedDate(); // get the owner $userid = $document->getOwnerID(); $username='n/a'; if (is_numeric($userid)) { $username = '* unknown *'; $user = User::get($userid); if (!is_null($user) && !PEAR::isError($user)) { $username = $user->getName(); } } $detail['owned_by'] = $username; // get the version $detail['version'] = $document->getVersion(); if ($wsversion >= 2) { $detail['version'] = (float) $detail['version']; } //might be unset at the bottom in case of old webservice version //make sure we're using the real document for this one $this->document->switchToRealCore(); $detail['linked_document_id'] = $document->getLinkedDocumentId(); $this->document->switchToLinkedCore(); // check immutability $detail['is_immutable'] = (bool) $document->getImmutable(); // check permissions $detail['permissions'] = KTAPI_Document::get_permission_string($document); // get workflow name $workflowid = $document->getWorkflowId(); $workflowname='n/a'; if (is_numeric($workflowid)) { $workflow = KTWorkflow::get($workflowid); if (!is_null($workflow) && !PEAR::isError($workflow)) { $workflowname = $workflow->getName(); } } $detail['workflow'] = $workflowname; // get the workflow state $stateid = $document->getWorkflowStateId(); $workflowstate = 'n/a'; if (is_numeric($stateid)) { $state = KTWorkflowState::get($stateid); if (!is_null($state) && !PEAR::isError($state)) { $workflowstate = $state->getName(); } } $detail['workflow_state']=$workflowstate; // get the full path $detail['full_path'] = '/' . $this->document->getFullPath(); // get mime info $mimetypeid = $document->getMimeTypeID(); $detail['mime_type'] =KTMime::getMimeTypeName($mimetypeid); $detail['mime_icon_path'] =KTMime::getIconPath($mimetypeid); $detail['mime_display'] =KTMime::getFriendlyNameForString($detail['mime_type']); // get the storage path $detail['storage_path'] = $document->getStoragePath(); if ($wsversion >= 2) { unset($detail['updated_by']); unset($detail['updated_date']); } if($wsversion < 3){ unset($detail['linked_document_id']); } return $detail; } function get_title() { return $this->document->getDescription(); } /** * This does a download of a version of the document. * * @param string $version */ function download($version=null) { $storage =& KTStorageManagerUtil::getSingleton(); $options = array(); $oDocumentTransaction = new DocumentTransaction($this->document, 'Document downloaded', 'ktcore.transactions.download', $aOptions); $oDocumentTransaction->create(); } /** * This returns the transaction history for the document. * * @return array */ function get_transaction_history() { $sQuery = 'SELECT DTT.name AS transaction_name, U.name AS username, DT.version AS version, DT.comment AS comment, DT.datetime AS datetime ' . 'FROM ' . KTUtil::getTableName('document_transactions') . ' AS DT INNER JOIN ' . KTUtil::getTableName('users') . ' AS U ON DT.user_id = U.id ' . 'INNER JOIN ' . KTUtil::getTableName('transaction_types') . ' AS DTT ON DTT.namespace = DT.transaction_namespace ' . 'WHERE DT.document_id = ? ORDER BY DT.datetime DESC'; $aParams = array($this->documentid); $transactions = DBUtil::getResultArray(array($sQuery, $aParams)); if (is_null($transactions) || PEAR::isError($transactions)) { return new KTAPI_Error(KTAPI_ERROR_INTERNAL_ERROR, $transactions ); } $config = KTConfig::getSingleton(); $wsversion = $config->get('webservice/version', LATEST_WEBSERVICE_VERSION); foreach($transactions as $key=>$transaction) { $transactions[$key]['version'] = (float) $transaction['version']; } return $transactions; } /** * This returns the version history on the document. * * @return array */ function get_version_history() { $metadata_versions = KTDocumentMetadataVersion::getByDocument($this->document); $config = KTConfig::getSingleton(); $wsversion = $config->get('webservice/version', LATEST_WEBSERVICE_VERSION); $versions = array(); foreach ($metadata_versions as $version) { $document = &Document::get($this->documentid, $version->getId()); $version = array(); $userid = $document->getModifiedUserId(); $user = User::get($userid); $username = 'Unknown'; if (!PEAR::isError($user)) { $username = is_null($user)?'n/a':$user->getName(); } $version['user'] = $username; $version['metadata_version'] = $document->getMetadataVersion(); $version['content_version'] = $document->getVersion(); if ($wsversion >= 2) { $version['metadata_version'] = (int) $version['metadata_version']; $version['content_version'] = (float) $version['content_version']; } $versions[] = $version; } return $versions; } /** * This expunges a document from the system. * * @access public */ function expunge() { if ($this->document->getStatusID() != 3) { return new PEAR_Error('You should not purge this'); } DBUtil::startTransaction(); $transaction = new DocumentTransaction($this->document, "Document expunged", 'ktcore.transactions.expunge'); $transaction->create(); $this->document->delete(); $this->document->cleanupDocumentData($this->documentid); $storage =& KTStorageManagerUtil::getSingleton(); $result= $storage->expunge($this->document); DBUtil::commit(); } /** * This expunges a document from the system. * * @access public */ function restore() { DBUtil::startTransaction(); $storage =& KTStorageManagerUtil::getSingleton(); $folder = Folder::get($this->document->getRestoreFolderId()); if (PEAR::isError($folder)) { $this->document->setFolderId(1); $folder = Folder::get(1); } else { $this->document->setFolderId($this->document->getRestoreFolderId()); } $storage->restore($this->document); $this->document->setStatusId(LIVE); $this->document->setPermissionObjectId($folder->getPermissionObjectId()); $res = $this->document->update(); $res = KTPermissionUtil::updatePermissionLookup($this->document); $user = $this->ktapi->get_user(); $oTransaction = new DocumentTransaction($this->document, 'Restored from deleted state by ' . $user->getName(), 'ktcore.transactions.update'); $oTransaction->create(); DBUtil::commit(); }}?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -