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); }
public function actionCreate(Request $request) { if ($request->isXhr()) { $model = Unit::find($request->getAttribute('id')); return $this->renderAjax('image/ajax/modal', ['model' => $model]); } $this->uploadFiles($request->getUploadedFiles(), $request->getParams(), $request->getAttribute('id')); return $this->goBack(); }
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; }
public function __invoke(Request $req, Response $res, array $args = []) { $school = $req->getAttribute('school', false); if (!$school) { return $res->withStatus(403, 'No school'); } $params = $req->getParams(); $id = $params['id']; $params['school_id'] = $school->id; if (isset($params['lessons']) && !is_array($params['lessons'])) { $params['lessons'] = explode(',', $params['lessons']); } unset($params['id']); try { if ($id) { $lab = $this->labservice->updateLab($params, $id); $res = $res->withStatus(200); } else { $lab = $this->labservice->createLab($params); $res = $res->withStatus(201); } $res = $res->withJson($lab); } catch (Exception $ex) { $res = $res->withStatus(500, $ex->getMessage()); } return $res; }
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; }
function getMunicipioDepartamento(Request $request, Response $response) { $response = $response->withHeader('Content-type', 'application/json'); $id = $request->getAttribute("id"); $data = Municipio::select("municipio.*", "departamento.nombre as departamento")->join('departamento', 'departamento.id', '=', 'municipio.idDepartamento')->where("municipio.id", "=", $id)->first(); $response->getBody()->write($data); return $response; }
function borrartipoturnosucursal(Request $request, Response $response) { $response = $response->withHeader('Content-type', 'application/json'); $data = json_decode($request->getBody(), true); $id = $request->getAttribute("id"); $tipo = Tipoturnosucursal::select("*")->where("idsucursal", "=", $id)->delete(); $response->getBody()->write($tipo); return $response; }
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); }
public function promedio(Request $request, Response $response) { $response = $response->withHeader('Content-type', 'application/json'); $idCliente = $request->getAttribute("idCliente"); $query = "SELECT COALESCE(AVG(calificacion),0) as promedio FROM calificacioncliente WHERE idCliente = " . $idCliente; $data = DB::select(DB::raw($query)); $response->getBody()->write(json_encode($data)); return $response; }
/** * display a static page * * @param Request $request * @param Response $response * @return Response */ public function display(Request $request, Response $response) { try { $res = $this->render($response, sprintf('pages/%s.html', $request->getAttribute('page', 'home'))); } catch (\Exception $e) { $res = $this->render($response, 'errors/404.html'); } return $res; }
function eliminarservicios(Request $request, Response $response) { $response = $response->withHeader('Content-type', 'application/json'); $data = json_decode($request->getBody(), true); $id = $request->getAttribute("idempleado"); $tipo = ServiciosEmpleado::select("*")->where("idEmpleado", "=", $id)->delete(); $response->getBody()->write($tipo); return $response; }
public function normalizeProfile(Request $request, Response $response, callable $next) { $routeInfo = $request->getAttribute('routeInfo'); $args = $routeInfo[2]; if (substr($args['username'], -5) == '.json') { $routeInfo[2]['username'] = substr($args['username'], 0, -5); $request = $request->withAttribute('routeInfo', $routeInfo)->withHeader('X-Requested-With', 'XMLHttpRequest'); } return $next($request, $response); }
public function __invoke(Request $req, Response $res, array $args = []) { $school = $req->getAttribute('school', false); if (!$school) { return $res->withStatus(403, 'No school'); } $staff = $this->staffService->getTeachersBySchoolId($school->id); return $this->view->render($res, 'schools/staff.twig', ['school' => $school, 'staff' => $staff, 'branches' => array_map(function ($branch) { return ['value' => $branch['id'], 'label' => $branch['name']]; }, $this->staffService->getBranches())]); }
/** * display a static page * * @param Request $request * @param Response $response */ public function get(Request $request, Response $response) { $pdate = str_replace('/', '-', $request->getAttribute('pdate')); $pslug = $request->getAttribute('pslug'); $pfile = sprintf('%s/blog/%s-%s.md', ROOT_PATH, $pdate, strtolower($pslug)); if (!is_file($pfile) || !is_readable($pfile)) { return $this->render($response, 'errors/404.html'); } $f = file_get_contents($pfile); $t = \Michelf\MarkdownExtra::defaultTransform($f); return $response->getBody()->write($t); $pdata = json_decode(file_get_contents($pfile), true); if (empty($pdata)) { return $this->render($response, 'errors/500.html'); } $pdata['published_at'] = $pdate; $pdata['slug'] = $pslug; $pdata['url'] = (string) $request->getUri(); return $this->render($response, 'post.html', compact('pdata')); }
function promocionesByUsuario(Request $request, Response $response) { $response = $response->withHeader('Content-type', 'application/json'); $id = $request->getAttribute('id'); $data = Promocion::where("idUsuario", "=", $id)->get(); if (count($data) == 0) { $response = $response->withStatus(404); } $response->getBody()->write($data); return $response; }
function getSucursalesByEmpresa(Request $request, Response $response) { $response = $response->withHeader('Content-type', 'application/json'); $email = $request->getAttribute('email'); $data = Sucursal::select("sucursal.*")->join("empresa", "sucursal.idEmpresa", "=", "empresa.email")->where("empresa.email", "=", $email)->get(); if (count($data) == 0) { $response = $response->withStatus(404); } $response->getBody()->write($data); return $response; }
public function __invoke(Request $req, Response $res) { $school = $req->getAttribute('school'); if (!isset($_SESSION['applicationForm']['appForm'])) { $res = $res->withRedirect($this->formUrl); return $res; } $appForm = $_SESSION['applicationForm']['appForm']; $_SESSION['applicationForm']['appForm'] = null; unset($_SESSION['applicationForm']['appForm']); return $this->view->render($res, 'application_form/submit_success.twig', ['school' => $school, 'appForm' => $appForm]); }
function getsectorxsucursales(Request $request, Response $response) { $response = $response->withHeader('Content-type', 'application/json'); $id = $request->getAttribute("id"); $servi = ServiciosSector::select('serviciossector.*')->where('serviciossector.idSector', '=', $id)->groupBy('serviciossector.idSector')->get(); for ($i = 0; $i < count($servi); $i++) { $sucu = ServiciosSucursal::select('serviciossucursal.idSucursal', 'sucursal.nombre', 'sucursal.latitud', 'sucursal.longitud', 'sucursal.estado', 'sucursal.direccion', 'sucursal.telefono', 'empresa.razonSocial')->join('sucursal', 'sucursal.id', '=', 'serviciossucursal.idSucursal')->join('empresa', 'empresa.id', '=', 'sucursal.idEmpresa')->where('serviciossucursal.idServicio', '=', $servi[$i]->idServicio)->get(); $servi[$i]['servicio'] = $sucu; } $response->getBody()->write($servi); return $response; }
function aplicaReserva(Request $request, Response $response) { $response = $response->withHeader('Content-type', 'application/json'); $id = $request->getAttribute("idSucursal"); $sucursal = Sucursal::select('sucursal.idEmpresa')->where('sucursal.id', '=', $id)->first(); $sectorempresa = SectorEmpresa::select('sectorempresa.idSector')->where('sectorempresa.idEmpresa', '=', $sucursal->idEmpresa)->get(); foreach ($sectorempresa as $row) { $sector = Sector::select('sector.aplicaReserva')->where('sector.id', '=', $row->idSector)->where('sector.aplicaReserva', '=', 'SI')->get(); } $response->getBody()->write(json_encode($sector)); return $response; }
function modulopermisoperfil(Request $request, Response $response) { $response = $response->withHeader('Content-type', 'application/json'); $idperfil = $request->getAttribute("idperfil"); $data = Perfilpermisos::select('idmodulo', 'idperfil')->where('idperfil', '=', $idperfil)->groupBy('idmodulo')->get(); for ($i = 0; $i < count($data); $i++) { $permisos = Perfilpermisos::select('idpermiso')->where('idperfil', '=', $data[$i]->idperfil)->where('idmodulo', '=', $data[$i]->idmodulo)->get(); $data[$i]['permisos'] = $permisos; } $response->getBody()->write($data); return $response; }
public function dispatch(Request $request, Response $response, $args) { $meetupID = $request->getAttribute('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)]; } $eventDetails['errors'] = $this->flash->getMessage('event') ?? []; $this->view->render($response, 'admin/event-info.twig', $eventDetails); return $response; }
public function actionDelete(Request $request) { if (!Oauth::isLogged()) { return $this->goBack(); } /* @var $model Unit */ $model = Unit::find($request->getAttribute('id')); if ($model->delete()) { Alert::add("Successful delete {$model->name}"); } return $this->goBack(); }
/** * Set our controller instance variables. * * @param Request $request * @param Response $response * @param array $args * * @return Response */ public function __invoke(Request $request, Response $response, array $args) { /** * Set our controllers parameters to the route's. */ $this->request = $request; $this->response = $response; $this->args = $args; /** * Call the controller method corresponding to the route name. */ return call_user_func([$this, $request->getAttribute('route')->getName()]); }
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; }
/** * Example middleware invokable class * * @param Slim\Http\Request $request PSR7 request * @param Slim\Http\Response $response PSR7 response * @param callable $next Next middleware * * @return \Psr\Http\Message\ResponseInterface */ public function __invoke(Request $request, Response $response, $next) { $route = $request->getAttribute('route'); $session = $this->container->session; $user_id = $session->getVar('userid', 0); if (!$this->hasAccess($route, $user_id)) { $router = $this->container->router; //return $response->withStatus(403); return $response->withRedirect($router->pathFor('front-index')); } $response = $next($request, $response); return $response; }
function eliminargaleria(Request $request, Response $response) { try { $response = $response->withHeader('Content-type', 'application/json'); $id = $request->getAttribute("id"); $servicio = Galeria::select("*")->where("id", "=", $id)->delete(); $respuesta = json_encode(array('msg' => "Eliminado correctamente", "std" => 1)); $response = $response->withStatus(200); } catch (Exception $err) { $respuesta = json_encode(array('msg' => "error", "std" => 0, "err" => $err->getMessage())); $response = $response->withStatus(404); } $response->getBody()->write($respuesta); return $response; }
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); $software = $this->softwareService->getSoftwareBySchoolId($school->id); $categories = $this->softwareService->getSoftwareCategories(); return $this->view->render($res, 'schools/software.twig', ['school' => $school, 'labs' => array_map(function ($lab) { return ['value' => $lab['id'], 'label' => $lab['name']]; }, $labs), 'softwareArray' => $software, 'categories' => array_map(function ($category) { return ['value' => $category['id'], 'label' => $category['name']]; }, $categories)]); }
public function __invoke(Request $request, Response $response, callable $next) { /** @var Route $currentRoute */ $currentRoute = $request->getAttribute('route'); if (!$this->shouldProcessRoute($currentRoute)) { return $next($request, $response); } if (!isset($_SESSION['account_id'])) { return $this->redirectToLoginPage($request, $response); } $account = $this->tryToLoadAccountFromDatabase($_SESSION['account_id']); if (!$account) { return $response->withRedirect('/logout', 303); } return $next($request, $response); }
public function __invoke(Request $req, Response $res, callable $next) { $school = $req->getAttribute('school'); $appForm = $this->appFormService->findSchoolApplicationForm($school->id); if ($appForm) { $appForm['items'] = array_reduce($appForm['items'], function ($aggr, $item) { $category = $item['itemcategory_id']; if (!isset($aggr[$category])) { $aggr[$category] = ['category' => $item['itemcategory'], 'count' => 0]; } $aggr[$category]['count'] += $item['qty']; return $aggr; }, []); } $this->view['appForm'] = $appForm; return $next($req, $res); }
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"; }))]); }