hide event

This commit is contained in:
Mathieu Lagacé
2020-10-06 18:54:56 -04:00
parent 63301aec97
commit f7845d8f1b
22 changed files with 614 additions and 187 deletions

View File

@@ -0,0 +1,81 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Schema;
class update extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'update';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Update C-CMS';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$this->info('Starting update ...');
$this->updateDatabase();
$this->info('Update completed !');
}
private function updateDatabase()
{
$this->info('Updating database ...');
// Check event table
if (!Schema::hasColumn('events','hidden'))
{
$this->info('Updating events table ...');
Schema::table('events', function ($table) {
$table->boolean('hidden')->default(0);
});
}
else
{
$this->info('Events table is up to date ...');
}
// Check event_type table
if (!Schema::hasColumn('event_types','hidden'))
{
$this->info('Updating event_types table ...');
Schema::table('event_types', function ($table) {
$table->boolean('hidden')->default(0);
});
}
else
{
$this->info('Event_types table is up to date ...');
}
return 0;
}
}

View File

@@ -37,6 +37,9 @@ class CalendarController extends Controller
public function indexTable()
{
return view('admin.schedule.table.index',['events' => \App\Event::allThisYear()->sortBy('date_begin')]);
$event = \App\Event::allThisYear()->sortBy('date_begin')->filter(function ($value,$key) {
return $value->hidden != 1;
});
return view('admin.schedule.table.index',['events' => $event]);
}
}

View File

