Преглед на файлове

Add system to require/accept user vinculation for HRM - refs BT#12955

Angel Fernando Quiroz Campos преди 7 години
родител
ревизия
c68767642f

+ 1 - 0
main/admin/index.php

@@ -109,6 +109,7 @@ if (api_is_platform_admin()) {
     }
     $items[] = array('url' => 'extra_fields.php?type=user', 'label' => get_lang('ManageUserFields'));
     $items[] = array('url'=>'usergroups.php', 'label' => get_lang('Classes'));
+    $items[] = ['url' => 'user_vinculation_requests.php', 'label' => get_lang('UserVinculationRequests')];
 } elseif (api_is_session_admin() && api_get_configuration_value('limit_session_admin_role')) {
     $items = array(
         array('url' => 'user_list.php', 'label' => get_lang('UserList')),

+ 109 - 0
main/admin/user_vinculation_requests.php

@@ -0,0 +1,109 @@
+<?php
+/* For licensing terms, see /license.txt */
+
+use Chamilo\CoreBundle\Entity\UserRelUser,
+    Chamilo\UserBundle\Entity\User;
+
+$cidReset = true;
+
+require_once __DIR__.'/../inc/global.inc.php';
+
+api_protect_admin_script();
+
+$action = isset($_GET['action']) ? $_GET['action'] : null;
+$hrmId = isset($_GET['hrm']) ? intval($_GET['hrm']) : 0;
+$assinedId = isset($_GET['u']) ? intval($_GET['u']) : 0;
+$hrm = $hrmId ? api_get_user_entity($hrmId) : null;
+
+$em = Database::getManager();
+
+if ($action === 'accept' && $hrm && $assinedId) {
+    /** @var UserRelUser $request */
+    $request = $em->getRepository('ChamiloCoreBundle:UserRelUser')
+        ->findOneBy([
+            'userId' => $assinedId,
+            'friendUserId' => $hrm->getId(),
+            'relationType' => USER_RELATION_TYPE_HRM_REQUEST
+        ]);
+
+    if ($request) {
+        $request->setRelationType(USER_RELATION_TYPE_RRHH);
+        $em->persist($request);
+        $em->flush();
+
+        Display::addFlash(
+            Display::return_message(get_lang('UserVinculationRequestAccepted'), 'success')
+        );
+    }
+
+    header('Location: '.api_get_self().'?hrm='.$hrm->getId());
+    exit;
+}
+
+function getData(User $hrm)
+{
+    $requests = UserManager::getUsersFollowedByUser(
+        $hrm->getId(),
+        null,
+        false,
+        false,
+        false,
+        null,
+        null,
+        null,
+        null,
+        null,
+        null,
+        HRM_REQUEST
+    );
+
+    $result = [];
+
+    $iconAccept = Display::return_icon('accept.png', get_lang('Accept'));
+    $urlAccept = api_get_self().'?action=accept&hrm='.$hrm->getId().'&u=';
+
+    foreach ($requests as $request) {
+        $result[] = [
+            api_get_person_name($request['firstname'], $request['lastname']),
+            Display::url(
+                $iconAccept,
+                $urlAccept.$request['user_id']
+            )
+        ];
+    }
+
+    return $result;
+}
+
+$form = new FormValidator('user_vinculation_requests', 'get');
+$form->addSelectAjax(
+    'hrm',
+    get_lang('DRH'),
+    $hrm ? [$hrm->getId() => $hrm->getCompleteName()] : [],
+    ['url' => api_get_path(WEB_AJAX_PATH).'user_manager.ajax.php?a=user_by_role']
+);
+$form->addButtonFilter(get_lang('Filter'));
+
+$content = $form->returnForm();
+
+if ($hrm) {
+    $requests = getData($hrm);
+
+    if ($requests) {
+        $content .= Display::table(
+            [get_lang('UserVinculationTo'), get_lang('Actions')],
+            $requests
+        );
+    } else {
+        $content .= Display::return_message(get_lang('NoResults'), 'warning');
+    }
+}
+
+$interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
+
+$toolName = get_lang('UserVinculationRequests');
+
+$view = new Template($toolName);
+$view->assign('header', $toolName);
+$view->assign('content', $content);
+$view->display_one_col_template();

+ 2 - 0
main/inc/lib/api.lib.php

@@ -49,6 +49,7 @@ define('SESSION_STUDENT', 15); //student subscribed in a session course
 define('COURSE_TUTOR', 16); // student is tutor of a course (NOT in session)
 define('STUDENT_BOSS', 17); // student is boss
 define('INVITEE', 20);
+define('HRM_REQUEST', 21); //HRM has request for vinculation with user
 
 // Table of status
 $_status_list[COURSEMANAGER] = 'teacher'; // 1
@@ -351,6 +352,7 @@ define('USER_RELATION_TYPE_ENEMY', 5); // should be deprecated is useless
 define('USER_RELATION_TYPE_DELETED', 6);
 define('USER_RELATION_TYPE_RRHH', 7);
 define('USER_RELATION_TYPE_BOSS', 8);
+define('USER_RELATION_TYPE_HRM_REQUEST', 9);
 
 // Gradebook link constants
 // Please do not change existing values, they are used in the database !

+ 37 - 0
main/inc/lib/usermanager.lib.php

@@ -4418,6 +4418,12 @@ class UserManager
             case STUDENT_BOSS:
                 $drhConditions = " AND friend_user_id = $userId AND relation_type = ".USER_RELATION_TYPE_BOSS;
                 break;
+            case HRM_REQUEST:
+                $drhConditions .= " AND
+                    friend_user_id = '$userId' AND
+                    relation_type = '".USER_RELATION_TYPE_HRM_REQUEST."'
+                ";
+                break;
         }
 
         $join = null;
@@ -4495,6 +4501,37 @@ class UserManager
         );
     }
 
+    /**
+     * Register request to assign users to HRM
+     * @param int $hrmId The HRM ID
+     * @param int $usersId The users ID
+     * @return int
+     */
+    public static function requestUsersToHRManager($hrmId, $usersId)
+    {
+        return self::subscribeUsersToUser(
+            $hrmId,
+            $usersId,
+            USER_RELATION_TYPE_HRM_REQUEST,
+            false,
+            false
+        );
+    }
+
+    /**
+     * Remove the requests for assign a user to a HRM
+     * @param \Chamilo\UserBundle\Entity\User $hrmId
+     */
+    public static function clearHrmRequestsForUser(User $hrmId)
+    {
+        Database::getManager()
+            ->createQuery('
+                DELETE FROM ChamiloCoreBundle:UserRelUser uru
+                WHERE uru.friendUserId = :hrm_id AND uru.relationType = :relation_type
+            ')
+            ->execute(['hrm_id' => $hrmId, 'relation_type' => USER_RELATION_TYPE_HRM_REQUEST]);
+    }
+
     /**
      * Add subscribed users to a user by relation type
      * @param int $userId The user id

+ 12 - 0
main/inc/lib/userportal.lib.php

@@ -975,6 +975,18 @@ class IndexManager
         $profile_content .= '<li class="profile-social"><a href="'.$editProfileUrl.'">'
             .Display::return_icon('edit-profile.png', get_lang('EditProfile'))
             .get_lang('EditProfile').'</a></li>';
+
+        if (api_get_configuration_value('show_link_request_hrm_user') && api_is_drh()) {
+            $label = get_lang('RequireVinculationWithUser');
+            $icon = Display::return_icon('new_group.png', $label);
+            $profile_content .= '<li>'
+                .Display::url(
+                    $icon.$label,
+                    api_get_path(WEB_CODE_PATH).'social/require_user_vinculation.php'
+                )
+                .'</li>';
+        }
+
         $profile_content .= '</ul>';
 
         $html = self::show_right_block(

+ 2 - 0
main/install/configuration.dist.php

@@ -564,3 +564,5 @@ $_configuration['score_grade_model'] = [
     ]
 ];
 */
+//Allow show link to request vinculation HRM-user
+//$_configuration['show_link_request_hrm_user'] = false;

+ 110 - 0
main/social/require_user_vinculation.php

@@ -0,0 +1,110 @@
+<?php
+/* For licensing terms, see /license.txt */
+
+$cidReset = true;
+
+require_once __DIR__.'/../inc/global.inc.php';
+
+$isAllowed = api_get_configuration_value('show_link_request_hrm_user') && api_is_drh();
+
+if (!$isAllowed) {
+    api_not_allowed(true);
+}
+
+$hrm = api_get_user_entity(api_get_user_id());
+
+$usersRequested = UserManager::getUsersFollowedByUser(
+    $hrm->getId(),
+    null,
+    null,
+    false,
+    false,
+    null,
+    null,
+    null,
+    null,
+    null,
+    null,
+    HRM_REQUEST
+);
+
+$requestOptions = [];
+
+foreach ($usersRequested as $userRequested) {
+    $userInfo = api_get_user_info($userRequested['user_id']);
+
+    if (!$userInfo) {
+        continue;
+    }
+
+    $requestOptions[$userInfo['user_id']] = $userInfo['complete_name'];
+}
+
+$form = new FormValidator('require_user_vinculation');
+$form->addUserAvatar('hrm', get_lang('DRH'), 'medium');
+$form->addSelectAjax(
+    'users',
+    get_lang('Users'),
+    $requestOptions,
+    ['multiple' => 'multiple', 'url' => api_get_path(WEB_AJAX_PATH).'user_manager.ajax.php?a=get_user_like']
+);
+$form->addButtonSave(get_lang('Save'));
+$form->setDefaults([
+    'hrm' => $hrm,
+    'users' => array_keys($requestOptions)
+]);
+
+if ($form->validate()) {
+    $values = $form->exportValues();
+    //Avoid self-subscribe as request
+    $usersId = array_filter($values['users'], function ($userId) use ($hrm) {
+        return (int) $userId != $hrm->getId();
+    });
+
+    UserManager::clearHrmRequestsForUser($hrm);
+    UserManager::requestUsersToHRManager($hrm->getId(), $usersId, false);
+
+    Display::addFlash(
+        Display::return_message(get_lang('RequestsVinculationAdded'), 'success')
+    );
+
+    header('Location: '.api_get_self());
+    exit;
+}
+
+$usersAssigned = UserManager::get_users_followed_by_drh($hrm->getId());
+
+$content = $form->returnForm();
+
+$content .= Display::page_subheader(get_lang('AssignedUsersListToHumanResourcesManager'));
+$content .= '<div class="row">';
+
+foreach ($usersAssigned as $userAssigned) {
+    $userAssigned = api_get_user_info($userAssigned['user_id']);
+    $userPicture = isset($userAssigned["avatar_medium"]) ? $userAssigned["avatar_medium"] : $userAssigned["avatar"];
+
+    $content .= '
+        <div class="col-sm-4 col-md-3">
+            <div class="media">
+                <div class="media-left">
+    ';
+    $content .= Display::img($userPicture, $userAssigned['complete_name'], ['class' => 'media-object'], false);
+    $content .= '
+                </div>
+                <div class="media-body">
+                    <h4 class="media-heading">'.$userAssigned['complete_name'].'</h4>
+                    '.$userAssigned['username'].'
+                </div>
+            </div>
+        </div>
+    ';
+}
+
+$content .= '</div>';
+
+$toolName = get_lang('RequireVinculationWithUser');
+
+$view = new Template($toolName);
+$view->assign('header', $toolName);
+$view->assign('content', $content);
+$view->display_one_col_template();

+ 1 - 1
src/Chamilo/UserBundle/Entity/User.php

@@ -2446,7 +2446,7 @@ class User implements UserInterface //implements ParticipantInterface, ThemeUser
     }
 
     /**
-     * Get the HRM list from the user
+     * Get the list of HRM who have assigned this user
      * @return array
      */
     public function getHrm()