Commit 76059215 authored by Guilhem's avatar Guilhem
Browse files

feat : adding and removing divers from a dive

parent 2e4cbb2d
Loading
Loading
Loading
Loading
+35 −8
Original line number Diff line number Diff line
@@ -2,6 +2,9 @@

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;


@@ -9,17 +12,41 @@

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

        $adherents = User::selectRaw('US_FIRST_NAME,US_NAME,US_LICENCE_ID, ROL_LABEL')
        ->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')
        ->where('car_prerogative.pre_level','>=',$level)
        ->where('CAR_ROLE.ROL_CODE','=','DIV')
        $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();

        return view('adherents', ['adherents' => $adherents]);    
        $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);

    }

}
+100 −30
Original line number Diff line number Diff line
@@ -6,14 +6,37 @@

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)
        $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();

        /*
@@ -22,51 +45,98 @@ function index(): View {
        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)
        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){

        $members = DivingSession::selectRaw('car_prerogative.pre_level, car_diving_session.DS_CODE, car_user.US_ID, car_user.us_name, car_user.us_first_name, car_role_attribution.ROL_CODE, car_user.US_SUB_DATE')
        ->join('car_registration', 'car_diving_session.DS_CODE', '=', 'car_registration.DS_CODE')
        ->join('car_user', 'car_registration.US_ID', '=', 'car_user.US_ID')
        ->join('car_prerogative','car_diving_session.pre_code','=','car_prerogative.pre_code')
        ->join('car_role_attribution', 'car_user.US_ID', '=', 'car_role_attribution.US_ID')
        ->where('car_diving_session.ds_code', '=', $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();

        /*select car_diving_session.DS_CODE, car_user.US_ID, car_user.us_name, car_user.US_FIRST_NAME, car_role_attribution.ROL_CODE
        from car_diving_session
        join car_registration on car_diving_session.DS_CODE = car_registration.DS_CODE
        join car_user on car_registration.US_ID = car_user.US_ID
        join car_role_attribution on car_user.US_ID = car_role_attribution.US_ID
        where car_diving_session.DS_CODE = 'DS2';*/

        $sessionplongee = DivingSession::selectRaw('car_diving_session.DS_CODE, car_diving_session.DS_DATE, car_diving_location.DL_NAME, car_diving_session.CAR_SCHEDULE')
        ->join('car_diving_location', 'car_diving_session.dl_id', '=', 'car_diving_location.dl_id')
        ->where('ds_code', '=', $ds_code)

        $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();

        $level = DivingSession::selectRaw('car_prerogative.pre_level')
        ->join('car_registration', 'car_diving_session.DS_CODE', '=', 'car_registration.DS_CODE')
        ->join('car_user', 'car_registration.US_ID', '=', 'car_user.US_ID')
        ->join('car_prerogative','car_diving_session.pre_code','=','car_prerogative.pre_code')
        ->join('car_role_attribution', 'car_user.US_ID', '=', 'car_role_attribution.US_ID')
        ->where('car_diving_session.ds_code', '=', $ds_code)
        $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' => $members,
            'sessionplongee' => $sessionplongee,
            'level' => $level,
            '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{
+21 −8
Original line number Diff line number Diff line
<x-layout>
    <link rel="stylesheet" href="/css/drop-down.css">
    <x-page-title>Ajouter des adhérents</x-page-title>
    <div class="shadow-md max-w-full w-1/3 rounded-lg overflow-hidden border-2 mx-auto">
    <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="searchbar" placeholder="Cherchez un utilisateur 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">Rôle</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">{{ $adherent->ROL_LABEL }}</td>

                        <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>
+6 −6
Original line number Diff line number Diff line
@@ -5,8 +5,8 @@
        <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-3">Prénom</th>
                <th scope="col" class="px-6 py-3">Nom</th>
                <th scope="col" class="px-6 py-3">Plage horaire</th>
                <th scope="col" class="px-6 py-3">Profondeur</th>
                <th scope="col" class="px-6 py-3">Lieu</th>
                <th scope="col" class="px-6 py-3">Actions</th>
@@ -15,17 +15,17 @@
            <tbody>
            @foreach ($dives as $dive)
                <tr class="odd:bg-white even:bg-gray-50 border-b">
                    <td class="px-6 py-4">{{ $dive['ds_date'] }}</td>
                    <td class="px-6 py-4">{{ $dive['car_schedule'] }}</td>
                    <td class="px-6 py-4">{{ $dive['dl_depth'] }}m</td>
                    <td class="px-6 py-4">{{ $dive['dl_name'] }}</td>
                    <td class="px-6 py-4">{{ $dive['DS_DATE'] }}</td>
                    <td class="px-6 py-4">{{ $dive['CAR_SCHEDULE'] }}</td>
                    <td class="px-6 py-4">{{ $dive['DL_DEPTH'] }}m</td>
                    <td class="px-6 py-4">{{ $dive['DL_NAME'] }}</td>
                    <td class="px-8 py-4">
                        <a href='\modificationdives'>
                            <x-button color="#ec9f21" colorHover="hover:bg-green-800">
                                Modifier
                            </x-button>
                        </a>
                        <a href="\modificationdives\members\{{$dive['ds_code']}}">
                        <a href="\modificationdives\members\{{$dive['DS_CODE']}}">
                            <x-button>
                                Adhérents
                            </x-button>
Loading