/** * Get a single user, ready to be serialized and assigned to the JsonApi * response. * * @param JsonApiRequest $request * @param Document $document * @return \Flarum\Core\Users\User */ protected function data(JsonApiRequest $request, Document $document) { $id = $request->get('id'); if (!is_numeric($id)) { $id = $this->users->getIdForUsername($id); } return $this->users->findOrFail($id, $request->actor); }
/** * {@inheritdoc} */ protected function conditions(Search $search, array $matches, $negate) { if (!$search instanceof DiscussionSearch) { throw new LogicException('This gambit can only be applied on a DiscussionSearch'); } $username = trim($matches[1], '"'); $id = $this->users->getIdForUsername($username); $search->getQuery()->where('start_user_id', $negate ? '!=' : '=', $id); }
public static function addId($tag, UserRepository $users) { if ($id = $users->getIdForUsername(rawurlencode($tag->getAttribute('username')))) { $tag->setAttribute('id', $id); return true; } }