Ejemplo n.º 1
0
 public function login(Request $request, Response $response, array $args)
 {
     $this->logger->info("Login page action dispatched");
     $username = null;
     $error = null;
     $urlRedirect = $request->getUri()->getBaseUrl() . $this->router->pathFor('homepage');
     //        if ($request->getAttribute('r') && $request->getAttribute('r') != '/logout' && $request->getAttribute('r') != '/login') {
     //            $_SESSION['urlRedirect'] = $request->getAttribute('r');
     //        }
     if (isset($_SESSION['urlRedirect'])) {
         $urlRedirect = $_SESSION['urlRedirect'];
         unset($_SESSION['urlRedirect']);
     }
     if ($request->isPost()) {
         $username = $request->getParam('username');
         $password = $request->getParam('password');
         $result = $this->authenticator->authenticate($username, $password);
         if ($result->isValid()) {
             //$error = $this->authenticator->getIdentity();
             return $response->withRedirect($urlRedirect);
         } else {
             $messages = $result->getMessages();
             $error = (string) $messages[0];
             //$this->flash->addMessage('flash', $error);
         }
     }
     $this->view->render($response, 'login.twig', ['username' => $username, 'error' => $error]);
     return $response;
 }
Ejemplo n.º 2
0
 public function dispatch(Request $request, Response $response, $args)
 {
     $speakers = $this->eventManager->getSpeakers();
     $venues = $this->eventService->getVenues();
     $supporters = $this->eventManager->getSupporters();
     $eventInfo = ['title' => '', 'description' => ''];
     if ($request->getParam('meetup_id')) {
         $event = $this->eventService->getEventById((int) $request->getParam('meetup_id'));
         if (!empty($event)) {
             $eventInfo['title'] = $event['subject'];
             $eventInfo['description'] = $event['description'];
             $eventInfo['venue_id'] = $event['venue_id'];
             $date = \DateTime::createFromFormat('F jS Y', $event['date']);
             $eventInfo['date'] = $date->format("d/m/Y");
         }
     }
     $errors = $this->flash->getMessage('event') ?? [];
     $frmErrors = [];
     if ($request->isPost()) {
         $validator = new EventValidator($_POST);
         try {
             $validator->talkValidation()->dateValidation();
             if (!$validator->isValid()) {
                 throw new \Exception('Form not valid.');
             }
             $event = new \App\Model\Event\Event(new Talk(strip_tags($request->getParam('talk_title'), '<p><a><br>'), strip_tags($request->getParam('talk_description'), '<p><img><a><br>'), $this->eventManager->getSpeakerById((int) $request->getParam('speaker'))), $request->getParam('start_date'), $request->getParam('start_time'), $this->eventService->getVenueById($request->getParam('venue')), $this->eventManager->getSupporterByID($request->getParam('supporter')));
             $this->eventService->createEvent($event);
             if (!$request->getParam('meetup_id')) {
                 if ((int) $this->eventService->createMeetup()->getStatusCode() !== 201) {
                     throw new \Exception('Could not create meetup event.');
                 }
             } else {
                 // Do not create a meetup
                 $this->eventService->getMeetupEvent()->setEventID((int) $request->getParam('meetup_id'));
             }
             if ((int) $this->eventService->createJoindinEvent($this->eventSettings['name'], $this->eventSettings['description'])->getStatusCode() !== 201) {
                 $this->flash->addMessage('event', 'Could not create Joindin event. Please try again.');
                 return $response->withStatus(302)->withHeader('Location', '/create-event?meetup_id=' . $this->eventService->getMeetupEvent()->getMeetupEventID());
             }
             if ((int) $this->eventService->createJoindinTalk()->getStatusCode() !== 201) {
                 // TODO
                 // Delete meetup event and JoindIn event just created.
                 throw new \Exception('Could not create Joindin talk.');
             }
             $eventEntity = $this->eventService->updateEvents();
             return $response->withStatus(302)->withHeader('Location', '/event/' . $eventEntity->getId());
         } catch (\Exception $e) {
             $frmErrors = $validator->getErrors();
             $errors[] = $e->getMessage();
         }
     }
     $nameKey = $this->csrf->getTokenNameKey();
     $valueKey = $this->csrf->getTokenValueKey();
     $name = $request->getAttribute($nameKey);
     $value = $request->getAttribute($valueKey);
     $this->view->render($response, 'admin/create-event.twig', ['speakers' => $speakers, 'venues' => $venues, 'eventInfo' => $eventInfo, 'supporters' => $supporters, 'nameKey' => $nameKey, 'valueKey' => $valueKey, 'name' => $name, 'value' => $value, 'errors' => $errors, 'frmErrors' => $frmErrors]);
     return $response;
 }
 /**
  * Get organization's relations action
  *
  * @param Request $request
  * @param Response $response
  * @param array $args
  *
  * @return Response
  */
 public function getRelationsAction(Request $request, Response $response, $args)
 {
     $name = $args['name'];
     $page = $this->getPage($request->getParam('page', 1));
     $count = $this->getCountPerPage($request->getParam('count', 10));
     $relations = $this->service->getRelations($name, $page, $count);
     $relations = $this->serializer->serialize($relations);
     return $response->withJson($relations);
 }
