Mail.php 2.41 KB
Newer Older
Mark committed
1 2 3 4 5 6 7 8 9
<?php

namespace yii\debug\models\search;

use yii\data\ArrayDataProvider;
use yii\debug\components\search\Filter;

/**
 * Mail represents the model behind the search form about current send emails.
10 11 12
 *
 * @author Mark Jebri <mark.github@yandex.ru>
 * @since 2.0
Mark committed
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
 */
class Mail extends Base
{
	/**
	 * @var string from attribute input search value
	 */
	public $from;

	/**
	 * @var string to attribute input search value
	 */
	public $to;

	/**
	 * @var string reply attribute input search value
	 */
	public $reply;

	/**
	 * @var string cc attribute input search value
	 */
	public $cc;

	/**
	 * @var string bcc attribute input search value
	 */
	public $bcc;

	/**
	 * @var string subject attribute input search value
	 */
	public $subject;

	/**
	 * @var string body attribute input search value
	 */
	public $body;

	/**
	 * @var string charset attribute input search value
	 */
	public $charset;

	/**
	 * @var string headers attribute input search value
	 */
	public $headers;

	/**
	 * @var string file attribute input search value
	 */
	public $file;

	public function rules()
	{
		return [
			[['from', 'to', 'reply', 'cc', 'bcc', 'subject', 'body', 'charset'], 'safe'],
		];
	}

	/**
	 * @inheritdoc
	 */
	public function attributeLabels()
	{
		return [
			'from' => 'From',
			'to' => 'To',
			'reply' => 'Reply',
			'cc' => 'Copy receiver',
			'bcc' => 'Hidden copy receiver',
			'subject' => 'Subject',
			'charset' => 'Charset'
		];
	}

	/**
	 * Returns data provider with filled models. Filter applied if needed.
	 * @param array $params
	 * @param array $models
	 * @return \yii\data\ArrayDataProvider
	 */
	public function search($params, $models)
	{
		$dataProvider = new ArrayDataProvider([
			'allModels' => $models,
			'pagination' => [
100
				'pageSize' => 20,
Mark committed
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
			],
			'sort' => [
				'attributes' => ['from', 'to', 'reply', 'cc', 'bcc', 'subject', 'body', 'charset'],
			],
		]);

		if (!($this->load($params) && $this->validate())) {
			return $dataProvider;
		}

		$filter = new Filter();
		$this->addCondition($filter, 'from', true);
		$this->addCondition($filter, 'to', true);
		$this->addCondition($filter, 'reply', true);
		$this->addCondition($filter, 'cc', true);
		$this->addCondition($filter, 'bcc', true);
		$this->addCondition($filter, 'subject', true);
		$this->addCondition($filter, 'body', true);
		$this->addCondition($filter, 'charset', true);
		$dataProvider->allModels = $filter->filter($models);

		return $dataProvider;
	}
}