id; } /** * @return \DateTime */ public function getBegin() { return $this->begin; } /** * @param \DateTime $begin * @return Timesheet */ public function setBegin($begin) { $this->begin = $begin; return $this; } /** * @return \DateTime */ public function getEnd() { return $this->end; } /** * @param \DateTime $end * @return Timesheet */ public function setEnd($end) { $this->end = $end; // FIXME test and then remove it, this should not be neccessary if (null === $end) { $this->duration = 0; } return $this; } /** * Set duration * * @param int $duration * @return Timesheet */ public function setDuration($duration) { $this->duration = $duration; return $this; } /** * Get duration * Do not rely on the results of this method for active records. * * @return int */ public function getDuration() { return $this->duration; } /** * Set user * * @param User $user * @return Timesheet */ public function setUser(User $user) { $this->user = $user; return $this; } /** * Get user * * @return User */ public function getUser() { return $this->user; } /** * Set activity * * @param Activity $activity * @return Timesheet */ public function setActivity($activity) { $this->activity = $activity; return $this; } /** * Get Activity * * @return Activity */ public function getActivity() { return $this->activity; } /** * @return Project */ public function getProject() { return $this->project; } /** * @param Project $project * @return Timesheet */ public function setProject(Project $project) { $this->project = $project; return $this; } /** * Set description * * @param string $description * @return Timesheet */ public function setDescription($description) { $this->description = $description; return $this; } /** * Get description * * @return string */ public function getDescription() { return $this->description; } /** * Set rate * * @param float $rate * @return Timesheet */ public function setRate($rate) { $this->rate = $rate; return $this; } /** * Get rate * * @return float */ public function getRate() { return $this->rate; } /** * @return float */ public function getFixedRate(): ?float { return $this->fixedRate; } /** * @param float $fixedRate * @return Timesheet */ public function setFixedRate(?float $fixedRate) { $this->fixedRate = $fixedRate; return $this; } /** * @return float */ public function getHourlyRate(): ?float { return $this->hourlyRate; } /** * @param float $hourlyRate * @return Timesheet */ public function setHourlyRate(?float $hourlyRate) { $this->hourlyRate = $hourlyRate; return $this; } /** * These validations are used in places, where we don't use a form yet (like the API). * * @param ExecutionContextInterface $context * @param mixed $payload * * @Assert\Callback */ public function validate(ExecutionContextInterface $context, $payload) { if (null === $this->getActivity()) { $context->buildViolation('A timesheet must have an activity.') ->atPath('activity') ->setTranslationDomain('validators') ->addViolation(); } if (null === $this->getProject()) { $context->buildViolation('A timesheet must have a project.') ->atPath('project') ->setTranslationDomain('validators') ->addViolation(); } if (null !== $this->getActivity() && null !== $this->getProject() && null !== $this->getActivity()->getProject() && $this->getActivity()->getProject() !== $this->getProject()) { $context->buildViolation('Project mismatch, project specific activity and timesheet project are different.') ->atPath('project') ->setTranslationDomain('validators') ->addViolation(); } if (null !== $this->getEnd() && $this->getEnd()->getTimestamp() < $this->getBegin()->getTimestamp()) { $context->buildViolation('End date must not be earlier then start date.') ->atPath('end') ->setTranslationDomain('validators') ->addViolation(); } } }