Ejemplo n.º 4
0
 public function dispatch(Request $request, Response $response, $args)
 {
     if (isset($args['callback']) && $args['callback'] === 'joindin') {
         // if logged in
         if ($this->auth->isLoggedIn() && strlen($request->getParam('access_token', '')) > 0) {
             // store token
             $this->fileRepository->save($this->auth->getUserId() . '_joindin', $request->getParam('access_token'));
         }
     }
     return $response->withStatus(302)->withHeader('Location', '/');
 }
 public function dispatch(Request $request, Response $response, $args)
 {
     if ($request->isPost()) {
         $speaker = new Speaker(null, $request->getParam('first_name'), $request->getParam('last_name'), new Email($request->getParam('email')), new Twitter($request->getParam('twitter')));
         $msg = [];
         try {
             $this->speakersRepository->save($speaker);
             $msg['id'] = $speaker->id;
         } catch (\Exception $e) {
             return $response->withStatus(200)->withHeader('Content-Type', 'application/json')->write(json_encode(['error' => $e->getMessage()]));
         }
         return $response->withStatus(201)->withHeader('Content-Type', 'application/json')->write(json_encode($msg));
     }
 }
Ejemplo n.º 6
0
 public function __invoke(Request $req, Response $res)
 {
     $school = $req->getAttribute('school', false);
     if (!$school) {
         return $res->withStatus(403, 'No school');
     }
     $teacherId = $req->getParam('teacher_id');
     $teacher = $this->staffService->getTeacherById($teacherId);
     if ($teacher['school_id'] !== $school->id) {
         return $res->withStatus(403, 'No school');
     }
     if ($req->isPost()) {
         $inputFilter = $this->inputFilter;
         $result = $inputFilter($req->getParams());
         if (!$result['is_valid']) {
             $res = $res->withStatus(422);
             $res = $res->withJson($result);
             return $res;
         }
         $this->service->saveAnswers($teacherId, $result['values']);
     }
     $data = $this->service->getAnswers($teacherId);
     $res = $res->withJson($data);
     return $res;
 }
 public function addPage(Request $request, Response $response, array $args)
 {
     $this->setPageTitle('Membership', 'Add new techno skill item');
     $skills = $this->data(Skills::class);
     $provinceId = $request->getParam('province_id');
     return $this->view->render('skills-add', ['skills_main' => array_pairs($skills->getParents(), 'skill_id', 'skill_name'), 'skills' => array_pairs($skills->getChilds($provinceId), 'skill_id', 'skill_name')]);
 }
