add Notes

This commit is contained in:
Leorne
2019-12-05 15:05:33 +03:00
parent 2279783ca8
commit f7177975a8
16 changed files with 521 additions and 2 deletions

View File

@ -0,0 +1,29 @@
<?php
namespace backend\modules\notes\models;
use common\models\FieldsValueNew;
class Note extends \common\models\Note
{
public function afterSave($insert, $changedAttributes)
{
$post = \Yii::$app->request->post('Note');
FieldsValueNew::deleteAll(['item_id' => $this->id, 'item_type' => FieldsValueNew::TYPE_NOTE]);
foreach ( $post['fields'] as $item) {
$fieldsValue = new FieldsValueNew();
$fieldsValue->field_id = $item['field_id'];
$fieldsValue->item_id = $this->id;
$fieldsValue->item_type = FieldsValueNew::TYPE_NOTE;
$fieldsValue->order = $item['order'];
$fieldsValue->value = $item['value'];
$fieldsValue->save();
}
parent::afterSave($insert, $changedAttributes);
}
}

View File

@ -0,0 +1,57 @@
<?php
namespace backend\modules\notes\models;
use Yii;
use yii\data\ActiveDataProvider;
class NoteSearch extends Note
{
public function rules()
{
return [
[['id'], 'integer'],
[['name', 'description', 'created_at', 'updated_at'], 'safe'],
];
}
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search()
{
$params = Yii::$app->request->queryParams;
$query = Note::find();
// add conditions that should always apply here
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
// grid filtering conditions
$query->andFilterWhere([
'id' => $this->id,
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
]);
$query->andFilterWhere(['like', 'name', $this->name])
->andFilterWhere(['like', 'description', $this->description]);
$query->orderBy('created_at DESC');
return $dataProvider;
}
}