/** * Helper for the global list and the details of a given class */ function DisplaySubclasses($oPage, $sClass, $sContext) { $aChildClasses = MetaModel::EnumChildClasses($sClass); if (count($aChildClasses) != 0) { $oPage->add("<ul>\n"); $aOrderedClasses = array(); foreach ($aChildClasses as $sClassName) { // Skip indirect childs, they will be handled somewhere else if (MetaModel::GetParentPersistentClass($sClassName) == $sClass) { $aOrderedClasses[$sClassName] = MetaModel::GetName($sClassName); } } // Sort on the display name asort($aOrderedClasses); foreach ($aOrderedClasses as $sClassName => $sDisplayName) { // Skip indirect childs, they will be handled somewhere else if (MetaModel::GetParentPersistentClass($sClassName) == $sClass) { $oPage->add("<li class=\"open\">" . MakeClassHLink($sClassName, $sContext) . "\n"); DisplaySubclasses($oPage, $sClassName, $sContext); $oPage->add("</li>\n"); } } $oPage->add("</ul>\n"); } }
function DisplayBareRelations(WebPage $oPage, $bEditMode = false) { $aRedundancySettings = $this->FindVisibleRedundancySettings(); // Related objects: display all the linkset attributes, each as a separate tab // In the order described by the 'display' ZList $aList = $this->FlattenZList(MetaModel::GetZListItems(get_class($this), 'details')); if (count($aList) == 0) { // Empty ZList defined, display all the linkedset attributes defined $aList = array_keys(MetaModel::ListAttributeDefs(get_class($this))); } $sClass = get_class($this); foreach ($aList as $sAttCode) { $oAttDef = MetaModel::GetAttributeDef(get_class($this), $sAttCode); // Display mode if (!$oAttDef->IsLinkset()) { continue; } // Process only linkset attributes... // $oSet = new DBObjectSet($this->Get($sAttCode)->GetFilter()); // Why do something so useless ? $oSet = $this->Get($sAttCode); $iCount = $oSet->Count(); $sCount = ''; if ($iCount != 0) { $sCount = " ({$iCount})"; } $oPage->SetCurrentTab($oAttDef->GetLabel() . $sCount); if ($this->IsNew()) { $iFlags = $this->GetInitialStateAttributeFlags($sAttCode); } else { $iFlags = $this->GetAttributeFlags($sAttCode); } // Adjust the flags according to user rights if ($oAttDef->IsIndirect()) { $sLinkedClass = $oAttDef->GetLinkedClass(); $oLinkingAttDef = MetaModel::GetAttributeDef($sLinkedClass, $oAttDef->GetExtKeyToRemote()); $sTargetClass = $oLinkingAttDef->GetTargetClass(); // n:n links => must be allowed to modify the linking class AND read the target class in order to edit the linkedset if (!UserRights::IsActionAllowed($sLinkedClass, UR_ACTION_MODIFY) || !UserRights::IsActionAllowed($sTargetClass, UR_ACTION_READ)) { $iFlags |= OPT_ATT_READONLY; } // n:n links => must be allowed to read the linking class AND the target class in order to display the linkedset if (!UserRights::IsActionAllowed($sLinkedClass, UR_ACTION_READ) || !UserRights::IsActionAllowed($sTargetClass, UR_ACTION_READ)) { $iFlags |= OPT_ATT_HIDDEN; } } else { // 1:n links => must be allowed to modify the linked class in order to edit the linkedset if (!UserRights::IsActionAllowed($oAttDef->GetLinkedClass(), UR_ACTION_MODIFY)) { $iFlags |= OPT_ATT_READONLY; } // 1:n links => must be allowed to read the linked class in order to display the linkedset if (!UserRights::IsActionAllowed($oAttDef->GetLinkedClass(), UR_ACTION_READ)) { $iFlags |= OPT_ATT_HIDDEN; } } // Non-readable/hidden linkedset... don't display anything if ($iFlags & OPT_ATT_HIDDEN) { continue; } $aArgs = array('this' => $this); $bReadOnly = $iFlags & (OPT_ATT_READONLY | OPT_ATT_SLAVE); if ($bEditMode && !$bReadOnly) { $sInputId = $this->m_iFormId . '_' . $sAttCode; $sLinkedClass = $oAttDef->GetLinkedClass(); if ($oAttDef->IsIndirect()) { $oLinkingAttDef = MetaModel::GetAttributeDef($sLinkedClass, $oAttDef->GetExtKeyToRemote()); $sTargetClass = $oLinkingAttDef->GetTargetClass(); } else { $sTargetClass = $sLinkedClass; } $oPage->p(MetaModel::GetClassIcon($sTargetClass) . " " . $oAttDef->GetDescription() . '<span id="busy_' . $sInputId . '"></span>'); $oValue = $this->Get($sAttCode); $sDisplayValue = ''; // not used $sHTMLValue = "<span id=\"field_{$sInputId}\">" . self::GetFormElementForField($oPage, $sClass, $sAttCode, $oAttDef, $oValue, $sDisplayValue, $sInputId, '', $iFlags, $aArgs) . '</span>'; $this->AddToFieldsMap($sAttCode, $sInputId); $oPage->add($sHTMLValue); } else { // Display mode if (!$oAttDef->IsIndirect()) { // 1:n links $sTargetClass = $oAttDef->GetLinkedClass(); $aDefaults = array($oAttDef->GetExtKeyToMe() => $this->GetKey()); $oAppContext = new ApplicationContext(); foreach ($oAppContext->GetNames() as $sKey) { // The linked object inherits the parent's value for the context if (MetaModel::IsValidAttCode($sClass, $sKey)) { $aDefaults[$sKey] = $this->Get($sKey); } } $aParams = array('target_attr' => $oAttDef->GetExtKeyToMe(), 'object_id' => $this->GetKey(), 'menu' => false, 'default' => $aDefaults, 'table_id' => $sClass . '_' . $sAttCode); } else { // n:n links $sLinkedClass = $oAttDef->GetLinkedClass(); $oLinkingAttDef = MetaModel::GetAttributeDef($sLinkedClass, $oAttDef->GetExtKeyToRemote()); $sTargetClass = $oLinkingAttDef->GetTargetClass(); $bMenu = $this->Get($sAttCode)->Count() > 0; // The menu is enabled only if there are already some elements... $aParams = array('link_attr' => $oAttDef->GetExtKeyToMe(), 'object_id' => $this->GetKey(), 'target_attr' => $oAttDef->GetExtKeyToRemote(), 'view_link' => false, 'menu' => false, 'display_limit' => true, 'table_id' => $sClass . '_' . $sAttCode); } $oPage->p(MetaModel::GetClassIcon($sTargetClass) . " " . $oAttDef->GetDescription()); $oBlock = new DisplayBlock($this->Get($sAttCode)->GetFilter(), 'list', false); $oBlock->Display($oPage, 'rel_' . $sAttCode, $aParams); } if (array_key_exists($sAttCode, $aRedundancySettings)) { foreach ($aRedundancySettings[$sAttCode] as $oRedundancyAttDef) { $sRedundancyAttCode = $oRedundancyAttDef->GetCode(); $sValue = $this->Get($sRedundancyAttCode); $iRedundancyFlags = $this->GetFormAttributeFlags($sRedundancyAttCode); $bRedundancyReadOnly = $iRedundancyFlags & (OPT_ATT_READONLY | OPT_ATT_SLAVE); $oPage->add('<fieldset>'); $oPage->add('<legend>' . $oRedundancyAttDef->GetLabel() . '</legend>'); if ($bEditMode && !$bRedundancyReadOnly) { $sInputId = $this->m_iFormId . '_' . $sRedundancyAttCode; $oPage->add("<span id=\"field_{$sInputId}\">" . self::GetFormElementForField($oPage, $sClass, $sRedundancyAttCode, $oRedundancyAttDef, $sValue, '', $sInputId, '', $iFlags, $aArgs) . '</span>'); } else { $oPage->add($oRedundancyAttDef->GetDisplayForm($sValue, $oPage, false, $this->m_iFormId)); } $oPage->add('</fieldset>'); } } } $oPage->SetCurrentTab(''); foreach (MetaModel::EnumPlugins('iApplicationUIExtension') as $oExtensionInstance) { $oExtensionInstance->OnDisplayRelations($this, $oPage, $bEditMode); } // Display Notifications after the other tabs since this tab disappears in edition if (!$bEditMode) { // Look for any trigger that considers this object as "In Scope" // If any trigger has been found then display a tab with notifications // $oTriggerSet = new CMDBObjectSet(new DBObjectSearch('Trigger')); $aTriggers = array(); while ($oTrigger = $oTriggerSet->Fetch()) { if ($oTrigger->IsInScope($this)) { $aTriggers[] = $oTrigger->GetKey(); } } if (count($aTriggers) > 0) { $iId = $this->GetKey(); $sTriggersList = implode(',', $aTriggers); $aNotifSearches = array(); $iNotifsCount = 0; $aNotificationClasses = MetaModel::EnumChildClasses('EventNotification', ENUM_CHILD_CLASSES_EXCLUDETOP); foreach ($aNotificationClasses as $sNotifClass) { $aNotifSearches[$sNotifClass] = DBObjectSearch::FromOQL("SELECT {$sNotifClass} AS Ev JOIN Trigger AS T ON Ev.trigger_id = T.id WHERE T.id IN ({$sTriggersList}) AND Ev.object_id = {$iId}"); $oNotifSet = new DBObjectSet($aNotifSearches[$sNotifClass]); $iNotifsCount += $oNotifSet->Count(); } // Display notifications regarding the object: on block per subclass to have the intersting columns $sCount = $iNotifsCount > 0 ? ' (' . $iNotifsCount . ')' : ''; $oPage->SetCurrentTab(Dict::S('UI:NotificationsTab') . $sCount); foreach ($aNotificationClasses as $sNotifClass) { $oPage->p(MetaModel::GetClassIcon($sNotifClass, true) . ' ' . MetaModel::GetName($sNotifClass)); $oBlock = new DisplayBlock($aNotifSearches[$sNotifClass], 'list', false); $oBlock->Display($oPage, 'notifications_' . $sNotifClass, array('menu' => false)); } } } }
public function EnumChildClasses($sClass, $iOption = ENUM_CHILD_CLASSES_EXCLUDETOP) { return MetaModel::EnumChildClasses($sClass, $iOption); }
/** * Overload the check of the "enable" state of this menu to take into account * derived classes of objects */ public function IsEnabled() { // Enable this menu, only if the current user has enough rights to create such an object, or an object of // any child class $aSubClasses = MetaModel::EnumChildClasses($this->sClass, ENUM_CHILD_CLASSES_ALL); // Including the specified class itself $bActionIsAllowed = false; foreach ($aSubClasses as $sCandidateClass) { if (!MetaModel::IsAbstract($sCandidateClass) && UserRights::IsActionAllowed($sCandidateClass, UR_ACTION_MODIFY) == UR_ALLOWED_YES) { $bActionIsAllowed = true; break; // Enough for now } } return $bActionIsAllowed; }
$iCount = utils::ReadParam('count', 0); $iCurrentPos = utils::ReadParam('position', 0); $iTune = utils::ReadParam('tune', 0); if (empty($sFullText)) { $oPage->p(Dict::S('UI:Search:NoSearch')); break; } // Search in full text mode in all the classes $aMatches = array(); // Build the ordered list of classes to search into // if (empty($sClassName)) { $aSearchClasses = MetaModel::GetClasses('searchable'); } else { // Search is limited to a given class and its subclasses $aSearchClasses = MetaModel::EnumChildClasses($sClassName, ENUM_CHILD_CLASSES_ALL); } // Skip abstract classes, since we search in all the child classes anyway foreach ($aSearchClasses as $idx => $sClass) { if (MetaModel::IsAbstract($sClass)) { unset($aSearchClasses[$idx]); } } $sMaxChunkDuration = MetaModel::GetConfig()->Get('full_text_chunk_duration'); $aAccelerators = MetaModel::GetConfig()->Get('full_text_accelerators'); foreach (array_reverse($aAccelerators) as $sClass => $aRestriction) { $bSkip = false; $iPos = array_search($sClass, $aSearchClasses); if ($iPos !== false) { unset($aSearchClasses[$iPos]); } else {
/** * Describe (as a text string) the modifications corresponding to this change */ public function GetDescription() { $sResult = ''; $oTargetObjectClass = $this->Get('objclass'); $oTargetObjectKey = $this->Get('objkey'); $oTargetSearch = new DBObjectSearch($oTargetObjectClass); $oTargetSearch->AddCondition('id', $oTargetObjectKey, '='); $oMonoObjectSet = new DBObjectSet($oTargetSearch); if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES) { if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) { return ''; } // Protects against renamed attributes... $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode')); $sAttName = $oAttDef->GetLabel(); $sLinkClass = $oAttDef->GetLinkedClass(); $aLinkClasses = MetaModel::EnumChildClasses($sLinkClass, ENUM_CHILD_CLASSES_ALL); // Search for changes on the corresponding link // $oSearch = new DBObjectSearch('CMDBChangeOpSetAttribute'); $oSearch->AddCondition('change', $this->Get('change'), '='); $oSearch->AddCondition('objkey', $this->Get('link_id'), '='); if (count($aLinkClasses) == 1) { // Faster than the whole building of the expression below for just one value ?? $oSearch->AddCondition('objclass', $sLinkClass, '='); } else { $oField = new FieldExpression('objclass', $oSearch->GetClassAlias()); $sListExpr = '(' . implode(', ', CMDBSource::Quote($aLinkClasses)) . ')'; $sOQLCondition = $oField->Render() . " IN {$sListExpr}"; $oNewCondition = Expression::FromOQL($sOQLCondition); $oSearch->AddConditionExpression($oNewCondition); } $oSet = new DBObjectSet($oSearch); $aChanges = array(); while ($oChangeOp = $oSet->Fetch()) { $aChanges[] = $oChangeOp->GetDescription(); } if (count($aChanges) == 0) { return ''; } $sItemDesc = MetaModel::GetHyperLink($this->Get('item_class'), $this->Get('item_id')); $sResult = $sAttName . ' - '; $sResult .= Dict::Format('Change:LinkSet:Modified', $sItemDesc); $sResult .= ' : ' . implode(', ', $aChanges); } return $sResult; }
function DisplayBareRelations(WebPage $oPage, $bEditMode = false) { parent::DisplayBareRelations($oPage, $bEditMode); $sTicketListAttCode = 'tickets_list'; if (MetaModel::IsValidAttCode(get_class($this), $sTicketListAttCode)) { // Display one list per leaf class (the only way to display the status as of now) $oAttDef = MetaModel::GetAttributeDef(get_class($this), $sTicketListAttCode); $sLnkClass = $oAttDef->GetLinkedClass(); $sExtKeyToMe = $oAttDef->GetExtKeyToMe(); $sExtKeyToRemote = $oAttDef->GetExtKeyToRemote(); $iTotal = 0; $aSearches = array(); foreach (MetaModel::EnumChildClasses('Ticket') as $sSubClass) { if (!MetaModel::HasChildrenClasses($sSubClass)) { $sStateAttCode = MetaModel::GetStateAttributeCode($sSubClass); if ($sStateAttCode != '') { $oSearch = DBSearch::FromOQL("SELECT {$sSubClass} AS t JOIN {$sLnkClass} AS lnk ON lnk.{$sExtKeyToRemote} = t.id WHERE {$sExtKeyToMe} = :myself AND {$sStateAttCode} NOT IN ('rejected', 'resolved', 'closed')", array('myself' => $this->GetKey())); $aSearches[$sSubClass] = $oSearch; $oSet = new DBObjectSet($oSearch); $iTotal += $oSet->Count(); } } } $sCount = $iTotal > 0 ? ' (' . $iTotal . ')' : ''; $oPage->SetCurrentTab(Dict::S('Class:FunctionalCI/Tab:OpenedTickets') . $sCount); foreach ($aSearches as $sSubClass => $oSearch) { $sBlockId = __CLASS__ . '_opened_' . $sSubClass; $oPage->add('<fieldset>'); $oPage->add('<legend>' . MetaModel::GetName($sSubClass) . '</legend>'); $oBlock = new DisplayBlock($oSearch, 'list', false); $oBlock->Display($oPage, $sBlockId, array('menu' => false)); $oPage->add('</fieldset>'); } } }
public function GetAllowedValues($aArgs = array(), $sContains = '') { $aRawValues = MetaModel::EnumChildClasses($this->GetHostClass(), ENUM_CHILD_CLASSES_ALL); $aLocalizedValues = array(); foreach ($aRawValues as $sClass) { $aLocalizedValues[$sClass] = MetaModel::GetName($sClass); } return $aLocalizedValues; }
/** * Check the validity of the expression with regard to the data model * and the query in which it is used * * @param ModelReflection $oModelReflection MetaModel to consider * @throws OqlNormalizeException */ public function Check(ModelReflection $oModelReflection, $sSourceQuery) { $aColumnToClasses = array(); foreach ($this->aQueries as $iQuery => $oQuery) { $oQuery->Check($oModelReflection, $sSourceQuery); $aAliasToClass = array($oQuery->GetClassAlias() => $oQuery->GetClass()); $aJoinSpecs = $oQuery->GetJoins(); if (is_array($aJoinSpecs)) { foreach ($aJoinSpecs as $oJoinSpec) { $aAliasToClass[$oJoinSpec->GetClassAlias()] = $oJoinSpec->GetClass(); } } $aSelectedClasses = $oQuery->GetSelectedClasses(); if ($iQuery != 0) { if (count($aSelectedClasses) < count($aColumnToClasses)) { $oLastClass = end($aSelectedClasses); throw new OqlNormalizeException('Too few selected classes in the subquery', $sSourceQuery, $oLastClass); } if (count($aSelectedClasses) > count($aColumnToClasses)) { $oLastClass = end($aSelectedClasses); throw new OqlNormalizeException('Too many selected classes in the subquery', $sSourceQuery, $oLastClass); } } foreach ($aSelectedClasses as $iColumn => $oClassDetails) { $sAlias = $oClassDetails->GetValue(); $sClass = $aAliasToClass[$sAlias]; $aColumnToClasses[$iColumn][] = array('alias' => $sAlias, 'class' => $sClass, 'class_name' => $oClassDetails); } } foreach ($aColumnToClasses as $iColumn => $aClasses) { foreach ($aClasses as $iQuery => $aData) { if ($iQuery == 0) { // Establish the reference $sRootClass = MetaModel::GetRootClass($aData['class']); } else { if (MetaModel::GetRootClass($aData['class']) != $sRootClass) { $aSubclasses = MetaModel::EnumChildClasses($sRootClass, ENUM_CHILD_CLASSES_ALL); throw new OqlNormalizeException('Incompatible classes: could not find a common ancestor', $sSourceQuery, $aData['class_name'], $aSubclasses); } } } } }
/** * Read a list of attribute codes from a Rest/Json structure. * * @param string $sClass Name of the class * @param StdClass $oData Structured input data. * @param string $sParamName Name of the parameter to fetch from the input data * @return An array of class => list of attributes (see RestResultWithObjects::AddObject that uses it) * @throws Exception * @api */ public static function GetFieldList($sClass, $oData, $sParamName) { $sFields = self::GetOptionalParam($oData, $sParamName, '*'); $aShowFields = array(); if ($sFields == '*') { foreach (MetaModel::ListAttributeDefs($sClass) as $sAttCode => $oAttDef) { $aShowFields[$sClass][] = $sAttCode; } } elseif ($sFields == '*+') { foreach (MetaModel::EnumChildClasses($sClass, ENUM_CHILD_CLASSES_ALL) as $sRefClass) { foreach (MetaModel::ListAttributeDefs($sRefClass) as $sAttCode => $oAttDef) { $aShowFields[$sRefClass][] = $sAttCode; } } } else { foreach (explode(',', $sFields) as $sAttCode) { $sAttCode = trim($sAttCode); if ($sAttCode != 'id' && !MetaModel::IsValidAttCode($sClass, $sAttCode)) { throw new Exception("{$sParamName}: invalid attribute code '{$sAttCode}'"); } $aShowFields[$sClass][] = $sAttCode; } } return $aShowFields; }
/** * Get the friendly name for the class and its subclasses (if finalclass = 'subclass' ...) * Simplifies the final expression by grouping classes having the same name expression * Used when querying a parent class */ protected static function GetExtendedNameExpression($sClass) { // 1st step - get all of the required expressions (instantiable classes) // and group them using their OQL representation // $aFNExpressions = array(); // signature => array('expression' => oExp, 'classes' => array of classes) foreach (MetaModel::EnumChildClasses($sClass, ENUM_CHILD_CLASSES_ALL) as $sSubClass) { if ($sSubClass != $sClass && MetaModel::IsAbstract($sSubClass)) { continue; } $oSubClassName = MetaModel::GetNameExpression($sSubClass); $sSignature = $oSubClassName->Render(); if (!array_key_exists($sSignature, $aFNExpressions)) { $aFNExpressions[$sSignature] = array('expression' => $oSubClassName, 'classes' => array()); } $aFNExpressions[$sSignature]['classes'][] = $sSubClass; } // 2nd step - build the final name expression depending on the finalclass // if (count($aFNExpressions) == 1) { $aExpData = reset($aFNExpressions); $oNameExpression = $aExpData['expression']; } else { $oNameExpression = null; foreach ($aFNExpressions as $sSignature => $aExpData) { $oClassListExpr = ListExpression::FromScalars($aExpData['classes']); $oClassExpr = new FieldExpression('finalclass', $sClass); $oClassInList = new BinaryExpression($oClassExpr, 'IN', $oClassListExpr); if (is_null($oNameExpression)) { $oNameExpression = $aExpData['expression']; } else { $oNameExpression = new FunctionExpression('IF', array($oClassInList, $aExpData['expression'], $oNameExpression)); } } } return $oNameExpression; }
$oP->add(Dict::S('UI:NotificationsMenu:HelpContent')); $oP->add('</div>'); $oP->add(''); $oP->add(''); $oP->EndCollapsibleSection(); $oP->add('<p> </p>'); $oP->AddTabContainer('Tabs_0'); $oP->SetCurrentTabContainer('Tabs_0'); $oP->SetCurrentTab(Dict::S('UI:NotificationsMenu:Triggers')); $oP->add('<h2>' . Dict::S('UI:NotificationsMenu:AvailableTriggers') . '</h2>'); $oFilter = new DBObjectSearch('Trigger'); $aParams = array(); $oBlock = new DisplayBlock($oFilter, 'list', false, $aParams); $oBlock->Display($oP, 'block_0', $aParams); $aActionClasses = array(); foreach (MetaModel::EnumChildClasses('Action', ENUM_CHILD_CLASSES_EXCLUDETOP) as $sActionClass) { if (!MetaModel::IsAbstract($sActionClass)) { $aActionClasses[] = $sActionClass; } } $oP->SetCurrentTab(Dict::S('UI:NotificationsMenu:Actions')); if (count($aActionClasses) == 1) { // Preserve old style $oP->add('<h2>' . Dict::S('UI:NotificationsMenu:AvailableActions') . '</h2>'); } $iBlock = 0; foreach ($aActionClasses as $sActionClass) { if (count($aActionClasses) > 1) { // New style $oP->add('<h2>' . MetaModel::GetName($sActionClass) . '</h2>'); }
/////////////////////////////////////////////////////////////////////////////////////////// case 'new': // Form to create a new object $sClass = utils::ReadParam('class', '', false, 'class'); $sStateCode = utils::ReadParam('state', ''); $bCheckSubClass = utils::ReadParam('checkSubclass', true); if (empty($sClass)) { throw new ApplicationException(Dict::Format('UI:Error:1ParametersMissing', 'class')); } $aArgs = utils::ReadParam('default', array(), false, 'raw_data'); $aContext = $oAppContext->GetAsHash(); foreach ($oAppContext->GetNames() as $key) { $aArgs[$key] = $oAppContext->GetCurrentValue($key); } // If the specified class has subclasses, ask the user an instance of which class to create $aSubClasses = MetaModel::EnumChildClasses($sClass, ENUM_CHILD_CLASSES_ALL); // Including the specified class itself $aPossibleClasses = array(); $sRealClass = ''; if ($bCheckSubClass) { foreach ($aSubClasses as $sCandidateClass) { if (!MetaModel::IsAbstract($sCandidateClass) && UserRights::IsActionAllowed($sCandidateClass, UR_ACTION_MODIFY) == UR_ALLOWED_YES) { $aPossibleClasses[$sCandidateClass] = MetaModel::GetName($sCandidateClass); } } // Only one of the subclasses can be instantiated... if (count($aPossibleClasses) == 1) { $aKeys = array_keys($aPossibleClasses); $sRealClass = $aKeys[0]; } } else {
public function GetObjectCreationDlg(WebPage $oPage, $sProposedRealClass = '') { // For security reasons: check that the "proposed" class is actually a subclass of the linked class // and that the current user is allowed to create objects of this class $sRealClass = ''; $oPage->add('<div class="wizContainer" style="vertical-align:top;"><div>'); $aSubClasses = MetaModel::EnumChildClasses($this->sLinkedClass, ENUM_CHILD_CLASSES_ALL); // Including the specified class itself $aPossibleClasses = array(); foreach ($aSubClasses as $sCandidateClass) { if (!MetaModel::IsAbstract($sCandidateClass) && UserRights::IsActionAllowed($sCandidateClass, UR_ACTION_MODIFY) == UR_ALLOWED_YES) { if ($sCandidateClass == $sProposedRealClass) { $sRealClass = $sProposedRealClass; } $aPossibleClasses[$sCandidateClass] = MetaModel::GetName($sCandidateClass); } } // Only one of the subclasses can be instantiated... if (count($aPossibleClasses) == 1) { $aKeys = array_keys($aPossibleClasses); $sRealClass = $aKeys[0]; } if ($sRealClass != '') { $oPage->add("<h1>" . MetaModel::GetClassIcon($sRealClass) . " " . Dict::Format('UI:CreationTitle_Class', MetaModel::GetName($sRealClass)) . "</h1>\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)); } else { $sClassLabel = MetaModel::GetName($this->sLinkedClass); $oPage->add('<p>' . Dict::Format('UI:SelectTheTypeOf_Class_ToCreate', $sClassLabel)); $oPage->add('<nobr><select name="class">'); asort($aPossibleClasses); foreach ($aPossibleClasses as $sClassName => $sClassLabel) { $oPage->add("<option value=\"{$sClassName}\">{$sClassLabel}</option>"); } $oPage->add('</select>'); $oPage->add(' <button type="button" onclick="$(\'#' . $this->sInputid . '\').directlinks(\'subclassSelected\');">' . Dict::S('UI:Button:Apply') . '</button><span class="indicator" style="display:inline-block;width:16px"></span></nobr></p>'); } $oPage->add('</div></div>'); }