private function parsePriceExcelXML reader new XMLReader reader- open

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
private function parsePriceExcelXML(){
$reader = new XMLReader();
$reader->open($this->filename, 'utf-8');
$row = 1;
$col = -1;
$search_array = $this->parse_rules['columns'];
while($reader->read()){
if($reader->nodeType == XMLReader::ELEMENT && $reader->name == 'Row'){
continue;
}
if($reader->nodeType == XMLReader::ELEMENT && $reader->name == 'Cell'){
$col++;
continue;
}
if($reader->nodeType == XMLReader::TEXT){
$key = array_search($col, $search_array);
if($key){
$this->data[$row][$key] = $reader->value;
}
continue;
}
if($reader->nodeType == XMLReader::END_ELEMENT && $reader->name == 'Row'){
$row++;
$col = -1;
}
if($reader->nodeType == XMLReader::END_ELEMENT && $reader->name == 'Table' ){
break;
}
}
//array_splice($this->data, 300);
unset($reader, $row, $col);
$rules = &$this->parse_rules;
$data_link = &$this->data;
foreach($data_link as $key => &$value){
if((isset($rules['columns']['isbn']) && preg_match('/^[0-9a-zа-я\-]{5,}$/iu', trim($value['isbn']))) || (isset($rules['columns']['ean']) && preg_match('/^\d{3,}$/',trim($value['ean'])))){
if(isset($rules['columns']['pubhouse'])){
$pubhouse_id = $this->searchPubhouseID($value['pubhouse']);
if($pubhouse_id){
//array_search()
if(in_array($pubhouse_id, $this->neededPubhouses)){
$value['pubhouse'] = $pubhouse_id;
if($this->verbose_output) echo "Pubhouse $pubhouse_id recognized and found in needed!\n";
}else{
if($this->verbose_output) echo "Pubhouse $pubhouse_id recognized, but no in needed!\n";
unset($data_link[$key]);
continue;
}
}else{
if($this->verbose_output) echo "Can't recognize pubhouse '".$value['pubhouse']."'\n";
unset($data_link[$key]);
continue;
}
}
}else{
unset($data_link[$key]);
}
}
unset($data_link, $value);
$this->cleanData();
}