Version 5.0.0 beta 1
This commit is contained in:
1 parent
25ddeb65d6
commit
15c7beabc5
6736 files changed
+627902
-497943
No files matched your search
@@ -12,49 +12,59 @@
|
||||
namespace IPS\nexus\Customer;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use IPS\Db;
|
||||
use IPS\Member;
|
||||
use IPS\nexus\Customer;
|
||||
use IPS\Patterns\ActiveRecord;
|
||||
use IPS\Patterns\ActiveRecordIterator;
|
||||
use IPS\Patterns\Bitwise;
|
||||
use function defined;
|
||||
use function intval;
|
||||
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Alternative Contact Model
|
||||
*/
|
||||
class _AlternativeContact extends \IPS\Patterns\ActiveRecord
|
||||
class AlternativeContact extends ActiveRecord
|
||||
{
|
||||
/**
|
||||
* @brief Multiton Store
|
||||
*/
|
||||
protected static $multitons;
|
||||
protected static array $multitons;
|
||||
|
||||
/**
|
||||
* @brief Database Table
|
||||
*/
|
||||
public static $databaseTable = 'nexus_alternate_contacts';
|
||||
public static ?string $databaseTable = 'nexus_alternate_contacts';
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] ID Database Column
|
||||
*/
|
||||
public static $databaseColumnId = NULL;
|
||||
|
||||
public static string $databaseColumnId = "";
|
||||
|
||||
/**
|
||||
* Get main account
|
||||
*
|
||||
* @return \IPS\nexus\Customer
|
||||
* @return Customer
|
||||
*/
|
||||
public function get_main_id()
|
||||
public function get_main_id() : Customer
|
||||
{
|
||||
return \IPS\nexus\Customer::load( $this->_data['main_id'] );
|
||||
return Customer::load( $this->_data['main_id'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set main account
|
||||
*
|
||||
* @param \IPS\Member $member Member
|
||||
* @param Member $member Member
|
||||
* @return void
|
||||
*/
|
||||
public function set_main_id( \IPS\Member $member )
|
||||
public function set_main_id( Member $member ) : void
|
||||
{
|
||||
$this->_data['main_id'] = $member->member_id;
|
||||
}
|
||||
@@ -62,20 +72,20 @@ class _AlternativeContact extends \IPS\Patterns\ActiveRecord
|
||||
/**
|
||||
* Get alternate account
|
||||
*
|
||||
* @return \IPS\nexus\Customer
|
||||
* @return Customer
|
||||
*/
|
||||
public function get_alt_id()
|
||||
public function get_alt_id() : Customer
|
||||
{
|
||||
return \IPS\nexus\Customer::load( $this->_data['alt_id'] );
|
||||
return Customer::load( $this->_data['alt_id'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set alternate account
|
||||
*
|
||||
* @param \IPS\Member $member Member
|
||||
* @param Member $member Member
|
||||
* @return void
|
||||
*/
|
||||
public function set_alt_id( \IPS\Member $member )
|
||||
public function set_alt_id( Member $member ) : void
|
||||
{
|
||||
$this->_data['alt_id'] = $member->member_id;
|
||||
}
|
||||
@@ -83,11 +93,11 @@ class _AlternativeContact extends \IPS\Patterns\ActiveRecord
|
||||
/**
|
||||
* Get purchases
|
||||
*
|
||||
* @return \IPS\Patterns\ActiveRecordIterator
|
||||
* @return ActiveRecordIterator
|
||||
*/
|
||||
public function get_purchases()
|
||||
public function get_purchases() : ActiveRecordIterator
|
||||
{
|
||||
return new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'nexus_purchases', array( array( 'ps_member=?', $this->main_id->member_id ), \IPS\Db::i()->in( 'ps_id', $this->purchaseIds() ) ) ), 'IPS\nexus\Purchase' );
|
||||
return new ActiveRecordIterator( Db::i()->select( '*', 'nexus_purchases', array( array( 'ps_member=?', $this->main_id->member_id ), Db::i()->in( 'ps_id', $this->purchaseIds() ) ) ), 'IPS\nexus\Purchase' );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -95,7 +105,7 @@ class _AlternativeContact extends \IPS\Patterns\ActiveRecord
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function purchaseIds()
|
||||
public function purchaseIds() : array
|
||||
{
|
||||
return explode( ',', $this->_data['purchases'] );
|
||||
}
|
||||
@@ -106,17 +116,43 @@ class _AlternativeContact extends \IPS\Patterns\ActiveRecord
|
||||
* @param array $purchases The purchases
|
||||
* @return void
|
||||
*/
|
||||
public function set_purchases( array $purchases )
|
||||
public function set_purchases( array $purchases ) : void
|
||||
{
|
||||
$this->_data['purchases'] = implode( ',', array_keys( $purchases ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct ActiveRecord from database row
|
||||
*
|
||||
* @param array $data Row from database table
|
||||
* @param bool $updateMultitonStoreIfExists Replace current object in multiton store if it already exists there?
|
||||
* @return ActiveRecord
|
||||
*/
|
||||
public static function constructFromData( array $data, bool $updateMultitonStoreIfExists = TRUE ): ActiveRecord
|
||||
{
|
||||
/* Initiate an object */
|
||||
$classname = get_called_class();
|
||||
$obj = new $classname;
|
||||
$obj->_new = FALSE;
|
||||
$obj->_data = array();
|
||||
|
||||
/* Import data */
|
||||
foreach ( $data as $k => $v )
|
||||
{
|
||||
$obj->_data[ $k ] = $v;
|
||||
}
|
||||
|
||||
$obj->changed = array();
|
||||
|
||||
return $obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save Changed Columns
|
||||
*
|
||||
* @return void
|
||||
* @return void
|
||||
*/
|
||||
public function save()
|
||||
public function save(): void
|
||||
{
|
||||
if ( $this->_new )
|
||||
{
|
||||
@@ -133,14 +169,13 @@ class _AlternativeContact extends \IPS\Patterns\ActiveRecord
|
||||
{
|
||||
foreach( $this->$k->values as $field => $value )
|
||||
{
|
||||
$data[ $field ] = \intval( $value );
|
||||
$data[ $field ] = intval( $value );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( $this->_new )
|
||||
{
|
||||
$insert = array();
|
||||
if( static::$databasePrefix === NULL )
|
||||
{
|
||||
$insert = $data;
|
||||
@@ -188,9 +223,9 @@ class _AlternativeContact extends \IPS\Patterns\ActiveRecord
|
||||
/**
|
||||
* [ActiveRecord] Delete Record
|
||||
*
|
||||
* @return void
|
||||
* @return void
|
||||
*/
|
||||
public function delete()
|
||||
public function delete(): void
|
||||
{
|
||||
static::db()->delete( 'nexus_alternate_contacts', array( 'main_id=? AND alt_id=?', $this->_data['main_id'], $this->_data['alt_id'] ) );
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user