database.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. /* For license terms, see /license.txt */
  3. /**
  4. * Plugin database installation script. Can only be executed if included
  5. * inside another script loading global.inc.php.
  6. *
  7. * @package chamilo.plugin.notebookteacher
  8. */
  9. /**
  10. * Check if script can be called.
  11. */
  12. if (!function_exists('api_get_path')) {
  13. die('This script must be loaded through the Chamilo plugin installer sequence');
  14. }
  15. $entityManager = Database::getManager();
  16. $pluginSchema = new \Doctrine\DBAL\Schema\Schema();
  17. $connection = $entityManager->getConnection();
  18. $platform = $connection->getDatabasePlatform();
  19. if ($pluginSchema->hasTable(NotebookTeacherPlugin::TABLE_NOTEBOOKTEACHER)) {
  20. return;
  21. }
  22. //Create tables
  23. $notebookTable = $pluginSchema->createTable(NotebookTeacherPlugin::TABLE_NOTEBOOKTEACHER);
  24. $notebookTable->addColumn('id', \Doctrine\DBAL\Types\Type::INTEGER, ['autoincrement' => true, 'unsigned' => true]);
  25. $notebookTable->addColumn('c_id', \Doctrine\DBAL\Types\Type::INTEGER, ['unsigned' => true]);
  26. $notebookTable->addColumn('session_id', \Doctrine\DBAL\Types\Type::INTEGER, ['unsigned' => true]);
  27. $notebookTable->addColumn('user_id', \Doctrine\DBAL\Types\Type::INTEGER, ['unsigned' => true]);
  28. $notebookTable->addColumn('student_id', \Doctrine\DBAL\Types\Type::INTEGER, ['unsigned' => true]);
  29. $notebookTable->addColumn('course', \Doctrine\DBAL\Types\Type::STRING);
  30. $notebookTable->addColumn('title', \Doctrine\DBAL\Types\Type::STRING);
  31. $notebookTable->addColumn('description', \Doctrine\DBAL\Types\Type::TEXT);
  32. $notebookTable->addColumn('creation_date', \Doctrine\DBAL\Types\Type::DATETIME);
  33. $notebookTable->addColumn('update_date', \Doctrine\DBAL\Types\Type::DATETIME);
  34. $notebookTable->addColumn('status', \Doctrine\DBAL\Types\Type::INTEGER, ['unsigned' => true]);
  35. $notebookTable->addIndex(['c_id']);
  36. $notebookTable->setPrimaryKey(['id']);
  37. $queries = $pluginSchema->toSql($platform);
  38. foreach ($queries as $query) {
  39. Database::query($query);
  40. }