Пример #1
4
 public function __invoke(Request $req, Response $res)
 {
     $school = $req->getAttribute('school');
     $appForm = $this->appFormService->findSchoolApplicationForm($school->id);
     if (null === $appForm) {
         return $res->withStatus(404);
     }
     $html = $this->view->fetch('application_form/pdf.twig', ['school' => $school, 'appForm' => $appForm, 'logo' => base64_encode(file_get_contents(__DIR__ . '/../../public/img/application_form/minedu_logo.jpg')), 'style' => file_get_contents(__DIR__ . '/../../public/css/application_form/pdf.css')]);
     $pdf = new \Dompdf\Dompdf(['default_paper_size' => 'A4', 'default_font' => 'DejaVu Sans', 'isHtml5ParserEnabled' => true, 'is_remote_enabled' => false]);
     $pdf->loadHtml($html);
     $pdf->render();
     $filename = 'edulabs_app_form_' . $appForm['id'] . '.pdf';
     $str = $pdf->output();
     $length = mb_strlen($str, '8bit');
     return $res->withHeader('Cache-Control', 'private')->withHeader('Content-type', 'application/pdf')->withHeader('Content-Length', $length)->withHeader('Content-Disposition', 'attachment;  filename=' . $filename)->withHeader('Accept-Ranges', $length)->write($str);
 }
Пример #2
1
 /**
  * {@inheritDoc}
  */
 public function register(Container $container)
 {
     // Append custom settings with missing params from default settings
     $container['settings']['view'] = self::mergeWithDefaultSettings($container['settings']['view']);
     /**
      * Add dependency (DI).
      *
      * @param Container $c
      *
      * @return Twig
      */
     $container['view'] = function (Container $c) {
         $settings = $c['settings']['view'];
         $path = rtrim($settings['path'], '/') . '/';
         $view = new Twig($path, $settings['options']);
         $view->addExtension(new TwigExtension($c['router'], $c['request']->getUri()));
         $view->addExtension(new \Twig_Extension_Debug());
         // Add extensions (must be loaded via e. g. composer)
         foreach ($settings['extensions'] as $extension) {
             $extension = is_callable($extension) ? $extension() : new $extension();
             $view->addExtension($extension);
         }
         return $view;
     };
 }
 public function __invoke(ContainerInterface $ci)
 {
     $settings = $ci->get('settings');
     $view = new Twig($settings['twig']['view_path'], $settings['twig']['settings']);
     $view->addExtension(new TwigExtension($ci['router'], $ci['request']->getUri()));
     return $view;
 }
Пример #4
0
 public function dispatch($request, $response, $args)
 {
     $event = $this->eventService->getLatestEvent();
     $filter = $this->contentService->getTwigFilter();
     $this->view->getEnvironment()->addFilter($filter);
     $this->view->render($response, 'home.twig', ['event' => $event]);
     return $response;
 }
Пример #5
0
 private function registerTwig()
 {
     $this->registerService('Twig', function ($container) {
         $view = new Twig(__DIR__ . '/../views', ['cache' => false]);
         $view->addExtension(new TwigExtension($container->get('router'), $container->get('request')->getUri()));
         return $view;
     });
 }
Пример #6
0
 public function __invoke(Request $req, Response $res)
 {
     try {
         return $this->view->render($res, 'index.twig', ['content' => $this->content]);
     } catch (\Exception $ex) {
         return $this->view->render($res, 'index.twig', ['content' => 'welcome']);
     }
 }
Пример #7
0
 public function setView(\Slim\Views\Twig $view)
 {
     $slimFormTemplatePath = realpath(implode(DIRECTORY_SEPARATOR, array(__DIR__, '..', 'templates')));
     $view->getInstance()->addExtension(new \SlimForm\Twig\Extension());
     $loader = $view->getInstance()->getLoader()->addPath($slimFormTemplatePath);
     $this->_view = $view;
     return $this;
 }
 public function dispatch($request, $response, $args)
 {
     $events = $this->eventService->getAll();
     $speakers = $this->eventManager->getSpeakers();
     $venues = $this->eventService->getVenues();
     $this->eventService->mergeEvents($events, $speakers, $venues);
     $this->view->render($response, 'admin/dashboard.twig', ['events' => $events]);
     return $response;
 }
