koolphp / koolreport

This is an Open Source PHP Reporting Framework which you can use to write perfect data reports or to construct awesome dashboards using PHP
https://www.koolreport.com/
MIT License
228 stars 65 forks source link

Error Connecting to MongoDB #14

Open A-Pradeep opened 5 years ago

A-Pradeep commented 5 years ago

Hi , im trying to connect the koolReport to the MongoDB but i'm facing some error

Fatal error: Uncaught Error: Class 'MongoDB\Driver\Manager' not found in C:\xampp\htdocs\caas\dash\koolreport\packages\mongodb\vendor\mongodb\mongodb\src\Client.php:81 Stack trace: #0 C:\xampp\htdocs\caas\dash\koolreport\packages\mongodb\MongoDataSource.php(59): MongoDB\Client->__construct('mongodb://127.0...') #1 C:\xampp\htdocs\caas\dash\koolreport\core\DataSource.php(22): koolreport\mongodb\MongoDataSource->onInit() #2 C:\xampp\htdocs\caas\dash\koolreport\KoolReport.php(215): koolreport\core\DataSource->__construct(Array, Object(SalesByCustomer)) #3 C:\xampp\htdocs\caas\dash\SalesByCustomer.php(26): koolreport\KoolReport->src('mongo_purchase') #4 C:\xampp\htdocs\caas\dash\koolreport\KoolReport.php(39): SalesByCustomer->setup() #5 C:\xampp\htdocs\caas\dash\index.php(5): koolreport\KoolReport->__construct() #6 {main} thrown in C:\xampp\htdocs\caas\dash\koolreport\packages\mongodb\vendor\mongodb\mongodb\src\Client.php on line 81

And i'm new to this so i need some guidance to connecting the koolReport to the MongoDB , The Code as follows


<?php
// index.php: Just a bootstrap file
require_once "SalesByCustomer.php";

$salesByCustomer = new SalesByCustomer;
$salesByCustomer->run()->render();
<?php
// SalesByCustomer.php - Report setup file
require_once "koolreport/autoload.php";
use \koolreport\processes\Group;
use \koolreport\processes\Sort;
use \koolreport\processes\Limit;
use \koolreport\mongodb\MongoDataSource;

class SalesByCustomer extends \koolreport\KoolReport
{
    public function settings()
    {
        return array(
            "dataSources"=>array(
                "mongo_purchase"=>array(
                    "class"=>'\koolreport\mongodb\MongoDataSource',
                    "connectionString"=>"mongodb://127.0.0.1:27017",
                    "database"=>"formioapp"
                ),
            )
        );
    }

    public function setup()
    {
        $this->src('mongo_purchase')
        ->query(array("collections"=>"forms"))
        ->pipe($this->dataStore('mongo_purchases'));
    }
}
<?php 
// SalesByCustomer.view.php - Handle the report view
use \koolreport\widgets\koolphp\Table;
use \koolreport\widgets\google\BarChart;
?>

<div class="text-center">
    <h1>Sales Report</h1>
    <h4>This report shows top 10 sales by customer</h4>
</div>
<hr/>

<?php
BarChart::create(array(
    "dataStore"=>$this->dataStore('sales_by_customer'),
    "width"=>"100%",
    "height"=>"500px",
    "columns"=>array(
        "customerName"=>array(
            "label"=>"Customer"
        ),
        "dollar_sales"=>array(
            "type"=>"number",
            "label"=>"Amount",
            "prefix"=>"$",
        )
    ),
    "options"=>array(
        "title"=>"Sales By Customer"
    )
));
?>

<?php
Table::create(array(
    "dataStore"=>$this->dataStore('sales_by_customer'),
        "columns"=>array(
            "customerName"=>array(
                "label"=>"Customer"
            ),
            "dollar_sales"=>array(
                "type"=>"number",
                "label"=>"Amount",
                "prefix"=>"$",
            )
        ),
    "cssClass"=>array(
        "table"=>"table table-hover table-bordered"
    )
));
?>