advpoll_helper.inc in Advanced Poll 7.2
File
includes/advpoll_helper.inc
View source
<?php
function advpoll_get_data($node) {
$data = array();
$lang = $node->language;
if ($node->type == 'advpoll') {
isset($node->advpoll_options[$lang]) ? $options = $node->advpoll_options[$lang] : ($options = $node->advpoll_options['und']);
isset($node->advpoll_choice[$lang]) ? $data['choices'] = $node->advpoll_choice[$lang] : ($data['choices'] = $node->advpoll_choice['und']);
isset($node->advpoll_dates[$lang]) ? $data['start_date'] = strtotime($node->advpoll_dates[$lang][0]['value']) : ($data['start_date'] = strtotime($node->advpoll_dates['und'][0]['value']));
isset($node->advpoll_dates[$lang]) ? $data['end_date'] = strtotime($node->advpoll_dates[$lang][0]['value2']) : ($data['end_date'] = strtotime($node->advpoll_dates['und'][0]['value2']));
isset($node->advpoll_mode[$lang]) ? $data['mode'] = $node->advpoll_mode[$lang][0]['value'] : ($data['mode'] = $node->advpoll_mode['und'][0]['value']);
isset($node->advpoll_cookie_duration[$lang]) ? $data['cookie_duration'] = $node->advpoll_cookie_duration[$lang][0]['value'] : ($data['cookie_duration'] = $node->advpoll_cookie_duration['und'][0]['value']);
isset($node->advpoll_closed[$lang]) ? $data['state'] = $node->advpoll_closed[$lang][0]['value'] : ($data['state'] = $node->advpoll_closed['und'][0]['value']);
isset($node->advpoll_behavior[$lang]) ? $data['behavior'] = $node->advpoll_behavior[$lang][0]['value'] : ($data['behavior'] = $node->advpoll_behavior['und'][0]['value']);
isset($node->advpoll_max_choices[$lang]) ? $data['max_choices'] = $node->advpoll_max_choices[$lang][0]['value'] : ($data['max_choices'] = $node->advpoll_max_choices['und'][0]['value']);
isset($node->advpoll_results[$lang]) ? $data['show_results'] = $node->advpoll_results[$lang][0]['value'] : ($data['show_results'] = $node->advpoll_results['und'][0]['value']);
$data['electoral'] = advpoll_has_data($options, 'electoral');
$data['show_votes'] = advpoll_has_data($options, 'showvotes');
$data['write_in'] = advpoll_has_data($options, 'writein');
$data['block'] = advpoll_has_data($options, 'block');
}
return (object) $data;
}
function advpoll_has_data($options, $term) {
foreach ($options as $option) {
if ($option['value'] == $term) {
return TRUE;
}
}
return FALSE;
}
function advpoll_get_form_data($form_state) {
$data = array();
$node = $form_state['build_info']['args'][0];
$lang = $node->language;
if ($node->type == 'advpoll') {
isset($node->advpoll_options[$lang]) ? $options = $node->advpoll_options[$lang] : ($options = $node->advpoll_options['und']);
isset($node->advpoll_choice[$lang]) ? $data['choices'] = $node->advpoll_choice[$lang] : ($data['choices'] = $node->advpoll_choice['und']);
isset($node->advpoll_dates[$lang]) ? $data['start_date'] = strtotime($node->advpoll_dates[$lang][0]['value']) : ($data['start_date'] = strtotime($node->advpoll_dates['und'][0]['value']));
isset($node->advpoll_dates[$lang]) ? $data['end_date'] = strtotime($node->advpoll_dates[$lang][0]['value2']) : ($data['end_date'] = strtotime($node->advpoll_dates['und'][0]['value2']));
isset($node->advpoll_mode[$lang]) ? $data['mode'] = $node->advpoll_mode[$lang][0]['value'] : ($data['mode'] = $node->advpoll_mode['und'][0]['value']);
isset($node->advpoll_cookie_duration[$lang]) ? $data['cookie_duration'] = $node->advpoll_cookie_duration[$lang][0]['value'] : ($data['cookie_duration'] = $node->advpoll_cookie_duration['und'][0]['value']);
isset($node->advpoll_closed[$lang]) ? $data['state'] = $node->advpoll_closed[$lang][0]['value'] : ($data['state'] = $node->advpoll_closed['und'][0]['value']);
isset($node->advpoll_behavior[$lang]) ? $data['behavior'] = $node->advpoll_behavior[$lang][0]['value'] : ($data['behavior'] = $node->advpoll_behavior['und'][0]['value']);
isset($node->advpoll_max_choices[$lang]) ? $data['max_choices'] = $node->advpoll_max_choices[$lang][0]['value'] : ($data['max_choices'] = $node->advpoll_max_choices['und'][0]['value']);
isset($node->advpoll_results[$lang]) ? $data['show_results'] = $node->advpoll_results[$lang][0]['value'] : ($data['show_results'] = $node->advpoll_results['und'][0]['value']);
$data['electoral'] = advpoll_has_data($options, 'electoral');
$data['show_votes'] = advpoll_has_data($options, 'showvotes');
$data['write_in'] = advpoll_has_data($options, 'writein');
$data['block'] = advpoll_has_data($options, 'block');
}
return (object) $data;
}
Functions
Name |
Description |
advpoll_get_data |
Returns an object with a predictable structure regardless of content type.
It basically saves having to extract the data in any given function that
retrieves specific fields from a node. |
advpoll_get_form_data |
Returns an object with a predictable structure regardless of content type form state.
This call returns the same data structure as the advpoll_get_data() call, only
using form_state data rather than node data. |
advpoll_has_data |
|