helpers
1 month ago
tables
1 month ago
aIProviderInterface.php
1 month ago
assets.php
1 month ago
baseObject.php
1 month ago
builderBlock.php
1 month ago
controller.php
1 month ago
date.php
1 month ago
db.php
1 month ago
dispatcher.php
1 month ago
errors.php
1 month ago
field.php
1 month ago
fieldAdapter.php
1 month ago
frame.php
1 month ago
helper.php
1 month ago
html.php
1 month ago
installer.php
1 month ago
installerDbUpdater.php
1 month ago
integration.php
1 month ago
modInstaller.php
1 month ago
model.php
1 month ago
module.php
1 month ago
req.php
1 month ago
response.php
1 month ago
table.php
1 month ago
uri.php
1 month ago
user.php
1 month ago
utils.php
1 month ago
validator.php
1 month ago
view.php
1 month ago
response.php
119 lines
| 1 | <?php |
| 2 | if ( ! defined( 'ABSPATH' ) ) { |
| 3 | exit; |
| 4 | } |
| 5 | class WaicResponse { |
| 6 | public $code = 0; |
| 7 | public $error = false; |
| 8 | public $errors = array(); |
| 9 | public $messages = array(); |
| 10 | public $html = ''; |
| 11 | public $data = array(); |
| 12 | public $recordsFiltered = 0; |
| 13 | public $recordsTotal = 0; |
| 14 | public $draw = 0; |
| 15 | public $task = false; |
| 16 | public $actions = false; |
| 17 | |
| 18 | /** |
| 19 | * Marker to set data not in internal $data var, but set it as object parameters |
| 20 | */ |
| 21 | private $_ignoreShellData = false; |
| 22 | public function getReqType() { |
| 23 | return WaicReq::getVar('reqType'); |
| 24 | } |
| 25 | public function isAjax() { |
| 26 | return $this->getReqType() == 'ajax'; |
| 27 | } |
| 28 | public function ajaxExec( $forceAjax = false ) { |
| 29 | $isAjax = $this->isAjax(); |
| 30 | $redirect = WaicReq::getVar('redirect'); |
| 31 | if (count($this->errors) > 0) { |
| 32 | $this->error = true; |
| 33 | } |
| 34 | if ($isAjax || $forceAjax) { |
| 35 | WaicHtml::echoEscapedHtml(waicJsonEncodeUTFnormal($this)); |
| 36 | exit(); |
| 37 | } |
| 38 | return $this; |
| 39 | } |
| 40 | public function mainRedirect( $redirectUrl = '' ) { |
| 41 | $redirectUrl = empty($redirectUrl) ? WAIC_SITE_URL : $redirectUrl; |
| 42 | $redirectData = array(); |
| 43 | if (!empty($this->errors)) { |
| 44 | $redirectData['waicErrors'] = $this->errors; |
| 45 | } |
| 46 | if (!empty($this->messages)) { |
| 47 | $redirectData['waicMsgs'] = $this->messages; |
| 48 | } |
| 49 | return waicRedirect( $redirectUrl . ( strpos($redirectUrl, '?') ? '&' : '?' ) . http_build_query($redirectData) ); |
| 50 | } |
| 51 | public function error() { |
| 52 | return $this->error; |
| 53 | } |
| 54 | public function addError( $error, $key = '' ) { |
| 55 | if (empty($error)) { |
| 56 | return; |
| 57 | } |
| 58 | $this->error = true; |
| 59 | if (is_array($error)) { |
| 60 | $this->errors = array_merge($this->errors, $error); |
| 61 | } else { |
| 62 | $m = ''; |
| 63 | if (empty($key)) { |
| 64 | $this->errors[] = $error; |
| 65 | } else { |
| 66 | $this->errors[$key] = $error; |
| 67 | } |
| 68 | } |
| 69 | } |
| 70 | /** |
| 71 | * Alias for WaicResponse::addError, @see addError method |
| 72 | */ |
| 73 | public function pushError( $error, $key = '' ) { |
| 74 | return $this->addError($error, $key); |
| 75 | } |
| 76 | public function addMessage( $msg ) { |
| 77 | if (empty($msg)) { |
| 78 | return; |
| 79 | } |
| 80 | if (is_array($msg)) { |
| 81 | $this->messages = array_merge($this->messages, $msg); |
| 82 | } else { |
| 83 | $this->messages[] = $msg; |
| 84 | } |
| 85 | } |
| 86 | public function getMessages() { |
| 87 | return $this->messages; |
| 88 | } |
| 89 | public function setHtml( $html ) { |
| 90 | $this->html = $html; |
| 91 | } |
| 92 | public function addData( $data, $value = null ) { |
| 93 | if (empty($data)) { |
| 94 | return; |
| 95 | } |
| 96 | if ($this->_ignoreShellData) { |
| 97 | if (!is_array($data)) { |
| 98 | $data = array($data => $value); |
| 99 | } |
| 100 | foreach ($data as $key => $val) { |
| 101 | $this->{$key} = $val; |
| 102 | } |
| 103 | } else { |
| 104 | $m = ''; |
| 105 | if (is_array($data)) { |
| 106 | $this->data = array_merge($this->data, $data); |
| 107 | } else { |
| 108 | $this->data[$data] = $value; |
| 109 | } |
| 110 | } |
| 111 | } |
| 112 | public function getErrors() { |
| 113 | return $this->errors; |
| 114 | } |
| 115 | public function ignoreShellData() { |
| 116 | $this->_ignoreShellData = true; |
| 117 | } |
| 118 | } |
| 119 |