/** * Delete model by id. * * @param ModelBase $model * @throws ControllerException */ protected function _deleteModelById($sql, $model) { if ($model->validateForDelete()) { $stmt = $this->_dbh->prepare($sql); if (!$stmt) { throw new ControllerException('Prepared statement failed for ' . $sql); } $id = $model->getId(); if (!$stmt->bind_param('i', $id)) { throw new ControllerException('Binding parameters for prepared statement failed.'); } if (!$stmt->execute()) { throw new ControllerException('Failed to execute DELETE statement. (' . $this->_dbh->error . ')'); } /** * @SuppressWarnings checkAliases */ if (!$stmt->close()) { throw new ControllerException('Something broke while trying to close the prepared statement.'); } return; } else { throw new ControllerException('Invalid data'); } }
/** * Método genérico que verifica se existe mensagem para o destinatário especificado(Objeto genérico). * OBS: Os filtros ainda não foram aplicados * @param ModelBase $detinatario O destinatário * @paran FiltrosSistema $filtrosSistema Objeto do sistema de filtros * @return boolean Retorna true caso haja ou false caso não haja */ public function temMensagem(ModelBase $detinatario, FiltrosSistema $filtrosSistema = null) { $tabela = $this->getTabela(); $query = "select* from {$tabela} "; $query .= "inner join " . $tabela . "_destinatarios on mensagem={$tabela}.id "; $query .= "where pk_destinatario=" . $detinatario->getId() . " limit 1"; return (bool) $this->queryStatement($query)->rowCount(); }