overrides
2 days ago
core.php
2 days ago
dispatcher.php
2 days ago
formbuilder.php
2 days ago
formfield.php
2 days ago
formfieldconstraints.php
2 days ago
index.html
2 days ago
job.php
2 days ago
response.php
2 days ago
response.php
233 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 manage the response of a cronjob. |
| 16 | * |
| 17 | * @since 1.5 |
| 18 | * @since 1.7 Renamed from CronJobResponse. |
| 19 | */ |
| 20 | class VAPCronJobResponse |
| 21 | { |
| 22 | /** |
| 23 | * The log of the response of the cron job execution. |
| 24 | * |
| 25 | * @var string |
| 26 | */ |
| 27 | private $content = ''; |
| 28 | |
| 29 | /** |
| 30 | * The status of the response of the cron job execution. |
| 31 | * When the status is false, the content will be permanently stored. |
| 32 | * |
| 33 | * @var boolean |
| 34 | */ |
| 35 | private $status = true; |
| 36 | |
| 37 | /** |
| 38 | * The administrator will be notified only whether the content is not empty. |
| 39 | * When this parameter is true, the administrator will be notified via e-mail with the content. |
| 40 | * |
| 41 | * @var boolean |
| 42 | */ |
| 43 | private $notify = false; |
| 44 | |
| 45 | /** |
| 46 | * The last update of the response in millis. |
| 47 | * |
| 48 | * @var integer |
| 49 | */ |
| 50 | private $lastUpdate = null; |
| 51 | |
| 52 | /** |
| 53 | * The construct of the cron job response to initialize the required parameters of this object. |
| 54 | * |
| 55 | * @param string $content The response content. |
| 56 | * @param boolean $status The response status. |
| 57 | * @param boolean $notify If the response should be notified. |
| 58 | * |
| 59 | * @uses triggerUpdate() |
| 60 | */ |
| 61 | public function __construct($content = '', $status = true, $notify = false) |
| 62 | { |
| 63 | $this->content = $content; |
| 64 | $this->status = $status; |
| 65 | $this->notify = $notify; |
| 66 | |
| 67 | // last update done on the initialization of the object |
| 68 | $this->triggerUpdate(); |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Check if the response contents are not empty. |
| 73 | * |
| 74 | * @return boolean True if the contents are set, otherwise false. |
| 75 | * |
| 76 | * @since 1.6 |
| 77 | */ |
| 78 | public function hasContent() |
| 79 | { |
| 80 | return !empty($this->content); |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Overwrites the content of the response. |
| 85 | * |
| 86 | * @param string $content The content of the response. |
| 87 | * |
| 88 | * @return self Returns this object to support chaining. |
| 89 | * |
| 90 | * @uses triggerUpdate() |
| 91 | */ |
| 92 | public function setContent($content) |
| 93 | { |
| 94 | $this->content = $content; |
| 95 | |
| 96 | return $this->triggerUpdate(); |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * Appends the content of the response to the existing one. |
| 101 | * |
| 102 | * @param string $content The content of the response to append. |
| 103 | * |
| 104 | * @return self Returns this object to support chaining. |
| 105 | * |
| 106 | * @uses triggerUpdate() |
| 107 | */ |
| 108 | public function appendContent($content) |
| 109 | { |
| 110 | $this->content .= $content; |
| 111 | |
| 112 | return $this->triggerUpdate(); |
| 113 | } |
| 114 | |
| 115 | /** |
| 116 | * Prepends the content of the response before the existing one. |
| 117 | * |
| 118 | * @param string $content The content of the response to prepend. |
| 119 | * |
| 120 | * @return self Returns this object to support chaining. |
| 121 | * |
| 122 | * @uses triggerUpdate() |
| 123 | */ |
| 124 | public function prependContent($content) |
| 125 | { |
| 126 | $this->content = $content . $this->content; |
| 127 | |
| 128 | return $this->triggerUpdate(); |
| 129 | } |
| 130 | |
| 131 | |
| 132 | /** |
| 133 | * Returns the content of the response. |
| 134 | * |
| 135 | * @return string The content of the response. |
| 136 | */ |
| 137 | public function getContent() |
| 138 | { |
| 139 | return $this->content; |
| 140 | } |
| 141 | |
| 142 | /** |
| 143 | * Sets the status of the response. |
| 144 | * |
| 145 | * @param boolean $status The status of the response (true or false). |
| 146 | * |
| 147 | * @return self Returns this object to support chaining. |
| 148 | * |
| 149 | * @uses triggerUpdate() |
| 150 | */ |
| 151 | public function setStatus($status) |
| 152 | { |
| 153 | $this->status = $status; |
| 154 | |
| 155 | return $this->triggerUpdate(); |
| 156 | } |
| 157 | |
| 158 | /** |
| 159 | * Returns true if the status of the response is equals to true. |
| 160 | * |
| 161 | * @return boolean The verified status of the response. |
| 162 | */ |
| 163 | public function isVerified() |
| 164 | { |
| 165 | return $this->status; |
| 166 | } |
| 167 | |
| 168 | /** |
| 169 | * Returns true if the status of the response is equals to false. |
| 170 | * |
| 171 | * @return boolean The error status of the response. |
| 172 | */ |
| 173 | public function isError() |
| 174 | { |
| 175 | return !$this->status; |
| 176 | } |
| 177 | |
| 178 | /** |
| 179 | * Sets the notify setting of the response. |
| 180 | * |
| 181 | * @param boolean $notify The notify setting of the response (true or false). |
| 182 | * |
| 183 | * @return self Returns this object to support chaining. |
| 184 | * |
| 185 | * @uses triggerUpdate() |
| 186 | */ |
| 187 | public function setNotify($notify) |
| 188 | { |
| 189 | $this->notify = $notify; |
| 190 | |
| 191 | return $this->triggerUpdate(); |
| 192 | } |
| 193 | |
| 194 | /** |
| 195 | * Returns true if the administrator have to be notified. |
| 196 | * |
| 197 | * @return boolean The notify status of the response. |
| 198 | */ |
| 199 | public function isNotify() |
| 200 | { |
| 201 | return $this->notify; |
| 202 | } |
| 203 | |
| 204 | /** |
| 205 | * Refreshes the last update time of the response. |
| 206 | * |
| 207 | * @return self Returns this object to support chaining. |
| 208 | */ |
| 209 | protected function triggerUpdate() |
| 210 | { |
| 211 | $this->lastUpdate = JFactory::getDate()->toSql(); |
| 212 | |
| 213 | return $this; |
| 214 | } |
| 215 | |
| 216 | /** |
| 217 | * Returns the last update of the response. |
| 218 | * |
| 219 | * @return string The last update military date string. |
| 220 | */ |
| 221 | public function getLastUpdate() |
| 222 | { |
| 223 | return $this->lastUpdate; |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | /** |
| 228 | * Register a class alias for backward compatibility. |
| 229 | * |
| 230 | * @deprecated 1.8 |
| 231 | */ |
| 232 | class_alias('VAPCronJobResponse', 'CronJobResponse'); |
| 233 |