| 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 fields. This handler |
* We use this as a parent class for both the nodereferrer fields. This handler |
| 15 |
*/ |
*/ |
| 16 |
function options_form(&$form, &$form_state) { |
function options_form(&$form, &$form_state) { |
| 17 |
parent::options_form($form, $form_state); |
parent::options_form($form, $form_state); |
| 18 |
|
|
| 19 |
$options = nodereferrer_field_formatter_info(); |
$options = nodereferrer_field_formatter_info(); |
| 20 |
foreach ($options as $k => $v) { |
foreach ($options as $k => $v) { |
| 21 |
$options[$k] = $v['label']; |
$options[$k] = $v['label']; |
| 28 |
'#description' => t('Select the formatter to use to display the fields'), |
'#description' => t('Select the formatter to use to display the fields'), |
| 29 |
'#default_value' => empty($this->options['formatter']) ? '' : $this->options['formatter'], |
'#default_value' => empty($this->options['formatter']) ? '' : $this->options['formatter'], |
| 30 |
); |
); |
| 31 |
|
|
| 32 |
$form['list'] = array( |
$form['list'] = array( |
| 33 |
'#type' => 'select', |
'#type' => 'select', |
| 34 |
'#multiple' => FALSE, |
'#multiple' => FALSE, |
| 37 |
'#description' => t('Select how multiple values should be displayed'), |
'#description' => t('Select how multiple values should be displayed'), |
| 38 |
'#default_value' => empty($this->options['list']) ? 'list' : $this->options['list'], |
'#default_value' => empty($this->options['list']) ? 'list' : $this->options['list'], |
| 39 |
); |
); |
| 40 |
|
|
| 41 |
$form['fields'] = array( |
$form['fields'] = array( |
| 42 |
'#type' => 'checkboxes', |
'#type' => 'checkboxes', |
| 43 |
'#multiple' => TRUE, |
'#multiple' => TRUE, |
| 46 |
'#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'), |
| 47 |
'#default_value' => empty($this->options['fields']) ? array() : $this->options['fields'], |
'#default_value' => empty($this->options['fields']) ? array() : $this->options['fields'], |
| 48 |
); |
); |
| 49 |
|
|
| 50 |
if (module_exists('translation')) { |
if (module_exists('translation')) { |
| 51 |
$form['multilingual'] = array( |
$form['multilingual'] = array( |
| 52 |
'#type' => 'fieldset', |
'#type' => 'fieldset', |
| 53 |
'#collapsible' => 'true', |
'#collapsible' => TRUE, |
| 54 |
'#collapsed' => 'true', |
'#collapsed' => TRUE, |
| 55 |
'#title' => t('Multilingual options'), |
'#title' => t('Multilingual options'), |
| 56 |
); |
); |
| 57 |
|
|
| 58 |
$default = 0; |
$default = 0; |
| 59 |
if (!empty($this->options['multilingual']['referrers_of_translations'])) { |
if (!empty($this->options['multilingual']['referrers_of_translations'])) { |
| 60 |
$default = $this->options['multilingual']['referrers_of_translations']; |
$default = $this->options['multilingual']['referrers_of_translations']; |
| 65 |
'#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'), |
| 66 |
'#default_value' => $default, |
'#default_value' => $default, |
| 67 |
); |
); |
| 68 |
|
|
| 69 |
$default = 0; |
$default = 0; |
| 70 |
if (!empty($this->options['multilingual']['translations_of_referrers'])) { |
if (!empty($this->options['multilingual']['translations_of_referrers'])) { |
| 71 |
$default = $this->options['multilingual']['translations_of_referrers']; |
$default = $this->options['multilingual']['translations_of_referrers']; |
| 78 |
); |
); |
| 79 |
} |
} |
| 80 |
} |
} |
| 81 |
|
|
| 82 |
/** |
/** |
| 83 |
* All we need to do is ensure our table is there |
* All we need to do is ensure our table is there |
| 84 |
*/ |
*/ |
| 85 |
function query() { |
function query() { |
| 86 |
$this->ensure_my_table(); |
$this->ensure_my_table(); |
| 87 |
} |
} |
| 88 |
|
|
| 89 |
/** |
/** |
| 90 |
* 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 |
| 91 |
* that refer to the given node. This takes translation settings into account |
* that refer to the given node. This takes translation settings into account |
| 92 |
*/ |
*/ |
| 93 |
function referrers($nid, $fields, $types = null) { |
function referrers($nid, $fields, $types = NULL) { |
| 94 |
return nodereferrer_referrers_with_translations( |
return nodereferrer_referrers_with_translations( |
| 95 |
$nid, $fields, $types, |
$nid, $fields, $types, |
| 96 |
!empty($this->options['multilingual']['referrers_of_translations']), |
!empty($this->options['multilingual']['referrers_of_translations']), |
| 97 |
!empty($this->options['multilingual']['translations_of_referrers']) |
!empty($this->options['multilingual']['translations_of_referrers']) |
| 98 |
); |
); |
| 99 |
} |
} |
| 100 |
|
|
| 101 |
/** |
/** |
| 102 |
* Render the field. |
* Render the field. |
| 103 |
* |
* |
| 105 |
function render($values) { |
function render($values) { |
| 106 |
$list = $this->get_item_list($values->nid); |
$list = $this->get_item_list($values->nid); |
| 107 |
foreach ($list as $k => $v) { |
foreach ($list as $k => $v) { |
| 108 |
$list[$k] = theme('nodereferrer_field_'.$this->options['formatter'], $v); |
$list[$k] = theme('nodereferrer_field_' . $this->options['formatter'], $v); |
| 109 |
} |
} |
| 110 |
if ($this->options['list'] == 'list') { |
if ($this->options['list'] == 'list') { |
| 111 |
if (count($list)) { |
if (count($list)) { |
| 112 |
return '<ul><li>'.implode('</li><li>', array_filter($list)).'</li></ul>'; |
return '<ul><li>' . implode('</li><li>', array_filter($list)) . '</li></ul>'; |
| 113 |
} else { |
} |
| 114 |
|
else { |
| 115 |
return ''; |
return ''; |
| 116 |
} |
} |
| 117 |
} else { |
} |
| 118 |
|
else { |
| 119 |
return implode(', ', $list); |
return implode(', ', $list); |
| 120 |
} |
} |
| 121 |
} |
} |
| 122 |
|
|
| 123 |
/** |
/** |
| 124 |
* This should be overriden by descendant classes |
* This should be overriden by descendant classes |
| 125 |
*/ |
*/ |
| 126 |
function get_node_list($nid) { |
function get_node_list($nid) { |
| 127 |
return array(); |
return array(); |
| 128 |
} |
} |
| 129 |
|
|
| 130 |
function get_options() { |
function get_options() { |
| 131 |
return array(); |
return array(); |
| 132 |
} |
} |
| 133 |
} |
} |
|
|
|