Ejemplo n.º 1
0
 public function getActivities($ids)
 {
     $activities = array();
     foreach ($ids as $key => $val) {
         $ids[$key] = mysql_real_escape_string($val, $this->db);
     }
     $res = mysql_query("\r\n\t\t\tselect \r\n\t\t\t\tactivities.user_id as user_id,\r\n\t\t\t\tactivities.id as activity_id,\r\n\t\t\t\tactivities.title as activity_title,\r\n\t\t\t\tactivities.body as activity_body,\r\n\t\t\t\tactivities.created as created\r\n\t\t\tfrom \r\n\t\t\t\tactivities\r\n\t\t\twhere\r\n\t\t\t\tactivities.user_id in (" . implode(',', $ids) . ")\r\n\t\t\torder by \r\n\t\t\t\tcreated desc\r\n\t\t\t");
     while ($row = @mysql_fetch_assoc($res)) {
         $activity = new Activity($row['activity_id'], $row['user_id']);
         $activity->setStreamTitle('activities');
         $activity->setTitle($row['activity_title']);
         $activity->setBody($row['activity_body']);
         $activity->setPostedTime($row['created']);
         $activity->setMediaItems($this->getMediaItems($row['activity_id']));
         $activities[] = $activity;
     }
     return $activities;
 }
 private function createActivities($streamItem, $userId, $streamTitle)
 {
     foreach ($streamItem->activity as $activityItem) {
         $title = isset($activityItem['title']) ? (string) $activityItem['title'] : '';
         $id = isset($activityItem['id']) ? (string) $activityItem['id'] : 0;
         $body = isset($activityItem['body']) ? (string) $activityItem['body'] : '';
         $activity = new Activity($id, $userId);
         $activity->setStreamTitle($this->turnEvil($streamTitle));
         $activity->setTitle($this->turnEvil($title));
         $activity->setBody($this->turnEvil($body));
         $activity->setMediaItems($this->getMediaItems($activityItem));
         $this->createActivity($userId, $activity, 0);
     }
 }
 /**
  * Tests Activity->getMediaItems()
  */
 public function testGetMediaItems()
 {
     $mediaItems = array('foo' => 'bar');
     $this->Activity->setMediaItems($mediaItems);
     $this->assertEquals($mediaItems, $this->Activity->getMediaItems());
 }
 /**
  * To get Activities of the User(s)
  *
  * @param
  *   $ids userids - for all activites needs to be fetched
  * @param
  *   $app_id application to which Activity belongs to
  * @param
  *   $sortBy to sort result sets by
  * @param
  *   $filterBy to filter activity results
  * @param
  *   $startIndex start index for pagination of results
  * @param
  *   $count number of results on the page
  * @param
  *   $fields activity fields in the results
  * @return
  *   $activities array of activity objects
  */
 public function getActivities($ids, $appId, $sortBy, $filterBy, $startIndex, $count, $fields)
 {
     $activities = array();
     foreach ($ids as $key => $val) {
         $ids[$key] = $val;
     }
     if (!is_array($ids) || count($ids) < 1) {
         return $activities;
     }
     $res = db_query("\n\t\t\tSELECT \n\t\t\t\tactivities.user_id as user_id,\n\t\t\t\tactivities.id as activity_id,\n\t\t\t\tactivities.title as activity_title,\n\t\t\t\tactivities.body as activity_body,\n\t\t\t\tactivities.created as created\n\t\t\tFROM \n\t\t\t\t{activities}\n\t\t\tWHERE\n\t\t\t\tactivities.user_id IN (" . implode(',', $ids) . ")\n\t\t\tORDER BY \n\t\t\t\tcreated DESC\n\t\t\t");
     while ($row = db_fetch_array($res)) {
         $activity = new Activity($row['activity_id'], $row['user_id']);
         $activity->setStreamTitle('activities');
         $activity->setTitle($row['activity_title']);
         $activity->setBody($row['activity_body']);
         $activity->setPostedTime($row['created']);
         $activity->setMediaItems($this->getMediaItems($row['activity_id']));
         $activities[] = $activity;
     }
     //Invoke hook_activities_alter() implementations
     $this->drupalAlter('activities', $activities, $appId);
     return $activities;
 }
