PluginProbe ʕ •ᴥ•ʔ
VikAppointments Services Booking Calendar / 1.2.21
VikAppointments Services Booking Calendar v1.2.21
1.2.21 1.2.20 trunk 1.2.17 1.2.18 1.2.19
vikappointments / site / helpers / libraries / invoice / constraints.php
vikappointments / site / helpers / libraries / invoice Last commit date
classes 3 days ago constraints.php 3 days ago factory.php 3 days ago generator.php 3 days ago index.html 3 days ago invoice.php 3 days ago
constraints.php
264 lines
1 <?php
2 /**
3 * @package VikAppointments
4 * @subpackage core
5 * @author E4J s.r.l.
6 * @copyright Copyright (C) 2021 E4J s.r.l. All Rights Reserved.
7 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
8 * @link https://vikwp.com
9 */
10
11 // No direct access
12 defined('ABSPATH') or die('No script kiddies please!');
13
14 /**
15 * Class used to wrap the invoice constraints.
16 *
17 * @since 1.7
18 */
19 class VAPInvoiceConstraints implements JsonSerializable, IteratorAggregate
20 {
21 /**
22 * The page orientation (landscape or portrait).
23 *
24 * @var string
25 */
26 protected $pageOrientation = self::PAGE_ORIENTATION_PORTRAIT;
27
28 /**
29 * The PDF measure unite (mm, cm, point or inch).
30 *
31 * @var string
32 */
33 protected $unit = self::UNIT_MILLIMETER;
34
35 /**
36 * The page format (A4, A5, or A6).
37 *
38 * @var string
39 */
40 protected $pageFormat = self::PAGE_FORMAT_A4;
41
42 /**
43 * The margins of the pages.
44 *
45 * @var array
46 */
47 protected $margins = array(
48 'top' => 10,
49 'bottom' => 10,
50 'right' => 10,
51 'left' => 10,
52 'header' => 5,
53 'footer' => 5,
54 );
55
56 /**
57 * Ratio used to adjust the conversion of pixels to user units.
58 *
59 * @var float
60 */
61 protected $imageScaleRatio = 1.25;
62
63 /**
64 * The default family font.
65 *
66 * @var string
67 *
68 * @since 1.7
69 */
70 protected $font = 'courier';
71
72 /**
73 * The font sizes to use for each specified section.
74 *
75 * @var array
76 */
77 protected $fontSizes = array(
78 'header' => 10,
79 'body' => 10,
80 'footer' => 10,
81 );
82
83 /**
84 * The header title. If empty, the header will be hidden.
85 *
86 * @var string
87 *
88 * @since 1.7
89 */
90 protected $headerTitle = null;
91
92 /**
93 * Flag used to check whether the footer should be displayed.
94 *
95 * @var boolean
96 *
97 * @since 1.7
98 */
99 protected $showFooter = false;
100
101 /**
102 * Class constructor.
103 *
104 * @param mixed $data An array/object of properties to bind.
105 */
106 public function __construct($data = array())
107 {
108 // iterate properties
109 foreach ($data as $k => $v)
110 {
111 // do not inject new properties
112 $this->__set($k, $v);
113 }
114 }
115
116 /**
117 * Magic method used to access the internal protected properties.
118 *
119 * @param string $name The property name.
120 *
121 * @return mixed The propery value if exists, null otherwise.
122 */
123 public function __get($name)
124 {
125 if (!property_exists($this, $name))
126 {
127 // missing property
128 return null;
129 }
130
131 if (is_array($this->{$name}))
132 {
133 // always cast arrays to objects
134 return (object) $this->{$name};
135 }
136
137 return $this->{$name};
138 }
139
140 /**
141 * Magic method used to check if the instance owns the specified property.
142 *
143 * @param string $name The property name.
144 *
145 * @return boolean True if set, false otherwise.
146 */
147 public function __isset($name)
148 {
149 return property_exists($this, $name);
150 }
151
152 /**
153 * Magic method used to prevent the assignment of new properties.
154 *
155 * @param string $name The property name.
156 * @param mixed $value The property value.
157 *
158 * @return void
159 */
160 public function __set($name, $value)
161 {
162 // set only if the property exists
163 if (property_exists($this, $name))
164 {
165 // check if our property is a scalar value
166 if (is_scalar($this->{$name}) || is_null($this->{$name}))
167 {
168 $this->{$name} = $value;
169 }
170 else
171 {
172 // iterate elements and assign them
173 foreach ((array) $value as $pk => $pv)
174 {
175 if (array_key_exists($pk, $this->{$name}))
176 {
177 $this->{$name}[$pk] = $pv;
178 }
179 }
180
181 // Do not need to recursively assign the attributes
182 // because the array properties of this class don't
183 // exceed the limit of one-level.
184 }
185 }
186 }
187
188 /**
189 * Creates an associative array, containing all the supported constraints.
190 *
191 * @return array
192 */
193 public function toArray()
194 {
195 $data = array();
196
197 // get object variables
198 foreach (get_object_vars($this) as $k => $v)
199 {
200 // get value that should be used outside the class
201 $data[$k] = $this->__get($k);
202
203 if (is_object($data[$k]))
204 {
205 // cast to array in case the attribute is an object
206 $data[$k] = (array) $data[$k];
207 }
208 }
209
210 return $data;
211 }
212
213 /**
214 * Creates a standard object, containing all the supported constraints,
215 * to be used when this class is passed to "json_encode()".
216 *
217 * @return object
218 *
219 * @see JsonSerializable
220 */
221 #[ReturnTypeWillChange]
222 public function jsonSerialize()
223 {
224 $obj = new stdClass;
225
226 // get object variables
227 foreach (get_object_vars($this) as $k => $v)
228 {
229 // get value that should be used outside the class
230 $obj->{$k} = $this->__get($k);
231 }
232
233 return $obj;
234 }
235
236 /**
237 * Returns the iterator interface.
238 *
239 * @return Traversable
240 *
241 * @see IteratorAggregate
242 */
243 #[ReturnTypeWillChange]
244 public function getIterator()
245 {
246 return new ArrayIterator($this->toArray());
247 }
248
249 // PAGE ORIENTATION
250 const PAGE_ORIENTATION_LANDSCAPE = 'L';
251 const PAGE_ORIENTATION_PORTRAIT = 'P';
252
253 // UNIT
254 const UNIT_POINT = 'pt';
255 const UNIT_MILLIMETER = 'mm';
256 const UNIT_CENTIMETER = 'cm';
257 const UNIT_INCH = 'in';
258
259 // PAGE FORMAT
260 const PAGE_FORMAT_A4 = 'A4';
261 const PAGE_FORMAT_A5 = 'A5';
262 const PAGE_FORMAT_A6 = 'A6';
263 }
264