Docs : Add dblayer example

git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@1584 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
2014-07-28 10:27:26 +00:00
parent d09e4ad4c1
commit 7631d8cb71

View File

@@ -215,7 +215,90 @@ A database abstraction permits to forget if the database engine is MySQL, SQLite
or PostgreSQL. It can read, insert, update easily from arrays, but display the
tables without having to think about the backend.
It check the foreign keys before doing insertions/updates, look at unique
constrains.
constrains. It can create table with the different syntax of the engines.
Define your table like this :
class record extends dblayer
{
public $table = "dns_records";
public $fields = array (
"id"=>array ("integer", "not null", "autoincrement"),
"zoneid"=>array ("integer", "not null"),
"source"=>array ("varchar", "255", "not null"),
"class"=>array ("varchar", "2", "not null"),
"rr"=>array ("varchar", "10", "not null"),
"addvalues"=>array ("varchar", "10"),
"target"=>array ("varchar", "255", "not null"),
"ttl"=>array ("integer"),
"comment"=>array ("varchar", "1024"),
"opendate"=>array ("datetime", "not null"),
"closedate"=>array ("datetime"),
);
/** The primary key of the table */
public $primary = "id";
/** The unique constrain of the table */
public $unique = array ("id");
/** The foreign keys of the table */
public $foreign = array ("zoneid"=>array ("dns_zones", "id",
"ON UPDATE CASCADE ON DELETE CASCADE"));
/** SQL Debug */
public $debug = FALSE;
/** Translation */
public function titles ()
{
return array (
"id"=>_("ID"),
"zoneid"=>_("ID Zone"),
"source"=>_("Source"),
"class"=>_("Class"),
"rr"=>_("RR"),
"addvalues"=>_("Add values"),
"target"=>_("Target"),
"ttl"=>_("TTL"),
"comment"=>_("Comment"),
"opendate"=>_("Open date"),
"closedate"=>_("Close date"),
);
}
public function verifyOne ($field, $val)
{
$verify = new verify ();
switch ($field)
{
case "id":
break;
case "zoneid":
if (strlen ($val) < 1)
{
$msg = _("Not enough chars");
return array ("error", $msg);
}
break;
// Add more unit tests here
}
return array ();
}
/** Verify all the fields consistency and return an error array */
public function verifyAll ($datas)
{
$errors = array ();
$verify = new verify ();
switch ($datas["rr"])
{
case "A":
if (substr ($datas["source"], -1*strlen ($datas["zone"])) ===
$datas["zone"])
{
$msg = _("Don't add the domain in the source");
$errors["source"] = array ("error", $msg);
}
break;
// Add more consistency tests here
}
return $errors;
}
}
11. Authentication / Authorization
----------------------------------