<commit_before><?php
namespace MessagingCenter\Model\Table;

use Cake\I18n\Time;
use Cake\ORM\Query;
use Cake\ORM\RulesChecker;
use Cake\ORM\Table;
use Cake\Validation\Validator;
use MessagingCenter\Model\Entity\Message;

/**
 * Messages Model
 *
 * @property \Cake\ORM\Association\BelongsTo $Users
 */
class MessagesTable extends Table
{
    const NEW_STATUS = 'new';
    const READ_STATUS = 'read';
    const ARCHIVED_STATUS = 'archived';
    const DELETED_STATUS = 'deleted';
    const STARRED_STATUS = 'starred';

    /**
     * Initialize method
     *
     * @param array $config The configuration for the Table.
     * @return void
     */
    public function initialize(array $config)
    {
        parent::initialize($config);

        $this->table('messages');
        $this->displayField('id');
        $this->primaryKey('id');

        $this->addBehavior('Timestamp');

        $this->belongsTo('Users', [
            'foreignKey' => 'from_user',
            'className' => 'CakeDC/Users.Users'
        ]);
    }

    /**
     * Default validation rules.
     *
     * @param \Cake\Validation\Validator $validator Validator instance.
     * @return \Cake\Validation\Validator
     */
    public function validationDefault(Validator $validator)
    {
        $validator
            ->uuid('id')
            ->allowEmpty('id', 'create');

        $validator
            ->uuid('from_user')
            ->requirePresence('from_user', 'create')
            ->notEmpty('from_user');

        $validator
            ->uuid('to_user')
            ->requirePresence('to_user', 'create')
            ->notEmpty('to_user');

        $validator
            ->requirePresence('subject', 'create')
            ->notEmpty('subject');

        $validator
            ->requirePresence('content', 'create')
            ->notEmpty('content');

        $validator
            ->dateTime('date_sent')
            ->allowEmpty('date_sent');

        $validator
            ->requirePresence('status', 'create')
            ->notEmpty('status');

        $validator
            ->allowEmpty('related_model');

        return $validator;
    }

    public function getUnreadCount($messages)
    {
        $result = 0;
        foreach ($messages as $message) {
            if (static::NEW_STATUS === $message->status) {
                $result++;
            }
        }

        return $result;
    }

    /**
     * Returns string to be used as status field value when a new message is created.
     * @return string
     */
    public function getNewMessageStatus()
    {
        return static::NEW_STATUS;
    }

    /**
     * Returns Time object to be used as date_sent field value.
     * @return Cake\I18n\Time
     */
    public function getDateSent()
    {<commit_msg>add method for returning read messages status string (task #1495)<commit_after><?php
namespace MessagingCenter\Model\Table;

use Cake\I18n\Time;
use Cake\ORM\Query;
use Cake\ORM\RulesChecker;
use Cake\ORM\Table;
use Cake\Validation\Validator;
use MessagingCenter\Model\Entity\Message;

/**
 * Messages Model
 *
 * @property \Cake\ORM\Association\BelongsTo $Users
 */
class MessagesTable extends Table
{
    const NEW_STATUS = 'new';
    const READ_STATUS = 'read';
    const ARCHIVED_STATUS = 'archived';
    const DELETED_STATUS = 'deleted';
    const STARRED_STATUS = 'starred';

    /**
     * Initialize method
     *
     * @param array $config The configuration for the Table.
     * @return void
     */
    public function initialize(array $config)
    {
        parent::initialize($config);

        $this->table('messages');
        $this->displayField('id');
        $this->primaryKey('id');

        $this->addBehavior('Timestamp');

        $this->belongsTo('Users', [
            'foreignKey' => 'from_user',
            'className' => 'CakeDC/Users.Users'
        ]);
    }

    /**
     * Default validation rules.
     *
     * @param \Cake\Validation\Validator $validator Validator instance.
     * @return \Cake\Validation\Validator
     */
    public function validationDefault(Validator $validator)
    {
        $validator
            ->uuid('id')
            ->allowEmpty('id', 'create');

        $validator
            ->uuid('from_user')
            ->requirePresence('from_user', 'create')
            ->notEmpty('from_user');

        $validator
            ->uuid('to_user')
            ->requirePresence('to_user', 'create')
            ->notEmpty('to_user');

        $validator
            ->requirePresence('subject', 'create')
            ->notEmpty('subject');

        $validator
            ->requirePresence('content', 'create')
            ->notEmpty('content');

        $validator
            ->dateTime('date_sent')
            ->allowEmpty('date_sent');

        $validator
            ->requirePresence('status', 'create')
            ->notEmpty('status');

        $validator
            ->allowEmpty('related_model');

        return $validator;
    }

    public function getUnreadCount($messages)
    {
        $result = 0;
        foreach ($messages as $message) {
            if (static::NEW_STATUS === $message->status) {
                $result++;
            }
        }

        return $result;
    }

    /**
     * Returns string to be used as status field value when a new message is created.
     * @return string
     */
    public function getNewStatus()
    {
        return static::NEW_STATUS;
    }

    /**
     * Returns string to be used as status field value when a message is read.
     * @return string
     */
    public function getReadStatus()
    {
        return static::READ_STATUS;
    }

    /**
     * Returns Time object to be used as date_sent field value.
     * @return Cake\I18n\Time
     */
    public function getDateSent()
    {
{'fraction_non_alphanumeric': 0.13094620307905205, 'fraction_numerical': 0.0024217263449230237, 'mean_word_length': 2.039957939011567, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 53, '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': '226729', 'n_tokens_mistral': 1633, 'n_tokens_neox': 1598, 'n_words': 358}