improve customer api & gui

This commit is contained in:
Roland Schneider
2021-10-02 22:21:14 +02:00
parent 1d065cc729
commit f98dcb656f
44 changed files with 893 additions and 298 deletions

View File

@@ -161,7 +161,8 @@ class Event extends ActiveRecord
* @return EventRegistration[]|ActiveQuery
*/
public function getActiveEventRegistrations(){
return $this->hasMany(EventRegistration::class,['id_event' => 'id'])->andWhere(
return $this->hasMany(EventRegistration::class,['id_event' => 'id'])
->andWhere(
[
'event_registration.canceled_at' => null,
'event_registration.deleted_at' => null,
@@ -169,19 +170,6 @@ class Event extends ActiveRecord
);
}
/**
* @return EventRegistration[]|ActiveQuery
*/
public function getActiveEventRegistrationsForCustomer(){
return $this->hasMany(EventRegistration::class,['id_event' => 'id'])->andWhere(
[
'event_registration.canceled_at' => null,
'event_registration.deleted_at' => null,
'event_registration.id_customer' => \Yii::$app->user->id
]
);
}
/**
* @return integer
*/

View File

@@ -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;

View File

@@ -11,6 +11,7 @@ use yii\helpers\ArrayHelper;
*
* @property integer $id
* @property string $name
* @property string $theme
* @property string $created_at
* @property string $updated_at
*/
@@ -30,9 +31,10 @@ class EventType extends \yii\db\ActiveRecord
public function rules()
{
return [
[['name'], 'required'],
[['name','theme'], 'required'],
[['name'], 'unique'],
[['name'], 'string', 'max' => 255]
[['name'], 'string', 'max' => 255],
[['theme'], 'string', 'max' => 50]
];
}
@@ -104,4 +106,12 @@ class EventType extends \yii\db\ActiveRecord
// TODO: implement bossiness logic to select ticket
return $possibleTickets[0];
}
static function themes() {
$themes = [];
for ($x = 0; $x < 10; $x++) {
$themes[$x] = "Színtéma " . ($x+1);
}
return $themes;
}
}

View File

@@ -2,6 +2,7 @@
namespace common\models;
use common\helpers\AppArrayHelper;
use Yii;
use yii\behaviors\TimestampBehavior;
use yii\helpers\ArrayHelper;