<commit_before><?php
/** Comments Entity
 *
 * @package    Core
 * @subpackage Entity
 * @author     lhe<<EMAIL>>
 */
class Comments extends InfoEntityAbstract
{
	/**
	 * The id of the entity
	 *
	 * @var int
	 */
	private $entityId;
	/**
	 * The name of the entity
	 *
	 * @var string
	 */
	private $entityName;
	/**
	 * Getter for EntityId
	 *
	 * @return int
	 */
	public function getEntityId()
	{
		return $this->entityId;
	}
	/**
	 * Setter for entity
	 *
	 * @param int $value The entity id
	 *
	 * @return Comments
	 */
	public function setEntityId($value)
	{
		$this->entityId = $value;
		return $this;
	}
	/**
	 * Getter for entityName
	 *
	 * @return string
	 */
	public function getEntityName()
	{
		return $this->entityName;
	}
	/**
	 * Setter for entityName
	 *
	 * @param string $value The entityName
	 *
	 * @return Comments
	 */
	public function setEntityName($value)
	{
		$this->entityName = $value;
		return $this;
	}
	/**
	 * (non-PHPdoc)
	 * @see BaseEntityAbstract::getJson()
	 */
	public function getJson($extra = array(), $reset = false)
	{
		$array = $extra;
	    if(!$this->isJsonLoaded($reset))
	    {
	    	if($this->getEntityName() === 'Question')
	    		$array['question'] = ($obj = Question::get($this->getEntityId())) instanceof Question ? $obj->getJson() : null;
	    	if($this->getEntityName() === 'Answer')
	    		$array['question'] = ($obj = Answer::get($this->getEntityId())) instanceof Answer ? $obj->getJson() : null;
	    	if($this->getEntityName() === 'Comments')
	    		$array['question'] = ($obj = Comments::get($this->getEntityId())) instanceof Comments ? $obj->getJson() : null;
	    }
	    return parent::getJson($array, $reset);
	}
	/**
	 * (non-PHPdoc)
	 * @see BaseEntity::__loadDaoMap()
	 */
	public function __loadDaoMap()
	{
		DaoMap::begin($this, 'comm');
				
		parent::__loadDaoMap();
		
		DaoMap::setIntType('entityId');
		DaoMap::setStringType('entityName','varchar', 100);
		
		DaoMap::createIndex('entityId');
		DaoMap::createIndex('entityName');

		DaoMap::commit();
	}
	/**
	 * create a Comments
	 * 
	 * @param string 				$title
	 * @param string 				$content
	 * @param BaseEntityAbstract 	$entity
	 * @param string	 			$refId
	 * @param UserAccount			$author
	 * @param string 				$authorName
	 * @param bool	 				$active
	 * 
	 * @throws Exception
	 * @return Comments
	 */
	public static function create($title, $content, BaseEntityAbstract $entity, $refId = null, $author = null, $authorName = null, $active = true)
	{
		if(($title = trim($title)) === '')
			throw new Exception('Title for a ' . __CLASS__ . ' must not be empty');
		if(($content = trim($content)) === '')
			throw new Exception('Content for a ' . __CLASS__ . ' must be null or a non-empty string');
		if(($refId = StringUtilsAbstract::nullOrString($refId)) !== null && $refId === '')
			throw new Exception('RefId for a ' . __CLASS__ . ' must not be empty');
		if($author !== null && !$author instanceof Person)
			throw new Exception('Author for a ' . __CLASS__ . ' must be null or instance of Person');
		if(($authorName = StringUtilsAbstract::nullOrString($authorName)) !== null && $authorName === '')
			throw new Exception('AuthorName for a ' . __CLASS__ . ' must not be empty');
	
		$active = (intval($active) === 1);
	
		$obj = self::getByRefId($refId, false); // deactived obj will also be found and replaced
		$obj = $obj instanceof self ? $obj : new self();
		$obj->setTitle($title)
			->setContent($content)
			->setEntityName(get_class($entity))
			->setEntityId($entity->getId())
			->setRefId($refId)
			->setAuthor($author)
			->setAuthorName($authorName)
			->setActive($active)
			->save();
		return $obj;
	}
	/**
	 * create a Comments by Question
	 * 
	 * @param string 	$title
	 * @param string 	$content
	 * @param Question 	$question
	 * @param string 	$refId
	 * @param string 	$author
	 * @param string 	$authorName
	 * @param string 	$active
	 */
	public static function createByQuestion($title, $content, Question $question, $refId = null, $author = null, $authorName = null, $active = true) 
	{
		$obj = self::create($title, $content, $question, $refId, $author, $authorName, $active);
		return $obj;
	}
	/**
	 * create a Comments by Answer
	 * 
	 * @param string 	$title
	 * @param string 	$content
	 * @param Answer 	$answer
	 * @param string 	$refId
	 * @param string 	$author
	 * @param string 	$authorName
	 * @param string 	$active
	 */
	public static function createByAnswer($title, $content, Answer $answer, $refId = null, $author = null, $authorName = null, $active = true) 
	{
		$obj = self::create($title, $content, $answer, $refId, $author, $authorName, $active);
		return $obj;
	}
	/**
	 * create a comment for this Comments
	 *
	 * @param string 		$title
	 * @param string 		$content
	 * @param string 		$refId
	 * @param UserAccount 	$author
	 * @param string 		$authorName
	 * @param bool	 		$active
	 */
	public function addComments($title, $content, $refId = null, $author = null, $authorName = null, $active = true) {
		$obj = Comments::createByQuestion($title, $content, $this, $refId, $author, $authorName, $active);
		return $obj;
	}
	/**
	 * get Comments for this Comments<commit_msg>addComments bug fix<commit_after><?php
/** Comments Entity
 *
 * @package    Core
 * @subpackage Entity
 * @author     lhe<<EMAIL>>
 */
class Comments extends InfoEntityAbstract
{
	/**
	 * The id of the entity
	 *
	 * @var int
	 */
	private $entityId;
	/**
	 * The name of the entity
	 *
	 * @var string
	 */
	private $entityName;
	/**
	 * Getter for EntityId
	 *
	 * @return int
	 */
	public function getEntityId()
	{
		return $this->entityId;
	}
	/**
	 * Setter for entity
	 *
	 * @param int $value The entity id
	 *
	 * @return Comments
	 */
	public function setEntityId($value)
	{
		$this->entityId = $value;
		return $this;
	}
	/**
	 * Getter for entityName
	 *
	 * @return string
	 */
	public function getEntityName()
	{
		return $this->entityName;
	}
	/**
	 * Setter for entityName
	 *
	 * @param string $value The entityName
	 *
	 * @return Comments
	 */
	public function setEntityName($value)
	{
		$this->entityName = $value;
		return $this;
	}
	/**
	 * (non-PHPdoc)
	 * @see BaseEntityAbstract::getJson()
	 */
	public function getJson($extra = array(), $reset = false)
	{
		$array = $extra;
	    if(!$this->isJsonLoaded($reset))
	    {
	    	if($this->getEntityName() === 'Question')
	    		$array['question'] = ($obj = Question::get($this->getEntityId())) instanceof Question ? $obj->getJson() : null;
	    	if($this->getEntityName() === 'Answer')
	    		$array['question'] = ($obj = Answer::get($this->getEntityId())) instanceof Answer ? $obj->getJson() : null;
	    	if($this->getEntityName() === 'Comments')
	    		$array['question'] = ($obj = Comments::get($this->getEntityId())) instanceof Comments ? $obj->getJson() : null;
	    }
	    return parent::getJson($array, $reset);
	}
	/**
	 * (non-PHPdoc)
	 * @see BaseEntity::__loadDaoMap()
	 */
	public function __loadDaoMap()
	{
		DaoMap::begin($this, 'comm');
				
		parent::__loadDaoMap();
		
		DaoMap::setIntType('entityId');
		DaoMap::setStringType('entityName','varchar', 100);
		
		DaoMap::createIndex('entityId');
		DaoMap::createIndex('entityName');

		DaoMap::commit();
	}
	/**
	 * create a Comments
	 * 
	 * @param string 				$title
	 * @param string 				$content
	 * @param BaseEntityAbstract 	$entity
	 * @param string	 			$refId
	 * @param UserAccount			$author
	 * @param string 				$authorName
	 * @param bool	 				$active
	 * 
	 * @throws Exception
	 * @return Comments
	 */
	public static function create($title, $content, BaseEntityAbstract $entity, $refId = null, $author = null, $authorName = null, $active = true)
	{
		if(($title = trim($title)) === '')
			throw new Exception('Title for a ' . __CLASS__ . ' must not be empty');
		if(($content = trim($content)) === '')
			throw new Exception('Content for a ' . __CLASS__ . ' must be null or a non-empty string');
		if(($refId = StringUtilsAbstract::nullOrString($refId)) !== null && $refId === '')
			throw new Exception('RefId for a ' . __CLASS__ . ' must not be empty');
		if($author !== null && !$author instanceof Person)
			throw new Exception('Author for a ' . __CLASS__ . ' must be null or instance of Person');
		if(($authorName = StringUtilsAbstract::nullOrString($authorName)) !== null && $authorName === '')
			throw new Exception('AuthorName for a ' . __CLASS__ . ' must not be empty');
	
		$active = (intval($active) === 1);
	
		$obj = self::getByRefId($refId, false); // deactived obj will also be found and replaced
		$obj = $obj instanceof self ? $obj : new self();
		$obj->setTitle($title)
			->setContent($content)
			->setEntityName(get_class($entity))
			->setEntityId($entity->getId())
			->setRefId($refId)
			->setAuthor($author)
			->setAuthorName($authorName)
			->setActive($active)
			->save();
		return $obj;
	}
	/**
	 * create a Comments by Question
	 * 
	 * @param string 	$title
	 * @param string 	$content
	 * @param Question 	$question
	 * @param string 	$refId
	 * @param string 	$author
	 * @param string 	$authorName
	 * @param string 	$active
	 */
	public static function createByQuestion($title, $content, Question $question, $refId = null, $author = null, $authorName = null, $active = true) 
	{
		$obj = self::create($title, $content, $question, $refId, $author, $authorName, $active);
		return $obj;
	}
	/**
	 * create a Comments by Answer
	 * 
	 * @param string 	$title
	 * @param string 	$content
	 * @param Answer 	$answer
	 * @param string 	$refId
	 * @param string 	$author
	 * @param string 	$authorName
	 * @param string 	$active
	 */
	public static function createByAnswer($title, $content, Answer $answer, $refId = null, $author = null, $authorName = null, $active = true) 
	{
		$obj = self::create($title, $content, $answer, $refId, $author, $authorName, $active);
		return $obj;
	}
	/**
	 * create a comment for this Comments
	 *
	 * @param string 		$title
	 * @param string 		$content
	 * @param string 		$refId
	 * @param UserAccount 	$author
	 * @param string 		$authorName
	 * @param bool	 		$active
	 */
	public function addComments($title, $content, $refId = null, $author = null, $authorName = null, $active = true) {
		$obj = self::create($title, $content, $this, $refId, $author, $authorName, $active);
		return $obj;
	}
	/**
	 * get Comments for this Comments
{'fraction_non_alphanumeric': 0.16369624176675707, 'fraction_numerical': 0.0007748934521503294, 'mean_word_length': 3.4755093194625055, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 55, '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': '5610572', 'n_tokens_mistral': 3683, 'n_tokens_neox': 3335, 'n_words': 889}