public function store() { $input = \Input::only('subject', 'message', 'send_to_all', 'recipient'); $this->emailNotificationValidator->validate($input); //This is for admins only unless they are part of a group, then they have access to specific lists if (!\Auth::user()->isAdmin() && !\Auth::user()->hasRole('laser')) { } if ($input['send_to_all']) { if ($input['recipient'] == 'all') { if (!\Auth::user()->isAdmin()) { throw new AuthenticationException("You don't have permission to send to this group"); } $users = $this->userRepository->getActive(); } else { if ($input['recipient'] == 'laser_induction_members') { if (!\Auth::user()->hasRole('laser')) { throw new AuthenticationException("You don't have permission to send to this group"); } $users = $this->inductionRepository->getUsersForEquipment('laser'); } else { throw new NotImplementedException("Recipient not supported"); } } foreach ($users as $user) { $notification = new UserMailer($user); $notification->sendNotificationEmail($input['subject'], nl2br($input['message'])); } } else { //Just send to the current user $notification = new UserMailer(\Auth::user()); $notification->sendNotificationEmail($input['subject'], nl2br($input['message'])); } \Notification::success('Email Queued to Send'); return \Redirect::route('notificationemail.create'); }
public function show($equipmentId) { $equipment = $this->equipmentRepository->findBySlug($equipmentId); $trainers = $this->inductionRepository->getTrainersForEquipment($equipment->induction_category); $equipmentLog = $this->equipmentLogRepository->getFinishedForEquipment($equipment->device_key); $usageTimes = []; $usageTimes['billed'] = $this->equipmentLogRepository->getTotalTime($equipment->device_key, true, ''); $usageTimes['unbilled'] = $this->equipmentLogRepository->getTotalTime($equipment->device_key, false, ''); $usageTimes['training'] = $this->equipmentLogRepository->getTotalTime($equipment->device_key, null, 'training'); $usageTimes['testing'] = $this->equipmentLogRepository->getTotalTime($equipment->device_key, null, 'testing'); $userInduction = $this->inductionRepository->getUserForEquipment(\Auth::user()->id, $equipment->induction_category); $trainedUsers = $this->inductionRepository->getTrainedUsersForEquipment($equipment->induction_category); $usersPendingInduction = $this->inductionRepository->getUsersPendingInductionForEquipment($equipment->induction_category); return \View::make('equipment.show')->with('equipmentId', $equipmentId)->with('equipment', $equipment)->with('trainers', $trainers)->with('equipmentLog', $equipmentLog)->with('userInduction', $userInduction)->with('trainedUsers', $trainedUsers)->with('usersPendingInduction', $usersPendingInduction)->with('usageTimes', $usageTimes); }
public function validateData() { //Verify the keyfob, device key and action //Validate the action if (!in_array($this->action, $this->deviceActions)) { throw new ValidationException('Invalid Device Action'); } //Validate the device try { $this->device = $this->equipmentRepository->findBySlug($this->deviceKey); } catch (ModelNotFoundException $e) { throw new ValidationException('Invalid Device Key'); } //Confirm the device is working if (!$this->device->working) { throw new ValidationException('Device Not Working'); } //Validate the key fob $this->keyFob = $this->lookupKeyFob($this->keyFobId); //Make sure the user is active $this->user = $this->keyFob->user()->first(); if (!$this->user || !$this->user->active) { throw new ValidationException('User Invalid'); } //Make sure the user is allowed to use the device if ($this->device->requires_induction) { //Verify the user has training if (!$this->inductionRepository->isUserTrained($this->user->id, $this->deviceKey)) { throw new ValidationException('User Not Trained'); } } //Make sure the member has enough money on their account $minimumBalance = $this->bbCredit->acceptableNegativeBalance('equipment-fee'); if ($this->user->cash_balance + $minimumBalance * 100 <= 0) { throw new ValidationException('User doesn\'t have enough credit'); } }