improve customer api & gui
This commit is contained in:
@@ -57,45 +57,52 @@ class EventRegistration extends \yii\db\ActiveRecord
|
||||
|
||||
public function behaviors()
|
||||
{
|
||||
return ArrayHelper::merge( [
|
||||
return ArrayHelper::merge([
|
||||
[
|
||||
'class' => TimestampBehavior::className(),
|
||||
'value' => function(){ return date('Y-m-d H:i:s' ); }
|
||||
'value' => function () {
|
||||
return date('Y-m-d H:i:s');
|
||||
}
|
||||
]
|
||||
],
|
||||
parent::behaviors());
|
||||
}
|
||||
|
||||
|
||||
public function getEvent(){
|
||||
return $this->hasOne($this->getEventClass(),['id' => 'id_event']);
|
||||
public function getEvent()
|
||||
{
|
||||
return $this->hasOne($this->getEventClass(), ['id' => 'id_event']);
|
||||
}
|
||||
|
||||
public function getCustomer(){
|
||||
return $this->hasOne($this->getCustomerClass(),['id' => 'id_customer']);
|
||||
public function getCustomer()
|
||||
{
|
||||
return $this->hasOne($this->getCustomerClass(), ['id' => 'id_customer']);
|
||||
}
|
||||
|
||||
|
||||
public function getEventClass(){
|
||||
public function getEventClass()
|
||||
{
|
||||
return Event::class;
|
||||
}
|
||||
|
||||
public function getCustomerClass(){
|
||||
public function getCustomerClass()
|
||||
{
|
||||
return Customer::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param EventRegistration $eventRegistration
|
||||
*/
|
||||
public static function isActive($eventRegistration){
|
||||
if ( !isset($eventRegistration ) ){
|
||||
public static function isActive($eventRegistration)
|
||||
{
|
||||
if (!isset($eventRegistration)) {
|
||||
return false;
|
||||
}
|
||||
if ( isset($eventRegistration->canceled_at ) ){
|
||||
if (isset($eventRegistration->canceled_at)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( isset($eventRegistration->deleted_at ) ){
|
||||
if (isset($eventRegistration->deleted_at)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -105,32 +112,40 @@ class EventRegistration extends \yii\db\ActiveRecord
|
||||
/**
|
||||
* @param EventRegistration $eventRegistration
|
||||
*/
|
||||
public static function isForCustomer($eventRegistration,$idCustomer){
|
||||
if ( !isset($eventRegistration ) ){
|
||||
public static function isForCustomer($eventRegistration, $idCustomer)
|
||||
{
|
||||
if (!isset($eventRegistration)) {
|
||||
return false;
|
||||
}
|
||||
if ( !isset($eventRegistration->id_customer ) ){
|
||||
if (!isset($eventRegistration->id_customer)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $eventRegistration->id_customer == $idCustomer;
|
||||
return $eventRegistration->id_customer == $idCustomer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param EventRegistration[] $eventRegistrations
|
||||
*/
|
||||
public static function filterActive($eventRegistrations){
|
||||
return array_filter($eventRegistrations, EventRegistration::class.'::isActive' );
|
||||
public static function filterActive($eventRegistrations)
|
||||
{
|
||||
if (!isset($eventRegistrations)) {
|
||||
return [];
|
||||
}
|
||||
return array_filter($eventRegistrations, EventRegistration::class . '::isActive');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param EventRegistration[] $eventRegistrations
|
||||
*/
|
||||
public static function filterForCustomer($eventRegistrations,$idCustomer){
|
||||
public static function filterForCustomer($eventRegistrations, $idCustomer)
|
||||
{
|
||||
$result = [];
|
||||
foreach ($eventRegistrations as $eventRegistration){
|
||||
if ( EventRegistration::isForCustomer($eventRegistration,$idCustomer)){
|
||||
$result[] = $eventRegistration;
|
||||
if (isset($eventRegistrations)) {
|
||||
foreach ($eventRegistrations as $eventRegistration) {
|
||||
if (EventRegistration::isForCustomer($eventRegistration, $idCustomer)) {
|
||||
$result[] = $eventRegistration;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
|
||||
Reference in New Issue
Block a user