-
Notifications
You must be signed in to change notification settings - Fork 3
/
views_handler_field_open_badges_user_uid.inc
99 lines (85 loc) · 3.09 KB
/
views_handler_field_open_badges_user_uid.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
/**
* @file
* A handler to provide proper displays for open badges.
*
* @author Heine Deelstra (Heine), http://drupal.org/user/17943
* @author Richard Skinner (Likeless), http://drupal.org/user/310635
*
* @ingroup views_field_handlers
*/
class views_handler_field_open_badges_user_uid extends views_handler_field {
function render($values) {
//dpm("views_handler_field_open_badges_user_uid: render(): entered");
//We'll be needing the uid
$uid = $values->{$this->field_alias};
switch ($this->options['appearance']) {
//For the text options, get the badge objects and format their names
case 'linked_text':
case 'unlinked_text':
$open_badges = open_badges_get_badges($uid);
//If we have no badges for the user, just return nothing.
if (count($open_badges) == 0) {
return '';
}
foreach ((array)$open_badges as $badge) {
if ($this->options['appearance'] == 'linked_text' && $badge->criteria) {
$badges[] = l($badge->name, $badge->criteria);
}
else {
$badges[] = check_plain($badge->name);
}
}
return implode($this->options['seperator'], $badges);
//Send the array of badge objects to the custom theme function
case 'custom_theme':
$open_badges = open_badges_get_badges($uid);
return theme($this->options['theme'], $open_badges);
//This case is for everything else. It returns the normal themed badges.
default:
return open_badges_for_uid($uid);
}
}
//Our options initialisation
function option_definition() {
$options = parent::option_definition();
$options['appearance'] = 'badges';
$options['seperator'] = ' ';
$options['theme'] = '';
return $options;
}
//Our options form
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$form['appearance'] = array(
'#title' => t('Appearance'),
'#description' => t('How the badges will appear.'),
'#type' => 'radios',
'#options' => array(
'badges' => t('Badges'),
'linked_text' => t('Linked Text'),
'unlinked_text' => t('Unlinked Text'),
'custom_theme' => t('Custom Theme'),
),
'#default_value' => $this->options['appearance'],
'#weight' => -3,
);
$form['seperator'] = array(
'#title' => t('Text Seperator'),
'#description' => t('If you select text formats above, this is the string that will go between each badge name.'),
'#type' => 'textfield',
'#default_value' => $this->options['seperator'],
'#size' => 6,
'#maxlength' => 128,
'#weight' => -2,
);
$form['theme'] = array(
'#title' => t('Custom Theme'),
'#description' => t('If you select "Custom Theme" above, enter the name of your theme here. It will be passed an array of badge objects.'),
'#type' => 'textfield',
'#default_value' => $this->options['theme'],
'#maxlength' => 128,
'#weight' => -1,
);
}
}