-
Notifications
You must be signed in to change notification settings - Fork 0
/
ba_module.module
182 lines (154 loc) · 4.81 KB
/
ba_module.module
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<?php
/**
* Implement hook_entity_info_alter
*/
function ba_module_entity_info_alter(&$entity_info) {
$entity_info['node']['view modes']['recent_tutorials'] = array(
'label' => t('Recent Tutorials'),
'custom settings' => TRUE,
);
$entity_info['node']['view modes']['discover_tutorials'] = array(
'label' => t('Discover Tutorials'),
'custom settings' => TRUE,
);
$entity_info['node']['view modes']['spotlight'] = array(
'label' => t('Spotlight'),
'custom settings' => TRUE,
);
}
/**
* Implement hook_block_info()
*/
function ba_module_block_info() {
$blocks['recent_tutorials'] = array(
'info' => t('Recent Tutorials'),
'cache' => DRUPAL_NO_CACHE,
);
$blocks['beginner_tutorials'] = array(
'info' => t('Beginner Tutorials'),
'cache' => DRUPAL_NO_CACHE,
);
$blocks['spotlight'] = array(
'info' => t('Spotlight'),
'cache' => DRUPAL_NO_CACHE,
);
return $blocks;
}
/**
* Implement hook_block_view()
*/
function ba_module_block_view($delta = '') {
$block = array();
switch ($delta) {
case 'recent_tutorials':
$results = array();
$terms = array(2989, 3193);
foreach ($terms as $tid) {
$result = NULL;
$query = new EntityFieldQuery;
$query
->entityCondition('entity_type', 'node')
->entityCondition('bundle', 'article')
->propertyCondition('status', 1)
->fieldCondition('field_difficulty', 'tid', NULL, '=')
->fieldCondition('field_instrument', 'tid', $tid, '=')
->propertyOrderBy('created', 'DESC')
->range(0,10);
$result = $query->execute();
if ($result) {
$results += entity_load('node', array_keys($result['node']));
}
}
shuffle($results);
$sliced = array_slice($results, 0, 10);
$view = entity_view('node', $sliced, 'recent_tutorials');
$block['subject'] = NULL;
$block['content'] = theme('recent_tutorials', array('title' => NULL, 'content' => render($view)));
break;
case 'beginner_tutorials':
$results = array();
$terms = array(2989, 3193);
foreach ($terms as $tid) {
$result = NULL;
$query = new EntityFieldQuery;
$query
->entityCondition('entity_type', 'node')
->entityCondition('bundle', 'article')
->propertyCondition('status', 1)
->fieldCondition('field_instrument', 'tid', $tid, '=')
->fieldCondition('field_difficulty', 'tid', 3385, '=')
->propertyOrderBy('created', 'DESC')
->range(0,10);
$result = $query->execute();
if ($result) {
$results += entity_load('node', array_keys($result['node']));
}
}
shuffle($results);
$sliced = array_slice($results, 0, 10);
$view = entity_view('node', $sliced, 'recent_tutorials');
$block['subject'] = NULL;
$block['content'] = theme('beginner_tutorials', array('title' => NULL, 'content' => render($view)));
break;
case 'spotlight':
$results = array();
$result = NULL;
$query = new EntityFieldQuery;
$query
->entityCondition('entity_type', 'node')
->entityCondition('bundle', 'article')
->propertyCondition('status', 1)
->fieldCondition('field_featured', 'value', '1', '=')
->propertyOrderBy('changed', 'DESC')
->range(0, 1);
$result = $query->execute();
if ($result) {
$results += entity_load('node', array_keys($result['node']));
}
$view = entity_view('node', $results, 'spotlight');
$block['subject'] = NULL;
$block['content'] = theme('spotlight', array('title' => NULL, 'content' => render($view)));
break;
}
return $block;
}
/**
* Preprocess recent_tutorials and beginner_tutorials block
*/
function ba_module_theme() {
return array(
'recent_tutorials' => array(
'template' => 'recent_tutorials',
'path' => drupal_get_path('module', 'ba_module') . '/tpl',
'variables' => array('title' => NULL, 'content' => NULL),
),
'beginner_tutorials' => array(
'template' => 'beginner_tutorials',
'path' => drupal_get_path('module', 'ba_module') . '/tpl',
'variables' => array('title' => NULL, 'content' => NULL),
),
'spotlight' => array(
'template' => 'spotlight',
'path' => drupal_get_path('module', 'ba_module') . '/tpl',
'variables' => array('title' => NULL, 'content' => NULL),
),
);
}
/**
* Preprocess recent_tutorials block
*/
function template_preprocess_recent_tutorials(&$variables) {
//dpm($variables);
}
/**
* Preprocess beginner_tutorials block
*/
function template_preprocess_beginner_tutorials(&$variables) {
//dpm($variables);
}
/**
* Preprocess spotlight block
*/
function template_preprocess_spotlight(&$variables) {
//dpm($variables);
}