dozent_html_table( $table_id,  $data_args = array(),  $raw_data = null,  $echo = true )


Source

File: includes/template-functions.php

	function dozent_html_table( $table_id, $data_args = [], $raw_data = null, $echo = true ) {

		$rows = array();

		$columns = dozent_array_get( 'columns', $data_args );

		/**
		 * Filter Dozent Table Columns from the function dozent_html_table()
		 *
		 * Filter Name "dozent_html_table_{$table_id}_columns"
		 *
		 * @since DozentLMS 1.0.0
		 *
		 * @see dozent_html_table();
		 *
		 * @param  string  $table_id  Given Table ID
		 * @param  array  $columns  Columns
		 * @param  array  $data_args  Table arguments, AKA options
		 * @param  array  $raw_data  Table raw data
		 */

		$columns = apply_filters( "dozent_html_table_columns", $columns, $table_id, $data_args, $raw_data );

		/**
		 * Filter Dozent Table Columns from the function dozent_html_table()
		 *
		 * Filter Name "dozent_html_table_{$table_id}_columns"
		 *
		 * @since DozentLMS 1.0.0
		 *
		 * @see dozent_html_table();
		 *
		 * @param  array  $columns  Columns
		 * @param  array  $data_args  Table arguments, AKA options
		 * @param  array  $raw_data  Table raw data
		 */

		$columns = apply_filters( "dozent_html_table_{$table_id}_columns", $columns, $data_args, $raw_data );

		//Table Header
		$thead = "";
		foreach ( $columns as $cell ) {
			$cells[] = "<th> {$cell} </th>";
		}
		$thead = "<thead> <tr>" . implode( '', $cells ) . "</tr> </thead>";


		//Rows
		foreach ( $raw_data as $row_data ) {
			$row_data = (array) $row_data;

			$cells = array();

			//Column
			foreach ( $columns as $column => $cell ) {

				$cell_data = dozent_array_get( $column, $row_data );

				/**
				 * Filter dozent_html_table() cell data
				 *
				 * Filter Name "dozent_html_table_{$table_id}_column"
				 *
				 * @since DozentLMS 1.0.0
				 *
				 * @param  string  $table_id  Given Table ID
				 * @param  string  $cell_data  Table Cell Data
				 * @param  string  $column  Column Name
				 * @param  array  $row_data  Current Row Data
				 */

				$cell_data = apply_filters( "dozent_html_table_{$table_id}_column", $cell_data, $column, $row_data );

				/**
				 * Filter dozent_html_table() cell data
				 *
				 * Filter Name "dozent_html_table_{$table_id}_column_{$column}"
				 *
				 * @since DozentLMS 1.0.0
				 *
				 * @param  string  $table_id  Given Table ID
				 * @param  string  $cell_data  Table Cell Data
				 * @param  array  $row_data  Current Row Data
				 */

				$cell_data = apply_filters( "dozent_html_table_{$table_id}_column_{$column}", $cell_data, $row_data );

				$cells[] = "<td data-label='{$cell}' class='column-{$column}'> {$cell_data} </td>";
			}


			$rows[] = "<tr>" . implode( '', $cells ) . "</tr>";
		}

		$css_class = "";
		if ( ! empty( $data_args['class'] ) ) {
			$table_class = $data_args['class'];
			$css_class   = is_array( $table_class ) ? implode( ' ', $table_class ) : $table_class;
		}

		$output = "<table id='{$table_id}' class='{$css_class}' > {$thead} " . implode( '', $rows ) . "</table>";


		/**
		 * Filter Dozent Table HTML output returns by function dozent_html_table()
		 *
		 * Filter Name "dozent_html_table"
		 *
		 * @since DozentLMS 1.0.0
		 *
		 * @see dozent_html_table();
		 *
		 * @param  string  $output  HTML Output
		 * @param  string  $table_id  Table ID
		 * @param  array  $data_args  Table arguments, AKA options
		 * @param  array  $raw_data  Table raw data
		 */

		$output = apply_filters( "dozent_html_table", $output, $table_id, $data_args, $raw_data );

		/**
		 * Filter Dozent Table HTML output returns by function dozent_html_table()
		 *
		 * Filter Name "dozent_html_table_{$table_id}"
		 *
		 * @since DozentLMS 1.0.0
		 *
		 * @see dozent_html_table();
		 *
		 * @param  string  $output  HTML Output
		 * @param  array  $data_args  Table arguments, AKA options
		 * @param  array  $raw_data  Table raw data
		 */

		$output = apply_filters( "dozent_html_table_{$table_id}", $output, $data_args, $raw_data );

		if ( $echo ) {
			echo $output;
		}

		return $output;
	}