/[drupal]/contributions/modules/ShindigIntegrator/shindig_integrator/shindig_files/ShindigIntegratorDbFetcher.php
ViewVC logotype

Diff of /contributions/modules/ShindigIntegrator/shindig_integrator/shindig_files/ShindigIntegratorDbFetcher.php

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.2, Mon Dec 8 12:58:17 2008 UTC revision 1.3, Thu Oct 22 10:51:44 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id$  // $Id: ShindigIntegratorDbFetcher.php,v 1.2.2.11 2009/08/14 11:40:51 impetus Exp $
3  /**  /**
4   * @file   * @file
5   * DB interaction layer for shindig services   * DB interaction layer for shindig services
# Line 58  class ShindigIntegratorDbFetcher { Line 58  class ShindigIntegratorDbFetcher {
58          public function getFriendIds($user_id)          public function getFriendIds($user_id)
59          {          {
60                  $ret = array();                  $ret = array();
61                  $res = db_query("select requester_id, requestee_id from user_relationships where requester_id = %d or requestee_id = %d and rtid=(select rtid from user_relationship_types where name='friend') and approved=1", $user_id, $user_id);                  $res = db_query("SELECT requester_id, requestee_id FROM user_relationships WHERE requester_id = %d OR requestee_id = %d AND rtid=(select rtid FROM user_relationship_types WHERE name='friend') AND approved=1", $user_id, $user_id);
62                  while ($row = db_fetch_array($res)) {                  while ($row = db_fetch_array($res)) {
63                          if($row['requester_id']==$user_id)                          if($row['requester_id']==$user_id)
64                          {                          {
# Line 93  class ShindigIntegratorDbFetcher { Line 93  class ShindigIntegratorDbFetcher {
93                  foreach($ids as $id)                  foreach($ids as $id)
94                  {                  {
95                          $user =array();                          $user =array();
96                          $res = db_query("SELECT * FROM profile_values INNER JOIN profile_fields ON profile_values.fid = profile_fields.fid WHERE uid =%d", $id);                          $res = db_query("SELECT * FROM profile_values INNER JOIN profile_fields ON profile_values.fid = profile_fields.fid WHERE uid =%d", $id);
97                          if ($res) {                          if ($res) {
98                                  while ($row = db_fetch_array($res))                                  while ($row = db_fetch_array($res))
99                                  {                                  {
100                                          $user[$row['name']] = $row['value'];                                          $user[$row['name']] = $row['value'];
101                                          $user['uid'] = $row['uid'];                                          $user['uid'] = $row['uid'];
102                                  }                                  }
103                          }                                  if(!empty($user)) {
104                          $user_id = $user['uid'];                                $user_id = $user['uid'];
105                          $name = new Name($user['profile_fname'] . ' ' . $user['profile_lname']);                                $name = new Name($user['profile_fname'] . ' ' . $user['profile_lname']);
106                          $name->setGivenName($user['profile_fname']);                                $name->setGivenName($user['profile_fname']);
107                          $name->setFamilyName($user['profile_lname']);                                $name->setFamilyName($user['profile_lname']);
108                          $person = new Person($user['uid'], $name);                                $person = new Person($user['uid'], $name);
109                          $person->setProfileUrl($this->url_prefix . 'user/' . $user['uid']);                                $person->setProfileUrl($this->url_prefix . 'user/' . $user['uid']);
110              $person->setDisplayName($user['profile_fname'] . ' ' . $user['profile_lname']);                    $person->setDisplayName($user['profile_fname'] . ' ' . $user['profile_lname']);
111                          $res = db_query("SELECT picture FROM users where uid = %d",$id);                                $res = db_query("SELECT picture FROM users WHERE uid = %d",$id);
112                          $row =  db_fetch_array($res);                                $row =  db_fetch_array($res);
113                          $person->setThumbnailUrl(! empty($row['picture']) ? $this->url_prefix.$row['picture'] : '');                                $person->setThumbnailUrl(! empty($row['picture']) ? $this->url_prefix.$row['picture'] : '');
114                                                  if ($user['profile_gender'] == 'Female') {                                if ($user['profile_gender'] == 'Female') {
115                                                      $person->setGender('FEMALE');                                  $person->setGender('FEMALE');
116                                              } else {                                } else {
117                                                      $person->setGender('MALE');                                  $person->setGender('MALE');
118                                              }                                }
119                                  $ret[$user_id] = $person;
120                              }
121                                  $ret[$user_id] = $person;                          }
   
122                  }                  }
123    
124                  return $ret;                  return $ret;
125          }          }
126    
127          /**          /**
128            * Get User Id(s) who have specific application
129            * Return array of Person Model Objects
130            *
131            * @param
132            *   $appId application id
133            * @return
134            *   $peopleWithApp array of person ids
135            */
136            public function getPeopleWithApp($appId) {
137                    $peopleWithApp = array();
138                    $res = db_query("SELECT user_id FROM user_applications WHERE application_id=%d", $appId);
139                    while ($row = db_fetch_array($res)) {
140                                    $peopleWithApp[] = $row['user_id'];
141                    }
142                    return $peopleWithApp;
143            }
144    
145            /**
146          * To save PersonAppData into database          * To save PersonAppData into database
147          *          *
148          * @param          * @param
# Line 137  class ShindigIntegratorDbFetcher { Line 154  class ShindigIntegratorDbFetcher {
154          * @param          * @param
155          *   $appId application to which Appdata belongs to          *   $appId application to which Appdata belongs to
156          */          */
157          public function setAppData($user_id, $key, $value, $app_id)          public function setAppData($userId, $key, $value, $appId)
158          {          {
159                    $user_id = $user_id;
160                    $app_id = $app_id;
161    
162                  if (empty($value)) {                  if (empty($value)) {
163                          if (! db_query("delete from application_settings where application_id = %d and user_id = %d and name = '%s'", $app_id, $user_id, $key)) {                          if (! db_query("DELETE FROM {application_settings} WHERE application_id = %d AND user_id = %d AND name = '%s'", $appId, $userId, $key)) {
164                                  return false;                                  return false;
165                          }                          }
166                  } else {                  } else {
167                          if (! db_query("insert into application_settings (application_id, user_id, module_id, name, value) values (%d, %d, 0, '%s', '%s') on duplicate key update value = '%s'", $app_id, $user_id, $key, $value, $value)) {                          if (! db_query("INSERT INTO {application_settings} (application_id, user_id, name, value) VALUES (%d, %d, '%s', '%s') ON DUPLICATE KEY UPDATE value = '%s'", $appId, $userId, $key, $value, $value)) {
168                                  return false;                                  return false;
169                          }                          }
170                  }                  }
171                  return true;                  return true;
172          }          }
173    
174          /**          /**
175          * To get PersonAppData          * To get PersonAppData
176          *          *
# Line 162  class ShindigIntegratorDbFetcher { Line 182  class ShindigIntegratorDbFetcher {
182          *   $appId application to which Appdata belongs to          *   $appId application to which Appdata belongs to
183          * @return          * @return
184          *   $data Appdata          *   $data Appdata
185          */          */
186          public function getAppData($ids, $keys, $app_id)          public function getAppData($ids, $keys, $app_id) {
187          {      $data = array();
188                  $data = array();      if(count($ids)) {
189                  foreach ($ids as $key => $val) {        $placeholders_ids = array_fill(0, count($ids), "%d");
190                          $ids[$key] = $val;        if (in_array("@all", $keys)) {
191                  }          $res = db_query("SELECT user_id, name, value FROM application_settings WHERE application_id = %d AND user_id IN (" . implode(',', $placeholders_ids) . ")", $app_id, $ids);
192                  if ($keys[0] == '*') {        }
193                          $keys = '';            else {
194                  } else {              if(count($keys)) {
195                          foreach ($keys as $key => $val) {          $placeholders_keys = array_fill(0, count($keys), "%s");
196                                  $keys[$key] = "'" . $val . "'";          $values = array();
197                          }          $values[] = $app_id;
198                          $keys = "and name in (" . implode(',', $keys) . ")";          $values = array_merge($values, $ids);
199                  }          $values = array_merge($values, $keys);
200                  $res = db_query("select user_id, name, value from application_settings where application_id = %d and user_id in (" . implode(',', $ids) . ") $keys", $app_id);          $res = db_query("SELECT user_id, name, value FROM application_settings WHERE application_id = %d
201                  while ($app_data = db_fetch_array($res)) {                          AND user_id IN (" . implode(',', $placeholders_ids) . ")
202                          $user_id = $app_data['user_id'];                                                  AND name IN ('". implode(',', $placeholders_keys )."')", $values);
203                          if (! isset($user_id)) {              }
204                                  $data[$user_id] = array();        }
205                          }        while ($app_data = db_fetch_array($res)) {
206                          $key = $app_data['name'];          $user_id = $app_data['user_id'];
207                          $value = $app_data['value'];          if (! isset($user_id)) {
208                          $data[$user_id][$key] = $value;            $data[$user_id] = array();
209                  }          }
210                  return $data;          $key = $app_data['name'];
211          }          $value = $app_data['value'];
212            $data[$user_id][$key] = $value;
213          }
214        }
215        return $data;
216      }
217    
218          /**          /**
219          * Delete PersonAppData          * Delete PersonAppData
220          *          *
# Line 203  class ShindigIntegratorDbFetcher { Line 228  class ShindigIntegratorDbFetcher {
228          public function deleteAppData($userId, $key, $appId)          public function deleteAppData($userId, $key, $appId)
229          {          {
230                  $userId = $userId;                  $userId = $userId;
                 $key = $key;  
231                  $appId = $appId;                  $appId = $appId;
232                  if(!db_query("delete from application_settings where application_id = %d and user_id = %d and name = '%s'",$appId,$userId,$key)) {                  if($key == "*") {
233                      if(!db_query("DELETE FROM {application_settings} WHERE application_id = %d AND user_id = %d ", $appId, $userId)) {
234                            return false;
235                      }
236                    } else {
237                      if(!db_query("DELETE FROM {application_settings} WHERE application_id = %d AND user_id = %d AND name = '%s'", $appId, $userId, $key)) {
238                          return false;                          return false;
239                      }
240                  }                  }
241                  return true;                  return true;
242    
# Line 227  class ShindigIntegratorDbFetcher { Line 257  class ShindigIntegratorDbFetcher {
257                  $title = isset($activity['title']) ? trim($activity['title']) : '';                  $title = isset($activity['title']) ? trim($activity['title']) : '';
258                  $body = isset($activity['body']) ? trim($activity['body']) : '';                  $body = isset($activity['body']) ? trim($activity['body']) : '';
259                  $time = time();                  $time = time();
260                  db_query("insert into activities (id, user_id, app_id, title, body, created) values (0, %d, %d, '%s', '%s', $time)", $user_id, $app_id, $title, $body);                  db_query("INSERT INTO activities (id, user_id, app_id, title, body, created) VALUES (0, %d, %d, '%s', '%s', $time)", $user_id, $app_id, $title, $body);
261                  if (! ($activityId = mysql_insert_id())) {                  if (! ($activityId = db_last_insert_id('activities', 'id'))) {
262                          return false;                          return false;
263                  }                  }
264                  $mediaItems = isset($activity['mediaItems']) ? $activity['mediaItems'] :  array();                  $mediaItems = isset($activity['mediaItems']) ? $activity['mediaItems'] :  array();
# Line 240  class ShindigIntegratorDbFetcher { Line 270  class ShindigIntegratorDbFetcher {
270                                  $type = trim($type);                                  $type = trim($type);
271                                  $mimeType = trim($mimeType);                                  $mimeType = trim($mimeType);
272                                  $url = trim($url);                                  $url = trim($url);
273                                  db_query("insert into activity_media_items (id, activity_id, mime_type, media_type, url) values (0, %d, '%s', '%s', '%s')", $activityId, $mimeType, $type, $url);                                  db_query("INSERT INTO activity_media_items (id, activity_id, mime_type, media_type, url) VALUES (0, %d, '%s', '%s', '%s')", $activityId, $mimeType, $type, $url);
274                          }                          }
275                  }                  }
276                  return true;                  return true;
# Line 273  class ShindigIntegratorDbFetcher { Line 303  class ShindigIntegratorDbFetcher {
303                          $ids[$key] = $val;                          $ids[$key] = $val;
304                  }                  }
305                  $res = db_query("                  $res = db_query("
306                          select                          SELECT
307                                  activities.user_id as user_id,                                  activities.user_id as user_id,
308                                  activities.id as activity_id,                                  activities.id as activity_id,
309                                  activities.title as activity_title,                                  activities.title as activity_title,
310                                  activities.body as activity_body,                                  activities.body as activity_body,
311                                  activities.created as created                                  activities.created as created
312                          from                          FROM
313                                  activities                                  activities
314                          where                          WHERE
315                                  activities.user_id in (" . implode(',', $ids) . ")                                  activities.user_id IN (" . implode(',', $ids) . ")
316                          order by                          ORDER BY
317                                  created desc                                  created DESC
318                          ");                          ");
319                  while ($row = db_fetch_array($res)) {                  while ($row = db_fetch_array($res)) {
320                          $activity = new Activity($row['activity_id'], $row['user_id']);                          $activity = new Activity($row['activity_id'], $row['user_id']);
# Line 310  class ShindigIntegratorDbFetcher { Line 340  class ShindigIntegratorDbFetcher {
340          {          {
341                  $media = array();                  $media = array();
342                  $activity_id = $activity_id;                  $activity_id = $activity_id;
343                  $res = db_query("select mime_type, media_type, url from activity_media_items where activity_id = %d", $activity_id);                  $res = db_query("SELECT mime_type, media_type, url FROM activity_media_items WHERE activity_id = %d", $activity_id);
344                  while ($row = db_fetch_array($res)) {                  while ($row = db_fetch_array($res)) {
345                          $media[] = new MediaItem($row['mime_type'], $row['media_type'], $row['url']);                          $media[] = new MediaItem($row['mime_type'], strtoupper($row['media_type']), $row['url']);
346                  }                  }
347                  return $media;                  return $media;
348          }          }

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

  ViewVC Help
Powered by ViewVC 1.1.2