ver. 0.284: DbModel elimination, update packages for 0.283-0.284
- Removed class.DbModel.php — only consumer (shop\Promotion) now has inlined constructor + __get() - Created update packages: ver_0.283.zip (S→Helpers migration, ~130 files), ver_0.284.zip (DbModel removal) - Updated docs: CHANGELOG, PROJECT_STRUCTURE, FRONTEND_REFACTORING_PLAN Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,79 +0,0 @@
|
||||
<?php
|
||||
class DbModel
|
||||
{
|
||||
public $data;
|
||||
public $table;
|
||||
public $table_key = 'id';
|
||||
|
||||
public function __construct( $id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( $id )
|
||||
{
|
||||
$result = $mdb -> get( $this -> table, '*', [ $this -> table_key => $id ] );
|
||||
if ( is_array( $result ) ) foreach ( $result as $key => $val )
|
||||
$this -> $key = $val;
|
||||
|
||||
if ( is_array( $this -> otm ) ) foreach ( $this -> otm as $otm )
|
||||
{
|
||||
if ( $otm['skey'] )
|
||||
{
|
||||
$result2 = $mdb -> select( $otm['table'], '*', [ $otm['fkey'] => $id ] );
|
||||
if ( is_array( $result2 ) ) foreach ( $result2 as $row2 )
|
||||
{
|
||||
$this -> data[ $otm['name'] ][ $row2[ $otm['skey'] ] ] = $row2;
|
||||
}
|
||||
}
|
||||
else
|
||||
$this -> data[ $otm['name'] ] = $mdb -> select( $otm['table'], '*', [ $otm['fkey'] => $id ] );
|
||||
}
|
||||
|
||||
if ( is_array( $this -> sotm ) ) foreach ( $this -> sotm as $sotm )
|
||||
{
|
||||
$this -> data[ $sotm['name'] ] = $mdb -> select( $sotm['table'], $sotm['column'], [ $sotm['fkey'] => $id ] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function __get( $variable )
|
||||
{
|
||||
if ( array_key_exists( $variable, $this -> data ) )
|
||||
return $this -> data[$variable];
|
||||
}
|
||||
|
||||
public function __set( $variable, $value )
|
||||
{
|
||||
$this -> data[$variable] = $value;
|
||||
}
|
||||
|
||||
public function save()
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( $this -> __get( $this -> table_key ) )
|
||||
{
|
||||
$table_id_param = $this -> table_key;
|
||||
$table_id_value = $this -> __get( $this -> table_key );
|
||||
$data_tmp = $this -> data;
|
||||
unset( $data_tmp[ $table_id_param ] );
|
||||
|
||||
$mdb -> update( $this -> table, $data_tmp, [ $table_id_param => $table_id_value ] );
|
||||
|
||||
return $table_id_value;
|
||||
}
|
||||
else
|
||||
{
|
||||
$mdb -> insert( $this -> table, $this -> data );
|
||||
$this -> __set( $this -> table_key, $mdb -> id() );
|
||||
}
|
||||
return $this -> __get( $this -> table_key );
|
||||
}
|
||||
|
||||
public function delete()
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> delete( $this -> table, [ $this -> table_key => $this -> __get( $this -> table_key ) ] );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,11 +1,9 @@
|
||||
<?php
|
||||
namespace shop;
|
||||
|
||||
use DbModel;
|
||||
|
||||
class Promotion extends DbModel
|
||||
class Promotion
|
||||
{
|
||||
public $table = 'pp_shop_promotion';
|
||||
private $data = [];
|
||||
|
||||
public static $condition_type = [
|
||||
1 => 'Rabat procentowy na produkty z kategorii 1 jeżeli w koszyku jest produkt z kategorii 2',
|
||||
@@ -17,6 +15,25 @@ class Promotion extends DbModel
|
||||
|
||||
public static $discount_type = [ 1 => 'Rabat procentowy' ];
|
||||
|
||||
public function __construct( $id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( $id )
|
||||
{
|
||||
$result = $mdb->get( 'pp_shop_promotion', '*', [ 'id' => $id ] );
|
||||
if ( is_array( $result ) )
|
||||
$this->data = $result;
|
||||
}
|
||||
}
|
||||
|
||||
public function __get( $variable )
|
||||
{
|
||||
if ( isset( $this->data[$variable] ) )
|
||||
return $this->data[$variable];
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function get_active_promotions()
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
Reference in New Issue
Block a user