diff --git a/app/Http/Controllers/EnrollmentActivityController.php b/app/Http/Controllers/EnrollmentActivityController.php index c85331a3..98377ec2 100644 --- a/app/Http/Controllers/EnrollmentActivityController.php +++ b/app/Http/Controllers/EnrollmentActivityController.php @@ -2,7 +2,7 @@ namespace App\Http\Controllers; -use App\EnrollmentActivity; +use App\Models\EnrollmentActivity; use Illuminate\Http\Request; class EnrollmentActivityController extends Controller diff --git a/app/Http/Controllers/KompetansepakkeController.php b/app/Http/Controllers/KompetansepakkeController.php index 840b01ef..a43fb443 100644 --- a/app/Http/Controllers/KompetansepakkeController.php +++ b/app/Http/Controllers/KompetansepakkeController.php @@ -2,7 +2,7 @@ namespace App\Http\Controllers; -use App\Kompetansepakke; +use App\Models\Kompetansepakke; use Illuminate\Http\Request; class KompetansepakkeController extends Controller diff --git a/app/Http/Controllers/SkolerController.php b/app/Http/Controllers/SkolerController.php index 52a3a7bb..91189e54 100644 --- a/app/Http/Controllers/SkolerController.php +++ b/app/Http/Controllers/SkolerController.php @@ -2,26 +2,14 @@ namespace App\Http\Controllers; -use App\Barnehage; -use App\Fylke; +use App\Models\Barnehage; +use App\Models\Fylke; use App\Http\Responses\SuccessResponse; -use App\Kommune; -use App\Skole; +use App\Models\Kommune; +use App\Models\Skole; use Illuminate\Http\Request; use Illuminate\Support\Facades\Artisan; -function filter_obsolete_counties($data) -{ - $obsolete_counties = ["01", "02", "04", "05", "06", "07", "08", "09", "10", "12", "13", "14", "16", "17", "19", "20"]; - $valid_counties = []; - foreach ($data as $county) { - if (!in_array($county->Fylkesnr, $obsolete_counties)) { - array_push($valid_counties, $county); - } - } - return $valid_counties; -} - function format_return_data($data) { return collect($data) @@ -43,8 +31,7 @@ class SkolerController extends Controller */ public function all_fylke() { - $all_fylke = Fylke::all(); - $all_fylke = filter_obsolete_counties($all_fylke); + $all_fylke = Fylke::where('nedlagt', false)->get(); return new SuccessResponse(format_return_data($all_fylke)); } diff --git a/app/Barnehage.php b/app/Models/Barnehage.php similarity index 83% rename from app/Barnehage.php rename to app/Models/Barnehage.php index be595cfb..71139ab9 100644 --- a/app/Barnehage.php +++ b/app/Models/Barnehage.php @@ -1,10 +1,10 @@ getKeyName()] = $annenOrgNr; - Barnehage::updateOrCreate($key, + Barnehage::updateOrCreate($key, [ - 'KommuneNr' => Kommune::$annetKommuneNr, - 'Navn' => Barnehage::$annetBarnehageNavn, + 'KommuneNr' => Kommune::$annetKommuneNr, + 'Navn' => Barnehage::$annetBarnehageNavn, 'FulltNavn' => Barnehage::$annetBarnehageNavn, - 'OrgNr' => $annenOrgNr, + 'OrgNr' => $annenOrgNr, 'NSRId' => $annenNsrId, 'FylkeNr' => Fylke::$annetFylkesNr, 'ErBarnehage' => true, diff --git a/app/Diploma.php b/app/Models/Diploma.php similarity index 85% rename from app/Diploma.php rename to app/Models/Diploma.php index bf72ed26..b4852048 100644 --- a/app/Diploma.php +++ b/app/Models/Diploma.php @@ -1,6 +1,6 @@ getKeyName()] = Fylke::$annetFylkesNr; - Fylke::updateOrCreate($key, ['Fylkesnr' => Fylke::$annetFylkesNr, 'Navn' => Fylke::$annetFylkesNavn, 'OrgNr' => $annetOrgNr, 'OrgNrFylkesmann' => $annetOrgNr]); + Fylke::updateOrCreate($key, ['Fylkesnr' => Fylke::$annetFylkesNr, 'Navn' => Fylke::$annetFylkesNavn, 'OrgNr' => $annetOrgNr, 'OrgNrFylkesmann' => $annetOrgNr, 'nedlagt' => false]); } public function UpdateFylke($county) { diff --git a/app/Kommune.php b/app/Models/Kommune.php similarity index 75% rename from app/Kommune.php rename to app/Models/Kommune.php index bcc4068c..7baaeb1f 100644 --- a/app/Kommune.php +++ b/app/Models/Kommune.php @@ -1,9 +1,9 @@ getKeyName()] = Kommune::$annetKommuneNr; Kommune::updateOrCreate($key, [ - 'Fylkesnr' => Fylke::$annetFylkesNr, - 'Navn' => Kommune::$annetKommuneNavn, - 'OrgNr' => '999999999', - 'Kommunenr' => Kommune::$annetKommuneNr, + 'Fylkesnr' => Fylke::$annetFylkesNr, + 'Navn' => Kommune::$annetKommuneNavn, + 'OrgNr' => '999999999', + 'Kommunenr' => Kommune::$annetKommuneNr, 'ErNedlagt' => false ]); diff --git a/app/Kompetansepakke.php b/app/Models/Kompetansepakke.php similarity index 81% rename from app/Kompetansepakke.php rename to app/Models/Kompetansepakke.php index 26fcf490..0eb3d83b 100644 --- a/app/Kompetansepakke.php +++ b/app/Models/Kompetansepakke.php @@ -1,6 +1,6 @@ getKeyName()] = $annenNsrId; - Skole::updateOrCreate($key, + Skole::updateOrCreate($key, [ - 'Kommunenr' => Kommune::$annetKommuneNr, - 'Navn' => Skole::$annetSkoleNavn, + 'Kommunenr' => Kommune::$annetKommuneNr, + 'Navn' => Skole::$annetSkoleNavn, 'FulltNavn' => Skole::$annetSkoleNavn, - 'OrgNr' => '999999999', + 'OrgNr' => '999999999', 'NSRId' => $annenNsrId, 'ErSkole' => true, 'ErSkoleEier' => false, @@ -49,6 +49,6 @@ public function CreateAnnenSkole() { public function UpdateSkole($school) { $key[$this->getKeyName()] = $school[$this->getKeyName()]; - Skole::updateOrCreate($key, $school); + Skole::updateOrCreate($key, $school); } } diff --git a/app/Services/DataNsrService.php b/app/Services/DataNsrService.php index 37d7b0e7..655d01f7 100644 --- a/app/Services/DataNsrService.php +++ b/app/Services/DataNsrService.php @@ -2,10 +2,10 @@ namespace App\Services; -use App\Barnehage; -use App\Fylke; -use App\Kommune; -use App\Skole; +use App\Models\Barnehage; +use App\Models\Fylke; +use App\Models\Kommune; +use App\Models\Skole; use Exception; use GuzzleHttp\Client; use GuzzleHttp\Exception\GuzzleException; @@ -38,7 +38,7 @@ public function getSchoolByOrgNr($orgnr) { try{ return $this->request($this->nsrDomain, "v3/enhet/$orgnr"); - } + } catch (\Exception $e){ throw new Exception("Could not find school with orgnr $orgnr"); } @@ -48,7 +48,7 @@ public function getKindergartenByOrgNr($orgnr) { try{ return $this->request($this->nbrDomain, "v3/enhet/$orgnr"); - } + } catch (\Exception $e) { throw new Exception("Could not find kindergarten with orgnr $orgnr"); } @@ -85,7 +85,7 @@ private function getEnheter(string $domain): array $fylkesnummer = array(); // Make an assosiative array of NSR id to enhet - // and find all fylkesnummers in use + // and find all fylkesnummers in use foreach ($enheter as $enhet) { $idToEnhet[$enhet->NSRId] = $enhet; $fylkesnummer[$enhet->FylkeNr] = true; @@ -106,7 +106,7 @@ private function getEnheter(string $domain): array if(!($i % 1000)) { logger("GetEnheter processed " . $i); } - + if (!isset($idToEnhet[$enhetInFylke->NSRId])) { continue; } @@ -237,4 +237,3 @@ public function store_kindergartens() logger("store_kindergartens complete."); } } - diff --git a/app/Services/DiplomaService.php b/app/Services/DiplomaService.php index 0ac75ee2..b09f3cb6 100644 --- a/app/Services/DiplomaService.php +++ b/app/Services/DiplomaService.php @@ -4,8 +4,8 @@ use App\Services\CanvasService; use GuzzleHttp\Client; use App\Exceptions\CanvasException; -use App\Kompetansepakke; -use App\Diploma; +use App\Models\Kompetansepakke; +use App\Models\Diploma; class DiplomaService { diff --git a/app/helpers.php b/app/Utils/helpers.php similarity index 100% rename from app/helpers.php rename to app/Utils/helpers.php diff --git a/composer.json b/composer.json index 2524ab94..dbf96a42 100644 --- a/composer.json +++ b/composer.json @@ -57,11 +57,12 @@ "autoload": { "psr-4": { "App\\": "app/", + "App\\Models\\": "app/Models/", "Database\\Factories\\": "database/factories/", "Database\\Seeders\\": "database/seeders/" }, "files": [ - "app/helpers.php" + "app/Utils/helpers.php" ] }, "autoload-dev": { diff --git a/composer.json.dev b/composer.json.dev index 7d8abdb3..86af6de7 100644 --- a/composer.json.dev +++ b/composer.json.dev @@ -56,11 +56,12 @@ "autoload": { "psr-4": { "App\\": "app/", + "App\\Models\\": "app/Models/", "Database\\Factories\\": "database/factories/", "Database\\Seeders\\": "database/seeders/" }, "files": [ - "app/helpers.php" + "app/Utils/helpers.php" ] }, "autoload-dev": { diff --git a/composer.json.prod b/composer.json.prod index 7d8abdb3..86af6de7 100644 --- a/composer.json.prod +++ b/composer.json.prod @@ -56,11 +56,12 @@ "autoload": { "psr-4": { "App\\": "app/", + "App\\Models\\": "app/Models/", "Database\\Factories\\": "database/factories/", "Database\\Seeders\\": "database/seeders/" }, "files": [ - "app/helpers.php" + "app/Utils/helpers.php" ] }, "autoload-dev": { diff --git a/database/migrations/2023_12_21_115102_add_er_nedlagt_to_fylkes.php b/database/migrations/2023_12_21_115102_add_er_nedlagt_to_fylkes.php new file mode 100644 index 00000000..67928bdb --- /dev/null +++ b/database/migrations/2023_12_21_115102_add_er_nedlagt_to_fylkes.php @@ -0,0 +1,32 @@ +boolean('nedlagt'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('fylkes', function (Blueprint $table) { + $table->dropColumn('nedlagt'); + }); + } +}; diff --git a/database/seeds/EnrollmentActivityTableSeeder.php b/database/seeds/EnrollmentActivityTableSeeder.php index fecd5f24..1f9e36da 100644 --- a/database/seeds/EnrollmentActivityTableSeeder.php +++ b/database/seeds/EnrollmentActivityTableSeeder.php @@ -1,6 +1,6 @@