本文整理汇总了PHP中Poll::userVoted方法的典型用法代码示例。如果您正苦于以下问题:PHP Poll::userVoted方法的具体用法?PHP Poll::userVoted怎么用?PHP Poll::userVoted使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Poll
的用法示例。
在下文中一共展示了Poll::userVoted方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: wfPollVote
function wfPollVote( $pollID, $choiceID ) {
global $wgUser;
$p = new Poll();
if( !$p->userVoted( $wgUser->getName(), $pollID ) ) {
$p->addPollVote( $pollID, $choiceID );
}
return 'OK';
}
示例2: view
//.........这里部分代码省略.........
$output .= '<div class="poll-links">' . "\n";
// Poll administrators can access the poll admin panel
if ($wgUser->isAllowed('polladmin')) {
$output .= '<a href="' . SpecialPage::getTitleFor('AdminPoll')->escapeFullURL() . '">' . wfMsg('poll-admin-panel') . '</a> | ';
}
if ($poll_info['status'] == 1 && ($poll_info['user_id'] == $wgUser->getID() || $wgUser->isAllowed('polladmin'))) {
$output .= "<a href=\"javascript:void(0)\" onclick=\"PollNY.toggleStatus({$toggle_status});\">{$toggle_label}</a> |";
}
if ($poll_info['status'] == 1 || $wgUser->isAllowed('polladmin')) {
$output .= " <a href=\"javascript:void(0)\" onclick=\"PollNY.toggleStatus({$toggle_flag_status});\">{$toggle_flag_label}</a>";
}
$output .= "\n" . '</div>' . "\n";
// .poll-links
$output .= '</div>' . "\n";
// .poll-right
$output .= '<div class="poll">' . "\n";
$output .= "<h1 class=\"pagetitle\">{$wgTitle->getText()}</h1>\n";
if ($poll_info['image']) {
$poll_image_width = 150;
$poll_image = wfFindFile($poll_info['image']);
$poll_image_url = $width = '';
if (is_object($poll_image)) {
$poll_image_url = $poll_image->createThumb($poll_image_width);
if ($poll_image->getWidth() >= $poll_image_width) {
$width = $poll_image_width;
} else {
$width = $poll_image->getWidth();
}
}
$poll_image_tag = '<img width="' . $width . '" alt="" src="' . $poll_image_url . '"/>';
$output .= "<div class=\"poll-image\">{$poll_image_tag}</div>";
}
// Display question and let user vote
if (!$p->userVoted($wgUser->getName(), $poll_info['id']) && $poll_info['status'] == 1) {
$output .= '<div id="loading-poll">' . wfMsg('poll-js-loading') . '</div>' . "\n";
$output .= '<div id="poll-display" style="display:none;">' . "\n";
$output .= '<form name="poll"><input type="hidden" id="poll_id" name="poll_id" value="' . $poll_info['id'] . '"/>' . "\n";
foreach ($poll_info['choices'] as $choice) {
$output .= '<div class="poll-choice">
<input type="radio" name="poll_choice" onclick="PollNY.vote()" id="poll_choice" value="' . $choice['id'] . '" />' . $choice['choice'] . '</div>';
}
$output .= '</form>
</div>' . "\n";
$output .= '<div class="poll-timestamp">' . wfMsg('poll-createdago', Poll::getTimeAgo($poll_info['timestamp'])) . '</div>' . "\n";
$output .= "\t\t\t\t\t" . '<div class="poll-button">
<a href="javascript:PollNY.skip();">' . wfMsg('poll-skip') . '</a>
</div>';
if ($wgRequest->getInt('prev_id')) {
$p = new Poll();
$poll_info_prev = $p->getPoll($wgRequest->getInt('prev_id'));
$poll_title = Title::makeTitle(NS_POLL, $poll_info_prev['question']);
$output .= '<div class="previous-poll">';
$output .= '<div class="previous-poll-title">' . wfMsg('poll-previous-poll') . " - <a href=\"{$poll_title->getFullURL()}\">{$poll_info_prev['question']}</a></div>\n\t\t\t\t\t<div class=\"previous-sub-title\">" . wfMsgExt('poll-view-answered-times', 'parsemag', $poll_info_prev['votes']) . '</div>';
$x = 1;
foreach ($poll_info_prev['choices'] as $choice) {
if ($poll_info_prev['votes'] > 0) {
$percent = round($choice['votes'] / $poll_info_prev['votes'] * 100);
$bar_width = floor(360 * ($choice['votes'] / $poll_info_prev['votes']));
} else {
$percent = 0;
$bar_width = 0;
}
if (empty($choice['votes'])) {
$choice['votes'] = 0;
}
$bar_img = '<img src="' . $wgScriptPath . '/extensions/PollNY/images/vote-bar-' . $x . '.gif" class="image-choice-' . $x . '" style="width:' . $bar_width . 'px;height:11px;"/>';
示例3: renderEmbedPoll
/**
* Callback function for the <pollembed> tag.
*
* @param $input Mixed: user input
* @param $args Array: arguments supplied to the pollembed tag
* @param $parser Object: instance of Parser class
* @return HTML or nothing
*/
public static function renderEmbedPoll($input, $args, $parser)
{
$poll_name = $args['title'];
if ($poll_name) {
global $wgOut, $wgUser, $wgScriptPath;
// Load CSS for non-Monaco skins - Monaco's ny.css already contains
// PollNY's styles (and more)
if (get_class($wgUser->getSkin()) !== 'SkinMonaco') {
$wgOut->addExtensionStyle($wgScriptPath . '/extensions/PollNY/Poll.css');
}
// Disable caching; this is important so that we don't cause subtle
// bugs that are a bitch to fix.
$wgOut->enableClientCache(false);
$parser->disableCache();
$poll_title = Title::newFromText($poll_name, NS_POLL);
$poll_title = PollNYHooks::followPollID($poll_title);
$poll_page_id = $poll_title->getArticleID();
if ($poll_page_id > 0) {
$p = new Poll();
$poll_info = $p->getPoll($poll_page_id);
$output = "\t\t" . '<div class="poll-embed-title">' . $poll_info['question'] . '</div>' . "\n";
if ($poll_info['image']) {
$poll_image_width = 100;
$poll_image = wfFindFile($poll_info['image']);
$width = $poll_image_url = '';
if (is_object($poll_image)) {
$poll_image_url = $poll_image->createThumb($poll_image_width);
if ($poll_image->getWidth() >= $poll_image_width) {
$width = $poll_image_width;
} else {
$width = $poll_image->getWidth();
}
}
$poll_image_tag = '<img width="' . $width . '" alt="" src="' . $poll_image_url . '" />';
$output .= "\t\t<div class=\"poll-image\">{$poll_image_tag}</div>\n";
}
// If the user hasn't voted for this poll yet and the poll is open
// for votes, display the question and let the user vote
if (!$p->userVoted($wgUser->getName(), $poll_info['id']) && $poll_info['status'] == 1) {
$wgOut->addScriptFile($wgScriptPath . '/extensions/PollNY/Poll.js');
$wgOut->addScript("<script type=\"text/javascript\">\$( function() { PollNY.showEmbedPoll({$poll_info['id']}); } );</script>\n");
$output .= "<div id=\"loading-poll_{$poll_info['id']}\">" . wfMsg('poll-js-loading') . '</div>';
$output .= "<div id=\"poll-display_{$poll_info['id']}\" style=\"display:none;\">";
$output .= "<form name=\"poll_{$poll_info['id']}\"><input type=\"hidden\" id=\"poll_id_{$poll_info['id']}\" name=\"poll_id_{$poll_info['id']}\" value=\"{$poll_info['id']}\"/>";
foreach ($poll_info['choices'] as $choice) {
$output .= "<div class=\"poll-choice\">\n\t\t\t\t\t\t<input type=\"radio\" name=\"poll_choice\" onclick=\"PollNY.pollEmbedVote({$poll_info['id']}, {$poll_page_id})\" id=\"poll_choice\" value=\"{$choice['id']}\">{$choice['choice']}\n\t\t\t\t\t\t</div>";
}
$output .= '</div>
</form>';
} else {
// Display message if poll has been closed for voting
if ($poll_info['status'] == 0) {
$output .= '<div class="poll-closed">' . wfMsg('poll-closed') . '</div>';
}
$x = 1;
foreach ($poll_info['choices'] as $choice) {
//$percent = round( $choice['votes'] / $poll_info['votes'] * 100 );
if ($poll_info['votes'] > 0) {
$bar_width = floor(480 * ($choice['votes'] / $poll_info['votes']));
}
$bar_img = "<img src=\"{$wgScriptPath}/extensions/PollNY/images/vote-bar-{$x}.gif\" border=\"0\" class=\"image-choice-{$x}\" style=\"width:{$choice['percent']}%;height:12px;\" alt=\"\" />";
$output .= "<div class=\"poll-choice\">\n\t\t\t\t\t\t<div class=\"poll-choice-left\">{$choice['choice']} ({$choice['percent']}%)</div>";
// If the amount of votes is not set, set it to 0
// This fixes an odd bug where "votes" would be shown
// instead of "0 votes" when using the pollembed tag.
if (empty($choice['votes'])) {
$choice['votes'] = 0;
}
$output .= "<div class=\"poll-choice-right\">{$bar_img} <span class=\"poll-choice-votes\">" . wfMsgExt('poll-votes', 'parsemag', $choice['votes']) . '</span></div>';
$output .= '</div>';
$x++;
}
$output .= '<div class="poll-total-votes">(' . wfMsgExt('poll-based-on-votes', 'parsemag', $poll_info['votes']) . ')</div>';
$output .= '<div><a href="' . $poll_title->escapeFullURL() . '">' . wfMsg('poll-discuss') . '</a></div>';
$output .= '<div class="poll-timestamp">' . wfMsg('poll-createdago', Poll::getTimeAgo($poll_info['timestamp'])) . '</div>';
}
return $output;
} else {
// Poll doesn't exist or is unavailable for some other reason
$output = '<div class="poll-embed-title">' . wfMsg('poll-unavailable') . '</div>';
return $output;
}
}
return '';
}