From 4148d4980d8972877162a70954dfc1dcdfd1d396 Mon Sep 17 00:00:00 2001 From: Imanol Losada Date: Tue, 20 Jan 2015 14:55:21 -0500 Subject: [PATCH 1/3] Create cron script that adds gradebook certificates to gradebook_certificate table from users who have achieved the requirements but have not reviewed them yet - refs BT#9022 --- main/cron/add_gradebook_certificates.php | 34 ++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 main/cron/add_gradebook_certificates.php diff --git a/main/cron/add_gradebook_certificates.php b/main/cron/add_gradebook_certificates.php new file mode 100644 index 0000000000..e3f1d4070b --- /dev/null +++ b/main/cron/add_gradebook_certificates.php @@ -0,0 +1,34 @@ + + */ + +/** + * 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'] + ); + } +} From 2fd2c2b7a4284204138662bd432a7301c625579d Mon Sep 17 00:00:00 2001 From: Imanol Losada Date: Mon, 26 Jan 2015 12:44:01 -0500 Subject: [PATCH 2/3] Add certificate path to the web service. Add 'add_gradebook_certificates_cron_task_enabled' configuration parameter - refs BT#9022 --- main/install/configuration.dist.php | 2 + main/webservices/registration.soap.php | 80 ++++++++++++++++++++++++++ 2 files changed, 82 insertions(+) diff --git a/main/install/configuration.dist.php b/main/install/configuration.dist.php index ed362558d7..153140f467 100755 --- a/main/install/configuration.dist.php +++ b/main/install/configuration.dist.php @@ -278,3 +278,5 @@ $_configuration['system_stable'] = NEW_VERSION_STABLE; //$_configuration['exercise_max_fckeditors_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; \ No newline at end of file diff --git a/main/webservices/registration.soap.php b/main/webservices/registration.soap.php index dba1bc1541..9f7c938f41 100755 --- a/main/webservices/registration.soap.php +++ b/main/webservices/registration.soap.php @@ -5533,6 +5533,86 @@ function WSUserSubscribedInCourse ($params) return (CourseManager::is_user_subscribed_in_course($userId,$courseCode)); } +/* 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)) { + $row['path_certificate'] = $basePath.substr((string) $row['user_id'], 0, 1) + .'/'.$row['user_id'].'/certificate'.$row['path_certificate']; + $result[] = $row; + } + return $result; + +} + // Use the request to (try to) invoke the service $HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : ''; // If you send your data in utf8 then this value must be false. From 0625c71c0c97110f13357b2be2988ce43e96bb47 Mon Sep 17 00:00:00 2001 From: Imanol Losada Date: Mon, 9 Mar 2015 10:18:16 -0500 Subject: [PATCH 3/3] Add 'split_users_upload_directory' setting when creating the certificate path (1.9.x) - refs BT#9022 --- main/cron/add_gradebook_certificates.php | 8 +++++--- main/webservices/registration.soap.php | 7 +++++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/main/cron/add_gradebook_certificates.php b/main/cron/add_gradebook_certificates.php index e3f1d4070b..816e047a2a 100644 --- a/main/cron/add_gradebook_certificates.php +++ b/main/cron/add_gradebook_certificates.php @@ -1,7 +1,5 @@ */ +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 diff --git a/main/webservices/registration.soap.php b/main/webservices/registration.soap.php index 9f7c938f41..78e88ef494 100755 --- a/main/webservices/registration.soap.php +++ b/main/webservices/registration.soap.php @@ -5605,8 +5605,11 @@ function WSCertificatesList($startingDate = '', $endingDate = '') $queryResult = Database::query($query); $basePath = api_get_path(WEB_CODE_PATH).'upload/users/'; while ($row = Database::fetch_array($queryResult)) { - $row['path_certificate'] = $basePath.substr((string) $row['user_id'], 0, 1) - .'/'.$row['user_id'].'/certificate'.$row['path_certificate']; + $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;