/**
  * Returns an array of BlogInfo objects with the information of all the blogs to which
  * a user belongs
  *
  * @param userId Identifier of the user
  * @return An array of BlogInfo objects to whom the user belongs.
  */
 function getUsersBlogs($userid, $status = BLOG_STATUS_ALL)
 {
     $usersBlogs = array();
     $blogs = new Blogs();
     $ids = array();
     // check if the user is the owner of any blog
     $prefix = $this->getPrefix();
     $owner = "SELECT * FROM {$prefix}blogs WHERE owner_id = " . $userid;
     if ($status != BLOG_STATUS_ALL) {
         $owner .= " AND status = '" . Db::qstr($status) . "'";
     }
     $result = $this->Execute($owner);
     while ($row = $result->FetchRow($result)) {
         $usersBlogs[] = $blogs->_fillBlogInformation($row);
         $ids[] = $row["id"];
     }
     // and now check to which other blogs he or she belongs
     $otherBlogs = "SELECT b.* FROM {$prefix}blogs b, {$prefix}users_permissions p \n                           WHERE p.user_id = '" . Db::qstr($userid) . "' AND b.id = p.blog_id";
     if (!empty($usersBlogs)) {
         $blogIds = implode(",", $ids);
         $otherBlogs .= " AND p.blog_id NOT IN (" . $blogIds . ")";
     }
     if ($status != BLOG_STATUS_ALL) {
         $otherBlogs .= " AND b.status = '" . Db::qstr($status) . "'";
     }
     $result = $this->Execute($otherBlogs);
     // now we know to which he or she belongs, so we only have
     // to load the information about those blogs
     while ($row = $result->FetchRow($result)) {
         $usersBlogs[] = $blogs->_fillBlogInformation($row);
     }
     return $usersBlogs;
 }