/** * Get a persistent config value for current user against portletId and keyName. * @param $portletId integer Id of the portlet or string representation of the unique id of the portlet to get value against * @param $keyName string Name of the key that should be returned * @param bool $returnBoolean bool Force return value to be boolean (explicit type casting) * @return bool|null|string */ public static function getForCurrentUserByPortletIdAndKey($portletId, $keyName, $returnBoolean = false) { assert('is_int($portletId) || is_string($portletId)'); assert('is_string($keyName)'); $moduleName = static::getModuleName(); $keyName = static::resolveKeyNameByPortletId($portletId, $keyName); $value = ZurmoConfigurationUtil::getForCurrentUserByModuleName($moduleName, $keyName); if ($returnBoolean) { $value = (bool) $value; } return $value; }
public function testGetAndSetByCurrentUserByModuleName() { Yii::app()->user->userModel = User::getByUsername('super'); $this->assertNull(ZurmoConfigurationUtil::getForCurrentUserByModuleName('ZurmoModule', 'aKey')); ZurmoConfigurationUtil::setForCurrentUserByModuleName('ZurmoModule', 'aKey', 'aValue'); Yii::app()->user->userModel = User::getByUsername('billy'); $this->assertNull(ZurmoConfigurationUtil::getForCurrentUserByModuleName('ZurmoModule', 'aKey')); ZurmoConfigurationUtil::setForCurrentUserByModuleName('ZurmoModule', 'aKey', 'bValue'); Yii::app()->user->userModel = User::getByUsername('sally'); $this->assertNull(ZurmoConfigurationUtil::getForCurrentUserByModuleName('ZurmoModule', 'aKey')); ZurmoConfigurationUtil::setForCurrentUserByModuleName('ZurmoModule', 'aKey', 'cValue'); //now retrieve again. Yii::app()->user->userModel = User::getByUsername('super'); $this->assertEquals('aValue', ZurmoConfigurationUtil::getForCurrentUserByModuleName('ZurmoModule', 'aKey')); Yii::app()->user->userModel = User::getByUsername('billy'); $this->assertEquals('bValue', ZurmoConfigurationUtil::getForCurrentUserByModuleName('ZurmoModule', 'aKey')); Yii::app()->user->userModel = User::getByUsername('sally'); $this->assertEquals('cValue', ZurmoConfigurationUtil::getForCurrentUserByModuleName('ZurmoModule', 'aKey')); //Test retrieving a generic value that is set globally on ZurmoModule. The value returned should be the //same for all users. $metadata = ZurmoModule::getMetadata(); $this->assertTrue(!isset($metadata['global']['bKey'])); $metadata['global']['bKey'] = 'GlobalValue'; ZurmoModule::setMetadata($metadata); Yii::app()->user->userModel = User::getByUsername('super'); $this->assertEquals('GlobalValue', ZurmoConfigurationUtil::getForCurrentUserByModuleName('ZurmoModule', 'bKey')); Yii::app()->user->userModel = User::getByUsername('billy'); $this->assertEquals('GlobalValue', ZurmoConfigurationUtil::getForCurrentUserByModuleName('ZurmoModule', 'bKey')); Yii::app()->user->userModel = User::getByUsername('sally'); $this->assertEquals('GlobalValue', ZurmoConfigurationUtil::getForCurrentUserByModuleName('ZurmoModule', 'bKey')); //Now change the bKey value, just for billy and retrieve again for all users. Only billy's bKey value //should be different. ZurmoConfigurationUtil::setByUserAndModuleName(User::getByUsername('billy'), 'ZurmoModule', 'bKey', 'BillyBKey'); Yii::app()->user->userModel = User::getByUsername('super'); $this->assertEquals('GlobalValue', ZurmoConfigurationUtil::getForCurrentUserByModuleName('ZurmoModule', 'bKey')); Yii::app()->user->userModel = User::getByUsername('billy'); $this->assertEquals('BillyBKey', ZurmoConfigurationUtil::getForCurrentUserByModuleName('ZurmoModule', 'bKey')); Yii::app()->user->userModel = User::getByUsername('sally'); $this->assertEquals('GlobalValue', ZurmoConfigurationUtil::getForCurrentUserByModuleName('ZurmoModule', 'bKey')); }
public function isCurrentUsersTimeZoneConfirmed() { $keyName = 'timeZoneConfirmed'; if (false != ZurmoConfigurationUtil::getForCurrentUserByModuleName('UsersModule', $keyName)) { return true; } return false; }
/** * @param $moduleName * @param RedBeanModel $model */ public static function deleteModelFromRecentlyViewed($moduleName, RedBeanModel $model) { if (!isset($model) || !isset($moduleName)) { return; } $newItem = array($moduleName, $model->id, strval($model)); $recentlyViewed = unserialize(ZurmoConfigurationUtil::getForCurrentUserByModuleName('ZurmoModule', 'recentlyViewed')); if (!is_array($recentlyViewed)) { return; } if (in_array($newItem, $recentlyViewed)) { $key = array_search($newItem, $recentlyViewed); unset($recentlyViewed[$key]); array_keys($recentlyViewed); } ZurmoConfigurationUtil::setForCurrentUserByModuleName('ZurmoModule', 'recentlyViewed', serialize($recentlyViewed)); }
public function testResolveNewRecentlyViewedModelAfterChangingName() { Yii::app()->user->userModel = User::getByUsername('super'); ZurmoConfigurationUtil::setForCurrentUserByModuleName('ZurmoModule', 'recentlyViewed', null); $account1 = new Account(); $account1->name = 'For test recently viewed'; $this->assertTrue($account1->save()); AuditEventsRecentlyViewedUtil::resolveNewRecentlyViewedModel('AccountsModule', $account1, 2); $this->assertEquals(serialize(array(array('AccountsModule', $account1->id, strval($account1)))), ZurmoConfigurationUtil::getForCurrentUserByModuleName('ZurmoModule', 'recentlyViewed')); $account1->name = 'new name for same account'; $this->assertTrue($account1->save()); AuditEventsRecentlyViewedUtil::resolveNewRecentlyViewedModel('AccountsModule', $account1, 2); $this->assertEquals(serialize(array(array('AccountsModule', $account1->id, strval($account1)))), ZurmoConfigurationUtil::getForCurrentUserByModuleName('ZurmoModule', 'recentlyViewed')); AuditEventsRecentlyViewedUtil::resolveNewRecentlyViewedModel('ContactsModule', $account1, 2); $this->assertEquals(serialize(array(array('ContactsModule', $account1->id, strval($account1)), array('AccountsModule', $account1->id, strval($account1)))), ZurmoConfigurationUtil::getForCurrentUserByModuleName('ZurmoModule', 'recentlyViewed')); }
/** * Get the pagination value for the current user by pagination type. * @param $type - pagination type * @param $moduleName - optional. Module class name. * @return $pageSize - integer. */ public function getForCurrentUserByType($type, $moduleName = null) { assert('in_array($type, static::getAvailablePageSizeNames()) == true'); assert('$moduleName == null || is_string($moduleName)'); $keyName = $this->getKeyByTypeAndModuleName($type); if (null != ($pageSize = ZurmoConfigurationUtil::getForCurrentUserByModuleName('ZurmoModule', $keyName))) { return $pageSize; } return $this->{'_' . $type}; }
public function actionToggleDismissIntroView($moduleName, $panelId) { $value = (bool) ZurmoConfigurationUtil::getForCurrentUserByModuleName($moduleName, $panelId); ZurmoConfigurationUtil::setForCurrentUserByModuleName($moduleName, $panelId, !$value); }
public function isIntroViewDismissed() { if (ZurmoConfigurationUtil::getForCurrentUserByModuleName($this->moduleName, $this->getPanelId())) { return true; } return false; }
public function isMenuCollapsed() { return (bool) ZurmoConfigurationUtil::getForCurrentUserByModuleName('ZurmoModule', static::TOGGLE_COLLAPSE_KEY); }