bslinkedsetfieldrenderer.class.inc.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536
  1. <?php
  2. // Copyright (C) 2010-2016 Combodo SARL
  3. //
  4. // This file is part of iTop.
  5. //
  6. // iTop is free software; you can redistribute it and/or modify
  7. // it under the terms of the GNU Affero General Public License as published by
  8. // the Free Software Foundation, either version 3 of the License, or
  9. // (at your option) any later version.
  10. //
  11. // iTop is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. // GNU Affero General Public License for more details.
  15. //
  16. // You should have received a copy of the GNU Affero General Public License
  17. // along with iTop. If not, see <http://www.gnu.org/licenses/>
  18. namespace Combodo\iTop\Renderer\Bootstrap\FieldRenderer;
  19. use \Exception;
  20. use \utils;
  21. use \IssueLog;
  22. use \Dict;
  23. use \UserRights;
  24. use \InlineImage;
  25. use \DBObjectSet;
  26. use \MetaModel;
  27. use \Combodo\iTop\Renderer\FieldRenderer;
  28. use \Combodo\iTop\Renderer\RenderingOutput;
  29. use \Combodo\iTop\Form\Field\LinkedSetField;
  30. /**
  31. * Description of BsLinkedSetFieldRenderer
  32. *
  33. * @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
  34. */
  35. class BsLinkedSetFieldRenderer extends FieldRenderer
  36. {
  37. /**
  38. * Returns a RenderingOutput for the FieldRenderer's Field
  39. *
  40. * @return \Combodo\iTop\Renderer\RenderingOutput
  41. */
  42. public function Render()
  43. {
  44. $oOutput = new RenderingOutput();
  45. $sFieldMandatoryClass = ($this->oField->GetMandatory()) ? 'form_mandatory' : '';
  46. // Vars to build the table
  47. $sAttributesToDisplayAsJson = json_encode($this->oField->GetAttributesToDisplay());
  48. $sAttCodesToDisplayAsJson = json_encode($this->oField->GetAttributesToDisplay(true));
  49. $aItems = array();
  50. $aItemIds = array();
  51. $this->PrepareItems($aItems, $aItemIds);
  52. $sItemsAsJson = json_encode($aItems);
  53. $sItemIdsAsJson = htmlentities(json_encode($aItemIds), ENT_QUOTES, 'UTF-8');
  54. if (!$this->oField->GetHidden())
  55. {
  56. // Rendering field
  57. $sIsEditable = ($this->oField->GetReadOnly()) ? 'false' : 'true';
  58. $sCollapseTogglerVisibleClass = 'glyphicon-menu-down';
  59. $sCollapseTogglerHiddenClass = 'glyphicon-menu-down collapsed';
  60. $sCollapseTogglerId = 'form_linkedset_toggler_' . $this->oField->GetGlobalId();
  61. $sFieldWrapperId = 'form_linkedset_wrapper_' . $this->oField->GetGlobalId();
  62. $oOutput->AddHtml('<div class="form-group ' . $sFieldMandatoryClass . '">');
  63. if ($this->oField->GetLabel() !== '')
  64. {
  65. $oOutput->AddHtml('<label for="' . $this->oField->GetGlobalId() . '" class="control-label">')
  66. ->AddHtml('<a id="' . $sCollapseTogglerId . '" class="form_linkedset_toggler" data-toggle="collapse" href="#' . $sFieldWrapperId . '" aria-expanded="false" aria-controls="' . $sFieldWrapperId . '">')
  67. ->AddHtml($this->oField->GetLabel(), true)
  68. ->AddHtml('<span class="text">' . count($aItemIds) . '</span>')
  69. ->AddHtml('<span class="glyphicon ' . $sCollapseTogglerHiddenClass . '"></>')
  70. ->AddHtml('</a>')
  71. ->AddHtml('</label>');
  72. }
  73. $oOutput->AddHtml('<div class="help-block"></div>');
  74. // Rendering table
  75. // - Vars
  76. $sTableId = 'table_' . $this->oField->GetGlobalId();
  77. // - Output
  78. $oOutput->AddHtml(
  79. <<<EOF
  80. <div class="form_linkedset_wrapper collapse" id="{$sFieldWrapperId}">
  81. <div class="row">
  82. <div class="col-xs-12">
  83. <input type="hidden" id="{$this->oField->GetGlobalId()}" name="{$this->oField->GetId()}" value="{$sItemIdsAsJson}" />
  84. <table id="{$sTableId}" data-field-id="{$this->oField->GetId()}" class="table table-striped table-bordered responsive" cellspacing="0" width="100%">
  85. <tbody>
  86. </tbody>
  87. </table>
  88. </div>
  89. </div>
  90. EOF
  91. );
  92. // Rendering table widget
  93. // - Vars
  94. $sEmptyTableLabel = htmlentities(Dict::S(($this->oField->GetReadOnly()) ? 'Portal:Datatables:Language:EmptyTable' : 'UI:Message:EmptyList:UseAdd'), ENT_QUOTES, 'UTF-8');
  95. $sLabelGeneralCheckbox = htmlentities(Dict::S('Core:BulkExport:CheckAll') . ' / ' . Dict::S('Core:BulkExport:UncheckAll'), ENT_QUOTES, 'UTF-8');
  96. $sSelectionOptionHtml = ($this->oField->GetReadOnly()) ? 'false' : '{"style": "multi"}';
  97. $sSelectionInputGlobalHtml = ($this->oField->GetReadOnly()) ? '' : '<span class="row_input"><input type="checkbox" id="' . $this->oField->GetGlobalId() . '_check_all" name="' . $this->oField->GetGlobalId() . '_check_all" title="' . $sLabelGeneralCheckbox . '" /></span>';
  98. $sSelectionInputHtml = ($this->oField->GetReadOnly()) ? '' : '<span class="row_input"><input type="checkbox" name="' . $this->oField->GetGlobalId() . '" /></span>';
  99. // - Output
  100. $oOutput->AddJs(
  101. <<<EOF
  102. // Collapse handlers
  103. // - Collapsing by default to optimize form space
  104. // It would be better to be able to construct the widget as collapsed, but in this ase, datatables thinks the container is very small and therefore renders the table as if it was in microbox.
  105. $('#{$sFieldWrapperId}').collapse({toggle: false});
  106. // - Change toggle icon class
  107. $('#{$sFieldWrapperId}').on('shown.bs.collapse', function(){
  108. // Creating the table if null (first expand). If we create it on start, it will be displayed as if it was in a micro screen due to the div being "display: none;"
  109. if(oTable_{$this->oField->GetGlobalId()} === undefined)
  110. {
  111. buildTable_{$this->oField->GetGlobalId()}();
  112. }
  113. })
  114. .on('show.bs.collapse', function(){
  115. $('#{$sCollapseTogglerId} > span.glyphicon').removeClass('{$sCollapseTogglerHiddenClass}').addClass('{$sCollapseTogglerVisibleClass}');
  116. })
  117. .on('hide.bs.collapse', function(){
  118. $('#{$sCollapseTogglerId} > span.glyphicon').removeClass('{$sCollapseTogglerVisibleClass}').addClass('{$sCollapseTogglerHiddenClass}');
  119. });
  120. // Places a loader in the empty datatables
  121. $('#{$sTableId} > tbody').html('<tr><td class="datatables_overlay" colspan="100">' + $('#page_overlay').html() + '</td></tr>');
  122. // Prepares data for datatables
  123. var oColumnProperties_{$this->oField->GetGlobalId()} = {$sAttributesToDisplayAsJson};
  124. var oRawDatas_{$this->oField->GetGlobalId()} = {$sItemsAsJson};
  125. var oTable_{$this->oField->GetGlobalId()};
  126. var oSelectedItems_{$this->oField->GetGlobalId()} = {};
  127. var getColumnsDefinition_{$this->oField->GetGlobalId()} = function()
  128. {
  129. var aColumnsDefinition = [];
  130. if({$sIsEditable})
  131. {
  132. aColumnsDefinition.push({
  133. "width": "auto",
  134. "searchable": false,
  135. "sortable": false,
  136. "title": '{$sSelectionInputGlobalHtml}',
  137. "type": "html",
  138. "data": "",
  139. "render": function(data, type, row)
  140. {
  141. var oCheckboxElem = $('{$sSelectionInputHtml}');
  142. oCheckboxElem.find(':input').attr('data-object-id', row.id).attr('data-target-object-id', row.target_id);
  143. return oCheckboxElem.prop('outerHTML');
  144. }
  145. });
  146. }
  147. for(sKey in oColumnProperties_{$this->oField->GetGlobalId()})
  148. {
  149. // Level main column
  150. aColumnsDefinition.push({
  151. "width": "auto",
  152. "searchable": true,
  153. "sortable": true,
  154. "title": oColumnProperties_{$this->oField->GetGlobalId()}[sKey],
  155. "defaultContent": "",
  156. "type": "html",
  157. "data": "attributes."+sKey+".att_code",
  158. "render": function(data, type, row){
  159. var cellElem;
  160. // Preparing the cell data
  161. if(row.attributes[data].url !== undefined)
  162. {
  163. cellElem = $('<a></a>');
  164. cellElem.attr('target', '_blank').attr('href', row.attributes[data].url);
  165. }
  166. else
  167. {
  168. cellElem = $('<span></span>');
  169. }
  170. cellElem.html('<span>' + row.attributes[data].value + '</span>');
  171. return cellElem.prop('outerHTML');
  172. },
  173. });
  174. }
  175. return aColumnsDefinition;
  176. };
  177. // Helper to build the datatable
  178. // Note : Those options should be externalized in an library so we can use them on any DataTables for the portal.
  179. // We would just have to override / complete the necessary elements
  180. var buildTable_{$this->oField->GetGlobalId()} = function()
  181. {
  182. var iDefaultOrderColumnIndex = ({$sIsEditable}) ? 1 : 0;
  183. // Instanciates datatables
  184. oTable_{$this->oField->GetGlobalId()} = $('#{$sTableId}').DataTable({
  185. "language": {
  186. "emptyTable": "{$sEmptyTableLabel}"
  187. },
  188. "displayLength": -1,
  189. "scrollY": "300px",
  190. "scrollCollapse": true,
  191. "order": [[iDefaultOrderColumnIndex, "asc"]],
  192. "dom": 't',
  193. "columns": getColumnsDefinition_{$this->oField->GetGlobalId()}(),
  194. "select": {$sSelectionOptionHtml},
  195. "rowId": "id",
  196. "data": oRawDatas_{$this->oField->GetGlobalId()},
  197. });
  198. // Handles items selection/deselection
  199. // - Directly on the table
  200. oTable_{$this->oField->GetGlobalId()}.off('select').on('select', function(oEvent, dt, type, indexes){
  201. var aData = oTable_{$this->oField->GetGlobalId()}.rows(indexes).data().toArray();
  202. // Checking input
  203. $('#{$sTableId} tbody tr[role="row"].selected td:first-child input').prop('checked', true);
  204. // Saving values in temp array
  205. for(var i in aData)
  206. {
  207. var iItemId = aData[i].id;
  208. if(!(iItemId in oSelectedItems_{$this->oField->GetGlobalId()}))
  209. {
  210. oSelectedItems_{$this->oField->GetGlobalId()}[iItemId] = aData[i].name;
  211. }
  212. }
  213. // Updating remove button
  214. updateRemoveButtonState_{$this->oField->GetGlobalId()}();
  215. });
  216. oTable_{$this->oField->GetGlobalId()}.off('deselect').on('deselect', function(oEvent, dt, type, indexes){
  217. var aData = oTable_{$this->oField->GetGlobalId()}.rows(indexes).data().toArray();
  218. // Checking input
  219. $('#{$sTableId} tbody tr[role="row"]:not(.selected) td:first-child input').prop('checked', false);
  220. // Saving values in temp array
  221. for(var i in aData)
  222. {
  223. var iItemId = aData[i].id;
  224. if(iItemId in oSelectedItems_{$this->oField->GetGlobalId()})
  225. {
  226. delete oSelectedItems_{$this->oField->GetGlobalId()}[iItemId];
  227. }
  228. }
  229. // Unchecking global checkbox
  230. $('#{$this->oField->GetGlobalId()}_check_all').prop('checked', false);
  231. // Updating remove button
  232. updateRemoveButtonState_{$this->oField->GetGlobalId()}();
  233. });
  234. // - From the global button
  235. $('#{$this->oField->GetGlobalId()}_check_all').off('click').on('click', function(oEvent){
  236. if($(this).prop('checked'))
  237. {
  238. oTable_{$this->oField->GetGlobalId()}.rows().select();
  239. }
  240. else
  241. {
  242. oTable_{$this->oField->GetGlobalId()}.rows().deselect();
  243. }
  244. updateRemoveButtonState_{$this->oField->GetGlobalId()}();
  245. });
  246. };
  247. EOF
  248. );
  249. // Attaching JS widget
  250. $sObjectInformationsUrl = $this->oField->GetInformationEndpoint();
  251. $oOutput->AddJs(
  252. <<<EOF
  253. $("[data-field-id='{$this->oField->GetId()}'][data-form-path='{$this->oField->GetFormPath()}']").portal_form_field({
  254. 'validators': {$this->GetValidatorsAsJson()},
  255. 'get_current_value_callback': function(me, oEvent, oData){
  256. var value = null;
  257. // Retrieving JSON value as a string and not an object
  258. //
  259. // Note : The value is passed as a string instead of an array because the attribute would not be included in the posted data when empty.
  260. // Which was an issue when deleting all objects from linkedset
  261. //
  262. // Old code : value = JSON.parse(me.element.find('#{$this->oField->GetGlobalId()}').val());
  263. value = me.element.find('#{$this->oField->GetGlobalId()}').val();
  264. return value;
  265. },
  266. 'set_current_value_callback': function(me, oEvent, oData){
  267. // When we have data (meaning that we picked objects from search)
  268. if(oData !== undefined && Object.keys(oData.values).length > 0)
  269. {
  270. // Showing loader while retrieving informations
  271. $('#page_overlay').fadeIn(200);
  272. // Retrieving new rows ids
  273. var aObjectIds = Object.keys(oData.values);
  274. // Retrieving rows informations so we can add them
  275. $.post(
  276. '{$sObjectInformationsUrl}',
  277. {
  278. sObjectClass: '{$this->oField->GetTargetClass()}',
  279. aObjectIds: aObjectIds,
  280. aObjectAttCodes: $sAttCodesToDisplayAsJson
  281. },
  282. function(oData){
  283. // Updating datatables
  284. if(oData.items !== undefined)
  285. {
  286. for(var i in oData.items)
  287. {
  288. // Adding target item id information
  289. oData.items[i].target_id = oData.items[i].id;
  290. // Adding item to table only if it's not already there
  291. if($('#{$sTableId} tr[role="row"] > td input[data-target-object-id="' + oData.items[i].target_id + '"], #{$sTableId} tr[role="row"] > td input[data-target-object-id="' + (oData.items[i].target_id*-1) + '"]').length === 0)
  292. {
  293. // Making id negative in order to recognize it when persisting
  294. oData.items[i].id = -1 * parseInt(oData.items[i].id);
  295. oTable_{$this->oField->GetGlobalId()}.row.add(oData.items[i]);
  296. }
  297. }
  298. oTable_{$this->oField->GetGlobalId()}.draw();
  299. }
  300. }
  301. )
  302. .done(function(oData){
  303. // Updating hidden field
  304. var aData = oTable_{$this->oField->GetGlobalId()}.rows().data().toArray();
  305. var aObjectIds = [];
  306. for(var i in aData)
  307. {
  308. aObjectIds.push({id: aData[i].id});
  309. }
  310. $('#{$this->oField->GetGlobalId()}').val(JSON.stringify(aObjectIds));
  311. // Updating items count
  312. updateItemCount_{$this->oField->GetGlobalId()}();
  313. // Updating global checkbox
  314. $('#{$this->oField->GetGlobalId()}_check_all').prop('checked', false);
  315. })
  316. .always(function(oData){
  317. // Hiding loader
  318. $('#page_overlay').fadeOut(200);
  319. });
  320. }
  321. // We come from a button
  322. else
  323. {
  324. // Updating hidden field
  325. var aData = oTable_{$this->oField->GetGlobalId()}.rows().data().toArray();
  326. var aObjectIds = [];
  327. for(var i in aData)
  328. {
  329. aObjectIds.push({id: aData[i].id});
  330. }
  331. $('#{$this->oField->GetGlobalId()}').val(JSON.stringify(aObjectIds));
  332. // Updating items count
  333. updateItemCount_{$this->oField->GetGlobalId()}();
  334. // Updating global checkbox
  335. $('#{$this->oField->GetGlobalId()}_check_all').prop('checked', false);
  336. }
  337. }
  338. });
  339. EOF
  340. );
  341. // Additional features if in edition mode
  342. if (!$this->oField->GetReadOnly())
  343. {
  344. // Rendering table
  345. // - Vars
  346. $sButtonRemoveId = 'btn_remove_' . $this->oField->GetGlobalId();
  347. $sButtonAddId = 'btn_add_' . $this->oField->GetGlobalId();
  348. $sLabelRemove = Dict::S('UI:Button:Remove');
  349. $sLabelAdd = Dict::S('UI:Button:AddObject');
  350. // - Output
  351. $oOutput->AddHtml(
  352. <<<EOF
  353. <div class="row">
  354. <div class="col-xs-12">
  355. <div class="btn-group" role="group">
  356. <button type="button" class="btn btn-sm btn-danger" id="{$sButtonRemoveId}" title="{$sLabelRemove}" disabled><span class="glyphicon glyphicon-minus"></span></button>
  357. <button type="button" class="btn btn-sm btn-default" id="{$sButtonAddId}" title="{$sLabelAdd}"><span class="glyphicon glyphicon-plus"></span></button>
  358. </div>
  359. </div>
  360. </div>
  361. EOF
  362. );
  363. // Rendering table widget
  364. // - Vars
  365. $sAddButtonEndpoint = str_replace('-sMode-', 'from-attribute', $this->oField->GetSearchEndpoint());
  366. // - Output
  367. $oOutput->AddJs(
  368. <<<EOF
  369. // Handles items selection/deselection
  370. // - Remove button state handler
  371. var updateRemoveButtonState_{$this->oField->GetGlobalId()} = function()
  372. {
  373. var bIsDisabled = (Object.keys(oSelectedItems_{$this->oField->GetGlobalId()}).length == 0);
  374. $('#{$sButtonRemoveId}').prop('disabled', bIsDisabled);
  375. };
  376. // - Item count state handler
  377. var updateItemCount_{$this->oField->GetGlobalId()} = function()
  378. {
  379. $('#{$sCollapseTogglerId} > .text').text( oTable_{$this->oField->GetGlobalId()}.rows().count() );
  380. };
  381. // Handles items remove/add
  382. $('#{$sButtonRemoveId}').off('click').on('click', function(){
  383. // Removing items from table
  384. oTable_{$this->oField->GetGlobalId()}.rows({selected: true}).remove().draw();
  385. // Resetting selected items
  386. oSelectedItems_{$this->oField->GetGlobalId()} = {};
  387. // Updating form value
  388. $("[data-field-id='{$this->oField->GetId()}'][data-form-path='{$this->oField->GetFormPath()}']").triggerHandler('set_current_value');
  389. // Updating global checkbox state
  390. $('#{$this->oField->GetGlobalId()}_check_all').prop('checked', false);
  391. // Updating remove button
  392. updateRemoveButtonState_{$this->oField->GetGlobalId()}();
  393. });
  394. $('#{$sButtonAddId}').off('click').on('click', function(){
  395. // Preparing current values
  396. var aObjectIdsToIgnore = [];
  397. $('#{$sTableId} tr[role="row"] > td input[data-target-object-id]').each(function(iIndex, oElem){
  398. aObjectIdsToIgnore.push( $(oElem).attr('data-target-object-id') );
  399. });
  400. // Creating a new modal
  401. var oModalElem;
  402. if($('.modal[data-source-element="{$sButtonAddId}"]').length === 0)
  403. {
  404. oModalElem = $('#modal-for-all').clone();
  405. oModalElem.attr('id', '').attr('data-source-element', '{$sButtonAddId}').appendTo('body');
  406. }
  407. else
  408. {
  409. oModalElem = $('.modal[data-source-element="{$sButtonAddId}"]').first();
  410. }
  411. // Resizing to small modal
  412. oModalElem.find('.modal-dialog').removeClass('modal-sm').addClass('modal-lg');
  413. // Loading content
  414. oModalElem.find('.modal-content').html($('#page_overlay .overlay_content').html());
  415. oModalElem.find('.modal-content').load(
  416. '{$sAddButtonEndpoint}',
  417. {
  418. sFormPath: '{$this->oField->GetFormPath()}',
  419. sFieldId: '{$this->oField->GetId()}',
  420. aObjectIdsToIgnore : aObjectIdsToIgnore
  421. }
  422. );
  423. oModalElem.modal('show');
  424. });
  425. EOF
  426. );
  427. }
  428. }
  429. // ... and in hidden mode
  430. else
  431. {
  432. $oOutput->AddHtml('<input type="hidden" id="' . $this->oField->GetGlobalId() . '" name="' . $this->oField->GetId() . '" value="' . $sItemIdsAsJson . '" />');
  433. }
  434. // End of table rendering
  435. $oOutput->AddHtml('</div>');
  436. $oOutput->AddHtml('</div>');
  437. return $oOutput;
  438. }
  439. protected function PrepareItems(&$aItems, &$aItemIds)
  440. {
  441. $oValueSet = $this->oField->GetCurrentValue();
  442. $oValueSet->OptimizeColumnLoad(array($this->oField->GetTargetClass() => $this->oField->GetAttributesToDisplay(true)));
  443. while ($oItem = $oValueSet->Fetch())
  444. {
  445. // In case of indirect linked set, we must retrieve the remote object
  446. if ($this->oField->IsIndirect())
  447. {
  448. try{
  449. // Note : AllowAllData set to true here instead of checking scope's flag because we are displaying a value that has been set and validated
  450. $oRemoteItem = MetaModel::GetObject($this->oField->GetTargetClass(), $oItem->Get($this->oField->GetExtKeyToRemote()), true, true);
  451. }
  452. catch(Exception $e)
  453. {
  454. // In some cases we can't retrieve an object from a linkedset, eg. when the extkey to remote is 0 due to a database corruption.
  455. // Rather than crashing we rather just skip the object like in the administration console
  456. IssueLog::Error('Could not retrieve object of linkedset in form #'.$this->oField->GetFormPath().' for field #'.$this->oField->GetId().'. Message: '.$e->getMessage());
  457. continue;
  458. }
  459. }
  460. else
  461. {
  462. $oRemoteItem = $oItem;
  463. }
  464. $aItemProperties = array(
  465. 'id' => ($this->oField->IsIndirect() && $oItem->IsNew()) ? -1*$oRemoteItem->GetKey() : $oItem->GetKey(),
  466. 'target_id' => $oRemoteItem->GetKey(),
  467. 'name' => $oItem->GetName(),
  468. 'attributes' => array()
  469. );
  470. // Target object others attributes
  471. foreach ($this->oField->GetAttributesToDisplay(true) as $sAttCode)
  472. {
  473. if ($sAttCode !== 'id')
  474. {
  475. $aAttProperties = array(
  476. 'att_code' => $sAttCode
  477. );
  478. $oAttDef = MetaModel::GetAttributeDef($this->oField->GetTargetClass(), $sAttCode);
  479. if ($oAttDef->IsExternalKey())
  480. {
  481. $aAttProperties['value'] = $oRemoteItem->Get($sAttCode . '_friendlyname');
  482. }
  483. else
  484. {
  485. $aAttProperties['value'] = $oAttDef->GetValueLabel($oRemoteItem->Get($sAttCode));
  486. }
  487. $aItemProperties['attributes'][$sAttCode] = $aAttProperties;
  488. }
  489. }
  490. $aItems[] = $aItemProperties;
  491. $aItemIds[] = array('id' => $aItemProperties['id']);
  492. }
  493. }
  494. }