public function PageLoad()
 {
     $this->page->SetEmailEnabled(Configuration::Instance()->GetKey(ConfigKeys::ENABLE_EMAIL, new BooleanConverter()));
     $userSession = ServiceLocator::GetServer()->GetUserSession();
     $user = $this->userRepository->LoadById($userSession->UserId);
     if ($this->page->IsPostBack()) {
         $this->UpdateProfile($user);
         $this->page->SetPreferencesSaved(true);
     }
     $this->page->SetApproved($user->WantsEventEmail(new ReservationApprovedEvent()));
     $this->page->SetCreated($user->WantsEventEmail(new ReservationCreatedEvent()));
     $this->page->SetUpdated($user->WantsEventEmail(new ReservationUpdatedEvent()));
     $this->page->SetDeleted($user->WantsEventEmail(new ReservationDeletedEvent()));
 }
 /**
  * @param int $userId
  * @return User|void
  */
 public function LoadById($userId)
 {
     $user = parent::LoadById($userId);
     $me = parent::LoadById($this->userSession->UserId);
     if ($userId == $this->userSession->UserId || $me->IsAdminFor($user)) {
         return $user;
     }
     return User::Null();
 }
 public function ChangeColor()
 {
     $userId = $this->page->GetUserId();
     Log::Debug('Changing reservation color for userId: %s', $userId);
     $color = $this->page->GetReservationColor();
     $user = $this->userRepository->LoadById($userId);
     $user->ChangePreference(UserPreferences::RESERVATION_COLOR, $color);
     $this->userRepository->Update($user);
 }
Exemple #4
0
 public function ChangeDefaultSchedule()
 {
     $userSession = ServiceLocator::GetServer()->GetUserSession();
     $scheduleId = $this->page->GetDefaultSchedule();
     Log::Debug('ProfilePresenter updating default schedule to %s for user %s', $scheduleId, $userSession->UserId);
     $user = $this->userRepository->LoadById($userSession->UserId);
     $user->ChangeDefaultSchedule($scheduleId);
     $this->userRepository->Update($user);
     $userSession->ScheduleId = $this->page->GetDefaultSchedule();
     ServiceLocator::GetServer()->SetUserSession($userSession);
 }
 public function ShowUserAttributes()
 {
     // User attributes on Dashboard, Added by Burak C.
     $userId = ServiceLocator::GetServer()->GetUserSession()->UserId;
     $userRepository = new UserRepository();
     $this->user = $userRepository->LoadById($userId);
     $attributeService = new AttributeService(new AttributeRepository());
     $attributes = $attributeService->GetByCategory(CustomAttributeCategory::USER);
     $reservationViewRepository = new ReservationViewRepository();
     $startDate = Date::Now();
     $endDate = $startDate->AddDays(30);
     $reservations = $reservationViewRepository->GetReservationList($startDate, $endDate, $userId, ReservationUserLevel::INVITEE);
     $this->_page->Set("invitations", $reservations);
     $this->_page->Set("user", $this->user);
     $this->_page->Set("attributes", $attributes);
 }
 /**
  * @param UserDto $user
  * @return void
  */
 public function SetReservationUser(UserDto $user)
 {
     $this->Set('ReservationUserName', $user->FullName());
     $this->Set('UserId', $user->Id());
     $this->Set('IsAdmin', ServiceLocator::GetServer()->GetUserSession()->IsAdmin);
     $userRepo = new UserRepository();
     $userAttributes = array();
     $loadedUser = $userRepo->LoadById($user->Id());
     $userAttributes['traininglevel'] = $loadedUser->GetAttributeValue(17);
     $userAttributes['trainingtype'] = $loadedUser->GetAttributeValue(15);
     $userAttributes['saat'] = $loadedUser->GetAttributeValue(8);
     $this->Set('UserAttributes', $userAttributes);
 }
 public function SetParticipants($reservationRefNum)
 {
     $reservationRepository = new ReservationRepository();
     $series = $reservationRepository->LoadByReferenceNumber($reservationRefNum);
     $userrepo = new UserRepository();
     $participantIDs = $series->CurrentInstance()->Participants();
     foreach ($participantIDs as $value) {
         $user = $userrepo->LoadById($value);
         $participantnames[] = $user->FullName();
     }
     return $participantnames;
 }
 public function IsSameTrainingLevel(UserSession $session)
 {
     $reservationType = $this->_reservation->GetAttributeValue(5);
     $userId = $session->UserId;
     $userRepository = new UserRepository();
     $user = $userRepository->LoadById($userId);
     $userTrainingType = $user->GetAttributeValue(17);
     return $reservationType == $userTrainingType;
 }
