From 8e1da1f405a5f307c84e12b9a40b4a657c16c05d Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Wed, 26 May 2021 21:33:52 +0200 Subject: Add instance methods to Concertlogs. This allows us to instantiate a Concertlogs objects just as with Concert and Venue objects. Also add a few instance methods to get the assigned user for a given role, and get the role assigned to a given user. --- includes/concertlogs.php | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'includes') diff --git a/includes/concertlogs.php b/includes/concertlogs.php index 70baf26..8b485ca 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. @@ -56,5 +66,28 @@ if ( !class_exists( 'GiglogAdmin_Concertlogs' ) ) 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 ); + } + + public function assigned_user(string $role) : ?string + { + return $this->roles[$role]; + } } } -- cgit v1.2.3