Skip to content

Commit

Permalink
Merge branch 'feature/da_add_la_basepackage' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
dasscheman committed Jul 1, 2024
2 parents 03457b2 + c6ffb6d commit 3fecaae
Show file tree
Hide file tree
Showing 34 changed files with 2,235 additions and 491 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docker-image-Laravel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
uses: redhat-actions/buildah-build@v2
with:
image: fsw-openshift
tags: latest
tags: latest develop
dockerfiles: |
./openshift/openshift.dockerfile
- name: Push to registry
Expand Down
137 changes: 137 additions & 0 deletions app/Http/Helpers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
<?php

if (! function_exists('getCountriesByIso')) {

function getCountriesByIso()
{
$fileContents = file(storage_path('app/country_list.csv'));
foreach ($fileContents as $line) {
$tempLine = str_getcsv($line);
$tempLine[0] = preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $tempLine[0]);
$data[$tempLine[0]] = [
$tempLine[0],
$tempLine[1],
$tempLine[2],
$tempLine[3],
];
}

return $data;
}
}

if (! function_exists('getCountriesByName')) {
function getCountriesByName()
{
$fileContents = file(storage_path('app/country_list.csv'));

foreach ($fileContents as $line) {
$tempLine = str_getcsv($line);
$tempLine[0] = preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $tempLine[0]);
$data[$tempLine[1]] = [
$tempLine[0],
$tempLine[1],
$tempLine[2],
$tempLine[3],
];
}

return $data;
}
}

if (! function_exists('csvToArray')) {
function csvToArray($filename = '', $headers = null, $delimiter = ';')
{
if (! file_exists($filename) || ! is_readable($filename)) {
return false;
}

$data = [];
if (($handle = fopen($filename, 'r')) !== false) {
$headerSet = false;
while (($row = fgetcsv($handle, 1000, $delimiter)) !== false) {
if (empty($headers) && ! $headerSet) {
$headers = $row;
$headerSet = true;

continue;
}
$data[] = array_combine($headers, $row);
}
fclose($handle);
}

return $data;
}
}

if (! function_exists('get_flag_for_locale')) {
function get_flag_for_locale($locale): string
{
switch ($locale) {
case 'en':
return 'gb';
case 'nl':
return 'nl';
case 'fr':
return 'fr';
default:
return 'sr';
}
}
}

if (! function_exists('printWithQuestionOptions')) {
function printWithQuestionOptions($text, $replace, $key = null): string
{
if (is_array($replace) && isset($replace[$key])) {
$replace = $replace[$key];
}
if (empty($replace)) {
$replace = '';
}
return str_replace(':questionOptions', $replace, $text);
}
}

if (! function_exists('echoArray')) {
function echoArray($text): string
{
$print = '';
if (! is_array($text)) {

return $print;

return $text;
}

foreach ($text as $line) {
$print .= $line.'<br>';
}

return $print;
}
}

//if (! function_exists('compareVariables')) {
// function compareVariables($value1, $operator, $value2): string
// {
// switch ($operator) {
// case '<':
// return $value1 < $value2;
// case '<=':
// return $value1 <= $value2;
// case '>':
// return $value1 > $value2;
// case '>=':
// return $value1 >= $value2;
// case '==':
// return $value1 == $value2;
// case '!=':
// return $value1 != $value2;
// default:
// return false;
// }
// }
//}
38 changes: 38 additions & 0 deletions app/Models/Role.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

/**
* Created by Reliese Model.
*/

namespace App\Models;

use Carbon\Carbon;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;

/**
* Class Role
*
* @property int $id
* @property string $name
* @property Carbon|null $created_at
* @property Carbon|null $updated_at
* @property Collection|User[] $users
*/
class Role extends Model
{
protected $table = 'roles';

const USER = 1;

const ADMINISTRATOR = 2;

protected $fillable = [
'name',
];

public function users()
{
return $this->hasMany(User::class);
}
}
10 changes: 10 additions & 0 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,14 @@ class User extends Authenticatable
'email_verified_at' => 'datetime',
'password' => 'hashed',
];

public function role()
{
return $this->belongsTo(Role::class);
}

public function isAdmin()
{
return $this->role_id === Role::ADMINISTRATOR;
}
}
14 changes: 12 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,20 @@
"description": "The skeleton application for the Laravel framework.",
"keywords": ["laravel", "framework"],
"license": "MIT",
"repositories": [
{
"type": "vcs",
"url": "[email protected]:UtrechtUniversity/HTS-AppTeam-LaravelBase.git"
}
],
"require": {
"php": "^8.1",
"doctrine/dbal": "^3.8",
"guzzlehttp/guzzle": "^7.2",
"laravel/framework": "^10.10",
"laravel/sanctum": "^3.3",
"laravel/tinker": "^2.8"
"laravel/tinker": "^2.8",
"utrecht_university/hts_appteam_laravelbase": "^2.0"
},
"require-dev": {
"fakerphp/faker": "^1.9.1",
Expand All @@ -26,7 +33,10 @@
"App\\": "app/",
"Database\\Factories\\": "database/factories/",
"Database\\Seeders\\": "database/seeders/"
}
},
"files": [
"app/Http/Helpers.php"
]
},
"autoload-dev": {
"psr-4": {
Expand Down
Loading

0 comments on commit 3fecaae

Please sign in to comment.