]> git.mxchange.org Git - friendica.git/blobdiff - include/group.php
Fixes E_WARNING from foreach() because count() seem to return TRUE even when $r is...
[friendica.git] / include / group.php
index fd1c97dfde47d1af8c665b03eac51370428a7940..2b872f16a7ce95234bdae038d3546df1f1242147 100644 (file)
@@ -215,7 +215,7 @@ function mini_group_select($uid,$gid = 0) {
 
 /**
  * @brief Create group sidebar widget
- * 
+ *
  * @param string $every
  * @param string $each
  * @param string $editmode
@@ -234,7 +234,7 @@ function group_side($every="contacts",$each="group",$editmode = "standard", $gro
                return '';
 
        $groups = array();
-       
+
        $groups[] = array(
                'text'  => t('Everybody'),
                'id' => 0,
@@ -255,7 +255,7 @@ function group_side($every="contacts",$each="group",$editmode = "standard", $gro
        if(count($r)) {
                foreach($r as $rr) {
                        $selected = (($group_id == $rr['id']) ? ' group-selected' : '');
-                       
+
                        if ($editmode == "full") {
                                $groupedit = array(
                                        'href' => "group/".$rr['id'],
@@ -264,7 +264,7 @@ function group_side($every="contacts",$each="group",$editmode = "standard", $gro
                        } else {
                                $groupedit = null;
                        }
-                       
+
                        $groups[] = array(
                                'id'            => $rr['id'],
                                'cid'           => $cid,
@@ -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);
        }
@@ -353,17 +362,16 @@ function groups_containing($uid,$c) {
  */
 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` ",
+       $r = q("SELECT `group`.`id`, `group`.`name`,
+                       (SELECT COUNT(*) FROM `item`
+                               WHERE `uid` = %d AND `unseen` AND
+                                       `contact-id` IN (SELECT `contact-id` FROM `group_member`
+                                                               WHERE `group_member`.`gid` = `group`.`id` AND `group_member`.`uid` = %d)) AS `count`
+                       FROM `group` WHERE `group`.`uid` = %d;",
+               intval(local_user()),
                intval(local_user()),
                intval(local_user())
        );
 
        return $r;
-}
\ No newline at end of file
+}