minenux-skindb-webdb/lib/class.model.php
mckaygerhard 7395532339 implements a renders oputput cos we will use same oouput many times
* fix http status code not property set in guachi, puff
* index default page will only show welcome
* not found page will show http status code and also link to repot issues
* render output will show and set as must be the http status code
* render output will show a minimal description message
2024-04-10 13:08:12 -04:00

95 lines
2.7 KiB
PHP

<?php
/*la clase del modelo*/
abstract class model {
protected $db = null;
protected $auth = null;
protected $router = null;
protected $view = null;
/* Constructor
*
* INPUT: object database, object settings, object user, object page, object view[, object language]
* OUTPUT: -
* ERROR: -
*/
public function __construct($db, $auth, $router, $view) {
$this->db = $db;
$this->auth = $auth;
$this->router = $router;
$this->view = $view;
}
/* Borrow function from other model
*
* INPUT: string module name
* OUTPUT: object model
* ERROR: null
*/
protected function borrow($module) {
if (file_exists($file = "../models/".$module.".php") == false) {
header("Content-Type: text/plain");
printf("Can't borrow model '%s'.\n", $module);
exit();
}
require_once($file);
$model_class = str_replace("/", "_", $module)."_model";
if (class_exists($model_class) == false) {
return null;
} else if (is_subclass_of($model_class, "model") == false) {
return null;
}
return new $model_class($this->db, $this->auth, $this->router, $this->view);
}
/* show ap[i output in json format
*
* INPUT: array
* OUTPUT: string
* ERROR: null
*/
protected function renderOutput($variables, $jsonout = false) {
$contentt = 'Content-Type: text/plain';
$protocol = (isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0');
$httpcode = '412';
$sucess = false;
$message = 'No message was specified, the server could not process the content or the page does not exist';
$page = 1;
$pages = 1;
$per_page = 1;
$data = array($message);
if(is_array($variables) ) {
foreach($variables as $key => $value) {
$$key = $value;
}
}
$GLOBALS['http_response_code'] = $httpcode;
if( !is_null($jsonout) and !empty($jsonout)) {
$contentt = 'Content-Type: application/json; charset=utf-8';
header($contentt);
$jsondata = array(
'sucess' => $sucess,
'message' => $message,
'page' => $page,
'pages' => $pages,
'per_page' => $per_page,
'data'=> $data
);
print(json_encode($jsondata));
}
else {
$contentt = 'Content-Type: text/html; charset=UTF-8';
header($contentt);
include(DIR_VIEWS."notfoundview.php");
}
}
}