|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Upload users file class |
|
5
|
|
|
* |
|
6
|
|
|
* @package upload_users |
|
7
|
|
|
* @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2 |
|
8
|
|
|
* @author Jaakko Naakka / Mediamaisteri Group |
|
9
|
|
|
* @author Ismayil Khayredinov / Arck Interactive |
|
10
|
|
|
* @copyright Mediamaisteri Group 2009 |
|
11
|
|
|
* @copyright ArckInteractive 2013 |
|
12
|
|
|
* @link http://www.mediamaisteri.com/ |
|
13
|
|
|
* @link http://arckinteractive.com/ |
|
14
|
|
|
*/ |
|
15
|
|
|
class UploadUsersFile extends ElggFile { |
|
16
|
|
|
|
|
17
|
|
|
protected function initializeAttributes() { |
|
18
|
|
|
parent::initializeAttributes(); |
|
19
|
|
|
|
|
20
|
|
|
$this->attributes['subtype'] = "upload_users_file"; |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
public function __construct($guid = null) { |
|
24
|
|
|
parent::__construct($guid); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
function parseCSVHeader() { |
|
28
|
|
|
if (($handle = fopen($this->getFilenameOnFilestore(), 'r')) !== FALSE) { |
|
29
|
|
|
return fgetcsv($handle, 0, $this->delimiter, $this->enclosure); |
|
30
|
|
|
} |
|
31
|
|
|
return false; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
function parseCSV() { |
|
35
|
|
|
$data = array(); |
|
36
|
|
|
if (($handle = fopen($this->getFilenameOnFilestore(), 'r')) !== FALSE) { |
|
37
|
|
|
while (($row = fgetcsv($handle, 0, $this->delimiter, $this->enclosure)) !== FALSE) { |
|
38
|
|
|
if (empty($headers)) { |
|
39
|
|
|
$headers = $row; |
|
40
|
|
|
} else { |
|
41
|
|
|
$data[] = array_combine($headers, $row); |
|
42
|
|
|
} |
|
43
|
|
|
} |
|
44
|
|
|
fclose($handle); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
return $data; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
function setHeaderMapping($mapping = array()) { |
|
51
|
|
|
$this->header_mapping = serialize($mapping); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
function getHeaderMapping() { |
|
55
|
|
|
return (isset($this->header_mapping)) ? unserialize($this->header_mapping) : null; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
function setRequiredFieldMapping($mapping = array()) { |
|
59
|
|
|
$this->required_fields_mapping = serialize($mapping); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
function getRequiredFieldMapping() { |
|
63
|
|
|
return (isset($this->required_fields_mapping)) ? unserialize($this->required_fields_mapping) : null; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
function setStatus($status = '') { |
|
67
|
|
|
$this->status = $status; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
function getStatus() { |
|
71
|
|
|
return ($this->status) ? $this->status : 'uploaded'; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
} |
|
75
|
|
|
|