@@ -100,6 +100,15 @@ class EventController extends Controller
$event->use_schedule = 0;
}
if(\request("hidden"))
{
$event->hidden = 1;
}
else
{
$event->hidden = 0;
}
$event->calendar_color = \request('calendar_color');
$event->calendar_icon = \request('calendar_icon');
@@ -225,7 +234,15 @@ class EventController extends Controller
*/
public function edit($id)
{
return view('admin.schedule.event.edit',['event' => \App\Event::find($id)]);
$event = \App\Event::find($id);
if ($event->hidden == 1)
{
if (\Auth::user()->p('instruction_see_hidden_event') != 1)
{
return redirect('/admin/schedule')->with('error','Modification non authorisé');
}
}
return view('admin.schedule.event.edit',['event' => $event]);
}
/**
@@ -238,6 +255,13 @@ class EventController extends Controller
public function update($id)
{
$event = Event::findOrFail($id);
if ($event->hidden == 1)
{
if (\Auth::user()->p('instruction_see_hidden_event') != 1)
{
return redirect('/admin/schedule')->with('error','Modification non authorisé');
}
}
// if (\App\GoogleDriveFile::checkConfig())
// {
@@ -297,6 +321,15 @@ class EventController extends Controller
$event->use_schedule = 0;
}
if(\request("hidden"))
{
$event->hidden = 1;
}
else
{
$event->hidden = 0;
}
$event->calendar_color = \request('calendar_color');
$event->calendar_icon = \request('calendar_icon');

View File

@@ -62,6 +62,14 @@ class EventTypeController extends Controller
{
$eventType->use_schedule = 0;
}
if(\request("hidden"))
{
$eventType->hidden = 1;
}
else
{
$eventType->hidden = 0;
}
if ($request->is_mandatory == 'on')
{
$eventType->is_mandatory = 1;
@@ -174,6 +182,14 @@ class EventTypeController extends Controller
{
$eventType->use_schedule = 0;
}
if(\request("hidden"))
{
$eventType->hidden = 1;
}
else
{
$eventType->hidden = 0;
}
if ($request->is_mandatory == 'on')
{
$eventType->is_mandatory = 1;

View File

@@ -46,11 +46,28 @@ class ScheduleController extends Controller
}
foreach ($allevents as $event) {
if(strtotime($event->date_begin) >= $start && strtotime($event->date_begin) <= $end) {
array_push($events,$event);
if ($event->hidden == 1) {
if (\Auth::check())
{
if (\Auth::user()->p('instruction_see_hidden_event') == 1)
{
if(strtotime($event->date_begin) >= $start && strtotime($event->date_begin) <= $end) {
array_push($events,$event);
}
else if(strtotime($event->date_end) >= $start && strtotime($event->date_end) <= $end) {
array_push($events,$event);
}
}
}
}
else if(strtotime($event->date_end) >= $start && strtotime($event->date_end) <= $end) {
array_push($events,$event);
else
{
if(strtotime($event->date_begin) >= $start && strtotime($event->date_begin) <= $end) {
array_push($events,$event);
}
else if(strtotime($event->date_end) >= $start && strtotime($event->date_end) <= $end) {
array_push($events,$event);
}
}
}
@@ -90,8 +107,16 @@ class ScheduleController extends Controller
$icon = $event->calendar_icon;
}
$name = $event->name;
if ($event->hidden == 1) {
$color = $this->hex2rgba($color,0.5);
$icon = 'fas fa-eye-slash';
$name = 'Caché - '.$name;
}
$myevent = [
'title' => $event->name,
'title' => $name,
'start' => date('c',strtotime($event->date_begin)),
'end' => date('c',strtotime($event->date_end)),
'color' => $color,
@@ -106,6 +131,45 @@ class ScheduleController extends Controller
return json_encode($jsonevents);
}
function hex2rgba($color, $opacity = false) {
$default = 'rgb(0,0,0)';
//Return default if no color provided
if(empty($color))
return $default;
//Sanitize $color if "#" is provided
if ($color[0] == '#' ) {
$color = substr( $color, 1 );
}
//Check if color has 6 or 3 characters and get values
if (strlen($color) == 6) {
$hex = array( $color[0] . $color[1], $color[2] . $color[3], $color[4] . $color[5] );
} elseif ( strlen( $color ) == 3 ) {
$hex = array( $color[0] . $color[0], $color[1] . $color[1], $color[2] . $color[2] );
} else {
return $default;
}
//Convert hexadec to rgb
$rgb = array_map('hexdec', $hex);
//Check if opacity is set(rgba or rgb)
if($opacity){
if(abs($opacity) > 1)
$opacity = 1.0;
$output = 'rgba('.implode(",",$rgb).','.$opacity.')';
} else {
$output = 'rgb('.implode(",",$rgb).')';
}
//Return rgb(a) color string
return $output;
}
public function loadModal($id,$db_type)
{
if($db_type == "event")
@@ -216,6 +280,13 @@ class ScheduleController extends Controller
public function delete($id)
{
$event = \App\Event::find($id);
if ($event->hidden == 1)
{
if (\Auth::user()->p('instruction_see_hidden_event') != 1)
{
abort(403);
}
}
foreach ($event->courses as $course)
{
$course->delete();

View File

@@ -16,7 +16,7 @@ use Illuminate\Support\Arr;
class Permission extends Model
{
const PERMISSIONS = [
'news' => [
'Nouvelle' => [
'news_see' => [
'ckey' => 'news_see',
'communName' => 'Voir les nouvelles',
@@ -46,7 +46,7 @@ class Permission extends Model
'valeur' => 0
]
],
'inventory' => [
'Inventaire' => [
'inventory_see' => [
'ckey' => 'inventory_see',
'communName' => 'Voir l\'inventaire',
@@ -76,7 +76,7 @@ class Permission extends Model
'valeur' => 0
],
],
'user' => [
'Utilisateur' => [
'user_see' => [
'ckey' => 'user_see',
'communName' => 'Voir la liste des utilisateurs',
@@ -106,7 +106,7 @@ class Permission extends Model
'valeur' => 0
],
],
'config' => [
'Configuration' => [
'config_see' => [
'ckey' => 'config_see',
'communName' => 'Voir les configurations',
@@ -157,7 +157,7 @@ class Permission extends Model
'valeur' => 0
]
],
'statistique' => [
'Statistique' => [
'stats_see' => [
'ckey' => 'stats_see',
'communName' => 'Voir les statistiques',
@@ -202,13 +202,6 @@ class Permission extends Model
'icon' => 'fa-eye',
'valeur' => 0
],
'stats_instruction_see' => [
'ckey' => 'stats_instruction_see',
'communName' => 'Voir les statistiques de l\'instruction',
'desc' => 'L\'utilisateur peut-il voir les statistiques de l\'instruction',
'icon' => 'fa-eye',
'valeur' => 0
],
'course_see_all' => [
'ckey' => 'course_see_all',
'communName' => 'Voir les cours de tous les utilisateurs',
@@ -237,6 +230,20 @@ class Permission extends Model
'icon' => 'fa-eye',
'valeur' => 0
],
'stats_instruction_see' => [
'ckey' => 'stats_instruction_see',
'communName' => 'Voir les statistiques de l\'instruction',
'desc' => 'L\'utilisateur peut-il voir les statistiques de l\'instruction',
'icon' => 'fa-eye',
'valeur' => 0
],
'instruction_see_hidden_event' => [
'ckey' => 'instruction_see_hidden_event',
'communName' => 'Voir les évenements cachés',
'desc' => 'L\'utilisateur peut-il voir les évenements cachés',
'icon' => 'fa-eye',
'valeur' => 0
],
],
'Administration' => [
'cadet_list_see' => [
@@ -277,7 +284,7 @@ class Permission extends Model
'valeur' => 0
]
],
'article' => [
'Articles' => [
'article_see' => [
'ckey' => 'article_see',
'communName' => 'Voir les articles',
@@ -307,7 +314,7 @@ class Permission extends Model
'valeur' => 0
],
],
'picture' => [
'Photos & Images' => [
'picture_see' => [
'ckey' => 'picture_see',
'communName' => 'Voir les images',
@@ -337,7 +344,7 @@ class Permission extends Model
'valeur' => 0
],
],
'file' => [
'Fichiers' => [
'file_see' => [
'ckey' => 'file_see',
'communName' => 'Voir les fichiers publiques',
@@ -388,6 +395,11 @@ class Permission extends Model
return self::PERMISSIONS;
}
public static function allToJSON()
{
return self::all()->toJson();
}
public static function allToString($value = null)
{
$perm = [];