/** * Persistent class Shortcut and derived * Shortcuts of any kind * * @copyright Copyright (C) 2010-2016 Combodo SARL * @license http://opensource.org/licenses/AGPL-3.0 */ abstract class Shortcut extends DBObject implements iDisplay { public static function Init() { $aParams = array ( "category" => "gui,view_in_gui", "key_type" => "autoincrement", "name_attcode" => "name", "state_attcode" => "", "reconc_keys" => array(), "db_table" => "priv_shortcut", "db_key_field" => "id", "db_finalclass_field" => "realclass", "display_template" => "", ); MetaModel::Init_Params($aParams); //MetaModel::Init_InheritAttributes(); MetaModel::Init_AddAttribute(new AttributeExternalKey("user_id", array("targetclass"=>"User", "allowed_values"=>null, "sql"=>"user_id", "is_null_allowed"=>true, "on_target_delete"=>DEL_AUTO, "depends_on"=>array()))); MetaModel::Init_AddAttribute(new AttributeString("name", array("allowed_values"=>null, "sql"=>"name", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array()))); MetaModel::Init_AddAttribute(new AttributeText("context", array("allowed_values"=>null, "sql"=>"context", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array()))); // Display lists MetaModel::Init_SetZListItems('details', array('name', 'context')); // Attributes to be displayed for the complete details MetaModel::Init_SetZListItems('list', array('name')); // Attributes to be displayed for a list // Search criteria // MetaModel::Init_SetZListItems('standard_search', array('name')); // Criteria of the std search form // MetaModel::Init_SetZListItems('advanced_search', array('name')); // Criteria of the advanced search form } abstract public function RenderContent(WebPage $oPage, $aExtraParams = array()); protected function OnInsert() { $this->Set('user_id', UserRights::GetUserId()); } public function StartRenameDialog($oPage) { $oPage->add('
'); $oForm = new DesignerForm(); $sDefault = $this->Get('name'); $oField = new DesignerTextField('name', Dict::S('Class:Shortcut/Attribute:name'), $sDefault); $oField->SetMandatory(true); $oForm->AddField($oField); $oForm->Render($oPage); $oPage->add('
'); $sDialogTitle = Dict::S('UI:ShortcutRenameDlg:Title'); $sOkButtonLabel = Dict::S('UI:Button:Ok'); $sCancelButtonLabel = Dict::S('UI:Button:Cancel'); $iShortcut = $this->GetKey(); $oPage->add_ready_script( << "gui,view_in_gui", "key_type" => "autoincrement", "name_attcode" => "name", "state_attcode" => "", "reconc_keys" => array(), "db_table" => "priv_shortcut_oql", "db_key_field" => "id", "db_finalclass_field" => "", "display_template" => "", ); MetaModel::Init_Params($aParams); MetaModel::Init_InheritAttributes(); MetaModel::Init_AddAttribute(new AttributeOQL("oql", array("allowed_values"=>null, "sql"=>"oql", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array()))); MetaModel::Init_AddAttribute(new AttributeEnum("auto_reload", array("allowed_values"=>new ValueSetEnum('none,custom'), "sql"=>"auto_reload", "default_value"=>"none", "is_null_allowed"=>false, "depends_on"=>array()))); MetaModel::Init_AddAttribute(new AttributeInteger("auto_reload_sec", array("allowed_values"=>null, "sql"=>"auto_reload_sec", "default_value"=>60, "is_null_allowed"=>false, "depends_on"=>array()))); // Display lists MetaModel::Init_SetZListItems('details', array('name', 'context', 'oql')); // Attributes to be displayed for the complete details MetaModel::Init_SetZListItems('list', array('name')); // Attributes to be displayed for a list // Search criteria // MetaModel::Init_SetZListItems('standard_search', array('name')); // Criteria of the std search form // MetaModel::Init_SetZListItems('advanced_search', array('name')); // Criteria of the advanced search form } public function RenderContent(WebPage $oPage, $aExtraParams = array()) { $oPage->set_title($this->Get('name')); switch($this->Get('auto_reload')) { case 'custom': $iRate = (int)$this->Get('auto_reload_sec'); if ($iRate > 0) { // Must a string otherwise it can be evaluated to 'true' and defaults to "standard" refresh rate! $aExtraParams['auto_reload'] = (string)$iRate; } break; default: case 'none': } $bSearchPane = true; $bSearchOpen = false; try { OQLMenuNode::RenderOQLSearch($this->Get('oql'), $this->Get('name'), 'shortcut_'.$this->GetKey(), $bSearchPane, $bSearchOpen, $oPage, $aExtraParams, true); } catch (Exception $e) { throw new Exception("The OQL shortcut '".$this->Get('name')."' (id: ".$this->GetKey().") could not be displayed: ".$e->getMessage()); } } public function CloneTableSettings($sTableSettings) { $aTableSettings = json_decode($sTableSettings, true); $oFilter = DBObjectSearch::FromOQL($this->Get('oql')); $oCustomSettings = new DataTableSettings($oFilter->GetSelectedClasses()); $oCustomSettings->iDefaultPageSize = $aTableSettings['iPageSize']; $oCustomSettings->aColumns = $aTableSettings['oColumns']; $oCustomSettings->Save('shortcut_'.$this->GetKey()); } 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 DesignerIntegerField('auto_reload_sec', Dict::S('Class:ShortcutOQL/Attribute:auto_reload_sec'), MetaModel::GetConfig()->GetStandardReloadInterval()); $oField->SetBoundaries(MetaModel::GetConfig()->Get('min_reload_interval'), null); // no upper limit $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; } public static function GetCreationDlgFromOQL($oPage, $sOQL, $sTableSettings) { $oPage->add('
'); $oForm = self::GetCreationForm($sOQL, $sTableSettings); $oForm->Render($oPage); $oPage->add('
'); $sDialogTitle = Dict::S('UI:ShortcutListDlg:Title'); $sOkButtonLabel = Dict::S('UI:Button:Ok'); $sCancelButtonLabel = Dict::S('UI:Button:Cancel'); $oAppContext = new ApplicationContext(); $sContext = $oAppContext->GetForLink(); $sRateTitle = addslashes(Dict::Format('Class:ShortcutOQL/Attribute:auto_reload_sec/tip', MetaModel::GetConfig()->Get('min_reload_interval'))); $oPage->add_ready_script( <<