http://atutor.ca/atutor/mantis/view.php?id=4451
authorharris wong <hwong@ocad.ca>
Mon, 9 Aug 2010 19:19:32 +0000 (19:19 -0000)
committerharris wong <hwong@ocad.ca>
Mon, 9 Aug 2010 19:19:32 +0000 (19:19 -0000)
docs/mods/_standard/social/lib/Shindig/ATutorDbFetcher.php
docs/mods/_standard/social/lib/Shindig/ATutorGroupService.php [new file with mode: 0644]

index dcc15bb..b9512f0 100644 (file)
@@ -137,7 +137,6 @@ class ATutorDbFetcher {
 
   public function getActivities($ids, $appId, $sortBy, $filterBy, $filterOp, $filterValue, $startIndex, $count, $fields, $activityIds) {
 //  public function getActivities($ids, $appId, $sortBy, $filterBy, $filterOp, $filterValue, $startIndex, $count, $fields) {
-       global $db;
     //TODO add support for filterBy, filterOp and filterValue
     $this->checkDb();
     $activities = array();
@@ -209,7 +208,7 @@ class ATutorDbFetcher {
   }
 
 /**
-  * I didn't implement this yet
+  * I haven't implement this yet
   */
   private function getMediaItems($activity_id) {
     $media = array();
@@ -221,6 +220,30 @@ class ATutorDbFetcher {
     return $media;
   }  
 
+  /**
+   * Retrieve all the groups of this person.  
+   * reference: http://www.opensocial.org/Technical-Resources/opensocial-spec-v081/restful-protocol.html Section 2.3
+   * Group ID, and Title.
+   * @param     Array   member ids
+   */
+  public function getPersonGroups($ids){
+        $this->checkDb();
+        $ret = array();
+
+        foreach ($ids as $k=>$v){
+            $ids[$k] = intval($v);
+        }
+        $ids = implode(', ', $ids);
+        $sql = "SELECT m.member_id, g.id, g.name FROM ".TABLE_PREFIX."social_groups_members m LEFT JOIN ".TABLE_PREFIX."social_groups g ON m.group_id=g.id WHERE m.member_id IN ($ids)";
+        $result = mysql_query($sql, $this->db);
+        if ($result){
+            while(list($member_id, $group_id, $group_name) = mysql_fetch_row($result)){
+                $ret[$member_id][] = array($group_id, $group_name);
+            }
+        }
+        return $ret;
+  }
+
   /**
    * @param            Int                                             Sender's member id
    * @param            appId                                   application id
@@ -228,7 +251,6 @@ class ATutorDbFetcher {
    * @return   null
    */
   public function createMessage($member_id, $appId, $message){
-       global $db;
        $this->checkDb();
        $app_id = intval($app_id);
        $member_id = intval($member_id);
@@ -262,11 +284,10 @@ class ATutorDbFetcher {
   }
 
   public function getFriendIds($member_id) {
-       global $db;
     $this->checkDb();
     $ret = array();
-    $person_id = intval($person_id);
-       $sql = "select member_id, friend_id from ".TABLE_PREFIX."social_friends where member_id = $member_id or friend_id = $member_id";
+    $member_id = intval($member_id);
+       $sql = "SELECT member_id, friend_id from ".TABLE_PREFIX."social_friends WHERE member_id = $member_id or friend_id = $member_id";
     $res = mysql_query($sql, $this->db);
     while (list($mid, $fid) = mysql_fetch_row($res)) {
       $id = ($mid == $member_id) ? $fid : $mid;
@@ -297,7 +318,6 @@ class ATutorDbFetcher {
   }
 
   public function deleteAppData($member_id, $key, $app_id) {
-    global $db;
        $this->checkDb();
     $person_id = intval($member_id);
     $app_id = intval($app_id);
diff --git a/docs/mods/_standard/social/lib/Shindig/ATutorGroupService.php b/docs/mods/_standard/social/lib/Shindig/ATutorGroupService.php
new file mode 100644 (file)
index 0000000..f928e5a
--- /dev/null
@@ -0,0 +1,31 @@
+<?php
+/***********************************************************************/
+/* ATutor                                                                                                                         */
+/***********************************************************************/
+/* Copyright (c) 2002-2010                                             */
+/* Inclusive Design Institute                                         */
+/* http://atutor.ca                                                                                                       */
+/*                                                                                                                                        */
+/* This program is free software. You can redistribute it and/or          */
+/* modify it under the terms of the GNU General Public License            */
+/* as published by the Free Software Foundation.                                          */
+/***********************************************************************/
+// $Id$
+
+class ATutorGroupService extends ATutorService implements GroupService {
+  /**
+   * Fetch groups for a list of ids.
+   * @param UserId The user id to perform the action for
+   * @param GroupId optional grouping ID
+   * @param token The SecurityToken for this request
+   * @return ResponseItem a response item with the error code set if
+   *     there was a problem
+   */
+  function getPersonGroups($userId, GroupId $groupId, SecurityToken $token){
+    $ids = $this->getIdSet($userId, $groupId, $token);
+    $data = ATutorDbFetcher::get()->getPersonGroups($ids);
+    // If the data array is empty, return empty DataCollection.
+    return new DataCollection($data);
+  }
+}
+?>
\ No newline at end of file