Ejemplo n.º 8
0
 public function __invoke(Request $req, Response $res)
 {
     $school = $req->getAttribute('school');
     if ($req->isPost()) {
         $this->appFormInputFilter->setData(array_merge($req->getParams(), ['school_id' => $school->id, 'submitted_by' => $this->authService->getIdentity()->mail]));
         $isValid = $this->appFormInputFilter->isValid();
         if ($isValid) {
             $data = $this->appFormInputFilter->getValues();
             $appForm = $this->appFormService->submit($data);
             $_SESSION['applicationForm']['appForm'] = $appForm;
             $res = $res->withRedirect($this->successUrl);
             return $res;
         }
         $this->view['form'] = ['is_valid' => $isValid, 'values' => $this->appFormInputFilter->getValues(), 'raw_values' => $this->appFormInputFilter->getRawValues(), 'messages' => $this->appFormInputFilter->getMessages()];
     }
     $loadForm = (bool) $req->getParam('load', false);
     $this->view['choose'] = !$loadForm && !$req->isPost();
     if (!$req->isPost() && $loadForm) {
         if (null !== ($appForm = $this->appFormService->findSchoolApplicationForm($school->id))) {
             $this->view['form'] = ['values' => $appForm];
         }
     }
     $labs = $this->labService->getLabsBySchoolId($school->id);
     $res = $this->view->render($res, 'application_form/form.twig', ['lab_choices' => array_map(function ($lab) {
         return ['value' => $lab['id'], 'label' => $lab['name']];
     }, $labs), 'type_choices' => array_map(function ($category) {
         return ['value' => $category['id'], 'label' => $category['name']];
     }, $this->assetsService->getAllItemCategories())]);
     return $res;
 }
Ejemplo n.º 9
0
 public function __invoke(Request $req, Response $res)
 {
     if ($req->isPost()) {
         $adapter = $this->authService->getAdapter();
         if ($adapter instanceof ValidatableAdapterInterface) {
             $adapter->setIdentity($req->getParam('identity'));
             $adapter->setCredential($req->getParam('credential'));
         }
         $result = $this->authService->authenticate($adapter);
         if (!$result->isValid()) {
             $this->flash->addMessage('danger', reset($result->getMessages()));
             return $res->withRedirect($req->getUri());
         }
         return $res->withRedirect($this->successUrl);
     }
     return $this->view->render($res, 'user/login.twig', []);
 }
 public function registerPage(Request $request, Response $response, array $args)
 {
     $this->enableCaptcha();
     $this->setPageTitle('Membership', 'Registrasi Anggota');
     $this->view->addData(['helpTitle' => 'Bantuan Register?', 'helpContent' => ['Sudah pernah terdaftar menjadi anggota PHP Indonesia, silahkan <a href="' . $this->router->pathFor('membership-login') . '" title="">Login Disini', 'Hilang atau lupa password login, silahkan <a href="' . $this->router->pathFor('membership-forgot-password') . '" title="">Reset Password</a> Anda.']], 'layouts::account');
     $regionals = $this->data(Regionals::class);
     $provinceId = $request->getParam('province_id');
     return $this->view->render('home-register', ['provinces' => array_pairs($regionals->getProvinces(), 'id', 'regional_name'), 'cities' => array_pairs($regionals->getCities($provinceId), 'id', 'regional_name'), 'jobs' => array_pairs($this->data(Careers::class)->getJobs(), 'job_id')]);
 }
Ejemplo n.º 11
0
 public function __invoke(Request $req, Response $res)
 {
     $school = $req->getAttribute('school', false);
     if (!$school) {
         return $res->withStatus(403, 'No school');
     }
     $this->service->setTotalTeachers($school->id, (int) $req->getParam('total_teachers', 0));
     return $res->withStatus(204);
 }
Ejemplo n.º 12
0
 /**
  * Invoke controller.
  *
  * @param Request  $request  The most recent Request object
  * @param Response $response The most recent Response object
  * @param array    $args
  *
  * @return Response
  * @throws Exception
  */
 public function __invoke(Request $request, Response $response, array $args)
 {
     $method = $args['method'];
     $settings = $this->settings['test'];
     if ($settings['always'] || $request->getParam($settings['key']) == $settings['value']) {
         if (method_exists($this, $method)) {
             return $this->{$method}($request, $response);
         }
     }
     return $this->notFound($request, $response);
 }
Ejemplo n.º 13
0
 public function dispatch(Request $request, Response $response, $args)
 {
     $meetupID = $request->getParam('meetup_id', false);
     if (!$meetupID) {
         $eventDetails['errors'][] = 'A meetup ID needs to be provided.';
     } else {
         $eventDetails = ['meetup_event' => $this->eventService->getEventById($meetupID), 'event_info' => $this->eventService->getEventInfo($meetupID)];
     }
     $this->view->render($response, 'admin/event-info.twig', $eventDetails);
     return $response;
 }
