Commit 57ce5995 authored by Guilhem's avatar Guilhem
Browse files

Merge branch 'creation-adherent-sur-creneau-de-plongee'

parents be107878 9cba282b
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';

}
+41 −0
Original line number Diff line number Diff line
<x-layout>
    <link rel="stylesheet" href="/css/drop-down.css">
    <x-page-title>Modification de la plongée du {{$sessionplongee['DS_DATE']}}, à {{$sessionplongee['DL_NAME']}}, {{$sessionplongee['CAR_SCHEDULE']}}</x-page-title>

    <form method="GET">
        <input type="text" name="nom" placeholder="Cherchez le nom ici"></input>
        <input type="text" name="prenom" placeholder="Cherchez le prénom ici"></input>
        <x-button type="submit">Rechercher</x-button>
    </form>

    <div class="shadow-md max-w-full rounded-lg overflow-hidden border-2">
        <table class="text-sm text-left text-gray-500 w-full">
            <thead class="text-xs text-gray-700 uppercase bg-gray-50">
                <tr>
                    <th scope="col" class="px-6 py-4">Prénom</th>
                    <th scope="col" class="px-6 py-4">Nom</th>
                    <th scope="col" class="px-6 py-4">N° Licence</th>
                </tr>
            </thead>
            <tbody>
                @foreach($adherents as $adherent)
                    <form method="POST" action="/modificationdives/members/{{$sessionplongee['DS_CODE']}}/ajoutadherent/{{$adherent['US_ID']}}">
                    @csrf
                    <tr class="odd:bg-white even:bg-gray-50 border-b">
                        <td class="px-6 py-4">{{ $adherent['US_NAME']}}</td>
                        <td class="px-6 py-4">{{ $adherent['US_FIRST_NAME'] }}</td>
                        <td class="px-6 py-4">{{ $adherent['US_LICENCE_ID']}}</td>
                        <td class="px-6 py-4">
                            <a>
                                <x-button type="submit" color="bg-green-500" colorHover="hover:bg-green-600">
                                    Ajouter
                                </x-button>
                            </a>
                        </td>
                    </tr>
                    </form>
                @endforeach
            </tbody>
        </table>
    </div>
</x-layout>
 No newline at end of file
Loading