Returns a person by $mode (email or username)

@param string $mode 'email' or 'username'
@param string $value An email adress or an username
@return mixed
@throws \Exception
961147
protected function getPersonBy($mode, $value)
    {
        $dbHandle = $this->getDatabase()->getDatabaseConnection();

        switch ($mode) {
            case 'email':
                $query = '
                SELECT
                    person.`id`,
                    person.`name`,
                    person.`username`,
                    email.`email`
                  FROM ' . Database::TABLE_EMAIL . ' email
                  INNER JOIN ' . Database::TABLE_PERSON . ' person ON (
                    email.`person` = person.`id`
                  )
                  WHERE email.`email` = :value';
                break;
            case 'username':
                $query = 'SELECT `id`, `name`, `username`
                  FROM ' . Database::TABLE_PERSON . '
                  WHERE `username` = :value';
                break;
            case 'name':
                $query = 'SELECT `id`, `name`, `username`
                  FROM ' . Database::TABLE_PERSON . '
                  WHERE `name` = :value';
                break;
            default:
                throw new \Exception('Wrong mode selected!', 1363897547);
        }

        $statement = $dbHandle->prepare($query);

        $statement->bindParam(':value', $value, \PDO::PARAM_STR);
        $executeResult = $statement->execute();

        $statement = $this->getDatabase()->checkQueryError($statement, $executeResult);
        return $statement->fetch(\PDO::FETCH_ASSOC);
    }
949053
public static function checkEmailAddress($value) {
        $value = filter_var(trim($value),FILTER_SANITIZE_EMAIL);
        
        //validate the email address format
        if(!empty($value) && filter_var($value, FILTER_VALIDATE_EMAIL) === false){            
            throw new HpsInvalidRequestException(
                HpsExceptionCodes::INVALID_EMAIL_ADDRESS, 'Invalid email address'
            );
        }

        //validate length of input data and throw exception
        if (!empty(self::$_inputFldMaxLength['Email']) && strlen($value) > self::$_inputFldMaxLength['Email']) {            
            $errorMessage = "The value for Email can be no more than " . self::$_inputFldMaxLength['Email'] . ' characters, Please try again after making corrections';
            throw new HpsInvalidRequestException(
                HpsExceptionCodes::INVALID_INPUT_LENGTH, $errorMessage
            );
        }
        return $value;
    }
454720
protected function getIdFromValue(string $value)
    {
        try {
            if (null !== $item = $this->getIriConverter()->getItemFromIri($value, ['fetch_data' => false])) {
                return $this->getPropertyAccessor()->getValue($item, 'id');
            }
        } catch (InvalidArgumentException $e) {
            // Do nothing, return the raw value
        }

        return $value;
    }
1043476
protected function loadSelectedTagValueFromPost($value)
    {
        $em = \Database::get()->getEntityManager();
        $r = $em->getRepository('\Concrete\Core\Entity\Attribute\Value\Value\SelectValueOption');
        $type = $this->attributeKey->getAttributeKeySettings();

        if (!is_array($value)) {
            $values = explode(',', $value);
        } else {
            $values = $value;
        }
        
        $response = [];
        foreach ($values as $value) {
            $value = trim($value);
            $o = new \stdClass();
            if (strpos($value, 'SelectAttributeOption:') === 0) {
                $optionID = substr($value, 22);
                $option = $r->findOneBy(['list' => $type->getOptionList(), 'avSelectOptionID' => $optionID]);
                if (is_object($option)) {
                    $o->id = $value;
                    $o->text = $option->getSelectAttributeOptionValue();
                }
            } else {
                $o->id = $value;
                $o->text = $value;
            }

            $response[] = $o;
        }

        return $response;
    }
312213
public static function email($name, $value = null, array $options = [])
    {
        self::exclure($options);

        return self::input('email', $name, $value, $options);
    }
1172756
public static function get($value, AbstractModule $mod = null){
	    return self::getInstance()->getI($value, $mod);
	}
720896
public function html($value, array $options, $mode) {
        if ($mode === self::TO && $options['encode']) {
            return htmlentities($value, $options['flags'], $options['encoding']);
        }

        if ($mode === self::FROM && $options['decode']) {
            return html_entity_decode($value, $options['flags'], $options['encoding']);
        }

        return $value;
    }
525580
public function prepareExportValue($data, $mode, $entry_id = null)
    {
        $modes = (object)$this->getExportModes();

        // Make sure we have an array to work with:
        if (isset($data['author_id']) && is_array($data['author_id']) === false) {
            $data['author_id'] = array(
                $data['author_id']
            );
        }

        // Return the author IDs:
        if ($mode === $modes->listAuthor || $mode === $modes->getPostdata) {
            return isset($data['author_id'])
                ? $data['author_id']
                : array();
        }

        // All other modes require full data:
        $authors = isset($data['author_id'])
            ? AuthorManager::fetchByID($data['author_id'])
            : array();
        $items = array();

        foreach ($authors as $author) {
            if (is_null($author)) {
                continue;
            }

            if ($mode === $modes->listAuthorObject) {
                $items[] = $author;
            } elseif ($mode === $modes->listValue) {
                $items[] = $author->getFullName();
            } elseif ($mode === $modes->listAuthorToValue) {
                $items[$data['author_id']] = $author->getFullName();
            }
        }

        return $items;
    }
947605
public function oneByStringOrFail(string $field, string $value): Model
    {
        return $this->oneByOrFail($field, $value);
    }
675215
function parse(string $value, \CharlotteDunois\Livia\Commands\Context $context, ?\CharlotteDunois\Livia\Arguments\Argument $arg = null) {
        $prg = \preg_match('/(?:<@!?)?(\d{15,})>?/', $value, $matches);
        if($prg === 1) {
            return $this->client->users->get($matches[1]);
        }
        
        $search = \mb_strtolower($value);
        
        $inexactUsers = $this->client->users->filter(function ($user) use ($search) {
            return (\mb_stripos($user->tag, $search) !== false);
        });
        $inexactLength = $inexactUsers->count();
        
        if($inexactLength === 0) {
             return null;
        }
        if($inexactLength === 1) {
            return $inexactUsers->first();
        }
        
        $exactUsers = $this->client->users->filter(function ($user) use ($search) {
            return (\mb_strtolower($user->tag) === $search);
        });
        $exactLength = $exactUsers->count();
        
        if($exactLength === 1) {
            return $exactUsers->first();
        }
        
        return null;
    }
871467
public function setValue($value)
	{
		$failure = true;
		switch($this->opration)
		{
			case '==':
				if($value==$this->condition)
					$failure = false;
				break;
			case '>':
				if($value>$this->condition)
					$failure = false;
				break;
			case '>=':
				if($value>=$this->condition)
					$faulure = false;
				break;
			case '<':
				if($value<$this->condition)
					$failure = false;
				break;
			case '<=':
				if($value<=$this->condition)
					$failure = false;
				break;
			case '*':
				if(strpos($value, $this->condition)!==false)
					$failure = false;
				break;
			case '^':
				if(strpos($value, $this->condition)===0)
					$failure = false;
				break;
			case '$':
				if(strrpos($value, $this->condition)==strlen($value)-strlen($this->condition))
					$failure = false;
				break;
			default:
				break;
		}
		if($failure)
			throw $this->getContext()->getModel('ValidationException', 'Form', array(
				array(
					'' => 'condition failed'
				)
			));
		return $value;
	}
319739
protected function query($value)
    {
        $query = $this->getEntityManager()->createQueryBuilder();
        $query->select(sprintf('entity.%s', $this->getField()))
                ->from($this->getEntity(), 'entity')
                ->where(sprintf('entity.%s = :field', $this->getField()))
                ->setParameter(':field', $value);

        foreach ($this->getExclude() as $exclude => $value) {
            $query->andWhere(sprintf('entity.%s != :%s', $exclude, $exclude))
                    ->setParameter($exclude, $value);
        }

        foreach ($this->getInclude() as $include => $value) {
            $query->andWhere(sprintf('entity.%s = :%s', $include, $include))
                    ->setParameter($include, $value);
        }

        return $query->getQuery()->execute();
    }
1075679
public function getUserValue($value)
    {
        if (! is_array($value)) {
            if ('' == $value) {
                $value = [];
            } else {
                $value = explode($this->getSeparator(), $value);
            }
        }

        return $value;
    }
942828
private function getValue($value)
    {
        if (!is_string($value)) {
            return $value;
        }

        if ($value[0] != '%' || $value[strlen($value) - 1] != '%')  {
            return $value;
        }

        $parameter = trim($value, '%');
        if ($this->container->hasParameter($parameter)) {
            return $this->container->getParameter($parameter);
        }

        return $value;
    }
454263
public function with($value)
    {
        $withs = explode(',', $value);
        $model = $this->builder->getModel();
        $withs = collect($withs)->filter(function ($with) use($model) {
            if (str_contains($with, '.')) return ($model->{explode('.', $with)[0]}() instanceof Relation);
            return ($model->{$with}() instanceof Relation);
        })->toArray();
        return $this->builder->when(count($withs), function (Builder $query) use($withs) {
            $query->with($withs);
        });
    }
394111
public function getGenderByValue($value)
    {

        // query whether or not, the requested gender ID is available
        if (isset($this->availableGenders[$value])) {
            return (integer) $this->availableGenders[$value];
        }

        // throw an exception, if not
        throw new \Exception(
            $this->appendExceptionSuffix(
                sprintf('Found invalid gender %s', $value)
            )
        );
    }
1352943
public function serialize($value) {
        if ($value instanceof SerializablePersonalDataValue) {
            return $this->serializePersonalDataValue($value);
        } elseif ($value instanceof SerializableValue) {
            return $this->serializeValue($value);
        }
        return $value;
    }