/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Projeto(); $model->data_inicio = date("d/m/Y"); $model->data_fim = date("d/m/Y"); $model->data_relatorio = date("d/m/Y"); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Projeto'])) { $model->attributes = $_POST['Projeto']; if (isset($_POST['Projeto']['pessoas_atuantes'])) { $model->pessoas_atuantes = $_POST['Projeto']['pessoas_atuantes']; } if ($model->save()) { //Cria permissão para o coordenador $this->createDafaultPermissions($model); $this->salvaPessoas($model->cod_projeto, $model->pessoas_atuantes); $this->redirect(array('view', 'id' => $model->cod_projeto)); } } $this->render('create', array('model' => $model)); }
function criarprojeto() { $this->valida_sessao(); $nome_projeto = $this->escape("nomeproj"); $usuario = $this->escape("user"); $numero_profissionais = 10; $custo_padrao_hora = 50; $p_analise = 10; $p_projeto = 25; $p_implementacao = 50; $p_testes = 15; //cod: 10 - 20 - 55 - 15 //art: 30 - 27 - 15 - 28 $projeto = new Projeto(); $projeto->idUsuario = $usuario; $projeto->nome = $nome_projeto; $projeto->linhasDeCodigoPrevistas = rand(300000, 600000); $projeto->artefatosPrevistos = $projeto->linhasDeCodigoPrevistas * (1 / 100); //1% do codigo $projeto->tempo = round($projeto->linhasDeCodigoPrevistas / ($numero_profissionais * 194 * 5)); $projeto->orcamento = $numero_profissionais * $custo_padrao_hora * 8 * 5 * $projeto->tempo * 1.12; //custo esperado + 12% $projeto->saldo = $projeto->orcamento; $projeto->percentualErros = 1.5; $projeto->idStatus = 0; $projeto->save(); $meta1 = new Meta(); $meta1->nome = "Análise"; $meta1->idProjeto = $projeto->idProjeto; $meta1->tempo = round($projeto->tempo * ($p_analise / 100)); $meta1->linhasDeCodigo = round($projeto->linhasDeCodigoPrevistas * (10 / 100)); $meta1->artefatos = round($projeto->artefatosPrevistos * (30 / 100)); $meta1->save(); $meta2 = new Meta(); $meta2->nome = "Projeto"; $meta2->idProjeto = $projeto->idProjeto; $meta2->tempo = round($projeto->tempo * ($p_projeto / 100)); $meta2->linhasDeCodigo = round($projeto->linhasDeCodigoPrevistas * (20 / 100)); $meta2->artefatos = round($projeto->artefatosPrevistos * (27 / 100)); $meta2->save(); $meta3 = new Meta(); $meta3->nome = "Implementação"; $meta3->idProjeto = $projeto->idProjeto; $meta3->tempo = round($projeto->tempo * ($p_implementacao / 100)); $meta3->linhasDeCodigo = round($projeto->linhasDeCodigoPrevistas * (55 / 100)); $meta3->artefatos = round($projeto->artefatosPrevistos * (15 / 100)); $meta3->save(); $meta4 = new Meta(); $meta4->nome = "Testes e Validação"; $meta4->idProjeto = $projeto->idProjeto; $meta4->tempo = $projeto->tempo - $meta3->tempo - $meta2->tempo - $meta1->tempo; $meta4->linhasDeCodigo = $projeto->linhasDeCodigoPrevistas - $meta3->linhasDeCodigo - $meta2->linhasDeCodigo - $meta1->linhasDeCodigo; $meta4->artefatos = $projeto->artefatosPrevistos - $meta3->artefatos - $meta2->artefatos - $meta1->artefatos; $meta4->save(); for ($i = 0; $i < $projeto->tempo; $i++) { $semana = new Semana(); $semana->idProjeto = $projeto->idProjeto; $semana->save(); for ($j = 0; $j < 5; $j++) { $dia = new Dia(); $dia->idSemana = $semana->idSemana; $dia->save(); } } $_SESSION["idprojeto"] = $projeto->idProjeto; $_SESSION["projeto"] = true; $apresentacao = $this->escape("apresentacao"); if ($apresentacao == true) { $this->set("apresentacao", true); } else { $this->set("apresentacao", false); } $this->show("pages/interno/index.tpl"); }
/** * Cria um projeto novo para um GT * @param integer $id - identificador do GT * @throws CHttpException */ public function actionCreateProjeto($id) { //Verifica se é um GT válido $gt = GrupoTrabalho::model()->findByPk($id); if ($gt == null) { //Dispara erro. throw new CHttpException(400, 'Invalid request. Please do not repeat this request again.'); } //Cria novo projeto $model = new Projeto(); //Seta o GT a qual ele pertnece $model->cod_gt = $gt->cod_gt; if (isset($_POST['Projeto'])) { $model->attributes = $_POST['Projeto']; if ($model->save()) { //Salva o projeto e redireciona para a pagina do projeto $this->redirect(array('viewProjeto', 'id' => $model->cod_projeto)); } } $this->render('/projeto/create', array('model' => $model)); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Projeto(); $model->instrumento_juridico = new InstrumentoJuridico(); $model->convenio = new Convenio(); $user_id = Yii::app()->user->getId(); //Define por padrão o usuario que esta criando o projeto $model->cod_professor = $user_id; $model->cod_grad = $user_id; $model->cod_pos_grad = $user_id; $model->cod_bolsista_responsavel = $user_id; /* $model->data_inicio = date("d/m/Y"); $model->data_fim = date("d/m/Y"); $model->data_relatorio = date("d/m/Y"); */ // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Projeto'])) { $model->attributes = $_POST['Projeto']; if (isset($_POST['Projeto']['pessoas'])) { $model->pessoas = $_POST['Projeto']['pessoas']; } if (isset($_POST['InstrumentoJuridico'])) { $model->instrumento_juridico = json_encode($_POST['InstrumentoJuridico']); } if (isset($_POST['Convenio'])) { $model->convenio = json_encode($_POST['Convenio']); } if (isset($_POST['Orcamento'])) { $model->orcamentos = $_POST['Orcamento']; } //$connection = Yii::app()->db; //$transaction=$connection->beginTransaction(); //try //{ if ($model->save()) { if (!$this->salvaOrcamento($model->cod_projeto, $model->orcamentos)) { $model->addError('orcamentos', "Erro ao salvar orçamentos"); } if (!$this->salvaPessoas($model->cod_projeto, explode(',', $model->pessoas))) { $model->addError('pessoas', "Erro ao adicionar equipe: Verifique os participantes e coordenadores"); } //Verifica erros e gera exceção if ($model->hasErrors()) { throw new CHttpException(500, "ERRO AO SALVAR PROJETO"); } //Notifica usuarios //$this->broadCast($model->cod_projeto, "adicionou você ao projeto"); //Salva definitivamente todas as alterações no banco //$transaction->commit(); //Redireciona $this->redirect(array('view', 'id' => $model->cod_projeto)); } /*} catch (Exception $e) { $transaction->rollBack(); $model->instrumento_juridico = InstrumentoJuridico::load(json_decode($model->instrumento_juridico)); $model->convenio = Convenio::load(json_decode($model->convenio)); } */ } $this->render('create', array('model' => $model)); }