public/wordpress/wp-content/plugins/wp-courseware/includes/legacy/classes/unitfrontend.php
/**
		 * Fetches the details of the question results, grouped by tag for this user.
		 * Data is returned as an array with the calculations so that that it can
		 * be used in any render that's needed (HTML, PDF or email).
		 *
		 * @return Array A nested array containing a list of tags, the tag details, and a list of the scores summarising how the user did for each tag.
		 */
Fetches the details of the question results, grouped by tag for this user.
Data is returned as an array with the calculations so that that it can
be used in any render that's needed (HTML, PDF or email).

@return Array A nested array containing a list of tags, the tag details, and a list of the scores summarising how the user did for each tag.
Fetches the details of the question results grouped by tag for this user . Data is returned as an array with the calculations so that that it can be used in any render that ' s needed ( HTML PDF or email ) . @return Array A nested array containing a list of tags the tag details and a list of the scores summarising how the user did for each tag .
public function fetch_quizzes_questionResultsByTag() {
			$tagBucketList = array();
			if ( $this->cached_resultsByTag ) {
				return $this->cached_resultsByTag;
			}
			if ( empty( $this->unitQuizDetails ) || empty( $this->unitQuizDetails->questions ) || empty( $this->unitQuizProgress->quiz_data ) ) {
				$this->cached_resultsByTag = $tagBucketList;
				return $tagBucketList;
			}
			$questionsWithMissingIDs = array();
			foreach ( $this->unitQuizDetails->questions as $questionID => $questionObj ) {
				if ( ! isset( $questionObj->tags ) ) {
					$questionsWithMissingIDs[] = $questionID;
				}
			}
			if ( ! empty( $questionsWithMissingIDs ) ) {
				$tagList = WPCW_questions_tags_getTagsForQuestionList( $questionsWithMissingIDs );
				if ( ! empty( $tagList ) ) {
					foreach ( $tagList as $singleTagObj ) {
						$questionToUpdate_id  = $singleTagObj->question_id;
						$questionToUpdate_obj = $this->unitQuizDetails->questions[ $questionToUpdate_id ];
						if ( ! isset( $questionToUpdate_obj->tags ) ) {
							$questionToUpdate_obj->tags = array();
						}
						$questionToUpdate_obj->tags[] = $singleTagObj;
					}
				}
			}
			foreach ( $this->unitQuizDetails->questions as $questionID => $questionObj ) {
				if ( ! empty( $questionObj->tags ) ) {
					$userResponse = array( 'got_right' => false );
					if ( isset( $this->unitQuizProgress->quiz_data[ $questionID ] ) ) {
						$userResponse = $this->unitQuizProgress->quiz_data[ $questionID ];
					}
					$isQuestionRight = ( 'yes' == $userResponse['got_right'] );
					$isQuestionOpen = false;
					if ( 'open' == $questionObj->question_type || 'upload' == $questionObj->question_type ) {
						$isQuestionOpen = true;
					}
					foreach ( $questionObj->tags as $tagObj ) {
												if ( isset( $tagBucketList[ $tagObj->question_tag_id ] ) ) {
							$tagBucketList[ $tagObj->question_tag_id ]['question_responses'][ $questionID ] = $userResponse;
							++ $tagBucketList[ $tagObj->question_tag_id ]['question_count'];
							$tagBucketList[ $tagObj->question_tag_id ]['score_correct_questions'] += ( $isQuestionRight ? 1 : 0 );
							$tagBucketList[ $tagObj->question_tag_id ]['question_open_count'] += ( $isQuestionOpen ? 1 : 0 );
						} 
						else {
							$tagBucketList[ $tagObj->question_tag_id ] = array(
								'question_open_count'     => ( $isQuestionOpen ? 1 : 0 ),
								'question_count'          => 1,
								'score_correct_questions' => ( $isQuestionRight ? 1 : 0 ),
								'score_total'             => 0,
								'tag_details'             => $tagObj,
								'question_responses'      => array( $questionID => $userResponse ),
							);
						}
					} 
				} 
			} 
			if ( ! empty( $tagBucketList ) ) {
				foreach ( $tagBucketList as $tagID => $tagDetails ) {
					$tagBucketList[ $tagID ]['score_total'] = WPCW_quizzes_calculateGradeForQuiz( $tagDetails['question_responses'], 0 );
					unset( $tagBucketList[ $tagID ]['question_responses'] );
				}
			}
			$this->cached_resultsByTag = $tagBucketList;
			return $tagBucketList;
		}
