]> git.mxchange.org Git - friendica.git/blobdiff - include/group.php
Merge pull request #2347 from annando/1602-dfrn-forum
[friendica.git] / include / group.php
index 862d06818dd0957bb8a7428f3a7c7b996b953e89..a1375e00dfa678f18368a407583d9d96e0625916 100644 (file)
@@ -297,17 +297,26 @@ function group_side($every="contacts",$each="group",$editmode = "standard", $gro
        return $o;
 }
 
-function expand_groups($a,$check_dead = false) {
+function expand_groups($a,$check_dead = false, $use_gcontact = false) {
        if(! (is_array($a) && count($a)))
                return array();
        $groups = implode(',', $a);
        $groups = dbesc($groups);
-       $r = q("SELECT `contact-id` FROM `group_member` WHERE `gid` IN ( $groups )");
+
+       if ($use_gcontact)
+               $r = q("SELECT `gcontact`.`id` AS `contact-id` FROM `group_member`
+                               INNER JOIN `contact` ON `contact`.`id` = `group_member`.`contact-id`
+                               INNER JOIN `gcontact` ON `gcontact`.`nurl` = `contact`.`nurl`
+                       WHERE `gid` IN ($groups)");
+       else
+               $r = q("SELECT `contact-id` FROM `group_member` WHERE `gid` IN ( $groups )");
+
+
        $ret = array();
        if(count($r))
                foreach($r as $rr)
                        $ret[] = $rr['contact-id'];
-       if($check_dead) {
+       if($check_dead AND !$use_gcontact) {
                require_once('include/acl_selectors.php');
                $ret = prune_deadguys($ret);
        }
@@ -340,3 +349,30 @@ function groups_containing($uid,$c) {
 
        return $ret;
 }
+/**
+ * @brief count unread group items
+ *
+ * Count unread items of each groups
+ *
+ * @return array
+ *     'id' => group id
+ *     'name' => group name
+ *     'count' => counted unseen group items
+ *
+ */
+function groups_count_unseen() {
+
+       $r = q("SELECT `group`.`id`, `group`.`name`, COUNT(`item`.`id`) AS `count` FROM `group`, `group_member`, `item`
+                       WHERE `group`.`uid` = %d
+                       AND `item`.`uid` = %d
+                       AND `item`.`unseen` AND `item`.`visible`
+                       AND NOT `item`.`deleted`
+                       AND `item`.`contact-id` = `group_member`.`contact-id`
+                       AND `group_member`.`gid` = `group`.`id`
+                       GROUP BY `group`.`id` ",
+               intval(local_user()),
+               intval(local_user())
+       );
+
+       return $r;
+}