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); } }
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; }
/** * Tests Activity->getTitle() */ public function testGetTitle() { $title = 'Foo Activity Title'; $this->Activity->setTitle($title); $this->assertEquals($title, $this->Activity->getTitle()); }
/** * 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; }
public function handleRequest($request) { try { $params = $request->getParams(); $type = $params['type']; error_log("OPEN SOCIAL DATA HANDLER:" . $type); $response = new ResponseItem(NOT_IMPLEMENTED, $type . " has not been implemented yet.", array()); $idSpec = idSpec::fromJson($params['idSpec']); $peopleIds = $this->peopleHandler->getIds($idSpec, $request->getToken()); error_log('peopleIds' . implode(',', $peopleIds)); switch ($type) { case 'FETCH_PEOPLE': error_log("SOCIAL CALL:FETCH_PEOPLE"); $profileDetail = $params["profileDetail"]; $profileDetailFields = array(); foreach ($profileDetail as $detail) { //error_log(" ".$detail); $profileDetailFields[] = $detail; } $sortOrder = !empty($params["sortOrder"]) ? $params["sortOrder"] : 'topFriends'; $filter = !empty($params["filter"]) ? $params["filter"] : 'all'; $first = intval($params["first"]); $max = intval($params["max"]); // TODO: Should we put this in the requestitem and pass the whole // thing along? $response = $this->peopleHandler->getPeople($peopleIds, $sortOrder, $filter, $first, $max, $profileDetailFields, $request->getToken()); break; case 'FETCH_PERSON_APP_DATA': error_log("FETCH_PERSON_APP_DATA"); $jsonKeys = $params["keys"]; $keys = array(); foreach ($jsonKeys as $key) { $keys[] = $key; } $response = $this->dataHandler->getPersonData($peopleIds, $keys, $request->getToken()); break; case 'UPDATE_PERSON_APP_DATA': error_log("UPDATE_PERSON_APP_DATA"); // this is either viewer or owner right? lets hack in propper support shall we? // We only support updating one person right now $id = $peopleIds[0]; $key = $params["key"]; $value = !empty($params["value"]) ? $params["value"] : ''; $response = $this->dataHandler->updatePersonData($id, $key, $value, $request->getToken()); break; case 'FETCH_ACTIVITIES': error_log("FETCH_ACTIVITIES"); $response = $this->activitiesHandler->getActivities($peopleIds, $request->getToken()); break; case 'CREATE_ACTIVITY': error_log("CREATE_ACTIVITY"); $activities = $params['activity']; $activityArry = $activities['fields_']; $activity = new Activity($activityArry['id'], $peopleIds[0]); $activity->setBody($activityArry['body']); $activity->setTitle($activityArry['title']); $response = $this->activitiesHandler->createActivity($personId, $activity, $request->getToken()); break; } } catch (Exception $e) { $response = new ResponseItem(BAD_REQUEST, $e->getMessage()); } error_log("EXITING NORMALLY"); return $response; }
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; } }
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; } }