diff --git a/main/cron/add_gradebook_certificates.php b/main/cron/add_gradebook_certificates.php new file mode 100644 index 0000000000..816e047a2a --- /dev/null +++ b/main/cron/add_gradebook_certificates.php @@ -0,0 +1,36 @@ + + */ + +require_once __DIR__.'/../inc/global.inc.php'; +require_once api_get_path(LIBRARY_PATH).'database.lib.php'; +require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/gradebook_functions.inc.php'; + +/** + * Get all categories and users ids from gradebook + * @return array Categories and users ids + */ +function getAllCategoriesAndUsers() { + $table = Database::get_main_table(TABLE_MAIN_GRADEBOOK_RESULT); + $jointable = Database::get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); + $joinStatement = ' JOIN '.$jointable.' ON '.$table.'.evaluation_id = '.$jointable.'.id'; + return Database::select( + 'DISTINCT '.$jointable.'.category_id,'.$table.'.user_id', + $table.$joinStatement + ); +} + +if ($categoriesAndUsers = getAllCategoriesAndUsers()) { + foreach ($categoriesAndUsers as $categoryAndUser) { + Category::register_user_certificate( + $categoryAndUser['category_id'], + $categoryAndUser['user_id'] + ); + } +} diff --git a/main/install/configuration.dist.php b/main/install/configuration.dist.php index 08693b3f01..d5c30f348f 100755 --- a/main/install/configuration.dist.php +++ b/main/install/configuration.dist.php @@ -286,6 +286,8 @@ $_configuration['system_stable'] = NEW_VERSION_STABLE; //$_configuration['exercise_max_ckeditors_in_page'] = 0; // Default upload option //$_configuration['document_if_file_exists_option'] = 'rename'; // overwrite +// Enable add_gradebook_certificates.php cron task +//$_configuration['add_gradebook_certificates_cron_task_enabled'] = true; // Which OpenBadges backpack send the badges //$_configuration['openbadges_backpack'] = 'https://backpack.openbadges.org/'; // Custom name_order_conventions diff --git a/main/webservices/registration.soap.php b/main/webservices/registration.soap.php index b3942f3616..1516048a9a 100755 --- a/main/webservices/registration.soap.php +++ b/main/webservices/registration.soap.php @@ -5549,6 +5549,7 @@ function WSUserSubscribedInCourse ($params) return (CourseManager::is_user_subscribed_in_course($userId,$courseCode)); } + /* Search session Web Service start */ // Input params for WSSearchSession @@ -5744,6 +5745,88 @@ function WSFetchSession($params) /* Fetch session Web Service end */ +/* Register WSCertificatesList function */ +// Register the data structures used by the service +$server->wsdl->addComplexType( + 'certificateDetails', + 'complexType', + 'struct', + 'all', + '', + array( + 'id' => array('name' => 'id', 'type' => 'xsd:int'), + 'username' => array('name' => 'username', 'type' => 'xsd:string'), + 'course_code' => array('name' => 'course_code', 'type' => 'xsd:string'), + 'session_id' => array('name' => 'session_id', 'type' => 'xsd:int'), + 'cat_id' => array('name' => 'cat_id', 'type' => 'xsd:int'), + 'created_at' => array('name' => 'created_at', 'type' => 'xsd:string'), + 'path_certificate' => array('name' => 'path_certificate', 'type' => 'xsd:string') + ) +); + +$server->wsdl->addComplexType( + 'certificatesList', + 'complexType', + 'array', + '', + 'SOAP-ENC:Array', + array(), + array( + array('ref'=>'SOAP:ENC:arrayType', + 'wsdl:arrayType'=>'tns:certificateDetails[]') + ), + 'tns:certificateDetails' +); +// Register the method to expose +$server->register( + 'WSCertificatesList', // method name + array( + 'startingDate' => 'xsd:string', // input parameters + 'endingDate' => 'xsd:string' + ), + array('return' => 'tns:certificatesList'), // output parameters + 'urn:WSRegistration', // namespace + 'urn:WSRegistration#WSCertificatesList', // soapaction + 'rpc', // style + 'encoded', // use + 'This service returns a list of certificates' // documentation +); + +function WSCertificatesList($startingDate = '', $endingDate = '') +{ + global $_configuration; + if ($_configuration['add_gradebook_certificates_cron_task_enabled']) { + require_once api_get_path(SYS_CODE_PATH).'cron/add_gradebook_certificates.php'; + } + $result = array(); + $certificateTable = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CERTIFICATE); + $userTable = Database::get_main_table(TABLE_MAIN_USER); + $categoryTable = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY); + $query = "SELECT certificate.id, user.username, category.course_code, category.session_id, + certificate.user_id, certificate.cat_id, certificate.created_at, certificate.path_certificate + FROM $certificateTable AS certificate + JOIN $userTable AS user ON certificate.user_id = user.user_id + JOIN $categoryTable AS category ON certificate.cat_id = category.id"; + if (!empty($startingDate) && !empty($endingDate)) { + $query .= " WHERE certificate.created_at BETWEEN '$startingDate' AND '$endingDate'"; + } else if (!empty($startingDate)) { + $query .= " WHERE certificate.created_at >= '$startingDate'"; + } else if (!empty($endingDate)) { + $query .= " WHERE certificate.created_at <= '$endingDate'"; + } + $queryResult = Database::query($query); + $basePath = api_get_path(WEB_CODE_PATH).'upload/users/'; + while ($row = Database::fetch_array($queryResult)) { + $certificatePath = $basePath; + if (api_get_setting('split_users_upload_directory') === 'true') { + $certificatePath .= substr((string) $row['user_id'], 0, 1).'/'; + } + $row['path_certificate'] = $certificatePath.$row['user_id'].'/certificate'.$row['path_certificate']; + $result[] = $row; + } + return $result; +} + // Add more webservices by Hooks if (!empty($hook)) { $hook->setEventData(array('server' => $server));