Пример #1
0
 /**
  * Creates a new Frequencia model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate($date)
 {
     $model = new Frequencia();
     $p = PeriodoInscricaoMonitoria::find()->orderBy(['id' => SORT_DESC])->one();
     //$letivo = $p->ano.'/'.$p->periodo;
     $aluno = AlunoMonitoria::find()->where(['cpf' => Yii::$app->user->identity->cpf])->andWhere(['IDperiodoinscr' => $p->id])->andFilterWhere(['or', ['like', 'status', 'Selecionado com bolsa'], ['like', 'status', 'Selecionado sem bolsa']])->one();
     // pesquisa para pegar o id do alun
     $model->dmy = $date;
     $pesquisa = Frequencia::find()->where(['IDMonitoria' => $aluno->id])->andWhere(['dmy' => $date])->one();
     // Serve para verificar se tem registro na data selecionada.
     if (empty($pesquisa)) {
         if ($model->load(Yii::$app->request->post())) {
             $numDia = date('w', strtotime($date));
             $cont = $flag = 0;
             $dia1 = strtotime('-' . $numDia . ' day', strtotime($date));
             $diaX = strtotime('+' . (6 - $numDia) . ' day', strtotime($date));
             $p = Frequencia::find()->where(['IDMonitoria' => $aluno->id])->andWhere(['>=', 'dmy', date("Y-m-d", $dia1)])->andWhere(['<=', 'dmy', date("Y-m-d", $diaX)])->all();
             foreach ($p as $f) {
                 $cont = $cont + $f->ch;
                 if ($cont > 12) {
                     $flag = 1;
                 }
             }
             if ($flag == 0 && $model->ch + $cont <= 12) {
                 $model->IDMonitoria = $aluno->id;
                 $model->save();
                 return $this->redirect(['index', 'id' => $model->IDMonitoria]);
             } else {
                 return $this->redirect(['index', 'id' => $aluno->id, 'mensagem' => 'Carga não cadastrada por conta do excesso de horas.']);
             }
         } else {
             return $this->renderAjax('create', ['model' => $model]);
         }
     } else {
         return $this->redirect(['index', 'id' => $aluno->id, 'mensagem' => 'Já existe registro nesta data para a sua monitoria.']);
     }
 }
Пример #2
0
 /**
  * Creates a new Frequencia model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate($date)
 {
     $model = new Frequencia();
     $aluno = Aluno::find()->where(['CPF' => Yii::$app->user->identity->login])->one();
     // pesquisa para pegar o id do aluno
     $moni = Monitoria::find()->where(['IDAluno' => $aluno->ID])->one();
     // pesquisa para pegar o id de monitoria do aluno
     $model->dmy = $date;
     $model->IDMonitoria = $moni->ID;
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['index']);
     } else {
         return $this->renderAjax('create', ['model' => $model]);
     }
 }