From 423665bd2957c612929f9144d934185a1453a493 Mon Sep 17 00:00:00 2001 From: dongnl Date: Wed, 8 May 2019 18:30:58 +0700 Subject: [PATCH] Init code --- .gitignore | 11 +++ CHANGELOG.md | 10 +++ Friendship.php | 51 +++++++++++++ LaravelDataSource.php | 16 ++++ README.md | 174 ++++++++++++++++++++++++++++++++++++++++++ composer.json | 11 +++ 6 files changed, 273 insertions(+) create mode 100644 .gitignore create mode 100644 CHANGELOG.md create mode 100644 Friendship.php create mode 100644 LaravelDataSource.php create mode 100644 README.md create mode 100644 composer.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ce9eeee --- /dev/null +++ b/.gitignore @@ -0,0 +1,11 @@ +# Build and Release Folders +vendor + +# Other files and folders + +# Executables +*.exe + +# Project files, i.e. `.project`, `.actionScriptProperties` and `.flexProperties` +# should NOT be excluded as they contain compiler settings and other important +# information for Eclipse / Flash Builder. diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..997807c --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,10 @@ +# Change Log + +## Version 1.5.0 + +1. Enhance assets url settings + +## Version 1.0.0 + +1. Implement HandShake between KoolReport and Laravel so that KoolReport can access to database settings of Laravel +2. Create special LaravelDataSource to handle data source from Laravel. \ No newline at end of file diff --git a/Friendship.php b/Friendship.php new file mode 100644 index 0000000..57998cc --- /dev/null +++ b/Friendship.php @@ -0,0 +1,51 @@ +reportSettings,"assets"); + if($assets==null) + { + $public_path = str_replace("\\","/",public_path()); + if(!is_dir($public_path."/koolreport_assets")) + { + mkdir($public_path."/koolreport_assets",0755); + } + $assets = array( + "url"=>url("")."/koolreport_assets", + "path"=>$public_path."/koolreport_assets", + ); + $this->reportSettings["assets"] = $assets; + } + + //DataSources + $dbSources = array(); + $dbConfig = Config::get('database'); + $defaultSource = Utility::get($dbConfig,"default"); + if($defaultSource) + { + $dbSources[$defaultSource] = array( + "class"=>LaravelDataSource::class, + "name"=>$defaultSource, + ); + } + foreach($dbConfig["connections"] as $name=>$config) + { + $dbSources[$name] = array( + "class"=>LaravelDataSource::class, + "name"=>$name, + ); + } + $dataSources = Utility::get($this->reportSettings,"dataSources",array()); + $this->reportSettings["dataSources"] = array_merge($dbSources,$dataSources); + + } +} \ No newline at end of file diff --git a/LaravelDataSource.php b/LaravelDataSource.php new file mode 100644 index 0000000..4bb251a --- /dev/null +++ b/LaravelDataSource.php @@ -0,0 +1,16 @@ +params,"name"); + $this->connection = DB::connection($name)->getPdo(); + } +} \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..0c74e7c --- /dev/null +++ b/README.md @@ -0,0 +1,174 @@ +# Introduction + +Without doubt, [Laravel](https://laravel.com) is the most favorite PHP Framework in the world. It is easy to learn, fast and powerful with full capability for any web application. + +Since we created KoolReport we received many questions like "_How to use KoolReport in Laravel?_". The answer is KoolReport was designed to work with any PHP Frameworks and Laravel is one of them. The setting to make them work together is simple but we want to make things simpler. + +__Laravel package__ is an add-on extension to make KoolReport work seamlessly in Laravel Framework environment. By adding package, report created with KoolReport will recorgnize Laravel databases automatically. Furthermore, KoolReport's widgets will be configured assets path and url so that all are working without requiring any further set-up effort from you. All with a simple line of code: + +``` +use \koolreport\laravel\Friendship; +``` + +While Laravel is PHP Framework for general purpose, KoolReport only __focus on reporting, data processing, charts and graphs__. KoolReport will power Laravel report capability to the max. For fun comparison, Laravel with KoolReport is like _Thanos with Mind Stone_ and this package is like the glove to connect them. Laravel is a __powerful framework__ and KoolReport will make it __better__. + +# Requirement + +1. KoolReport >= 2.75.0 +2. Laravel >= 4.2 + +# Installation + +1. Download and unzip it +2. Copy `laravel` folder into `koolreport\packages` folder +3. All done, you are ready to create report in laravel php framework. + +# Documentation + +## Step-by-step tutorial + +#### Step 1: Create report and claim friendship with Laravel + +1. First, you create folder `Reports` inside Laravel's `app` folder +2. Inside Reports folder, create two files `MyReport.php` and `MyReport.view.php` +3. Adding `use \koolreport\laravel\Friendship` to your report like following + +`MyReport.php` + +``` +src("sale_database") + ->query("SELECT * FROM offices") + ->pipe($this->dataStore("offices")); + } +} +``` + +`MyReport.view.php` + +``` + + + + My Report + + +

It works

+ $this->dataStore("offices") + ]); + ?> + + +``` + +#### Step 2: Run report and display report + +Now you have MyReport ready, in order to get report display inside Laravel, you will create MyReport's object in controller and pass that object to the view to render. + + +`HomeController.php` + +``` +middleware("guest"); + } + public function index() + { + $report = new MyReport; + $report->run(); + return view("report",["report"=>$report]); + } +} +``` + +`report.blade.php` + +``` +render(); ?> +``` + +## Other notes + +### Auto-generated assets + +__Laravel packages__ will automatically create a folder name `koolreport_assets` inside Laravel's `public` folder in order to hold the report resources such as Javascript files or CSS file. + + +### Other datasources other than Laravel's default + +If you have another datasources rather than Laravel's datasources, feel free to add them in `settings()` function as you normally do. For example, in below example code, we will have anoher csv source: + +``` +class MyReport extends \koolreport\KoolReport +{ + use \koolreport\laravel\Friendship; + function settings() + { + return array( + "dataSources"=>array( + "csv_source"=>array( + "class"=>'\koolreport\datasources\CSVDataSource', + 'filePath'=>dirname(__FILE__)."\mycsvdata.csv", + ) + ) + ); + } +} +``` + +### Customize assets folder + +By default, adding `Friendship` will configure assets path and url for report automatically. But in some cases that you would like to set your own location, you can do: + +``` +class MyReport extends \koolreport\KoolReport +{ + function settings() + { + return array( + "assets"=>array( + "path"=>"../../public/resources/kool" + "url"=>"resources/kool" + ) + ); + } +} +``` + +The `path` can be ralative path from the report to the assets folder or absolute path to assets folder. + +The `url` is the browser url to access the assets folder. + + +# Support + +Please use our forum if you need support, by this way other people can benefit as well. If the support request need privacy, you may send email to us at __support@koolreport.com__. \ No newline at end of file diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..bf12433 --- /dev/null +++ b/composer.json @@ -0,0 +1,11 @@ +{ + "name": "koolreport/laravel", + "version":"1.5.0", + "description": "Allow to use KoolReport seamlessly in Laravel", + "keywords": ["PHP","Reporting Tools","Data Report","laravel","KooLReport Laravel","Laravel Report","laravel reporting","laravel reporting tool"], + "homepage": "https://www.koolreport.com", + "type": "library", + "license": "https://www.koolreport.com/license#regular-license", + "require": { + } +} \ No newline at end of file