/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = ContratacaoJustificativas::find()->orderBy(['id' => SORT_DESC]); $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, 'id_contratacao' => $this->id_contratacao]); $session = Yii::$app->session; $query->andFilterWhere(['id_contratacao' => $session['sess_contratacao']])->andFilterWhere(['like', 'descricao', $this->descricao])->andFilterWhere(['like', 'usuario', $this->usuario]); return $dataProvider; }
/** * Deletes an existing Contratacao model. * If deletion is successful, the browser will be redirected to the 'index' page. * @param string $id * @return mixed */ public function actionDelete($id) { $model = $this->findModel($id); //USUÁRIOS APENAS IRÃO EXCLUIR AS SOLICITAÇÕES DE CONTRATAÇÃO COM STATUS DE 'EM ELABORAÇÃO' e 'EM CORREÇÃO' if ($model->situacao_id != 1 && $model->situacao_id != 2) { Yii::$app->session->setFlash('danger', '<strong>ERRO! </strong> Não é possível <strong>EXCLUIR</strong> a Solicitação de Contratação de código: ' . '<strong>' . $id . '</strong>' . ' pois a mesma está com status de ' . '<strong>' . $model->situacao->descricao . '.</strong>'); return $this->redirect(['index']); } //BUSCA NO BANCO SE EXISTE JUSTIFICATIVAS PARA A SOLICITAÇÃO $checarJustificativa = ContratacaoJustificativas::find()->where(['id_contratacao' => $_GET])->all(); foreach ($checarJustificativa as $value) { $justificativa = $value["id_contratacao"]; //Caso tenha justificativa será excluida. $connection = Yii::$app->db; $command = $connection->createCommand("DELETE FROM `contratacao_justificativas` WHERE `contratacao_justificativas`.`id_contratacao`= '" . $justificativa . "'"); $command->execute(); } //BUSCA NO BANCO SE EXISTE SISTEMAS CADASTRADOS PARA A SOLICITAÇÃO $checarSistema = SistemasContratacao::find()->where(['contratacao_id' => $_GET])->all(); foreach ($checarSistema as $value) { $sistema = $value["contratacao_id"]; //Caso tenha justificativa será excluida. $connection = Yii::$app->db; $command = $connection->createCommand("DELETE FROM `sistemas_contratacao` WHERE `sistemas_contratacao`.`contratacao_id`= '" . $sistema . "'"); $command->execute(); } //Executa a exclusão da solicitação de transporte $model = $this->findModel($id); $this->findModel($id)->delete(); //MENSAGEM DE EXCLUSÃO DA SOLICITAÇÃO DE CONTRATAÇÃO CRIADA COM SUCESSO Yii::$app->session->setFlash('success', '<strong>SUCESSO! </strong> A solicitação de Processo Seletivo de código <strong>' . $model->id . '</strong> foi EXCLUÍDA!</strong>'); return $this->redirect(['index']); }
/** * @return \yii\db\ActiveQuery */ public function getContratacaoJustificativas() { return $this->hasMany(ContratacaoJustificativas::className(), ['id_contratacao' => 'id']); }
/** * Finds the ContratacaoJustificativas model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return ContratacaoJustificativas the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = ContratacaoJustificativas::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }