Beispiel #1
0
    /**
     * Search for users based on query string.
     *
     * @see \pdyn\orm\SearchableObjectInterface
     * @param \pdyn\database\DbDriverInterface $DB An active database connection.
     * @param string $q A query string to search with.
     * @param int|null $opts An bitmask of options to affect the search results, or null.
     * @return array An array of users with full names that match the query string.
     */
    public static function search(\pdyn\database\DbDriverInterface &$DB, $q, $opts = null)
    {
        $filters = ['id != ?', '(namefull LIKE ? OR username LIKE ? OR nameshort LIKE ?)'];
        $q = '%' . $q . '%';
        $params = [static::GUESTID, $q, $q, $q];
        if (static::opts_contains($opts, static::INCLUDE_DELETED) === false) {
            $filters[] = 'deleted = ?';
            $params[] = 0;
        }
        $sql = 'SELECT id, username, nameshort, namefull, deleted
			      FROM {' . static::DB_TABLE . '}
			     WHERE ' . implode(' AND ', $filters) . '
			  ORDER BY id ASC';
        return $DB->get_records_sql($sql, $params);
    }