kompass/modules/event-participants/Models/class-eventgroup.php

58 lines
1.4 KiB
PHP

<?php
namespace Bdp\Modules\EventParticipants\Models;
use Bdp\Libs\CommonModel;
class EventGroup extends CommonModel {
public static function loadById(int $group_id) {
global $dbHandler;
$data = $dbHandler->readFromDb('kompass_veranstaltungen_gruppen', ['id' => $group_id]);
$class = new EventGroup();
foreach (get_object_vars($data[0]) as $key => $value) {
$class->$key = $value;
}
foreach (EventParticipant::list_for_group($group_id) as $participant_id) {
$class->participants[] = EventParticipant::loadById($participant_id);
}
return $class;
}
public static function list_simple_for_event(int $event_id) : array {
global $dbHandler;
$data = $dbHandler->readFromDb('kompass_veranstaltungen_gruppen', ['eventId' => $event_id]);
$return = [];
foreach ($data as $group) {
$group_class = new EventGroup();
foreach (get_object_vars($group) as $key => $value) {
$group_class->$key = $value;
}
$return[] = $group_class;
}
return $return;
}
public static function list_for_event(int $event_id) : array {
global $dbHandler;
$data = $dbHandler->readFromDb('kompass_veranstaltungen_teilis', ['eventId' => $event_id]);
$return = [];
foreach ($data as $group) {
$return[] = $group->id;
}
return $return;
}
public function __construct() {
$this->_tablename = 'kompass_veranstaltungen_gruppen';
$this->participants = [];
}
}