<commit_before><?php
/**
 * @package plugins.quiz
 * @subpackage model
 */

class AnswerCuePoint extends CuePoint implements IMetadataObject
{
	const CUSTOM_DATA_QUIZ_USER_ENTRY_ID= 'quizUserEntryId';
	const CUSTOM_DATA_ANSWER_KEY = 'answerKey';
	const CUSTOM_DATA_IS_CORRECT = 'isCorrect';
	const CUSTOM_DATA_CORRECT_ANSWER_KEYS = 'correctAnswerKeys';
	const CUSTOM_DATA_EXPLANATION= 'explanation';

	public function __construct()
	{
		parent::__construct();
		$this->applyDefaultValues();
	}

	/**
	 * Applies default values to this object.
	 * This method should be called from the object's constructor (or equivalent initialization method).
	 * @see __construct()
	 */
	public function applyDefaultValues()
	{
		$this->setType(QuizPlugin::getCuePointTypeCoreValue(QuizCuePointType::QUIZ_ANSWER));
	}

	public function setQuizUserEntryId($v) {return $this->putInCustomData(self::CUSTOM_DATA_QUIZ_USER_ENTRY_ID, $v);}

	public function getQuizUserEntryId() {return $this->getFromCustomData(self::CUSTOM_DATA_QUIZ_USER_ENTRY_ID);}

	public function setAnswerKey($v) {return $this->putInCustomData(self::CUSTOM_DATA_ANSWER_KEY, $v);}

	public function getAnswerKey() {return $this->getFromCustomData(self::CUSTOM_DATA_ANSWER_KEY);}

	public function setIsCorrect($v) {return $this->putInCustomData(self::CUSTOM_DATA_IS_CORRECT, $v);}

	public function getIsCorrect() {return $this->getFromCustomData(self::CUSTOM_DATA_IS_CORRECT);}

	public function setCorrectAnswerKeys($v) {return $this->putInCustomData(self::CUSTOM_DATA_CORRECT_ANSWER_KEYS, $v);}

	public function getCorrectAnswerKeys() {return $this->getFromCustomData(self::CUSTOM_DATA_CORRECT_ANSWER_KEYS);}

	public function setExplanation($v) {return $this->putInCustomData(self::CUSTOM_DATA_EXPLANATION, $v);}

	public function getExplanation() {return $this->getFromCustomData(self::CUSTOM_DATA_EXPLANATION);}

	public function copyToClipEntry( entry $clipEntry, $clipStartTime, $clipDuration )
	{
		return false;
	}
	
    public function setKuserId($v) {
		$userEntry = UserEntryPeer::retrieveByPK($this->getQuizUserEntryId());
		parent::setKuserId($userEntry->getKuserId());
	}


	/** (non-PHPdoc)
    * @see BaseCuePoint::preInsert()
    */
	public function preInsert(PropelPDO $con = null)
	{
		$dbParentCuePoint = CuePointPeer::retrieveByPK($this->getParentId());
		$optionalAnswers =  $dbParentCuePoint->getOptionalAnswers();
		$correctKeys = array();
		foreach ($optionalAnswers as $answer)
		{
			if ( $answer->getIsCorrect() )
				$correctKeys[] = $answer->getKey();
		}
		$this->setCorrectAnswerKeys( $correctKeys );
		$this->setExplanation( $dbParentCuePoint->getExplanation() );
		$this->setIsCorrect( in_array( $this->getAnswerKey(), $correctKeys ) );
		$this->setCustomDataObj();
		return parent::preInsert($con);
	}

	/**
	 * Code to be run before updating the object in database
	 * @param PropelPDO $con
	 * @return bloolean
	 */
	public function preUpdate(PropelPDO $con = null)
	{
		if ($this->isCustomDataModified(AnswerCuePoint::CUSTOM_DATA_ANSWER_KEY))
		{
			$this->setIsCorrect(in_array($this->getAnswerKey(), $this->getCorrectAnswerKeys()));
			$this->setCustomDataObj();
		}
		return parent::preSave($con);
	}

	public function getMetadataObjectType()
	{
		return QuizPlugin::getCoreValue('MetadataObjectType', QuizCuePointMetadataObjectType::ANSWER_CUE_POINT);
	}

	/* (non-PHPdoc)
	 * @see BaseCuePoint::postInsert()
	 */
	public function postInsert(PropelPDO $con = null)
	{
		parent::postInsert($con);
		$userEntry = UserEntryPeer::retrieveByPK($this->getQuizUserEntryId());
		if (!is_null($userEntry))
		{
			$userEntry->addAnswerId($this->parent_id, $this->id);
			$userEntry->save();
		}
	}

	public function shouldReIndexEntry(array $modifiedColumns = array())
	{
		return false;
	}


}<commit_msg>Added additional verification before setting the kUserId<commit_after><?php
/**
 * @package plugins.quiz
 * @subpackage model
 */

