Replace custom queries with entities

pull/3844/head
Julio Montoya 4 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'];
$new_course_list = SessionManager::get_course_list_by_session_id($new_session_id);
$course_founded = false;
@ -123,6 +122,7 @@ if (isset($_REQUEST['load_ajax'])) {
// Begin with the import process
$course_info = api_get_course_info($origin_course_code);
$course_id = $course_info['real_id'];
$course = api_get_course_entity($course_id);
$TABLETRACK_EXERCICES = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
$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
$score = Tracking::get_avg_student_score(
$user_id,
$origin_course_code,
$course,
[$data['lp_id']],
$origin_session_id
$session
);
$progress = Tracking::get_avg_student_progress(
$user_id,
$origin_course_code,
$course,
[$data['lp_id']],
$origin_session_id
$session
);
$result_message['LP_VIEW'][$data['lp_id']] = [
'score' => $score,

@ -51,14 +51,13 @@ $tbl_item_property = Database::get_course_table(TABLE_ITEM_PROPERTY);
$isTutor = false;
if (!empty($group_id)) {
$groupEntity = api_get_group_entity($group_id);
$groupProperties = GroupManager::get_group_properties($group_id);
$interbreadcrumb[] = [
'url' => api_get_path(WEB_CODE_PATH).'group/group.php?'.api_get_cidreq(),
'name' => get_lang('Groups'),
];
$interbreadcrumb[] = [
'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) {
@ -68,7 +67,7 @@ if (!empty($group_id)) {
$allowToEdit = true;
}
// 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;
}
}
@ -488,7 +487,7 @@ switch ($action) {
}
$element = CourseManager::addUserGroupMultiSelect($form, []);
} else {
$element = CourseManager::addGroupMultiSelect($form, $groupProperties, []);
$element = CourseManager::addGroupMultiSelect($form, $groupEntity, []);
}
$form->addHtml('</div>');

@ -1,12 +1,16 @@
<?php
use Chamilo\CoreBundle\Entity\Course;
/* For licensing terms, see /license.txt */
/**
/*
* 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.
*/
exit;
require_once __DIR__.'/../../main/inc/global.inc.php';
api_protect_admin_script();
@ -35,9 +39,8 @@ foreach ($sessions as $session) {
continue;
}
}
$courseInfo = api_get_course_info_by_id($courseId);
$courseCode = $courseInfo['code'];
$course = api_get_course_entity($courseId);
$courseCode = $course->getCode();
$users = CourseManager::get_user_list_from_course_code(
$courseCode,
@ -48,9 +51,9 @@ foreach ($sessions as $session) {
);
foreach ($users as $user) {
$result = compareLpTimeAndCourseTime($user, $courseInfo, $sessionId);
$result = compareLpTimeAndCourseTime($user, $course, $sessionId);
if ($result) {
$counter++;
++$counter;
}
if ($counter > $max) {
@ -73,22 +76,22 @@ foreach($courses as $courseInfo) {
}*/
/**
* @param array $user
* @param array $courseInfo
* @param int $sessionId
* @param array $user
* @param Course $course
* @param int $sessionId
*
* @return bool
*/
function compareLpTimeAndCourseTime($user, $courseInfo, $sessionId = 0)
function compareLpTimeAndCourseTime($user, Course $course, $sessionId = 0)
{
$userId = $user['user_id'];
$defaultValue = 600; // 10 min
$courseCode = $courseInfo['code'];
$courseId = $courseInfo['real_id'];
$courseCode = $course->getCode();
$courseId = $course->getId();
$totalLpTime = Tracking::get_time_spent_in_lp(
$userId,
$courseCode,
$course,
[],
$sessionId
);
@ -108,8 +111,8 @@ function compareLpTimeAndCourseTime($user, $courseInfo, $sessionId = 0)
$totalLpTimeFormatted = api_time_to_hms($totalLpTime);
$diff = $totalLpTime - $totalCourseTime;
$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.'User: '.$user['user_id']." - Total course: $totalCourseTimeFormatted / Total LP: $totalLpTimeFormatted".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;
$content .= Display::url('Check', $url, ['target' => '_blank']);
$content .= PHP_EOL;
@ -135,15 +138,15 @@ function compareLpTimeAndCourseTime($user, $courseInfo, $sessionId = 0)
$lpId = $item['lp_id'];
$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;
$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 .= "SQL with possible fix:".PHP_EOL;
$content .= 'SQL with possible fix:'.PHP_EOL;
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;
}
$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_')) {
$new_work_recipients[] = substr($rec, strlen('user_'));
} elseif (0 === strpos($rec, 'group_')) {
$groupInfo = GroupManager::get_group_properties(substr($rec, strlen('group_')));
$userList = GroupManager::get_subscribed_users($groupInfo);
$group = api_get_group_entity(substr($rec, strlen('group_')));
$userList = GroupManager::get_subscribed_users($group);
foreach ($userList as $usr) {
if (!in_array($usr['user_id'], $new_work_recipients) && $usr['user_id'] != $_user['user_id']) {
$new_work_recipients[] = $usr['user_id'];

@ -150,7 +150,7 @@ if (!empty($complete_user_list)) {
}
// Group members
$group_member_list = GroupManager::get_subscribed_users($current_group);
$group_member_list = GroupManager::get_subscribed_users($groupEntity);
$selected_users = [];
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)
$cat = GroupManager::get_category_from_group($current_group['iid']);
$cat = GroupManager::get_category_from_group($group_id);
$categoryId = 0;
if ($cat) {
$categoryId = $cat['iid'];
}
$max_member = $current_group['max_student'];
$max_member = $groupEntity->getMaxStudent();
if (isset($_POST['group_members']) &&
count($_POST['group_members']) > $max_member &&

@ -2,6 +2,9 @@
/* For licensing terms, see /license.txt */
use Chamilo\CoreBundle\Framework\Container;
use Chamilo\CourseBundle\Entity\CGroup;
require_once __DIR__.'/../inc/global.inc.php';
$this_section = SECTION_COURSES;
$current_course_tool = TOOL_GROUP;
@ -10,9 +13,8 @@ $current_course_tool = TOOL_GROUP;
api_protect_course_script(true);
$group_id = api_get_group_id();
$groupRepo = \Chamilo\CoreBundle\Framework\Container::getGroupRepository();
/** @var \Chamilo\CourseBundle\Entity\CGroup $groupEntity */
$groupEntity = $groupRepo->find($group_id);
$groupRepo = Container::getGroupRepository();
$groupEntity = api_get_group_entity($group_id);
$current_group = GroupManager::get_group_properties($group_id);
$nameTools = get_lang('Edit this group');
@ -101,7 +103,7 @@ $complete_user_list = CourseManager::get_user_list_from_course_code(
$possible_users = [];
$userGroup = new UserGroup();
$subscribedUsers = GroupManager::get_subscribed_users($current_group);
$subscribedUsers = GroupManager::get_subscribed_users($groupEntity);
if ($subscribedUsers) {
$subscribedUsers = array_column($subscribedUsers, 'user_id');
}
@ -157,13 +159,13 @@ if ($form->validate()) {
$values = $form->exportValues();
// 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) {
GroupManager::subscribeTutors($values['group_tutors'], $groupEntity);
}
// 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;
$max_member = null;
if (!empty($cat)) {

@ -48,11 +48,13 @@ switch ($action) {
foreach ($sessionList as $session) {
$courses = $session['courses'];
$sessionId = $session['session_id'];
$sessionEntity = api_get_session_entity($sessionId);
$session['session_name'];
$totalCourse = 0;
$totalSessionAverage = 0;
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;
$totalCourse++;
if (false !== $average) {

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

@ -428,7 +428,8 @@ class CourseManager
Database::query($sql);
// 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) {
// Getting all work from user
$workList = getWorkPerUser($userId);
@ -444,7 +445,7 @@ class CourseManager
}
}
}
}
}*/
// Unsubscribe user from all blogs in the course.
$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
* 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 string $limit
* @param string $order_by the field to order the users by.
@ -1303,7 +1304,7 @@ class CourseManager
* @return array|int
*/
public static function get_user_list_from_course_code(
$course_code = null,
$courseCode,
$sessionId = 0,
$limit = null,
$order_by = null,
@ -1323,13 +1324,17 @@ class CourseManager
$sessionTable = Database::get_main_table(TABLE_MAIN_SESSION);
$sessionId = (int) $sessionId;
$course_code = Database::escape_string($course_code);
$courseInfo = api_get_course_info($course_code);
$courseCode = Database::escape_string($courseCode);
$courseInfo = api_get_course_info($courseCode);
$courseId = 0;
if (!empty($courseInfo)) {
$courseId = $courseInfo['real_id'];
}
$session = null;
if (!empty($sessionId)) {
$session = api_get_session_entity($sessionId);
}
$course = api_get_course_entity($courseId);
$where = [];
if (empty($order_by)) {
$order_by = 'user.lastname, user.firstname';
@ -1422,7 +1427,7 @@ class CourseManager
if ($return_count) {
$sql = " SELECT COUNT(*) as count";
} else {
if (empty($course_code)) {
if (empty($courseCode)) {
$sql = 'SELECT DISTINCT
course.title,
course.code,
@ -1454,7 +1459,7 @@ class CourseManager
$sqlInjectJoins
";
if (!empty($course_code)) {
if (!empty($courseId)) {
$sql .= " AND course_rel_user.c_id = $courseId";
}
$where[] = ' course_rel_user.c_id IS NOT NULL ';
@ -1568,7 +1573,6 @@ class CourseManager
}
$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'].') ' : '';
if ($add_reports) {
@ -1628,7 +1632,7 @@ class CourseManager
$category = Category:: load(
null,
null,
$course_code,
$courseCode,
null,
null,
$sessionId
@ -1643,7 +1647,7 @@ class CourseManager
}
foreach ($extra_fields as $extra) {
if ('ruc' == $extra['1']) {
if ('ruc' === $extra['1']) {
continue;
}
@ -1669,7 +1673,7 @@ class CourseManager
$category = Category:: load(
null,
null,
$course_code,
$courseCode,
null,
null,
$sessionId
@ -1680,18 +1684,15 @@ class CourseManager
$report_info['certificate'] = Display::label(get_lang('Yes'), 'success');
}
$progress = intval(
Tracking::get_avg_student_progress(
$user['user_id'],
$course_code,
[],
$sessionId
)
$progress = (int) Tracking::get_avg_student_progress(
$user['user_id'],
$course,
[],
$session
);
$report_info['progress_100'] = 100 == $progress ? Display::label(get_lang('Yes'), 'success') : Display::label(get_lang('No'));
$report_info['progress'] = $progress."%";
foreach ($extra_fields as $extra) {
$user_data = UserManager::get_extra_user_data_by_field($user['user_id'], $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.
*
* @param FormValidator $form
* @param array $groupInfo
* @param array $to
*
* @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);
$groupEntity = api_get_group_entity($groupInfo['iid']);
$array = self::buildSelectOptions([$groupEntity], $groupUsers, $to);
$groupUsers = GroupManager::get_subscribed_users($group);
$array = self::buildSelectOptions([$group], $groupUsers, $to);
$result = [];
foreach ($array as $content) {

@ -3,9 +3,12 @@
/* For licensing terms, see /license.txt */
use Chamilo\CoreBundle\Entity\Course;
use Chamilo\CoreBundle\Entity\User;
use Chamilo\CoreBundle\Framework\Container;
use Chamilo\CourseBundle\Entity\CGroup;
use Chamilo\CourseBundle\Entity\CGroupCategory;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Criteria;
/**
* This library contains some functions for group-management.
@ -549,9 +552,10 @@ class GroupManager
$result['chat_state'] = $db_object->chat_state;
$result['self_registration_allowed'] = $db_object->self_registration_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)
);
);*/
/*$result['count_tutor'] = count(
self::get_subscribed_tutors($result)
);*/
@ -1625,60 +1629,45 @@ class GroupManager
/**
* Get all subscribed users (members) from a group.
*
* @param array $groupInfo
*
* @return array An array with information of all users from the given group.
* (user_id, firstname, lastname, email)
*/
public static function get_subscribed_users($groupInfo)
public static function get_subscribed_users(CGroup $group)
{
if (empty($groupInfo)) {
return [];
//$order = api_sort_by_first_name() ? ' ORDER BY u.firstname, u.lastname' : ' ORDER BY u.lastname, u.firstname';
$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');
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'];
if (empty($group_id)) {
return [];
$users = $group->getMembers();
$userList = [];
foreach ($users as $groupRelUser) {
$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
ug.iid,
u.id as user_id,
u.lastname,
u.firstname,
u.email,
u.username
FROM $table_user u
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,
$list = [];
foreach ($users as $user) {
$list[$user->getId()] = [
'user_id' => $user->getId(),
'firstname' => $user->getFirstname(),
'lastname' => $user->getLastname(),
'email' => $user->getEmail(),
'username' => $user->getUsername(),
];
}
return $users;
return $list;
}
/**

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

@ -408,7 +408,12 @@ class SortableTable extends HTML_Table
if (count($this->form_actions) > 0) {
$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>';

@ -179,7 +179,8 @@ class Tracking
$user_id = (int) $user_id;
$session_id = (int) $session_id;
$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);
$course_id = $courseInfo['real_id'];
$courseCode = $courseInfo['code'];
@ -2814,7 +2815,7 @@ class Tracking
// Compose a filter based on optional learning paths list given
$condition_lp = '';
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
@ -3243,7 +3244,7 @@ class Tracking
* This function gets time spent in learning path for a student inside a course.
*
* @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 int $session_id Session id (optional), if param $session_id is null(default)
* 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(
$student_id,
$course_code,
Course $course,
$lp_ids = [],
$session_id = 0
) {
$course = api_get_course_info($course_code);
$student_id = (int) $student_id;
$session_id = (int) $session_id;
$total_time = 0;
@ -3267,18 +3267,18 @@ class Tracking
$lpViewTable = Database::get_course_table(TABLE_LP_VIEW);
$lpItemViewTable = Database::get_course_table(TABLE_LP_ITEM_VIEW);
$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
$condition_lp = '';
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
// database (and if no list was given, get them all)
$sql = "SELECT DISTINCT(iid) FROM $lpTable
WHERE c_id = $course_id $condition_lp";
WHERE $condition_lp";
$result = Database::query($sql);
$session_condition = api_get_session_condition($session_id);
@ -3286,10 +3286,10 @@ class Tracking
if (Database::num_rows($result) > 0) {
while ($row = Database::fetch_array($result)) {
$lp_id = (int) $row['iid'];
$lp = Container::getLpRepository()->find($lp_id);
// Start Exercise in LP 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) {
$sql = "SELECT max(view_count)
FROM $lpViewTable
@ -3316,9 +3316,9 @@ class Tracking
path
FROM $lpItemTable as i
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
ON (iv.lp_view_id = v.iid AND v.c_id = iv.c_id)
ON (iv.lp_view_id = v.iid)
WHERE
v.c_id = $course_id AND
i.iid = $itemId AND
@ -3373,11 +3373,9 @@ class Tracking
FROM $lpItemViewTable AS item_view
INNER JOIN $lpViewTable AS view
ON (
item_view.lp_view_id = view.iid AND
item_view.c_id = view.c_id
item_view.lp_view_id = view.iid
)
WHERE
item_view.c_id = $course_id AND
view.c_id = $course_id AND
view.lp_id = $lp_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
// database (and if no list was given, get them all)
$sql = "SELECT iid FROM $lp_table
WHERE c_id = $course_id AND iid = $lp_id ";
WHERE iid = $lp_id ";
$row = Database::query($sql);
$count = Database::num_rows($row);
@ -3465,10 +3463,9 @@ class Tracking
$sql = 'SELECT MAX(start_time)
FROM '.$t_lpiv.' AS item_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
status != "not attempted" AND
item_view.c_id = '.$course_id.' AND
view.c_id = '.$course_id.' AND
view.lp_id = '.$lp_id.' AND
view.user_id = '.$student_id.' AND
@ -8669,9 +8666,12 @@ class TrackingCourseLog
$number_of_items,
$column,
$direction,
$includeInvitedUsers = false
$params = []
) {
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);
$tbl_user = Database::get_main_table(TABLE_MAIN_USER);
@ -8683,7 +8683,7 @@ class TrackingCourseLog
$user_ids = array_map('intval', $user_ids);
$condition_user = " WHERE user.user_id IN (".implode(',', $user_ids).") ";
} else {
$user_ids = intval($user_ids);
$user_ids = (int) $user_ids;
$condition_user = " WHERE user.user_id = $user_ids ";
}
@ -8699,7 +8699,8 @@ class TrackingCourseLog
$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.lastname as col1,
user.firstname as col2,
@ -8722,8 +8723,7 @@ class TrackingCourseLog
$users = [];
$sortByFirstName = api_sort_by_first_name();
$courseInfo = api_get_course_info($course_code);
$courseId = $courseInfo['real_id'];
$course = api_get_course_entity($courseId);
while ($user = Database::fetch_array($res, 'ASSOC')) {
$user['official_code'] = $user['col0'];
@ -8740,7 +8740,7 @@ class TrackingCourseLog
$user['time'] = api_time_to_hms($totalCourseTime);
$totalLpTime = Tracking::get_time_spent_in_lp(
$user['user_id'],
$course_code,
$course,
[],
$session_id
);
@ -8752,7 +8752,6 @@ class TrackingCourseLog
}
$user['total_lp_time'] = api_time_to_hms($totalLpTime).$warning;
$user['first_connection'] = Tracking::get_first_connection_date_on_the_course(
$user['user_id'],
$courseId,
@ -8765,11 +8764,13 @@ class TrackingCourseLog
false === $export_csv
);
$user['link'] = '<center>
<a href="../mySpace/myStudents.php?student='.$user['user_id'].'&details=true&course='.$course_code.'&origin=tracking_course&id_session='.$session_id.'">
'.Display::return_icon('2rightarrow.png', get_lang('Details')).'
</a>
</center>';
$user['link'] = '
<center>
<a
href="../mySpace/myStudents.php?student='.$user['user_id'].'&details=true&cid='.$courseId.'&origin=tracking_course&sid='.$session_id.'">
'.Display::return_icon('2rightarrow.png', get_lang('Details')).'
</a>
</center>';
// store columns in array $users
$user_row = [];
@ -8786,7 +8787,6 @@ class TrackingCourseLog
$user_row['total_lp_time'] = $user['total_lp_time'];
$user_row['first_connection'] = $user['first_connection'];
$user_row['last_connection'] = $user['last_connection'];
$user_row['link'] = $user['link'];
$users[] = array_values($user_row);
}

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

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

@ -6,6 +6,7 @@ use Chamilo\CoreBundle\Entity\Asset;
use Chamilo\CoreBundle\Framework\Container;
use Chamilo\CourseBundle\Entity\CLp;
use Chamilo\CourseBundle\Entity\CLpItem;
use League\Flysystem\Filesystem;
use League\Flysystem\ZipArchive\ZipArchiveAdapter;
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'];
$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/
if ($this->debug > 1) {
@ -600,7 +597,7 @@ class scorm extends learnpath
}
$zipAdapter = new ZipArchiveAdapter($zipFilePath);
$filesystem = new \League\Flysystem\Filesystem($zipAdapter);
$filesystem = new Filesystem($zipAdapter);
$zipContentArray = $filesystem->listContents();
$packageType = '';

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

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

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

@ -285,8 +285,10 @@ if (count($a_students) > 0) {
(api_is_western_name_order() xor api_sort_by_first_name()) ? 3 : 2
);
$parameters['cidReq'] = Security::remove_XSS($_GET['cidReq']);
$parameters['id_session'] = $session_id;
$table->setDataFunctionParams(['cid' => api_get_course_int_id(), 'sid' => $session_id]);
$parameters['cid'] = api_get_course_int_id();
$parameters['sid'] = $session_id;
$parameters['from'] = isset($_GET['myspace']) ? Security::remove_XSS($_GET['myspace']) : null;
$table->set_additional_parameters($parameters);
@ -308,15 +310,27 @@ if (count($a_students) > 0) {
$table->set_header(3, get_lang('Login'), false);
$headers['login'] = get_lang('Login');
$table->set_header(4, get_lang('Time').'&nbsp;'.
Display::return_icon('info3.gif', get_lang('Time spent in the course'), ['align' => 'absmiddle', 'hspace' => '3px']),
$table->set_header(
4,
get_lang('Time').'&nbsp;'.
Display::return_icon(
'info3.gif',
get_lang('Time spent in the course'),
['align' => 'absmiddle', 'hspace' => '3px']
),
false,
['style' => 'width:110px;']
);
$headers['training_time'] = get_lang('Time');
$table->set_header(5, get_lang('Total learnpath time').'&nbsp;'.
Display::return_icon('info3.gif', get_lang('Total learnpath time'), ['align' => 'absmiddle', 'hspace' => '3px']),
$table->set_header(
5,
get_lang('Total learnpath time').'&nbsp;'.
Display::return_icon(
'info3.gif',
get_lang('Total learnpath time'),
['align' => 'absmiddle', 'hspace' => '3px']
),
false,
['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 ($debug) {
error_log("LP deleted $lpId");
}
$course_dir = $courseInfo['directory'].'/document';
$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);
$base_work_dir = null;
$items = $lp->get_flat_ordered_items_list($lp, 0, $courseId);
if (!empty($items)) {
/** @var $item learnpathItem */
@ -476,7 +473,6 @@ function WSDeleteLp($params)
if ($item) {
$documentId = $item->get_path();
if ($debug) {
error_log("lp item id found #$itemId");
}

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

@ -2,6 +2,9 @@
/* For licensing terms, see /license.txt */
use Chamilo\CoreBundle\Framework\Container;
use Chamilo\CourseBundle\Entity\CStudentPublication;
require_once __DIR__.'/../inc/global.inc.php';
$current_course_tool = TOOL_STUDENTPUBLICATION;
@ -9,7 +12,6 @@ api_protect_course_script(true);
api_protect_course_group(GroupManager::GROUP_TOOL_WORK);
$this_section = SECTION_COURSES;
$studentId = isset($_GET['studentId']) ? (int) ($_GET['studentId']) : null;
if (empty($studentId)) {
@ -18,15 +20,17 @@ if (empty($studentId)) {
$tool_name = get_lang('Assignments');
$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();
$course = api_get_course_entity();
$session = api_get_session_entity();
if (empty($userInfo) || empty($courseInfo)) {
if (null === $user || null === $course) {
api_not_allowed(true);
}
// Only a teachers page.
if (!empty($group_id)) {
$group_properties = GroupManager::get_group_properties($group_id);
$interbreadcrumb[] = [
@ -43,7 +47,7 @@ if (!empty($group_id)) {
}
}
$action = isset($_GET['action']) ? $_GET['action'] : null;
$action = $_GET['action'] ?? null;
switch ($action) {
case 'export_to_pdf':
@ -59,7 +63,7 @@ switch ($action) {
break;
case 'delete_all':
if (api_is_allowed_to_edit()) {
$deletedItems = deleteAllWorkPerUser($studentId, $courseInfo);
$deletedItems = deleteAllWorkPerUser($user, $course);
if (!empty($deletedItems)) {
$message = get_lang('File deleted').'<br >';
foreach ($deletedItems as $item) {
@ -81,30 +85,33 @@ $interbreadcrumb[] = [
];
$interbreadcrumb[] = [
'url' => '#',
'name' => $userInfo['complete_name'],
'name' => $completeName,
];
Display :: display_header(null);
$workPerUser = getWorkPerUser($studentId);
Display::display_header(null);
echo '<div class="actions">';
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()) {
echo '<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=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().'">'.
Display::return_icon('save.png', get_lang('Download'), '', ICON_SIZE_MEDIUM).'</a>';
echo '<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
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().'">'.
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>';
$table = new HTML_Table(['class' => 'data_table']);
@ -125,31 +132,35 @@ $row++;
$column = 0;
$url = api_get_path(WEB_CODE_PATH).'work/';
foreach ($workPerUser as $work) {
$work = $work['work'];
$scoreWeight = 0 == (int) ($work->qualification) ? null : $work->qualification;
$workId = $work->id;
$workExtraData = get_work_assignment_by_id($workId);
foreach ($work->user_results as $userResult) {
$itemId = $userResult['id'];
$table->setCellContents($row, $column, $work->title.' ['.trim(strip_tags($userResult['title'])).']');
$repo = Container::getStudentPublicationRepository();
$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'];
$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']);
$column++;
$table->setCellContents($row, $column, $userResult['sent_date']);
$table->setCellContents($row, $column, api_get_local_time($userResult->getSentDate()));
$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);
$column++;
$score = null;
$score = $userResult['qualification'];
$score = $userResult->getQualification();
$table->setCellContents($row, $column, $score);
$column++;
// Detail
$links = null;
// is a text
$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);
@ -160,20 +171,19 @@ foreach ($workPerUser as $work) {
}
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(
Display::return_icon('edit.png', get_lang('Comment')),
$url
);
}
$table->setCellContents($row, $column, $links);
$row++;
$column = 0;
}
}
echo Display::page_subheader($userInfo['complete_name']);
echo Display::page_subheader($completeName);
echo $table->toHtml();
Display :: display_footer();
Display::display_footer();

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

@ -9,24 +9,22 @@ $current_course_tool = TOOL_STUDENTPUBLICATION;
api_protect_course_script(true);
$this_section = SECTION_COURSES;
$workId = isset($_GET['id']) ? (int) $_GET['id'] : null;
$courseInfo = api_get_course_info();
if (empty($workId) || empty($courseInfo)) {
api_not_allowed(true);
}
$course = api_get_course_entity();
// Student publications are saved with the iid in a LP
$origin = api_get_origin();
if ('learnpath' === $origin) {
$em = Database::getManager();
/** @var CStudentPublication $work */
$work = $em->getRepository(CStudentPublication::class)->findOneBy(
['iid' => $workId, 'cId' => $courseInfo['real_id']]
);
$work = $em->getRepository(CStudentPublication::class)->find($workId);
if ($work) {
$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();
if (!empty($group_id)) {
$group_properties = GroupManager :: get_group_properties($group_id);
$group = api_get_group_entity($group_id);
$interbreadcrumb[] = [
'url' => api_get_path(WEB_CODE_PATH).'group/group.php?'.api_get_cidreq(),
'name' => get_lang('Groups'),
];
$interbreadcrumb[] = [
'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) {
case 'delete':
$fileDeleted = deleteWorkItem($item_id, $courseInfo);
$fileDeleted = deleteWorkItem($item_id, $course);
if (!$fileDeleted) {
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)) {
api_not_allowed(true);
}
$course = api_get_course_entity();
$work_data = get_work_assignment_by_id($workId);
$studentPublicationRepo = Container::getStudentPublicationRepository();
@ -96,7 +96,7 @@ switch ($action) {
case 'delete':
/* Delete document */
if ($itemId) {
$fileDeleted = deleteWorkItem($itemId, $courseInfo);
$fileDeleted = deleteWorkItem($itemId, $course);
if (!$fileDeleted) {
Display::addFlash(
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;
}
/**
* Set displayOrder.
*
* @return CGlossary
*/
public function setDisplayOrder(int $displayOrder)
public function setDisplayOrder(int $displayOrder): self
{
$this->displayOrder = $displayOrder;

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

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

@ -44,8 +44,9 @@ final class CStudentPublicationRepository extends ResourceRepository
public function getStudentAssignments(
CStudentPublication $publication,
Course $course,
Session $session = null,
CGroup $group = null
?Session $session = null,
?CGroup $group = null,
?User $user = null
): QueryBuilder {
$qb = $this->getResourcesByCourse($course, $session, $group);
@ -58,6 +59,22 @@ final class CStudentPublicationRepository extends ResourceRepository
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
{
$qb = $this->getResourcesByCourseLinkedToUser($user, $course, $session);

Loading…
Cancel
Save