Skip to content

Commit

Permalink
Merge branch 'main' of github.com:Kamieljv/watkanikdoen-app into wkid…
Browse files Browse the repository at this point in the history
…_tool
  • Loading branch information
Kamieljv committed Apr 20, 2024
2 parents b6f2d8b + d345b47 commit 6767c65
Show file tree
Hide file tree
Showing 39 changed files with 1,676 additions and 15,156 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/laravel.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Laravel

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
laravel-tests:

runs-on: ubuntu-latest

steps:
- uses: shivammathur/setup-php@15c43e89cdef867065b0213be354c2841860869e
with:
php-version: '8.0'
- uses: actions/checkout@v3
- name: Copy .env
run: php -r "file_exists('.env') || copy('.env.example', '.env');"
- name: Install Dependencies
run: composer install --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
- name: Generate key
run: php artisan key:generate
- name: Directory Permissions
run: chmod -R 777 storage bootstrap/cache
- name: Create Database
run: |
mkdir -p database
touch database/database.sqlite
- name: Execute tests (Unit and Feature tests) via PHPUnit/Pest
env:
DB_CONNECTION: sqlite
DB_DATABASE: database/database.sqlite
run: php artisan test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
package-lock.json
/node_modules
/public/hot
/public/js
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/ActieController.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public function search(Request $request)
$query->whereRaw("ST_Distance_Sphere(location, ST_GeomFromText('POINT({$coordinates[1]} {$coordinates[0]})')) <= {$radius}");
}

$query->published()->orderBy('time_start');
$query->published()->orderBy('start_date')->orderBy('start_time');

if ($request->show_past === 'false') {
$query->toekomstig();
Expand Down
43 changes: 30 additions & 13 deletions app/Http/Controllers/ReportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,11 @@ public function create(Request $request)
'organizer_ids' => $organizer_ids ? implode(",", $organizer_ids) : '',
'title' => $request->report['title'],
'body' => $request->report['body'] ?? null,
'externe_link' => $request->report['externe_link'],
'time_start' => Date::parse($request->report['time_start'])->format('Y-m-d\TH:i'),
'time_end' => Date::parse($request->report['time_end'])->format('Y-m-d\TH:i'),
'externe_link' => $request->report['actionUrls'],
'start_date' => Date::parse($request->report['start_date'])->format('Y-m-d'),
'end_date' => Date::parse($request->report['end_date'])->format('Y-m-d'),
'start_time' => isset($request->report['start_time']) ? Date::parse($request->report['start_time'])->format('H:i') : null,
'end_time' => isset($request->report['end_time']) ? Date::parse($request->report['end_time'])->format('H:i') : null,
'location' => isset($request->report['location']) ?
DB::raw("ST_GeomFromText('POINT({$request->report['location']['lng']} {$request->report['location']['lat']})')") : null,
'location_human' => $request->report['location_human'],
Expand Down Expand Up @@ -115,9 +117,10 @@ public function create(Request $request)
}

// Send email notification to admin
$admin = User::where('username', 'admin')->first();
$admin->notify(new ReportReceived($report));

