PluginProbe
NotificationX – FOMO, Live Sales Notification, WooCommerce Sales Popup, GDPR, Social Proof, Announcement Banner & Floating Notification Bar / 3.2.9
NotificationX – FOMO, Live Sales Notification, WooCommerce Sales Popup, GDPR, Social Proof, Announcement Banner & Floating Notification Bar v3.2.9
3.3.1 3.3.0 3.2.14 3.2.13 3.2.12 3.2.11 3.2.10 3.2.9 3.2.8 3.2.7 trunk 0.2.5.5 0.2.5.6 0.2.5.7 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.2.0 1.2.1 All 156 releases
notificationx / includes / Admin / Entries.php

Entries.php in NotificationX – FOMO, Live Sales Notification, WooCommerce Sales Popup, GDPR, Social Proof, Announcement Banner & Floating Notification Bar 3.2.9, at includes/Admin/Entries.php

128 lines 4.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Extension Factory
5 *
6 * @package NotificationX\Extensions
7 */
8
9 namespace NotificationX\Admin;
10
11 use NotificationX\Core\Database;
12 use NotificationX\Core\Helper;
13 use NotificationX\GetInstance;
14
15 /**
16 * @method static Entries get_instance($args = null)
17 */
18 class Entries {
19 /**
20 * Instance of Entries
21 *
22 * @var Entries
23 */
24 use GetInstance;
25
26 protected $wpdb;
27 protected $count = [];
28 public $format = [
29 'entry_id' => '%d',
30 'nx_id' => '%d',
31 'source' => '%s',
32 'entry_key' => '%s',
33 'data' => '%s',
34 'created_at' => '%s',
35 'updated_at' => '%s',
36 ];
37
38 /**
39 * Initially Invoked when initialized.
40 * @hook init
41 */
42 public function __construct() {
43 global $wpdb;
44 $this->wpdb = $wpdb;
45 }
46
47 public function count($source, $col = 'source'){
48 if(empty($this->count)){
49 $this->count = Database::get_instance()->get_source_count(Database::$table_entries, $col, [$col => $source]);
50 }
51 if(!empty($this->count[$source])){
52 return $this->count[$source];
53 }
54 elseif(!empty($source)){
55 return 0;
56 }
57 return $this->count;
58 }
59
60
61 public function insert_entry($entry) {
62 if(empty($entry['data'])){
63 return false;
64 }
65 $timestamp = !empty($entry['data']['timestamp']) ? $entry['data']['timestamp'] : time();
66 if(empty($entry['created_at'])){
67 $entry['created_at'] = Helper::mysql_time($timestamp);
68 }
69 if(empty($entry['updated_at'])){
70 $entry['updated_at'] = Helper::mysql_time($timestamp);
71 }
72 $entry = apply_filters('nx_insert_entry', $entry);
73 $result = Database::get_instance()->insert_post(Database::$table_entries, $entry, $this->format);
74 if ( $result ) {
75 do_action( 'nx_after_entry_inserted', $entry );
76 }
77 return $result;
78 }
79
80 public function insert_entries($entries) {
81 foreach ($entries as $key => $entry) {
82 if(empty($entry['data'])){
83 unset($entries[$key]);
84 continue;
85 }
86 $timestamp = !empty($entry['data']['timestamp']) ? $entry['data']['timestamp'] : time();
87 if(empty($entry['created_at'])){
88 $entry['created_at'] = Helper::mysql_time($timestamp);
89 }
90 if(empty($entry['updated_at'])){
91 $entry['updated_at'] = Helper::mysql_time($timestamp);
92 }
93 $entries[$key] = apply_filters('nx_insert_entry', $entry);
94 }
95 return Database::get_instance()->insert_posts(Database::$table_entries, $entries, $this->format);
96 }
97
98 public function get_entries($where__or_nx_id = [], $select = "*", $join_table = '', $group_by_col = '', $data_in_entry = false) {
99 if (is_int($where__or_nx_id)) {
100 $where__or_nx_id = ['nx_id' => $where__or_nx_id];
101 }
102 $entries = Database::get_instance()->get_posts(Database::$table_entries, $select, $where__or_nx_id, $join_table, $group_by_col, '', 'ORDER BY `created_at` DESC');
103 if ($data_in_entry) {
104 $entries = apply_filters('nx_get_entries', $entries);
105 return $entries;
106 }
107 foreach ($entries as $key => $value) {
108 if (!empty($value['data'])) {
109 $value = array_merge($value['data'], $value);
110 unset($value['data']);
111 }
112 $entries[$key] = apply_filters('nx_get_entry', $value);
113 }
114 $entries = apply_filters('nx_get_entries', $entries);
115 return $entries;
116 }
117
118 public function delete_entries($where__or_nx_id, $limit = 0) {
119 if (!is_array($where__or_nx_id)) {
120 $where__or_nx_id = ['nx_id' => $where__or_nx_id];
121 }
122 $results = Database::get_instance()->delete_posts(Database::$table_entries, $where__or_nx_id, $limit);
123 // @todo add action.
124 return $results;
125 }
126
127 }
128