diff options
author | AndreaChirulescu <andrea.chirulescu@gmail.com> | 2021-04-18 20:31:38 +0200 |
---|---|---|
committer | AndreaChirulescu <andrea.chirulescu@gmail.com> | 2021-04-18 20:31:38 +0200 |
commit | 106ca5e5247d542b62efa9034ad2d0427cb6fc5c (patch) | |
tree | 02e655a92c252f5f50286725184464a35c370e0a /includes | |
parent | d4af42336c745bb743560370bbbfc39c350ad51c (diff) | |
parent | a851dd35b8ead5e4688062ff0c6e94d83133b006 (diff) | |
download | gigologadmin-106ca5e5247d542b62efa9034ad2d0427cb6fc5c.tar.gz gigologadmin-106ca5e5247d542b62efa9034ad2d0427cb6fc5c.tar.bz2 gigologadmin-106ca5e5247d542b62efa9034ad2d0427cb6fc5c.zip |
Merge branch 'dev' of https://code.volse.net/wordpress/plugins/gigologadmin.git into andreaschanges
Diffstat (limited to 'includes')
-rw-r--r-- | includes/admin/views/giglog_import_gigs.php | 6 | ||||
-rw-r--r-- | includes/band.php | 54 |
2 files changed, 33 insertions, 27 deletions
diff --git a/includes/admin/views/giglog_import_gigs.php b/includes/admin/views/giglog_import_gigs.php index ca1c7b8..17b1cbd 100644 --- a/includes/admin/views/giglog_import_gigs.php +++ b/includes/admin/views/giglog_import_gigs.php @@ -61,7 +61,7 @@ if ( !class_exists( 'GiglogAdmin_ImportGigsPage' ) ) { } $resultArray = explode("\t", $line); - $band = trim($resultArray[0]); + $bandname = trim($resultArray[0]); $venue = trim($resultArray[1]); $condate = date('Y-m-d', strtotime($resultArray[2])); $ticketlink = trim($resultArray[3]); @@ -69,7 +69,7 @@ if ( !class_exists( 'GiglogAdmin_ImportGigsPage' ) ) { //first item in the row should be band $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]; - $newconcert[0] = GiglogAdmin_Band::create($band,''); + $band = GiglogAdmin_Band::create($bandname); if (is_numeric($venue)) $newconcert[1] = $venue; @@ -81,7 +81,7 @@ if ( !class_exists( 'GiglogAdmin_ImportGigsPage' ) ) { //not sure how to check dates, hopefully manual verification of files will take care of it GiglogAdmin_Concert::create( - $newconcert[0], + $band->id(), $newconcert[1], $condate, $ticketlink, diff --git a/includes/band.php b/includes/band.php index ad5ce28..47b663c 100644 --- a/includes/band.php +++ b/includes/band.php @@ -20,37 +20,43 @@ if ( !class_exists('GiglogAdmin_Band') ) { $this->country = isset($attrs->country) ? $attrs->country : 'NO'; } - static function create($bandname, $country) + static function create($bandname, $country = 'NO') { - global $wpdb; - if (empty($country)) $country = 'NO'; - $bandsql = 'SELECT id FROM wpg_bands WHERE upper(wpgband_name)="' . $bandname . '" and wpgband_country = "'.$country.'"'; - $results = $wpdb->get_results($bandsql); - $attrs = new stdClass(); - $attrs->bandname = $bandname; - $attrs->country = $country; - - if ($results) - { - $attrs->id = $results[0]->id; - $bid = new GiglogAdmin_Band($attrs); + $band = GiglogAdmin_Band::find($bandname, $country); + + if ( ! $band ) { + $band = new GiglogAdmin_Band((object) [ + 'bandname' => $bandname, + 'country' => $country, + ]); + + $band->save(); + + error_log( 'NEW BAND ADDED: ' + . ' ID: ' . $band->id() + . ' BAND NAME ' . $band->bandname() + . ', COUNTRY ' . $band->country()); } - else - { - $attrs->id = ''; + return $band; + } + + static function find($name, $country) + { + global $wpdb; - $bid = new GiglogAdmin_Band($attrs); - $bid->save(); + $q = 'SELECT * FROM wpg_bands ' + . 'WHERE upper(wpgband_name)="' . $name + . '" and wpgband_country = "' . $country.'"'; + $results = $wpdb->get_results($q); - error_log( 'NEW BAND ADDED: ' - . ' ID: ' . $bid -> id() - . ' BAND NAME ' . $bandname - . ', COUNTRY ' . $country); + if ($results) { + return new GiglogAdmin_Band($results[0]); + } + else { + return NULL; } - return ($bid->id()); - } |