ui.linkswidget.class.inc.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  1. <?php
  2. // Copyright (C) 2010 Combodo SARL
  3. //
  4. // This program is free software; you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation; version 3 of the License.
  7. //
  8. // This program is distributed in the hope that it will be useful,
  9. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. // GNU General Public License for more details.
  12. //
  13. // You should have received a copy of the GNU General Public License
  14. // along with this program; if not, write to the Free Software
  15. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. /**
  17. * Class UILinksWidget
  18. *
  19. * @author Erwan Taloc <erwan.taloc@combodo.com>
  20. * @author Romain Quetiez <romain.quetiez@combodo.com>
  21. * @author Denis Flaven <denis.flaven@combodo.com>
  22. * @license http://www.opensource.org/licenses/gpl-3.0.html LGPL
  23. */
  24. require_once(APPROOT.'/application/webpage.class.inc.php');
  25. require_once(APPROOT.'/application/displayblock.class.inc.php');
  26. class UILinksWidget
  27. {
  28. protected $m_sClass;
  29. protected $m_sAttCode;
  30. protected $m_sNameSuffix;
  31. protected $m_iInputId;
  32. protected $m_aAttributes;
  33. protected $m_sExtKeyToRemote;
  34. protected $m_sLinkedClass;
  35. protected $m_sRemoteClass;
  36. protected $m_bDuplicatesAllowed;
  37. protected static $iWidgetIndex = 0;
  38. public function __construct($sClass, $sAttCode, $iInputId, $sNameSuffix = '', $bDuplicatesAllowed = false)
  39. {
  40. $this->m_sClass = $sClass;
  41. $this->m_sAttCode = $sAttCode;
  42. $this->m_sNameSuffix = $sNameSuffix;
  43. $this->m_iInputId = $iInputId;
  44. $this->m_bDuplicatesAllowed = $bDuplicatesAllowed;
  45. $this->m_aEditableFields = array();
  46. self::$iWidgetIndex++;
  47. $oAttDef = MetaModel::GetAttributeDef($this->m_sClass, $this->m_sAttCode);
  48. $this->m_sLinkedClass = $oAttDef->GetLinkedClass();
  49. $this->m_sExtKeyToRemote = $oAttDef->GetExtKeyToRemote();
  50. $oLinkingAttDef = MetaModel::GetAttributeDef($this->m_sLinkedClass, $this->m_sExtKeyToRemote);
  51. $this->m_sRemoteClass = $oLinkingAttDef->GetTargetClass();
  52. $sExtKeyToMe = $oAttDef->GetExtKeyToMe();
  53. $sStateAttCode = MetaModel::GetStateAttributeCode($this->m_sClass);
  54. $sDefaultState = MetaModel::GetDefaultState($this->m_sClass);
  55. $this->m_aEditableFields = array();
  56. $this->m_aTableConfig = array();
  57. $this->m_aTableConfig['form::checkbox'] = array( 'label' => "<input class=\"select_all\" type=\"checkbox\" value=\"1\" onClick=\"CheckAll('#linkedset_{$this->m_sAttCode}{$this->m_sNameSuffix} .selection', this.checked); oWidget".self::$iWidgetIndex.".OnSelectChange();\">", 'description' => Dict::S('UI:SelectAllToggle+'));
  58. foreach(MetaModel::ListAttributeDefs($this->m_sLinkedClass) as $sAttCode=>$oAttDef)
  59. {
  60. if ($sStateAttCode == $sAttCode)
  61. {
  62. // State attribute is always hidden from the UI
  63. }
  64. else if (!$oAttDef->IsExternalField() && ($sAttCode != $sExtKeyToMe) && ($sAttCode != $this->m_sExtKeyToRemote) && ($sAttCode != 'finalclass'))
  65. {
  66. $iFlags = MetaModel::GetAttributeFlags($this->m_sLinkedClass, $sDefaultState, $sAttCode);
  67. if ( !($iFlags & OPT_ATT_HIDDEN) && !($iFlags & OPT_ATT_READONLY) )
  68. {
  69. $this->m_aEditableFields[] = $sAttCode;
  70. $this->m_aTableConfig[$sAttCode] = array( 'label' => $oAttDef->GetLabel(), 'description' => $oAttDef->GetDescription());
  71. }
  72. }
  73. }
  74. $this->m_aTableConfig['static::key'] = array( 'label' => MetaModel::GetName($this->m_sRemoteClass), 'description' => MetaModel::GetClassDescription($this->m_sRemoteClass));
  75. foreach(MetaModel::GetZListItems($this->m_sRemoteClass, 'list') as $sFieldCode)
  76. {
  77. // TO DO: check the state of the attribute: hidden or visible ?
  78. if ($sFieldCode != 'finalclass')
  79. {
  80. $oAttDef = MetaModel::GetAttributeDef($this->m_sRemoteClass, $sFieldCode);
  81. $this->m_aTableConfig['static::'.$sFieldCode] = array( 'label' => $oAttDef->GetLabel(), 'description' => $oAttDef->GetDescription());
  82. }
  83. }
  84. }
  85. /**
  86. * A one-row form for editing a link record
  87. * @param WebPage $oP Web page used for the ouput
  88. * @param DBObject $oLinkedObj The object to which all the elements of the linked set refer to
  89. * @param mixed $linkObjOrId Either the object linked or a unique number for new link records to add
  90. * @param Hash $aArgs Extra context arguments
  91. * @return string The HTML fragment of the one-row form
  92. */
  93. protected function GetFormRow(WebPage $oP, DBObject $oLinkedObj, $linkObjOrId = null, $aArgs = array() )
  94. {
  95. $sPrefix = "$this->m_sAttCode{$this->m_sNameSuffix}";
  96. $aRow = array();
  97. if(is_object($linkObjOrId))
  98. {
  99. $key = $linkObjOrId->GetKey();
  100. $sPrefix .= "[$key][";
  101. $sNameSuffix = "]"; // To make a tabular form
  102. $aArgs['prefix'] = $sPrefix;
  103. $aRow['form::checkbox'] = "<input class=\"selection\" type=\"checkbox\" onChange=\"oWidget".self::$iWidgetIndex.".OnSelectChange();\" value=\"$key\">";
  104. $aRow['form::checkbox'] .= "<input type=\"hidden\" name=\"attr_{$sPrefix}id{$sNameSuffix}\" value=\"$key\">";
  105. foreach($this->m_aEditableFields as $sFieldCode)
  106. {
  107. $oAttDef = MetaModel::GetAttributeDef($this->m_sLinkedClass, $sFieldCode);
  108. $aRow[$sFieldCode] = cmdbAbstractObject::GetFormElementForField($oP, $this->m_sLinkedClass, $sFieldCode, $oAttDef, $linkObjOrId->Get($sFieldCode), '' /* DisplayValue */, $this->m_iInputId.'_'.$sFieldCode.'['.$key.']', $sNameSuffix, 0, $aArgs);
  109. }
  110. }
  111. else
  112. {
  113. // form for creating a new record
  114. $sPrefix .= "[$linkObjOrId][";
  115. $sNameSuffix = "]"; // To make a tabular form
  116. $aArgs['prefix'] = $sPrefix;
  117. $aRow['form::checkbox'] = "<input class=\"selection\" type=\"checkbox\" onChange=\"oWidget".self::$iWidgetIndex.".OnSelectChange();\" value=\"$linkObjOrId\">";
  118. $aRow['form::checkbox'] .= "<input type=\"hidden\" name=\"attr_{$sPrefix}id{$sNameSuffix}\" value=\"\">";
  119. foreach($this->m_aEditableFields as $sFieldCode)
  120. {
  121. $oAttDef = MetaModel::GetAttributeDef($this->m_sLinkedClass, $sFieldCode);
  122. $aRow[$sFieldCode] = cmdbAbstractObject::GetFormElementForField($oP, $this->m_sLinkedClass, $sFieldCode, $oAttDef, '' /* TO DO/ call GetDefaultValue($oObject->ToArgs()) */, '' /* DisplayValue */, $this->m_iInputId.'_'.$sFieldCode.'['.$linkObjOrId.']' /* id */, $sNameSuffix, 0, $aArgs);
  123. }
  124. }
  125. $aRow['static::key'] = $oLinkedObj->GetHyperLink();
  126. foreach(MetaModel::GetZListItems($this->m_sRemoteClass, 'list') as $sFieldCode)
  127. {
  128. $aRow['static::'.$sFieldCode] = $oLinkedObj->GetAsHTML($sFieldCode);
  129. }
  130. return $aRow;
  131. }
  132. /**
  133. * Display one row of the whole form
  134. * @return none
  135. */
  136. protected function DisplayFormRow(WebPage $oP, $aConfig, $aRow, $iRowId)
  137. {
  138. $sHtml = '';
  139. $sHtml .= "<tr id=\"{$this->m_sAttCode}{$this->m_sNameSuffix}_row_$iRowId\">\n";
  140. foreach($aConfig as $sName=>$void)
  141. {
  142. $sHtml .= "<td>".$aRow[$sName]."</td>\n";
  143. }
  144. $sHtml .= "</tr>\n";
  145. return $sHtml;
  146. }
  147. /**
  148. * Display the table with the form for editing all the links at once
  149. * @param WebPage $oP The web page used for the output
  150. * @param Hash $aConfig The table's header configuration
  151. * @param Hash $aData The tabular data to be displayed
  152. * @return string Html fragment representing the form table
  153. */
  154. protected function DisplayFormTable(WebPage $oP, $aConfig, $aData)
  155. {
  156. $sHtml = '';
  157. $sHtml .= "<table class=\"listResults\">\n";
  158. // Header
  159. $sHtml .= "<thead>\n";
  160. $sHtml .= "<tr>\n";
  161. foreach($aConfig as $sName=>$aDef)
  162. {
  163. $sHtml .= "<th title=\"".$aDef['description']."\">".$aDef['label']."</th>\n";
  164. }
  165. $sHtml .= "</tr>\n";
  166. $sHtml .= "</thead>\n";
  167. // Content
  168. $sHtml .= "</tbody>\n";
  169. if (count($aData) == 0)
  170. {
  171. $sHtml .= "<tr id=\"{$this->m_sAttCode}{$this->m_sNameSuffix}_empty_row\"><td colspan=\"".count($aConfig)."\" style=\"text-align:center;\">".Dict::S('UI:Message:EmptyList:UseAdd')."<input type=\"hidden\" name=\"attr_{$this->m_sAttCode}{$this->m_sNameSuffix}\" value=\"\"></td></td>";
  172. }
  173. else
  174. {
  175. foreach($aData as $iRowId => $aRow)
  176. {
  177. $sHtml .= $this->DisplayFormRow($oP, $aConfig, $aRow, $iRowId);
  178. }
  179. }
  180. $sHtml .= "</tbody>\n";
  181. // Footer
  182. $sHtml .= "</table>\n";
  183. return $sHtml;
  184. }
  185. /**
  186. * Get the HTML fragment corresponding to the linkset editing widget
  187. * @param WebPage $oP The web page used for all the output
  188. * @param DBObjectSet The initial value of the linked set
  189. * @param Hash $aArgs Extra context arguments
  190. * @return string The HTML fragment to be inserted into the page
  191. */
  192. public function Display(WebPage $oPage, DBObjectSet $oValue, $aArgs = array())
  193. {
  194. $iWidgetIndex = self::$iWidgetIndex;
  195. $sHtmlValue = '';
  196. $sTargetClass = self::GetTargetClass($this->m_sClass, $this->m_sAttCode);
  197. $sHtmlValue .= "<div id=\"linkedset_{$this->m_sAttCode}{$this->m_sNameSuffix}\">\n";
  198. $oValue->Rewind();
  199. $aForm = array();
  200. while($oCurrentLink = $oValue->Fetch())
  201. {
  202. $aRow = array();
  203. $key = $oCurrentLink->GetKey();
  204. $oLinkedObj = MetaModel::GetObject($this->m_sRemoteClass, $oCurrentLink->Get($this->m_sExtKeyToRemote));
  205. $aForm[$key] = $this->GetFormRow($oPage, $oLinkedObj, $oCurrentLink, $aArgs);
  206. }
  207. $sHtmlValue .= $this->DisplayFormTable($oPage, $this->m_aTableConfig, $aForm);
  208. $sDuplicates = ($this->m_bDuplicatesAllowed) ? 'true' : 'false';
  209. $oPage->add_ready_script(<<<EOF
  210. oWidget$iWidgetIndex = new LinksWidget('{$this->m_sAttCode}{$this->m_sNameSuffix}', '{$this->m_sClass}', '{$this->m_sAttCode}', '{$this->m_iInputId}', '{$this->m_sNameSuffix}', $sDuplicates);
  211. oWidget$iWidgetIndex.Init();
  212. EOF
  213. );
  214. $sHtmlValue .= "<span style=\"float:left;\">&nbsp;&nbsp;&nbsp;<img src=\"../images/tv-item-last.gif\">&nbsp;&nbsp;<input id=\"{$this->m_sAttCode}{$this->m_sNameSuffix}_btnRemove\" type=\"button\" value=\"".Dict::S('UI:RemoveLinkedObjectsOf_Class')."\" onClick=\"oWidget$iWidgetIndex.RemoveSelected();\" >";
  215. $sHtmlValue .= "&nbsp;&nbsp;&nbsp;<input id=\"{$this->m_sAttCode}{$this->m_sNameSuffix}_btnAdd\" type=\"button\" value=\"".Dict::Format('UI:AddLinkedObjectsOf_Class', MetaModel::GetName($this->m_sRemoteClass))."\" onClick=\"oWidget$iWidgetIndex.AddObjects();\"></span>\n";
  216. $sHtmlValue .= "<span style=\"clear:both;\"><p>&nbsp;</p></span>\n";
  217. $sHtmlValue .= "</div>\n";
  218. $oPage->add_at_the_end($this->GetObjectPickerDialog($oPage)); // To prevent adding forms inside the main form
  219. return $sHtmlValue;
  220. }
  221. /**
  222. * This static function is called by the Ajax Page when there is a need to fill an autocomplete combo
  223. * @param $oPage WebPage The ajax page used for the output (sent back to the browser)
  224. * @param $sClass string The name of the class of the current object being edited
  225. * @param $sAttCode string The name of the attribute being edited
  226. * @param $sName string The partial name that was typed by the user
  227. * @param $iMaxCount integer The maximum number of items to return
  228. * @return void
  229. */
  230. static public function Autocomplete(WebPage $oPage, $sClass, $sAttCode, $sName, $iMaxCount)
  231. {
  232. // #@# todo - add context information, otherwise any value will be authorized for external keys
  233. $aAllowedValues = MetaModel::GetAllowedValues_att($sClass, $sAttCode, array() /* $aArgs */, $sName);
  234. if ($aAllowedValues != null)
  235. {
  236. $iCount = $iMaxCount;
  237. foreach($aAllowedValues as $key => $value)
  238. {
  239. $oPage->add($value."|".$key."\n");
  240. $iCount--;
  241. if ($iCount == 0) break;
  242. }
  243. }
  244. else // No limitation to the allowed values
  245. {
  246. // Search for all the object of the linked class
  247. $oAttDef = $oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode);
  248. $sLinkedClass = $oAttDef->GetLinkedClass();
  249. $sSearchClass = self::GetTargetClass($sClass, $sAttCode);
  250. $oFilter = new DBObjectSearch($sSearchClass);
  251. $sSearchAttCode = MetaModel::GetNameAttributeCode($sSearchClass);
  252. $oFilter->AddCondition($sSearchAttCode, $sName, 'Begins with');
  253. $oSet = new CMDBObjectSet($oFilter, array($sSearchAttCode => true));
  254. $iCount = 0;
  255. while( ($iCount < $iMaxCount) && ($oObj = $oSet->fetch()) )
  256. {
  257. $oPage->add($oObj->GetName()."|".$oObj->GetKey()."\n");
  258. $iCount++;
  259. }
  260. }
  261. }
  262. /**
  263. * This static function is called by the Ajax Page display a set of objects being linked
  264. * to the object being created
  265. * @param $oPage WebPage The ajax page used for the put^put (sent back to the browser
  266. * @param $sClass string The name of the 'linking class' which is the class of the objects to display
  267. * @param $sSet JSON serialized set of objects
  268. * @param $sExtKeyToMe Name of the attribute in sClass that is pointing to a given object
  269. * @param $iObjectId The id of the object $sExtKeyToMe is pointing to
  270. * @return void
  271. */
  272. static public function RenderSet($oPage, $sClass, $sJSONSet, $sExtKeyToMe, $sExtKeyToRemote, $iObjectId)
  273. {
  274. $aSet = json_decode($sJSONSet, true); // true means hash array instead of object
  275. $oSet = CMDBObjectSet::FromScratch($sClass);
  276. foreach($aSet as $aObject)
  277. {
  278. $oObj = MetaModel::NewObject($sClass);
  279. foreach($aObject as $sAttCode => $value)
  280. {
  281. $oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode);
  282. if ($oAttDef->IsExternalKey() && ($value != 0))
  283. {
  284. $oTargetObj = MetaModel::GetObject($oAttDef->GetTargetClass(), $value); // @@ optimization, don't do & query per object in the set !
  285. $oObj->Set($sAttCode, $oTargetObj);
  286. }
  287. else
  288. {
  289. $oObj->Set($sAttCode, $value);
  290. }
  291. }
  292. $oSet->AddObject($oObj);
  293. }
  294. $aExtraParams = array();
  295. $aExtraParams['link_attr'] = $sExtKeyToMe;
  296. $aExtraParams['object_id'] = $iObjectId;
  297. $aExtraParams['target_attr'] = $sExtKeyToRemote;
  298. $aExtraParams['menu'] = false;
  299. $aExtraParams['select'] = false;
  300. $aExtraParams['view_link'] = false;
  301. cmdbAbstractObject::DisplaySet($oPage, $oSet, $aExtraParams);
  302. }
  303. protected static function GetTargetClass($sClass, $sAttCode)
  304. {
  305. $oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode);
  306. $sLinkedClass = $oAttDef->GetLinkedClass();
  307. switch(get_class($oAttDef))
  308. {
  309. case 'AttributeLinkedSetIndirect':
  310. $oLinkingAttDef = MetaModel::GetAttributeDef($sLinkedClass, $oAttDef->GetExtKeyToRemote());
  311. $sTargetClass = $oLinkingAttDef->GetTargetClass();
  312. break;
  313. case 'AttributeLinkedSet':
  314. $sTargetClass = $sLinkedClass;
  315. break;
  316. }
  317. return $sTargetClass;
  318. }
  319. protected function GetObjectPickerDialog($oPage)
  320. {
  321. $sHtml = "<div id=\"dlg_{$this->m_sAttCode}{$this->m_sNameSuffix}\">";
  322. $sHtml .= "<div class=\"wizContainer\" style=\"vertical-align:top;\">\n";
  323. $iWidgetIndex = self::$iWidgetIndex;
  324. $oFilter = new DBObjectSearch($this->m_sRemoteClass);
  325. $oSet = new CMDBObjectSet($oFilter);
  326. $oBlock = new DisplayBlock($oFilter, 'search', false);
  327. $sHtml .= $oBlock->GetDisplay($oPage, "SearchFormToAdd_{$this->m_sAttCode}{$this->m_sNameSuffix}", array('open' => true));
  328. $sHtml .= "<form id=\"ObjectsAddForm_{$this->m_sAttCode}{$this->m_sNameSuffix}\" OnSubmit=\"return oWidget$iWidgetIndex.DoAddObjects(this.id);\">\n";
  329. $sHtml .= "<div id=\"SearchResultsToAdd_{$this->m_sAttCode}{$this->m_sNameSuffix}\" style=\"vertical-align:top;background: #fff;height:100%;overflow:auto;padding:0;border:0;\">\n";
  330. $sHtml .= "<div style=\"background: #fff; border:0; text-align:center; vertical-align:middle;\"><p>".Dict::S('UI:Message:EmptyList:UseSearchForm')."</p></div>\n";
  331. $sHtml .= "</div>\n";
  332. $sHtml .= "<input type=\"button\" value=\"".Dict::S('UI:Button:Cancel')."\" onClick=\"$('#dlg_{$this->m_sAttCode}{$this->m_sNameSuffix}').dialog('close');\">&nbsp;&nbsp;<input type=\"submit\" value=\"".Dict::S('UI:Button:Add')."\">";
  333. $sHtml .= "</div>\n";
  334. $sHtml .= "</form>\n";
  335. $sHtml .= "</div>\n";
  336. $oPage->add_ready_script("$('#dlg_{$this->m_sAttCode}{$this->m_sNameSuffix}').dialog({ width: $(window).width()*0.8, height: $(window).height()*0.8, autoOpen: false, modal: true, resizeStop: oWidget$iWidgetIndex.UpdateSizes });");
  337. $oPage->add_ready_script("$('#dlg_{$this->m_sAttCode}{$this->m_sNameSuffix}').dialog('option', {title:'".addslashes(Dict::Format('UI:AddObjectsOf_Class_LinkedWith_Class', MetaModel::GetName($this->m_sLinkedClass), MetaModel::GetName($this->m_sClass)))."'});");
  338. $oPage->add_ready_script("$('#SearchFormToAdd_{$this->m_sAttCode}{$this->m_sNameSuffix} form').bind('submit.uilinksWizard', oWidget$iWidgetIndex.SearchObjectsToAdd);");
  339. $oPage->add_ready_script("$('#SearchFormToAdd_{$this->m_sAttCode}{$this->m_sNameSuffix}').resize(oWidget$iWidgetIndex.UpdateSizes);");
  340. return $sHtml;
  341. }
  342. /**
  343. * Search for objects to be linked to the current object (i.e "remote" objects)
  344. * @param WebPage $oP The page used for the output (usually an AjaxWebPage)
  345. * @param string $sRemoteClass Name of the "remote" class to perform the search on, must be a derived class of m_sRemoteClass
  346. * @param Array $aAlreadyLinkedIds List of IDs of objects of "remote" class already linked, to be filtered out of the search
  347. */
  348. public function SearchObjectsToAdd(WebPage $oP, $sRemoteClass = '', $aAlreadyLinkedIds = array())
  349. {
  350. if ($sRemoteClass != '')
  351. {
  352. // assert(MetaModel::IsParentClass($this->m_sRemoteClass, $sRemoteClass));
  353. $oFilter = new DBObjectSearch($sRemoteClass);
  354. }
  355. else
  356. {
  357. // No remote class specified use the one defined in the linkedset
  358. $oFilter = new DBObjectSearch($this->m_sRemoteClass);
  359. }
  360. if (!$this->m_bDuplicatesAllowed && count($aAlreadyLinkedIds) > 0)
  361. {
  362. // Positive IDs correspond to existing link records
  363. // negative IDs correspond to "remote" objects to be linked
  364. $aLinkIds = array();
  365. $aRemoteObjIds = array();
  366. foreach($aAlreadyLinkedIds as $iId)
  367. {
  368. if ($iId > 0)
  369. {
  370. $aLinkIds[] = $iId;
  371. }
  372. else
  373. {
  374. $aRemoteObjIds[] = -$iId;
  375. }
  376. }
  377. if (count($aLinkIds) >0)
  378. {
  379. // Search for the links to find to which "remote" object they are linked
  380. $oLinkFilter = new DBObjectSearch($this->m_sLinkedClass);
  381. $oLinkFilter->AddCondition('id', $aLinkIds, 'IN');
  382. $oLinkSet = new CMDBObjectSet($oLinkFilter);
  383. while($oLink = $oLinkSet->Fetch())
  384. {
  385. $aRemoteObjIds[] = $oLink->Get($this->m_sExtKeyToRemote);
  386. }
  387. }
  388. $oFilter->AddCondition('id', $aRemoteObjIds, 'NOTIN');
  389. }
  390. $oSet = new CMDBObjectSet($oFilter);
  391. $oBlock = new DisplayBlock($oFilter, 'list', false);
  392. $oBlock->Display($oP, 'ResultsToAdd', array('menu' => false, 'selection_mode' => true, 'display_limit' => false)); // Don't display the 'Actions' menu on the results
  393. }
  394. public function DoAddObjects(WebPage $oP, $aLinkedObjectIds = array())
  395. {
  396. $aTable = array();
  397. foreach($aLinkedObjectIds as $iObjectId)
  398. {
  399. $oLinkedObj = MetaModel::GetObject($this->m_sRemoteClass, $iObjectId);
  400. if (is_object($oLinkedObj))
  401. {
  402. $aRow = $this->GetFormRow($oP, $oLinkedObj, -$iObjectId ); // Not yet created link get negative Ids
  403. $oP->add($this->DisplayFormRow($oP, $this->m_aTableConfig, $aRow, -$iObjectId));
  404. }
  405. else
  406. {
  407. $oP->p(Dict::Format('UI:Error:Object_Class_Id_NotFound', $this->m_sLinkedClass, $iObjectId));
  408. }
  409. }
  410. }
  411. }
  412. ?>