librefm-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Librefm-commits] [1025] Beginnings of group listing and group creation.


From: Toby Inkster
Subject: [Librefm-commits] [1025] Beginnings of group listing and group creation.
Date: Wed, 29 Apr 2009 22:16:53 +0000

Revision: 1025
          http://svn.sv.gnu.org/viewvc/?view=rev&root=librefm&revision=1025
Author:   tobyink
Date:     2009-04-29 22:16:53 +0000 (Wed, 29 Apr 2009)
Log Message:
-----------
Beginnings of group listing and group creation.

Modified Paths:
--------------
    trunk/nixtape/data/Group.php
    trunk/nixtape/group.php

Modified: trunk/nixtape/data/Group.php
===================================================================
--- trunk/nixtape/data/Group.php        2009-04-29 21:33:39 UTC (rev 1024)
+++ trunk/nixtape/data/Group.php        2009-04-29 22:16:53 UTC (rev 1025)
@@ -79,6 +79,63 @@
                }               
        }
        
+       static function create ($name, $owner)
+       {
+               global $mdb2;
+               
+               $q = sprintf("INSERT INTO Groups (groupname, owner, modified) 
VALUES (%s, %s, %d)"
+                               , $mdb2->quote($name, 'text')
+                               , $mdb2->quote($owner->name, 'text')
+                               , time());
+               $res = $mdb2->query($q);
+               
+               if(PEAR::isError($res)) {
+                       header("Content-Type: text/plain");
+                       print_r($res);
+                       exit;
+               }
+
+               $q = sprintf("INSERT INTO Group_Members (groupname, member, 
joined) VALUES (%s, %s, %d)"
+                               , $mdb2->quote($name, 'text')
+                               , $mdb2->quote($owner->name, 'text')
+                               , time());
+               $res = $mdb2->query($q);
+               
+               if(PEAR::isError($res)) {
+                       header("Content-Type: text/plain");
+                       print_r($res);
+                       exit;
+               }
+
+               return 1;
+       }
+       
+       static function groupList ()
+       {
+               global $mdb2;
+               $res = $mdb2->query("SELECT g.groupname, g.owner, g.fullname, 
g.bio, g.homepage, g.created, g.modifed, g.avatar_uri, g.grouptype, COUNT(*) AS 
gm.member_count "
+                       ."FROM Groups g "
+                       ."LEFT JOIN Group_Members gm ON 
gm.groupname=g.groupname "
+                       ."GROUP BY g.groupname, g.owner, g.fullname, g.bio, 
g.homepage, g.created, g.modifed, g.avatar_uri, g.grouptype");
+               
+               if(PEAR::isError($res))
+               {
+                       header("Content-Type: text/plain");
+                       print_r($res);
+                       exit;
+               }
+
+               $list = array();
+               while ($row = $res->fetchRow(MDB2_FETCHMODE_ASSOC))
+               {
+                       $g = new Group($row['group_name'], $row);
+                       $g->count = $row['member_count'];
+                       $list[] = $g;
+               }
+
+               return $list;
+       }
+       
        function save ()
        {
                global $mdb2;

Modified: trunk/nixtape/group.php
===================================================================
--- trunk/nixtape/group.php     2009-04-29 21:33:39 UTC (rev 1024)
+++ trunk/nixtape/group.php     2009-04-29 22:16:53 UTC (rev 1025)
@@ -27,7 +27,9 @@
 
 if (! $_GET['group'])
 {
-       print "Here we should provide a list of existing groups, perhaps 
largest first.";
+       header('Content-Type: text/plain');
+       print "Here we should provide a list of existing groups, perhaps 
largest first.\n\n";
+       print_r( Group::groupList() );
        exit;
 }
 





reply via email to

[Prev in Thread] Current Thread [Next in Thread]