Improved the export feature to allow bulk custom overide, and dynamic behaviour towards larger sets. Added function name to custom buttons as a class for CSS styling.
This commit is contained in:
@@ -1637,6 +1637,9 @@ class Interpretation extends Fields
|
||||
$exel[] = $this->_t(3) . "->setLastModifiedBy(\$modified)";
|
||||
$exel[] = $this->_t(3) . "->setTitle(\$title)";
|
||||
$exel[] = $this->_t(3) . "->setSubject(\$subjectTab);";
|
||||
$exel[] = $this->_t(2) . "//" . $this->setLine(__LINE__)
|
||||
. " The file type";
|
||||
$exel[] = $this->_t(2) . "\$file_type = 'Xls';";
|
||||
$exel[] = $this->_t(2) . "//" . $this->setLine(__LINE__)
|
||||
. " set description";
|
||||
$exel[] = $this->_t(2) . "if (\$description)";
|
||||
@@ -1682,27 +1685,52 @@ class Interpretation extends Fields
|
||||
$exel[] = $this->_t(2) . "));";
|
||||
$exel[] = PHP_EOL . $this->_t(2) . "//" . $this->setLine(__LINE__)
|
||||
. " Add some data";
|
||||
$exel[] = $this->_t(2) . "if (self::checkArray(\$rows))";
|
||||
$exel[] = $this->_t(2) . "if ((\$size = self::checkArray(\$rows)) !== false)";
|
||||
$exel[] = $this->_t(2) . "{";
|
||||
$exel[] = $this->_t(3) . "\$i = 1;";
|
||||
$exel[] = $this->_t(3) . "foreach (\$rows as \$array){";
|
||||
$exel[] = PHP_EOL . $this->_t(3) . "//" . $this->setLine(__LINE__)
|
||||
. " Based on data size we adapt the behaviour.";
|
||||
$exel[] = $this->_t(3) . "\$xls_mode = 1;";
|
||||
$exel[] = $this->_t(3) . "if (\$size > 3000)";
|
||||
$exel[] = $this->_t(3) . "{";
|
||||
$exel[] = $this->_t(4) . "\$xls_mode = 3;";
|
||||
$exel[] = $this->_t(4) . "\$file_type = 'Csv';";
|
||||
$exel[] = $this->_t(3) . "}";
|
||||
$exel[] = $this->_t(3) . "elseif (\$size > 2000)";
|
||||
$exel[] = $this->_t(3) . "{";
|
||||
$exel[] = $this->_t(4) . "\$xls_mode = 2;";
|
||||
$exel[] = $this->_t(3) . "}";
|
||||
$exel[] = PHP_EOL . $this->_t(3) . "//" . $this->setLine(__LINE__)
|
||||
. " Set active sheet and get it.";
|
||||
$exel[] = $this->_t(3) . "\$active_sheet = \$spreadsheet->setActiveSheetIndex(0);";
|
||||
$exel[] = $this->_t(3) . "foreach (\$rows as \$array)";
|
||||
$exel[] = $this->_t(3) . "{";
|
||||
$exel[] = $this->_t(4) . "\$a = 'A';";
|
||||
$exel[] = $this->_t(4) . "foreach (\$array as \$value){";
|
||||
$exel[] = $this->_t(4) . "foreach (\$array as \$value)";
|
||||
$exel[] = $this->_t(4) . "{";
|
||||
$exel[] = $this->_t(5)
|
||||
. "\$spreadsheet->setActiveSheetIndex(0)->setCellValue(\$a.\$i, \$value);";
|
||||
$exel[] = $this->_t(5) . "if (\$i == 1){";
|
||||
$exel[] = $this->_t(6)
|
||||
. "\$spreadsheet->getActiveSheet()->getColumnDimension(\$a)->setAutoSize(true);";
|
||||
$exel[] = $this->_t(6)
|
||||
. "\$spreadsheet->getActiveSheet()->getStyle(\$a.\$i)->applyFromArray(\$headerStyles);";
|
||||
$exel[] = $this->_t(6)
|
||||
. "\$spreadsheet->getActiveSheet()->getStyle(\$a.\$i)->getAlignment()->setHorizontal(PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER);";
|
||||
$exel[] = $this->_t(5) . "} elseif (\$a === 'A'){";
|
||||
$exel[] = $this->_t(6)
|
||||
. "\$spreadsheet->getActiveSheet()->getStyle(\$a.\$i)->applyFromArray(\$sideStyles);";
|
||||
$exel[] = $this->_t(5) . "} else {";
|
||||
$exel[] = $this->_t(6)
|
||||
. "\$spreadsheet->getActiveSheet()->getStyle(\$a.\$i)->applyFromArray(\$normalStyles);";
|
||||
. "\$active_sheet->setCellValue(\$a.\$i, \$value);";
|
||||
$exel[] = $this->_t(5) . "if (\$xls_mode != 3)";
|
||||
$exel[] = $this->_t(5) . "{";
|
||||
$exel[] = $this->_t(6) . "if (\$i == 1)";
|
||||
$exel[] = $this->_t(6) . "{";
|
||||
$exel[] = $this->_t(7)
|
||||
. "\$active_sheet->getColumnDimension(\$a)->setAutoSize(true);";
|
||||
$exel[] = $this->_t(7)
|
||||
. "\$active_sheet->getStyle(\$a.\$i)->applyFromArray(\$headerStyles);";
|
||||
$exel[] = $this->_t(7)
|
||||
. "\$active_sheet->getStyle(\$a.\$i)->getAlignment()->setHorizontal(PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER);";
|
||||
$exel[] = $this->_t(6) . "}";
|
||||
$exel[] = $this->_t(6) . "elseif (\$a === 'A')";
|
||||
$exel[] = $this->_t(6) . "{";
|
||||
$exel[] = $this->_t(7)
|
||||
. "\$active_sheet->getStyle(\$a.\$i)->applyFromArray(\$sideStyles);";
|
||||
$exel[] = $this->_t(6) . "}";
|
||||
$exel[] = $this->_t(6) . "elseif (\$xls_mode == 1)";
|
||||
$exel[] = $this->_t(6) . "{";
|
||||
$exel[] = $this->_t(7)
|
||||
. "\$active_sheet->getStyle(\$a.\$i)->applyFromArray(\$normalStyles);";
|
||||
$exel[] = $this->_t(6) . "}";
|
||||
$exel[] = $this->_t(5) . "}";
|
||||
$exel[] = $this->_t(5) . "\$a++;";
|
||||
$exel[] = $this->_t(4) . "}";
|
||||
@@ -1725,7 +1753,7 @@ class Interpretation extends Fields
|
||||
$exel[] = $this->_t(2)
|
||||
. "header('Content-Type: application/vnd.ms-excel');";
|
||||
$exel[] = $this->_t(2)
|
||||
. "header('Content-Disposition: attachment;filename=\"'.\$fileName.'.xls\"');";
|
||||
. "header('Content-Disposition: attachment;filename=\"' . \$fileName . '.' . strtolower(\$file_type) .'\"');";
|
||||
$exel[] = $this->_t(2) . "header('Cache-Control: max-age=0');";
|
||||
$exel[] = $this->_t(2) . "//" . $this->setLine(__LINE__)
|
||||
. " If you're serving to IE 9, then the following may be needed";
|
||||
@@ -1744,7 +1772,7 @@ class Interpretation extends Fields
|
||||
$exel[] = $this->_t(2) . "header ('Pragma: public'); //"
|
||||
. $this->setLine(__LINE__) . " HTTP/1.0";
|
||||
$exel[] = PHP_EOL . $this->_t(2)
|
||||
. "\$writer = IOFactory::createWriter(\$spreadsheet, 'Xls');";
|
||||
. "\$writer = IOFactory::createWriter(\$spreadsheet, \$file_type);";
|
||||
$exel[] = $this->_t(2) . "\$writer->save('php://output');";
|
||||
$exel[] = $this->_t(2) . "jexit();";
|
||||
$exel[] = $this->_t(1) . "}";
|
||||
@@ -5631,7 +5659,8 @@ class Interpretation extends Fields
|
||||
$buttons[] = $this->_t(1) . $tab . $this->_t(2)
|
||||
. "JToolBarHelper::custom('" . $viewName . "."
|
||||
. $custom_button['method'] . "', '"
|
||||
. $custom_button['icomoon'] . "', '', '" . $keyLang
|
||||
. $custom_button['icomoon'] . " custom-button-"
|
||||
. strtolower($custom_button['method']) . "', '', '" . $keyLang
|
||||
. "', false);";
|
||||
$buttons[] = $this->_t(1) . $tab . $this->_t(1) . "}";
|
||||
}
|
||||
@@ -5665,7 +5694,8 @@ class Interpretation extends Fields
|
||||
) . $tab . $this->_t(1)
|
||||
. "JToolBarHelper::custom('" . $viewsName . "."
|
||||
. $custom_button['method'] . "', '"
|
||||
. $custom_button['icomoon'] . "', '', '"
|
||||
. $custom_button['icomoon'] . " custom-button-"
|
||||
. strtolower($custom_button['method']) . "', '', '"
|
||||
. $keyLang . "', false);";
|
||||
$this->onlyFunctionButton[$viewsName][] = $this->_t(
|
||||
1
|
||||
@@ -5685,7 +5715,8 @@ class Interpretation extends Fields
|
||||
$buttons[] = $this->_t(1) . $tab . $this->_t(2)
|
||||
. "JToolBarHelper::custom('" . $viewsName . "."
|
||||
. $custom_button['method'] . "', '"
|
||||
. $custom_button['icomoon'] . "', '', '"
|
||||
. $custom_button['icomoon'] . " custom-button-"
|
||||
. strtolower($custom_button['method']) . "', '', '"
|
||||
. $keyLang . "', '" . $validateSelection
|
||||
. "');";
|
||||
$buttons[] = $this->_t(1) . $tab . $this->_t(1)
|
||||
@@ -14365,9 +14396,9 @@ class Interpretation extends Fields
|
||||
$query .= PHP_EOL . $this->_t(1) . "{";
|
||||
$query .= PHP_EOL . $this->_t(2) . "//" . $this->setLine(__LINE__)
|
||||
. " setup the query";
|
||||
$query .= PHP_EOL . $this->_t(2) . "if ("
|
||||
$query .= PHP_EOL . $this->_t(2) . "if ((\$pks_size = "
|
||||
. $this->fileContentStatic[$this->hhh . 'Component'
|
||||
. $this->hhh] . "Helper::checkArray(\$pks))";
|
||||
. $this->hhh] . "Helper::checkArray(\$pks)) !== false || 'bulk' === \$pks)";
|
||||
$query .= PHP_EOL . $this->_t(2) . "{";
|
||||
$query .= PHP_EOL . $this->_t(3) . "//" . $this->setLine(__LINE__)
|
||||
. " Set a value to know this is " . $config['type']
|
||||
@@ -14399,8 +14430,39 @@ class Interpretation extends Fields
|
||||
. "\$query->from(\$db->quoteName('#__"
|
||||
. $this->componentCodeName . "_" . $viewName_single
|
||||
. "', 'a'));";
|
||||
$query .= PHP_EOL . $this->_t(3) . "//" . $this->setLine(__LINE__)
|
||||
. " The bulk export path";
|
||||
$query .= PHP_EOL . $this->_t(3) . "if ('bulk' === \$pks)";
|
||||
$query .= PHP_EOL . $this->_t(3)
|
||||
. "{";
|
||||
$query .= PHP_EOL . $this->_t(4)
|
||||
. "\$query->where('a.id > 0');";
|
||||
$query .= PHP_EOL . $this->_t(3)
|
||||
. "}";
|
||||
$query .= PHP_EOL . $this->_t(3) . "//" . $this->setLine(__LINE__)
|
||||
. " A large array of ID's will not work out well";
|
||||
$query .= PHP_EOL . $this->_t(3) . "elseif (\$pks_size > 500)";
|
||||
$query .= PHP_EOL . $this->_t(3)
|
||||
. "{";
|
||||
$query .= PHP_EOL . $this->_t(4) . "//" . $this->setLine(__LINE__)
|
||||
. " Use lowest ID";
|
||||
$query .= PHP_EOL . $this->_t(4)
|
||||
. "\$query->where('a.id >= ' . (int) min(\$pks));";
|
||||
$query .= PHP_EOL . $this->_t(4) . "//" . $this->setLine(__LINE__)
|
||||
. " Use highest ID";
|
||||
$query .= PHP_EOL . $this->_t(4)
|
||||
. "\$query->where('a.id <= ' . (int) max(\$pks));";
|
||||
$query .= PHP_EOL . $this->_t(3)
|
||||
. "}";
|
||||
$query .= PHP_EOL . $this->_t(3) . "//" . $this->setLine(__LINE__)
|
||||
. " The normal default path";
|
||||
$query .= PHP_EOL . $this->_t(3) . "else";
|
||||
$query .= PHP_EOL . $this->_t(3)
|
||||
. "{";
|
||||
$query .= PHP_EOL . $this->_t(4)
|
||||
. "\$query->where('a.id IN (' . implode(',',\$pks) . ')');";
|
||||
$query .= PHP_EOL . $this->_t(3)
|
||||
. "}";
|
||||
// add custom filtering php
|
||||
$query .= $this->getCustomScriptBuilder(
|
||||
'php_getlistquery', $viewName_single,
|
||||
|
@@ -6309,6 +6309,8 @@ abstract class ComponentbuilderHelper
|
||||
->setLastModifiedBy($modified)
|
||||
->setTitle($title)
|
||||
->setSubject($subjectTab);
|
||||
// The file type
|
||||
$file_type = 'Xls';
|
||||
// set description
|
||||
if ($description)
|
||||
{
|
||||
@@ -6348,21 +6350,46 @@ abstract class ComponentbuilderHelper
|
||||
));
|
||||
|
||||
// Add some data
|
||||
if (self::checkArray($rows))
|
||||
if (($size = self::checkArray($rows)) !== false)
|
||||
{
|
||||
$i = 1;
|
||||
foreach ($rows as $array){
|
||||
|
||||
// Based on data size we adapt the behaviour.
|
||||
$xls_mode = 1;
|
||||
if ($size > 3000)
|
||||
{
|
||||
$xls_mode = 3;
|
||||
$file_type = 'Csv';
|
||||
}
|
||||
elseif ($size > 2000)
|
||||
{
|
||||
$xls_mode = 2;
|
||||
}
|
||||
|
||||
// Set active sheet and get it.
|
||||
$active_sheet = $spreadsheet->setActiveSheetIndex(0);
|
||||
foreach ($rows as $array)
|
||||
{
|
||||
$a = 'A';
|
||||
foreach ($array as $value){
|
||||
$spreadsheet->setActiveSheetIndex(0)->setCellValue($a.$i, $value);
|
||||
if ($i == 1){
|
||||
$spreadsheet->getActiveSheet()->getColumnDimension($a)->setAutoSize(true);
|
||||
$spreadsheet->getActiveSheet()->getStyle($a.$i)->applyFromArray($headerStyles);
|
||||
$spreadsheet->getActiveSheet()->getStyle($a.$i)->getAlignment()->setHorizontal(PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER);
|
||||
} elseif ($a === 'A'){
|
||||
$spreadsheet->getActiveSheet()->getStyle($a.$i)->applyFromArray($sideStyles);
|
||||
} else {
|
||||
$spreadsheet->getActiveSheet()->getStyle($a.$i)->applyFromArray($normalStyles);
|
||||
foreach ($array as $value)
|
||||
{
|
||||
$active_sheet->setCellValue($a.$i, $value);
|
||||
if ($xls_mode != 3)
|
||||
{
|
||||
if ($i == 1)
|
||||
{
|
||||
$active_sheet->getColumnDimension($a)->setAutoSize(true);
|
||||
$active_sheet->getStyle($a.$i)->applyFromArray($headerStyles);
|
||||
$active_sheet->getStyle($a.$i)->getAlignment()->setHorizontal(PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER);
|
||||
}
|
||||
elseif ($a === 'A')
|
||||
{
|
||||
$active_sheet->getStyle($a.$i)->applyFromArray($sideStyles);
|
||||
}
|
||||
elseif ($xls_mode == 1)
|
||||
{
|
||||
$active_sheet->getStyle($a.$i)->applyFromArray($normalStyles);
|
||||
}
|
||||
}
|
||||
$a++;
|
||||
}
|
||||
@@ -6382,7 +6409,7 @@ abstract class ComponentbuilderHelper
|
||||
|
||||
// Redirect output to a client's web browser (Excel5)
|
||||
header('Content-Type: application/vnd.ms-excel');
|
||||
header('Content-Disposition: attachment;filename="'.$fileName.'.xls"');
|
||||
header('Content-Disposition: attachment;filename="' . $fileName . '.' . strtolower($file_type) .'"');
|
||||
header('Cache-Control: max-age=0');
|
||||
// If you're serving to IE 9, then the following may be needed
|
||||
header('Cache-Control: max-age=1');
|
||||
@@ -6393,7 +6420,7 @@ abstract class ComponentbuilderHelper
|
||||
header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
|
||||
header ('Pragma: public'); // HTTP/1.0
|
||||
|
||||
$writer = IOFactory::createWriter($spreadsheet, 'Xls');
|
||||
$writer = IOFactory::createWriter($spreadsheet, $file_type);
|
||||
$writer->save('php://output');
|
||||
jexit();
|
||||
}
|
||||
|
Reference in New Issue
Block a user