api_get_*_entity instead of EntityRepository::find - refs BT#17453

pull/3372/merge^2
Sébastien Ducoulombier 6 years ago
parent c464ee3863
commit 830d80bd13
  1. 2
      main/admin/course_edit.php
  2. 5
      main/auth/profile.php
  3. 4
      main/course_home/course_home.php
  4. 2
      main/cron/import_csv.php
  5. 3
      main/cron/user_import/resend_email_with_new_password.php
  6. 4
      main/inc/ajax/skill.ajax.php
  7. 2
      main/inc/lib/add_course.lib.inc.php
  8. 43
      main/inc/lib/api.lib.php
  9. 10
      main/inc/lib/course.lib.php
  10. 9
      main/inc/lib/usermanager.lib.php
  11. 5
      main/inc/lib/webservices/Rest.php
  12. 12
      main/lp/learnpath.class.php
  13. 6
      main/lp/lp_subscribe_users.php
  14. 2
      main/lp/lp_subscribe_users_to_category.php
  15. 2
      main/lp/lp_view.php
  16. 2
      main/mySpace/lp_tracking.php
  17. 5
      main/session/resume_session.php
  18. 7
      main/webservices/api/tests/CreateLearningPathTest.php
  19. 3
      main/webservices/api/tests/CreateSessionFromModelTest.php
  20. 28
      main/webservices/registration.soap.php
  21. 9
      plugin/buycourses/src/service_process.php
  22. 5
      plugin/oauth2/src/OAuth2.php
  23. 10
      src/Chamilo/CoreBundle/Entity/Course.php
  24. 3
      src/Chamilo/CoreBundle/Entity/Repository/ItemPropertyRepository.php
  25. 10
      src/Chamilo/CoreBundle/Entity/Repository/SequenceRepository.php
  26. 12
      src/Chamilo/CoreBundle/Entity/Repository/SequenceResourceRepository.php
  27. 20
      src/Chamilo/CoreBundle/Entity/Session.php
  28. 2
      src/Chamilo/CourseBundle/Entity/CCourseSetting.php
  29. 4
      src/Chamilo/CourseBundle/Entity/CDocument.php
  30. 2
      src/Chamilo/CourseBundle/Entity/CForumForum.php
  31. 2
      src/Chamilo/CourseBundle/Entity/CLink.php
  32. 4
      src/Chamilo/CourseBundle/Entity/CLp.php
  33. 2
      src/Chamilo/CourseBundle/Entity/CLpCategory.php
  34. 2
      src/Chamilo/CourseBundle/Entity/CLpItem.php
  35. 2
      src/Chamilo/CourseBundle/Entity/CQuiz.php
  36. 2
      src/Chamilo/CourseBundle/Entity/CTool.php
  37. 2
      src/Chamilo/UserBundle/Entity/User.php

