| 1 |
<?php |
| 2 |
|
| 3 |
namespace MasterAddons\Inc\Classes\Notifications\Base; |
| 4 |
|
| 5 |
// No, Direct access Sir !!! |
| 6 |
if (!defined('ABSPATH')) { |
| 7 |
exit; |
| 8 |
} |
| 9 |
|
| 10 |
/** |
| 11 |
* Data abstract class |
| 12 |
* |
| 13 |
* Jewel Theme <support@jeweltheme.com> |
| 14 |
*/ |
| 15 |
abstract class Data |
| 16 |
{ |
| 17 |
|
| 18 |
use Date; |
| 19 |
|
| 20 |
public $notifications = array(); |
| 21 |
|
| 22 |
/** |
| 23 |
* Get Notifications |
| 24 |
* |
| 25 |
* @param [type] $instance_key . |
| 26 |
* |
| 27 |
* @author Jewel Theme <support@jeweltheme.com> |
| 28 |
*/ |
| 29 |
public function get_notification($instance_key) |
| 30 |
{ |
| 31 |
if (array_key_exists($instance_key, $this->notifications)) { |
| 32 |
return $this->notifications[$instance_key]; |
| 33 |
} |
| 34 |
|
| 35 |
return null; |
| 36 |
} |
| 37 |
|
| 38 |
/** |
| 39 |
* Get Notificaiton |
| 40 |
* |
| 41 |
* @param [type] $type . |
| 42 |
* |
| 43 |
* @author Jewel Theme <support@jeweltheme.com> |
| 44 |
*/ |
| 45 |
public function get_notifications($type = null) |
| 46 |
{ |
| 47 |
$notifications = $this->notifications; |
| 48 |
|
| 49 |
if ($type) { |
| 50 |
$notifications = wp_list_filter($notifications, array('type' => $type)); |
| 51 |
} |
| 52 |
|
| 53 |
return $notifications; |
| 54 |
} |
| 55 |
|
| 56 |
/** |
| 57 |
* Get Active notifications |
| 58 |
* |
| 59 |
* @param [type] $type . |
| 60 |
* |
| 61 |
* @author Jewel Theme <support@jeweltheme.com> |
| 62 |
*/ |
| 63 |
public function get_active_notifications($type = null) |
| 64 |
{ |
| 65 |
$notifications = wp_list_filter($this->get_notifications($type), array('is_active' => true)); |
| 66 |
|
| 67 |
return wp_list_sort($notifications, 'next_exec_time'); |
| 68 |
} |
| 69 |
|
| 70 |
/** |
| 71 |
* Get executable notifications |
| 72 |
* |
| 73 |
* @param [type] $date . |
| 74 |
* @param [type] $type . |
| 75 |
* |
| 76 |
* @author Jewel Theme <support@jeweltheme.com> |
| 77 |
*/ |
| 78 |
public function get_exec_notifications($date = null, $type = null) |
| 79 |
{ |
| 80 |
if (!$date) { |
| 81 |
$date = $this->current_time(); |
| 82 |
} |
| 83 |
|
| 84 |
$notifications = $this->get_active_notifications($type); |
| 85 |
|
| 86 |
$_notifications = array(); |
| 87 |
|
| 88 |
foreach ($notifications as $notification) { |
| 89 |
if (empty($notification->next_exec_time)) { |
| 90 |
continue; |
| 91 |
} |
| 92 |
|
| 93 |
if ($this->date_is_current_or_prev($notification->next_exec_time, $date)) { |
| 94 |
$_notifications[] = $notification; |
| 95 |
} |
| 96 |
} |
| 97 |
|
| 98 |
return $_notifications; |
| 99 |
} |
| 100 |
|
| 101 |
/** |
| 102 |
* Get Upcoming Notificaitons |
| 103 |
* |
| 104 |
* @param [type] $date . |
| 105 |
* @param [type] $type . |
| 106 |
* |
| 107 |
* @author Jewel Theme <support@jeweltheme.com> |
| 108 |
*/ |
| 109 |
public function get_upcoming_notifications($date = null, $type = null) |
| 110 |
{ |
| 111 |
if (!$date) { |
| 112 |
$date = $this->current_time(); |
| 113 |
} |
| 114 |
|
| 115 |
$notifications = $this->get_active_notifications($type); |
| 116 |
|
| 117 |
$_notifications = array(); |
| 118 |
|
| 119 |
foreach ($notifications as $notification) { |
| 120 |
if (empty($notification->next_exec_time)) { |
| 121 |
continue; |
| 122 |
} |
| 123 |
|
| 124 |
if ($this->date_is_next($notification->next_exec_time, $date)) { |
| 125 |
$_notifications[] = $notification; |
| 126 |
} |
| 127 |
} |
| 128 |
|
| 129 |
return $_notifications; |
| 130 |
} |
| 131 |
|
| 132 |
/** |
| 133 |
* Register Instance |
| 134 |
* |
| 135 |
* @param [type] $instance . |
| 136 |
* |
| 137 |
* @author Jewel Theme <support@jeweltheme.com> |
| 138 |
*/ |
| 139 |
public function register($instance) |
| 140 |
{ |
| 141 |
if (!array_key_exists($instance->get_id(), $this->notifications)) { |
| 142 |
$this->notifications[$instance->get_id()] = $instance; |
| 143 |
} |
| 144 |
} |
| 145 |
} |
| 146 |
|