Ejemplo n.º 5
0
 public function getActivities($ids, $appId, $sortBy, $filterBy, $filterOp, $filterValue, $startIndex, $count, $fields, $activityIds)
 {
     //TODO add support for filterBy, filterOp and filterValue
     $this->checkDb();
     $activities = array();
     $ids = array_map('intval', $ids);
     $ids = implode(',', $ids);
     if (isset($activityIds) && is_array($activityIds)) {
         $activityIds = array_map('intval', $activityIds);
         $activityIdQuery = " and activities.id in (" . implode(',', $activityIds);
     } else {
         $activityIdQuery = '';
     }
     $appIdQuery = $appId ? " and activities.app_id = " . intval($appId) : '';
     // return a proper totalResults count
     $res = mysqli_query($this->db, "select count(id) from activities where activities.person_id in ({$ids}) {$activityIdQuery} {$appIdQuery}");
     if ($res !== false) {
         list($totalResults) = mysqli_fetch_row($res);
     } else {
         $totalResults = '0';
     }
     $startIndex = !is_null($startIndex) && $startIndex !== false && is_numeric($startIndex) ? intval($startIndex) : '0';
     $count = !is_null($count) && $count !== false && is_numeric($count) ? intval($count) : '20';
     $activities['totalResults'] = $totalResults;
     $activities['startIndex'] = $startIndex;
     $activities['count'] = $count;
     $query = "\n      select\n        activities.person_id as person_id,\n        activities.id as activity_id,\n        activities.title as activity_title,\n        activities.body as activity_body,\n        activities.created as created\n      from\n        activities\n      where\n        activities.person_id in ({$ids})\n        {$activityIdQuery}\n        {$appIdQuery}\n      order by\n        created desc\n      limit\n        {$startIndex}, {$count}\n      ";
     $res = mysqli_query($this->db, $query);
     if ($res) {
         if (@mysqli_num_rows($res)) {
             while ($row = @mysqli_fetch_array($res, MYSQLI_ASSOC)) {
                 $activity = new Activity($row['activity_id'], $row['person_id']);
                 $activity->setStreamTitle('activities');
                 $activity->setTitle($row['activity_title']);
                 $activity->setBody($row['activity_body']);
                 $activity->setPostedTime($row['created']);
                 $activity->setMediaItems($this->getMediaItemsByActivityId($row['activity_id']));
                 $activities[] = $activity;
             }
         } elseif (isset($activityIds) && is_array($activityIds)) {
             // specific activity id was specified, return a not found flag
             return false;
         }
         return $activities;
     } else {
         return false;
     }
 }
Ejemplo n.º 6
0
 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) {
     //TODO add support for filterBy, filterOp and filterValue
     $this->checkDb();
     $activities = array();
     foreach ($ids as $key => $val) {
         $ids[$key] = mysql_real_escape_string($val);
     }
     $ids = implode(',', $ids);
     if (isset($activityIds) && is_array($activityIds)) {
         foreach ($activityIds as $key => $val) {
             $activityIds[$key] = mysql_real_escape_string($val);
         }
         $activityIdQuery = " AND id IN (" . implode(',', $activityIds);
     } else {
         $activityIdQuery = '';
     }
     // return a proper totalResults count
     $sql = "SELECT count(id) FROM " . TABLE_PREFIX . "social_activities WHERE member_id in ({$ids}) {$activityIdQuery}";
     $res = mysql_query($sql, $this->db);
     if ($res !== false) {
         list($totalResults) = mysql_fetch_row($res);
     } else {
         $totalResults = '0';
     }
     $startIndex = !is_null($startIndex) && $startIndex !== false && is_numeric($startIndex) ? intval($startIndex) : '0';
     $count = !is_null($count) && $count !== false && is_numeric($count) ? intval($count) : '20';
     $activities['totalResults'] = $totalResults;
     $activities['startIndex'] = $startIndex;
     $activities['count'] = $count;
     $query = "SELECT member_id, id, title, created_date FROM " . TABLE_PREFIX . "social_activities WHERE member_id in ({$ids}) {$activityIdQuery} order by created_date desc limit {$startIndex}, {$count}";
     $res = mysql_query($query, $this->db);
     if ($res) {
         if (mysql_num_rows($res)) {
             while ($row = mysql_fetch_assoc($res)) {
                 $activity = new Activity($row['id'], $row['member_id']);
                 $activity->setStreamTitle('activities');
                 $activity->setTitle($row['title']);
                 //          $activity->setBody($row['activity_body']);
                 $activity->setPostedTime($row['created_date']);
                 $activity->setMediaItems($this->getMediaItems($row['id']));
                 $activities[] = $activity;
             }
         } elseif (isset($activityIds) && is_array($activityIds)) {
             // specific activity id was specified, return a not found flag
             return false;
         }
         return $activities;
     } else {
         return false;
     }
 }