Commit d7fa3c59 authored by Andgel Brissaud's avatar Andgel Brissaud
Browse files

Merge branch 'master' into fix-dives-list

parents 216ae155 ae9856a3
Loading
Loading
Loading
Loading
+76 −0
Original line number Diff line number Diff line
<?php

namespace App\Http\Controllers;
use App\Models\User;
use App\Models\DivingSession;
use App\Models\Registration;
use App\Http\Controllers\ModificationDives;
use Illuminate\View\View;


use Illuminate\Http\Request;

class AdherentController extends Controller
{
    static function index($ds_code, $level): View
    {

        $adherents = User::selectRaw('US_FIRST_NAME,US_NAME,US_LICENCE_ID, CAR_USER.US_ID')
        ->join('CAR_PREROGATIVE','CAR_PREROGATIVE.PRE_CODE','=','CAR_USER.PRE_CODE')
        ->where('CAR_PREROGATIVE.PRE_LEVEl','>=',$level)
        ->get();

        $sessionplongee = DivingSession::selectRaw('CAR_DIVING_SESSION.DS_CODE, CAR_DIVING_SESSION.DS_DATE, CAR_DIVING_LOCATION.DL_NAME, CAR_DIVING_SESSION.CAR_SCHEDULE, CAR_DIVING_SESSION.DS_LEVEL')
        ->join('CAR_DIVING_LOCATION', 'CAR_DIVING_SESSION.DL_ID', '=', 'CAR_DIVING_LOCATION.DL_ID')
        ->where('ds_code', '=', $ds_code)
        ->get();


        return view('adherents', [
            'adherents' => $adherents,
            'sessionplongee' => $sessionplongee[0],
            ]);    
    }





    static function addUserToDive($ds_code, $us_id): View
    {

        $query = Registration::insert([
            'US_ID' => $us_id,
            'DS_CODE' => $ds_code,
            'REG_ACTIVE' => 1
        ]);

        return ModificationDives::modificationMembers($ds_code);

    }



    static function searchByName($ds_code, $level, Request $request){

        $nom = $request['nom'];
        $prenom = $request['prenom'];

        $request = User::selectRaw('US_FIRST_NAME,US_NAME,US_LICENCE_ID, CAR_USER.US_ID')
        ->where('US_NAME', 'LIKE', "%".$nom."%")
        ->where('US_FIRST_NAME', 'LIKE', "%".$prenom."%")
        ->get();

        $sessionplongee = DivingSession::selectRaw('CAR_DIVING_SESSION.DS_CODE, CAR_DIVING_SESSION.DS_DATE, CAR_DIVING_LOCATION.DL_NAME, CAR_DIVING_SESSION.CAR_SCHEDULE, CAR_DIVING_SESSION.DS_LEVEL')
        ->join('CAR_DIVING_LOCATION', 'CAR_DIVING_SESSION.DL_ID', '=', 'CAR_DIVING_LOCATION.DL_ID')
        ->where('ds_code', '=', $ds_code)
        ->get();

        return view('adherents', [
            'adherents' => $request,
            'sessionplongee' => $sessionplongee[0],
        ]); 

    }

}
+142 −0
Original line number Diff line number Diff line
<?php

namespace App\Http\Controllers;

use Illuminate\View\View;

use App\Models\DivingSession;
use App\Models\Registration;
use App\Models\User;

class ModificationDives extends Controller
{

    static function sessionContainsPilot($ds_code){
        $query = DivingSession::selectRaw('US_ID')
        ->where('DS_CODE', '=', $ds_code)
        ->get();
        return($query[0]['US_ID'] != 0);
    }

    static function sessionContainsSecurity($ds_code){
        $query = DivingSession::selectRaw('US_ID_CAR_SECURE')
        ->where('DS_CODE', '=', $ds_code)
        ->get();
        return($query[0]['US_ID_CAR_SECURE'] != 0);
    }

    static function sessionContainsDirector($ds_code){
        $query = DivingSession::selectRaw('US_ID_CAR_DIRECT')
        ->where('DS_CODE', '=', $ds_code)
        ->get();
        return($query[0]['US_ID_CAR_DIRECT'] != 0);
    }

    function index(): View {

        $request = DivingSession::selectRaw('DS_CODE, DS_DATE, CAR_SCHEDULE, DL_DEPTH, DL_NAME')
        ->join('CAR_DIVING_LOCATION','CAR_DIVING_SESSION.DL_ID', '=', 'CAR_DIVING_LOCATION.DL_ID')
        ->where('CAR_DIVING_SESSION.DS_ACTIVE', '=', 1)
        ->get();

        /*
        select ds_code, dl_name, ds_date, CAR_SCHEDULE, dl_depth
        from car_diving_session
        join car_diving_location using(DL_ID)
        where car_diving_session.DS_ACTIVE = 1;*/


        return view('modification_dives', ['dives' => $request]);
    }



    static function removalOfAMemberFromASession(string $ds_code, int $us_id){
        Registration::where('CAR_REGISTRATION.DS_CODE', '=', $ds_code)
        ->where('CAR_REGISTRATION.US_ID', '=', $us_id)
        ->delete();

        return ModificationDives::modificationMembers($ds_code);
    }







