PluginProbe
Timetics – Appointment Booking Calendar & Scheduling / 1.0.64
Timetics – Appointment Booking Calendar & Scheduling v1.0.64
1.0.64 1.0.62 1.0.63 1.0.61 1.0.60 1.0.59 1.0.58 1.0.57 1.0.56 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.2 1.0.20 1.0.21 All 65 releases
timetics / vendor / themewinter / email-notification-sdk / src / Base / PostModel.php

PostModel.php in Timetics – Appointment Booking Calendar & Scheduling 1.0.64, at vendor/themewinter/email-notification-sdk/src/Base/PostModel.php

201 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 namespace Ens\Base;
4
5 use Ens\Base\ForwardCalls;
6 use Ens\Config;
7
8 /**
9 * Post Model Class
10 *
11 * @since 1.0.0
12 *
13 * @package ENS
14 */
15 abstract class PostModel {
16 use ForwardCalls;
17
18 /**
19 * Store post type
20 *
21 * @since 1.0.0
22 *
23 * @var string
24 */
25 public $post_type;
26
27 /**
28 * Store prefix
29 *
30 * @since 1.0.0
31 *
32 * @var string
33 */
34 public $prefix;
35
36 /**
37 * Store data for the current post
38 *
39 * @since 1.0.0
40 *
41 * @var array
42 */
43 public $data = [];
44
45 /**
46 * Get the post property dynamically
47 *
48 * @since 1.0.0
49 *
50 * @param string $name Property name of the current post
51 *
52 * @return mixed
53 */
54 public function __get( $name ) {
55 if ( isset( $this->data[$name] ) ) {
56 return $this->data[$name];
57 }
58
59 // translators: %s is the name of the property
60 throw new \Exception( esc_html( sprintf( 'Undefined property %s', $name ) ) );
61 }
62
63 /**
64 * Set dynamic property
65 *
66 * @since 1.0.0
67 *
68 * @param string $key
69 * @param mixed $value
70 *
71 * @return void
72 */
73 public function __set( $key, $value ) {
74 if ( !isset( $this->data[$key] ) ) {
75 // translators: %s is the name of the property
76 throw new \Exception( esc_html( sprintf( 'Undefined property %s', $key ) ) );
77 }
78
79 $this->data[$key] = $value;
80 }
81
82 /**
83 * Debug info for current object
84 *
85 * @since 1.0.0
86 *
87 * @return mixed
88 */
89 public function __debugInfo() {
90 return $this->data;
91 }
92
93 /**
94 * Handle dynamic static method call
95 *
96 * @since 1.0.0
97 *
98 * @param string $method Method name for dynamic call
99 * @param mixed $params method params
100 *
101 * @return string
102 */
103 public static function __callStatic( $method, $params ) {
104 return static::forward_call_to_static( new static , $method, $params );
105 }
106
107 /**
108 * Handle dynamic method call
109 *
110 * @since 1.0.0
111 *
112 * @param string $method Method name for dynamic call
113 * @param mixed $params method params
114 *
115 * @return string
116 */
117 public function __call( $method, $params ) {
118 return static::forward_call_to_static( ( new static ), $method, $params );
119 }
120
121 /**
122 * Get property of current post
123 *
124 * @since 1.0.0
125 *
126 * @return mixed
127 */
128 public function get_prop( $name = '' ) {
129 $key = $this->prefix . $name;
130
131 return get_post_meta( $this->id, $key, true );
132 }
133
134 /**
135 * Convert object property to an Array
136 *
137 * @since 1.0.0
138 *
139 * @return array
140 */
141 public function to_array() {
142 $items = [];
143 $data = $this->data;
144 $items['id'] = $this->id;
145
146 unset( $data['id'] );
147
148 foreach ( $data as $key => $value ) {
149 $prop = $this->get_prop( $key );
150
151 $items[$key] = '' === $prop ? $value : $prop;
152 }
153
154 return $items;
155 }
156
157 /**
158 * Get all models
159 *
160 * @since 1.0.0
161 *
162 * @return array
163 */
164 public function all( $data = [] ) {
165 $models = [];
166 $model = new static();
167 $meta = [];
168
169 if ( $data ) {
170 foreach ( $data as $key => $value ) {
171 $meta_data = [
172 'key' => $model->prefix . $key,
173 'value' => $value,
174 'compare' => '=',
175 ];
176
177 $meta[] = $meta_data;
178 }
179 }
180
181 $args = [
182 'post_type' => $model->post_type,
183 ];
184
185 if ( $meta ) {
186 $meta['relation'] = 'AND';
187 $args['meta_query'] = $meta;
188 }
189
190 $posts = get_posts( $args );
191
192 foreach ( $posts as $post ) {
193 $object = new static();
194 $model->load( $object, $post );
195 $models[] = $object;
196 }
197
198 return $models;
199 }
200 }
201