Пример #9
0
 public function __invoke(ServerRequestInterface $request, ResponseInterface $response)
 {
     $id = $request->getAttribute('id');
     if (!($comment = $this->repository->find($id))) {
         return $response->withStatus(404, 'post not found');
     }
     $this->view->render($response, 'post.phtml', ['comment' => new CommentViewModel($comment)]);
     return $response;
 }
 /**
  * @param Request $request
  * @param Response $response
  * @return Response
  */
 public function saveAction(Request $request, Response $response) : Response
 {
     $service = new FieldService();
     $entity = (new SampleEntity())->setOne((new Field())->setId(1)->setValue(8))->setTwo($service->getFieldGroup(2))->setThree($service->getFieldGroup(3))->setFour((new Field())->setId(4)->setValue(123));
     $form = $this->formFactory->create(SampleType::class, $entity);
     $form->submit($request->getParams())->isValid();
     $bla = 0;
     return $this->view->render($response, 'field/index.html.twig', ['form' => $form->createView()]);
 }
Пример #11
0
 public function testRender()
 {
     $mockBody = $this->getMockBuilder('Psr\\Http\\Message\\StreamInterface')->disableOriginalConstructor()->getMock();
     $mockResponse = $this->getMockBuilder('Psr\\Http\\Message\\ResponseInterface')->disableOriginalConstructor()->getMock();
     $mockBody->expects($this->once())->method('write')->with("<p>Hi, my name is Josh.</p>\n")->willReturn(28);
     $mockResponse->expects($this->once())->method('getBody')->willReturn($mockBody);
     $response = $this->view->render($mockResponse, 'example.html', ['name' => 'Josh']);
     $this->assertInstanceOf('Psr\\Http\\Message\\ResponseInterface', $response);
 }
Пример #12
0
 public function dispatch($request, $response, $args)
 {
     $event = $this->eventService->getLatestEvent();
     $filter = $this->contentService->getTwigFilter();
     $this->view->getEnvironment()->addFilter($filter);
     $previousEvents = $this->eventService->getPastEvents();
     $resWithETag = $this->cache->withETag($response, $event->getMeetupID());
     $this->view->render($response, 'home.twig', ['event' => $event, 'previousEvents' => $previousEvents]);
     return $resWithETag;
 }
Пример #13
0
 public function registerDi()
 {
     $this->container['view'] = function ($c) {
         $view = new Twig(APP_PATH . 'templates');
         // Instantiate and add Slim specific extension
         $view->addExtension(new TwigExtension($c['router'], $c['request']->getUri()));
         $view->addExtension(new \Twig_Extension_Debug());
         return $view;
     };
 }
Пример #14
0
 /**
  * Register Twig Service Provider
  *
  * @param Container $container
  */
 public function register(Container $container)
 {
     $config = $this->getConfig($container->get('settings'));
     $container['view'] = function (Container $container) use($config) {
         $engine = new Twig($config['template_path'], $config['twig']);
         // Add extensions
         $engine->addExtension(new TwigExtension($container->get('router'), $container->get('request')->getUri()));
         $engine->addExtension(new \Twig_Extension_Debug());
         return $engine;
     };
 }
Пример #15
0
 public function eventByYearMonth(Request $request, Response $response, $args)
 {
     $year = intval($args["year"]);
     $month = intval($args["month"]);
     $eventMeta = $this->eventManager->getByYearMonth($year, $month);
     $event = $this->eventService->getEventById($eventMeta[0]['meetup_id']);
     $resWithETag = $this->cache->withETag($response, $eventMeta[0]['meetup_id']);
     $previousEvents = $this->eventService->getPastEvents();
     $this->view->render($response, 'event.twig', ['event' => $event, 'eventMeta' => $eventMeta[0], 'previousEvents' => $previousEvents]);
     return $resWithETag;
 }
