Example #1
0
	/**
	 * Populates the question with data and builds question->view
	 */
	function parseQuestionBody( qp_StubQuestion $question ) {
		try {
			if ( $question->getState() == 'error' ) {
				throw new Exception( 'qp_error' );
			}
			# populate $question with raw source values
			$question->getQuestionAnswer( $this->pollStore );
			# check whether the global showresults level prohibits to show statistical data
			# to the users who hasn't voted
			if ( qp_Setup::$global_showresults <= 1 && !$question->alreadyVoted ) {
				# suppress statistical results when the current user hasn't voted the question
				$question->view->showResults = array( 'type' => 0 );
			}
			# parse the question body
			# will populate $question->view which can be modified accodring to quiz results
			# warning! parameters are passed only by value, not the reference
			$question->parseBody();
			$question->isEmpty();
			if ( $question->getState() == 'error' ) {
				throw new Exception( 'qp_error' );
			}
			if ( $this->mBeingCorrected ) {
				if ( $question->getState() == '' ) {
					# question is OK, store it into pollStore
					$this->pollStore->setQuestion( $question );
				} else {
					# http post: not every proposals were answered: do not update DB
					$this->pollStore->stateIncomplete();
				}
			} else {
				# this is the get, not the post: do not update DB
				if ( $question->getState() == '' ) {
					$this->pollStore->stateIncomplete();
				} else {
					# http get: invalid question syntax, parse errors will cause submit button disabled
					$this->pollStore->stateError();
				}
			}
		} catch ( Exception $e ) {
			if ( $e->getMessage() === 'qp_error' ) {
				# error occured during the previously performed header parsing, do not process further
				# http get: invalid question syntax, parse errors will cause submit button disabled
				$this->pollStore->stateError();
				return;
			} else {
				throw new MWException( $e->getMessage() );
			}
		}
	}
	/**
	 * Applies previousely parsed attributes from main header into question's view
	 * (all attributes but type)
	 * @param  $paramkeys array
	 *   key is attribute name regexp match, value is the value of attribute
	 */ 
	function applyAttributes( array $paramkeys ) {
		parent::applyAttributes( $paramkeys );
		# commented out, because now the "catreq" attribute can be set per proposal row, thus
		# it is unpractical to disable radiobuttons for all proposals of the question.
		# todo: disable radiobuttons per proposal, when current catreq=0 ?
		/*
		if ( $this->mCatReq === 'all' ) {
			# radio button prevents from filling all categories, disable it
			if ( ( $radio_brace = array_search( 'radio', $this->input_braces_types, true ) ) !== false ) {
				unset( $this->input_braces_types[$radio_brace] );
				unset( $this->matching_braces[$radio_brace] );
			}
		}
		*/
		$braces_list = array_map( 'preg_quote',
			array_merge(
				( array_values( $this->matching_braces ) ),
				array_keys( $this->matching_braces ),
				array( '|' )
			)
		);
		$this->propCatPattern = '/(' . implode( '|', $braces_list ) . ')/u';
	}