Ejemplo n.º 14
0
 public function editUser(Request $request, Response $response, array $args)
 {
     $username = strtolower($args['username']);
     if (empty($username)) {
         $this->flash->addMessage('flash', 'No user specified');
         return $response->withRedirect($this->router->pathFor('profile'));
     }
     $id = $this->authenticator->getIdentity();
     // restrict access to own profile or Admin user
     if ($username != strtolower($id['name'])) {
         if (strtolower($id['name']) != 'admin') {
             $this->flash->addMessage('flash', 'Access Denied');
             return $response->withRedirect($this->router->pathFor('profile'));
         }
     }
     if ($username != 'new') {
         $user = R::findOrCreate('users', ['name' => $username]);
     } else {
         $user = R::dispense('users');
     }
     if ($request->isPost()) {
         $data = $request->getParams();
         //$username = $request->getParam('username');
         $user->import($data, 'fullname,shortdial,longdial,colour,mobile,home');
         $user->name = $request->getParam('username');
         $password = $request->getParam('password');
         if (!empty($password)) {
             $pass = password_hash($password, PASSWORD_DEFAULT);
             $user->hash = $pass;
         }
         $id = R::store($user);
         $this->flash->addMessage('flash', "{$user->name} updated");
         return $response->withRedirect($this->router->pathFor('edituser', ['username' => $username]));
         //            $member = 'INSERT INTO `users` (`name`, `fullname`, `password`, `hash`, `colour`, `shortdial`, `longdial`, `mobile`, `home`, `ins_mf`, `ins_win`, `health_mf`, `health_win`, `life_mf`, `life_win`, `wealth_mf`, `wealth_win`, `uk_shift`, `atss`) VALUES '
         //                . "($username, $fullname, :pass, '', 'FAD2F5', $shortdial, $longdial, '', '', '1', '0', '0', '1', '0', '0', '0', '1', '0', '0');
         //                ";
     }
     $this->view->render($response, 'user.twig', $user->export());
     return $response;
 }
Ejemplo n.º 15
0
 public function dispatch(Request $request, Response $response, $args)
 {
     // CSRF token name and value
     $nameKey = $this->csrf->getTokenNameKey();
     $valueKey = $this->csrf->getTokenValueKey();
     $name = $request->getAttribute($nameKey);
     $value = $request->getAttribute($valueKey);
     $email = '';
     $msg = '';
     if ($request->isPost()) {
         $email = $request->getParam('email');
         $password = $request->getParam('password');
         if ($this->auth->isValid($email, $password)) {
             $this->auth->store();
             return $response->withStatus(302)->withHeader('Location', '/');
         } else {
             $msg = 'Incorrect email or password.';
         }
     }
     $this->view->render($response, 'login.twig', ['nameKey' => $nameKey, 'valueKey' => $valueKey, 'name' => $name, 'value' => $value, 'email' => $email, 'msg' => $msg]);
     return $response;
 }
Ejemplo n.º 16
0
 /**
  * @param Request $request
  * @param Response $response
  * @param $args
  * @return Response
  */
 public function dispatch(Request $request, Response $response, $args)
 {
     $data = [];
     if ($request->isPost()) {
         $magnetUri = $request->getParam('magnetUri');
         if ($magnetUri) {
             $torrent = Torrent::fromMagnet($magnetUri);
             $data['torrent'] = $torrent;
             $data['torrentLink'] = (new Torcache())->getDownloadUrl($torrent);
         }
     }
     $this->view->render($response, 'home.twig', $data);
     return $response;
 }
