Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //classe dashboard
- class Dashboard {
- private $data_inicio;
- private $data_fim;
- private $numeroVendas;
- private $totalVendas;
- public function __get($atributo){
- return $this->$atributo;
- }
- public function __set($atributo, $valor){
- $this->$atributo = $valor;
- return $this;
- }
- }
- class Conexao {
- private $host = 'localhost';
- private $dbname = 'dashboard';
- private $user = 'root';
- private $pass = '';
- public function conectar(){
- try{
- $conexao = new PDO(
- "mysql:host=$this->host;dbname=$this->dbname",
- "$this->user",
- "$this->pass"
- );
- //
- $conexao->exec('set charset set utf8');
- return $conexao;
- } catch (PDOException $e) {
- echo '<p>Problema na conexao com a base de dados: ' . $e->getMessage() . '</p>';
- }
- }
- }
- class Bd {
- private $conexao;
- private $dashboard;
- public function __construct(Conexao $conexao, Dashboard $dashboard){
- $this->conexao = $conexao->conectar();
- $this->dashboard = $dashboard;
- }
- public function getNumeroVendas() {
- $query = '
- select
- count(*) as numero_vendas
- from
- tb_vendas
- where
- data_venda BETWEEN :data_inicio AND :data_fim';
- $stmt = $this->conexao->prepare($query);
- $stmt->bindValue(':data_inicio', $this->dashboard->__get('data_inicio'));
- $stmt->bindValue(':data_fim', $this->dashboard->__get('data_fim'));
- $stmt->execute();
- return $stmt->fetch(PDO::FETCH_OBJ)->numero_vendas;
- }
- public function getTotalVendas() {
- $query = '
- select
- sum(total) as total_vendas
- from
- tb_vendas
- where
- data_venda BETWEEN :data_inicio AND :data_fim';
- $stmt = $this->conexao->prepare($query);
- $stmt->bindValue(':data_inicio', $this->dashboard->__get('data_inicio'));
- $stmt->bindValue(':data_fim', $this->dashboard->__get('data_fim'));
- $stmt->execute();
- return $stmt->fetch(PDO::FETCH_OBJ)->total_vendas;
- }
- }
- $dashboard = new Dashboard();
- $conexao = new Conexao();
- $competencia = explode('-', $_GET['competencia']);
- $ano = $competencia[0];
- $mes = $competencia[1];
- $dias_do_mes = cal_days_in_month(CAL_GREGORIAN, $mes, $ano);
- $dashboard->__set('data_inicio', '2017-08-02');
- $dashboard->__set('data_fim', '2018-10-31');
- //como é que ele consegue ir buscar a info da data sendo que o atributo está private???
- echo '<br>';
- echo $dashboard->data_inicio;
- echo '</br>';
- $bd = new Bd($conexao, $dashboard);
- $dashboard->__set('numeroVendas', $bd->getNumeroVendas());
- $dashboard->__set('totalVendas', $bd->getTotalVendas());
- print_r($ano.'/'.$mes.'/'.$dias_do_mes);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement