コード例 #1
0
	function getQuestionAnswer( qp_PollStore $pollStore ) {
		if ( $pollStore->pid !== null ) {
			if ( $pollStore->questionExists( $this->mQuestionId ) ) {
				$qdata = $pollStore->Questions[ $this->mQuestionId ];
				$this->loadAnswer( $qdata );
				return true;
			}
		}
		return false;
	}
コード例 #2
0
 function qpuserchoice(Parser &$parser, PPFrame $frame, array $args)
 {
     $this->frame = $frame;
     $this->args =& $args;
     if (isset($args[0])) {
         # args[0] is a poll address
         $this->pollAddr = trim($this->frame->expand($this->args[0]));
         $this->pollStore = qp_PollStore::newFromAddr($this->pollAddr);
         if ($this->pollStore instanceof qp_PollStore && $this->pollStore->pid !== null) {
             $this->error_message = 'missing_question_id';
             if (isset($args[1])) {
                 # args[1] is question_id
                 $qdata = $this->getQuestionData(trim($frame->expand($args[1])));
                 if ($qdata instanceof qp_QuestionData) {
                     $this->error_message = 'missing_proposal_id';
                     if (isset($args[2])) {
                         # get poll's proposal choice
                         $this->proposal_id = trim($frame->expand($args[2]));
                         $this->error_message = 'invalid_proposal_id';
                         if (preg_match(qp_Setup::PREG_NON_NEGATIVE_INT4_MATCH, $this->proposal_id)) {
                             $this->defaultProposalText = isset($args[3]) ? trim($frame->expand($args[3])) : '';
                             $this->proposal_id = intval($this->proposal_id);
                             $this->error_message = 'missing_proposal_id';
                             if (array_key_exists($this->proposal_id, $qdata->ProposalText)) {
                                 return $this->qpuserchoiceValidResult($qdata);
                             }
                         }
                     }
                 }
             }
         }
     }
     return '<strong class="error">qpuserchoice: ' . wfMsgHTML('qp_func_' . $this->error_message, qp_Setup::specialchars($this->pollAddr), qp_Setup::specialchars($this->question_id), qp_Setup::specialchars($this->proposal_id)) . '</strong>';
 }
コード例 #3
0
	/**
	 * Prepares qp_PollStore object
	 * @return  boolean  true on success ($this->pollStore has been created successfully)
	 *          string  error message on failure
	 */
	function getPollStore() {
		$this->pollStore = qp_PollStore::newFromAddr( $this->pollAddr );
		if ( !( $this->pollStore instanceof qp_PollStore ) || $this->pollStore->pid === null ) {
			return self::fatalErrorQuote( 'qp_error_no_such_poll', $this->pollAddr );
		}
		if ( !$this->pollStore->loadQuestions() ) {
			$this->mState = "error";
			return self::fatalErrorQuote( 'qp_error_no_stats', $this->pollAddr );
		}
		$this->pollStore->setLastUser( $this->username );
		# do not check the result, because we may show results even if the user hasn't voted
		$this->pollStore->loadUserAlreadyVoted();
		return true;
	}
コード例 #4
0
ファイル: qp_user.php プロジェクト: schwarer2006/wikia
/**
 * Returns either scalar or associative array with structured interpretation
 * of the specified poll for the current user
 *
 * @return  scalar/array when success; null when there is no structured interpretation
 */
