Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stage #288

Merged
merged 6 commits into from
Jan 10, 2024
Merged

Stage #288

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/Http/Controllers/EnrollmentActivityController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Http\Controllers;

use App\EnrollmentActivity;
use App\Models\EnrollmentActivity;
use Illuminate\Http\Request;

class EnrollmentActivityController extends Controller
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/KompetansepakkeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Http\Controllers;

use App\Kompetansepakke;
use App\Models\Kompetansepakke;
use Illuminate\Http\Request;

class KompetansepakkeController extends Controller
Expand Down
23 changes: 5 additions & 18 deletions app/Http/Controllers/SkolerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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));
}

Expand Down
14 changes: 7 additions & 7 deletions app/Barnehage.php → app/Models/Barnehage.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

namespace App;
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use App\Fylke;
use App\Kommune;
use App\Models\Fylke;
use App\Models\Kommune;

class Barnehage extends Model
{
Expand All @@ -30,12 +30,12 @@ public function CreateAnnenBarnehage() {
$annenNsrId = '99';
$annenOrgNr = '999999999';
$key[$this->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,
Expand Down
2 changes: 1 addition & 1 deletion app/Diploma.php → app/Models/Diploma.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace App;
namespace App\Models;

use Illuminate\Database\Eloquent\Model;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace App;
namespace App\Models;

use Illuminate\Database\Eloquent\Model;

Expand Down
6 changes: 3 additions & 3 deletions app/Fylke.php → app/Models/Fylke.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace App;
namespace App\Models;

use Illuminate\Database\Eloquent\Model;

Expand All @@ -10,13 +10,13 @@ class Fylke extends Model
public static $annetFylkesNr = '99';
public $incrementing = false;
protected $primaryKey = 'Fylkesnr';
protected $fillable = ['Fylkesnr', 'Navn', 'OrgNr', 'OrgNrFylkesmann'];
protected $fillable = ['Fylkesnr', 'Navn', 'OrgNr', 'OrgNrFylkesmann', 'nedlagt'];

public function CreateAnnetFylke() {
$annetOrgNr = '999999999';

$key[$this->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) {
Expand Down
12 changes: 6 additions & 6 deletions app/Kommune.php → app/Models/Kommune.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

namespace App;
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use App\Fylke;
use App\Models\Fylke;

class Kommune extends Model
{
Expand All @@ -16,10 +16,10 @@ class Kommune extends Model
public function CreateAnnenKommune() {
$key[$this->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
]);

Expand Down
2 changes: 1 addition & 1 deletion app/Kompetansepakke.php → app/Models/Kompetansepakke.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace App;
namespace App\Models;

use Illuminate\Database\Eloquent\Model;

Expand Down
14 changes: 7 additions & 7 deletions app/Skole.php → app/Models/Skole.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

namespace App;
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use App\Kommune;
use App\Models\Kommune;

class Skole extends Model
{
Expand All @@ -29,12 +29,12 @@ class Skole extends Model
public function CreateAnnenSkole() {
$annenNsrId = '99';
$key[$this->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,
Expand All @@ -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);
}
}
17 changes: 8 additions & 9 deletions app/Services/DataNsrService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
}
Expand All @@ -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");
}
Expand Down Expand Up @@ -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;
Expand All @@ -106,7 +106,7 @@ private function getEnheter(string $domain): array
if(!($i % 1000)) {
logger("GetEnheter processed " . $i);
}

if (!isset($idToEnhet[$enhetInFylke->NSRId])) {
continue;
}
Expand Down Expand Up @@ -237,4 +237,3 @@ public function store_kindergartens()
logger("store_kindergartens complete.");
}
}

4 changes: 2 additions & 2 deletions app/Services/DiplomaService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
File renamed without changes.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
3 changes: 2 additions & 1 deletion composer.json.dev
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
3 changes: 2 additions & 1 deletion composer.json.prod
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
32 changes: 32 additions & 0 deletions database/migrations/2023_12_21_115102_add_er_nedlagt_to_fylkes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('fylkes', function (Blueprint $table) {
$table->boolean('nedlagt');
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('fylkes', function (Blueprint $table) {
$table->dropColumn('nedlagt');
});
}
};
2 changes: 1 addition & 1 deletion database/seeds/EnrollmentActivityTableSeeder.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

use App\EnrollmentActivity;
use App\Models\EnrollmentActivity;
use Faker\Factory;
use Illuminate\Database\Seeder;

Expand Down