/** * Parse question main header (common question and XML attributes) * initializes common question and question type/subtype * @param $header string * the question's header in QPoll syntax * @return instance of question that matches the header attributes */ function parseMainHeader( $header ) { # split common question and question attributes from the header $parts = explode( '|', $header ); # last pipe character separates attributes from common question $attr_str = array_pop( $parts ); # this enables to use tables and templates in common question $common_question = implode( '|', $parts ); $error_msg = ''; # assume that question name does not exists (by default) $name = null; if ( isset( $attr_str ) ) { $paramkeys = array(); $type = $this->getQuestionAttributes( $attr_str, $paramkeys ); if ( !array_key_exists( $type, qp_Setup::$questionTypes ) ) { $error_msg = wfMsg( 'qp_error_invalid_question_type', qp_Setup::entities( $type ) ); } if ( $paramkeys['name'] !== null && ( $name = trim( $paramkeys['name'] ) ) === '' || is_numeric( $name ) || strlen( $name ) > qp_Setup::$field_max_len['question_name'] ) { # empty name is not allowed; # numeric name is not allowed; # name longer than maximal DB field length is not allowed; $error_msg = wfMsg( 'qp_error_invalid_question_name', qp_Setup::entities( $name ) ); $name = null; } } else { $error_msg = wfMsg( 'qp_error_in_question_header', qp_Setup::entities( $header ) ); } if ( $error_msg !== '' ) { $question = new qp_StubQuestion( $this, qp_StubQuestionView::newFromBaseView( $this->view ), ++$this->mQuestionId, $name ); $question->setState( 'error', $error_msg ); return $question; } $qt = qp_Setup::$questionTypes[$type]; $question = new $qt['ctrl']( $this, call_user_func( array( $qt['view'], 'newFromBaseView' ), $this->view ), ++$this->mQuestionId, $name ); # set the question type and subtype corresponding to the header 'type' attribute $question->mType = $qt['mType']; if ( isset( $qt['mSubType'] ) ) { $question->mSubType = $qt['mSubType']; } $question->mCommonQuestion = trim( $common_question ); $question->applyAttributes( $paramkeys ); return $question; }
/** * @param $parser * @param $frame * @param $showResults poll's showResults (may be overriden in the question) */ function __construct( Parser $parser, PPFrame $frame, $showResults ) { parent::__construct( $parser, $frame ); $this->vr = new qp_TextQuestionViewRow( $this ); /* todo: implement showResults */ }
/** * @param $parser * @param $frame * @param $showResults poll's showResults (may be overriden in the question) */ function __construct( Parser $parser, PPFrame $frame, $showResults ) { parent::__construct( $parser, $frame ); $this->pollShowResults = $showResults; }