/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Avaliado::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' => $this->id]); $query->andFilterWhere(['like', 'nome', $this->nome])->andFilterWhere(['like', 'tipo', $this->tipo]); return $dataProvider; }
/** * Creates a new Turma model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Turma(); if ($model->load(Yii::$app->request->post()) && $model->save()) { echo '<pre>'; $itensAvaliadosPelaTurma = Yii::$app->request->post('AvaliadoTurma'); foreach ($itensAvaliadosPelaTurma as $key => $item) { if ($item['id_avaliado'] === '1') { $avaliadoTurma = new AvaliadoTurma(); $avaliadoTurma->id_avaliado = $key; $avaliadoTurma->id_turma = $model->id; $avaliadoTurma->save(); } } return $this->redirect(['view', 'id' => $model->id]); } else { $itens = Avaliado::find()->orderBy('tipo')->all(); return $this->render('create', ['model' => $model, 'itens' => $itens]); } }
/** * @return \yii\db\ActiveQuery */ public function getIdAvaliado() { return $this->hasOne(Avaliado::className(), ['id' => 'id_avaliado']); }
/** * Finds the Avaliado model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Avaliado the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Avaliado::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
<?php $key = 0; ?> <?php foreach ($itens as $item) { ?> <?php $avaliados = []; if ($item->tipo != 'PRO') { $avaliados = [\app\models\Avaliado::find()->where(['tipo' => $item->tipo])->one()]; } else { $avaliados = \app\models\Avaliado::find()->joinWith('avaliadoTurmas')->where(['tipo' => 'PRO', 'id_turma' => $turma->id])->all(); } foreach ($avaliados as $avaliado) { $key++; $avaliacao = new \app\models\Avaliacao(); echo $form->field($avaliacao, '[' . $key . ']id_item')->textInput(['type' => 'hidden', 'value' => $item->id])->label(false); echo $form->field($avaliacao, '[' . $key . ']id_turma')->textInput(['type' => 'hidden', 'value' => $turma->id])->label(false); echo $form->field($avaliacao, '[' . $key . ']id_avaliado')->textInput(['value' => $avaliado->id, 'type' => 'hidden'])->label(false); ?> <tr> <td colspan="3"> <h4><?php echo $item->descricao; ?> <h5> <?php echo $item->tipo == 'PRO' ? 'Professor(a) ' . $avaliado->nome : '';
public static function getTipo() { return Avaliado::getTipo(); }