From 0e8991fec2bc27f0bfab308cc9b04406e42c6dd8 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Tue, 11 Aug 2015 22:23:20 -0700 Subject: more consistent output on forum widget --- include/widgets.php | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/include/widgets.php b/include/widgets.php index 49470287e..e735f5b2f 100644 --- a/include/widgets.php +++ b/include/widgets.php @@ -1001,17 +1001,39 @@ function widget_forums($arr) { else $limit = ''; + $unseen = 0; + if(is_array($arr) && array_key_exists('unseen',$arr) && intval($arr['unseen'])) + $unseen = 1; + $perms_sql = item_permissions_sql(local_channel()) . item_normal(); - - $r = q("select sum(item_unseen) as unseen, owner_xchan, abook_id, xchan.* from xchan left join item on owner_xchan = xchan_hash left join abook on abook_xchan = xchan_hash where xchan_pubforum = 1 and uid = %d and abook_channel = %d $perms_sql group by owner_xchan order by xchan_name $limit ", - intval(local_channel()), + + $r1 = q("select * from abook left join xchan on abook_xchan = xchan_hash where xchan_pubforum = 1 and abook_channel = %d order by xchan_name $limit ", intval(local_channel()) ); - if($r) { + if(! $r1) + return $o; + + $str = ''; + + // Trying to cram all this into a single query with joins and the proper group by's is tough. + // There also should be a way to update this via ajax. + + for($x = 0; $x < count($r1); $x ++) { + $r = q("select sum(item_unseen) as unseen from item where owner_xchan = '%s' and uid = %d $perms_sql ", + dbesc($r1[$x]['xchan_hash']), + intval(local_channel()) + ); + if($r) + $r1[$x]['unseen'] = $r[0]['unseen']; + } + + if($r1) { $o .= '
'; $o .= '

' . t('Forums') . '

'; -- cgit v1.2.3