PluginProbe
NotificationX – FOMO, Live Sales Notification, WooCommerce Sales Popup, GDPR, Social Proof, Announcement Banner & Floating Notification Bar / 1.1.4
NotificationX – FOMO, Live Sales Notification, WooCommerce Sales Popup, GDPR, Social Proof, Announcement Banner & Floating Notification Bar v1.1.4
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 / class-nx-array.php

class-nx-array.php in NotificationX – FOMO, Live Sales Notification, WooCommerce Sales Popup, GDPR, Social Proof, Announcement Banner & Floating Notification Bar 1.1.4, at includes/class-nx-array.php

70 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * This class is responsible for Handling Array.
5 */
6
7 class NotificationX_Array {
8 private $limit = 5;
9 private $values;
10 private $priority = [];
11 public $sortBy = 'priority';
12
13 public function setValues( $values ) {
14 $this->values = $values;
15 $this->sort();
16 }
17
18 public function values() {
19 $this->values = array_slice( $this->values, 0, $this->limit );
20 return $this->values;
21 }
22 public function setLimit( $limit = 5 ) {
23 $this->limit = $limit;
24 }
25
26 public function size(){
27 return count( $this->values );
28 }
29
30 public function sort( $flags = SORT_DESC ) {
31 if( empty( $this->values ) ) {
32 return $this;
33 }
34 foreach( $this->values as $key => $value ) {
35 $this->priority[ $key ] = $value[ $this->sortBy ];
36 }
37 array_multisort( $this->priority, $flags, $this->values );
38 $this->priority = [];
39 return $this;
40 }
41
42 public function append( $value, $key = null ) {
43 if( $this->size() == $this->limit ) {
44 $this->sort();
45 array_pop( $this->values );
46 }
47 if( $key === null ) {
48 array_push( $this->values, $value );
49 } else {
50 $this->values = $this->values + [ $key => $value ];
51 }
52 $this->sort();
53 return $this;
54 }
55
56 public function prepend( $value, $key = null ){
57 if( $this->size() == $this->limit ) {
58 $this->sort();
59 array_pop( $this->values );
60 }
61
62 if( $key === null ) {
63 array_unshift( $this->values, $value );
64 } else {
65 $this->values = [ $key => $value ] + $this->values;
66 }
67 $this->sort();
68 return $this;
69 }
70 }