Code Duplication    Length = 17-20 lines in 2 locations

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

@@ 281-297 (lines=17) @@
278
279
		if ( is_array( $old_datetimes ) ) {
280
			$dtts_to_delete = array_diff( $old_datetimes, $saved_dtt_ids );
281
			foreach ( $dtts_to_delete as $id ) {
282
				$id = absint( $id );
283
				if ( empty( $id ) )
284
					continue;
285
286
				$dtt_to_remove = EE_Registry::instance()->load_model('Datetime')->get_one_by_ID($id);
287
288
				//remove tkt relationships.
289
				$related_tickets = $dtt_to_remove->get_many_related('Ticket');
290
				foreach ( $related_tickets as $tkt ) {
291
					$dtt_to_remove->_remove_relation_to($tkt, 'Ticket');
292
				}
293
294
				$evt_obj->_remove_relation_to( $id, 'Datetime' );
295
				$dtt_to_remove->refresh_cache_of_related_objects();
296
297
			}
298
		}
299
300
		return $saved_dtt_objs;

admin_pages/events/Events_Admin_Page.core.php 1 location

@@ 1147-1166 (lines=20) @@
1144
		$old_tickets = isset( $old_tickets[0] ) && $old_tickets[0] == '' ? array() : $old_tickets;
1145
		$tickets_removed = array_diff( $old_tickets, array_keys( $saved_tickets ) );
1146
1147
		foreach ( $tickets_removed as $id ) {
1148
			$id = absint( $id );
1149
1150
			//get the ticket for this id
1151
			$tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id);
1152
1153
			//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)
1154
			$dtts = $tkt_to_remove->get_many_related('Datetime');
1155
1156
			foreach( $dtts as $dtt ) {
1157
				$tkt_to_remove->_remove_relation_to($dtt, 'Datetime');
1158
			}
1159
1160
			//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))
1161
			$tkt_to_remove->delete_related_permanently('Price');
1162
1163
1164
			//finally let's delete this ticket (which should not be blocked at this point b/c we've removed all our relationships)
1165
			$tkt_to_remove->delete_permanently();
1166
		}
1167
		return array( $saved_dtt, $saved_tickets );
1168
	}
1169