From 158b7e9ef12f4dc3e60f7642740e47a363c47b01 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Mon, 15 Feb 2021 14:27:25 +0100 Subject: [PATCH] Minor - Add psalm checks, fix code from 1.11.x --- psalm.xml | 17 ++- public/main/forum/forumfunction.inc.php | 8 +- public/main/inc/ajax/admin.ajax.php | 48 ++++--- public/main/inc/ajax/announcement.ajax.php | 9 +- public/main/inc/ajax/exercise.ajax.php | 2 +- public/main/inc/ajax/extra_field.ajax.php | 12 +- public/main/inc/ajax/forum.ajax.php | 5 +- public/main/inc/ajax/install.ajax.php | 5 +- public/main/inc/ajax/sequence.ajax.php | 4 +- public/main/inc/ajax/session.ajax.php | 2 +- public/main/inc/ajax/skill.ajax.php | 13 +- public/main/inc/ajax/social.ajax.php | 4 +- public/main/inc/ajax/statistics.ajax.php | 21 ++-- .../main/inc/lib/course_description.lib.php | 6 +- public/main/inc/lib/webservices/Rest.php | 117 +++++++++--------- public/main/lp/lp_edit.php | 1 - .../Controller/CourseHomeController.php | 13 +- .../Entity/ExtraFieldSavedSearch.php | 23 +--- 18 files changed, 163 insertions(+), 147 deletions(-) diff --git a/psalm.xml b/psalm.xml index b8f9da2632..4ef7a9b3b9 100644 --- a/psalm.xml +++ b/psalm.xml @@ -40,6 +40,8 @@ + + @@ -48,7 +50,6 @@ - @@ -157,6 +158,20 @@ + + + + + + + + + + + + + + diff --git a/public/main/forum/forumfunction.inc.php b/public/main/forum/forumfunction.inc.php index a1cc19862c..adff8da135 100644 --- a/public/main/forum/forumfunction.inc.php +++ b/public/main/forum/forumfunction.inc.php @@ -6118,13 +6118,7 @@ function getForumCategoryByTitle($title, $courseId, $sessionId = 0) return $resultData;*/ } -/** - * @param array $row - * @param bool $addWrapper - * - * @return string - */ -function getPostStatus(CForumForum $forum, $row, $addWrapper = true) +function getPostStatus(CForumForum $forum, array $row, bool $addWrapper = true): string { $statusIcon = ''; if ($forum->isModerated()) { diff --git a/public/main/inc/ajax/admin.ajax.php b/public/main/inc/ajax/admin.ajax.php index a8d846c8c0..844c3b0d8d 100644 --- a/public/main/inc/ajax/admin.ajax.php +++ b/public/main/inc/ajax/admin.ajax.php @@ -1,15 +1,13 @@ http://www.chamilo.org/stats/. When registering you will also appear on the worldwide list (http://www.chamilo.org/community.php. If you do not want to appear in this list you have to check the checkbox below. The registration is as easy as it can be: you only have to click this button:
'); - $return .= '
'; - $return .= ''; + $return .= ''; + $return .= ' + '; $return .= '
'; check_system_version(); } else { @@ -132,7 +140,8 @@ function check_system_version() { // Check if curl is available. if (!in_array('curl', get_loaded_extensions())) { - return ''.get_lang('Impossible to contact the version server right now. Please try again later.').''; + return ''. + get_lang('Impossible to contact the version server right now. Please try again later.').''; } $url = 'https://version.chamilo.org'; @@ -177,10 +186,10 @@ function check_system_version() $uniqueId = ''; $entityManager = Database::getManager(); /** @var BranchSyncRepository $branch */ - $repository = $entityManager->getRepository('ChamiloCoreBundle:BranchSync'); + $repository = $entityManager->getRepository(BranchSync::class); /** @var BranchSync $branch */ $branch = $repository->getTopBranch(); - if (is_a($branch, '\Chamilo\CoreBundle\Entity\BranchSync')) { + if (is_a($branch, BranchSync::class)) { $uniqueId = $branch->getUniqueId(); } @@ -223,17 +232,26 @@ function check_system_version() } if (version_compare($system_version, $version, '<')) { - $output = ''.get_lang('Your version is not up-to-date').'
- '.get_lang('The latest version is').' Chamilo '.$version.'.
- '.get_lang('Your version is').' Chamilo '.$system_version.'.
'.str_replace('http://www.chamilo.org', 'http://www.chamilo.org', get_lang('Please visit our website: http://www.chamilo.org')).'
'; + $output = ''. + get_lang('Your version is not up-to-date').'
'. + get_lang('The latest version is').' Chamilo '.$version.'.
'. + get_lang('Your version is').' Chamilo '.$system_version.'.
'. + str_replace( + 'http://www.chamilo.org', + 'http://www.chamilo.org', + get_lang('Please visit our website: http://www.chamilo.org') + ). + '
'; } else { - $output = ''.get_lang('Your version is up-to-date').': Chamilo '.$version.''; + $output = ''. + get_lang('Your version is up-to-date').': Chamilo '.$version.''; } return $output; } - return ''.get_lang('Impossible to contact the version server right now. Please try again later.').''; + return ''. + get_lang('Impossible to contact the version server right now. Please try again later.').''; } /** diff --git a/public/main/inc/ajax/announcement.ajax.php b/public/main/inc/ajax/announcement.ajax.php index ae9c28cdfa..b6af24f0cc 100644 --- a/public/main/inc/ajax/announcement.ajax.php +++ b/public/main/inc/ajax/announcement.ajax.php @@ -11,15 +11,14 @@ $action = isset($_REQUEST['a']) ? $_REQUEST['a'] : null; $isAllowedToEdit = api_is_allowed_to_edit(); $courseInfo = api_get_course_info(); $courseId = api_get_course_int_id(); +$courseCode = api_get_course_id(); $groupId = api_get_group_id(); $sessionId = api_get_session_id(); $isTutor = false; if (!empty($groupId)) { $groupInfo = GroupManager::get_group_properties($groupId); - $groupRepo = \Chamilo\CoreBundle\Framework\Container::getGroupRepository(); - /** @var \Chamilo\CourseBundle\Entity\CGroup $groupEntity */ - $groupEntity = $groupRepo->find($groupId); + $groupEntity = api_get_group_entity($groupId); $isTutor = GroupManager::isTutorOfGroup(api_get_user_id(), $groupEntity); if ($isTutor) { $isAllowedToEdit = true; @@ -39,9 +38,7 @@ switch ($action) { } if (false === $allowToEdit && !empty($groupId)) { - $groupRepo = \Chamilo\CoreBundle\Framework\Container::getGroupRepository(); - /** @var \Chamilo\CourseBundle\Entity\CGroup $groupEntity */ - $groupEntity = $groupRepo->find($groupId); + $groupEntity = api_get_group_entity($groupId); // Check if user is tutor group $isTutor = GroupManager::isTutorOfGroup(api_get_user_id(), $groupEntity); if ($isTutor) { diff --git a/public/main/inc/ajax/exercise.ajax.php b/public/main/inc/ajax/exercise.ajax.php index d476c12a9a..13033e5e1e 100644 --- a/public/main/inc/ajax/exercise.ajax.php +++ b/public/main/inc/ajax/exercise.ajax.php @@ -938,7 +938,7 @@ switch ($action) { $confirmed = !empty($_POST['quiz_confirm_saved_answers_check']); $em = Database::getManager(); - $repo = $em->getRepository('ChamiloCoreBundle:TrackEExerciseConfirmation'); + $repo = $em->getRepository(TrackEExerciseConfirmation::class); try { if (!$trackConfirmationId) { diff --git a/public/main/inc/ajax/extra_field.ajax.php b/public/main/inc/ajax/extra_field.ajax.php index ce0cbaa559..7316c9e926 100644 --- a/public/main/inc/ajax/extra_field.ajax.php +++ b/public/main/inc/ajax/extra_field.ajax.php @@ -1,7 +1,9 @@ getRepository('ChamiloCoreBundle:Tag') + ->getRepository(Tag::class) ->createQueryBuilder('t') ->where("t.tag LIKE :tag") ->andWhere('t.fieldId = :field') @@ -117,10 +119,10 @@ switch ($action) { 'field' => $extraFieldInfo['id'], ]; - $extraFieldSavedSearch = $em->getRepository('ChamiloCoreBundle:ExtraFieldSavedSearch')->findOneBy($search); + $extraFieldSavedSearch = $em->getRepository(ExtraFieldSavedSearch::class)->findOneBy($search); if ($save) { - $extraField = new \Chamilo\CoreBundle\Entity\ExtraFieldSavedSearch('session'); + $extraField = new ExtraFieldSavedSearch('session'); if ($extraFieldSavedSearch) { $extraFieldSavedSearch->setValue($values); $em->persist($extraFieldSavedSearch); @@ -129,8 +131,8 @@ switch ($action) { } if ($extraFieldInfo) { - /** @var \Chamilo\CoreBundle\Entity\ExtraFieldSavedSearch $options */ - $extraFieldSavedSearch = $em->getRepository('ChamiloCoreBundle:ExtraFieldSavedSearch')->findOneBy($search); + /** @var ExtraFieldSavedSearch $extraFieldSavedSearch */ + $extraFieldSavedSearch = $em->getRepository(ExtraFieldSavedSearch::class)->findOneBy($search); $values = $extraFieldSavedSearch->getValue(); $url = api_get_self().'?a=order&save=1&field_variable='.$variable; diff --git a/public/main/inc/ajax/forum.ajax.php b/public/main/inc/ajax/forum.ajax.php index 86969651cb..b0dce7e460 100644 --- a/public/main/inc/ajax/forum.ajax.php +++ b/public/main/inc/ajax/forum.ajax.php @@ -1,4 +1,5 @@ find('ChamiloCourseBundle:CForumPost', $postId); + $post = $em->find(CForumPost::class, $postId); if ($post) { - $forum = get_forums($post->getForumId(), api_get_course_id()); + $forum = $post->getForum(); $status = $post->getStatus(); if (empty($status)) { $status = CForumPost::STATUS_WAITING_MODERATION; diff --git a/public/main/inc/ajax/install.ajax.php b/public/main/inc/ajax/install.ajax.php index daf5c06ffe..ff8e193837 100644 --- a/public/main/inc/ajax/install.ajax.php +++ b/public/main/inc/ajax/install.ajax.php @@ -1,4 +1,5 @@ request('GET', $url, $options); if ('200' == $res->getStatusCode() || '301' == $res->getStatusCode()) { $urlValidated = true; diff --git a/public/main/inc/ajax/sequence.ajax.php b/public/main/inc/ajax/sequence.ajax.php index fbcf3eafef..915b564139 100644 --- a/public/main/inc/ajax/sequence.ajax.php +++ b/public/main/inc/ajax/sequence.ajax.php @@ -23,9 +23,9 @@ $sequenceId = isset($_REQUEST['sequence_id']) ? $_REQUEST['sequence_id'] : 0; $em = Database::getManager(); /** @var SequenceRepository $sequenceRepository */ -$sequenceRepository = $em->getRepository('ChamiloCoreBundle:Sequence'); +$sequenceRepository = $em->getRepository(Sequence::class); /** @var SequenceResourceRepository $sequenceResourceRepository */ -$sequenceResourceRepository = $em->getRepository('ChamiloCoreBundle:SequenceResource'); +$sequenceResourceRepository = $em->getRepository(SequenceResource::class); switch ($action) { case 'graph': diff --git a/public/main/inc/ajax/session.ajax.php b/public/main/inc/ajax/session.ajax.php index 30cfc23cb7..6e08c26014 100644 --- a/public/main/inc/ajax/session.ajax.php +++ b/public/main/inc/ajax/session.ajax.php @@ -282,7 +282,7 @@ switch ($action) { 1 ); - $id = (int) $newFolderData['iid']; + $id = $newFolderData->getIid(); } else { $id = DocumentManager::get_document_id($courseInfo, $folderName, $session->getId()); } diff --git a/public/main/inc/ajax/skill.ajax.php b/public/main/inc/ajax/skill.ajax.php index 6b0d944e68..a7ac9a4428 100644 --- a/public/main/inc/ajax/skill.ajax.php +++ b/public/main/inc/ajax/skill.ajax.php @@ -4,6 +4,7 @@ use Chamilo\CoreBundle\Entity\SkillRelCourse; use Chamilo\CoreBundle\Entity\SkillRelItem; +use Chamilo\CoreBundle\Entity\SkillRelItemRelUser; /** * Responses to AJAX calls. @@ -415,7 +416,7 @@ switch ($action) { if (!empty($typeId) && !empty($itemId) && !empty($skillId) && !empty($userId) && !empty($courseId)) { $em = Database::getManager(); $user = api_get_user_entity($userId); - $skill = $em->getRepository('ChamiloCoreBundle:Skill')->find($skillId); + $skill = $em->getRepository(\Chamilo\CoreBundle\Entity\Skill::class)->find($skillId); if (empty($user) || empty($skill)) { exit; } @@ -435,13 +436,13 @@ switch ($action) { 'user' => $userId, 'skillRelItem' => $skillRelItem, ]; - $skillRelItemRelUser = $em->getRepository('ChamiloCoreBundle:SkillRelItemRelUser')->findOneBy($criteria); + $skillRelItemRelUser = $em->getRepository(SkillRelItemRelUser::class)->findOneBy($criteria); if ($skillRelItemRelUser) { $em->remove($skillRelItemRelUser); $em->flush(); $skillRelItemRelUser = null; } else { - $skillRelItemRelUser = new Chamilo\CoreBundle\Entity\SkillRelItemRelUser(); + $skillRelItemRelUser = new SkillRelItemRelUser(); $skillRelItemRelUser ->setUser($user) ->setSkillRelItem($skillRelItem) @@ -476,7 +477,7 @@ switch ($action) { } $em = Database::getManager(); - $skillRepo = $em->getRepository('ChamiloCoreBundle:Skill'); + $skillRepo = $em->getRepository(\Chamilo\CoreBundle\Entity\Skill::class); $skill = $skillRepo->find($skillId); $user = api_get_user_entity($userId); @@ -484,7 +485,7 @@ switch ($action) { exit; } - $skillUserRepo = $em->getRepository('ChamiloCoreBundle:SkillRelUser'); + $skillUserRepo = $em->getRepository(\Chamilo\CoreBundle\Entity\SkillRelUser::class); $criteria = [ 'user' => $user, 'skill' => $skill, @@ -502,7 +503,7 @@ switch ($action) { $course = api_get_course_entity($courseId); $skillUser->setCourse($course); if (!empty($sessionId)) { - $session = $em->getRepository('ChamiloCoreBundle:Session')->find($sessionId); + $session = api_get_session_entity($sessionId); $skillUser->setSession($session); } diff --git a/public/main/inc/ajax/social.ajax.php b/public/main/inc/ajax/social.ajax.php index cee1e5f54e..d97c052280 100644 --- a/public/main/inc/ajax/social.ajax.php +++ b/public/main/inc/ajax/social.ajax.php @@ -349,8 +349,8 @@ switch ($action) { } $em = Database::getManager(); - $messageRepo = $em->getRepository('ChamiloCoreBundle:Message'); - $messageLikesRepo = $em->getRepository('ChamiloCoreBundle:MessageFeedback'); + $messageRepo = $em->getRepository(Message::class); + $messageLikesRepo = $em->getRepository(MessageFeedback::class); /** @var Message $message */ $message = $messageRepo->find($messageId); diff --git a/public/main/inc/ajax/statistics.ajax.php b/public/main/inc/ajax/statistics.ajax.php index ce7f612359..a2f2c2a4f8 100644 --- a/public/main/inc/ajax/statistics.ajax.php +++ b/public/main/inc/ajax/statistics.ajax.php @@ -430,16 +430,17 @@ switch ($action) { if (!empty($row['value'])) { $date1 = new DateTime($row['value']); $interval = $now->diff($date1); - $years = (int) $interval->y; - - if ($years >= 16 && $years <= 17) { - $all['16-17']++; - } - if ($years >= 18 && $years <= 25) { - $all['18-25']++; - } - if ($years >= 26 && $years <= 30) { - $all['26-30']++; + if ($interval) { + $years = $interval->y; + if ($years >= 16 && $years <= 17) { + $all['16-17']++; + } + if ($years >= 18 && $years <= 25) { + $all['18-25']++; + } + if ($years >= 26 && $years <= 30) { + $all['26-30']++; + } } } } diff --git a/public/main/inc/lib/course_description.lib.php b/public/main/inc/lib/course_description.lib.php index 35063fe6a3..96758a3026 100644 --- a/public/main/inc/lib/course_description.lib.php +++ b/public/main/inc/lib/course_description.lib.php @@ -107,9 +107,9 @@ class CourseDescription * Get all data by description and session id, * first you must set session_id property with the object CourseDescription. * - * @param int $description_type Description type - * @param int $courseId Course code (optional) - * @param int $session_id Session id (optional) + * @param int $description_type Description type + * @param int $courseId Course code (optional) + * @param int $session_id Session id (optional) * * @return array List of fields from the descriptions found of the given type */ diff --git a/public/main/inc/lib/webservices/Rest.php b/public/main/inc/lib/webservices/Rest.php index f41f2b2885..67ce2749cc 100644 --- a/public/main/inc/lib/webservices/Rest.php +++ b/public/main/inc/lib/webservices/Rest.php @@ -9,67 +9,67 @@ use Chamilo\CoreBundle\Entity\Session; use Chamilo\CoreBundle\Framework\Container; use Chamilo\CourseBundle\Entity\CLpCategory; use Chamilo\CourseBundle\Entity\CNotebook; -use Chamilo\CourseBundle\Entity\Repository\CNotebookRepository; -use Chamilo\UserBundle\Entity\User; +use Chamilo\CourseBundle\Repository\CNotebookRepository; +use Chamilo\CoreBundle\Entity\User; /** * Class RestApi. */ class Rest extends WebService { - const SERVICE_NAME = 'MsgREST'; - const EXTRA_FIELD_GCM_REGISTRATION = 'gcm_registration_id'; - - const GET_AUTH = 'authenticate'; - const GET_USER_MESSAGES = 'user_messages'; - const POST_USER_MESSAGE_READ = 'user_message_read'; - const POST_USER_MESSAGE_UNREAD = 'user_message_unread'; - const SAVE_GCM_ID = 'gcm_id'; - const GET_USER_COURSES = 'user_courses'; - const GET_PROFILE = 'user_profile'; - const GET_COURSE_INFO = 'course_info'; - const GET_COURSE_DESCRIPTIONS = 'course_descriptions'; - const GET_COURSE_DOCUMENTS = 'course_documents'; - const GET_COURSE_ANNOUNCEMENTS = 'course_announcements'; - const GET_COURSE_ANNOUNCEMENT = 'course_announcement'; - const GET_COURSE_AGENDA = 'course_agenda'; - const GET_COURSE_NOTEBOOKS = 'course_notebooks'; - const GET_COURSE_FORUM_CATEGORIES = 'course_forumcategories'; - const GET_COURSE_FORUM = 'course_forum'; - const GET_COURSE_FORUM_THREAD = 'course_forumthread'; - const GET_COURSE_LEARNPATHS = 'course_learnpaths'; - const GET_COURSE_LEARNPATH = 'course_learnpath'; - const GET_COURSE_LP_PROGRESS = 'course_lp_progress'; - const SAVE_FORUM_POST = 'save_forum_post'; - const GET_USER_SESSIONS = 'user_sessions'; - const SAVE_USER_MESSAGE = 'save_user_message'; - const GET_MESSAGE_USERS = 'message_users'; - const SAVE_COURSE_NOTEBOOK = 'save_course_notebook'; - const SAVE_FORUM_THREAD = 'save_forum_thread'; - const SAVE_COURSE = 'save_course'; - const SAVE_USER = 'save_user'; - const SAVE_USER_JSON = 'save_user_json'; - const SUBSCRIBE_USER_TO_COURSE = 'subscribe_user_to_course'; - const EXTRAFIELD_GCM_ID = 'gcm_registration_id'; - const GET_USER_MESSAGES_RECEIVED = 'user_messages_received'; - const GET_USER_MESSAGES_SENT = 'user_messages_sent'; - const DELETE_USER_MESSAGE = 'delete_user_message'; - const SET_MESSAGE_READ = 'set_message_read'; - const CREATE_CAMPUS = 'add_campus'; - const EDIT_CAMPUS = 'edit_campus'; - const DELETE_CAMPUS = 'delete_campus'; - const SAVE_SESSION = 'save_session'; - const GET_USERS = 'get_users'; - const GET_COURSES = 'get_courses'; - const ADD_COURSES_SESSION = 'add_courses_session'; - const ADD_USERS_SESSION = 'add_users_session'; - const CREATE_SESSION_FROM_MODEL = 'create_session_from_model'; - const SUBSCRIBE_USER_TO_SESSION_FROM_USERNAME = 'subscribe_user_to_session_from_username'; - const GET_SESSION_FROM_EXTRA_FIELD = 'get_session_from_extra_field'; - const UPDATE_USER_FROM_USERNAME = 'update_user_from_username'; - const USERNAME_EXIST = 'username_exist'; - const GET_COURSE_QUIZ_MDL_COMPAT = 'get_course_quiz_mdl_compat'; - const UPDATE_USER_PAUSE_TRAINING = 'update_user_pause_training'; + public const SERVICE_NAME = 'MsgREST'; + public const EXTRA_FIELD_GCM_REGISTRATION = 'gcm_registration_id'; + + public const GET_AUTH = 'authenticate'; + public const GET_USER_MESSAGES = 'user_messages'; + public const POST_USER_MESSAGE_READ = 'user_message_read'; + public const POST_USER_MESSAGE_UNREAD = 'user_message_unread'; + public const SAVE_GCM_ID = 'gcm_id'; + public const GET_USER_COURSES = 'user_courses'; + public const GET_PROFILE = 'user_profile'; + public const GET_COURSE_INFO = 'course_info'; + public const GET_COURSE_DESCRIPTIONS = 'course_descriptions'; + public const GET_COURSE_DOCUMENTS = 'course_documents'; + public const GET_COURSE_ANNOUNCEMENTS = 'course_announcements'; + public const GET_COURSE_ANNOUNCEMENT = 'course_announcement'; + public const GET_COURSE_AGENDA = 'course_agenda'; + public const GET_COURSE_NOTEBOOKS = 'course_notebooks'; + public const GET_COURSE_FORUM_CATEGORIES = 'course_forumcategories'; + public const GET_COURSE_FORUM = 'course_forum'; + public const GET_COURSE_FORUM_THREAD = 'course_forumthread'; + public const GET_COURSE_LEARNPATHS = 'course_learnpaths'; + public const GET_COURSE_LEARNPATH = 'course_learnpath'; + public const GET_COURSE_LP_PROGRESS = 'course_lp_progress'; + public const SAVE_FORUM_POST = 'save_forum_post'; + public const GET_USER_SESSIONS = 'user_sessions'; + public const SAVE_USER_MESSAGE = 'save_user_message'; + public const GET_MESSAGE_USERS = 'message_users'; + public const SAVE_COURSE_NOTEBOOK = 'save_course_notebook'; + public const SAVE_FORUM_THREAD = 'save_forum_thread'; + public const SAVE_COURSE = 'save_course'; + public const SAVE_USER = 'save_user'; + public const SAVE_USER_JSON = 'save_user_json'; + public const SUBSCRIBE_USER_TO_COURSE = 'subscribe_user_to_course'; + public const EXTRAFIELD_GCM_ID = 'gcm_registration_id'; + public const GET_USER_MESSAGES_RECEIVED = 'user_messages_received'; + public const GET_USER_MESSAGES_SENT = 'user_messages_sent'; + public const DELETE_USER_MESSAGE = 'delete_user_message'; + public const SET_MESSAGE_READ = 'set_message_read'; + public const CREATE_CAMPUS = 'add_campus'; + public const EDIT_CAMPUS = 'edit_campus'; + public const DELETE_CAMPUS = 'delete_campus'; + public const SAVE_SESSION = 'save_session'; + public const GET_USERS = 'get_users'; + public const GET_COURSES = 'get_courses'; + public const ADD_COURSES_SESSION = 'add_courses_session'; + public const ADD_USERS_SESSION = 'add_users_session'; + public const CREATE_SESSION_FROM_MODEL = 'create_session_from_model'; + public const SUBSCRIBE_USER_TO_SESSION_FROM_USERNAME = 'subscribe_user_to_session_from_username'; + public const GET_SESSION_FROM_EXTRA_FIELD = 'get_session_from_extra_field'; + public const UPDATE_USER_FROM_USERNAME = 'update_user_from_username'; + public const USERNAME_EXIST = 'username_exist'; + public const GET_COURSE_QUIZ_MDL_COMPAT = 'get_course_quiz_mdl_compat'; + public const UPDATE_USER_PAUSE_TRAINING = 'update_user_pause_training'; /** * @var Session @@ -1773,8 +1773,7 @@ class Rest extends WebService if (is_null($userId)) { throw new Exception(get_lang('NoData')); } - /** @var User $user */ - $user = UserManager::getRepository()->find($userId); + $user = api_get_user_entity($userId); if (empty($user)) { throw new Exception(get_lang('CouldNotLoadUser')); } @@ -1999,12 +1998,12 @@ class Rest extends WebService 'indent' => 0, 'onclick' => '', 'afterlink' => null, - 'customdata' => "", + 'customdata' => '', 'noviewlink' => false, 'completion' => (int) ($exercise[1] > 0), ]; }, - Exercise::exerciseGrid(0, '', $userId, $courseId, $sessionId, true) + Exercise::exerciseGridResource(0, '', $userId, $courseId, $sessionId, true) ); return [$json]; diff --git a/public/main/lp/lp_edit.php b/public/main/lp/lp_edit.php index 4a53191ed6..f0a73d43b8 100644 --- a/public/main/lp/lp_edit.php +++ b/public/main/lp/lp_edit.php @@ -11,7 +11,6 @@ use ChamiloSession as Session; * * @author Yannick Warnier */ - api_protect_course_script(); /** @var learnpath $learnPath */ diff --git a/src/CoreBundle/Controller/CourseHomeController.php b/src/CoreBundle/Controller/CourseHomeController.php index 92d9a56404..432a1c8473 100644 --- a/src/CoreBundle/Controller/CourseHomeController.php +++ b/src/CoreBundle/Controller/CourseHomeController.php @@ -173,10 +173,7 @@ class CourseHomeController extends ToolBaseController if (!empty($item) && isset($item['value']) && !empty($item['value'])) { /** @var Graph $graph */ - $graph = UnserializeApi::unserialize( - 'career', - $item['value'] - ); + $graph = UnserializeApi::unserialize('career', $item['value']); $diagram = Career::renderDiagram($careerInfo, $graph); } } @@ -192,8 +189,12 @@ class CourseHomeController extends ToolBaseController api_remove_in_gradebook(); \Exercise::cleanSessionVariables(); - $shortcutQuery = $shortcutRepository->getResources($this->getUser(), $course->getResourceNode(), $course); - $shortcuts = $shortcutQuery->getQuery()->getResult(); + + $shortcuts = []; + if ($user) { + $shortcutQuery = $shortcutRepository->getResources($user, $course->getResourceNode(), $course); + $shortcuts = $shortcutQuery->getQuery()->getResult(); + } return $this->render( '@ChamiloCore/Course/home.html.twig', diff --git a/src/CoreBundle/Entity/ExtraFieldSavedSearch.php b/src/CoreBundle/Entity/ExtraFieldSavedSearch.php index 3936f9e203..252e6d3e91 100644 --- a/src/CoreBundle/Entity/ExtraFieldSavedSearch.php +++ b/src/CoreBundle/Entity/ExtraFieldSavedSearch.php @@ -41,7 +41,7 @@ class ExtraFieldSavedSearch protected User $user; /** - * @var string + * @var array * * @ORM\Column(name="value", type="array", nullable=true, unique=false) */ @@ -57,20 +57,12 @@ class ExtraFieldSavedSearch return $this->id; } - /** - * @return ExtraField - */ - public function getField() + public function getField(): ExtraField { return $this->field; } - /** - * @param ExtraField $field - * - * @return ExtraFieldSavedSearch - */ - public function setField($field) + public function setField(ExtraField $field): self { $this->field = $field; @@ -78,19 +70,14 @@ class ExtraFieldSavedSearch } /** - * @return string + * @return array */ public function getValue() { return $this->value; } - /** - * @param string $value - * - * @return ExtraFieldSavedSearch - */ - public function setValue($value) + public function setValue(array $value): self { $this->value = $value;