示例#1
0
 /**
  * the singleton pattern
  *
  * @return Tinebase_State
  */
 public static function getInstance()
 {
     if (self::$instance === NULL) {
         self::$instance = new Tinebase_State();
     }
     return self::$instance;
 }
示例#2
0
 /**
  * Returns registry data of tinebase.
  * @see Tinebase_Application_Json_Abstract
  *
  * @return mixed array 'variable name' => 'data'
  */
 public function getRegistryData()
 {
     $locale = Tinebase_Core::get('locale');
     $tbFrontendHttp = new Tinebase_Frontend_Http();
     // default credentials
     if (isset(Tinebase_Core::getConfig()->login)) {
         $loginConfig = Tinebase_Core::getConfig()->login;
         $defaultUsername = isset($loginConfig->username) ? $loginConfig->username : '';
         $defaultPassword = isset($loginConfig->password) ? $loginConfig->password : '';
     } else {
         $defaultUsername = '';
         $defaultPassword = '';
     }
     $registryData = array('serviceMap' => $tbFrontendHttp->getServiceMap(), 'timeZone' => Tinebase_Core::get(Tinebase_Core::USERTIMEZONE), 'locale' => array('locale' => $locale->toString(), 'language' => Zend_Locale::getTranslation($locale->getLanguage(), 'language', $locale), 'region' => Zend_Locale::getTranslation($locale->getRegion(), 'country', $locale)), 'version' => array('buildType' => TINE20_BUILDTYPE, 'codeName' => TINE20_CODENAME, 'packageString' => TINE20_PACKAGESTRING, 'releaseTime' => TINE20_RELEASETIME, 'filesHash' => TINE20_BUILDTYPE != 'DEVELOPMENT' ? $tbFrontendHttp->getJsCssHash() : null), 'defaultUsername' => $defaultUsername, 'defaultPassword' => $defaultPassword, 'denySurveys' => Tinebase_Core::getConfig()->denySurveys, 'titlePostfix' => Tinebase_Config::getInstance()->getConfig(Tinebase_Model_Config::PAGETITLEPOSTFIX, NULL, '')->value, 'redirectUrl' => Tinebase_Config::getInstance()->getConfig(Tinebase_Model_Config::REDIRECTURL, NULL, '')->value, 'maxFileUploadSize' => convertToBytes(ini_get('upload_max_filesize')), 'maxPostSize' => convertToBytes(ini_get('post_max_size')));
     if (Tinebase_Core::isRegistered(Tinebase_Core::USER)) {
         $user = Tinebase_Core::getUser();
         $userContactArray = array();
         if (Tinebase_Application::getInstance()->isInstalled('Addressbook') === true) {
             try {
                 $userContactArray = Addressbook_Controller_Contact::getInstance()->getContactByUserId($user->getId(), TRUE)->toArray();
             } catch (Addressbook_Exception_NotFound $aenf) {
                 if (Tinebase_Core::isLogLevel(Zend_Log::NOTICE)) {
                     Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . ' User not found in Addressbook: ' . $user->accountDisplayName);
                 }
             }
         }
         $registryData += array('currentAccount' => $user->toArray(), 'userContact' => $userContactArray, 'accountBackend' => Tinebase_User::getConfiguredBackend(), 'jsonKey' => Tinebase_Core::get('jsonKey'), 'userApplications' => $user->getApplications()->toArray(), 'NoteTypes' => $this->getNoteTypes(), 'stateInfo' => Tinebase_State::getInstance()->loadStateInfo(), 'changepw' => Tinebase_User::getBackendConfiguration('changepw', true), 'mustchangepw' => $user->mustChangePassword(), 'mapPanel' => Tinebase_Config::getInstance()->getConfig(Tinebase_Config::MAPPANEL, NULL, TRUE)->value, 'confirmLogout' => Tinebase_Core::getPreference()->getValue(Tinebase_Preference::CONFIRM_LOGOUT, 1), 'persistentFilters' => Tinebase_Frontend_Json_PersistentFilter::getAllPersistentFilters(), 'messenger' => $this->getMessengerConfig());
     }
     return $registryData;
 }
 /**
  * get user registry
  * 
  * @return array
  */
 protected function _getUserRegistryData()
 {
     $user = Tinebase_Core::getUser();
     $userContactArray = array();
     if (Tinebase_Application::getInstance()->isInstalled('Addressbook') === true) {
         try {
             $userContactArray = Addressbook_Controller_Contact::getInstance()->getContactByUserId($user->getId(), TRUE)->toArray();
         } catch (Addressbook_Exception_NotFound $aenf) {
             if (Tinebase_Core::isLogLevel(Zend_Log::NOTICE)) {
                 /** @noinspection PhpUndefinedMethodInspection */
                 Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . ' User not found in Addressbook: ' . $user->accountDisplayName);
             }
         }
     }
     try {
         $persistentFilters = Tinebase_Frontend_Json_PersistentFilter::getAllPersistentFilters();
     } catch (Tinebase_Exception_NotFound $tenf) {
         if (Tinebase_Core::isLogLevel(Zend_Log::NOTICE)) {
             Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . " Failed to fetch persistent filters. Exception: \n" . $tenf);
         }
         $persistentFilters = array();
     } catch (Exception $e) {
         if (Tinebase_Core::isLogLevel(Zend_Log::NOTICE)) {
             Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . " Failed to fetch persistent filters. Exception: \n" . $e);
         }
         $persistentFilters = array();
     }
     $userRegistryData = array('timeZone' => Tinebase_Core::getUserTimezone(), 'currentAccount' => $user->toArray(), 'userContact' => $userContactArray, 'accountBackend' => Tinebase_User::getConfiguredBackend(), 'jsonKey' => Tinebase_Core::get('jsonKey'), 'userApplications' => $user->getApplications()->toArray(), 'NoteTypes' => $this->getNoteTypes(), 'stateInfo' => Tinebase_State::getInstance()->loadStateInfo(), 'mustchangepw' => $user->mustChangePassword(), 'confirmLogout' => Tinebase_Core::getPreference()->getValue(Tinebase_Preference::CONFIRM_LOGOUT, 1), 'advancedSearch' => Tinebase_Core::getPreference()->getValue(Tinebase_Preference::ADVANCED_SEARCH, 0), 'persistentFilters' => $persistentFilters, 'userAccountChanged' => Tinebase_Controller::getInstance()->userAccountChanged());
     if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
         Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' User registry: ' . print_r($userRegistryData, TRUE));
     }
     return $userRegistryData;
 }
