/[drupal]/contributions/modules/topichubs/plugins/topichubs_contributors/topichubs_contributors.topichubs.inc
ViewVC logotype

Diff of /contributions/modules/topichubs/plugins/topichubs_contributors/topichubs_contributors.topichubs.inc

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

revision 1.1, Tue Mar 3 23:51:06 2009 UTC revision 1.1.2.1, Wed Sep 2 12:00:21 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2    
3  /**  /**
4   *   *
5   */   */
6  class topichubs_plugin_contributors extends topichub_sql_plugin {  class topichubs_plugin_contributors extends topichub_sql_plugin {
7    
8    function settings_form(&$form, &$form_state) {    function settings_form(&$form, &$form_state) {
9      $options = array();      $options = array();
10      $result = db_query("SELECT uid, name from {users}");      $result = db_query("SELECT uid, name from {users}");
11      while($item = db_fetch_object($result)) {      while($item = db_fetch_object($result)) {
12        $options[$item->uid] = $item->name;        $options[$item->uid] = $item->name;
13      }      }
14    
15      $form['topichubs_contrib_ignore'] = array(      $form['topichubs_contrib_ignore'] = array(
16        '#type' => 'select',        '#type' => 'select',
17        '#title' => t('Ignore the following'),        '#title' => t('Ignore the following'),
18        '#options' => $options,        '#options' => $options,
19        '#multiple' => true,        '#multiple' => true,
20        '#default_value' => variable_get('topichubs_contrib_ignore', 1),        '#default_value' => variable_get('topichubs_contrib_ignore', 1),
21        '#description' => t('Selected Users will not appear as contributors'),        '#description' => t('Selected Users will not appear as contributors'),
22      );      );
23    }    }
24    
25    function options_form(&$form, &$form_state) {    function options_form(&$form, &$form_state) {
26      $this->add_types_field($form, $form_state);      $this->add_types_field($form, $form_state);
27      $form['author_count'] = array(      $form['author_count'] = array(
28        '#type' => 'textfield',        '#type' => 'textfield',
29        '#title' => t('Number of Authors to return'),        '#title' => t('Number of Authors to return'),
30        '#description' => t('Set the maximum number of Top Contributors to be displayed on the Topic Hub\'s        '#description' => t('Set the maximum number of Top Contributors to be displayed on the Topic Hub\'s
31  page.'),  page.'),
32        '#size' => 4,        '#size' => 4,
33        '#maxlength' => 4,        '#maxlength' => 4,
34        '#default_value' => $this->settings['author_count'] ? $this->settings['author_count'] : 5,        '#default_value' => $this->settings['author_count'] ? $this->settings['author_count'] : 5,
35      );      );
36    }    }
37    
38    function execute() {    function execute() {
39      $authors = $this->get_authors();      $authors = $this->get_authors();
40      $hub_data = array(      $hub_data = array(
41        '#values' => $authors,        '#values' => $authors,
42        '#view' => theme(array("topichubs_contributors__{$this->node->nid}", 'topichubs_contributors'), $this->node, $authors),        '#view' => theme(array("topichubs_contributors__{$this->node->nid}", 'topichubs_contributors'), $this->node, $authors),
43      );      );
44      return $hub_data;      return $hub_data;
45    }    }
46    
47    /**    /**
48     * Find the <em>x</em> most published authors for this topic hub.     * Find the <em>x</em> most published authors for this topic hub.
49     */     */
50    function get_authors() {    function get_authors() {
51      $ignore = variable_get('topichubs_contrib_ignore', array());      $ignore = variable_get('topichubs_contrib_ignore', array());
52    
53      $node_alias = 'n';      $node_alias = 'n';
54      $term_joins = $this->get_term_where($node_alias);      $term_joins = $this->get_term_where($node_alias);
55      $args = $term_joins['args'];      $args = $term_joins['args'];
56    
57      $type_where = $this->get_content_type_where($this->get_types_setting(), $node_alias);      $type_where = $this->get_content_type_where($this->get_types_setting(), $node_alias);
58      $args = array_merge($args, $type_where['args']);      $args = array_merge($args, $type_where['args']);
59    
60      $sql .= "SELECT u.uid, u.name, u.picture, count(*) as node_count";      $sql .= "SELECT u.uid, u.name, u.picture, count(*) as node_count";
61      $sql .= " FROM {users} u";      $sql .= " FROM {users} u";
62      $sql .= " JOIN {node} n ON n.uid = u.uid";      $sql .= " JOIN {node} n ON n.uid = u.uid";
63      $sql .= implode(' ', $term_joins['joins']);      $sql .= implode(' ', $term_joins['joins']);
64      $sql .= " WHERE u.status = 1 AND n.status = 1";      $sql .= " WHERE u.status = 1 AND n.status = 1";
65      $sql .= " AND " . $term_joins['where'];      $sql .= " AND " . $term_joins['where'];
66      $sql .= " AND " . $type_where['where'];      $sql .= " AND " . $type_where['where'];
67      if(!empty($ignore)) {      if(!empty($ignore)) {
68        $sql .= " AND u.uid NOT IN (" . db_placeholders($ignore, 'int') . ")";        $sql .= " AND u.uid NOT IN (" . db_placeholders($ignore, 'int') . ")";
69        $args = array_merge($args, array_values($ignore));        $args = array_merge($args, array_values($ignore));
70      }      }
71      $sql .= " GROUP BY u.uid";      $sql .= " GROUP BY u.uid";
72      $sql .= " ORDER BY node_count DESC";      $sql .= " ORDER BY node_count DESC";
73    
74      $count = (int)$this->get_setting('author_count', 5);      $count = (int)$this->get_setting('author_count', 5);
75      if($count > 0) {      if($count > 0) {
76        $result = db_query_range($sql, $args, 0, $count);        $result = db_query_range($sql, $args, 0, $count);
77      }      }
78      else {      else {
79        $result = db_query($sql, $args);        $result = db_query($sql, $args);
80      }      }
81    
82      $results = array();      $results = array();
83      while ($contributor = db_fetch_object($result)) {      while ($contributor = db_fetch_object($result)) {
84        if(empty($contributor->picture)) {        if(empty($contributor->picture)) {
85          $contributor->picture = variable_get('user_picture_default', '');          $contributor->picture = variable_get('user_picture_default', '');
86        }        }
87        $results[] = $contributor;        $results[] = $contributor;
88      }      }
89      return $results;      return $results;
90    }    }
91  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.2