parent
d7f3734d78
commit
620a3fe1d4
@ -1,46 +0,0 @@ |
|||||||
<?php |
|
||||||
|
|
||||||
declare(strict_types=1); |
|
||||||
|
|
||||||
/** |
|
||||||
* @author Robert Strutts <Robert@TryingToScale.com> |
|
||||||
* @copyright Copyright (c) 2022, Robert Strutts. |
|
||||||
* @license https://mit-license.org/ |
|
||||||
*/ |
|
||||||
|
|
||||||
namespace tts; |
|
||||||
|
|
||||||
final class json { |
|
||||||
|
|
||||||
public static function do_json_headers(int $status_code = 200) { |
|
||||||
if (!headers_sent()) { |
|
||||||
header($_SERVER['SERVER_PROTOCOL'] . " " . $status_code); |
|
||||||
header('Content-Type: application/json; charset=utf-8', true, intval($status_code)); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public static function output(array $data, string $misc = '') { |
|
||||||
$number_of_rows = \bs_tts\common::get_count($data); |
|
||||||
|
|
||||||
self::do_json_headers(); |
|
||||||
|
|
||||||
$dt = new \DateTime(); |
|
||||||
$ds = $dt->format('Y-m-d h:i:s A'); |
|
||||||
|
|
||||||
echo "{ \r\n \"records_total\": {$number_of_rows}, \r\n"; |
|
||||||
echo "\"date_stamp\": \"{$ds}\", \r\n"; |
|
||||||
|
|
||||||
if (! empty($misc) ) { |
|
||||||
echo $misc; |
|
||||||
} |
|
||||||
|
|
||||||
if ($number_of_rows > 0) { |
|
||||||
echo '"data":['; |
|
||||||
echo json_encode($data); |
|
||||||
echo ']}'; // end JSON object |
|
||||||
} else { |
|
||||||
echo '"data":[]}'; // No users!!! |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
Loading…
Reference in new issue