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

Diff of /contributions/modules/sna/sna.module

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

revision 1.1, Wed Aug 16 15:25:46 2006 UTC revision 1.2, Thu Aug 17 14:53:04 2006 UTC
# Line 91  function sna_user($op, &$edit, &$account Line 91  function sna_user($op, &$edit, &$account
91        $output[] = array('title' => t("Search route"), 'value' => theme_item_list($possibilities));        $output[] = array('title' => t("Search route"), 'value' => theme_item_list($possibilities));
92      }      }
93      if (user_access('browse sna map')) {      if (user_access('browse sna map')) {
94        $draws[] = l(t('Draw user\'s tree of minimal routes'), 'sna/tree_draw/' . $account->uid . '/0');        $draws[] = l(t('Draw user\'s tree of minimal routes'), 'sna/tree_draw/' . $account->uid . '/'. ROUTE_SHORTEST);
95        $draws[] = l(t('Draw user\'s tree of breadth-first search'), 'sna/tree_draw/' . $account->uid . '/1');        $draws[] = l(t('Draw user\'s tree of breadth-first search'), 'sna/tree_draw/' . $account->uid . '/' . ROUTE_MIN_STEP);
96        $output[] = array('title' => t('Visualization'), 'value' => theme_item_list($draws));        $output[] = array('title' => t('Visualization'), 'value' => theme_item_list($draws));
97      }      }
98      return array(t("Social network informations") => $output);      return array(t("Social network informations") => $output);
# Line 104  function sna_user($op, &$edit, &$account Line 104  function sna_user($op, &$edit, &$account
104   */   */
105  function sna_block($op = 'list', $delta = 0, $edit = array()) {  function sna_block($op = 'list', $delta = 0, $edit = array()) {
106    global $user;    global $user;
   
107    if ($op == 'list') {    if ($op == 'list') {
108       $blocks[0]['info'] = t('Most linked users');       $blocks[0]['info'] = t('Most linked users');
109       $blocks[1]['info'] = t('Average step separation');       $blocks[1]['info'] = t('Average step separation');
# Line 147  function sna_block($op = 'list', $delta Line 146  function sna_block($op = 'list', $delta
146   */   */
147  function sna_routes() {  function sna_routes() {
148    // Generate form for searching route    // Generate form for searching route
149    $form['a_to_b'] = array(    $form['sna_a_to_b'] = array(
150      '#type' => 'fieldset',      '#type' => 'fieldset',
151      '#title' => t('Searching best route between users'),      '#title' => t('Searching best route between users'),
152      '#tree' => TRUE);      '#tree' => TRUE);
153    $form['a_to_b']['from'] = array(    $form['sna_a_to_b']['from'] = array(
154      '#type' => 'select',      '#type' => 'select',
155      '#title' => t('From'),      '#title' => t('From'),
156      '#options' => get_all_vertices_for_forms());      '#options' => get_all_vertices_for_forms());
157    $form['a_to_b']['to'] = array(    $form['sna_a_to_b']['to'] = array(
158      '#type' => 'select',      '#type' => 'select',
159      '#title' => t('To'),      '#title' => t('To'),
160      '#options' => get_all_vertices_for_forms());      '#options' => get_all_vertices_for_forms());
161    $form['a_to_b']['min_or_step'] = array(    $form['sna_a_to_b']['min_or_step'] = array(
162      '#type' => 'radios',      '#type' => 'radios',
163      '#title' => t('Type of route searching'),      '#title' => t('Type of route searching'),
164      '#options' => array(t('Shortest route'), t('Minimal step route')));      '#options' => array(ROUTE_SHORTEST => t('Shortest route'),
165    $form['a_to_b']['submit'] = array('#type' => 'submit', '#value' => t('Search'));                          ROUTE_MIN_STEP => t('Minimal step route')));
166    return drupal_get_form('a_to_b', $form);    $form['sna_a_to_b']['submit'] = array('#type' => 'submit', '#value' => t('Search'));
167      return drupal_get_form('sna_a_to_b', $form);
168  }  }
169    
170  /**  /**
# Line 204  function sna_dist() { Line 204  function sna_dist() {
204           '" height="' . PIC_HEIGHT . '">' . t('SVG support is needed') . '</object>';           '" height="' . PIC_HEIGHT . '">' . t('SVG support is needed') . '</object>';
205  }  }
206    
207    /**
208     * Display the strongly connected components of the social graph
209     *
210     * @return string The formatted output of grups
211     */
212  function sna_groups() {  function sna_groups() {
213    get_graph($edges);    get_graph($edges);
214    $groups = search_groups($edges);    $groups = search_groups($edges);
# Line 214  function sna_groups() { Line 219  function sna_groups() {
219        $group[] = user_load(array('uid' => $groups[$act_group][$act_user]));        $group[] = user_load(array('uid' => $groups[$act_group][$act_user]));
220      }      }
221      $output .= theme_box(t('Group ' . ($act_group + 1)), theme('user_list', $group));      $output .= theme_box(t('Group ' . ($act_group + 1)), theme('user_list', $group));
222        $group = array();
223    }    }
224    if (empty($output)) {    if (empty($output)) {
225      $output = t('No groups in the network yet.');      $output = t('No groups in the network yet.');
226    }    }
227      drupal_set_message(t('A directed graph is called strongly connected if for every pair
228                            of vertices u and v there is a path from u to v and a path from
229                            v to u. The strongly connected components (SCC) of a directed graph
230                            are its maximal strongly connected subgraphs. These form a partition
231                            of the graph. (source: Wikipedia)'));
232    return $output;    return $output;
233  }  }
234    
# Line 225  function sna_groups() { Line 236  function sna_groups() {
236   * Handle the form of the sna_operations page   * Handle the form of the sna_operations page
237   *   *
238   */   */
239  function a_to_b_submit($form_id, $form_values) {  function sna_a_to_b_submit($form_id, $form_values) {
240    get_graph($edges);    $from = $form_values[$form_id]['from'];
241      $to = $form_values[$form_id]['to'];
242    $from = $form_values['a_to_b']['from'];    $type = $form_values[$form_id]['min_or_step'];
243    $to = $form_values['a_to_b']['to'];    drupal_set_message(sna_a_to_b_common($from, $to, $type));
   $type = $form_values['a_to_b']['min_or_step'];  
   if ($type == 0) {  
     if (user_access('realtime shortest route searching in sna') || is_in_cache($from) !== FALSE) {  
       $min_route = a_to_b($edges, $from, $to);  
     }  
     else {  
       return drupal_set_message(t('Realtime shortest route searching is disabled'), 'error');  
     }  
   }  
   else {  
     $min_route = a_to_b($edges, $from, $to, TRUE);  
   }  
   if ($from == $to) {  
     drupal_set_message(t('The destination and the source is the same.'));  
   }  
   else if (count($min_route) == 0 || $min_route === FALSE) {  
     drupal_set_message(t('No route from ') . get_real_name($from) . t(' to ') . get_real_name($to));  
   }  
   else {  
     $index = 0;  
     $route[] = array(t("User"), t(($type == 0 ? "Distance " : "Step ") . "from the source"));  
     for ($i = end($min_route); is_array($i); $i = prev($min_route)) {  
       $route[] = array(get_real_name($i['n']), $i['d']);  
     }  
     drupal_set_message(theme_table(array(), $route, array()));  
   }  
244  }  }
245    
246  /**  /**
# Line 267  function a_to_b_submit($form_id, $form_v Line 252  function a_to_b_submit($form_id, $form_v
252   *   *
253   */   */
254  function sna_a_to_b_show($from = FALSE, $to = FALSE, $type = FALSE) {  function sna_a_to_b_show($from = FALSE, $to = FALSE, $type = FALSE) {
255    if (!(is_numeric($from) && is_numeric($to) && is_numeric($type))) {    return sna_a_to_b_common($from, $to, $type);
256    }
257    
258    /**
259     * Create the table of the minimal route
260     *
261     * @param integer $from User id
262     * @param integer $to User id
263     * @param integer $type ROUTE_MIN_STEP or ROUTE_SHORTEST
264     * @return string The themed table
265     */
266    function sna_a_to_b_common($from, $to, $type) {
267      if (!is_numeric($from) || !is_numeric($to) || !($type == ROUTE_MIN_STEP || $type == ROUTE_SHORTEST)) {
268      drupal_access_denied();      drupal_access_denied();
269        return '';
270    }    }
271    get_graph($edges);    get_graph($edges);
272    if ($type == 0) {   // Dijkstra search (slow!)    if ($type == ROUTE_SHORTEST) {
273      if (user_access('realtime shortest route searching in sna') || is_in_cache($from) !== FALSE) {      if (user_access('realtime shortest route searching in sna') || is_in_cache($from) !== FALSE) {
274        $min_route = a_to_b($edges, $from, $to);        $min_route = a_to_b($edges, $from, $to);
275      }      }
# Line 279  function sna_a_to_b_show($from = FALSE, Line 277  function sna_a_to_b_show($from = FALSE,
277        return drupal_set_message(t('Realtime shortest route searching is disabled'), 'error');        return drupal_set_message(t('Realtime shortest route searching is disabled'), 'error');
278      }      }
279    }    }
280    else {              // Breadth-first search    else {
281      $min_route = a_to_b($edges, $from, $to, TRUE);      $min_route = a_to_b($edges, $from, $to, TRUE);
282    }    }
283    if ($from == $to) {    if ($from == $to) {
# Line 296  function sna_a_to_b_show($from = FALSE, Line 294  function sna_a_to_b_show($from = FALSE,
294      }      }
295      return theme_table(array(), $route, array());      return theme_table(array(), $route, array());
296    }    }
297      return '';
298  }  }
299    
300  /**  /**
# Line 307  function sna_a_to_b_show($from = FALSE, Line 306  function sna_a_to_b_show($from = FALSE,
306   */   */
307  function sna_tree_draw($uid, $type) {  function sna_tree_draw($uid, $type) {
308    get_graph($edges);    get_graph($edges);
309    if ($type == 0) {   // Dijkstra search (slow!)    if ($type == ROUTE_MIN_STEP) {   // Dijkstra search (slow!)
310      $tree = a_to_any($edges, $uid);      $tree = a_to_any($edges, $uid);
311    }    }
312    else {              // Breadth-first search    else {              // Breadth-first search
# Line 316  function sna_tree_draw($uid, $type) { Line 315  function sna_tree_draw($uid, $type) {
315    return sna_applet(show_tree($tree), t('The tree of user ') . get_real_name($uid));    return sna_applet(show_tree($tree), t('The tree of user ') . get_real_name($uid));
316  }  }
317    
318    /**
319     * Create the page of the distribution of edges. This is an svg document.
320     *
321     */
322  function sna_svg_distribution() {  function sna_svg_distribution() {
323    get_graph($edges);    get_graph($edges);
324    header('Content-type: image/svg+xml');    header('Content-type: image/svg+xml');
325    print visualize_distribution(distribution_of_degree($edges));    print visualize_distribution(distribution_of_degree($edges));
326  }  }
327    
328    /**
329     * Create a summary of possible commands
330     *
331     * @return string The commands with descriptions
332     */
333  function sna_page() {  function sna_page() {
334    $ops = sna_get_operations();    $ops = sna_get_operations();
335    $num_ops = count($ops);    $num_ops = count($ops);
# Line 348  function sna_menu($may_cache) { Line 356  function sna_menu($may_cache) {
356    $ops = sna_get_operations();    $ops = sna_get_operations();
357    $num_ops = count($ops);    $num_ops = count($ops);
358    for ($i = 0; $i < $num_ops; $i++) {    for ($i = 0; $i < $num_ops; $i++) {
359      $items[] = array('path' => $ops[$i]['path'], 'title' => $ops[$i]['title'],      $items[] = array('path' => $ops[$i]['path'],
360          'callback' => str_replace('/', '_', $ops[$i]['path']) , 'access' => user_access($ops[$i]['access']));                      'title' => $ops[$i]['title'],
361    }                      'callback' => str_replace('/', '_', $ops[$i]['path']) ,
362    $items[] = array('path' => 'sna/a_to_b', 'title' => t('Search routes'), 'callback' => 'sna_a_to_b_show',                      'access' => user_access($ops[$i]['access']));
363         'access' => user_access('access sna'), 'type' => MENU_CALLBACK);    }
364    $items[] = array('path' => 'sna/tree_draw', 'title' => t('Drawing tree'), 'callback' => 'sna_tree_draw',    $items[] =   array('path' => 'sna/_to_b',
365         'access' => TRUE, 'type' => MENU_CALLBACK);                       'title' => t('Search routes'),
366    $items[] = array('path' => 'sna/svg_distribution_of_edges', 'title' => t(''), 'callback' => 'sna_svg_distribution',                       'callback' => 'sna_a_to_b_show',
367         'access' => TRUE, 'type' => MENU_CALLBACK);                       'access' => user_access('access sna'),
368                         'type' => MENU_CALLBACK);
369      $items[] =   array('path' => 'sna/tree_draw',
370                         'title' => t('Drawing tree'),
371                         'callback' => 'sna_tree_draw',
372                         'access' => TRUE,
373                         'type' => MENU_CALLBACK);
374      $items[] =   array('path' => 'sna/svg_distribution_of_edges',
375                         'title' => t(''),
376                         'callback' => 'sna_svg_distribution',
377                         'access' => TRUE,
378                         'type' => MENU_CALLBACK);
379    return $items;    return $items;
380  }  }
381    
# Line 371  function sna_settings() { Line 390  function sna_settings() {
390    }*/    }*/
391    if (array_search(DBA_HANDLER, array_keys(dba_handlers())) === FALSE) {    if (array_search(DBA_HANDLER, array_keys(dba_handlers())) === FALSE) {
392      drupal_set_message(t('The proper dba_handler support is missing.'), 'error');      drupal_set_message(t('The proper dba_handler support is missing.'), 'error');
393      drupal_set_message(t('You have to choose a valid dba_handler in common.php'), 'error');      drupal_set_message(t('You have to choose a valid dba_handler in common.php'), 'status');
394    }    }
395    
396    $form['sna_data_source'] = array('#title' => t('Data source of the network'),    $form['sna_data_source'] = array('#title' => t('Data source of the network'),
397                                     '#type' => 'select',                                     '#type' => 'select',
398                                     '#options' => array('nodes' => 'nodes', 'buddy' => 'buddy', 'stats' => 'stats'),                                     '#options' => array('nodes' => 'Comments and replies', 'buddy' => 'Buddymodule', 'stats' => 'Viewing other\'s user page'),
399                                     '#default_value' => variable_get('sna_data_source', 'nodes'));                                     '#default_value' => variable_get('sna_data_source', 'nodes'),
400                                       '#description' => t('The relations between users can be gathered from various source.
401                                                            For example if you choose the Comments and replies option the
402                                                            comments will be the base of the connection. If someone reply to a node
403                                                            or another comment it results an edge in the network.'));
404    $form['sna_size_cache'] = array('#title' => t('Number of cached shortest routes'),    $form['sna_size_cache'] = array('#title' => t('Number of cached shortest routes'),
405                                     '#type' => 'textfield',                                    '#type' => 'textfield',
406                                     '#default_value' => variable_get('sna_size_cache', 10));                                    '#default_value' => variable_get('sna_size_cache', 10),
407                                      '#description' => t('The Dijkstra algorithm will be executed on the top-n users by
408                                                            sna_cron script so when the visitors want to search shortest route
409                                                            it can be served from cache fast.'));
410    $form['sna_data_path'] = array('#title' => t('Data files path which is writeable by the web server'),    $form['sna_data_path'] = array('#title' => t('Data files path which is writeable by the web server'),
411                                     '#type' => 'textfield',                                   '#type' => 'textfield',
412                                     '#default_value' => variable_get('sna_data_path', FILES_PATH));                                   '#default_value' => variable_get('sna_data_path', FILES_PATH),
413                                     '#description' => t('Trailing / is needed.'));
414    $form['sna_pic_size'] = array('#title' => t('Size of SVG picture in pixel'),    $form['sna_pic_size'] = array('#title' => t('Size of SVG picture in pixel'),
415                                     '#type' => 'textfield',                                  '#type' => 'textfield',
416                                     '#default_value' => variable_get('sna_pic_size', PIC_WIDTH));                                  '#default_value' => variable_get('sna_pic_size', PIC_WIDTH),
417                                    '#description' => t('The distribution of edges picture\'s size'));
418    $form['sna_limit'] = array('#title' => t('Ignore edges longer than'),    $form['sna_limit'] = array('#title' => t('Ignore edges longer than'),
419                                     '#type' => 'textfield',                                     '#type' => 'textfield',
420                                     '#default_value' => variable_get('sna_limit', 0),                                     '#default_value' => variable_get('sna_limit', 0),
421                                     '#description' => t('Zero means no limit.'));                                     '#description' => t('Zero means no limit. You have to raise this number if the graph
422                                                            function become too slow.'));
423    return $form;    return $form;
 }  
424    }
425    
426    ?>

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

  ViewVC Help
Powered by ViewVC 1.1.2