Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 58e422606a
Fetching contributors…

Cannot retrieve contributors at this time

100 lines (85 sloc) 3.165 kb
<?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,
);
}
}
Jump to Line
Something went wrong with that request. Please try again.