diff options
author | AndreaChirulescu <andrea.chirulescu@gmail.com> | 2021-06-15 18:34:29 +0200 |
---|---|---|
committer | AndreaChirulescu <andrea.chirulescu@gmail.com> | 2021-06-15 18:34:29 +0200 |
commit | 1a8155ea64352b0eaf088675d51547361f6f17a7 (patch) | |
tree | 7da669474e0896cefbec89a16b65413a7ed25cb1 /includes/concertlogs.php | |
parent | bfe4eb5efd705b64943a0e1c0b7e18bfe0eee4d8 (diff) | |
parent | 82c4a8f2c4e5acd80b813829cecc40f621da3b21 (diff) | |
download | gigologadmin-1a8155ea64352b0eaf088675d51547361f6f17a7.tar.gz gigologadmin-1a8155ea64352b0eaf088675d51547361f6f17a7.tar.bz2 gigologadmin-1a8155ea64352b0eaf088675d51547361f6f17a7.zip |
Merge branch 'dev' of https://code.volse.net/wordpress/plugins/gigologadmin.git into andreaschanges
Diffstat (limited to 'includes/concertlogs.php')
-rw-r--r-- | includes/concertlogs.php | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/includes/concertlogs.php b/includes/concertlogs.php index 3b8083a..8b1ca63 100644 --- a/includes/concertlogs.php +++ b/includes/concertlogs.php @@ -9,6 +9,16 @@ if ( !class_exists( 'GiglogAdmin_Concertlogs' ) ) { class GiglogAdmin_Concertlogs { + private array $roles; + + private function __construct( $attr = [] ) + { + $this->roles['photo1'] = $attr->{"wpgcl_photo1"}; + $this->roles['photo2'] = $attr->{"wpgcl_photo2"}; + $this->roles['rev1'] = $attr->{"wpgcl_rev1"}; + $this->roles['rev2'] = $attr->{"wpgcl_rev2"}; + } + /** * Adds a default entry for the given concert id in the * concert logs table. @@ -25,5 +35,81 @@ if ( !class_exists( 'GiglogAdmin_Concertlogs' ) ) $wpdb->query($q); } + + static function update($cid, $ph1, $ph2, $rev1, $rev2) + { + global $wpdb; + + $res = $wpdb->update('wpg_concertlogs', array( + 'wpgcl_photo1' => $ph1, + 'wpgcl_photo2' => $ph2, + 'wpgcl_rev1' => $rev1, + 'wpgcl_rev2' => $rev2 + ), + array('wpgcl_concertid' => $cid) + ); + + if ( !$res ) { + // exit( var_dump( $wpdb->last_query ) ); //for onscreen debugging when needed + error_log( __CLASS__ . '::' . __FUNCTION__ . ": {$wpdb->last_error}"); + die; + } + + return ($wpdb->last_error); + } + + public static function get_status(int $concert_id) : ?int + { + global $wpdb; + + $q = $wpdb->prepare( + 'select wpgcl_status from wpg_concertlogs where id = %d', + $concert_id); + $res = $wpdb->get_results($q); + + return $res ? $res[0]->wpgcl_status : null; + } + + public static function get_assigned_user( int $concert_id, string $role ) : ?string + { + global $wpdb; + + if ( ! in_array( $role, [ 'photo1', 'photo2', 'rev1', 'rev2' ] ) ) { + error_log(__METHOD__ . ": invalid \$role ({$role}) given."); + return null; + } + + $column = "wpgcl_{$role}"; + $q = $wpdb->prepare( + "select {$column} from wpg_concertlogs where id = %d", + $concert_id); + + $res = $wpdb->get_row($q, ARRAY_A); + + return array_shift( $res ); + } + + public static function get(int $concert_id) : ?self + { + global $wpdb; + + $q = $wpdb->prepare( + "select * from wpg_concertlogs where id = %d", + $concert_id); + + $res = $wpdb->get_row($q); + + return $res ? new self($res) : null; + } + + public function get_assigned_role(string $username) : ?string + { + return array_search( $username, $this->roles ) || NULL; + } + + public function assigned_user(string $role) : ?string + { + return $this->roles[$role]; + } } } |