Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 28 additions & 11 deletions app/Certificate.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@


use Carbon\Carbon;
use Log;
use Illuminate\Support\Facades\Storage;
use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Process\Process;
Expand Down Expand Up @@ -35,7 +36,7 @@ public function generate()

$this->customize_and_save_latex();
$this->run_pdf_creation();
$s3path = $this->copy_to_s3();
$s3path = $this->copy_to_s3();
$this->update_event($s3path);
$this->clean_temp_files();

Expand All @@ -44,11 +45,26 @@ public function generate()

}

private function clean_temp_files(){
Storage::disk('latex')->delete($this->event->id.".aux");
Storage::disk('latex')->delete($this->event->id.".tex");
Storage::disk('latex')->delete($this->event->id.".pdf");
Storage::disk('latex')->delete($this->event->id.".log");
private function clean_temp_files()
{
Storage::disk('latex')->delete($this->event->id . ".aux");
Storage::disk('latex')->delete($this->event->id . ".tex");
Storage::disk('latex')->delete($this->event->id . ".pdf");
Storage::disk('latex')->delete($this->event->id . ".log");
}

public function is_greek()
{

$split = preg_split('/[\p{Greek}]/u', $this->name_of_certificate_holder);
if (count($split) > 1) {
Log::info("Detected as Greek: " . $this->name_of_certificate_holder);
return true;
}

return false;


}

private function tex_escape($string)
Expand All @@ -74,9 +90,10 @@ function ($matches) use ($map) {
, $string);
}