Ejemplo n.º 17
0
 public function editUser(Request $request, Response $response, array $args)
 {
     $username = $args['username'];
     if (empty($username)) {
         $this->flash->addMessage('flash', 'No user specified');
         return $response->withRedirect($request->getUri()->getBaseUrl() . $this->router->pathFor('profile'));
     }
     $username = base64_decode($username);
     $id = $this->authenticator->getIdentity();
     // restrict access to own profile or Admin role
     if ($username != strtolower($id['email'])) {
         if (strtolower($id['role']) != 'admin') {
             $this->flash->addMessage('flash', 'Access Denied');
             return $response->withRedirect($request->getUri()->getBaseUrl() . $this->router->pathFor('profile'));
         }
     }
     $user = R::findOne('users', ' email = ? ', [$username]);
     if ($user == NULL) {
         $user = R::dispense('users');
     }
     if ($request->isPost()) {
         $user->fullname = $request->getParam('userfullname');
         $user->email = $request->getParam('username');
         $password = $request->getParam('userpassword');
         if (!empty($password)) {
             $pass = password_hash($password, PASSWORD_DEFAULT);
             $user->hash = $pass;
         }
         $id = R::store($user);
         $this->flash->addMessage('flash', "{$user->name} updated");
         return $response->withRedirect($request->getUri()->getBaseUrl() . $this->router->pathFor('edituser', ['username' => base64_encode($username)]));
     }
     $expUser['user'] = $user->export();
     $expUser['user']['hashemail'] = base64_encode($user['email']);
     $this->view->render($response, 'user.twig', $expUser);
     return $response;
 }
Ejemplo n.º 18
0
 public function editUser(Request $request, Response $response, array $args)
 {
     $username = strtolower($args['username']);
     if (empty($username)) {
         $this->flash->addMessage('flash', 'No user specified');
         return $response->withRedirect($request->getUri()->getBaseUrl() . $this->router->pathFor('profile'));
     }
     $id = $this->authenticator->getIdentity();
     // restrict access to own profile or Admin user
     if ($username != strtolower($id['name'])) {
         if (strtolower($id['name']) != 'admin') {
             $this->flash->addMessage('flash', 'Access Denied');
             return $response->withRedirect($request->getUri()->getBaseUrl() . $this->router->pathFor('profile'));
         }
     }
     if ($username != 'new') {
         $user = R::findOrCreate('users', ['name' => $username]);
     } else {
         $user = R::dispense('users');
     }
     if ($request->isPost()) {
         $data = $request->getParams();
         //$username = $request->getParam('username');
         $user->import($data, 'fullname,colour,mobile,home');
         $user->name = $request->getParam('username');
         $password = $request->getParam('password');
         if (!empty($password)) {
             $pass = password_hash($password, PASSWORD_DEFAULT);
             $user->hash = $pass;
         }
         $id = R::store($user);
         $this->flash->addMessage('flash', "{$user->name} updated");
         return $response->withRedirect($request->getUri()->getBaseUrl() . $this->router->pathFor('edituser', ['username' => $username]));
     }
     $this->view->render($response, 'user.twig', $user->export());
     return $response;
 }
Ejemplo n.º 19
0
 public function actionUpdate(Request $request)
 {
     if (!Oauth::isLogged()) {
         return $this->goBack();
     }
     /* @var $model Unit */
     $model = Unit::find($request->getAttribute('id'));
     if ($request->isXhr()) {
         return $this->renderAjax('unit/ajax/modal', ['model' => $model]);
     }
     $model->addTagsToUnit($request->getParam('tags'));
     $model->fill($request->getParams());
     if ($model->validate() && $model->save()) {
         Alert::add("Successful update {$model->name}");
     }
     return $this->goBack();
 }
Ejemplo n.º 20
0
 public function __invoke(Request $req, Response $res)
 {
     $school = $req->getAttribute('school', false);
     if (!$school) {
         return $res->withStatus(403, 'No school');
     }
     $lab_id = $req->getParam('lab_id', false);
     if (!$lab_id) {
         return $res->withStatus(404, 'No lab id');
     }
     $lab = $this->labService->getLabForSchool($school->id, $lab_id);
     try {
         $this->labService->removeLabAttachment($lab['id']);
         return $res->withStatus(204);
     } catch (Exception $ex) {
         return $res->withStatus(500, $ex->getMessage());
     }
 }
