1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the jquery-datatables-bundle package. |
5
|
|
|
* |
6
|
|
|
* (c) 2018 WEBEWEB |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace WBW\Bundle\JQuery\DataTablesBundle\Helper; |
13
|
|
|
|
14
|
|
|
use DeviceDetector\DeviceDetector; |
15
|
|
|
use Symfony\Component\HttpFoundation\Request; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* DataTables export helper. |
19
|
|
|
* |
20
|
|
|
* @author webeweb <https://github.com/webeweb/> |
21
|
|
|
* @package WBW\Bundle\JQuery\DataTablesBundle\Helper |
22
|
|
|
*/ |
23
|
|
|
class DataTablesExportHelper { |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Convert. |
27
|
|
|
* |
28
|
|
|
* @param array $values The values. |
29
|
|
|
* @param bool $windows Windows ? |
30
|
|
|
* @return array Returns the converted values. |
31
|
|
|
*/ |
32
|
|
|
public static function convert(array $values, $windows = false) { |
33
|
|
|
if (true === $windows) { |
34
|
|
|
for ($i = count($values) - 1; 0 <= $i; --$i) { |
35
|
|
|
$values[$i] = utf8_decode($values[$i]); |
36
|
|
|
} |
37
|
|
|
} |
38
|
|
|
return $values; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Determines if the operating system is windows. |
43
|
|
|
* |
44
|
|
|
* @param Request $request The request. |
45
|
|
|
* @return bool Returns true in case of success. |
46
|
|
|
*/ |
47
|
|
|
public static function isWindows(Request $request) { |
48
|
|
|
|
49
|
|
|
// Check the headers. |
50
|
|
|
if (false === $request->headers->has("user-agent")) { |
51
|
|
|
return false; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
// Initialize a device detector. |
55
|
|
|
$dd = new DeviceDetector($request->headers->get("user-agent")); |
56
|
|
|
$dd->parse(); |
57
|
|
|
|
58
|
|
|
// Get the operating system. |
59
|
|
|
$os = $dd->getOs("name"); |
60
|
|
|
if (DeviceDetector::UNKNOWN === $os || 0 === preg_match("/Windows/", $os)) { |
61
|
|
|
return false; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
// |
65
|
|
|
return true; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
} |
69
|
|
|
|