diff --git a/dblayer.php b/dblayer.php index 824810c..611f674 100644 --- a/dblayer.php +++ b/dblayer.php @@ -551,6 +551,7 @@ class dblayer extends PDO array_walk ($binds, function(&$value, $key) { $value = md5 ($value); }); + $datasOK = $this->pre-insert ($datasOK); $req = "INSERT INTO $this->sep$this->tableprefix$this->table$this->sep "; $req .= "($this->sep". implode ("$this->sep,$this->sep", array_keys ($datasOK)). @@ -586,7 +587,9 @@ class dblayer extends PDO echo "dblayer execute exception : ".$e->getMessage()."\n"; exit; } - return $this->lastInsertId(); + $lastID = $this->lastInsertId(); + $lastID = $this->hookpostinsert ($datasOK, $lastID); + return $lastID; } /** Read the table content based on a select filter, ordered by order @@ -785,6 +788,7 @@ class dblayer extends PDO $datasOK[$field] = $datas[$field]; } + $datasOK = $this->hookpreupdate ($updatekey, $datasOK); $req = "UPDATE $this->sep".$this->tableprefix."$this->table$this->sep SET "; $i = 0; foreach ($datasOK as $key=>$val) @@ -840,7 +844,10 @@ class dblayer extends PDO } $st->execute (); - return $st->rowCount (); + $nbLinesUpdated = $st->rowCount (); + $nbLinesUpdated = $this->hookpostupdate ($updatekey, $datasOK, + $nbLinesUpdated); + return $nbLinesUpdated; } /** Delete a tuple identified by its primary key @@ -851,6 +858,7 @@ class dblayer extends PDO if ($this->debug) echo "== Entering delete\n"; if ($this->sep === "") throw new Exception (dgettext("domframework", "Database not connected")); + $deletekey = $this->hookpredelete ($deletekey); $req = "DELETE FROM $this->sep$this->tableprefix$this->table$this->sep "; $req .= "WHERE $this->primary = :primary"; $st = $this->prepare ($req); @@ -859,7 +867,9 @@ class dblayer extends PDO var_export ($deletekey, TRUE)."\n"; $st->bindValue (":primary", $deletekey); $st->execute (); - return $st->rowCount(); + $nbLinesDeleted = $st->rowCount(); + $nbLinesDeleted = $this->hookpostdelete ($deletekey, $nbLinesDeleted); + return $nbLinesDeleted; } /** Translation of fields */ @@ -1225,6 +1235,57 @@ class dblayer extends PDO $res[] = $d; return $res; } + + /** Hook preinsert + This hook is run before inserting a new data in the database, after the + verification + @param array the data to insert in the database + @return the modified datas */ + public function hookpreinsert ($data) + { + return $data; + } + + /** Hook postinsert + This hook is run after successfuly insert a new data in the database + @return the modified lastID */ + public function hookpostinsert ($data, $lastID) + { + return $lastID; + } + + /** Hook preupdate + This hook is run before updating a data in the database, after the + verification + @return the modified datas */ + public function hookpreupdate ($updatekey, $data) + { + return $data; + } + + /** Hook postupdate + This hook is run after successfuly update a data in the database + @return the modified $nbLinesUpdated */ + public function hookpostupdate ($updatekey, $data, $nbLinesUpdated) + { + return $nbLinesUpdated; + } + + /** Hook predelete + This hook is run before deleting a data in the database + @return the modified $deletekey */ + public function hookpredelete ($deletekey) + { + return $deletekey; + } + + /** Hook postdelete + This hook is run after successfuly deleting a data in the database + @return $nbLinesUpdated */ + public function hookpostdelete ($deletekey, $nbLinesDeleted) + { + return $nbLinesDeleted; + } } /** POC :