/** * Ajax response to event occurrence being moved. * * TODO Prevent two occurrences from the same event * occuring on the same *date*. * * @ignore */ function eventorganiser_admin_calendar_edit_date() { $event_id = (int) $_POST['event_id']; $occurrence_id = (int) $_POST['occurrence_id']; $all_day = eo_is_all_day($event_id); if ('event' != get_post_type($event_id)) { echo json_encode(array('success' => false, 'data' => array('message' => __('Event not found', 'eventorganiser')))); exit; } $edittime = defined('EVENT_ORGANISER_BETA_FEATURES') && EVENT_ORGANISER_BETA_FEATURES; if (!$edittime) { echo json_encode(array('success' => false, 'data' => array('message' => __('Events are not editable via the admin calendar', 'eventorganiser')))); exit; } if (!check_ajax_referer('edit_events', false, false)) { echo json_encode(array('success' => false, 'data' => array('message' => __('Are you sure you want to do this?', 'eventorganiser')))); exit; } if (!current_user_can('edit_event', $event_id)) { echo json_encode(array('success' => false, 'data' => array('message' => __('You do not have permission to edit this event', 'eventorganiser')))); exit; } $tz = eo_get_blog_timezone(); $new_start = new DateTime($_POST['start'], $tz); $new_end = new DateTime($_POST['end'], $tz); $re = eventorganiser_move_occurrence($event_id, $occurrence_id, $new_start, $new_end); if (!is_wp_error($re)) { echo json_encode(array('success' => true)); exit; } else { echo json_encode(array('success' => false, 'data' => array('message' => sprintf(__('Event not created: %s', 'eventorganiser'), $re->get_error_message())))); exit; } }
/** * Currently the following case is not allowed: * - Changing the start date to a date where an occurrence already exists */ public function testMoveOccurrenceNotAllowed() { $event = array('start' => new DateTime('2014-08-11 18:48:00', eo_get_blog_timezone()), 'end' => new DateTime('2014-08-11 19:48:00', eo_get_blog_timezone()), 'schedule' => 'weekly', 'until' => new DateTime('2014-09-01 18:48:00', eo_get_blog_timezone())); $event_id = $this->factory->event->create($event); $occurrences = eo_get_the_occurrences_of($event_id); $occurrence_ids = array_keys($occurrences); $occurrence_id = $occurrence_ids[2]; //Check the start/end datetimes are as expected $this->assertEquals(array('start' => new DateTime('2014-08-25 18:48:00', eo_get_blog_timezone()), 'end' => new DateTime('2014-08-25 19:48:00', eo_get_blog_timezone())), $occurrences[$occurrence_id]); //Try to move to an 'occupied date' (even with different time) $new_start = new DateTime('2014-08-18 15:48:00', eo_get_blog_timezone()); $new_end = new DateTime('2014-08-18 16:48:00', eo_get_blog_timezone()); $response = eventorganiser_move_occurrence($event_id, $occurrence_id, $new_start, $new_end); $this->assertInstanceOf('WP_Error', $response); $this->assertEquals('events-cannot-share-date', $response->get_error_code()); }