summaryrefslogtreecommitdiffstats
path: root/includes
diff options
context:
space:
mode:
authorAndreaChirulescu <andrea.chirulescu@gmail.com>2021-05-09 21:58:23 +0200
committerAndreaChirulescu <andrea.chirulescu@gmail.com>2021-05-09 21:58:23 +0200
commit11570d3e87707396674bdf5179df48c641bb154d (patch)
tree5c4677689569dbece70de222d1869b4049698f6d /includes
parentcfc0341c66e5c24ee4c1b8a8e53afac99587244b (diff)
parent142ff436282844677b8b4e7d8ececd44440ec96d (diff)
downloadgigologadmin-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')
-rw-r--r--includes/admin/helpfiles/instr_photog.php2
-rw-r--r--includes/admin/helpfiles/instr_reviewers.php2
-rw-r--r--includes/admin/helpfiles/instrunctions.php2
-rw-r--r--includes/admin/register_db_tables.php5
-rw-r--r--includes/admin/views/giglog_admin_page.php48
-rw-r--r--includes/admin/views/giglog_import_gigs.php40
-rw-r--r--includes/band.php11
-rw-r--r--includes/concert.php53
-rw-r--r--includes/concertlogs.php4
-rw-r--r--includes/public/shortcodes/giglog_bands.php4
-rw-r--r--includes/public/shortcodes/giglog_display_unprocessed.php6
-rw-r--r--includes/public/shortcodes/giglog_photographers.php16
-rw-r--r--includes/public/shortcodes/giglog_process_files.php2
-rw-r--r--includes/venue.php40
14 files changed, 148 insertions, 87 deletions
diff --git a/includes/admin/helpfiles/instr_photog.php b/includes/admin/helpfiles/instr_photog.php
index 0750557..f661c5f 100644
--- a/includes/admin/helpfiles/instr_photog.php
+++ b/includes/admin/helpfiles/instr_photog.php
@@ -13,7 +13,7 @@ if ( !class_exists( 'Instructions_Photogs' ) ) {
- static function render_instr_photo_html() {
+ static function render_instr_photo_html(): void {
diff --git a/includes/admin/helpfiles/instr_reviewers.php b/includes/admin/helpfiles/instr_reviewers.php
index e00a432..3632980 100644
--- a/includes/admin/helpfiles/instr_reviewers.php
+++ b/includes/admin/helpfiles/instr_reviewers.php
@@ -9,7 +9,7 @@ if ( !class_exists( 'Instructions_Reviewers' ) ) {
class Instructions_Reviewers {
- static function render_instr_rev_html() {
+ static function render_instr_rev_html(): void {
?>
diff --git a/includes/admin/helpfiles/instrunctions.php b/includes/admin/helpfiles/instrunctions.php
index 49b77fe..b9c4d89 100644
--- a/includes/admin/helpfiles/instrunctions.php
+++ b/includes/admin/helpfiles/instrunctions.php
@@ -9,7 +9,7 @@ if ( !class_exists( 'Instructions_Page' ) ) {
class Instructions_Page {
- static function render_instr_html() {
+ static function render_instr_html(): void {
?>
diff --git a/includes/admin/register_db_tables.php b/includes/admin/register_db_tables.php
index 947be22..11223b3 100644
--- a/includes/admin/register_db_tables.php
+++ b/includes/admin/register_db_tables.php
@@ -5,7 +5,7 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
if (!function_exists('giglogadmin_populate_countries')) {
- function giglogadmin_populate_countries()
+ function giglogadmin_populate_countries(): void
{
global $wpdb;
$wpdb->query(
@@ -254,6 +254,9 @@ if (!function_exists('giglogadmin_populate_countries')) {
if ( !function_exists( "giglog_register_db_tables") )
{
+ /**
+ * @return void
+ */
function giglog_register_db_tables()
{
$db_version = get_option('giglogadmin_db_version');
diff --git a/includes/admin/views/giglog_admin_page.php b/includes/admin/views/giglog_admin_page.php
index 3482ae2..9d9d759 100644
--- a/includes/admin/views/giglog_admin_page.php
+++ b/includes/admin/views/giglog_admin_page.php
@@ -9,7 +9,7 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) {
require_once __DIR__ . '/../../venue.php';
class GiglogAdmin_AdminPage {
- static function render_html() {
+ static function render_html(): void {
?>
<div class="wrap">
<h1>Giglog Admin</h1>
@@ -36,13 +36,17 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) {
echo(GiglogAdmin_AdminPage::editforms()); //not sure why it doesn't show without the echo?
}
- static function get_allvenues($invenue)
+ static function get_venue_selector( ?GiglogAdmin_Venue $invenue ): string
{
$select = '<select name="selectvenueadmin">';
$select .= '<option value="">Please Select..</option>';
foreach ( GiglogAdmin_Venue::all_venues() AS $venue ) {
- if($invenue==$venue ->id() ) $select .= '<option value="' . $venue -> id(). '" selected="selected">'.$venue->name();
- else $select .= '<option value="' . $venue->id() . '">'. $venue->name();
+ if($invenue && $invenue->id() == $venue->id() ) {
+ $select .= '<option value="' . $venue->id(). '" selected="selected">'.$venue->name();
+ }
+ else {
+ $select .= '<option value="' . $venue->id() . '">'. $venue->name();
+ }
$select .='</option>';
}
$select .= '</select>';
@@ -50,7 +54,7 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) {
}
- static function get_user($cid, $ctype)
+ static function get_user( ?int $cid, string $ctype): string
{
$hf_user = wp_get_current_user();
$hf_username = $hf_user->user_login;
@@ -75,7 +79,7 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) {
}
- static function get_filters()
+ static function get_filters(): string
{
$cities = array_merge(["ALL"], GiglogAdmin_Venue::all_cities());
$cty = filter_input( INPUT_POST, 'selectcity', FILTER_SANITIZE_SPECIAL_CHARS );
@@ -107,9 +111,9 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) {
|| $venue_list[0];
$select .= '<select name="selectvenue">';
- foreach ( $venue_list AS $venue ) {
- //below line returns an erorr which I haven't really figured out yet But filtering works. It doesn't keep the venue selected in the dropdown
- $select .= '<option value="' . $venue[0] . '"' . selected($venue[0], $selected_venue) . '>';
+
+ foreach ( $venue_list as $venue ) {
+ $select .= '<option value="' . $venue[0] . '"' . selected($venue, $selected_venue) . '>';
$select .= $venue[1] . '</option>';
}
$select .= '</select>';
@@ -125,13 +129,13 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) {
return $select;
}
- static function editforms()
+ static function editforms(): string
{
$cid = filter_input(INPUT_POST, "cid");
$editing = filter_input(INPUT_POST, "edit") == "EDIT";
if ($editing && !empty($cid)) //A bit overdoing with the checks if concert ID is empty both here and in find_cid. But based on that, things are NULL or not. Better ideas?
- $c = GiglogAdmin_Concert::find_cid($cid);
+ $c = GiglogAdmin_Concert::get($cid);
else
$c = new GiglogAdmin_Concert();
@@ -140,7 +144,7 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) {
.'<div class="concertitems"><strong>CONCERT DETAILS</strong><br><br><fieldset>'
.'<input type="hidden" name="pid" value="' .$c->id(). '" />'
.'<label for="cname">Concert Name:</label><textarea id="cname" name="cname" value="'.$c->cname().'">'.$c->cname().'</textarea><br>'
- .'<label for="venue">Venue:</label>'.GiglogAdmin_AdminPage::get_allvenues($c->venue()).'<br>'
+ .'<label for="venue">Venue:</label>' . GiglogAdmin_AdminPage::get_venue_selector($c->venue()) . '<br>'
.'<label for="cdate">Date:</label><input type="date" id="cdate" name="cdate" value="'.$c->cdate().'"><br>'
.'<label for="ticket">Tickets:</label><input type="text" id="ticket" name="ticket" value="'.$c->tickets().'"><br>'
.'<label for="eventurl">Event link:</label><input type="text" id="eventurl" name="eventurl" value="'.$c->eventlink().'"><br>'
@@ -168,7 +172,7 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) {
return $content;
}
- static function adminactions($concert_id)
+ static function adminactions( int $concert_id ) : string
{
global $wpdb;
$query = "SELECT id,wpgs_name from wpg_pressstatus" ;
@@ -193,7 +197,10 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) {
}
//function to calculate if the concert has been added in the past 10 days or before that and show a green NEW for the newest rows
- static function getpublishstatus($concert_id)
+ /**
+ * @return null|string
+ */
+ static function getpublishstatus(int $concert_id)
{
global $wpdb;
$date1 = new DateTime("now");
@@ -210,11 +217,11 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) {
}
- static function get_concerts()
+ static function get_concerts(): string
{
$hf_user = wp_get_current_user();
$hf_username = $hf_user->user_login;
- $roles = ( array ) $hf_user->roles;
+ $roles = $hf_user->roles;
global $wpdb;
$content = '<table class="assignit">';
@@ -293,6 +300,9 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) {
}
+ /**
+ * @return void
+ */
static function update()
{
global $wpdb;
@@ -372,7 +382,7 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) {
}
}
- static function assignconcert($p1, $c)
+ static function assignconcert($p1, $c): void
{
global $wpdb;
@@ -393,7 +403,7 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) {
wp_mail( $to, $subject, $body, $headers );
}
- static function unassignconcert($p1, $c)
+ static function unassignconcert($p1, $c): void
{
global $wpdb;
@@ -414,7 +424,7 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) {
wp_mail( $to, $subject, $body, $headers );
}
- static function returnuser($p1, $c)
+ static function returnuser(string $p1, ?int $c): string
{
global $wpdb;
$hf_user = wp_get_current_user();
diff --git a/includes/admin/views/giglog_import_gigs.php b/includes/admin/views/giglog_import_gigs.php
index 053f505..a8daa3f 100644
--- a/includes/admin/views/giglog_import_gigs.php
+++ b/includes/admin/views/giglog_import_gigs.php
@@ -12,7 +12,7 @@ if ( !class_exists( 'GiglogAdmin_ImportGigsPage' ) ) {
require_once __DIR__ . '/../../venue.php';
class GiglogAdmin_ImportGigsPage {
- static function render_html() {
+ static function render_html(): void {
?>
<div class="wrap">
<h1>Import gigs</h1>
@@ -27,7 +27,7 @@ if ( !class_exists( 'GiglogAdmin_ImportGigsPage' ) ) {
<?php
}
- static function submit_form() {
+ static function submit_form(): void {
if ('POST' === $_SERVER['REQUEST_METHOD'] && current_user_can('upload_files') && !empty($_FILES['giglog_import_file']['tmp_name'])) {
$nonce = $_POST['giglog_import_nonce'];
$valid_nonce = isset($nonce) && wp_verify_nonce($nonce);
@@ -42,14 +42,18 @@ if ( !class_exists( 'GiglogAdmin_ImportGigsPage' ) ) {
* tab character:
*
* 1. Concertname
- * 2. Venuename
+ * 2. Venuename or numeric venue id
* 3. Concert date
* 4. Ticket link
* 5. Event info link
*
* Empty lines are ignored.
+ *
+ * @return void
+ *
+ * @param ArrayAccess|array $file
*/
- static function process_upload($file) {
+ static function process_upload(array $file): void {
$newconcert= [];
$fo = new SplFileObject($file['tmp_name']);
@@ -61,31 +65,21 @@ if ( !class_exists( 'GiglogAdmin_ImportGigsPage' ) ) {
}
$resultArray = explode("\t", $line);
- $cname = trim($resultArray[0]);
+ $cname = trim($resultArray[0]);
$venue = trim($resultArray[1]);
- $condate = date('Y-m-d', strtotime($resultArray[2]));
- $ticketlink = trim($resultArray[3]);
- $eventlink = trim($resultArray[4]);
- //first item in the row should be concert name $resultArray[0]; second should be venue $resultArray[1]; third should be concert date $resultArray[2];
- //fourth item is ticketlink $resultArray[3]; fifth item is eventlink $resultArray[4];
-
-
- if (is_numeric($venue))
- $newconcert[1] = $venue;
+ if (is_numeric($venue)) {
+ $venue = GiglogAdmin_Venue::get($venue);
+ }
else {
- $v = GiglogAdmin_Venue::find_or_create($venue,'Oslo'); //phase 666 of the project should maybe consider both city and band country when creating concerts/importing files
- $newconcert[1] = $v->id();
+ $venue = GiglogAdmin_Venue::find_or_create($venue,'Oslo');
}
- //not sure how to check dates, hopefully manual verification of files will take care of it
+ $condate = date('Y-m-d', strtotime($resultArray[2]));
+ $ticketlink = trim($resultArray[3]);
+ $eventlink = trim($resultArray[4]);
- GiglogAdmin_Concert::create(
- $cname,
- $newconcert[1],
- $condate,
- $ticketlink,
- $eventlink);
+ GiglogAdmin_Concert::create($cname, $venue->id(), $condate, $ticketlink, $eventlink);
}
}
}
diff --git a/includes/band.php b/includes/band.php
index 14daa18..3460acb 100644
--- a/includes/band.php
+++ b/includes/band.php
@@ -25,7 +25,7 @@ if ( !class_exists('GiglogAdmin_Band') ) {
$this->country = isset($attrs->wpgband_country) ? $attrs->wpgband_country : 'NO';
}
- static function create($bandname, $country = 'NO')
+ static function create($bandname, $country = 'NO'): self
{
$band = GiglogAdmin_Band::find($bandname, $country);
@@ -46,7 +46,7 @@ if ( !class_exists('GiglogAdmin_Band') ) {
return $band;
}
- static function find($name, $country)
+ static function find($name, $country): ?self
{
global $wpdb;
@@ -83,6 +83,11 @@ if ( !class_exists('GiglogAdmin_Band') ) {
return ($results);
}
+ /**
+ * @return array|string
+ *
+ * @psalm-return array{0: mixed, 1: mixed}|string
+ */
static function get_band($bid)
{
global $wpdb;
@@ -116,7 +121,7 @@ if ( !class_exists('GiglogAdmin_Band') ) {
return ($wpdb->last_error);
}
- public function save()
+ public function save(): void
{
global $wpdb;
diff --git a/includes/concert.php b/includes/concert.php
index d95934e..e3c32e8 100644
--- a/includes/concert.php
+++ b/includes/concert.php
@@ -25,33 +25,49 @@ if ( !class_exists('GiglogAdmin_Concert') ) {
{
$this->id = isset($attrs->id) ? $attrs->id : NULL;
$this->cname = isset($attrs->wpgconcert_name) ? $attrs->wpgconcert_name : NULL;
- $this->venue = isset($attrs->venue) ? $attrs->venue : NULL;
$this->cdate = isset($attrs->wpgconcert_date) ? $attrs->wpgconcert_date : NULL;
$this->tickets = isset($attrs->wpgconcert_tickets) ? $attrs->wpgconcert_tickets : NULL;
$this->eventlink = isset($attrs->wpgconcert_event) ? $attrs->wpgconcert_event : NULL;
+
+
+ if ( isset( $attrs->venue ) ) {
+ if (isset($attrs->wpgvenue_name) && isset($attrs->wpgvenue_city)) {
+ $venue_attrs = (object) [
+ "id" => $attrs->venue,
+ "wpgvenue_name" => $attrs->wpgvenue_name,
+ "wpgvenue_city" => $attrs->wpgvenue_city,
+ ];
+
+ $this->venue = new GiglogAdmin_Venue($venue_attrs);
+ }
+ else {
+ $this->venue = GiglogAdmin_Venue::get($attrs->venue);
+ }
+ }
}
- static function find_cid($id)
+ /**
+ * Get concert with given id.
+ *
+ * @param int $id.
+ * @return null|self.
+ */
+ static function get( int $id ) : ?self
{
global $wpdb;
- if(!empty($id))
- {
- $csql = 'SELECT * FROM wpg_concerts WHERE id="' . $id . '"';
- $results = $wpdb->get_results($csql);
- if ($results)
- {
- return new GiglogAdmin_Concert($results[0]);
- }
- }
- else
- {
- return new GiglogAdmin_Concert();
- }
+ $query = 'SELECT wpg_concerts.*, wpg_venues.wpgvenue_name, wpg_venues.wpgvenue_city '
+ . 'FROM wpg_concerts '
+ . 'LEFT JOIN wpg_venues ON wpg_concerts.venue = wpg_venues.id '
+ . 'WHERE ' . $wpdb->prepare('wpg_concerts.id = %d', $id);
+
+ $results = $wpdb->get_results($query);
+
+ return $results ? new GiglogAdmin_Concert($results[0]) : NULL;
}
- public static function create($name, $venue, $date, $ticketlink, $eventlink)
+ public static function create(string $name, $venue, string $date, string $ticketlink, string $eventlink): ?self
{
if ( GiglogAdmin_Concert::find($name, $venue, $date) ) {
error_log( 'DUPLICATE ROW detected: '
@@ -151,18 +167,17 @@ if ( !class_exists('GiglogAdmin_Concert') ) {
. ' and venue = ' . $venue
. ' and wpgconcert_date ="' . $date . '"';
- error_log(__CLASS__ . '::' . __FUNCTION__ . ": {$sql}");
return $wpdb->get_results($sql);
}
- public function save()
+ public function save(): void
{
global $wpdb;
$wpdb->insert('wpg_concerts', array(
'id' => '',
'wpgconcert_name' => $this->cname,
- 'venue' => $this->venue,
+ 'venue' => $this->venue->id(),
'wpgconcert_date' => $this->cdate,
'wpgconcert_tickets' => $this->tickets,
'wpgconcert_event' => $this->eventlink
diff --git a/includes/concertlogs.php b/includes/concertlogs.php
index 409a454..3b8083a 100644
--- a/includes/concertlogs.php
+++ b/includes/concertlogs.php
@@ -12,8 +12,10 @@ if ( !class_exists( 'GiglogAdmin_Concertlogs' ) )
/**
* Adds a default entry for the given concert id in the
* concert logs table.
+ *
+ * @return void
*/
- public static function add($concert_id)
+ public static function add($concert_id): void
{
global $wpdb;
diff --git a/includes/public/shortcodes/giglog_bands.php b/includes/public/shortcodes/giglog_bands.php
index 78fd72b..e4fe71d 100644
--- a/includes/public/shortcodes/giglog_bands.php
+++ b/includes/public/shortcodes/giglog_bands.php
@@ -10,7 +10,7 @@
* builds the table with concerts
*/
-function giglogadmin_getfilters()
+function giglogadmin_getfilters(): string
{
global $wpdb;
@@ -59,7 +59,7 @@ function giglogadmin_getfilters()
}
-function giglogadmin_getconcerts()
+function giglogadmin_getconcerts(): string
{
global $wpdb;
// Shortcodes RETURN content, so store in a variable to return
diff --git a/includes/public/shortcodes/giglog_display_unprocessed.php b/includes/public/shortcodes/giglog_display_unprocessed.php
index aa3596c..90ef69f 100644
--- a/includes/public/shortcodes/giglog_display_unprocessed.php
+++ b/includes/public/shortcodes/giglog_display_unprocessed.php
@@ -16,7 +16,7 @@
* gone through the processing process - aka fetching each line and
* transforming it into a concert line
*/
-function giglogadmin_getunprocessed()
+function giglogadmin_getunprocessed(): string
{
global $wpdb;
@@ -42,7 +42,7 @@ function giglogadmin_getunprocessed()
* venue exists. If they don't, they get created, if they do, their ID from
* their table is fetchd and used in concerts table
*/
-function giglogadmin_insertconcerts()
+function giglogadmin_insertconcerts(): string
{
global $wpdb;
$concertlist = '<p>Inserted the following:</p>';
@@ -128,7 +128,7 @@ function giglogadmin_insertconcerts()
return $concertlist;
}
-function giglogadmin_display_unprocessed() {
+function giglogadmin_display_unprocessed(): string {
$output = giglogadmin_getunprocessed();
$output .= '<form method="POST" action=""><input type="submit" name="ProcessConcerts" value="ProcessConcerts"/></form>';
diff --git a/includes/public/shortcodes/giglog_photographers.php b/includes/public/shortcodes/giglog_photographers.php
index 500445a..829c53e 100644
--- a/includes/public/shortcodes/giglog_photographers.php
+++ b/includes/public/shortcodes/giglog_photographers.php
@@ -10,7 +10,7 @@
* Admin users also control concert statuses here
*/
-function giglogadmin_assignconcert($p1, $c)
+function giglogadmin_assignconcert($p1, $c): void
{
global $wpdb;
@@ -40,7 +40,7 @@ function giglogadmin_assignconcert($p1, $c)
}
-function giglogadmin_unassignconcert($p1, $c)
+function giglogadmin_unassignconcert($p1, $c): void
{
global $wpdb;
@@ -71,6 +71,9 @@ function giglogadmin_unassignconcert($p1, $c)
}
+/**
+ * @return null|string
+ */
function giglogadmin_getpublishstatus ($c)
{
global $wpdb;
@@ -88,6 +91,9 @@ function giglogadmin_getpublishstatus ($c)
}
+/**
+ * @return null|string
+ */
function giglogadmin_returnuser($p1, $c)
{
global $wpdb;
@@ -164,7 +170,7 @@ function giglogadmin_returnuser($p1, $c)
}
-function giglogadmin_getfiltersphotog() {
+function giglogadmin_getfiltersphotog(): string {
global $wpdb;
//echo (var_dump($_POST["selectvenue"]));
@@ -211,7 +217,7 @@ function giglogadmin_getfiltersphotog() {
}
-function giglogadmin_getconcertsphotog ( ) {
+function giglogadmin_getconcertsphotog ( ): string {
$hf_user = wp_get_current_user();
$hf_username = $hf_user->user_login;
$roles = ( array ) $hf_user->roles;
@@ -370,7 +376,7 @@ function giglogadmin_getconcertsphotog ( ) {
return $content;
}
-function giglogadmin_photographers()
+function giglogadmin_photographers(): string
{
$output = giglogadmin_getfiltersphotog();
$output .= giglogadmin_getconcertsphotog();
diff --git a/includes/public/shortcodes/giglog_process_files.php b/includes/public/shortcodes/giglog_process_files.php
index 9dc2ec0..9443cda 100644
--- a/includes/public/shortcodes/giglog_process_files.php
+++ b/includes/public/shortcodes/giglog_process_files.php
@@ -9,7 +9,7 @@
* Band Venue Date TicketLink Eventlink. The form is at the end of this snippet
*/
-function giglogadmin_upload_files() {
+function giglogadmin_upload_files(): string {
global $wpdb;
$output = "";
$dir = wp_upload_dir()['basedir'].'/concertlists/'; //the basedir is from file uploader plugin, namely the uploads folder in which I created a concertlist folder
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;