|
|
|
|
@ -2,7 +2,6 @@ |
|
|
|
|
|
|
|
|
|
/* For licensing terms, see /license.txt */ |
|
|
|
|
|
|
|
|
|
use Chamilo\PluginBundle\Entity\XApi\Cmi5Item; |
|
|
|
|
use Chamilo\PluginBundle\Entity\XApi\SharedStatement; |
|
|
|
|
use Chamilo\PluginBundle\Entity\XApi\ToolLaunch; |
|
|
|
|
use Doctrine\ORM\EntityManager; |
|
|
|
|
@ -105,7 +104,6 @@ class XApiPlugin extends Plugin implements HookPluginInterface |
|
|
|
|
[ |
|
|
|
|
'xapi_shared_statement', |
|
|
|
|
'xapi_tool_launch', |
|
|
|
|
'xapi_cmi5_item', |
|
|
|
|
|
|
|
|
|
'xapi_attachment', |
|
|
|
|
'xapi_object', |
|
|
|
|
@ -128,62 +126,6 @@ class XApiPlugin extends Plugin implements HookPluginInterface |
|
|
|
|
$this->installHook(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @throws \Doctrine\ORM\Tools\ToolsException |
|
|
|
|
*/ |
|
|
|
|
private function installPluginDbTables() |
|
|
|
|
{ |
|
|
|
|
$em = Database::getManager(); |
|
|
|
|
$pluginEm = self::getEntityManager(); |
|
|
|
|
|
|
|
|
|
$schemaTool = new SchemaTool($em); |
|
|
|
|
$schemaTool->createSchema( |
|
|
|
|
[ |
|
|
|
|
$em->getClassMetadata(SharedStatement::class), |
|
|
|
|
$em->getClassMetadata(ToolLaunch::class), |
|
|
|
|
] |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
$pluginSchemaTool = new SchemaTool($pluginEm); |
|
|
|
|
$pluginSchemaTool->createSchema( |
|
|
|
|
[ |
|
|
|
|
$pluginEm->getClassMetadata(\XApi\Repository\Doctrine\Mapping\Attachment::class), |
|
|
|
|
$pluginEm->getClassMetadata(\XApi\Repository\Doctrine\Mapping\StatementObject::class), |
|
|
|
|
$pluginEm->getClassMetadata(\XApi\Repository\Doctrine\Mapping\Result::class), |
|
|
|
|
$pluginEm->getClassMetadata(\XApi\Repository\Doctrine\Mapping\Verb::class), |
|
|
|
|
$pluginEm->getClassMetadata(\XApi\Repository\Doctrine\Mapping\Extensions::class), |
|
|
|
|
$pluginEm->getClassMetadata(\XApi\Repository\Doctrine\Mapping\Context::class), |
|
|
|
|
$pluginEm->getClassMetadata(\XApi\Repository\Doctrine\Mapping\Actor::class), |
|
|
|
|
$pluginEm->getClassMetadata(\XApi\Repository\Doctrine\Mapping\Statement::class), |
|
|
|
|
] |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @throws \Exception |
|
|
|
|
*/ |
|
|
|
|
private function installUuid() |
|
|
|
|
{ |
|
|
|
|
$uuidNamespace = Uuid::uuid1(); |
|
|
|
|
|
|
|
|
|
$pluginName = $this->get_name(); |
|
|
|
|
$urlId = api_get_current_access_url_id(); |
|
|
|
|
|
|
|
|
|
api_add_setting( |
|
|
|
|
$uuidNamespace, |
|
|
|
|
$pluginName.'_'.self::SETTING_UUID_NAMESPACE, |
|
|
|
|
$pluginName, |
|
|
|
|
'setting', |
|
|
|
|
'Plugins', |
|
|
|
|
$pluginName, |
|
|
|
|
'', |
|
|
|
|
'', |
|
|
|
|
'', |
|
|
|
|
$urlId, |
|
|
|
|
1 |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Process to uninstall plugin. |
|
|
|
|
*/ |
|
|
|
|
@ -195,7 +137,7 @@ class XApiPlugin extends Plugin implements HookPluginInterface |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @inheritDoc |
|
|
|
|
* {@inheritdoc} |
|
|
|
|
*/ |
|
|
|
|
public function uninstallHook() |
|
|
|
|
{ |
|
|
|
|
@ -271,29 +213,6 @@ class XApiPlugin extends Plugin implements HookPluginInterface |
|
|
|
|
->getStateApiClient()->getDocument(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @param string|null $lrsUrl |
|
|
|
|
* @param string|null $lrsAuthUsername |
|
|
|
|
* @param string|null $lrsAuthPassword |
|
|
|
|
* |
|
|
|
|
* @return \Xabbuh\XApi\Client\XApiClientInterface |
|
|
|
|
*/ |
|
|
|
|
private function createXApiClient($lrsUrl = null, $lrsAuthUsername = null, $lrsAuthPassword = null) |
|
|
|
|
{ |
|
|
|
|
$baseUrl = $lrsUrl ?: $this->get(self::SETTING_LRS_URL); |
|
|
|
|
$lrsAuthUsername = $lrsAuthUsername ?: $this->get(self::SETTING_LRS_AUTH_USERNAME); |
|
|
|
|
$lrsAuthPassword = $lrsAuthPassword ?: $this->get(self::SETTING_LRS_AUTH_PASSWORD); |
|
|
|
|
|
|
|
|
|
$clientBuilder = new XApiClientBuilder(); |
|
|
|
|
$clientBuilder |
|
|
|
|
->setHttpClient(Client::createWithConfig([RequestOptions::VERIFY => false])) |
|
|
|
|
->setRequestFactory(new GuzzleMessageFactory()) |
|
|
|
|
->setBaseUrl(trim($baseUrl, "/ \t\n\r\0\x0B")) |
|
|
|
|
->setAuth(trim($lrsAuthUsername), trim($lrsAuthPassword)); |
|
|
|
|
|
|
|
|
|
return $clientBuilder->build(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Perform actions after save the plugin configuration. |
|
|
|
|
* |
|
|
|
|
@ -339,7 +258,7 @@ class XApiPlugin extends Plugin implements HookPluginInterface |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @inheritDoc |
|
|
|
|
* {@inheritdoc} |
|
|
|
|
*/ |
|
|
|
|
public function installHook() |
|
|
|
|
{ |
|
|
|
|
@ -402,27 +321,8 @@ class XApiPlugin extends Plugin implements HookPluginInterface |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private function addCourseTools() |
|
|
|
|
{ |
|
|
|
|
$courses = Database::getManager() |
|
|
|
|
->createQuery('SELECT c.id FROM ChamiloCoreBundle:Course c') |
|
|
|
|
->getResult(); |
|
|
|
|
|
|
|
|
|
foreach ($courses as $course) { |
|
|
|
|
$this->addCourseToolForTinCan($course['id']); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private function deleteCourseTools() |
|
|
|
|
{ |
|
|
|
|
Database::getManager() |
|
|
|
|
->createQuery('DELETE FROM ChamiloCourseBundle:CTool t WHERE t.category = :category AND t.link LIKE :link') |
|
|
|
|
->execute(['category' => 'plugin', 'link' => 'xapi/tincan/index.php%']); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @param \Xabbuh\XApi\Model\LanguageMap $languageMap |
|
|
|
|
* @param string $language |
|
|
|
|
* @param string $language |
|
|
|
|
* |
|
|
|
|
* @return mixed|string |
|
|
|
|
*/ |
|
|
|
|
@ -500,7 +400,7 @@ class XApiPlugin extends Plugin implements HookPluginInterface |
|
|
|
|
$em = Database::getManager(); |
|
|
|
|
|
|
|
|
|
$prefixes = [ |
|
|
|
|
__DIR__.'/../php-xapi/repository-doctrine-orm/metadata' => 'XApi\Repository\Doctrine\Mapping' |
|
|
|
|
__DIR__.'/../php-xapi/repository-doctrine-orm/metadata' => 'XApi\Repository\Doctrine\Mapping', |
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
$driver = new SimplifiedXmlDriver($prefixes); |
|
|
|
|
@ -517,4 +417,101 @@ class XApiPlugin extends Plugin implements HookPluginInterface |
|
|
|
|
|
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @throws \Doctrine\ORM\Tools\ToolsException |
|
|
|
|
*/ |
|
|
|
|
private function installPluginDbTables() |
|
|
|
|
{ |
|
|
|
|
$em = Database::getManager(); |
|
|
|
|
$pluginEm = self::getEntityManager(); |
|
|
|
|
|
|
|
|
|
$schemaTool = new SchemaTool($em); |
|
|
|
|
$schemaTool->createSchema( |
|
|
|
|
[ |
|
|
|
|
$em->getClassMetadata(SharedStatement::class), |
|
|
|
|
$em->getClassMetadata(ToolLaunch::class), |
|
|
|
|
] |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
$pluginSchemaTool = new SchemaTool($pluginEm); |
|
|
|
|
$pluginSchemaTool->createSchema( |
|
|
|
|
[ |
|
|
|
|
$pluginEm->getClassMetadata(\XApi\Repository\Doctrine\Mapping\Attachment::class), |
|
|
|
|
$pluginEm->getClassMetadata(\XApi\Repository\Doctrine\Mapping\StatementObject::class), |
|
|
|
|
$pluginEm->getClassMetadata(\XApi\Repository\Doctrine\Mapping\Result::class), |
|
|
|
|
$pluginEm->getClassMetadata(\XApi\Repository\Doctrine\Mapping\Verb::class), |
|
|
|
|
$pluginEm->getClassMetadata(\XApi\Repository\Doctrine\Mapping\Extensions::class), |
|
|
|
|
$pluginEm->getClassMetadata(\XApi\Repository\Doctrine\Mapping\Context::class), |
|
|
|
|
$pluginEm->getClassMetadata(\XApi\Repository\Doctrine\Mapping\Actor::class), |
|
|
|
|
$pluginEm->getClassMetadata(\XApi\Repository\Doctrine\Mapping\Statement::class), |
|
|
|
|
] |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @throws \Exception |
|
|
|
|
*/ |
|
|
|
|
private function installUuid() |
|
|
|
|
{ |
|
|
|
|
$uuidNamespace = Uuid::uuid1(); |
|
|
|
|
|
|
|
|
|
$pluginName = $this->get_name(); |
|
|
|
|
$urlId = api_get_current_access_url_id(); |
|
|
|
|
|
|
|
|
|
api_add_setting( |
|
|
|
|
$uuidNamespace, |
|
|
|
|
$pluginName.'_'.self::SETTING_UUID_NAMESPACE, |
|
|
|
|
$pluginName, |
|
|
|
|
'setting', |
|
|
|
|
'Plugins', |
|
|
|
|
$pluginName, |
|
|
|
|
'', |
|
|
|
|
'', |
|
|
|
|
'', |
|
|
|
|
$urlId, |
|
|
|
|
1 |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @param string|null $lrsUrl |
|
|
|
|
* @param string|null $lrsAuthUsername |
|
|
|
|
* @param string|null $lrsAuthPassword |
|
|
|
|
* |
|
|
|
|
* @return \Xabbuh\XApi\Client\XApiClientInterface |
|
|
|
|
*/ |
|
|
|
|
private function createXApiClient($lrsUrl = null, $lrsAuthUsername = null, $lrsAuthPassword = null) |
|
|
|
|
{ |
|
|
|
|
$baseUrl = $lrsUrl ?: $this->get(self::SETTING_LRS_URL); |
|
|
|
|
$lrsAuthUsername = $lrsAuthUsername ?: $this->get(self::SETTING_LRS_AUTH_USERNAME); |
|
|
|
|
$lrsAuthPassword = $lrsAuthPassword ?: $this->get(self::SETTING_LRS_AUTH_PASSWORD); |
|
|
|
|
|
|
|
|
|
$clientBuilder = new XApiClientBuilder(); |
|
|
|
|
$clientBuilder |
|
|
|
|
->setHttpClient(Client::createWithConfig([RequestOptions::VERIFY => false])) |
|
|
|
|
->setRequestFactory(new GuzzleMessageFactory()) |
|
|
|
|
->setBaseUrl(trim($baseUrl, "/ \t\n\r\0\x0B")) |
|
|
|
|
->setAuth(trim($lrsAuthUsername), trim($lrsAuthPassword)); |
|
|
|
|
|
|
|
|
|
return $clientBuilder->build(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private function addCourseTools() |
|
|
|
|
{ |
|
|
|
|
$courses = Database::getManager() |
|
|
|
|
->createQuery('SELECT c.id FROM ChamiloCoreBundle:Course c') |
|
|
|
|
->getResult(); |
|
|
|
|
|
|
|
|
|
foreach ($courses as $course) { |
|
|
|
|
$this->addCourseToolForTinCan($course['id']); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private function deleteCourseTools() |
|
|
|
|
{ |
|
|
|
|
Database::getManager() |
|
|
|
|
->createQuery('DELETE FROM ChamiloCourseBundle:CTool t WHERE t.category = :category AND t.link LIKE :link') |
|
|
|
|
->execute(['category' => 'plugin', 'link' => 'xapi/tincan/index.php%']); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|