summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2021-05-26 21:33:52 +0200
committerHarald Eilertsen <haraldei@anduin.net>2021-05-26 21:33:52 +0200
commit8e1da1f405a5f307c84e12b9a40b4a657c16c05d (patch)
tree2041ebd3883d61cea42931d49689ed3734695dec
parent72a0df55f1a5858ac088cfce34183c740c544663 (diff)
downloadgigologadmin-8e1da1f405a5f307c84e12b9a40b4a657c16c05d.tar.gz
gigologadmin-8e1da1f405a5f307c84e12b9a40b4a657c16c05d.tar.bz2
gigologadmin-8e1da1f405a5f307c84e12b9a40b4a657c16c05d.zip
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.
-rw-r--r--includes/concertlogs.php33
1 files changed, 33 insertions, 0 deletions
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];
+ }
}
}