summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2022-03-10 22:57:41 +0100
committerHarald Eilertsen <haraldei@anduin.net>2022-03-10 22:57:41 +0100
commite0bf0d9d073894774bef5ce29056cc27c74d1505 (patch)
tree8bd18d5503945dac3d370f8166a29f756f6cc0ee
parenta5198af622cdab6a4b42723f3a4eb7b0681de054 (diff)
downloadgigologadmin-e0bf0d9d073894774bef5ce29056cc27c74d1505.tar.gz
gigologadmin-e0bf0d9d073894774bef5ce29056cc27c74d1505.tar.bz2
gigologadmin-e0bf0d9d073894774bef5ce29056cc27c74d1505.zip
Move code to update concert table to concert table class.
Puts everything that belongs together into the same place. This means the concerts table is getting a tad large, but let's refactor that later.
-rw-r--r--includes/admin/views/_concerts_table.php104
-rw-r--r--includes/admin/views/giglog_admin_page.php111
2 files changed, 107 insertions, 108 deletions
diff --git a/includes/admin/views/_concerts_table.php b/includes/admin/views/_concerts_table.php
index 2d1ed04..a7bf7c5 100644
--- a/includes/admin/views/_concerts_table.php
+++ b/includes/admin/views/_concerts_table.php
@@ -30,6 +30,106 @@ if (!class_exists("GiglogAdmin_ConcertsTable"))
private array $filter;
private int $page_no;
+ public static function update() : void
+ {
+ if (isset($_POST['assignitem'])) {
+ $concert = GiglogAdmin_Concert::get(intval($_POST['cid']));
+
+ if ($concert) {
+ $role = sanitize_text_field($_POST['pid']);
+ self::assignconcert($role, $concert);
+ }
+
+ return;
+ }
+
+ if (isset($_POST['unassignitem'])) {
+ $concert = GiglogAdmin_Concert::get(intval($_POST['cid']));
+
+ if ($concert) {
+ $role = sanitize_text_field($_POST['pid']);
+ self::unassignconcert($role, $concert);
+ }
+
+ return;
+ }
+
+ // handle the status drop down
+ if (isset($_POST['selectstatus']) && !empty($_POST['selectstatus']) && !empty($_POST['cid'])) {
+ if ($_POST['selectstatus'] > 0 && $_POST['selectstatus'] < count(self::STATUS_LABELS)) {
+ $concert = GiglogAdmin_Concert::get(intval($_POST['cid']));
+ if ( $concert ) {
+ $concert->set_status(intval($_POST['selectstatus']));
+ $concert->save();
+ self::emailuser($concert,intval($_POST['selectstatus']));
+ }
+ }
+ }
+ }
+
+ static function assignconcert(string $p1, GiglogAdmin_Concert $concert): void
+ {
+ $username = wp_get_current_user()->user_login;
+ $concert->assign_role($p1, $username);
+ $concert->save();
+
+ $cuser = get_user_by( 'login', 'etadmin');
+
+ if ( $cuser ) {
+ $dest = $cuser->user_email;
+ $subject = 'WP-GIGLOG '.$username.' has taken '.$p1. 'for concert '.$concert->cname();
+ $body = 'WP-GIGLOG '.$username.' has taken '.$p1. 'for concert '.$concert->cname().', concert with ID ' .$concert->id();
+ $headers = array('Content-Type: text/html; charset=UTF-8');
+
+ wp_mail( $dest, $subject, $body );
+ }
+ }
+
+ static function unassignconcert(string $p1, GiglogAdmin_Concert $concert): void
+ {
+ $username = wp_get_current_user()->user_login;
+ $concert->remove_user_from_roles($username);
+ $concert->save();
+
+ $cuser = get_user_by( 'login', 'etadmin');
+
+ if ( $cuser ) {
+ $dest = $cuser->user_email;
+ $subject = 'WP-GIGLOG '.$username.' has UNASSIGNED '.$p1. 'for concert '.$concert->cname();
+ $body = 'WP-GIGLOG '.$username.' has UNASSIGNED '.$p1. 'for concert '.$concert->cname().', concert with ID ' .$concert->id();
+ $headers = array('Content-Type: text/html; charset=UTF-8');
+
+ wp_mail( $dest, $subject, $body );
+ }
+ }
+
+ static function emailuser(GiglogAdmin_Concert $concert, string $cstatus): void
+ {
+ $username = wp_get_current_user()->user_login;
+ $useremail = 'live@eternal-terror.com';
+ $dest = '';
+ $roles = $concert -> roles();
+ $x = '';
+
+ foreach ($roles as $role) {
+ if($role){
+ $cuser = get_user_by( 'login', $role);
+
+ if ( $cuser ) {
+ $dest .= $cuser->user_email . ',';
+ }
+ }
+ }
+
+ $subject = 'Message from GIGLOG: Concert '.$concert->cname().' has a new status '.$cstatus. '.';
+ $body = 'You receive this message because you have assigned one of the roles for Concert '.$concert->cname().'.';
+ $body .= '\r\n This is to inform you that there is a new status for the acreditation '.$cstatus. '.';
+ $body .= '\r\n Should you no longer want to receive updates about this concert, please log in to Giglog and remove yourself from the concert. Thanks!';
+ $headers = array('Content-Type: text/plain; charset=UTF-8'); //it is text by default so no need for headers actually
+
+ wp_mail( $dest, $subject, $body );
+ }
+
public function __construct() {
$this->username = wp_get_current_user()->user_login;
$this->get_args();
@@ -44,9 +144,9 @@ if (!class_exists("GiglogAdmin_ConcertsTable"))
private function render_concert_table_header() : string
{
$content = '<div style="overflow-x:auto;"><table class="assignit">';
- $content.= '<span style="font-size:0.8em;font-style: italic;"> Note: the iCal link will download a file with extension .ical which can be used to add the event to your calendar. For convenience, we set all events with start time at 19:00 but please check the actual event for the correct time.</span>';
+ $content.= '<span style="font-size:0.8em;font-style: italic;">Note: the iCal link will download a file with extension .ical which can be used to add the event to your calendar. For convenience, we set all events with start time at 19:00 but please check the actual event for the correct time.</span>';
- $content.= '<tr class="assignithrow">';
+ $content.= '<tr class="assignithrow">';
$content.= '<th>CITY</th><th>DATE</th><th>NAME</th><th>VENUE</th>';
if (!is_admin()) {
diff --git a/includes/admin/views/giglog_admin_page.php b/includes/admin/views/giglog_admin_page.php
index c8e9250..6ce3cc8 100644
--- a/includes/admin/views/giglog_admin_page.php
+++ b/includes/admin/views/giglog_admin_page.php
@@ -67,53 +67,17 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) {
/**
* @return void
*/
- static function update()
+ static function update() : void
{
if ('POST' !== $_SERVER['REQUEST_METHOD'])
return;
- if(isset($_POST['assignitem']))
- {
- $concert = GiglogAdmin_Concert::get(intval($_POST['cid']));
- $role = sanitize_text_field($_POST['pid']);
-
- if ($concert) {
- GiglogAdmin_AdminPage::assignconcert($role, $concert);
- }
-
- $url2=$_SERVER['REQUEST_URI'];
- header("Refresh: 1; URL=$url2"); //reload page
- }
-
- if(isset($_POST['unassignitem']))
- {
- $concert = GiglogAdmin_Concert::get(intval($_POST['cid']));
- if ( ! $concert ) {
- wp_die( "Invalid concert specified." );
- }
-
- $role = sanitize_text_field($_POST['pid']);
-
- GiglogAdmin_AdminPage::unassignconcert($role, $concert);
-
- $url3=$_SERVER['REQUEST_URI'];
- header("Refresh: 1; URL=$url3"); //reload page
- }
-
- // handle the status drop down
- if (isset($_POST['selectstatus']) && !empty($_POST['selectstatus']) && !empty($_POST['cid']))
- {
- if ($_POST['selectstatus'] > 0 && $_POST['selectstatus'] < count(self::STATUS_LABELS)) {
- $concert = GiglogAdmin_Concert::get(intval($_POST['cid']));
- if ( $concert ) {
- $concert->set_status(intval($_POST['selectstatus']));
- $concert->save();
- GiglogAdmin_AdminPage::emailuser($concert,intval($_POST['selectstatus']));
- }
- }
+ if (isset($_POST['assignitem']) || isset($_POST['unassignitem']) || isset($_POST['selectstatus'])) {
+ GiglogAdmin_ConcertsTable::update();
+ return;
}
- if(isset($_POST['newconcert'])) {
+ if (isset($_POST['newconcert'])) {
if (empty($_POST['cname']) || empty($_POST['selectvenueadmin']) || empty($_POST['cdate']) || empty($_POST['ticket']) || empty($_POST['eventurl'])) {
echo '<script language="javascript">alert("You are missing a value, concert was not created"); </script>';
}
@@ -183,70 +147,5 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) {
}
}
}
-
- static function assignconcert(string $p1, GiglogAdmin_Concert $concert): void
- {
- $username = wp_get_current_user()->user_login;
- $concert->assign_role($p1, $username);
- $concert->save();
-
- $cuser = get_user_by( 'login', 'etadmin');
-
- if ( $cuser ) {
- $dest = $cuser->user_email;
- $subject = 'WP-GIGLOG '.$username.' has taken '.$p1. 'for concert '.$concert->cname();
- $body = 'WP-GIGLOG '.$username.' has taken '.$p1. 'for concert '.$concert->cname().', concert with ID ' .$concert->id();
- $headers = array('Content-Type: text/html; charset=UTF-8');
-
- wp_mail( $dest, $subject, $body );
- }
- }
-
- static function unassignconcert(string $p1, GiglogAdmin_Concert $concert): void
- {
- $username = wp_get_current_user()->user_login;
- $concert->remove_user_from_roles($username);
- $concert->save();
-
- $cuser = get_user_by( 'login', 'etadmin');
-
- if ( $cuser ) {
- $dest = $cuser->user_email;
- $subject = 'WP-GIGLOG '.$username.' has UNASSIGNED '.$p1. 'for concert '.$concert->cname();
- $body = 'WP-GIGLOG '.$username.' has UNASSIGNED '.$p1. 'for concert '.$concert->cname().', concert with ID ' .$concert->id();
- $headers = array('Content-Type: text/html; charset=UTF-8');
-
- wp_mail( $dest, $subject, $body );
- }
- }
-
- static function emailuser(GiglogAdmin_Concert $concert, $cstatus): void
- {
- $username = wp_get_current_user()->user_login;
- $useremail = 'live@eternal-terror.com';
- $dest = '';
- $roles = $concert -> roles();
- $x = '';
-
- foreach ($roles as $role) {
- if($role){
- $cuser = get_user_by( 'login', $role);
-
- if ( $cuser ) {
- $dest .= $cuser->user_email . ',';
- }
- }
- }
-
- $subject = 'Message from GIGLOG: Concert '.$concert->cname().' has a new status '.$cstatus. '.';
- $body = 'You receive this message because you have assigned one of the roles for Concert '.$concert->cname().'.';
- $body .= '\r\n This is to inform you that there is a new status for the acreditation '.$cstatus. '.';
- $body .= '\r\n Should you no longer want to receive updates about this concert, please log in to Giglog and remove yourself from the concert. Thanks!';
- $headers = array('Content-Type: text/plain; charset=UTF-8'); //it is text by default so no need for headers actually
-
- wp_mail( $dest, $subject, $body );
- }
-
}
}
-?>