public static function GetDashletCreationForm($sOQL = null) { $oForm = new DesignerForm(); // Get the list of all 'dashboard' menus in which we can insert a dashlet $aAllMenus = ApplicationMenu::ReflectionMenuNodes(); $aAllowedDashboards = array(); foreach ($aAllMenus as $idx => $aMenu) { $oMenu = $aMenu['node']; $sParentId = $aMenu['parent']; if ($oMenu instanceof DashboardMenuNode) { $sMenuLabel = $oMenu->GetTitle(); $sParentLabel = Dict::S('Menu:' . $sParentId); if ($sParentLabel != $sMenuLabel) { $aAllowedDashboards[$oMenu->GetMenuId()] = $sParentLabel . ' - ' . $sMenuLabel; } else { $aAllowedDashboards[$oMenu->GetMenuId()] = $sMenuLabel; } } } asort($aAllowedDashboards); $aKeys = array_keys($aAllowedDashboards); // Select the first one by default $sDefaultDashboard = $aKeys[0]; $oField = new DesignerComboField('menu_id', Dict::S('UI:DashletCreation:Dashboard'), $sDefaultDashboard); $oField->SetAllowedValues($aAllowedDashboards); $oField->SetMandatory(true); $oForm->AddField($oField); // Get the list of possible dashlets that support a creation from // an OQL $aDashlets = array(); foreach (get_declared_classes() as $sDashletClass) { if (is_subclass_of($sDashletClass, 'Dashlet')) { $oReflection = new ReflectionClass($sDashletClass); if (!$oReflection->isAbstract()) { $aCallSpec = array($sDashletClass, 'CanCreateFromOQL'); $bShorcutMode = call_user_func($aCallSpec); if ($bShorcutMode) { $aCallSpec = array($sDashletClass, 'GetInfo'); $aInfo = call_user_func($aCallSpec); $aDashlets[$sDashletClass] = array('label' => $aInfo['label'], 'class' => $sDashletClass, 'icon' => $aInfo['icon']); } } } } $oSelectorField = new DesignerFormSelectorField('dashlet_class', Dict::S('UI:DashletCreation:DashletType'), ''); $oForm->AddField($oSelectorField); foreach ($aDashlets as $sDashletClass => $aDashletInfo) { $oSubForm = new DesignerForm(); $oMetaModel = new ModelReflectionRuntime(); $oDashlet = new $sDashletClass($oMetaModel, 0); $oDashlet->GetPropertiesFieldsFromOQL($oSubForm, $sOQL); $oSelectorField->AddSubForm($oSubForm, $aDashletInfo['label'], $aDashletInfo['class']); } $oField = new DesignerBooleanField('open_editor', Dict::S('UI:DashletCreation:EditNow'), true); $oForm->AddField($oField); return $oForm; }
public function GetPropertiesFields(DesignerForm $oForm) { $oField = new DesignerTextField('title', Dict::S('UI:DashletHeaderDynamic:Prop-Title'), $this->aProperties['title']); $oForm->AddField($oField); $oField = $this->oModelReflection->GetIconSelectionField('icon', Dict::S('UI:DashletHeaderDynamic:Prop-Icon'), $this->aProperties['icon']); $oForm->AddField($oField); $oField = new DesignerTextField('subtitle', Dict::S('UI:DashletHeaderDynamic:Prop-Subtitle'), $this->aProperties['subtitle']); $oForm->AddField($oField); $oField = new DesignerTextField('query', Dict::S('UI:DashletHeaderDynamic:Prop-Query'), $this->aProperties['query']); $oField->SetMandatory(); $oForm->AddField($oField); try { // Group by field: build the list of possible values (attribute codes + ...) $oQuery = $this->oModelReflection->GetQuery($this->aProperties['query']); $sClass = $oQuery->GetClass(); $aGroupBy = array(); foreach ($this->oModelReflection->ListAttributes($sClass, 'AttributeEnum,AttributeFinalClass') as $sAttCode => $sAttType) { if (is_subclass_of($sAttType, 'AttributeFinalClass') || $sAttType == 'AttributeFinalClass') { if (!$this->oModelReflection->HasChildrenClasses($sClass)) { continue; } } $sLabel = $this->oModelReflection->GetLabel($sClass, $sAttCode); $aGroupBy[$sAttCode] = $sLabel; } $oField = new DesignerComboField('group_by', Dict::S('UI:DashletHeaderDynamic:Prop-GroupBy'), $this->aProperties['group_by']); $oField->SetMandatory(); $oField->SetAllowedValues($aGroupBy); } catch (Exception $e) { $oField = new DesignerTextField('group_by', Dict::S('UI:DashletHeaderDynamic:Prop-GroupBy'), $this->aProperties['group_by']); $oField->SetReadOnly(); } $oForm->AddField($oField); $oField = new DesignerComboField('values', Dict::S('UI:DashletHeaderDynamic:Prop-Values'), $this->aProperties['values']); $oField->MultipleSelection(true); if (isset($sClass) && $this->oModelReflection->IsValidAttCode($sClass, $this->aProperties['group_by'])) { $aValues = $this->oModelReflection->GetAllowedValues_att($sClass, $this->aProperties['group_by']); $oField->SetAllowedValues($aValues); } else { $oField->SetReadOnly(); } $oForm->AddField($oField); }