|
|
|
|
@ -3,6 +3,9 @@ |
|
|
|
|
|
|
|
|
|
use Chamilo\CourseBundle\Entity\CTool; |
|
|
|
|
use Chamilo\CoreBundle\Entity\Course; |
|
|
|
|
use Doctrine\DBAL\Schema\Schema; |
|
|
|
|
use Doctrine\DBAL\Types\Type; |
|
|
|
|
use Doctrine\DBAL\DBALException; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Description of MsiLti |
|
|
|
|
@ -53,7 +56,11 @@ class ImsLtiPlugin extends Plugin |
|
|
|
|
*/ |
|
|
|
|
public function install() |
|
|
|
|
{ |
|
|
|
|
try { |
|
|
|
|
$this->setupDatabase(); |
|
|
|
|
} catch (DBALException $e) { |
|
|
|
|
error_log('Error while installing IMS/LTI plugin: '.$e->getMessage()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
@ -61,37 +68,39 @@ class ImsLtiPlugin extends Plugin |
|
|
|
|
*/ |
|
|
|
|
public function uninstall() |
|
|
|
|
{ |
|
|
|
|
try { |
|
|
|
|
$this->clearDatabase(); |
|
|
|
|
$this->removeTools(); |
|
|
|
|
} catch (DBALException $e) { |
|
|
|
|
error_log('Error while uninstalling IMS/LTI plugin: '.$e->getMessage()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Creates the plugin tables on database |
|
|
|
|
* @return boolean |
|
|
|
|
* @throws \Doctrine\DBAL\DBALException |
|
|
|
|
*/ |
|
|
|
|
private function setupDatabase() |
|
|
|
|
{ |
|
|
|
|
$entityManager = Database::getManager(); |
|
|
|
|
$connection = $entityManager->getConnection(); |
|
|
|
|
$chamiloSchema = $connection->getSchemaManager(); |
|
|
|
|
$pluginSchema = new \Doctrine\DBAL\Schema\Schema(); |
|
|
|
|
$pluginSchema = new Schema(); |
|
|
|
|
$platform = $connection->getDatabasePlatform(); |
|
|
|
|
|
|
|
|
|
if ($chamiloSchema->tablesExist([self::TABLE_TOOL])) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$toolTable = $pluginSchema->createTable(self::TABLE_TOOL); |
|
|
|
|
$toolTable->addColumn( |
|
|
|
|
'id', |
|
|
|
|
\Doctrine\DBAL\Types\Type::INTEGER, |
|
|
|
|
['autoincrement' => true, 'unsigned' => true] |
|
|
|
|
); |
|
|
|
|
$toolTable->addColumn('name', \Doctrine\DBAL\Types\Type::STRING); |
|
|
|
|
$toolTable->addColumn('description', \Doctrine\DBAL\Types\Type::TEXT, ['notnull' => false]); |
|
|
|
|
$toolTable->addColumn('launch_url', \Doctrine\DBAL\Types\Type::TEXT); |
|
|
|
|
$toolTable->addColumn('consumer_key', \Doctrine\DBAL\Types\Type::STRING); |
|
|
|
|
$toolTable->addColumn('shared_secret', \Doctrine\DBAL\Types\Type::STRING); |
|
|
|
|
$toolTable->addColumn('custom_params', \Doctrine\DBAL\Types\Type::TEXT); |
|
|
|
|
$toolTable->addColumn('name', Type::STRING); |
|
|
|
|
$toolTable->addColumn('description', Type::TEXT)->setNotnull(false); |
|
|
|
|
$toolTable->addColumn('launch_url', Type::TEXT); |
|
|
|
|
$toolTable->addColumn('consumer_key', Type::STRING); |
|
|
|
|
$toolTable->addColumn('shared_secret', Type::STRING); |
|
|
|
|
$toolTable->addColumn('custom_params', Type::TEXT); |
|
|
|
|
$toolTable->addColumn('is_global', Type::BOOLEAN); |
|
|
|
|
$toolTable->setPrimaryKey(['id']); |
|
|
|
|
|
|
|
|
|
$queries = $pluginSchema->toSql($platform); |
|
|
|
|
@ -106,6 +115,7 @@ class ImsLtiPlugin extends Plugin |
|
|
|
|
/** |
|
|
|
|
* Drops the plugin tables on database |
|
|
|
|
* @return boolean |
|
|
|
|
* @throws \Doctrine\DBAL\DBALException |
|
|
|
|
*/ |
|
|
|
|
private function clearDatabase() |
|
|
|
|
{ |
|
|
|
|
@ -123,6 +133,15 @@ class ImsLtiPlugin extends Plugin |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @throws \Doctrine\DBAL\DBALException |
|
|
|
|
*/ |
|
|
|
|
private function removeTools() |
|
|
|
|
{ |
|
|
|
|
$sql = "DELETE FROM c_tool WHERE link LIKE 'ims_lti/start.php%' AND category = 'plugin'"; |
|
|
|
|
Database::query($sql); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Set the course settings |
|
|
|
|
*/ |
|
|
|
|
@ -130,7 +149,7 @@ class ImsLtiPlugin extends Plugin |
|
|
|
|
{ |
|
|
|
|
$button = Display::toolbarButton( |
|
|
|
|
$this->get_lang('AddExternalTool'), |
|
|
|
|
api_get_path(WEB_PLUGIN_PATH).'ims_lti/add.php', |
|
|
|
|
api_get_path(WEB_PLUGIN_PATH).'ims_lti/add.php?'.api_get_cidreq(), |
|
|
|
|
'cog', |
|
|
|
|
'primary' |
|
|
|
|
); |
|
|
|
|
|