Skip to content

Commit 3327cd4

Browse files
committed
Add allow_teacher_comment_audio configuration setting - refs BT#12615
1 parent 8015124 commit 3327cd4

File tree

4 files changed

+97
-11
lines changed

4 files changed

+97
-11
lines changed

main/exercise/exercise_show.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@
139139
$gradebook = Security::remove_XSS($_SESSION['gradebook']);
140140
}
141141

142+
$allowRecordAudio = api_get_setting('enable_record_audio') === 'true';
143+
$allowTeacherComentAudio = api_get_configuration_value('allow_teacher_comment_audio') === true;
144+
142145
if (!empty($gradebook) && $gradebook == 'view') {
143146
$interbreadcrumb[] = array(
144147
'url' => '../gradebook/'.$_SESSION['gradebook_dest'],
@@ -159,6 +162,14 @@
159162
$htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_JS_PATH).'hotspot/js/hotspot.js"></script>';
160163
$htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_JS_PATH).'annotation/js/annotation.js"></script>';
161164

165+
if ($allowRecordAudio && $allowTeacherComentAudio) {
166+
$htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_JS_PATH).'rtc/RecordRTC.js"></script>';
167+
$htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'wami-recorder/recorder.js"></script>';
168+
$htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'wami-recorder/gui.js"></script>';
169+
$htmlHeadXtra[] = '<script type="text/javascript" src="'.api_get_path(WEB_LIBRARY_PATH).'swfobject/swfobject.js"></script>';
170+
$htmlHeadXtra[] = api_get_js('record_audio/record_audio.js');
171+
}
172+
162173
if ($origin != 'learnpath') {
163174
Display::display_header('');
164175
} else {
@@ -713,10 +724,13 @@ function getFCK(vals, marksid) {
713724
$comnt = trim(Event::get_comments($id, $questionId));
714725
if (!empty($comnt)) {
715726
echo ExerciseLib::getFeedbackText($comnt);
727+
echo ExerciseLib::getOralFeedbackAudio($id, $questionId, $student_id);
716728
}
717729
echo '</div>';
718730

719-
echo '<div id="'.$name.'" class="hidden">';
731+
echo '<div id="'.$name.'" class="row hidden">';
732+
echo '<div class="col-sm-'.($allowTeacherComentAudio ? 7 : 12).'">';
733+
720734
$arrid[] = $questionId;
721735
$feedback_form = new FormValidator('frmcomments'.$questionId);
722736
$renderer = &$feedback_form->defaultRenderer();
@@ -742,6 +756,15 @@ function getFCK(vals, marksid) {
742756
}
743757
$feedback_form->setDefaults($default);
744758
$feedback_form->display();
759+
760+
echo '</div>';
761+
762+
if ($allowRecordAudio && $allowTeacherComentAudio) {
763+
echo '<div class="col-sm-5">';
764+
echo ExerciseLib::getOralFeedbackForm($id, $questionId, $student_id);
765+
echo '</div>';
766+
}
767+
745768
echo '</div>';
746769

747770
} else {
@@ -750,6 +773,7 @@ function getFCK(vals, marksid) {
750773
if (!empty($comnt)) {
751774
echo '<b>'.get_lang('Feedback').'</b>';
752775
echo ExerciseLib::getFeedbackText($comnt);
776+
echo ExerciseLib::getOralFeedbackAudio($id, $questionId, $student_id);
753777
}
754778
}
755779

main/inc/ajax/record_audio_wami.ajax.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
die();
2424
}
2525

26-
if ($wamiuserid != api_get_user_id() || api_get_user_id() == 0 || $wamiuserid == 0) {
26+
if (empty($wamiuserid)) {
2727
api_not_allowed();
2828
die();
2929
}
@@ -58,14 +58,14 @@
5858

5959
//avoid duplicates
6060
$waminame_to_save = $waminame;
61-
$waminame_noex = basename($waminame, ".wav");
62-
if (file_exists($saveDir.'/'.$waminame_noex.'.'.$ext)) {
63-
$i = 1;
64-
while (file_exists($saveDir.'/'.$waminame_noex.'_'.$i.'.'.$ext)) {
65-
$i++;
66-
}
67-
$waminame_to_save = $waminame_noex.'_'.$i.'.'.$ext;
68-
}
61+
//$waminame_noex = basename($waminame, ".wav");
62+
//if (file_exists($saveDir.'/'.$waminame_noex.'.'.$ext)) {
63+
// $i = 1;
64+
// while (file_exists($saveDir.'/'.$waminame_noex.'_'.$i.'.'.$ext)) {
65+
// $i++;
66+
// }
67+
// $waminame_to_save = $waminame_noex.'_'.$i.'.'.$ext;
68+
//}
6969

7070
$documentPath = $saveDir.'/'.$waminame_to_save;
7171

main/inc/lib/exercise.lib.php

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3859,10 +3859,19 @@ public static function displayQuestionListByAttempt(
38593859
$comnt = null;
38603860
if ($show_results) {
38613861
$comnt = Event::get_comments($exe_id, $questionId);
3862-
if (!empty($comnt)) {
3862+
$teacherAudio = ExerciseLib::getOralFeedbackAudio($exe_id, $questionId, api_get_user_id());;
3863+
3864+
if (!empty($comnt) || $teacherAudio) {
38633865
echo '<b>'.get_lang('Feedback').'</b>';
3866+
}
3867+
3868+
if (!empty($comnt)) {
38643869
echo ExerciseLib::getFeedbackText($comnt);
38653870
}
3871+
3872+
if ($teacherAudio) {
3873+
echo $teacherAudio;
3874+
}
38663875
}
38673876

38683877
if ($show_results) {
@@ -4154,4 +4163,55 @@ public static function getFeedbackText($message)
41544163
//return '<div id="question_feedback">'.$message.'</div>';
41554164
return Display::return_message($message, 'warning', false);
41564165
}
4166+
4167+
/**
4168+
* Get the recorder audio component for save a teacher audio feedback
4169+
* @param int $attemptId
4170+
* @param int $questionId
4171+
* @param int $userId
4172+
* @return string
4173+
*/
4174+
public static function getOralFeedbackForm($attemptId, $questionId, $userId)
4175+
{
4176+
$view = new Template('', false, false, false, false, false, false);
4177+
$view->assign('user_id', $userId);
4178+
$view->assign('question_id', $questionId);
4179+
$view->assign('directory', "/../exercises/teacher_audio/$attemptId/");
4180+
$view->assign('file_name', "{$questionId}_{$userId}");
4181+
$template = $view->get_template('exercise/oral_expression.tpl');
4182+
4183+
return $view->fetch($template);
4184+
}
4185+
4186+
/**
4187+
* Get the audio componen for a teacher audio feedback
4188+
* @param int $attemptId
4189+
* @param int $questionId
4190+
* @param int $userId
4191+
* @return string
4192+
*/
4193+
public static function getOralFeedbackAudio($attemptId, $questionId, $userId)
4194+
{
4195+
$courseInfo = api_get_course_info();
4196+
$sysCourseDir = api_get_path(SYS_COURSE_PATH).$courseInfo['path'];
4197+
$webCourseDir = api_get_path(WEB_COURSE_PATH).$courseInfo['path'];
4198+
$fileName = "{$questionId}_{$userId}";
4199+
$filePath = null;
4200+
4201+
if (file_exists("$sysCourseDir/exercises/teacher_audio/$attemptId/$fileName.ogg")) {
4202+
$filePath = "$webCourseDir/exercises/teacher_audio/$attemptId/$fileName.ogg";
4203+
} elseif (file_exists("$sysCourseDir/exercises/teacher_audio/$attemptId/$fileName.wav.wav")) {
4204+
$filePath = "$webCourseDir/exercises/teacher_audio/$attemptId/$fileName.wav.wav";
4205+
}
4206+
4207+
if (!$filePath) {
4208+
return '';
4209+
}
4210+
4211+
return Display::tag(
4212+
'audio',
4213+
null,
4214+
['src' => $filePath]
4215+
);
4216+
}
41574217
}

main/install/configuration.dist.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,8 @@
508508
// Add option in exercise to show or hide the "previous" button.
509509
//ALTER TABLE c_quiz ADD show_previous_button TINYINT(1) DEFAULT 1;
510510
//$_configuration['allow_quiz_show_previous_button_setting'] = false;
511+
// Allow to teachers review exercises question with audio notes
512+
//$_configuration["allow_teacher_comment_audio"] = false;
511513
// ------
512514
// Hide search form in session list
513515
//$_configuration['hide_search_form_in_session_list'] = false;

0 commit comments

Comments
 (0)