Exemple #9
0
 /**
  * @param $term string
  * @return array|AutocompleteUser[]
  */
 private function GetMyUsers($term)
 {
     $userSession = ServiceLocator::GetServer()->GetUserSession();
     if ($userSession->IsAdmin) {
         return $this->GetUsers($term);
     }
     $userRepo = new UserRepository();
     $user = $userRepo->LoadById($userSession->UserId);
     $groupIds = array();
     foreach ($user->GetAdminGroups() as $group) {
         $groupIds[] = $group->GroupId;
     }
     $users = array();
     if (!empty($groupIds)) {
         $userFilter = new SqlFilterLike(ColumnNames::FIRST_NAME, $term);
         $userFilter->_Or(new SqlFilterLike(ColumnNames::LAST_NAME, $term));
         $groupRepo = new GroupRepository();
         $results = $groupRepo->GetUsersInGroup($groupIds, null, null, $userFilter)->Results();
         /** @var $result UserItemView */
         foreach ($results as $result) {
             // consolidates results by user id if the user is in multiple groups
             $users[$result->Id] = new AutocompleteUser($result->Id, $result->First, $result->Last, $result->Email, $result->Username);
         }
     }
     return array_values($users);
 }
 /**
  * @param $invitationAction
  * @return string|null
  */
 private function HandleInvitationAction($invitationAction)
 {
     $referenceNumber = $this->page->GetInvitationReferenceNumber();
     $userId = $this->page->GetUserId();
     $userRepository = new UserRepository();
     $user = $userRepository->LoadById($userId);
     $userCredit = $user->GetAttributeValue(8);
     Log::Debug('Invitation action %s for user %s and reference number %s', $invitationAction, $userId, $referenceNumber);
     $series = $this->reservationRepository->LoadByReferenceNumber($referenceNumber);
     foreach ($this->rules as $rule) {
         $ruleResult = $rule->Validate($series);
         if (!$ruleResult->IsValid()) {
             return Resources::GetInstance()->GetString('ParticipationNotAllowed');
         }
     }
     $error = null;
     $reservationCredit = $series->GetAttributeValue(6);
     if ($invitationAction == InvitationAction::Accept) {
         $error = $this->CheckCapacityAndReturnAnyError($series);
         if (!$error && $userCredit >= $reservationCredit) {
             $userCredit -= $reservationCredit;
             $user->ChangeCustomAttribute(8, $userCredit);
             $userRepository->Update($user);
             $series->AcceptInvitation($userId);
         } else {
             $error = "Yeterli kredininiz bulunmamaktadır. Kredi almak için ödeme gerçekleştirebilirsiniz.";
         }
     }
     if ($invitationAction == InvitationAction::Decline) {
         $series->DeclineInvitation($userId);
     }
     if ($invitationAction == InvitationAction::CancelInstance) {
         $cancelCredit = $user->GetAttributeValue(12);
         //iptal hakkı
         if ($cancelCredit > 0) {
             $cancelCredit -= 1;
             $reservationCredit = $series->GetAttributeValue(6);
             $userCredit += $reservationCredit;
             $user->ChangeCustomAttribute(8, $userCredit);
             $user->ChangeCustomAttribute(12, $cancelCredit);
             /*   first training date optional logic
             				$firstTrainingDate= $user->GetAttributeValue(19);
             				$reservationDate= $series->CurrentInstance()->StartDate();
             				// One more logic should be added to cancel.
             
             				if(strcmp($firstTrainingDate,$reservationDate)==0 ) {
             
             					$user->ChangeCustomAttribute(19,null);
             				}
             */
             $userRepository->Update($user);
             $series->CancelInstanceParticipation($userId);
         } else {
             $error = "You dont have cancel right";
         }
     }
     if ($invitationAction == InvitationAction::CancelAll) {
         $series->CancelInstanceParticipation($userId);
         $series->CancelAllParticipation($userId);
     }
     if ($invitationAction == InvitationAction::Join) {
         if (!$series->GetAllowParticipation()) {
             $error = Resources::GetInstance()->GetString('ParticipationNotAllowed');
         } else {
             $error = $this->CheckCapacityAndReturnAnyError($series);
             $reservationCredit = $series->GetAttributeValue(6);
             if (!$error && $userCredit >= $reservationCredit) {
                 $userCredit -= $reservationCredit;
                 $user->ChangeCustomAttribute(8, $userCredit);
                 $firstTrainingDate = $user->GetAttributeValue(19);
                 $reservationDate = $series->CurrentInstance()->StartDate()->ToTimezone($user->Timezone());
                 // One more logic should be added to cancel.
                 if ($firstTrainingDate == null || $firstTrainingDate == 0) {
                     $firstTrainingDate = $reservationDate;
                     $user->ChangeCustomAttribute(19, $firstTrainingDate);
                 }
                 $userRepository->Update($user);
                 $series->JoinReservationSeries($userId);
             } else {
                 $series->JoinInviteeList($userId);
                 $error = "Eğitime katılmak için ödeme yapmanız gerekmektedir. Ödeme yaptıktan sonra eğitiminizi onaylayıp katılabilirsiniz.  ";
             }
         }
     }
     if ($invitationAction == InvitationAction::JoinAll) {
         if (!$series->GetAllowParticipation()) {
             $error = Resources::GetInstance()->GetString('ParticipationNotAllowed');
         } else {
             $reservationAmount = count($series->Instances());
             $reservationCredit = $reservationAmount * $series->GetAttributeValue(6);
             /**  Bugfix added by Deniz. prevention against participation to reservation in occurence of an error * */
             $error = $this->CheckCapacityAndReturnAnyError($series);
             if (!$error && $userCredit >= $reservationCredit) {
                 $userCredit -= $reservationCredit;
                 $user->ChangeCustomAttribute(8, $userCredit);
                 $firstTrainingDate = $user->GetAttributeValue(19);
                 $reservationDate = $series->CurrentInstance()->StartDate()->ToTimezone($user->Timezone());
                 // One more logic should be added to cancel.
                 if ($firstTrainingDate == null || $firstTrainingDate == 0) {
                     $user->ChangeCustomAttribute(19, $reservationDate);
                 }
                 $userRepository->Update($user);
                 //$series->CurrentInstance()->With
                 $series->JoinReservationSeries($userId);
             } else {
                 $series->JoinInviteeListSeries($userId);
                 $error = "Eğitime katılmak için ödeme yapmanız gerekmektedir. Ödeme yaptıktan sonra eğitiminizi onaylayıp katılabilirsiniz.";
             }
         }
     }
     $this->reservationRepository->Update($series);
     return $error;
 }
 public function testLoadsUserFromCacheIfAlreadyLoadedFromDatabase()
 {
     $userId = 1;
     $row = $this->GetUserRow();
     $this->db->SetRow(0, array($row));
     $this->db->SetRow(1, $this->GetEmailPrefRows());
     $this->db->SetRow(2, $this->GetPermissionsRows());
     $this->db->SetRow(3, $this->GetGroupsRows());
     $this->db->SetRow(4, $this->GetAttributeRows());
     $this->db->SetRow(5, $this->GetOwnedGroupRows());
     $this->db->SetRow(6, $this->GetPreferenceRows());
     $userRepository = new UserRepository();
     $user = $userRepository->LoadById($userId);
     $user = $userRepository->LoadById($userId);
     // 2nd call should load from cache
     $this->assertEquals(7, count($this->db->_Commands));
 }