<commit_before><?php

namespace Ora\ReadModel;

use Ora\TaskManagement\TaskInterface;
use Doctrine\ORM\Mapping AS ORM;
use Doctrine\Common\Collections\ArrayCollection;
use Rhumsaa\Uuid\Uuid;
use Ora\IllegalStateException;
use Ora\DuplicatedDomainEntityException;
use Ora\DomainEntityUnavailableException;
use Ora\User\User;
use Zend\Permissions\Acl\Resource\ResourceInterface;

/**
 * @ORM\Entity @ORM\Table(name="tasks")
 * @ORM\InheritanceType("SINGLE_TABLE")
 * @ORM\DiscriminatorColumn(name="type", type="string")
 * @author <NAME>
 *
 */

// If no DiscriminatorMap annotation is specified, doctrine uses lower-case class name as default values

class Task extends EditableEntity implements ResourceInterface
{	
    CONST STATUS_IDEA = 0;
    CONST STATUS_OPEN = 10;
    CONST STATUS_ONGOING = 20;
    CONST STATUS_COMPLETED = 30;
    CONST STATUS_ACCEPTED = 40;
    CONST STATUS_CLOSED = 50;
    CONST STATUS_DELETED = -10;
    
    CONST ROLE_MEMBER = 'member';
    CONST ROLE_OWNER  = 'owner';

    CONST TYPE = 'task';

	/**
	 * @ORM\Column(type="string")
	 * @var string
	 */
	private $subject;
	
	/**
	 * @ORM\Column(type="integer")
	 * @var int
	 */
	private $status;
	
	/**
	 * @ORM\ManyToOne(targetEntity="Ora\ReadModel\Stream")
	 * @ORM\JoinColumn(name="stream_id", referencedColumnName="id", nullable=false)
	 */
	private $stream;

	/**
	 * @ORM\OneToMany(targetEntity="Ora\ReadModel\TaskMember", mappedBy="task", cascade={"PERSIST", "REMOVE"}, indexBy="member_id")
	 * @var TaskMember[]
	 */
	private $members;
	
	public function __construct($id) 
	{
		$this->id = $id;
		$this->members = new ArrayCollection();
	}
	
	public function getStatus() {
	    return $this->status;
	}
	
	public function getSubject() {
		return $this->subject;
	}
	
	public function setSubject($subject) {
		$this->subject = $subject;
	}
	
	public function getStream() {
	    return $this->stream;
	}
	
	public function setStream(Stream $stream) {
		$this->stream = $stream;
		return $this->stream;
	}
	
	public function setStatus($status) {
		$this->status = $status;
		return $this->status;
	}
	
    public function addMember(User $user, $role, User $by, \DateTime $when) {
        $taskMember = new TaskMember($this, $user, $role);
        $taskMember->setCreatedAt($when);
        $taskMember->setCreatedBy($by);
        $taskMember->setMostRecentEditAt($when);
        $taskMember->setMostRecentEditBy($by);
		$this->members->set($user->getId(), $taskMember);
		return $this;
	}
	
	/**
	 * 
	 * @param id|TaskMember $member
	 */
	public function removeMember($member) {
		if($member instanceof TaskMember) {
			$this->members->removeElement($member);
		} else {			
			$this->members->remove($member);
		}
		return $this;
	}
    
	/**
	 * 
	 * @param id|User $user
	 * @return \Ora\ReadModel\TaskMember|NULL
	 */
    public function getMember($user) {
    	$key = $user instanceof User ? $user->getId() : $user;
    	return $this->members->get($key);
    }
    
    /**
     * 
     * @param id|User $user
     * @return boolean
     */
    public function hasMember($user) {
    	$key = $user instanceof User ? $user->getId() : $user;
    	return $this->members->containsKey($key);
    }

    /**
     * @return TaskMember[]
     */
	public function getMembers() {
	    return $this->members->toArray();
	}
	
    public function getType(){

         $c = get_called_class();
         return $c::TYPE;
    }
    
