Skip to content

Commit

Permalink
Merge pull request #717 from TheRestartProject/RES-1964_customisable_…
Browse files Browse the repository at this point in the history
…banners

RES-1964 customisable banners
  • Loading branch information
edwh committed Mar 12, 2024
2 parents 93520d3 + e3bdf66 commit 435e876
Show file tree
Hide file tree
Showing 23 changed files with 839 additions and 111 deletions.
35 changes: 35 additions & 0 deletions app/Alert.php
@@ -0,0 +1,35 @@
<?php

namespace App;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use DB;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Lang;
use Illuminate\Support\Facades\Log;
use OwenIt\Auditing\Contracts\Auditable;

class Alert extends Model implements Auditable
{
use HasFactory;

use \OwenIt\Auditing\Auditable;

protected $table = 'alerts';
protected $primaryKey = 'id';

/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'title',
'html',
'ctatitle',
'ctalink',
'start',
'end',
'variant'
];
}
77 changes: 77 additions & 0 deletions app/Console/Commands/AlertCreate.php
@@ -0,0 +1,77 @@
<?php

namespace App\Console\Commands;

use App\User;
use Illuminate\Console\Command;
use Illuminate\Support\Str;

use function Symfony\Component\VarDumper\Dumper\esc;

class AlertCreate extends Command
{
/**
* Example: php artisan alert:create 'Test alert' '<p>Testing</p>' 'today' 'next year' 'Click here' 'https://therestartproject.org'
*
* @var string
*/
protected $signature = 'alert:create {title} {html} {start} {end} {variant?} {ctatitle?} {ctalink?}';


/**
* The console command description.
*
* @var string
*/
protected $description = 'Create a system-wide alert';

/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}

/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$title = trim($this->argument('title'));
$html = trim($this->argument('html'));
$ctatitle = trim($this->argument('ctatitle'));
$ctalink = trim($this->argument('ctalink'));
$start = trim($this->argument('start'));
$end = trim($this->argument('end'));
$variant = trim($this->argument('variant'));
$variant = $variant ? $variant : 'secondary';

$alert = new \App\Alert();
$alert->title = $title;
$alert->html = $html;
$alert->variant = $variant;

if ($ctatitle && $ctalink) {
$alert->ctatitle = $ctatitle;
$alert->ctalink = $ctalink;
}

// Parse $start as a date and set it in the alert.
$start = \Carbon\Carbon::parse($start);
$start->setTimezone('UTC');
$end = \Carbon\Carbon::parse($end);
$end->setTimezone('UTC');

$alert->start = $start;
$alert->end = $end;

$alert->save();

$this->info("Created alert " . $alert->id);
}
}

0 comments on commit 435e876

Please sign in to comment.