Internal: Fix session tutor general course errors - refs BT#21542

pull/5402/head
christianbeeznst 2 years ago
parent 192cccb4dc
commit d9088d58e0
  1. 22
      assets/css/app.scss
  2. 14
      public/main/announcements/announcements.php
  3. 4
      public/main/exercise/exercise_report.php
  4. 2
      public/main/exercise/exercise_show.php
  5. 6
      public/main/gradebook/lib/be/category.class.php
  6. 6
      public/main/gradebook/lib/fe/displaygradebook.php
  7. 58
      public/main/gradebook/lib/fe/gradebooktable.class.php
  8. 13
      public/main/inc/ajax/model.ajax.php
  9. 125
      public/main/inc/lib/AnnouncementManager.php
  10. 15
      public/main/inc/lib/formvalidator/Element/DateTimePicker.php
  11. 2
      public/main/inc/lib/pear/HTML/QuickForm/advmultiselect.php
  12. 8
      public/main/inc/lib/webservices/Rest.php

@ -599,6 +599,28 @@ form .field {
textarea {
width: 100%;
}
.freeze {
display: block;
padding-top: 10px;
}
.freeze + label,
.html-editor-container + label,
.advmultiselect + label {
font-size: 13px;
@apply absolute top-0 left-0 text-support-3 text-caption px-1 bg-white text-primary;
}
}
.flatpickr-calendar .flatpickr-validate-btn {
margin-top: 10px;
width: 100%;
padding: 5px;
background-color: #569ff7;
border: none;
cursor: pointer;
color: #ffffff;
}
//@import 'primevue-md-light-indigo/theme.css';

@ -199,28 +199,28 @@ switch ($action) {
[
'name' => 'title',
'index' => 'title',
'width' => '300',
'width' => '400px',
'align' => 'left',
'sortable' => 'false',
],
[
'name' => 'username',
'index' => 'username',
'width' => '100',
'width' => '350px',
'align' => 'left',
'sortable' => 'false',
],
[
'name' => 'lastedit_date',
'index' => 'lastedit_date',
'width' => '200',
'width' => '350px',
'align' => 'left',
'sortable' => 'false',
],
[
'name' => 'actions',
'index' => 'actions',
'width' => '150',
'width' => '150px',
'align' => 'left',
'sortable' => 'false',
],
@ -262,11 +262,7 @@ switch ($action) {
});
</script>';
$count = AnnouncementManager::getAnnouncements(
$token,
$announcement_number,
true
);
$count = AnnouncementManager::getNumberAnnouncements();
if (empty($count)) {
$html = '';

@ -59,7 +59,7 @@ $TBL_TRACK_ATTEMPT = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
$TBL_LP_ITEM_VIEW = Database::get_course_table(TABLE_LP_ITEM_VIEW);
$allowCoachFeedbackExercises = 'true' === api_get_setting('allow_coach_feedback_exercises');
$course_id = api_get_course_int_id();
$exercise_id = isset($_REQUEST['exerciseId']) ? (int) $_REQUEST['exerciseId'] : 0;
$exercise_id = isset($_REQUEST['exerciseId']) ? (int) $_REQUEST['exerciseId'] : (isset($_GET['id']) ? (int) $_GET['id'] : 0);
$locked = api_resource_is_locked_by_gradebook($exercise_id, LINK_EXERCISE);
$sessionId = api_get_session_id();
@ -408,7 +408,7 @@ if (isset($_REQUEST['comments']) &&
$sql = "UPDATE $TBL_LP_ITEM_VIEW
SET score = '".(float) $tot."'
$statusCondition
WHERE c_id = $course_id AND iid = $lp_item_view_id";
WHERE iid = $lp_item_view_id";
Database::query($sql);
header('Location: '.api_get_path(WEB_CODE_PATH).'exercise/exercise_show.php?id='.$id.'&student='.$student_id.'&'.api_get_cidreq());

@ -865,7 +865,7 @@ foreach ($questionList as $questionId) {
} // end of large foreach on questions
// Display the text when finished message if we are on a LP #4227
$end_of_message = $objExercise->getFinishText();
$end_of_message = $objExercise->getFinishText($totalScore, $totalWeighting);
if (!empty($end_of_message) && ('learnpath' === $origin)) {
echo Display::return_message($end_of_message, 'normal', false);
echo "<div class='clear'>&nbsp;</div>";

@ -463,6 +463,10 @@ class Category implements GradebookItem
$bond = ' AND';
}
if (!isset($session_id)) {
$session_id = api_get_session_id();
}
if (empty($session_id)) {
$sql .= $bond.' (session_id IS NULL OR session_id = 0) ';
} else {
@ -1466,7 +1470,7 @@ class Category implements GradebookItem
{
$tbl_main_courses = Database::get_main_table(TABLE_MAIN_COURSE);
$tbl_main_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
$sql = 'SELECT DISTINCT(code), title, id
$sql = 'SELECT DISTINCT(code), title, cc.id
FROM '.$tbl_main_courses.' cc, '.$tbl_main_course_user.' cu
WHERE cc.id = cu.c_id AND cu.status = '.COURSEMANAGER;
if (!api_is_platform_admin()) {

@ -383,7 +383,7 @@ class DisplayGradebook
Display::getMdiIcon('table-plus', 'ch-tool-icon', null, ICON_SIZE_MEDIUM, get_lang('Add classroom activity')).'</a>';
$cats = Category::load($selectcat);
if (!empty($cats[0]->getCourseId()) && empty($messageResource)) {
if (isset($cats[0]) && !empty($cats[0]->getCourseId()) && empty($messageResource)) {
$actionsLeft .= '<a href="gradebook_add_link.php?'.$my_api_cidreq.'&selectcat='.$catobj->get_id().'">'.
Display::getMdiIcon('link-plus', 'ch-tool-icon', null, ICON_SIZE_MEDIUM, get_lang('Add online activity')).'</a>';
} else {
@ -426,7 +426,7 @@ class DisplayGradebook
// Right icons
if ($accessToEdit) {
$actionsRight = '<a href="gradebook_edit_cat.php?editcat='.$catobj->get_id(
).'&cid='.$catobj->getCourseId().'&id_session='.$catobj->get_session_id().'">'.
).'&cid='.$catobj->getCourseId().'&sid='.$catobj->get_session_id().'">'.
Display::getMdiIcon(ActionIcon::EDIT, 'ch-tool-icon', null, ICON_SIZE_MEDIUM, get_lang('Edit')).'</a>';
if ('true' == api_get_plugin_setting('customcertificate', 'enable_plugin_customcertificate') &&
@ -504,7 +504,7 @@ class DisplayGradebook
}
$min_certification = get_lang('Minimum certification score').' : '.$min_certification;
$edit_icon = '<a href="gradebook_edit_cat.php?editcat='.$catobj->get_id().'&cid='.$catobj->getCourseId().'&id_session='.$catobj->get_session_id().'">'.
$edit_icon = '<a href="gradebook_edit_cat.php?editcat='.$catobj->get_id().'&cid='.$catobj->getCourseId().'&sid='.$catobj->get_session_id().'">'.
Display::getMdiIcon(ActionIcon::EDIT, 'ch-tool-icon', null, ICON_SIZE_MEDIUM, get_lang('Edit')).'</a>';
$msg = $weight.' - '.$min_certification.$edit_icon;

@ -947,37 +947,39 @@ class GradebookTable extends SortableTable
) {
$id_cat = (int) $_GET['selectcat'];
$category = Category::load($id_cat);
$weight_category = (int) $this->build_weight($category[0]);
$course_code = $this->build_course_code($category[0]);
$localCourseInfo = api_get_course_info($course_code);
$localCourseId = $localCourseInfo['real_id'];
$weight_total_links = round($weight_total_links);
if ($weight_total_links > $weight_category ||
$weight_total_links < $weight_category ||
$weight_total_links > $weight_category
) {
$warning_message = sprintf(get_lang('The sum of all weights of activities must be %s'), $weight_category);
$modify_icons =
'<a href="gradebook_edit_cat.php?editcat='.$id_cat.'&cid='.$localCourseId.'&sid='.api_get_session_id().'">'.
Display::getMdiIcon(ActionIcon::EDIT, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Edit'), ['alt' => $warning_message]);
$warning_message .= $modify_icons;
echo Display::return_message($warning_message, 'warning', false);
}
if (isset($category[0])) {
$weight_category = (int) $this->build_weight($category[0]);
$course_code = $this->build_course_code($category[0]);
$localCourseInfo = api_get_course_info($course_code);
$localCourseId = $localCourseInfo['real_id'];
$weight_total_links = round($weight_total_links);
if ($weight_total_links > $weight_category ||
$weight_total_links < $weight_category ||
$weight_total_links > $weight_category
) {
$warning_message = sprintf(get_lang('The sum of all weights of activities must be %s'), $weight_category);
$modify_icons =
'<a href="gradebook_edit_cat.php?editcat='.$id_cat.'&cid='.$localCourseId.'&sid='.api_get_session_id().'">'.
Display::getMdiIcon(ActionIcon::EDIT, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Edit'), ['alt' => $warning_message]);
$warning_message .= $modify_icons;
echo Display::return_message($warning_message, 'warning', false);
}
$content_html = DocumentManager::replace_user_info_into_html(
api_get_user_id(),
$localCourseInfo,
api_get_session_id()
);
$content_html = DocumentManager::replace_user_info_into_html(
api_get_user_id(),
$localCourseInfo,
api_get_session_id()
);
if (!empty($content_html)) {
$new_content = explode('</head>', $content_html['content']);
}
if (!empty($content_html)) {
$new_content = explode('</head>', $content_html['content']);
}
if (empty($new_content[0])) {
// Set default certificate
DocumentManager::generateDefaultCertificate($localCourseInfo);
if (empty($new_content[0])) {
// Set default certificate
DocumentManager::generateDefaultCertificate($localCourseInfo);
}
}
}

@ -16,6 +16,8 @@ require_once __DIR__.'/../global.inc.php';
$action = $_GET['a'];
$page = (int) $_REQUEST['page']; //page
$limit = (int) $_REQUEST['rows']; //quantity of rows
$cid = isset($_REQUEST['cid']) ? (int) $_REQUEST['cid'] : null;
$sid = isset($_REQUEST['sid']) ? (int) $_REQUEST['sid'] : null;
// Makes max row persistence after refreshing the grid
$savedRows = Session::read('max_rows_'.$action);
@ -551,7 +553,7 @@ switch ($action) {
$count = $skill->getUserListSkillRankingCount();
break;
case 'get_course_announcements':
$count = AnnouncementManager::getNumberAnnouncements();
$count = AnnouncementManager::getNumberAnnouncements($cid, $sid);
break;
case 'get_work_teacher':
$count = getWorkListTeacher(0, $limit, null, null, $whereCondition, true);
@ -1371,13 +1373,8 @@ switch ($action) {
$result = AnnouncementManager::getAnnouncements(
null,
null,
false,
$start,
$limit,
$sidx,
$sord,
$titleToSearch,
$userIdToSearch
$cid,
$sid
);
break;

@ -1336,51 +1336,35 @@ class AnnouncementManager
/**
* @param $stok
* @param $announcement_number
* @param bool $getCount
* @param null $start
* @param null $limit
* @param string $sidx
* @param string $sord
* @param string $titleToSearch
* @param int $userIdToSearch
* @param int $userId
* @param int $courseId
* @param int $sessionId
* @param int $courseId
* @param int $sessionId
*
* @return array
*/
public static function getAnnouncements(
$stok,
$announcement_number,
$getCount = false,
$start = null,
$limit = null,
$sidx = '',
$sord = '',
$titleToSearch = '',
$userIdToSearch = 0,
$userId = 0,
$courseId = 0,
$sessionId = 0
) {
$group_id = api_get_group_id();
$session_id = $sessionId ?: api_get_session_id();
if (empty($courseId)) {
$courseInfo = api_get_course_info();
$courseId = $courseInfo['real_id'];
} else {
$courseId = (int) $courseId;
$courseInfo = api_get_course_info_by_id($courseId);
}
?int $courseId = null,
?int $sessionId = null
): array {
$groupId = api_get_group_id();
if (empty($courseInfo)) {
return [];
if (null === $courseId) {
$courseId = api_get_course_int_id();
}
if (null === $sessionId) {
$sessionId = api_get_session_id();
}
$repo = Container::getAnnouncementRepository();
$course = api_get_course_entity($courseId);
$session = api_get_session_entity($session_id);
$group = api_get_group_entity(api_get_group_id());
if (null === $course) {
return [];
}
$session = api_get_session_entity($sessionId);
$group = api_get_group_entity($groupId);
if (api_is_allowed_to_edit(false, true)) {
$qb = $repo->getResourcesByCourse($course, $session, $group, null, true, true);
@ -1398,7 +1382,8 @@ class AnnouncementManager
$bottomAnnouncement = $announcement_number;
$displayed = [];
$actionUrl = api_get_path(WEB_CODE_PATH).'announcements/announcements.php?'.api_get_cidreq();
$cidReq = 'cid='.$courseId.'&sid='.$sessionId.'&gid='.$groupId;
$actionUrl = api_get_path(WEB_CODE_PATH).'announcements/announcements.php?'.$cidReq;
$emailIcon = Display::getMdiIcon(StateIcon::MAIL_NOTIFICATION, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Announcement sent by e-mail'));
$attachmentIcon = Display::getMdiIcon(ObjectIcon::ATTACHMENT, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Attachment'));
@ -1478,16 +1463,6 @@ class AnnouncementManager
get_lang('Down')
);
/*$isTutor = false;
if (!empty($group_id)) {
$groupInfo = GroupManager::get_group_properties(api_get_group_id());
//User has access in the group?
$isTutor = GroupManager::is_tutor_of_group(
api_get_user_id(),
$groupInfo
);
}*/
$results = [];
/** @var CAnnouncement $announcement */
foreach ($announcements as $announcement) {
@ -1503,7 +1478,7 @@ class AnnouncementManager
$disableEdit = false;
$to = [];
$separated = AbstractResource::separateUsersGroups($to);
if (!empty($group_id)) {
if (!empty($groupId)) {
// If the announcement was sent to many groups, disable edition inside a group
if (isset($separated['groups']) && count($separated['groups']) > 1) {
$disableEdit = true;
@ -1515,7 +1490,7 @@ class AnnouncementManager
}
// Announcement sent to only a user
if ($separated['groups'] > 1 && !in_array($group_id, $separated['groups'])) {
if ($separated['groups'] > 1 && !in_array($groupId, $separated['groups'])) {
$disableEdit = true;
}
} else {
@ -1525,12 +1500,6 @@ class AnnouncementManager
}
$title = $announcement->getTitle().$groupReference.$sent_to_icon;
/*$item_visibility = api_get_item_visibility(
$courseInfo,
TOOL_ANNOUNCEMENT,
$row['id'],
$session_id
);*/
$visibility = $announcement->isVisible($course, $session);
// show attachment list
@ -1554,14 +1523,6 @@ class AnnouncementManager
$actionUrl.'&action=view&id='.$announcementId
);
// we can edit if : we are the teacher OR the element belongs to
// the session we are coaching OR the option to allow users to edit is on
/*if api_is_allowed_to_edit(false, true) ||
(api_is_session_general_coach() && api_is_element_in_the_session(TOOL_ANNOUNCEMENT, $announcementId)) ||
(api_get_course_setting('allow_user_edit_announcement') && !api_is_anonymous()) ||
($isTutor)
//$row['to_group_id'] == $group_id &&
) {*/
if ($repo->isGranted(ResourceNodeVoter::EDIT, $announcement)) {
if (true === $disableEdit) {
$modify_icons = $editIconDisable;
@ -1644,45 +1605,23 @@ class AnnouncementManager
/**
* @return int
*/
public static function getNumberAnnouncements()
public static function getNumberAnnouncements(?int $courseId = null, ?int $sessionId = null): int
{
$session_id = api_get_session_id();
$courseInfo = api_get_course_info();
$courseId = $courseInfo['real_id'];
$userId = api_get_user_id();
if (null === $courseId) {
$courseId = api_get_course_int_id();
}
if (null === $sessionId) {
$sessionId = api_get_session_id();
}
$userId = api_get_user_id();
$repo = Container::getAnnouncementRepository();
$course = api_get_course_entity($courseId);
$session = api_get_session_entity($session_id);
$session = api_get_session_entity($sessionId);
$group = api_get_group_entity(api_get_group_id());
if (api_is_allowed_to_edit(false, true)) {
// check teacher status
if (empty($_GET['origin']) || 'learnpath' !== $_GET['origin']) {
/*if (0 == api_get_group_id()) {
$group_condition = '';
} else {
$group_condition = " AND (ip.to_group_id='".api_get_group_id()."' OR ip.to_group_id = 0 OR ip.to_group_id IS NULL)";
}
$sql = "SELECT
announcement.*,
ip.visibility,
ip.to_group_id,
ip.insert_user_id
FROM $tbl_announcement announcement
INNER JOIN $tbl_item_property ip
ON (announcement.c_id = ip.c_id AND announcement.id = ip.ref)
WHERE
announcement.c_id = $courseId AND
ip.c_id = $courseId AND
ip.tool = 'announcement' AND
ip.visibility <> '2'
$group_condition
$condition_session
GROUP BY ip.ref
ORDER BY display_order DESC
LIMIT 0, $maximum";*/
$qb = $repo->getResourcesByCourse($course, $session, $group);
$qb->select('count(resource)');
@ -1700,5 +1639,7 @@ class AnnouncementManager
return $qb->getQuery()->getSingleScalarResult();
}
return 0;
}
}

@ -79,14 +79,25 @@ class DateTimePicker extends HTML_QuickForm_text
$js = $localeScript . "<script>
document.addEventListener('DOMContentLoaded', function () {
flatpickr('#{$id}', {
const fp = flatpickr('#{$id}', {
locale: '{$localeCode}',
altInput: true,
altFormat: '".get_lang('F d, Y')." ".get_lang('at')." H:i',
enableTime: true,
dateFormat: 'Y-m-d H:i',
time_24hr: true,
wrap: false
wrap: false,
onReady: function(selectedDates, dateStr, instance) {
const validateButton = document.createElement('button');
validateButton.textContent = '".get_lang('Validate')."';
validateButton.className = 'flatpickr-validate-btn';
validateButton.type = 'button';
validateButton.onclick = function() {
instance.close();
};
instance.calendarContainer.appendChild(validateButton);
}
});
document.querySelector('label[for=\"' + '{$id}' + '\"]').classList.add('datepicker-label');

@ -473,7 +473,7 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select
} else {
$this->_elementTemplate = '
{javascript}
<div class="grid grid-cols-3">
<div class="grid grid-cols-3 advmultiselect">
<div><!-- BEGIN label_2 -->{label_2}<!-- END label_2 --> {unselected}</div>
<div><div class="text-center">{add}{remove}</div></div>
<div><!-- BEGIN label_3 -->{label_3}<!-- END label_3 -->{selected}</div>

@ -464,14 +464,6 @@ class Rest extends WebService
$announcements = AnnouncementManager::getAnnouncements(
null,
null,
false,
null,
null,
null,
null,
null,
0,
$this->user->getId(),
$this->course->getId(),
$sessionId
);

Loading…
Cancel
Save