/**
  * Finds the GrupoUsuarios model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return GrupoUsuarios the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = GrupoUsuarios::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 /**
  * Creates a new Mensagens model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionGroup()
 {
     $model = new Mensagens();
     if ($model->load(Yii::$app->request->post())) {
         $model->criado_por = Yii::$app->user->getId();
         $group = GrupoUsuarios::findOne($model->id_destinatario);
         $receivers = $group->usuarios;
         foreach ($receivers as $destinatario) {
             $model2 = new Mensagens();
             $model2->attributes = $model->attributes;
             $model2->id_destinatario = $destinatario->id_usuario;
             $model2->criado_por = Yii::$app->user->getId();
             $model2->ativo = 1;
             $model2->save();
         }
         return $this->redirect(['sent']);
     } else {
         $model->scenario = "group";
         return $this->render('create', ['model' => $model]);
     }
 }