diff --git a/app/Event.php b/app/Event.php index 555c1657b..3f2ec3adb 100644 --- a/app/Event.php +++ b/app/Event.php @@ -13,12 +13,12 @@ use Log; use Spatie\Activitylog\Traits\LogsActivity; use Laravel\Nova\Actions\Actionable; + class Event extends Model { use LogsActivity, Actionable; - protected $table = 'events'; protected $fillable = [ 'status', 'title', 'slug', 'organizer', 'description', @@ -72,7 +72,7 @@ public function path() public function picture_path() { - if ($this->picture){ + if ($this->picture) { return env('AWS_URL') . $this->picture; } else { return 'https://s3-eu-west-1.amazonaws.com/codeweek-dev/events/pictures/event_default_picture.png'; @@ -146,13 +146,14 @@ public function getClosest() } - public function notifyAmbassadors(){ + public function notifyAmbassadors() + { //Get the ambassador list based on the event country $ambassadors = User::role('ambassador')->where('country_iso', $this->country_iso)->get(); - if ($ambassadors->isEmpty()){ + if ($ambassadors->isEmpty()) { Mail::to('info@codeweek.eu')->queue(new \App\Mail\EventCreatedNoAmbassador($this)); - }else { + } else { //send emails foreach ($ambassadors as $ambassador) { Mail::to($ambassador->email)->queue(new \App\Mail\EventCreated($this, $ambassador)); @@ -161,16 +162,23 @@ public function notifyAmbassadors(){ } - public function approve(){ + public function approve() + { - $data = ['status' => "APPROVED", 'approved_by' => auth()->user()->id]; + $data = ['status' => "APPROVED", 'approved_by' => auth()->user()->id]; - $this->update($data); - Mail::to($this->owner->email)->queue(new \App\Mail\EventApproved($this, $this->owner)); + + if (!empty($this->user_email)) { + Mail::to($this->user_email)->queue(new \App\Mail\EventApproved($this, $this->owner)); + } else if (!is_null($this->owner) && (!is_null($this->owner->email))) { + Mail::to($this->owner->email)->queue(new \App\Mail\EventApproved($this, $this->owner)); + } + + return true; } diff --git a/app/Http/Controllers/ScoreboardController.php b/app/Http/Controllers/ScoreboardController.php index be38edc5b..63669d14e 100644 --- a/app/Http/Controllers/ScoreboardController.php +++ b/app/Http/Controllers/ScoreboardController.php @@ -12,6 +12,11 @@ class ScoreboardController extends Controller public function index() { + $total = DB::table('events') + ->where('status',"=","APPROVED") + ->whereYear('end_date', '>=', Carbon::now('Europe/Brussels')->year) + ->count(); + $events = DB::table('events') ->join('countries', 'events.country_iso', '=', 'countries.iso') ->select('countries.iso', 'countries.name as country_name','countries.population as country_population', DB::raw('count(*) as total'), DB::raw('countries.population / count(*) as rank')) @@ -21,6 +26,9 @@ public function index() ->orderBy('rank','asc') ->get(); - return view('scoreboard', ['events'=>$events]); + return view('scoreboard', [ + 'events'=>$events, + 'total'=>$total + ]); } } diff --git a/app/Providers/NovaServiceProvider.php b/app/Providers/NovaServiceProvider.php index d7d0d6855..fdb357fa9 100644 --- a/app/Providers/NovaServiceProvider.php +++ b/app/Providers/NovaServiceProvider.php @@ -43,7 +43,7 @@ protected function gate() { Gate::define('viewNova', function ($user) { return in_array($user->email, [ - "alainvd@gmail.com" + "alainvd@gmail.com","raphdom@gmail.com" ]); }); } diff --git a/public/css/ext/style.css b/public/css/ext/style.css index c4bd6dd57..188130341 100755 --- a/public/css/ext/style.css +++ b/public/css/ext/style.css @@ -13127,4 +13127,14 @@ textarea.border-form-control { .youtube-iframe{ width:100%; +} + +.scoreboard-total{ + text-align: center; + font-size: 24px; + padding: 15px; +} + +.country-name.macedonia { + font-size: 10px; } \ No newline at end of file diff --git a/resources/views/ambassadors.blade.php b/resources/views/ambassadors.blade.php index 7d1a27150..b94deab95 100755 --- a/resources/views/ambassadors.blade.php +++ b/resources/views/ambassadors.blade.php @@ -123,7 +123,7 @@ class="social-icon inline-block si-small si-light si-rounded si-gplus"> {{$country->country_iso}} -
+
@lang('countries.'.$country->name) ({{$country->total}})
diff --git a/resources/views/events.blade.php b/resources/views/events.blade.php index ea0b5a931..737c33cb5 100644 --- a/resources/views/events.blade.php +++ b/resources/views/events.blade.php @@ -23,7 +23,7 @@ {{$country->name}} -
+
@lang('countries.'.$country->name)
diff --git a/resources/views/scoreboard.blade.php b/resources/views/scoreboard.blade.php index 022ad7ea0..0655eaddf 100755 --- a/resources/views/scoreboard.blade.php +++ b/resources/views/scoreboard.blade.php @@ -17,6 +17,9 @@

@lang('scoreboard.paragraph')

+
+ {{$total}} @lang('scoreboard.events') +
    @@ -29,11 +32,14 @@ alt=" {{$event->country_name}}"/> -
    - @lang('countries.'.$event->country_name) -

    @lang('scoreboard.parcipating_with')

    +
    +
    + @lang('countries.'.$event->country_name) +

    @lang('scoreboard.parcipating_with')

    +
    - {{ $event->total }} @lang('scoreboard.events') + {{ $event->total }} @lang('search.' . str_plural('event', $event->total)) +
    diff --git a/tests/Feature/ApproveEventTest.php b/tests/Feature/ApproveEventTest.php index 00c61b787..479f15d2f 100644 --- a/tests/Feature/ApproveEventTest.php +++ b/tests/Feature/ApproveEventTest.php @@ -2,8 +2,10 @@ namespace Tests\Feature; +use App\Mail\EventApproved; use App\School; use Illuminate\Foundation\Testing\DatabaseMigrations; +use Illuminate\Support\Facades\Mail; use Tests\TestCase; use Illuminate\Foundation\Testing\WithFaker; use Illuminate\Foundation\Testing\RefreshDatabase; @@ -14,14 +16,12 @@ class ApproveEventTest extends TestCase use DatabaseMigrations; - public function setup() { parent::setUp(); $this->seed('RolesAndPermissionsSeeder'); - } /** @test */ @@ -36,17 +36,92 @@ public function event_can_be_approved_by_admin() $this->signIn($superadmin); - $event = create('App\Event', ['status'=>'PENDING']); + $event = create('App\Event', ['status' => 'PENDING']); $this->assertEquals($event->fresh()->status, 'PENDING'); $this->post(route('event.approve', $event)); $this->assertEquals($event->fresh()->status, 'APPROVED'); - $this->assertEquals($superadmin->id, $event->fresh()->approved_by ); + $this->assertEquals($superadmin->id, $event->fresh()->approved_by); } + /** @test */ + public function email_should_be_sent_to_event_email_when_event_is_approved() + { + + $this->withExceptionHandling(); + + Mail::fake(); + + $superadmin = create('App\User'); + $superadmin->assignRole('super admin'); + + $this->signIn($superadmin); + + $event = create('App\Event', ['status' => 'PENDING', 'user_email' => 'foo@bar.com']); + + + $event->approve(); + + // Assert a message was sent to the given users... + Mail::assertQueued(EventApproved::class, function ($mail) use ($event) { + return $mail->hasTo($event->user_email); + }); + + } + + /** @test */ + public function email_should_be_sent_to_creator_email_when_event_email_is_blank() + { + + $this->withExceptionHandling(); + + Mail::fake(); + + $superadmin = create('App\User', ['email' => 'test@boo.com']); + $superadmin->assignRole('super admin'); + + $this->signIn($superadmin); + + $event = create('App\Event', ['status' => 'PENDING', 'user_email' => '', 'creator_id' => $superadmin->id]); + + + $event->approve(); + + + // Assert a message was sent to the given users... + Mail::assertQueued(EventApproved::class, function ($mail) use ($superadmin) { + + return $mail->hasTo($superadmin->email); + }); + + } + + /** @test */ + public function email_should_not_be_sent_to_creator_email() + { + + $this->withExceptionHandling(); + + Mail::fake(); + + $superadmin = create('App\User', ['email' => NULL]); + $superadmin->assignRole('super admin'); + + $this->signIn($superadmin); + + $event = create('App\Event', ['status' => 'PENDING', 'user_email' => '', 'creator_id' => $superadmin->id]); + + + $event->approve(); + + + // Assert a message was sent to the given users... + Mail::assertNotQueued(EventApproved::class); + + } /** @test */ @@ -56,12 +131,12 @@ public function event_cant_be_approved_by_ambassador_of_other_country() $this->withExceptionHandling(); - $ambassador = create('App\User',['country_iso'=>'FR']); + $ambassador = create('App\User', ['country_iso' => 'FR']); $ambassador->assignRole('ambassador'); $this->signIn($ambassador); - $event = create('App\Event', ['status'=>'PENDING','country_iso'=>'BE']); + $event = create('App\Event', ['status' => 'PENDING', 'country_iso' => 'BE']); $this->assertEquals($event->fresh()->status, 'PENDING'); @@ -79,12 +154,12 @@ public function event_can_be_approved_by_ambassador_of_same_country() $this->withExceptionHandling(); - $ambassador = create('App\User',['country_iso'=>'FR']); + $ambassador = create('App\User', ['country_iso' => 'FR']); $ambassador->assignRole('ambassador'); $this->signIn($ambassador); - $event = create('App\Event', ['status'=>'PENDING','country_iso'=>'FR']); + $event = create('App\Event', ['status' => 'PENDING', 'country_iso' => 'FR']); $this->assertEquals($event->fresh()->status, 'PENDING'); @@ -110,10 +185,10 @@ public function visitors_cant_see_the_approve_banner() /** @test */ public function ambassadors_of_other_countries_cant_see_the_approve_banner() { - $ambassador = create('App\User',['country_iso'=>'FR'])->assignRole('ambassador'); + $ambassador = create('App\User', ['country_iso' => 'FR'])->assignRole('ambassador'); $this->signIn($ambassador); - $event = create('App\Event',['country_iso'=>'BE']); + $event = create('App\Event', ['country_iso' => 'BE']); $this->get('/view/' . $event->id . '/random') ->assertDontSee('moderate-event'); @@ -123,10 +198,10 @@ public function ambassadors_of_other_countries_cant_see_the_approve_banner() /** @test */ public function ambassadors_of_right_country_can_see_the_approve_banner() { - $ambassador = create('App\User',['country_iso'=>'FR'])->assignRole('ambassador'); + $ambassador = create('App\User', ['country_iso' => 'FR'])->assignRole('ambassador'); $this->signIn($ambassador); - $event = create('App\Event',['country_iso'=>'FR']); + $event = create('App\Event', ['country_iso' => 'FR']); $this->get('/view/' . $event->id . '/random') ->assertSee('moderate-event'); @@ -134,10 +209,6 @@ public function ambassadors_of_right_country_can_see_the_approve_banner() } - - - - }