Skip to content

Commit

Permalink
Xapi: Allow cron process use alternative LRS - refs BT#18160
Browse files Browse the repository at this point in the history
  • Loading branch information
AngelFQC committed Oct 28, 2022
1 parent 9628c95 commit f25786a
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 6 deletions.
2 changes: 1 addition & 1 deletion plugin/xapi/cron/send_statements.php
Expand Up @@ -34,7 +34,7 @@
if ($countNotSent > 0) {
echo '['.time().'] Trying to send '.$countNotSent.' statements to LRS'.PHP_EOL;

$client = XApiPlugin::create()->getXApiStatementClient();
$client = XApiPlugin::create()->getXapiStatementCronClient();

/** @var SharedStatement $notSentSharedStatement */
foreach ($notSentSharedStatements as $notSentSharedStatement) {
Expand Down
6 changes: 6 additions & 0 deletions plugin/xapi/lang/english.php
Expand Up @@ -14,6 +14,12 @@
$strings['lrs_auth_username_help'] = 'Username for basic HTTP authentication';
$strings['lrs_auth_password'] = 'LRS password';
$strings['lrs_auth_password_help'] = 'Password for basic HTTP authentication';
$strings['cron_lrs_url'] = 'Cron: LRS endpoint';
$strings['cron_lrs_url_help'] = 'Alternative base URL of the LRS for the cron process';
$strings['cron_lrs_auth_username'] = 'Cron: LRS user';
$strings['cron_lrs_auth_username_help'] = 'Alternative username for basic HTTP authentication for the cron process';
$strings['cron_lrs_auth_password'] = 'Cron: LRS password';
$strings['cron_lrs_auth_password_help'] = 'Alternative password for basic HTTP authentication for the cron process';
$strings['lrs_lp_item_viewed_active'] = 'Learning path item viewed';
$strings['lrs_lp_end_active'] = 'Learning path ended';
$strings['lrs_quiz_active'] = 'Quiz ended';
Expand Down
6 changes: 6 additions & 0 deletions plugin/xapi/lang/french.php
Expand Up @@ -14,6 +14,12 @@
$strings['lrs_auth_username_help'] = 'Nom d\'utilisateur pour l\'authentification HTTP de base';
$strings['lrs_auth_password'] = 'Mot de passe LRS';
$strings['lrs_auth_password_help'] = 'Mot de passe pour l\'authentification HTTP de base';
$strings['cron_lrs_url'] = 'Cron: LRS endpoint';
$strings['cron_lrs_url_help'] = 'Alternative base URL of the LRS for the cron process';
$strings['cron_lrs_auth_username'] = 'Cron: LRS user';
$strings['cron_lrs_auth_username_help'] = 'Alternative username for basic HTTP authentication for the cron process';
$strings['cron_lrs_auth_password'] = 'Cron: LRS password';
$strings['cron_lrs_auth_password_help'] = 'Alternative password for basic HTTP authentication for the cron process';
$strings['lrs_lp_item_viewed_active'] = 'Élément de parcours visionné';
$strings['lrs_lp_end_active'] = 'Parcours terminé';
$strings['lrs_quiz_active'] = 'Exercice terminé';
Expand Down
8 changes: 7 additions & 1 deletion plugin/xapi/lang/spanish.php
Expand Up @@ -11,9 +11,15 @@
$strings['lrs_url'] = 'LRS endpoint';
$strings['lrs_url_help'] = 'Base de la URL del LRS';
$strings['lrs_auth_username'] = 'Usuario del LRS';
$strings['lrs_auth_username_help'] = 'Usuario para autenticación con HTTP básica';
$strings['lrs_auth_username_help'] = 'Usuario para autenticación con HTTP básica';
$strings['lrs_auth_password'] = 'Contraseña del LRS';
$strings['lrs_auth_password_help'] = 'Contraseña para autenticación con HTTP básica';
$strings['cron_lrs_url'] = 'Cron: LRS endpoint';
$strings['cron_lrs_url_help'] = 'Opcional. Base de la URL alternativa del LRS del proceso cron.';
$strings['cron_lrs_auth_username'] = 'Cron: Usuario del LRS';
$strings['cron_lrs_auth_username_help'] = 'Opcional. Usuario alternativo para autenticación con HTTP básica del proceso cron';
$strings['cron_lrs_auth_password'] = 'Cron: Contraseña del LRS';
$strings['cron_lrs_auth_password_help'] = 'Opcional. Contraseña alternativa para autenticación con HTTP básica del proceso cron';
$strings['lrs_lp_item_viewed_active'] = 'Visualización de contenido de lección';
$strings['lrs_lp_end_active'] = 'Finalización de lección';
$strings['lrs_quiz_active'] = 'Finalización de ejercicio';
Expand Down
28 changes: 24 additions & 4 deletions plugin/xapi/src/XApiPlugin.php
Expand Up @@ -17,6 +17,7 @@
use Http\Adapter\Guzzle6\Client;
use Http\Message\MessageFactory\GuzzleMessageFactory;
use Ramsey\Uuid\Uuid;
use Xabbuh\XApi\Client\Api\StatementsApiClientInterface;
use Xabbuh\XApi\Client\XApiClientBuilder;
use Xabbuh\XApi\Model\Agent;
use Xabbuh\XApi\Model\IRI;
Expand All @@ -30,6 +31,9 @@ class XApiPlugin extends Plugin implements HookPluginInterface
public const SETTING_LRS_URL = 'lrs_url';
public const SETTING_LRS_AUTH_USERNAME = 'lrs_auth_username';
public const SETTING_LRS_AUTH_PASSWORD = 'lrs_auth_password';
public const SETTING_CRON_LRS_URL = 'cron_lrs_url';
public const SETTING_CRON_LRS_AUTH_USERNAME = 'cron_lrs_auth_username';
public const SETTING_CRON_LRS_AUTH_PASSWORD = 'cron_lrs_auth_password';
public const SETTING_UUID_NAMESPACE = 'uuid_namespace';
public const SETTING_LRS_LP_ITEM_ACTIVE = 'lrs_lp_item_viewed_active';
public const SETTING_LRS_LP_ACTIVE = 'lrs_lp_end_active';
Expand All @@ -56,6 +60,10 @@ protected function __construct()
self::SETTING_LRS_AUTH_USERNAME => 'text',
self::SETTING_LRS_AUTH_PASSWORD => 'text',

self::SETTING_CRON_LRS_URL => 'text',
self::SETTING_CRON_LRS_AUTH_USERNAME => 'text',
self::SETTING_CRON_LRS_AUTH_PASSWORD => 'text',

self::SETTING_LRS_LP_ITEM_ACTIVE => 'boolean',
self::SETTING_LRS_LP_ACTIVE => 'boolean',
self::SETTING_LRS_QUIZ_ACTIVE => 'boolean',
Expand Down Expand Up @@ -199,14 +207,26 @@ public function getXApiStateClient($lrsUrl = null, $lrsAuthUsername = null, $lrs
->getStateApiClient();
}

/**
* @return \Xabbuh\XApi\Client\Api\StatementsApiClientInterface
*/
public function getXApiStatementClient()
public function getXApiStatementClient(): StatementsApiClientInterface
{
return $this->createXApiClient()->getStatementsApiClient();
}

public function getXapiStatementCronClient(): StatementsApiClientInterface
{
$lrsUrl = $this->get(self::SETTING_CRON_LRS_URL);
$lrsUsername = $this->get(self::SETTING_CRON_LRS_AUTH_USERNAME);
$lrsPassword = $this->get(self::SETTING_CRON_LRS_AUTH_PASSWORD);

return $this
->createXApiClient(
empty($lrsUrl) ? null : $lrsUrl,
empty($lrsUsername) ? null : $lrsUsername,
empty($lrsPassword) ? null : $lrsPassword
)
->getStatementsApiClient();
}

/**
* Perform actions after save the plugin configuration.
*
Expand Down

0 comments on commit f25786a

Please sign in to comment.