public function fetch_quizzes_questionResultsByTag ( ) { $ tagBucketList = array ( ) ; if ( $ this -> cached_resultsByTag ) { return $ this -> cached_resultsByTag ; } if ( empty ( $ this -> unitQuizDetails ) || empty ( $ this -> unitQuizDetails -> questions ) || empty ( $ this -> unitQuizProgress -> quiz_data ) ) { $ this -> cached_resultsByTag = $ tagBucketList ; return $ tagBucketList ; } $ questionsWithMissingIDs = array ( ) ; foreach ( $ this -> unitQuizDetails -> questions as $ questionID => $ questionObj ) { if ( ! isset ( $ questionObj -> tags ) ) { $ questionsWithMissingIDs [ ] = $ questionID ; } } if ( ! empty ( $ questionsWithMissingIDs ) ) { $ tagList = WPCW_questions_tags_getTagsForQuestionList ( $ questionsWithMissingIDs ) ; if ( ! empty ( $ tagList ) ) { foreach ( $ tagList as $ singleTagObj ) { $ questionToUpdate_id = $ singleTagObj -> question_id ; $ questionToUpdate_obj = $ this -> unitQuizDetails -> questions [ $ questionToUpdate_id ] ; if ( ! isset ( $ questionToUpdate_obj -> tags ) ) { $ questionToUpdate_obj -> tags = array ( ) ; } $ questionToUpdate_obj -> tags [ ] = $ singleTagObj ; } } } foreach ( $ this -> unitQuizDetails -> questions as $ questionID => $ questionObj ) { if ( ! empty ( $ questionObj -> tags ) ) { $ userResponse = array ( 'got_right' => false ) ; if ( isset ( $ this -> unitQuizProgress -> quiz_data [ $ questionID ] ) ) { $ userResponse = $ this -> unitQuizProgress -> quiz_data [ $ questionID ] ; } $ isQuestionRight = ( 'yes' == $ userResponse [ 'got_right' ] ) ; $ isQuestionOpen = false ; if ( 'open' == $ questionObj -> question_type || 'upload' == $ questionObj -> question_type ) { $ isQuestionOpen = true ; } foreach ( $ questionObj -> tags as $ tagObj ) { if ( isset ( $ tagBucketList [ $ tagObj -> question_tag_id ] ) ) { $ tagBucketList [ $ tagObj -> question_tag_id ] [ 'question_responses' ] [ $ questionID ] = $ userResponse ; ++ $ tagBucketList [ $ tagObj -> question_tag_id ] [ 'question_count' ] ; $ tagBucketList [ $ tagObj -> question_tag_id ] [ 'score_correct_questions' ] += ( $ isQuestionRight ? 1 : 0 ) ; $ tagBucketList [ $ tagObj -> question_tag_id ] [ 'question_open_count' ] += ( $ isQuestionOpen ? 1 : 0 ) ; } else { $ tagBucketList [ $ tagObj -> question_tag_id ] = array ( 'question_open_count' => ( $ isQuestionOpen ? 1 : 0 ) , 'question_count' => 1 , 'score_correct_questions' => ( $ isQuestionRight ? 1 : 0 ) , 'score_total' => 0 , 'tag_details' => $ tagObj , 'question_responses' => array ( $ questionID => $ userResponse ) , ) ; } } } } if ( ! empty ( $ tagBucketList ) ) { foreach ( $ tagBucketList as $ tagID => $ tagDetails ) { $ tagBucketList [ $ tagID ] [ 'score_total' ] = WPCW_quizzes_calculateGradeForQuiz ( $ tagDetails [ 'question_responses' ] , 0 ) ; unset ( $ tagBucketList [ $ tagID ] [ 'question_responses' ] ) ; } } $ this -> cached_resultsByTag = $ tagBucketList ; return $ tagBucketList ; }
Fetches the details of the question results, grouped by tag for this user.
Fetches the details of the question results grouped by tag for this user .
// Use the cached version if we have it. // ### 1 - Check to make sure we have questions // ### 1A - Ensure that the questions all have tags (random questions will not have these tags, hence fetching // them here). // Tags should always exist for normal questions. So this will just be triggered for randoms. // Get all of the tags for the questions missing tags as a single query (to keep this O(N) rather than // O(N^2) with the previous method, which fetched the tags for each question per question. // Get tags for all questions that are missing tags // Need to map tags back to their questions. // Get the question that we wish to update // Ensure that we have a valid list to add to. // Now add this single tag. // ### 2 - Build a list of tags used by the questions // ### 3 - Got some tags for this question // ### 4 - Get the question from the user's responses. Can't assume it's // there, hence the initialisation above. // ###Ê5 - Work out if an open-ended question or not. // ### 5 - For each tag, add the tag details to the list, and then // add the association for this question. // Is the tag already in the bucket?
 // Append the response from the user. // Increase question count // Increase correct count (if correct) // Increase question open count // Nope, add the tag to the bucket. // Question type only needed to be determined for the first tag. // Used for score calculation if open ended questions // Is the question right? (this will be false if open ended) // Stores the total grade for use later // Stores the details of the tag // Stores the ID of the question => the score from the user. Build up a list of all // of these, hence using an array. // end of foreach // Check of question tags // end of questionforeach // ### 6 - Now we need to calculate the total for each of these tags using the questions responses we have. // Don't need responses now. // Update cache to save time later.