Пример #16
0
 public function register(ContainerInterface $container)
 {
     $config = $this->getConfig();
     $container['view'] = function ($container) use($config) {
         $view = new Twig($config['template_path'], $config['twig']);
         // Add extensions
         $view->addExtension(new TwigExtension($container['router'], $container['request']->getUri()));
         $view->addExtension(new \Twig_Extension_Debug());
         return $view;
     };
 }
Пример #17
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;
 }
Пример #18
0
 /**
  * Register DI container in slim framework
  */
 public function registerDi()
 {
     $this->container['flash'] = function () {
         return new Messages();
     };
     $this->container['view'] = function ($c) {
         $view = new Twig($c->config['view']['template_path'], $c->config['view']['twig']);
         // Instantiate and add Slim specific extension
         $view->addExtension(new TwigExtension($c['router'], $c['request']->getUri()));
         $view->addExtension(new \Twig_Extension_Debug());
         return $view;
     };
 }
Пример #19
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;
 }
Пример #20
0
 /**
  * Register twig view in Slim container
  *
  * @return Shiniwork $this
  */
 protected function registerView()
 {
     $container = $this->getContainer();
     $settings = $container->get('settings');
     if (!empty($settings['view']) && !empty($settings['view']['twig'])) {
         $container['view'] = function ($c) {
             $view = new Twig($c->getRootPath() . trim($c->settings['view']['template_path'], '/'), $c->settings['view']['twig']);
             $view->addExtension(new TwigExtension($c['router'], $c['request']->getUri()));
             $view->addExtension(new \Twig_Extension_Debug());
             return $view;
         };
     }
     return $this;
 }
 public function authenticateCallback(Request $request, Response $response)
 {
     $code = $request->getQueryParams()['code'] ?? '';
     try {
         if (!$code) {
             throw new \Exception('No access code provided.');
         }
         $token = $this->provider->getAccessToken('authorization_code', ['code' => $_GET['code']]);
         $this->helper->setAccessToken(['access_token' => $token->getToken(), 'expires' => $token->getExpires()]);
         return $response->withStatus(301)->withHeader('Location', '/' . self::AREA);
     } catch (\Exception $ex) {
         return $this->view->render($response, 'error.twig', ['error' => $ex->getMessage()]);
     }
 }
 /**
  * @param Request $request
  * @param Response $response
  * @param array $arguments
  * @return Response
  */
 public function add(Request $request, Response $response, array $arguments)
 {
     $settings = $request->getAttribute('settings');
     $root = rtrim($settings['root'], '/\\') . DIRECTORY_SEPARATOR;
     $virtualHost = trim($arguments['virtualHost'], '/\\') . DIRECTORY_SEPARATOR;
     $absolutePath = $root . $virtualHost;
     if (!@is_dir($absolutePath)) {
         throw new \InvalidArgumentException('Wrong path provided', 1461609455);
     }
     $folders = isset($settings['virtual-hosts'][$virtualHost]['add']['allow']) ? $settings['virtual-hosts'][$virtualHost]['add']['allow'] : isset($settings['virtual-hosts']['default']['add']['allow']) ? $settings['virtual-hosts']['default']['add']['allow'] : [];
     if (!empty($folders)) {
         array_walk($folders, function (&$value) {
             $value = ['relativePathname' => trim($value, '\\/')];
         });
     } else {
         $depth = isset($settings['virtual-hosts'][$virtualHost]['show']['depth']) ? $settings['virtual-hosts'][$virtualHost]['show']['depth'] : $settings['virtual-hosts']['default']['show']['depth'];
         $folders = new Finder();
         $folders->directories()->ignoreUnreadableDirs(true)->ignoreDotFiles(true)->ignoreVCS(true)->followLinks()->depth($depth)->sort(function (SplFileInfo $a, SplFileInfo $b) {
             return strcmp($a->getRelativePathname(), $b->getRelativePathname());
         })->in($absolutePath);
         $excludeShowDirs = isset($settings['virtual-hosts'][$virtualHost]['show']['exclude']) ? $settings['virtual-hosts'][$virtualHost]['show']['exclude'] : isset($settings['virtual-hosts']['default']['show']['exclude']) ? $settings['virtual-hosts']['default']['show']['exclude'] : [];
         $excludeAddDirs = isset($settings['virtual-hosts'][$virtualHost]['add']['exclude']) ? $settings['virtual-hosts'][$virtualHost]['add']['exclude'] : isset($settings['virtual-hosts']['default']['add']['exclude']) ? $settings['virtual-hosts']['default']['add']['exclude'] : [];
         foreach (array_merge($excludeShowDirs, $excludeAddDirs) as $dir) {
             $folders->notPath(strtr($dir, '\\', '/'));
         }
     }
     $this->view->render($response, 'add.twig', ['settings' => $settings, 'root' => $root, 'virtualHost' => $virtualHost, 'folders' => $folders]);
     return $response;
 }
