/** * Display a list of files available * to the user */ public function actionIndex() { if (\Yii::$app->user->isGuest) { $this->redirect(['/site/index']); } $user = \Yii::$app->user->identity; // Get the list of file groups this user belongs too $usergroups = UserFileGroup::find()->where(['user_id' => $user->id])->all(); // get the list of filegroups $files = []; foreach ($usergroups as $ug) { $groups = FileFileGroup::find()->where(['group_id' => $ug->file_group_id])->all(); foreach ($groups as $g) { array_push($files, $g->file_id); } } $files = File::findAll($files); return $this->render('index', ['user' => $user, 'files' => $files]); }