-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConvertRezult.php
54 lines (50 loc) · 1.62 KB
/
ConvertRezult.php
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
<?php
class ConvertRezult
{
private function arrayToXml($data, &$xmlData) {
foreach($data as $key => $value) {
if(is_array($value)) {
$subnode = $xmlData->addChild("$key");
$this->arrayToXml($value, $subnode);
}
else {
$xmlData->addChild("$key","$value");
}
}
}
public function convertToXML($data){
$xmlData = new SimpleXMLElement("<?xml version=\"1.0\"?><data></data>");
$this->arrayToXml($data, $xmlData);
return $xmlData;
}
private function FindThumbByID($AllFilesShuter, $id){
foreach ($AllFilesShuter as $value) {
if($value['id'] == $id){
return $value['thumb'];
break;
}
}
}
private function NormalizationOfDataArray($data, $AllFilesShuter){
foreach ($data as $value) {
$value['shutterstock_thumb'] = $this->FindThumbByID($AllFilesShuter , $value['shutterstock_item_id']);
}
return $data;
}
/*
IN: $data: array('item_id' , 'title', 'keywords', 'shutterstock_item_id')
OUT: json($data)
*/
public function convertToJson($data, $folder, $AllFilesShuter){
$data = $this->NormalizationOfDataArray($data, $AllFilesShuter);
$data = json_encode(array('items' => $data), JSON_PRETTY_PRINT);
file_put_contents("./resultFor".$folder.".txt", $data);
return $data;
}
}
// $converter = new ConverToXml();
// var_dump($converter->convert(array(array('ddd'=>'val1', 'ccc'=>'val2', 'eee'=>'val3'),
// array('ddd'=>'val11', 'ccc'=>'val22', 'eee'=>'val33'),
// array('ddd'=>'val111', 'ccc'=>'val222', 'eee'=>'val333'),
// array('ddd'=>'val1111', 'ccc'=>'val2222', 'eee'=>'val3333')
// )));