Пример #23
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;
 }
Пример #24
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', []);
 }
Пример #25
0
 public function __invoke(Request $req, Response $res, array $args = [])
 {
     $school = $req->getAttribute('school', false);
     if (!$school) {
         return $res->withStatus(403, 'No school');
     }
     $assets = $this->schoolAssetsService->getAssetsForSchool($school->id);
     $itemCategories = $this->assetsService->getAllItemCategories();
     $labs = $this->labService->getLabsBySchoolId($school->id);
     return $this->view->render($res, 'schools/assets.twig', ['school' => $school, 'assets' => $assets, 'item_categories' => array_map(function ($category) {
         return ['value' => $category['id'], 'label' => $category['name']];
     }, $itemCategories), 'labs' => array_map(function ($lab) {
         return ['value' => $lab['id'], 'label' => $lab['name']];
     }, array_filter($labs, function ($lab) {
         return $lab['is_new'] !== "1";
     }))]);
 }
Пример #26
0
 public function render($template, $data = null)
 {
     if (ACCEPT_JSON) {
         echo json_encode($data);
     } else {
         echo parent::render($template, $data);
     }
 }
Пример #27
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;
 }
Пример #28
0
 protected function render($template, $data = null)
 {
     foreach (\SlimForm\View\TemplateMap::getInstance()->getTemplatePaths() as $directory) {
         $this->templatesDirectory = $directory;
         if (is_file($this->getTemplatePathname($template))) {
             break;
         }
     }
     return parent::render($template, $data);
 }
Пример #29
0
 public function __invoke(Request $req, Response $res, array $args = [])
 {
     $school = $req->getAttribute('school', false);
     if (!$school) {
         return $res->withStatus(403, 'No school');
     }
     $labs = $this->labService->getLabsBySchoolId($school->id);
     return $this->view->render($res, 'schools/labs.twig', ['school' => $school, 'labs' => $labs, 'staff' => array_map(function ($teacher) {
         return ['value' => $teacher['id'], 'label' => $teacher['fullname']];
     }, $this->staffService->getTeachersBySchoolId($school->id)), 'network_options' => array_map(function ($option) {
         return ['value' => $option, 'label' => $option];
     }, $this->labService->getHasNetworkValues()), 'server_options' => array_map(function ($option) {
         return ['value' => $option, 'label' => $option];
     }, $this->labService->getHasServerValues()), 'lab_types' => array_map(function ($type) {
         return ['value' => $type['id'], 'label' => $type['name']];
     }, $this->labService->getLabTypes()), 'lessons_options' => array_map(function ($lesson) {
         return ['value' => $lesson['id'], 'label' => $lesson['name']];
     }, $this->labService->getLessons())]);
 }
Пример #30
0
 /**
  * Init the login action
  *
  * @param Request $request            
  * @param Response $response            
  * @param unknown $args            
  * @return Response
  */
 public function login(Request $request, Response $response, $args)
 {
     // $helper = $this->facebook->getRedirectLoginHelper();
     // $permissions = $this->settings['facebook-permissions'];
     // $baseDomain = $this->settings['baseDomain'];
     // $loginUrl = $helper->getLoginUrl($baseDomain . '/login-callback', $permissions);
     // $view['loginUrl'] = $loginUrl;
     // $this->session->clear();
     $this->view->render($response, 'login.twig', $this->viewData);
     return $response;
 }