-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExample.php
59 lines (52 loc) · 1.62 KB
/
Example.php
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
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Example extends CI_Controller {
public function index()
{
// Loading Lib
$this->load->library('cidoc');
// Preparing Data
$data = [];
for($i=0; $i<50; $i++){
$name = 'Lorem Ipsum';
if ($i > 11 && $i < 15) {
$name = 'Dolor Sit';
}
$data[] = array(
'id' => $i+1,
'date' => date('d M Y'),
'name' => $name,
'hit' => rand(0, 100),
'status' => 'Complete',
);
}
// Preparing Table Header and Mapping Data
$header = array(
array('label' => 'ID.', 'data' => 'id'),
array('label' => 'Date', 'data' => 'date'),
array('label' => 'Name', 'data' => 'name'),
array('label' => 'Hit', 'data' => 'hit'),
array('label' => 'Status', 'data' => 'status'),
);
// Preparing Option Lib
$option = array(
'title' => 'User Report', // Set the title of table
'summary' => array( // Set summary or footer table
array(
'label' => 'Total Hit',
'column' => array(
'hit' => array_sum(array_column($data, 'hit')),
)
)
),
'filter' => array( // Set more information on header
array('label' => 'Date', 'value' => date('d M Y')),
array('label' => 'Status', 'value' => 'Complete'),
),
'merged' => array('by' => 'name', 'except' => array('id', 'hit', 'date', 'status')), // Merge unique name data vertically
);
$this->cidoc->set($header, $data, $option)->createHTML(); // Output HTML
// $this->cidoc->set($header, $data, $option)->createExcel(); // Output Excel
// $this->cidoc->set($header, $data, $option)->createPDF(); // Output PDF
}
}