1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
client.php
См. документацию.
1<?
3{
4 protected $bInit = false;
5 protected $RESPONSE;
7
8 protected $ATTACHMENTS_PATH = '/upload/sharepoint';
9
10 /* public section */
11
12 public function __construct($arParams)
13 {
14 if (is_array($arParams))
15 {
17 }
18 }
19
21 {
22 $arDefaultParams = array(
23 'scheme' => 'http',
24 'host' => '',
25 'port' => 80,
26 'user' => '',
27 'pass' => '',
28 'path' => WS_SP_SERVICE_PATH,
29 'query' => '',
30 'fragment' => ''
31 );
32
33 $arParams['path'] = WS_SP_SERVICE_PATH; // temporary.
34
35 foreach ($arDefaultParams as $param => $value)
36 $this->arConnectionParams[$param] = isset($arParams[$param]) ? $arParams[$param] : $value;
37
38 if ($this->arConnectionParams['scheme'] == 'https')
39 $this->arConnectionParams['port'] = 443;
40 elseif ($this->arConnectionParams['port'] == 443)
41 $this->arConnectionParams['scheme'] = 'https';
42
43 return $this->__initialize();
44 }
45
46 public function Call($method, $arParams = array())
47 {
49 $this->RESPONSE = $this->send($REQUEST);
50
51 if (!$this->RESPONSE)
52 {
53 $GLOBALS['APPLICATION']->ThrowException('Connection error!');
54 return false;
55 }
56 elseif ($this->RESPONSE->isFault())
57 {
58 $GLOBALS['APPLICATION']->ThrowException('SOAP Fault '.$this->RESPONSE->faultCode().': '.$this->RESPONSE->faultString());
59 return false;
60 }
61 else
62 {
63 return true;
64 }
65 }
66
67 /* ws methods functions */
68 public function GetListCollection()
69 {
70 if (
71 $this->__initialize()
72 && $this->Call('GetListCollection')
73 && ($DOM = $this->RESPONSE->DOMDocument)
74 )
75 {
76 $arListNodes = $DOM->elementsByName('List');
77
78 if (!is_array($arListNodes) || count($arListNodes) <= 0)
79 {
80 return array();
81 }
82 else
83 {
84 $arLists = array();
85 foreach ($arListNodes as $node)
86 {
87 $arLists[] = array(
88 'ID' => $node->getAttribute('ID'),
89 'URL' => $node->getAttribute('DefaultViewUrl'),
90 'TITLE' => $node->getAttribute('Title'),
91 'DESCRIPTION' => $node->getAttribute('Description'),
92 'IMAGE' => $node->getAttribute('ImageUrl'),
93 );
94 }
95
96 return $this->GetListCollectionProcessResult($arLists);
97 }
98 }
99 else
100 return false;
101 }
102
103 protected function _GetByID_query($XML_ID)
104 {
105 $node = new CXMLCreator('Eq');
106 $node->addChild(CXMLCreator::createTagAttributed('FieldRef Name="ID"'));
107 $node->addChild(CXMLCreator::createTagAttributed('Value Type="integer"', intval($XML_ID)));
108
109 return $node;
110 }
111
112 public function GetByID($listName, $XML_ID)
113 {
114 $RESULT = false;
115
116 $arMethodParams = array('listName' => $listName);
117
118 $query = new CXMLCreator('Query');
119 $query->addChild(new CXMLCreator('Where'));
120
121 if (!is_array($XML_ID))
122 $query->children[0]->addChild($this->_GetByID_query($XML_ID));
123 elseif (count($XML_ID) == 1)
124 $query->children[0]->addChild($this->_GetByID_query($XML_ID[0]));
125 else
126 {
127 $obOr = new CXMLCreator('Or');
128
129 foreach ($XML_ID as $item)
130 {
131 $obOr->addChild($this->_GetByID_query($item));
132 }
133
134 $query->children[0]->addChild($obOr);
135 }
136
137 $arMethodParams['query'] = $query;
138
139 if (
140 $this->__initialize()
141 && $this->Call('GetListItems', $arMethodParams)
142 && ($DOM = $this->RESPONSE->DOMDocument)
143 )
144 {
145 $DATA_NODE = $DOM->elementsByName('data');
146 if (is_array($DATA_NODE) && count($DATA_NODE) > 0)
147 {
148 $RESULT = $this->ConvertRows($DATA_NODE[0]);
149 }
150 }
151
152 return $this->GetByIDProcessResult($RESULT);
153 }
154
155 public function GetList($listName)
156 {
157 if (
158 $this->__initialize()
159 && $this->Call('GetList', array('listName' => $listName))
160 && ($DOM = $this->RESPONSE->DOMDocument)
161 )
162 {
163 $RESULT = array('PARAMS' => array(), 'FIELDS' => array());
164
165 $LIST = $DOM->elementsByName('List');
166 $LIST = $LIST[0];
167
168 $ar = $LIST->getAttributes();
169 foreach ($ar as $attr)
170 {
171 $RESULT['PARAMS'][$attr->name()] = $attr->textContent();
172 }
173
174 $arFieldNodes = $LIST->elementsByName('Field');
175
176 if (is_array($arFieldNodes) && count($arFieldNodes) > 0)
177 {
178 foreach ($arFieldNodes as $node)
179 {
180 $ar = $node->getAttributes();
181 $arField = array();
182 foreach ($ar as $attr)
183 {
184 $arField[$attr->name()] = $attr->textContent();
185 }
186
187 if ($arField['ID'])
188 {
189 if ($arField['Type'] == 'Choice' || $arField['Type'] == 'MultiChoice')
190 {
191 $arChoiceNodes = $node->elementsByName('CHOICE');
192 $arField['CHOICE'] = array();
193 foreach ($arChoiceNodes as $choice_node)
194 {
195 $arField['CHOICE'][] = $choice_node->textContent();
196 }
197
198 $arDefaultNodes = $arChoiceNodes = $node->elementsByName('Default');
199 if (count($arDefaultNodes) > 0)
200 $arField['DEFAULT'] = $arDefaultNodes[0]->textContent();
201 }
202
203 $RESULT['FIELDS'][] = $arField;
204 }
205 }
206 }
207
208 return $this->GetListProcessResult($RESULT);
209 }
210
211 return false;
212 }
213
214/*
215 Paging work algorithm:
216
217 1. No changeToken
218 1.1. Send Query w/o changeToken (TOKEN) and with rowLimit (NUM_ROWS);
219 1.2. Recieve Changes section with LastChangeToken (TOKEN), first page of data (DATA) and ListItemCollectionPositionNext (PAGING) param. WARNING! Now's the only chance to remember LastChangeToken - it won't be available during pages navigation
220 1.3. Send another request w/o changeToken (TOKEN) and with rowLimit (NUM_ROWS) and attached queryOptions element with ListItemCollectionPositionNext (PAGING) param taken from previous query
221 1.4. Recieve more rows with new ListItemCollectionPositionNext (PAGING) value
222 1.5. Continue from 1.3 till data is over - no ListItemCollectionPositionNext param recieved
223
224 2. We have changeToken
225 1.1. Send Query with changeToken (TOKEN) and rowLimit (NUM_ROWS)
226 1.2. Recieve rows and Changes section with new LastChangeToken (TOKEN)
227 1.3. Continue to 1.1. with new TOKEN till data is over
228 1.4. Final query will result empty data and unchanged TOKEN;
229
230 WARNING! Don't event try to analyze and change TOKEN and PAGING values! They SHOULD be unchanged for further queries.
231
232 Input:
233 listName - id of a list (ex. {9C00647C-836C-485B-A025-0663F6EE972A})
234 arParams - array(
235 'TOKEN' - token to set timing start of a list
236 'PAGING' - token to set paging
237 'NUM_ROWS' - number of a rows per page
238 'FIELDS' - array with a list of a field names needed
239 )
240
241 Output: array(
242 'MORE_ROWS' => {true|false} - flag "is there more data available"
243 'TOKEN' => string that chould be used for further queries (or for next page query, if it's not a first query)
244 'PAGING' => string that chould be used for next page query (if it's the query w/o TOKEN)
245 'COUNT' => recieved data rows count
246 'DATA' => array of data rows ('ows_' prefix is cutted from attrubute names)
247 )
248*/
249 public function GetListItemChangesSinceToken($listName, $arParams = array())
250 {
251 $arMethodParams = array('listName' => $listName);
252
253 if ($arParams['TOKEN'])
254 $arMethodParams['changeToken'] = $arParams['TOKEN'];
255
256 if ($arParams['NUM_ROWS'])
257 $arMethodParams['rowLimit'] = intval($arParams['NUM_ROWS']);
258
259 $queryOptions = new CXMLCreator('QueryOptions');
260 if (isset($arParams['PAGING']))
261 {
262 $queryOptions->addChild(CXMLCreator::createTagAttributed('Paging ListItemCollectionPositionNext="'.htmlspecialchars($arParams['PAGING']).'"'));
263 }
264
265 $arMethodParams['queryOptions'] = $queryOptions;
266
267 if (is_array($arParams['FIELDS']))
268 {
269 $viewFields = new CXMLCreator('ViewFields');
270 $viewFields->setAttribute('Properties', 'TRUE');
271
272 foreach ($arParams['FIELDS'] as $fld)
273 $viewFields->addChild(CXMLCreator::createTagAttributed('FieldRef Name="'.$fld.'"'));
274
275 $arMethodParams['viewFields'] = $viewFields;
276 }
277
278 if (
279 $this->__initialize()
280 && $this->Call('GetListItemChangesSinceToken', $arMethodParams)
281 && ($DOM = $this->RESPONSE->DOMDocument)
282 )
283 {
284 $RESULT = array();
285
286 $CHANGES = $DOM->elementsByName('Changes');
287
288 $RESULT['MORE_ROWS'] = false;
289 if (is_array($CHANGES) && count($CHANGES) > 0)
290 {
291 $CHANGES = $CHANGES[0];
292 $RESULT['TOKEN'] = $CHANGES->getAttribute('LastChangeToken');
293 $RESULT['MORE_ROWS'] |= ($CHANGES->getAttribute('MoreChanges') == 'TRUE');
294 }
295
296 $DATA_NODE = $DOM->elementsByName('data');
297 if (is_array($DATA_NODE) && count($DATA_NODE) > 0)
298 {
299 $DATA_NODE = $DATA_NODE[0];
300
301 $RESULT['COUNT'] = $DATA_NODE->getAttribute('ItemCount');
302 $RESULT['PAGING'] = $DATA_NODE->getAttribute('ListItemCollectionPositionNext');
303 $RESULT['MORE_ROWS'] |= ($RESULT['PAGING'] <> '');
304
305 $RESULT['DATA'] = $this->ConvertRows($DATA_NODE);
306
307 if (count($RESULT['DATA']) <= 0)
308 $RESULT['MORE_ROWS'] = false;
309 }
310
311 return $this->GetListItemChangesSinceTokenProcessResult($RESULT);
312 }
313
314 return false;
315 }
316
317 public function GetAttachmentCollection($listName, $arParams)
318 {
319 $arMethodParams = array('listName' => $listName);
320 $arMethodParams['listItemID'] = $arParams['SP_ID'];
321
322 if (
323 $this->__initialize()
324 && $this->Call('GetAttachmentCollection', $arMethodParams)
325 && ($DOM = $this->RESPONSE->DOMDocument)
326 )
327 {
328 $RESULT = array();
329
330 $ATTACHMENTS = $DOM->elementsByName('Attachment');
331
332 foreach ($ATTACHMENTS as $ATTACH)
333 {
334 $RESULT[] = $ATTACH->textContent();
335 }
336
337 return $this->GetAttachmentCollectionProcessResult($RESULT);
338 }
339
340 return false;
341 }
342
343 public function UpdateListItems($listName, $arChanges)
344 {
345 $arMethodParams = array('listName' => $listName);
346
347 $updates = CXMLCreator::createTagAttributed('Batch OnError="Continue" DateInUtc="TRUE" Properties="TRUE"');
348
349 $i = 0;
350
351 foreach ($arChanges as $row)
352 {
353 $obRow = CXMLCreator::createTagAttributed('Method ID="'.($i++).'"');
354
355 if ($ID = intval($row['ID']))
356 {
357 $obRow->setAttribute('Cmd', 'Update');
358 }
359 else
360 {
361 $obRow->setAttribute('Cmd', 'New');
362
363 unset($row['ID']);
364
365 $obRow->addChild(CXMLCreator::createTagAttributed('Field Name="ID"', 'New'));
366 $obRow->addChild(CXMLCreator::createTagAttributed('Field Name="MetaInfo" Property="ReplicationID"', $row['ReplicationID']));
367 unset($row['ReplicationID']);
368 }
369
370 foreach ($row as $fld => $value)
371 {
372 if (mb_substr($fld, 0, 9) == 'MetaInfo_')
373 {
374 $obRow->addChild(CXMLCreator::createTagAttributed('Field Name="MetaInfo" Property="'.CXMLCreator::xmlspecialchars(mb_substr($fld, 9)).'"', $value));
375 }
376 else
377 {
378 if ($fld)
379 {
380 $obRow->addChild(CXMLCreator::createTagAttributed('Field Name="'.CXMLCreator::xmlspecialchars($fld).'"', $value));
381 }
382 }
383 }
384
385 $updates->addChild($obRow);
386 }
387
388 $arMethodParams['updates'] = $updates;
389
390 $RESULT = false;
391
392 if (
393 $this->__initialize()
394 && $this->Call('UpdateListItems', $arMethodParams)
395 && ($DOM = $this->RESPONSE->DOMDocument)
396 )
397 {
398 $RESULT = array();
399
400 $arResults = $DOM->elementsByName('Result');
401
402 foreach ($arResults as $resultNode)
403 {
404 $arRes = array(
405 'ErrorCode' => $resultNode->children[0]->textContent(),
406 'Row' => $this->ConvertRows($resultNode),
407 );
408
409 if ($arRes['Row']) $arRes['Row'] = $arRes['Row'][0];
410
411 $RESULT[] = $arRes;
412 }
413
414 }
415
416 return $RESULT;
417 }
418
419 public function LoadFile($listName, $arParams)
420 {
421 if ($arParams['URL'])
422 {
423 // hack!
424 $URL = str_replace(
425 array('%3A', '%2F'),
426 array(':', '/'),
427 rawurlencode(urldecode($arParams['URL']))
428 );
429
430 $CLIENT = new CHTTP();
431 $res = false;
432
433 if ($this->arConnectionParams['user'])
434 {
435 $CLIENT->SetAuthBasic(
436 $this->arConnectionParams['user'],
437 $this->arConnectionParams['pass']
438 );
439 }
440
441 if ($file_contents = $CLIENT->Get($URL))
442 {
443 $point_pos = mb_strrpos($URL, '.');
444 $ext = '';
445
446 $new_filename = md5($URL).($point_pos > 0? mb_substr($URL, $point_pos) : '');
447
448 $new_filepath = $_SERVER['DOCUMENT_ROOT'].$this->ATTACHMENTS_PATH.'/'.mb_substr($new_filename, 0, 2).'/'.$new_filename;
449 CheckDirPath($new_filepath);
450
451 $fp = fopen($new_filepath, 'wb');
452 fwrite($fp, $file_contents);
453 fclose($fp);
454
455 $res = CFile::MakeFileArray($new_filepath);
456 }
457 }
458
459 unset($CLIENT);
460
461 return $res;
462 }
463
464 /* getters */
465 public function GetConnectionParams()
466 {
468 }
469
470 public function GetResponseObject()
471 {
472 return $this->RESPONSE;
473 }
474
475 /* protected section */
476
477 protected function __initialize()
478 {
479 global $APPLICATION;
480
481 if ($this->bInit)
482 return true;
483
484 if (!$this->arConnectionParams['host'])
485 {
486 $APPLICATION->ThrowException('No SP host specified!');
487 return false;
488 }
489
490 $this->CSOAPClient($this->arConnectionParams['host'], $this->arConnectionParams['path'], $this->arConnectionParams['port']);
491
492 if ($this->arConnectionParams['user'])
493 {
494 $this->setLogin($this->arConnectionParams['user']);
495 $this->setPassword($this->arConnectionParams['pass']);
496 }
497
498 $this->bInit = true;
499
500 return true;
501 }
502
503 /* override these methods to add custom processing for method results */
504 protected function GetListCollectionProcessResult($RESULT)
505 {
506 return $RESULT;
507 }
508
509 protected function GetListProcessResult($RESULT)
510 {
511 return $RESULT;
512 }
513
515 {
516 return $RESULT;
517 }
518
519 protected function GetAttachmentCollectionProcessResult($RESULT)
520 {
521 foreach ($RESULT as $key => $file)
522 {
523 $RESULT[$key] = $this->LoadFile('', array('URL' => $file));
524 }
525
526 return $RESULT;
527 }
528
529 protected function GetByIDProcessResult($RESULT)
530 {
531 return $RESULT;
532 }
533
534 protected function ConvertRows($DATA_NODE)
535 {
536 $arRows = array();
537
538 $DATA = $DATA_NODE->elementsByName('row');
539 foreach ($DATA as $row)
540 {
541 $arRow = array();
542 $arAttrs = $row->getAttributes();
543 foreach($arAttrs as $attr)
544 {
545 // cut 'ows' prefix
546 $name = mb_substr($attr->name, 0, 4) == 'ows_'
547 ? mb_substr($attr->name, 4)
548 : $attr->name;
549
550 $arRow[$name] = $attr->content;
551 }
552
553 $arRows[] = $arRow;
554 }
555
556 return $arRows;
557 }
558}
559?>
$arParams
Определения access_dialog.php:21
global $APPLICATION
Определения include.php:80
Определения http.php:7
Определения soapclient.php:4
setLogin( $login)
Определения soapclient.php:129
send( $request)
Определения soapclient.php:39
setPassword( $password)
Определения soapclient.php:149
Определения soaprequest.php:4
Определения client.php:3
_GetByID_query($XML_ID)
Определения client.php:103
GetListItemChangesSinceToken($listName, $arParams=array())
Определения client.php:249
GetListItemChangesSinceTokenProcessResult($RESULT)
Определения client.php:514
UpdateListItems($listName, $arChanges)
Определения client.php:343
GetByID($listName, $XML_ID)
Определения client.php:112
Call($method, $arParams=array())
Определения client.php:46
GetResponseObject()
Определения client.php:470
$arConnectionParams
Определения client.php:6
GetConnectionParams()
Определения client.php:465
GetListProcessResult($RESULT)
Определения client.php:509
$bInit
Определения client.php:4
LoadFile($listName, $arParams)
Определения client.php:419
GetListCollection()
Определения client.php:68
ConvertRows($DATA_NODE)
Определения client.php:534
GetListCollectionProcessResult($RESULT)
Определения client.php:504
GetByIDProcessResult($RESULT)
Определения client.php:529
GetAttachmentCollection($listName, $arParams)
Определения client.php:317
$ATTACHMENTS_PATH
Определения client.php:8
GetAttachmentCollectionProcessResult($RESULT)
Определения client.php:519
$RESPONSE
Определения client.php:5
SetConnectionParams($arParams)
Определения client.php:20
__initialize()
Определения client.php:477
__construct($arParams)
Определения client.php:12
GetList($listName)
Определения client.php:155
Определения xmlcreator.php:3
static createTagAttributed($heavyTag, $value=null)
Определения xmlcreator.php:21
static xmlspecialchars($str)
Определения xmlcreator.php:238
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$res
Определения filter_act.php:7
$query
Определения get_search.php:11
if($ajaxMode) $ID
Определения get_user.php:27
$_SERVER["DOCUMENT_ROOT"]
Определения cron_frame.php:9
CheckDirPath($path)
Определения tools.php:2707
$name
Определения menu_edit.php:35
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
$ar
Определения options.php:199
if(empty($signedUserToken)) $key
Определения quickway.php:257
$i
Определения factura.php:643
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936
$method
Определения index.php:27
$arRes
Определения options.php:104
$GLOBALS['_____370096793']
Определения update_client.php:1
const WS_SP_SERVICE_PATH
Определения include.php:4
const WS_SP_SERVICE_NS
Определения include.php:5