diff --git a/main/work/work.lib.php b/main/work/work.lib.php index 4f4e8d3705..fc69e235dd 100755 --- a/main/work/work.lib.php +++ b/main/work/work.lib.php @@ -816,9 +816,56 @@ function deleteDirWork($id) $t_agenda = Database::get_course_table(TABLE_AGENDA); $course_id = api_get_course_int_id(); + $sessionId = api_get_session_id(); if (!empty($work_data['url'])) { if ($check) { + $consideredWorkingTime = api_get_configuration_value('considered_working_time'); + + if (!empty($consideredWorkingTime)) { + $fieldValue = new ExtraFieldValue('work'); + $resultExtra = $fieldValue->getAllValuesForAnItem( + $work_data['id'], + true + ); + + $workingTime = null; + + foreach ($resultExtra as $field) { + $field = $field['value']; + if ($consideredWorkingTime == $field->getField()->getVariable()) { + $workingTime = $field->getValue(); + + break; + } + } + + $courseUsers = CourseManager::get_user_list_from_course_code($_course['code'], $sessionId); + + if (!empty($workingTime)) { + foreach ($courseUsers as $user) { + $userWorks = get_work_user_list( + 0, + 100, + null, + null, + $work_data['id'], + null, + $user['user_id'], + false, + $course_id, + $sessionId + ); + + if (count($userWorks) != 1) { + continue; + } + + Event::eventRemoveVirtualCourseTime($course_id, $user['user_id'], $sessionId, $workingTime); + } + } + } + // Deleting all contents inside the folder $sql = "UPDATE $table SET active = 2 WHERE c_id = $course_id AND filetype = 'folder' AND id = $id"; @@ -854,6 +901,20 @@ function deleteDirWork($id) WHERE c_id = $course_id AND publication_id = $id"; Database::query($sql); + Event::addEvent( + LOG_WORK_DIR_DELETE, + LOG_WORK_DATA, + [ + 'id' => $work_data['id'], + 'url' => $work_data['url'], + 'title' => $work_data['title'] + ], + null, + api_get_user_id(), + api_get_course_int_id(), + $sessionId + ); + $link_info = GradebookUtils::is_resource_in_course_gradebook( api_get_course_id(), 3,