Use api_get_user_entity() instead of custom code

pull/2487/head
jmontoyaa 7 years ago
parent d5c9458284
commit 0f05432558
  1. 4
      main/admin/user_information.php
  2. 4
      main/auth/external_login/newUser.ldap.php
  3. 2
      main/badge/issued.php
  4. 7
      main/badge/issued_all.php
  5. 3
      main/forum/forumfunction.inc.php
  6. 5
      main/gradebook/lib/be/studentpublicationlink.class.php
  7. 4
      main/inc/lib/CourseChatUtils.php
  8. 7
      main/inc/lib/api.lib.php
  9. 7
      main/inc/lib/myspace.lib.php
  10. 3
      plugin/bbb/lib/bbb.lib.php
  11. 3
      src/Chamilo/CoreBundle/Component/Editor/CkEditor/CkEditor.php

@ -230,9 +230,7 @@ $socialInformation = '';
* Show social activity
*/
if (api_get_setting('allow_social_tool') === 'true') {
$em = Database::getManager();
$userObject = $em->find('ChamiloUserBundle:User', $user['user_id']);
$userObject = api_get_user_entity($user['user_id']);
$data = [];
// Calculate values

@ -44,13 +44,11 @@ require_once __DIR__.'/functions.inc.php';
$ldap_user = extldap_authenticate($login, $password);
if ($ldap_user !== false) {
$em = Database::getManager();
$chamilo_user = extldap_get_chamilo_user($ldap_user);
//username is not on the ldap, we have to use $login variable
$chamilo_user['username'] = $login;
$chamilo_uid = external_add_user($chamilo_user);
$chamiloUser = $em->find('ChamiloUserBundle:User', $chamilo_uid);
$chamiloUser = api_get_user_entity($chamilo_uid);
if ($chamiloUser) {
$loginFailed = false;

@ -75,7 +75,7 @@ $htmlHeadXtra[] = "
";
$currentUserId = api_get_user_id();
$currentUser = $entityManager->find('ChamiloUserBundle:User', $currentUserId);
$currentUser = api_get_user_entity($currentUserId);
$allowDownloadExport = $currentUser ? $currentUser->getId() === $user->getId() : false;
$allowComment = $currentUser ? Skill::userCanAddFeedbackToUser($currentUser, $user) : false;
$skillIssueDate = api_get_local_time($skillIssue->getAcquiredSkillAt());

@ -23,7 +23,7 @@ if (!$userId || !$skillId) {
Skill::isAllowed($userId);
$em = Database::getManager();
$user = $em->find('ChamiloUserBundle:User', $userId);
$user = api_get_user_entity($userId);
$skill = $em->find('ChamiloCoreBundle:Skill', $skillId);
$currentUserId = api_get_user_id();
@ -65,8 +65,7 @@ $skillInfo = [
$allUserBadges = [];
/** @var SkillRelUser $skillIssue */
foreach ($userSkills as $index => $skillIssue) {
/** @var User $currentUser */
$currentUser = $em->find('ChamiloUserBundle:User', $currentUserId);
$currentUser = api_get_user_entity($currentUserId);
$allowDownloadExport = $currentUser ? $currentUser->getId() === $user->getId() : false;
$allowComment = $currentUser ? Skill::userCanAddFeedbackToUser($currentUser, $user) : false;
$skillIssueDate = api_get_local_time($skillIssue->getAcquiredSkillAt());
@ -274,7 +273,7 @@ foreach ($userSkills as $index => $skillIssue) {
$template = new Template(get_lang('IssuedBadgeInformation'));
$template->assign('user_badges', $allUserBadges);
$template->assign('show_level', api_get_configuration_value('hide_skill_levels') == false;
$template->assign('show_level', api_get_configuration_value('hide_skill_levels') == false);
$content = $template->fetch(
$template->get_template('skill/issued_all.tpl')

@ -2075,8 +2075,7 @@ function getPosts(
$posterId = $post->getPosterId();
if (!empty($posterId)) {
/** @var User $user */
$user = $em->find('ChamiloUserBundle:User', $posterId);
$user = api_get_user_entity($posterId);
if ($user) {
$postInfo['user_id'] = $user->getUserId();
$postInfo['username'] = $user->getUsername();

@ -168,7 +168,7 @@ class StudentPublicationLink extends AbstractLink
/**
* @param null $stud_id
* @return array|null
* @return array
*/
public function calc_score($stud_id = null, $type = null)
{
@ -177,10 +177,9 @@ class StudentPublicationLink extends AbstractLink
$data = $this->get_exercise_data();
if (empty($data)) {
return '';
return [];
}
$id = $data['id'];
$session = $em->find('ChamiloCoreBundle:Session', api_get_session_id());
$assignment = $em

@ -109,9 +109,7 @@ class CourseChatUtils
if (empty($message)) {
return false;
}
$em = Database::getManager();
$user = $em->find('ChamiloUserBundle:User', $this->userId);
$user = api_get_user_entity($this->userId);
$courseInfo = api_get_course_info_by_id($this->courseId);
$isMaster = (bool) api_is_course_admin();
$document_path = api_get_path(SYS_COURSE_PATH).$courseInfo['path'].'/document';

@ -1609,6 +1609,7 @@ function api_get_user_info(
*/
function api_get_user_entity($userId)
{
$userId = (int) $userId;
/** @var \Chamilo\UserBundle\Repository\UserRepository $repo */
$repo = Database::getManager()->getRepository('ChamiloUserBundle:User');
@ -3999,14 +4000,14 @@ function api_item_property_update(
if ($result == false || Database::affected_rows($result) == 0) {
$objCourse = $em->find('ChamiloCoreBundle:Course', intval($course_id));
$objTime = new DateTime('now', new DateTimeZone('UTC'));
$objUser = $em->find('ChamiloUserBundle:User', intval($user_id));
$objUser = api_get_user_entity($user_id);
if (empty($objUser)) {
// Use anonymous
$user_id = api_get_anonymous_id();
$objUser = $em->find('ChamiloUserBundle:User', $user_id);
$objUser = api_get_user_entity($user_id);
}
$objGroup = $em->find('ChamiloCourseBundle:CGroupInfo', intval($to_group_id));
$objToUser = $em->find('ChamiloUserBundle:User', intval($to_user_id));
$objToUser = api_get_user_entity($to_user_id);
$objSession = $em->find('ChamiloCoreBundle:Session', intval($session_id));
$startVisibleDate = !empty($start_visible) ? new DateTime($start_visible, new DateTimeZone('UTC')) : null;

@ -2689,9 +2689,10 @@ class MySpace
}
if (!empty($studentId)) {
$student = $em->find('ChamiloUserBundle:User', $studentId);
$studentList[$student->getId()] = $student->getCompleteName();
$student = api_get_user_entity($studentId);
if ($student) {
$studentList[$student->getId()] = $student->getCompleteName();
}
}
$form = new FormValidator('access_overview', 'GET');

@ -1361,7 +1361,6 @@ class bbb
*/
public function findMeetingParticipants($meetingId)
{
$em = Database::getManager();
$meetingData = Database::select(
'*',
'plugin_bbb_room',
@ -1380,7 +1379,7 @@ class bbb
$return[] = [
'id' => $participantInfo['id'],
'meeting_id' => $participantInfo['meeting_id'],
'participant' => $em->find('ChamiloUserBundle:User', $participantInfo['participant_id']),
'participant' => api_get_user_entity($participantInfo['participant_id']),
'in_at' => $participantInfo['in_at'],
'out_at' => $participantInfo['out_at']
];

@ -221,8 +221,7 @@ class CkEditor extends Editor
$entityManager = \Database::getManager();
$templatesRepo = $entityManager->getRepository('ChamiloCoreBundle:Templates');
$user = $entityManager->find('ChamiloUserBundle:User', $userId);
$user = api_get_user_entity($userId);
$course = $entityManager->find('ChamiloCoreBundle:Course', api_get_course_int_id());
if (!$user || !$course) {

Loading…
Cancel
Save