MIDDAG for Moodle

bigquery_view_service

A service class for managing Google BigQuery views and database tables within Moodle.

This class provides methods for handling default and custom views, managing database table configurations, and integrating with plugins that register additional views. It also manages the interactions related to enabling and disabling specific database tables for use within the BigQuery service.

Table of Contents

Constants

MODE_CUSTOM_AND_DEFAULT  = 3
MODE_DEFAULT_AND_CUSTOM  = 2
MODE_ONLY_CUSTOM  = 4
MODE_ONLY_DEFAULT  = 1

Methods

file_cleanup()  : void
Cleans up files associated with Google BigQuery jobs that have not been marked as deleted.
formatted_test()  : string
Executes a test on the Google BigQuery API service and processes the results.
get_all_moodle_table()  : array<string|int, mixed>
Retrieves all the table names from the Moodle database.
get_custom_view_data()  : array<string|int, mixed>
Filters and retrieves custom view data based on specific criteria.
get_db_table()  : array<string|int, mixed>
Retrieves an array of database table information, including table metadata, active status, default status, and other relevant details.
get_default_view_data()  : array<string|int, mixed>
Filters and retrieves the default view data based on a specific criteria.
get_generic_default_views()  : array<string|int, mixed>
Retrieves a list of generic default views.
get_list_view_data()  : array<string|int, mixed>
Retrieves and organizes data for list views including default and custom views.
get_options_modes()  : array<string|int, mixed>|string
Retrieves available modes as options or a specific mode label based on the input.
get_table_count_rows()  : int
Retrieves the row count for a specified table from the Google BigQuery configuration.
get_view_fullname()  : string
Retrieves the full name of a Google BigQuery view based on the given ID.
get_views()  : array<string|int, mixed>|bool
Retrieves a list of views based on configuration and mode settings.
save_db_table()  : bool
Saves the state of a database table to the configuration.

Constants

Methods

file_cleanup()

Cleans up files associated with Google BigQuery jobs that have not been marked as deleted.

public static file_cleanup() : void

This method iterates through all Google BigQuery views and retrieves associated job items that have not been marked as deleted (i.e., where 'file_deleted_at' is NULL). It processes these items in batches, calling the cleanup method on each item to perform necessary cleanup operations based on the current time and configuration settings.

The method uses pagination to handle large datasets, processing a specified number of items per page. It logs progress messages to indicate the start and completion of the cleanup process for each view and item.

Tags
throws
dml_exception

formatted_test()

Executes a test on the Google BigQuery API service and processes the results.

public static formatted_test() : string

This method attempts to run a test using the Google BigQuery API service. If the test result is an array, it renders and returns the output using a specific template. If the test result is an Exception, it returns an error message. If an error occurs during the execution, the exception message is captured and returned.

Return values
string

Returns the rendered template as a string if the test is successful and returns an array. Returns a string containing the error message if the test fails or an exception occurs. Returns null if no valid result is obtained.

get_all_moodle_table()

Retrieves all the table names from the Moodle database.

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

the list of table names in the Moodle database

get_custom_view_data()

Filters and retrieves custom view data based on specific criteria.

public static get_custom_view_data(array<string|int, mixed> $data) : array<string|int, mixed>

This method filters the provided data array to include only the items where the 'idnumber' starts with the specified prefix 'custom_'. The filtered data is then re-indexed and returned.

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

The input array containing the data to be filtered. Each item in the array is expected to be an associative array with at least an 'idnumber' key.

Return values
array<string|int, mixed>

returns the filtered and re-indexed array containing only the items with 'idnumber' starting with 'custom_'

get_db_table()

Retrieves an array of database table information, including table metadata, active status, default status, and other relevant details.

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

An array of associative arrays, each containing the following keys:

  • 'prefix': The database table prefix.
  • 'tablerow': The count of rows in the corresponding database table.
  • 'id': A unique identifier for the table, determined based on its type (fixed or dynamic).
  • 'table': The name of the

get_default_view_data()

Filters and retrieves the default view data based on a specific criteria.

public static get_default_view_data(array<string|int, mixed> $data) : array<string|int, mixed>

This method processes the input data, filtering out items whose 'idnumber' does not start with 'default_'. It then re-indexes the filtered array to ensure a contiguous numeric index.

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

the input array of data where each item is expected to be an associative array containing an 'idnumber' key

Return values
array<string|int, mixed>

returns a re-indexed array of filtered data items that match the 'default_' condition

get_generic_default_views()

Retrieves a list of generic default views.

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

An array of generic default views, where each entry consists of:

  • The identifier of the view.
  • The description or name of the view.
  • The default view key identifier.

get_list_view_data()

Retrieves and organizes data for list views including default and custom views.

public static get_list_view_data() : array<string|int, mixed>

This method interacts with the Google BigQuery views, fetching all available views and formatting their details into an array. The data is then categorized into default views and custom views for further usage.

Return values
array<string|int, mixed>

Returns an associative array containing two keys:

  • 'default_views': An array containing formatted data for default views.
  • 'custom_views': An array containing formatted data for custom views.

get_options_modes()

Retrieves available modes as options or a specific mode label based on the input.

public static get_options_modes([bool|int $mode = false ]) : array<string|int, mixed>|string

This method generates an array of modes with their corresponding labels. If a specific mode is provided as input, it returns the label for that particular mode. Otherwise, it returns the full list of mode options.

Parameters
$mode : bool|int = false

Optional. A specific mode key to retrieve its corresponding label. Defaults to false, which returns all modes.

Return values
array<string|int, mixed>|string

Returns an associative array of all mode options if $mode is false. Returns a string representing the label of the specified mode if $mode is provided.

get_table_count_rows()

Retrieves the row count for a specified table from the Google BigQuery configuration.

public static get_table_count_rows(string $table) : int
Parameters
$table : string

the name of the table whose row count is to be retrieved

Return values
int

the number of rows for the specified table, or 0 if the row count is not found

get_view_fullname()

Retrieves the full name of a Google BigQuery view based on the given ID.

public static get_view_fullname(mixed $id) : string
Parameters
$id : mixed

the identifier of the Google BigQuery view

Return values
string

the full name of the Google BigQuery view

get_views()

Retrieves a list of views based on configuration and mode settings.

public static get_views() : array<string|int, mixed>|bool

This method generates a collection of views, which may include default views, custom views, or a combination, depending on the mode and enabled tables specified in the configuration settings.

Return values
array<string|int, mixed>|bool

an array of views, or false if no views are matched based on the mode

save_db_table()

Saves the state of a database table to the configuration.

public static save_db_table(object $table) : bool
Parameters
$table : object

a table object containing information about the database table, including its active state

Tags
throws
dml_exception
Return values
bool

true if the operation was completed successfully


        
On this page

Search results