Ejemplo n.º 21
0
 public function __invoke(Request $req, Response $res)
 {
     $school = $req->getAttribute('school', false);
     if (!$school->id) {
         return $res->withStatus(403, 'No school');
     }
     $id = $req->getParam('id', false);
     if (!$id) {
         $res = $res->withStatus(404);
         return $res;
     }
     try {
         $this->schoolAssetsService->removeAssetFromSchool($school->id, $id);
         $res = $res->withStatus(204);
     } catch (Exception $ex) {
         $res = $res->withStatus(500, $ex->getMessage());
     }
     return $res;
 }
Ejemplo n.º 22
0
 public function __invoke(Request $req, Response $res)
 {
     $school = $req->getAttribute('school', false);
     if (!$school) {
         return $res->withStatus(403, 'No school');
     }
     $lab_id = $req->getParam('lab_id', false);
     if (!$lab_id) {
         return $res->withStatus(404, 'No lab id');
     }
     $lab = $this->labService->getLabForSchool($school->id, $lab_id);
     if ($lab['attachment'] && is_readable($this->uploadDir . '/' . $lab['attachment'])) {
         $contents = file_get_contents($this->uploadDir . '/' . $lab['attachment']);
         $contentType = $lab['attachment_mime'] ? $lab['attachment_mime'] : 'application/octet-stream';
         $res = $res->withHeader('Content-Type', $contentType);
         $res = $res->withHeader('Content-Disposition', 'filename="' . basename($lab['attachment']) . '"');
         $res->getBody()->write($contents);
     } else {
         $res->withStatus(404, 'No attachment');
     }
     return $res;
 }
Ejemplo n.º 23
0
 public function dispatch(Request $request, Response $response, $args)
 {
     // ONLY WHEN CALLED THROUGH CLI
     if (PHP_SAPI !== 'cli') {
         return $response->withStatus(404)->withHeader('Location', '/404');
     }
     if (!$request->getParam('event')) {
         return $response->withStatus(404)->withHeader('Location', '/404');
     }
     // Default UserID for the required auth token
     $userID = 1;
     // Create talks for approved events
     try {
         $result = $this->eventsService->manageApprovedEvents($userID);
         $this->logger->info(__CLASS__ . ' :: ' . $result);
         echo $result;
         echo PHP_EOL;
     } catch (\Exception $e) {
         echo __CLASS__ . ' :: ERROR :: ' . $e->getMessage() . PHP_EOL;
         $this->logger->alert(__CLASS__ . ' :: ' . $e->getMessage());
     }
     exit;
 }
Ejemplo n.º 24
0
 public function __invoke(Request $req, Response $res)
 {
     $school = $req->getAttribute('school', false);
     if (!$school->id) {
         return $res->withStatus(403, 'No school');
     }
     $id = $req->getParam('id', false);
     if (!$id) {
         $res = $res->withStatus(404);
         return $res;
     }
     $software = $this->softwareService->getSoftwareById($id);
     if ($software['school_id'] != $school->id) {
         $res = $res->withStatus(403, 'Schools not match');
         return $res;
     }
     try {
         $this->softwareService->removeSoftware($id);
         $res = $res->withStatus(204);
     } catch (Exception $ex) {
         $res = $res->withStatus(500, $ex->getMessage());
     }
     return $res;
 }
