本文整理汇总了PHP中Poll::isVotable方法的典型用法代码示例。如果您正苦于以下问题:PHP Poll::isVotable方法的具体用法?PHP Poll::isVotable怎么用?PHP Poll::isVotable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Poll
的用法示例。
在下文中一共展示了Poll::isVotable方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Reads the input parameters and vote the poll
*
* @param array $p_input
*/
public function __construct(array $p_input)
{
$this->m_defined = true;
$this->m_name = 'poll';
if (!isset($p_input['f_poll_nr']) || empty($p_input['f_poll_nr'])) {
$this->m_error = new PEAR_Error('The poll number is missing.', ACTION_POLL_ERR_NO_POLL_NUMBER);
return false;
}
$this->m_properties['poll_nr'] = $p_input['f_poll_nr'];
if (!isset($p_input['f_poll_language_id']) || empty($p_input['f_poll_language_id'])) {
$this->m_error = new PEAR_Error('The poll language is missing.', ACTION_POLL_ERR_NO_LANGUAGE_ID);
return false;
}
$this->m_properties['poll_language_id'] = $p_input['f_poll_language_id'];
if ($p_input['f_poll_mode'] !== 'standard' && $p_input['f_poll_mode'] !== 'ajax') {
$this->m_error = new PEAR_Error('The poll mode parameter is invalid.', ACTION_POLL_ERR_INVLID_MODE);
return false;
}
$this->m_properties['poll_mode'] = $p_input['f_poll_mode'];
$Poll = new Poll($this->m_properties['poll_language_id'], $this->m_properties['poll_nr']);
if (!$Poll->exists()) {
$this->m_error = new PEAR_Error('Poll does not exists.', ACTION_POLL_ERR_NOT_EXISTS);
return false;
}
if (!$Poll->isVotable()) {
$this->m_error = new PEAR_Error('Poll is not votable.', ACTION_POLL_ERR_NOT_VOTABLE);
return false;
} else {
switch($p_input['f_poll_mode']) {
case 'ajax':
$allowed_values = $_SESSION['camp_poll_maxvote'][$this->m_properties['poll_nr']][$this->m_properties['poll_language_id']];
if (!is_array($allowed_values)) {
$this->m_error = new PEAR_Error('Invalid poll voting value.', ACTION_POLL_ERR_INVALID_VALUE);
return false;
}
foreach ($Poll->getAnswers() as $PollAnswer) {
$nr = $PollAnswer->getNumber();
if (isset($p_input['f_pollanswer_'.$nr]) && !empty($p_input['f_pollanswer_'.$nr])) {
// check if value is valid
if (!array_key_exists($p_input['f_pollanswer_'.$nr], $allowed_values[$nr])) {
$this->m_error = new PEAR_Error('Invalid poll voting value.', ACTION_POLL_ERR_INVALID_VALUE);
return false;
}
$this->m_properties['pollanswer_nr'] = $nr;
$this->m_properties['value'] = $p_input['f_pollanswer_'.$nr];
break;
}
}
if (!$this->m_properties['value']) {
$this->m_error = new PEAR_Error('No answer value was given.', ACTION_POLL_ERR_NOANSWER_VALUE);
return false;
}
break;
case 'standard':
if (!isset($p_input['f_pollanswer_nr']) || empty($p_input['f_pollanswer_nr'])) {
$this->m_error = new PEAR_Error('Invalid poll voting value.', ACTION_POLL_ERR_INVALID_VALUE);
return false;
}
$this->m_properties['pollanswer_nr'] = $p_input['f_pollanswer_nr'];
$this->m_properties['value'] = 1;
break;
}
}
$this->m_poll = $Poll;
}