Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 48708f6

Browse files
committed
Remove Gibbon\Core dependency from Importer, trim down strings used
1 parent 834128c commit 48708f6

File tree

4 files changed

+363
-387
lines changed

4 files changed

+363
-387
lines changed

Data Admin/export_run.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,11 @@
1919

2020
use Gibbon\Module\DataAdmin\ImportType;
2121

22-
//Increase max execution time, as this stuff gets big
22+
// Increase max execution time, as this stuff gets big
2323
ini_set('max_execution_time', 600);
2424

2525
// Gibbon Bootstrap
2626
include __DIR__ . '/../../gibbon.php';
27-
include __DIR__ . '/../../version.php';
2827

2928
// Module Bootstrap
3029
require __DIR__ . '/module.php';

Data Admin/import_manage.php

Lines changed: 59 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919

2020
use Gibbon\Module\DataAdmin\ImportType;
2121

22+
use Gibbon\Tables\DataTable;
23+
use Gibbon\Services\Format;
24+
use Gibbon\Domain\DataSet;
25+
use Gibbon\Domain\System\LogGateway;
26+
2227
// Module Bootstrap
2328
require __DIR__ . '/module.php';
2429

@@ -30,93 +35,64 @@
3035
} else {
3136
$page->breadcrumbs->add(__('Import From File', 'Data Admin'));
3237

38+
$logGateway = $container->get(LogGateway::class);
39+
$logsByType = $logGateway->selectLogsByModuleAndTitle('System Admin', 'Import - %')->fetchGrouped();
40+
41+
$checkUserPermissions = getSettingByScope($connection2, 'Data Admin', 'enableUserLevelPermissions');
42+
3343
// Get a list of available import options
3444
$importTypeList = ImportType::loadImportTypeList($pdo, false);
3545

36-
if (count($importTypeList)<1) {
37-
echo "<div class='error'>" ;
38-
echo __("There are no records to display.") ;
39-
echo "</div>" ;
40-
} else {
41-
$checkUserPermissions = getSettingByScope($connection2, 'Data Admin', 'enableUserLevelPermissions');
42-
43-
$grouping = '';
44-
foreach ($importTypeList as $importTypeName => $importType) {
45-
if (!$importType->isValid()) {
46-
continue;
47-
}
48-
49-
if ($grouping != $importType->getDetail('grouping')) {
50-
if ($grouping != '') {
51-
echo "</table><br/>" ;
52-
}
53-
54-
$grouping = $importType->getDetail('grouping');
55-
56-
echo "<tr class='break'>" ;
57-
echo "<td colspan='5'><h4>".$grouping."</h4></td>" ;
58-
echo "</tr>" ;
59-
60-
echo "<table class='fullWidth colorOddEven' cellspacing='0'>" ;
61-
62-
echo "<tr class='head'>" ;
63-
echo "<th style='width: 15%;padding: 5px 5px 5px 20px !important;'>" ;
64-
echo __("Category") ;
65-
echo "</th>" ;
66-
echo "<th style='width: 23%;padding: 5px !important;'>" ;
67-
echo __("Name") ;
68-
echo "</th>" ;
69-
echo "<th style='width: 35%;padding: 5px !important;'>" ;
70-
echo __("Description") ;
71-
echo "</th>" ;
72-
echo "<th style='width: 15%;padding: 5px !important;'>" ;
73-
echo __("Last Run", 'Data Admin') ;
74-
echo "</th>" ;
75-
echo "<th style='width: 12%;padding: 5px !important;'>" ;
76-
echo __("Actions") ;
77-
echo "</th>" ;
78-
echo "</tr>" ;
79-
}
80-
81-
echo "<tr>" ;
82-
echo "<td>" . $importType->getDetail('category'). "</td>" ;
83-
echo "<td>" . $importType->getDetail('name'). "</td>" ;
84-
echo "<td>" . $importType->getDetail('desc'). "</td>" ;
85-
echo "<td>";
86-
87-
$data=array('type' => $importTypeName);
88-
$sql = "SELECT gibbonPerson.surname, gibbonPerson.preferredName, gibbonLog.timestamp
89-
FROM gibbonLog
90-
JOIN gibbonPerson ON (gibbonPerson.gibbonPersonID=gibbonLog.gibbonPersonID)
91-
WHERE gibbonLog.title = CONCAT('Import - ', :type)
92-
ORDER BY gibbonLog.timestamp DESC LIMIT 1" ;
93-
$result=$pdo->executeQuery($data, $sql);
94-
95-
if ($pdo->getQuerySuccess() && $result->rowCount()>0) {
96-
$log = $result->fetch();
97-
printf("<span title='%s by %s %s'>%s</span> ", $log['timestamp'], $log['preferredName'], $log['surname'], date('M j, Y', strtotime($log['timestamp'])));
98-
}
99-
100-
echo "</td>";
101-
echo "<td>";
102-
103-
if ($checkUserPermissions == 'Y' && $importType->isImportAccessible($guid, $connection2)) {
104-
echo "<a href='" . $_SESSION[$guid]["absoluteURL"] . "/index.php?q=/modules/" . $_SESSION[$guid]["module"] . "/import_run.php&type=" . $importTypeName . "'><img title='" . __('Import', 'Data Admin') . "' src='./themes/" . $_SESSION[$guid]["gibbonThemeName"] . "/img/run.png'/></a> " ;
105-
echo "<a href='" . $_SESSION[$guid]["absoluteURL"] . "/modules/" . $_SESSION[$guid]["module"] . "/export_run.php?type=". $importTypeName. "&data=0'><img style='margin-left: 5px' title='" . __('Export Structure', 'Data Admin'). "' src='./themes/" . $_SESSION[$guid]["gibbonThemeName"] . "/img/download.png'/></a>" ;
106-
} else {
107-
echo "<img style='margin-left: 5px' title='" . __('You do not have access to this action.'). "' src='./themes/" . $_SESSION[$guid]["gibbonThemeName"] . "/img/key.png'/>" ;
108-
}
109-
110-
111-
echo "</td>";
112-
echo "</tr>" ;
46+
$importTypeGroups = array_reduce($importTypeList, function ($group, $importType) use ($checkUserPermissions, $guid, $connection2, $logsByType) {
47+
if ($importType->isValid()) {
48+
$type = $importType->getDetail('type');
49+
$log = $logsByType['Import - '.$type] ?? [];
50+
51+
$group[$importType->getDetail('grouping', 'System')][] = [
52+
'type' => $type,
53+
'log' => current($log),
54+
'category' => $importType->getDetail('category'),
55+
'name' => $importType->getDetail('name'),
56+
'isAccessible' => $checkUserPermissions == 'Y'
57+
? $importType->isImportAccessible($guid, $connection2)
58+
: true,
59+
];
11360
}
61+
return $group;
62+
}, []);
63+
64+
foreach ($importTypeGroups as $importGroupName => $importTypes) {
65+
$table = DataTable::create('rollGroups');
66+
$table->setTitle(__($importGroupName));
67+
68+
$table->addColumn('category', __('Category'))->width('20%');
69+
$table->addColumn('name', __('Name'));
70+
$table->addColumn('lastRun', __('Last Run'))
71+
->width('25%')
72+
->format(function ($importType) {
73+
if ($log = $importType['log']) {
74+
return '<span title="'.Format::dateTime($log['timestamp']).' - '.Format::nameList([$log]).'">'.Format::dateReadable($log['timestamp']).'</span>';
75+
}
76+
return '';
77+
});
78+
79+
$table->addActionColumn()
80+
->addParam('type')
81+
->format(function ($importType, $actions) {
82+
if ($importType['isAccessible']) {
83+
$actions->addAction('import', __('Import'))
84+
->setIcon('run')
85+
->setURL('/modules/Data Admin/import_run.php');
86+
87+
$actions->addAction('export', __('Export Structure'))
88+
->isDirect()
89+
->addParam('q', $_GET['q'])
90+
->addParam('data', 0)
91+
->setIcon('download')
92+
->setURL('/modules/Data Admin/export_run.php');
93+
}
94+
});
11495

115-
echo "</table><br/>" ;
96+
echo $table->render(new DataSet($importTypes));
11697
}
117-
118-
// Info
119-
echo "<div class='message'>" ;
120-
echo __('This list is being added to with each version. New import types may be added by request, please post requests for new import types on the forum thread <a href="https://ask.gibbonedu.org/discussion/895/data-import-module">here</a>.', 'Data Admin');
121-
echo "</div>" ;
12298
}

0 commit comments

Comments
 (0)