/[drupal]/contributions/modules/cre/recommendation_modules/node_recommendation.module
ViewVC logotype

Diff of /contributions/modules/cre/recommendation_modules/node_recommendation.module

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

revision 1.1.4.7, Wed May 9 17:14:45 2007 UTC revision 1.1.4.8, Mon Jul 23 14:11:41 2007 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: node_recommendation.module,v 1.1.4.6 2007/05/09 15:19:12 hickory Exp $  // $Id: node_recommendation.module,v 1.1.4.7 2007/05/09 17:14:45 hickory Exp $
3    
4  /*  /*
5  * hook_help  * hook_help
# Line 58  function node_recommendation_menu($may_c Line 58  function node_recommendation_menu($may_c
58  function node_recommendation_settings() {  function node_recommendation_settings() {
59    $form['node_recommendation_page_n'] = array(    $form['node_recommendation_page_n'] = array(
60      '#type' => 'textfield',      '#type' => 'textfield',
61      '#title' => t('Numer of items to display'),      '#title' => t('Number of items to display'),
62      '#description' => t('The maximum number of items to display on a node recommendation page.'),      '#description' => t('The maximum number of items to display on a node recommendation page.'),
63      '#size' => 3,      '#size' => 3,
64      '#default_value' => variable_get('node_recommendation_page_n', 20),      '#default_value' => variable_get('node_recommendation_page_n', 20),
65      );      );
66    
67    $form['node_recommendation_days'] = array(    foreach (node_get_types() as $type) {
68      '#type' => 'textfield',      $form['node_recommendation_days_' . $type->type] = array(
69      '#title' => t('Maximum age (in days) of any recommended node'),        '#type' => 'textfield',
70      '#description' => t('Only nodes newer than this will be recommended; leave blank to recommend nodes of any age.'),        '#title' => t('Maximum age (in days) of any recommended %type node', array('%type' => $type->name)),
71      '#size' => 3,        '#description' => t('Only nodes newer than this will be recommended; leave blank to recommend nodes of any age.'),
72      '#default_value' => variable_get('node_recommendation_days', NULL),        '#size' => 3,
73      );        '#default_value' => variable_get('node_recommendation_days_' . $type->type, NULL),
74          );
75      }
76    
77    $tags = _node_recommendation_get_tags();    $tags = _node_recommendation_get_tags();
78    if (!empty($tags)) {    if (!empty($tags)) {
# Line 81  function node_recommendation_settings() Line 83  function node_recommendation_settings()
83        '#options' => $tags        '#options' => $tags
84        );        );
85    }    }
86    
87      $options = array('1' => t('All types'));
88      foreach (node_get_types() as $type) {
89        $options[$type->type] = $type->name;
90      }
91    
92      $form['node_recommendation_global_type'] = array(
93        '#type' => 'select',
94        '#title' => t('Type of node to recommend'),
95        '#default_value' => variable_get('node_recommendation_global_type', '1'),
96        '#description' => t('Limit all recommendations to nodes of a particular type?'),
97        '#options' => $options
98        );
99    
100    return system_settings_form($form);    return system_settings_form($form);
101  }  }
# Line 103  function node_recommendation_block($op = Line 118  function node_recommendation_block($op =
118    
119    // The $op parameter determines what piece of information is being requested.    // The $op parameter determines what piece of information is being requested.
120    switch ($op) {    switch ($op) {
121    case 'list':      case 'list':
122      $blocks[0]['info'] = t('CRE: Recommended nodes (all types)');      return array(
123      $blocks[1]['info'] = t('CRE: Similarly rated nodes');        '0' => array('info' => t('CRE: Recommended nodes (all types)')),
124      $blocks[2]['info'] = t('CRE: Recommended nodes (' . variable_get('node_recommendation_type_type_2', 1) . ')');        '1' => array('info' => t('CRE: Similarly rated nodes')),
125      $blocks[3]['info'] = t('CRE: Recommended nodes (' . variable_get('node_recommendation_type_type_3', 2) . ')');        '2' => array('info' => t('CRE: Recommended nodes (' . variable_get('node_recommendation_type_type_2', 1) . ')')),
126      $blocks[4]['info'] = t('CRE: Recommended nodes (' . variable_get('node_recommendation_type_type_4', 3) . ')');        '3' => array('info' => t('CRE: Recommended nodes (' . variable_get('node_recommendation_type_type_3', 2) . ')')),
127      return $blocks;        '4' => array('info' => t('CRE: Recommended nodes (' . variable_get('node_recommendation_type_type_4', 3) . ')')),
128          );
129        break;
130    
131    case 'configure':      case 'configure':
132      $form = array();      $form = array();
133      switch ($delta){      switch ($delta){
134      case 0: // Personalised recommendations.  
135          // Personalised recommendations.
136          case 0:
137        $form['node_recommendation_n'] = array(        $form['node_recommendation_n'] = array(
138          '#type' => 'textfield',          '#type' => 'textfield',
139          '#title' => t('Maximum number of nodes to recommend'),          '#title' => t('Maximum number of nodes to recommend'),
# Line 124  function node_recommendation_block($op = Line 143  function node_recommendation_block($op =
143          );          );
144        break;        break;
145    
146      case 1: // General similar block.        // General similar block.
147          case 1:
148        $form['node_recommendation_n'] = array(        $form['node_recommendation_n'] = array(
149          '#type' => 'textfield',          '#type' => 'textfield',
150          '#title' => t('Maximum number of nodes to recommend'),          '#title' => t('Maximum number of nodes to recommend'),
# Line 134  function node_recommendation_block($op = Line 154  function node_recommendation_block($op =
154          );          );
155        break;        break;
156    
157      // Recommendations of a certain type.        // Recommendations of a certain type.
158      case 2:        case 2:
159      case 3:        case 3:
160      case 4:        case 4:
161        $options = array();        $options = array();
162        foreach (node_get_types() as $type) {        foreach (node_get_types() as $type) {
163          $options[$type->type] = $type->name;          $options[$type->type] = $type->name;
164        }        }
165    
166        $form['node_recommendation_type'] = array(        $form['node_recommendation_type'] = array(
167          '#type' => 'select',          '#type' => 'select',
168          '#title' => t('Type of node to recommend'),          '#title' => t('Type of node to recommend'),
169          '#default_value' => variable_get('node_recommendation_type_type_' . $delta, 'story'),          '#default_value' => variable_get('node_recommendation_type_type_' . $delta, 'story'),
170          '#options' => $options          '#options' => $options
171          );          );
172    
173        $form['node_recommendation_n'] = array(        $form['node_recommendation_n'] = array(
174          '#type' => 'textfield',          '#type' => 'textfield',
175          '#title' => t('Maximum number of nodes to recommend'),          '#title' => t('Maximum number of nodes to recommend'),
# Line 162  function node_recommendation_block($op = Line 182  function node_recommendation_block($op =
182      }      }
183      return $form;      return $form;
184    
185    case 'save':      case 'save':
186      switch ($delta){      switch ($delta){
187      case 0:        case 0:
188        variable_set('node_recommendation_n_value', $edit['node_recommendation_n']);        variable_set('node_recommendation_n_value', $edit['node_recommendation_n']);
189        break;        break;
190      case 1:  
191          case 1:
192        variable_set('node_recommendation_similar_n_value', $edit['node_recommendation_n']);        variable_set('node_recommendation_similar_n_value', $edit['node_recommendation_n']);
193        break;        break;
194      case 2:  
195      case 3:        case 2:
196      case 4:        case 3:
197          case 4:
198        variable_set('node_recommendation_type_type_' . $delta, $edit['node_recommendation_type']);        variable_set('node_recommendation_type_type_' . $delta, $edit['node_recommendation_type']);
199        variable_set('node_recommendation_type_n_value_' . $delta, $edit['node_recommendation_n']);        variable_set('node_recommendation_type_n_value_' . $delta, $edit['node_recommendation_n']);
200        break;        break;
201      }      }
202      return;      return;
203    
204    case 'view':      case 'view':
205    default:      default:
206      switch ($delta) {      switch ($delta) {
207      case 0: // Personalised recommendations.  
208        $block['subject'] = l(t('Recommended'), variable_get('node_recommendation_path_to_page', 'recommendations'));        // Personalised recommendations.
209        if ($content = node_recommendation_get_top_n($user->uid, variable_get('node_recommendation_n_value', 5))) {        case 0:
210          $block['content'] = theme('cre_title_list', $content);        return array(
211        }          'subject' => l(t('Recommended'), variable_get('node_recommendation_path_to_page', 'recommendations')),
212            'content' => theme('cre_title_list', node_recommendation_get_top_n($user->uid, variable_get('node_recommendation_n_value', 5))),
213            );
214        break;        break;
215    
216      case 1: // General similar block.        // General similar block.
217          case 1:
218        if (arg(0) == 'node') {        if (arg(0) == 'node') {
219          if ($content = node_recommendation_get_similar(variable_get('node_recommendation_similar_n_value', 5))) {          return array(
220            $block['subject'] = t('Those that like this also like');            'subject' => t('Those that like this also like'),
221            $block['content'] = theme('cre_title_list', $content);            'content' => theme('cre_title_list', node_recommendation_get_similar(variable_get('node_recommendation_similar_n_value', 5))),
222          }            );
223        }        }
224        break;        break;
225    
226      // Recommendations of a certain type.        // Recommendations of a certain type.
227      case 2:        case 2:
228      case 3:        case 3:
229      case 4:        case 4:
230        $type = variable_get('node_recommendation_type_type_' . $delta, 'story');        $type = variable_get('node_recommendation_type_type_' . $delta, 'story');
231        $block['subject'] = l(t('Recommended'), variable_get('node_recommendation_path_to_page', 'recommendations') . "/$type");        return array(
232        if ($content = node_recommendation_get_top_n($user->uid, variable_get('node_recommendation_type_n_value_' . $delta, 5), $type)) {          'subject' => l(t('Recommended'), variable_get('node_recommendation_path_to_page', 'recommendations') . "/$type"),
233          $block['content'] = theme('cre_title_list', $content);          'content' => theme('cre_title_list', node_recommendation_get_top_n($user->uid, variable_get('node_recommendation_type_n_value_' . $delta, 5), $type)),
234        }          );
235        break;        break;
236      }      }
   
     return $block;  
237    }    }
238  }  }
239    
 function theme_cre_title_list($items = array()){  
   $output = array();  
   foreach ($items as $item){  
     $output[] = l($item->title, "node/$item->content_id", array('class' => 'node-' . $item->type));  
   }  
   return theme('item_list', $output);  
 }  
   
   
240  /*  /*
241  * Returns the top n nodes of a particular type  * Returns the top n nodes of a particular type
242  *  *
# Line 265  function node_recommendation_recommendat Line 279  function node_recommendation_recommendat
279    
280    $content = array();    $content = array();
281    foreach ($recommendations as $node) {    foreach ($recommendations as $node) {
282      $content[] = node_view(node_load(array('nid' => $node->content_id)), FALSE);      $content[] = theme('cre_node_view', $node->content_id);
283    }    }
284    return implode("\n", $content);    return implode("\n", $content);
285  }  }
# Line 297  function node_recommendation_cre_query(& Line 311  function node_recommendation_cre_query(&
311    if ($type = $args[0]){    if ($type = $args[0]){
312      $query->add_where("n.type = '%s'", $type);      $query->add_where("n.type = '%s'", $type);
313    }    }
314    else if ($numdays = variable_get('node_recommendation_days', FALSE)) { // FIXME: need to set date limit per node type    else {
315        $global_type = variable_get('node_recommendation_global_type', '1');
316        if ($global_type != '1'){
317          $query->add_where("n.type = '%s'", $global_type);
318        }
319      }
320    
321      if ($numdays = variable_get('node_recommendation_days_' . $type, FALSE)) {
322      $query->add_where('n.created >= %d', time() - (60 * 60 * 24 * $numdays));      $query->add_where('n.created >= %d', time() - (60 * 60 * 24 * $numdays));
323    }    }
324  }  }

Legend:
Removed from v.1.1.4.7  
changed lines
  Added in v.1.1.4.8

  ViewVC Help
Powered by ViewVC 1.1.2