summaryrefslogtreecommitdiffstats
path: root/includes/venue.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/venue.php')
-rw-r--r--includes/venue.php35
1 files changed, 25 insertions, 10 deletions
diff --git a/includes/venue.php b/includes/venue.php
index aedb6a7..3ad0f06 100644
--- a/includes/venue.php
+++ b/includes/venue.php
@@ -7,11 +7,19 @@
if ( !class_exists('GiglogAdmin_Venue') ) {
class GiglogAdmin_Venue
{
- private $id;
- private $name;
- private $city;
- private $address;
- private $webpage;
+ private ?int $id;
+
+ /**
+ * @psalm-suppress PropertyNotSetInConstructor
+ */
+ private string $name;
+
+ /**
+ * @psalm-suppress PropertyNotSetInConstructor
+ */
+ private string $city;
+ private ?string $address;
+ private ?string $webpage;
/*
* Constructs a new venue object from an array of attributes.
@@ -19,11 +27,19 @@ if ( !class_exists('GiglogAdmin_Venue') ) {
* so this constructor can be used to construct the object
* directly from the database row.
*/
- public function __construct($attrs)
+ public function __construct(object $attrs)
{
$this->id = isset($attrs->id) ? $attrs->id : NULL;
- $this->name = isset($attrs->wpgvenue_name) ? $attrs->wpgvenue_name : NULL;
- $this->city = isset($attrs->wpgvenue_city) ? $attrs->wpgvenue_city : NULL;
+
+ if (isset($attrs->wpgvenue_name, $attrs->wpgvenue_city)) {
+ $this->name = $attrs->wpgvenue_name;
+ $this->city = $attrs->wpgvenue_city;
+ }
+ else {
+ error_log('Trying to construct a Venue without a name or a city');
+ wp_die();
+ }
+
$this->address = isset($attrs->wpgvenue_address) ? $attrs->wpgvenue_address : NULL;
$this->webpage = isset($attrs->wpgvenue_webpage) ? $attrs->wpgvenue_webpage : NULL;
}
@@ -108,8 +124,7 @@ if ( !class_exists('GiglogAdmin_Venue') ) {
static function venues_in_city(string $city): array
{
global $wpdb;
- $q = $wpdb->prepare(
- "select id, wpgvenue_name from wpg_venues where wpgvenue_city=%s", $city);
+ $q = $wpdb->prepare("select * from wpg_venues where wpgvenue_city=%s", $city);
$results = $wpdb->get_results($q);
return array_map(function ($r) { return new GiglogAdmin_Venue($r); }, $results);