@ -186,7 +186,7 @@ if ($countCategories >= 100) {
$courseTeacherNames = [];
foreach ($course_teachers as $courseTeacherId) {
/** @var User $courseTeacher */
$courseTeacher = UserManager::getRepository()->find($courseTeacherId);
$courseTeacher = api_get_user_entity($courseTeacherId);
$courseTeacherNames[$courseTeacher->getId()] = UserManager::formatUserFullName($courseTeacher, true);
}

@ -400,8 +400,7 @@ if ($form->validate()) {
$wrong_current_password = false;
$user_data = $form->getSubmitValues(1);
/** @var User $user */
$user = UserManager::getRepository()->find(api_get_user_id());
$user = api_get_user_entity();
// set password if a new one was provided
$validPassword = false;
@ -664,7 +663,7 @@ if ($form->validate()) {
if ($hook) {
Database::getManager()->clear(User::class); // Avoid cache issue (user entity is used before)
$user = api_get_user_entity(api_get_user_id()); // Get updated user info for hook event
$user = api_get_user_entity(); // Get updated user info for hook event
$hook->setEventData(['user' => $user]);
$hook->notifyUpdateUser(HOOK_EVENT_TYPE_POST);
}

@ -241,7 +241,7 @@ if ($action === 'subscribe') {
/**
* @var Chamilo\UserBundle\Entity\User
*/
$user = UserManager::getRepository()->find(api_get_user_id());
$user = api_get_user_entity();
if ($user) {
foreach ($user->getCurrentlyAccessibleSessions() as $session) {
$redirectionTarget = api_get_self().'?id_session='.$session->getId();
@ -253,7 +253,7 @@ if ($action === 'subscribe') {
/**
* @var Chamilo\UserBundle\Entity\User
*/
$user = UserManager::getRepository()->find(api_get_user_id());
$user = api_get_user_entity();
if ($user && !$user->getCurrentlyAccessibleSessions()) {
// subscription was probably refused because user session expired, go back to page "about"
$redirectionTarget = api_get_path(WEB_PATH).'course/'.$courseId.'/about';

@ -1286,7 +1286,7 @@ class ImportCsv
];
/** @var CItemProperty $itemProperty */
$itemProperty = $em->getRepository('ChamiloCourseBundle:CItemProperty')->findOneBy($criteria);
$courseEntity = $em->getRepository('ChamiloCoreBundle:Course')->find($courseInfo['real_id']);
$courseEntity = api_get_course_entity($courseInfo['real_id']);
if ($itemProperty && $courseEntity) {
$itemProperty->setCourse($courseEntity);
$em->persist($itemProperty);

@ -44,8 +44,7 @@ foreach ($list as $mail) {
$pass = api_substr($row['username'], 0, 4).rand(0, 9).rand(0, 9);
if ($user) {
/** @var User $user */
$user = $repository->find($row['user_id']);
$user = api_get_user_entity($row['user_id']);
$user->setPlainPassword($pass);
$userManager->updateUser($user, true);
} else {

@ -420,7 +420,7 @@ switch ($action) {
exit;
}
$session = $em->getRepository('ChamiloCoreBundle:Session')->find($sessionId);
$session = api_get_session_entity($sessionId);
/** @var \Chamilo\SkillBundle\Entity\SkillRelItem $skillRelItem */
$skillRelItem = $em->getRepository('ChamiloSkillBundle:SkillRelItem')->findOneBy(
['itemId' => $itemId, 'itemType' => $typeId, 'skill' => $skillId]
@ -498,7 +498,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);
}

@ -956,7 +956,7 @@ class AddCourse
}
// Adding the course to an URL.
$url = AccessUrl::getRepository()->find($accessUrlId);
$url = api_get_access_url_entity($accessUrlId);
if (!is_null($url)) {
$urlRelCourse = (new AccessUrlRelCourse())
->setCourse($course)

@ -1,10 +1,12 @@
<?php
/* For licensing terms, see /license.txt */
use Chamilo\CoreBundle\Entity\AccessUrl;
use Chamilo\CoreBundle\Entity\SettingsCurrent;
use Chamilo\CoreBundle\Entity\UserCourseCategory;
use Chamilo\CourseBundle\Entity\CGroupInfo;
use Chamilo\CourseBundle\Entity\CItemProperty;
use Chamilo\CourseBundle\Entity\CLp;
use Chamilo\UserBundle\Entity\User;
use ChamiloSession as Session;
use Doctrine\Common\Collections\Criteria;
@ -1795,9 +1797,9 @@ function api_get_user_info(
*
* @return User
*/
function api_get_user_entity($userId)
function api_get_user_entity($userId = 0)
{
$userId = (int) $userId;
$userId = (int) $userId ?: api_get_user_id();
$repo = UserManager::getRepository();
/** @var User $user */
@ -2214,6 +2216,16 @@ function api_get_session_entity($id = 0)
return Database::getManager()->getRepository('ChamiloCoreBundle:Session')->find($id);
}
/**
* @param int $id the learning path identifier
*
* @return CLp|null
*/
function api_get_lp_entity($id)
{
return Database::getManager()->getRepository('ChamiloCourseBundle:CLp')->find($id);
}
/**
* Returns the current course info array.
@ -2614,6 +2626,16 @@ function api_get_group_id()
return Session::read('_gid', 0);
}
/**
* @param int $id the group identifier
*
* @return CGroupInfo|object|null
*/
function api_get_group_entity($id = 0)
{
return Database::getManager()->getRepository('ChamiloCourseBundle:CGroupInfo')->find($id ?: api_get_group_id());
}
/**
* Gets the current or given session name.
*
@ -4199,15 +4221,15 @@ function api_item_property_update(
if (!array_key_exists('real_id', $_course)) {
return false;
}
$course = \Chamilo\CoreBundle\Entity\Course::getRepository()->find($_course['real_id']);
$course = api_get_course_entity($_course['real_id']);
if (is_null($course)) {
return false;
}
$toUser = api_get_user_entity($to_user_id);
$toGroup = array_key_exists('iid', $groupInfo) ? CGroupInfo::getRepository()->find($groupInfo['iid']) : null;
$toGroup = array_key_exists('iid', $groupInfo) ? api_get_group_entity($groupInfo['iid']) : null;
$user = api_get_user_entity($user_id) ?: api_get_user_entity(api_get_anonymous_id());
$session = \Chamilo\CoreBundle\Entity\Session::getRepository()->find($session_id ?: api_get_session_id());
$session = api_get_session_entity($session_id);
$startVisibleDate = empty($start_visible)
? null
@ -6387,6 +6409,17 @@ function api_get_access_url_from_user($user_id)
return $list;
}
/**
* @param int $id the access url identifier
*
* @return AccessUrl|null
*/
function api_get_access_url_entity($id = 0) {
return Database::getManager()->getRepository('ChamiloCoreBundle:AccessUrl')->find(
$id ?: api_get_current_access_url_id()
);
}
/**
* Gets the status of a user in a course.
*

@ -565,10 +565,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
*/
$user = UserManager::getRepository()->find($userId);
$user = api_get_user_entity($userId);
$sessions = $user->getCurrentlyAccessibleSessions();
if (empty($sessions)) {
// user has no accessible session
@ -1196,10 +1193,7 @@ class CourseManager
if (is_null($course)) {
return false;
}
/**
* @var \Chamilo\UserBundle\Entity\User
*/
$user = UserManager::getRepository()->find($user_id);
$user = api_get_user_entity($user_id);
if (is_null($user)) {
return false;
}

@ -146,9 +146,7 @@ class UserManager
*/
public static function updatePassword($userId, $password)
{
$repository = self::getRepository();
/** @var User $user */
$user = $repository->find($userId);
$user = api_get_user_entity($userId);
$userManager = self::getManager();
$user->setPlainPassword($password);
$userManager->updateUser($user, true);
@ -714,7 +712,7 @@ class UserManager
// (extra field values of a deleted user might remain)
foreach ($itemList as $item) {
$userId = intval($item['item_id']);
$user = UserManager::getRepository()->find($userId);
$user = api_get_user_entity($userId);
if (!is_null($user)) {
if (false === $loginName) {
$loginName = $user->getUsername();
@ -1366,8 +1364,7 @@ class UserManager
}
$userManager = self::getManager();
/** @var User $user */
$user = self::getRepository()->find($user_id);
$user = api_get_user_entity($user_id);
if (empty($user)) {
return false;

@ -1811,8 +1811,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'));
}
@ -2090,7 +2089,7 @@ class Rest extends WebService
if (0 == $sessionId) {
$learningPath->setSessionId(0);
} else {
$session = Session::getRepository()->find($sessionId);
$session = api_get_session_entity($sessionId);
if (is_null($session)) {
throw new Exception("no session has id '$sessionId'");
}

@ -508,8 +508,8 @@ class learnpath
$previous = (int) $previous;
$id = (int) $id;
$max_time_allowed = htmlentities($max_time_allowed);
$course = \Chamilo\CoreBundle\Entity\Course::getRepository()->find($course_id);
$learningPath = CLp::getRepository()->find($this->get_id());
$course = api_get_course_entity($course_id);
$learningPath = api_get_lp_entity($this->get_id());
$item = (new CLpItem())
->setCourse($course)
->setLearningPath($learningPath)
@ -628,7 +628,7 @@ class learnpath
if ('zip' !== $origin) {
$course_id = api_get_course_int_id($courseCode);
if ($course_id) {
$course = \Chamilo\CoreBundle\Entity\Course::getRepository()->find($course_id);
$course = api_get_course_entity($course_id);
if (!is_null($course)) {
$learningPath = (new CLp())
->setCourse($course)
@ -4423,14 +4423,12 @@ class learnpath
/** @var ItemPropertyRepository $itemRepo */
$itemRepo = $em->getRepository('ChamiloCourseBundle:CItemProperty');
/** @var CourseRepository $courseRepo */
$courseRepo = $em->getRepository('ChamiloCoreBundle:Course');
$session = null;
if (!empty($sessionId)) {
$session = $em->getRepository('ChamiloCoreBundle:Session')->find($sessionId);
$session = api_get_session_entity($sessionId);
}
$course = $courseRepo->find($courseId);
$course = api_get_course_entity($courseId);
if ($courseId != 0) {
// Subscribed groups to a LP

@ -57,10 +57,10 @@ $itemRepo = $em->getRepository('ChamiloCourseBundle:CItemProperty');
/** @var Session $session */
$session = null;
if (!empty($sessionId)) {
$session = $em->getRepository('ChamiloCoreBundle:Session')->find($sessionId);
$session = api_get_session_entity($sessionId);
}
$course = $courseRepo->find($courseId);
$course = api_get_course_entity($courseId);
$subscribedUsers = [];
// Getting subscribe users to the course.
@ -159,7 +159,7 @@ if (!empty($selectedGroupChoices)) {
}
$form->setDefaults($defaults);
$currentUser = api_get_user_entity(api_get_user_id());
$currentUser = api_get_user_entity();
if ($form->validate()) {
$values = $form->getSubmitValues();

@ -176,7 +176,7 @@ if ($formUsers->validate()) {
foreach ($users as $userId) {
$categoryUser = new CLpCategoryUser();
$user = UserManager::getRepository()->find($userId);
$user = api_get_user_entity($userId);
if ($user) {
$categoryUser->setUser($user);
$category->addUser($categoryUser);

@ -86,7 +86,7 @@ if (!$is_allowed_to_edit) {
$category = $em->getRepository('ChamiloCourseBundle:CLpCategory')->find($categoryId);
$block = false;
if ($category) {
$user = UserManager::getRepository()->find($user_id);
$user = api_get_user_entity($user_id);
$users = $category->getUsers();
if (!empty($users) && $users->count() > 0) {
if ($user && !$category->hasUserAdded($user)) {

@ -99,7 +99,7 @@ switch ($action) {
}
$view = $em->getRepository('ChamiloCourseBundle:CLpView')->find($itemView->getLpViewId());
$lp = $em->getRepository('ChamiloCourseBundle:CLp')->find($view->getLpId());
$lp = api_get_lp_entity($view->getLpId());
$duration = learnpathItem::getScormTimeFromParameter('js', $itemView->getTotalTime());
$endTime = $itemView->getStartTime() + $itemView->getTotalTime();

@ -48,10 +48,7 @@ $table_access_url_user = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER
$em = Database::getManager();
$sessionInfo = api_get_session_info($sessionId);
/** @var SessionRepository $sessionRepository */
$sessionRepository = $em->getRepository('ChamiloCoreBundle:Session');
/** @var Session $session */
$session = $sessionRepository->find($sessionId);
$session = api_get_session_entity($sessionId);
$sessionCategory = $session->getCategory();
$action = isset($_GET['action']) ? $_GET['action'] : null;

@ -148,7 +148,7 @@ class CreateLearningPathTest extends V2TestCase
// assert the learning path was created
/** @var CLp $learningPath */
$learningPath = CLp::getRepository()->find($learningPathId);
$learningPath = api_get_lp_entity($learningPathId);
self::assertNotNull($learningPath);
// in the right course
@ -182,8 +182,7 @@ class CreateLearningPathTest extends V2TestCase
);
// assert the learning path was created
/** @var CLp $learningPath */
$learningPath = CLp::getRepository()->find($learningPathId);
$learningPath = api_get_lp_entity($learningPathId);
self::assertNotNull($learningPath);
// in the right session, course and category
@ -300,7 +299,7 @@ class CreateLearningPathTest extends V2TestCase
// assert the learning path was created as specified
/** @var CLp $learningPath */
$learningPath = CLp::getRepository()->find($learningPathId);
$learningPath = api_get_lp_entity($learningPathId);
self::assertNotNull($learningPath);
self::assertEquals(self::$session->getId(), $learningPath->getSessionId());

@ -53,8 +53,7 @@ class CreateSessionFromModelTest extends V2TestCase
// assert the session was created and given the returned session id
$entityManager = Database::getManager();
$repository = $entityManager->getRepository('ChamiloCoreBundle:Session');
$newSession = $repository->find($newSessionId);
$newSession = api_get_session_entity($newSessionId);
$this->assertIsObject($newSession);
// assert the new session got the right data

@ -304,8 +304,7 @@ function WSCreateUsers($params)
$original_user_id_name
);
if ($user_id > 0) {
/** @var User $user */
$user = $userRepository->find($user_id);
$user = api_get_user_entity($user_id);
if ($user && $user->isActive() == false) {
if (!is_null($password)) {
@ -532,8 +531,7 @@ function WSCreateUser($params)
$userRepository = UserManager::getRepository();
if ($user_id > 0) {
/** @var User $user */
$user = $userRepository->find($user_id);
$user = api_get_user_entity($user_id);
if ($user && $user->isActive() == false) {
if (!is_null($password)) {
$user->setPlainPassword($password);
@ -867,7 +865,7 @@ function WSCreateUsersPasswordCrypted($params)
$count_row = Database::num_rows($res);
if ($count_row > 0) {
// Check if user is not active.
$sql = "SELECT user_id FROM $table_user
$sql = "SELECT user_id FROM $table_user
WHERE user_id ='".$row[1]."' AND active= '0'";
$resu = Database::query($sql);
$r_check_user = Database::fetch_row($resu);
@ -1389,7 +1387,7 @@ function WSCreateUserPasswordCrypted($params)
phone='".Database::escape_string($phone)."',
expiration_date='".Database::escape_string($expiration_date)."',
active='1',
hr_dept_id=".intval($hr_dept_id)."
hr_dept_id=".intval($hr_dept_id)."
WHERE user_id='".$r_check_user[0]."'";
Database::query($sql);
@ -1459,7 +1457,7 @@ function WSCreateUserPasswordCrypted($params)
phone = '".Database::escape_string($phone)."',
language = '".Database::escape_string($language)."',
registration_date = '".api_get_utc_datetime()."',
roles = 'a:0:{}',
roles = 'a:0:{}',
".$queryExpirationDate."
hr_dept_id = '".Database::escape_string($hr_dept_id)."',
active = '".Database::escape_string($active)."'";
@ -1657,8 +1655,7 @@ function WSEditUserCredentials($params)
return 0;
}
/** @var User $user */
$user = $userRepository->find($user_id);
$user = api_get_user_entity($user_id);
if ($user) {
$user->setUsername($username);
if (!is_null($password)) {
@ -1787,8 +1784,7 @@ function WSEditUsers($params)
}
// Edit lastname and firstname only if not empty
/** @var User $user */
$user = $userRepository->find($user_id);
$user = api_get_user_entity($user_id);
if (!empty($lastname)) {
$user->setLastname($lastname);
@ -1968,8 +1964,7 @@ function WSEditUser($params)
return 0;
}
/** @var User $user */
$user = $userRepository->find($user_id);
$user = api_get_user_entity($user_id);
if (!empty($lastname)) {
$user->setLastname($lastname);
@ -2139,7 +2134,7 @@ function WSEditUserWithPicture($params)
}
// Check whether username already exits.
$sql = "SELECT username FROM $table_user
$sql = "SELECT username FROM $table_user
WHERE username = '$username' AND id <> $user_id";
$res_un = Database::query($sql);
$r_username = Database::fetch_row($res_un);
@ -2148,8 +2143,7 @@ function WSEditUserWithPicture($params)
return 0;
}
/** @var User $user */
$user = $userRepository->find($user_id);
$user = api_get_user_entity($user_id);
if (!empty($lastname)) {
$user->setLastname($lastname);
@ -4768,7 +4762,7 @@ function WSSubscribeUserToCourseSimple($params)
error_log('Try to register: user_id= '.$user_id.' to course: '.$course_data['code']);
}
if (!CourseManager::subscribeUser($user_id, $course_data['code'], $status, 0, false, false)) {
$result = 'User was not registered possible reasons: User already registered to the course,
$result = 'User was not registered possible reasons: User already registered to the course,
Course visibility doesnt allow user subscriptions ';
if ($debug) {
error_log($result);

@ -104,8 +104,7 @@ if ($typeUser) {
}
$form->addSelect('info_select', get_lang('User'), $selectOptions);
} elseif ($typeCourse) {
/** @var User $user */
$user = UserManager::getRepository()->find($currentUserId);
$user = api_get_user_entity($currentUserId);
$courses = $user->getCourses();
$checker = false;
foreach ($courses as $course) {
@ -123,8 +122,7 @@ if ($typeUser) {
$form->addSelect('info_select', get_lang('Course'), $selectOptions);
} elseif ($typeSession) {
$sessions = [];
/** @var User $user */
$user = UserManager::getRepository()->find($currentUserId);
$user = api_get_user_entity($currentUserId);
$userSubscriptions = $user->getSessionCourseSubscriptions();
/** @var SessionRelCourseRelUser $userSubscription */
@ -146,8 +144,7 @@ if ($typeUser) {
}
} elseif ($typeFinalLp) {
// We need here to check the current user courses first
/** @var User $user */
$user = UserManager::getRepository()->find($currentUserId);
$user = api_get_user_entity($currentUserId);
$courses = $user->getCourses();
$courseLpList = [];
$sessionLpList = [];

@ -294,10 +294,7 @@ class OAuth2 extends Plugin
private function updateUser($userId, $response)
{
/**
* @var $user Chamilo\UserBundle\Entity\User
*/
$user = UserManager::getRepository()->find($userId);
$user = api_get_user_entity($userId);
$user->setFirstname(
$this->getValueByKey($response, $this->get(
self::SETTING_RESPONSE_RESOURCE_OWNER_FIRSTNAME

@ -458,14 +458,6 @@ class Course
return Database::getManager()->getRepository('ChamiloCoreBundle:Course');
}
/**
* @return Course|null
*/
public static function getCurrentCourse()
{
return self::getRepository()->find(api_get_course_int_id());
}
/**
* Sets sane values if still unset.
* Makes directory if missing.
@ -540,7 +532,7 @@ class Course
$this->departmentUrl = 'https://'.$this->departmentUrl;
}
if ($this->accessUrls->isEmpty()) {
$this->accessUrls->add(AccessUrl::getRepository()->find(api_get_current_access_url_id()));
$this->accessUrls->add(api_get_access_url_entity());
}
$this->prepareRepository();
$this->createTools();

@ -213,7 +213,6 @@ class ItemPropertyRepository extends EntityRepository
$newUserList = []
) {
$em = $this->getEntityManager();
$user = $em->getRepository('ChamiloUserBundle:User');
$usersSubscribedToItem = $this->getUsersSubscribedToItem(
$tool,
@ -248,7 +247,7 @@ class ItemPropertyRepository extends EntityRepository
foreach ($newUserList as $userId) {
if (!in_array($userId, $alreadyAddedUsers)) {
$userObj = $user->find($userId);
$userObj = api_get_user_entity($userId);
$item = new CItemProperty($course);
$item

@ -53,19 +53,13 @@ class SequenceRepository extends EntityRepository
$resource = null;
switch ($type) {
case SequenceResource::COURSE_TYPE:
$repo = $this->getEntityManager()->getRepository('ChamiloCoreBundle:Course');
$resource = api_get_course_entity($itemId);
break;
case SequenceResource::SESSION_TYPE:
$repo = $this->getEntityManager()->getRepository('ChamiloCoreBundle:Session');
$resource = api_get_session_entity($itemId);
break;
}
if ($repo) {
$resource = $repo->find($itemId);
}
return $resource;
}

@ -132,14 +132,10 @@ class SequenceResourceRepository extends EntityRepository
$resource = null;
switch ($type) {
case SequenceResource::SESSION_TYPE:
$repo = $em->getRepository('ChamiloCoreBundle:Session');
$resource = $repo->find($vertexId);
$resource = api_get_session_entity($vertexId);
break;
case SequenceResource::COURSE_TYPE:
$repo = $em->getRepository('ChamiloCoreBundle:Course');
$resource = $repo->find($vertexId);
$resource = api_get_course_entity($vertexId);
break;
}
@ -389,10 +385,10 @@ class SequenceResourceRepository extends EntityRepository
$vertexId = $supVertex->getId();
switch ($type) {
case SequenceResource::SESSION_TYPE:
$resource = $em->getRepository('ChamiloCoreBundle:Session')->find($vertexId);
$resource = api_get_session_entity($vertexId);
break;
case SequenceResource::COURSE_TYPE:
$resource = $em->getRepository('ChamiloCoreBundle:Course')->find($vertexId);
$resource = api_get_course_entity($vertexId);
break;
}

@ -294,19 +294,6 @@ class Session
return Database::getManager()->getRepository('ChamiloCoreBundle:Session');
}
/**
* @return Session|null
*/
public static function getCurrentSession()
{
$sessionId = api_get_session_id();
if (0 != $sessionId) {
return self::getRepository()->find($sessionId);
}
return null;
}
/**
* @return int
*/
@ -479,12 +466,7 @@ class Session
*/
public function isRelatedToCourse($course)
{
return !is_null(
Database::getManager()->getRepository('ChamiloCoreBundle:SessionRelCourse')->findOneBy([
'session' => $this,
'course' => $course,
])
);
return $this->courses->contains($course);
}
/**

@ -339,7 +339,7 @@ class CCourseSetting
public function setCId($cId)
{
$this->cId = $cId;
$this->setCourse(Course::getRepository()->find($cId));
$this->setCourse(api_get_course_entity($cId));
return $this;
}

@ -184,7 +184,7 @@ class CDocument
public function getAbsolutePath()
{
if (is_null($this->course) && $this->cId) {
$this->course = Database::getManager()->find('ChamiloCoreBundle:Course', $this->cId);
$this->course = api_get_course_entity($this->cId);
}
if (is_null($this->course)) {
throw new Exception('this document does not have a course yet');
@ -475,7 +475,7 @@ class CDocument
public function setCId($cId)
{
$this->cId = $cId;
$this->setCourse(Course::getRepository()->find($cId));
$this->setCourse(api_get_course_entity($cId));
return $this;
}

@ -773,7 +773,7 @@ class CForumForum
public function setCId($cId)
{
$this->cId = $cId;
$this->setCourse(Course::getRepository()->find($cId));
$this->setCourse(api_get_course_entity($cId));
return $this;
}

@ -391,7 +391,7 @@ class CLink
public function setCId($cId)
{
$this->cId = $cId;
$this->setCourse(Course::getRepository()->find($cId));
$this->setCourse(api_get_course_entity($cId));
return $this;
}

@ -375,7 +375,7 @@ class CLp
public function prePersist()
{
if (is_null($this->course)) {
$this->course = Course::getCurrentCourse();
$this->course = api_get_course_entity();
if (is_null($this->course)) {
throw new Exception('cannot persist a leaning path without course');
}
@ -1218,7 +1218,7 @@ class CLp
public function setCId($cId)
{
$this->cId = $cId;
$this->setCourse(Course::getRepository()->find($cId));
$this->setCourse(api_get_course_entity($cId));
return $this;
}

@ -141,7 +141,7 @@ class CLpCategory
public function setCId($cId)
{
$this->cId = $cId;
$this->setCourse(Course::getRepository()->find($cId));
$this->setCourse(api_get_course_entity($cId));
return $this;
}

@ -944,7 +944,7 @@ class CLpItem
public function setCId($cId)
{
$this->cId = $cId;
$this->setCourse(Course::getRepository()->find($cId));
$this->setCourse(api_get_course_entity($cId));
return $this;
}

@ -862,7 +862,7 @@ class CQuiz
public function setCId($cId)
{
$this->cId = $cId;
$this->setCourse(Course::getRepository()->find($cId));
$this->setCourse(api_get_course_entity($cId));
return $this;
}

@ -459,7 +459,7 @@ class CTool
public function setCId($cId)
{
$this->cId = $cId;
$this->setCourse(Course::getRepository()->find($cId));
$this->setCourse(api_get_course_entity($cId));
return $this;
}

@ -2609,7 +2609,7 @@ class User implements UserInterface //implements ParticipantInterface, ThemeUser
}
/**
* Retreives this user's related sessions.
* Retrieves this user's related sessions.
*
* @param int $relationType \Chamilo\CoreBundle\Entity\SessionRelUser::relationTypeList key
*

Loading…
Cancel
Save