Code Duplication    Length = 14-14 lines in 2 locations

caffeinated/admin/new/pricing/espresso_events_Pricing_Hooks.class.php 1 location

@@ 401-414 (lines=14) @@
398
        $old_datetimes = $old_datetimes[0] === '' ? array() : $old_datetimes;
399
        if (is_array($old_datetimes)) {
400
            $datetimes_to_delete = array_diff($old_datetimes, $saved_dtt_ids);
401
            foreach ($datetimes_to_delete as $id) {
402
                $id = absint($id);
403
                if (empty($id)) {
404
                    continue;
405
                }
406
                $dtt_to_remove = EE_Registry::instance()->load_model('Datetime')->get_one_by_ID($id);
407
                // remove tkt relationships.
408
                $related_tickets = $dtt_to_remove->get_many_related('Ticket');
409
                foreach ($related_tickets as $tkt) {
410
                    $dtt_to_remove->_remove_relation_to($tkt, 'Ticket');
411
                }
412
                $event->_remove_relation_to($id, 'Datetime');
413
                $dtt_to_remove->refresh_cache_of_related_objects();
414
            }
415
        }
416
        return $saved_dtt_objs;
417
    }

admin_pages/events/Events_Admin_Page.core.php 1 location

@@ 1348-1361 (lines=14) @@
1345
        // however now we need to handle permanently deleting tickets via the ui.  Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold.  However, it does allow for deleting tickets that have no tickets sold, in which case we want to get rid of permanently because there is no need to save in db.
1346
        $old_tickets = isset($old_tickets[0]) && $old_tickets[0] == '' ? array() : $old_tickets;
1347
        $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
1348
        foreach ($tickets_removed as $id) {
1349
            $id = absint($id);
1350
            // get the ticket for this id
1351
            $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id);
1352
            // need to get all the related datetimes on this ticket and remove from every single one of them (remember this process can ONLY kick off if there are NO tkts_sold)
1353
            $dtts = $tkt_to_remove->get_many_related('Datetime');
1354
            foreach ($dtts as $dtt) {
1355
                $tkt_to_remove->_remove_relation_to($dtt, 'Datetime');
1356
            }
1357
            // need to do the same for prices (except these prices can also be deleted because again, tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
1358
            $tkt_to_remove->delete_related_permanently('Price');
1359
            // finally let's delete this ticket (which should not be blocked at this point b/c we've removed all our relationships)
1360
            $tkt_to_remove->delete_permanently();
1361
        }
1362
        return array($saved_dtt, $saved_tickets);
1363
    }
1364