Commit e0f3d0b9e9cd2b223a367e0f52506150d440db27

Authored by Jalaloedien
1 parent b4c43889

KTS-1800

"Folder notifications in the RSS section on the dashboard not given the correct information when actions are performed on that folder. "
Fixed.

Reviewed By: Conrad

git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@6544 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing 1 changed file with 88 additions and 10 deletions
plugins/rssplugin/KTrss.inc.php
... ... @@ -87,9 +87,9 @@ class KTrss{
87 87  
88 88 // Get list of folder subscriptions
89 89 function getFolderList($iUserId){
90   - $sQuery = "SELECT folder_id as id FROM folder_subscriptions WHERE user_id = ?";
  90 + $sQuery = "SELECT folder_id as id, is_tree as tree FROM folder_subscriptions WHERE user_id = ?";
91 91 $aParams = array($iUserId);
92   - $aFolderList = DBUtil::getResultArrayKey(array($sQuery, $aParams), 'id');
  92 + $aFolderList = DBUtil::getResultArray(array($sQuery, $aParams));
93 93  
94 94 if (PEAR::isError($aFolderList)) {
95 95 // XXX: log error
... ... @@ -123,14 +123,17 @@ class KTrss{
123 123 // Get data for all folders subscribed to
124 124 function getFolders($iUserId){
125 125 $aFList = KTrss::getFolderList($iUserId);
  126 +
126 127 if($aFList){
127   - foreach($aFList as $folder_id){
  128 + foreach($aFList as $folderElement){
  129 + $folder_id = $folderElement['id'];
128 130 $folder = KTrss::getOneFolder($folder_id, $iUserId);
129 131 if($folder){
130 132 $aFolders[] = $folder;
131 133 }
132 134 }
133 135 }
  136 +
134 137 if (PEAR::isError($aFolders)) {
135 138 // XXX: log error
136 139 return false;
... ... @@ -140,6 +143,51 @@ class KTrss{
140 143 }
141 144 }
142 145  
  146 + function getChildrenFolderTransactions($iParentFolderId, $depth = '1'){
  147 + if($depth == '1'){
  148 + $sQuery = "SELECT id from folders WHERE parent_folder_ids LIKE ?";
  149 + $aParams = array('%'.$iParentFolderId);
  150 + }//else
  151 +
  152 + $aFolderList = DBUtil::getResultArray(array($sQuery, $aParams));
  153 + if (PEAR::isError($aFolderList)) {
  154 + // XXX: log error
  155 + return false;
  156 + }
  157 + if ($aFolderList) {
  158 + foreach($aFolderList as $folderElement){
  159 + $folder_id = $folderElement['id'];
  160 + $aFolderTransactions = array_merge($aFolderTransactions, KTrss::getFolderTransactions($folder_id));
  161 + }
  162 + }
  163 + if ($aFolderTransactions){
  164 + return $aFolderTransactions;
  165 + }
  166 + }
  167 +
  168 + function getChildrenDocumentTransactions($iParentFolderId, $depth = '1'){
  169 + if($depth == '1'){
  170 + $sQuery = "SELECT id from documents WHERE parent_folder_ids LIKE ? ";
  171 + $aParams = array('%'.$iParentFolderId);
  172 + }//else
  173 +
  174 + $aDocumentList = DBUtil::getResultArray(array($sQuery, $aParams));
  175 +
  176 + if (PEAR::isError($aDocumentList)) {
  177 + // XXX: log error
  178 + return false;
  179 + }
  180 + if ($aDocumentList) {
  181 + foreach($aDocumentList as $documentElement){
  182 + $document_id = $documentElement['id'];
  183 + $aDocumentTransactions = array_merge($aDocumentTransactions, KTrss::getDocumentTransactions($document_id));
  184 + }
  185 + }
  186 + if ($aDocumentTransactions){
  187 + return $aDocumentTransactions;
  188 + }
  189 + }
  190 +
143 191 // get information on document
144 192 function getOneDocument($iDocumentId, $iUserId){
145 193 $aDData = KTrss::getDocumentData($iUserId, $iDocumentId);
... ... @@ -162,11 +210,26 @@ class KTrss{
162 210 return $aDocument;
163 211 }
164 212 }
165   -
  213 +
166 214 // get information for folder
167 215 function getOneFolder($iFolderId){
168 216 $aFData = KTrss::getFolderData($iFolderId);
169   - $aFTransactions = KTrss::getFolderTransactions($iFolderId);
  217 + $aFTransactions = array_merge(KTrss::getChildrenFolderTransactions($iFolderId), KTrss::getFolderTransactions($iFolderId));
  218 + $aFTransactions = array_merge($aFTransactions, KTrss::getChildrenDocumentTransactions($iFolderId));
  219 +
  220 + $code = 'if (strtotime($a[datetime]) == strtotime($b[datetime])){
  221 + return 0;
  222 + }
  223 + return (strtotime($a[datetime]) > strtotime($b[datetime])) ? -1 : 1;';
  224 +
  225 + $compare = create_function('$a,$b', $code);
  226 +
  227 + usort($aFTransactions, $compare);
  228 + for($i=0; $i<4; $i++){
  229 + $aFTransactions_new[] = $aFTransactions[$i];
  230 + }
  231 + $aFTransactions = $aFTransactions_new;
  232 +
170 233 if($aFData){
171 234 $aFData['itemType'] = 'folder';
172 235  
... ... @@ -255,7 +318,19 @@ class KTrss{
255 318 "&lt;table width='100%'&gt;\n";
256 319 foreach($aItems[1] as $item){
257 320 $feed .= "&lt;tr&gt;\n".
258   - "&lt;td&gt;Description:&lt;/td&gt;\n".
  321 + "&lt;td&gt;".$item[type]." name:&lt;/td&gt;\n".
  322 + "&lt;td&gt;".$item[name]."&lt;/td&gt;\n".
  323 + "&lt;/tr&gt;\n".
  324 + "&lt;tr&gt;\n".
  325 + "&lt;td&gt;Path:&lt;/td&gt;\n".
  326 + "&lt;td&gt;".$item[fullpath]."&lt;/td&gt;\n".
  327 + "&lt;/tr&gt;\n".
  328 + "&lt;tr&gt;\n".
  329 + "&lt;td&gt;Transaction:&lt;/td&gt;\n".
  330 + "&lt;td&gt;".$item[transaction_name]."&lt;/td&gt;\n".
  331 + "&lt;/tr&gt;\n".
  332 + "&lt;tr&gt;\n".
  333 + "&lt;td&gt;Comment:&lt;/td&gt;\n".
259 334 "&lt;td&gt;".$item[comment]."&lt;/td&gt;\n".
260 335 "&lt;/tr&gt;\n".
261 336 "&lt;tr&gt;\n";if($item[version]){
... ... @@ -521,12 +596,14 @@ class KTrss{
521 596  
522 597 // get a listing of the latest 3 transactions for a document
523 598 function getDocumentTransactions($iDocumentId){
524   - $sQuery = "SELECT DTT.name AS transaction_name, U.name AS user_name, DT.version AS version, DT.comment AS comment, DT.datetime AS datetime " .
  599 + $sQuery = "SELECT DT.datetime AS datetime, 'Document' AS type, DMV.name, D.full_path AS fullpath, DTT.name AS transaction_name, U.name AS user_name, DT.version AS version, DT.comment AS comment " .
525 600 "FROM document_transactions AS DT INNER JOIN users AS U ON DT.user_id = U.id " .
526 601 "INNER JOIN document_transaction_types_lookup AS DTT ON DTT.namespace = DT.transaction_namespace " .
  602 + "LEFT JOIN document_metadata_version AS DMV ON DT.document_id = DMV.document_id " .
  603 + "LEFT JOIN documents AS D ON DT.document_id = D.id " .
527 604 "WHERE DT.document_id = ? " .
528 605 "ORDER BY DT.datetime DESC " .
529   - "LIMIT 3";
  606 + "LIMIT 4";
530 607  
531 608 $aParams = array($iDocumentId);
532 609 $aDocumentTransactions = DBUtil::getResultArray(array($sQuery, $aParams));
... ... @@ -537,12 +614,13 @@ class KTrss{
537 614  
538 615 // Get a listing of the latest 3 transactions for a folder
539 616 function getFolderTransactions($iFolderId){
540   - $sQuery = "SELECT DTT.name AS transaction_name, U.name AS user_name, FT.comment AS comment, FT.datetime AS datetime " .
  617 + $sQuery = "SELECT FT.datetime AS datetime, 'Folder' AS type, F.name, F.full_path AS fullpath, DTT.name AS transaction_name, U.name AS user_name, FT.comment AS comment " .
541 618 "FROM folder_transactions AS FT LEFT JOIN users AS U ON FT.user_id = U.id " .
542 619 "LEFT JOIN document_transaction_types_lookup AS DTT ON DTT.namespace = FT.transaction_namespace " .
  620 + "LEFT JOIN folders AS F ON FT.folder_id = F.id " .
543 621 "WHERE FT.folder_id = ? " .
544 622 "ORDER BY FT.datetime DESC " .
545   - "LIMIT 3";
  623 + "LIMIT 4";
546 624  
547 625 $aParams = array($iFolderId);
548 626 $aFolderTransactions = DBUtil::getResultArray(array($sQuery, $aParams));
... ...