/** * Creates a new CurriculosFormacao model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new CurriculosFormacao(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
/** * Creates a new Curriculos model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $this->layout = 'main-curriculos'; $model = new Curriculos(); $curriculosEndereco = new CurriculosEndereco(); $curriculosFormacao = new CurriculosFormacao(); $modelsComplemento = [new CurriculosComplemento()]; $modelsEmpregos = [new CurriculosEmpregos()]; if (isset($_COOKIE['PHPSESSID']) && !empty($_COOKIE['PHPSESSID'])) { session_id($_COOKIE['PHPSESSID']); } session_start(); //session numero de edital e do id do processo $session = Yii::$app->session; $model->edital = $session["numeroEdital"]; $id = $session["id"]; $model->data = date('Y-m-d H:i:s'); //NÚMERO DE INSCRIÇÃO 'ANO CORRENTE + 000000 + ID DO CANDIDATO' $query_id = "SELECT max(id) as id FROM curriculos LIMIT 1"; $last_id = Curriculos::findBySql($query_id)->all(); foreach ($last_id as $value) { $incremento = $value['id']; $incremento++; } $model->numeroInscricao = date('Y') . '00000' . $incremento; $curriculosEndereco->curriculos_id = $incremento; $curriculosFormacao->curriculos_id = $incremento; //localizando somente os cargos que fazem parte do edital selecionado $cargos = Cargos::find()->innerJoinWith('cargosProcessos')->where(['processo_id' => $id])->AndWhere('cargo_id = idcargo')->all(); //Caso não tenha puxado nenhum edital, será redirecionado para a página de processo seletivo if ($model->edital == NULL) { return $this->redirect('http://www.am.senac.br/trabsenac.php'); } if ($model->load(Yii::$app->request->post()) && $curriculosEndereco->load(Yii::$app->request->post()) && $curriculosFormacao->load(Yii::$app->request->post()) && Model::validateMultiple([$model, $curriculosEndereco, $curriculosFormacao])) { //Calcular a idade do candidato $datetime1 = new \DateTime($model->datanascimento, new \DateTimeZone('UTC')); $datetime2 = new \DateTime(); $diff = $datetime1->diff($datetime2); $model->idade = $diff->y; $model->save(false); // skip validation as model is already validated $curriculosEndereco->curriculos_id = $model->id; $curriculosFormacao->curriculos_id = $model->id; $curriculosEndereco->save(false); $curriculosFormacao->save(false); //ENVIA E-MAIL DA INSCRIÇÃO PARA O CANDIDATO Yii::$app->mailer->compose()->setFrom(['*****@*****.**' => 'Processo Seletivo - Senac AM'])->setTo($model->email)->setSubject('Inscrição para o Edital: ' . $model->edital)->setTextBody('Prezado Candidato, confirmamos o envio de seu currículo para concorrer a vaga de ' . $model->cargo . ' para o Edital ' . $model->edital . ' ')->setHtmlBody("Prezado Senhor(a), <strong>" . $model->nome . "</strong><br><br>" . "Recebemos a sua inscrição em nosso processo de seleção com sucesso para o Edital: <strong>" . $model->edital . " </strong>e pedimos que acompanhe em nosso site o resultado das próximas etapas.<br><br>" . "<strong><font color='red'><center>NÃO RESPONDA A ESSE E-MAIL!!!!</center></font></strong><br><br>" . "<strong>INFORMAÇÕES GERAIS</STRONG><br><br>" . "<strong>Número de Inscrição: </strong><font color='red'>" . $model->numeroInscricao . "</font><br><br>" . "<strong>Data do envio: </strong> " . $model->data . "<br>" . "<strong>Processo Seletivo: </strong> " . $model->edital . "<br>" . "<strong>Cargo: </strong> " . $model->cargo . "<br><br>")->send(); //Inserir vários cursos complementares $modelsComplemento = Model::createMultiple(CurriculosComplemento::classname()); Model::loadMultiple($modelsComplemento, Yii::$app->request->post()); //Inserir vários emprgos anteriores $modelsEmpregos = Model::createMultiple(CurriculosEmpregos::classname()); Model::loadMultiple($modelsEmpregos, Yii::$app->request->post()); // validate all models $valid = $model->validate(); $valid = Model::validateMultiple($modelsComplemento) && $valid; $valid2 = $model->validate(); $valid_empregos = Model::validateMultiple($modelsEmpregos) && $valid2; if ($valid && $valid_empregos) { $transaction = \Yii::$app->db->beginTransaction(); try { if ($flag = $model->save(false)) { foreach ($modelsComplemento as $modelComplemento) { //cursos complementares $modelComplemento->curriculos_id = $model->id; if (!($flag = $modelComplemento->save(false))) { $transaction->rollBack(); break; } } foreach ($modelsEmpregos as $modelEmpregos) { //empregos anteriores $modelEmpregos->curriculos_id = $model->id; if (!($flag = $modelEmpregos->save(false))) { $transaction->rollBack(); break; } } } if ($flag) { $transaction->commit(); return $this->redirect('http://www.am.senac.br/trabsenac_success.php'); } } catch (Exception $e) { $transaction->rollBack(); } } return $this->redirect('http://www.am.senac.br/trabsenac_success.php'); } else { return $this->render('create', ['model' => $model, 'cargos' => $cargos, 'curriculosEndereco' => $curriculosEndereco, 'curriculosFormacao' => $curriculosFormacao, 'modelsComplemento' => empty($modelsComplemento) ? [new CurriculosComplemento()] : $modelsComplemento, 'modelsEmpregos' => empty($modelsEmpregos) ? [new CurriculosEmpregos()] : $modelsEmpregos]); } }