    /**
     * TODO: da rimuovere, deve leggere un valore già calcolato. Il calcolo sta nel write model
     * @return string|number|NULL
     */
    public function getEstimation() {
    	$tot = null;
    	$estimationsCount = 0;
    	$notEstimationCount = 0;
    	foreach ($this->members as $member) {
    		$estimation = $member->getEstimation()->getValue();
    		switch ($estimation) {
    		case null:
    			break;
    		case Estimation::NOT_ESTIMATED:<commit_msg>Update Task.php<commit_after><?php

namespace Ora\ReadModel;

use Ora\TaskManagement\TaskInterface;
use Doctrine\ORM\Mapping AS ORM;
use Doctrine\Common\Collections\ArrayCollection;
use Rhumsaa\Uuid\Uuid;
use Ora\IllegalStateException;
use Ora\DuplicatedDomainEntityException;
use Ora\DomainEntityUnavailableException;
use Ora\User\User;
use Zend\Permissions\Acl\Resource\ResourceInterface;

/**
 * @ORM\Entity @ORM\Table(name="tasks")
 * @ORM\InheritanceType("SINGLE_TABLE")
 * @ORM\DiscriminatorColumn(name="type", type="string")
 * @author <NAME>
 *
 */

// If no DiscriminatorMap annotation is specified, doctrine uses lower-case class name as default values

class Task extends EditableEntity implements ResourceInterface
{	
    CONST STATUS_IDEA = 0;
    CONST STATUS_OPEN = 10;
    CONST STATUS_ONGOING = 20;
    CONST STATUS_COMPLETED = 30;
    CONST STATUS_ACCEPTED = 40;
    CONST STATUS_CLOSED = 50;
    CONST STATUS_DELETED = -10;
    
    CONST ROLE_MEMBER = 'member';
    CONST ROLE_OWNER  = 'owner';

    CONST TYPE = 'task';

	/**
	 * @ORM\Column(type="string")
	 * @var string
	 */
	private $subject;
	
	/**
	 * @ORM\Column(type="integer")
	 * @var int
	 */
	private $status;
	
	/**
	 * @ORM\ManyToOne(targetEntity="Ora\ReadModel\Stream")
	 * @ORM\JoinColumn(name="stream_id", referencedColumnName="id", nullable=false)
	 */
	private $stream;

	/**
	 * @ORM\OneToMany(targetEntity="Ora\ReadModel\TaskMember", mappedBy="task", cascade={"PERSIST", "REMOVE"}, indexBy="member_id")
	 * @var TaskMember[]
	 */
	private $members;
	
	public function __construct($id) 
	{
		$this->id = $id;
		$this->members = new ArrayCollection();
	}
	
	public function getStatus() {
	    return $this->status;
	}
	
	public function getSubject() {
		return $this->subject;
	}
	
	public function setSubject($subject) {
		$this->subject = $subject;
	}
	
	public function getStream() {
	    return $this->stream;
	}
	
	public function setStream(Stream $stream) {
		$this->stream = $stream;
		return $this->stream;
	}
	
	public function setStatus($status) {
		$this->status = $status;
		return $this->status;
	}
	
	public function addMember(User $user, $role, User $by, \DateTime $when) {
        	$taskMember = new TaskMember($this, $user, $role);
        	$taskMember->setCreatedAt($when);
        	$taskMember->setCreatedBy($by);
        	$taskMember->setMostRecentEditAt($when);
        	$taskMember->setMostRecentEditBy($by);
		$this->members->set($user->getId(), $taskMember);
		return $this;
	}
	
	/**
	 * 
	 * @param id|TaskMember $member
	 */
	public function removeMember($member) {
		if($member instanceof TaskMember) {
			$this->members->removeElement($member);
		} else {
			$this->members->remove($member);
		}
		return $this;
	}
    
	/**
	 * 
	 * @param id|User $user
	 * @return \Ora\ReadModel\TaskMember|NULL
	 */
	public function getMember($user) {
		$key = $user instanceof User ? $user->getId() : $user;
    		return $this->members->get($key);
	}
    
	/**
	 * 
	 * @param id|User $user
	 * @return boolean
	 */
	public function hasMember($user) {
		$key = $user instanceof User ? $user->getId() : $user;
		return $this->members->containsKey($key);
	}

    	/**
	 * @return TaskMember[]
	 */
	public function getMembers() {
	    return $this->members->toArray();
	}
	
	public function getType(){
        	$c = get_called_class();
        	return $c::TYPE;
	}
    
    /**
     * TODO: da rimuovere, deve leggere un valore già calcolato. Il calcolo sta nel write model
     * @return string|number|NULL
     */
    public function getEstimation() {
    	$tot = null;
    	$estimationsCount = 0;
    	$notEstimationCount = 0;
    	foreach ($this->members as $member) {
    		$estimation = $member->getEstimation()->getValue();
    		switch ($estimation) {
    		case null:
    			break;
    		case Estimation::NOT_ESTIMATED:
{'fraction_non_alphanumeric': 0.14717323651452283, 'fraction_numerical': 0.0038900414937759337, 'mean_word_length': 3.345352112676056, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 69, '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': '228798', 'n_tokens_mistral': 2747, 'n_tokens_neox': 2536, 'n_words': 538}