Candidate users
@param string $search
@return array
491547
public function find_users($search) {
        global $DB;
        // By default wherecondition retrieves all users except the deleted, not confirmed and guest.
        list($wherecondition, $params) = $this->search_sql($search, 'u');
        $params['enrolid'] = $this->enrolid;

        $fields      = 'SELECT ' . $this->required_fields_sql('u');
        $countfields = 'SELECT COUNT(1)';

        $sql = " FROM {user} u
                 JOIN {user_enrolments} ue ON (ue.userid = u.id AND ue.enrolid = :enrolid)
                WHERE $wherecondition";

        list($sort, $sortparams) = users_order_by_sql('u', $search, $this->accesscontext);
        $order = ' ORDER BY ' . $sort;

        if (!$this->is_validating()) {
            $potentialmemberscount = $DB->count_records_sql($countfields . $sql, $params);
            if ($potentialmemberscount > $this->maxusersperpage) {
                return $this->too_many_results($search, $potentialmemberscount);
            }
        }

        $availableusers = $DB->get_records_sql($fields . $sql . $order, array_merge($params, $sortparams));

        if (empty($availableusers)) {
            return array();
        }


        if ($search) {
            $groupname = get_string('enrolledusersmatching', 'enrol', $search);
        } else {
            $groupname = get_string('enrolledusers', 'enrol');
        }

        return array($groupname => $availableusers);
    }
464698
public function search($query) {
        $found = false;
        if (strpos(strtolower($this->name), $query) !== false) {
            $found = true;
        } else if (strpos(core_text::strtolower($this->visiblename), $query) !== false) {
                $found = true;
            }
        if ($found) {
            $result = new stdClass();
            $result->page     = $this;
            $result->settings = array();
            return array($this->name => $result);
        } else {
            return array();
        }
    }
97075
public function findDocuments(Search $search)
    {
        $results = $this->executeSearch($search);

        return new DocumentIterator(
            $results,
            $this->getManager(),
            $this->getScrollConfiguration($results, $search->getScroll())
        );
    }
534654
public function getSearchableRules(): array
    {
        return [
            'roles:[]' => function (Builder $query, array $roles) {
                return $query->whereHas('roles', function (Builder $query) use ($roles) {
                    return $query->whereIn(Role::column('name'), $roles);
                });
            },
        ];
    }
22221
public static function search_users($query, $capability = '', $limitfrom = 0, $limitnum = 100) {
        global $DB, $CFG, $PAGE, $USER;

        $params = self::validate_parameters(self::search_users_parameters(), array(
            'query' => $query,
            'capability' => $capability,
            'limitfrom' => $limitfrom,
            'limitnum' => $limitnum,
        ));
        $query = $params['query'];
        $cap = $params['capability'];
        $limitfrom = $params['limitfrom'];
        $limitnum = $params['limitnum'];

        $context = context_system::instance();
        self::validate_context($context);
        $output = $PAGE->get_renderer('tool_lp');

        list($filtercapsql, $filtercapparams) = api::filter_users_with_capability_on_user_context_sql($cap,
            $USER->id, SQL_PARAMS_NAMED);

        $extrasearchfields = array();
        if (!empty($CFG->showuseridentity) && has_capability('moodle/site:viewuseridentity', $context)) {
            $extrasearchfields = explode(',', $CFG->showuseridentity);
        }
        $fields = \user_picture::fields('u', $extrasearchfields);

        list($wheresql, $whereparams) = users_search_sql($query, 'u', true, $extrasearchfields);
        list($sortsql, $sortparams) = users_order_by_sql('u', $query, $context);

        $countsql = "SELECT COUNT('x') FROM {user} u WHERE $wheresql AND u.id $filtercapsql";
        $countparams = $whereparams + $filtercapparams;
        $sql = "SELECT $fields FROM {user} u WHERE $wheresql AND u.id $filtercapsql ORDER BY $sortsql";
        $params = $whereparams + $filtercapparams + $sortparams;

        $count = $DB->count_records_sql($countsql, $countparams);
        $result = $DB->get_recordset_sql($sql, $params, $limitfrom, $limitnum);

        $users = array();
        foreach ($result as $key => $user) {
            // Make sure all required fields are set.
            foreach (user_summary_exporter::define_properties() as $propertykey => $definition) {
                if (empty($user->$propertykey) || !in_array($propertykey, $extrasearchfields)) {
                    if ($propertykey != 'id') {
                        $user->$propertykey = '';
                    }
                }
            }
            $exporter = new user_summary_exporter($user);
            $newuser = $exporter->export($output);

            $users[$key] = $newuser;
        }
        $result->close();

        return array(
            'users' => $users,
            'count' => $count
        );
    }
578999
public function findAllForDataTables($search, $sortColumn, $sortDirection, $roles)
    {
        // select
        $qb = $this->getQueryBuilder()
            ->select('u.id, u.email, u.name, u.lastname, i.path actorImage');

        // join
        $qb->leftJoin('u.roles', 'r');
        $qb->leftJoin('u.image', 'i');
                
        $x=0;
        if(count($roles)>0){
            foreach ($roles as $role) {
                $x++;
                if($x == 1){
                    $qb->where('r.role = :role'.$x)
                        ->setParameter('role'.$x, $role);
                }else{
                    $qb->orWhere('r.role = :role'.$x)
                        ->setParameter('role'.$x, $role);
                }
                
            }
        }
                
        // search
        if (!empty($search)) {
            // where('u.email LIKE :search')
            $qb->where('u.email LIKE :search')
                ->orWhere('u.name LIKE :search')
                ->orWhere('u.lastname LIKE :search')
                
                ->setParameter('search', '%'.$search.'%');
        }

        // sort by column
        switch($sortColumn) {
            case 0:
                $qb->orderBy('u.id', $sortDirection);
                break;
            case 2:
                $qb->orderBy('u.email', $sortDirection);
                break;
            case 3:
                $qb->orderBy('u.name', $sortDirection);
                break;
            case 4:
                $qb->orderBy('u.lastname', $sortDirection);
                break;
        }

        return $qb->getQuery();
    }
643333
public function find( $search ) {

		if ( ! is_array( $search ) ) {
			wp_die( 'LogicException: $search should be a [meta_key => val] array' );
		}

		if ( $search === [
			null => null,
		] ) {
			return false; // Abort search
		}

		if ( $this->paramSearchMeta( $search ) !== false ) {
			return true;
		}

		return false;
	}
1196032
public function getField($search)
    {
        return isset($this->data[$search])
            ? $this->data[$search]
            : null;
    }
405469
protected function doSearch($search)
    {
        $found = [];
        $result = $this->driver->getFolder(
            $this->container,
            $this->folderPath,
            $this->request->getParameterAsBool('include_files', true),
            $this->request->getParameterAsBool('include_folders', true),
            $this->request->getParameterAsBool('full_tree', false)
        );

        foreach ($result as $rs) {
            if (stripos(basename($rs['path']), $search) !== false) {
                $found[] = $rs;
            }
        }

        return $found;
    }
453016
private function executeSearch(Search $search)
    {
        return $this->getManager()->search([$this->getType()], $search->toArray(), $search->getUriParams());
    }
965258
public function actionConfirm($search)
    {
        $user = User::findByEmailOrMobile($search);
        if ($user === null) {
            $this->stdout(Yii::t('user', 'User is not found') . "\n", Console::FG_RED);
        } else {
            if ($user->setEmailConfirm()) {
                $this->stdout(Yii::t('user', 'User has been confirmed') . "\n", Console::FG_GREEN);
            } else {
                $this->stdout(Yii::t('user', 'Error occurred while confirming user') . "\n", Console::FG_RED);
            }
        }
    }
374845
public static function get_users($query) {
        global $DB;
        $params = external_api::validate_parameters(self::get_users_parameters(), [
            'query' => $query
        ]);
        $query = $params['query'];

        // Validate context.
        $context = context_system::instance();
        self::validate_context($context);
        require_capability('tool/dataprivacy:managedatarequests', $context);

        $allusernames = get_all_user_name_fields(true);
        // Exclude admins and guest user.
        $excludedusers = array_keys(get_admins()) + [guest_user()->id];
        $sort = 'lastname ASC, firstname ASC';
        $fields = 'id,' . $allusernames;

        $extrafields = get_extra_user_fields($context);
        if (!empty($extrafields)) {
            $fields .= ',' . implode(',', $extrafields);
        }

        list($sql, $params) = users_search_sql($query, '', false, $extrafields, $excludedusers);
        $users = $DB->get_records_select('user', $sql, $params, $sort, $fields, 0, 30);

        $useroptions = [];
        foreach ($users as $user) {
            $useroption = (object)[
                'id' => $user->id,
                'fullname' => fullname($user)
            ];
            $useroption->extrafields = [];
            foreach ($extrafields as $extrafield) {
                $useroption->extrafields[] = (object)[
                    'name' => $extrafield,
                    'value' => $user->$extrafield
                ];
            }
            $useroptions[$user->id] = $useroption;
        }

        return $useroptions;
    }
470861
protected function _getSearchDataHeader(BaseSearch $search): array
    {
        $header = $search->getOptions();

        if ($search->hasIndices()) {
            $header['index'] = $search->getIndices();
        }

        if ($search->hasTypes()) {
            $header['types'] = $search->getTypes();
        }

        // Filter options accepted in the "header"
        return \array_intersect_key($header, \array_flip(self::$HEADER_OPTIONS));
    }
74975
public function findBySearchAndRoles($search, array $roles)
    {
        $dql = "
            SELECT DISTINCT w FROM Claroline\CoreBundle\Entity\Workspace\Workspace w
            JOIN w.roles r
            WHERE r.name in (:roles)
            AND (
                UPPER(w.name) LIKE :search
                OR UPPER(w.code) LIKE :search
            )
            ORDER BY w.name
        ";

        $query = $this->_em->createQuery($dql);
        $query->setParameter('roles', $roles);
        $upperSearch = strtoupper($search);
        $query->setParameter('search', "%{$upperSearch}%");

        return $query->getResult();
    }
534217
function search_users( $q,  $count = 10 )
	{
		$params = array();
		$params['q'] = $q;
		$params['count'] = $count;
		return $this->oauth->get( 'search/suggestions/users',  $params );
	}
1307797
function all_users($include_desc = false, $search = "*", $sorted = true){
        if (!$this->_bind){
            return (false);
        }
        
        //perform the search and grab all their details
        $filter = "(&(objectClass=user)(samaccounttype=". ADLDAP_NORMAL_ACCOUNT .")(objectCategory=person)(cn=".$search."))";
        $fields=array($this->_cn_identifier,"displayname");
        $sr=ldap_search($this->_conn,$this->_base_dn,$filter,$fields);
        $entries = $this->ldap_get_entries_raw($sr);

        $users_array = array();
        for ($i=0; $i<$entries["count"]; $i++){
            if ($include_desc && strlen($entries[$i]["displayname"][0])>0){
                $users_array[ $entries[$i][$this->_cn_identifier][0] ] = $entries[$i]["displayname"][0];
            } elseif ($include_desc){
                $users_array[ $entries[$i][$this->_cn_identifier][0] ] = $entries[$i][$this->_cn_identifier][0];
            } else {
                array_push($users_array, $entries[$i][$this->_cn_identifier][0]);
            }
        }
        if ($sorted){ asort($users_array); }
        return ($users_array);
    }
952013
public function findFirstUsersByName($search)
    {
        return $this->_em->createQueryBuilder()
            ->select(
                'u.id',
                "CONCAT(u.firstName, ' ', u.lastName, ' (', u.username, ')') AS name"
            )
            ->from('ClarolineCoreBundle:User', 'u')
            ->where('u.firstName LIKE :search')
            ->orWhere('u.lastName LIKE :search')
            ->orWhere('u.username LIKE :search')
            ->setMaxResults(5)
            ->setParameter(':search', "%{$search}%")
            ->getQuery()
            ->getArrayResult();
    }