diff --git a/app/Http/Controllers/OCOMController.php b/app/Http/Controllers/OCOMController.php index 90c54c5f..5aee0c07 100644 --- a/app/Http/Controllers/OCOMController.php +++ b/app/Http/Controllers/OCOMController.php @@ -3,7 +3,9 @@ namespace App\Http\Controllers; use App\OCOM; +use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; +use Illuminate\Routing\Redirector; use function GuzzleHttp\json_encode; use function GuzzleHttp\Psr7\str; @@ -26,7 +28,11 @@ class OCOMController extends Controller */ public function create() { + return view('admin.ocom.add'); + } + public function generate() + { $text = "Niveau 1,,,,,,,,,Niveau 2,,,,,,,,,Niveau 3,,,,,,,,,Niveau 4,,,,,,, N° de l'OREN,Objectif de rendement,N° de l’OCOM,Objectif de compétence,Nbredepériode,,Nbre dans horaire,Instructeur,,N° de l’OREN,Objectif de rendement,N° de l’OCOM,Objectif de compétence,Nbre de période,,Nbre dans horaire,Instructeur,,\"N° de l’OREN\",\"Objectif de @@ -596,11 +602,11 @@ X20,\"Participer à des activités ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,OREN 490 - Total des périodes d’instruction complémentaires,20,,, ,,,,,,,,,,,,,,,,,,,,,,,,,,,S.O.,Participer à une revue annuelle (ACR),,,3,,,"; - \App\OCOM::truncate(); + OCOM::truncate(); $matches = []; $orens = []; - preg_match_all('/[X\d]\d\d,[^,]*/',$text,$matches); + preg_match_all('/[X\d]\d\d,[^,]*/',\request('text'),$matches); foreach ($matches[0] as $match) { $match = str_replace('"',"",$match); @@ -632,6 +638,7 @@ X20,\"Participer à des activités $obj_competence = str_replace($ocom[0].",","",$match); $obj_competence = trim(preg_replace('/\s\s+/', ' ', $obj_competence)); + $obj_competence = trim($obj_competence,"\\"); $nbPeriode = preg_replace('/[MC]\S\d\d.\d\d[A-Z]?,[^,]*,/','',$match); $newocom->nbPeriode = $nbPeriode; @@ -654,21 +661,83 @@ X20,\"Participer à des activités $newocom->objectif_competence = $obj_competence; $newocom->objectif_rendement = $orens[$oren[0]]; + $newocom->objectif_rendement = trim($newocom->objectif_rendement,"\\"); $newocom->save(); } } - dd(\App\OCOM::all()); + return redirect('/admin/ocom')->with('success','Base de donnée des cours générée avec succès!'); + } + + public function showgenerate() + { + return view('admin.ocom.generate'); + } + + public function updateOCOMDB() + { + $ocoms = OCOM::all(); + + $from = strtotime(\App\Config::getData('instruction_year_begin')); + $to = strtotime(\App\Config::getData('instruction_year_end')); + $allEvent = \App\Event::all(); + $events = collect(); + + foreach ($allEvent as $e) + { + if ($e->use_schedule == 1) + { + if (strtotime($e->date_begin) >= $from) + { + if (strtotime($e->date_begin) <= $to) + { + $events->push($e); + foreach ($e->courses as $c) + { + $r = $ocoms->where('ocom',$c->ocom)->first(); + if ($r != null) + { + $r->saveCourse($c); + } + } + } + } + } + } + foreach ($ocoms as $o) + { + $o->save(); + } + + dd($ocoms); } /** * Store a newly created resource in storage. * - * @param \Illuminate\Http\Request $request + * @param Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { - // + $ocom = new OCOM(); + $ocom->ocom = $request->ocom; + $ocom->objectif_competence = $request->objectif_competence; + $ocom->nbPeriode = $request->nbPeriode; + $ocom->objectif_rendement = $request->objectif_rendement; + $ocom->oren = $request->oren; + + if ($ocom->ocom[0] == 'C' || $ocom->ocom[0] == 'c') + { + $ocom->complementary = true; + } + else + { + $ocom->complementary = false; + } + $ocom->course_id = ""; + $ocom->save(); + clog('add','success','a ajouter un ocom',\Auth::User()->id); + return redirect('/admin/ocom/'.$ocom->id); } /** @@ -685,40 +754,58 @@ X20,\"Participer à des activités /** * Show the form for editing the specified resource. * - * @param \App\OCOM $oCOM + * @param $id * @return \Illuminate\Http\Response */ - public function edit(OCOM $oCOM) + public function edit($id) { - // + return view('admin.ocom.edit',['ocom' => OCOM::find($id)]); } /** * Update the specified resource in storage. * - * @param \Illuminate\Http\Request $request - * @param \App\OCOM $oCOM - * @return \Illuminate\Http\Response + * @param Request $request + * @param $id + * @return RedirectResponse|Redirector */ - public function update(Request $request, OCOM $oCOM) + public function update(Request $request,$id) { - // + $ocom = OCOM::find($id); + $ocom->ocom = $request->ocom; + $ocom->objectif_competence = $request->objectif_competence; + $ocom->nbPeriode = $request->nbPeriode; + $ocom->objectif_rendement = $request->objectif_rendement; + $ocom->oren = $request->oren; + + if ($ocom->ocom[0] == 'C' || $ocom->ocom[0] == 'c') + { + $ocom->complementary = true; + } + else + { + $ocom->complementary = false; + } + + $ocom->save(); + clog('edit','success','a modifié un ocom',\Auth::User()->id); + return redirect('/admin/ocom/'.$id); } /** * Remove the specified resource from storage. * - * @param \App\OCOM $oCOM + * @param OCOM $oCOM * @return \Illuminate\Http\Response */ - public function destroy(OCOM $oCOM) + public function destroy($id) { - // + OCOM::find($id)->delete(); } public function jsonList() { - $ocoms = \App\OCOM::all(); + $ocoms = OCOM::all(); $name = []; @@ -731,7 +818,7 @@ X20,\"Participer à des activités public function getName(string $ocom) { - $foo = \App\OCOM::all()->where('ocom','=',$ocom)->first(); + $foo = OCOM::all()->where('ocom','=',$ocom)->first(); if($foo != null) { return $foo->objectif_competence; diff --git a/app/OCOM.php b/app/OCOM.php index e82cd1b6..60030651 100644 --- a/app/OCOM.php +++ b/app/OCOM.php @@ -19,14 +19,60 @@ class OCOM extends Model public function saveCourses($courses) { - $courses_id = []; + $courses_id = explode(',',$this->course_id); foreach ($courses as $cours) { if ($cours != null){ array_push($courses_id,$cours->id); } } + $courses_id = array_unique($courses_id); + $courses_id = array_filter($courses_id); $this->course_id = implode(',',$courses_id); $this->save(); } + + public function saveCourse($course) + { + $courses_id = explode(',',$this->course_id); + array_push($courses_id,$course->id); + $courses_id = array_unique($courses_id); + $courses_id = array_filter($courses_id); + $this->course_id = implode(',',$courses_id); + $this->save(); + } + + public function wasGiven() + { + $courses = $this->courses(); + $result = collect(); + + $from = strtotime(\App\Config::getData('instruction_year_begin')); + $to = strtotime(\App\Config::getData('instruction_year_end')); + + foreach ($courses as $course) + { + $event = null; + try { + $event = $course->event; + } + catch (\Exception $e) + { + // Nettoyer ? + break; + } + if (strtotime($event->date_begin) >= $from) + { + if (strtotime($event->date_begin) <= $to) + { + $result->push($event); + } + } + } + if ($result->isEmpty()) + { + return false; + } + return $result; + } } diff --git a/database/seeds/ConfigsTableSeeder.php b/database/seeds/ConfigsTableSeeder.php index 59c516da..80e89e9d 100644 --- a/database/seeds/ConfigsTableSeeder.php +++ b/database/seeds/ConfigsTableSeeder.php @@ -256,6 +256,16 @@ class ConfigsTableSeeder extends Seeder 'name' => 'is_Google_Drive_enabled', 'state' => 0, 'data' => '["false"]' + ], + [ + 'name' => 'instruction_year_begin', + 'state' => 0, + 'data' => '["2019-08-1"]' + ], + [ + 'name' => 'instruction_year_end', + 'state' => 0, + 'data' => '["2020-05-31"]' ] ]; diff --git a/public/js/ocom.js b/public/js/ocom.js new file mode 100644 index 00000000..c76f2e24 --- /dev/null +++ b/public/js/ocom.js @@ -0,0 +1,39 @@ +function deleteOCOM(id) +{ + Swal.fire({ + title: 'Êtes vous certain ?', + text: "Vous ne pourrez annuler cette action", + type: 'warning', + showCancelButton: true, + confirmButtonColor: '#3085d6', + cancelButtonColor: '#d33', + confirmButtonText: 'Oui', + cancelButtonText: 'Non' + }).then((result) => { + if (result.value) { + let request = $.ajax({ + url: "/api/ocom/"+id, + method: "DELETE", + data: { api_token : api_token }, + dataType: "html" + }); + request.done(function (msg) { + Swal.fire( + 'Supprimé!', + 'Le fichier a été supprimé', + 'success' + ).then(() => { + window.location.href = '/admin/ocom'; + }); + }); + request.fail(function (jqXHR, textStatus) { + Swal.fire({ + type: 'error', + title: 'Oops...', + text: 'Le cours n\'a pas pus être supprimé', + footer: ''+textStatus+'' + }) + }) + } + }); +} \ No newline at end of file diff --git a/public/mix-manifest.json b/public/mix-manifest.json index 3284f7c6..264e3dcb 100644 --- a/public/mix-manifest.json +++ b/public/mix-manifest.json @@ -1,5 +1,4 @@ { - "/js/app.js": "/js/app.js", "/css/app.css": "/css/app.css", "/css/material-dashboard.css": "/css/material-dashboard.css", "/css/custom.css": "/css/custom.css" diff --git a/resources/views/admin/ocom/add.blade.php b/resources/views/admin/ocom/add.blade.php new file mode 100644 index 00000000..81d6cb8a --- /dev/null +++ b/resources/views/admin/ocom/add.blade.php @@ -0,0 +1,62 @@ +@extends('layouts.admin.main') + +@section('content') +
Liste des cours dans la base de données
+|
- @if($ocom->course_id != "")
-
+
+ @if($ocom->wasGiven() != false)
+ |
-
+
@else
- 1
+
+
@endif
0 {{$ocom->oren}} |
- {{$ocom->ocom}} |
- {{$ocom->nbPeriode}} |
- {{$ocom->objectif_rendement}} |
- {{$ocom->objectif_competence}} |
+ {{$ocom->oren}} |
+ {{$ocom->ocom}} |
+ {{$ocom->nbPeriode}} |
+ {{$ocom->objectif_rendement}} |
+ {{$ocom->objectif_competence}} |
-
- |
@@ -63,12 +82,14 @@
@endsection
@section('custom_scripts')
+
diff --git a/resources/views/admin/ocom/show.blade.php b/resources/views/admin/ocom/show.blade.php
index 0814d7dd..724f0677 100644
--- a/resources/views/admin/ocom/show.blade.php
+++ b/resources/views/admin/ocom/show.blade.php
@@ -9,6 +9,19 @@
+
+ @if($ocom->wasGiven() != false)
+
+
+ @else
+ 1 + +
+
+ @endif
+ 0 + +{{$ocom->oren}} @@ -21,7 +34,7 @@{{$ocom->objectif_competence}}
+
{{$ocom->nbPeriode}} {{$ocom->objectif_rendement}}
@if($ocom->course_id == "")
- Le cours n'est jamais donnée +Le cours n'a jamais été donnée @else -
|