function qp_getStructuredInterpretation($poll_address)
{
    $pollStore = qp_PollStore::newFromAddr($poll_address);
    if (!$pollStore instanceof qp_PollStore || $pollStore->pid === null) {
        return null;
    }
    $username = qp_Setup::getCurrUserName();
    $pollStore->loadQuestions();
    $pollStore->setLastUser($username);
    if ($pollStore->interpResult->structured === '') {
        return null;
    }
    return unserialize($pollStore->interpResult->structured);
}
コード例 #5
0
	private function checkDependance( $dependsOn, $nonVotedDepLink = false ) {
		# check the headers for dependance to other polls
		if ( $dependsOn === '' ) {
			return true;
		}
		$depPollStore = qp_PollStore::newFromAddr( $dependsOn );
		if ( $depPollStore instanceof qp_PollStore ) {
			# process recursive dependance
			$depTitle = $depPollStore->getTitle();
			$depPollId = $depPollStore->mPollId;
			$depLink = $this->view->link( $depTitle, $depTitle->getPrefixedText() . ' (' . $depPollStore->mPollId . ')' );
			if ( $depPollStore->pid === null ) {
				return self::fatalErrorNoQuote( 'qp_error_missed_dependance_poll', qp_Setup::specialchars( $this->mPollId ), $depLink, qp_Setup::specialchars( $depPollId ) );
			}
			if ( !$depPollStore->loadQuestions() ) {
				return self::fatalErrorNoQuote( 'qp_error_vote_dependance_poll', $depLink );
			}
			$depPollStore->setLastUser( $this->username );
			if ( $depPollStore->loadUserAlreadyVoted() ) {
				# user already voted in current the poll in chain
				if ( $depPollStore->dependsOn === '' ) {
					if ( $nonVotedDepLink === false ) {
						# there was no non-voted deplinks in the chain at some previous level of recursion
						return true;
					} else {
						# there is an non-voted deplink in the chain at some previous level of recursion
						return self::fatalErrorNoQuote( 'qp_error_vote_dependance_poll', $nonVotedDepLink );
					}
				} else {
					return $this->checkDependance( $depPollStore->dependsOn, $nonVotedDepLink );
				}
			} else {
				# user hasn't voted in current the poll in chain
				if ( $depPollStore->dependsOn === '' ) {
					# current element of chain is not voted and furthermore, doesn't depend on any other polls
					return self::fatalErrorNoQuote( 'qp_error_vote_dependance_poll', $depLink );
				} else {
					# current element of chain is not voted, BUT it has it's own dependance
					# so we will check for the most deeply nested poll which hasn't voted, yet
					return $this->checkDependance( $depPollStore->dependsOn, $depLink );
				}
			}
		} else {
			# process poll address errors
			switch ( $depPollStore ) {
			case qp_Setup::ERROR_INVALID_ADDRESS :
				return self::fatalErrorQuote( 'qp_error_invalid_dependance_value', $this->mPollId, $dependsOn );
			case qp_Setup::ERROR_MISSED_TITLE :
				$depSplit = self::getPrefixedPollAddress( $dependsOn );
				if ( is_array( $depSplit ) ) {
					list( $depTitleStr, $depPollId ) = $depSplit;
					$depTitle = Title::newFromURL( $depTitleStr );
					$depTitleStr = $depTitle->getPrefixedText();
					$depLink = $this->view->link( $depTitle, $depTitleStr );
					return self::fatalErrorNoQuote( 'qp_error_missed_dependance_title', qp_Setup::specialchars( $this->mPollId ), $depLink, qp_Setup::specialchars( $depPollId ) );
				} else {
					return self::fatalErrorQuote( 'qp_error_invalid_dependance_value', $this->mPollId, $dependsOn );
				}
			default :
				throw new MWException( __METHOD__ . ' invalid dependance poll store found' );
			}
		}
	}
コード例 #6
0
	function getPageHeader() {
		global $wgLang, $wgContLang;
		$link = "";
		if ( $this->pid !== null ) {
			$pollStore = new qp_PollStore( array( 'from' => 'pid', 'pid' => $this->pid ) );
			if ( $pollStore->pid !== null ) {
				$pollStore->loadQuestions();
				$poll_title = Title::makeTitle( intval( $this->ns ), $this->title, qp_AbstractPoll::s_getPollTitleFragment( $this->poll_id, '' ) );
				$pagename = qp_Setup::specialchars( $wgContLang->convert( $poll_title->getPrefixedText() ) );
				$pollname = qp_Setup::specialchars( $this->poll_id );
				$head = array();
				$head[] = $this->showPollActionsList(
					$pollStore->pid,
					$pollStore->mPollId,
					$poll_title
				);
				$head[] = wfMsg( 'qp_header_line_qpul', wfMsg( 'qp_users_link' ), $pagename, $pollname );
				$ques_found = false;
				foreach ( $pollStore->Questions as $qdata ) {
					if ( $qdata->question_id == $this->question_id ) {
						$ques_found = true;
						break;
					}
				}
				if ( $ques_found ) {
					$qpa = wfMsg( 'qp_header_line_qucl', $this->question_id, qp_Setup::entities( $qdata->CommonQuestion ) );
					if ( array_key_exists( $this->cat_id, $qdata->Categories ) ) {
						$categ = &$qdata->Categories[ $this->cat_id ];
						$proptext = $qdata->ProposalText[ $this->proposal_id ];
						$cat_name = $categ['name'];
						if ( array_key_exists( 'spanId', $categ ) ) {
							$cat_name =  wfMsg( 'qp_full_category_name', $cat_name, $qdata->CategorySpans[ $categ['spanId'] ]['name'] );
						}
						$head[] = wfMsg( 'qp_header_line_qucl',
							$this->question_id,
							qp_Setup::entities( $qdata->CommonQuestion ),
							qp_Setup::entities( $proptext ),
							qp_Setup::entities( $cat_name ) );
						qp_Renderer::applyAttrsToRow( $head, array( '__tag' => 'li', '__end' => "\n" ) );
						$head = array( '__tag' => 'ul', 'class' => 'head', $head );
						$link = PollResults::getPollsLink() .
							PollResults::getUsersLink() .
							qp_Renderer::renderTagArray( $head );
					}
				}
			}
		}
		return $link;
	}
