summaryrefslogtreecommitdiffstats
path: root/includes/band.php
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2021-04-15 21:29:26 +0200
committerHarald Eilertsen <haraldei@anduin.net>2021-04-15 21:29:26 +0200
commite59f12fd21af5489b8889aa4c3ab5a90a9b317a9 (patch)
tree160214bb992a2b5287996606f6a7daba681527f0 /includes/band.php
parentf8f01743b8b5256dda9e199f5d8e77ddb9eea278 (diff)
parent02caa8be1541d11a65dc00cdea08d1b0bc932ba5 (diff)
downloadgigologadmin-e59f12fd21af5489b8889aa4c3ab5a90a9b317a9.tar.gz
gigologadmin-e59f12fd21af5489b8889aa4c3ab5a90a9b317a9.tar.bz2
gigologadmin-e59f12fd21af5489b8889aa4c3ab5a90a9b317a9.zip
Merge remote-tracking branch 'andrea/andreaschanges' into dev
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;
+ }
}
}