add_gradebook_certificates.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Adds gradebook certificates to gradebook_certificate table from users
  5. * who have achieved the requirements but have not reviewed them yet
  6. * @package chamilo.cron
  7. * @author Imanol Losada <imanol.losada@beeznest.com>
  8. */
  9. require_once __DIR__.'/../inc/global.inc.php';
  10. require_once api_get_path(LIBRARY_PATH).'database.lib.php';
  11. require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/gradebook_functions.inc.php';
  12. /**
  13. * Get all categories and users ids from gradebook
  14. * @return array Categories and users ids
  15. */
  16. function getAllCategoriesAndUsers() {
  17. $table = Database::get_main_table(TABLE_MAIN_GRADEBOOK_RESULT);
  18. $jointable = Database::get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
  19. $joinStatement = ' JOIN '.$jointable.' ON '.$table.'.evaluation_id = '.$jointable.'.id';
  20. return Database::select(
  21. 'DISTINCT '.$jointable.'.category_id,'.$table.'.user_id',
  22. $table.$joinStatement
  23. );
  24. }
  25. if ($categoriesAndUsers = getAllCategoriesAndUsers()) {
  26. foreach ($categoriesAndUsers as $categoryAndUser) {
  27. Category::register_user_certificate(
  28. $categoryAndUser['category_id'],
  29. $categoryAndUser['user_id']
  30. );
  31. }
  32. }