class 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.

Constants

MODE_ONLY_DEFAULT

MODE_DEFAULT_AND_CUSTOM

MODE_CUSTOM_AND_DEFAULT

MODE_ONLY_CUSTOM

Methods

static array|false
get_views()

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

static array
get_generic_default_views()

Retrieves a list of generic default views.

static array
get_all_moodle_table()

Retrieves all the table names from the Moodle database.

static array
get_db_table()

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

static bool
save_db_table(object $table)

Saves the state of a database table to the configuration.

static array|string
formatted_test()

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

static array|string
get_options_modes(bool|int $mode = false)

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

static void
file_cleanup()

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

static array
get_default_view_data(array $data)

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

static array
get_list_view_data()

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

static array
get_custom_view_data(array $data)

Filters and retrieves custom view data based on specific criteria.

static string
get_view_fullname(mixed $id)

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

static int
get_table_count_rows(string $table)

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

Details

at line 54
static array|false get_views()

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

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 Value

array|false

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

at line 121
static array get_generic_default_views()

Retrieves a list of generic default views.

Return Value

array

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.

at line 170
static array get_all_moodle_table()

Retrieves all the table names from the Moodle database.

Return Value

array

the list of table names in the Moodle database

at line 186
static array get_db_table()

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

Return Value

array

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

at line 228
static bool save_db_table(object $table)

Saves the state of a database table to the configuration.

Parameters

object $table

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

Return Value

bool

true if the operation was completed successfully

Exceptions

dml_exception

at line 268
static array|string formatted_test()

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

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 Value

array|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.

at line 300
static array|string get_options_modes(bool|int $mode = false)

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

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

bool|int $mode

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

Return Value

array|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.

at line 331
static void file_cleanup()

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

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.

Return Value

void

Exceptions

dml_exception

at line 383
static array get_default_view_data(array $data)

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

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

array $data

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

Return Value

array

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

at line 401
static array get_list_view_data()

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

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 Value

array

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.

at line 438
static array get_custom_view_data(array $data)

Filters and retrieves custom view data based on specific criteria.

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

array $data

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 Value

array

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

at line 452
static string get_view_fullname(mixed $id)

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

Parameters

mixed $id

the identifier of the Google BigQuery view

Return Value

string

the full name of the Google BigQuery view

at line 466
static int get_table_count_rows(string $table)

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

Parameters

string $table

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

Return Value

int

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