MIDDAG for Moodle

generic_view extends bigquery_base_table_service

Abstract class for handling Google BigQuery operations, including schema definition, data retrieval, and integration with Google BigQuery APIs.

Table of Contents

Constants

DATASET  = ''
IDNUMBER  = ''
MODE_NULLABLE  = 'NULLABLE'
MODE_REPEATED  = 'REPEATED'
MODE_REQUIRED  = 'REQUIRED'
TABLE  = ''
TYPE_ARRAY  = 'ARRAY'
TYPE_BIGNUMERIC  = 'BIGNUMERIC'
TYPE_BOOL  = 'BOOL'
TYPE_BOOLEAN  = 'BOOLEAN'
TYPE_BYTES  = 'BYTES'
TYPE_DATE  = 'DATE'
TYPE_DATETIME  = 'DATETIME'
TYPE_FLOAT  = 'FLOAT'
TYPE_FLOAT64  = 'FLOAT64'
TYPE_GEOGRAPHY  = 'GEOGRAPHY'
TYPE_INT64  = 'INT64'
TYPE_INTEGER  = 'INTEGER'
TYPE_JSON  = 'JSON'
TYPE_NUMERIC  = 'NUMERIC'
TYPE_RECORD  = 'RECORD'
TYPE_STRING  = 'STRING'
TYPE_STRUCT  = 'STRUCT'
TYPE_TIME  = 'TIME'
TYPE_TIMESTAMP  = 'TIMESTAMP'

Properties

$idnumber  : mixed
$instances  : array<string|int, mixed>
$name  : string
$table  : string

Methods

__construct()  : mixed
Constructor method to initialize the object with table, name, and idnumber.
can_execute()  : bool
Determines if the current operation can be executed.
execute()  : null|bool
Executes the data preparation process for Google BigQuery, including table validation, data generation, and job creation, while handling errors and cleaning up temporary files.
foreignkeys()  : bool
Indicates whether foreign keys are present or enabled.
get_dataset()  : string
Retrieves the dataset name associated with the class.
get_field_type()  : string
Determines and returns the corresponding field type based on the provided type.
get_fields()  : array<string|int, mixed>
Retrieves and returns the fields associated with the current table.
get_fields_by_table()  : array<string|int, mixed>
Retrieves and returns the fields and their metadata for a given database table.
get_header()  : array<string|int, mixed>
Retrieves the header information associated with the current table.
get_header_by_table()  : array<string|int, mixed>
Retrieves and returns the header of a table as an array of column names.
get_idnumber()  : string
Retrieves the ID number associated with the object.
get_name()  : string
Get the name of the view.
get_options()  : array<string|int, mixed>
Retrieves and constructs a set of options including schema, primary key, and foreign key information.
get_table()  : string
Retrieves the table name associated with the object.
getInstance()  : static
Get an instance of the class for a specific table.
primarykey()  : bool|string
Get the table name associated with the class.
set_count_table_row()  : void
Updates and stores the row count of a specific database table in the configuration.
generate_data()  : array<string|int, mixed>
Generates and retrieves data from the database table associated with this instance.
get_filename()  : string
Generates a filename based on the class name, current timestamp, and given extension.
get_filepath()  : string
Retrieves the full file path for a given file extension.
get_schema()  : array<string|int, mixed>
Retrieves the schema of the current context.
save_to_csv()  : null|string
Saves the provided data to a CSV file with an optional header.
save_to_json()  : string
Saves the provided data to a JSON file.

Constants

Properties

Methods

__construct()

Constructor method to initialize the object with table, name, and idnumber.

public __construct([string $table = '' ][, string $name = '' ][, string $idnumber = '' ]) : mixed
Parameters
$table : string = ''

the table name, defaults to an empty string

$name : string = ''

the name, defaults to an empty string

$idnumber : string = ''

the identifier number for the object

can_execute()

Determines if the current operation can be executed.

public static can_execute() : bool
Return values
bool

returns true if the operation is permitted to execute, otherwise false

execute()

Executes the data preparation process for Google BigQuery, including table validation, data generation, and job creation, while handling errors and cleaning up temporary files.

public execute() : null|bool
Return values
null|bool

returns true if the operation is successfully executed, otherwise false in case of an exception

foreignkeys()

Indicates whether foreign keys are present or enabled.

public foreignkeys() : bool
Return values
bool

returns false, indicating that foreign keys are not present or enabled

get_dataset()

Retrieves the dataset name associated with the class.

public static get_dataset() : string
Return values
string

the dataset name defined as a constant in the class

get_field_type()

Determines and returns the corresponding field type based on the provided type.

