user_linking_requests.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use Chamilo\CoreBundle\Entity\UserRelUser,
  4. Chamilo\UserBundle\Entity\User;
  5. $cidReset = true;
  6. require_once __DIR__.'/../inc/global.inc.php';
  7. api_protect_admin_script();
  8. $action = isset($_GET['action']) ? $_GET['action'] : null;
  9. $hrmId = isset($_GET['hrm']) ? intval($_GET['hrm']) : 0;
  10. $assinedId = isset($_GET['u']) ? intval($_GET['u']) : 0;
  11. $hrm = $hrmId ? api_get_user_entity($hrmId) : null;
  12. $em = Database::getManager();
  13. if ($action === 'accept' && $hrm && $assinedId) {
  14. /** @var UserRelUser $request */
  15. $request = $em->getRepository('ChamiloCoreBundle:UserRelUser')
  16. ->findOneBy([
  17. 'userId' => $assinedId,
  18. 'friendUserId' => $hrm->getId(),
  19. 'relationType' => USER_RELATION_TYPE_HRM_REQUEST
  20. ]);
  21. if ($request) {
  22. $request->setRelationType(USER_RELATION_TYPE_RRHH);
  23. $em->persist($request);
  24. $em->flush();
  25. Display::addFlash(
  26. Display::return_message(get_lang('UserLinkingRequestAccepted'), 'success')
  27. );
  28. }
  29. header('Location: '.api_get_self().'?hrm='.$hrm->getId());
  30. exit;
  31. }
  32. function getData(User $hrm)
  33. {
  34. $requests = UserManager::getUsersFollowedByUser(
  35. $hrm->getId(),
  36. null,
  37. false,
  38. false,
  39. false,
  40. null,
  41. null,
  42. null,
  43. null,
  44. null,
  45. null,
  46. HRM_REQUEST
  47. );
  48. $result = [];
  49. $iconAccept = Display::return_icon('accept.png', get_lang('Accept'));
  50. $urlAccept = api_get_self().'?action=accept&hrm='.$hrm->getId().'&u=';
  51. foreach ($requests as $request) {
  52. $result[] = [
  53. api_get_person_name($request['firstname'], $request['lastname']),
  54. Display::url(
  55. $iconAccept,
  56. $urlAccept.$request['user_id']
  57. )
  58. ];
  59. }
  60. return $result;
  61. }
  62. $form = new FormValidator('user_linking_requests', 'get');
  63. $form->addSelectAjax(
  64. 'hrm',
  65. get_lang('DRH'),
  66. $hrm ? [$hrm->getId() => $hrm->getCompleteName()] : [],
  67. ['url' => api_get_path(WEB_AJAX_PATH).'user_manager.ajax.php?a=user_by_role']
  68. );
  69. $form->addButtonFilter(get_lang('Filter'));
  70. $content = $form->returnForm();
  71. if ($hrm) {
  72. $requests = getData($hrm);
  73. if ($requests) {
  74. $content .= Display::table(
  75. [get_lang('UserLinkingTo'), get_lang('Actions')],
  76. $requests
  77. );
  78. } else {
  79. $content .= Display::return_message(get_lang('NoResults'), 'warning');
  80. }
  81. }
  82. $interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
  83. $toolName = get_lang('UserLinkingRequests');
  84. $view = new Template($toolName);
  85. $view->assign('header', $toolName);
  86. $view->assign('content', $content);
  87. $view->display_one_col_template();