Skip to content

Commit c025963

Browse files
committed
Delete gradebook categories when deleting course - refs BT#14687
1 parent e0c569c commit c025963

File tree

4 files changed

+39
-6
lines changed

4 files changed

+39
-6
lines changed

main/admin/course_list.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,6 @@ function get_course_visibility_icon($visibility)
338338
if (count($course_codes) > 0) {
339339
foreach ($course_codes as $course_code) {
340340
CourseManager::delete_course($course_code);
341-
$obj_cat = new Category();
342-
$obj_cat->update_category_delete($course_code);
343341
}
344342
}
345343

@@ -409,8 +407,6 @@ function get_course_visibility_icon($visibility)
409407
$tool_name = get_lang('CourseList');
410408
if (isset($_GET['delete_course'])) {
411409
CourseManager::delete_course($_GET['delete_course']);
412-
$obj_cat = new Category();
413-
$obj_cat->update_category_delete($_GET['delete_course']);
414410
Display::addFlash(Display::return_message(get_lang('Deleted')));
415411
}
416412
// Create a search-box

main/course_info/delete_course.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828

2929
if (isset($_GET['delete']) && $_GET['delete'] === 'yes') {
3030
CourseManager::delete_course($_course['sysCode']);
31-
$obj_cat = new Category();
32-
$obj_cat->update_category_delete($_course['sysCode']);
3331

3432
// DELETE CONFIRMATION MESSAGE
3533
Session::erase('_cid');

main/gradebook/lib/be/category.class.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,8 @@ public function delete()
746746

747747
/**
748748
* Not delete this category from the database,when visible=3 is category eliminated.
749+
*
750+
* @deprecated To delete categories form course when deleting course use Category::deleteFromCourse
749751
*/
750752
public function update_category_delete($course_id)
751753
{
@@ -756,6 +758,41 @@ public function update_category_delete($course_id)
756758
Database::query($sql);
757759
}
758760

761+
/**
762+
* Delete the gradebook categories from a course, including course sessions
763+
*
764+
* @param string $courseCode
765+
*/
766+
public static function deleteFromCourse($courseCode)
767+
{
768+
$em = Database::getManager();
769+
$categories = $em
770+
->createQuery(
771+
'SELECT DISTINCT gc.sessionId
772+
FROM ChamiloCoreBundle:GradebookCategory gc WHERE gc.courseCode = :code'
773+
)
774+
->setParameter('code', $courseCode)
775+
->getResult();
776+
777+
foreach ($categories as $category) {
778+
$cats = self::load(
779+
null,
780+
null,
781+
$courseCode,
782+
null,
783+
null,
784+
(int) $category['sessionId']
785+
);
786+
787+
if (!empty($cats)) {
788+
/** @var self $cat */
789+
foreach ($cats as $cat) {
790+
$cat->delete_all();
791+
}
792+
}
793+
}
794+
}
795+
759796
/**
760797
* Show message resource delete.
761798
*/

main/inc/lib/course.lib.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2278,6 +2278,8 @@ public static function delete_course($code)
22782278
rename($course_dir, $archive_dir);
22792279
}
22802280

2281+
Category::deleteFromCourse($course['code']);
2282+
22812283
// Unsubscribe all users from the course
22822284
$sql = "DELETE FROM $table_course_user WHERE c_id = $courseId";
22832285
Database::query($sql);

0 commit comments

Comments
 (0)