<commit_before><?php

require_once 'Store/dataobjects/StoreAccount.php';
require_once 'CME/dataobjects/CMECredit.php';
require_once 'CME/dataobjects/CMEEvaluation.php';
require_once 'CME/dataobjects/CMEFrontMatter.php';
require_once 'CME/dataobjects/CMEQuiz.php';
require_once 'CME/dataobjects/CMEQuizResponse.php';

/**
 * CME specific Account object
 *
 * @package   CME
 * @copyright 2011-2014 silverorange
 * @license   http://www.opensource.org/licenses/mit-license.html MIT License
 */
abstract class CMEAccount extends StoreAccount
{
	// {{{ abstract public function hasCMEAccess()

	abstract public function hasCMEAccess();

	// }}}
	// {{{ public function hasCMEAttested()

	public function hasAttested(CMEFrontMatter $front_matter)
	{
		$this->checkDB();

		$sql = sprintf(
			'select count(1) from AccountAttestedCMEFrontMatter
			where account = %s and front_matter = %s',
			$this->db->quote($this->id, 'integer'),
			$this->db->quote($front_matter->id, 'integer')
		);

		return (SwatDB::queryOne($this->db, $sql) > 0);
	}

	// }}}
	// {{{ public function isEvaluationComplete()

	public function isEvaluationComplete(CMEFrontMatter $front_matter)
	{
		$complete = false;

		$evaluation = $front_matter->evaluation;
		if ($evaluation instanceof CMEEvaluation) {
			$evaluation_response = $evaluation->getResponseByAccount($this);
			$complete = ($evaluation_response instanceof InquisitionResponse &&
				$evaluation_response->complete_date instanceof SwatDate);
		}

		return $complete;
	}

	// }}}
	// {{{ public function isQuizComplete()

	public function isQuizComplete(CMECredit $credit)
	{
		$complete = false;

		if ($credit->quiz instanceof CMEQuiz) {
			$quiz_response = $credit->quiz->getResponseByAccount($this);
			$complete = ($quiz_response instanceof CMEQuizResponse &&
				$quiz_response->complete_date instanceof SwatDate);
		}

		return $complete;
	}

	// }}}
	// {{{ public function isQuizPassed()

	public function isQuizPassed(CMECredit $credit)
	{
		$passed = false;

		if ($this->isQuizComplete($credit)) {
			$quiz_response = $credit->quiz->getResponseByAccount($this);
			$passed = $quiz_response->isPassed();
		}

		return $passed;
	}

	// }}}
	// {{{ public function getEarnedCMECreditHours()

	public function getEarnedCMECreditHours()
	{
		$hours = 0;

		foreach ($this->earned_cme_credits as $earned_credit) {
			$hours += $earned_credit->credit->hours;
		}

		return $hours;
	}

	// }}}<commit_msg>Add CMEAccount::isCreditEarned() method.<commit_after><?php

require_once 'Store/dataobjects/StoreAccount.php';
require_once 'CME/dataobjects/CMECredit.php';
require_once 'CME/dataobjects/CMEEvaluation.php';
require_once 'CME/dataobjects/CMEFrontMatter.php';
require_once 'CME/dataobjects/CMEQuiz.php';
require_once 'CME/dataobjects/CMEQuizResponse.php';

/**
 * CME specific Account object
 *
 * @package   CME
 * @copyright 2011-2014 silverorange
 * @license   http://www.opensource.org/licenses/mit-license.html MIT License
 */
abstract class CMEAccount extends StoreAccount
{
	// {{{ abstract public function hasCMEAccess()

	abstract public function hasCMEAccess();

	// }}}
	// {{{ public function hasCMEAttested()

	public function hasAttested(CMEFrontMatter $front_matter)
	{
		$this->checkDB();

		$sql = sprintf(
			'select count(1) from AccountAttestedCMEFrontMatter
			where account = %s and front_matter = %s',
			$this->db->quote($this->id, 'integer'),
			$this->db->quote($front_matter->id, 'integer')
		);

		return (SwatDB::queryOne($this->db, $sql) > 0);
	}

	// }}}
	// {{{ public function isEvaluationComplete()

	public function isEvaluationComplete(CMEFrontMatter $front_matter)
	{
		$complete = false;

		$evaluation = $front_matter->evaluation;
		if ($evaluation instanceof CMEEvaluation) {
			$evaluation_response = $evaluation->getResponseByAccount($this);
			$complete = ($evaluation_response instanceof InquisitionResponse &&
				$evaluation_response->complete_date instanceof SwatDate);
		}

		return $complete;
	}

	// }}}
	// {{{ public function isQuizComplete()

	public function isQuizComplete(CMECredit $credit)
	{
		$complete = false;

		if ($credit->quiz instanceof CMEQuiz) {
			$quiz_response = $credit->quiz->getResponseByAccount($this);
			$complete = ($quiz_response instanceof CMEQuizResponse &&
				$quiz_response->complete_date instanceof SwatDate);
		}

		return $complete;
	}

	// }}}
	// {{{ public function isQuizPassed()

	public function isQuizPassed(CMECredit $credit)
	{
		$passed = false;

		if ($this->isQuizComplete($credit)) {
			$quiz_response = $credit->quiz->getResponseByAccount($this);
			$passed = $quiz_response->isPassed();
		}

		return $passed;
	}

	// }}}
	// {{{ public function isCreditEarned()

	public function isCreditEarned(CMECredit $credit)
	{
		$earned = false;

		foreach ($this->earned_cme_credits as $earned_credit) {
			if ($earned_credit->id === $credit->id) {
				$earned = true;
				break;
			}
		}

		return $earned;
	}

	// }}}
	// {{{ public function getEarnedCMECreditHours()

	public function getEarnedCMECreditHours()
	{
		$hours = 0;

		foreach ($this->earned_cme_credits as $earned_credit) {
			$hours += $earned_credit->credit->hours;
		}

		return $hours;
	}

	// }}}
{'fraction_non_alphanumeric': 0.14453200076878725, 'fraction_numerical': 0.004228329809725159, 'mean_word_length': 4.466386554621849, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 52, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3077476', 'n_tokens_mistral': 1994, 'n_tokens_neox': 1747, 'n_words': 323}