Replace custom queries with entities

pull/3844/head
Julio Montoya 5 years ago
parent a7beb2feaf
commit 78c3b48f31
  1. 10
      public/main/admin/user_move_stats.php
  2. 7
      public/main/announcements/announcements.php
  3. 41
      public/main/cron/check_lp_total_time.php
  4. 4
      public/main/dropbox/dropbox_functions.inc.php
  5. 6
      public/main/group/member_settings.php
  6. 14
      public/main/group/tutor_settings.php
  7. 4
      public/main/inc/ajax/myspace.ajax.php
  8. 23
      public/main/inc/lib/certificate.lib.php
  9. 54
      public/main/inc/lib/course.lib.php
  10. 71
      public/main/inc/lib/groupmanager.lib.php
  11. 8
      public/main/inc/lib/myspace.lib.php
  12. 7
      public/main/inc/lib/sortable_table.class.php
  13. 62
      public/main/inc/lib/tracking.lib.php
  14. 25
      public/main/lp/learnpath.class.php
  15. 4
      public/main/lp/lp_report.php
  16. 7
      public/main/lp/scorm.class.php
  17. 4
      public/main/mySpace/course.php
  18. 66
      public/main/mySpace/myStudents.php
  19. 5
      public/main/tracking/lp_report.php
  20. 26
      public/main/tracking/total_time.php
  21. 12
      public/main/webservices/lp.php
  22. 3
      public/main/wiki/wiki.inc.php
  23. 84
      public/main/work/student_work.php
  24. 76
      public/main/work/work.lib.php
  25. 14
      public/main/work/work_list.php
  26. 4
      public/main/work/work_list_all.php
  27. 7
      src/CourseBundle/Entity/CGlossary.php
  28. 10
      src/CourseBundle/Entity/CGroup.php
  29. 5
      src/CourseBundle/Entity/CSurvey.php
  30. 21
      src/CourseBundle/Repository/CStudentPublicationRepository.php

@ -86,7 +86,6 @@ if (isset($_REQUEST['load_ajax'])) {
} }
//} //}
$user_id = (int) $_REQUEST['user_id']; $user_id = (int) $_REQUEST['user_id'];
$new_course_list = SessionManager::get_course_list_by_session_id($new_session_id); $new_course_list = SessionManager::get_course_list_by_session_id($new_session_id);
$course_founded = false; $course_founded = false;
@ -123,6 +122,7 @@ if (isset($_REQUEST['load_ajax'])) {
// Begin with the import process // Begin with the import process
$course_info = api_get_course_info($origin_course_code); $course_info = api_get_course_info($origin_course_code);
$course_id = $course_info['real_id']; $course_id = $course_info['real_id'];
$course = api_get_course_entity($course_id);
$TABLETRACK_EXERCICES = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES); $TABLETRACK_EXERCICES = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
$TBL_TRACK_ATTEMPT = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT); $TBL_TRACK_ATTEMPT = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
@ -288,15 +288,15 @@ if (isset($_REQUEST['load_ajax'])) {
//Getting all information of that lp_item_id //Getting all information of that lp_item_id
$score = Tracking::get_avg_student_score( $score = Tracking::get_avg_student_score(
$user_id, $user_id,
$origin_course_code, $course,
[$data['lp_id']], [$data['lp_id']],
$origin_session_id $session
); );
$progress = Tracking::get_avg_student_progress( $progress = Tracking::get_avg_student_progress(
$user_id, $user_id,
$origin_course_code, $course,
[$data['lp_id']], [$data['lp_id']],
$origin_session_id $session
); );
$result_message['LP_VIEW'][$data['lp_id']] = [ $result_message['LP_VIEW'][$data['lp_id']] = [
'score' => $score, 'score' => $score,

@ -51,14 +51,13 @@ $tbl_item_property = Database::get_course_table(TABLE_ITEM_PROPERTY);
$isTutor = false; $isTutor = false;
if (!empty($group_id)) { if (!empty($group_id)) {
$groupEntity = api_get_group_entity($group_id); $groupEntity = api_get_group_entity($group_id);
$groupProperties = GroupManager::get_group_properties($group_id);
$interbreadcrumb[] = [ $interbreadcrumb[] = [
'url' => api_get_path(WEB_CODE_PATH).'group/group.php?'.api_get_cidreq(), 'url' => api_get_path(WEB_CODE_PATH).'group/group.php?'.api_get_cidreq(),
'name' => get_lang('Groups'), 'name' => get_lang('Groups'),
]; ];
$interbreadcrumb[] = [ $interbreadcrumb[] = [
'url' => api_get_path(WEB_CODE_PATH).'group/group_space.php?'.api_get_cidreq(), 'url' => api_get_path(WEB_CODE_PATH).'group/group_space.php?'.api_get_cidreq(),
'name' => get_lang('Group area').' '.$groupProperties['name'], 'name' => get_lang('Group area').' '.$groupEntity->getName(),
]; ];
if (false === $allowToEdit) { if (false === $allowToEdit) {
@ -68,7 +67,7 @@ if (!empty($group_id)) {
$allowToEdit = true; $allowToEdit = true;
} }
// Last chance ... students can send announcements // Last chance ... students can send announcements
if (GroupManager::TOOL_PRIVATE_BETWEEN_USERS == $groupProperties['announcements_state']) { if (GroupManager::TOOL_PRIVATE_BETWEEN_USERS == $groupEntity->getAnnouncementsState()) {
$allowStudentInGroupToSend = true; $allowStudentInGroupToSend = true;
} }
} }
@ -488,7 +487,7 @@ switch ($action) {
} }
$element = CourseManager::addUserGroupMultiSelect($form, []); $element = CourseManager::addUserGroupMultiSelect($form, []);
} else { } else {
$element = CourseManager::addGroupMultiSelect($form, $groupProperties, []); $element = CourseManager::addGroupMultiSelect($form, $groupEntity, []);
} }
$form->addHtml('</div>'); $form->addHtml('</div>');

@ -1,12 +1,16 @@
<?php <?php
use Chamilo\CoreBundle\Entity\Course;
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
/** /*
* This script checks and propose a query fix for LP items with high time values * This script checks and propose a query fix for LP items with high time values
* Only if the total LP time is bigger than the total course time. * Only if the total LP time is bigger than the total course time.
*/ */
exit; exit;
require_once __DIR__.'/../../main/inc/global.inc.php'; require_once __DIR__.'/../../main/inc/global.inc.php';
api_protect_admin_script(); api_protect_admin_script();
@ -35,9 +39,8 @@ foreach ($sessions as $session) {
continue; continue;
} }
} }
$course = api_get_course_entity($courseId);
$courseInfo = api_get_course_info_by_id($courseId); $courseCode = $course->getCode();
$courseCode = $courseInfo['code'];
$users = CourseManager::get_user_list_from_course_code( $users = CourseManager::get_user_list_from_course_code(
$courseCode, $courseCode,
@ -48,9 +51,9 @@ foreach ($sessions as $session) {
); );
foreach ($users as $user) { foreach ($users as $user) {
$result = compareLpTimeAndCourseTime($user, $courseInfo, $sessionId); $result = compareLpTimeAndCourseTime($user, $course, $sessionId);
if ($result) { if ($result) {
$counter++; ++$counter;
} }
if ($counter > $max) { if ($counter > $max) {
@ -73,22 +76,22 @@ foreach($courses as $courseInfo) {
}*/ }*/
/** /**
* @param array $user * @param array $user
* @param array $courseInfo * @param Course $course
* @param int $sessionId * @param int $sessionId
* *
* @return bool * @return bool
*/ */
function compareLpTimeAndCourseTime($user, $courseInfo, $sessionId = 0) function compareLpTimeAndCourseTime($user, Course $course, $sessionId = 0)
{ {
$userId = $user['user_id']; $userId = $user['user_id'];
$defaultValue = 600; // 10 min $defaultValue = 600; // 10 min
$courseCode = $courseInfo['code']; $courseCode = $course->getCode();
$courseId = $courseInfo['real_id']; $courseId = $course->getId();
$totalLpTime = Tracking::get_time_spent_in_lp( $totalLpTime = Tracking::get_time_spent_in_lp(
$userId, $userId,
$courseCode, $course,
[], [],
$sessionId $sessionId
); );
@ -108,8 +111,8 @@ function compareLpTimeAndCourseTime($user, $courseInfo, $sessionId = 0)
$totalLpTimeFormatted = api_time_to_hms($totalLpTime); $totalLpTimeFormatted = api_time_to_hms($totalLpTime);
$diff = $totalLpTime - $totalCourseTime; $diff = $totalLpTime - $totalCourseTime;
$content = PHP_EOL."User: ".$user['user_id']." - Total course: $totalCourseTimeFormatted / Total LP: $totalLpTimeFormatted".PHP_EOL; $content = PHP_EOL.'User: '.$user['user_id']." - Total course: $totalCourseTimeFormatted / Total LP: $totalLpTimeFormatted".PHP_EOL;
$content .= PHP_EOL."Diff: ".api_time_to_hms($diff).PHP_EOL; $content .= PHP_EOL.'Diff: '.api_time_to_hms($diff).PHP_EOL;
$url = api_get_path(WEB_CODE_PATH).'mySpace/myStudents.php?student='.$userId.'&course='.$courseCode.'&id_session='.$sessionId; $url = api_get_path(WEB_CODE_PATH).'mySpace/myStudents.php?student='.$userId.'&course='.$courseCode.'&id_session='.$sessionId;
$content .= Display::url('Check', $url, ['target' => '_blank']); $content .= Display::url('Check', $url, ['target' => '_blank']);
$content .= PHP_EOL; $content .= PHP_EOL;
@ -135,15 +138,15 @@ function compareLpTimeAndCourseTime($user, $courseInfo, $sessionId = 0)
$lpId = $item['lp_id']; $lpId = $item['lp_id'];
$link = api_get_path(WEB_CODE_PATH).'mySpace/lp_tracking.php?cidReq='.$courseCode. $link = api_get_path(WEB_CODE_PATH).'mySpace/lp_tracking.php?cidReq='.$courseCode.
'&course='.$courseCode.'&origin=&lp_id='.$lpId.'&student_id='.$userId.'&id_session='.$sessionId; '&course='.$courseCode.'&origin=&lp_id='.$lpId.'&student_id='.$userId.'&id_session='.$sessionId;
$content .= "total_time to be reduced = ".api_time_to_hms($item['total_time']).PHP_EOL; $content .= 'total_time to be reduced = '.api_time_to_hms($item['total_time']).PHP_EOL;
$content .= Display::url('See report before update', $link, ['target' => '_blank']).PHP_EOL; $content .= Display::url('See report before update', $link, ['target' => '_blank']).PHP_EOL;
$content .= "SQL with possible fix:".PHP_EOL; $content .= 'SQL with possible fix:'.PHP_EOL;
if ($item['total_time'] < $defaultValue) { if ($item['total_time'] < $defaultValue) {
$content .= "Skip because total_time is too short. total_time: ".$item['total_time'].' value to rest'.$defaultValue.PHP_EOL; $content .= 'Skip because total_time is too short. total_time: '.$item['total_time'].' value to rest'.$defaultValue.PHP_EOL;
continue; continue;
} }
$content .= "UPDATE c_lp_item_view SET total_time = total_time - '$defaultValue' WHERE iid = ".$item['iid'].";".PHP_EOL.PHP_EOL; $content .= "UPDATE c_lp_item_view SET total_time = total_time - '$defaultValue' WHERE iid = ".$item['iid'].';'.PHP_EOL.PHP_EOL;
} }
} }
} }

@ -1045,8 +1045,8 @@ function store_add_dropbox($file = [], $work = null)
if (0 === strpos($rec, 'user_')) { if (0 === strpos($rec, 'user_')) {
$new_work_recipients[] = substr($rec, strlen('user_')); $new_work_recipients[] = substr($rec, strlen('user_'));
} elseif (0 === strpos($rec, 'group_')) { } elseif (0 === strpos($rec, 'group_')) {
$groupInfo = GroupManager::get_group_properties(substr($rec, strlen('group_'))); $group = api_get_group_entity(substr($rec, strlen('group_')));
$userList = GroupManager::get_subscribed_users($groupInfo); $userList = GroupManager::get_subscribed_users($group);
foreach ($userList as $usr) { foreach ($userList as $usr) {
if (!in_array($usr['user_id'], $new_work_recipients) && $usr['user_id'] != $_user['user_id']) { if (!in_array($usr['user_id'], $new_work_recipients) && $usr['user_id'] != $_user['user_id']) {
$new_work_recipients[] = $usr['user_id']; $new_work_recipients[] = $usr['user_id'];

@ -150,7 +150,7 @@ if (!empty($complete_user_list)) {
} }
// Group members // Group members
$group_member_list = GroupManager::get_subscribed_users($current_group); $group_member_list = GroupManager::get_subscribed_users($groupEntity);
$selected_users = []; $selected_users = [];
if (!empty($group_member_list)) { if (!empty($group_member_list)) {
@ -183,12 +183,12 @@ if ($form->validate()) {
} }
// Returning to the group area (note: this is inconsistent with the rest of chamilo) // Returning to the group area (note: this is inconsistent with the rest of chamilo)
$cat = GroupManager::get_category_from_group($current_group['iid']); $cat = GroupManager::get_category_from_group($group_id);
$categoryId = 0; $categoryId = 0;
if ($cat) { if ($cat) {
$categoryId = $cat['iid']; $categoryId = $cat['iid'];
} }
$max_member = $current_group['max_student']; $max_member = $groupEntity->getMaxStudent();
if (isset($_POST['group_members']) && if (isset($_POST['group_members']) &&
count($_POST['group_members']) > $max_member && count($_POST['group_members']) > $max_member &&

@ -2,6 +2,9 @@
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
use Chamilo\CoreBundle\Framework\Container;
use Chamilo\CourseBundle\Entity\CGroup;
require_once __DIR__.'/../inc/global.inc.php'; require_once __DIR__.'/../inc/global.inc.php';
$this_section = SECTION_COURSES; $this_section = SECTION_COURSES;
$current_course_tool = TOOL_GROUP; $current_course_tool = TOOL_GROUP;
@ -10,9 +13,8 @@ $current_course_tool = TOOL_GROUP;
api_protect_course_script(true); api_protect_course_script(true);
$group_id = api_get_group_id(); $group_id = api_get_group_id();
$groupRepo = \Chamilo\CoreBundle\Framework\Container::getGroupRepository(); $groupRepo = Container::getGroupRepository();
/** @var \Chamilo\CourseBundle\Entity\CGroup $groupEntity */ $groupEntity = api_get_group_entity($group_id);
$groupEntity = $groupRepo->find($group_id);
$current_group = GroupManager::get_group_properties($group_id); $current_group = GroupManager::get_group_properties($group_id);
$nameTools = get_lang('Edit this group'); $nameTools = get_lang('Edit this group');
@ -101,7 +103,7 @@ $complete_user_list = CourseManager::get_user_list_from_course_code(
$possible_users = []; $possible_users = [];
$userGroup = new UserGroup(); $userGroup = new UserGroup();
$subscribedUsers = GroupManager::get_subscribed_users($current_group); $subscribedUsers = GroupManager::get_subscribed_users($groupEntity);
if ($subscribedUsers) { if ($subscribedUsers) {
$subscribedUsers = array_column($subscribedUsers, 'user_id'); $subscribedUsers = array_column($subscribedUsers, 'user_id');
} }
@ -157,13 +159,13 @@ if ($form->validate()) {
$values = $form->exportValues(); $values = $form->exportValues();
// Storing the tutors (we first remove all the tutors and then add only those who were selected) // Storing the tutors (we first remove all the tutors and then add only those who were selected)
GroupManager::unsubscribe_all_tutors($current_group['iid']); GroupManager::unsubscribe_all_tutors($group_id);
if (isset($_POST['group_tutors']) && count($_POST['group_tutors']) > 0) { if (isset($_POST['group_tutors']) && count($_POST['group_tutors']) > 0) {
GroupManager::subscribeTutors($values['group_tutors'], $groupEntity); GroupManager::subscribeTutors($values['group_tutors'], $groupEntity);
} }
// Returning to the group area (note: this is inconsistent with the rest of chamilo) // Returning to the group area (note: this is inconsistent with the rest of chamilo)
$cat = GroupManager::get_category_from_group($current_group['iid']); $cat = GroupManager::get_category_from_group($group_id);
$categoryId = null; $categoryId = null;
$max_member = null; $max_member = null;
if (!empty($cat)) { if (!empty($cat)) {

@ -48,11 +48,13 @@ switch ($action) {
foreach ($sessionList as $session) { foreach ($sessionList as $session) {
$courses = $session['courses']; $courses = $session['courses'];
$sessionId = $session['session_id']; $sessionId = $session['session_id'];
$sessionEntity = api_get_session_entity($sessionId);
$session['session_name']; $session['session_name'];
$totalCourse = 0; $totalCourse = 0;
$totalSessionAverage = 0; $totalSessionAverage = 0;
foreach ($courses as &$course) { foreach ($courses as &$course) {
$average = Tracking::get_avg_student_progress($userId, $course['course_code'], [], $sessionId); $courseEntity = api_get_course_entity($course['real_id']);
$average = Tracking::get_avg_student_progress($userId, $courseEntity, [], $sessionEntity);
$totalSessionAverage += $average; $totalSessionAverage += $average;
$totalCourse++; $totalCourse++;
if (false !== $average) { if (false !== $average) {

@ -732,12 +732,9 @@ class Certificate extends Model
foreach ($sessions as $session) { foreach ($sessions as $session) {
$allCoursesApproved = []; $allCoursesApproved = [];
foreach ($session['courses'] as $course) { foreach ($session['courses'] as $course) {
$courseInfo = api_get_course_info_by_id($course['real_id']); $course = api_get_course_entity($course['real_id']);
$courseCode = $courseInfo['code']; $courseId = $course->getId();
$category = $gradeBookRepo->findOneBy(['course' => $course, 'session' => $session['session_id']]);
$category = $gradeBookRepo->findOneBy(
['course' => $course['real_id'], 'session' => $session['session_id']]
);
/*$gradebookCategories = Category::load( /*$gradebookCategories = Category::load(
null, null,
@ -758,25 +755,25 @@ class Certificate extends Model
// Find time spent in LP // Find time spent in LP
$timeSpent = Tracking::get_time_spent_in_lp( $timeSpent = Tracking::get_time_spent_in_lp(
$this->user_id, $this->user_id,
$courseCode, $course,
[], [],
$session['session_id'] $session['session_id']
); );
if (!isset($courseList[$course['real_id']])) { if (!isset($courseList[$courseId])) {
$courseList[$course['real_id']]['approved'] = false; $courseList[$courseId]['approved'] = false;
$courseList[$course['real_id']]['time_spent'] = 0; $courseList[$courseId]['time_spent'] = 0;
} }
if ($result) { if ($result) {
$courseList[$course['real_id']]['approved'] = true; $courseList[$courseId]['approved'] = true;
$coursesApproved[$course['real_id']] = $courseInfo['title']; $coursesApproved[$courseId] = $course->getTitle();
// Find time spent in LP // Find time spent in LP
//$totalTimeInLearningPaths += $timeSpent; //$totalTimeInLearningPaths += $timeSpent;
$allCoursesApproved[] = true; $allCoursesApproved[] = true;
} }
$courseList[$course['real_id']]['time_spent'] += $timeSpent; $courseList[$courseId]['time_spent'] += $timeSpent;
} }
} }

@ -428,7 +428,8 @@ class CourseManager
Database::query($sql); Database::query($sql);
// Erase user student publications (works) in the course - by André Boivin // Erase user student publications (works) in the course - by André Boivin
if (!empty($userList)) { // @todo this should be handled by doctrine.
/*if (!empty($userList)) {
foreach ($userList as $userId) { foreach ($userList as $userId) {
// Getting all work from user // Getting all work from user
$workList = getWorkPerUser($userId); $workList = getWorkPerUser($userId);
@ -444,7 +445,7 @@ class CourseManager
} }
} }
} }
} }*/
// Unsubscribe user from all blogs in the course. // Unsubscribe user from all blogs in the course.
$sql = "DELETE FROM ".Database::get_course_table(TABLE_BLOGS_REL_USER)." $sql = "DELETE FROM ".Database::get_course_table(TABLE_BLOGS_REL_USER)."
@ -1282,7 +1283,7 @@ class CourseManager
* Return user info array of all users registered in a course * Return user info array of all users registered in a course
* This only returns the users that are registered in this actual course, not linked courses. * This only returns the users that are registered in this actual course, not linked courses.
* *
* @param string $course_code * @param string $courseCode
* @param int $sessionId * @param int $sessionId
* @param string $limit * @param string $limit
* @param string $order_by the field to order the users by. * @param string $order_by the field to order the users by.
@ -1303,7 +1304,7 @@ class CourseManager
* @return array|int * @return array|int
*/ */
public static function get_user_list_from_course_code( public static function get_user_list_from_course_code(
$course_code = null, $courseCode,
$sessionId = 0, $sessionId = 0,
$limit = null, $limit = null,
$order_by = null, $order_by = null,
@ -1323,13 +1324,17 @@ class CourseManager
$sessionTable = Database::get_main_table(TABLE_MAIN_SESSION); $sessionTable = Database::get_main_table(TABLE_MAIN_SESSION);
$sessionId = (int) $sessionId; $sessionId = (int) $sessionId;
$course_code = Database::escape_string($course_code); $courseCode = Database::escape_string($courseCode);
$courseInfo = api_get_course_info($course_code); $courseInfo = api_get_course_info($courseCode);
$courseId = 0; $courseId = 0;
if (!empty($courseInfo)) { if (!empty($courseInfo)) {
$courseId = $courseInfo['real_id']; $courseId = $courseInfo['real_id'];
} }
$session = null;
if (!empty($sessionId)) {
$session = api_get_session_entity($sessionId);
}
$course = api_get_course_entity($courseId);
$where = []; $where = [];
if (empty($order_by)) { if (empty($order_by)) {
$order_by = 'user.lastname, user.firstname'; $order_by = 'user.lastname, user.firstname';
@ -1422,7 +1427,7 @@ class CourseManager
if ($return_count) { if ($return_count) {
$sql = " SELECT COUNT(*) as count"; $sql = " SELECT COUNT(*) as count";
} else { } else {
if (empty($course_code)) { if (empty($courseCode)) {
$sql = 'SELECT DISTINCT $sql = 'SELECT DISTINCT
course.title, course.title,
course.code, course.code,
@ -1454,7 +1459,7 @@ class CourseManager
$sqlInjectJoins $sqlInjectJoins
"; ";
if (!empty($course_code)) { if (!empty($courseId)) {
$sql .= " AND course_rel_user.c_id = $courseId"; $sql .= " AND course_rel_user.c_id = $courseId";
} }
$where[] = ' course_rel_user.c_id IS NOT NULL '; $where[] = ' course_rel_user.c_id IS NOT NULL ';
@ -1568,7 +1573,6 @@ class CourseManager
} }
$sessionId = isset($user['session_id']) ? $user['session_id'] : 0; $sessionId = isset($user['session_id']) ? $user['session_id'] : 0;
$course_code = isset($user['code']) ? $user['code'] : null;
$sessionName = isset($user['session_name']) ? ' ('.$user['session_name'].') ' : ''; $sessionName = isset($user['session_name']) ? ' ('.$user['session_name'].') ' : '';
if ($add_reports) { if ($add_reports) {
@ -1628,7 +1632,7 @@ class CourseManager
$category = Category:: load( $category = Category:: load(
null, null,
null, null,
$course_code, $courseCode,
null, null,
null, null,
$sessionId $sessionId
@ -1643,7 +1647,7 @@ class CourseManager
} }
foreach ($extra_fields as $extra) { foreach ($extra_fields as $extra) {
if ('ruc' == $extra['1']) { if ('ruc' === $extra['1']) {
continue; continue;
} }
@ -1669,7 +1673,7 @@ class CourseManager
$category = Category:: load( $category = Category:: load(
null, null,
null, null,
$course_code, $courseCode,
null, null,
null, null,
$sessionId $sessionId
@ -1680,18 +1684,15 @@ class CourseManager
$report_info['certificate'] = Display::label(get_lang('Yes'), 'success'); $report_info['certificate'] = Display::label(get_lang('Yes'), 'success');
} }
$progress = intval( $progress = (int) Tracking::get_avg_student_progress(
Tracking::get_avg_student_progress( $user['user_id'],
$user['user_id'], $course,
$course_code, [],
[], $session
$sessionId
)
); );
$report_info['progress_100'] = 100 == $progress ? Display::label(get_lang('Yes'), 'success') : Display::label(get_lang('No')); $report_info['progress_100'] = 100 == $progress ? Display::label(get_lang('Yes'), 'success') : Display::label(get_lang('No'));
$report_info['progress'] = $progress."%"; $report_info['progress'] = $progress."%";
foreach ($extra_fields as $extra) { foreach ($extra_fields as $extra) {
$user_data = UserManager::get_extra_user_data_by_field($user['user_id'], $extra['1']); $user_data = UserManager::get_extra_user_data_by_field($user['user_id'], $extra['1']);
$report_info[$extra['1']] = $user_data[$extra['1']]; $report_info[$extra['1']] = $user_data[$extra['1']];
@ -6080,17 +6081,12 @@ class CourseManager
/** /**
* Shows the form for sending a message to a specific group or user. * Shows the form for sending a message to a specific group or user.
* *
* @param FormValidator $form
* @param array $groupInfo
* @param array $to
*
* @return HTML_QuickForm_element * @return HTML_QuickForm_element
*/ */
public static function addGroupMultiSelect($form, $groupInfo, $to = []) public static function addGroupMultiSelect(FormValidator $form, CGroup $group, $to = [])
{ {
$groupUsers = GroupManager::get_subscribed_users($groupInfo); $groupUsers = GroupManager::get_subscribed_users($group);
$groupEntity = api_get_group_entity($groupInfo['iid']); $array = self::buildSelectOptions([$group], $groupUsers, $to);
$array = self::buildSelectOptions([$groupEntity], $groupUsers, $to);
$result = []; $result = [];
foreach ($array as $content) { foreach ($array as $content) {

@ -3,9 +3,12 @@
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
use Chamilo\CoreBundle\Entity\Course; use Chamilo\CoreBundle\Entity\Course;
use Chamilo\CoreBundle\Entity\User;
use Chamilo\CoreBundle\Framework\Container; use Chamilo\CoreBundle\Framework\Container;
use Chamilo\CourseBundle\Entity\CGroup; use Chamilo\CourseBundle\Entity\CGroup;
use Chamilo\CourseBundle\Entity\CGroupCategory; use Chamilo\CourseBundle\Entity\CGroupCategory;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Criteria;
/** /**
* This library contains some functions for group-management. * This library contains some functions for group-management.
@ -549,9 +552,10 @@ class GroupManager
$result['chat_state'] = $db_object->chat_state; $result['chat_state'] = $db_object->chat_state;
$result['self_registration_allowed'] = $db_object->self_registration_allowed; $result['self_registration_allowed'] = $db_object->self_registration_allowed;
$result['self_unregistration_allowed'] = $db_object->self_unregistration_allowed; $result['self_unregistration_allowed'] = $db_object->self_unregistration_allowed;
$result['count_users'] = count( $result['count_users'] = 0;
/*$result['count_users'] = count(
self::get_subscribed_users($result) self::get_subscribed_users($result)
); );*/
/*$result['count_tutor'] = count( /*$result['count_tutor'] = count(
self::get_subscribed_tutors($result) self::get_subscribed_tutors($result)
);*/ );*/
@ -1625,60 +1629,45 @@ class GroupManager
/** /**
* Get all subscribed users (members) from a group. * Get all subscribed users (members) from a group.
* *
* @param array $groupInfo
*
* @return array An array with information of all users from the given group. * @return array An array with information of all users from the given group.
* (user_id, firstname, lastname, email) * (user_id, firstname, lastname, email)
*/ */
public static function get_subscribed_users($groupInfo) public static function get_subscribed_users(CGroup $group)
{ {
if (empty($groupInfo)) { //$order = api_sort_by_first_name() ? ' ORDER BY u.firstname, u.lastname' : ' ORDER BY u.lastname, u.firstname';
return []; $order = ['lastname'=> Criteria::DESC, 'firstname'=> Criteria::ASC];
if (api_sort_by_first_name()) {
$order = ['firstname' => Criteria::ASC, 'lastname' => Criteria::ASC];
} }
$table_user = Database::get_main_table(TABLE_MAIN_USER);
$table_group_user = Database::get_course_table(TABLE_GROUP_USER);
$order_clause = api_sort_by_first_name() ? ' ORDER BY u.firstname, u.lastname' : ' ORDER BY u.lastname, u.firstname';
$orderListByOfficialCode = api_get_setting('order_user_list_by_official_code'); $orderListByOfficialCode = api_get_setting('order_user_list_by_official_code');
if ('true' === $orderListByOfficialCode) { if ('true' === $orderListByOfficialCode) {
$order_clause = ' ORDER BY u.official_code, u.firstname, u.lastname'; //$order = ' ORDER BY u.official_code, u.firstname, u.lastname';
$order = ['officialCode' => Criteria::ASC, 'firstname' => Criteria::ASC, 'lastname' => Criteria::ASC];
} }
$group_id = (int) $groupInfo['iid']; $users = $group->getMembers();
$userList = [];
if (empty($group_id)) { foreach ($users as $groupRelUser) {
return []; $userList[] = $groupRelUser->getUser();
} }
$course_id = api_get_course_int_id(); $criteria = Criteria::create();
$criteria->orderBy($order);
$users = new ArrayCollection($userList);
$users = $users->matching($criteria);
$sql = "SELECT $list = [];
ug.iid, foreach ($users as $user) {
u.id as user_id, $list[$user->getId()] = [
u.lastname, 'user_id' => $user->getId(),
u.firstname, 'firstname' => $user->getFirstname(),
u.email, 'lastname' => $user->getLastname(),
u.username 'email' => $user->getEmail(),
FROM $table_user u 'username' => $user->getUsername(),
INNER JOIN $table_group_user ug
ON (ug.user_id = u.id)
WHERE
ug.group_id = $group_id
$order_clause";
$db_result = Database::query($sql);
$users = [];
while ($user = Database::fetch_object($db_result)) {
$users[$user->user_id] = [
'user_id' => $user->user_id,
'firstname' => $user->firstname,
'lastname' => $user->lastname,
'email' => $user->email,
'username' => $user->username,
]; ];
} }
return $users; return $list;
} }
/** /**

@ -347,7 +347,7 @@ class MySpace
//'image_small' => $courseInfo['course_image'], //'image_small' => $courseInfo['course_image'],
//'image_large' => $courseInfo['course_image_large'], //'image_large' => $courseInfo['course_image_large'],
'time_spent' => api_time_to_hms(Tracking::get_time_spent_on_the_course($userId, $courseId)), 'time_spent' => api_time_to_hms(Tracking::get_time_spent_on_the_course($userId, $courseId)),
'student_progress' => round(Tracking::get_avg_student_progress($userId, $courseCode)), 'student_progress' => round(Tracking::get_avg_student_progress($userId, $course)),
'student_score' => $avg_score, 'student_score' => $avg_score,
'student_message' => Container::getForumPostRepository()->countUserForumPosts($user, $course), 'student_message' => Container::getForumPostRepository()->countUserForumPosts($user, $course),
'student_assignments' => Container::getStudentPublicationRepository()->countUserPublications($user, $course), 'student_assignments' => Container::getStudentPublicationRepository()->countUserPublications($user, $course),
@ -1574,7 +1574,7 @@ class MySpace
$nb_progress_lp += $progress_tmp[1]; $nb_progress_lp += $progress_tmp[1];
$score_tmp = Tracking::get_avg_student_score( $score_tmp = Tracking::get_avg_student_score(
$userId, $userId,
$courseCode, $course,
[], [],
null, null,
true true
@ -1749,7 +1749,7 @@ class MySpace
); );
$progress_tmp = Tracking::get_avg_student_progress( $progress_tmp = Tracking::get_avg_student_progress(
$userId, $userId,
$courseCode, $course,
[], [],
null, null,
true true
@ -1994,7 +1994,7 @@ class MySpace
$time_spent += Tracking::get_time_spent_on_the_course($row_user->user_id, $courseId, $session_id); $time_spent += Tracking::get_time_spent_on_the_course($row_user->user_id, $courseId, $session_id);
$progress_tmp = Tracking::get_avg_student_progress( $progress_tmp = Tracking::get_avg_student_progress(
$row_user->user_id, $row_user->user_id,
$courseCode, $course,
[], [],
$session_id, $session_id,
true true

@ -408,7 +408,12 @@ class SortableTable extends HTML_Table
if (count($this->form_actions) > 0) { if (count($this->form_actions) > 0) {
$params = $this->get_sortable_table_param_string().'&amp;'.$this->get_additional_url_paramstring(); $params = $this->get_sortable_table_param_string().'&amp;'.$this->get_additional_url_paramstring();
$html .= '<form id ="'.$table_id.'" class="form-search" method="post" action="'.api_get_self().'?'.$params.'" name="form_'.$this->table_name.'">'; $html .= '<form
id ="'.$table_id.'"
class="form-search"
method="post"
action="'.api_get_self().'?'.$params.'"
name="form_'.$this->table_name.'">';
} }
$html .= '<div class="table-responsive">'.$content.'</div>'; $html .= '<div class="table-responsive">'.$content.'</div>';

@ -179,7 +179,8 @@ class Tracking
$user_id = (int) $user_id; $user_id = (int) $user_id;
$session_id = (int) $session_id; $session_id = (int) $session_id;
$origin = Security::remove_XSS($origin); $origin = Security::remove_XSS($origin);
$list = learnpath::get_flat_ordered_items_list($lp_id, 0, $courseInfo['real_id']); $lp = Container::getLpRepository()->find($lp_id);
$list = learnpath::get_flat_ordered_items_list($lp, 0, $courseInfo['real_id']);
$is_allowed_to_edit = api_is_allowed_to_edit(null, true); $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
$course_id = $courseInfo['real_id']; $course_id = $courseInfo['real_id'];
$courseCode = $courseInfo['code']; $courseCode = $courseInfo['code'];
@ -2814,7 +2815,7 @@ class Tracking
// Compose a filter based on optional learning paths list given // Compose a filter based on optional learning paths list given
$condition_lp = ''; $condition_lp = '';
if (count($lp_ids) > 0) { if (count($lp_ids) > 0) {
$condition_lp = " AND iid IN(".implode(',', $lp_ids).") "; $condition_lp = " iid IN(".implode(',', $lp_ids).") ";
} }
// Compose a filter based on optional session id // Compose a filter based on optional session id
@ -3243,7 +3244,7 @@ class Tracking
* This function gets time spent in learning path for a student inside a course. * This function gets time spent in learning path for a student inside a course.
* *
* @param int|array $student_id Student id(s) * @param int|array $student_id Student id(s)
* @param string $course_code Course code * @param Course $course Course code
* @param array $lp_ids Limit average to listed lp ids * @param array $lp_ids Limit average to listed lp ids
* @param int $session_id Session id (optional), if param $session_id is null(default) * @param int $session_id Session id (optional), if param $session_id is null(default)
* it'll return results including sessions, 0 = session is not filtered * it'll return results including sessions, 0 = session is not filtered
@ -3252,11 +3253,10 @@ class Tracking
*/ */
public static function get_time_spent_in_lp( public static function get_time_spent_in_lp(
$student_id, $student_id,
$course_code, Course $course,
$lp_ids = [], $lp_ids = [],
$session_id = 0 $session_id = 0
) { ) {
$course = api_get_course_info($course_code);
$student_id = (int) $student_id; $student_id = (int) $student_id;
$session_id = (int) $session_id; $session_id = (int) $session_id;
$total_time = 0; $total_time = 0;
@ -3267,18 +3267,18 @@ class Tracking
$lpViewTable = Database::get_course_table(TABLE_LP_VIEW); $lpViewTable = Database::get_course_table(TABLE_LP_VIEW);
$lpItemViewTable = Database::get_course_table(TABLE_LP_ITEM_VIEW); $lpItemViewTable = Database::get_course_table(TABLE_LP_ITEM_VIEW);
$trackExercises = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES); $trackExercises = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
$course_id = $course['real_id']; $course_id = $course->getId();
// Compose a filter based on optional learning paths list given // Compose a filter based on optional learning paths list given
$condition_lp = ''; $condition_lp = '';
if (count($lp_ids) > 0) { if (count($lp_ids) > 0) {
$condition_lp = " AND iid IN(".implode(',', $lp_ids).") "; $condition_lp = " iid IN(".implode(',', $lp_ids).") ";
} }
// Check the real number of LPs corresponding to the filter in the // Check the real number of LPs corresponding to the filter in the
// database (and if no list was given, get them all) // database (and if no list was given, get them all)
$sql = "SELECT DISTINCT(iid) FROM $lpTable $sql = "SELECT DISTINCT(iid) FROM $lpTable
WHERE c_id = $course_id $condition_lp"; WHERE $condition_lp";
$result = Database::query($sql); $result = Database::query($sql);
$session_condition = api_get_session_condition($session_id); $session_condition = api_get_session_condition($session_id);
@ -3286,10 +3286,10 @@ class Tracking
if (Database::num_rows($result) > 0) { if (Database::num_rows($result) > 0) {
while ($row = Database::fetch_array($result)) { while ($row = Database::fetch_array($result)) {
$lp_id = (int) $row['iid']; $lp_id = (int) $row['iid'];
$lp = Container::getLpRepository()->find($lp_id);
// Start Exercise in LP total_time // Start Exercise in LP total_time
// Get duration time from track_e_exercises.exe_duration instead of lp_view_item.total_time // Get duration time from track_e_exercises.exe_duration instead of lp_view_item.total_time
$list = learnpath::get_flat_ordered_items_list($lp_id, 0, $course_id); $list = learnpath::get_flat_ordered_items_list($lp, 0, $course_id);
foreach ($list as $itemId) { foreach ($list as $itemId) {
$sql = "SELECT max(view_count) $sql = "SELECT max(view_count)
FROM $lpViewTable FROM $lpViewTable
@ -3316,9 +3316,9 @@ class Tracking
path path
FROM $lpItemTable as i FROM $lpItemTable as i
INNER JOIN $lpItemViewTable as iv INNER JOIN $lpItemViewTable as iv
ON (i.iid = iv.lp_item_id AND i.c_id = iv.c_id) ON (i.iid = iv.lp_item_id)
INNER JOIN $lpViewTable as v INNER JOIN $lpViewTable as v
ON (iv.lp_view_id = v.iid AND v.c_id = iv.c_id) ON (iv.lp_view_id = v.iid)
WHERE WHERE
v.c_id = $course_id AND v.c_id = $course_id AND
i.iid = $itemId AND i.iid = $itemId AND
@ -3373,11 +3373,9 @@ class Tracking
FROM $lpItemViewTable AS item_view FROM $lpItemViewTable AS item_view
INNER JOIN $lpViewTable AS view INNER JOIN $lpViewTable AS view
ON ( ON (
item_view.lp_view_id = view.iid AND item_view.lp_view_id = view.iid
item_view.c_id = view.c_id
) )
WHERE WHERE
item_view.c_id = $course_id AND
view.c_id = $course_id AND view.c_id = $course_id AND
view.lp_id = $lp_id AND view.lp_id = $lp_id AND
view.user_id = $student_id AND view.user_id = $student_id AND
@ -3456,7 +3454,7 @@ class Tracking
// Check the real number of LPs corresponding to the filter in the // Check the real number of LPs corresponding to the filter in the
// database (and if no list was given, get them all) // database (and if no list was given, get them all)
$sql = "SELECT iid FROM $lp_table $sql = "SELECT iid FROM $lp_table
WHERE c_id = $course_id AND iid = $lp_id "; WHERE iid = $lp_id ";
$row = Database::query($sql); $row = Database::query($sql);
$count = Database::num_rows($row); $count = Database::num_rows($row);
@ -3465,10 +3463,9 @@ class Tracking
$sql = 'SELECT MAX(start_time) $sql = 'SELECT MAX(start_time)
FROM '.$t_lpiv.' AS item_view FROM '.$t_lpiv.' AS item_view
INNER JOIN '.$t_lpv.' AS view INNER JOIN '.$t_lpv.' AS view
ON (item_view.lp_view_id = view.iid AND item_view.c_id = view.c_id) ON (item_view.lp_view_id = view.iid)
WHERE WHERE
status != "not attempted" AND status != "not attempted" AND
item_view.c_id = '.$course_id.' AND
view.c_id = '.$course_id.' AND view.c_id = '.$course_id.' AND
view.lp_id = '.$lp_id.' AND view.lp_id = '.$lp_id.' AND
view.user_id = '.$student_id.' AND view.user_id = '.$student_id.' AND
@ -8669,9 +8666,12 @@ class TrackingCourseLog
$number_of_items, $number_of_items,
$column, $column,
$direction, $direction,
$includeInvitedUsers = false $params = []
) { ) {
global $user_ids, $course_code, $export_csv, $csv_content, $session_id; global $user_ids, $course_code, $export_csv, $csv_content, $session_id;
$includeInvitedUsers = false;
$courseId = $params['cid'];
$sessionId = $params['sid'];
$course_code = Database::escape_string($course_code); $course_code = Database::escape_string($course_code);
$tbl_user = Database::get_main_table(TABLE_MAIN_USER); $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
@ -8683,7 +8683,7 @@ class TrackingCourseLog
$user_ids = array_map('intval', $user_ids); $user_ids = array_map('intval', $user_ids);
$condition_user = " WHERE user.user_id IN (".implode(',', $user_ids).") "; $condition_user = " WHERE user.user_id IN (".implode(',', $user_ids).") ";
} else { } else {
$user_ids = intval($user_ids); $user_ids = (int) $user_ids;
$condition_user = " WHERE user.user_id = $user_ids "; $condition_user = " WHERE user.user_id = $user_ids ";
} }
@ -8699,7 +8699,8 @@ class TrackingCourseLog
$invitedUsersCondition = " AND user.status != ".INVITEE; $invitedUsersCondition = " AND user.status != ".INVITEE;
} }
$sql = "SELECT user.user_id as user_id, $sql = "SELECT
user.user_id as user_id,
user.official_code as col0, user.official_code as col0,
user.lastname as col1, user.lastname as col1,
user.firstname as col2, user.firstname as col2,
@ -8722,8 +8723,7 @@ class TrackingCourseLog
$users = []; $users = [];
$sortByFirstName = api_sort_by_first_name(); $sortByFirstName = api_sort_by_first_name();
$courseInfo = api_get_course_info($course_code); $course = api_get_course_entity($courseId);
$courseId = $courseInfo['real_id'];
while ($user = Database::fetch_array($res, 'ASSOC')) { while ($user = Database::fetch_array($res, 'ASSOC')) {
$user['official_code'] = $user['col0']; $user['official_code'] = $user['col0'];
@ -8740,7 +8740,7 @@ class TrackingCourseLog
$user['time'] = api_time_to_hms($totalCourseTime); $user['time'] = api_time_to_hms($totalCourseTime);
$totalLpTime = Tracking::get_time_spent_in_lp( $totalLpTime = Tracking::get_time_spent_in_lp(
$user['user_id'], $user['user_id'],
$course_code, $course,
[], [],
$session_id $session_id
); );
@ -8752,7 +8752,6 @@ class TrackingCourseLog
} }
$user['total_lp_time'] = api_time_to_hms($totalLpTime).$warning; $user['total_lp_time'] = api_time_to_hms($totalLpTime).$warning;
$user['first_connection'] = Tracking::get_first_connection_date_on_the_course( $user['first_connection'] = Tracking::get_first_connection_date_on_the_course(
$user['user_id'], $user['user_id'],
$courseId, $courseId,
@ -8765,11 +8764,13 @@ class TrackingCourseLog
false === $export_csv false === $export_csv
); );
$user['link'] = '<center> $user['link'] = '
<a href="../mySpace/myStudents.php?student='.$user['user_id'].'&details=true&course='.$course_code.'&origin=tracking_course&id_session='.$session_id.'"> <center>
'.Display::return_icon('2rightarrow.png', get_lang('Details')).' <a
</a> href="../mySpace/myStudents.php?student='.$user['user_id'].'&details=true&cid='.$courseId.'&origin=tracking_course&sid='.$session_id.'">
</center>'; '.Display::return_icon('2rightarrow.png', get_lang('Details')).'
</a>
</center>';
// store columns in array $users // store columns in array $users
$user_row = []; $user_row = [];
@ -8786,7 +8787,6 @@ class TrackingCourseLog
$user_row['total_lp_time'] = $user['total_lp_time']; $user_row['total_lp_time'] = $user['total_lp_time'];
$user_row['first_connection'] = $user['first_connection']; $user_row['first_connection'] = $user['first_connection'];
$user_row['last_connection'] = $user['last_connection']; $user_row['last_connection'] = $user['last_connection'];
$user_row['link'] = $user['link']; $user_row['link'] = $user['link'];
$users[] = array_values($user_row); $users[] = array_values($user_row);
} }

@ -6693,7 +6693,7 @@ class learnpath
* @param CLpItem $lpItem * @param CLpItem $lpItem
* *
* @throws Exception * @throws Exception
* @throws HTML_QuickForm_Error *
* *
* @return string * @return string
*/ */
@ -6788,7 +6788,7 @@ class learnpath
* could be added to the learning path. * could be added to the learning path.
* *
* @throws Exception * @throws Exception
* @throws HTML_QuickForm_Error *
* *
* @return bool * @return bool
*/ */
@ -6925,7 +6925,7 @@ class learnpath
* @param CLink $link * @param CLink $link
* *
* @throws Exception * @throws Exception
* @throws HTML_QuickForm_Error *
* *
* @return string HTML form * @return string HTML form
*/ */
@ -7039,7 +7039,7 @@ class learnpath
* @param string $action * @param string $action
* *
* @throws Exception * @throws Exception
* @throws HTML_QuickForm_Error *
* *
* @return string HTML form * @return string HTML form
*/ */
@ -7109,7 +7109,7 @@ class learnpath
* @param string $action (add/edit) * @param string $action (add/edit)
* @param CLpItem $lpItem * @param CLpItem $lpItem
* *
* @throws HTML_QuickForm_Error *
* @throws Exception * @throws Exception
* *
* @return string HTML form * @return string HTML form
@ -7482,7 +7482,7 @@ class learnpath
* @param CLpItem $lpItem * @param CLpItem $lpItem
* *
* @throws Exception * @throws Exception
* @throws HTML_QuickForm_Error *
* *
* @return string HTML form * @return string HTML form
*/ */
@ -7772,7 +7772,7 @@ class learnpath
* @param bool $showInvisibleFiles * @param bool $showInvisibleFiles
* *
* @throws Exception * @throws Exception
* @throws HTML_QuickForm_Error *
* *
* @return string * @return string
*/ */
@ -9356,9 +9356,10 @@ EOD;
$sessionId = api_get_session_id(); $sessionId = api_get_session_id();
$course_data = api_get_course_info($this->cc); $course_data = api_get_course_info($this->cc);
$lp = Container::getLpRepository()->find($lp_id);
if (!empty($course_data)) { if (!empty($course_data)) {
$scorm_path = api_get_path(SYS_COURSE_PATH).$course_data['path'].'/scorm/'.$this->path; $scorm_path = api_get_path(SYS_COURSE_PATH).$course_data['path'].'/scorm/'.$this->path;
$list = self::get_flat_ordered_items_list($lp_id); $list = self::get_flat_ordered_items_list($lp);
if (!empty($list)) { if (!empty($list)) {
foreach ($list as $item_id) { foreach ($list as $item_id) {
$item = $this->items[$item_id]; $item = $this->items[$item_id];
@ -9676,7 +9677,7 @@ EOD;
{ {
$em = Database::getManager(); $em = Database::getManager();
/** @var CLpCategory $item */ /** @var CLpCategory $item */
$item = $em->find('ChamiloCourseBundle:CLpCategory', $params['id']); $item = $em->find(CLpCategory::class, $params['id']);
if ($item) { if ($item) {
$item->setName($params['name']); $item->setName($params['name']);
$em->persist($item); $em->persist($item);
@ -9692,7 +9693,7 @@ EOD;
$id = (int) $id; $id = (int) $id;
$em = Database::getManager(); $em = Database::getManager();
/** @var CLpCategory $item */ /** @var CLpCategory $item */
$item = $em->find('ChamiloCourseBundle:CLpCategory', $id); $item = $em->find(CLpCategory::class, $id);
if ($item) { if ($item) {
$position = $item->getPosition() - 1; $position = $item->getPosition() - 1;
$item->setPosition($position); $item->setPosition($position);
@ -9709,7 +9710,7 @@ EOD;
$id = (int) $id; $id = (int) $id;
$em = Database::getManager(); $em = Database::getManager();
/** @var CLpCategory $item */ /** @var CLpCategory $item */
$item = $em->find('ChamiloCourseBundle:CLpCategory', $id); $item = $em->find(CLpCategory::class, $id);
if ($item) { if ($item) {
$position = $item->getPosition() + 1; $position = $item->getPosition() + 1;
$item->setPosition($position); $item->setPosition($position);
@ -10264,7 +10265,7 @@ EOD;
* Get the LP Final Item form. * Get the LP Final Item form.
* *
* @throws Exception * @throws Exception
* @throws HTML_QuickForm_Error *
* *
* @return string * @return string
*/ */

@ -292,14 +292,14 @@ if (!empty($users)) {
$userInfo = api_get_user_info($userId); $userInfo = api_get_user_info($userId);
$lpTime = Tracking::get_time_spent_in_lp( $lpTime = Tracking::get_time_spent_in_lp(
$userId, $userId,
$courseCode, $course,
[$lpId], [$lpId],
$sessionId $sessionId
); );
$lpScore = Tracking::get_avg_student_score( $lpScore = Tracking::get_avg_student_score(
$userId, $userId,
$courseCode, $course,
[$lpId], [$lpId],
$sessionId $sessionId
); );

@ -6,6 +6,7 @@ use Chamilo\CoreBundle\Entity\Asset;
use Chamilo\CoreBundle\Framework\Container; use Chamilo\CoreBundle\Framework\Container;
use Chamilo\CourseBundle\Entity\CLp; use Chamilo\CourseBundle\Entity\CLp;
use Chamilo\CourseBundle\Entity\CLpItem; use Chamilo\CourseBundle\Entity\CLpItem;
use League\Flysystem\Filesystem;
use League\Flysystem\ZipArchive\ZipArchiveAdapter; use League\Flysystem\ZipArchive\ZipArchiveAdapter;
use Symfony\Component\DomCrawler\Crawler; use Symfony\Component\DomCrawler\Crawler;
@ -565,8 +566,6 @@ class scorm extends learnpath
); );
} }
$courseInfo = empty($courseInfo) ? api_get_course_info() : $courseInfo;
$maxFilledSpace = DocumentManager::get_course_quota($courseInfo['code']);
$zipFilePath = $zipFileInfo['tmp_name']; $zipFilePath = $zipFileInfo['tmp_name'];
$zipFileName = $zipFileInfo['name']; $zipFileName = $zipFileInfo['name'];
@ -577,8 +576,6 @@ class scorm extends learnpath
); );
} }
//$courseRelDir = api_get_course_path($courseInfo['code']).'/scorm'; // scorm dir web path starting from /courses
//$courseSysDir = api_get_path(SYS_COURSE_PATH).$courseRelDir; // Absolute system path for this course.
$currentDir = api_replace_dangerous_char(trim($currentDir)); // Current dir we are in, inside scorm/ $currentDir = api_replace_dangerous_char(trim($currentDir)); // Current dir we are in, inside scorm/
if ($this->debug > 1) { if ($this->debug > 1) {
@ -600,7 +597,7 @@ class scorm extends learnpath
} }
$zipAdapter = new ZipArchiveAdapter($zipFilePath); $zipAdapter = new ZipArchiveAdapter($zipFilePath);
$filesystem = new \League\Flysystem\Filesystem($zipAdapter); $filesystem = new Filesystem($zipAdapter);
$zipContentArray = $filesystem->listContents(); $zipContentArray = $filesystem->listContents();
$packageType = ''; $packageType = '';

@ -309,8 +309,8 @@ function get_courses($from, $limit, $column, $direction)
if (count($userIdList) > 0) { if (count($userIdList) > 0) {
$countStudents = count($userIdList); $countStudents = count($userIdList);
// tracking data // tracking data
$avgProgressInCourse = Tracking::get_avg_student_progress($userIdList, $courseCode, [], $sessionId); $avgProgressInCourse = Tracking::get_avg_student_progress($userIdList, $course, [], $session);
$avgScoreInCourse = Tracking::get_avg_student_score($userIdList, $courseCode, [], $sessionId); $avgScoreInCourse = Tracking::get_avg_student_score($userIdList, $course, [], $session);
$avgTimeSpentInCourse = Tracking::get_time_spent_on_the_course( $avgTimeSpentInCourse = Tracking::get_time_spent_on_the_course(
$userIdList, $userIdList,
$courseInfo['real_id'], $courseInfo['real_id'],

@ -5,6 +5,7 @@
use Chamilo\CoreBundle\Framework\Container; use Chamilo\CoreBundle\Framework\Container;
use Chamilo\CourseBundle\Entity\CLpCategory; use Chamilo\CourseBundle\Entity\CLpCategory;
use Chamilo\CourseBundle\Entity\CQuiz; use Chamilo\CourseBundle\Entity\CQuiz;
use Chamilo\CourseBundle\Entity\CStudentPublication;
use ChamiloSession as Session; use ChamiloSession as Session;
if (!isset($_GET['course'])) { if (!isset($_GET['course'])) {
@ -341,7 +342,7 @@ switch ($action) {
$bestScore = Tracking::get_avg_student_score( $bestScore = Tracking::get_avg_student_score(
$studentId, $studentId,
$courseCodeItem, $course,
[], [],
$sId, $sId,
false, false,
@ -1615,9 +1616,9 @@ if (empty($details)) {
// Get progress in lp // Get progress in lp
$progress = Tracking::get_avg_student_progress( $progress = Tracking::get_avg_student_progress(
$studentId, $studentId,
$courseCode, $course,
[$lp_id], [$lp_id],
$sessionId $session
); );
if (null === $progress) { if (null === $progress) {
@ -1633,7 +1634,7 @@ if (empty($details)) {
} else { } else {
$total_time = Tracking::get_time_spent_in_lp( $total_time = Tracking::get_time_spent_in_lp(
$studentId, $studentId,
$courseCode, $course,
[$lp_id], [$lp_id],
$sessionId $sessionId
); );
@ -1646,7 +1647,7 @@ if (empty($details)) {
// Get last connection time in lp // Get last connection time in lp
$start_time = Tracking::get_last_connection_time_in_lp( $start_time = Tracking::get_last_connection_time_in_lp(
$studentId, $studentId,
$courseCode, $course,
$lp_id, $lp_id,
$sessionId $sessionId
); );
@ -1664,26 +1665,26 @@ if (empty($details)) {
// Quiz in lp // Quiz in lp
$score = Tracking::get_avg_student_score( $score = Tracking::get_avg_student_score(
$studentId, $studentId,
$courseCode, $course,
[$lp_id], [$lp_id],
$sessionId $session
); );
// Latest exercise results in a LP // Latest exercise results in a LP
$score_latest = Tracking::get_avg_student_score( $score_latest = Tracking::get_avg_student_score(
$studentId, $studentId,
$courseCode, $course,
[$lp_id], [$lp_id],
$sessionId, $session,
false, false,
true true
); );
$bestScore = Tracking::get_avg_student_score( $bestScore = Tracking::get_avg_student_score(
$studentId, $studentId,
$courseCode, $course,
[$lp_id], [$lp_id],
$sessionId, $session,
false, false,
false, false,
true true
@ -1700,9 +1701,7 @@ if (empty($details)) {
} else { } else {
$css_class = 'row_odd'; $css_class = 'row_odd';
} }
$i++; $i++;
if (isset($score_latest) && !is_null($score_latest)) { if (isset($score_latest) && !is_null($score_latest)) {
if (is_numeric($score_latest)) { if (is_numeric($score_latest)) {
$score_latest = $score_latest.'%'; $score_latest = $score_latest.'%';
@ -2089,7 +2088,6 @@ if (empty($details)) {
} }
} }
$userWorks = getWorkPerUser($studentId, $courseId, $sessionId);
echo ' echo '
<div class="table-responsive"> <div class="table-responsive">
<table class="table table-striped table-hover"> <table class="table table-striped table-hover">
@ -2106,32 +2104,42 @@ if (empty($details)) {
<tbody> <tbody>
'; ';
foreach ($userWorks as $work) { $repo = Container::getStudentPublicationRepository();
$work = $work['work']; $works = $repo->getStudentPublicationByUser($user, $course, $session);
//$userWorks = getWorkPerUser($studentId, $courseId, $sessionId);
foreach ($works as $workData) {
/** @var CStudentPublication $work */
$work = $workData['work'];
/** @var CStudentPublication[] $results */
$results = $workData['results'];
$showOnce = true; $showOnce = true;
foreach ($work->user_results as $key => $results) { $key = 1;
$resultId = $results['id']; foreach ($results as $result) {
$resultId = $result->getIid();
$assignment = $work->getAssignment();
echo '<tr>'; echo '<tr>';
echo '<td>'.$work->title.'</td>'; echo '<td>'.$work->getTitle().'</td>';
$documentNumber = $key + 1; $documentNumber = $key + 1;
$url = api_get_path(WEB_CODE_PATH). $key++;
'work/view.php?cidReq='.$courseCode.'&id_session='.$sessionId.'&id='.$resultId; $url = api_get_path(WEB_CODE_PATH).'work/view.php?cid='.$courseId.'&sid='.$sessionId.'&id='.$resultId;
echo '<td class="text-center"><a href="'.$url.'">('.$documentNumber.')</a></td>'; echo '<td class="text-center"><a href="'.$url.'">('.$documentNumber.')</a></td>';
$qualification = !empty($results['qualification']) ? $results['qualification'] : '-'; $qualification = $result->getQualification();
$qualification = !empty($qualification) ? $qualification : '-';
echo '<td class="text-center">'.$qualification.'</td>'; echo '<td class="text-center">'.$qualification.'</td>';
echo '<td class="text-center">'. echo '<td class="text-center">'.
api_convert_and_format_date($results['sent_date_from_db']).' '.$results['expiry_note'].'</td>'; api_convert_and_format_date($result->getSentDate()).' </td>';
$assignment = get_work_assignment_by_id($work->iid, $courseId);
echo '<td class="text-center">'; echo '<td class="text-center">';
if (!empty($assignment['expires_on'])) { if ($assignment && !empty($assignment->getExpiresOn())) {
echo api_convert_and_format_date($assignment['expires_on']); echo api_convert_and_format_date($assignment->getExpiresOn());
} }
echo '</td>'; echo '</td>';
$fieldValue = new ExtraFieldValue('work'); $fieldValue = new ExtraFieldValue('work');
$resultExtra = $fieldValue->getAllValuesForAnItem( $resultExtra = $fieldValue->getAllValuesForAnItem(
$work->iid, $resultId,
true true
); );
@ -2145,12 +2153,12 @@ if (empty($details)) {
$showOnce = false; $showOnce = false;
echo '&nbsp;'.Display::url( echo '&nbsp;'.Display::url(
get_lang('AddTime'), get_lang('AddTime'),
$currentUrl.'&action=add_work_time&time='.$time.'&work_id='.$work->id $currentUrl.'&action=add_work_time&time='.$time.'&work_id='.$work->getIid()
); );
echo '&nbsp;'.Display::url( echo '&nbsp;'.Display::url(
get_lang('RemoveTime'), get_lang('RemoveTime'),
$currentUrl.'&action=remove_work_time&time='.$time.'&work_id='.$work->id $currentUrl.'&action=remove_work_time&time='.$time.'&work_id='.$work->getIid()
); );
} }
echo '</td>'; echo '</td>';

@ -272,6 +272,7 @@ function getData($from, $numberOfItems, $column, $direction)
$sessionId = api_get_session_id(); $sessionId = api_get_session_id();
$courseCode = api_get_course_id(); $courseCode = api_get_course_id();
$courseId = api_get_course_int_id(); $courseId = api_get_course_int_id();
$course = api_get_course_entity();
$lps = Session::read('lps'); $lps = Session::read('lps');
@ -323,7 +324,7 @@ function getData($from, $numberOfItems, $column, $direction)
$lpId = $lp['iid']; $lpId = $lp['iid'];
$progress = Tracking::get_avg_student_progress( $progress = Tracking::get_avg_student_progress(
$userId, $userId,
$courseCode, $course,
[$lpId], [$lpId],
$sessionId $sessionId
); );
@ -333,7 +334,7 @@ function getData($from, $numberOfItems, $column, $direction)
} else { } else {
$time = Tracking::get_time_spent_in_lp( $time = Tracking::get_time_spent_in_lp(
$userId, $userId,
$courseCode, $course,
[$lpId], [$lpId],
$sessionId $sessionId
); );

@ -285,8 +285,10 @@ if (count($a_students) > 0) {
(api_is_western_name_order() xor api_sort_by_first_name()) ? 3 : 2 (api_is_western_name_order() xor api_sort_by_first_name()) ? 3 : 2
); );
$parameters['cidReq'] = Security::remove_XSS($_GET['cidReq']); $table->setDataFunctionParams(['cid' => api_get_course_int_id(), 'sid' => $session_id]);
$parameters['id_session'] = $session_id;
$parameters['cid'] = api_get_course_int_id();
$parameters['sid'] = $session_id;
$parameters['from'] = isset($_GET['myspace']) ? Security::remove_XSS($_GET['myspace']) : null; $parameters['from'] = isset($_GET['myspace']) ? Security::remove_XSS($_GET['myspace']) : null;
$table->set_additional_parameters($parameters); $table->set_additional_parameters($parameters);
@ -308,15 +310,27 @@ if (count($a_students) > 0) {
$table->set_header(3, get_lang('Login'), false); $table->set_header(3, get_lang('Login'), false);
$headers['login'] = get_lang('Login'); $headers['login'] = get_lang('Login');
$table->set_header(4, get_lang('Time').'&nbsp;'. $table->set_header(
Display::return_icon('info3.gif', get_lang('Time spent in the course'), ['align' => 'absmiddle', 'hspace' => '3px']), 4,
get_lang('Time').'&nbsp;'.
Display::return_icon(
'info3.gif',
get_lang('Time spent in the course'),
['align' => 'absmiddle', 'hspace' => '3px']
),
false, false,
['style' => 'width:110px;'] ['style' => 'width:110px;']
); );
$headers['training_time'] = get_lang('Time'); $headers['training_time'] = get_lang('Time');
$table->set_header(5, get_lang('Total learnpath time').'&nbsp;'. $table->set_header(
Display::return_icon('info3.gif', get_lang('Total learnpath time'), ['align' => 'absmiddle', 'hspace' => '3px']), 5,
get_lang('Total learnpath time').'&nbsp;'.
Display::return_icon(
'info3.gif',
get_lang('Total learnpath time'),
['align' => 'absmiddle', 'hspace' => '3px']
),
false, false,
['style' => 'width:110px;'] ['style' => 'width:110px;']
); );

@ -457,17 +457,14 @@ function WSDeleteLp($params)
} }
*/ */
$lp = new learnpath($courseCode, $lpId, null); $lp = \Chamilo\CoreBundle\Framework\Container::getLpRepository()->find($lpId);
$lp = new learnpath($lp, $lpId, null);
if ($lp) { if ($lp) {
if ($debug) { if ($debug) {
error_log("LP deleted $lpId"); error_log("LP deleted $lpId");
} }
$base_work_dir = null;
$course_dir = $courseInfo['directory'].'/document'; $items = $lp->get_flat_ordered_items_list($lp, 0, $courseId);
$sys_course_path = api_get_path(SYS_COURSE_PATH);
$base_work_dir = $sys_course_path.$course_dir;
$items = $lp->get_flat_ordered_items_list($lpId, 0, $courseId);
if (!empty($items)) { if (!empty($items)) {
/** @var $item learnpathItem */ /** @var $item learnpathItem */
@ -476,7 +473,6 @@ function WSDeleteLp($params)
if ($item) { if ($item) {
$documentId = $item->get_path(); $documentId = $item->get_path();
if ($debug) { if ($debug) {
error_log("lp item id found #$itemId"); error_log("lp item id found #$itemId");
} }

@ -2552,7 +2552,6 @@ class Wiki
$assignment_type = $values['assignment']; $assignment_type = $values['assignment'];
$session_id = $this->session_id; $session_id = $this->session_id;
$groupId = api_get_group_id(); $groupId = api_get_group_id();
$groupInfo = GroupManager::get_group_properties($groupId);
$group = api_get_group_entity($groupId); $group = api_get_group_entity($groupId);
if (0 == $groupId) { if (0 == $groupId) {
@ -2570,7 +2569,7 @@ class Wiki
} }
} else { } else {
//extract group members //extract group members
$subscribed_users = GroupManager::get_subscribed_users($groupInfo); $subscribed_users = GroupManager::get_subscribed_users($group);
$tutors = $group->getTutors(); $tutors = $group->getTutors();
$subscribed_tutors = []; $subscribed_tutors = [];
foreach ($tutors as $tutor) { foreach ($tutors as $tutor) {

@ -2,6 +2,9 @@
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
use Chamilo\CoreBundle\Framework\Container;
use Chamilo\CourseBundle\Entity\CStudentPublication;
require_once __DIR__.'/../inc/global.inc.php'; require_once __DIR__.'/../inc/global.inc.php';
$current_course_tool = TOOL_STUDENTPUBLICATION; $current_course_tool = TOOL_STUDENTPUBLICATION;
@ -9,7 +12,6 @@ api_protect_course_script(true);
api_protect_course_group(GroupManager::GROUP_TOOL_WORK); api_protect_course_group(GroupManager::GROUP_TOOL_WORK);
$this_section = SECTION_COURSES; $this_section = SECTION_COURSES;
$studentId = isset($_GET['studentId']) ? (int) ($_GET['studentId']) : null; $studentId = isset($_GET['studentId']) ? (int) ($_GET['studentId']) : null;
if (empty($studentId)) { if (empty($studentId)) {
@ -18,15 +20,17 @@ if (empty($studentId)) {
$tool_name = get_lang('Assignments'); $tool_name = get_lang('Assignments');
$group_id = api_get_group_id(); $group_id = api_get_group_id();
$userInfo = api_get_user_info($studentId); $user = api_get_user_entity($studentId);
$completeName = UserManager::formatUserFullName($user);
$courseInfo = api_get_course_info(); $courseInfo = api_get_course_info();
$course = api_get_course_entity();
$session = api_get_session_entity();
if (empty($userInfo) || empty($courseInfo)) { if (null === $user || null === $course) {
api_not_allowed(true); api_not_allowed(true);
} }
// Only a teachers page. // Only a teachers page.
if (!empty($group_id)) { if (!empty($group_id)) {
$group_properties = GroupManager::get_group_properties($group_id); $group_properties = GroupManager::get_group_properties($group_id);
$interbreadcrumb[] = [ $interbreadcrumb[] = [
@ -43,7 +47,7 @@ if (!empty($group_id)) {
} }
} }
$action = isset($_GET['action']) ? $_GET['action'] : null; $action = $_GET['action'] ?? null;
switch ($action) { switch ($action) {
case 'export_to_pdf': case 'export_to_pdf':
@ -59,7 +63,7 @@ switch ($action) {
break; break;
case 'delete_all': case 'delete_all':
if (api_is_allowed_to_edit()) { if (api_is_allowed_to_edit()) {
$deletedItems = deleteAllWorkPerUser($studentId, $courseInfo); $deletedItems = deleteAllWorkPerUser($user, $course);
if (!empty($deletedItems)) { if (!empty($deletedItems)) {
$message = get_lang('File deleted').'<br >'; $message = get_lang('File deleted').'<br >';
foreach ($deletedItems as $item) { foreach ($deletedItems as $item) {
@ -81,30 +85,33 @@ $interbreadcrumb[] = [
]; ];
$interbreadcrumb[] = [ $interbreadcrumb[] = [
'url' => '#', 'url' => '#',
'name' => $userInfo['complete_name'], 'name' => $completeName,
]; ];
Display :: display_header(null); Display::display_header(null);
$workPerUser = getWorkPerUser($studentId);
echo '<div class="actions">'; echo '<div class="actions">';
echo '<a href="'.api_get_path(WEB_CODE_PATH).'work/work.php?'.api_get_cidreq().'">'. echo '<a href="'.api_get_path(WEB_CODE_PATH).'work/work.php?'.api_get_cidreq().'">'.
Display::return_icon('back.png', get_lang('Back to Assignments list'), '', ICON_SIZE_MEDIUM).'</a>'; Display::return_icon('back.png', get_lang('Back to Assignments list'), '', ICON_SIZE_MEDIUM).
'</a>';
if (api_is_allowed_to_edit()) { if (api_is_allowed_to_edit()) {
echo '<a href="'.api_get_path(WEB_CODE_PATH).'work/student_work.php?action=export_to_pdf&studentId='.$studentId.'&'.api_get_cidreq().'">'. echo '<a
Display::return_icon('pdf.png', get_lang('Export to PDF'), '', ICON_SIZE_MEDIUM).'</a>'; href="'.api_get_path(WEB_CODE_PATH).'work/student_work.php?action=export_to_pdf&studentId='.$studentId.'&'.api_get_cidreq().'">'.
Display::return_icon('pdf.png', get_lang('Export to PDF'), '', ICON_SIZE_MEDIUM).
'</a>';
echo '<a href="'.api_get_path(WEB_CODE_PATH).'work/student_work.php?action=download&studentId='.$studentId.'&'.api_get_cidreq().'">'. echo '<a
Display::return_icon('save.png', get_lang('Download'), '', ICON_SIZE_MEDIUM).'</a>'; href="'.api_get_path(WEB_CODE_PATH).'work/student_work.php?action=download&studentId='.$studentId.'&'.api_get_cidreq().'">'.
Display::return_icon('save.png', get_lang('Download'), '', ICON_SIZE_MEDIUM).
'</a>';
echo '<a echo '<a
onclick="javascript:if(!confirm(\''.get_lang('Are you sure you want to delete').'\')) return false;" onclick="javascript:if(!confirm(\''.get_lang('Are you sure you want to delete').'\')) return false;"
href="'.api_get_path(WEB_CODE_PATH).'work/student_work.php?action=delete_all&studentId='.$studentId.'&'.api_get_cidreq().'">'. href="'.api_get_path(WEB_CODE_PATH).'work/student_work.php?action=delete_all&studentId='.$studentId.'&'.api_get_cidreq().'">'.
Display::return_icon('delete.png', get_lang('Delete all papers'), '', ICON_SIZE_MEDIUM).'</a>'; Display::return_icon('delete.png', get_lang('Delete all papers'), '', ICON_SIZE_MEDIUM).
'</a>';
} }
echo '</div>'; echo '</div>';
$table = new HTML_Table(['class' => 'data_table']); $table = new HTML_Table(['class' => 'data_table']);
@ -125,31 +132,35 @@ $row++;
$column = 0; $column = 0;
$url = api_get_path(WEB_CODE_PATH).'work/'; $url = api_get_path(WEB_CODE_PATH).'work/';
foreach ($workPerUser as $work) { $repo = Container::getStudentPublicationRepository();
$work = $work['work']; $works = $repo->getStudentPublicationByUser($user, $course, $session);
$scoreWeight = 0 == (int) ($work->qualification) ? null : $work->qualification; //$userWorks = getWorkPerUser($studentId, $courseId, $sessionId);
$workId = $work->id; foreach ($works as $workData) {
$workExtraData = get_work_assignment_by_id($workId); /** @var CStudentPublication $work */
$work = $workData['work'];
foreach ($work->user_results as $userResult) { /** @var CStudentPublication[] $results */
$itemId = $userResult['id']; $results = $workData['results'];
$table->setCellContents($row, $column, $work->title.' ['.trim(strip_tags($userResult['title'])).']');
$scoreWeight = 0 == (int) $work->getQualification() ? null : $work->getQualification();
$workId = $work->getIid();
foreach ($results as $userResult) {
$itemId = $userResult->getIid();
$table->setCellContents($row, $column, $work->getTitle().' ['.trim(strip_tags($userResult->getTitle())).']');
$table->setCellAttributes($row, $column, ['width' => '300px']); $table->setCellAttributes($row, $column, ['width' => '300px']);
$column++; $column++;
$table->setCellContents($row, $column, $userResult['sent_date']); $table->setCellContents($row, $column, api_get_local_time($userResult->getSentDate()));
$column++; $column++;
$dateQualification = !empty($workExtraData['expires_on']) ? api_get_local_time($workExtraData['expires_on']) : '-'; $assignment = $work->getAssignment();
$dateQualification = !empty($assignment->getExpiresOn()) ? api_get_local_time($assignment->getExpiresOn()) : '-';
$table->setCellContents($row, $column, $dateQualification); $table->setCellContents($row, $column, $dateQualification);
$column++; $column++;
$score = $userResult->getQualification();
$score = null;
$score = $userResult['qualification'];
$table->setCellContents($row, $column, $score); $table->setCellContents($row, $column, $score);
$column++; $column++;
// Detail // Detail
$links = null; $links = null;
// is a text // is a text
$url = api_get_path(WEB_CODE_PATH).'work/view.php?'.api_get_cidreq().'&id='.$itemId; $url = api_get_path(WEB_CODE_PATH).'work/view.php?'.api_get_cidreq().'&id='.$itemId;
$links .= Display::url(Display::return_icon('default.png', get_lang('View')), $url); $links .= Display::url(Display::return_icon('default.png', get_lang('View')), $url);
@ -160,20 +171,19 @@ foreach ($workPerUser as $work) {
} }
if (api_is_allowed_to_edit()) { if (api_is_allowed_to_edit()) {
$url = api_get_path(WEB_CODE_PATH).'work/edit.php?'.api_get_cidreq().'&item_id='.$itemId.'&id='.$workId.'&parent_id='.$workId; $url = api_get_path(WEB_CODE_PATH).
'work/edit.php?'.api_get_cidreq().'&item_id='.$itemId.'&id='.$workId.'&parent_id='.$workId;
$links .= Display::url( $links .= Display::url(
Display::return_icon('edit.png', get_lang('Comment')), Display::return_icon('edit.png', get_lang('Comment')),
$url $url
); );
} }
$table->setCellContents($row, $column, $links); $table->setCellContents($row, $column, $links);
$row++; $row++;
$column = 0; $column = 0;
} }
} }
echo Display::page_subheader($userInfo['complete_name']); echo Display::page_subheader($completeName);
echo $table->toHtml(); echo $table->toHtml();
Display :: display_footer(); Display::display_footer();

@ -4,6 +4,7 @@
use Chamilo\CoreBundle\Entity\Course; use Chamilo\CoreBundle\Entity\Course;
use Chamilo\CoreBundle\Entity\ResourceLink; use Chamilo\CoreBundle\Entity\ResourceLink;
use Chamilo\CoreBundle\Entity\User;
use Chamilo\CoreBundle\Framework\Container; use Chamilo\CoreBundle\Framework\Container;
use Chamilo\CourseBundle\Entity\CDocument; use Chamilo\CourseBundle\Entity\CDocument;
use Chamilo\CourseBundle\Entity\CStudentPublication; use Chamilo\CourseBundle\Entity\CStudentPublication;
@ -347,39 +348,6 @@ function getWorkList($id, $my_folder_data, $add_in_where_query = null, $course_i
return $work_parents; return $work_parents;
} }
/**
* @param int $userId
* @param int $courseId
* @param int $sessionId
*
* @return array
*/
function getWorkPerUser($userId, $courseId = 0, $sessionId = 0)
{
$works = getWorkList(null, null, null, $courseId, $sessionId);
$result = [];
if (!empty($works)) {
foreach ($works as $workData) {
$workId = $workData->getIid();
$result[$workId]['work'] = $workData;
$result[$workId]['work']->user_results = get_work_user_list(
0,
100,
null,
null,
$workId,
null,
$userId,
false,
$courseId,
$sessionId
);
}
}
return $result;
}
/** /**
* @param int $workId * @param int $workId
* @param int $groupId * @param int $groupId
@ -2260,7 +2228,7 @@ function get_work_user_list(
$qualification_string = formatWorkScore($qualification, $qualification); $qualification_string = formatWorkScore($qualification, $qualification);
} }
} }
$work['iid'] = $assignment->getIid();
$work['qualification_score'] = $studentPublication->getQualification(); $work['qualification_score'] = $studentPublication->getQualification();
$add_string = ''; $add_string = '';
$time_expires = ''; $time_expires = '';
@ -3391,8 +3359,8 @@ function get_list_users_without_publication($task_id, $studentId = 0)
$new_group_user_list = []; $new_group_user_list = [];
if ($group_id) { if ($group_id) {
$groupInfo = GroupManager::get_group_properties($group_id); $group = api_get_group_entity($group_id);
$group_user_list = GroupManager::get_subscribed_users($groupInfo); $group_user_list = GroupManager::get_subscribed_users($group);
if (!empty($group_user_list)) { if (!empty($group_user_list)) {
foreach ($group_user_list as $group_user) { foreach ($group_user_list as $group_user) {
$new_group_user_list[] = $group_user['user_id']; $new_group_user_list[] = $group_user['user_id'];
@ -5344,23 +5312,22 @@ function updatePublicationAssignment($workId, $params, $courseInfo, $groupId)
/** /**
* Delete all work by student. * Delete all work by student.
* *
* @param int $userId
* @param array $courseInfo
*
* @return array return deleted items * @return array return deleted items
*/ */
function deleteAllWorkPerUser($userId, $courseInfo) function deleteAllWorkPerUser(User $user, Course $course)
{ {
$deletedItems = []; $deletedItems = [];
$workPerUser = getWorkPerUser($userId); //$workPerUser = getWorkPerUser($userId);
if (!empty($workPerUser)) { $repo = Container::getStudentPublicationRepository();
foreach ($workPerUser as $work) { $works = $repo->getStudentPublicationByUser($user, $course);
$work = $work['work'];
foreach ($work->user_results as $userResult) { foreach ($works as $workData) {
$result = deleteWorkItem($userResult['iid'], $courseInfo); /** @var CStudentPublication[] $results */
if ($result) { $results = $workData['results'];
$deletedItems[] = $userResult; foreach ($results as $userResult) {
} $result = deleteWorkItem($userResult->getIid(), $course);
if ($result) {
$deletedItems[] = $userResult;
} }
} }
} }
@ -5369,16 +5336,16 @@ function deleteAllWorkPerUser($userId, $courseInfo)
} }
/** /**
* @param int $item_id * @param int $item_id
* @param array $courseInfo course info * @param Course $course course info
* *
* @return bool * @return bool
*/ */
function deleteWorkItem($item_id, $courseInfo) function deleteWorkItem($item_id, Course $course)
{ {
$item_id = (int) $item_id; $item_id = (int) $item_id;
if (empty($item_id) || empty($courseInfo)) { if (empty($item_id) || null === $course) {
return false; return false;
} }
@ -5388,7 +5355,7 @@ function deleteWorkItem($item_id, $courseInfo)
$is_author = user_is_author($item_id); $is_author = user_is_author($item_id);
$work_data = get_work_data_by_id($item_id); $work_data = get_work_data_by_id($item_id);
$locked = api_resource_is_locked_by_gradebook($work_data['parent_id'], LINK_STUDENTPUBLICATION); $locked = api_resource_is_locked_by_gradebook($work_data['parent_id'], LINK_STUDENTPUBLICATION);
$course_id = $courseInfo['real_id']; $course_id = $course->getId();
if (($is_allowed_to_edit && false == $locked) || if (($is_allowed_to_edit && false == $locked) ||
( (
@ -6158,7 +6125,6 @@ function exportAllWork($userId, $courseInfo, $format = 'pdf')
case 'pdf': case 'pdf':
if (!empty($workPerUser)) { if (!empty($workPerUser)) {
$pdf = new PDF(); $pdf = new PDF();
$content = null; $content = null;
foreach ($workPerUser as $work) { foreach ($workPerUser as $work) {
$work = $work['work']; $work = $work['work'];

@ -9,24 +9,22 @@ $current_course_tool = TOOL_STUDENTPUBLICATION;
api_protect_course_script(true); api_protect_course_script(true);
$this_section = SECTION_COURSES; $this_section = SECTION_COURSES;
$workId = isset($_GET['id']) ? (int) $_GET['id'] : null; $workId = isset($_GET['id']) ? (int) $_GET['id'] : null;
$courseInfo = api_get_course_info(); $courseInfo = api_get_course_info();
if (empty($workId) || empty($courseInfo)) { if (empty($workId) || empty($courseInfo)) {
api_not_allowed(true); api_not_allowed(true);
} }
$course = api_get_course_entity();
// Student publications are saved with the iid in a LP // Student publications are saved with the iid in a LP
$origin = api_get_origin(); $origin = api_get_origin();
if ('learnpath' === $origin) { if ('learnpath' === $origin) {
$em = Database::getManager(); $em = Database::getManager();
/** @var CStudentPublication $work */ /** @var CStudentPublication $work */
$work = $em->getRepository(CStudentPublication::class)->findOneBy( $work = $em->getRepository(CStudentPublication::class)->find($workId);
['iid' => $workId, 'cId' => $courseInfo['real_id']]
);
if ($work) { if ($work) {
$workId = $work->getIid(); $workId = $work->getIid();
} }
@ -44,14 +42,14 @@ $htmlHeadXtra[] = api_get_jqgrid_js();
$url_dir = api_get_path(WEB_CODE_PATH).'work/work.php?'.api_get_cidreq(); $url_dir = api_get_path(WEB_CODE_PATH).'work/work.php?'.api_get_cidreq();
if (!empty($group_id)) { if (!empty($group_id)) {
$group_properties = GroupManager :: get_group_properties($group_id); $group = api_get_group_entity($group_id);
$interbreadcrumb[] = [ $interbreadcrumb[] = [
'url' => api_get_path(WEB_CODE_PATH).'group/group.php?'.api_get_cidreq(), 'url' => api_get_path(WEB_CODE_PATH).'group/group.php?'.api_get_cidreq(),
'name' => get_lang('Groups'), 'name' => get_lang('Groups'),
]; ];
$interbreadcrumb[] = [ $interbreadcrumb[] = [
'url' => api_get_path(WEB_CODE_PATH).'group/group_space.php?'.api_get_cidreq(), 'url' => api_get_path(WEB_CODE_PATH).'group/group_space.php?'.api_get_cidreq(),
'name' => get_lang('Group area').' '.$group_properties['name'], 'name' => get_lang('Group area').' '.$group->getName(),
]; ];
} }
@ -138,7 +136,7 @@ $item_id = isset($_REQUEST['item_id']) ? (int) $_REQUEST['item_id'] : null;
switch ($action) { switch ($action) {
case 'delete': case 'delete':
$fileDeleted = deleteWorkItem($item_id, $courseInfo); $fileDeleted = deleteWorkItem($item_id, $course);
if (!$fileDeleted) { if (!$fileDeleted) {
Display::addFlash(Display::return_message(get_lang('You are not allowed to delete this document'))); Display::addFlash(Display::return_message(get_lang('You are not allowed to delete this document')));

@ -22,7 +22,7 @@ $my_folder_data = get_work_data_by_id($workId);
if (empty($my_folder_data)) { if (empty($my_folder_data)) {
api_not_allowed(true); api_not_allowed(true);
} }
$course = api_get_course_entity();
$work_data = get_work_assignment_by_id($workId); $work_data = get_work_assignment_by_id($workId);
$studentPublicationRepo = Container::getStudentPublicationRepository(); $studentPublicationRepo = Container::getStudentPublicationRepository();
@ -96,7 +96,7 @@ switch ($action) {
case 'delete': case 'delete':
/* Delete document */ /* Delete document */
if ($itemId) { if ($itemId) {
$fileDeleted = deleteWorkItem($itemId, $courseInfo); $fileDeleted = deleteWorkItem($itemId, $course);
if (!$fileDeleted) { if (!$fileDeleted) {
Display::addFlash( Display::addFlash(
Display::return_message(get_lang('You are not allowed to delete this document'), 'error') Display::return_message(get_lang('You are not allowed to delete this document'), 'error')

@ -78,12 +78,7 @@ class CGlossary extends AbstractResource implements ResourceInterface
return $this->description; return $this->description;
} }
/** public function setDisplayOrder(int $displayOrder): self
* Set displayOrder.
*
* @return CGlossary
*/
public function setDisplayOrder(int $displayOrder)
{ {
$this->displayOrder = $displayOrder; $this->displayOrder = $displayOrder;

@ -369,7 +369,10 @@ class CGroup extends AbstractResource implements ResourceInterface
return $this; return $this;
} }
public function getMembers(): Collection /**
* @return CGroupRelUser[]|Collection
*/
public function getMembers()
{ {
return $this->members; return $this->members;
} }
@ -407,7 +410,10 @@ class CGroup extends AbstractResource implements ResourceInterface
return $this->tutors->matching($criteria)->count() > 0; return $this->tutors->matching($criteria)->count() > 0;
} }
public function getTutors(): Collection /**
* @return CGroupRelTutor[]|Collection
*/
public function getTutors()
{ {
return $this->tutors; return $this->tutors;
} }

@ -656,7 +656,10 @@ class CSurvey extends AbstractResource implements ResourceInterface
return $this->isMandatory; return $this->isMandatory;
} }
public function getQuestions(): Collection /**
* @return CSurveyQuestion[]|Collection
*/
public function getQuestions()
{ {
return $this->questions; return $this->questions;
} }

@ -44,8 +44,9 @@ final class CStudentPublicationRepository extends ResourceRepository
public function getStudentAssignments( public function getStudentAssignments(
CStudentPublication $publication, CStudentPublication $publication,
Course $course, Course $course,
Session $session = null, ?Session $session = null,
CGroup $group = null ?CGroup $group = null,
?User $user = null
): QueryBuilder { ): QueryBuilder {
$qb = $this->getResourcesByCourse($course, $session, $group); $qb = $this->getResourcesByCourse($course, $session, $group);
@ -58,6 +59,22 @@ final class CStudentPublicationRepository extends ResourceRepository
return $qb; return $qb;
} }
public function getStudentPublicationByUser(User $user, Course $course, Session $session = null)
{
$qb = $this->findAllByCourse($course, $session);
/** @var CStudentPublication[] $works */
$works = $qb->getQuery()->getResult();
$list = [];
foreach ($works as $work) {
$qb = $this->getStudentAssignments($work, $course, $session, null, $user);
$results = $qb->getQuery()->getResult();
$list[$work->getIid()]['work'] = $work;
$list[$work->getIid()]['results'] = $results;
}
return $list;
}
public function countUserPublications(User $user, Course $course, Session $session = null, CGroup $group = null): int public function countUserPublications(User $user, Course $course, Session $session = null, CGroup $group = null): int
{ {
$qb = $this->getResourcesByCourseLinkedToUser($user, $course, $session); $qb = $this->getResourcesByCourseLinkedToUser($user, $course, $session);

Loading…
Cancel
Save