remove old plannings code
This commit is contained in:
parent
24393d6f4e
commit
812b44636a
7 changed files with 44 additions and 212 deletions
|
|
@ -1,3 +1,9 @@
|
|||
### 08.03.2022 -> 1.08
|
||||
- passage à 8 slots dans le planning
|
||||
|
||||
### 03.01.2022 -> 1.0.7
|
||||
- nouveau stockage pour le planning
|
||||
|
||||
### 01.12 -> 1.0.6
|
||||
- Ajout d'un nouveau type de Ticket : Demande relative aux Newsletters
|
||||
|
||||
|
|
|
|||
|
|
@ -1,65 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Enums\Role;
|
||||
use App\Http\Requests\EraseCellContentRequest;
|
||||
use App\Http\Requests\SetCellContentRequest;
|
||||
use App\Models\User;
|
||||
use App\Models\WeekPlanning;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
class PlanningController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$date = Carbon::now()->startOfWeek();
|
||||
if ($request->p) {
|
||||
$date = Carbon::createFromTimestamp($request->p)->startOfWeek();
|
||||
}
|
||||
$userIds = User::where('role', Role::developper())->pluck('id');
|
||||
$weeks = WeekPlanning::whereDate('start', $date)
|
||||
->with('user')->get();
|
||||
foreach ($userIds as $id) {
|
||||
// auto create missing planning for user
|
||||
if ($date >= Carbon::now()->startOfWeek() and !$weeks->contains('user.id', $id)) {
|
||||
$wp = new WeekPlanning([
|
||||
'start' => $date,
|
||||
'planning' => WeekPlanning::getWeekBlock($date),
|
||||
'user_id' => $id
|
||||
]);
|
||||
$wp->saveOrFail();
|
||||
$weeks->push($wp);
|
||||
}
|
||||
}
|
||||
return view('planning.index', compact('weeks', 'date'));
|
||||
}
|
||||
|
||||
public function setCellContent(SetCellContentRequest $request)
|
||||
{
|
||||
$wp = WeekPlanning::findOrFail($request->id);
|
||||
if (!isset($wp->planning[$request->day][$request->row])) {
|
||||
abort(422, trans('Ce jour et ce moment n\'existent pas.'));
|
||||
}
|
||||
$planning = $wp->planning;
|
||||
$planning[$request->day][$request->row] =
|
||||
array_merge(WeekPlanning::getCell(), array_intersect_key($request->all(), WeekPlanning::getCell()));
|
||||
$wp->planning = $planning;
|
||||
$wp->saveOrFail();
|
||||
return \response()->json(['status' => true]);
|
||||
}
|
||||
|
||||
public function eraseCellContent(EraseCellContentRequest $request)
|
||||
{
|
||||
$wp = WeekPlanning::findOrFail($request->id);
|
||||
if (!isset($wp->planning[$request->day][$request->row])) {
|
||||
abort(422, trans('Ce jour et ce moment n\'existent pas.'));
|
||||
}
|
||||
$planning = $wp->planning;
|
||||
$planning[$request->day][$request->row] = WeekPlanning::getCell();
|
||||
$wp->planning = $planning;
|
||||
$wp->saveOrFail();
|
||||
return \response()->json(['status' => true]);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,61 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\Planning\TableRow;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
class WeekPlanning extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
public $casts = [
|
||||
'start' => 'date',
|
||||
'planning' => 'array'
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
'start', 'planning', 'user_id'
|
||||
];
|
||||
|
||||
public static function getWeekBlock(Carbon $start): array
|
||||
{
|
||||
$start = $start->copy();
|
||||
$out = [];
|
||||
$daysOfWeek = 5;
|
||||
for ($i = 1; $i <= $daysOfWeek; $i++) {
|
||||
$out[$start->timestamp] = [];
|
||||
foreach (TableRow::toArray() as $tableRow) {
|
||||
$out[$start->timestamp][$tableRow->value] = \array_replace(
|
||||
self::getCell(),
|
||||
[
|
||||
'row' => $tableRow->value
|
||||
]
|
||||
);
|
||||
}
|
||||
$day = $start->addDay();
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
|
||||
public static function getCell(): array
|
||||
{
|
||||
return [
|
||||
/** @var \App\Enums\Planning\CellType */
|
||||
'type' => null,
|
||||
/** @var \App\Enums\Planning\TableRow */
|
||||
'row' => null,
|
||||
'foreign' => null,
|
||||
/** @var \App\Enums\Planning\CellModel */
|
||||
'cellModel' => null,
|
||||
'text' => ''
|
||||
];
|
||||
}
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "ldcweb/supportweb",
|
||||
"version": "1.0.6",
|
||||
"version": "1.0.8",
|
||||
"type": "project",
|
||||
"description": "The Laravel Framework.",
|
||||
"keywords": [
|
||||
|
|
|
|||
|
|
@ -1,76 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Enums\Planning\CellModel;
|
||||
use App\Enums\Planning\CellType;
|
||||
use App\Models\Project;
|
||||
use App\Models\Site;
|
||||
use App\Models\Ticket;
|
||||
use App\Models\WeekPlanning;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use ReflectionFunction;
|
||||
|
||||
class WeekPlanningFactory extends Factory
|
||||
{
|
||||
|
||||
/**
|
||||
* The name of the factory's corresponding model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $model = WeekPlanning::class;
|
||||
|
||||
/** @var \Illuminate\Support\Carbon */
|
||||
private static $currentDate = null;
|
||||
|
||||
private static $user_id = null;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function definition()
|
||||
{
|
||||
$func = new ReflectionFunction(collect($this->states)->last());
|
||||
if (static::$user_id and $func->getStaticVariables()['state']['user_id'] != static::$user_id) {
|
||||
static::$currentDate = null;
|
||||
}
|
||||
if (!static::$currentDate) {
|
||||
static::$user_id = $func->getStaticVariables()['state']['user_id'];
|
||||
static::$currentDate = $func->getStaticVariables()['state']['start'];
|
||||
} else {
|
||||
static::$currentDate = static::$currentDate->endOfWeek()->addDay();
|
||||
}
|
||||
$wBlock = WeekPlanning::getWeekBlock(static::$currentDate);
|
||||
foreach ($wBlock as &$dayRows) {
|
||||
foreach ($dayRows as &$cell) {
|
||||
$cell['type'] = collect(CellType::toArray())->random()->value;
|
||||
if (rand(0, 3)) {
|
||||
$cellModel = collect(CellModel::toArray())->random();
|
||||
$cell['cellModel'] = $cellModel->value;
|
||||
switch ($cellModel) {
|
||||
case (new Ticket())->getTable():
|
||||
$cell['foreign'] = Ticket::select(['id'])
|
||||
->inRandomOrder()->first()->id;
|
||||
break;
|
||||
case (new Site())->getTable():
|
||||
$cell['foreign'] = Site::select(['id'])
|
||||
->inRandomOrder()->first()->id;
|
||||
break;
|
||||
case (new Project())->getTable():
|
||||
$cell['foreign'] = Project::select(['id'])
|
||||
->inRandomOrder()->first()->id;
|
||||
break;
|
||||
}
|
||||
$cell['text'] = $this->faker->text(rand(20, 50));
|
||||
}
|
||||
}
|
||||
}
|
||||
return [
|
||||
'start' => static::$currentDate,
|
||||
'planning' => $wBlock
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class DropWeekPlanningsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::dropIfExists('week_plannings');
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::create('week_plannings', function (Blueprint $table) {
|
||||
$table->id();
|
||||
|
||||
$table->date('start');
|
||||
$table->text('planning');
|
||||
|
||||
$table->foreignId('user_id')->constrained('users')->cascadeOnDelete();
|
||||
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -3,7 +3,6 @@
|
|||
use App\Http\Controllers\FileController;
|
||||
use App\Http\Controllers\HomeController;
|
||||
use App\Http\Controllers\LogController;
|
||||
use App\Http\Controllers\PlanningController;
|
||||
use App\Http\Controllers\ProjectController;
|
||||
use App\Http\Controllers\ScheduleController;
|
||||
use App\Http\Controllers\SiteController;
|
||||
|
|
@ -77,14 +76,6 @@ Route::middleware(['auth'])->group(function () {
|
|||
->name('message.create');
|
||||
});
|
||||
|
||||
// Route::prefix('/planning')->name('planning.')->group(function () {
|
||||
// Route::get('/', [PlanningController::class, 'index'])->name('index');
|
||||
// Route::post('/setCellContent', [PlanningController::class, 'setCellContent'])
|
||||
// ->name('setCellContent');
|
||||
// Route::post('/eraseCellContent', [PlanningController::class, 'eraseCellContent'])
|
||||
// ->name('eraseCellContent');
|
||||
// });
|
||||
|
||||
Route::prefix('/schedule')->name('schedule.')->group(function () {
|
||||
Route::get('/', [ScheduleController::class, 'index'])->name('index');
|
||||
Route::post('/setCellContent', [ScheduleController::class, 'setCellContent'])
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue