Move student publications settings in the course settings page #2523

Requires testings
pull/2573/head
Julio 7 years ago
parent 6bc8f3eecf
commit cb8e321862
  1. 60
      main/course_info/infocours.php
  2. 1
      main/inc/lib/course.lib.php
  3. 109
      main/work/work.lib.php
  4. 32
      main/work/work.php

@ -948,6 +948,48 @@ $form->addHtml('
');
$form->addHtml('</div>');
// Student publication
$form->addHtml('<div class="panel panel-default">');
$form->addHtml('
<div class="panel-heading" role="tab" id="heading-student-publication-settings">
<h4 class="panel-title">
<a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion"
href="#collapse-student-publication-settings" aria-expanded="false" aria-controls="collapse-student-publication-settings">
');
$form->addHtml(
Display::return_icon('work.png', get_lang('StudentPublications')).' '.get_lang('StudentPublications')
);
$form->addHtml('
</a>
</h4>
</div>
');
$form->addHtml('
<div id="collapse-student-publication-settings" class="panel-collapse collapse" role="tabpanel"
aria-labelledby="heading-student-publication-settings">
<div class="panel-body">
');
$group = [
$form->createElement('radio', 'show_score', null, get_lang('NewVisible'), 0),
$form->createElement('radio', 'show_score', null, get_lang('NewUnvisible'), 1),
];
$form->addGroup($group, '', get_lang('DefaultUpload'));
$group = [
$form->createElement('radio', 'student_delete_own_publication', null, get_lang('Yes'), 1),
$form->createElement('radio', 'student_delete_own_publication', null, get_lang('No'), 0),
];
$form->addGroup($group, '', get_lang('StudentAllowedToDeleteOwnPublication'));
$form->addButtonSave(get_lang('SaveSettings'), 'submit_save');
$form->addHtml('
</div>
</div>
');
$form->addHtml('</div>');
// Plugin course settings
$appPlugin = new AppPlugin();
$appPlugin->add_course_settings_form($form);
@ -970,6 +1012,7 @@ $values['unsubscribe'] = $_course['unsubscribe'];
$values['course_registration_password'] = $all_course_information['registration_code'];
$values['legal'] = $all_course_information['legal'];
$values['activate_legal'] = $all_course_information['activate_legal'];
$values['show_score'] = $all_course_information['show_score'];
$courseSettings = CourseManager::getCourseSettingVariables($appPlugin);
@ -1043,22 +1086,6 @@ if ($form->validate() && is_settings_editable()) {
unset($updateValues['pdf_export_watermark_path']);
}
// Variables that will be saved in the TABLE_MAIN_COURSE table
$update_in_course_table = [
'title',
'course_language',
'category_code',
'department_name',
'department_url',
'visibility',
'subscribe',
'unsubscribe',
'tutor_name',
'course_registration_password',
'legal',
'activate_legal',
];
$activeLegal = isset($updateValues['activate_legal']) ? $updateValues['activate_legal'] : 0;
$table_course = Database::get_main_table(TABLE_MAIN_COURSE);
@ -1074,6 +1101,7 @@ if ($form->validate() && is_settings_editable()) {
'legal' => $updateValues['legal'],
'activate_legal' => $activeLegal,
'registration_code' => $updateValues['course_registration_password'],
'show_score' => $updateValues['show_score'],
];
Database::update($table_course, $params, ['id = ?' => $courseId]);

@ -5535,6 +5535,7 @@ class CourseManager
'enable_forum_auto_launch',
'show_course_in_user_language',
'email_to_teachers_on_new_work_feedback',
'student_delete_own_publication',
];
$courseModels = ExerciseLib::getScoreModels();

@ -56,17 +56,7 @@ function displayWorkActionLinks($id, $action, $isTutor)
}
}
if (api_is_allowed_to_edit(null, true) && $origin != 'learnpath') {
if (empty($id)) {
// Options
$output .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&action=settings">';
$output .= Display::return_icon(
'settings.png',
get_lang('EditToolOptions'),
'',
ICON_SIZE_MEDIUM
).'</a>';
}
if (api_is_allowed_to_edit(null, true) && $origin != 'learnpath' && $action == 'list') {
$output .= '<a id="open-view-list" href="#">'.
Display::return_icon(
'listwork.png',
@ -84,45 +74,6 @@ function displayWorkActionLinks($id, $action, $isTutor)
}
}
/**
* Returns a form displaying all options for this tool.
* These are
* - make all files visible / invisible
* - set the default visibility of uploaded files.
*
* @param $defaults
*
* @return string The HTML form
*/
function settingsForm($defaults)
{
$allowed = api_is_allowed_to_edit(null, true);
if (!$allowed) {
return;
}
$url = api_get_path(WEB_CODE_PATH).'work/work.php?'.api_get_cidreq().'&action=settings';
$form = new FormValidator('edit_settings', 'post', $url);
$form->addElement('hidden', 'changeProperties', 1);
$form->addElement('header', get_lang('EditToolOptions'));
$group = [
$form->createElement('radio', 'show_score', null, get_lang('NewVisible'), 0),
$form->createElement('radio', 'show_score', null, get_lang('NewUnvisible'), 1),
];
$form->addGroup($group, '', get_lang('DefaultUpload'));
$group = [
$form->createElement('radio', 'student_delete_own_publication', null, get_lang('Yes'), 1),
$form->createElement('radio', 'student_delete_own_publication', null, get_lang('No'), 0),
];
$form->addGroup($group, '', get_lang('StudentAllowedToDeleteOwnPublication'));
$form->addButtonSave(get_lang('Save'));
$form->setDefaults($defaults);
return $form->returnForm();
}
/**
* @param string $path
* @param int $courseId
@ -4721,64 +4672,6 @@ function getUploadDocumentType()
];
}
/**
* @param array $courseInfo
* @param bool $showScore
* @param bool $studentDeleteOwnPublication
*
* @return bool
*/
function updateSettings($courseInfo, $showScore, $studentDeleteOwnPublication)
{
$showScore = (int) $showScore;
$courseId = api_get_course_int_id();
$main_course_table = Database::get_main_table(TABLE_MAIN_COURSE);
$table_course_setting = Database::get_course_table(TOOL_COURSE_SETTING);
if (empty($courseId)) {
return false;
}
$query = "UPDATE $main_course_table
SET show_score = '$showScore'
WHERE id = $courseId";
Database::query($query);
/**
* Course data are cached in session so we need to update both the database
* and the session data.
*/
$courseInfo['show_score'] = $showScore;
Session::write('_course', $courseInfo);
// changing the tool setting: is a student allowed to delete his/her own document
// counting the number of occurrences of this setting (if 0 => add, if 1 => update)
$query = "SELECT * FROM $table_course_setting
WHERE
c_id = $courseId AND
variable = 'student_delete_own_publication'";
$result = Database::query($query);
$number_of_setting = Database::num_rows($result);
if ($number_of_setting == 1) {
$query = "UPDATE $table_course_setting SET
value = '".Database::escape_string($studentDeleteOwnPublication)."'
WHERE variable = 'student_delete_own_publication' AND c_id = $courseId";
Database::query($query);
} else {
$params = [
'c_id' => $courseId,
'variable' => 'student_delete_own_publication',
'value' => $studentDeleteOwnPublication,
'category' => 'work',
];
Database::insert($table_course_setting, $params);
}
return true;
}
/**
* @param int $item_id
* @param array $course_info

@ -90,7 +90,7 @@ if (!empty($groupId)) {
} else {
if ($origin != 'learnpath') {
if (isset($_GET['id']) &&
!empty($_GET['id']) || $display_upload_form || $action == 'settings' || $action == 'create_dir'
!empty($_GET['id']) || $display_upload_form || $action == 'create_dir'
) {
$interbreadcrumb[] = [
'url' => api_get_path(WEB_CODE_PATH).'work/work.php?'.api_get_cidreq(),
@ -110,9 +110,7 @@ if (!empty($groupId)) {
if ($action == 'upload_form') {
$interbreadcrumb[] = ['url' => '#', 'name' => get_lang('UploadADocument')];
}
if ($action == 'settings') {
$interbreadcrumb[] = ['url' => '#', 'name' => get_lang('EditToolOptions')];
}
if ($action == 'create_dir') {
$interbreadcrumb[] = ['url' => '#', 'name' => get_lang('CreateAssignment')];
}
@ -145,32 +143,6 @@ $content = null;
// For teachers
switch ($action) {
case 'settings':
//if posts
if ($is_allowed_to_edit && !empty($_POST['changeProperties'])) {
updateSettings(
$courseInfo,
$_POST['show_score'],
$_POST['student_delete_own_publication']
);
Display::addFlash(Display::return_message(get_lang('Saved'), 'success'));
header('Location: '.$currentUrl);
exit;
}
if (!$is_allowed_to_edit) {
api_not_allowed(true);
}
$studentDeleteOwnPublication = api_get_course_setting('student_delete_own_publication') == 1 ? 1 : 0;
/* Display of tool options */
$content = settingsForm(
[
'show_score' => $courseInfo['show_score'],
'student_delete_own_publication' => $studentDeleteOwnPublication,
]
);
break;
case 'add':
case 'create_dir':
if (!($is_allowed_to_edit || $isTutor)) {

Loading…
Cancel
Save