Internal: Add files to psalm, fix psalm errors.

pull/3513/head
Julio Montoya 4 years ago
parent 2d11e47681
commit 32d53c3cbd
  1. 22
      psalm.xml
  2. 34
      public/main/admin/user_move_stats.php
  3. 4
      public/main/gradebook/lib/be/studentpublicationlink.class.php
  4. 3
      public/main/inc/ajax/session.ajax.php
  5. 6
      public/main/inc/lib/CourseChatUtils.php
  6. 3
      public/main/inc/lib/add_course.lib.inc.php
  7. 14
      public/main/inc/lib/api.lib.php
  8. 39
      public/main/inc/lib/attendance.lib.php
  9. 51
      public/main/inc/lib/course.lib.php
  10. 108
      public/main/inc/lib/sessionmanager.lib.php
  11. 2
      public/main/inc/lib/skill.visualizer.lib.php
  12. 36
      public/main/inc/lib/social.lib.php
  13. 28
      public/main/inc/lib/sortable_table.class.php
  14. 8
      public/main/inc/lib/thematic.lib.php
  15. 86
      public/main/inc/lib/usergroup.lib.php
  16. 11
      public/main/inc/lib/webservices/Rest.php
  17. 7
      public/main/portfolio/index.php
  18. 2
      public/main/session/index.php
  19. 6
      public/main/session/session_course_user.php
  20. 6
      public/main/survey/pending.php
  21. 4
      public/plugin/bbb/lib/bbb.lib.php
  22. 53
      src/CoreBundle/Entity/Session.php
  23. 60
      src/CoreBundle/Entity/User.php
  24. 18
      src/CoreBundle/Framework/Container.php
  25. 2
      src/CoreBundle/Traits/CourseControllerTrait.php
  26. 32
      src/CourseBundle/Entity/CAttendanceCalendar.php

@ -19,7 +19,29 @@
<!-- <directory name="public/main/session" /> -->
<!-- <directory name="public/main/exercise"/> -->
<file name="public/main/inc/lib/add_course.lib.inc.php"/>
<!-- <file name="public/main/inc/lib/agenda.lib.php"/>-->
<file name="public/main/inc/lib/attendance.lib.php"/>
<file name="public/main/inc/lib/career.lib.php"/>
<file name="public/main/inc/lib/course.lib.php"/>
<file name="public/main/inc/lib/course_category.lib.php"/>
<!-- <file name="public/main/inc/lib/course_description.lib.php"/>-->
<!-- <file name="public/main/inc/lib/course_home.lib.php"/>-->
<file name="public/main/inc/lib/course_request.lib.php"/>
<file name="public/main/inc/lib/sessionmanager.lib.php"/>
<!-- <file name="public/main/inc/lib/skill.lib.php"/>-->
<file name="public/main/inc/lib/skill.visualizer.lib.php"/>
<file name="public/main/inc/lib/social.lib.php"/>
<file name="public/main/inc/lib/sortable_table.class.php"/>
<file name="public/main/inc/lib/SortableTableFromArray.php"/>
<file name="public/main/inc/lib/SortableTableFromArrayConfig.php"/>
<file name="public/main/inc/lib/thematic.lib.php"/>
<file name="public/main/inc/lib/urlmanager.lib.php"/>
<file name="public/main/inc/lib/usergroup.lib.php"/>
<!-- <file name="public/main/inc/lib/usergroup.lib.php"/>-->
<ignoreFiles>
<directory name="vendor/*"/>

@ -77,7 +77,7 @@ if (isset($_REQUEST['load_ajax'])) {
$origin_course_code = $combination_result['course_code'];
$origin_session_id = (int) $combination_result['session_id'];
$new_session_id = (int) $_REQUEST['session_id'];
$session = $em->find('ChamiloCoreBundle:Session', $new_session_id);
$session = api_get_session_entity($new_session_id);
//if (!isset($_REQUEST['view_stat'])) {
if ($origin_session_id == $new_session_id) {
@ -169,9 +169,9 @@ if (isset($_REQUEST['load_ajax'])) {
// DESTINY COURSE
if (!$update_database) {
$sql = "SELECT * FROM $TABLETRACK_EXERCICES
WHERE
c_id = $course_id AND
session_id = $new_session_id AND
WHERE
c_id = $course_id AND
session_id = $new_session_id AND
exe_user_id = $user_id ";
$res = Database::query($sql);
$list = [];
@ -182,7 +182,7 @@ if (isset($_REQUEST['load_ajax'])) {
if (!empty($list)) {
foreach ($list as $exe_id => $data) {
if ($update_database) {
$sql = "UPDATE $TABLETRACK_EXERCICES
$sql = "UPDATE $TABLETRACK_EXERCICES
SET session_id = '$new_session_id'
WHERE exe_id = $exe_id";
$res = Database::query($sql);
@ -213,8 +213,8 @@ if (isset($_REQUEST['load_ajax'])) {
if (!empty($list)) {
foreach ($list as $id => $data) {
if ($update_database) {
$sql = "UPDATE $TBL_TRACK_E_COURSE_ACCESS
SET session_id = $new_session_id
$sql = "UPDATE $TBL_TRACK_E_COURSE_ACCESS
SET session_id = $new_session_id
WHERE course_access_id = $id";
if ($debug) {
echo $sql;
@ -239,8 +239,8 @@ if (isset($_REQUEST['load_ajax'])) {
if (!empty($list)) {
foreach ($list as $id) {
if ($update_database) {
$sql = "UPDATE $TBL_TRACK_E_LAST_ACCESS
SET access_session_id = $new_session_id
$sql = "UPDATE $TBL_TRACK_E_LAST_ACCESS
SET access_session_id = $new_session_id
WHERE access_id = $id";
if ($debug) {
echo $sql;
@ -273,8 +273,8 @@ if (isset($_REQUEST['load_ajax'])) {
if (!empty($list)) {
foreach ($list as $id => $data) {
if ($update_database) {
$sql = "UPDATE $TBL_LP_VIEW
SET session_id = $new_session_id
$sql = "UPDATE $TBL_LP_VIEW
SET session_id = $new_session_id
WHERE c_id = $course_id AND id = $id ";
if ($debug) {
var_dump($sql);
@ -348,7 +348,7 @@ if (isset($_REQUEST['load_ajax'])) {
//6. Agenda
//calendar_event_attachment no problems no session_id
$sql = "SELECT ref FROM $TBL_ITEM_PROPERTY
$sql = "SELECT ref FROM $TBL_ITEM_PROPERTY
WHERE tool = 'calendar_event' AND insert_user_id = $user_id AND c_id = $course_id ";
$res = Database::query($sql);
while ($row = Database::fetch_array($res, 'ASSOC')) {
@ -368,7 +368,7 @@ if (isset($_REQUEST['load_ajax'])) {
//7. Forum ?? So much problems when trying to import data
//8. Student publication - Works
$sql = "SELECT ref FROM $TBL_ITEM_PROPERTY
$sql = "SELECT ref FROM $TBL_ITEM_PROPERTY
WHERE tool = 'work' AND insert_user_id = $user_id AND c_id = $course_id";
if ($debug) {
echo $sql;
@ -388,7 +388,7 @@ if (isset($_REQUEST['load_ajax'])) {
}
$parent_id = $data['parent_id'];
if (isset($data['parent_id']) && !empty($data['parent_id'])) {
$sql = "SELECT * FROM $TBL_STUDENT_PUBLICATION
$sql = "SELECT * FROM $TBL_STUDENT_PUBLICATION
WHERE id = $parent_id AND c_id = $course_id";
$select_res = Database::query($sql);
$parent_data = Database::fetch_array(
@ -540,7 +540,7 @@ if (isset($_REQUEST['load_ajax'])) {
//9. Survey Pending
//10. Dropbox - not neccesary to move categories (no presence of session_id)
$sql = "SELECT id FROM $TBL_DROPBOX_FILE
$sql = "SELECT id FROM $TBL_DROPBOX_FILE
WHERE uploader_id = $user_id AND session_id = $origin_session_id AND c_id = $course_id";
if ($debug) {
var_dump($sql);
@ -581,8 +581,8 @@ if (isset($_REQUEST['load_ajax'])) {
while ($row = Database::fetch_array($res, 'ASSOC')) {
$id = $row['notebook_id'];
if ($update_database) {
$sql = "UPDATE $TBL_NOTEBOOK
SET session_id = $new_session_id
$sql = "UPDATE $TBL_NOTEBOOK
SET session_id = $new_session_id
WHERE c_id = $course_id AND notebook_id = $id";
if ($debug) {
var_dump($sql);

@ -82,7 +82,7 @@ class StudentPublicationLink extends AbstractLink
}
$em = Database::getManager();
$sessionId = $this->get_session_id();
$session = $em->find('ChamiloCoreBundle:Session', $sessionId);
$session = api_get_session_entity($sessionId);
/*
if (empty($session_id)) {
$session_condition = api_get_session_condition(0, true);
@ -128,7 +128,7 @@ class StudentPublicationLink extends AbstractLink
$id = $data['id'];
$em = Database::getManager();
$session = $em->find('ChamiloCoreBundle:Session', $this->get_session_id());
$session = api_get_session_entity($this->get_session_id());
$results = $em
->getRepository('ChamiloCourseBundle:CStudentPublication')
->findBy([

@ -251,8 +251,7 @@ switch ($action) {
$currentUserId = api_get_user_id();
$em = Database::getManager();
$course = $em->find('ChamiloCoreBundle:Course', $courseId);
$course = api_get_course_entity($courseId);
$session = api_get_session_entity($sessionId);
if (!$course || !$session) {

@ -654,12 +654,10 @@ class CourseChatUtils
return array_merge($tutors, $students);
}
/** @var Course $course */
$course = $em->find('ChamiloCoreBundle:Course', $this->courseId);
$course = api_get_course_entity($this->courseId);
if ($this->sessionId) {
/** @var Session $session */
$session = $em->find('ChamiloCoreBundle:Session', $this->sessionId);
$session = api_get_session_entity($this->sessionId);
$criteria = Criteria::create()->where(Criteria::expr()->eq('course', $course));
$userIsCoach = api_is_course_session_coach($this->userId, $course->getId(), $session->getId());

@ -480,7 +480,6 @@ class AddCourse
$toolIntro = new CToolIntro();
$toolIntro
->setCId($course_id)
->setId(TOOL_COURSE_HOMEPAGE)
->setSessionId(0)
->setIntroText($intro_text);
$manager->persist($toolIntro);
@ -488,7 +487,6 @@ class AddCourse
$toolIntro = new CToolIntro();
$toolIntro
->setCId($course_id)
->setId(TOOL_STUDENTPUBLICATION)
->setSessionId(0)
->setIntroText(get_lang('This page allows users and groups to publish documents.'));
$manager->persist($toolIntro);
@ -496,7 +494,6 @@ class AddCourse
$toolIntro = new CToolIntro();
$toolIntro
->setCId($course_id)
->setId(TOOL_WIKI)
->setSessionId(0)
->setIntroText(get_lang('The word Wiki is short for WikiWikiWeb. Wikiwiki is a Hawaiian word, meaning "fast" or "speed". In a wiki, people write pages together. If one person writes something wrong, the next person can correct it. The next person can also add something new to the page. Because of this, the pages improve continuously.'));
$manager->persist($toolIntro);

@ -432,13 +432,13 @@ define('GROUP_PERMISSION_OPEN', '1');
define('GROUP_PERMISSION_CLOSED', '2');
// Group user permissions
define('GROUP_USER_PERMISSION_ADMIN', '1'); // the admin of a group
define('GROUP_USER_PERMISSION_READER', '2'); // a normal user
define('GROUP_USER_PERMISSION_PENDING_INVITATION', '3'); // When an admin/moderator invites a user
define('GROUP_USER_PERMISSION_PENDING_INVITATION_SENT_BY_USER', '4'); // an user joins a group
define('GROUP_USER_PERMISSION_MODERATOR', '5'); // a moderator
define('GROUP_USER_PERMISSION_ANONYMOUS', '6'); // an anonymous user
define('GROUP_USER_PERMISSION_HRM', '7'); // a human resources manager
define('GROUP_USER_PERMISSION_ADMIN', 1); // the admin of a group
define('GROUP_USER_PERMISSION_READER', 2); // a normal user
define('GROUP_USER_PERMISSION_PENDING_INVITATION', 3); // When an admin/moderator invites a user
define('GROUP_USER_PERMISSION_PENDING_INVITATION_SENT_BY_USER', 4); // an user joins a group
define('GROUP_USER_PERMISSION_MODERATOR', 5); // a moderator
define('GROUP_USER_PERMISSION_ANONYMOUS', 6); // an anonymous user
define('GROUP_USER_PERMISSION_HRM', 7); // a human resources manager
define('GROUP_IMAGE_SIZE_ORIGINAL', 1);
define('GROUP_IMAGE_SIZE_BIG', 2);

@ -35,8 +35,7 @@ class Attendance
{
$tbl_attendance = Database::get_course_table(TABLE_ATTENDANCE);
$session_id = api_get_session_id();
$condition_session = api_get_session_condition($session_id);
$course_id = api_get_course_int_id();
$condition_session = '';
$active_plus = '';
if ((isset($_GET['isStudentView']) && 'true' == $_GET['isStudentView']) ||
@ -48,7 +47,6 @@ class Attendance
$sql = "SELECT COUNT(att.iid) AS total_number_of_items
FROM $tbl_attendance att
WHERE
c_id = $course_id AND
active <> 2 $active_plus $condition_session ";
/*$active = (int) $active;
if ($active === 1 || $active === 0) {
@ -82,7 +80,7 @@ class Attendance
// Get attendance data
$sql = "SELECT iid, name, attendance_qualify_max
FROM $table
WHERE c_id = $course_id AND active = 1 $condition_session ";
WHERE active = 1 $condition_session ";
$result = Database::query($sql);
$data = [];
if (Database::num_rows($result) > 0) {
@ -115,7 +113,7 @@ class Attendance
$tbl_attendance = Database::get_course_table(TABLE_ATTENDANCE);
$course_id = api_get_course_int_id();
$session_id = api_get_session_id();
$condition_session = api_get_session_condition($session_id);
$condition_session = '';
$column = (int) $column;
$from = (int) $from;
$number_of_items = (int) $number_of_items;
@ -137,12 +135,11 @@ class Attendance
att.description AS col2,
att.attendance_qualify_max AS col3,
att.locked AS col4,
att.active AS col5,
att.session_id
att.active AS col5
FROM $tbl_attendance att
WHERE
att.active <> 2 AND
c_id = $course_id $active_plus $condition_session
att.active <> 2
$active_plus $condition_session
ORDER BY col$column $direction
LIMIT $from,$number_of_items ";
@ -159,9 +156,9 @@ class Attendance
while ($attendance = Database::fetch_row($res)) {
$session_star = '';
if ($session_id == $attendance[6]) {
/*if ($session_id == $attendance[6]) {
$session_star = api_get_session_image($session_id, $user_info['status']);
}
}*/
if (1 == $attendance[5]) {
$isDrhOfCourse = CourseManager::isUserSubscribedInCourseAsDrh(
@ -290,10 +287,10 @@ class Attendance
{
$tbl_attendance = Database::get_course_table(TABLE_ATTENDANCE);
$attendanceId = (int) $attendanceId;
$course_id = api_get_course_int_id();
$attendance_data = [];
$sql = "SELECT * FROM $tbl_attendance
WHERE c_id = $course_id AND iid = '$attendanceId'";
WHERE iid = $attendanceId";
$res = Database::query($sql);
if (Database::num_rows($res) > 0) {
while ($row = Database::fetch_array($res)) {
@ -469,7 +466,7 @@ class Attendance
foreach ($attendanceId as $id) {
$id = (int) $id;
$sql = "UPDATE $tbl_attendance SET active = 1
WHERE c_id = $course_id AND iid = '$id'";
WHERE iid = '$id'";
$result = Database::query($sql);
$affected_rows = Database::affected_rows($result);
if (!empty($affected_rows)) {
@ -486,7 +483,7 @@ class Attendance
} else {
$attendanceId = (int) $attendanceId;
$sql = "UPDATE $tbl_attendance SET active = 1
WHERE c_id = $course_id AND iid = '$attendanceId'";
WHERE iid = '$attendanceId'";
$result = Database::query($sql);
$affected_rows = Database::affected_rows($result);
if (!empty($affected_rows)) {
@ -614,7 +611,7 @@ class Attendance
$attendanceId = (int) $attendanceId;
$locked = $lock ? 1 : 0;
$upd = "UPDATE $tbl_attendance SET locked = $locked
WHERE c_id = $course_id AND iid = $attendanceId";
WHERE iid = $attendanceId";
$result = Database::query($upd);
$affected_rows = Database::affected_rows($result);
if ($affected_rows && $lock) {
@ -826,7 +823,7 @@ class Attendance
// update done_attendance inside attendance calendar table
$sql = "UPDATE $tbl_attendance_calendar SET done_attendance = 1
WHERE c_id = $course_id AND iid = '$calendar_id'";
WHERE iid = '$calendar_id'";
Database::query($sql);
// save users' results
@ -990,7 +987,6 @@ class Attendance
$sql = "SELECT count(done_attendance) as count
FROM $table
WHERE
c_id = $course_id AND
attendance_id = '$attendanceId' AND
done_attendance = 1
";
@ -1550,7 +1546,6 @@ class Attendance
$sql = "SELECT count(a.iid)
FROM $tbl_attendance_calendar a
WHERE
c_id = $course_id AND
$where_attendance
attendance_id = '$attendanceId' AND
iid NOT IN (
@ -1565,9 +1560,8 @@ class Attendance
$sql = "SELECT count(a.iid)
FROM $tbl_attendance_calendar a
INNER JOIN $calendarRelGroup g
ON (a.iid = g.calendar_id AND a.c_id = g.c_id)
ON (a.iid = g.calendar_id)
WHERE
a.c_id = $course_id AND
$where_attendance
attendance_id = '$attendanceId' AND
group_id = $groupId
@ -1598,7 +1592,7 @@ class Attendance
$sql = "SELECT count(a.iid)
FROM $tbl_attendance_calendar a
INNER JOIN $calendarRelGroup g
ON (a.iid = g.calendar_id AND a.c_id = g.c_id)
ON (a.iid = g.calendar_id)
WHERE
a.c_id = $course_id AND
$where_attendance
@ -1628,7 +1622,6 @@ class Attendance
$course_id = api_get_course_int_id();
$sql = "SELECT count(iid) FROM $tbl_attendance_calendar
WHERE
c_id = $course_id AND
attendance_id = '$attendanceId'";
$rs = Database::query($sql);
$count = 0;

@ -2,6 +2,7 @@
/* For licensing terms, see /license.txt*/
use Chamilo\CoreBundle\Entity\AccessUrlRelSession;
use Chamilo\CoreBundle\Entity\Course;
use Chamilo\CoreBundle\Entity\ExtraField as EntityExtraField;
use Chamilo\CoreBundle\Entity\SequenceResource;
@ -13,6 +14,7 @@ use Chamilo\CourseBundle\Component\CourseCopy\CourseBuilder;
use Chamilo\CourseBundle\Component\CourseCopy\CourseRestorer;
use Chamilo\CourseBundle\Manager\SettingsManager;
use ChamiloSession as Session;
use Doctrine\Common\Collections\Criteria;
use Doctrine\ORM\EntityManager;
/**
@ -564,13 +566,13 @@ class CourseManager
if (api_get_configuration_value('catalog_course_subscription_in_user_s_session')) {
// Also unlink the course from the users' currently accessible sessions
/** @var Course $course */
$course = Database::getManager()->getRepository('ChamiloCoreBundle:Course')->findOneBy([
$course = Container::getCourseRepository()->findOneBy([
'code' => $course_code,
]);
if (is_null($course)) {
return false;
}
/** @var Chamilo\UserBundle\Entity\User $user */
/** @var Chamilo\CoreBundle\Entity\User $user */
foreach (UserManager::getRepository()->matching(
Criteria::create()->where(Criteria::expr()->in('id', $userList))
) as $user) {
@ -609,7 +611,7 @@ class CourseManager
return false;
}
$course = Database::getManager()->getRepository('ChamiloCoreBundle:Course')->findOneBy(['code' => $courseCode]);
$course = Container::getCourseRepository()->findOneBy(['code' => $courseCode]);
if (null === $course) {
return false;
@ -647,9 +649,7 @@ class CourseManager
$userId = api_get_user_id();
if (api_get_configuration_value('catalog_course_subscription_in_user_s_session')) {
/**
* @var Chamilo\UserBundle\Entity\User
*/
/** @var \Chamilo\CoreBundle\Entity\User $user */
$user = UserManager::getRepository()->find($userId);
$sessions = $user->getCurrentlyAccessibleSessions();
if (empty($sessions)) {
@ -689,7 +689,8 @@ class CourseManager
$session->setCoachAccessEndDate($endDate);
$session->setDisplayEndDate($endDate);
$session->setSendSubscriptionNotification(false);
$session->setSessionAdminId(api_get_configuration_value('session_automatic_creation_user_id') ?: 1);
$adminId = api_get_configuration_value('session_automatic_creation_user_id') ?: 1;
$session->setSessionAdmin(api_get_user_entity($adminId));
$session->addUserInSession(0, $user);
Database::getManager()->persist($session);
try {
@ -704,9 +705,9 @@ class CourseManager
return false;
}
$accessUrlRelSession = new \Chamilo\CoreBundle\Entity\AccessUrlRelSession();
$accessUrlRelSession->setAccessUrlId(api_get_current_access_url_id());
$accessUrlRelSession->setSessionId($session->getId());
$accessUrlRelSession = new AccessUrlRelSession();
$accessUrlRelSession->setUrl(api_get_url_entity());
$accessUrlRelSession->setSession($session);
Database::getManager()->persist($accessUrlRelSession);
try {
Database::getManager()->flush();
@ -1273,15 +1274,13 @@ class CourseManager
if (api_get_configuration_value('catalog_course_subscription_in_user_s_session')) {
// with this option activated, only check whether the course is in one of the users' sessions
$course = Database::getManager()->getRepository('ChamiloCoreBundle:Course')->findOneBy([
$course = Container::getCourseRepository()->findOneBy([
'code' => $course_code,
]);
if (is_null($course)) {
return false;
}
/**
* @var \Chamilo\UserBundle\Entity\User
*/
/** @var \Chamilo\CoreBundle\Entity\User $user */
$user = UserManager::getRepository()->find($user_id);
if (is_null($user)) {
return false;
@ -2537,7 +2536,7 @@ class CourseManager
$courseEntity = api_get_course_entity($courseId);
/** @var SequenceResourceRepository $repo */
$repo = Database::getManager()->getRepository('ChamiloCoreBundle:SequenceResource');
$repo = Database::getManager()->getRepository(SequenceResource::class);
$sequenceResource = $repo->findRequirementForResource(
$courseId,
SequenceResource::COURSE_TYPE
@ -4399,7 +4398,7 @@ class CourseManager
$params['link'] = $session_url;
$entityManager = Database::getManager();
/** @var SequenceResourceRepository $repo */
$repo = $entityManager->getRepository('ChamiloCoreBundle:SequenceResource');
$repo = $entityManager->getRepository(SequenceResource::class);
$sequences = $repo->getRequirements($course_info['real_id'], SequenceResource::COURSE_TYPE);
$sequenceList = $repo->checkRequirementsForUser($sequences, SequenceResource::COURSE_TYPE, $user_id);
@ -4527,11 +4526,9 @@ class CourseManager
if (Skill::isAllowed($user_id, false)) {
$em = Database::getManager();
$objUser = api_get_user_entity($user_id);
/** @var Course $objCourse */
$objCourse = $em->find('ChamiloCoreBundle:Course', $course['real_id']);
$objSession = $em->find('ChamiloCoreBundle:Session', $session_id);
$skill = $em->getRepository('ChamiloCoreBundle:Skill')->getLastByUser($objUser, $objCourse, $objSession);
$objCourse = api_get_course_entity($course['real_id']);
$objSession = api_get_session_entity($session_id);
$skill = $em->getRepository(\Chamilo\CoreBundle\Entity\Skill::class)->getLastByUser($objUser, $objCourse, $objSession);
$output['skill'] = null;
if ($skill) {
@ -5589,7 +5586,7 @@ class CourseManager
$courseUserData = $teacherBackup[$userId][$course_code];
$userCourseCategory = $courseUserData['user_course_cat'];
if ($logger) {
$logger->addInfo("Recovering user_course_cat: $userCourseCategory");
$logger->debug("Recovering user_course_cat: $userCourseCategory");
}
}
@ -5611,7 +5608,7 @@ class CourseManager
$sessions = SessionManager::get_session_by_course($courseId);
if (!empty($sessions)) {
if ($logger) {
$logger->addInfo("Edit teachers in sessions");
$logger->debug("Edit teachers in sessions");
}
foreach ($sessions as $session) {
$sessionId = $session['id'];
@ -5619,7 +5616,7 @@ class CourseManager
if ($deleteSessionTeacherNotInList) {
foreach ($teachers as $userId) {
if ($logger) {
$logger->addInfo("Set coach #$userId in session #$sessionId of course #$courseId ");
$logger->debug("Set coach #$userId in session #$sessionId of course #$courseId ");
}
SessionManager::set_coach_to_course_session(
$userId,
@ -5636,7 +5633,7 @@ class CourseManager
if (!empty($teachersToDelete)) {
foreach ($teachersToDelete as $userId) {
if ($logger) {
$logger->addInfo("Delete coach #$userId in session #$sessionId of course #$courseId ");
$logger->debug("Delete coach #$userId in session #$sessionId of course #$courseId ");
}
SessionManager::set_coach_to_course_session(
$userId,
@ -5650,7 +5647,7 @@ class CourseManager
// Add new teachers only
foreach ($teachers as $userId) {
if ($logger) {
$logger->addInfo("Add coach #$userId in session #$sessionId of course #$courseId ");
$logger->debug("Add coach #$userId in session #$sessionId of course #$courseId ");
}
SessionManager::set_coach_to_course_session(
$userId,
@ -6787,7 +6784,7 @@ class CourseManager
*
* @return string HTML string
*/
public static function returnDescriptionButton($course)
public static function returnDescriptionButton($course, $url = '')
{
if (empty($course)) {
return '';

@ -6,10 +6,12 @@ use Chamilo\CoreBundle\Entity\Course;
use Chamilo\CoreBundle\Entity\ExtraField;
use Chamilo\CoreBundle\Entity\SequenceResource;
use Chamilo\CoreBundle\Entity\Session;
use Chamilo\CoreBundle\Entity\SessionCategory;
use Chamilo\CoreBundle\Entity\SessionRelCourse;
use Chamilo\CoreBundle\Entity\SessionRelCourseRelUser;
use Chamilo\CoreBundle\Entity\SessionRelUser;
use Chamilo\CoreBundle\Entity\User;
use Chamilo\CoreBundle\Framework\Container;
use Chamilo\CoreBundle\Repository\SequenceRepository;
use ExtraField as ExtraFieldModel;
use Monolog\Logger;
@ -58,8 +60,7 @@ class SessionManager
return [];
}
/** @var Session $session */
$session = $em->find('ChamiloCoreBundle:Session', $id);
$session = api_get_session_entity($id);
if (!$session) {
return [];
@ -775,15 +776,15 @@ class SessionManager
// Cleaning double selects.
foreach ($session as $key => &$value) {
if (isset($optionsByDouble[$key]) || isset($optionsByDouble[$key.'_second'])) {
/*if (isset($optionsByDouble[$key]) || isset($optionsByDouble[$key.'_second'])) {
$options = explode('::', $value);
}
}*/
$original_key = $key;
if (false !== strpos($key, '_second')) {
$key = str_replace('_second', '', $key);
}
if (isset($optionsByDouble[$key]) &&
/*if (isset($optionsByDouble[$key]) &&
isset($options[0]) &&
isset($optionsByDouble[$key][$options[0]])
) {
@ -792,7 +793,7 @@ class SessionManager
} else {
$value = $optionsByDouble[$key][$options[1]]['option_display_text'];
}
}
}*/
}
$categoryName = isset($orderedCategories[$session['session_category_id']]) ? $orderedCategories[$session['session_category_id']] : '';
@ -1710,7 +1711,7 @@ class SessionManager
;
if (!empty($sessionAdminId)) {
$sessionEntity->setSessionAdminId($sessionAdminId);
$sessionEntity->setSessionAdmin(api_get_user_entity($sessionAdminId));
}
if (!empty($startDate)) {
@ -1738,7 +1739,7 @@ class SessionManager
}
if (!empty($sessionCategoryId)) {
$category = $em->getRepository('ChamiloCoreBundle:SessionCategory')->find($sessionCategoryId);
$category = $em->getRepository(SessionCategory::class)->find($sessionCategoryId);
$sessionEntity->setCategory($category);
} else {
$sessionEntity->setCategory(null);
@ -1803,8 +1804,7 @@ class SessionManager
$em = Database::getManager();
$userId = api_get_user_id();
/** @var SequenceRepository $repo */
$repo = Database::getManager()->getRepository('ChamiloCoreBundle:SequenceResource');
$repo = Container::getSequenceResourceRepository();
$sequenceResource = $repo->findRequirementForResource(
$sessionId,
SequenceResource::SESSION_TYPE
@ -2112,7 +2112,7 @@ class SessionManager
FROM $tbl_session_rel_course_rel_user
WHERE session_id = $sessionId AND c_id = $courseId AND status<>2";
$rs = Database::query($sql);
list($nbr_users) = Database::fetch_array($rs);
[$nbr_users] = Database::fetch_array($rs);
// update the session-course relation to add the users total
$sql = "UPDATE $tbl_session_rel_course SET nbr_users = $nbr_users
WHERE session_id = $sessionId AND c_id = $courseId";
@ -2336,7 +2336,7 @@ class SessionManager
c_id = $courseId AND
status <> 2";
$result = Database::query($sql);
list($userCount) = Database::fetch_array($result);
[$userCount] = Database::fetch_array($result);
// update the session-course relation to add the users total
$sql = "UPDATE $tableSessionCourse
@ -2438,7 +2438,7 @@ class SessionManager
$userInfo = api_get_user_info($enreg_user);
foreach ($forums as $forum) {
$forumId = $forum['iid'];
set_notification('forum', $forumId, false, $userInfo, $courseInfo);
//set_notification('forum', $forumId, false, $userInfo, $courseInfo);
}
}
@ -2471,7 +2471,7 @@ class SessionManager
FROM $tbl_session_rel_course_rel_user
WHERE session_id = $session_id AND c_id = $courseId AND status <> 2";
$rs = Database::query($sql);
list($nbr_users) = Database::fetch_array($rs);
[$nbr_users] = Database::fetch_array($rs);
// update the session-course relation to add the users total
$sql = "UPDATE $tbl_session_rel_course
SET nbr_users = $nbr_users
@ -2598,10 +2598,7 @@ class SessionManager
return false;
}
$em = Database::getManager();
/** @var Session $session */
$session = $em->find('ChamiloCoreBundle:Session', $sessionId);
$session = api_get_session_entity( $sessionId);
if (!$session) {
return false;
@ -4434,7 +4431,7 @@ class SessionManager
{
$em = Database::getManager();
$subscriptions = $em
->getRepository('ChamiloCoreBundle:SessionRelUser')
->getRepository(SessionRelUser::class)
->findBy(['session' => $sessionId, 'user' => $userId]);
/** @var SessionRelUser $subscription */
@ -4638,7 +4635,8 @@ class SessionManager
$flat_list = $list->get_flat_list();
if (!empty($flat_list)) {
foreach ($flat_list as $lp_id => $data) {
api_item_property_update(
// @todo fix
/*api_item_property_update(
$course_info,
TOOL_LEARNPATH,
$lp_id,
@ -4649,7 +4647,7 @@ class SessionManager
0,
0,
$sid
);
);*/
}
}
$quiz_table = Database::get_course_table(TABLE_QUIZ_TEST);
@ -5036,9 +5034,9 @@ class SessionManager
$session_name = $enreg['SessionName'];
if ($debug) {
$logger->addInfo('---------------------------------------');
$logger->addInfo("Sessions - Start process of session: $session_name");
$logger->addInfo('---------------------------------------');
$logger->debug('---------------------------------------');
$logger->debug("Sessions - Start process of session: $session_name");
$logger->debug('---------------------------------------');
}
// Default visibility
@ -5138,7 +5136,7 @@ class SessionManager
$deleteOnlyCourseCoaches = false;
if (1 == count($courses)) {
if ($logger) {
$logger->addInfo('Only one course delete old coach list');
$logger->debug('Only one course delete old coach list');
}
$deleteOnlyCourseCoaches = true;
}
@ -5185,14 +5183,14 @@ class SessionManager
if ($debug) {
if ($session_id) {
foreach ($enreg as $key => $value) {
if ('extra_' == substr($key, 0, 6)) { //an extra field
if ('extra_' === substr($key, 0, 6)) { //an extra field
self::update_session_extra_field_value($session_id, substr($key, 6), $value);
}
}
$logger->addInfo("Session created: #$session_id - $session_name");
$logger->debug("Session created: #$session_id - $session_name");
} else {
$message = "Sessions - Session NOT created: $session_name";
$logger->addError($message);
$logger->debug($message);
$report[] = $message;
}
}
@ -5216,7 +5214,7 @@ class SessionManager
if ($sessionExistsWithName) {
if ($debug) {
$message = "Skip Session - Trying to update a session, but name already exists: $session_name";
$logger->addError($message);
$logger->debug($message);
$report[] = $message;
}
continue;
@ -5251,7 +5249,7 @@ class SessionManager
}
}
if ($debug) {
$logger->addInfo("Sessions - #$session_id created: $session_name");
$logger->debug("Sessions - #$session_id created: $session_name");
}
// Delete session-user relation only for students
@ -5311,7 +5309,7 @@ class SessionManager
$sessionName = Database::escape_string($enreg['SessionName']);
$sql = "UPDATE $tbl_session SET name = '$sessionName' WHERE id = $session_id";
Database::query($sql);
$logger->addInfo(
$logger->debug(
"Session #$session_id name IS updated with: '$session_name' External id: ".$enreg['extra_'.$extraFieldId]
);
} else {
@ -5322,13 +5320,13 @@ class SessionManager
if (true === $sessionExistsBesidesMe) {
if ($debug) {
$message = "Skip Session. Error when update session Session #$session_id Name: '$session_name'. Other session has the same name. External id: ".$enreg['extra_'.$extraFieldId];
$logger->addError($message);
$logger->debug($message);
$report[] = $message;
}
continue;
} else {
if ($debug) {
$logger->addInfo(
$logger->debug(
"Session #$session_id name is not updated because it didn't change (but update of other session values will continue) Name: '$session_name' External id: ".$enreg['extra_'.$extraFieldId]
);
}
@ -5341,7 +5339,7 @@ class SessionManager
}
if ($debug) {
$logger->addInfo("Session #$session_id to be updated: '$session_name'");
$logger->debug("Session #$session_id to be updated: '$session_name'");
}
if ($session_id) {
@ -5372,7 +5370,7 @@ class SessionManager
}
if ($debug) {
$logger->addInfo("Session updated #$session_id");
$logger->debug("Session updated #$session_id");
}
// Delete session-user relation only for students
@ -5402,7 +5400,7 @@ class SessionManager
}
} else {
if ($debug) {
$logger->addError(
$logger->debug(
"Sessions - Session not found"
);
}
@ -5448,7 +5446,7 @@ class SessionManager
registered_at = '".api_get_utc_datetime()."'";
Database::query($sql);
if ($debug) {
$logger->addInfo("Adding User #$user_id ($user) to session #$session_id");
$logger->debug("Adding User #$user_id ($user) to session #$session_id");
}
$user_counter++;
}
@ -5500,7 +5498,7 @@ class SessionManager
self::installCourse($session_id, $courseInfo['real_id']);
if ($debug) {
$logger->addInfo("Adding course '$course_code' to session #$session_id");
$logger->debug("Adding course '$course_code' to session #$session_id");
}
$course_counter++;
@ -5526,7 +5524,7 @@ class SessionManager
);
if ($debug) {
$msg = "Adding student list ".implode(', #', $userList)." to course: '$course_code' and session #$session_id";
$logger->addInfo($msg);
$logger->debug($msg);
}
}
}
@ -5566,7 +5564,7 @@ class SessionManager
);
if ($debug) {
$logger->addInfo("Adding course coach: user #$coach_id ($course_coach) to course: '$course_code' and session #$session_id");
$logger->debug("Adding course coach: user #$coach_id ($course_coach) to course: '$course_code' and session #$session_id");
}
$savedCoaches[] = $coach_id;
} else {
@ -5580,7 +5578,7 @@ class SessionManager
// Only one coach is added.
if (true == $onlyAddFirstCoachOrTeacher) {
if ($debug) {
$logger->addInfo("onlyAddFirstCoachOrTeacher : true");
$logger->debug("onlyAddFirstCoachOrTeacher : true");
}
foreach ($course_coaches as $course_coach) {
@ -5639,7 +5637,7 @@ class SessionManager
);
if ($debug) {
$logger->addInfo("Delete user #".$teacher['user_id']." from base course: $course_code");
$logger->debug("Delete user #".$teacher['user_id']." from base course: $course_code");
}
}
}
@ -5654,7 +5652,7 @@ class SessionManager
);
if ($debug) {
$logger->addInfo("Add coach #$teacherToAdd to course $courseId and session $session_id");
$logger->debug("Add coach #$teacherToAdd to course $courseId and session $session_id");
}
$userCourseCategory = '';
@ -5674,7 +5672,7 @@ class SessionManager
);
if ($debug) {
$logger->addInfo("Subscribe user #$teacherToAdd as teacher in course $course_code with user userCourseCategory $userCourseCategory");
$logger->debug("Subscribe user #$teacherToAdd as teacher in course $course_code with user userCourseCategory $userCourseCategory");
}
if (isset($groupBackup['user'][$teacherToAdd]) &&
@ -5711,7 +5709,7 @@ class SessionManager
// All coaches are added.
if ($removeAllTeachersFromCourse) {
if ($debug) {
$logger->addInfo("removeAllTeachersFromCourse true");
$logger->debug("removeAllTeachersFromCourse true");
}
$teacherToAdd = null;
foreach ($course_coaches as $course_coach) {
@ -5773,7 +5771,7 @@ class SessionManager
);
if ($debug) {
$logger->addInfo("Delete user #".$teacher['user_id']." from base course: $course_code");
$logger->debug("Delete user #".$teacher['user_id']." from base course: $course_code");
}
}
}
@ -5797,7 +5795,7 @@ class SessionManager
);
if ($debug) {
$logger->addInfo("Add user as teacher #".$teacherId." in base course: $course_code with userCourseCategory: $userCourseCategory");
$logger->debug("Add user as teacher #".$teacherId." in base course: $course_code with userCourseCategory: $userCourseCategory");
}
if (isset($groupBackup['user'][$teacherId]) &&
@ -5850,7 +5848,7 @@ class SessionManager
);
if ($debug) {
$logger->addInfo("Sessions - Adding course coach: user #$coach_id ($course_coach) to course: '$course_code' and session #$session_id");
$logger->debug("Sessions - Adding course coach: user #$coach_id ($course_coach) to course: '$course_code' and session #$session_id");
}
$savedCoaches[] = $coach_id;
} else {
@ -5874,7 +5872,7 @@ class SessionManager
$course_code
);
if ($debug) {
$logger->addInfo("Adding student: user #$user_id ($user) to course: '$course_code' and session #$session_id");
$logger->debug("Adding student: user #$user_id ($user) to course: '$course_code' and session #$session_id");
}
} else {
$error_message .= get_lang('This user doesn\'t exist').': '.$user.$eol;
@ -5893,15 +5891,15 @@ class SessionManager
self::addClassesByName($session_id, $classes, false);
if ($debug) {
$logger->addInfo("End process session #$session_id -------------------- ");
$logger->debug("End process session #$session_id -------------------- ");
}
}
if (!empty($report)) {
if ($debug) {
$logger->addInfo("--Summary--");
$logger->debug("--Summary--");
foreach ($report as $line) {
$logger->addInfo($line);
$logger->debug($line);
}
}
}
@ -7188,11 +7186,9 @@ class SessionManager
public static function getCoursesListByCourseCoach($coachId)
{
$entityManager = Database::getManager();
$scuRepo = $entityManager->getRepository(
'ChamiloCoreBundle:SessionRelCourseRelUser'
);
$repo = $entityManager->getRepository(SessionRelCourseRelUser::class);
return $scuRepo->findBy([
return $repo->findBy([
'user' => $coachId,
'status' => SessionRelCourseRelUser::STATUS_COURSE_COACH,
]);

@ -113,7 +113,7 @@ class SkillVisualizer
} else {
$brothers[$skill['parent_id']] = 1;
}*/
$brother_count = $brothers[$skill['id']];
//$brother_count = $brothers[$skill['id']];
$my_count = 0;
$parent_x = 0;
if (0 == $skill['parent_id']) {

@ -230,6 +230,8 @@ class SocialManager extends UserManager
*/
public static function get_list_web_path_user_invitation_by_user_id($user_id)
{
return [];
// @todo
$list_ids = self::get_list_invitation_of_friends_by_user_id($user_id);
$list = [];
foreach ($list_ids as $values_ids) {
@ -1154,15 +1156,19 @@ class SocialManager extends UserManager
if (!empty($announcementsByCourse)) {
foreach ($announcementsByCourse as $announcement) {
$courseInfo = api_get_course_info_by_id($announcement->getCId());
$url = Display::url(
Display::return_icon(
'announcement.png',
get_lang('Announcements')
).$courseInfo['name'],
api_get_path(WEB_CODE_PATH).'announcements/announcements.php?cid='.$courseInfo['real_id']
);
$announcements[] = Display::tag('li', $url);
$resourceLink = $announcement->getFirstResourceLink();
$course = $resourceLink->getCourse();
//$courseInfo = api_get_course_info_by_id($announcement->getCId());
if ($course) {
$url = Display::url(
Display::return_icon(
'announcement.png',
get_lang('Announcements')
).$course->getName(),
api_get_path(WEB_CODE_PATH).'announcements/announcements.php?cid='.$course->getId()
);
$announcements[] = Display::tag('li', $url);
}
}
}
@ -1348,6 +1354,8 @@ class SocialManager extends UserManager
*/
public static function display_productions($user_id)
{
return ;
$webdir_array = UserManager::get_user_picture_path_by_id($user_id, 'web');
$sysdir = UserManager::getUserPathById($user_id, 'system');
$webdir = UserManager::getUserPathById($user_id, 'web');
@ -1663,8 +1671,8 @@ class SocialManager extends UserManager
$res = Database::query($oneQuery);
$em = Database::getManager();
if (Database::num_rows($res) > 0) {
$repo = $em->getRepository('ChamiloCourseBundle:CForumPost');
$repoThread = $em->getRepository('ChamiloCourseBundle:CForumThread');
$repo = $em->getRepository(CForumPost::class);
$repoThread = $em->getRepository(CForumThread::class);
$groups = [];
$userGroup = new UserGroup();
$urlGroup = api_get_path(WEB_CODE_PATH).'social/group_view.php?id=';
@ -1692,12 +1700,12 @@ class SocialManager extends UserManager
$thread = $repoThread->find($row['thread_id']);
if ($post && $thread) {
$courseInfo = api_get_course_info_by_id($post->getCId());
$row['post_title'] = $post->getForumId();
$row['post_title'] = $post->getForum()->getForumTitle();
$row['forum_title'] = $thread->getThreadTitle();
$row['thread_url'] = api_get_path(WEB_CODE_PATH).'forum/viewthread.php?'.http_build_query([
'cid' => $courseInfo['real_id'],
'forum' => $post->getForumId(),
'thread' => $post->getThreadId(),
'forum' => $post->getForum()->getIid(),
'thread' => $post->getThread()->getIid(),
'post_id' => $post->getIid(),
]).'#post_id_'.$post->getIid();
}

@ -415,29 +415,29 @@ class SortableTable extends HTML_Table
if (count($this->form_actions) > 0) {
$html .= '<div class="btn-group" role="group">';
$html .= '<a
class="btn btn-outline-primary"
href="?'.$params.'&amp;'.$this->param_prefix.'selectall=1"
$html .= '<a
class="btn btn-outline-primary"
href="?'.$params.'&amp;'.$this->param_prefix.'selectall=1"
onclick="javascript: setCheckbox(true, \''.$table_id.'\'); return false;">'.get_lang('Select all').'</a>';
$html .= '<a
class="btn btn-outline-primary"
href="?'.$params.'"
$html .= '<a
class="btn btn-outline-primary"
href="?'.$params.'"
onclick="javascript: setCheckbox(false, \''.$table_id.'\'); return false;">'.get_lang('UnSelect all').'</a> ';
$html .= '<div class="btn-group" role="group">
<button
id="'.$table_id.'_actions"
<button
id="'.$table_id.'_actions"
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"
class="btn btn-outline-primary dropdown-toggle"
class="btn btn-outline-primary dropdown-toggle"
onclick="javascript:return false;">'.
get_lang('Detail').'
</button>
';
$html .= '<div class="dropdown-menu" aria-labelledby="'.$table_id.'_actions" >';
foreach ($this->form_actions as $action => &$label) {
$html .= '<a
class="dropdown-item"
data-action ="'.$action.'"
href="#"
$html .= '<a
class="dropdown-item"
data-action ="'.$action.'"
href="#"
onclick="javascript:action_click(this, \''.$table_id.'\');">'.$label.'</a>';
}
$html .= '</div>';
@ -881,7 +881,7 @@ class SortableTable extends HTML_Table
* @param string $label The label
* @param bool $sortable Is the table sortable by this column? (defatult
* = true)
* @param string $th_attributes Additional attributes for the th-tag of the
* @param array $th_attributes Additional attributes for the th-tag of the
* table header
* @param string $td_attributes Additional attributes for the td-tags of the
* column

@ -654,20 +654,20 @@ class Thematic
public function getThematicAdvance($id)
{
$repo = Container::getThematicAdvanceRepository();
/*
$courseEntity = api_get_course_entity($courseId);
$sessionEntity = null;
if ($sessionId) {
$sessionEntity = api_get_session_entity($sessionId);
/*$list = api_get_item_property_by_tool(
$list = api_get_item_property_by_tool(
'thematic_advance',
$course_info['code'],
api_get_session_id()
);
foreach ($list as $value) {
$elements[$value['ref']] = $value;
}*/
}
}
}*/
return $repo->find($id);
}

@ -1,4 +1,5 @@
<?php
/* For licensing terms, see /license.txt */
/**
@ -110,7 +111,7 @@ class UserGroup extends Model
$urlId = api_get_current_access_url_id();
$sql = "SELECT $select
FROM $this->usergroup_rel_user_table u
INNER JOIN $this->access_url_rel_user a
INNER JOIN $this->access_url_rel_user a
ON (u.user_id = a.user_id)
WHERE u.usergroup_id = $id AND access_url_id = $urlId ";
} else {
@ -212,7 +213,7 @@ class UserGroup extends Model
if ($this->getUseMultipleUrl()) {
$urlId = api_get_current_access_url_id();
$sql = "SELECT count(u.id) as count
$sql = "SELECT count(u.id) as count
FROM $this->table u
INNER JOIN $this->access_url_rel_usergroup a
ON (u.id = a.usergroup_id)
@ -459,7 +460,7 @@ class UserGroup extends Model
ON (a.usergroup_id = u.id)
";
} else {
$sql = "SELECT $select
$sql = "SELECT $select
FROM {$this->usergroup_rel_course_table} usergroup
INNER JOIN {$this->table} u
ON (u.id = usergroup.usergroup_id)
@ -586,7 +587,7 @@ class UserGroup extends Model
],
],
];
$from = " $this->usergroup_rel_course_table as c
$from = " $this->usergroup_rel_course_table as c
INNER JOIN $this->access_url_rel_usergroup a
ON c.usergroup_id = a.usergroup_id ";
} else {
@ -792,7 +793,7 @@ class UserGroup extends Model
if ($this->getUseMultipleUrl()) {
$urlId = api_get_current_access_url_id();
$from = $this->usergroup_rel_user_table." u
INNER JOIN {$this->access_url_rel_usergroup} a
INNER JOIN {$this->access_url_rel_usergroup} a
ON (a.usergroup_id = u.usergroup_id) ";
$where = ['where' => ['user_id = ? AND access_url_id = ? ' => [$userId, $urlId]]];
} else {
@ -1093,7 +1094,7 @@ class UserGroup extends Model
if ($this->getUseMultipleUrl()) {
$urlId = api_get_current_access_url_id();
$sql = "SELECT * FROM $this->table u
INNER JOIN {$this->access_url_rel_usergroup} a
INNER JOIN {$this->access_url_rel_usergroup} a
ON (a.usergroup_id = u.id)
WHERE name = '".$name."' AND access_url_id = $urlId";
} else {
@ -1203,7 +1204,7 @@ class UserGroup extends Model
{
if ($this->getUseMultipleUrl()) {
$urlId = api_get_current_access_url_id();
$from = $this->table." u
$from = $this->table." u
INNER JOIN {$this->access_url_rel_usergroup} a
ON (u.id = a.usergroup_id)";
$options = ['where' => ['access_url_id = ? ' => $urlId]];
@ -1359,34 +1360,31 @@ class UserGroup extends Model
return false;
}
/**
* {@inheritdoc}
*/
public function update($values, $showQuery = false)
public function update($params, $showQuery = false)
{
$values['updated_on'] = api_get_utc_datetime();
$values['group_type'] = isset($values['group_type']) ? self::SOCIAL_CLASS : self::NORMAL_CLASS;
$values['allow_members_leave_group'] = isset($values['allow_members_leave_group']) ? 1 : 0;
$values['crop_image'] = isset($values['picture_crop_result']) ? $values['picture_crop_result'] : null;
$params['updated_on'] = api_get_utc_datetime();
$params['group_type'] = isset($params['group_type']) ? self::SOCIAL_CLASS : self::NORMAL_CLASS;
$params['allow_members_leave_group'] = isset($params['allow_members_leave_group']) ? 1 : 0;
$params['crop_image'] = isset($params['picture_crop_result']) ? $params['picture_crop_result'] : null;
if (isset($values['id'])) {
if (isset($params['id'])) {
$picture = isset($_FILES['picture']) ? $_FILES['picture'] : null;
if (!empty($picture)) {
$picture = $this->manageFileUpload($values['id'], $picture, $values['crop_image']);
$picture = $this->manageFileUpload($params['id'], $picture, $params['crop_image']);
if ($picture) {
$values['picture'] = $picture;
$params['picture'] = $picture;
}
}
if (isset($values['delete_picture'])) {
$values['picture'] = null;
if (isset($params['delete_picture'])) {
$params['picture'] = null;
}
}
parent::update($values, $showQuery);
parent::update($params, $showQuery);
if (isset($values['delete_picture'])) {
$this->delete_group_picture($values['id']);
if (isset($params['delete_picture'])) {
$this->delete_group_picture($params['id']);
}
return true;
@ -1588,7 +1586,7 @@ class UserGroup extends Model
$needle = api_convert_encoding($needle, $charset, 'utf-8');
$needle = Database::escape_string($needle);
$sql = 'SELECT id, name
$sql = 'SELECT id, name
FROM '.Database::get_main_table(TABLE_USERGROUP).' u
WHERE name LIKE "'.$needle.'%"
ORDER BY name
@ -1717,7 +1715,7 @@ class UserGroup extends Model
* @param string $id group id
* @param string picture group name
* @param string height
* @param string $size_picture picture size it can be small_, medium_ or big_
* @param int $size_picture picture size it can be small_, medium_ or big_
* @param string style css
*
* @return array with the file and the style of an image i.e $array['file'] $array['style']
@ -1885,9 +1883,9 @@ class UserGroup extends Model
$user_role = $this->get_user_group_role($user_id, $group_id);
if (in_array($user_role, [GROUP_USER_PERMISSION_ADMIN])) {
return true;
} else {
return false;
}
return false;
}
/**
@ -1955,7 +1953,7 @@ class UserGroup extends Model
$group_id = (int) $group_id;
if (!empty($user_id) && !empty($group_id)) {
$sql = "SELECT relation_type
$sql = "SELECT relation_type
FROM $table_group_rel_user
WHERE
usergroup_id = $group_id AND
@ -2134,7 +2132,7 @@ class UserGroup extends Model
/**
* Gets the inner join from users and group table.
*
* @return array Database::store_result of the result
* @return array|int Database::store_result of the result
*
* @author Julio Montoya
* */
@ -2219,9 +2217,9 @@ class UserGroup extends Model
$num = (int) $num;
}
// only show admins and readers
$whereCondition = " WHERE
$whereCondition = " WHERE
g.group_type = ".self::SOCIAL_CLASS." AND
gu.relation_type IN
gu.relation_type IN
('".GROUP_USER_PERMISSION_ADMIN."' , '".GROUP_USER_PERMISSION_READER."', '".GROUP_USER_PERMISSION_HRM."') ";
$sql = 'SELECT DISTINCT count(user_id) as count, g.picture, g.name, g.description, g.id ';
@ -2284,13 +2282,13 @@ class UserGroup extends Model
$num = (int) $num;
}
$where = " WHERE
$where = " WHERE
g.group_type = ".self::SOCIAL_CLASS." AND
gu.relation_type IN
('".GROUP_USER_PERMISSION_ADMIN."' ,
gu.relation_type IN
('".GROUP_USER_PERMISSION_ADMIN."' ,
'".GROUP_USER_PERMISSION_READER."',
'".GROUP_USER_PERMISSION_MODERATOR."',
'".GROUP_USER_PERMISSION_HRM."')
'".GROUP_USER_PERMISSION_MODERATOR."',
'".GROUP_USER_PERMISSION_HRM."')
";
$sql = 'SELECT DISTINCT
count(user_id) as count,
@ -2571,7 +2569,7 @@ class UserGroup extends Model
/**
* @param string $user_id
* @param string $relation_type
* @param int $relation_type
* @param bool $with_image
*
* @deprecated
@ -2585,12 +2583,12 @@ class UserGroup extends Model
) {
$table_group_rel_user = $this->usergroup_rel_user_table;
$tbl_group = $this->table;
$user_id = intval($user_id);
$user_id = (int) $user_id;
if (0 == $relation_type) {
$where_relation_condition = '';
} else {
$relation_type = intval($relation_type);
$relation_type = (int) $relation_type;
$where_relation_condition = "AND gu.relation_type = $relation_type ";
}
@ -2642,7 +2640,7 @@ class UserGroup extends Model
g.name LIKE '%".$keyword."%' OR
g.description LIKE '%".$keyword."%' OR
g.url LIKE '%".$keyword."%'
) $urlCondition
) $urlCondition
";
} else {
$sql .= " WHERE 1 = 1 $urlCondition ";
@ -2690,11 +2688,11 @@ class UserGroup extends Model
$select_part .= "rg$rg_number.group_id as id_$rg_number, ";
}
if (1 == $i) {
$cond_part .= "FROM $t_rel_group rg0
LEFT JOIN $t_rel_group rg$i
$cond_part .= "FROM $t_rel_group rg0
LEFT JOIN $t_rel_group rg$i
ON rg$rg_number.group_id = rg$i.subgroup_id ";
} else {
$cond_part .= " LEFT JOIN $t_rel_group rg$i
$cond_part .= " LEFT JOIN $t_rel_group rg$i
ON rg$rg_number.group_id = rg$i.subgroup_id ";
}
}
@ -2793,7 +2791,7 @@ class UserGroup extends Model
$select .= $i != $levels ? ', ' : null;
if (1 == $i) {
$from .= " INNER JOIN $groupRelGroupTable gg0
$from .= " INNER JOIN $groupRelGroupTable gg0
ON g1.id = gg0.subgroup_id and gg0.group_id = $groupId ";
} else {
$from .= "LEFT JOIN $groupRelGroupTable gg$tableIndexJoinNumber ";

@ -153,9 +153,7 @@ class Rest extends WebService
return;
}
$em = Database::getManager();
/** @var Course $course */
$course = $em->find('ChamiloCoreBundle:Course', $id);
$course = api_get_course_entity($id);
if (!$course) {
throw new Exception(get_lang('NoCourse'));
@ -179,9 +177,7 @@ class Rest extends WebService
return;
}
$em = Database::getManager();
/** @var Session $session */
$session = $em->find('ChamiloCoreBundle:Session', $id);
$session = api_get_session_entity( $id);
if (!$session) {
throw new Exception(get_lang('NoSession'));
@ -325,8 +321,7 @@ class Rest extends WebService
$data = [];
foreach ($courses as $courseInfo) {
/** @var Course $course */
$course = Database::getManager()->find('ChamiloCoreBundle:Course', $courseInfo['real_id']);
$course = api_get_course_entity($courseInfo['real_id']);
$teachers = CourseManager::getTeacherListFromCourseCodeToString($course->getCode());
$picturePath = CourseManager::getPicturePath($course, true)
?: Display::return_icon('session_default.png', null, null, null, null, true);

@ -24,12 +24,9 @@ $em = Database::getManager();
$currentUserId = api_get_user_id();
$userId = isset($_GET['user']) ? (int) $_GET['user'] : $currentUserId;
/** @var User $user */
$user = api_get_user_entity($userId);
/** @var Course $course */
$course = $em->find('ChamiloCoreBundle:Course', api_get_course_int_id());
/** @var Session $session */
$session = $em->find('ChamiloCoreBundle:Session', api_get_session_id());
$course = api_get_course_entity( api_get_course_int_id());
$session = api_get_session_entity(api_get_session_id());
$action = isset($_GET['action']) ? $_GET['action'] : 'list';
$cidreq = api_get_cidreq();

@ -189,7 +189,7 @@ if (false == api_is_coach_of_course_in_session($session_id)) {
}
$entityManager = Database::getManager();
$session = $entityManager->find('ChamiloCoreBundle:Session', $session_id);
$session = api_get_session_entity($session_id);
$sessionTitleLink = api_get_configuration_value('courses_list_session_title_link');
if (2 == $sessionTitleLink && 1 === $session->getNbrCourses()) {

@ -58,8 +58,7 @@ if ($form->validate()) {
}
foreach ($values['courses_to_avoid'] as $courseId) {
/** @var Course $course */
$course = $em->find('ChamiloCoreBundle:Course', $courseId);
$course = api_get_course_entity($courseId);
if (!$session->getUserInCourse($user, $course)->count()) {
continue;
@ -71,8 +70,7 @@ if ($form->validate()) {
$coursesToResubscribe = array_diff($avoidedCourseIds, $values['courses_to_avoid']);
foreach ($coursesToResubscribe as $courseId) {
/** @var Course $course */
$course = $em->find('ChamiloCoreBundle:Course', $courseId);
$course = api_get_course_entity($courseId);
if ($session->getUserInCourse($user, $course)->count()) {
continue;

@ -30,10 +30,8 @@ foreach ($pending as $i => $item) {
$survey = $item;
/** @var CSurveyInvitation invitation */
$invitation = $pending[$i + 1];
/** @var Course $course */
$course = $em->find('ChamiloCoreBundle:Course', $survey->getCId());
/** @var Session $session */
$session = $em->find('ChamiloCoreBundle:Session', $survey->getSessionId());
$course = api_get_course_entity($survey->getCId());
$session = api_get_session_entity( $survey->getSessionId());
$course = $course ? ['id' => $course->getId(), 'title' => $course->getTitle(), 'code' => $course->getCode()] : null;
$session = $session ? ['id' => $session->getId(), 'name' => $session->getName()] : null;

@ -1147,8 +1147,8 @@ class bbb
}
$item = array_merge($item, $meetingDB, $meetingBBB);
$item['course'] = $em->find('ChamiloCoreBundle:Course', $item['c_id']);
$item['session'] = $em->find('ChamiloCoreBundle:Session', $item['session_id']);
$item['course'] = api_get_course_entity($item['c_id']);
$item['session'] = api_get_session_entity($item['session_id']);
$newMeetingList[] = $item;
}

@ -495,6 +495,21 @@ class Session
return false;
}
/**
* Check for existence of a relation (SessionRelCourse) between a course and this session.
*
* @return bool whether the course is related to this session
*/
public function isRelatedToCourse(Course $course): bool
{
return !is_null(
\Database::getManager()->getRepository(SessionRelCourse::class)->findOneBy([
'session' => $this,
'course' => $course,
])
);
}
/**
* Remove $course.
*
@ -980,6 +995,24 @@ class Session
return $this->compareDates($start, $end);
}
/**
* Compare the current date with start and end access dates.
* Either missing date is interpreted as no limit.
*
* @return bool whether now is between the session access start and end dates
*/
public function isCurrentlyAccessible()
{
try {
$now = new \Datetime();
} catch (\Exception $exception) {
return false;
}
return (is_null($this->accessStartDate) || $this->accessStartDate < $now)
&& (is_null($this->accessEndDate) || $now < $this->accessEndDate);
}
public function addCourse(Course $course)
{
$entity = new SessionRelCourse();
@ -987,6 +1020,26 @@ class Session
$this->addCourses($entity);
}
/**
* Removes a course from this session.
*
* @param Course $course the course to remove from this session
*
* @return bool whether the course was actually found in this session and removed from it
*/
public function removeCourse(Course $course)
{
$relCourse = $this->getCourseSubscription($course);
if ($relCourse) {
$this->courses->removeElement($relCourse);
$this->setNbrCourses(count($this->courses));
return true;
}
return false;
}
/**
* @return ArrayCollection
*/

@ -2217,4 +2217,64 @@ class User implements UserInterface, EquatableInterface
return $this->courseGroupsAsTutor->matching($criteria);
}
/**
* Retreives this user's related sessions.
*
* @param int $relationType \Chamilo\CoreBundle\Entity\SessionRelUser::relationTypeList key
*
* @return Session[]
*/
public function getSessions($relationType)
{
$sessions = [];
foreach ($this->sessions as $sessionRelUser) {
if ($sessionRelUser->getRelationType() == $relationType) {
$sessions[] = $sessionRelUser->getSession();
}
}
return $sessions;
}
/**
* Retreives this user's related student sessions.
*
* @return Session[]
*/
public function getStudentSessions()
{
return $this->getSessions(0);
}
/**
* Retreives this user's related DRH sessions.
*
* @return Session[]
*/
public function getDRHSessions()
{
return $this->getSessions(1);
}
/**
* Get this user's related accessible sessions of a type, student by default.
*
* @param int $relationType \Chamilo\CoreBundle\Entity\SessionRelUser::relationTypeList key
*
* @return Session[]
*/
public function getCurrentlyAccessibleSessions($relationType = 0)
{
$sessions = [];
foreach ($this->getSessions($relationType) as $session) {
if ($session->isCurrentlyAccessible()) {
$sessions[] = $session;
}
}
return $sessions;
}
}

@ -10,6 +10,8 @@ use Chamilo\CoreBundle\Repository\AccessUrlRepository;
use Chamilo\CoreBundle\Repository\CourseCategoryRepository;
use Chamilo\CoreBundle\Repository\CourseRepository;
use Chamilo\CoreBundle\Repository\IllustrationRepository;
use Chamilo\CoreBundle\Repository\SequenceRepository;
use Chamilo\CoreBundle\Repository\SequenceResourceRepository;
use Chamilo\CoreBundle\Repository\UserRepository;
use Chamilo\CoreBundle\ToolChain;
use Chamilo\CourseBundle\Repository\CAnnouncementAttachmentRepository;
@ -519,6 +521,22 @@ class Container
return self::$container->get(CStudentPublicationCommentRepository::class);
}
/**
* @return SequenceResourceRepository
*/
public static function getSequenceResourceRepository()
{
return self::$container->get(SequenceResourceRepository::class);
}
/**
* @return SequenceRepository
*/
public static function getSequenceRepository()
{
return self::$container->get(SequenceRepository::class);
}
public static function getThematicRepository()
{
return self::$container->get(CThematicRepository::class);

@ -66,7 +66,7 @@ trait CourseControllerTrait
return null;
}
return $this->getDoctrine()->getManager()->find('ChamiloCoreBundle:Session', $sessionId);
return $this->getDoctrine()->getManager()->find(Session::class, $sessionId);
}
public function getGroup()

@ -12,7 +12,6 @@ use Doctrine\ORM\Mapping as ORM;
* @ORM\Table(
* name="c_attendance_calendar",
* indexes={
* @ORM\Index(name="course", columns={"c_id"}),
* @ORM\Index(name="attendance_id", columns={"attendance_id"}),
* @ORM\Index(name="done_attendance", columns={"done_attendance"})
* }
@ -30,13 +29,6 @@ class CAttendanceCalendar
*/
protected $iid;
/**
* @var int
*
* @ORM\Column(name="c_id", type="integer")
*/
protected $cId;
/**
* @var int
*
@ -129,28 +121,4 @@ class CAttendanceCalendar
{
return $this->doneAttendance;
}
/**
* Set cId.
*
* @param int $cId
*
* @return CAttendanceCalendar
*/
public function setCId($cId)
{
$this->cId = $cId;
return $this;
}
/**
* Get cId.
*
* @return int
*/
public function getCId()
{
return $this->cId;
}
}

Loading…
Cancel
Save