diff --git a/main/admin/add_drh_to_user.php b/main/admin/add_drh_to_user.php new file mode 100644 index 0000000000..435d6b5bba --- /dev/null +++ b/main/admin/add_drh_to_user.php @@ -0,0 +1,97 @@ +getRepository('ChamiloCoreBundle:UserRelUser'); +/** @var User $user */ +$user = UserManager::getManager()->find($_REQUEST['u']); + +if (!$user) { + api_not_allowed(true); +} + +$subscribedUsers = $user->getHrm(); + +$hrmOptions = []; + +/** @var UserRelUser $subscribedUser */ +foreach ($subscribedUsers as $subscribedUser) { + /** @var User $hrm */ + $hrm = UserManager::getManager()->find($subscribedUser->getFriendUserId()); + + if (!$hrm) { + continue; + } + + $hrmOptions[$hrm->getId()] = $hrm->getCompleteNameWithUsername(); +} + +$form = new FormValidator('assign_hrm'); +$form->addUserAvatar('u', get_lang('User'), 'medium'); +$form->addSelectAjax( + 'hrm', + get_lang('HrmList'), + $hrmOptions, + ['multiple' => 'multiple', 'url' => api_get_path(WEB_AJAX_PATH).'user_manager.ajax.php?a=user_by_role'] +); +$form->addButtonSave(get_lang('Send')); +$form->setDefaults([ + 'u' => $user, + 'hrm' => array_keys($hrmOptions) +]); + +if ($form->validate()) { + /** @var UserRelUser $subscribedUser */ + foreach ($subscribedUsers as $subscribedUser) { + $em->remove($subscribedUser); + }; + + $em->flush(); + + $values = $form->exportValues(); + + foreach ($values['hrm'] as $hrmId) { + /** @var User $hrm */ + $hrm = UserManager::getManager()->find($hrmId); + + if (!$hrm) { + continue; + } + + if ($hrm->getStatus() !== DRH) { + continue; + } + + UserManager::subscribeUsersToHRManager($hrm->getId(), [$user->getId()]); + } + + Display::addFlash( + Display::return_message(get_lang('AssignedUsersHaveBeenUpdatedSuccessfully'), 'success') + ); + + header('Location: '.api_get_self().'?u='.$user->getId()); + exit; +} + +$interbreadcrumb[] = ['name' => get_lang('PlatformAdmin'), 'url' => 'index.php']; +$interbreadcrumb[] = ['name' => get_lang('UserList'), 'url' => 'user_list.php']; +$interbreadcrumb[] = ['name' => $user->getCompleteName(), 'url' => 'user_information.php?user_id='.$user->getId()]; + +$toolName = get_lang('AssignHrmToUser'); + +$view = new Template($toolName); +$view->assign('header', $toolName); +$view->assign('content', $form->returnForm()); +$view->display_one_col_template(); diff --git a/main/admin/user_information.php b/main/admin/user_information.php index 295a8a5673..c777140db4 100755 --- a/main/admin/user_information.php +++ b/main/admin/user_information.php @@ -1,5 +1,7 @@ getHrm(); + +if ($hrmList) { + echo Display::page_subheader(get_lang('HrmList')); + echo '
'; + + /** @var UserRelUser $hrm */ + foreach ($hrmList as $hrm) { + $hrmInfo = api_get_user_info($hrm->getId()); + $userPicture = isset($hrmInfo["avatar_medium"]) ? $hrmInfo["avatar_medium"] : $hrmInfo["avatar"]; + + echo '
'; + echo '
'; + echo '
'; + echo Display::img($userPicture, $hrmInfo['complete_name'], ['class' => 'media-object'], false); + echo '
'; + echo '
'; + echo '

'.$hrmInfo['complete_name'].'

'; + echo $hrmInfo['username']; + echo '
'; + echo '
'; + echo '
'; + } + + echo '
'; +} + if (api_get_setting('allow_social_tool') === 'true') { echo Display::page_subheader(get_lang('SocialData')); echo $socialInformation; diff --git a/main/inc/ajax/user_manager.ajax.php b/main/inc/ajax/user_manager.ajax.php index 09283e167f..c5d21bb44b 100755 --- a/main/inc/ajax/user_manager.ajax.php +++ b/main/inc/ajax/user_manager.ajax.php @@ -1,5 +1,7 @@ where( + Criteria::expr()->orX( + Criteria::expr()->contains('username', $_REQUEST['q']), + Criteria::expr()->contains('firstname', $_REQUEST['q']), + Criteria::expr()->contains('lastname', $_REQUEST['q']) + ) + ) + ->andWhere( + Criteria::expr()->eq('status', DRH) + ); + + $users = UserManager::getRepository()->matching($criteria); + + if (!$users->count()) { + echo json_encode([]); + break; + } + + $items = []; + + /** @var User $user */ + foreach ($users as $user) { + $items[] = [ + 'id' => $user->getId(), + 'text' => $user->getCompleteNameWithUsername() + ]; + } + + header('Content-Type: application/json'); + echo json_encode(['items' => $items]); + break; default: echo ''; } diff --git a/src/Chamilo/UserBundle/Entity/User.php b/src/Chamilo/UserBundle/Entity/User.php index 43f9c0a91d..bed50ac327 100644 --- a/src/Chamilo/UserBundle/Entity/User.php +++ b/src/Chamilo/UserBundle/Entity/User.php @@ -9,6 +9,7 @@ use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\Event\LifecycleEventArgs; use Doctrine\ORM\Mapping as ORM; //use Sonata\UserBundle\Entity\BaseUser as BaseUser; +use Doctrine\ORM\Query\Expr\Join; use Sonata\UserBundle\Model\User as BaseUser; use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; use Symfony\Component\HttpFoundation\File\File; @@ -2443,4 +2444,32 @@ class User implements UserInterface //implements ParticipantInterface, ThemeUser { return $this->sessionAsGeneralCoach; } + + /** + * Get the HRM list from the user + * @return array + */ + public function getHrm() + { + $em = \Database::getManager(); + $qb = $em->createQueryBuilder(); + + $hrmList = $qb + ->select('uru') + ->from('ChamiloCoreBundle:UserRelUser', 'uru') + ->innerJoin('ChamiloCoreBundle:AccessUrlRelUser', 'auru', Join::WITH, 'auru.userId = uru.friendUserId') + ->where( + $qb->expr()->eq('auru.accessUrlId', api_get_current_access_url_id()) + ) + ->andWhere( + $qb->expr()->eq('uru.userId', $this->id) + ) + ->andWhere( + $qb->expr()->eq('uru.relationType', USER_RELATION_TYPE_RRHH) + ) + ->getQuery() + ->getResult(); + + return $hrmList; + } }