Ejemplo n.º 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);
 }
Ejemplo n.º 2
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.º 3
0
 public function assert(Acl $acl, RoleInterface $role = null, ResourceInterface $resource = null, $privilege = null)
 {
     $identity = $this->authService->getIdentity();
     $user = R::load('user', $identity->id);
     if (!($school = $user->school)) {
         return false;
     }
     $appForm = $this->appFormService->findSchoolApplicationForm($school->id);
     return null === $appForm;
 }
Ejemplo n.º 4
0
 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);
 }
Ejemplo n.º 5
0
 public function __invoke(Request $req, Response $res, callable $next)
 {
     $school = $req->getAttribute('school');
     $appForm = $this->appFormService->findSchoolApplicationForm($school->id);
     if ($appForm) {
         $settings = $this->container->get('settings');
         $currentVersion = $settings['application_form']['itemcategory']['currentversion'];
         // get the existing (db) application form version
         $items_version = $currentVersion;
         if (isset($appForm['items']) && \count($appForm['items']) > 0) {
             $items_version = array_values($appForm['items'])[0]['version'];
         }
         $appForm['items'] = array_reduce($appForm['items'], function ($aggr, $item) use($currentVersion, $items_version) {
             $category = $item['itemcategory_id'];
             if (!isset($aggr[$category])) {
                 $aggr[$category] = ['category' => $item['itemcategory'], 'count' => 0, 'countAcquired' => 0, 'available' => 'LATEST'];
                 /**
                  * 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.
                  */
                 if ($currentVersion != $items_version && 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'] == $currentVersion && isset($this->container['settings']['application_form']['itemcategory']['map']['items'])) {
                     if (isset($this->container['settings']['application_form']['itemcategory']['map']['items'][$item['itemcategory_id']]) && intval($this->container['settings']['application_form']['itemcategory']['map']['items'][$item['itemcategory_id']]) > 0) {
                         $aggr[$category]['available'] = "MIGRATE";
                     } else {
                         $aggr[$category]['available'] = "UNAVAILABLE";
                     }
                 } elseif ($currentVersion != $items_version && 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'] != $currentVersion)) {
                     $aggr[$category]['available'] = "UNAVAILABLE";
                 }
             }
             $aggr[$category]['count'] += $item['qty'];
             $aggr[$category]['countAcquired'] += $item['qtyacquired'];
             return $aggr;
         }, []);
     }
     $this->view['appForm'] = $appForm;
     return $next($req, $res);
 }
Ejemplo n.º 6
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;
 }