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