1
|
<?php
|
2
|
/**
|
3
|
* @file
|
4
|
* Contains the topic list style plugin.
|
5
|
*/
|
6
|
|
7
|
/**
|
8
|
* Style plugin to render each item as a row in a table.
|
9
|
*
|
10
|
* @ingroup views_style_plugins
|
11
|
*/
|
12
|
// @codingStandardsIgnoreStart
|
13
|
class advanced_forum_plugin_style_forum_topic_list extends views_plugin_style_table {
|
14
|
/**
|
15
|
* {@inheritdoc}
|
16
|
*/
|
17
|
public function option_definition() {
|
18
|
$options = parent::option_definition();
|
19
|
$options['tid'] = array('default' => '');
|
20
|
return $options;
|
21
|
}
|
22
|
|
23
|
/**
|
24
|
* {@inheritdoc}
|
25
|
*/
|
26
|
public function options_form(&$form, &$form_state) {
|
27
|
parent::options_form($form, $form_state);
|
28
|
$options = array('' => t('None'));
|
29
|
|
30
|
$arguments = $this->display->handler->get_handlers('argument');
|
31
|
foreach ($arguments as $id => $argument) {
|
32
|
$options['argument.' . $id] = $argument->ui_name();
|
33
|
|
34
|
}
|
35
|
$filters = $this->display->handler->get_handlers('filter');
|
36
|
foreach ($filters as $id => $filter) {
|
37
|
$options['filter.' . $id] = $filter->ui_name();
|
38
|
}
|
39
|
|
40
|
$form['tid'] = array(
|
41
|
'#type' => 'select',
|
42
|
'#title' => t('Source of forum ID'),
|
43
|
'#options' => $options,
|
44
|
'#default_value' => $this->options['tid'],
|
45
|
);
|
46
|
}
|
47
|
|
48
|
/**
|
49
|
* {@inheritdoc}
|
50
|
*
|
51
|
* Add a couple of fields to the query that we can later use. We are going to
|
52
|
* specificly alias them because this style is not meant to be used on relationships.
|
53
|
*/
|
54
|
public function query() {
|
55
|
$this->view->query->add_field('node', 'sticky', 'topic_is_sticky');
|
56
|
$this->view->query->add_field('forum', 'tid', 'topic_actual_forum');
|
57
|
}
|
58
|
|
59
|
/**
|
60
|
* Figure out what the forum ID is. It could have come from an argument or a filter or nowhere.
|
61
|
*
|
62
|
* This source would be set by the user in the options.
|
63
|
*/
|
64
|
public function get_forum_ids() {
|
65
|
$where = $this->options['tid'];
|
66
|
if (empty($where)) {
|
67
|
return;
|
68
|
}
|
69
|
|
70
|
$term = '';
|
71
|
|
72
|
list($type, $id) = explode('.', $where, 2);
|
73
|
$handler = $this->display->handler->get_handler($type, $id);
|
74
|
if ($type == 'argument') {
|
75
|
return empty($handler->argument) ? array() : array($handler->argument);
|
76
|
}
|
77
|
else {
|
78
|
$terms = is_array($handler->value) ? $handler->value : array($handler->value);
|
79
|
if (isset($handler->options['depth'])) {
|
80
|
foreach ($terms as $tid) {
|
81
|
$term = taxonomy_term_load($tid);
|
82
|
$tree = taxonomy_get_tree($term->vid, $tid, -1, $handler->options['depth']);
|
83
|
$terms = array_merge($terms, array_map('_taxonomy_get_tid_from_term', $tree));
|
84
|
}
|
85
|
}
|
86
|
return $terms;
|
87
|
}
|
88
|
}
|
89
|
}
|
90
|
// @codingStandardsIgnoreEnd
|