    static function modificationMembers(string $ds_code){

        $pilote_temp = DivingSession::selectRaw('US_FIRST_NAME,US_NAME,US_LICENCE_ID, CAR_USER.US_ID')
        ->join('CAR_USER','CAR_DIVING_SESSION.US_ID','=','CAR_USER.US_ID')
        ->where('CAR_DIVING_SESSION.DS_CODE', '=', $ds_code)
        ->get();


        $pilote = [
            'US_FIRST_NAME' => $pilote_temp[0]['US_FIRST_NAME'],
            'US_NAME' => $pilote_temp[0]['US_NAME'],
            'US_LICENCE_ID' => $pilote_temp[0]['US_LICENCE_ID'],
            'US_ID' => $pilote_temp[0]['US_ID'],
            'ROL_LABEL' => "Pilote"
        ];

        $securite_temp = DivingSession::selectRaw('US_FIRST_NAME,US_NAME,US_LICENCE_ID, CAR_USER.US_ID')
        ->join('CAR_USER','CAR_DIVING_SESSION.US_ID_CAR_SECURE','=','CAR_USER.US_ID')
        ->where('CAR_DIVING_SESSION.DS_CODE', '=', $ds_code)
        ->get();

        $securite = [
            'US_FIRST_NAME' => $securite_temp[0]['US_FIRST_NAME'],
            'US_NAME' => $securite_temp[0]['US_NAME'],
            'US_LICENCE_ID' => $securite_temp[0]['US_LICENCE_ID'],
            'US_ID' => $securite_temp[0]['US_ID'],
            'ROL_LABEL' => "Sécurité de surface"
        ];

        $directeur_temp = DivingSession::selectRaw('US_FIRST_NAME,US_NAME,US_LICENCE_ID, CAR_USER.US_ID')
        ->join('CAR_USER','CAR_DIVING_SESSION.US_ID_CAR_DIRECT','=','CAR_USER.US_ID')
        ->where('CAR_DIVING_SESSION.DS_CODE', '=', $ds_code)
        ->get();

        $directeur = [
            'US_FIRST_NAME' => $directeur_temp[0]['US_FIRST_NAME'],
            'US_NAME' => $directeur_temp[0]['US_NAME'],
            'US_LICENCE_ID' => $directeur_temp[0]['US_LICENCE_ID'],
            'US_ID' => $directeur_temp[0]['US_ID'],
            'ROL_LABEL' => "Directeur"
        ];

        $plongeurs = User::selectRaw('US_FIRST_NAME,US_NAME,US_LICENCE_ID, ROL_LABEL, CAR_USER.US_ID')
        ->join('CAR_PREROGATIVE','CAR_PREROGATIVE.PRE_CODE','=','CAR_USER.PRE_CODE')
        ->join('CAR_ROLE_ATTRIBUTION','CAR_USER.US_ID','=','CAR_ROLE_ATTRIBUTION.US_ID')
        ->join('CAR_ROLE','CAR_ROLE_ATTRIBUTION.ROL_CODE','=','CAR_ROLE.ROL_CODE')
        ->join('CAR_REGISTRATION', 'CAR_USER.US_ID', '=', 'CAR_REGISTRATION.US_ID')
        ->join('CAR_DIVING_SESSION', 'CAR_REGISTRATION.DS_CODE', '=', 'CAR_DIVING_SESSION.DS_CODE')
        ->where('CAR_DIVING_SESSION.DS_CODE', '=', $ds_code)
        ->where('CAR_ROLE.ROL_CODE','=','DIV')
        ->get();

        $adherents = array();
        array_push($adherents, $pilote);
        array_push($adherents, $securite);
        array_push($adherents, $directeur);
        foreach($plongeurs as $plongeur){
            array_push($adherents, $plongeur);
        }

        $sessionplongee = DivingSession::selectRaw('CAR_DIVING_SESSION.DS_CODE, CAR_DIVING_SESSION.DS_DATE, CAR_DIVING_LOCATION.DL_NAME, CAR_DIVING_SESSION.CAR_SCHEDULE, CAR_DIVING_SESSION.DS_LEVEL')
        ->join('CAR_DIVING_LOCATION', 'CAR_DIVING_SESSION.DL_ID', '=', 'CAR_DIVING_LOCATION.DL_ID')
        ->where('DS_CODE', '=', $ds_code)
        ->get();


        return view('modification_members_of_session', [
            'persons' => $adherents,
            'sessionplongee' => $sessionplongee[0],
            'directeurpresent' => ModificationDives::sessionContainsDirector($ds_code),
            'pilotepresent' => ModificationDives::sessionContainsPilot($ds_code),
            'securitepresent' => ModificationDives::sessionContainsSecurity($ds_code)
        ]);    
    }
}
+2 −0
Original line number Diff line number Diff line
@@ -17,6 +17,8 @@ class DivingSession extends Model
    protected $keyType = 'string';
    public $timestamps = false;

    protected $guarded = [];

    use HasFactory;

    public function getParticipants(): array{
+14 −0
Original line number Diff line number Diff line
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Registration extends Model
{
    use HasFactory;

    protected $table = 'CAR_REGISTRATION';

}
+16 −0
Original line number Diff line number Diff line
    document.addEventListener('DOMContentLoaded', function () {
        var currentDate = new Date();
        var Hour = this.document.getElementById("SelectHour");
        var maxDate = new Date(currentDate.getFullYear(), 11, 1);
        var formattedMaxDate = maxDate.toISOString().split('T')[0];
        var dayInput = document.getElementById('dayInput');
        dayInput.max = formattedMaxDate;
    });

    document.getElementById('dayInput').addEventListener('change', function () {
        var selectedDate = new Date(this.value);
        var dayOfWeek = selectedDate.getDay();

        var selectHour = document.getElementById('SelectHour');

        selectHour.options[1].disabled = false;
        selectHour.options[2].disabled = false;

        if (dayOfWeek === 0) {
            selectHour.options[1].disabled = true;
            selectHour.options[2].disabled = true;
        }
    });
Loading