Skip to content
Snippets Groups Projects
Select Git revision
  • e766694bd98a843f52acc89fc9084eeeee282a89
  • main default protected
  • step-3263
  • feature/plugins-cli
  • feature/vite
  • step-2484-peerreview
  • biest/issue-5051
  • tests/simplify-jsonapi-tests
  • fix/typo-in-1a70031
  • feature/broadcasting
  • database-seeders-and-factories
  • feature/peer-review-2
  • feature-feedback-jsonapi
  • feature/peerreview
  • feature/balloon-plus
  • feature/stock-images-unsplash
  • tic-2588
  • 5.0
  • 5.2
  • biest/unlock-blocks
  • biest-1514
21 results

GlobalSearchUsers.php

Blame
  • Forked from Stud.IP / Stud.IP
    Source project has a limited visibility.
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    GlobalSearchUsers.php 4.92 KiB
    <?php
    /**
     * GlobalSearchModule for user
     *
     * @author      Thomas Hackl <thomas.hackl@uni-passau.de>
     * @license     http://www.gnu.org/licenses/gpl-2.0.html GPL version 2
     * @category    Stud.IP
     * @since       4.1
     */
    class GlobalSearchUsers extends GlobalSearchModule implements GlobalSearchFulltext
    {
    
        /**
         * Returns the displayname for this module
         *
         * @return string
         */
        public static function getName()
        {
            return _('Personen');
        }
    
        /**
         * Transforms the search request into an sql statement, that provides the id (same as getId) as type and
         * the object id, that is later passed to the filter.
         *
         * This function is required to make use of the mysql union parallelism
         *
         * @param string $search the input query string
         * @param array $filter an array with search limiting filter information (e.g. 'category', 'semester', etc.)
         * @return string SQL Query to discover elements for the search
         */
        public static function getSQL($search, $filter, $limit)
        {
            if (!$search) {
                return null;
            }
    
            // if you're no admin respect visibilty
            $visQuery = '';
            if (!$GLOBALS['perm']->have_perm('admin')) {
                $visQuery = get_vis_query('user', 'search') . " AND ";
            }
    
            $search = str_replace(' ', '% ', $search);
            $query = DBManager::get()->quote("%{$search}%");
    
            $sql = "SELECT SQL_CALC_FOUND_ROWS user.`user_id`, user.`Vorname`, user.`Nachname`, user.`username`, `user_info`.`title_front`, `user_info`.`title_rear`
                    FROM `auth_user_md5` AS user
                    JOIN `user_info` USING (`user_id`)
                    LEFT JOIN `user_visibility` USING (`user_id`)
                    WHERE {$visQuery}
                        (CONCAT_WS(', ', user.`Nachname`, user.`Vorname`) LIKE {$query}
                            OR CONCAT_WS(' ', user.`Nachname`, user.`Vorname`, user.`Nachname`) LIKE {$query}
                            OR `username` LIKE {$query}
                        )
                    ORDER BY user.`Nachname`, user.`Vorname`
                    LIMIT " . $limit;
            return $sql;
        }
    
        /**
         * Returns an array of information for the found element. Following informations (key: description) are necessary
         *
         * - name: The name of the object
         * - url: The url to send the user to when he clicks the link
         *
         * Additional informations are:
         *
         * - additional: Subtitle for the hit