@@ -90,6 +90,11 @@ public static function instance($arg1, $arg2 = null) {
90
90
return self ::query_row ("SELECT * FROM ` $ table` WHERE $ fields $ active_field " , $ bind );
91
91
}
92
92
93
+ public static function connect ($ host , $ database , $ username , $ password ) {
94
+ $ db = new \Models \DB (DB_HOST , DB_NAME , DB_USER , DB_PASSWORD );
95
+ self ::set_db ($ db );
96
+ }
97
+
93
98
/**
94
99
* Set the DB object to our base model class
95
100
*
@@ -367,10 +372,16 @@ public function delete() {
367
372
$ pk = $ model ['pk ' ];
368
373
369
374
// we don't delete here :P
370
- if (self ::get_field ('active ' ))
371
- return $ this ->update ('active ' , 0 );
372
- else
375
+ if (self ::get_field ('active ' )) {
376
+ $ data = ['active ' => 0 ];
377
+ if (self ::get_field ('deleted_at ' )) {
378
+ $ data ['deleted_at ' ] = date ('Y-m-d H:i:s ' );
379
+ }
380
+
381
+ return $ this ->update ($ data );
382
+ } else {
373
383
return self ::$ db ->delete ("DELETE FROM $ table WHERE $ pk = :pk " , [':pk ' => $ this ->{$ pk }]);
384
+ }
374
385
}
375
386
376
387
/**
@@ -403,7 +414,6 @@ public function to_array($get_fields = null) {
403
414
$ result = [];
404
415
$ properties = get_object_vars ($ this );
405
416
406
-
407
417
foreach ($ properties as $ field => $ value ) {
408
418
if (!$ get_fields || ($ get_fields && in_array ($ field , $ get_fields ))) {
409
419
$ this ->_set_type ($ field , $ value );
0 commit comments