Commit 45bca035 authored by zYne's avatar zYne

Docs updated

parent f44cc732
...@@ -226,7 +226,9 @@ class Doctrine_Validator { ...@@ -226,7 +226,9 @@ class Doctrine_Validator {
$looseType = self::gettype($var); $looseType = self::gettype($var);
if($type == 'enum') if($type == 'enum')
$type = 'integer'; $type = 'integer';
elseif($type == 'date' || $type == 'clob')
$type = 'string';
switch($looseType): switch($looseType):
case 'float': case 'float':
......
...@@ -8,7 +8,14 @@ class Doctrine_Validator_Date { ...@@ -8,7 +8,14 @@ class Doctrine_Validator_Date {
* @return boolean * @return boolean
*/ */
public function validate(Doctrine_Record $record, $key, $value, $args) { public function validate(Doctrine_Record $record, $key, $value, $args) {
return checkdate($value); if(empty($value))
return true;
$e = explode("-", $value);
if(count($e) !== 3)
return false;
return checkdate($e[1], $e[0], $e[2]);
} }
} }
?> ?>
...@@ -5,18 +5,22 @@ class Entity extends Doctrine_Record { ...@@ -5,18 +5,22 @@ class Entity extends Doctrine_Record {
$this->hasColumn("username","string",20); $this->hasColumn("username","string",20);
$this->hasColumn("password","string",16); $this->hasColumn("password","string",16);
$this->hasColumn("created","integer",11); $this->hasColumn("created","integer",11);
// this column is used for column
// aggregation inheritance
$this->hasColumn("type", "integer", 11);
} }
} }
class User extends Entity { class User extends Entity {
public function setUp() { public function setUp() {
$this->setInheritanceMap(array("type"=>1); $this->setInheritanceMap(array("type"=>1));
} }
} }
class Group extends Entity { class Group extends Entity {
public function setUp() { public function setUp() {
$this->setInheritanceMap(array("type"=>2); $this->setInheritanceMap(array("type"=>2));
} }
} }
?> ?>
...@@ -35,6 +35,10 @@ $user->Group[1]->name = "Second Group"; ...@@ -35,6 +35,10 @@ $user->Group[1]->name = "Second Group";
// save changes into database // save changes into database
$user->save(); $user->save();
// deleting the associations between user and groups it belongs to
$user->Groupuser->delete();
$groups = new Doctrine_Collection($session->getTable("Group")); $groups = new Doctrine_Collection($session->getTable("Group"));
$groups[0]->name = "Third Group"; $groups[0]->name = "Third Group";
...@@ -46,4 +50,5 @@ $user->Group[2] = $groups[0]; ...@@ -46,4 +50,5 @@ $user->Group[2] = $groups[0];
$user->Group = $groups; $user->Group = $groups;
// $user will now have two groups 'Third Group' and 'Fourth Group' // $user will now have two groups 'Third Group' and 'Fourth Group'
?> ?>
If you are coming from relational database background it may be familiar to you If you are coming from relational database background it may be familiar to you
how many-to-many associations are handled: an additional association table is needed. how many-to-many associations are handled: an additional association table is needed.
<br \><br \> <br \><br \>
In many-to-many relations the relation between the two components is always an aggregate
relation and the association table is owned by both ends. For example in the case of users and groups
when user is being deleted the groups it belongs to are not being deleted and the associations between this user
and the groups it belongs to are being deleted.
<br \><br \>
Sometimes you may not want that association table rows are being deleted when user / group is being deleted. You can override
this behoviour by setting the relations to association component (in this case Groupuser) explicitly.
<br \><br \>
In the following example we have Groups and Users of which relation is defined as In the following example we have Groups and Users of which relation is defined as
many-to-many. In this case we also need to define an additional class called Groupuser. many-to-many. In this case we also need to define an additional class called Groupuser.
...@@ -32,7 +32,9 @@ function render($title,$t,$e) { ...@@ -32,7 +32,9 @@ function render($title,$t,$e) {
if(file_exists("codes/$title - $t.php")) { if(file_exists("codes/$title - $t.php")) {
print "<table border=1 class='dashed' cellpadding=0 cellspacing=0>"; print "<table border=1 class='dashed' cellpadding=0 cellspacing=0>";
print "<tr><td>"; print "<tr><td>";
$c = file_get_contents("codes/$title - $t.php"); $c = file_get_contents("codes/$title - $t.php");
$c = trim($c);
$h->loadString($c); $h->loadString($c);
print $h->toHtml(); print $h->toHtml();
print "</td></tr>"; print "</td></tr>";
...@@ -52,13 +54,18 @@ function render_block($name) { ...@@ -52,13 +54,18 @@ function render_block($name) {
} }
} }
if(file_exists("codes/$name.php")) { if(file_exists("codes/$name.php")) {
print "<table width=500 border=1 class='dashed' cellpadding=0 cellspacing=0>";
print "<tr><td>";
$c = file_get_contents("codes/$name.php"); $c = file_get_contents("codes/$name.php");
$c = trim($c);
if( ! empty($c)) {
$h->loadString($c); $h->loadString($c);
print "<table width=500 border=1 class='dashed' cellpadding=0 cellspacing=0>";
print "<tr><td>";
print $h->toHtml(); print $h->toHtml();
print "</td></tr>"; print "</td></tr>";
print "</table>"; print "</table>";
}
} }
} }
function array2path($array, $path = '') { function array2path($array, $path = '') {
...@@ -189,7 +196,8 @@ $menu = array("Getting started" => ...@@ -189,7 +196,8 @@ $menu = array("Getting started" =>
"Creating related records", "Creating related records",
"Retrieving related records", "Retrieving related records",
"Updating related records", "Updating related records",
"Deleting related records"), "Deleting related records",
"Working with associations"),
"Inheritance" => "Inheritance" =>
array("One table many classes", array("One table many classes",
"One table one class", "One table one class",
...@@ -315,6 +323,7 @@ $menu = array("Getting started" => ...@@ -315,6 +323,7 @@ $menu = array("Getting started" =>
"Real world examples" => array("User management system","Forum application","Album lister") "Real world examples" => array("User management system","Forum application","Album lister")
); );
?> ?>
...@@ -352,14 +361,16 @@ $menu = array("Getting started" => ...@@ -352,14 +361,16 @@ $menu = array("Getting started" =>
if( ! file_exists("docs/$title - $k - $v2.php")) { if( ! file_exists("docs/$title - $k - $v2.php")) {
$missing[0]++; $missing[0]++;
$str .= " [ <font color='red'>doc</font> ] "; $str .= " [ <font color='red'>doc</font> ] ";
//touch("docs/$title - $k - $v2.php");
} }
if( ! file_exists("codes/$title - $k - $v2.php")) { if( ! file_exists("codes/$title - $k - $v2.php")) {
$missing[1]++; $missing[1]++;
$str .= " [ <font color='red'>code</font> ] "; $str .= " [ <font color='red'>code</font> ] ";
//touch("codes/$title - $k - $v2.php");
} }
$e = implode(".",array($i,$i2,$i3)); $e = implode(".",array($i,$i2,$i3));
print "<dd><dd>".$e." <a href=\"".$_SERVER['PHP_SELF']."?index=$i.$i2#$e\">".$v2."</a><br>\n"; print "<dd><dd>".$e." <a href=\"".$_SERVER['PHP_SELF']."?index=$i.$i2#$e\">".$v2."</a>$str<br>\n";
$i3++; $i3++;
} }
} else { } else {
...@@ -367,12 +378,14 @@ $menu = array("Getting started" => ...@@ -367,12 +378,14 @@ $menu = array("Getting started" =>
if( ! file_exists("docs/$title - $t.php")) { if( ! file_exists("docs/$title - $t.php")) {
$missing[0]++; $missing[0]++;
$str .= " [ <font color='red'>doc</font> ] "; $str .= " [ <font color='red'>doc</font> ] ";
//touch("docs/$title - $t.php");
} }
if( ! file_exists("codes/$title - $t.php")) { if( ! file_exists("codes/$title - $t.php")) {
$missing[1]++; $missing[1]++;
$str .= " [ <font color='red'>code</font> ] "; $str .= " [ <font color='red'>code</font> ] ";
//touch("codes/$title - $t.php");
} }
print "<dd>".$e." <a href=\"".$_SERVER['PHP_SELF']."?index=$i#$e\">".$t."</a><br>\n"; print "<dd>".$e." <a href=\"".$_SERVER['PHP_SELF']."?index=$i#$e\">".$t."</a>$str<br>\n";
} }
$i2++; $i2++;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment