*
* CALLS BEFORE change occurs:
*
- * beforeDelete($dependants_array, $roo)
+ * beforeDelete($dependants_array, $roo, $request)
* Argument is an array of un-find/fetched dependant items.
* - jerr() will stop insert.. (Prefered)
* - return false for fail and set DO->err;
$affects = array();
- $all_links = $GLOBALS['_DB_DATAOBJECT']['LINKS'][$x->_database];
+ $all_links = $x->databaseLinks();
+
foreach($all_links as $tbl => $links) {
foreach($links as $col => $totbl_col) {
$to = explode(':', $totbl_col);
$match_total = 0;
if ( $has_beforeDelete ) {
- if ($xx->beforeDelete($match_ar, $this) === false) {
+ if ($xx->beforeDelete($match_ar, $this, $req) === false) {
$errs[] = "Delete failed ({$xx->id})\n".
(isset($xx->err) ? $xx->err : '');
continue;
}
- DB_DataObject::Factory('Events')->logDeletedRecord($x);
-
- $this->addEvent("DELETE", $x);
+ $this->logDeleteEvent($x);
$xx->delete();
}
+ function logDeleteEvent($object)
+ {
+
+ DB_DataObject::Factory('Events')->logDeletedRecord($object);
+
+ $this->addEvent("DELETE", $object);
+
+
+ }
+
+
function update($x, $req, $with_perm_check = true)
{
if ( $with_perm_check && !$this->checkPerm($x,'E', $req) ) {
{
$this->permitError = true; // allow it to fail without dieing
- $lock = DB_DataObjecT::factory('Core_locking');
- Pman::$permitError = false;
+ $lock = DB_DataObjecT::factory('core_locking');
+ $this->permitError = false;
if (is_a($lock,'DB_DataObject') && $this->authUser) {
$lock->on_id = $x->{$this->key};
// edit it anyways...
// can we find the user's lock.
- $lock = DB_DataObjecT::factory('Core_locking');
+ $lock = DB_DataObjecT::factory('core_locking');
$lock->on_id = $x->{$this->key};
$lock->on_table= strtolower($x->tableName());
$lock->person_id = $this->authUser->id;
$x->modified_by != $this->authUser->id
)
{
- $p = DB_DataObject::factory('Person');
+ $p = DB_DataObject::factory('core_person');
$p->get($x->modified_by);
- $this->jerr($p->name . " saved the record since you started editing,\nDo you really want to update it?", array('needs_confirm' => true));
+ $this->jerr($p->name . " saved the record since you started editing,\nDo you really want to update it?", array('needs_confirm' => true));
}
-
-
-
}
+
return $lock;
}
+
+ function insert($x, $req, $with_perm_check = true)
+ {
+ if (method_exists($x, 'setFromRoo')) {
+ $res = $x->setFromRoo($req, $this);
+ if (is_string($res)) {
+ $this->jerr($res);
+ }
+ } else {
+ $x->setFrom($req);
+ }
+
+ if ( $with_perm_check && !$this->checkPerm($x,'A', $req)) {
+ $this->jerr("PERMISSION DENIED (i)");
+ }
+ $cols = $x->table();
+
+ if (isset($cols['created'])) {
+ $x->created = date('Y-m-d H:i:s');
+ }
+ if (isset($cols['created_dt'])) {
+ $x->created_dt = date('Y-m-d H:i:s');
+ }
+ if (isset($cols['created_by'])) {
+ $x->created_by = $this->authUser->id;
+ }
+
+
+ if (isset($cols['modified'])) {
+ $x->modified = date('Y-m-d H:i:s');
+ }
+ if (isset($cols['modified_dt'])) {
+ $x->modified_dt = date('Y-m-d H:i:s');
+ }
+ if (isset($cols['modified_by'])) {
+ $x->modified_by = $this->authUser->id;
+ }
+
+ if (isset($cols['updated'])) {
+ $x->updated = date('Y-m-d H:i:s');
+ }
+ if (isset($cols['updated_dt'])) {
+ $x->updated_dt = date('Y-m-d H:i:s');
+ }
+ if (isset($cols['updated_by'])) {
+ $x->updated_by = $this->authUser->id;
+ }
+
+ if (method_exists($x, 'beforeInsert')) {
+ $x->beforeInsert($_REQUEST, $this);
+ }
+
+ $res = $x->insert();
+ if ($res === false) {
+ $this->jerr($x->_lastError->toString());
+ }
+ if (method_exists($x, 'onInsert')) {
+ $x->onInsert($_REQUEST, $this);
+ }
+ $ev = $this->addEvent("ADD", $x);
+ if ($ev) {
+ $ev->audit($x);
+ }
+
+ // note setFrom might handle this before hand...!??!
+ if (!empty($_FILES) && method_exists($x, 'onUpload')) {
+ $x->onUpload($this, $_REQUEST);
+ }
+
+ return $this->selectSingle(
+ DB_DataObject::factory($x->tableName()),
+ $x->pid()
+ );
+
+ }
}
\ No newline at end of file