add company

This commit is contained in:
king199025
2018-10-11 17:24:47 +03:00
parent 3e10a51c3a
commit 5e2bc02bb5
21 changed files with 720 additions and 10 deletions

View File

@ -0,0 +1,58 @@
<?php
namespace backend\modules\company\models;
use common\models\FieldsValue;
class Company extends \common\models\Company
{
public $fields;
public function init()
{
parent::init();
$fieldValue = FieldsValue::find()->where(
[
'company_id' => \Yii::$app->request->get('id'),
'project_id' => null,
'card_id' => null,
])
->all();
$array = [];
if(!empty($fieldValue)){
foreach ($fieldValue as $item){
array_push($array, ['field_id' => $item->field_id, 'value' => $item->value, 'order' => $item->order]);
}
$this->fields = $array;
}
else{
$this->fields = [
[
'field_id' => null,
'value' => null,
'order' => null,
],
];
}
}
public function afterSave($insert, $changedAttributes)
{
$post = \Yii::$app->request->post('Company');
FieldsValue::deleteAll(['company_id' => $this->id]);
foreach ( $post['fields'] as $item) {
$fildsValue = new FieldsValue();
$fildsValue->field_id = $item['field_id'];
$fildsValue->value = $item['value'];
$fildsValue->order = $item['order'];
$fildsValue->company_id = $this->id;
$fildsValue->save();
}
parent::afterSave($insert, $changedAttributes); // TODO: Change the autogenerated stub
}
}

View File

@ -0,0 +1,73 @@
<?php
namespace backend\modules\company\models;
use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use backend\modules\company\models\Company;
/**
* CompanySearch represents the model behind the search form of `backend\modules\company\models\Company`.
*/
class CompanySearch extends Company
{
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['id', 'status_id'], 'integer'],
[['name', 'description', 'created_at', 'updated_at'], 'safe'],
];
}
/**
* {@inheritdoc}
*/
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = Company::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,
'status_id' => $this->status_id,
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
]);
$query->andFilterWhere(['like', 'name', $this->name])
->andFilterWhere(['like', 'description', $this->description]);
return $dataProvider;
}
}