如何解决显示与Yii2中提供给用户的节点有关的记录
我正在研究yii2
。我在一个视图中向用户显示一些数据。有节点的用户层次结构。
- 用户已附加到节点
- 节点已附加到客户
在将节点分配给客户时,将在所选节点下创建客户。没有子项(即客户)的子节点parent_id
告诉该客户已附加该节点。
- 客户已连接到仪表
我正在显示的数据如下
我想做什么?
在我上面的视图中,我只想显示与给用户节点附加的customer ID's
和meters
数据。
在我的search model
public function search($params)
{
if(Yii::$app->user->identity->user_role ==1)
{
// do nothing as the user is admin
}
else
{
$user_id = \Yii::$app->user->id;
}
$query = MdcmetersData::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,'cust_id'=>$this->cust_id,'data_date_time' => $this->data_date_time,]);
$query->andFilterWhere(['like','msn',$this->msn])
->andFilterWhere(['like','device_id',$this->device_id])
->andFilterWhere(['like','cust_id',$this->cust_id])
->andFilterWhere(['like','kwh_t',$this->kwh_t])
->andFilterWhere(['like','d_type',$this->d_type])
->andFilterWhere(['like','voltage_p1',$this->voltage_p1])
->andFilterWhere(['like','voltage_p2',$this->voltage_p2])
->andFilterWhere(['like','voltage_p3',$this->voltage_p3])
->andFilterWhere(['like','current_p1',$this->current_p1])
->andFilterWhere(['like','current_p2',$this->current_p2])
->andFilterWhere(['like','current_p3',$this->current_p3])
->andFilterWhere(['like','data_date_time',$this->data_date_time]);
$query->andWhere(['not',['cust_id'=>null]]);
$query->andWhere(['not',['cust_id'=>'']]);
$query->orderBy(['data_date_time' => SORT_DESC]);
return $dataProvider;
}
节点表(mdc_node)
表GIS Office
上方的I是customer
,它附加在Floor-1
下。在将客户附加到节点上时,将在所选节点(即子节点)下创建一个新节点。
注意:父节点下可以有多个子节点
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。