<commit_before><?php namespace Blindern\UKA\Billett;

use \Carbon\Carbon;
use \Henrist\LaravelApiQuery\ApiQueryInterface;

class Order extends \Eloquent implements ApiQueryInterface {
    /**
     * How long a incomplete reservation is valid
     */
    const EXPIRE_INCOMPLETE_RESERVATION = 600;

    /**
     * How long a reservation that is sent to payment is valid
     */
    const EXPIRE_LOCKED_RESERVATION = 1800;

    /**
     * Create reservation
     *
     * @param Eventgroup $eg
     * @param array(array(Ticketgroup, int ticket-count), ...)
     * @param bool by ticket office
     * @return Order
     */
    public static function createReservation(Eventgroup $eg, $is_admin = false)
    {
        $order = new static();

        $order->eventgroup()->associate($eg);
        $order->time = time();
        $order->ip = $_SERVER['REMOTE_ADDR'];
        $order->browser = $_SERVER['HTTP_USER_AGENT'];
        $order->is_admin = $is_admin;

        if ($is_admin) {
            $order->user_created = \Auth::check() ? \Auth::user()->username : null;
        }

        $order->save();
        $order->generateOrderTextId();

        return $order;
    }

    /**
     * Find order by text id or fail
     */
    public static function findByTextIdOrFail($text_id)
    {
        if (empty($text_id))
        {<commit_msg>Truncate user agent in case it overflows column size<commit_after><?php namespace Blindern\UKA\Billett;

use \Carbon\Carbon;
use \Henrist\LaravelApiQuery\ApiQueryInterface;

class Order extends \Eloquent implements ApiQueryInterface {
    /**
     * How long a incomplete reservation is valid
     */
    const EXPIRE_INCOMPLETE_RESERVATION = 600;

    /**
     * How long a reservation that is sent to payment is valid
     */
    const EXPIRE_LOCKED_RESERVATION = 1800;

    /**
     * Create reservation
     *
     * @param Eventgroup $eg
     * @param array(array(Ticketgroup, int ticket-count), ...)
     * @param bool by ticket office
     * @return Order
     */
    public static function createReservation(Eventgroup $eg, $is_admin = false)
    {
        $order = new static();

        $order->eventgroup()->associate($eg);
        $order->time = time();
        $order->ip = $_SERVER['REMOTE_ADDR'];
        $order->browser = substr($_SERVER['HTTP_USER_AGENT'], 0, 255); // truncate in case it overflows
        $order->is_admin = $is_admin;

        if ($is_admin) {
            $order->user_created = \Auth::check() ? \Auth::user()->username : null;
        }

        $order->save();
        $order->generateOrderTextId();

        return $order;
    }

    /**
     * Find order by text id or fail
     */
    public static function findByTextIdOrFail($text_id)
    {
        if (empty($text_id))
        {
{'fraction_non_alphanumeric': 0.125544267053701, 'fraction_numerical': 0.006531204644412192, 'mean_word_length': 2.3995067817509246, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6861834', 'n_tokens_mistral': 873, 'n_tokens_neox': 824, 'n_words': 205}