Commit 5f4982d42fcd4e17d9a70c36f5b276dbd27562e5

Authored by Tohir Solomons
1 parent a93dfd9d

Backend code for implementing recently viewed documents in Explorer CP

Committed by: Tohir Solomons
Reviewed by: Megan Watson
ktapi/KTAPIDocument.inc.php
... ... @@ -2602,10 +2602,13 @@ class KTAPI_Document extends KTAPI_FolderItem
2602 2602 */
2603 2603 public function addDocumentToUserHistory()
2604 2604 {
2605   - require_once(KT_DIR . '/plugins/commercial/network/userhistory/UserHistoryActions.php');
2606   -
2607   - $docAction = new UserHistoryDocumentAction($this->document, $this->ktapi->get_user());
2608   - $docAction->_show();
  2605 + if (KTPluginUtil::pluginIsActive('brad.UserHistory.plugin')) {
  2606 + $path = KTPluginUtil::getPluginPath('brad.UserHistory.plugin');
  2607 + require_once($path . 'UserHistoryActions.php');
  2608 +
  2609 + $docAction = new UserHistoryDocumentAction($this->document, $this->ktapi->get_user());
  2610 + $docAction->_show();
  2611 + }
2609 2612 }
2610 2613  
2611 2614 /**
... ... @@ -2620,4 +2623,4 @@ class KTAPI_Document extends KTAPI_FolderItem
2620 2623 }
2621 2624 }
2622 2625  
2623 2626 -?>
  2627 +?>
2624 2628 \ No newline at end of file
... ...
ktapi/KTAPIFolder.inc.php
... ... @@ -1616,11 +1616,25 @@ class KTAPI_Folder extends KTAPI_FolderItem
1616 1616 */
1617 1617 public function addFolderToUserHistory()
1618 1618 {
1619   - require_once(KT_DIR . '/plugins/commercial/network/userhistory/UserHistoryActions.php');
1620   -
1621   - $docAction = new UserHistoryFolderAction($this->folder, $this->ktapi->get_user());
1622   - $docAction->_show();
  1619 + if (KTPluginUtil::pluginIsActive('brad.UserHistory.plugin')) {
  1620 + $path = KTPluginUtil::getPluginPath('brad.UserHistory.plugin');
  1621 + require_once($path.'UserHistoryActions.php');
  1622 +
  1623 + $folderAction = new UserHistoryFolderAction($this->folder, $this->ktapi->get_user());
  1624 + $folderAction->_show();
  1625 + }
  1626 + }
  1627 +
  1628 + /**
  1629 + * Method to get the Ids of all the Parent Folders
  1630 + *
  1631 + * @author KnowledgeTree Team
  1632 + * @access public
  1633 + */
  1634 + public function getParentFolderIDs()
  1635 + {
  1636 + return $this->folder->getParentFolderIDs();
1623 1637 }
1624 1638 }
1625 1639  
1626 1640 -?>
  1641 +?>
1627 1642 \ No newline at end of file
... ...
ktapi/ktapi.inc.php
... ... @@ -4832,6 +4832,58 @@ class KTAPI
4832 4832  
4833 4833 return $response;
4834 4834 }
  4835 +
  4836 + /**
  4837 + * Method to get the Recently Viewed Documents
  4838 + *
  4839 + * @author KnowledgeTree Team
  4840 + * @access public
  4841 + */
  4842 + public function getRecentlyViewedDocuments()
  4843 + {
  4844 + if (KTPluginUtil::pluginIsActive('brad.UserHistory.plugin')) {
  4845 + $path = KTPluginUtil::getPluginPath('brad.UserHistory.plugin');
  4846 + require_once($path.'UserHistoryActions.php');
  4847 + $user = $this->get_user();
  4848 +
  4849 + if (is_null($user) || PEAR::isError($user))
  4850 + {
  4851 + $result = new PEAR_Error(KTAPI_ERROR_USER_INVALID);
  4852 + return $result;
  4853 + }
  4854 +
  4855 + return UserHistoryDocumentEntry::getByUser($user);
  4856 +
  4857 + } else {
  4858 + return array();
  4859 + }
  4860 + }
  4861 +
  4862 + /**
  4863 + * Method to get the Recently Viewed Folders
  4864 + *
  4865 + * @author KnowledgeTree Team
  4866 + * @access public
  4867 + */
  4868 + public function getRecentlyViewedFolders()
  4869 + {
  4870 + if (KTPluginUtil::pluginIsActive('brad.UserHistory.plugin')) {
  4871 + $path = KTPluginUtil::getPluginPath('brad.UserHistory.plugin');
  4872 + require_once($path.'UserHistoryActions.php');
  4873 + $user = $this->get_user();
  4874 +
  4875 + if (is_null($user) || PEAR::isError($user))
  4876 + {
  4877 + $result = new PEAR_Error(KTAPI_ERROR_USER_INVALID);
  4878 + return $result;
  4879 + }
  4880 +
  4881 + return UserHistoryFolderEntry::getByUser($user);
  4882 +
  4883 + } else {
  4884 + return array();
  4885 + }
  4886 + }
