Those are all business module files.
but the file names are comes like customer the variables are business.
if (isset ( $model->territory ) && ! empty ( $model->territory->territory_name))
checking the table is in or not
[color="#FF0000"]My model[/color]
class Customer extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'tbl_business';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['business_name', 'business_cond_type_id', 'email', 'mobile'], 'required'],
[['territory_type_id', 'business_cond_type_id', 'num', 'added_at', 'updated_at', 'inserted_by', 'updated_by'], 'integer'],
[['business_name', 'latitude', 'longitude', 'street', 'between_street', 'and_street', 'colony', 'inserted_ip', 'updated_ip', 'email', 'first_name', 'last_name', 'phone', 'mobile', 'fax'], 'string', 'max' => 255]
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => Yii::t('app', 'ID'),
'business_name' => Yii::t('app', 'Business Name'),
'territory_type_id' => Yii::t('app', 'Territory Type'),
'business_cond_type_id' => Yii::t('app', 'Business Type'),
'latitude' => Yii::t('app', 'Latitude'),
'longitude' => Yii::t('app', 'Longitude'),
'num' => Yii::t('app', 'Minutes'),
'street' => Yii::t('app', 'Street'),
'between_street' => Yii::t('app', 'Between Street'),
'and_street' => Yii::t('app', 'And Street'),
'email' => Yii::t('app', 'Email'),
'first_name' => Yii::t('app', 'First Name'),
'last_name' => Yii::t('app', 'Last Name'),
'phone' => Yii::t('app', 'Phone'),
'mobile' => Yii::t('app', 'Mobile'),
'fax' => Yii::t('app', 'Fax'),
'contact_id' => Yii::t('app', 'Contact'),
'added_at' => Yii::t('app', 'Added At'),
'updated_at' => Yii::t('app', 'Updated At'),
'inserted_ip' => Yii::t('app', 'inserted_ip'),
'inserted_by' => Yii::t('app', 'inserted_by'),
'updated_ip' => Yii::t('app', 'updated_ip'),
'updated_by' => Yii::t('app', 'updated_by'),
];
}
public function getCustomerType()
{
return $this->hasOne(CustomerType::className(), ['id' => 'business_cond_type_id']);
}
[color="#FF0000"]Searchmodel:[/color]
class Customer extends CustomerModel
{
public function rules()
{
return [
[['id', 'business_cond_type_id', 'territory_type_id', 'added_at', 'updated_at'], 'integer'],
[['business_name', 'email', 'first_name', 'last_name', 'phone', 'mobile', 'fax'], 'safe'],
];
}
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}
public function search($params)
{
$query = CustomerModel::find();
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
if (!($this->load($params) && $this->validate())) {
return $dataProvider;
}
$query->andFilterWhere([
'id' => $this->id,
'business_cond_type_id' => $this->business_cond_type_id,
'territory_type_id' => $this->territory_type_id,
//'contact_id' => $this->contact_id,
'added_at' => $this->added_at,
'updated_at' => $this->updated_at,
]);
$query->andFilterWhere(['like', 'business_name', $this->business_name])
->andFilterWhere(['like', 'email', $this->email])
->andFilterWhere(['like', 'first_name', $this->first_name])
->andFilterWhere(['like', 'last_name', $this->last_name])
->andFilterWhere(['like', 'phone', $this->phone])
->andFilterWhere(['like', 'mobile', $this->mobile])
->andFilterWhere(['like', 'fax', $this->fax]);
return $dataProvider;
}
public function searchProject($params,$customer_id)
{
$query = ProjectModel::find()->where("customer_id=$customer_id");
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
return $dataProvider;
}
public function searchAddresses($params, $entity_id)
{
$sql ="select tbl_city.city,tbl_country.country,tbl_state.state,tbl_address.*,tbl_customer_addresses.* from tbl_city,tbl_country,tbl_state,tbl_address,tbl_customer_addresses where tbl_city.id=tbl_address.city_id and tbl_state.id=tbl_address.state_id and tbl_country.id=tbl_address.country_id and tbl_address.entity_id=$entity_id and tbl_address.is_primary='1' and tbl_address.entity_type='customer'";
$connection = \Yii::$app->db;
$command=$connection->createCommand($sql);
$dataReader=$command->queryAll();
return $dataReader;
}
public function searchCustomer(){
$sql ="select
tbl_city.city,
tbl_country.country,
tbl_state.state,
tbl_address.*,
tbl_business.*,
tbl_business_condition_type.type,
tbl_territory.territory_name
from
tbl_business
LEFT JOIN tbl_business_condition_type
ON tbl_business.business_cond_type_id=tbl_business_condition_type.id
LEFT JOIN tbl_territory
ON tbl_business.territory_type_id=tbl_territory.territory_type_id
LEFT JOIN tbl_address
ON tbl_address.entity_id=tbl_business.id and tbl_address.is_primary='1'
LEFT JOIN tbl_country
ON tbl_country.id=tbl_address.country_id
LEFT JOIN tbl_state
ON tbl_state.id=tbl_address.state_id
LEFT JOIN tbl_city
ON tbl_city.id=tbl_address.city_id
";
//echo $sql;
$connection = \Yii::$app->db;
$command=$connection->createCommand($sql);
$dataReader=$command->queryAll();
return $dataReader;
}
[color="#FF0000"]My View:[/color]
Pjax::begin ();
echo GridView::widget ( [
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => '\kartik\grid\CheckboxColumn'],
['class' => 'yii\grid\SerialColumn'],
// 'id',
[
'attribute' => 'business_name',
'width' => '200px',
'format' => 'raw',
'value' => function ($model, $key, $index, $widget)
{
return '<a href="index.php?r=customer/customer/customer-view&id=' . $model->id . '">' . $model->business_name . '</a>';
}
],
[
'attribute' => 'business_cond_type_id',
// 'label' => 'Type',
'filterType' => GridView::FILTER_SELECT2,
'format' => 'raw',
'width' => '100px',
'filter' => ArrayHelper::map ( CustomerType::find ()->orderBy ( 'sort_order' )->asArray ()->all (), 'id', 'label' ),
'filterWidgetOptions' => [
'options' => [
'placeholder' => 'All...'
],
'pluginOptions' => [
'allowClear' => true
]
],
'value' => function ($model, $key, $index, $widget)
{
// var_dump($model->user);
// var_dump($model->customerType);
if (isset ( $model->customerType ) && ! empty ( $model->customerType->label ))
return $model->customerType->label;
}
],
// [
// 'attribute' => 'territory_type_id',
// 'label' => 'Type',
// 'filterType' => GridView::FILTER_SELECT2,
// 'format' => 'raw',
// 'width' => '100px',
// 'filter' => ArrayHelper::map ( Territory::find ()->orderBy ( 'territory_name' )->asArray ()->all (), 'territory_type_id', 'territory_name' ),
// 'filterWidgetOptions' => [
// 'options' => [
// 'placeholder' => 'All...'
// ],
// 'pluginOptions' => [
// 'allowClear' => true
// ]
// ],
// 'value' => function ($model, $key, $index, $widget)
// {
// var_dump($model->user);
// var_dump($model->customerType);
// if (isset ( $model->Territory ) && ! empty ( $model->Territory->territory_name ))
// return $model->Territory->territory_name;
// }
// ],
'latitude',
'longitude',
'email:email',
// 'phone',
'mobile',
// 'fax',
// 'address_id',
// 'created_at',
// 'updated_at',
[
'class' => 'yii\grid\ActionColumn',
'template' => '{update} {delete}',
'buttons' => [
'update' => function ($url, $model)
{
return '<a href="?r=customer/customer/customer-view&id=' . $model->id . '"><span class="glyphicon glyphicon-eye-open"></span></a>';
} ,
'delete' => function($url,$model){
$view =$_GET['view']?'&view='.$_GET['view']:'';
return '<form action="index.php?r=customer/customer/delete&id='.$model->id.$view.'" method="post" name="cust'.$model->id.'" style="display:inline">
<input type="hidden" name="_csrf" value="">
<button type="submit" onClick="return confirm(\''.Yii::t ('app','Are you Sure!').'\')" class="btn btn-link" style="color:#337ab7;display:inline;padding:0"><span class="glyphicon glyphicon-trash"></span></button>
</form> ';
}
]
]
],
'responsive' => true,
'hover' => true,
'condensed' => true,
'floatHeader' => false,
'panel' => [
'heading' => '<h3 class="panel-title"><i class="glyphicon glyphicon-th-list"></i> '.Yii::t ( 'app', 'Business' ).' </h3>',
'type' => 'info',
'before' => Html::a ( '<i class="glyphicon glyphicon-plus"></i> '.Yii::t ( 'app', 'Add' ), [
'create'
], [
'class' => 'btn btn-success'
] ).' <a href="javascript:void(0)" onClick="all_del()" class="btn btn-danger"><i class="glyphicon glyphicon-trash"></i> '.Yii::t ( 'app', 'Delete Selected' ).'</a>',
'after' => Html::a ( '<i class="glyphicon glyphicon-repeat"></i> '.Yii::t ( 'app', 'Reset List' ), [
'index'
], [
'class' => 'btn btn-info'
] ),
'showFooter' => false
]
] );
Pjax::end ();