/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Grupo::find(); $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; } $query->andFilterWhere(['id_grupo' => $this->id_grupo]); $query->andFilterWhere(['like', 'nombre', $this->nombre])->andFilterWhere(['like', 'descripcion', $this->descripcion]); return $dataProvider; }
/** * @return \yii\db\ActiveQuery */ public function getIdGrupos() { return $this->hasMany(\app\modules\admin\models\Grupo::className(), ['id_grupo' => 'id_grupo'])->viaTable(\app\modules\admin\models\UsuarioGrupo::tableName(), ['id_usuario' => 'id_usuario']); }
/** * @return \yii\db\ActiveQuery */ public function getIdGrupo() { return $this->hasOne(Grupo::className(), ['id_grupo' => 'id_grupo']); }
/** * Search roles of user * @param integer $id * @param string $target * @param string $term * @return string */ public function actionBuscarPermisos() { try { $return = ['success' => false, 'message' => "No se pudo procesar la solicitud."]; if (\Yii::$app->request->isAjax) { Yii::$app->response->format = 'json'; $usuario = SeguridadUsuarios::findOne(Yii::$app->request->post("id")); $available = Grupo::getGrupos(); $assigned = $usuario->getPermisos(); // $permisosGrupo = $grupo->getPermisos(); // $available = array_diff($available, $permisosGrupo); // $assigned = array_intersect($available, $permisosGrupo); $available = \yii\helpers\Html::listBox("list-available", NULL, $available, ['id' => 'list-available', "multiple" => true, "size" => "20", "style" => "width:100%"]); $assigned = \yii\helpers\Html::listBox("list-assigned", NULL, $assigned, ['id' => 'list-assigned', "multiple" => true, "size" => "20", "style" => "width:100%"]); $return = ['success' => true, 'available' => $available, 'assigned' => $assigned]; } } catch (Exception $ex) { $return = ['success' => false, 'message' => $ex->getMessage()]; } return $return; }
/** * Finds the Grupo model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Grupo the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Grupo::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }