From 5f4982d42fcd4e17d9a70c36f5b276dbd27562e5 Mon Sep 17 00:00:00 2001 From: Tohir Solomons Date: Fri, 19 Feb 2010 12:06:40 +0200 Subject: [PATCH] Backend code for implementing recently viewed documents in Explorer CP --- ktapi/KTAPIDocument.inc.php | 13 ++++++++----- ktapi/KTAPIFolder.inc.php | 24 +++++++++++++++++++----- ktapi/ktapi.inc.php | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ webservice/clienttools/services/0.9/kt.php | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----- 4 files changed, 150 insertions(+), 15 deletions(-) diff --git a/ktapi/KTAPIDocument.inc.php b/ktapi/KTAPIDocument.inc.php index e878140..eb9670f 100644 --- a/ktapi/KTAPIDocument.inc.php +++ b/ktapi/KTAPIDocument.inc.php @@ -2602,10 +2602,13 @@ class KTAPI_Document extends KTAPI_FolderItem */ public function addDocumentToUserHistory() { - require_once(KT_DIR . '/plugins/commercial/network/userhistory/UserHistoryActions.php'); - - $docAction = new UserHistoryDocumentAction($this->document, $this->ktapi->get_user()); - $docAction->_show(); + if (KTPluginUtil::pluginIsActive('brad.UserHistory.plugin')) { + $path = KTPluginUtil::getPluginPath('brad.UserHistory.plugin'); + require_once($path . 'UserHistoryActions.php'); + + $docAction = new UserHistoryDocumentAction($this->document, $this->ktapi->get_user()); + $docAction->_show(); + } } /** @@ -2620,4 +2623,4 @@ class KTAPI_Document extends KTAPI_FolderItem } } -?> +?> \ No newline at end of file diff --git a/ktapi/KTAPIFolder.inc.php b/ktapi/KTAPIFolder.inc.php index c021783..a53614a 100755 --- a/ktapi/KTAPIFolder.inc.php +++ b/ktapi/KTAPIFolder.inc.php @@ -1616,11 +1616,25 @@ class KTAPI_Folder extends KTAPI_FolderItem */ public function addFolderToUserHistory() { - require_once(KT_DIR . '/plugins/commercial/network/userhistory/UserHistoryActions.php'); - - $docAction = new UserHistoryFolderAction($this->folder, $this->ktapi->get_user()); - $docAction->_show(); + if (KTPluginUtil::pluginIsActive('brad.UserHistory.plugin')) { + $path = KTPluginUtil::getPluginPath('brad.UserHistory.plugin'); + require_once($path.'UserHistoryActions.php'); + + $folderAction = new UserHistoryFolderAction($this->folder, $this->ktapi->get_user()); + $folderAction->_show(); + } + } + + /** + * Method to get the Ids of all the Parent Folders + * + * @author KnowledgeTree Team + * @access public + */ + public function getParentFolderIDs() + { + return $this->folder->getParentFolderIDs(); } } -?> +?> \ No newline at end of file diff --git a/ktapi/ktapi.inc.php b/ktapi/ktapi.inc.php index f8a6b96..5c0e57e 100644 --- a/ktapi/ktapi.inc.php +++ b/ktapi/ktapi.inc.php @@ -4832,6 +4832,58 @@ class KTAPI return $response; } + + /** + * Method to get the Recently Viewed Documents + * + * @author KnowledgeTree Team + * @access public + */ + public function getRecentlyViewedDocuments() + { + if (KTPluginUtil::pluginIsActive('brad.UserHistory.plugin')) { + $path = KTPluginUtil::getPluginPath('brad.UserHistory.plugin'); + require_once($path.'UserHistoryActions.php'); + $user = $this->get_user(); + + if (is_null($user) || PEAR::isError($user)) + { + $result = new PEAR_Error(KTAPI_ERROR_USER_INVALID); + return $result; + } + + return UserHistoryDocumentEntry::getByUser($user); + + } else { + return array(); + } + } + + /** + * Method to get the Recently Viewed Folders + * + * @author KnowledgeTree Team + * @access public + */ + public function getRecentlyViewedFolders() + { + if (KTPluginUtil::pluginIsActive('brad.UserHistory.plugin')) { + $path = KTPluginUtil::getPluginPath('brad.UserHistory.plugin'); + require_once($path.'UserHistoryActions.php'); + $user = $this->get_user(); + + if (is_null($user) || PEAR::isError($user)) + { + $result = new PEAR_Error(KTAPI_ERROR_USER_INVALID); + return $result; + } + + return UserHistoryFolderEntry::getByUser($user); + + } else { + return array(); + } + } } diff --git a/webservice/clienttools/services/0.9/kt.php b/webservice/clienttools/services/0.9/kt.php index a7273fd..00745ea 100644 --- a/webservice/clienttools/services/0.9/kt.php +++ b/webservice/clienttools/services/0.9/kt.php @@ -1354,14 +1354,80 @@ Fatal error: Cannot unset string offsets in on line 981 $this->logTrace ((__METHOD__.'('.__FILE__.' '.__LINE__.')'), 'Enter Function' ); $kt = &$this->KT; - $items = array(); - $folders = array(); + + // Generate Folders List + $returnFoldersArray = array(); + + $folders = $kt->getRecentlyViewedFolders(); + foreach ($folders as $folder) + { + $folderObj = &$kt->get_folder_by_id ( $folder->getFolderId() ); + + $folderArray = array(); + $folderArray['id'] = $folderObj->folderid; + $folderArray['name'] = $folderObj->get_folder_name(); + + $parentIds = explode(',', $folderObj->getParentFolderIds()); + $path = '/F_0'; + + if (count($parentIds) > 0 && $folderObj->getParentFolderIds() != '') { + foreach ($parentIds as $parentId) + { + $path .= '/F_'.$parentId; + } + } + + $path .= '/F_'.$folderObj->folderid; + + $folderArray['path'] = $path; + + $returnFoldersArray[] = $folderArray; + } - // Fake for the timebeing - //$folders = array(array('id'=>'2', 'path'=>'/F_0/F_1/F_2', 'name'=>'Dropped Documents (fake)'), array('id'=>'3', 'path'=>'/F_0/F_1/F_2/F_3', 'name'=>'admin (fake)')); + // Generate Documents List + $returnDocumentArray = array(); + + $items = $kt->getRecentlyViewedDocuments(); + foreach ($items as $item) + { + $document = $kt->get_document_by_id($item->getDocumentId()); + $documentDetail = $document->get_detail(); + + $documentArray = array(); + + $documentArray['id'] = $document->documentid; + $documentArray['contentID'] = $document->documentid; + $documentArray['title'] = $documentDetail['title']; + $documentArray['folderId'] = $documentDetail['folder_id']; + + // Determine Icon Class + $extpos = strrpos ( $documentDetail['filename'], '.' ); + if ($extpos === false) { + $class = 'file-unknown'; + } else { + $class = 'file-' . substr ( $documentDetail['filename'], $extpos + 1 ); // Get Extension without the dot + } + $documentArray['iconCls'] = $class; + + // Determine Icon Path + $folderObj = $kt->get_folder_by_id ( $documentDetail['folder_id']); + $parentIds = explode(',', $folderObj->getParentFolderIds()); + $path = '/F_0'; + if (count($parentIds) > 0 && $folderObj->getParentFolderIds() != '') { + foreach ($parentIds as $parentId) + { + $path .= '/F_'.$parentId; + } + } + $path .= '/F_'.$documentDetail['folder_id']; + + $documentArray['folderPath'] = $path; + + $returnDocumentArray[] = $documentArray; + } - $this->setResponse(array('items'=>$items, 'folders'=>$folders)); + $this->setResponse(array('documents'=>$returnDocumentArray, 'folders'=>$returnFoldersArray)); } -- libgit2 0.21.4