<commit_before><?php

namespace Depotwarehouse\YEGVotes\Model;

use Carbon\Carbon;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;

/**
 * Class AgendaItem
 * @package Depotwarehouse\YEGVotes\Model
 *
 * @method Builder bylaws()
 */
class AgendaItem extends Model
{

    const CATEGORY_IGNORE = "ignore";
    const CATEGORY_OTHER = "uncategorized";
    const CATEGORY_BYLAW = "bylaw";
    const CATEGORY_PASSED_WITHOUT_DEBATE = "passed-without-debate";
    const CATEGORY_INQUIRY = "councillor-inquiry";
    const CATEGORY_PRIVATE = "private";

    const BYLAW_REGEX_MATCHER = '/^Bylaw \d+/';
    /*
     * Councillor inquiries and protocol items take the same form. A councillor inquiry is an agenda item that matches
     * the protocol item regex, and includes a motion.
     */
    const PROTOCOL_REGEX_MATCHER = '/\([A-Za-z]. [A-Za-z]+\)$/';

    use FiltersProtocolItems;

    public $table = "agenda_items";
    public $incrementing = false;
    public $timestamps = false;

    protected $fillable = [ 'id', 'meeting_id', 'title' ];
    protected $interestingMotions = null;

    public function __toString()
    {
        return $this->title;
    }

    public function getTitleAttribute()
    {
        $title = trim($this->attributes['title']);
        $title = str_replace('<br>', '', $title);
        return str_replace('<BR>', '', $title);
    }

    public function scopeWithoutProtocolItems(Builder $query)
    {
        return $this->filterProtocolItems($query);
    }

    public function getFormattedTitleAttribute()
    {
        $title = preg_replace('/(^<br>)|(^<BR>)|(<BR>$)|(<br>$)/', "", trim($this->title));
        if ($this->isBylaw()) {
            return preg_replace(self::BYLAW_REGEX_MATCHER, "<strong>$0</strong>", $title);
        }

        return $title;
    }

    /**
     * Get a scope that only contains agenda items relating to the passing of Bylaws. An agenda item must have
     * at least one motion that has at least one vote taken (future bylaw votes will not appear)
     *
     * @param Builder $query
     * @return Builder
     */
    public function scopeBylaws($query)
    {
        return $query->where('title', 'RLIKE', 'Bylaw [0-9](.*)')
            ->hasVotes()
            ->orderedByMeetingDate()
            ->with('motions.votes');
    }

    public function scopeRecent($query)
    {
        $recentThreshold = Carbon::now()->subDays(45)->toDateTimeString();
        return $query->join("meetings", "agenda_items.meeting_id", '=', 'meetings.id')
            ->select("agenda_items.*")
            ->where('meetings.date', '>', $recentThreshold);
    }

    /**
     * @param Builder $query
     */
    public function scopeOrderedByMeetingDate($query)
    {
        return $query->join("meetings", "agenda_items.meeting_id", '=', 'meetings.id')
            ->select("agenda_items.*")
            ->orderBy('meetings.date', 'DESC');
    }

    /**
     * Filters the current scope to only include items that have motions with votes on them.
     * @param Builder $query
     * @return \Illuminate\Database\Eloquent\Builder
     */
    public function scopeHasVotes($query)
    {
        return $query->whereHas('motions', function (Builder $query) {
            $query->has('votes');
        });
    }
<commit_msg>Added another agenda scope<commit_after><?php

namespace Depotwarehouse\YEGVotes\Model;

use Carbon\Carbon;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;

/**
 * Class AgendaItem
 * @package Depotwarehouse\YEGVotes\Model
 *
 * @method Builder bylaws()
 */
class AgendaItem extends Model
{

    const CATEGORY_IGNORE = "ignore";
    const CATEGORY_OTHER = "uncategorized";
    const CATEGORY_BYLAW = "bylaw";
    const CATEGORY_PASSED_WITHOUT_DEBATE = "passed-without-debate";
    const CATEGORY_INQUIRY = "councillor-inquiry";
    const CATEGORY_PRIVATE = "private";

    const BYLAW_REGEX_MATCHER = '/^Bylaw \d+/';
    /*
     * Councillor inquiries and protocol items take the same form. A councillor inquiry is an agenda item that matches
     * the protocol item regex, and includes a motion.
     */
    const PROTOCOL_REGEX_MATCHER = '/\([A-Za-z]. [A-Za-z]+\)$/';

    use FiltersProtocolItems;

    public $table = "agenda_items";
    public $incrementing = false;
    public $timestamps = false;

    protected $fillable = [ 'id', 'meeting_id', 'title' ];
    protected $interestingMotions = null;

    public function __toString()
    {
        return $this->title;
    }

    public function getTitleAttribute()
    {
        $title = trim($this->attributes['title']);
        $title = str_replace('<br>', '', $title);
        return str_replace('<BR>', '', $title);
    }

    public function scopeWithoutProtocolItems(Builder $query)
    {
        return $this->filterProtocolItems($query);
    }

    public function getFormattedTitleAttribute()
    {
        $title = preg_replace('/(^<br>)|(^<BR>)|(<BR>$)|(<br>$)/', "", trim($this->title));
        if ($this->isBylaw()) {
            return preg_replace(self::BYLAW_REGEX_MATCHER, "<strong>$0</strong>", $title);
        }

        return $title;
    }

    /**
     * Get a scope that only contains agenda items relating to the passing of Bylaws. An agenda item must have
     * at least one motion that has at least one vote taken (future bylaw votes will not appear)
     *
     * @param Builder $query
     * @return Builder
     */
    public function scopeBylaws($query)
    {
        return $query->where('title', 'RLIKE', 'Bylaw [0-9](.*)')
            ->hasVotes()
            ->orderedByMeetingDate()
            ->with('motions.votes');
    }

    public function scopeRecent($query)
    {
        $recentThreshold = Carbon::now()->subDays(45)->toDateTimeString();
        return $query->join("meetings", "agenda_items.meeting_id", '=', 'meetings.id')
            ->select("agenda_items.*")
            ->where('meetings.date', '>', $recentThreshold);
    }

    /**
     * @param Builder $query
     */
    public function scopeOrderedByMeetingDate($query)
    {
        return $query->join("meetings", "agenda_items.meeting_id", '=', 'meetings.id')
            ->select("agenda_items.*")
            ->orderBy('meetings.date', 'DESC');
    }

    /**
     * Filters the current scope to only include items that have motions with votes on them.
     * @param Builder $query
     * @return \Illuminate\Database\Eloquent\Builder
     */
    public function scopeHasVotes($query)
    {
        return $query->whereHas('motions', function (Builder $query) {
            $query->has('votes');
        });
    }

    public function scopeHasMotions($query)
    {
        return $query->has('motions');
    }

{'fraction_non_alphanumeric': 0.1421863536316948, 'fraction_numerical': 0.001467351430667645, 'mean_word_length': 2.8056951423785597, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 60, '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': '5182415', 'n_tokens_mistral': 2194, 'n_tokens_neox': 2115, 'n_words': 478}