-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiondry.view.inc
80 lines (73 loc) · 1.91 KB
/
iondry.view.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
class iondry_view {
/**
* Loads nodes from a view
*/
public function load_nodes($view, $display=false, $args=false, $options = array()) {
$result = array();
$nids = $this->load_nodeIds($view, $display, $args, $options);
if(count($nids)) {
$res = node_load_multiple($nids);
foreach($res as $item) {
$result[] = iondry::n($item);
}
}
return $result;
}
public function load_nodeIds($view, $display=false, $args=false, $options = array()) {
$nids = array();
$view = views_get_view($view);
if($view) {
if($args) {
$view->set_arguments($args);
}
if($display) {
$view->set_display($display);
}
if($options && $options['limit']) {
$view->set_items_per_page($options['limit']);
}
$view->execute();
if(!empty($view->result) && $view->result[0]) {
foreach($view->result as $item) {
if(!empty($item->nid)) {
$nids[] = $item->nid;
} elseif(!empty($item->entity)) { // View of type search index returns different structured objects
$nids[] = $item->entity;
}
}
}
}
return $nids;
}
public function load_termIds($view, $display=false, $args=false, $options = array()) {
$tids = array();
$view = views_get_view($view);
if($view) {
if($args) {
$view->set_arguments($args);
}
if($display) {
$view->set_display($display);
}
if($options && $options['limit']) {
$view->set_items_per_page($options['limit']);
}
$view->execute();
if(!empty($view->result) && $view->result[0]) {
foreach($view->result as $item) {
if(!empty($item->tid)) {
$tids[] = $item->tid;
}
}
}
}
return $tids;
}
/**
* Factory method
*/
public static function instance() {
return new self();
}
}