Add groups to post notifications history

[MAILPOET-2192]
This commit is contained in:
Pavel Dohnal
2019-08-28 15:47:29 +02:00
committed by M. Shull
parent ca8768316f
commit d0d27a66ae
2 changed files with 34 additions and 8 deletions

View File

@ -823,19 +823,17 @@ class Newsletter extends Model {
static function groups($data = []) {
$type = isset($data['params']['type']) ? $data['params']['type'] : null;
$group = (isset($data['params']['group'])) ? $data['params']['group'] : null;
$parentId = (isset($data['params']['parent_id'])) ? $data['params']['parent_id'] : null;
// newsletter types without groups
if (in_array($type, [
self::TYPE_NOTIFICATION_HISTORY,
])) {
return false;
$get_published_query = Newsletter::getPublished();
if (!is_null($parentId)) {
$get_published_query->where('parent_id', $parentId);
}
$groups = [
[
'name' => 'all',
'label' => WPFunctions::get()->__('All', 'mailpoet'),
'count' => Newsletter::getPublished()
'count' => $get_published_query
->filter('filterType', $type, $group)
->count(),
],
@ -879,6 +877,29 @@ class Newsletter extends Model {
]);
break;
case self::TYPE_NOTIFICATION_HISTORY:
$groups = array_merge($groups, [
[
'name' => self::STATUS_SENDING,
'label' => WPFunctions::get()->__('Sending', 'mailpoet'),
'count' => Newsletter::getPublished()
->where('parent_id', $parentId)
->filter('filterType', $type, $group)
->filter('filterStatus', self::STATUS_SENDING)
->count(),
],
[
'name' => self::STATUS_SENT,
'label' => WPFunctions::get()->__('Sent', 'mailpoet'),
'count' => Newsletter::getPublished()
->where('parent_id', $parentId)
->filter('filterType', $type, $group)
->filter('filterStatus', self::STATUS_SENT)
->count(),
],
]);
break;
case self::TYPE_WELCOME:
case self::TYPE_NOTIFICATION:
case self::TYPE_AUTOMATIC:
@ -903,10 +924,14 @@ class Newsletter extends Model {
break;
}
$get_trashed_query = Newsletter::getTrashed();
if (!is_null($parentId)) {
$get_trashed_query->where('parent_id', $parentId);
}
$groups[] = [
'name' => 'trash',
'label' => WPFunctions::get()->__('Trash', 'mailpoet'),
'count' => Newsletter::getTrashed()
'count' => $get_trashed_query
->filter('filterType', $type, $group)
->count(),
];