XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
DataDownloadAction.class.php
1<?php
10
11if (!defined('XOOPS_ROOT_PATH')) {
12 exit();
13}
14
15require_once XOOPS_MODULE_PATH . '/profile/class/AbstractListAction.class.php';
16
18{
19 public function &_getHandler()
20 {
21 $handler =& xoops_getmodulehandler('data');
22 return $handler;
23 }
24
25 public function &_getBaseUrl()
26 {
27 return './index.php?action=DataDownload';
28 }
29
30 public function executeViewIndex(&$render)
31 {
32 $render->setTemplateName('data_download.html');
33 $handler =& $this->_getHandler();
34 $count = $handler->getCount();
35 $render->setAttribute('profileCount', $count);
36 }
37
38 public function getDefaultView()
39 {
40 return PROFILE_FRAME_VIEW_INDEX;
41 }
42
43
45 public function execute()
46 {
47 $handler =& $this->_getHandler();
48 $count = $handler->getCount();
49 if (0 == $count) {
50 return PROFILE_FRAME_VIEW_INDEX;
51 }
52 $filename = sprintf('%s_Profile_data_List.csv', $GLOBALS['xoopsConfig']['sitename']);
53
54 if (preg_match('/firefox/i', xoops_getenv('HTTP_USER_AGENT'))) {
55 header('Content-Type: application/x-csv');
56 } else {
57 header('Content-Type: application/vnd.ms-excel');
58 }
59 header("Content-Disposition: attachment ; filename=\"{$filename}\"");
60
61 $offset = 0;
62 $limit = 20;
63 $fp = fopen('php://output', 'w');
64
65 $defHandler =& xoops_getmodulehandler('definitions');
66 $defArr =& $defHandler->getDefinitions(false);
67 $label = ['uid'];
68 $columns = ['uid'];
69 foreach ($defArr as $column => $obj) {
70 $label[] = $this->_encoding($obj->get('label'));
71 $columns[] = $obj->get('field_name');
72 }
73 fputcsv($fp, $label, ',', '"');
74
75 $criteria = new CriteriaElement();
76 $criteria->setSort('uid');
77 $criteria->setLimit($limit);
78 for ($i = 1; $offset < $count; $i++) {
79 $criteria->setStart($offset);
80 $dataArr = $handler->getObjects($criteria);
81 foreach ($dataArr as $profile) {
82 $data = [];
83 foreach ($columns as $column) {
84 if (isset($defArr[$column]) && 'date' == $defArr[$column]->get('type')) {
85 $value = $value ? formatTimestamp($profile->get($column), 'Y/n/j H:i') : '';
86 } else {
87 $value = $this->_encoding($profile->get($column));
88 }
89 $data[] = $value;
90 }
91 fputcsv($fp, $data, ',', '"');
92 }
93 $offset = $i * $limit;
94 }
95 fclose($fp);
96 exit();
97 }
98
99 protected function _encoding($text)
100 {
101 // japanese
102 if (0 === strncasecmp($GLOBALS['xoopsConfig']['language'], 'ja', 2)) {
103 mb_convert_variables('SJIS', _CHARSET, $text);
104 }
105 return $text;
106 }
107}
execute()
CSVγƒ•γ‚‘γ‚€γƒ«γ‚’ε‡ΊεŠ›γ™γ‚‹