Add page to assign mutiples HRM to one user - refs BT#12955

pull/2487/head
Angel Fernando Quiroz Campos 7 years ago
parent 137527fab9
commit 26fb108206
  1. 97
      main/admin/add_drh_to_user.php
  2. 35
      main/admin/user_information.php
  3. 38
      main/inc/ajax/user_manager.ajax.php
  4. 29
      src/Chamilo/UserBundle/Entity/User.php

@ -0,0 +1,97 @@
<?php
/* For licensing terms, see /license.txt */
use Chamilo\UserBundle\Entity\User,
Chamilo\CoreBundle\Entity\UserRelUser;
$cidReset = true;
require_once __DIR__.'/../inc/global.inc.php';
api_protect_admin_script();
if (!isset($_REQUEST['u'])) {
api_not_allowed(true);
}
$em = Database::getManager();
$relationsRepo = $em->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();

@ -1,5 +1,7 @@
<?php
/* For licensing terms, see /license.txt */
use Chamilo\UserBundle\Entity\User,
Chamilo\CoreBundle\Entity\UserRelUser;
/**
* Script showing information about a user (name, e-mail, courses and sessions)
@ -22,6 +24,8 @@ if (empty($user)) {
api_not_allowed(true);
}
/** @var User $userEntity */
$userEntity = api_get_user_entity($user['user_id']);
$myUserId = api_get_user_id();
if (!api_is_student_boss()) {
@ -93,6 +97,10 @@ if (api_is_platform_admin()) {
),
api_get_path(WEB_PATH).'main/social/vcard_export.php?userId='.$userId
);
$actions[] = Display::url(
Display::return_icon('new_group.png', get_lang('AddHrmToUser'), [], ICON_SIZE_MEDIUM),
api_get_path(WEB_PATH).'main/admin/add_drh_to_user.php?u='.$userId
);
}
$studentBossList = UserManager::getStudentBossList($userId);
@ -578,6 +586,33 @@ if ($studentBossList) {
echo $studentBossListToString;
}
$hrmList = $userEntity->getHrm();
if ($hrmList) {
echo Display::page_subheader(get_lang('HrmList'));
echo '<div class="row">';
/** @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 '<div class="col-sm-3">';
echo '<div class="media">';
echo '<div class="media-left">';
echo Display::img($userPicture, $hrmInfo['complete_name'], ['class' => 'media-object'], false);
echo '</div>';
echo '<div class="media-body">';
echo '<h4 class="media-heading">'.$hrmInfo['complete_name'].'</h4>';
echo $hrmInfo['username'];
echo '</div>';
echo '</div>';
echo '</div>';
}
echo '</div>';
}
if (api_get_setting('allow_social_tool') === 'true') {
echo Display::page_subheader(get_lang('SocialData'));
echo $socialInformation;

@ -1,5 +1,7 @@
<?php
/* For licensing terms, see /license.txt */
use Doctrine\Common\Collections\Criteria,
Chamilo\UserBundle\Entity\User;
/**
* Responses to AJAX calls
@ -179,6 +181,42 @@ switch ($action) {
echo '-1';
}
break;
case 'user_by_role':
api_block_anonymous_users(false);
$criteria = new Criteria();
$criteria
->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 '';
}

@ -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;
}
}

Loading…
Cancel
Save