diff options
author | AndreaChirulescu <andrea.chirulescu@gmail.com> | 2021-04-14 22:42:38 +0200 |
---|---|---|
committer | AndreaChirulescu <andrea.chirulescu@gmail.com> | 2021-04-14 22:42:38 +0200 |
commit | 02caa8be1541d11a65dc00cdea08d1b0bc932ba5 (patch) | |
tree | 42cfcdc6a1569b0ee251a8653cb091aa9875004a /includes/concert.php | |
parent | 558544fcef3335216d225bb587129a424db8d7af (diff) | |
download | gigologadmin-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/concert.php')
-rw-r--r-- | includes/concert.php | 81 |
1 files changed, 44 insertions, 37 deletions
diff --git a/includes/concert.php b/includes/concert.php index 89d28bd..7afedca 100644 --- a/includes/concert.php +++ b/includes/concert.php @@ -32,21 +32,6 @@ if ( !class_exists('GiglogAdmin_Concert') ) { } - static function find_or_create($band, $venue, $cdate, $ticketlink, $eventlink) - { - global $wpdb; - $cresults = GiglogAdmin_Concert::get($band, $venue, $cdate); - if ($cresults) { - error_log( 'DUPLICATE ROW detected: ' - . ' BAND ID ' . $band - . ', VENUE ID ' . $venue - . ', CONCERTDATE ' . $cdate); - } - else - return GiglogAdmin_Concert::create($band, $venue, $cdate, $ticketlink, $eventlink); - } - - static function find_cid($id) { global $wpdb; @@ -66,26 +51,39 @@ if ( !class_exists('GiglogAdmin_Concert') ) { } } - public static function create($band, $venue, $cdate, $ticketlink, $eventlink) + static function check_duplicate($band, $venue, $cdate, $ticketlink, $eventlink) { - $attrs = new stdClass(); - $attrs->id = ''; - $attrs->band = $band; - $attrs->venue = $venue; - $attrs->wpgconcert_date = $cdate; - $attrs->wpgconcert_tickets = $ticketlink; - $attrs->wpgconcert_event = $eventlink; - $cid = new GiglogAdmin_Concert($attrs); - $cid->save(); - - error_log( 'NEW CONCERT ADDED: ' - . ' ID: ' . $cid -> id() - . ' BAND ID ' . $band - . ', VENUE ID ' . $venue - . ', CONCERTDATE ' . $cdate - . ', Ticket LINK ' . $ticketlink - . ', Event LINK ' . $eventlink); - GiglogAdmin_Concertlogs::add($cid->id()); + global $wpdb; + + $cresults = GiglogAdmin_Concert::get($band, $venue, $cdate); + if ($cresults) + return($cresults); + else + return ('new'); + + } + public static function create($band, $venue, $cdate, $ticketlink, $eventlink) + { $c = GiglogAdmin_Concert::check_duplicate($band, $venue, $cdate, $ticketlink, $eventlink); + if ($c=='new') + { + $attrs = new stdClass(); + $attrs->id = ''; + $attrs->band = $band; + $attrs->venue = $venue; + $attrs->wpgconcert_date = $cdate; + $attrs->wpgconcert_tickets = $ticketlink; + $attrs->wpgconcert_event = $eventlink; + $cid = new GiglogAdmin_Concert($attrs); + $cid->save(); + + error_log( 'NEW CONCERT ADDED: ' + . ' ID: ' . $cid -> id() + . ' BAND ID ' . $band + . ', VENUE ID ' . $venue + . ', CONCERTDATE ' . $cdate + . ', Ticket LINK ' . $ticketlink + . ', Event LINK ' . $eventlink); + GiglogAdmin_Concertlogs::add($cid->id()); /*the last line can be replaced by a trigger CREATE TRIGGER `insertIntoPhotoLogs` AFTER INSERT ON `wpg_concerts` FOR EACH ROW INSERT INTO wpg_concertlogs ( @@ -96,11 +94,20 @@ if ( !class_exists('GiglogAdmin_Concert') ) { VALUES (null, new.id, 1) */ - return $cid; + return $cid; + } + else + { + error_log( 'DUPLICATE ROW detected: ' + . ' BAND ID ' . $band + . ', VENUE ID ' . $venue + . ', CONCERTDATE ' . $cdate); + return('dup'); + } } - public static function updatec($id, $band, $venue, $cdate, $ticketlink, $eventlink) + public static function update_concert($id, $band, $venue, $cdate, $ticketlink, $eventlink) { global $wpdb; @@ -120,7 +127,7 @@ if ( !class_exists('GiglogAdmin_Concert') ) { die; } - return ($wpdb->last_error); //not sure what to return here? + return ($wpdb->last_error); } public static function get($band, $venue, $date) |