Example #1
0
 /**
  * Delete referente ao model TipoEquip.
  * Se for deletado com sucesso retorna à index, senão abre a view com o registo
  * @param string $id
  * @return mixed
  */
 public function actionDelete($id)
 {
     $equipamento = Equipamento::findBySql("SELECT idequipamento FROM tb_equipamento WHERE idtipoequip = " . $id . " AND fl_delete = 0 LIMIT 1;")->all();
     if (isset($equipamento[0]->idequipamento)) {
         return $this->redirect(['view', 'id' => $id, 'msg' => 'Não foi possível excluir, pois já possui um equipamento com este tipo.']);
     }
     $model = $this->findModel($id);
     // Altera o coluna fl_delete para 1, que representa que o registro foi deletado
     $model->fl_delete = TRUE;
     if ($model->save()) {
         return $this->redirect(['index']);
     } else {
         return $this->redirect(['view', 'id' => $id]);
     }
 }
Example #2
0
 /**
  * Cria uma instância do provedor de dados com consulta de pesquisa aplicada
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Equipamento::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // Descomentar a seguinte linha se você não quer devolver quaisquer registos quando a validação falhar
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['idequipamento' => $this->idequipamento, 'idtipoequip' => $this->idtipoequip, 'dtcompra' => $this->dtcompra, 'valor_compra' => $this->valor_compra, 'fl_delete' => $this->fl_delete]);
     $query->andFilterWhere(['like', 'descricao', $this->descricao])->andFilterWhere(['like', 'nserie', $this->nserie]);
     // Filtra os registros que são diferentes de fl_delete=0, pois significa que foram deletados
     $query->andFilterWhere(['fl_delete' => 0]);
     return $dataProvider;
 }
 /**
  * Finds the Equipamento model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $id
  * @return Equipamento the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Equipamento::findOne($id)) !== null && $model->fl_delete == 0) {
         return $model;
     } else {
         throw new NotFoundHttpException('O registro solicitado não foi encontrado.');
     }
 }