kompass/modules/event-participants/Controllers/class-main.php

237 lines
6.3 KiB
PHP
Raw Permalink Normal View History

<?php
2024-05-27 16:59:30 +02:00
namespace Bdp\Modules\EventParticipants\Controllers;
use Bdp\Libs\FileAccess;
use SearchMemberRequest;
2024-05-27 16:59:30 +02:00
class MainController
{
2024-05-27 16:59:30 +02:00
public const KOMPASS_EVENTS_EVENTS = 'kompass_veranstaltungen_index';
public const KOMPASS_EVENTS_PARTICIPANTS = 'kompass_veranstaltungen_teilis';
2024-05-27 16:59:30 +02:00
public static function setup()
{
global $wpdb;
$charset = $wpdb->get_charset_collate();
$fileReader = new FileAccess();
2024-05-31 22:47:04 +02:00
foreach ([self::KOMPASS_EVENTS_EVENTS, self::KOMPASS_EVENTS_PARTICIPANTS] as $table) {
$sqlTable = $wpdb->prefix . $table;
$sql = "SHOW TABLES LIKE '$sqlTable'";
$result = $wpdb->get_var( $sql );
if ( $result == $sqlTable ) {
continue;
}
$sqlSetup = str_replace(
'%tablename%',
$sqlTable,
$fileReader->get_contents( WP_PLUGIN_DIR . '/' . BDP_LV_PLUGIN_SLUG . '/lib/database/' . $table . '.sql' ) );
$sqlSetup = str_replace('%charset%', $charset, $sqlSetup);
$sqlSetup = str_replace('%prefix%', $wpdb->prefix, $sqlSetup);
dbDelta( $sqlSetup );
}
}
public function __construct()
{
2024-08-10 22:13:57 +02:00
global $dbHandler, $wpdb;
$no_events = true;
foreach ( [ self::KOMPASS_EVENTS_EVENTS ] as $table ) {
$sqlTable = $wpdb->prefix . $table;
$sql = "SHOW TABLES LIKE '$sqlTable'";
$result = $wpdb->get_var( $sql );
if ( $result == $sqlTable ) {
$no_events = 0 === $dbHandler->countSqlRows( self::KOMPASS_EVENTS_EVENTS, [ 'archived' => false ] );
}
}
if ( !$no_events ) {
add_menu_page(
__( 'Events (legacy)', BDP_LV_PLUGIN_SLUG ),
__( 'Events (legacy)', BDP_LV_PLUGIN_SLUG ),
'send_mails',
'kompass-events',
[ $this, 'router' ],
'dashicons-tickets-alt',
3
);
foreach ( $dbHandler->readFromDb( self::KOMPASS_EVENTS_EVENTS, [ 'archived' => false ] ) as $currentEvent ) {
add_submenu_page(
'kompass-events',
$currentEvent->event_name,
$currentEvent->event_name,
'show_groups',
'kompass-events&action=show-event&event-id=' . $currentEvent->id,
[ $this, 'router' ] );
}
}
}
2024-08-10 22:13:57 +02:00
public function router()
{
if (isset($_REQUEST['action'])) {
switch ($_REQUEST['action']) {
2024-05-27 16:59:30 +02:00
case 'show-event':
new ListGroupsAndMembersController();
break;
case 'show-participant':
if (isset($_REQUEST['save'])) {
new UpdateMemberDetailsController();
}
new MemberDetailsController();
break;
case 'delete-participant':
new DeleteMemberController();
break;
case 'update-participant-amount':
new UpdateMemberAmountController();
break;
case 'open-event':
new OpenEvent();
break;
case 'close-event':
new CloseEvent();
break;
case 'archive-event':
new ArchiveEvent();
break;
case 'edit-event':
new EditEvent();
break;
case 'update-event':
new UpdateEvent();
break;
case 'new-event':
new NewEvent();
break;
case 'create-event':
new CreateEvent();
break;
case 'kompass_print_participant_mail_form':
new MemberMailFormController();
break;
case 'send-mail-to-all':
new EventMailFormController();
break;
case 'send-mail-to-group':
new EventGroupMailFormController();
break;
case 'send-mail-to-local-group':
new EventLocalGroupMailFormController();
break;
case 'searchmember':
$memberList = SearchMemberRequest::listByName($_POST['member_name']);
new PrintMemberListController($memberList);
break;
case 'create_group_form':
new CreateGroupController();
break;
case 'update-group':
\UpdateGroupAction::execute(['gruppen_name' => $_REQUEST['kompass_groups_group_name']],
(int)$_REQUEST['group_id']);
new PrintGroupsController();
break;
case 'create-group':
$data = ['gruppen_name' => $_REQUEST['kompass_groups_group_name']];
\CreateGroupAction::execute($data);
new PrintGroupsController();
break;
case 'new-member':
new CreateMemberController();
break;
case 'create-member':
$userData = \CreateGroupMemberDataAction::execute($_REQUEST);
if (count($userData['errors']) === 0) {
$memberId = \CreateGroupMemberAction::execute( $userData['data'] );
new PrintMemberController($memberId);
} else {
kompass_print_message_box(implode('<br />', $userData['errors']), 'error');
new CreateMemberController($userData['rawData']);
exit;
}
new PrintGroupsController();
break;
case 'show-members':
$memberList = \ListMemberRequest::listForGroup((int)$_REQUEST['group-id']);
new PrintMemberListController($memberList);
break;
case 'show-member':
new PrintMemberController((int)$_REQUEST['member-id']);
break;
case 'compose-mail':
current_user_can('send_mails');
break;
case 'delete-group':
if (current_user_can('delete_groups')) {
}
break;
case 'edit-group':
if (current_user_can('edit_groups')) {
kompass_edit_group_form($_REQUEST['group-id']);
}
break;
default:
2024-05-27 16:59:30 +02:00
new ListEventsController();
}
} else {
2024-05-27 16:59:30 +02:00
new ListEventsController();
}
}
private function listMembers()
{
}
private function printMembers(array $memberList)
{
}
}