<commit_before><?php

namespace Coyote\Repositories\Eloquent;

use Coyote\Repositories\Contracts\TopicRepositoryInterface;

class TopicRepository extends Repository implements TopicRepositoryInterface
{
    /**
     * @return \Coyote\Topic
     */
    public function model()
    {
        return 'Coyote\Topic';
    }

    public function paginate($userId, $sessionId, $order = 'topics.last_post_id', $direction = 'DESC', $perPage = 20)
    {
        $this->applyCriteria();

        $sql = $this->model
                    ->select([
                        'topics.*',
                        'forum_track.created_at AS forum_marked_at',
                        'topic_track.created_at AS topic_marked_at',
                        'first.created_at AS first_created_at',
                        'first.user_name AS first_user_name',
                        'last.created_at AS last_created_at',
                        'last.user_name AS last_user_name',
                        'author.id AS author_id',
                        'author.name AS author_name',
                        'author.is_active AS author_is_active',
                        'author.is_blocked AS author_is_blocked',
                        'poster.id AS poster_id',
                        'poster.name AS poster_name',
                        'poster.is_active AS poster_is_active',
                        'poster.is_blocked AS poster_is_blocked',
                        'poster.photo AS poster_photo',
                        'forums.path AS forum_path',
                        'forums.name AS forum_name',
                        'prev.name AS prev_forum_name'
                    ])
                    ->join('forums', 'forums.id', '=', 'topics.forum_id')
                    ->leftJoin('forums AS prev', 'prev.id', '=', 'prev_forum_id')
                    ->leftJoin('posts AS first', 'first.id', '=', 'topics.first_post_id')
                    ->leftJoin('posts AS last', 'last.id', '=', 'topics.last_post_id')
                    ->leftJoin('users AS author', 'author.id', '=', 'first.user_id')
                    ->leftJoin('users AS poster', 'poster.id', '=', 'last.user_id')
                    ->leftJoin('forum_track', function ($join) use ($userId, $sessionId) {
                        $join->on('forum_track.forum_id', '=', 'forums.id');

                        if ($userId) {
                            $join->on('forum_track.user_id', '=', \DB::raw($userId));
                        } else {
                            $join->on('forum_track.session_id', '=', \DB::raw("'" . $sessionId . "'"));
                        }
                    })
                    ->leftJoin('topic_track', function ($join) use ($userId, $sessionId) {
                        $join->on('topic_track.topic_id', '=', 'topics.id');

                        if ($userId) {
                            $join->on('topic_track.user_id', '=', \DB::raw($userId));
                        } else {
                            $join->on('topic_track.session_id', '=', \DB::raw("'" . $sessionId . "'"));
                        }
                    })
                    ->sortable($order, $direction, ['id', 'last', 'replies', 'views', 'score'], ['last' => 'topics.last_post_id']);

        $result = $sql->paginate($perPage);

        foreach ($result as $topic) {
            $lastMarked = $topic->forum_marked_at ?: new \DateTime('last month');
            /*
             * Jezeli data napisania ostatniego posta jest pozniejsza
             * niz data odznaczenia forum jako przeczytanego...
             * ORAZ
             * data napisania ostatniego postu jest pozniejsza niz data
             * ostatniego "czytania" tematu...
             * ODZNACZ JAKO NOWY
             */
            $topic->unread = $topic->last_created_at > $lastMarked && $topic->last_created_at > $topic->topic_marked_at;
        }

        return $result;
    }
}
<commit_msg>poprawiony bug: formatowanie obiektu DateTime to stringa<commit_after><?php

namespace Coyote\Repositories\Eloquent;

use Coyote\Repositories\Contracts\TopicRepositoryInterface;

class TopicRepository extends Repository implements TopicRepositoryInterface
{
    /**
     * @return \Coyote\Topic
     */
    public function model()
    {
        return 'Coyote\Topic';
    }

    public function paginate($userId, $sessionId, $order = 'topics.last_post_id', $direction = 'DESC', $perPage = 20)
    {
        $this->applyCriteria();

        $sql = $this->model
                    ->select([
                        'topics.*',
                        'forum_track.created_at AS forum_marked_at',
                        'topic_track.created_at AS topic_marked_at',
                        'first.created_at AS first_created_at',
                        'first.user_name AS first_user_name',
                        'last.created_at AS last_created_at',
                        'last.user_name AS last_user_name',
                        'author.id AS author_id',
                        'author.name AS author_name',
                        'author.is_active AS author_is_active',
                        'author.is_blocked AS author_is_blocked',
                        'poster.id AS poster_id',
                        'poster.name AS poster_name',
                        'poster.is_active AS poster_is_active',
                        'poster.is_blocked AS poster_is_blocked',
                        'poster.photo AS poster_photo',
                        'forums.path AS forum_path',
                        'forums.name AS forum_name',
                        'prev.name AS prev_forum_name'
                    ])
                    ->join('forums', 'forums.id', '=', 'topics.forum_id')
                    ->leftJoin('forums AS prev', 'prev.id', '=', 'prev_forum_id')
                    ->leftJoin('posts AS first', 'first.id', '=', 'topics.first_post_id')
                    ->leftJoin('posts AS last', 'last.id', '=', 'topics.last_post_id')
                    ->leftJoin('users AS author', 'author.id', '=', 'first.user_id')
                    ->leftJoin('users AS poster', 'poster.id', '=', 'last.user_id')
                    ->leftJoin('forum_track', function ($join) use ($userId, $sessionId) {
                        $join->on('forum_track.forum_id', '=', 'forums.id');

                        if ($userId) {
                            $join->on('forum_track.user_id', '=', \DB::raw($userId));
                        } else {
                            $join->on('forum_track.session_id', '=', \DB::raw("'" . $sessionId . "'"));
                        }
                    })
                    ->leftJoin('topic_track', function ($join) use ($userId, $sessionId) {
                        $join->on('topic_track.topic_id', '=', 'topics.id');

                        if ($userId) {
                            $join->on('topic_track.user_id', '=', \DB::raw($userId));
                        } else {
                            $join->on('topic_track.session_id', '=', \DB::raw("'" . $sessionId . "'"));
                        }
                    })
                    ->sortable($order, $direction, ['id', 'last', 'replies', 'views', 'score'], ['last' => 'topics.last_post_id']);

        $result = $sql->paginate($perPage);

        foreach ($result as $topic) {
            $lastMarked = $topic->forum_marked_at ?: (new \DateTime('last month'))->format('Y-m-d H:i:s');
            /*
             * Jezeli data napisania ostatniego posta jest pozniejsza
             * niz data odznaczenia forum jako przeczytanego...
             * ORAZ
             * data napisania ostatniego postu jest pozniejsza niz data
             * ostatniego "czytania" tematu...
             * ODZNACZ JAKO NOWY
             */
            $topic->unread = $topic->last_created_at > $lastMarked && $topic->last_created_at > $topic->topic_marked_at;
        }

        return $result;
    }
}

{'fraction_non_alphanumeric': 0.13553989428643343, 'fraction_numerical': 0.0005033979360684622, 'mean_word_length': 1.4657151721998138, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 58, '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': '2268375', 'n_tokens_mistral': 2310, 'n_tokens_neox': 2201, 'n_words': 411}