add_gradebook_certificates.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  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. /**
  11. * Get all categories and users ids from gradebook
  12. * @return array Categories and users ids
  13. */
  14. function getAllCategoriesAndUsers()
  15. {
  16. $table = Database::get_main_table(TABLE_MAIN_GRADEBOOK_RESULT);
  17. $jointable = Database::get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
  18. $joinStatement = ' JOIN '.$jointable.' ON '.$table.'.evaluation_id = '.$jointable.'.id';
  19. return Database::select(
  20. 'DISTINCT '.$jointable.'.category_id,'.$table.'.user_id',
  21. $table.$joinStatement
  22. );
  23. }
  24. if ($categoriesAndUsers = getAllCategoriesAndUsers()) {
  25. foreach ($categoriesAndUsers as $categoryAndUser) {
  26. Category::generateUserCertificate(
  27. $categoryAndUser['category_id'],
  28. $categoryAndUser['user_id']
  29. );
  30. }
  31. }