コード例 #7
0
	function interpretationToXLS( qp_PollStore $pollStore ) {
		$offset = 0;
		# iterate through the voters of the current poll (there might be many)
		while ( ( $limit = count( $voters = $pollStore->pollVotersPager( $offset ) ) ) > 0 ) {
			foreach ( $voters as &$voter ) {
				if ( $voter['interpretation']->short != '' ) {
					$this->writeLn( 0, wfMsg( 'qp_results_short_interpretation' ), 'heading' );
					$this->writeLn( 0, $voter['interpretation']->short );
				}
				if ( $voter['interpretation']->structured != '' ) {
					$this->writeLn( 0, wfMsg( 'qp_results_structured_interpretation' ), 'heading' );
					$strucTable = $voter['interpretation']->getStructuredAnswerTable();
					foreach ( $strucTable as &$line ) {
						if ( isset( $line['keys'] ) ) {
							# current node is associative array
							$this->writeRowLn( 0, $line['keys'], 'odd' );
							$this->writeRowLn( 0, $line['vals'] );
						} else {
							$this->writeLn( 0, $line['vals'] );
						}
					}
					$this->nextRow();
				}
			}
			$offset += $limit;
		}
	}
コード例 #8
0
	/**
	 * Calculates Percents[] properties for specified question from
	 * it's Votes[] properties.
	 * @param  $store
	 *   instance of qp_PollStore associated with $this qdata
	 */
	function calculateQuestionStatistics( qp_PollStore $store ) {
		if ( !isset( $this->Votes ) ) {
			return;
		}
		# $this has votes
		$this->restoreSpans();
		$spansUsed = count( $this->CategorySpans ) > 0 ;
		foreach ( $this->ProposalText as $propkey => $proposal_text ) {
			if ( isset( $this->Votes[ $propkey ] ) ) {
				$votes_row = &$this->Votes[ $propkey ];
				if ( $this->type == "singleChoice" ) {
					if ( $spansUsed ) {
						$row_totals = array_fill( 0, count( $this->CategorySpans ), 0 );
					} else {
						$votes_total = 0;
					}
					foreach ( $this->Categories as $catkey => $cat ) {
						if ( isset( $votes_row[ $catkey ] ) ) {
							if ( $spansUsed ) {
								$row_totals[ intval( $cat[ "spanId" ] ) ] += $votes_row[ $catkey ];
							} else {
								$votes_total += $votes_row[ $catkey ];
							}
						}
					}
				} else {
					$votes_total = $store->totalUsersAnsweredQuestion( $this );
				}
				foreach ( $this->Categories as $catkey => $cat ) {
					$num_of_votes = '';
					if ( isset( $votes_row[ $catkey ] ) ) {
						$num_of_votes = $votes_row[ $catkey ];
						if ( $spansUsed ) {
							if ( isset( $this->Categories[ $catkey ][ "spanId" ] ) ) {
								$votes_total = $row_totals[ intval( $this->Categories[ $catkey ][ "spanId" ] ) ];
							}
						}
					}
					$this->Percents[ $propkey ][ $catkey ] = ( $votes_total > 0 ) ? (float) $num_of_votes / (float) $votes_total : 0.0;
				}
			}
		}
	}