Add Campaigns module for grouping short links.
Deploy Ladill Link / deploy (push) Successful in 1m26s
Deploy Ladill Link / deploy (push) Successful in 1m26s
Let accounts organise links by promo or launch, attach or detach links, and view combined click totals from the sidebar.
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Campaign extends Model
|
||||
{
|
||||
public const STATUS_DRAFT = 'draft';
|
||||
|
||||
public const STATUS_ACTIVE = 'active';
|
||||
|
||||
public const STATUS_ARCHIVED = 'archived';
|
||||
|
||||
public const STATUSES = [
|
||||
self::STATUS_DRAFT => 'Draft',
|
||||
self::STATUS_ACTIVE => 'Active',
|
||||
self::STATUS_ARCHIVED => 'Archived',
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'name',
|
||||
'description',
|
||||
'status',
|
||||
'starts_at',
|
||||
'ends_at',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'starts_at' => 'datetime',
|
||||
'ends_at' => 'datetime',
|
||||
];
|
||||
}
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function shortLinks(): HasMany
|
||||
{
|
||||
return $this->hasMany(ShortLink::class);
|
||||
}
|
||||
|
||||
public function statusLabel(): string
|
||||
{
|
||||
return self::STATUSES[$this->status] ?? ucfirst((string) $this->status);
|
||||
}
|
||||
|
||||
public function isLive(): bool
|
||||
{
|
||||
if ($this->status !== self::STATUS_ACTIVE) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->starts_at && $this->starts_at->isFuture()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->ends_at && $this->ends_at->isPast()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function totalClicks(): int
|
||||
{
|
||||
return (int) $this->shortLinks()->sum('clicks_total');
|
||||
}
|
||||
|
||||
public function linksCount(): int
|
||||
{
|
||||
return (int) $this->shortLinks()->count();
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ class ShortLink extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'campaign_id',
|
||||
'source_app',
|
||||
'source_kind',
|
||||
'source_ref',
|
||||
@@ -40,6 +41,11 @@ class ShortLink extends Model
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function campaign(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Campaign::class);
|
||||
}
|
||||
|
||||
public function clicks(): HasMany
|
||||
{
|
||||
return $this->hasMany(LinkClick::class);
|
||||
|
||||
@@ -49,6 +49,11 @@ class User extends Authenticatable
|
||||
return $this->hasMany(ShortLink::class);
|
||||
}
|
||||
|
||||
public function campaigns(): HasMany
|
||||
{
|
||||
return $this->hasMany(Campaign::class);
|
||||
}
|
||||
|
||||
public function linkCustomDomains(): HasMany
|
||||
{
|
||||
return $this->hasMany(LinkCustomDomain::class);
|
||||
|
||||
Reference in New Issue
Block a user