CrestRoad/laravel/app/Http/Requests/Creation.php

121 lines
5.5 KiB
PHP

<?php
namespace App\Http\Requests;
use Auth;
use Log;
class Creation
{
public static function certificate($session, $doctor) {
$folder = storage_path('app/public/certificate/'.$session->type);
$templatename = 'template.png';
$outputImage = self::retimage($folder.'/'.$templatename);
if($session->type == 'road'){
$font = storage_path('app').'/fonts/ANTQUAB.TTF';
$white = imagecolorallocate($outputImage, 0, 0, 0);
imagettftext($outputImage, 30, 0, 590, 567, $white, $font, $doctor->name );
imagettftext($outputImage, 26, 0, 1154, 689, $white, $font, $session->venue );
imagettftext($outputImage, 30, 0, 214, 748, $white, $font, 'on ' . date("d M Y", strtotime($session->start_date)) );
}
if($session->type == 'casper'){
$font = storage_path('app').'/fonts/pala.ttf';
$white = imagecolorallocate($outputImage, 0, 0, 0);
imagettftext($outputImage, 30, 0, 565, 537, $white, $font, $doctor->name );
imagettftext($outputImage, 26, 0, 754, 740, $white, $font, $session->venue );
imagettftext($outputImage, 30, 0, 1111, 805, $white, $font, date("d M Y", strtotime($session->start_date)) );
}
if($session->type == 'casper_clinic'){
$font = storage_path('app').'/fonts/pala.ttf';
$white = imagecolorallocate($outputImage, 0, 0, 0);
imagettftext($outputImage, 30, 0, 580, 514, $white, $font, $doctor->name );
imagettftext($outputImage, 30, 0, 988, 684, $white, $font, date("d M Y", strtotime($session->start_date)) );
}
if($session->type == 'casper_clinic_new'){
$font = storage_path('app').'/fonts/pala.ttf';
$white = imagecolorallocate($outputImage, 0, 0, 0);
imagettftext($outputImage, 30, 0, 590, 514, $white, $font, $doctor->name );
imagettftext($outputImage, 30, 0, 988, 684, $white, $font, date("d M Y", strtotime($session->start_date)) );
}
if($session->type == 'casper_plus'){
$font = storage_path('app').'/fonts/pala.ttf';
$color = imagecolorallocate($outputImage, 0, 0, 0);
$nameSize = 30;
$dateSize = 30;
$nameX = 590;
$nameY = 514;
$dateX = 988;
$dateY = 684;
$certificateDate = !empty($session->start_date)
? date('d M Y', strtotime($session->start_date))
: date('d M Y');
imagettftext($outputImage, $nameSize, 0, $nameX, $nameY, $color, $font, $doctor->name);
imagettftext($outputImage, $dateSize, 0, $dateX, $dateY, $color, $font, $certificateDate);
}
if($session->type == 'APFT'){
$font = storage_path('app').'/fonts/pala.ttf';
$white = imagecolorallocate($outputImage, 0, 0, 0);
imagettftext($outputImage, 30, 0, 629, 522, $white, $font, $doctor->name );
imagettftext($outputImage, 30, 0, 1184, 670, $white, $font, date("d M Y", strtotime($session->start_date)) );
}
if($session->type == 'spirometry_simplified'){
$font = storage_path('app').'/fonts/pala.ttf';
$white = imagecolorallocate($outputImage, 0, 0, 0);
imagettftext($outputImage, 30, 0, 642, 590, $white, $font, $doctor->name );
imagettftext($outputImage, 30, 0, 749, 845, $white, $font, date("d M Y", strtotime($session->start_date)) );
}
if($session->type == 'ecampus'){
$font = storage_path('app').'/fonts/pala.ttf';
$white = imagecolorallocate($outputImage, 0, 0, 0);
imagettftext($outputImage, 16, 0, 312, 388, $white, $font, $doctor->name );
imagettftext($outputImage, 15, 0, 474, 465, $white, $font, date("d M Y", strtotime($session->start_date)) );
}
$filename = 'Certificate-'.$session->code.'-'.$doctor->id.'.png';
imagepng($outputImage, $folder.'/'.$filename);
imagedestroy($outputImage);
return ['filename' => $filename, 'folder' => $folder];
}
public static function lmscertificate($course, $doctor) {
$folder = storage_path('app/public/lmscertificate/'.$course->id);
$templatename = 'template.png';
if($doctor->designation == 'Chemist') {
$templatename = 'chemist_template.png';
}
$outputImage = self::retimage($folder.'/'.$templatename);
$font = storage_path('app').'/fonts/pala.ttf';
$white = imagecolorallocate($outputImage, 0, 0, 0);
imagettftext($outputImage, 30, 0, 353, 618, $white, $font, $doctor->name );
//imagettftext($outputImage, 26, 0, 754, 740, $white, $font, $course->title );
//imagettftext($outputImage, 30, 0, 1111, 805, $white, $font, date("d M Y", strtotime("now")) );
$filename = 'Certificate-'.$doctor->id.'.png';
imagepng($outputImage, $folder.'/'.$filename);
imagedestroy($outputImage);
return ['filename' => $filename, 'folder' => $folder];
}
protected static function retimage($image) {
$size = getimagesize($image);
switch ($size['mime']) {
case 'image/jpeg':
$photoimg = imagecreatefromjpeg($image);
break;
case 'image/png':
$photoimg = imagecreatefrompng($image);
break;
case 'image/jpeg':
$photoimg = imagecreatefrompng($image);
break;
default:
# code...
break;
}
return $photoimg;
}
}