| 1 |
<?php |
<?php |
| 2 |
|
// $Id$ |
| 3 |
|
/** |
| 4 |
|
* @file |
| 5 |
|
* nodereferrer.module Views integration |
| 6 |
|
*/ |
| 7 |
|
|
| 8 |
/** |
/** |
| 9 |
* We use this as a parent class for both the nodereferrer arguments. This handler |
* We use this as a parent class for both the nodereferrer arguments. This handler |
| 12 |
class nodereferrer_view_handler_argument extends views_handler_argument { |
class nodereferrer_view_handler_argument extends views_handler_argument { |
| 13 |
// Don't use the normal operator as this doesn't display nicely |
// Don't use the normal operator as this doesn't display nicely |
| 14 |
var $no_operator = TRUE; |
var $no_operator = TRUE; |
| 15 |
|
|
| 16 |
/** |
/** |
| 17 |
* Form to get filter parameters |
* Form to get filter parameters |
| 18 |
*/ |
*/ |
| 19 |
function options_form(&$form, &$form_state) { |
function options_form(&$form, &$form_state) { |
| 20 |
parent::options_form($form, $form_state); |
parent::options_form($form, $form_state); |
| 21 |
|
|
| 22 |
$form['operator'] = array( |
$form['operator'] = array( |
| 23 |
'#type' => 'select', |
'#type' => 'select', |
| 24 |
'#title' => t('Operator'), |
'#title' => t('Operator'), |
| 27 |
'in' => t('Return nodes that refer to given node id'), |
'in' => t('Return nodes that refer to given node id'), |
| 28 |
'not in' => t('Do not return nodes that do not refer to given node id'), |
'not in' => t('Do not return nodes that do not refer to given node id'), |
| 29 |
), |
), |
| 30 |
'#required' => true, |
'#required' => TRUE, |
| 31 |
); |
); |
| 32 |
|
|
| 33 |
$form['fields'] = array( |
$form['fields'] = array( |
| 34 |
'#type' => 'checkboxes', |
'#type' => 'checkboxes', |
| 35 |
'#multiple' => TRUE, |
'#multiple' => TRUE, |
| 38 |
'#description' => t('This is optional ; if nothing is selected then all referrers will be returned'), |
'#description' => t('This is optional ; if nothing is selected then all referrers will be returned'), |
| 39 |
'#default_value' => empty($this->options['fields']) ? array() : $this->options['fields'], |
'#default_value' => empty($this->options['fields']) ? array() : $this->options['fields'], |
| 40 |
); |
); |
| 41 |
|
|
| 42 |
if (module_exists('translation')) { |
if (module_exists('translation')) { |
| 43 |
$form['multilingual'] = array( |
$form['multilingual'] = array( |
| 44 |
'#type' => 'fieldset', |
'#type' => 'fieldset', |
| 57 |
'#description' => t('If this is checked, will also include nodes that refer to translations of the given node'), |
'#description' => t('If this is checked, will also include nodes that refer to translations of the given node'), |
| 58 |
'#default_value' => $default, |
'#default_value' => $default, |
| 59 |
); |
); |
| 60 |
|
|
| 61 |
$default = 0; |
$default = 0; |
| 62 |
if (!empty($this->options['multilingual']['translations_of_referrers'])) { |
if (!empty($this->options['multilingual']['translations_of_referrers'])) { |
| 63 |
$default = $this->options['multilingual']['translations_of_referrers']; |
$default = $this->options['multilingual']['translations_of_referrers']; |
| 70 |
); |
); |
| 71 |
} |
} |
| 72 |
} |
} |
| 73 |
|
|
| 74 |
/** |
/** |
| 75 |
* Admin summary |
* Admin summary |
| 76 |
*/ |
*/ |
| 77 |
function admin_summary() { |
function admin_summary() { |
| 78 |
return ''; |
return ''; |
| 79 |
} |
} |
| 80 |
|
|
| 81 |
/** |
/** |
| 82 |
* Update the query |
* Update the query |
| 83 |
*/ |
*/ |
| 84 |
function query() { |
function query() { |
| 85 |
$this->ensure_my_table(); |
$this->ensure_my_table(); |
| 86 |
|
|
| 87 |
$list = $this->get_node_list(); |
$list = $this->get_node_list(); |
| 88 |
if (empty($list)) { |
if (empty($list)) { |
| 89 |
if ($this->options['operator'] == 'in') { |
if ($this->options['operator'] == 'in') { |
| 90 |
$this->query->add_where($this->options['group'], 'FALSE'); |
$this->query->add_where($this->options['group'], 'FALSE'); |
| 91 |
} |
} |
| 92 |
} else { |
} |
| 93 |
$in = '('.implode(', ',$list).')'; |
else { |
| 94 |
|
$in = '(' . implode(', ', $list) . ')'; |
| 95 |
|
|
| 96 |
$this->query->add_where( |
$this->query->add_where( |
| 97 |
$this->options['group'], |
$this->options['group'], |
| 98 |
"$this->table_alias.$this->real_field " . $this->options['operator'].' '.$in |
"$this->table_alias.$this->real_field " . $this->options['operator'] . ' ' . $in |
| 99 |
); |
); |
| 100 |
} |
} |
| 101 |
} |
} |
| 102 |
|
|
| 103 |
/** |
/** |
| 104 |
* Given a node id, field names and content names, returns the list of nodes |
* Given a node id, field names and content names, returns the list of nodes |
| 105 |
* that refer to the given node. This takes translation settings into account |
* that refer to the given node. This takes translation settings into account |
| 106 |
*/ |
*/ |
| 107 |
function referrers($nid, $fields, $types = null) { |
function referrers($nid, $fields, $types = NULL) { |
| 108 |
return array_keys(nodereferrer_referrers_with_translations( |
return array_keys(nodereferrer_referrers_with_translations( |
| 109 |
$nid, $fields, $types, |
$nid, $fields, $types, |
| 110 |
!empty($this->options['multilingual']['referrers_of_translations']), |
!empty($this->options['multilingual']['referrers_of_translations']), |
| 111 |
!empty($this->options['multilingual']['translations_of_referrers']) |
!empty($this->options['multilingual']['translations_of_referrers']) |
| 112 |
)); |
)); |
| 113 |
} |
} |
| 114 |
|
|
| 115 |
/** |
/** |
| 116 |
* This should be overriden by descendant classes |
* This should be overriden by descendant classes |
| 117 |
*/ |
*/ |
| 118 |
function get_node_list() { |
function get_node_list() { |
| 119 |
return array(); |
return array(); |
| 120 |
} |
} |
| 121 |
|
|
| 122 |
function get_options() { |
function get_options() { |
| 123 |
return array(); |
return array(); |
| 124 |
} |
} |