-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSinglePage.php
More file actions
109 lines (102 loc) · 3 KB
/
SinglePage.php
File metadata and controls
109 lines (102 loc) · 3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
/**
* This file contain definition for KoolReport
*
* @category Core
* @package KoolReport
* @author KoolPHP Inc <support@koolphp.net>
* @copyright 2017-2028 KoolPHP Inc
* @license MIT License https://www.koolreport.com/license#mit-license
* @link https://www.koolphp.net
*/
namespace koolreport\instant;
use \koolreport\core\Utility;
/**
* SinglePage trait for KoolReport
*
* @category Core
* @package KoolReport
* @author KoolPHP Inc <support@koolphp.net>
* @copyright 2017-2028 KoolPHP Inc
* @license MIT License https://www.koolreport.com/license#mit-license
* @link https://www.koolphp.net
*/
trait SinglePage
{
/**
* Keep the old active report
*
* @var KoolReport Old active report
*/
protected $oldActiveReport;
/**
* Constructor
*
* @return null
*/
public function __constructSinglePage()
{
//assets folder
$assets = Utility::get($this->reportSettings, "assets");
if ($assets === null) {
$asset_path = str_replace("\\", "/", dirname($_SERVER["SCRIPT_FILENAME"]) . "/koolreport_assets");
if (!is_dir($asset_path)) {
mkdir($asset_path, 0755);
}
$assets = array(
"url" => "koolreport_assets",
"path" => $asset_path,
);
$this->reportSettings["assets"] = $assets;
}
}
/**
* Report start
*
* Call this function before rendering the html of the report view
*
* @return null
*/
public function start()
{
$this->run();
$this->oldActiveReport = isset($GLOBALS["__ACTIVE_KOOLREPORT__"])
? $GLOBALS["__ACTIVE_KOOLREPORT__"] : null;
$GLOBALS["__ACTIVE_KOOLREPORT__"] = $this;
$this->registerEvent(
"OnResourceInit",
function () {
$this->getResourceManager()->addScriptFileOnBegin(
$this->getResourceManager()->publishAssetFolder(
realpath(dirname(__FILE__) . "/../core/src/clients/core")
) . "/KoolReport.js"
);
},
true
);
$this->getResourceManager()->init();
ob_start();
}
/**
* Call this function after rendering the html of report view
*
* @return null
*/
public function end()
{
$content = ob_get_clean();
if ($this->fireEvent("OnBeforeRender")) {
if ($this->oldActiveReport === null) {
unset($GLOBALS["__ACTIVE_KOOLREPORT__"]);
} else {
$GLOBALS["__ACTIVE_KOOLREPORT__"] = $this->oldActiveReport;
}
if ($this->fireEvent("OnBeforeResourceAttached")) {
$this->getResourceManager()->process($content);
$this->fireEvent("OnResourceAttached");
}
$this->fireEvent("OnRenderEnd", array('content' => &$content));
echo $content;
}
}
}