|
18 | 18 | */
|
19 | 19 |
|
20 | 20 | use Gibbon\Data\ImportType;
|
| 21 | +use Gibbon\Tables\DataTable; |
| 22 | +use Gibbon\Domain\DataSet; |
| 23 | +use Gibbon\Domain\System\LogGateway; |
| 24 | +use Gibbon\Services\Format; |
21 | 25 |
|
22 | 26 | // Module Bootstrap
|
23 | 27 | require __DIR__ . '/module.php';
|
|
28 | 32 | echo __("You do not have access to this action.") ;
|
29 | 33 | echo "</div>" ;
|
30 | 34 | } else {
|
31 |
| - $page->breadcrumbs->add(__('View Import History', 'Data Admin')); |
32 |
| - |
33 |
| - echo "<h3>" ; |
34 |
| - echo __("Import History", 'Data Admin') ; |
35 |
| - echo "</h3>" ; |
| 35 | + $page->breadcrumbs->add(__('View Import History')); |
36 | 36 |
|
37 | 37 | // Get a list of available import options
|
38 | 38 | $importTypeList = ImportType::loadImportTypeList($pdo, false);
|
39 | 39 |
|
40 |
| - $sql = "SELECT gibbonLog.*, gibbonPerson.username, gibbonPerson.surname, gibbonPerson.preferredName |
41 |
| - FROM gibbonLog |
42 |
| - JOIN gibbonPerson ON (gibbonPerson.gibbonPersonID=gibbonLog.gibbonPersonID) |
43 |
| - WHERE gibbonLog.title LIKE 'Import -%'"; |
44 |
| - |
45 |
| - $result=$pdo->executeQuery(array(), $sql); |
46 |
| - |
47 |
| - if (empty($importTypeList) || $result->rowCount()<1) { |
48 |
| - echo "<div class='error'>" ; |
49 |
| - echo __("There are no records to display.") ; |
50 |
| - echo "</div>" ; |
51 |
| - } else { |
52 |
| - echo "<table class='fullWidth colorOddEven' cellspacing='0'>" ; |
53 |
| - echo "<tr class='head'>" ; |
54 |
| - echo "<th style='width: 100px;'>" ; |
55 |
| - echo __("Date") ; |
56 |
| - echo "</th>" ; |
57 |
| - echo "<th>" ; |
58 |
| - echo __("User") ; |
59 |
| - echo "</th>" ; |
60 |
| - echo "<th style='width: 80px;'>" ; |
61 |
| - echo __("Category") ; |
62 |
| - echo "</th>" ; |
63 |
| - echo "<th >" ; |
64 |
| - echo __("Import Type", 'Data Admin') ; |
65 |
| - echo "</th>" ; |
66 |
| - echo "<th>" ; |
67 |
| - echo __("Details") ; |
68 |
| - echo "</th>" ; |
69 |
| - echo "<th>" ; |
70 |
| - echo __("Actions") ; |
71 |
| - echo "</th>" ; |
72 |
| - echo "</tr>" ; |
73 |
| - |
74 |
| - while ($row=$result->fetch()) { |
75 |
| - $data = isset($row['serialisedArray'])? unserialize($row['serialisedArray']) : []; |
76 |
| - if (!isset($importTypeList[ $data['type'] ])) { |
77 |
| - continue; |
78 |
| - } // Skip invalid import types |
79 |
| - |
80 |
| - echo "<tr class='".($data['success'] == false? 'error' : '')."'>" ; |
81 |
| - $importType = $importTypeList[ $data['type'] ]; |
82 |
| - |
83 |
| - echo "<td>"; |
84 |
| - printf("<span title='%s'>%s</span> ", $row['timestamp'], date('M j, Y', strtotime($row['timestamp']))); |
85 |
| - echo "</td>"; |
86 |
| - |
87 |
| - echo "<td>"; |
88 |
| - echo $row['preferredName'].' '.$row['surname']; |
89 |
| - echo "</td>"; |
90 |
| - |
91 |
| - echo "<td>" . $importType->getDetail('category'). "</td>" ; |
92 |
| - echo "<td>" . $importType->getDetail('name'). "</td>" ; |
93 |
| - echo "<td>" .(($data['success'] == true)? 'Success' : 'Failed'). "</td>"; |
94 |
| - |
95 |
| - echo "<td>"; |
96 |
| - echo "<a class='thickbox' href='" . $_SESSION[$guid]["absoluteURL"] . "/fullscreen.php?q=/modules/" . $_SESSION[$guid]["module"] . "/import_history_view.php&gibbonLogID=" . $row['gibbonLogID'] . "&width=600&height=550'><img title='" . __('View Details') . "' src='./themes/" . $_SESSION[$guid]["gibbonThemeName"] . "/img/plus.png'/></a> " ; |
97 |
| - echo "</td>"; |
98 |
| - |
99 |
| - echo "</tr>" ; |
100 |
| - } |
101 |
| - echo "</table>" ; |
102 |
| - } |
| 40 | + $logGateway = $container->get(LogGateway::class); |
| 41 | + $logsByType = $logGateway->selectLogsByModuleAndTitle('System Admin', 'Import - %')->fetchAll(); |
| 42 | + |
| 43 | + $logsByType = array_map(function ($log) use (&$importTypeList) { |
| 44 | + $log['data'] = isset($log['serialisedArray'])? unserialize($log['serialisedArray']) : []; |
| 45 | + $log['importType'] = @$importTypeList[$log['data']['type']]; |
| 46 | + return $log; |
| 47 | + }, $logsByType); |
| 48 | + |
| 49 | + $table = DataTable::create('importHistory'); |
| 50 | + $table->setTitle(__('Import History')); |
| 51 | + |
| 52 | + $table->addColumn('timestamp', __('Date')) |
| 53 | + ->format(Format::using('dateTime', 'timestamp')); |
| 54 | + |
| 55 | + $table->addColumn('user', __('User')) |
| 56 | + ->format(Format::using('name', ['', 'preferredName', 'surname', 'Staff', false, true])); |
| 57 | + |
| 58 | + $table->addColumn('category', __('Category')) |
| 59 | + ->format(function ($log) { |
| 60 | + return $log['importType']->getDetail('category'); |
| 61 | + }); |
| 62 | + |
| 63 | + $table->addColumn('name', __('Name')) |
| 64 | + ->format(function ($log) { |
| 65 | + return $log['importType']->getDetail('name'); |
| 66 | + }); |
| 67 | + |
| 68 | + $table->addColumn('details', __('Details')) |
| 69 | + ->format(function ($log) { |
| 70 | + return !empty($log['data']['success']) ? __('Success') : __('Failed'); |
| 71 | + }); |
| 72 | + |
| 73 | + $table->addActionColumn() |
| 74 | + ->addParam('gibbonLogID') |
| 75 | + ->format(function ($importType, $actions) { |
| 76 | + $actions->addAction('view', __('View')) |
| 77 | + ->isModal('600', '550') |
| 78 | + ->setURL('/modules/Data Admin/import_history_view.php'); |
| 79 | + }); |
| 80 | + |
| 81 | + echo $table->render(new DataSet($logsByType)); |
103 | 82 | }
|
0 commit comments