public static get_field_type(string $type) : string
Parameters
$type : string

The type of the field as a string (e.g., 'bigint', 'tinyint').

Return values
string

The corresponding field type constant (e.g., TYPE_INT64, TYPE_INTEGER, or TYPE_STRING).

get_fields()

Retrieves and returns the fields associated with the current table.

public get_fields() : array<string|int, mixed>
Return values
array<string|int, mixed>

the list of fields for the table returned by the get_table method

get_fields_by_table()

Retrieves and returns the fields and their metadata for a given database table.

public static get_fields_by_table(string $tablename) : array<string|int, mixed>
Parameters
$tablename : string

the name of the database table to fetch fields from

Return values
array<string|int, mixed>

an array of fields, where each field is represented by an associative array containing 'name' (field name), 'type' (field type), and optionally 'mode' if the field is required

get_header()

Retrieves the header information associated with the current table.

public get_header() : array<string|int, mixed>
Return values
array<string|int, mixed>

the header data obtained based on the table

get_header_by_table()

Retrieves and returns the header of a table as an array of column names.

public static get_header_by_table(string $tablename) : array<string|int, mixed>
Parameters
$tablename : string

the name of the database table to fetch the header from

Return values
array<string|int, mixed>

an array of column names representing the header of the specified table

get_idnumber()

Retrieves the ID number associated with the object.

public get_idnumber() : string

If the ID number is not set, it returns a default static ID number.

Return values
string

the ID number, or a default static ID number if not set

get_name()

Get the name of the view.

public get_name() : string

If the name is empty or '0', it returns a default string from the language file. Otherwise, it returns the actual name.

Return values
string

the name of the view or a default string if the name is empty

get_options()

Retrieves and constructs a set of options including schema, primary key, and foreign key information.

public get_options() : array<string|int, mixed>
Return values
array<string|int, mixed>

an associative array containing the schema and table constraints (primary key and foreign keys, if available)

get_table()

Retrieves the table name associated with the object.

public get_table() : string

If the table name is not set or is empty, it returns a default static table name.

Return values
string

the table name, or a default static table name if not set

getInstance()

Get an instance of the class for a specific table.

public static getInstance(string $table[, null|string $name = null ][, null|string $idnumber = null ]) : static
Parameters
$table : string

the table name

$name : null|string = null

the name, defaults to null

$idnumber : null|string = null

the identifier number, defaults to null

Return values
static

an instance of the class for the specified table

primarykey()

Get the table name associated with the class.

public primarykey() : bool|string
Return values
bool|string

the table name defined in the class property

set_count_table_row()

Updates and stores the row count of a specific database table in the configuration.

public set_count_table_row() : void

This method retrieves the row count of a given table from the database and saves it into a configuration entry. If there are existing table row counts stored, they are maintained and updated with the new row count for the specific table.

Tags
throws
dml_exception

generate_data()

Generates and retrieves data from the database table associated with this instance.

protected generate_data() : array<string|int, mixed>
Tags
throws
dml_exception
Return values
array<string|int, mixed>

the data retrieved from the database table

get_filename()

Generates a filename based on the class name, current timestamp, and given extension.

protected static get_filename(string $extension) : string
Parameters
$extension : string

the file extension to be used in the generated filename

Return values
string

the generated filename

get_filepath()

Retrieves the full file path for a given file extension.

protected static get_filepath(string $extension) : string
Parameters
$extension : string

the file extension for which the file path is generated

Return values
string

the complete file path including the directory and filename

get_schema()

Retrieves the schema of the current context.

protected get_schema() : array<string|int, mixed>
Return values
array<string|int, mixed>

save_to_csv()

Saves the provided data to a CSV file with an optional header.

protected static save_to_csv(array<string|int, mixed> $data, array<string|int, mixed> $header) : null|string
Parameters
$data : array<string|int, mixed>

the data to be saved, each entry representing a row

$header : array<string|int, mixed>

an optional header row for the CSV file

Tags
throws
Exception

if an error occurs while saving the CSV file

Return values
null|string

the file path of the saved CSV file

save_to_json()

Saves the provided data to a JSON file.

protected static save_to_json(array<string|int, mixed> $data) : string

Each array entry will be written as a separate JSON object in a new line, following the newline-delimited JSON (NDJSON) format, often used for compatibility with tools like Google BigQuery.

Parameters
$data : array<string|int, mixed>

the array of data to be saved, where each element represents a row

Tags
throws
Exception

if an error occurs while attempting to save the JSON file

Return values
string

the full path to the saved JSON file


        
On this page

Search results