diff --git a/app/Http/Controllers/ScheduleController.php b/app/Http/Controllers/ScheduleController.php index f4106d8..d14ac4f 100644 --- a/app/Http/Controllers/ScheduleController.php +++ b/app/Http/Controllers/ScheduleController.php @@ -50,6 +50,7 @@ class ScheduleController extends Controller $arSchedules[$schedule->user_id] = array( $schedule->slot => array( $schedule->date->format('d/m/Y') => array( + 'id' => $schedule->id, 'type' => $schedule->activity, 'text' => $schedule->description, 'id_lie' => $schedule->id_lie, @@ -63,6 +64,7 @@ class ScheduleController extends Controller //new slot $arSchedules[$schedule->user_id][$schedule->slot] = array( $schedule->date->format('d/m/Y') => array( + 'id' => $schedule->id, 'type' => $schedule->activity, 'text' => $schedule->description, 'id_lie' => $schedule->id_lie, @@ -74,6 +76,7 @@ class ScheduleController extends Controller if ($prevDate != $schedule->date) { //new date $arSchedules[$schedule->user_id][$schedule->slot][$schedule->date->format('d/m/Y')] = array( + 'id' => $schedule->id, 'type' => $schedule->activity, 'text' => $schedule->description, 'id_lie' => $schedule->id_lie, @@ -102,66 +105,4 @@ class ScheduleController extends Controller return view('schedule.index', compact('users', 'date', 'weekCells', 'arSchedules')); } - - /** - * Migrates data from week_plannings - * to schedules table - * - * @author Olivier Legat - * - */ - public function import(Request $request) - { - // $schedule_test = Schedule::first(); - // dd($schedule_test->relatedModel); - - $week_plannings = WeekPlanning::all(); - - foreach ($week_plannings as $oneweek) { - $user_id = $oneweek->user_id; - $plan = $oneweek->planning; - foreach ($plan as $time => $data) { - $date = Carbon::createFromTimestamp($time); - foreach ($data as $dayslot => $cell) { - $activite = $this->convertColorToType($cell["type"]); - $description = $cell["text"]; - $id_objetlie = $cell["foreign"]; - $type_objetlie = $cell["cellModel"]; //c'est une table d'après l'Enum CellModel - - $collected = [ - 'user_id' => $user_id, - 'date' => $date, - 'slot' => $dayslot, - 'activity' => $activite, - 'description' => $description, - 'id_lie' => $id_objetlie, - 'model_lie' => $type_objetlie - ]; - //si activite null et description null ne pas enregistrer - if (!is_null($activite) && !is_null($description)) { - $schedule = new Schedule(); - $schedule->fill($collected); - $schedule->save(); - } - } - } - } - dump('finished'); - } - - /** - * convertir une value de couleur en type - */ - private function convertColorToType($value) { - $converter = array( - '#c6e0b4' => 'support', - '#b4c6e7' => 'rnd', - '#00b0f0' => 'dev', - '#ffe699' => 'projects', - '#f4b084' => 'management', - '#aeaaaa' => 'absence', - 'abscence' => 'absence' - ); - return $converter[$value] ?? null; - } } diff --git a/database/migrations/2021_12_03_195755_create_schedules_table.php b/database/migrations/2021_12_03_195755_create_schedules_table.php index 21aaf36..ade7153 100644 --- a/database/migrations/2021_12_03_195755_create_schedules_table.php +++ b/database/migrations/2021_12_03_195755_create_schedules_table.php @@ -1,5 +1,8 @@ timestamps(); $table->unique(['user_id','date','slot'], 'user_day_slot_unique'); }); + + //migrate data from week plannings + $week_plannings = WeekPlanning::all(); + + foreach ($week_plannings as $oneweek) { + $user_id = $oneweek->user_id; + $plan = $oneweek->planning; + foreach ($plan as $time => $data) { + $date = Carbon::createFromTimestamp($time); + foreach ($data as $dayslot => $cell) { + $activite = $this->convertColorToType($cell["type"]); + $description = $cell["text"]; + $id_objetlie = $cell["foreign"]; + $type_objetlie = $cell["cellModel"]; //c'est une table d'après l'Enum CellModel + + $collected = [ + 'user_id' => $user_id, + 'date' => $date, + 'slot' => $dayslot, + 'activity' => $activite, + 'description' => $description, + 'id_lie' => $id_objetlie, + 'model_lie' => $type_objetlie + ]; + //si activite null et description null ne pas enregistrer + if (!is_null($activite) && !is_null($description)) { + $schedule = new Schedule(); + $schedule->fill($collected); + $schedule->save(); + } + } + } + } } /** @@ -36,4 +72,21 @@ class CreateSchedulesTable extends Migration { Schema::dropIfExists('schedules'); } + + + /** + * convertir une value de couleur en type + */ + private function convertColorToType($value) { + $converter = array( + '#c6e0b4' => 'support', + '#b4c6e7' => 'rnd', + '#00b0f0' => 'dev', + '#ffe699' => 'projects', + '#f4b084' => 'management', + '#aeaaaa' => 'absence', + 'abscence' => 'absence' + ); + return $converter[$value] ?? null; + } }