Global subscribers and fix notifications
This commit is contained in:
committed by
Graham Campbell
parent
5abd25c408
commit
05bb91d2d9
@@ -30,6 +30,7 @@ class Subscriber extends Model implements HasPresenter
|
||||
'email' => 'string',
|
||||
'verify_code' => 'string',
|
||||
'verified_at' => 'date',
|
||||
'global' => 'bool',
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -91,6 +92,33 @@ class Subscriber extends Model implements HasPresenter
|
||||
return $query->whereNotNull('verified_at');
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope global subscribers.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeIsGlobal(Builder $query)
|
||||
{
|
||||
return $query->where('global', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds all verified subscriptions for a component.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param int $component_id
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeForComponent(Builder $query, $component_id)
|
||||
{
|
||||
return $query->select('subscribers.*')
|
||||
->join('subscriptions', 'subscribers.id', '=', 'subscriptions.subscriber_id')
|
||||
->where('subscriptions.component_id', $component_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the subscriber is verified.
|
||||
*
|
||||
|
||||
@@ -107,7 +107,10 @@ class Subscription extends Model
|
||||
{
|
||||
return $query->select('subscriptions.*')
|
||||
->join('subscribers', 'subscriptions.subscriber_id', '=', 'subscribers.id')
|
||||
->where('component_id', $component_id)
|
||||
->where(function ($query) {
|
||||
$query->where('subscriptions.component_id', $component_id)
|
||||
->orWhere('subscribers.global');
|
||||
})
|
||||
->whereNotNull('subscribers.verified_at');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user