add_gradebook_certificates.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  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. $table = Database::get_main_table(TABLE_MAIN_GRADEBOOK_RESULT);
  16. $jointable = Database::get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
  17. $joinStatement = ' JOIN '.$jointable.' ON '.$table.'.evaluation_id = '.$jointable.'.id';
  18. return Database::select(
  19. 'DISTINCT '.$jointable.'.category_id,'.$table.'.user_id',
  20. $table.$joinStatement
  21. );
  22. }
  23. if ($categoriesAndUsers = getAllCategoriesAndUsers()) {
  24. foreach ($categoriesAndUsers as $categoryAndUser) {
  25. Category::register_user_certificate(
  26. $categoryAndUser['category_id'],
  27. $categoryAndUser['user_id']
  28. );
  29. }
  30. }