/[drupal]/contributions/modules/activity_map/activity_map.module
ViewVC logotype

Contents of /contributions/modules/activity_map/activity_map.module

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


Revision 1.8 - (show annotations) (download) (as text)
Sun Apr 19 13:05:45 2009 UTC (7 months, 1 week ago) by 4vinoth
Branch: MAIN
CVS Tags: DRUPAL-6--1-2, HEAD
Changes since 1.7: +2 -2 lines
File MIME type: text/x-php
no message
1 <?php
2 // $Id: activity_map.module,v 1.7 2009/04/19 13:05:18 4vinoth Exp $
3
4 /***
5 * @file
6 * Displays Site Activity on GMAP.
7 */
8
9 /****************************************************************************
10 * Implementation of hook_init()
11 */
12 function activity_map_init(){
13
14 drupal_add_js(drupal_get_path('module','activity_map') .'/js/gmap_activity.js', 'module', 'footer'); //run only after gmap initialized.
15 }
16
17 function activity_map_menu() {
18
19 $items = array();
20
21 $items['activity_map'] = array(
22 'title' => t('Activity Map'),
23 'page callback' => '_activity_map_activity_map_page',
24 'access arguments' => array('access content'),
25 );
26 $items['activity_map/all/json'] = array(
27 'title' => '',
28 'page callback' => 'activity_map_all_json',
29 'access arguments' => array('access content'),
30 'type' => MENU_CALLBACK,
31 );
32 $items['admin/settings/activity_map'] = array(
33 'title' => 'Activity Map',
34 'page callback' => 'drupal_get_form',
35 'page arguments' => array('activity_map_admin_settings'),
36 'description' => 'Configure Activity Map settings.',
37 'access arguments' => array('administer site configuration'),
38 );
39 return $items;
40 }
41
42 function activity_map_theme(){
43 return array(
44 'activity_map_info_window' => array(
45 'arguments' => array('activity' => NULL),
46 ),
47 );
48 }
49
50
51
52 /****************************************************************************
53 * Implementation of hook_block()
54 */
55 function activity_map_block($op = 'list', $delta=0, $edit = array()){
56 global $user;
57
58 switch($op){
59 case 'list':
60
61 $blocks[0]['info'] = t('Activity Map');
62
63 return $blocks;
64 case 'view':
65 if (user_access('access content')){
66 switch($delta){
67 case 0:
68 $title = t('Activity');
69 $content = _activity_map_activity_map_block();
70 break;
71 }
72 }
73 if (!empty($content)){
74 $block['subject'] = $title;
75 $block['content'] = $content;
76 return $block;
77 }
78 }
79
80 }
81
82 function _activity_map_activity_map_page(){
83 $macro = variable_get('activity_map_page', '[gmap |id=activity_gmap |zoom=10 |width=100% |height=500px |control=Small |type=Map]');
84 //print_r($macro);
85 return _activity_map_activity_map($macro['macro']);
86 }
87
88 function _activity_map_activity_map_block(){
89 $macro = variable_get('activity_map_block', '[gmap |id=activity_gmap |zoom=10 |width=100% |height=300px |control=Small |type=Map]');
90 return _activity_map_activity_map($macro['macro']);
91 }
92
93 function _activity_map_activity_map($macro){
94
95 $map = array(
96 '#map' => 'activity_gmap',
97 '#settings' => gmap_parse_macro($macro),
98 );
99 $map['#settings']['behavior']['notype'] = TRUE;
100 $map['#settings']['markers'] = array();
101
102 $markup = array(
103 '#type' => 'markup',
104 '#value' => theme('gmap', $map)
105 );
106
107 return '<div id="user-activity-map">'. drupal_render($markup) . '</div>';
108 }
109
110 function activity_map_all_json(){
111
112
113 $limit = 20;
114 $wheres = array();
115 $params = array();
116
117 //copied from activity
118
119 // Build sql limiting query to on filtered fields
120 if (!empty($filters) && is_array($filters)) {
121 $ops = array(
122 'include' => " = '%s'",
123 'exclude' => " != '%s'",
124 'lt' => ' < %d',
125 'gt' => ' > %d',
126 'lte' => ' <= %d',
127 'gte' => ' >= %d'
128 );
129
130 foreach ($filters as $column => $filter) {
131 // Of the possible columns, role is in the at table and all others in the
132 // a table. Prefix the column name with the appropriate table.
133 if ($column == 'target_role') {
134 $column = 'at.target_role';
135 }
136 else {
137 $column = "a.{$column}";
138 }
139
140 // attempt to rewrite old filters to the new format
141 if (!is_array($filter) || count(array_intersect(array_keys($ops), array_keys($filter))) == 0) {
142 $filter = array('include' => $filter);
143 }
144
145 foreach ($filter as $criteria => $values) {
146 if (is_array($values)) {
147 $strings = array();
148 foreach ($values as $value) {
149 $strings[] = "'%s'";
150 $params[] = $value;
151 }
152 $wheres[] = $column . ($criteria == 'exclude' ? ' NOT IN ' : ' IN ') .'('. implode(',', $strings). ')';
153 }
154 else {
155 $wheres[] = $column . $ops[$criteria];
156 // $values is a string with the single value.
157 $params[] = $values;
158 }
159 }
160 }
161 }
162 if (count($wheres) > 0) {
163 $where = implode(' AND ', $wheres);
164 $where = "WHERE $where";
165 }
166
167 // Build the sql and do the query. Wrapping it in db_rewrite_sql allows other
168 // modules to impose access restrictions on activity listings.
169 $sql = "SELECT
170 a.*, at.target_uid, at.target_role, l.latitude, l.longitude
171 FROM {activity_targets} at
172 INNER JOIN {activity} a ON a.aid = at.aid
173 LEFT JOIN {location_instance} i ON i.uid = a.uid
174 LEFT JOIN {location} l ON l.lid=i.lid
175 $where ";
176
177
178 $sql = db_rewrite_sql("$sql ORDER BY a.created desc", 'at', 'aid', array('uids' => $uids));
179
180 $result = pager_query($sql, $limit, 0, NULL, $params);
181
182 $activities = array();
183 while ($row = db_fetch_array($result)) {
184 $row['data'] = unserialize($row['data']);
185 $row['data']['aid'] = $row['aid'];
186 $row['data']['uid'] = $row['uid'];
187 $row['data']['module'] = $row['module'];
188 $row['data']['type'] = $row['type'];
189 $row['data']['operation'] = ($row['data']['operation'] ? $row['data']['operation'] : $row['operation']);
190 $row['data']['created'] = $row['created'];
191 $row['data']['latitude'] = $row['latitude'];
192 $row['data']['longitude'] = $row['longitude'];
193
194 // Load Activity comments
195 $row['comments'] = activity_comments_load($row['aid']);
196
197 // Invoke activityapi
198 activity_invoke_activityapi($row, 'load');
199
200 if (!empty($row)) {
201 $activities[] = $row;
202 }
203 }
204
205 //$activities = activity_get_activity(ACTIVITY_ALL, NULL, variable_get('activity_page_pager', 20));
206 $activity_raw_res = array();
207
208 foreach ($activities as $activity) {
209 $activity_raw_res[] = array(
210 'activity' => theme('activity_map_info_window', $activity), //. ' ' . theme('activity_timestamp', $activity['created']);
211 'latitude' => $activity['data']['latitude'],
212 'longitude' => $activity['data']['longitude'],
213 );
214 }
215
216 //print_r($rows);
217 //return '';
218 print drupal_json($activity_raw_res);
219 exit();
220 }
221
222 function theme_activity_map_info_window($activity){
223 //TODO :
224 if ($activity_message = activity_token_replace($activity)) {
225 return theme('user_picture', user_load($activity['data']['uid'])) . $activity_message . '<br /> ' . format_date($activity['data']['created'], 'small');;
226 }
227 }
228
229
230 function activity_map_admin_settings(){
231
232 //[gmap |id=activity_gmap |zoom=10 |width=100% |height=400px |control=Small |type=Map]
233
234 $activity_map_block = variable_get('activity_map_block', array('macro' => '[gmap |id=activity_gmap |zoom=10 |width=100% |height=300px |control=Small |type=Map]'));
235
236
237 $form['activity_map_block'] = array(
238 '#type' => 'fieldset',
239 '#title' => t('Activity map Block'),
240 '#tree' => TRUE,
241 );
242 $form['activity_map_block']['macro'] = array(
243 '#type' => 'textfield',
244 '#title' => t('Macro'),
245 '#default_value' => $activity_map_block['macro'],
246 '#size' => 50,
247 '#maxlength' => 500,
248 '#description' => t('Donot change the map ID.'),
249 );
250
251 $activity_map_page = variable_get('activity_map_page', array('macro' => '[gmap |id=activity_gmap |zoom=10 |width=100% |height=500px |control=Small |type=Map]'));
252
253 $form['activity_map_page'] = array(
254 '#type' => 'fieldset',
255 '#title' => t('Activity map Page'),
256 '#tree' => TRUE,
257 );
258 $form['activity_map_page']['macro'] = array(
259 '#type' => 'textfield',
260 '#title' => t('Macro'),
261 '#default_value' => $activity_map_page['macro'],
262 '#size' => 50,
263 '#maxlength' => 500,
264 '#description' => t('Donot change the map ID.'),
265 );
266
267 /*
268 // Option to use a different marker for each role
269 $form['activity_map_block']['gmap_role_markers'] = array(
270 '#type' => 'fieldset',
271 '#title' => t('Markers per role'),
272 '#description' => t('Choose a marker to represent each user role on the user map. If a user belongs to multiple roles, the marker for the highest Role ID will be used.'),
273 '#tree' => TRUE,
274 );
275
276 // Retrieve and sort list of roles, sans anonymous user
277 $roles = user_roles(TRUE);
278 //asort($roles);
279
280 $defaults = variable_get('gmap_role_markers', array());
281
282 // Create a selection box per role
283 foreach ($roles as $rid => $role) {
284 $form['activity_map_block']['gmap_role_markers'][$rid] = array(
285 '#type' => 'gmap_markerchooser',
286 '#title' => t('%role (Role ID: %rid)', array('%role' => $role, '%rid' => $rid)),
287 '#default_value' => isset($defaults[$rid]) ? $defaults[$rid] : 'drupal',
288 );
289 }
290 */
291
292 return system_settings_form($form);
293
294 }

  ViewVC Help
Powered by ViewVC 1.1.2