summaryrefslogtreecommitdiffstats
path: root/includes/band.php
diff options
context:
space:
mode:
authorAndreaChirulescu <andrea.chirulescu@gmail.com>2021-04-14 22:42:38 +0200
committerAndreaChirulescu <andrea.chirulescu@gmail.com>2021-04-14 22:42:38 +0200
commit02caa8be1541d11a65dc00cdea08d1b0bc932ba5 (patch)
tree42cfcdc6a1569b0ee251a8653cb091aa9875004a /includes/band.php
parent558544fcef3335216d225bb587129a424db8d7af (diff)
downloadgigologadmin-02caa8be1541d11a65dc00cdea08d1b0bc932ba5.tar.gz
gigologadmin-02caa8be1541d11a65dc00cdea08d1b0bc932ba5.tar.bz2
gigologadmin-02caa8be1541d11a65dc00cdea08d1b0bc932ba5.zip
Got rid of find or create for concert and band
Refactored band
Diffstat (limited to 'includes/band.php')
-rw-r--r--includes/band.php110
1 files changed, 96 insertions, 14 deletions
diff --git a/includes/band.php b/includes/band.php
index f631b08..ad5ce28 100644
--- a/includes/band.php
+++ b/includes/band.php
@@ -8,29 +8,52 @@
if ( !class_exists('GiglogAdmin_Band') ) {
class GiglogAdmin_Band
{
- static function create($name, $country)
- {
- global $wpdb;
- if (empty($country)) $country = 'NO';
- $wpdb->insert('wpg_bands', array(
- 'id' => '',
- 'wpgband_name' => $name,
- 'wpgband_country' => $country
- ));
+ private $id;
+ private $bandname;
+ private $country;
- return $wpdb->insert_id;
+
+ public function __construct($attrs = [])
+ {
+ $this->id = isset($attrs->id) ? $attrs->id : NULL;
+ $this->bandname = isset($attrs->bandname) ? $attrs->bandname : NULL;
+ $this->country = isset($attrs->country) ? $attrs->country : 'NO';
}
- static function find_or_create($name, $country)
+ static function create($bandname, $country)
{
global $wpdb;
- if(empty($country)) $country = 'NO';
- $bandsql = 'SELECT id FROM wpg_bands WHERE upper(wpgband_name)="' . $name . '"';
+ 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);
+ }
+ else
+ {
+
+ $attrs->id = '';
+
+ $bid = new GiglogAdmin_Band($attrs);
+ $bid->save();
+
+
+ error_log( 'NEW BAND ADDED: '
+ . ' ID: ' . $bid -> id()
+ . ' BAND NAME ' . $bandname
+ . ', COUNTRY ' . $country);
+ }
+ return ($bid->id());
- return $results ? $results[0]->id : GiglogAdmin_Band::create($name, $country);
}
+
static function all_bands()
{
global $wpdb;
@@ -49,5 +72,64 @@ if ( !class_exists('GiglogAdmin_Band') ) {
return ($results);
}
+ static function get_band($bid)
+ {
+ global $wpdb;
+ if(!empty($bid))
+ {
+
+ $results = $wpdb->get_results('select wpgband_name as bname, wpgband_country as cname from wpg_bands where wpg_bands.id = '.$bid );
+
+ return array ($results[0]->bname,$results[0]->cname);
+ }
+ else return('');
+ }
+
+ static function update_band($bid,$bname,$bcountry)
+ {
+ global $wpdb;
+
+ $res = $wpdb->update('wpg_bands', array(
+ 'wpgband_name' => $bname,
+ 'wpgband_country' => $bcountry
+ ),
+ array('id' => $bid)
+ );
+
+ if ( !$res ) {
+ // exit( var_dump( $wpdb->last_query ) ); //for onscreen debugging when needed
+ error_log( __CLASS__ . '::' . __FUNCTION__ . ": {$wpdb->last_error}");
+ die;
+ }
+
+ return ($wpdb->last_error);
+ }
+
+ public function save()
+ {
+ global $wpdb;
+
+ $wpdb->insert('wpg_bands', array(
+ 'id' => '',
+ 'wpgband_name' => $this->bandname,
+ 'wpgband_country' => $this->country
+ ));
+
+ $this->id = $wpdb->insert_id;
+ }
+
+ public function id()
+ {
+ return $this->id;
+ }
+
+ public function bandname()
+ {
+ return $this->bandname;
+ }
+ public function country()
+ {
+ return $this->country;
+ }
}
}