public function afterSave($insert, $changedAttributes) { if (sizeof($this->horarios) == 0) { $h1 = new Horario(); $h1->descricao = '12:00h às 13:30h'; $h1->inicio = '12:00:00'; $h1->termino = '13:30:00'; $h1->exame_idexame = $this->idexame; $h1->save(); $h2 = new Horario(); $h2->descricao = '14:00h às 15:30h'; $h2->inicio = '14:00:00'; $h2->termino = '15:30:00'; $h2->exame_idexame = $this->idexame; $h2->save(); $h3 = new Horario(); $h3->descricao = '16:00h às 17:30h'; $h3->inicio = '16:00:00'; $h3->termino = '17:30:00'; $h3->exame_idexame = $this->idexame; $h3->save(); $h4 = new Horario(); $h4->descricao = '18:00h às 19:30h'; $h4->inicio = '18:00:00'; $h4->termino = '19:30:00'; $h4->exame_idexame = $this->idexame; $h4->save(); } parent::afterSave($insert, $changedAttributes); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Horario::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(['idhorario' => $this->idhorario, 'inicio' => $this->inicio, 'termino' => $this->termino, 'exame_idexame' => $this->exame_idexame]); $query->andFilterWhere(['like', 'descricao', $this->descricao]); return $dataProvider; }
/** * Finds the Horario model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param string $id * @return Horario the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Horario::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * @return \yii\db\ActiveQuery */ public function getHorario() { return $this->hasOne(Horario::className(), ['idhorario' => 'horario_idhorario']); }
use yii\helpers\Html; use yii\widgets\ActiveForm; use yii\helpers\ArrayHelper; /* @var $this yii\web\View */ /* @var $model backend\models\Prova */ /* @var $form yii\widgets\ActiveForm */ ?> <div class="prova-form"> <?php $form = ActiveForm::begin(); ?> <?php $horarioArray = ArrayHelper::map(\backend\models\Horario::find()->orderBy('descricao')->where(['exame_idexame' => $model->calendario->exame_idexame])->all(), 'idhorario', 'descricao'); ?> <?php echo $form->field($model, 'horario_idhorario')->dropDownList($horarioArray, ['prompt' => '---- Selecione um Horário ----'])->label('Horário'); ?> <?php $predioArray = ArrayHelper::map(\backend\models\Predio::find()->orderBy('nome')->where(['unidade' => 1])->all(), 'idpredio', 'nome'); ?> <?php echo $form->field($model, 'predio_idpredio')->dropDownList($predioArray, ['prompt' => '---- Selecione uma Unidade ----'])->label('Unidade'); ?> <?php $disciplinaArray = ArrayHelper::map(\backend\models\Disciplina::find()->orderBy('nome')->all(), 'iddisciplina', 'nome'); ?>