class AnswerCuePoint extends CuePoint implements IMetadataObject
{
	const CUSTOM_DATA_QUIZ_USER_ENTRY_ID= 'quizUserEntryId';
	const CUSTOM_DATA_ANSWER_KEY = 'answerKey';
	const CUSTOM_DATA_IS_CORRECT = 'isCorrect';
	const CUSTOM_DATA_CORRECT_ANSWER_KEYS = 'correctAnswerKeys';
	const CUSTOM_DATA_EXPLANATION= 'explanation';

	public function __construct()
	{
		parent::__construct();
		$this->applyDefaultValues();
	}

	/**
	 * Applies default values to this object.
	 * This method should be called from the object's constructor (or equivalent initialization method).
	 * @see __construct()
	 */
	public function applyDefaultValues()
	{
		$this->setType(QuizPlugin::getCuePointTypeCoreValue(QuizCuePointType::QUIZ_ANSWER));
	}

	public function setQuizUserEntryId($v) {return $this->putInCustomData(self::CUSTOM_DATA_QUIZ_USER_ENTRY_ID, $v);}

	public function getQuizUserEntryId() {return $this->getFromCustomData(self::CUSTOM_DATA_QUIZ_USER_ENTRY_ID);}

	public function setAnswerKey($v) {return $this->putInCustomData(self::CUSTOM_DATA_ANSWER_KEY, $v);}

	public function getAnswerKey() {return $this->getFromCustomData(self::CUSTOM_DATA_ANSWER_KEY);}

	public function setIsCorrect($v) {return $this->putInCustomData(self::CUSTOM_DATA_IS_CORRECT, $v);}

	public function getIsCorrect() {return $this->getFromCustomData(self::CUSTOM_DATA_IS_CORRECT);}

	public function setCorrectAnswerKeys($v) {return $this->putInCustomData(self::CUSTOM_DATA_CORRECT_ANSWER_KEYS, $v);}

	public function getCorrectAnswerKeys() {return $this->getFromCustomData(self::CUSTOM_DATA_CORRECT_ANSWER_KEYS);}

	public function setExplanation($v) {return $this->putInCustomData(self::CUSTOM_DATA_EXPLANATION, $v);}

	public function getExplanation() {return $this->getFromCustomData(self::CUSTOM_DATA_EXPLANATION);}

	public function copyToClipEntry( entry $clipEntry, $clipStartTime, $clipDuration )
	{
		return false;
	}
	
    public function setKuserId($v) {
		$userEntry = UserEntryPeer::retrieveByPK($this->getQuizUserEntryId());
		if ($userEntry) {
			if (($userEntry->getKuserId() === kCurrentContext::getCurrentKsKuserId()) || (kCurrentContext::$is_admin_session))
				return parent::setKuserId($userEntry->getKuserId());
			else
				throw new KalturaAPIException(KalturaErrors::INVALID_USER_ID);
		}
		return parent::setKuserId($v);
	}


	/** (non-PHPdoc)
    * @see BaseCuePoint::preInsert()
    */
	public function preInsert(PropelPDO $con = null)
	{
		$dbParentCuePoint = CuePointPeer::retrieveByPK($this->getParentId());
		$optionalAnswers =  $dbParentCuePoint->getOptionalAnswers();
		$correctKeys = array();
		foreach ($optionalAnswers as $answer)
		{
			if ( $answer->getIsCorrect() )
				$correctKeys[] = $answer->getKey();
		}
		$this->setCorrectAnswerKeys( $correctKeys );
		$this->setExplanation( $dbParentCuePoint->getExplanation() );
		$this->setIsCorrect( in_array( $this->getAnswerKey(), $correctKeys ) );
		$this->setCustomDataObj();
		return parent::preInsert($con);
	}

	/**
	 * Code to be run before updating the object in database
	 * @param PropelPDO $con
	 * @return bloolean
	 */
	public function preUpdate(PropelPDO $con = null)
	{
		if ($this->isCustomDataModified(AnswerCuePoint::CUSTOM_DATA_ANSWER_KEY))
		{
			$this->setIsCorrect(in_array($this->getAnswerKey(), $this->getCorrectAnswerKeys()));
			$this->setCustomDataObj();
		}
		return parent::preSave($con);
	}

	public function getMetadataObjectType()
	{
		return QuizPlugin::getCoreValue('MetadataObjectType', QuizCuePointMetadataObjectType::ANSWER_CUE_POINT);
	}

	/* (non-PHPdoc)
	 * @see BaseCuePoint::postInsert()
	 */
	public function postInsert(PropelPDO $con = null)
	{
		parent::postInsert($con);
		$userEntry = UserEntryPeer::retrieveByPK($this->getQuizUserEntryId());
		if (!is_null($userEntry))
		{
			$userEntry->addAnswerId($this->parent_id, $this->id);
			$userEntry->save();
		}
	}

	public function shouldReIndexEntry(array $modifiedColumns = array())
	{
		return false;
	}


}
{'fraction_non_alphanumeric': 0.13548795944233208, 'fraction_numerical': 0.0, 'mean_word_length': 6.451369216241737, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 72, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '5521779', 'n_tokens_mistral': 2894, 'n_tokens_neox': 2673, 'n_words': 449}