Example #1
0
 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)
 {
     if (is_null(self::$aClassList)) {
         // Cache the ordered list of classes (ordered on the label)
         // (has a significant impact when editing a page with lots of badges)
         //
         $aClasses = array();
         foreach ($this->oModelReflection->GetClasses('bizmodel', true) as $sClass) {
             $aClasses[$sClass] = $this->oModelReflection->GetName($sClass);
         }
         asort($aClasses);
         self::$aClassList = array();
         foreach ($aClasses as $sClass => $sLabel) {
             $sIconUrl = $this->oModelReflection->GetClassIcon($sClass, false);
             $sIconFilePath = str_replace(utils::GetAbsoluteUrlAppRoot(), APPROOT, $sIconUrl);
             if ($sIconUrl == '') {
                 // The icon does not exist, let's use a transparent one of the same size.
                 $sIconUrl = utils::GetAbsoluteUrlAppRoot() . 'images/transparent_32_32.png';
             }
             self::$aClassList[] = array('value' => $sClass, 'label' => $sLabel, 'icon' => $sIconUrl);
         }
     }
     $oField = new DesignerIconSelectionField('class', Dict::S('UI:DashletBadge:Prop-Class'), $this->aProperties['class']);
     $oField->SetAllowedValues(self::$aClassList);
     $oForm->AddField($oField);
 }
Example #3
0
 public function __construct()
 {
     parent::__construct();
     $this->aTable = array();
 }
 public static function GetCreationForm($sOQL = null, $sTableSettings = null)
 {
     $oForm = new DesignerForm();
     // Find a unique default name
     // -> The class of the query + an index if necessary
     if ($sOQL == null) {
         $sDefault = '';
     } else {
         $oBMSearch = new DBObjectSearch('Shortcut');
         $oBMSearch->AddCondition('user_id', UserRights::GetUserId(), '=');
         $oBMSet = new DBObjectSet($oBMSearch);
         $aNames = $oBMSet->GetColumnAsArray('name');
         $oSearch = DBObjectSearch::FromOQL($sOQL);
         $sDefault = utils::MakeUniqueName($oSearch->GetClass(), $aNames);
     }
     $oField = new DesignerTextField('name', Dict::S('Class:Shortcut/Attribute:name'), $sDefault);
     $oField->SetMandatory(true);
     $oForm->AddField($oField);
     /*
     $oField = new DesignerComboField('auto_reload', Dict::S('Class:ShortcutOQL/Attribute:auto_reload'), 'none');
     $oAttDef = MetaModel::GetAttributeDef(__class__, 'auto_reload');
     $oField->SetAllowedValues($oAttDef->GetAllowedValues());
     $oField->SetMandatory(true);
     $oForm->AddField($oField);
     */
     $oField = new DesignerBooleanField('auto_reload', Dict::S('Class:ShortcutOQL/Attribute:auto_reload'), false);
     $oForm->AddField($oField);
     $oField = new DesignerTextField('auto_reload_sec', Dict::S('Class:ShortcutOQL/Attribute:auto_reload_sec'), MetaModel::GetConfig()->GetStandardReloadInterval());
     $oField->SetValidationPattern('^$|^0*([5-9]|[1-9][0-9]+)$');
     // Can be empty, or a number > 4
     $oField->SetMandatory(false);
     $oForm->AddField($oField);
     $oField = new DesignerHiddenField('oql', '', $sOQL);
     $oForm->AddField($oField);
     $oField = new DesignerHiddenField('table_settings', '', $sTableSettings);
     $oForm->AddField($oField);
     return $oForm;
 }