EssaysReportsGenerator::getEssayScore( $activity )

Return the essay score if available

Description

Source

File: bp-integrations/learndash/buddypress/generators/EssaysReportsGenerator.php

	protected function getEssayScore($activity)
	{
		if (! $activity->activity_completed) {
			return '-';
		}

		$essayId    = $activity->essay_id;
		$essay      = get_post($essayId);
		$quizId     = get_post_meta($essayId, 'quiz_id', true);
		$questionId = get_post_meta($essayId, 'question_id', true);

		$questionMapper = new WpProQuiz_Model_QuestionMapper();
		$question       = $questionMapper->fetchById(intval($questionId), null);

		if ( ! $question instanceof WpProQuiz_Model_Question ) {
			return '-';
		}

		$maxPoints = $question->getPoints();
		$essayData = learndash_get_submitted_essay_data($quizId, $questionId, $essay);
		$currentPoints = $essayData['points_awarded']? intval($essayData['points_awarded']) : 0;

		return sprintf(
			_x(
				'%1$s / %2$s',
				'placeholders: current points / maximum point',
				'buddyboss'
			), $currentPoints, $maxPoints
		);
	}

Changelog

Changelog
Version Description
BuddyBoss 1.0.0 Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.