Skip to content

Commit c33fc56

Browse files
committed
WIP structure de données subdivision
1 parent bac5b79 commit c33fc56

6 files changed

+219
-0
lines changed

app/Models/Pays.php

+3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
*
3636
* @property int $ch_pay_id
3737
* @property string $ch_pay_label
38+
* @property bool $use_subdivisions
3839
* @property int $ch_pay_publication
3940
* @property string $ch_pay_continent
4041
* @property int|null $ch_pay_emplacement
@@ -124,6 +125,7 @@
124125
* @method static Builder|Pays whereChPayId($value)
125126
* @method static Builder|Pays whereChPayIndustrieCarte($value)
126127
* @method static Builder|Pays whereChPayLabel($value)
128+
* @method static Builder|Pays whereUseSubdivisions($value)
127129
* @method static Builder|Pays whereChPayLangueOfficielle($value)
128130
* @method static Builder|Pays whereChPayLienForum($value)
129131
* @method static Builder|Pays whereChPayLienImgdrapeau($value)
@@ -217,6 +219,7 @@ class Pays extends Model implements Searchable, Infrastructurable, Resourceable,
217219

218220
protected array $dontVersionFields = [
219221
'ch_pay_label',
222+
'use_subdivisions',
220223
'ch_pay_publication',
221224
'ch_pay_date',
222225
'ch_pay_nb_update',

app/Models/Subdivision.php

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
namespace Roxayl\MondeGC\Models;
4+
5+
use Carbon\Carbon;
6+
use Illuminate\Database\Eloquent\Builder;
7+
use Illuminate\Database\Eloquent\Model;
8+
use Illuminate\Database\Eloquent\Relations\BelongsTo;
9+
10+
/**
11+
* Class Subdivision
12+
*
13+
* @property int $id
14+
* @property int|null $subdivision_type_id
15+
* @property string $name
16+
* @property string|null $summary
17+
* @property string|null $content
18+
* @property Carbon|null $created_at
19+
* @property Carbon|null $updated_at
20+
* @property SubdivisionType|null $subdivision_type
21+
* @property-read SubdivisionType|null $subdivisionType
22+
* @method static Builder|Subdivision newModelQuery()
23+
* @method static Builder|Subdivision newQuery()
24+
* @method static Builder|Subdivision query()
25+
* @method static Builder|Subdivision whereContent($value)
26+
* @method static Builder|Subdivision whereCreatedAt($value)
27+
* @method static Builder|Subdivision whereId($value)
28+
* @method static Builder|Subdivision whereName($value)
29+
* @method static Builder|Subdivision whereSubdivisionTypeId($value)
30+
* @method static Builder|Subdivision whereSummary($value)
31+
* @method static Builder|Subdivision whereUpdatedAt($value)
32+
* @mixin \Eloquent
33+
*/
34+
class Subdivision extends Model
35+
{
36+
protected $table = 'subdivisions';
37+
38+
protected $casts = [
39+
'subdivision_type_id' => 'int'
40+
];
41+
42+
protected $fillable = [
43+
'subdivision_type_id',
44+
'name',
45+
'summary',
46+
'content'
47+
];
48+
49+
/**
50+
* @return BelongsTo
51+
*/
52+
public function subdivisionType(): BelongsTo
53+
{
54+
return $this->belongsTo(SubdivisionType::class);
55+
}
56+
}

app/Models/SubdivisionType.php

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
namespace Roxayl\MondeGC\Models;
4+
5+
use Carbon\Carbon;
6+
use Illuminate\Database\Eloquent\Builder;
7+
use Illuminate\Database\Eloquent\Collection;
8+
use Illuminate\Database\Eloquent\Model;
9+
use Illuminate\Database\Eloquent\Relations\BelongsTo;
10+
use Illuminate\Database\Eloquent\Relations\HasMany;
11+
12+
/**
13+
* Class SubdivisionType
14+
*
15+
* @property int $id
16+
* @property int|null $pays_id
17+
* @property string $type_name
18+
* @property Carbon|null $created_at
19+
* @property Carbon|null $updated_at
20+
* @property Pays|null $pays
21+
* @property Collection|Subdivision[] $subdivisions
22+
* @property-read int|null $subdivisions_count
23+
* @method static Builder|SubdivisionType newModelQuery()
24+
* @method static Builder|SubdivisionType newQuery()
25+
* @method static Builder|SubdivisionType query()
26+
* @method static Builder|SubdivisionType whereCreatedAt($value)
27+
* @method static Builder|SubdivisionType whereId($value)
28+
* @method static Builder|SubdivisionType wherePaysId($value)
29+
* @method static Builder|SubdivisionType whereTypeName($value)
30+
* @method static Builder|SubdivisionType whereUpdatedAt($value)
31+
* @mixin \Eloquent
32+
*/
33+
class SubdivisionType extends Model
34+
{
35+
protected $table = 'subdivision_types';
36+
37+
protected $casts = [
38+
'pays_id' => 'int'
39+
];
40+
41+
protected $fillable = [
42+
'pays_id',
43+
'type_name'
44+
];
45+
46+
/**
47+
* @return BelongsTo
48+
*/
49+
public function pays(): BelongsTo
50+
{
51+
return $this->belongsTo(Pays::class, 'pays_id', 'ch_pay_id');
52+
}
53+
54+
/**
55+
* @return HasMany
56+
*/
57+
public function subdivisions(): HasMany
58+
{
59+
return $this->hasMany(Subdivision::class);
60+
}
61+
}

app/Models/Ville.php

+13
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
* @property int $ch_vil_paysID
3434
* @property int $ch_vil_user
3535
* @property string $ch_vil_label
36+
* @property int|null $subdivision_id
3637
* @property Carbon|null $ch_vil_date_enregistrement
3738
* @property Carbon|null $ch_vil_mis_jour
3839
* @property int|null $ch_vil_nb_update
@@ -83,6 +84,7 @@
8384
* @method static Builder|Ville whereChVilHeader($value)
8485
* @method static Builder|Ville whereChVilID($value)
8586
* @method static Builder|Ville whereChVilLabel($value)
87+
* @method static Builder|Ville whereSubdivisionId($value)
8688
* @method static Builder|Ville whereChVilLegendeImg1($value)
8789
* @method static Builder|Ville whereChVilLegendeImg2($value)
8890
* @method static Builder|Ville whereChVilLegendeImg3($value)
@@ -120,6 +122,7 @@ class Ville extends Model implements Searchable, Infrastructurable, Resourceable
120122
protected $casts = [
121123
'ch_vil_paysID' => 'int',
122124
'ch_vil_user' => 'int',
125+
'subdivision_id' => 'int',
123126
'ch_vil_nb_update' => 'int',
124127
'ch_vil_coord_X' => 'float',
125128
'ch_vil_coord_Y' => 'float',
@@ -136,6 +139,7 @@ class Ville extends Model implements Searchable, Infrastructurable, Resourceable
136139
'ch_vil_paysID',
137140
'ch_vil_user',
138141
'ch_vil_label',
142+
'subdivision_id',
139143
'ch_vil_date_enregistrement',
140144
'ch_vil_mis_jour',
141145
'ch_vil_nb_update',
@@ -169,6 +173,7 @@ class Ville extends Model implements Searchable, Infrastructurable, Resourceable
169173
'ch_vil_paysID',
170174
'ch_vil_user',
171175
'ch_vil_label',
176+
'subdivision_id',
172177
'ch_vil_date_enregistrement',
173178
'ch_vil_mis_jour',
174179
'ch_vil_nb_update',
@@ -216,6 +221,14 @@ public function patrimoines(): HasMany
216221
return $this->hasMany(Patrimoine::class, 'ch_pat_villeID');
217222
}
218223

224+
/**
225+
* @return BelongsTo
226+
*/
227+
public function subdivision(): BelongsTo
228+
{
229+
return $this->belongsTo(Subdivision::class, 'subdivision_id');
230+
}
231+
219232
/**
220233
* @return Collection<int, CustomUser>
221234
*/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
class CreateSubdivisionTable extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*
12+
* @return void
13+
*/
14+
public function up()
15+
{
16+
Schema::create('subdivision_types', function (Blueprint $table) {
17+
$table->id();
18+
$table->integer('pays_id')->nullable();
19+
$table->string('type_name');
20+
$table->timestamps();
21+
$table->foreign('pays_id')
22+
->references('ch_pay_id')->on('pays')
23+
->nullOnDelete()->cascadeOnUpdate();
24+
});
25+
26+
Schema::create('subdivisions', function (Blueprint $table) {
27+
$table->id();
28+
$table->unsignedBigInteger('subdivision_type_id')->nullable();
29+
$table->string('name', 191);
30+
$table->longText('summary')->nullable();
31+
$table->longText('content')->nullable();
32+
$table->timestamps();
33+
$table->foreign('subdivision_type_id')
34+
->references('id')->on('subdivision_types')
35+
->nullOnDelete()->cascadeOnUpdate();
36+
});
37+
}
38+
39+
/**
40+
* Reverse the migrations.
41+
*
42+
* @return void
43+
*/
44+
public function down()
45+
{
46+
Schema::dropIfExists('subdivisions');
47+
Schema::dropIfExists('subdivision_types');
48+
}
49+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
class UseSubdivisions extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*
12+
* @return void
13+
*/
14+
public function up()
15+
{
16+
Schema::table('pays', function (Blueprint $table) {
17+
$table->boolean('use_subdivisions')->after('ch_pay_label')
18+
->default(false);
19+
});
20+
21+
Schema::table('villes', function (Blueprint $table) {
22+
$table->unsignedBigInteger('subdivision_id')->after('ch_vil_label')
23+
->nullable()->default(null);
24+
});
25+
}
26+
27+
/**
28+
* Reverse the migrations.
29+
*
30+
* @return void
31+
*/
32+
public function down()
33+
{
34+
Schema::dropColumns('villes', 'subdivision_id');
35+
Schema::dropColumns('pays', 'use_subdivisions');
36+
}
37+
}

0 commit comments

Comments
 (0)