diff --git a/application/dashboardlayout.class.inc.php b/application/dashboardlayout.class.inc.php index 4a17ed070..c99d6d7d8 100644 --- a/application/dashboardlayout.class.inc.php +++ b/application/dashboardlayout.class.inc.php @@ -105,13 +105,14 @@ abstract class DashboardLayoutMultiCol extends DashboardLayout { // Trim the list of cells to remove the invisible/empty ones at the end of the array $aCells = $this->TrimCellsArray($aCells); - + $oPage->add(''); $iCellIdx = 0; $fColSize = 100 / $this->iNbCols; $sStyle = $bEditMode ? 'border: 1px #ccc dashed; width:'.$fColSize.'%;' : 'width: '.$fColSize.'%;'; $sClass = $bEditMode ? 'layout_cell edit_mode' : 'dashboard'; $iNbRows = ceil(count($aCells) / $this->iNbCols); + for($iRows = 0; $iRows < $iNbRows; $iRows++) { $oPage->add(''); @@ -129,7 +130,8 @@ abstract class DashboardLayoutMultiCol extends DashboardLayout { if ($oDashlet->IsVisible()) { - $sDashletId = $oDashlet->GetID(); + $sDashletIdOrig = $oDashlet->GetID(); + $sDashletId = $sDashletIdOrig; if(strpos($sDashletId, 'IDrow') === false) { $sDashboardDivId = $aExtraParams['dashboard_div_id']; @@ -143,6 +145,7 @@ abstract class DashboardLayoutMultiCol extends DashboardLayout } $oDashlet->SetID($sDashletId); } + $this->UpdateDashletsUserPrefs($oDashlet, $sDashletIdOrig, $aExtraParams); $oDashlet->DoRender($oPage, $bEditMode, true /* bEnclosingDiv */, $aExtraParams); } } @@ -175,6 +178,64 @@ abstract class DashboardLayoutMultiCol extends DashboardLayout } $oPage->add('
'); } + + /** + * Migrate dashlet specific prefs to new format + * Before 2.7.0 we were using the same for dashboard menu or dashboard attributes, standard or custom : + * -|Dashlet + * Since 2.7.0 it is the following, with a "CUSTOM_" prefix if necessary : + * * dashboard menu : _IDrow-col- + * * dashboard attribute : ___IDrow-col- + * + * @param \Dashlet $oDashlet + * @param string $sDashletIdOrig + * + * @param array $aExtraParams + * + * @since 2.7.0 N°2735 + */ + private function UpdateDashletsUserPrefs(\Dashlet $oDashlet, $sDashletIdOrig, array $aExtraParams) + { + $bIsDashletWithListPref = ($oDashlet instanceof DashletObjectList); + if (!$bIsDashletWithListPref) + { + return; + } + /** @var \DashletObjectList $oDashlet */ + + $bDashletIdInNewFormat = ($sDashletIdOrig === $oDashlet->GetID()); + if ($bDashletIdInNewFormat) + { + return; + } + + $sNewPrefKey = $this->GetDashletAppUserPrefPrefix($oDashlet, $aExtraParams, $oDashlet->GetID()); + $sPrefValueForNewKey = appUserPreferences::GetPref($sNewPrefKey, null); + $bHasPrefInNewFormat = ($sPrefValueForNewKey !== null); + if ($bHasPrefInNewFormat) + { + return; + } + + $sOldPrefKey = $this->GetDashletAppUserPrefPrefix($oDashlet, $aExtraParams, $sDashletIdOrig); + $sPrefValueForOldKey = appUserPreferences::GetPref($sOldPrefKey, null); + $bHasPrefInOldFormat = ($sPrefValueForOldKey !== null); + if (!$bHasPrefInOldFormat) + { + return; + } + + appUserPreferences::SetPref($sNewPrefKey, $sPrefValueForOldKey); + appUserPreferences::UnsetPref($sOldPrefKey); + } + + private function GetDashletAppUserPrefPrefix(\DashletObjectList $oDashlet, array $aExtraParams, $sDashletId) + { + $sDataTableId = DashletObjectList::APPUSERPREFERENCE_TABLE_PREFIX.$sDashletId; + $oFilter = $oDashlet->GetDBSearch($aExtraParams); + $aClassAliases = $oFilter->GetSelectedClasses(); + return DataTableSettings::GetAppUserPreferenceKey($aClassAliases, $sDataTableId); + } } class DashboardLayoutOneCol extends DashboardLayoutMultiCol diff --git a/application/dashlet.class.inc.php b/application/dashlet.class.inc.php index c62392860..8f0a4db90 100644 --- a/application/dashlet.class.inc.php +++ b/application/dashlet.class.inc.php @@ -892,6 +892,7 @@ class DashletPlainText extends Dashlet class DashletObjectList extends Dashlet { + const APPUSERPREFERENCE_TABLE_PREFIX = 'Dashlet'; /** * @inheritdoc */ @@ -913,7 +914,6 @@ class DashletObjectList extends Dashlet public function Render($oPage, $bEditMode = false, $aExtraParams = array()) { $sTitle = $this->aProperties['title']; - $sQuery = $this->aProperties['query']; $sShowMenu = $this->aProperties['menu'] ? '1' : '0'; $oPage->add('
'); @@ -922,6 +922,20 @@ class DashletObjectList extends Dashlet { $oPage->add('

'.$sHtmlTitle.'

'); } + $oFilter = $this->GetDBSearch($aExtraParams); + $oBlock = new DisplayBlock($oFilter, 'list'); + $aParams = array( + 'menu' => $sShowMenu, + 'table_id' => self::APPUSERPREFERENCE_TABLE_PREFIX.$this->sId, + ); + $sBlockId = 'block_'.$this->sId.($bEditMode ? '_edit' : ''); // make a unique id (edition occurring in the same DOM) + $oBlock->Display($oPage, $sBlockId, array_merge($aExtraParams, $aParams)); + $oPage->add('
'); + } + + public function GetDBSearch($aExtraParams = array()) + { + $sQuery = $this->aProperties['query']; if (isset($aExtraParams['query_params'])) { $aQueryParams = $aExtraParams['query_params']; @@ -935,15 +949,8 @@ class DashletObjectList extends Dashlet { $aQueryParams = array(); } - $oFilter = DBObjectSearch::FromOQL($sQuery, $aQueryParams); - $oBlock = new DisplayBlock($oFilter, 'list'); - $aParams = array( - 'menu' => $sShowMenu, - 'table_id' => 'Dashlet'.$this->sId, - ); - $sBlockId = 'block_'.$this->sId.($bEditMode ? '_edit' : ''); // make a unique id (edition occurring in the same DOM) - $oBlock->Display($oPage, $sBlockId, array_merge($aExtraParams, $aParams)); - $oPage->add(''); + + return DBObjectSearch::FromOQL($sQuery, $aQueryParams); } /** diff --git a/application/datatable.class.inc.php b/application/datatable.class.inc.php index a4662a27d..009937e88 100644 --- a/application/datatable.class.inc.php +++ b/application/datatable.class.inc.php @@ -1158,9 +1158,18 @@ class DataTableSettings implements Serializable */ protected function GetPrefsKey($sTableId = null) { - if ($sTableId == null) $sTableId = '*'; + return static::GetAppUserPreferenceKey($this->aClassAliases, $sTableId); + } + + public static function GetAppUserPreferenceKey($aClassAliases, $sTableId) + { + if ($sTableId === null) + { + $sTableId = '*'; + } + $aKeys = array(); - foreach($this->aClassAliases as $sAlias => $sClass) + foreach($aClassAliases as $sAlias => $sClass) { $aKeys[] = $sAlias.'-'.$sClass; } diff --git a/application/user.preferences.class.inc.php b/application/user.preferences.class.inc.php index 6febec34a..960384a3e 100644 --- a/application/user.preferences.class.inc.php +++ b/application/user.preferences.class.inc.php @@ -34,7 +34,7 @@ require_once(APPROOT.'/core/userrights.class.inc.php'); */ class appUserPreferences extends DBObject { - static $oUserPrefs = null; // Local cache + private static $oUserPrefs = null; // Local cache /** * Get the value of the given property/preference @@ -43,7 +43,7 @@ class appUserPreferences extends DBObject * @param string $sDefaultValue The default value * @return string The value of the property for the current user */ - static function GetPref($sCode, $sDefaultValue) + public static function GetPref($sCode, $sDefaultValue) { if (self::$oUserPrefs == null) { @@ -65,7 +65,7 @@ class appUserPreferences extends DBObject * @param string $sCode Code/Name of the property/preference to set * @param string $sValue Value to set */ - static function SetPref($sCode, $sValue) + public static function SetPref($sCode, $sValue) { if (self::$oUserPrefs == null) { @@ -83,13 +83,13 @@ class appUserPreferences extends DBObject self::Save(); } } - + /** * Clears the value for a given preference (or list of preferences that matches a pattern), and updates the database - * @param string $sPattern Code/Pattern of the properties/preferences to reset + * @param string $sCodeOrPattern Code/Pattern of the properties/preferences to reset * @param boolean $bPattern Whether or not the supplied code is a PCRE pattern */ - static function UnsetPref($sCodeOrPattern, $bPattern = false) + public static function UnsetPref($sCodeOrPattern, $bPattern = false) { if (self::$oUserPrefs == null) { @@ -124,7 +124,7 @@ class appUserPreferences extends DBObject * Call this function to get all the preferences for the user, packed as a JSON object * @return string JSON representation of the preferences */ - static function GetAsJSON() + public static function GetAsJSON() { if (self::$oUserPrefs == null) { @@ -137,19 +137,19 @@ class appUserPreferences extends DBObject /** * Call this function if the user has changed (like when doing a logoff...) */ - static public function ResetPreferences() + public static function ResetPreferences() { self::$oUserPrefs = null; } /** * Call this function to ERASE all the preferences from the current user */ - static public function ClearPreferences() + public static function ClearPreferences() { self::$oUserPrefs = null; } - static protected function Save() + protected static function Save() { if (self::$oUserPrefs != null) { @@ -166,7 +166,7 @@ class appUserPreferences extends DBObject * Loads the preferences for the current user, creating the record in the database * if needed */ - static protected function Load() + protected static function Load() { if (self::$oUserPrefs != null) return; $oSearch = new DBObjectSearch('appUserPreferences');