Ejemplo n.º 25
0
 public function __invoke(Request $req, Response $res)
 {
     $school = $req->getAttribute('school');
     if ($req->isPost()) {
         $reqParams = $req->getParams();
         array_splice($reqParams['items'], 0, 0);
         $this->appFormInputFilter->setData(array_merge($reqParams, ['school_id' => $school->id, 'submitted_by' => $this->authService->getIdentity()->mail]));
         $isValid = $this->appFormInputFilter->isValid();
         if ($isValid) {
             $data = $this->appFormInputFilter->getValues();
             $appForm = $this->appFormService->submit($data);
             $_SESSION['applicationForm']['appForm'] = $appForm;
             $res = $res->withRedirect($this->successUrl);
             return $res;
         }
         $this->view['form'] = ['is_valid' => $isValid, 'values' => $this->appFormInputFilter->getValues(), 'raw_values' => $this->appFormInputFilter->getRawValues(), 'messages' => $this->appFormInputFilter->getMessages()];
     }
     $loadForm = (bool) $req->getParam('load', false);
     $this->view['choose'] = !$loadForm && !$req->isPost();
     if (!$req->isPost() && $loadForm) {
         // take care of new options in applications and migrate existing ones
         if (null !== ($appForm = $this->appFormService->findSchoolApplicationForm($school->id))) {
             /**
              * Do mapping of old items to new only if items do exist (old form) 
              * and the map is available at the app settings.
              * TODO: Only one version migrations are supported. If the old items are
              * two or more versions older, they will not be handled.
              */
             // get the existing (db) application form version
             $items_version = $this->version;
             if (isset($appForm['items']) && \count($appForm['items']) > 0) {
                 $items_version = array_values($appForm['items'])[0]['version'];
             }
             if ($this->version != $items_version && isset($appForm['items']) && isset($this->container['settings']['application_form']['itemcategory']['map']) && $this->container['settings']['application_form']['itemcategory']['map']['fromversion'] == $items_version && $this->container['settings']['application_form']['itemcategory']['map']['toversion'] == $this->version && isset($this->container['settings']['application_form']['itemcategory']['map']['items'])) {
                 // if map exists for this version, use it
                 $items_map = $this->container['settings']['application_form']['itemcategory']['map']['items'];
                 $appForm['items'] = array_map(function ($item) use($items_map) {
                     $migrate_values = [];
                     if (isset($items_map[$item['itemcategory_id']]) && intval($items_map[$item['itemcategory_id']]) > 0) {
                         $migrate_values = ['itemcategory_prev' => $item['itemcategory_id'], 'itemcategory_id_prev' => $item['itemcategory_id'], 'itemcategory_id' => intval($items_map[$item['itemcategory_id']])];
                     } else {
                         $migrate_values = ['itemcategory_prev' => '', 'itemcategory_id_prev' => -1];
                     }
                     $migrate_values['prev_form_load'] = true;
                     return array_merge($item, $migrate_values);
                 }, $appForm['items']);
             } elseif ($this->version != $items_version && isset($appForm['items']) && isset($this->container['settings']['application_form']['itemcategory']['map']) && ($this->container['settings']['application_form']['itemcategory']['map']['fromversion'] != $items_version || $this->container['settings']['application_form']['itemcategory']['map']['toversion'] != $this->version)) {
                 // if map does not exist for this version, notify user
                 $items_map = $this->container['settings']['application_form']['itemcategory']['map']['items'];
                 $appForm['items'] = array_map(function ($item) use($items_map) {
                     $migrate_values = ['itemcategory_prev' => '', 'itemcategory_id_prev' => -2, 'prev_form_load' => true];
                     return array_merge($item, $migrate_values);
                 }, $appForm['items']);
             }
             $this->view['form'] = ['values' => $appForm];
         }
     }
     $labs = $this->labService->getLabsBySchoolId($school->id);
     $res = $this->view->render($res, 'application_form/form.twig', ['lab_choices' => array_map(function ($lab) {
         return ['value' => $lab['id'], 'label' => $lab['name']];
     }, $labs), 'type_choices' => array_map(function ($category) {
         return ['value' => $category['id'], 'label' => $category['name']];
     }, $this->assetsService->getAllItemCategories($this->version))]);
     return $res;
 }
Ejemplo n.º 26
0
 private function editAlbum(Request $request, Response $response)
 {
     $queryParams = $request->getQueryParams();
     if (isset($queryParams['id'])) {
         /* @var \App\models\Album $album */
         $album = $this->model->load('Album');
         $output = $album->filter(['id' => $queryParams['id'], 'user_id' => $this->user['id']])->fetch();
         if ($output) {
             $output['action'] = self::ACTION_EDIT;
             $output['isPublicOptions'] = $album->getIsPublicOptions();
             $output['photoId'] = $request->getParam('pid', 0);
             return $this->renderer->render($response, 'admin/edit_album.html', $output);
         } else {
             return $response->withStatus(302)->withHeader('Location ', $this->router->pathFor('admin_index'));
         }
     } else {
         return $response->withStatus(302)->withHeader('Location ', $this->router->pathFor('admin_index'));
     }
 }
Ejemplo n.º 27
0
 /**
  * @param Request $request
  * @param Response $response
  * @return Response
  */
 public function read(Request $request, Response $response)
 {
     $url = $request->getParam('url');
     $feed = $this->getFeedIo()->read($url)->getFeed();
     return $response->withJson($feed, 200);
 }
