/** * Hydrate User entity from UserForm * @param \Nette\ArrayHash $values * @return \App\Model\Entities\User */ public static function hydrateUserFromHash(ArrayHash $values) { $nu = new User(); $nu->fromArray((array) $values); $na = new Address(); $na->fromArray((array) $values); $nc = new Contact(); $nc->fromArray((array) $values); $nc->setAddress($na); $nu->setContact($nc); return $nu; }
/** * Calls rollback * @param \App\Model\Entities\User $uDb * @param \App\Model\Entities\User $formUser * @throws Exceptions\DuplicateEntryException * @throws Exceptions\DataErrorException */ private function handleUpdateUser(User $uDb, User $formUser) { $identifier = null; $now = new DateTime(); try { $this->editorTypeHandle($uDb->getWebProfile()); $formUser->setWebProfile($uDb->getWebProfile()); $formUser->setCreated($uDb->getCreated()); $formUser->setUpdated($now); $formUser->setLastLogin($uDb->getLastLogin()); $formUser->setContact($uDb->getContact()); $uDb->fromArray($formUser->toArray()); $this->entityManager->merge($uDb); $this->entityManager->flush(); } catch (DuplicateEntryException $e) { $this->imageService->removeResource($identifier); throw new Exceptions\DuplicateEntryException($e->getMessage(), $e->getCode(), $e->getPrevious()); } catch (\Exception $e) { $this->imageService->removeResource($identifier); throw new Exceptions\DataErrorException($e->getMessage(), $e->getCode(), $e->getPrevious()); } }