Пример #1
0
 /**
  * @param \DLigo\Animaltool\Domain\Model\Animal $newAnimal
  * @param \DLigo\Animaltool\Domain\Model\Owner $newOwner
  * @param array<\DLigo\Animaltool\Domain\Model\Bread> $bread
  * @param string $tag
  * @Flow\Validate (argumentName="$newAnimal.photo", type="NotEmpty")
  * @Flow\Validate (argumentName="$newAnimal.gender", type="NotEmpty")
  * @return void
  */
 public function createAction(Animal $newAnimal, \DLigo\Animaltool\Domain\Model\Owner $newOwner, $bread, $tag = '')
 {
     $oldAnimal = null;
     $duplicate = false;
     $dummyAction = new \DLigo\Animaltool\Domain\Model\Action();
     $dummyAction->setLat(0);
     $dummyAction->setLng(0);
     $dummyAction->setAnimal($newAnimal);
     $dummyAction->setDate(new \DateTime('now'));
     $user = $this->session->getUser();
     $boxid = $user->getTeamID() . '-' . ($user->getLastBoxID() + 1);
     $dummyAction->setBoxID($boxid);
     $dummyAction->setTeam($user);
     $location = $this->session->getLocation();
     if ($location == null) {
         $location = $newAnimal->getLocation();
     }
     $dummyAction->setLocation($location);
     $newAnimal->setLocation($location);
     $speciesid = $this->persistenceManager->getIdentifierByObject($newAnimal->getSpecies());
     $breadid = $bread[$speciesid];
     $newAnimal->setBread($breadid);
     $newAnimal->setStayStatus(Animal::CATCHED);
     $newAnimal->setTherapyStatus(Animal::WAIT);
     $this->actionRepository->add($dummyAction);
     $newAnimal->setOwner($newOwner);
     if (!empty($tag)) {
         $oldAnimal = $this->animalRepository->findByRFID($tag)->getFirst();
         if ($oldAnimal) {
             $tag = "_DUMMY_" . $tag . "_" . time();
             $duplicate = true;
             $newAnimal->setIsDummy(true);
         }
         $newAnimal->setRFID($tag);
     }
     $this->ownerRepository->add($newOwner);
     $this->animalRepository->add($newAnimal);
     $this->addFlashMessage('Created a new animal.', '', \TYPO3\Flow\Error\Message::SEVERITY_OK, array(), 'flash.animal.new');
     if ($duplicate) {
         $this->redirect('duplicate', null, null, array('animal' => $newAnimal, 'oldAnimal' => $oldAnimal));
     }
     $this->redirect('treatment', null, null, array('animal' => $newAnimal));
 }
Пример #2
0
 public function addAction()
 {
     $currentUser = $this->authenticationManager->getSecurityContext()->getAccount()->getParty();
     $photoInfo = $this->request->getArgument("photo");
     $actionData = $this->request->getArgument("action");
     $actionData = json_decode($actionData, true);
     $animalData = $this->request->getArgument("animal");
     $animalData = json_decode($animalData, true);
     $ownerData = $this->request->getArgument("owner");
     $ownerData = json_decode($ownerData, true);
     $photoData = $this->request->getArgument("photo");
     $action = $this->propertyMapper->convert($actionData, 'DLigo\\Animaltool\\Domain\\Model\\Action');
     $action->setDate(new \DateTime('now'));
     $user = $this->propertyMapper->convert($actionData['team'], 'DLigo\\Animaltool\\Domain\\Model\\User');
     $lastId = $user->getLastBoxID();
     $action->setTeam($user);
     $box = explode('-', $actionData['boxID']);
     if ($lastId > $box[1]) {
         $action->setBoxID($user->getTeamID() . '-' . ($lastId + 1));
     }
     $animal = $this->propertyMapper->convert($animalData, 'DLigo\\Animaltool\\Domain\\Model\\Animal');
     $birthday = \DateTime::createFromFormat("U", $animalData["birthday"]);
     if (!empty($animalData["birthday"])) {
         $birthday = \DateTime::createFromFormat("U", $animalData["birthday"]);
         $birthday->setTime(0, 0, 0);
         $animal->setBirthday($birthday);
     }
     $action->setAnimal($animal);
     $owner = null;
     if (isset($animalData["isPrivate"]) && $animalData["isPrivate"]) {
         $owner = $this->propertyMapper->convert($ownerData, 'DLigo\\Animaltool\\Domain\\Model\\Owner');
         $animal->setOwner($owner);
         $animal->setEarTag(null);
         if (!empty($animalData["earTag"])) {
             $rfid = $animalData["earTag"];
             $oldAnimal = $this->animalRepository->findOneByRFID($rfid);
             if ($oldAnimal == null) {
                 $animal->setRFID($rfid);
             }
         }
     } else {
         if (!empty($animalData["earTag"])) {
             $eartag = $animalData["earTag"];
             $oldAnimal = $this->animalRepository->findOneByEarTag($eartag);
             if ($oldAnimal != null) {
                 $animal->setEarTag(null);
             }
         }
     }
     $photo = $this->resourceManager->importUploadedResource($photoInfo);
     //$this->systemLogger->log(\TYPO3\Flow\var_dump($photo,"Photo",true,true),LOG_INFO);
     $animal->setPhoto($photo);
     if ($owner) {
         $this->ownerRepository->add($owner);
     }
     $this->animalRepository->add($animal);
     $this->actionRepository->add($action);
     $this->userRepository->update($user);
     $this->persistenceManager->persistAll();
     $this->response->setStatus(201);
     echo "{" . '"lastID": ' . $currentUser->getLastBoxID() . "}";
     flush();
     ob_flush();
 }