public function renderDefault()
 {
     $this->template->products = $this->products->findAll();
     $this->template->orders = $this->orders->findAll();
     $user = 3;
     $userEntity = $this->users->get($user);
     // $userEntity->cartOrder->id
     $cart = $userEntity->cartOrder;
     if ($cart) {
         $cart->status = 'ordered';
         $this->orders->persist($cart);
         dump($userEntity->cartOrder->status);
     }
     $product = new Product();
     $product->name = 'Tajnej';
     $this->products->persist($product);
     $newOrder = new Order();
     $newOrder->user = $userEntity;
     $newOrder->created_date = new \Nette\Utils\DateTime();
     $this->orders->persist($newOrder);
     $newOrder->addToProducts(array($product));
     $this->orders->persist($newOrder);
     //dump($userEntity);
     //exit();
 }
 public function logEvent(\LeanMapper\Entity $entity, $action)
 {
     $log = new Log();
     $log->entity_name = $entity->getConventionalName();
     $log->entity_identifier = $entity->id;
     $log->user = $this->userRepository->find($this->user->id);
     $log->logged_at = new DateTime();
     $log->action = $action;
     $this->logRepository->persist($log);
 }
 private function onSubmit()
 {
     $username = $this->registerView->GetUsername();
     $password1 = $this->registerView->GetPassword1();
     $password2 = $this->registerView->GetPassword2();
     try {
         $user = new User();
         if ($password1 === $password2) {
             $this->registerModel->SetUsername($username);
             $hashedPassword = $this->registerModel->hashPassword($password1);
             $user->SetPassword($hashedPassword);
         } else {
             $this->registerView->msgPasswordNotSame();
             return;
         }
         $user->SetUsername($username);
         $userRepository = new UserRepository();
         $userRepository->add($user);
         $loginView = new LoginView();
         $agent = $loginView->GetAgent();
         $sessionModel = new SessionModel();
         $sessionModel->SetValidSession($agent);
         $sessionModel->SetUser($username);
         NavView::redirectToUMLRegisterMSG($username);
     } catch (RegisterUsernameLengthException $e) {
         $this->registerView->msgUsernameLength();
     } catch (RegexException $e) {
         $name = $e->getMessage();
         $this->registerView->SetUsername($name);
         $this->registerView->msgUsernameWrongChar($name);
     } catch (RegisterException $e) {
         $this->registerView->msgPasswordLength();
     } catch (DbUserExistException $e) {
         $this->registerView->msgUserExist();
     } catch (RegisterUsernameMaxLengthException $e) {
         $this->registerView->msgUsernameMaxLength();
     } catch (RegisterPasswordMaxLengthException $e) {
         $this->registerView->msgPasswordMaxLength();
     }
 }
 public function deleteUmlProject($sessionModel)
 {
     $projectView = new ProdjectsView();
     // Get projectname from view.
     if ($projectName = $projectView->GetProjectName()) {
         try {
             $uml = new Uml();
             $uml->SetSaveName($projectName);
             // Get userID from UserRepository and then populate to UML object.
             $username = $sessionModel->GetUser();
             $userRepository = new UserRepository();
             $user = $userRepository->getUserByUsername($username);
             $uml->SetUserID($user->GetUserID());
             // Delete project by UserID and projectName.
             $this->umlRepository->deleteProject($uml);
             $this->memberView->deleteMSG($uml->GetSaveName());
         } catch (DeleteProjextException $e) {
             $this->memberView->errorDeleteMSG();
         }
     }
 }
 public function getUsernameByUserID($userID)
 {
     $userRepository = new UserRepository();
     $username = $userRepository->getUsernameByUserID($userID);
     return $username;
 }