Commit 16059513 authored by Julien Ait azzouzene's avatar Julien Ait azzouzene
Browse files

📝 docs: add documentation for classes relative to security sheets

parent 90e37fa1
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -2,7 +2,19 @@

namespace App\Http\Controllers\SecuritySheets;

/**
 * A strategy that simply returns the HTML code so that it's displayed on the web page as a preview.
 * It's mostly used for testing without generating and downloading the PDF file.
 * @implements SecuritySheetStrategy
 */
class PreviewStrategy implements SecuritySheetStrategy{

    /**
     * Returns the HTML code for it to be displayed.
     * @param $html the HTML code of the document
     * @param $ds_code the code of the diving session (unused, included for compatibility with the interface method)
     * @return string the exact same HTML code
     */
    public function generatePdf($html, $ds_code){
        return $html;
    }
+20 −4
Original line number Diff line number Diff line
@@ -11,6 +11,10 @@
use App\Http\Controllers\Controller;
use App\Http\Controllers\SecuritySheets\StoreSilentStrategy;

/**
 * A controller for generating and previewing PDF security sheets.
 * @author Julien Ait azzouzene <aitazzo221@unicaen.fr>
 */
class SecuritySheetController extends Controller
{
    private SecuritySheetStrategy $strategy;
@@ -19,20 +23,32 @@ public function __construct(){
        $this->strategy = new StoreSilentStrategy;
    }

    /**
     * Generates a security sheet for a particular diving session.
     * The action performed with this security sheet will depend of the strategy set (storing the file by default).
     * @param $ds_code the code of the diving session to generate the security sheet of
     * @return string|\View what to display on the page (what the strategy returns) 
     */
    public function generate(string $ds_code){
        $html =  self::callPdfBuilderView($ds_code);
        return $this->strategy->generatePdf($html, $ds_code);
    }

    public function show(string $ds_code){
       
    }

    /**
     * Sets the strategy for the security sheet and returns this instance.
     * @param $strategy the strategy
     * @return self
     */
    public function setStrategy(SecuritySheetStrategy $strategy){
        $this->strategy = $strategy;
        return $this;
    }

    /**
     * Build HTML from a view to generate the PDF sheet.
     * @param $ds_code the code of the diving session
     * @return string the HTML code
     */
    private function callPdfBuilderView(string $ds_code){
        $dive = DivingSession::find($ds_code);

+10 −0
Original line number Diff line number Diff line
@@ -2,6 +2,16 @@

namespace App\Http\Controllers\SecuritySheets;

/**
 * A strategy (the design pattern) for security sheets generation.
 * @author Julien Ait azzouzene <aitazzo221@unicaen.fr>
 */
interface SecuritySheetStrategy{
    /**
     * Generates the PDF sheet.
     * @param $html the HTML code to generate the document with
     * @param $ds_code the code of the diving session
     * @return string the content to display on the page
     */
    public function generatePdf($html, $ds_code);
}
 No newline at end of file
+11 −0
Original line number Diff line number Diff line
@@ -4,7 +4,18 @@

use Spipu\Html2Pdf\Html2Pdf;

/**
 * A strategy that stores the document on the server, and make it public.
 * It displays 'OK' after successfully generating the file.
 * @implements SecuritySheetStrategy
 */
class StoreSilentStrategy implements SecuritySheetStrategy{
    /**
     * Generates the PDF sheet and store it as a file on the server.
     * @param $html the HTML code to generate the document with
     * @param $ds_code the code of the diving session
     * @return string 'OK' to tell the generation was successful
     */
    public function generatePdf($html, $ds_code){
        $html2pdf = new Html2Pdf();

+16 −15
Original line number Diff line number Diff line
<?php

use App\Http\Controllers\DiversBySession;
use App\Http\Controllers\DivesList;
use App\Http\Controllers\SecuritySheets\PreviewStrategy;
use App\Models\DivingSession;
use App\Http\Controllers\DivingSignUpController;
use App\Http\Controllers\SecuritySheets\SecuritySheetController;
use Illuminate\Support\Facades\Route;
use App\Models\Boat;
use App\Models\User;
use App\Models\DivingGroup;
use App\Models\Prerogative;
use Illuminate\Http\Request;
use Spipu\Html2Pdf\Html2Pdf;
use App\Http\Controllers\DivingNumberController;
use App\Models\DivingSession;
use App\Models\DivingLocation;
use App\Models\DivingNumberModel;
use App\Http\Controllers\HomepageController;
use App\Http\Controllers\DiveSessionCreation;
use App\Http\Controllers\DiveSessionUpdate;
use App\Http\Controllers\DivesList;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\AuthController;
use App\Http\Controllers\DiversBySession;
use App\Http\Controllers\DiveSessionUpdate;
use App\Http\Controllers\HomepageController;

/*
|--------------------------------------------------------------------------
@@ -27,10 +27,11 @@
|
*/

use App\Models\User;
use App\Models\DivingLocation;
use App\Models\Boat;
use App\Models\Prerogative;
use App\Http\Controllers\DiveSessionCreation;
use App\Http\Controllers\DivingNumberController;
use App\Http\Controllers\DivingSignUpController;
use App\Http\Controllers\SecuritySheets\PreviewStrategy;
use App\Http\Controllers\SecuritySheets\SecuritySheetController;


Route::get('/login', function () {