function makemeeting_preprocess_makemeeting_choices in Make Meeting Scheduler 7
Preprocess for makemeeting choices
Parameters
$vars:
File
- ./
makemeeting.module, line 39 - Make Meeting module
Code
function makemeeting_preprocess_makemeeting_choices(&$vars) {
global $user;
// Get the element
$element = $vars['element'];
$vars['options'] = array();
// Get the options data
foreach ($element['#attributes']['days_and_options'] as $days => $options_array) {
// Day of the option
$option = array(
'day' => check_plain(substr($days, strpos($days, "_") + 1)),
);
// Options of the day
$options = array();
foreach ($options_array as $o) {
$start = strpos($o, "_");
$options[substr($o, 0, $start)] = check_plain(substr($o, $start + 1));
}
$option['options'] = $options;
$vars['options'][] = $option;
}
$votes = $votes_stats = array();
foreach ($element['#attributes']['answers'] as $username => $vote) {
$votes[$username] = array();
foreach ($vars['options'] as $option) {
foreach ($option['options'] as $id => $data) {
// Initialize statistics
if (!isset($votes_stats[$id])) {
$votes_stats[$id] = array();
}
// Initialize vote
if (!isset($vote[$id])) {
$vote[$id] = 0;
}
// Analyse vote
switch ($vote[$id]) {
case 0:
$votes[$username][$id] = 'no';
break;
case 1:
$votes[$username][$id] = 'ok';
break;
case 2:
$votes[$username][$id] = 'maybe';
}
// Update stats
if (isset($votes_stats[$id][$vote[$id]])) {
$votes_stats[$id][$vote[$id]]++;
}
else {
$votes_stats[$id][$vote[$id]] = 1;
}
}
}
}
$vars['total_count'] = count($votes) * count(reset($votes));
$vars['votes'] = $votes;
foreach ($votes_stats as &$stats) {
$yes = isset($stats[1]) ? $stats[1] : 0;
$no = isset($stats[0]) ? $stats[0] : 0;
$maybe = isset($stats[2]) ? $stats[2] : 0;
if ($element['#attributes']['maybe_option'] == 1) {
$style = $no > $yes + $maybe ? "red" : ($yes > $no + $maybe ? "green" : "yellow");
}
else {
$style = $yes > $no ? "green" : ($yes == $no ? "yellow" : "red");
}
$stats = array(
'style' => $style,
'yes' => $yes,
'no' => $no,
'maybe' => $maybe,
);
}
$vars['votes_stats'] = $votes_stats;
$vars['choices'] = array(
'no' => t('No'),
'ok' => t('Yes'),
'maybe' => t('Maybe'),
);
$element = array(
'#type' => 'textfield',
'#name' => 'your_name',
'#attributes' => array(),
'#value' => isset($element['#value']['name']) ? $element['#value']['name'] : $user->name,
'#size' => 20,
);
$vars['input'] = drupal_render($element);
$vars['input_type'] = 'radio';
if (isset($element['#attributes']['multiple_allowed']) && $element['#attributes']['multiple_allowed'] == 0) {
$vars['input_type'] = 'checkbox';
}
}