if(config('app.debug') == false){
$admin = User::where('username', 'admin')->first();
$admin->notify(new ReportReceived($report));
}
return response([
'status' => 'success',
'message' => __('reports.add_success'),
Expand Down Expand Up @@ -183,8 +186,10 @@ public function approve($id)
'title' => $report->title,
'body' => $report->body,
'externe_link' => $report->externe_link,
'time_start' => $report->time_start,
'time_end' => $report->time_end,
'start_date' => $report->start_date,
'start_time' => $report->start_time,
'end_date' => $report->end_date,
'end_time' => $report->end_time,
'location' => $report->coordinates ? DB::raw("ST_GeomFromText('POINT({$report->coordinates['lng']} {$report->coordinates['lat']})')") : null,
'location_human' => $report->location_human,
'image' => $report->image ? $newImagePath : '',
Expand Down Expand Up @@ -225,14 +230,18 @@ public function approve($id)
*/
protected function validator(array $data)
{
return Validator::make($data, [
$v = Validator::make($data, [
'userId' => 'required|integer',

'report.title' => 'required|string|max:255',
'report.body' => 'required|string|max:16000',
'report.externe_link' => ['required', 'string', 'max:500', new Website()],
'report.time_start' => 'required|date_format:Y-m-d\TH:i|after_or_equal:today',
'report.time_end' => 'required|date_format:Y-m-d\TH:i|after:time_start',
'report.actionUrls' => 'required|array',
'report.actionUrls.*' => 'url|max:500',
'report.start_date' => 'required|date_format:Y-m-d|after_or_equal:today',
'report.start_time' => 'date_format:H:i',
'report.end_date' => 'required|date_format:Y-m-d|after_or_equal:report.start_date',
'report.end_time' => 'date_format:H:i',

'report.location' => 'array:lat,lng',
'report.location_human' => 'required|string|max:200',
'report.image' => '',
Expand All @@ -241,8 +250,16 @@ protected function validator(array $data)
'organizers.*.description' => 'sometimes|string|max:16000',
'organizers.*.website' => ['sometimes', 'required', 'string', 'max:500', new Website()]
], [
'organizers.*.name.unique' => 'De organisatornaam :input bestaat al.'
'organizers.*.name.unique' => 'De organisatornaam :input bestaat al.',
'report.end_time' => 'Het einde van de actie moet na het begin zijn.'
]);

// Add rule (end_time must be after start_time) for when start_date and end_date are the same
$v->sometimes('report.end_time', 'date_format:H:i|after:report.start_time', function ($data) {
return $data->report['start_date'] == $data->report['end_date'];
});

return $v;
}

protected function createSlug($title, $model = Actie::class)
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/WidgetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function index(Request $request)
$query->whereRaw("ST_Distance_Sphere(location, ST_GeomFromText('POINT({$coordinates[1]} {$coordinates[0]})')) <= {$radius}");
}

$query->published()->orderBy('time_start');
$query->published()->orderBy('start_date')->orderBy('start_time');

if ($request->show_past === 'false') {
$query->toekomstig();
Expand Down
35 changes: 26 additions & 9 deletions app/Models/Actie.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ class Actie extends Model
'title',
'body',
'externe_link',
'time_start',
'time_end',
'start_date',
'start_time',
'end_date',
'end_time',
'location',
'location_human',
'slug',
Expand Down Expand Up @@ -93,11 +95,11 @@ public function getLinkAttribute()

public function getStartEndAttribute()
{
if ($this->time_start && $this->time_end) {
$start = Date::parse($this->time_start);
$end = Date::parse($this->time_end);
if ($this->start_date && $this->end_date) {
$start = Date::parse($this->start_date . " " . $this->start_time);
$end = Date::parse($this->end_date . " " . $this->end_time);

if ($start->format('Y-m-d') == $end->format('Y-m-d')) {
if ($this->start_date == $this->end_date) {
// start and end on same day
return $start->format('j M Y, G:i') . '-' . $end->format('G:i');
} else if ($start->diffInDays($end) < 3) {
Expand All @@ -114,7 +116,7 @@ public function getStartEndAttribute()

public function getStartUnixAttribute()
{
return Date::parse($this->time_start)->timestamp;
return Date::parse($this->start_date . " " . $this->start_time)->timestamp;
}

public function getPageviewsTextAttribute()
Expand Down Expand Up @@ -142,6 +144,21 @@ public function getgeolocAttribute()
}
}

public function setExterneLinkAttribute($value)
{
// check if value is array, then implode, else use as is
if (is_array($value)) {
$this->attributes['externe_link'] = implode(",", $value);
} else {
$this->attributes['externe_link'] = $value;
}
}

public function getExterneLinkAttribute($value)
{
return explode(",", $value);
}

/**
* Get a new query builder for the model's table.
* Manipulate in case we need to convert geometrical fields to text.
Expand Down Expand Up @@ -191,7 +208,7 @@ public function report()

public function getAfgelopenAttribute()
{
return Date::parse($this->time_end)->timestamp < time();
return Date::parse($this->end_date . " " . $this->end_time)->timestamp < time();
}

public function getPublishedAttribute()
Expand All @@ -205,7 +222,7 @@ public function scopePublished($query)
}
public function scopeToekomstig($query)
{
return $query->where('time_end', '>', Date::now()->toDateTimeString());
return $query->whereRaw("STR_TO_DATE(CONCAT(start_date, ' ', start_time), '%Y-%m-%d %H:%i:%s') > '" . Date::now()->toDateTimeString() . "'");
}

public function publish()
Expand Down
5 changes: 5 additions & 0 deletions app/Models/Announcement.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,9 @@ public function users()
{
return $this->belongsToMany(User::class);
}

public function scopeActive($query)
{
return $query->where('status', 'ACTIVE');
}
}
16 changes: 14 additions & 2 deletions app/Models/Report.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ class Report extends Model
'title',
'body',
'externe_link',
'time_start',
'time_end',
'start_date',
'start_time',
'end_date',
'end_time',
'location',
'location_human',
'image',
Expand Down Expand Up @@ -77,6 +79,16 @@ public function actie()
return $this->belongsTo(Actie::class)->without('report');
}

public function setExterneLinkAttribute($value)
{
$this->attributes['externe_link'] = implode(",", $value);
}

public function getExterneLinkAttribute($value)
{
return explode(",", $value);
}

/**
* Get a new query builder for the model's table.
* Manipulate in case we need to convert geometrical fields to text.
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"blade-ui-kit/blade-icons": "^1.1",
"codeat3/blade-ant-design-icons": "^1.2",
"codeat3/blade-clarity-icons": "^1.3",
"doctrine/dbal": "^2.13",
"guzzlehttp/guzzle": "^7.0.1",
"intervention/image": "^2.4",
"jenssegers/date": "^4.0",
Expand Down
Loading

0 comments on commit 6767c65

Please sign in to comment.