protected function update_event($s3path){
protected function update_event($s3path)
{
$this->event->update([
"certificate_url"=>$s3path,
"certificate_url" => $s3path,
"certificate_generated_at" => Carbon::now()
]);
}
Expand All @@ -87,7 +104,7 @@ protected function update_event($s3path){
*/
protected function copy_to_s3(): string
{
$inputStream = Storage::disk('latex')->getDriver()->readStream( $this->event->id . '.pdf');
$inputStream = Storage::disk('latex')->getDriver()->readStream($this->event->id . '.pdf');
$destination = Storage::disk('s3')->getDriver()->getAdapter()->getPathPrefix() . '/certificates/' . $this->id . '.pdf';
Storage::disk('s3')->getDriver()->putStream($destination, $inputStream);

Expand All @@ -100,6 +117,8 @@ protected function copy_to_s3(): string
*/
protected function customize_and_save_latex()
{
if ($this->is_greek()) $this->templateName = "template_greek.tex";
Log::info($this->templateName);
//open the latex template
$base_template = Storage::disk('latex')->get($this->templateName);

Expand Down Expand Up @@ -130,6 +149,4 @@ protected function run_pdf_creation(): void
}




}
17 changes: 13 additions & 4 deletions resources/latex/template.tex
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
\documentclass[12pt]{article}
\usepackage[T2A,T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[russian,english]{babel}
\usepackage[greek,russian,english]{babel}
\usepackage{mathpazo}
\renewcommand{\familydefault}{\rmdefault}
\usepackage[landscape,a4paper]{geometry}
Expand All @@ -11,8 +12,12 @@
\usepackage{graphicx}
\usepackage{url}
\usepackage{eso-pic}
\usepackage[T2A,T1]{fontenc}
\usepackage{textcomp}
\usepackage{paratype}
\usepackage{tgpagella}

\usepackage{substitutefont}
\substitutefont{T2A}{\rmdefault}{PTSerif-TLF}

\newcommand\BackgroundPic{%
\put(0,0){%
Expand Down Expand Up @@ -50,8 +55,12 @@

\vspace{0.4cm}

\Huge{that \textbf{<CERTIFICATE_HOLDER_NAME>
}}
\Huge{that
\begin{otherlanguage*}{russian}
\textbf{<CERTIFICATE_HOLDER_NAME>}
\end{otherlanguage*}
}


\vspace{0.4cm}

Expand Down
109 changes: 109 additions & 0 deletions resources/latex/template_greek.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
\documentclass[12pt]{article}
\usepackage[T1,LGR,T2A]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[greek,russian,english]{babel}
\usepackage{mathpazo}
\renewcommand{\familydefault}{\rmdefault}
\usepackage[landscape,a4paper]{geometry}
\geometry{verbose,tmargin=0cm,bmargin=0cm,lmargin=3cm,rmargin=3cm}
\usepackage{fancybox}
\usepackage{calc}
\usepackage{multicol}
\usepackage{graphicx}
\usepackage{url}
\usepackage{eso-pic}
\usepackage{textcomp}
\usepackage{paratype}
\usepackage{tgpagella}

\usepackage{substitutefont}
\substitutefont{T2A}{\rmdefault}{PTSerif-TLF}
\substitutefont{LGR}{\rmdefault}{udidot}

\newcommand\BackgroundPic{%
\put(0,0){%
\parbox[b][\paperheight]{\paperwidth}{%
\vfill
\centering
\includegraphics[width=\paperwidth,height=\paperheight,%
keepaspectratio]{images/background.png}%
\vfill
}}}


\begin{document}
\AddToShipoutPicture{\BackgroundPic}
~
\vspace{1.2cm}
~
\begin{center}

\begin{table}[h]
\footnotesize
\begin{center}
\begin{tabular}{lr}
%~\hspace{0.7cm}
\includegraphics[height=3.4cm]{images/codeweek_logo.png}
\includegraphics[height=3.4cm]{images/european_commission_logo.png}
\end{tabular}
\end{center}
\end{table}
\vspace{-0.2cm}
\LARGE{CodeWeek EU organisers are honoured\\
\vspace{1cm}
\fontsize{50}{60}{\textbf{TO CERTIFY}}
}


\Huge{that
\begin{otherlanguage*}{greek}
\textbf{<CERTIFICATE_HOLDER_NAME>}
\end{otherlanguage*}
}


\vspace{0.4cm}

\Huge{actively contributed to the success of}

\vspace{0.3cm}

\Huge{\textbf{EUROPE CODE WEEK 2018}}

\vspace{0.3cm}

\Large{by running a coding event.}

\vspace{.2cm}

\vspace{1cm}

\begin{table}[h]
\footnotesize
\begin{center}

\end{center}
\end{table}

\vspace{-3cm}
\end{center}
\begin{table}[h]
\footnotesize
\begin{center}
\begin{tabular}{lr}
%~\hspace{0.7cm}
\includegraphics[height=2.5cm]{images/signature_and_stamp.png}
\end{tabular}
\end{center}
\end{table}
\vspace{-2.2cm}
\begin{center}
\footnotesize{On behalf of Europe Code Week Ambassadors}\\
%\end{tabular}

%Diploma elaborado con el software libre \texttt{Pyploma}, (c)
%\url{fjruizruano@gmail.com} bajo licencia
%GPLv3. Visite: \url{http://code.google.com/p/pyploma}

\end{center}
\end{document}
58 changes: 58 additions & 0 deletions tests/Feature/ReportEventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Tests\Feature;

use App\Certificate;
use App\Event;
use Carbon\Carbon;
use Illuminate\Foundation\Testing\DatabaseMigrations;
Expand Down Expand Up @@ -158,6 +159,63 @@ public function user_should_see_list_of_his_reportable_events(){
;
}

/** @test */
public function text_should_not_be_detected_as_greek(){

$certificate = new Certificate($this->event);
$this->assertFalse($certificate->is_greek());

}

/** @test */
public function text_should_be_detected_as_greek(){

$this->event->name_for_certificate = "Λιανού Κυριακή - Lianou Kiriaki 10ο Δημοτικό Σχολείο Αιγάλεω";
$certificate = new Certificate($this->event);
$this->asserttrue($certificate->is_greek());


}

/** @test */
public function text_should_be_detected_as_greek_with_all_uppercase(){

$this->event->name_for_certificate = "ΖΑΧΑΡΩΦ ΣΟΝΙΑ";
$certificate = new Certificate($this->event);
$this->asserttrue($certificate->is_greek());


}

/** @test */
public function text_should_be_detected_as_greek_with_one_greek_char(){

$this->event->name_for_certificate = "This is a Σ";
$certificate = new Certificate($this->event);
$this->asserttrue($certificate->is_greek());


}

/** @test */
public function text_should_not_be_detected_as_greek_with_one_special_char(){

$this->event->name_for_certificate = "Teacher Di Lella Lucia and the 1D con l’evento “Di Pixel in Pixel.. cosa apparirà?:stuck_out_tongue_winking_eye:";
$certificate = new Certificate($this->event);
$this->assertfalse($certificate->is_greek());


}

/** @test */
public function text_should_not_be_detected_as_greek_with_several_special_chars(){

$this->event->name_for_certificate = 'Nemyriv Educational Establishment "Comprehensive Shool of I-III grades №2-lyceum" - of Nemyriv town Concil Vinnytsia Region';
$certificate = new Certificate($this->event);
$this->assertfalse($certificate->is_greek());

}


}

Expand Down