public function create_job(JobParameters $job_parameters) { if (!\EE_Capabilities::instance()->current_user_can('ee_read_contacts', 'generating_report')) { throw new BatchRequestException(__('You do not have permission to view contacts', 'event_espresso')); } $filepath = $this->create_file_from_job_with_name($job_parameters->job_id(), __('contact-list-report.csv', 'event_espresso')); $job_parameters->add_extra_data('filepath', $filepath); $job_parameters->set_job_size($this->count_units_to_process()); //we should also set the header columns $csv_data_for_row = $this->get_csv_data(0, 1); \EEH_Export::write_data_array_to_csv($filepath, $csv_data_for_row, true); //if we actually processed a row there, record it if ($job_parameters->job_size()) { $job_parameters->mark_processed(1); } return new JobStepResponse($job_parameters, __('Contacts report started successfully...', 'event_espresso')); }
/** * Performs any necessary setup for starting the job. This is also a good * place to setup the $job_arguments which will be used for subsequent HTTP requests * when continue_job will be called * @param JobParameters $job_parameters * @throws BatchRequestException * @return JobStepResponse */ public function create_job(JobParameters $job_parameters) { $event_id = intval($job_parameters->request_datum('EVT_ID', '0')); if (!\EE_Capabilities::instance()->current_user_can('ee_read_registrations', 'generating_report')) { throw new BatchRequestException(__('You do not have permission to view registrations', 'event_espresso')); } $filepath = $this->create_file_from_job_with_name($job_parameters->job_id(), $this->get_filename_from_event($event_id)); $job_parameters->add_extra_data('filepath', $filepath); $question_data_for_columns = $this->_get_questions_for_report($event_id); $job_parameters->add_extra_data('questions_data', $question_data_for_columns); $job_parameters->set_job_size($this->count_units_to_process($event_id)); //we should also set the header columns $csv_data_for_row = $this->get_csv_data_for($event_id, 0, 1, $job_parameters->extra_datum('questions_data')); \EEH_Export::write_data_array_to_csv($filepath, $csv_data_for_row, true); //if we actually processed a row there, record it if ($job_parameters->job_size()) { $job_parameters->mark_processed(1); } return new JobStepResponse($job_parameters, __('Registrations report started successfully...', 'event_espresso')); }