ReportsGenerator::export()

Prepare the export data

Description

Source

File: bp-integrations/learndash/library/ReportsGenerator.php

	public function export()
	{
		$hash    = $this->hasArg('hash')? $this->args['hash'] : md5(microtime());
		$exports = get_transient($hash) ?: [];
		$columns = apply_filters('bp_ld_sync/export_report_column', $this->columns(), $this, $this->args);
		$data = apply_filters('bp_ld_sync/export_report_data', $this->getData(), $this, $this->args);

    	foreach ($data as $result) {
    		$data = [];

    		foreach (array_keys($columns) as $key) {
    			$data[$key] = $result[$key];
    		}

    		$exports[] = $data;
    	}

		set_transient($hash, $exports, HOUR_IN_SECONDS);
		set_transient("{$hash}_info", [
			'filename' => 'learndash-report-export-group-' . $this->args['group'] . '.csv',
			'columns' => $columns
		], HOUR_IN_SECONDS);

		wp_send_json_success([
			'page'     => $this->args['start'] / $this->args['length'] + 1,
			'total'    => $this->pager['total_pages'],
			'has_more' => $this->pager['total_pages'] > $this->args['start'] / $this->args['length'] + 1,
			'url'      => add_query_arg([
				'hash'   => $hash,
				'action' => 'download_bp_ld_reports',
			], admin_url('admin-ajax.php')),
			'hash'     => $hash
		]);
	}

Changelog

Changelog
Version Description
BuddyBoss 1.0.0 Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.