示例#4
0
 /**
  * calendar colors: state -> container
  */
 public function update_6()
 {
     $tablePrefix = SQL_TABLE_PREFIX;
     // mialena fixed color map
     $colorMap = array(9 => '#FF6600', 16 => '#FF0000', 21 => '#3366FF', 24 => '#FF00FF', 27 => '#00FF00', 30 => '#993366');
     // $containerId => array($colorId => $usageCount)
     $colorHistogram = array();
     $stmt = $this->_db->query("\n            SELECT *\n            FROM `{$tablePrefix}state` AS `state`\n        ");
     $states = $stmt->fetchAll(Zend_Db::FETCH_ASSOC);
     foreach ($states as $state) {
         $data = Zend_Json::decode($state['data']);
         if (array_key_exists('cal-color-mgr-containers', $data)) {
             $colorMgrData = Tinebase_State::decode($data['cal-color-mgr-containers']);
             $containerColorMap = $colorMgrData['colorMap'];
             foreach ($containerColorMap as $containerId => $colorId) {
                 if (!array_key_exists($containerId, $colorHistogram)) {
                     $colorHistogram[$containerId] = array();
                 }
                 if (!array_key_exists($colorId, $colorHistogram[$containerId])) {
                     $colorHistogram[$containerId][$colorId] = 0;
                 }
                 $colorHistogram[$containerId][$colorId] = $colorHistogram[$containerId][$colorId] + 1;
             }
         }
         unset($data['cal-color-mgr-containers']);
         $this->_db->update($tablePrefix . 'state', array('data' => Zend_Json::encode($data)), "`id` = '{$state['id']}'");
     }
     foreach ($colorHistogram as $containerId => $histogram) {
         arsort($histogram);
         reset($histogram);
         $colorId = key($histogram);
         $color = $colorMap[$colorId];
         $this->_db->update($tablePrefix . 'container', array('color' => $color), "`id` = '{$containerId}'");
     }
     $this->setApplicationVersion('Calendar', '3.7');
 }
 /**
  * save state and load it with registry data
  */
 public function testSaveAndGetState()
 {
     $testData = array('bla' => 'blubb', 'zzing' => 'zzang');
     foreach ($testData as $key => $value) {
         Tinebase_State::getInstance()->setState($key, $value);
     }
     $stateInfo = Tinebase_State::getInstance()->loadStateInfo();
     $this->assertEquals($testData, $stateInfo);
 }
示例#6
0
 /**
  * save state and load it with registry data
  *
  * @todo save old state and recover it after the test
  */
 public function testSaveAndGetState()
 {
     $testData = array('bla' => 'blubb', 'zzing' => 'zzang');
     Tinebase_State::getInstance()->saveStateInfo($testData);
     $stateInfo = Tinebase_State::getInstance()->loadStateInfo();
     $this->assertEquals($testData, $stateInfo);
     //$registryData = $this->_instance->getAllRegistryData();
 }