4835 4887 }
4836 4888  
4837 4889  
... ...
webservice/clienttools/services/0.9/kt.php
... ... @@ -1354,14 +1354,80 @@ Fatal error: Cannot unset string offsets in on line 981
1354 1354 $this->logTrace ((__METHOD__.'('.__FILE__.' '.__LINE__.')'), 'Enter Function' );
1355 1355 $kt = &$this->KT;
1356 1356  
1357   - $items = array();
1358   - $folders = array();
  1357 +
  1358 + // Generate Folders List
  1359 + $returnFoldersArray = array();
  1360 +
  1361 + $folders = $kt->getRecentlyViewedFolders();
  1362 + foreach ($folders as $folder)
  1363 + {
  1364 + $folderObj = &$kt->get_folder_by_id ( $folder->getFolderId() );
  1365 +
  1366 + $folderArray = array();
  1367 + $folderArray['id'] = $folderObj->folderid;
  1368 + $folderArray['name'] = $folderObj->get_folder_name();
  1369 +
  1370 + $parentIds = explode(',', $folderObj->getParentFolderIds());
  1371 + $path = '/F_0';
  1372 +
  1373 + if (count($parentIds) > 0 && $folderObj->getParentFolderIds() != '') {
  1374 + foreach ($parentIds as $parentId)
  1375 + {
  1376 + $path .= '/F_'.$parentId;
  1377 + }
  1378 + }
  1379 +
  1380 + $path .= '/F_'.$folderObj->folderid;
  1381 +
  1382 + $folderArray['path'] = $path;
  1383 +
  1384 + $returnFoldersArray[] = $folderArray;
  1385 + }
1359 1386  
1360 1387  
1361   - // Fake for the timebeing
1362   - //$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)'));
  1388 + // Generate Documents List
  1389 + $returnDocumentArray = array();
  1390 +
  1391 + $items = $kt->getRecentlyViewedDocuments();
  1392 + foreach ($items as $item)
  1393 + {
  1394 + $document = $kt->get_document_by_id($item->getDocumentId());
  1395 + $documentDetail = $document->get_detail();
  1396 +
  1397 + $documentArray = array();
  1398 +
  1399 + $documentArray['id'] = $document->documentid;
  1400 + $documentArray['contentID'] = $document->documentid;
  1401 + $documentArray['title'] = $documentDetail['title'];
  1402 + $documentArray['folderId'] = $documentDetail['folder_id'];
  1403 +
  1404 + // Determine Icon Class
  1405 + $extpos = strrpos ( $documentDetail['filename'], '.' );
  1406 + if ($extpos === false) {
  1407 + $class = 'file-unknown';
  1408 + } else {
  1409 + $class = 'file-' . substr ( $documentDetail['filename'], $extpos + 1 ); // Get Extension without the dot
  1410 + }
  1411 + $documentArray['iconCls'] = $class;
  1412 +
  1413 + // Determine Icon Path
  1414 + $folderObj = $kt->get_folder_by_id ( $documentDetail['folder_id']);
  1415 + $parentIds = explode(',', $folderObj->getParentFolderIds());
  1416 + $path = '/F_0';
  1417 + if (count($parentIds) > 0 && $folderObj->getParentFolderIds() != '') {
  1418 + foreach ($parentIds as $parentId)
  1419 + {
  1420 + $path .= '/F_'.$parentId;
  1421 + }
  1422 + }
  1423 + $path .= '/F_'.$documentDetail['folder_id'];
  1424 +
  1425 + $documentArray['folderPath'] = $path;
  1426 +
  1427 + $returnDocumentArray[] = $documentArray;
  1428 + }
1363 1429  
1364   - $this->setResponse(array('items'=>$items, 'folders'=>$folders));
  1430 + $this->setResponse(array('documents'=>$returnDocumentArray, 'folders'=>$returnFoldersArray));
1365 1431 }
1366 1432  
1367 1433  
... ...