Ejemplo n.º 28
0
 /**
  * @param Request $req
  * @param Response $res
  * @param $args
  * @throws \InvalidArgumentException
  * @return Response
  */
 public function createUser(Request $req, Response $res, $args)
 {
     $newUser = ['id' => (int) $req->getParam('id'), 'name' => $req->getParam('name')];
     //simple validation
     if (empty($newUser['id']) || !is_int($newUser['id']) || empty($newUser['name'])) {
         throw new \InvalidArgumentException('Id and name are required');
     }
     $user = $this->friendship->createUser($newUser);
     return $this->view->render($res, $user);
 }
Ejemplo n.º 29
0
 public function postDebug(Request $request, Response $response, $args)
 {
     $res = ["body" => $request->getBody(), "pa" => $request->getParsedBody(), "params" => $request->getParams(), "name" => $request->getParam('name')];
     return $this->echoJson($response, $res);
 }
Ejemplo n.º 30
0
 public function change(Request $request, Response $response, array $args)
 {
     $this->logger->info("Oncall Change page action dispatched");
     $rota = strtolower($args['rota']);
     $display = 6;
     $name = $request->getParam('name', '');
     $prev = $request->getParam('prev', 0);
     $day = $request->getParam('day');
     $month = $request->getParam('month');
     $monthObj = \DateTime::createFromFormat('!m', $month);
     $monthName = $monthObj->format('F');
     $year = $request->getParam('year');
     $title = "Please select who is oncall for - {$day} {$monthName} {$year}";
     if (!empty($name)) {
         $rotaUser = R::findOne('users', ' name = :username ', ['username' => $name]);
         if (empty($rotaUser)) {
             $this->flash->addMessage('flash', "{$name} not found");
             return $response->withRedirect($this->router->pathFor('oncall', ['rota' => $rota]));
         }
         $oldDay = (int) $day;
         $oldMonth = (int) $month;
         $oldYear = (int) $year;
         $whatDay = 8 - date('w', mktime(0, 0, 0, $oldMonth, $oldDay, $oldYear));
         if ($whatDay == 8 || $request->getParam('allweek') == null) {
             $whatDay = 1;
         }
         for ($x = 0; $x < $whatDay; $x++) {
             $day = date('j', mktime(0, 0, 0, $oldMonth, $oldDay + $x, $oldYear));
             $month = date('n', mktime(0, 0, 0, $oldMonth, $oldDay + $x, $oldYear));
             $year = date('Y', mktime(0, 0, 0, $oldMonth, $oldDay + $x, $oldYear));
             $rotaDay = R::findOrCreate($rota, ['day' => $day, 'month' => $month, 'year' => $year]);
             $rotaDay->name = $rotaUser;
             $id = $this->authenticator->getIdentity();
             $whoUser = R::load('users', $id['id']);
             $rotaDay->who = $whoUser;
             $rotaDay->stamp = date("Y-m-d H:i:s");
             R::store($rotaDay);
         }
         $this->flash->addMessage('flash', "Rota updated");
         return $response->withRedirect($this->router->pathFor('oncall', ['rota' => $rota]));
     }
     $rotaBean = R::findOne('rotas', ' name = :name ', [':name' => $rota]);
     if (empty($rotaBean)) {
         $this->flash->addMessage('flash', "sorry {$rota} not found");
         return $response->withRedirect($this->router->pathFor('homepage'));
     }
     $userlist = [];
     $users = $rotaBean->sharedUsersList;
     foreach ($users as $user) {
         $userlist[] = ['colour' => $user['colour'], 'linkday' => '<a href="?name=' . $user['name'] . "&day={$day}&month={$month}&year={$year}\">" . $user['fullname'] . "</a>", 'linkweek' => '<a href="?name=' . $user['name'] . "&day={$day}&month={$month}&year={$year}&allweek=Y\">" . $user['fullname'] . "</a>"];
     }
     $this->view->render($response, 'change.twig', ['rota' => $rota, 'title' => $title, 'userlist' => $userlist]);
     return $response;
 }