minor updates

parent 30d0e77f
......@@ -262,3 +262,11 @@ getlimitspercourse:
_controller: '\Drupal\epal\Controller\DirectorView::getlimitsperCourse'
requirements:
_user_is_logged_in: 'TRUE'
epal.applicant.creationpdf:
path: '/epal/pdf-application'
options:
_auth: [ 'basic_auth' ]
defaults:
_controller: '\Drupal\epal\Controller\PdfCreator::createApplicantPDF'
requirements:
_user_is_logged_in: 'TRUE'
......@@ -94,7 +94,8 @@ class InformUnlocatedStudents extends ControllerBase {
// εύρεση μαθητών που η αίτησή τους ΔΕΝ ικανοποιήθηκε
$sCon = $this->connection->select('epal_student_class', 'eStudent')
->fields('eStudent', array('student_id'));
->fields('eStudent', array('student_id'))
->condition('eStudent.finalized', 0 , '=');
$epalStudents = $sCon->execute()->fetchAll(\PDO::FETCH_OBJ);
$studentIds = array();
......@@ -224,7 +225,8 @@ class InformUnlocatedStudents extends ControllerBase {
// εύρεση μαθητών που η αίτησή τους ΙΚΑΝΟΠΟΙΗΘΗΚΕ
$sCon = $this->connection->select('epal_student_class', 'eStudent')
->fields('eStudent', array('student_id', 'epal_id'));
->fields('eStudent', array('student_id', 'epal_id'))
->condition('eStudent.finalized', 1 , '=');
$epalStudents = $sCon->execute()->fetchAll(\PDO::FETCH_OBJ);
$studentIds = array();
......
<?php
/**
* @file
* Contains \Drupal\query_example\Controller\QueryExampleController.
*/
namespace Drupal\epal\Controller;
use Drupal\Core\Entity\Query\QueryFactory;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Drupal\Core\Database\Database;
use Drupal\Core\Database\Connection;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Drupal\Core\Logger\LoggerChannelFactoryInterface;
use Drupal\Core\TypedData\Plugin\DataType\TimeStamp;
use Drupal\Core\Language\LanguageManagerInterface;
//require_once('fpdf.php');
//require('C:\wamp64\bin\php\php5.6.25\fpdf16/fpdf.php');
use FPDF;
class PDFCreator extends ControllerBase {
protected $entity_query;
protected $entityTypeManager;
protected $logger;
protected $connection;
public function __construct(
EntityTypeManagerInterface $entityTypeManager,
QueryFactory $entity_query,
Connection $connection,
LoggerChannelFactoryInterface $loggerChannel)
{
$this->entityTypeManager = $entityTypeManager;
$this->entity_query = $entity_query;
$connection = Database::getConnection();
$this->connection = $connection;
$this->logger = $loggerChannel->get('epal');
}
public static function create(ContainerInterface $container)
{
return new static(
$container->get('entity_type.manager'),
$container->get('entity.query'),
$container->get('database'),
$container->get('logger.factory')
);
}
public function createApplicantPDF(Request $request) {
try {
if (!$request->isMethod('GET')) {
return $this->respondWithStatus([
"message" => t("Method Not Allowed")
], Response::HTTP_METHOD_NOT_ALLOWED);
}
/*
$authToken = $request->headers->get('PHP_AUTH_USER');
$epalUsers = $this->entityTypeManager->getStorage('epal_users')->loadByProperties(array('authtoken' => $authToken));
$epalUser = reset($epalUsers);
if ($epalUser) {
//$userid = $epalUser -> id();
$users = $this->entityTypeManager->getStorage('user')->loadByProperties(array('name' => $authToken));
$user = reset($users);
if (!$user) {
return $this->respondWithStatus([
'message' => t("User not found"),
], Response::HTTP_FORBIDDEN);
}
}
*/
//user validation
/*
$authToken = $request->headers->get('PHP_AUTH_USER');
$users = $this->entityTypeManager->getStorage('user')->loadByProperties(array('name' => $authToken));
$user = reset($users);
return $this->respondWithStatus([
'message' => t("User:") . $authToken,
], Response::HTTP_FORBIDDEN);
if (!$user) {
return $this->respondWithStatus([
'message' => t("User not found"),
], Response::HTTP_FORBIDDEN);
}
//user role validation
$roles = $user->getRoles();
$validRole = false;
foreach ($roles as $role)
if ($role === "applicant") {
$validRole = true;
break;
}
return $this->respondWithStatus([
'message' => t("User Role:") . $role,
], Response::HTTP_FORBIDDEN);
if (!$validRole) {
return $this->respondWithStatus([
'message' => t("User Invalid Role"),
], Response::HTTP_FORBIDDEN);
}
*/
//$user->id()
$pdf=new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World! This is a funny day!!!!Hello World! This is a funny day!!!!Hello World! This is a funny day!!!!');
ob_end_clean();
//$s = $pdf->Output("c:\BACKUP\myFile2.pdf", "D");
$s = $pdf->Output("c:\BACKUP\myFile2.pdf", "S");
$s = utf8_encode($s);
$pdf->Close();
//ob_end_flush();
//$s = file_get_contents("c:/BACKUP/test.pdf");
//$s = utf8_encode($s);
//file_put_contents("c:/BACKUP/test2.pdf",$s);
return $this->respondWithStatus([
'pdfString' => $s,
//$s,
], Response::HTTP_OK);
} //end try
catch (\Exception $e) {
$this->logger->warning($e->getMessage());
return $this->respondWithStatus([
"message" => t("An unexpected problem occured during createApplicantPDF Method ")
], Response::HTTP_INTERNAL_SERVER_ERROR);
}
}
public function array_utf8_encode($dat)
{
if (is_string($dat))
return utf8_encode($dat);
if (!is_array($dat))
return $dat;
$ret = array();
foreach ($dat as $i => $d)
$ret[$i] = self::array_utf8_encode($d);
return $ret;
}
private function respondWithStatus($arr, $s) {
$res = new JsonResponse($arr);
$res->setStatusCode($s);
return $res;
}
}
......@@ -340,29 +340,11 @@ html2canvas(document.getElementById("target"), <Html2Canvas.Html2CanvasOptions>{
createPdfServerSide()
{
/*
this.SubmitedDetailsSub = this._hds.createPdfServerSide().subscribe(data => {
this.data = data;
},
error => {
console.log("Error Getting createPdfServerSide");
},
() => {
console.log("Success Getting createPdfServerSide");
//$window.open(this.data);
//window.open("data:application/pdf," + encodeURI(this.data));
console.log("Test Now!");
console.log(this.data);
//window.open("https://www.w3schools.com");
}
);
*/
this._hds.createPdfServerSide(this.authToken, this.role);
/*
this._hds.createPdfServerSide(this.authToken, this.role)
.then(msg => {
//console.log("Nikos2");
......@@ -371,6 +353,7 @@ createPdfServerSide()
//console.log("Nikos1");
console.log(err);
});
*/
}
......
import {Http, Headers, RequestOptions} from '@angular/http';
import {Http, Headers, RequestOptions, ResponseContentType, Response } from '@angular/http';
import {Injectable, OnInit, OnDestroy} from '@angular/core';
import {BehaviorSubject} from "rxjs/Rx";
import 'rxjs/add/operator/map';
......@@ -913,25 +913,50 @@ createPdfServerSide(auth_token, role) {
*/
let headers = new Headers({
//"Content-Type": "application/json",
"Content-Type": "application/json",
//"Access-Control-Allow-Origin": "true",
});
this.authToken = auth_token;
this.authRole = role;
console.log(this.authToken);
console.log(this.authRole);
this.createAuthorizationHeader(headers);
let options = new RequestOptions({ headers: headers });
let options = new RequestOptions([{ headers: headers }, { responseType: ResponseContentType.Blob }]);
//let options = new RequestOptions({ headers: headers });
return this.http.get(`${AppSettings.API_ENDPOINT}/epal/pdf-application/`, options)
.map(response => response.json())
//.map(response => (response.blob())
//.map((res:Response) => res.blob())
//.map(response => (<Response>response).blob())
.subscribe(
data => {
console.log("Hello!");
console.log(data);
var blob = new Blob([data['pdfString']], {type: 'application/pdf'});
console.log(blob);
FileSaver.saveAs(blob, "testData.pdf");
//return this.http.get(`${AppSettings.API_ENDPOINT}/epal/pdf-application/`, options)
// .map(response => response.json());
},
err => console.error(err),
() => console.log('done')
);
/*
return new Promise((resolve, reject) => {
this.http.post(`${AppSettings.API_ENDPOINT}/epal/pdf-application`, options)
.map(response => response.json())
//.map(response => response.json())
.subscribe(data => {
resolve(data);
console.log("Nik");
var blob = new Blob([data['_body']], {type: 'application/pdf'});
console.log(blob);
FileSaver.saveAs(blob, "testData.pdf");
//console.log(data['_body']);
},
error => {
......@@ -939,6 +964,7 @@ createPdfServerSide(auth_token, role) {
},
() => console.log("Nikos!!!"));
});
*/
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment