<commit_before><?php

namespace frontend\modules\bbii\models;

use frontend\modules\bbii\models\BbiiAR;
use frontend\modules\bbii\models\_query\BbiiPostQuery;

/**
 * This is the model class for table "bbii_post".
 *
 * The followings are the available columns in table 'bbii_post':
 * @property string $id
 * @property string $subject
 * @property string $content
 * @property string $user_id
 * @property string $topic_id
 * @property string $forum_id
 * @property string $ip
 * @property string $create_time
 * @property integer $approved
 * @property string $change_id
 * @property string $change_time
 * @property string $change_reason
 * @property integer $upvoted
 */
class BbiiPost extends BbiiAR
{
	public $search;

    public static function find()
    {
        return new BbiiPostQuery(get_called_class());
    }

	/**
	 * @return string the associated database table name
	 */
	public static function tableName()
	{
		return 'bbii_post';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		$obj = new HtmlPurifier();
		$obj->options = Yii::$app->getController()->module->purifierOptions;
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('subject, content', 'required'),
			array('change_id, user_id, topic_id, forum_id, approved, upvoted', 'numerical', 'integerOnly' => true),
			array('subject, change_reason', 'length', 'max' => 255),
			array('content','filter','filter' => array($obj, 'purify')),
			array('ip', 'length', 'max' => 39),
			array('ip', 'blocked'),
			array('ip', 'default', 'value' => Yii::$app->request->userHostAddress, 'on' => 'insert'),
			array('user_id', 'default', 'value' => Yii::$app->user->id, 'on' => 'insert'),
			array('create_time', 'default', 'value' => new CDbExpression('NOW()'), 'on' => 'insert'),
			array('change_id', 'default', 'value' => Yii::$app->user->id, 'on' => 'update'),
			array('change_time', 'default', 'value' => new CDbExpression('NOW()'), 'on' => 'update'),
			array('create_time, change_time, search', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, subject, content, user_id, topic_id, forum_id, ip, create_time, approved, change_id, change_time, change_reason, search', 'safe', 'on' => 'search'),
		);
	}

	public function blocked($attribute, $params) {
		if(BbiiIpaddress::blocked($this->ip)) {
			$this->addError('ip', Yii::t('BbiiModule.bbii','Your IP address has been blocked.'));
		}
	}
	
	/**
	 * @return array relational rules.
	 */<commit_msg>MDL BbiiPost rules() worked on<commit_after><?php

namespace frontend\modules\bbii\models;

use frontend\modules\bbii\models\BbiiAR;
use frontend\modules\bbii\models\_query\BbiiPostQuery;

use yii;
use yii\data\ActiveDataProvider;
use yii\helpers\HtmlPurifier;

/**
 * This is the model class for table "bbii_post".
 *
 * The followings are the available columns in table 'bbii_post':
 * @property string $id
 * @property string $subject
 * @property string $content
 * @property string $user_id
 * @property string $topic_id
 * @property string $forum_id
 * @property string $ip
 * @property string $create_time
 * @property integer $approved
 * @property string $change_id
 * @property string $change_time
 * @property string $change_reason
 * @property integer $upvoted
 */
class BbiiPost extends BbiiAR
{
	public $search;

    public static function find()
    {
        return new BbiiPostQuery(get_called_class());
    }

	/**
	 * @return string the associated database table name
	 */
	public static function tableName()
	{
		return 'bbii_post';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		$obj = new HtmlPurifier();

		//$obj->options = Yii::$app->getController()->module->purifierOptions;
		$obj->options = Yii::$app->controller->module->purifierOptions;
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('subject, content', 'required'),
			array('change_id, user_id, topic_id, forum_id, approved, upvoted', 'numerical', 'integerOnly' => true),
			array('subject, change_reason', 'length', 'max' => 255),
			array('content','filter','filter' => array($obj, 'purify')),
			array('ip', 'length', 'max' => 39),
			array('ip', 'blocked'),
			array('ip', 'default', 'value' => $_SERVER['REMOTE_ADDR'], 'on' => 'insert'),
			array('user_id', 'default', 'value' => Yii::$app->user->id, 'on' => 'insert'),
			array('create_time', 'default', 'value' => 'NOW()', 'on' => 'insert'),
			array('change_id', 'default', 'value' => Yii::$app->user->id, 'on' => 'update'),
			array('change_time', 'default', 'value' => 'NOW()', 'on' => 'update'),
			array('create_time, change_time, search', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, subject, content, user_id, topic_id, forum_id, ip, create_time, approved, change_id, change_time, change_reason, search', 'safe', 'on' => 'search'),
		);
	}

	public function blocked($attribute, $params) {
		if(BbiiIpaddress::blocked($this->ip)) {
			$this->addError('ip', Yii::t('BbiiModule.bbii','Your IP address has been blocked.'));
		}
	}
	
	/**
	 * @return array relational rules.
	 */
{'fraction_non_alphanumeric': 0.16967777984727136, 'fraction_numerical': 0.0018625442354255914, 'mean_word_length': 4.536082474226804, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 59, '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': '3581754', 'n_tokens_mistral': 1825, 'n_tokens_neox': 1702, 'n_words': 470}