diff options
author | AndreaChirulescu <andrea.chirulescu@gmail.com> | 2021-05-09 21:58:23 +0200 |
---|---|---|
committer | AndreaChirulescu <andrea.chirulescu@gmail.com> | 2021-05-09 21:58:23 +0200 |
commit | 11570d3e87707396674bdf5179df48c641bb154d (patch) | |
tree | 5c4677689569dbece70de222d1869b4049698f6d /includes/venue.php | |
parent | cfc0341c66e5c24ee4c1b8a8e53afac99587244b (diff) | |
parent | 142ff436282844677b8b4e7d8ececd44440ec96d (diff) | |
download | gigologadmin-11570d3e87707396674bdf5179df48c641bb154d.tar.gz gigologadmin-11570d3e87707396674bdf5179df48c641bb154d.tar.bz2 gigologadmin-11570d3e87707396674bdf5179df48c641bb154d.zip |
Tried to fix the psalm local changes done when I manually installed it
Diffstat (limited to 'includes/venue.php')
-rw-r--r-- | includes/venue.php | 40 |
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; |