📄 ktapifolder.inc.php.tmp
字号:
'filename'=>$folder->getName(), 'size'=>'n/a', 'major_version'=>'n/a', 'minor_version'=>'n/a', 'storage_path'=>'n/a', 'mime_type'=>'folder', 'mime_icon_path'=>'folder', 'mime_display'=>'Folder', 'items'=>$items, 'workflow'=>'n/a', 'workflow_state'=>'n/a' ); } } } } if (strpos($what,'D') !== false) { $document_children = Document::getList(array('folder_id = ? AND status_id = 1', $this->folderid)); // I hate that KT doesn't cache things nicely... $mime_cache=array(); foreach ($document_children as $document) { if (KTPermissionUtil::userHasPermissionOnItem($user, $read_permission, $document)) { $created_by=$this->_resolve_user($document->getCreatorID()); $created_date = $document->getCreatedDateTime(); if (empty($created_date)) $created_date = 'n/a'; $checked_out_by=$this->_resolve_user($document->getCheckedOutUserID()); $checked_out_date = $document->getCheckedOutDate(); if (empty($checked_out_date)) $checked_out_date = 'n/a'; $modified_by=$this->_resolve_user($document->getCreatorID()); $modified_date = $document->getLastModifiedDate(); if (empty($modified_date)) $modified_date = 'n/a'; $owned_by =$this->_resolve_user($document->getOwnerID()); $mimetypeid=$document->getMimeTypeID(); if (!array_key_exists($mimetypeid, $mime_cache)) { $type=KTMime::getMimeTypeName($mimetypeid); $icon=KTMime::getIconPath($mimetypeid); $display=KTMime::getFriendlyNameForString($type); $mime_cache[$mimetypeid] = array( 'type'=>$type, 'icon'=>$icon, 'display'=>$display ); } $mimeinfo=$mime_cache[$mimetypeid]; $workflow='n/a'; $state='n/a'; $wf = KTWorkflowUtil::getWorkflowForDocument($document); if (!is_null($wf) && !PEAR::isError($wf)) { $workflow=$wf->getHumanName(); $ws=KTWorkflowUtil::getWorkflowStateForDocument($document); if (!is_null($ws) && !PEAR::isError($ws)) { $state=$ws->getHumanName(); } } if ($wsversion >= 2) { $docTypeId = $document->getDocumentTypeID(); $documentType = DocumentType::get($docTypeId); $oemDocumentNo = $document->getOemNo(); if (empty($oemDocumentNo)) $oemDocumentNo = 'n/a'; $array = array( 'id' => (int) $document->getId(), 'item_type' => 'D', 'custom_document_no'=>'n/a', 'oem_document_no'=>$oemDocumentNo, 'title' => $document->getName(), 'document_type'=>$documentType->getName(), 'filename' => $document->getFileName(), 'filesize' => $document->getFileSize(), 'created_by' => is_null($created_by)?'n/a':$created_by->getName(), 'created_date' => $created_date, 'checked_out_by' => is_null($checked_out_by)?'n/a':$checked_out_by->getName(), 'checked_out_date' => $checked_out_date, 'modified_by' => is_null($modified_by)?'n/a':$modified_by->getName(), 'modified_date' => $modified_date, 'owned_by' => is_null($owned_by)?'n/a':$owned_by->getName(), 'version' => $document->getMajorVersionNumber() . '.' . $document->getMinorVersionNumber(), 'is_immutable'=> $document->getImmutable()?'true':'false', 'permissions' => KTAPI_Document::get_permission_string($document), 'workflow'=> $workflow, 'workflow_state'=> $state, 'mime_type' => $mime_cache[$mimetypeid]['type'], 'mime_icon_path' => $mime_cache[$mimetypeid]['icon'], 'mime_display' => $mime_cache[$mimetypeid]['display'], 'storage_path' => $document->getStoragePath(), ); if($wsversion>=3){ $document->switchToRealCore(); $array['linked_document_id'] = $document->getLinkedDocumentId(); $document->switchToLinkedCore(); if($document->isSymbolicLink()){ $array['item_type'] = "S"; } } $array['items']=array(); if($wsversion<3 || (strpos($what,'D') !== false && !$document->isSymbolicLink()) || ($document->isSymbolicLink() && strpos($what,'S') !== false)){ $contents[] = $array; } } else { $contents[] = array( 'id' => (int) $document->getId(), 'item_type'=>'D', 'title'=>$document->getName(), 'creator'=>is_null($created_by)?'n/a':$created_by->getName(), 'checkedoutby'=>is_null($checked_out_by)?'n/a':$checked_out_by->getName(), 'modifiedby'=>is_null($modified_by)?'n/a':$modified_by->getName(), 'filename'=>$document->getFileName(), 'size'=>$document->getFileSize(), 'major_version'=>$document->getMajorVersionNumber(), 'minor_version'=>$document->getMinorVersionNumber(), 'storage_path'=>$document->getStoragePath(), 'mime_type'=>$mime_cache[$mimetypeid]['type'], 'mime_icon_path'=>$mime_cache[$mimetypeid]['icon'], 'mime_display'=>$mime_cache[$mimetypeid]['display'], 'items'=>array(), 'workflow'=>$workflow, 'workflow_state'=>$state ); } } } } return $contents; } /** * This adds a shortcut to an existing document to the current folder * * @param int $document_id The ID of the document to create a shortcut to * */ function &add_document_shortcut($document_id){ $user = $this->can_user_access_object_requiring_permission($this->folder, KTAPI_PERMISSION_WRITE); if (PEAR::isError($user)) { return $user; } $oDocument = Document::get($document_id); if(PEAR::isError($oDocument)){ return $oDocument; } $user = $this->can_user_access_object_requiring_permission($oDocument, KTAPI_PERMISSION_READ); if (PEAR::isError($user)) { return $user; } $document = KTDocumentUtil::createSymbolicLink($document_id,$this->folder,$user); if (PEAR::isError($document)) { return new PEAR_Error(KTAPI_ERROR_INTERNAL_ERROR . ' : ' . $document->getMessage()); } return new KTAPI_Document($this->ktapi,$this,$document); } /** * This adds a shortcut pointing to an existing folder to the current folder * * @param int $folder_id The ID of the folder to create a shortcut to * */ function &add_folder_shortcut($folder_id){ $user = $this->can_user_access_object_requiring_permission($this->folder, KTAPI_PERMISSION_WRITE); if (PEAR::isError($user)) { return $user; } $oFolder = Folder::get($folder_id); if(PEAR::isError($oFolder)){ return $oFolder; } $user = $this->can_user_access_object_requiring_permission($oFolder, KTAPI_PERMISSION_READ); if (PEAR::isError($user)) { return $user; } $folder = & KTFolderUtil::createSymbolicLink($folder_id,$this->folder,$user); if (PEAR::isError($folder)) { return new PEAR_Error(KTAPI_ERROR_INTERNAL_ERROR . ' : ' . $folder->getMessage()); } return new KTAPI_Folder($this->ktapi,$folder); } /** * This adds a document to the current folder. * * @access public * @param string $title This is the title for the file in the repository. * @param string $filename This is the filename in the system for the file. * @param string $documenttype This is the name or id of the document type. It first looks by name, then by id. * @param string $tempfilename This is a reference to the file that is accessible locally on the file system. * @return KTAPI_Document */ function &add_document($title, $filename, $documenttype, $tempfilename) { if (!is_file($tempfilename)) { return new PEAR_Error('File does not exist.'); } $user = $this->can_user_access_object_requiring_permission($this->folder, KTAPI_PERMISSION_WRITE); if (PEAR::isError($user)) { return $user; } $title = KTUtil::replaceInvalidCharacters($title); $filename = basename($filename); $filename = KTUtil::replaceInvalidCharacters($filename); $documenttypeid = KTAPI::get_documenttypeid($documenttype); if (PEAR::isError($documenttypeid)) { $config = KTCache::getSingleton(); $defaultToDefaultDocType = $config->get('webservice/useDefaultDocumentTypeIfInvalid',true); if ($defaultToDefaultDocType) { $documenttypeid = KTAPI::get_documenttypeid('Default'); } else { return new KTAPI_DocumentTypeError('The document type could not be resolved or is disabled: ' . $documenttype); } } $options = array( 'contents' => new KTFSFileLike($tempfilename), 'temp_file' => $tempfilename, 'novalidate' => true, 'documenttype' => DocumentType::get($documenttypeid), 'description' => $title, 'metadata'=>array(), 'cleanup_initial_file' => true ); DBUtil::startTransaction(); $document =& KTDocumentUtil::add($this->folder, $filename, $user, $options); if (PEAR::isError($document)) { DBUtil::rollback(); return new PEAR_Error(KTAPI_ERROR_INTERNAL_ERROR . ' : ' . $document->getMessage()); } DBUtil::commit(); KTUploadManager::temporary_file_imported($tempfilename); return new KTAPI_Document($this->ktapi, $this, $document); } /** * This adds a subfolder folder to the current folder. * * @access public * @param string $foldername * @return KTAPI_Folder */ function &add_folder($foldername) { $user = $this->can_user_access_object_requiring_permission($this->folder, KTAPI_PERMISSION_ADD_FOLDER); if (PEAR::isError($user)) { return $user; } $foldername = KTUtil::replaceInvalidCharacters($foldername); DBUtil::startTransaction(); $result = KTFolderUtil::add($this->folder, $foldername, $user); if (PEAR::isError($result)) { DBUtil::rollback(); return new KTAPI_Error(KTAPI_ERROR_INTERNAL_ERROR, $result); } DBUtil::commit(); $folderid = $result->getId(); return $this->ktapi->get_folder_by_id($folderid); } /** * This deletes the current folder. * * @param string $reason */ function delete($reason) { $user = $this->can_user_access_object_requiring_permission($this->folder, KTAPI_PERMISSION_DELETE); if (PEAR::isError($user)) { return $user; } if ($this->folderid == 1) { return new PEAR_Error('Cannot delete root folder!'); } DBUtil::startTransaction(); $result = KTFolderUtil::delete($this->folder, $user, $reason); if (PEAR::isError($result)) { DBUtil::rollback(); return new KTAPI_Error(KTAPI_ERROR_INTERNAL_ERROR, $result); } DBUtil::commit(); } /** * This renames the folder * * @param string $newname */ function rename($newname) { $user = $this->can_user_access_object_requiring_permission($this->folder, KTAPI_PERMISSION_RENAME_FOLDER); if (PEAR::isError($user)) { return $user; } $newname = KTUtil::replaceInvalidCharacters($newname); DBUtil::startTransaction(); $result = KTFolderUtil::rename($this->folder, $newname, $user); if (PEAR::isError($result)) { DBUtil::rollback(); return new KTAPI_Error(KTAPI_ERROR_INTERNAL_ERROR, $result); } DBUtil::commit(); } /** * This moves the folder to another location. * * @param KTAPI_Folder $ktapi_target_folder * @param string $reason */ function move($ktapi_target_folder, $reason='') { assert(!is_null($ktapi_target_folder)); assert(is_a($ktapi_target_folder,'KTAPI_Folder')); $user = $this->ktapi->get_user(); $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; } DBUtil::startTransaction(); $result = KTFolderUtil::move($this->folder, $target_folder, $user, $reason); if (PEAR::isError($result)) { DBUtil::rollback(); return new KTAPI_Error(KTAPI_ERROR_INTERNAL_ERROR, $result); } DBUtil::commit(); } /** * This copies a folder to another location. * * @param KTAPI_Folder $ktapi_target_folder * @param string $reason */ function copy($ktapi_target_folder, $reason='') { assert(!is_null($ktapi_target_folder)); assert(is_a($ktapi_target_folder,'KTAPI_Folder')); $user = $this->ktapi->get_user(); $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; } DBUtil::startTransaction(); $result = KTFolderUtil::copy($this->folder, $target_folder, $user, $reason); if (PEAR::isError($result)) { DBUtil::rollback(); return new KTAPI_Error(KTAPI_ERROR_INTERNAL_ERROR, $result); } DBUtil::commit(); } /** * This returns all permissions linked to the folder. * * @access public * @return array */ function get_permissions() { return new PEAR_Error('TODO'); } /** * This returns a transaction history listing. * * @access public * @return array */ function get_transaction_history() { return new PEAR_Error('TODO'); }}?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -