Searches users by username, first or last name.

@EXT\Route("/{search}", name="questions_share_users")
@EXT\Method("GET")

@param string $search

@return JsonResponse
511763
public function searchUsers($search)
    {
        $users = $this->userRepository->findByName($search);

        return new JsonResponse(array_map(function (User $user) {
            return $this->userSerializer->serialize($user);
        }, $users));
    }
1036376
public static function after($subject, $search)
    {
        if ($search == '') {
            return $subject;
        }

        $pos = strpos($subject, $search);

        if ($pos === false) {
            return $subject;
        }

        return substr($subject, $pos + strlen($search));
    }
960195
public function searchBarAction(Request $request)
    {
        $this->denyAccessIfProfilerDisabled();

        if (null !== $this->cspHandler) {
            $this->cspHandler->disableCsp();
        }

        if (!$request->hasSession()) {
            $ip =
            $method =
            $statusCode =
            $url =
            $start =
            $end =
            $limit =
            $token = null;
        } else {
            $session = $request->getSession();

            $ip = $request->query->get('ip', $session->get('_profiler_search_ip'));
            $method = $request->query->get('method', $session->get('_profiler_search_method'));
            $statusCode = $request->query->get('status_code', $session->get('_profiler_search_status_code'));
            $url = $request->query->get('url', $session->get('_profiler_search_url'));
            $start = $request->query->get('start', $session->get('_profiler_search_start'));
            $end = $request->query->get('end', $session->get('_profiler_search_end'));
            $limit = $request->query->get('limit', $session->get('_profiler_search_limit'));
            $token = $request->query->get('token', $session->get('_profiler_search_token'));
        }

        return new Response(
            $this->twig->render('@WebProfiler/Profiler/search.html.twig', [
                'token' => $token,
                'ip' => $ip,
                'method' => $method,
                'status_code' => $statusCode,
                'url' => $url,
                'start' => $start,
                'end' => $end,
                'limit' => $limit,
                'request' => $request,
            ]),
            200,
            ['Content-Type' => 'text/html']
        );
    }
1199210
public function search($params)
    {
        $query = static::find();
        /* @var $query BaseUserQuery */
        $userClass = $this->userClass;
        $query = $query->from("{$userClass::tableName()} {$this->userAlias}");
        $noInitUser = $userClass::buildNoInitModel();
        /* @var $noInitUser User */
        $profileClass = $noInitUser->profileClass;
        if (!empty($profileClass)) {
            $query = $query->joinWith(["profile {$this->profileAlias}"]);
        }
        $dataProvider = new ActiveDataProvider([
            'query' => $query,
            'pagination' => [
                'pageParam' => 'user-page',
                'defaultPageSize' => 20,
                'pageSizeParam' => 'user-per-page',
            ],
            'sort' => [
                'sortParam' => 'user-sort',
                'attributes' => [
                    'id',
                    'nickname',
                    'name' => [
                        'asc' => [$this->profileAlias . '.first_name' => SORT_ASC, $this->profileAlias . '.last_name' => SORT_ASC],
                        'desc' => [$this->profileAlias . '.first_name' => SORT_DESC, $this->profileAlias . '.last_name' => SORT_DESC],
                        'default' => SORT_DESC,
                        'label' => Yii::t('user', 'Name'),
                    ],
                    'gender' => [
                        'asc' => [$this->profileAlias . '.gender' => SORT_ASC],
                        'desc' => [$this->profileAlias . '.gender' => SORT_DESC],
                        'default' => SORT_ASC,
                        'label' => Yii::t('user', 'Gender'),
                    ],
                    'createdAt' => [
                        'asc' => [$this->userAlias . '.created_at' => SORT_ASC],
                        'desc' => [$this->userAlias . '.created_at' => SORT_DESC],
                        'default' => SORT_ASC,
                        'label' => Yii::t('user', 'Creation Time'),
                    ],
                    'updatedAt' => [
                        'asc' => [$this->userAlias . '.updated_at' => SORT_ASC],
                        'desc' => [$this->userAlias . '.updated_at' => SORT_DESC],
                        'default' => SORT_ASC,
                        'label' => Yii::t('user', 'Last Updated Time'),
                    ],
                ],
            ],
        ]);

        if (!($this->load($params) && $this->validate())) {
            return $dataProvider;
        }

        $query = $query->andFilterWhere([
            'LIKE', $this->userAlias . '.id', $this->id,
        ])->andFilterWhere([
            'LIKE', $this->profileAlias . '.nickname', $this->nickname,
        ])->andFilterWhere([
            '>=', $this->userAlias . '.created_at', $this->createdFromInUtc,
        ])->andFilterWhere([
            '<=', $this->userAlias . '.created_at', $this->createdToInUtc,
        ])->andFilterWhere([
            'LIKE', $this->profileAlias . '.first_name', $this->first_name,
        ])->andFilterWhere([
            'LIKE', $this->profileAlias . '.last_name', $this->last_name,
        ])->andFilterWhere([
            $this->profileAlias . '.gender' => $this->gf,
        ]);
        $dataProvider->query = $query;
        return $dataProvider;
    }
105512
public function actionJsentity($search = NULL,$id = NULL)
  {
    header('Content-type: application/json');
    $clean['more'] = false;

    $query = new Query;
    if(!is_Null($search))
    {
      $mainQuery = $query->select('id, name AS text')
        ->from('{{%entity}}')
        ->where('UPPER(name) LIKE "%'.strtoupper($search).'%"');

      $command = $mainQuery->createCommand();
      $rows = $command->queryAll();
      $clean['results'] = array_values($rows);
    }
    else
    {     
      if(!is_null($id))
      {
        $clean['results'] = ['id'=> $id,'text' => Entity::findOne($id)->name];
      }else
      {
        $clean['results'] = ['id'=> 0,'text' => 'None found'];
      }
    }
    echo Json::encode($clean);
    exit();
  }
1282318
public function findByNameAndGroup(
        $search,
        Group $group,
        $executeQuery = true,
        $orderedBy = 'id',
        $order = 'ASC'
    )
    {
        $dql = "
            SELECT DISTINCT u FROM Claroline\CoreBundle\Entity\User u
            JOIN u.groups g
            WHERE g.id = :groupId
            AND (UPPER(u.username) LIKE :search
            OR UPPER(u.lastName) LIKE :search
            OR UPPER(u.firstName) LIKE :search)
            AND u.isEnabled = true
            ORDER BY u.{$orderedBy} {$order}
        ";
        $upperSearch = strtoupper($search);
        $query = $this->_em->createQuery($dql);
        $query->setParameter('search', "%{$upperSearch}%");
        $query->setParameter('groupId', $group->getId());

        return $executeQuery ? $query->getResult() : $query;
    }
276026
public function searchUsersAction()
    {
        if (!$this->getRequest()->isXmlHttpRequest()) {
            throw new \RuntimeException('This action must be called via ajax request');
        }
        
        $model = new JsonModel();
        $query = $this->params()->fromPost('query', false);
        if (!$query) {
            $query = $this->params()->fromQuery('q', false);
        }
        if (false === $query) {
            $result = array();
        } else {
            $repositories = $this->repositories;
            $repository   = $repositories->get('Auth/User');
            
            $users = $repository->findByQuery($query);
        
            $userFilter = $this->filterManager->get('Auth/Entity/UserToSearchResult');
            $filterFunc = function ($user) use ($userFilter) {
                return $userFilter->filter($user);
            };
            $result     = array_values(array_map($filterFunc, $users->toArray()));
        }
        
        //$model->setVariable('users', $result);
        $model->setVariables($result);
        return $model;
    }
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);
    }
1122090
public function get($request, $match)
    {
        $userId = $match['userId'];
//         $user = Pluf_Shortcuts_GetObjectOr404('User', $userId);
//         try {
//             $profile = $user->getProfile();
//         } catch (Pluf_Exception_DoesNotExist $ex) {
//             $profile = new $profile_model();
//             $profile->user = $user;
//             $profile->create();
//         }
//         return new Pluf_HTTP_Response_Json($profile);
        $profileDoc = User_Views_CProfile::get_profile_document($userId);
        $docMap = User_Views_CProfile::getDocumentMap($profileDoc);
        $docMap['user'] = $userId;
        return new Pluf_HTTP_Response_Json($docMap);
    }
413409
public function actionAdmin($search) {
    $user = User::findIdentityByUsernameOrEmail($search);
    if ($user) {
      $rbac = new Rbac();
      $rbac->setAdminRole($user);
      $this->stdout(Yii::t('users', 'Admin rights granted') . "\n", Console::FG_GREEN);
    } else {
      $this->stdout(Yii::t('users', 'User is not found') . "\n", Console::FG_RED);
    }
  }
1083653
public function getData($search = false) {
        if ($this->option && method_exists($this->form, $this->option)) {
            return $this->form->{$this->option}(...[$search]);
        }

        return [];
    }
375446
public function byUsernameAction(Request $request)
   {
       $term = $request->get('username');
       $users = $this->get('asf_user.user.manager')->getRepository()->findByUsernameContains($term);
       $search = array();
       	
       foreach($users as $user) {
           $search[] = array(
               'id' => $user->getId(),
               'username' => $user->getUsername(),
               'email' => $user->getEmail()
           );
       }
       
       $response = new Response();
       $response->setContent(json_encode(array(
           'total_count' => count($search),
           'items' => $search
       )));
       
       return $response;
   }
23432
public function searchAction(Request $request, $string)
    {
        $ret = [];

        foreach ($this->getFinderRegistry()->all() as $searcher) {
            $local = $searcher->find($string, false, 16);
            if ($local) {
                foreach ($local as $result) {
                    $ret[] = [
                        'id'          => $result->getId(),
                        'type'        => $result->getType(),
                        'title'       => check_plain($result->getTitle()),
                        'group'       => check_plain($result->getGroup()),
                        'description' => check_plain($result->getDescription()),
                    ];
                }
            }
        }

        return new JsonResponse($ret);
    }
197728
public function getUsers($opts = [])
    {
        $query = '';
        
        if(isset($opts['search'])) $query .= '?search='.$opts['search'];
        
    	$endpoint = '/users'.$query;        
    	return $this->doRequest('GET', $endpoint);
    }
1066243
static protected function get($search, $protocol = 'https') {
		$vicopoUrl = $protocol . '://vicopo.selfbuild.fr/search/' . urlencode($search);
		$json = @json_decode(file_get_contents($vicopoUrl));
		if (!is_object($json) || !isset($json->cities)) {
			throw new Exception("No valid answear found", 1);
		}
		return $json->cities;
	}
1212851
public function search(array $search)
        {
            $results    = array();
            $cart       = $this->getContent();
            $rows       = $cart->_fields;
            foreach($rows as $rowId) {
                $item  = $cart->$rowId;
                $found = $item->search($search);

                if(true === $found) {
                    $results[] = $item;
                }
            }

            return (empty($results)) ? false : $results;
        }
985209
public function searchAction(Request $request)
    {
        $this->denyAccessIfProfilerDisabled();

        $ip = preg_replace('/[^:\d\.]/', '', $request->query->get('ip'));
        $method = $request->query->get('method');
        $statusCode = $request->query->get('status_code');
        $url = $request->query->get('url');
        $start = $request->query->get('start', null);
        $end = $request->query->get('end', null);
        $limit = $request->query->get('limit');
        $token = $request->query->get('token');

        if ($request->hasSession()) {
            $session = $request->getSession();

            $session->set('_profiler_search_ip', $ip);
            $session->set('_profiler_search_method', $method);
            $session->set('_profiler_search_status_code', $statusCode);
            $session->set('_profiler_search_url', $url);
            $session->set('_profiler_search_start', $start);
            $session->set('_profiler_search_end', $end);
            $session->set('_profiler_search_limit', $limit);
            $session->set('_profiler_search_token', $token);
        }

        if (!empty($token)) {
            return new RedirectResponse($this->generator->generate('_profiler', ['token' => $token]), 302, ['Content-Type' => 'text/html']);
        }

        $tokens = $this->profiler->find($ip, $url, $limit, $method, $start, $end, $statusCode);

        return new RedirectResponse($this->generator->generate('_profiler_search_results', [
            'token' => $tokens ? $tokens[0]['token'] : 'empty',
            'ip' => $ip,
            'method' => $method,
            'status_code' => $statusCode,
            'url' => $url,
            'start' => $start,
            'end' => $end,
            'limit' => $limit,
        ]), 302, ['Content-Type' => 'text/html']);
    }