function statsToXls( qp_PollStore $pollStore ) { $pollStore->loadQuestions(); $pollStore->loadTotals(); $pollStore->calculateStatistics(); $first_question = true; foreach ( $pollStore->Questions as $qkey => $qdata ) { $xlsq = ( $qdata->type === 'textQuestion' ) ? $this->text_writer : $this->tabular_writer; $xlsq->setQuestionData( $qdata ); if ( $first_question ) { $this->writeHeader( $pollStore->totalUsersAnsweredQuestion( $qdata ) ); $first_question = false; } $xlsq->writeHeader(); $percentsTable = array(); $spansUsed = count( $qdata->CategorySpans ) > 0 || $qdata->type == "multipleChoice"; $xlsq->writeQuestionStats(); } }
/** * 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; } } } }