/** * @param \DLigo\Animaltool\Domain\Model\Animal $animal * @param array $treatment * @param string $tag * @param string $passId * @param string $contunue * @param string $release * @param string $extern * @param string $newextern * @param string $dead * @param string $origRFID * @param string $origEarTag * @Flow\Validate (argumentName="$treatment", type="\DLigo\Animaltool\Validation\Validator\TreatmentValidator") * @Flow\Validate (argumentName="$animal.healthCondition",type="NotEmpty") * @Flow\Validate (argumentName="$animal.photo", type="NotEmpty") * @return void */ public function treatAction(Animal $animal, $treatment, $tag = '', $passId = '', $continue = null, $release = null, $extern = null, $newextern = null, $dead = null, $origRFID = '', $origEarTag = '') { $duplicate = false; // \TYPO3\Flow\var_dump($this->request); $done = false; $mergeMessage = ''; $merge = ''; $tr = $animal->getOpenTreatment(); if (!$tr) { $tr = new \DLigo\Animaltool\Domain\Model\Treatment(); $tr->setStartDate(new \DateTime('now')); $tr->setAnimal($animal); // $tr->setDoctor($this->session->getUser()); $animal->getTreatments()->add($tr); } $did = isset($treatment['doctor']['__identity']) ? $treatment['doctor']['__identity'] : $treatment['doctor']; $tr->setDoctor($this->userRepository->findByIdentifier($did)); $therapies = new \Doctrine\Common\Collections\ArrayCollection(); $extras = new \Doctrine\Common\Collections\ArrayCollection(); if (is_array($treatment['therapies'])) { foreach ($treatment['therapies'] as $thid) { $therapy = $this->therapyRepository->findByIdentifier($thid); if ($therapy->getHasExtraData()) { $extra = $this->treatmentExtraRepository->findByTherapyAndTreatment($thid, $tr)->getFirst(); if (!$extra) { $extra = new \DLigo\Animaltool\Domain\Model\TreatmentExtra(); $extra->setTreatment($tr); $extra->setTherapy($therapy); } $extra->setValue($treatment['treatmentExtra'][$thid]); unset($treatment['treatmentExtra'][$thid]); $extras->add($extra); } $therapies->add($therapy); } } $tr->setTherapies($therapies); $tr->setTreatmentExtras($extras); $tr->setComment($treatment['comment']); if ($this->persistenceManager->isNewObject($tr)) { $this->treatmentRepository->add($tr); } else { $this->treatmentRepository->update($tr); } if (isset($treatment['treatmentExtra']) && is_array($treatment['treatmentExtra'])) { foreach ($treatment['treatmentExtra'] as $thid => $value) { $extra = $this->treatmentExtraRepository->findByTherapyAndTreatment($thid, $tr)->getFirst(); if ($extra != null) { $this->treatmentExtraRepository->remove($extra); } } } if ($continue) { $animal->setStayStatus(Animal::THERAPY); $animal->setTherapyStatus(Animal::OPERATION); $animal->stopOpenExternals(); $animal->stopOpenTreatments(); } elseif ($release) { $animal->setStayStatus(Animal::RELEASING); $animal->setTherapyStatus(Animal::READY); $animal->stopOpenExternals(); $animal->stopOpenTreatments(); $animal->getLastAction()->setReleaseDate(new \DateTime('now')); } elseif ($extern) { if ($animal->getStayStatus() == Animal::CATCHED) { $animal->setStayStatus(Animal::THERAPY); } if ($animal->getTherapyStatus() == Animal::WAIT) { $animal->setTherapyStatus(Animal::OPERATION); } $animal->stopOpenTreatments(); } elseif ($newextern) { $animal->stopOpenExternals(); $animal->stopOpenTreatments(); } elseif ($dead) { $animal->setStayStatus(Animal::RELEASED); $animal->setTherapyStatus(Animal::DEAD); $animal->stopOpenExternals(); $animal->stopOpenTreatments(); } $oldAnimal = null; if ($animal->getIsPrivate()) { $animal->setRFID($tag); if ($tag != $origRFID && !empty($tag)) { $oldAnimal = $this->animalRepository->findByRFID($tag)->getFirst(); } $animal->getOwner()->setPassId($passId); } else { $animal->setEarTag($tag); if ($tag != $origEarTag && !empty($tag)) { $oldAnimal = $this->animalRepository->findByEarTag($tag)->getFirst(); } } if (!empty($oldAnimal)) { $tag = "_DUMMY_" . $tag . "_" . time(); $duplicate = true; $animal->setIsDummy(true); $animal->setRFID($tag); } $this->animalRepository->update($animal); if ($duplicate) { $this->redirect('duplicate', null, null, array('animal' => $animal, 'oldAnimal' => $oldAnimal, 'external' => $extern != null)); } if ($extern || $newextern) { $this->redirect('open', 'External', null, array('animal' => $animal)); } $this->addFlashMessage('Updated the animal.' . $mergeMessage, '', \TYPO3\Flow\Error\Message::SEVERITY_OK, array(), 'flash.animal.update' . $merge); $this->redirect('index'); return ''; }