diff options
author | Harald Eilertsen <haraldei@anduin.net> | 2021-04-23 20:53:49 +0200 |
---|---|---|
committer | Harald Eilertsen <haraldei@anduin.net> | 2021-04-23 20:53:49 +0200 |
commit | c4446eb3cbe8f7074d565ad9b68192b2c5d222f4 (patch) | |
tree | 0266296afcca47e0fbb212a6bcdb84e9b23ba883 /includes | |
parent | ce5ed26cadf5f60e2b07d6a355f64d3357bf5397 (diff) | |
download | gigologadmin-c4446eb3cbe8f7074d565ad9b68192b2c5d222f4.tar.gz gigologadmin-c4446eb3cbe8f7074d565ad9b68192b2c5d222f4.tar.bz2 gigologadmin-c4446eb3cbe8f7074d565ad9b68192b2c5d222f4.zip |
Refactor Concert::create
Restructure the method a bit, drop the `c`prefix on variables, rename
the variable to hold the created concert, and use object notation to
pass the attributes to the constructor.
Also rename the method `get` to `find`, the only call site was the
`create` method. Drop the unnecessary method `check_duplicate`. Just use
`find` instead.
Diffstat (limited to 'includes')
-rw-r--r-- | includes/concert.php | 67 |
1 files changed, 27 insertions, 40 deletions
diff --git a/includes/concert.php b/includes/concert.php index 22fc13d..aff41ac 100644 --- a/includes/concert.php +++ b/includes/concert.php @@ -51,41 +51,36 @@ if ( !class_exists('GiglogAdmin_Concert') ) { } } - private static function check_duplicate($cname, $venue, $cdate, $ticketlink, $eventlink) + public static function create($name, $venue, $date, $ticketlink, $eventlink) { - global $wpdb; - - $cresults = GiglogAdmin_Concert::get($cname, $venue, $cdate); - if ($cresults) - return($cresults); - else - return ('new'); + if ( GiglogAdmin_Concert::find($name, $venue, $date) ) { + error_log( 'DUPLICATE ROW detected: ' + . ' CONCERT NAME ' . $name + . ', VENUE ID ' . $venue + . ', CONCERTDATE ' . $date); - } + return NULL; + } + else { + $concert = new GiglogAdmin_Concert( (object) [ + "wpgconcert_name" => $name, + "venue" => $venue, + "wpgconcert_date" => $date, + "wpgconcert_tickets" => $ticketlink, + "wpgconcert_event" => $eventlink, + ]); - public static function create($cname, $venue, $cdate, $ticketlink, $eventlink) - { - $c = GiglogAdmin_Concert::check_duplicate($cname, $venue, $cdate, $ticketlink, $eventlink); - if ($c=='new') - { - $attrs = new stdClass(); - $attrs->id = ''; - $attrs->wpgconcert_name = $cname; - $attrs->venue = $venue; - $attrs->wpgconcert_date = $cdate; - $attrs->wpgconcert_tickets = $ticketlink; - $attrs->wpgconcert_event = $eventlink; - $cid = new GiglogAdmin_Concert($attrs); - $cid->save(); + $concert->save(); error_log( 'NEW CONCERT ADDED: ' - . ' ID: ' . $cid -> id() - . ' CONCERT NAME ' . $cname - . ', VENUE ID ' . $venue - . ', CONCERTDATE ' . $cdate - . ', Ticket LINK ' . $ticketlink - . ', Event LINK ' . $eventlink); - GiglogAdmin_Concertlogs::add($cid->id()); + . ' ID: ' . $concert -> id() + . ' CONCERT NAME ' . $name + . ', VENUE ID ' . $venue + . ', CONCERTDATE ' . $date + . ', Ticket LINK ' . $ticketlink + . ', Event LINK ' . $eventlink); + + GiglogAdmin_Concertlogs::add( $concert->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,15 +91,7 @@ if ( !class_exists('GiglogAdmin_Concert') ) { VALUES (null, new.id, 1) */ - return $cid; - } - else - { - error_log( 'DUPLICATE ROW detected: ' - . ' CONCERT NAME ' . $cname - . ', VENUE ID ' . $venue - . ', CONCERTDATE ' . $cdate); - return NULL; + return $concert; } } @@ -155,7 +142,7 @@ if ( !class_exists('GiglogAdmin_Concert') ) { } - public static function get($cname, $venue, $date) + public static function find($cname, $venue, $date) { global $wpdb; |