ui.linkswidget.class.inc.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  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_sExtKeyToMe;
  35. protected $m_sLinkedClass;
  36. protected $m_sRemoteClass;
  37. protected $m_bDuplicatesAllowed;
  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. $oAttDef = MetaModel::GetAttributeDef($this->m_sClass, $this->m_sAttCode);
  47. $this->m_sLinkedClass = $oAttDef->GetLinkedClass();
  48. $this->m_sExtKeyToRemote = $oAttDef->GetExtKeyToRemote();
  49. $this->m_sExtKeyToMe = $oAttDef->GetExtKeyToMe();
  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".$this->m_iInputId.".OnSelectChange();\">", 'description' => Dict::S('UI:SelectAllToggle+'));
  58. foreach(MetaModel::FlattenZList(MetaModel::GetZListItems($this->m_sLinkedClass, 'list')) as $sAttCode)
  59. {
  60. $oAttDef = MetaModel::GetAttributeDef($this->m_sLinkedClass, $sAttCode);
  61. if ($sStateAttCode == $sAttCode)
  62. {
  63. // State attribute is always hidden from the UI
  64. }
  65. else if ($oAttDef->IsWritable() && ($sAttCode != $sExtKeyToMe) && ($sAttCode != $this->m_sExtKeyToRemote) && ($sAttCode != 'finalclass'))
  66. {
  67. $iFlags = MetaModel::GetAttributeFlags($this->m_sLinkedClass, $sDefaultState, $sAttCode);
  68. if ( !($iFlags & OPT_ATT_HIDDEN) && !($iFlags & OPT_ATT_READONLY) )
  69. {
  70. $this->m_aEditableFields[] = $sAttCode;
  71. $this->m_aTableConfig[$sAttCode] = array( 'label' => $oAttDef->GetLabel(), 'description' => $oAttDef->GetDescription());
  72. }
  73. }
  74. }
  75. $this->m_aTableConfig['static::key'] = array( 'label' => MetaModel::GetName($this->m_sRemoteClass), 'description' => MetaModel::GetClassDescription($this->m_sRemoteClass));
  76. foreach(MetaModel::GetZListItems($this->m_sRemoteClass, 'list') as $sFieldCode)
  77. {
  78. // TO DO: check the state of the attribute: hidden or visible ?
  79. if ($sFieldCode != 'finalclass')
  80. {
  81. $oAttDef = MetaModel::GetAttributeDef($this->m_sRemoteClass, $sFieldCode);
  82. $this->m_aTableConfig['static::'.$sFieldCode] = array( 'label' => $oAttDef->GetLabel(), 'description' => $oAttDef->GetDescription());
  83. }
  84. }
  85. }
  86. /**
  87. * A one-row form for editing a link record
  88. * @param WebPage $oP Web page used for the ouput
  89. * @param DBObject $oLinkedObj The object to which all the elements of the linked set refer to
  90. * @param mixed $linkObjOrId Either the object linked or a unique number for new link records to add
  91. * @param Hash $aArgs Extra context arguments
  92. * @return string The HTML fragment of the one-row form
  93. */
  94. protected function GetFormRow(WebPage $oP, DBObject $oLinkedObj, $linkObjOrId = null, $aArgs = array(), $oCurrentObj )
  95. {
  96. $sPrefix = "$this->m_sAttCode{$this->m_sNameSuffix}";
  97. $aRow = array();
  98. $aFieldsMap = array();
  99. if(is_object($linkObjOrId))
  100. {
  101. $key = $linkObjOrId->GetKey();
  102. $sPrefix .= "[$key][";
  103. $sNameSuffix = "]"; // To make a tabular form
  104. $aArgs['prefix'] = $sPrefix;
  105. $aArgs['wizHelper'] = "oWizardHelper{$this->m_iInputId}{$key}";
  106. $aArgs['this'] = $linkObjOrId;
  107. $aRow['form::checkbox'] = "<input class=\"selection\" type=\"checkbox\" onClick=\"oWidget".$this->m_iInputId.".OnSelectChange();\" value=\"$key\">";
  108. $aRow['form::checkbox'] .= "<input type=\"hidden\" name=\"attr_{$sPrefix}id{$sNameSuffix}\" value=\"$key\">";
  109. foreach($this->m_aEditableFields as $sFieldCode)
  110. {
  111. $sFieldId = $this->m_iInputId.'_'.$sFieldCode.'['.$linkObjOrId->GetKey().']';
  112. $sSafeId = str_replace(array('[',']','-'), '_', $sFieldId);
  113. $oAttDef = MetaModel::GetAttributeDef($this->m_sLinkedClass, $sFieldCode);
  114. $aRow[$sFieldCode] = cmdbAbstractObject::GetFormElementForField($oP, $this->m_sLinkedClass, $sFieldCode, $oAttDef, $linkObjOrId->Get($sFieldCode), '' /* DisplayValue */, $sSafeId, $sNameSuffix, 0, $aArgs);
  115. $aFieldsMap[$sFieldCode] = $sFieldId;
  116. }
  117. $sState = $linkObjOrId->GetState();
  118. }
  119. else
  120. {
  121. // form for creating a new record
  122. $sPrefix .= "[$linkObjOrId][";
  123. $oNewLinkObj = MetaModel::NewObject($this->m_sLinkedClass);
  124. $oRemoteObj = MetaModel::GetObject($this->m_sRemoteClass, -$linkObjOrId);
  125. $oNewLinkObj->Set($this->m_sExtKeyToRemote, $oRemoteObj); // Setting the extkey with the object alsoo fills the related external fields
  126. $oNewLinkObj->Set($this->m_sExtKeyToMe, $oCurrentObj); // Setting the extkey with the object alsoo fills the related external fields
  127. $sNameSuffix = "]"; // To make a tabular form
  128. $aArgs['prefix'] = $sPrefix;
  129. $aArgs['wizHelper'] = "oWizardHelper{$this->m_iInputId}_".(-$linkObjOrId);
  130. $aArgs['this'] = $oNewLinkObj;
  131. $aRow['form::checkbox'] = "<input class=\"selection\" type=\"checkbox\" onClick=\"oWidget".$this->m_iInputId.".OnSelectChange();\" value=\"$linkObjOrId\">";
  132. $aRow['form::checkbox'] .= "<input type=\"hidden\" name=\"attr_{$sPrefix}id{$sNameSuffix}\" value=\"\">";
  133. foreach($this->m_aEditableFields as $sFieldCode)
  134. {
  135. $sFieldId = $this->m_iInputId.'_'.$sFieldCode.'['.$linkObjOrId.']';
  136. $sSafeId = str_replace(array('[',']','-'), '_', $sFieldId);
  137. $oAttDef = MetaModel::GetAttributeDef($this->m_sLinkedClass, $sFieldCode);
  138. $aRow[$sFieldCode] = cmdbAbstractObject::GetFormElementForField($oP, $this->m_sLinkedClass, $sFieldCode, $oAttDef, $oNewLinkObj->Get($sFieldCode) /* TO DO/ call GetDefaultValue($oObject->ToArgs()) */, '' /* DisplayValue */, $sSafeId /* id */, $sNameSuffix, 0, $aArgs);
  139. $aFieldsMap[$sFieldCode] = $sFieldId;
  140. }
  141. $sState = '';
  142. }
  143. $iFieldsCount = count($aFieldsMap);
  144. $sJsonFieldsMap = json_encode($aFieldsMap);
  145. $oP->add_script(
  146. <<<EOF
  147. var {$aArgs['wizHelper']} = new WizardHelper('{$this->m_sLinkedClass}', '', '$sState');
  148. {$aArgs['wizHelper']}.SetFieldsMap($sJsonFieldsMap);
  149. {$aArgs['wizHelper']}.SetFieldsCount($iFieldsCount);
  150. EOF
  151. );
  152. $aRow['static::key'] = $oLinkedObj->GetHyperLink();
  153. foreach(MetaModel::GetZListItems($this->m_sRemoteClass, 'list') as $sFieldCode)
  154. {
  155. $aRow['static::'.$sFieldCode] = $oLinkedObj->GetAsHTML($sFieldCode);
  156. }
  157. return $aRow;
  158. }
  159. /**
  160. * Display one row of the whole form
  161. * @return none
  162. */
  163. protected function DisplayFormRow(WebPage $oP, $aConfig, $aRow, $iRowId)
  164. {
  165. $sHtml = '';
  166. $sHtml .= "<tr id=\"{$this->m_sAttCode}{$this->m_sNameSuffix}_row_$iRowId\">\n";
  167. foreach($aConfig as $sName=>$void)
  168. {
  169. $sHtml .= "<td>".$aRow[$sName]."</td>\n";
  170. }
  171. $sHtml .= "</tr>\n";
  172. return $sHtml;
  173. }
  174. /**
  175. * Display the table with the form for editing all the links at once
  176. * @param WebPage $oP The web page used for the output
  177. * @param Hash $aConfig The table's header configuration
  178. * @param Hash $aData The tabular data to be displayed
  179. * @return string Html fragment representing the form table
  180. */
  181. protected function DisplayFormTable(WebPage $oP, $aConfig, $aData)
  182. {
  183. $sHtml = '';
  184. $sHtml .= "<table class=\"listResults\">\n";
  185. // Header
  186. $sHtml .= "<thead>\n";
  187. $sHtml .= "<tr>\n";
  188. foreach($aConfig as $sName=>$aDef)
  189. {
  190. $sHtml .= "<th title=\"".$aDef['description']."\">".$aDef['label']."</th>\n";
  191. }
  192. $sHtml .= "</tr>\n";
  193. $sHtml .= "</thead>\n";
  194. // Content
  195. $sHtml .= "</tbody>\n";
  196. $sEmptyRowStyle = '';
  197. if (count($aData) != 0)
  198. {
  199. $sEmptyRowStyle = 'style="display:none;"';
  200. }
  201. $sHtml .= "<tr $sEmptyRowStyle 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>";
  202. foreach($aData as $iRowId => $aRow)
  203. {
  204. $sHtml .= $this->DisplayFormRow($oP, $aConfig, $aRow, $iRowId);
  205. }
  206. $sHtml .= "</tbody>\n";
  207. // Footer
  208. $sHtml .= "</table>\n";
  209. return $sHtml;
  210. }
  211. /**
  212. * Get the HTML fragment corresponding to the linkset editing widget
  213. * @param WebPage $oP The web page used for all the output
  214. * @param DBObjectSet The initial value of the linked set
  215. * @param Hash $aArgs Extra context arguments
  216. * @param string $sFormPrefix prefix of the fields in the current form
  217. * @param DBObject $oCurrentObj the current object to which the linkset is related
  218. * @return string The HTML fragment to be inserted into the page
  219. */
  220. public function Display(WebPage $oPage, DBObjectSet $oValue, $aArgs = array(), $sFormPrefix, $oCurrentObj)
  221. {
  222. $sHtmlValue = '';
  223. $sTargetClass = self::GetTargetClass($this->m_sClass, $this->m_sAttCode);
  224. $sHtmlValue .= "<div id=\"linkedset_{$this->m_sAttCode}{$this->m_sNameSuffix}\">\n";
  225. $oValue->Rewind();
  226. $aForm = array();
  227. while($oCurrentLink = $oValue->Fetch())
  228. {
  229. $aRow = array();
  230. $oLinkedObj = MetaModel::GetObject($this->m_sRemoteClass, $oCurrentLink->Get($this->m_sExtKeyToRemote));
  231. if ($oCurrentLink->IsNew())
  232. {
  233. $key = -$oLinkedObj->GetKey();
  234. $aForm[$key] = $this->GetFormRow($oPage, $oLinkedObj, $key, $aArgs, $oCurrentObj);
  235. }
  236. else
  237. {
  238. $key = $oCurrentLink->GetKey();
  239. $aForm[$key] = $this->GetFormRow($oPage, $oLinkedObj, $oCurrentLink, $aArgs, $oCurrentObj);
  240. }
  241. }
  242. $sHtmlValue .= $this->DisplayFormTable($oPage, $this->m_aTableConfig, $aForm);
  243. $sDuplicates = ($this->m_bDuplicatesAllowed) ? 'true' : 'false';
  244. $sWizHelper = 'oWizardHelper'.$sFormPrefix;
  245. $oPage->add_ready_script(<<<EOF
  246. oWidget{$this->m_iInputId} = new LinksWidget('{$this->m_sAttCode}{$this->m_sNameSuffix}', '{$this->m_sClass}', '{$this->m_sAttCode}', '{$this->m_iInputId}', '{$this->m_sNameSuffix}', $sDuplicates, $sWizHelper);
  247. oWidget{$this->m_iInputId}.Init();
  248. EOF
  249. );
  250. $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{$this->m_iInputId}.RemoveSelected();\" >";
  251. $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{$this->m_iInputId}.AddObjects();\"><span id=\"{$this->m_sAttCode}{$this->m_sNameSuffix}_indicatorAdd\"></span></span>\n";
  252. $sHtmlValue .= "<span style=\"clear:both;\"><p>&nbsp;</p></span>\n";
  253. $sHtmlValue .= "</div>\n";
  254. $oPage->add_at_the_end("<div id=\"dlg_{$this->m_sAttCode}{$this->m_sNameSuffix}\"></div>"); // To prevent adding forms inside the main form
  255. return $sHtmlValue;
  256. }
  257. protected static function GetTargetClass($sClass, $sAttCode)
  258. {
  259. $oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode);
  260. $sLinkedClass = $oAttDef->GetLinkedClass();
  261. switch(get_class($oAttDef))
  262. {
  263. case 'AttributeLinkedSetIndirect':
  264. $oLinkingAttDef = MetaModel::GetAttributeDef($sLinkedClass, $oAttDef->GetExtKeyToRemote());
  265. $sTargetClass = $oLinkingAttDef->GetTargetClass();
  266. break;
  267. case 'AttributeLinkedSet':
  268. $sTargetClass = $sLinkedClass;
  269. break;
  270. }
  271. return $sTargetClass;
  272. }
  273. public function GetObjectPickerDialog($oPage, $oCurrentObj)
  274. {
  275. $sHtml = "<div class=\"wizContainer\" style=\"vertical-align:top;\">\n";
  276. $oFilter = new DBObjectSearch($this->m_sRemoteClass);
  277. $this->SetSearchDefaultFromContext($oCurrentObj, $oFilter);
  278. $oBlock = new DisplayBlock($oFilter, 'search', false);
  279. $sHtml .= $oBlock->GetDisplay($oPage, "SearchFormToAdd_{$this->m_sAttCode}{$this->m_sNameSuffix}", array('open' => true));
  280. $sHtml .= "<form id=\"ObjectsAddForm_{$this->m_sAttCode}{$this->m_sNameSuffix}\" OnSubmit=\"return oWidget{$this->m_iInputId}.DoAddObjects(this.id);\">\n";
  281. $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";
  282. $sHtml .= "<div style=\"background: #fff; border:0; text-align:center; vertical-align:middle;\"><p>".Dict::S('UI:Message:EmptyList:UseSearchForm')."</p></div>\n";
  283. $sHtml .= "</div>\n";
  284. $sHtml .= "<input type=\"hidden\" id=\"count_{$this->m_sAttCode}{$this->m_sNameSuffix}\" value=\"0\"/>";
  285. $sHtml .= "<input type=\"button\" value=\"".Dict::S('UI:Button:Cancel')."\" onClick=\"$('#dlg_{$this->m_sAttCode}{$this->m_sNameSuffix}').dialog('close');\">&nbsp;&nbsp;<input id=\"btn_ok_{$this->m_sAttCode}{$this->m_sNameSuffix}\" disabled=\"disabled\" type=\"submit\" value=\"".Dict::S('UI:Button:Add')."\">";
  286. $sHtml .= "</div>\n";
  287. $sHtml .= "</form>\n";
  288. $oPage->add($sHtml);
  289. $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{$this->m_iInputId}.UpdateSizes });");
  290. $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)))."'});");
  291. $oPage->add_ready_script("$('#SearchFormToAdd_{$this->m_sAttCode}{$this->m_sNameSuffix} form').bind('submit.uilinksWizard', oWidget{$this->m_iInputId}.SearchObjectsToAdd);");
  292. $oPage->add_ready_script("$('#SearchFormToAdd_{$this->m_sAttCode}{$this->m_sNameSuffix}').resize(oWidget{$this->m_iInputId}.UpdateSizes);");
  293. }
  294. /**
  295. * Search for objects to be linked to the current object (i.e "remote" objects)
  296. * @param WebPage $oP The page used for the output (usually an AjaxWebPage)
  297. * @param string $sRemoteClass Name of the "remote" class to perform the search on, must be a derived class of m_sRemoteClass
  298. * @param Array $aAlreadyLinkedIds List of IDs of objects of "remote" class already linked, to be filtered out of the search
  299. */
  300. public function SearchObjectsToAdd(WebPage $oP, $sRemoteClass = '', $aAlreadyLinkedIds = array())
  301. {
  302. if ($sRemoteClass != '')
  303. {
  304. // assert(MetaModel::IsParentClass($this->m_sRemoteClass, $sRemoteClass));
  305. $oFilter = new DBObjectSearch($sRemoteClass);
  306. }
  307. else
  308. {
  309. // No remote class specified use the one defined in the linkedset
  310. $oFilter = new DBObjectSearch($this->m_sRemoteClass);
  311. }
  312. if (!$this->m_bDuplicatesAllowed && count($aAlreadyLinkedIds) > 0)
  313. {
  314. // Positive IDs correspond to existing link records
  315. // negative IDs correspond to "remote" objects to be linked
  316. $aLinkIds = array();
  317. $aRemoteObjIds = array();
  318. foreach($aAlreadyLinkedIds as $iId)
  319. {
  320. if ($iId > 0)
  321. {
  322. $aLinkIds[] = $iId;
  323. }
  324. else
  325. {
  326. $aRemoteObjIds[] = -$iId;
  327. }
  328. }
  329. if (count($aLinkIds) >0)
  330. {
  331. // Search for the links to find to which "remote" object they are linked
  332. $oLinkFilter = new DBObjectSearch($this->m_sLinkedClass);
  333. $oLinkFilter->AddCondition('id', $aLinkIds, 'IN');
  334. $oLinkSet = new CMDBObjectSet($oLinkFilter);
  335. while($oLink = $oLinkSet->Fetch())
  336. {
  337. $aRemoteObjIds[] = $oLink->Get($this->m_sExtKeyToRemote);
  338. }
  339. }
  340. $oFilter->AddCondition('id', $aRemoteObjIds, 'NOTIN');
  341. }
  342. $oSet = new CMDBObjectSet($oFilter);
  343. $oBlock = new DisplayBlock($oFilter, 'list', false);
  344. $oBlock->Display($oP, "ResultsToAdd_{$this->m_sAttCode}", array('menu' => false, 'cssCount'=> '#count_'.$this->m_sAttCode.$this->m_sNameSuffix , 'selection_mode' => true)); // Don't display the 'Actions' menu on the results
  345. }
  346. public function DoAddObjects(WebPage $oP, $oFullSetFilter, $oCurrentObj)
  347. {
  348. $aLinkedObjectIds = utils::ReadMultipleSelection($oFullSetFilter);
  349. foreach($aLinkedObjectIds as $iObjectId)
  350. {
  351. $oLinkedObj = MetaModel::GetObject($this->m_sRemoteClass, $iObjectId);
  352. if (is_object($oLinkedObj))
  353. {
  354. $aRow = $this->GetFormRow($oP, $oLinkedObj, -$iObjectId, array(), $oCurrentObj ); // Not yet created link get negative Ids
  355. $oP->add($this->DisplayFormRow($oP, $this->m_aTableConfig, $aRow, -$iObjectId));
  356. }
  357. else
  358. {
  359. $oP->p(Dict::Format('UI:Error:Object_Class_Id_NotFound', $this->m_sLinkedClass, $iObjectId));
  360. }
  361. }
  362. }
  363. /**
  364. * Initializes the default search parameters based on 1) a 'current' object and 2) the silos defined by the context
  365. * @param DBObject $oSourceObj
  366. * @param DBObjectSearch $oSearch
  367. */
  368. protected function SetSearchDefaultFromContext($oSourceObj, &$oSearch)
  369. {
  370. $oAppContext = new ApplicationContext();
  371. $sSrcClass = get_class($oSourceObj);
  372. $sDestClass = $oSearch->GetClass();
  373. foreach($oAppContext->GetNames() as $key)
  374. {
  375. // Find the value of the object corresponding to each 'context' parameter
  376. $aCallSpec = array($sSrcClass, 'MapContextParam');
  377. $sAttCode = '';
  378. if (is_callable($aCallSpec))
  379. {
  380. $sAttCode = call_user_func($aCallSpec, $key); // Returns null when there is no mapping for this parameter
  381. }
  382. if (MetaModel::IsValidAttCode($sSrcClass, $sAttCode))
  383. {
  384. $oAttDef = MetaModel::GetAttributeDef($sSrcClass, $sAttCode);
  385. $defaultValue = $oSourceObj->Get($sAttCode);
  386. // Find the attcode for the same 'context' parameter in the destination class
  387. // and sets its value as the default value for the search condition
  388. $aCallSpec = array($sDestClass, 'MapContextParam');
  389. $sAttCode = '';
  390. if (is_callable($aCallSpec))
  391. {
  392. $sAttCode = call_user_func($aCallSpec, $key); // Returns null when there is no mapping for this parameter
  393. }
  394. if (MetaModel::IsValidAttCode($sDestClass, $sAttCode) && !empty($defaultValue))
  395. {
  396. $oSearch->AddCondition($sAttCode, $defaultValue);
  397. }
  398. }
  399. }
  400. }
  401. }
  402. ?>