2 /****************************************************************/
4 /****************************************************************/
5 /* Copyright (c) 2002-2009 */
6 /* Inclusive Design Institute */
9 /* This program is free software. You can redistribute it and/or*/
10 /* modify it under the terms of the GNU General Public License */
11 /* as published by the Free Software Foundation. */
12 /****************************************************************/
16 * This class is designed to handle the transactions for all the news, updates and
17 * activities that are issued by the user.
25 * Adds a new activity into the database.
27 * @param string the message of that describe this activity
28 * @param int the application that's linked with this activity. Purpose is to display it with a link.
29 * TODO: What happens if title is empty? Don't add it?
31 function addActivity($id, $title, $app_id=0){
32 global $db, $addslashes;
34 $app_id = intval($app_id);
38 $app_string = ", application_id=$app_id";
39 //overwrite title with an automated message
40 $title = $this->generateApplicationTitle($app_id);
43 if ($id > 0 && $title!=''){
44 $sql = 'INSERT INTO '.TABLE_PREFIX."social_activities SET member_id=$id, title='$title'".$app_string;
45 mysql_query($sql, $db);
51 * Retrieve this user's activity
54 * @param boolean set TRUE to display all entry
55 * @return The array of description of all the activities from the given user.
57 function getActivities($id, $displayAll=false){
59 $activities = array();
62 $sql = 'SELECT * FROM '.TABLE_PREFIX."social_activities WHERE member_id=$id ORDER BY created_date DESC";
64 $sql .= ' LIMIT '.SOCIAL_FRIEND_ACTIVITIES_MAX;
66 $result = mysql_query($sql, $db);
68 while($row = mysql_fetch_assoc($result)){
69 $activities[$row['id']]['member_id'] = $row['member_id'];
70 $activities[$row['id']]['title'] = $row['title'];
71 $activities[$row['id']]['created_date'] = $row['created_date'];
84 * @return true if activity is deleted.
86 function deleteActivity($id){
90 $sql = 'DELETE FROM '.TABLE_PREFIX.'social_activities WHERE member_id='.$_SESSION['member_id'].' AND id='.$id;
91 mysql_query($sql, $db);
92 if (mysql_affected_rows() > 0){
101 * Retrieve friends' recent activities
104 * @param boolean set TRUE to display all entry
105 * @return The array of description of all the activities of the given user's friends.
107 function getFriendsActivities($id, $displayAll=false){
109 $activities = array();
111 $friends = getFriends($id);
112 $friends_ids = implode(', ', array_keys($friends));
113 $sql = 'SELECT * FROM '.TABLE_PREFIX.'social_activities WHERE member_id IN ('.$friends_ids.') ORDER BY created_date DESC';
115 $sql .= ' LIMIT '.SOCIAL_FRIEND_ACTIVITIES_MAX;
117 $result = mysql_query($sql, $db);
120 while($row = mysql_fetch_assoc($result)){
121 $activities[$row['id']]['member_id'] = $row['member_id'];
122 $activities[$row['id']]['title'] = $row['title'];
123 $activities[$row['id']]['created_date'] = $row['created_date'];
131 * Generate the title string for application.
133 * @param int application id
134 * @return the title string that has a hyperlink to the application itself.
136 function generateApplicationTitle($app_id){
138 $app_id = intval($app_id);
140 //This here, it is actually better to use $url instead of app_id.
141 //$url is the primary key. $id is also a key, but it is not guranteed that it will be unique
142 $sql = 'SELECT title FROM '.TABLE_PREFIX."social_applications WHERE id=$app_id";
143 $result = mysql_query($sql, $db);
144 $row = mysql_fetch_assoc($result);
146 $msg = _AT("has_added_app", url_rewrite(AT_SOCIAL_BASENAME.'applications.php?app_id='.$app_id, AT_PRETTY_URL_IS_HEADER),
147 htmlentities_utf8($row['title']));