Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
orderdocument.php
1<?php
2
4
5
7{
11 static public function getFieldsInfo()
12 {
13 return array_merge(
14 parent::getFieldsInfo(),
15 array('SUBORDINATES'=>array())
16 );
17 }
18
23 static public function prepareFieldsData(array $document)
24 {
25 $result = parent::prepareFieldsData($document);
26
27 foreach(static::getFieldsInfo() as $k=>$v)
28 {
29 switch($k)
30 {
31 case 'SUBORDINATES':
32 $result[$k] = self::resolveSubordinateDocuments($document);
33 break;
34 }
35 }
36 return $result;
37 }
38
43 protected static function resolveSubordinateDocuments($value)
44 {
45 $result = null;
46 $message = self::getMessage();
47
48 if(is_array($value["#"][$message["SALE_EXPORT_SUBORDINATES"]][0]["#"][$message["SALE_EXPORT_SUBORDINATE"]][0]["#"]))
49 {
50 $rawSubordinates = $value["#"][$message["SALE_EXPORT_SUBORDINATES"]][0]["#"][$message["SALE_EXPORT_SUBORDINATE"]];
51
52 foreach ($rawSubordinates as $raw)
53 {
54 $documentTypeId = self::resolveRawDocumentTypeId($raw);
55 $document = DocumentFactory::create($documentTypeId);
56 $result[] = $document::prepareFieldsData($raw);
57 }
58 }
59 return $result;
60 }
61
62 static protected function unitFieldsInfo(&$info)
63 {
64 $info['ITEMS']['FIELDS']['BASE_UNIT'] = array(
65 'TYPE' => 'string'
66 );
67 }
68
74 protected function outputXml(array $fields, $level = 0)
75 {
76 $xml = parent::outputXml($fields, $level);
77
78 foreach ($fields as $name=>$value)
79 {
80 if(is_array($value))
81 {
82 switch ($name)
83 {
84 case 'SUBORDINATES':
85 if(is_array($value) && count($value)>0)
86 {
87 $xml .= $this->openNodeDirectory($level, 'SUBORDINATES');
88 foreach ($value as $v)
89 {
90 $xml .= $this->openNodeDirectory($level+1, 'SUBORDINATE');
91 $typeId = static::resolveDocumentTypeId($v['OPERATION']);
92 if($typeId>0)
93 {
94 $document = DocumentFactory::create($typeId);
95 $document->setFields($v);
96 $xml .= $document->output($level+2);
97 }
98
99 $xml .= $this->closeNodeDirectory($level+1, 'SUBORDINATE');
100 }
101 $xml .= $this->closeNodeDirectory($level, 'SUBORDINATES');
102 }
103 break;
104 }
105 }
106 }
107 return $xml;
108 }
109}
static resolveRawDocumentTypeId(array $document)