Ejemplo n.º 1
0
 /**
  * @Authorize "Admin"
  */
 public function deleteUser(int $userId) : View
 {
     try {
         $user = $this->db->FindFirst(\Framework\Config\Config::USER_CLASS, "id='{$userId}'");
         if ($user == false) {
             throw new \Exception("User #{$userId} does not exist");
         }
         $userLectures = $this->db->FindAll("UserLecture", "user_id='{$userId}'");
         $lectures = $this->db->FindAll("Lecture", "user_id='{$userId}'");
         $confs = $this->db->FindAll("Conference", "user_id='{$userId}'");
         $notifs = $this->db->FindAll("Notification", "user_id='{$userId}'");
         foreach ($userLectures as $ul) {
             $ul->destroy();
         }
         foreach ($lectures as $l) {
             $l->destroy();
         }
         foreach ($confs as $c) {
             $c->destroy();
         }
         foreach ($notifs as $n) {
             $n->destroy();
         }
         $user->destroy();
         $this->redirect(\Framework\Helpers\Helpers::url() . "admin/users");
     } catch (\Exception $e) {
         $viewModel = new \Framework\Areas\Admin\ViewModels\Users\EditUserViewModel();
         $viewModel->errorsList = $model->getErrorsList();
         $viewModel->errorsList[] = $e->getMessage();
         $viewModel->error = true;
         $user = \Framework\Core\Identity::getUserInformation($userId);
         $viewModel->firstname = $user['firstname'];
         $viewModel->lastname = $user['lastname'];
         $viewModel->email = $user['email'];
         $viewModel->id = $user['id'];
         $viewModel->username = $user['username'];
         return new View('\\Users\\getEditUser', $viewModel);
     }
 }
 public function identity()
 {
     return json_decode(json_encode(\Framework\Core\Identity::getUserInformation($_SESSION['userId'])), FALSE);
 }
Ejemplo n.º 3
0
 /**
  * @Route ["/conference/{conferenceId}/sign-up","get"]
  * @Authorize
  */
 public function signUpForConference(int $conferenceId) : View
 {
     $model = new \Framework\ViewModels\Conference\GetConferenceViewModel();
     $userId = $this->httpContext->identity()->id;
     $conf = $this->db->findFirst("Conference", "id='{$conferenceId}'");
     if ($conf == false) {
         throw new \Exception("No such conference", 404);
     }
     if ($this->db->FindFirst("UserConference", "user_id='{$userId}' AND conference_id='{$conf->id}'") != false) {
         throw new \Exception("Already signed up");
     }
     $res = $this->db->Create("UserConference", array("user_id" => $userId, "conference_id" => $conferenceId));
     $res->save();
     $venue = $this->db->FindFirst("Venue", "id='{$conf->venue_id}'");
     $model->conferenceName = $conf->name;
     $model->conferenceId = $conf->id;
     $model->start = date('d/m/Y', strtotime($conf->start));
     $model->end = date('d/m/Y', strtotime($conf->end));
     $model->venue = $venue->name;
     $model->success = true;
     $model->successList[] = "You have successfully signed up for the conference";
     $model->isRegisteredFor = true;
     foreach ($this->db->FindAll("Lecture", "conference_id='{$conf->id}'") as $lecture) {
         $user = \Framework\Core\Identity::getUserInformation($lecture->user_id);
         $model->lectures[] = array('id' => $lecture->id, 'name' => $lecture->name, "start" => date('d/m/Y', strtotime($lecture->start)), "end" => date('d/m/Y', strtotime($lecture->end)), "speaker" => $user["firstname"] . " " . $user["lastname"]);
     }
     if (count($model->lectures) > 0) {
         $model->hasLectures = true;
     }
     return new View("\\Conference\\getConference", $model);
 }