From 6be7a552cebd689ca5b73e6376a1aced67b61542 Mon Sep 17 00:00:00 2001 From: Huong Nguyen Date: Tue, 16 Dec 2025 10:58:00 +0700 Subject: [PATCH] MDL-67733 core: Add Google API Client integration for Moodle --- public/lib/classes/google_api_client.php | 67 ++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 public/lib/classes/google_api_client.php diff --git a/public/lib/classes/google_api_client.php b/public/lib/classes/google_api_client.php new file mode 100644 index 00000000000..e5a84cf4a0c --- /dev/null +++ b/public/lib/classes/google_api_client.php @@ -0,0 +1,67 @@ +. + +namespace core; + +use Google\Client; + +/** + * Google API Client integration for Moodle. + * + * @package core + * @copyright 2025 Huong Nguyen + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class google_api_client extends Client{ + + /** + * Constructor. + * + * @param array $config Configuration array. + */ + public function __construct(array $config = []) { + $client = di::get(http_client::class); + $this->setHttpClient($client); + $config = $this->get_options($config); + + parent::__construct($config); + } + + /** + * Get the custom options for Google API Client integration in Moodle. + * + * @param array $settings The settings or options from client. + * @return array + */ + protected function get_options(array $settings): array { + global $CFG; + + if (empty($settings['application_name'])) { + // Configure the application name. + $settings['application_name'] = 'Moodle ' . $CFG->release; + } + if (empty($settings['access_type'])) { + // Configure the access type. + $settings['access_type'] = 'online'; + } + if (empty($settings['approval_prompt'])) { + // Configure the approval prompt. + $settings['approval_prompt'] = 'auto'; + } + + return $settings; + } +}