Ignore:
Timestamp:
02/27/08 22:01:07 (4 years ago)
Author:
hverton
Message:

updated the forum_threads_list_panel module to make use of the thread_first_read functionality

File:
1 edited

Legend:

Unmodified
Added
Removed
  • modules/common/forum_threads_list_panel/php-files/modules/forum_threads_list_panel/new_posts_detail.php

    r1282 r1318  
    3737            WHERE tr.user_id = '".$userdata['user_id']."' 
    3838                AND (p.post_datestamp > ".$settings['unread_threshold']." OR p.post_edittime > ".$settings['unread_threshold'].") 
    39                 AND (p.post_datestamp > tr.thread_last_read OR p.post_edittime > tr.thread_last_read) 
     39                AND ((p.post_datestamp > tr.thread_last_read OR p.post_edittime > tr.thread_last_read) 
     40                    OR (p.post_datestamp < tr.thread_first_read OR (p.post_edittime != 0 AND p.post_edittime < tr.thread_first_read))) 
    4041            GROUP BY p.thread_id 
    4142        "); 
    4243    // update the last_read datestamp of all threads found 
    4344    while ($data = dbarray($result)) { 
    44         $result2 = dbquery("UPDATE ".$db_prefix."threads_read SET thread_last_read = '".time()."' WHERE user_id = '".$userdata['user_id']."' AND thread_id = '".$data['thread_id']."'"); 
     45        $result2 = dbquery("UPDATE ".$db_prefix."threads_read SET thread_first_read = '0', thread_last_read = '".time()."' WHERE user_id = '".$userdata['user_id']."' AND thread_id = '".$data['thread_id']."'"); 
    4546    } 
    4647    // done, fall back to the homepage 
     
    5354// check if there are any unread threads for this user 
    5455if ($userdata['user_posts_unread']) { 
    55     $result = dbquery("SELECT count(*) as unread, sum(tr.thread_page) AS pages FROM ".$db_prefix."posts p LEFT JOIN ".$db_prefix."threads_read tr ON p.thread_id = tr.thread_id WHERE tr.user_id = '".$userdata['user_id']."' AND (p.post_datestamp > ".$settings['unread_threshold']." OR p.post_edittime > ".$settings['unread_threshold'].") AND (p.post_datestamp > tr.thread_last_read OR p.post_edittime > tr.thread_last_read) GROUP BY tr.thread_id", false); 
     56    $result = dbquery(" 
     57        SELECT count(*) as unread, tr.thread_id 
     58            FROM ".$db_prefix."posts p  
     59                LEFT JOIN ".$db_prefix."threads_read tr ON p.thread_id = tr.thread_id  
     60            WHERE tr.user_id = '".$userdata['user_id']."'  
     61                AND (p.post_datestamp > ".$settings['unread_threshold']." OR p.post_edittime > ".$settings['unread_threshold'].") 
     62                AND ((p.post_datestamp > tr.thread_last_read OR p.post_edittime > tr.thread_last_read) 
     63                    OR (p.post_datestamp < tr.thread_first_read OR (p.post_edittime != 0 AND p.post_edittime < tr.thread_first_read))) 
     64            GROUP BY tr.thread_id" 
     65        ); 
    5666} else { 
    57     $result = dbquery("SELECT count(*) as unread, sum(tr.thread_page) AS pages FROM ".$db_prefix."posts p LEFT JOIN ".$db_prefix."threads_read tr ON p.thread_id = tr.thread_id WHERE tr.user_id = '".$userdata['user_id']."' AND p.post_author != '".$userdata['user_id']."' AND p.post_edittime != '".$userdata['user_id']."' AND (p.post_datestamp > ".$settings['unread_threshold']." OR p.post_edittime > ".$settings['unread_threshold'].") AND (p.post_datestamp > tr.thread_last_read OR p.post_edittime > tr.thread_last_read) GROUP BY tr.thread_id", false); 
    58 } 
    59 if (dbrows($result)) { 
    60     $data = dbarray($result); 
    61     $variables['threads'] = $data['unread']; 
    62 } else { 
    63     $variables['threads'] = 0; 
    64 } 
     67    $result = dbquery(" 
     68        SELECT count(*) as unread, tr.thread_id  
     69            FROM ".$db_prefix."posts p  
     70                LEFT JOIN ".$db_prefix."threads_read tr ON p.thread_id = tr.thread_id  
     71            WHERE tr.user_id = '".$userdata['user_id']."'  
     72                AND p.post_author != '".$userdata['user_id']."' 
     73                AND p.post_edituser != '".$userdata['user_id']."' 
     74                AND (p.post_datestamp > ".$settings['unread_threshold']." OR p.post_edittime > ".$settings['unread_threshold'].") 
     75                AND ((p.post_datestamp > tr.thread_last_read OR p.post_edittime > tr.thread_last_read) 
     76                    OR (p.post_datestamp < tr.thread_first_read OR (p.post_edittime != 0 AND p.post_edittime < tr.thread_first_read))) 
     77            GROUP BY tr.thread_id" 
     78        ); 
     79}  
     80$variables['threads'] = dbrows($result); 
    6581 
    66 // if any data found 
     82// if there are unread threads ... 
    6783if ($variables['threads']) { 
    6884 
    69     // check if there are any unread threads for this user 
     85    // get the unread posts 
    7086    if ($userdata['user_posts_unread']) { 
    71         $result = dbquery("SELECT count(*) as unread, sum(tr.thread_page) AS pages FROM ".$db_prefix."posts p LEFT JOIN ".$db_prefix."threads_read tr ON p.thread_id = tr.thread_id WHERE tr.user_id = '".$userdata['user_id']."' AND (p.post_datestamp > ".$settings['unread_threshold']." OR p.post_edittime > ".$settings['unread_threshold'].") AND (p.post_datestamp > tr.thread_last_read OR p.post_edittime > tr.thread_last_read)", false); 
     87        $result = dbquery(" 
     88            SELECT count(*) as unread  
     89                FROM ".$db_prefix."posts p  
     90                    LEFT JOIN ".$db_prefix."threads_read tr ON p.thread_id = tr.thread_id  
     91                WHERE tr.user_id = '".$userdata['user_id']."'  
     92                    AND (p.post_datestamp > ".$settings['unread_threshold']." OR p.post_edittime > ".$settings['unread_threshold'].") 
     93                    AND ((p.post_datestamp > tr.thread_last_read OR p.post_edittime > tr.thread_last_read) 
     94                        OR (p.post_datestamp < tr.thread_first_read OR (p.post_edittime != 0 AND p.post_edittime < tr.thread_first_read)))" 
     95            ); 
    7296    } else { 
    73         $result = dbquery("SELECT count(*) as unread, sum(tr.thread_page) AS pages FROM ".$db_prefix."posts p LEFT JOIN ".$db_prefix."threads_read tr ON p.thread_id = tr.thread_id WHERE tr.user_id = '".$userdata['user_id']."' AND p.post_author != '".$userdata['user_id']."' AND p.post_edituser != '".$userdata['user_id']."' AND (p.post_datestamp > ".$settings['unread_threshold']." OR p.post_edittime > ".$settings['unread_threshold'].") AND (p.post_datestamp > tr.thread_last_read OR p.post_edittime > tr.thread_last_read)", false); 
    74     } 
    75     if (dbrows($result)) { 
    76         $data = dbarray($result); 
    77         $variables['rows'] = $data['unread']; 
    78     } else { 
    79         $variables['rows'] = 0; 
    80     } 
     97        $result = dbquery(" 
     98            SELECT count(*) as unread  
     99                FROM ".$db_prefix."posts p  
     100                    LEFT JOIN ".$db_prefix."threads_read tr ON p.thread_id = tr.thread_id  
     101                WHERE tr.user_id = '".$userdata['user_id']."'  
     102                    AND p.post_author != '".$userdata['user_id']."' 
     103                    AND p.post_edituser != '".$userdata['user_id']."' 
     104                    AND (p.post_datestamp > ".$settings['unread_threshold']." OR p.post_edittime > ".$settings['unread_threshold'].") 
     105                    AND ((p.post_datestamp > tr.thread_last_read OR p.post_edittime > tr.thread_last_read) 
     106                        OR (p.post_datestamp < tr.thread_first_read OR (p.post_edittime != 0 AND p.post_edittime < tr.thread_first_read)))" 
     107            ); 
     108    }  
     109    $variables['rows'] = ($result ? mysql_result($result, 0) : 0); 
    81110 
    82111    // make sure rowstart has a valid value 
     
    95124                    WHERE tr.user_id = '".$userdata['user_id']."' 
    96125                        AND (p.post_datestamp > ".$settings['unread_threshold']." OR p.post_edittime > ".$settings['unread_threshold'].") 
    97                         AND (p.post_datestamp > tr.thread_last_read OR p.post_edittime > tr.thread_last_read) 
    98                     ORDER BY post_datestamp ASC LIMIT $rowstart,".ITEMS_PER_PAGE 
     126                        AND ((p.post_datestamp > tr.thread_last_read OR p.post_edittime > tr.thread_last_read) 
     127                            OR (p.post_datestamp < tr.thread_first_read OR (p.post_edittime != 0 AND p.post_edittime < tr.thread_first_read))) 
     128                    ORDER BY post_datestamp ASC  
     129                    LIMIT $rowstart,".ITEMS_PER_PAGE 
    99130                ); 
    100131    } else { 
     
    110141                        AND p.post_edituser != '".$userdata['user_id']."' 
    111142                        AND (p.post_datestamp > ".$settings['unread_threshold']." OR p.post_edittime > ".$settings['unread_threshold'].") 
    112                         AND (p.post_datestamp > tr.thread_last_read OR p.post_edittime > tr.thread_last_read) 
    113                     ORDER BY post_datestamp ASC LIMIT $rowstart,".ITEMS_PER_PAGE 
     143                        AND ((p.post_datestamp > tr.thread_last_read OR p.post_edittime > tr.thread_last_read) 
     144                            OR (p.post_datestamp < tr.thread_first_read OR (p.post_edittime != 0 AND p.post_edittime < tr.thread_first_read))) 
     145                    ORDER BY post_datestamp ASC  
     146                    LIMIT $rowstart,".ITEMS_PER_PAGE 
    114147                ); 
    115148    } 
Note: See TracChangeset for help on using the changeset viewer.