summaryrefslogtreecommitdiffstats
path: root/includes/venue.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/venue.php')
-rw-r--r--includes/venue.php40
1 files changed, 33 insertions, 7 deletions
diff --git a/includes/venue.php b/includes/venue.php
index f6f46b2..f9f7e4f 100644
--- a/includes/venue.php
+++ b/includes/venue.php
@@ -19,7 +19,7 @@ if ( !class_exists('GiglogAdmin_Venue') ) {
* so this constructor can be used to construct the object
* directly from the database row.
*/
- private function __construct($attrs)
+ public function __construct($attrs)
{
$this->id = isset($attrs->id) ? $attrs->id : NULL;
$this->name = isset($attrs->wpgvenue_name) ? $attrs->wpgvenue_name : NULL;
@@ -28,7 +28,23 @@ if ( !class_exists('GiglogAdmin_Venue') ) {
$this->webpage = isset($attrs->wpgvenue_webpage) ? $attrs->wpgvenue_webpage : NULL;
}
- static function create($name, $city = 'Oslo')
+ /**
+ * Get venue by given id.
+ *
+ * @param int $id.
+ * @return null|self.
+ */
+ static function get(int $id) : ?self
+ {
+ global $wpdb;
+
+ $query = $wpdb->prepare('SELECT * from wpg_venues WHERE id = %d', $id);
+ $results = $wpdb->get_results($query);
+
+ return $results ? new GiglogAdmin_Venue($results[0]) : NULL;
+ }
+
+ static function create($name, $city = 'Oslo'): self
{
$venue = new GiglogAdmin_Venue((object) [
'wpgvenue_name' => $name,
@@ -43,7 +59,7 @@ if ( !class_exists('GiglogAdmin_Venue') ) {
return $venue;
}
- static function find_or_create($name, $city = 'Oslo')
+ static function find_or_create(string $name, string $city = 'Oslo'): self
{
global $wpdb;
$venuesql = 'SELECT * FROM wpg_venues WHERE upper(wpgvenue_name)=upper("' . $name . '")'.' and wpgvenue_city="'.$city.'"';
@@ -61,7 +77,7 @@ if ( !class_exists('GiglogAdmin_Venue') ) {
}
}
- static function all_cities()
+ static function all_cities(): array
{
global $wpdb;
$results = $wpdb->get_results('select distinct wpgvenue_city from wpg_venues');
@@ -69,7 +85,12 @@ if ( !class_exists('GiglogAdmin_Venue') ) {
return array_map(function ($r) { return $r->wpgvenue_city; }, $results);
}
- static function all_venues()
+ /**
+ * @return self[]
+ *
+ * @psalm-return array<array-key, self>
+ */
+ static function all_venues(): array
{
global $wpdb;
@@ -79,7 +100,12 @@ if ( !class_exists('GiglogAdmin_Venue') ) {
}
- static function venues_in_city($city)
+ /**
+ * @return self[]
+ *
+ * @psalm-return array<array-key, self>
+ */
+ static function venues_in_city(string $city): array
{
global $wpdb;
$q = $wpdb->prepare(
@@ -89,7 +115,7 @@ if ( !class_exists('GiglogAdmin_Venue') ) {
return array_map(function ($r) { return new GiglogAdmin_Venue($r); }, $results);
}
- public function save()
+ public function save(): void
{
global $wpdb;