Automatic pass to convert with php-cs-fixer
This commit is contained in:
462
src/RouteSQL.php
462
src/RouteSQL.php
@@ -1,108 +1,175 @@
|
||||
<?php
|
||||
|
||||
/** DomFramework
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
/**
|
||||
* DomFramework
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
|
||||
namespace Domframework;
|
||||
|
||||
/** Automatic Routing for SQL database
|
||||
* Allow to do CRUD on data with only one line in index.php
|
||||
*/
|
||||
/**
|
||||
* Automatic Routing for SQL database
|
||||
* Allow to do CRUD on data with only one line in index.php
|
||||
*/
|
||||
class RouteSQL
|
||||
{
|
||||
/** Activate the debug */
|
||||
/**
|
||||
* Activate the debug
|
||||
*/
|
||||
public $debug = 0;
|
||||
/** Display the Actions column in list of entries */
|
||||
/**
|
||||
* Display the Actions column in list of entries
|
||||
*/
|
||||
public $displayActions = true;
|
||||
/** Do a confirmation in javascript before deleting entry */
|
||||
/**
|
||||
* Do a confirmation in javascript before deleting entry
|
||||
*/
|
||||
public $deleteConfirm = true;
|
||||
/** Push the actions buttons at end of line */
|
||||
/**
|
||||
* Push the actions buttons at end of line
|
||||
*/
|
||||
public $actionsAtEnd = false;
|
||||
/** The Text to Delete */
|
||||
/**
|
||||
* The Text to Delete
|
||||
*/
|
||||
public $textDelete = "";
|
||||
/** The Text to Edit */
|
||||
/**
|
||||
* The Text to Edit
|
||||
*/
|
||||
public $textEdit = "";
|
||||
/** enable internal CSS */
|
||||
/**
|
||||
* enable internal CSS
|
||||
*/
|
||||
public $enableInternalCSS = true;
|
||||
/** Definition of the position in top bar at left
|
||||
Allowed : addNew numberEntryByDisplay search information paginator */
|
||||
public $topBarLeft = array("addNew", "numberEntryByDisplay");
|
||||
/** Definition of the position in top bar at right
|
||||
Allowed : addNew numberEntryByDisplay search information paginator */
|
||||
public $topBarRight = array("search");
|
||||
/** Definition of the position in bottom bar at left
|
||||
Allowed : addNew numberEntryByDisplay search information paginator */
|
||||
public $bottomBarLeft = array("information");
|
||||
/** Definition of the position in bottom bar at right
|
||||
Allowed : addNew numberEntryByDisplay search information paginator */
|
||||
public $bottomBarRight = array("paginator");
|
||||
/** The cookie path used to determine the old parameters
|
||||
It is automatically generated with the URL */
|
||||
/**
|
||||
* Definition of the position in top bar at left
|
||||
* Allowed : addNew numberEntryByDisplay search information paginator
|
||||
*/
|
||||
public $topBarLeft = ["addNew", "numberEntryByDisplay"];
|
||||
/**
|
||||
* Definition of the position in top bar at right
|
||||
* Allowed : addNew numberEntryByDisplay search information paginator
|
||||
*/
|
||||
public $topBarRight = ["search"];
|
||||
/**
|
||||
* Definition of the position in bottom bar at left
|
||||
* Allowed : addNew numberEntryByDisplay search information paginator
|
||||
*/
|
||||
public $bottomBarLeft = ["information"];
|
||||
/**
|
||||
* Definition of the position in bottom bar at right
|
||||
* Allowed : addNew numberEntryByDisplay search information paginator
|
||||
*/
|
||||
public $bottomBarRight = ["paginator"];
|
||||
/**
|
||||
* The cookie path used to determine the old parameters
|
||||
* It is automatically generated with the URL
|
||||
*/
|
||||
public $path = "";
|
||||
/** Authentication for HTML part */
|
||||
public $authHTML = array("email" => "anonymous");
|
||||
/** Authentication for REST part */
|
||||
public $authREST = array("email" => "anonymous");
|
||||
/** Authorization object. Should allow a method named
|
||||
"allow ($module, $user, $object)" which return
|
||||
- NO if the object is not defined
|
||||
- RO if the object is in read-only mode
|
||||
- RW if the object is in read-write mode */
|
||||
/**
|
||||
* Authentication for HTML part
|
||||
*/
|
||||
public $authHTML = ["email" => "anonymous"];
|
||||
/**
|
||||
* Authentication for REST part
|
||||
*/
|
||||
public $authREST = ["email" => "anonymous"];
|
||||
/**
|
||||
* Authorization object. Should allow a method named
|
||||
* "allow ($module, $user, $object)" which return
|
||||
* - NO if the object is not defined
|
||||
* - RO if the object is in read-only mode
|
||||
* - RW if the object is in read-write mode
|
||||
*/
|
||||
public $authorization = null;
|
||||
/** Module name for authorization */
|
||||
/**
|
||||
* Module name for authorization
|
||||
*/
|
||||
public $module = null;
|
||||
/** Chain multiple routeSQL. Wait for an routeSQL object */
|
||||
/**
|
||||
* Chain multiple routeSQL. Wait for an routeSQL object
|
||||
*/
|
||||
public $chained = null;
|
||||
/** Chain multiple routeSQL. Wait for the foreign key */
|
||||
/**
|
||||
* Chain multiple routeSQL. Wait for the foreign key
|
||||
*/
|
||||
public $chainedForeign = null;
|
||||
/** Allow one or multiple links by entry in the list
|
||||
The array must be of the form array ("linkname"=>, "icon"=>)
|
||||
icon is optional and the linkname is used if it is not provided */
|
||||
public $internalLinks = array();
|
||||
/** The renderer class to use for HTML pages */
|
||||
/**
|
||||
* Allow one or multiple links by entry in the list
|
||||
* The array must be of the form array ("linkname"=>, "icon"=>)
|
||||
* icon is optional and the linkname is used if it is not provided
|
||||
*/
|
||||
public $internalLinks = [];
|
||||
/**
|
||||
* The renderer class to use for HTML pages
|
||||
*/
|
||||
public $rendererHTMLclass = false;
|
||||
/** The renderer method to use for HTML pages */
|
||||
/**
|
||||
* The renderer method to use for HTML pages
|
||||
*/
|
||||
public $rendererHTMLmethod = false;
|
||||
/** The layout HTML to use for HTML pages */
|
||||
/**
|
||||
* The layout HTML to use for HTML pages
|
||||
*/
|
||||
public $rendererHTMLlayout = false;
|
||||
/** The extensions allowed in REST */
|
||||
public $extensionsAllowed = array("json", "xml");
|
||||
/**
|
||||
* The extensions allowed in REST
|
||||
*/
|
||||
public $extensionsAllowed = ["json", "xml"];
|
||||
|
||||
/** The model file containing the database description */
|
||||
/**
|
||||
* The model file containing the database description
|
||||
*/
|
||||
private $model_file = "";
|
||||
/** The model class included in the model file */
|
||||
/**
|
||||
* The model class included in the model file
|
||||
*/
|
||||
private $model_class = "";
|
||||
/** The prefix to be used in the URL. Should be the end of $model_file
|
||||
Ex : if $model_file = models/model_zone.php, the url_prefix should be
|
||||
zone */
|
||||
/**
|
||||
* The prefix to be used in the URL. Should be the end of $model_file
|
||||
* Ex : if $model_file = models/model_zone.php, the url_prefix should be
|
||||
* zone
|
||||
*/
|
||||
private $url_prefix = "";
|
||||
/** The SQL object created */
|
||||
/**
|
||||
* The SQL object created
|
||||
*/
|
||||
private $objectDB = null;
|
||||
/** The DSN to connect to the database */
|
||||
/**
|
||||
* The DSN to connect to the database
|
||||
*/
|
||||
private $dsn = null;
|
||||
/** The Username to connect to the database */
|
||||
/**
|
||||
* The Username to connect to the database
|
||||
*/
|
||||
private $username = null;
|
||||
/** The Password to connect to the database */
|
||||
/**
|
||||
* The Password to connect to the database
|
||||
*/
|
||||
private $password = null;
|
||||
/** The Options to the PDO driver if needed */
|
||||
/**
|
||||
* The Options to the PDO driver if needed
|
||||
*/
|
||||
private $driver_options = null;
|
||||
/** The Datas are protected in read-only */
|
||||
/**
|
||||
* The Datas are protected in read-only
|
||||
*/
|
||||
private $readwriteAllowed = true;
|
||||
|
||||
/** Connect to the database
|
||||
* @param string $model_file The model file containing the database
|
||||
* description
|
||||
* @param string $model_class The model class included in the model file
|
||||
* @param string $url_prefix The prefix to be used in the URL. Should be the
|
||||
* end of $model_file
|
||||
* @param string $dsn The DSN to connect to the database
|
||||
* @param string $username The username to connect to the database
|
||||
* @param string $password The password to connect to the database
|
||||
* @param array|null $driver_options The PDO driver options
|
||||
*/
|
||||
/**
|
||||
* Connect to the database
|
||||
* @param string $model_file The model file containing the database
|
||||
* description
|
||||
* @param string $model_class The model class included in the model file
|
||||
* @param string $url_prefix The prefix to be used in the URL. Should be the
|
||||
* end of $model_file
|
||||
* @param string $dsn The DSN to connect to the database
|
||||
* @param string $username The username to connect to the database
|
||||
* @param string $password The password to connect to the database
|
||||
* @param array|null $driver_options The PDO driver options
|
||||
*/
|
||||
public function __construct(
|
||||
$model_file,
|
||||
$model_class,
|
||||
@@ -129,7 +196,9 @@ class RouteSQL
|
||||
}
|
||||
}
|
||||
|
||||
/** Connect to the database */
|
||||
/**
|
||||
* Connect to the database
|
||||
*/
|
||||
private function connect()
|
||||
{
|
||||
include "models/$this->model_file";
|
||||
@@ -141,7 +210,9 @@ class RouteSQL
|
||||
);
|
||||
}
|
||||
|
||||
/** Display the flash information if no flash view is available */
|
||||
/**
|
||||
* Display the flash information if no flash view is available
|
||||
*/
|
||||
private function showflash()
|
||||
{
|
||||
$dataflash = "";
|
||||
@@ -180,15 +251,16 @@ class RouteSQL
|
||||
return $dataflash;
|
||||
}
|
||||
|
||||
/** Display a paginator
|
||||
* $nbentries is the total number of elements
|
||||
* num is the number of elements displayed by page
|
||||
* page is the page to display
|
||||
* @param integer $nbentries The number of entries to display
|
||||
* @param integer $page The page number to display
|
||||
* @param integer $num ???
|
||||
* @param string $search The search query
|
||||
*/
|
||||
/**
|
||||
* Display a paginator
|
||||
* $nbentries is the total number of elements
|
||||
* num is the number of elements displayed by page
|
||||
* page is the page to display
|
||||
* @param integer $nbentries The number of entries to display
|
||||
* @param integer $page The page number to display
|
||||
* @param integer $num ???
|
||||
* @param string $search The search query
|
||||
*/
|
||||
private function paginatorArea($nbentries, $page, $num, $search)
|
||||
{
|
||||
// The maximum of links available in the paginator
|
||||
@@ -246,13 +318,14 @@ class RouteSQL
|
||||
return $content;
|
||||
}
|
||||
|
||||
/** Display the actions buttons outside of the table (actually, juste the
|
||||
* 'Add new entry' button
|
||||
* @param integer $nbentries The number of entries
|
||||
* @param integer $page The page number
|
||||
* @param integer $num ???
|
||||
* @param string $search The search query
|
||||
*/
|
||||
/**
|
||||
* Display the actions buttons outside of the table (actually, juste the
|
||||
* 'Add new entry' button
|
||||
* @param integer $nbentries The number of entries
|
||||
* @param integer $page The page number
|
||||
* @param integer $num ???
|
||||
* @param string $search The search query
|
||||
*/
|
||||
private function addNewArea($nbentries, $page, $num, $search)
|
||||
{
|
||||
$content = "";
|
||||
@@ -266,12 +339,13 @@ class RouteSQL
|
||||
return $content;
|
||||
}
|
||||
|
||||
/** Display the select list to choose the number of displayed entries
|
||||
* @param integer $nbentries The number of entries
|
||||
* @param integer $page The page number
|
||||
* @param integer $num ???
|
||||
* @param string $search The search query
|
||||
*/
|
||||
/**
|
||||
* Display the select list to choose the number of displayed entries
|
||||
* @param integer $nbentries The number of entries
|
||||
* @param integer $page The page number
|
||||
* @param integer $num ???
|
||||
* @param string $search The search query
|
||||
*/
|
||||
private function numberEntryByDisplayArea($nbentries, $page, $num, $search)
|
||||
{
|
||||
$route = new Route();
|
||||
@@ -280,7 +354,7 @@ class RouteSQL
|
||||
$content .= " <form method='get' action='" . $route->baseURL() .
|
||||
$this->url_prefix . "'>\n";
|
||||
$content .= " <select name='num' onchange='this.form.submit()' >\n";
|
||||
$list = array(10, 20, 50, 100, 200, 500, 1000);
|
||||
$list = [10, 20, 50, 100, 200, 500, 1000];
|
||||
foreach ($list as $element) {
|
||||
$content .= " <option ";
|
||||
if ($element == $num) {
|
||||
@@ -295,12 +369,13 @@ class RouteSQL
|
||||
return $content;
|
||||
}
|
||||
|
||||
/** Display the search area
|
||||
* @param integer $nbentries The number of entries
|
||||
* @param integer $page The page number
|
||||
* @param integer $num ???
|
||||
* @param string $search The search query
|
||||
*/
|
||||
/**
|
||||
* Display the search area
|
||||
* @param integer $nbentries The number of entries
|
||||
* @param integer $page The page number
|
||||
* @param integer $num ???
|
||||
* @param string $search The search query
|
||||
*/
|
||||
private function searchArea($nbentries, $page, $num, $search)
|
||||
{
|
||||
$route = new Route();
|
||||
@@ -316,12 +391,13 @@ class RouteSQL
|
||||
return $content;
|
||||
}
|
||||
|
||||
/** Display the information
|
||||
* @param integer $nbentries The number of entries
|
||||
* @param integer $page The page number
|
||||
* @param integer $num ???
|
||||
* @param string $search The search query
|
||||
*/
|
||||
/**
|
||||
* Display the information
|
||||
* @param integer $nbentries The number of entries
|
||||
* @param integer $page The page number
|
||||
* @param integer $num ???
|
||||
* @param string $search The search query
|
||||
*/
|
||||
private function informationArea($nbentries, $page, $num, $search)
|
||||
{
|
||||
$content = "";
|
||||
@@ -346,7 +422,9 @@ class RouteSQL
|
||||
return $content;
|
||||
}
|
||||
|
||||
/** Create the routes for REST pages and the associated actions */
|
||||
/**
|
||||
* Create the routes for REST pages and the associated actions
|
||||
*/
|
||||
public function routesREST()
|
||||
{
|
||||
$route = new Route();
|
||||
@@ -411,7 +489,7 @@ class RouteSQL
|
||||
if (!isset($extension) || $extension === null || $extension === "") {
|
||||
$extension = reset($this->extensionsAllowed);
|
||||
}
|
||||
if (!in_array($extension, $this->extensionsAllowed)) {
|
||||
if (!in_array($extension, $this->extensionsAllowed, true)) {
|
||||
throw new \Exception(dgettext(
|
||||
"domframework",
|
||||
"Extension not allowed"
|
||||
@@ -423,7 +501,7 @@ class RouteSQL
|
||||
unset($titles[$this->chainedForeign]);
|
||||
$foreignSelect = null;
|
||||
if ($this->chained !== null) {
|
||||
$foreignSelect = array(array($this->chainedForeign, $chain));
|
||||
$foreignSelect = [[$this->chainedForeign, $chain]];
|
||||
}
|
||||
if ($search === "") {
|
||||
$data = $this->objectDB->read(
|
||||
@@ -434,7 +512,7 @@ class RouteSQL
|
||||
$foreignSelect
|
||||
);
|
||||
} else {
|
||||
$criteria = array();
|
||||
$criteria = [];
|
||||
foreach (array_keys($titles) as $column) {
|
||||
$s = $search;
|
||||
if ($search[0] === "^") {
|
||||
@@ -447,7 +525,7 @@ class RouteSQL
|
||||
} else {
|
||||
$s = "$s%";
|
||||
}
|
||||
$criteria[] = array($column, "$s", "LIKE");
|
||||
$criteria[] = [$column, "$s", "LIKE"];
|
||||
}
|
||||
$data = $this->objectDB->read(
|
||||
$criteria,
|
||||
@@ -535,7 +613,7 @@ class RouteSQL
|
||||
if (!isset($extension) || $extension === null || $extension === "") {
|
||||
$extension = reset($this->extensionsAllowed);
|
||||
}
|
||||
if (!in_array($extension, $this->extensionsAllowed)) {
|
||||
if (!in_array($extension, $this->extensionsAllowed, true)) {
|
||||
throw new \Exception(dgettext(
|
||||
"domframework",
|
||||
"Extension not allowed"
|
||||
@@ -543,17 +621,17 @@ class RouteSQL
|
||||
}
|
||||
$this->connect();
|
||||
$values = $_POST;
|
||||
$errorsChain = array();
|
||||
$errorsChain = [];
|
||||
if (
|
||||
$this->chainedForeign !== null &&
|
||||
isset($values[$this->chainedForeign]) &&
|
||||
$values[$this->chainedForeign] !== $chain
|
||||
) {
|
||||
$errorsChain[$this->chainedForeign] =
|
||||
array("error", dgettext(
|
||||
["error", dgettext(
|
||||
"domframework",
|
||||
"Can not change the external key"
|
||||
));
|
||||
)];
|
||||
}
|
||||
if ($this->chainedForeign !== null) {
|
||||
$values[$this->chainedForeign] = $chain;
|
||||
@@ -637,7 +715,7 @@ class RouteSQL
|
||||
if (!isset($extension) || $extension === null || $extension === "") {
|
||||
$extension = reset($this->extensionsAllowed);
|
||||
}
|
||||
if (!in_array($extension, $this->extensionsAllowed)) {
|
||||
if (!in_array($extension, $this->extensionsAllowed, true)) {
|
||||
throw new \Exception(dgettext(
|
||||
"domframework",
|
||||
"Extension not allowed"
|
||||
@@ -645,17 +723,17 @@ class RouteSQL
|
||||
}
|
||||
$this->connect();
|
||||
parse_str(file_get_contents("php://input"), $values);
|
||||
$errorsChain = array();
|
||||
$errorsChain = [];
|
||||
if (
|
||||
$this->chainedForeign !== null &&
|
||||
isset($values[$this->chainedForeign]) &&
|
||||
$values[$this->chainedForeign] !== $chain
|
||||
) {
|
||||
$errorsChain[$this->chainedForeign] =
|
||||
array("error", dgettext(
|
||||
["error", dgettext(
|
||||
"domframework",
|
||||
"Can not change the external key"
|
||||
));
|
||||
)];
|
||||
}
|
||||
$errors = $this->objectDB->verify($values, $id);
|
||||
if (count($errors) > 0 || count($errorsChain) > 0) {
|
||||
@@ -736,7 +814,7 @@ class RouteSQL
|
||||
if (!isset($extension) || $extension === null || $extension === "") {
|
||||
$extension = reset($this->extensionsAllowed);
|
||||
}
|
||||
if (!in_array($extension, $this->extensionsAllowed)) {
|
||||
if (!in_array($extension, $this->extensionsAllowed, true)) {
|
||||
throw new \Exception(dgettext(
|
||||
"domframework",
|
||||
"Extension not allowed"
|
||||
@@ -753,7 +831,9 @@ class RouteSQL
|
||||
);
|
||||
}
|
||||
|
||||
/** Create the routes for HTML pages and the associated actions */
|
||||
/**
|
||||
* Create the routes for HTML pages and the associated actions
|
||||
*/
|
||||
public function routesHTML()
|
||||
{
|
||||
// If chained routeSQL, the url_prefix must be adapted
|
||||
@@ -767,7 +847,9 @@ class RouteSQL
|
||||
$this->url_prefix = $this->chained->url_prefix . "/{chain}/" .
|
||||
$this->url_prefix;
|
||||
}
|
||||
/** Add HTML routes */
|
||||
/**
|
||||
* Add HTML routes
|
||||
*/
|
||||
$route = new Route();
|
||||
$route->debug = $this->debug;
|
||||
;
|
||||
@@ -902,7 +984,7 @@ class RouteSQL
|
||||
unset($titles[$this->chainedForeign]);
|
||||
$foreignSelect = null;
|
||||
if ($this->chained !== null) {
|
||||
$foreignSelect = array(array($this->chainedForeign, $chain));
|
||||
$foreignSelect = [[$this->chainedForeign, $chain]];
|
||||
}
|
||||
if ($search === "") {
|
||||
$data = $this->objectDB->read(
|
||||
@@ -913,7 +995,7 @@ class RouteSQL
|
||||
$foreignSelect
|
||||
);
|
||||
} else {
|
||||
$criteria = array();
|
||||
$criteria = [];
|
||||
foreach (array_keys($titles) as $column) {
|
||||
$s = $search;
|
||||
if ($search[0] === "^") {
|
||||
@@ -926,7 +1008,7 @@ class RouteSQL
|
||||
} else {
|
||||
$s = "$s%";
|
||||
}
|
||||
$criteria[] = array($column, "$s", "LIKE");
|
||||
$criteria[] = [$column, "$s", "LIKE"];
|
||||
}
|
||||
$data = $this->objectDB->read(
|
||||
$criteria,
|
||||
@@ -950,7 +1032,7 @@ class RouteSQL
|
||||
|
||||
// Get the non mandatory foreign keys and display them instead of the
|
||||
// unusable id
|
||||
$foreignData = array();
|
||||
$foreignData = [];
|
||||
if (isset($this->objectDB->foreign)) {
|
||||
foreach ($this->objectDB->foreign as $foreign => $params) {
|
||||
if (! isset($params[0])) {
|
||||
@@ -970,10 +1052,10 @@ class RouteSQL
|
||||
);
|
||||
if (isset($foreignObject->unique)) {
|
||||
$tmpData = $foreignObject->read(null, array_merge(
|
||||
array($column),
|
||||
[$column],
|
||||
$foreignObject->unique
|
||||
));
|
||||
$associated = array();
|
||||
$associated = [];
|
||||
$unique = reset($foreignObject->unique);
|
||||
foreach ($tmpData as $vals) {
|
||||
// TODO : If $foreignObject->unique is not an array ?
|
||||
@@ -1458,7 +1540,7 @@ class RouteSQL
|
||||
|
||||
// Get the non mandatory foreign keys and display them instead of the
|
||||
// unusable id
|
||||
$foreignData = array();
|
||||
$foreignData = [];
|
||||
if (isset($this->objectDB->foreign)) {
|
||||
foreach ($this->objectDB->foreign as $foreign => $params) {
|
||||
if (! isset($params[0])) {
|
||||
@@ -1478,10 +1560,10 @@ class RouteSQL
|
||||
);
|
||||
if (isset($foreignObject->unique)) {
|
||||
$tmpData = $foreignObject->read(null, array_merge(
|
||||
array($column),
|
||||
[$column],
|
||||
$foreignObject->unique
|
||||
));
|
||||
$associated = array();
|
||||
$associated = [];
|
||||
$unique = reset($foreignObject->unique);
|
||||
foreach ($tmpData as $vals) {
|
||||
// TODO : If $foreignObject->unique is not an array ?
|
||||
@@ -1494,8 +1576,8 @@ class RouteSQL
|
||||
}
|
||||
|
||||
$content = $this->showflash();
|
||||
$values = array();
|
||||
$errors = array();
|
||||
$values = [];
|
||||
$errors = [];
|
||||
$titles = $this->objectDB->titles();
|
||||
if (isset($_SESSION["domframework"]["routeSQL"]["errors"])) {
|
||||
$errors = $_SESSION["domframework"]["routeSQL"]["errors"];
|
||||
@@ -1609,7 +1691,7 @@ class RouteSQL
|
||||
}
|
||||
|
||||
$f = new Form();
|
||||
$fields = array();
|
||||
$fields = [];
|
||||
foreach ($titles as $key => $val) {
|
||||
$field = new Formfield($key, $val);
|
||||
if (! isset($this->objectDB->fields[$key])) {
|
||||
@@ -1621,10 +1703,10 @@ class RouteSQL
|
||||
$key
|
||||
), 500);
|
||||
}
|
||||
if (in_array("not null", $this->objectDB->fields[$key])) {
|
||||
if (in_array("not null", $this->objectDB->fields[$key], true)) {
|
||||
$field->mandatory = true;
|
||||
}
|
||||
if (in_array("autoincrement", $this->objectDB->fields[$key])) {
|
||||
if (in_array("autoincrement", $this->objectDB->fields[$key], true)) {
|
||||
$field->type = "hidden";
|
||||
}
|
||||
if ($key === $this->chainedForeign) {
|
||||
@@ -1716,17 +1798,17 @@ class RouteSQL
|
||||
$this->connect();
|
||||
$f = new Form();
|
||||
$values = $f->values();
|
||||
$errorsChain = array();
|
||||
$errorsChain = [];
|
||||
if (
|
||||
$this->chainedForeign !== null &&
|
||||
isset($values[$this->chainedForeign]) &&
|
||||
$values[$this->chainedForeign] !== $chain
|
||||
) {
|
||||
$errorsChain[$this->chainedForeign] =
|
||||
array("error", dgettext(
|
||||
["error", dgettext(
|
||||
"domframework",
|
||||
"Can not change the external key"
|
||||
));
|
||||
)];
|
||||
}
|
||||
$errors = $this->objectDB->verify($values);
|
||||
if (count($errors) == 0 && count($errorsChain) == 0) {
|
||||
@@ -1817,7 +1899,7 @@ class RouteSQL
|
||||
$this->connect();
|
||||
// Get the non mandatory foreign keys and display them instead of the
|
||||
// unusable id
|
||||
$foreignData = array();
|
||||
$foreignData = [];
|
||||
if (isset($this->objectDB->foreign)) {
|
||||
foreach ($this->objectDB->foreign as $foreign => $params) {
|
||||
if (! isset($params[0])) {
|
||||
@@ -1837,10 +1919,10 @@ class RouteSQL
|
||||
);
|
||||
if (isset($foreignObject->unique)) {
|
||||
$tmpData = $foreignObject->read(null, array_merge(
|
||||
array($column),
|
||||
[$column],
|
||||
$foreignObject->unique
|
||||
));
|
||||
$associated = array();
|
||||
$associated = [];
|
||||
$unique = reset($foreignObject->unique);
|
||||
foreach ($tmpData as $vals) {
|
||||
// TODO : If $foreignObject->unique is not an array ?
|
||||
@@ -1852,11 +1934,11 @@ class RouteSQL
|
||||
}
|
||||
}
|
||||
$content = $this->showflash();
|
||||
$values = array();
|
||||
$errors = array();
|
||||
$values = [];
|
||||
$errors = [];
|
||||
$titles = $this->objectDB->titles();
|
||||
$values = $this->objectDB->read(array(array($this->objectDB->primary,
|
||||
$id)));
|
||||
$values = $this->objectDB->read([[$this->objectDB->primary,
|
||||
$id]]);
|
||||
if (count($values) === 0) {
|
||||
throw new \Exception(
|
||||
dgettext("domframework", "Object not found"),
|
||||
@@ -1976,7 +2058,7 @@ class RouteSQL
|
||||
}
|
||||
|
||||
$f = new Form();
|
||||
$fields = array();
|
||||
$fields = [];
|
||||
foreach ($titles as $key => $val) {
|
||||
$field = new Formfield($key, $val);
|
||||
if (! isset($this->objectDB->fields[$key])) {
|
||||
@@ -1988,10 +2070,10 @@ class RouteSQL
|
||||
$key
|
||||
), 500);
|
||||
}
|
||||
if (in_array("not null", $this->objectDB->fields[$key])) {
|
||||
if (in_array("not null", $this->objectDB->fields[$key], true)) {
|
||||
$field->mandatory = true;
|
||||
}
|
||||
if (in_array("autoincrement", $this->objectDB->fields[$key])) {
|
||||
if (in_array("autoincrement", $this->objectDB->fields[$key], true)) {
|
||||
$field->type = "hidden";
|
||||
}
|
||||
if ($readonly === true || $this->readwriteAllowed === false) {
|
||||
@@ -2086,7 +2168,7 @@ class RouteSQL
|
||||
}
|
||||
|
||||
$this->connect();
|
||||
$oldvalues = $this->objectDB->read(array(array($this->objectDB->primary, $id)));
|
||||
$oldvalues = $this->objectDB->read([[$this->objectDB->primary, $id]]);
|
||||
if (count($oldvalues) === 0) {
|
||||
throw new \Exception(
|
||||
dgettext("domframework", "Object not found"),
|
||||
@@ -2102,17 +2184,17 @@ class RouteSQL
|
||||
"Can not change the primary key"
|
||||
), 403);
|
||||
}
|
||||
$errorsChain = array();
|
||||
$errorsChain = [];
|
||||
if (
|
||||
$this->chainedForeign !== null &&
|
||||
isset($values[$this->chainedForeign]) &&
|
||||
$values[$this->chainedForeign] !== $chain
|
||||
) {
|
||||
$errorsChain[$this->chainedForeign] =
|
||||
array("error", dgettext(
|
||||
["error", dgettext(
|
||||
"domframework",
|
||||
"Can not change the external key"
|
||||
));
|
||||
)];
|
||||
}
|
||||
if ($this->chainedForeign !== null) {
|
||||
$values[$this->chainedForeign] = $chain;
|
||||
@@ -2150,11 +2232,12 @@ class RouteSQL
|
||||
});
|
||||
}
|
||||
|
||||
/** Authorization : Return TRUE if the user right allow to see the data
|
||||
* Return FALSE else
|
||||
* @param array $auth The auth to authenticate
|
||||
* @param integer|null $id The id to examine
|
||||
*/
|
||||
/**
|
||||
* Authorization : Return TRUE if the user right allow to see the data
|
||||
* Return FALSE else
|
||||
* @param array $auth The auth to authenticate
|
||||
* @param integer|null $id The id to examine
|
||||
*/
|
||||
public function accessright($auth, $id = null)
|
||||
{
|
||||
// echo "accessright=".var_export ($id, TRUE)." for ".
|
||||
@@ -2177,11 +2260,12 @@ class RouteSQL
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Authorization : Return TRUE if the user right allow to edit the data
|
||||
* Return FALSE else
|
||||
* @param array $auth The auth to authenticate
|
||||
* @param integer|null $id The id to examine
|
||||
*/
|
||||
/**
|
||||
* Authorization : Return TRUE if the user right allow to edit the data
|
||||
* Return FALSE else
|
||||
* @param array $auth The auth to authenticate
|
||||
* @param integer|null $id The id to examine
|
||||
*/
|
||||
public function editright($auth, $id = null)
|
||||
{
|
||||
// echo "editright=".var_export ($id, TRUE)." for ".
|
||||
@@ -2201,11 +2285,12 @@ class RouteSQL
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Authorization : Return TRUE if the $id is in READONLY for the user or
|
||||
* FALSE if the user have the RW rights
|
||||
* @param array $auth The auth to authenticate
|
||||
* @param integer|null $id The id to examine
|
||||
*/
|
||||
/**
|
||||
* Authorization : Return TRUE if the $id is in READONLY for the user or
|
||||
* FALSE if the user have the RW rights
|
||||
* @param array $auth The auth to authenticate
|
||||
* @param integer|null $id The id to examine
|
||||
*/
|
||||
public function readonly($auth, $id = null)
|
||||
{
|
||||
// echo "readonly=".var_export ($id, TRUE)." for ".
|
||||
@@ -2225,30 +2310,32 @@ class RouteSQL
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Return the data of the row if the $id exists in the primary key of the
|
||||
* table
|
||||
* Return FALSE in the other cases
|
||||
* @param integer $id The id to examine
|
||||
*/
|
||||
/**
|
||||
* Return the data of the row if the $id exists in the primary key of the
|
||||
* table
|
||||
* Return FALSE in the other cases
|
||||
* @param integer $id The id to examine
|
||||
*/
|
||||
public function keyexists($id)
|
||||
{
|
||||
$data = $this->objectDB->read(array(array($this->objectDB->primary,
|
||||
$id)));
|
||||
$data = $this->objectDB->read([[$this->objectDB->primary,
|
||||
$id]]);
|
||||
if (count($data) > 0) {
|
||||
return $data[0];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Display the data in HTML with the view class/method if they are defined
|
||||
* @param array $data The data to display
|
||||
*/
|
||||
/**
|
||||
* Display the data in HTML with the view class/method if they are defined
|
||||
* @param array $data The data to display
|
||||
*/
|
||||
private function rendererhtml($data)
|
||||
{
|
||||
$route = new Route();
|
||||
|
||||
$html = new Outputhtml();
|
||||
$replacement = array("{baseurl}" => $route->baseURL());
|
||||
$replacement = ["{baseurl}" => $route->baseURL()];
|
||||
if ($this->rendererHTMLlayout === false) {
|
||||
$this->rendererHTMLlayout = "<!DOCTYPE html>
|
||||
<html>
|
||||
@@ -2274,11 +2361,12 @@ class RouteSQL
|
||||
exit;
|
||||
}
|
||||
|
||||
/** Return the result converted by JSON/XML, defined in REST
|
||||
* @param string $extension The display method
|
||||
* @param array $data The data to return
|
||||
* @param integer $getCode The HTTP code to return (200 OK by default)
|
||||
*/
|
||||
/**
|
||||
* Return the result converted by JSON/XML, defined in REST
|
||||
* @param string $extension The display method
|
||||
* @param array $data The data to return
|
||||
* @param integer $getCode The HTTP code to return (200 OK by default)
|
||||
*/
|
||||
private function renderrest($extension, $data, $getCode = 200)
|
||||
{
|
||||
$http = new Http();
|
||||
|
||||
Reference in New Issue
Block a user