add_gradebook_certificates.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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. *
  7. * @package chamilo.cron
  8. *
  9. * @author Imanol Losada <imanol.losada@beeznest.com>
  10. */
  11. require_once __DIR__.'/../inc/global.inc.php';
  12. /**
  13. * Get all categories and users ids from gradebook.
  14. *
  15. * @return array Categories and users ids
  16. */
  17. function getAllCategoriesAndUsers()
  18. {
  19. $table = Database::get_main_table(TABLE_MAIN_GRADEBOOK_RESULT);
  20. $jointable = Database::get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
  21. $joinStatement = ' JOIN '.$jointable.' ON '.$table.'.evaluation_id = '.$jointable.'.id';
  22. return Database::select(
  23. 'DISTINCT '.$jointable.'.category_id,'.$table.'.user_id',
  24. $table.$joinStatement
  25. );
  26. }
  27. if ($categoriesAndUsers = getAllCategoriesAndUsers()) {
  28. foreach ($categoriesAndUsers as $categoryAndUser) {
  29. Category::generateUserCertificate(
  30. $categoryAndUser['category_id'],
  31. $categoryAndUser['user_id']
  32. );
  33. }
  34. }