コード例 #1
0
 /**
  * This method is a simplification of loadPreferences()
  * It is created mostly because of the performance reasons.
  * The method loads given preferences in given account only.
  *
  * It doesn't take into account any preferences cascading so
  * before using this method be sure that the performance you are
  * looking for can't cascade (this is often the case for the preferences
  * which are available only in given accounts).
  *
  * This method uses by default static in-memory caching to improve
  * the speed of reading in the preferences - this is helpful in maintenance
  * where admin preferences can be read in many places and many times.
  *
  */
 function loadPreferencesByNameAndAccount($accountId, $aPreferencesNames, $accountType, $useCache = true)
 {
     $aPrefs = OA_Preferences::cachePreferences($accountId, $aPreferencesNames);
     if (count($aPrefs) == count($aPreferencesNames)) {
         return $aPrefs;
     }
     $aPrefsIds = OA_Preferences::getCachedPreferencesIds($aPreferencesNames, $accountType);
     $doAccount_preference_assoc = OA_Dal::factoryDO('account_preference_assoc');
     $doAccount_preference_assoc->account_id = $accountId;
     $doAccount_preference_assoc->whereInAdd('preference_id', $aPrefsIds);
     $doAccount_preference_assoc->find();
     $aPrefs = array();
     $prefsIdsFlip = array_flip($aPrefsIds);
     while ($doAccount_preference_assoc->fetch()) {
         $aPrefs[$prefsIdsFlip[$doAccount_preference_assoc->preference_id]] = $doAccount_preference_assoc->value;
     }
     OA_Preferences::cachePreferences($accountId, $aPrefs);
     return $aPrefs;
 }
コード例 #2
0
 function testLoadPreferencesByNameAndAccount()
 {
     // clean cache
     OA_Preferences::cachePreferences(null, array(), null, true);
     $prefs = OA_Preferences::loadPreferencesByNameAndAccount($accountId = 1, array('pref1'), 'ADMIN');
     $this->assertEqual($prefs, array());
     // add prefs
     $prefsNamesIds = array('pref1' => 1, 'pref2' => 2);
     $this->_createPreferences($prefsNamesIds);
     $this->_addPrefsToAccount(array(1 => 'pref1val'), $accountId);
     $prefs = OA_Preferences::loadPreferencesByNameAndAccount($accountId, array('pref1'), 'ADMIN');
     $this->assertEqual($prefs, array('pref1' => 'pref1val'));
     $this->_addPrefsToAccount(array(2 => 'pref2val'), $accountId);
     $prefs = OA_Preferences::loadPreferencesByNameAndAccount($accountId, array('pref1', 'pref2'), 'ADMIN');
     $this->assertEqual($prefs, array('pref1' => 'pref1val', 'pref2' => 'pref2val'));
     $prefs = OA_Preferences::loadPreferencesByNameAndAccount(2, array('pref1'), 'ADMIN');
     $this->assertEqual($prefs, array());
 }