diff --git a/application/ui.linksdirectwidget.class.inc.php b/application/ui.linksdirectwidget.class.inc.php index 6f558f38b9..e62729f8bf 100644 --- a/application/ui.linksdirectwidget.class.inc.php +++ b/application/ui.linksdirectwidget.class.inc.php @@ -30,7 +30,14 @@ class UILinksWidgetDirect protected $sInputid; protected $sNameSuffix; protected $sLinkedClass; - + + /** + * UILinksWidgetDirect constructor. + * @param string $sClass + * @param string $sAttCode + * @param string $sInputId + * @param string $sNameSuffix + */ public function __construct($sClass, $sAttCode, $sInputId, $sNameSuffix = '') { $this->sClass = $sClass; @@ -74,12 +81,12 @@ class UILinksWidgetDirect /** * @param WebPage $oPage - * @param DBObjectSet $oValue + * @param DBObjectSet|ormLinkSet $oValue * @param array $aArgs - * @param $sFormPrefix - * @param $oCurrentObj + * @param string $sFormPrefix + * @param DBObject $oCurrentObj */ - public function Display(WebPage $oPage, DBObjectSet $oValue, $aArgs = array(), $sFormPrefix, $oCurrentObj) + public function Display(WebPage $oPage, $oValue, $aArgs = array(), $sFormPrefix, $oCurrentObj) { $oLinksetDef = MetaModel::GetAttributeDef($this->sClass, $this->sAttCode); switch($oLinksetDef->GetEditMode()) @@ -127,11 +134,11 @@ class UILinksWidgetDirect * @param WebPage $oPage * @param DBObjectSet $oValue * @param array $aArgs - * @param $sFormPrefix - * @param $oCurrentObj - * @param $bDisplayMenu + * @param string $sFormPrefix + * @param DBObject $oCurrentObj + * @param bool $bDisplayMenu */ - protected function DisplayAsBlock(WebPage $oPage, DBObjectSet $oValue, $aArgs = array(), $sFormPrefix, $oCurrentObj, $bDisplayMenu) + protected function DisplayAsBlock(WebPage $oPage, $oValue, $aArgs = array(), $sFormPrefix, $oCurrentObj, $bDisplayMenu) { $oLinksetDef = MetaModel::GetAttributeDef($this->sClass, $this->sAttCode); $sTargetClass = $oLinksetDef->GetLinkedClass(); @@ -170,50 +177,8 @@ class UILinksWidgetDirect /** * @param WebPage $oPage - * @param DBObjectSet $oValue - * @param array $aArgs - * @param $sFormPrefix - * @param $oCurrentObj - * @param array $aButtons + * @param string $sProposedRealClass */ - protected function DisplayEditInPlace(WebPage $oPage, DBObjectSet $oValue, $aArgs = array(), $sFormPrefix, $oCurrentObj, $aButtons = array('create', 'delete')) - { - $aAttribs = $this->GetTableConfig(); - - $oValue->Rewind(); - $oPage->add('
'); - - $aData = array(); - while($oLinkObj = $oValue->Fetch()) - { - $aRow = array(); - $aRow['form::select'] = ''; - foreach($this->aZlist as $sLinkedAttCode) - { - $aRow[$sLinkedAttCode] = $oLinkObj->GetAsHTML($sLinkedAttCode); - } - $aData[] = $aRow; - } - $oPage->table($aAttribs, $aData); - $oPage->add('
'); //listcontainer - $sInputName = $sFormPrefix.'attr_'.$this->sAttCode; - $aLabels = array( - 'delete' => Dict::S('UI:Button:Delete'), - // 'modify' => 'Modify...' , - 'creation_title' => Dict::Format('UI:CreationTitle_Class', MetaModel::GetName($this->sLinkedClass)), - 'create' => Dict::Format('UI:ClickToCreateNew', MetaModel::GetName($this->sLinkedClass)), - 'remove' => Dict::S('UI:Button:Remove'), - 'add' => Dict::Format('UI:AddAnExisting_Class', MetaModel::GetName($this->sLinkedClass)), - 'selection_title' => Dict::Format('UI:SelectionOf_Class', MetaModel::GetName($this->sLinkedClass)), - ); - $oContext = new ApplicationContext(); - $sSubmitUrl = utils::GetAbsoluteUrlAppRoot().'pages/ajax.render.php?'.$oContext->GetForLink(); - $sJSONLabels = json_encode($aLabels); - $sJSONButtons = json_encode($aButtons); - $sWizHelper = 'oWizardHelper'.$sFormPrefix; - $oPage->add_ready_script("$('#{$this->sInputid}').directlinks({class_name: '$this->sClass', att_code: '$this->sAttCode', input_name:'$sInputName', labels: $sJSONLabels, submit_to: '$sSubmitUrl', buttons: $sJSONButtons, oWizardHelper: $sWizHelper });"); - } - public function GetObjectCreationDlg(WebPage $oPage, $sProposedRealClass = '') { // For security reasons: check that the "proposed" class is actually a subclass of the linked class @@ -239,14 +204,14 @@ class UILinksWidgetDirect $aKeys = array_keys($aPossibleClasses); $sRealClass = $aKeys[0]; } - + if ($sRealClass != '') { $oPage->add("

".MetaModel::GetClassIcon($sRealClass)." ".Dict::Format('UI:CreationTitle_Class', MetaModel::GetName($sRealClass))."

\n"); $oLinksetDef = MetaModel::GetAttributeDef($this->sClass, $this->sAttCode); $sExtKeyToMe = $oLinksetDef->GetExtKeyToMe(); $aFieldFlags = array( $sExtKeyToMe => OPT_ATT_HIDDEN); - cmdbAbstractObject::DisplayCreationForm($oPage, $sRealClass, null, array(), array('formPrefix' => $this->sInputid, 'noRelations' => true, 'fieldsFlags' => $aFieldFlags)); + cmdbAbstractObject::DisplayCreationForm($oPage, $sRealClass, null, array(), array('formPrefix' => $this->sInputid, 'noRelations' => true, 'fieldsFlags' => $aFieldFlags)); } else { @@ -263,7 +228,58 @@ class UILinksWidgetDirect } $oPage->add(''); } - + + /** + * @param WebPage $oPage + * @param DBObjectSet $oValue + * @param array $aArgs + * @param string $sFormPrefix + * @param DBObject $oCurrentObj + * @param array $aButtons + */ + protected function DisplayEditInPlace(WebPage $oPage, $oValue, $aArgs = array(), $sFormPrefix, $oCurrentObj, $aButtons = array('create', 'delete')) + { + $aAttribs = $this->GetTableConfig(); + + $oValue->Rewind(); + $oPage->add('
'); + + $aData = array(); + while($oLinkObj = $oValue->Fetch()) + { + $aRow = array(); + $aRow['form::select'] = ''; + foreach($this->aZlist as $sLinkedAttCode) + { + $aRow[$sLinkedAttCode] = $oLinkObj->GetAsHTML($sLinkedAttCode); + } + $aData[] = $aRow; + } + $oPage->table($aAttribs, $aData); + $oPage->add('
'); //listcontainer + $sInputName = $sFormPrefix.'attr_'.$this->sAttCode; + $aLabels = array( + 'delete' => Dict::S('UI:Button:Delete'), + // 'modify' => 'Modify...' , + 'creation_title' => Dict::Format('UI:CreationTitle_Class', MetaModel::GetName($this->sLinkedClass)), + 'create' => Dict::Format('UI:ClickToCreateNew', MetaModel::GetName($this->sLinkedClass)), + 'remove' => Dict::S('UI:Button:Remove'), + 'add' => Dict::Format('UI:AddAnExisting_Class', MetaModel::GetName($this->sLinkedClass)), + 'selection_title' => Dict::Format('UI:SelectionOf_Class', MetaModel::GetName($this->sLinkedClass)), + ); + $oContext = new ApplicationContext(); + $sSubmitUrl = utils::GetAbsoluteUrlAppRoot().'pages/ajax.render.php?'.$oContext->GetForLink(); + $sJSONLabels = json_encode($aLabels); + $sJSONButtons = json_encode($aButtons); + $sWizHelper = 'oWizardHelper'.$sFormPrefix; + $oPage->add_ready_script("$('#{$this->sInputid}').directlinks({class_name: '$this->sClass', att_code: '$this->sAttCode', input_name:'$sInputName', labels: $sJSONLabels, submit_to: '$sSubmitUrl', buttons: $sJSONButtons, oWizardHelper: $sWizHelper });"); + } + + /** + * @param WebPage $oPage + * @param DBObject $oCurrentObj + * @throws Exception + */ public function GetObjectsSelectionDlg($oPage, $oCurrentObj) { $sHtml = "
\n"; @@ -299,13 +315,14 @@ class UILinksWidgetDirect $sHtml .= "\n"; $oPage->add($sHtml); } - + /** * Search for objects to be linked to the current object (i.e "remote" objects) * @param WebPage $oP The page used for the output (usually an AjaxWebPage) * @param string $sRemoteClass Name of the "remote" class to perform the search on, must be a derived class of $this->sLinkedClass * @param array $aAlreadyLinked Array of indentifiers of objects which are already linke to the current object (or about to be linked) * @param DBObject $oCurrentObj The object currently being edited... if known... + * @throws Exception */ public function SearchObjectsToAdd(WebPage $oP, $sRemoteClass = '', $aAlreadyLinked = array(), $oCurrentObj = null) { @@ -350,6 +367,10 @@ class UILinksWidgetDirect $oBlock->Display($oP, "ResultsToAdd_{$this->sInputid}", array('menu' => false, 'cssCount'=> '#count_'.$this->sInputid , 'selection_mode' => true, 'table_id' => 'add_'.$this->sInputid)); // Don't display the 'Actions' menu on the results } + /** + * @param WebPage $oP + * @param $oFullSetFilter + */ public function DoAddObjects(WebPage $oP, $oFullSetFilter) { $aLinkedObjectIds = utils::ReadMultipleSelection($oFullSetFilter); @@ -377,7 +398,14 @@ class UILinksWidgetDirect } return $aAttribs; } - + + /** + * @param WebPage $oPage + * @param string $sRealClass + * @param array $aValues + * @param int $iTempId + * @return mixed + */ public function GetRow($oPage, $sRealClass, $aValues, $iTempId) { if ($sRealClass == '') @@ -389,7 +417,13 @@ class UILinksWidgetDirect return $this->GetObjectRow($oPage, $oLinkObj, $iTempId); } - + + /** + * @param WebPage $oPage + * @param $oLinkObj + * @param int $iTempId + * @return mixed + */ protected function GetObjectRow($oPage, $oLinkObj, $iTempId) { $aAttribs = $this->GetTableConfig(); @@ -405,7 +439,7 @@ class UILinksWidgetDirect /** * Initializes the default search parameters based on 1) a 'current' object and 2) the silos defined by the context * @param DBObject $oSourceObj - * @param DBSearch $oSearch + * @param DBSearch|DBObjectSearch $oSearch */ protected function SetSearchDefaultFromContext($oSourceObj, &$oSearch) { @@ -424,7 +458,6 @@ class UILinksWidgetDirect if (MetaModel::IsValidAttCode($sSrcClass, $sAttCode)) { - $oAttDef = MetaModel::GetAttributeDef($sSrcClass, $sAttCode); $defaultValue = $oSourceObj->Get($sAttCode); // Find the attcode for the same 'context' parameter in the destination class diff --git a/application/ui.linkswidget.class.inc.php b/application/ui.linkswidget.class.inc.php index db034cb4fb..60a746dc8f 100644 --- a/application/ui.linkswidget.class.inc.php +++ b/application/ui.linkswidget.class.inc.php @@ -39,7 +39,15 @@ class UILinksWidget protected $m_sLinkedClass; protected $m_sRemoteClass; protected $m_bDuplicatesAllowed; - + + /** + * UILinksWidget constructor. + * @param string $sClass + * @param string $sAttCode + * @param int $iInputId + * @param string $sNameSuffix + * @param bool $bDuplicatesAllowed + */ public function __construct($sClass, $sAttCode, $iInputId, $sNameSuffix = '', $bDuplicatesAllowed = false) { $this->m_sClass = $sClass; @@ -98,11 +106,11 @@ class UILinksWidget * @param WebPage $oP Web page used for the ouput * @param DBObject $oLinkedObj Remote object * @param mixed $linkObjOrId Either the object linked or a unique number for new link records to add - * @param array|Hash $aArgs Extra context arguments - * @param $oCurrentObj The object to which all the elements of the linked set refer to - * @param $iUniqueId A unique identifier of new links - * @param boolean $bReadOnly Display link as editable or read-only. Default is false (editable) - * @return string The HTML fragment of the one-row form + * @param array $aArgs Extra context arguments + * @param DBObject $oCurrentObj The object to which all the elements of the linked set refer to + * @param int $iUniqueId A unique identifier of new links + * @param boolean $bReadOnly Display link as editable or read-only. Default is false (editable) + * @return array The HTML fragment of the one-row form */ protected function GetFormRow(WebPage $oP, DBObject $oLinkedObj, $linkObjOrId, $aArgs, $oCurrentObj, $iUniqueId, $bReadOnly = false) { @@ -229,7 +237,11 @@ EOF /** * Display one row of the whole form - * @return none + * @param WebPage $oP + * @param array $aConfig + * @param array $aRow + * @param int $iRowId + * @return string */ protected function DisplayFormRow(WebPage $oP, $aConfig, $aRow, $iRowId) { @@ -247,8 +259,8 @@ EOF /** * Display the table with the form for editing all the links at once * @param WebPage $oP The web page used for the output - * @param Hash $aConfig The table's header configuration - * @param Hash $aData The tabular data to be displayed + * @param array $aConfig The table's header configuration + * @param array $aData The tabular data to be displayed * @return string Html fragment representing the form table */ protected function DisplayFormTable(WebPage $oP, $aConfig, $aData) @@ -285,21 +297,20 @@ EOF return $sHtml; } - + /** * Get the HTML fragment corresponding to the linkset editing widget - * @param WebPage $oP The web page used for all the output - * @param DBObjectSet The initial value of the linked set - * @param Hash $aArgs Extra context arguments + * @param WebPage $oPage + * @param DBObject|ormLinkSet $oValue + * @param array $aArgs Extra context arguments * @param string $sFormPrefix prefix of the fields in the current form * @param DBObject $oCurrentObj the current object to which the linkset is related * @return string The HTML fragment to be inserted into the page */ - public function Display(WebPage $oPage, DBObjectSet $oValue, $aArgs = array(), $sFormPrefix, $oCurrentObj) + public function Display(WebPage $oPage, $oValue, $aArgs = array(), $sFormPrefix, $oCurrentObj) { $sHtmlValue = ''; - $sTargetClass = self::GetTargetClass($this->m_sClass, $this->m_sAttCode); $sHtmlValue .= "
m_sAttCode}{$this->m_sNameSuffix}\">\n"; $sHtmlValue .= "m_iInputId}\">\n"; $oValue->Rewind(); @@ -346,11 +357,17 @@ EOF $oPage->add_at_the_end("
m_sAttCode}{$this->m_sNameSuffix}\">
"); // To prevent adding forms inside the main form return $sHtmlValue; } - + + /** + * @param string $sClass + * @param string $sAttCode + * @return string + */ protected static function GetTargetClass($sClass, $sAttCode) { $oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode); $sLinkedClass = $oAttDef->GetLinkedClass(); + $sTargetClass = ''; switch(get_class($oAttDef)) { case 'AttributeLinkedSetIndirect': @@ -365,7 +382,11 @@ EOF return $sTargetClass; } - + + /** + * @param WebPage $oPage + * @param DBObject $oCurrentObj + */ public function GetObjectPickerDialog($oPage, $oCurrentObj) { $bOpen = MetaModel::GetConfig()->Get('legacy_search_drawer_open'); @@ -414,7 +435,13 @@ EOF $oBlock = new DisplayBlock($oFilter, 'list', false); $oBlock->Display($oP, "ResultsToAdd_{$this->m_sAttCode}", array('menu' => false, 'cssCount'=> '#count_'.$this->m_sAttCode.$this->m_sNameSuffix , 'selection_mode' => true, 'table_id' => 'add_'.$this->m_sAttCode)); // Don't display the 'Actions' menu on the results } - + + /** + * @param WebPage $oP + * @param int $iMaxAddedId + * @param $oFullSetFilter + * @param DBObject $oCurrentObj + */ public function DoAddObjects(WebPage $oP, $iMaxAddedId, $oFullSetFilter, $oCurrentObj) { $aLinkedObjectIds = utils::ReadMultipleSelection($oFullSetFilter); @@ -439,7 +466,7 @@ EOF /** * Initializes the default search parameters based on 1) a 'current' object and 2) the silos defined by the context * @param DBObject $oSourceObj - * @param DBSearch $oSearch + * @param DBSearch|DBObjectSearch $oSearch */ protected function SetSearchDefaultFromContext($oSourceObj, &$oSearch) { @@ -458,7 +485,6 @@ EOF if (MetaModel::IsValidAttCode($sSrcClass, $sAttCode)) { - $oAttDef = MetaModel::GetAttributeDef($sSrcClass, $sAttCode); $defaultValue = $oSourceObj->Get($sAttCode); // Find the attcode for the same 'context' parameter in the destination class diff --git a/core/ormlinkset.class.inc.php b/core/ormlinkset.class.inc.php index 8639f3efe4..152ea4d115 100644 --- a/core/ormlinkset.class.inc.php +++ b/core/ormlinkset.class.inc.php @@ -74,6 +74,14 @@ class ormLinkSet implements iDBObjectSetIterator, Iterator, SeekableIterator */ protected $iCursor = 0; + /** + * __toString magical function overload. + */ + public function __toString() + { + return ''; + } + /** * ormLinkSet constructor. * @param $sHostClass