<commit_before><?php

namespace Coyote\Repositories\Eloquent;

use Coyote\Repositories\Contracts\PmRepositoryInterface;
use Coyote\Repositories\Contracts\UserRepositoryInterface as User;
use Illuminate\Http\Request;
use Illuminate\Container\Container as App;
use Coyote\Pm;
use Illuminate\Pagination\LengthAwarePaginator;
use Carbon\Carbon;

/**
 * Class PmRepository
 * @package Coyote\Repositories\Eloquent
 */
class PmRepository extends Repository implements PmRepositoryInterface
{
    /**
     * @var User
     */
    private $user;

    /**
     * @param App $app
     * @param User $user
     */
    public function __construct(App $app, User $user)
    {
        parent::__construct($app);

        $this->user = $user;
    }
    /**
     * @return \Coyote\Pm
     */
    public function model()
    {
        return 'Coyote\Pm';
    }

    /**
     * Get last messages
     *
     * @param int $userId
     * @param int $limit
     * @return mixed
     */
    public function takeForUser($userId, $limit = 10)
    {
        return $this->prepare($userId)->limit($limit)->get();
    }

    /**
     * @param int $userId
     * @param int $perPage
     * @return LengthAwarePaginator
     */
    public function paginate($userId, $perPage = 10)
    {
        $count = $this->model
                ->select(\DB::raw('COUNT(*)'))
                ->where('user_id', $userId)
                ->groupBy('root_id')
                ->get()
                ->count();

        $result = $this->prepare($userId)
                ->limit($perPage)
                ->skip(request('page') * $perPage)
                ->get();

        return new LengthAwarePaginator($result, $count, $perPage, request('page'));
    }

    /**
     * Gets conversation
     *
     * @param int $userId
     * @param string $rootId
     * @param int $limit
     * @param int $offset
     * @return mixed
     */
    public function talk($userId, $rootId, $limit = 10, $offset = 0)
    {
        $result = $this->model->select([
                    'pm.*',
                    'pm_text.text',
                    'pm_text.created_at',
                    'name',
                    'is_active',
                    'is_blocked',
                    'photo'<commit_msg>Bug generowania stronnicowania (generowanie linkow do kolejnych stron)<commit_after><?php

namespace Coyote\Repositories\Eloquent;

use Coyote\Repositories\Contracts\PmRepositoryInterface;
use Coyote\Repositories\Contracts\UserRepositoryInterface as User;
use Illuminate\Http\Request;
use Illuminate\Container\Container as App;
use Coyote\Pm;
use Illuminate\Pagination\LengthAwarePaginator;
use Carbon\Carbon;

/**
 * Class PmRepository
 * @package Coyote\Repositories\Eloquent
 */
class PmRepository extends Repository implements PmRepositoryInterface
{
    /**
     * @var User
     */
    private $user;

    /**
     * @param App $app
     * @param User $user
     */
    public function __construct(App $app, User $user)
    {
        parent::__construct($app);

        $this->user = $user;
    }
    /**
     * @return \Coyote\Pm
     */
    public function model()
    {
        return 'Coyote\Pm';
    }

    /**
     * Get last messages
     *
     * @param int $userId
     * @param int $limit
     * @return mixed
     */
    public function takeForUser($userId, $limit = 10)
    {
        return $this->prepare($userId)->limit($limit)->get();
    }

    /**
     * @param int $userId
     * @param int $perPage
     * @return LengthAwarePaginator
     */
    public function paginate($userId, $perPage = 10)
    {
        $count = $this->model
                ->select(\DB::raw('COUNT(*)'))
                ->where('user_id', $userId)
                ->groupBy('root_id')
                ->get()
                ->count();

        $result = $this->prepare($userId)
                ->limit($perPage)
                ->skip(request('page') * $perPage)
                ->get();

        return new LengthAwarePaginator(
            $result, $count, $perPage, LengthAwarePaginator::resolveCurrentPage(), [
                'path' => LengthAwarePaginator::resolveCurrentPath()
            ]
        );
    }

    /**
     * Gets conversation
     *
     * @param int $userId
     * @param string $rootId
     * @param int $limit
     * @param int $offset
     * @return mixed
     */
    public function talk($userId, $rootId, $limit = 10, $offset = 0)
    {
        $result = $this->model->select([
                    'pm.*',
                    'pm_text.text',
                    'pm_text.created_at',
                    'name',
                    'is_active',
                    'is_blocked',
                    'photo'
{'fraction_non_alphanumeric': 0.13311965811965812, 'fraction_numerical': 0.0029914529914529917, 'mean_word_length': 1.804673457159976, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 36, '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': '5443090', 'n_tokens_mistral': 1432, 'n_tokens_neox': 1401, 'n_words': 291}