function __($stringId) { if (!defined('PLANCAKE_PUBLIC_RELEASE')) { $lang = PcLanguagePeer::getUserPreferredLanguage()->getId(); $key = ''; if ($cache = PcCache::getInstance()) { $key = PcCache::generateKeyForTranslation($lang, $stringId); if ($cache->has($key)) { return $cache->get($key); } } $translation = PcTranslationPeer::retrieveByPK($lang, $stringId); if (!is_object($translation) || !strlen(trim($translation->getString())) > 0) { $translation = PcTranslationPeer::retrieveByPK(SfConfig::get('app_site_defaultLang'), $stringId); } if (!$translation) { throw new Exception("Couldn't find the string {$stringId} for the language {$lang}"); } $ret = $translation->getString(); if ($cache) { $cache->set($key, $ret); } } else { global $pc_lang; if (!array_key_exists($stringId, $pc_lang)) { throw new Exception("Couldn't find the string {$stringId}"); } $ret = $pc_lang[$stringId]; } return $ret; }
/** * Clears the cache relevant for contexts */ private function clearRelevantCache() { if (sfContext::getInstance()->getUser()->isAuthenticated()) { $userId = PcUserPeer::getLoggedInUser()->getId(); $cache = PcCache::getInstance(); if (is_object($cache)) { $cache->remove('PcUser::getContexts' . $userId); $cache->remove('PcUser::getContextsArray' . $userId); } } }
public static function getInstance() { if (is_object(self::$cache)) { return self::$cache; } $viewCacheManager = sfContext::getInstance()->getViewCacheManager(); if (is_object($viewCacheManager)) { $cacheClass = get_class($viewCacheManager->getCache()); if ($cacheClass == 'sfMemcacheCache') { $newObject = new $cacheClass(array('prefix' => 'generic_')); self::$cache = $newObject; return $newObject; } } return null; }
/** * Clears the cache relevant for lists */ private function clearRelevantCache() { if ($this->getId()) { if (sfContext::getInstance()->getUser()->isAuthenticated()) { $userId = PcUserPeer::getLoggedInUser()->getId(); $cacheManager = sfContext::getInstance()->getViewCacheManager(); if (is_object($cacheManager)) { $cacheManager->remove('@sf_cache_partial?module=lists&action=_mainNavigation&sf_cache_key=' . PcCache::getMainNavigationKey()); } $cache = PcCache::getInstance(); if (is_object($cache)) { $cache->remove('PcUser::getLists' . $userId); $cache->remove('PcUser::getSystemLists' . $userId); $cache->remove('PcUser::getAllLists' . $userId); } } } // we need to clear the cache of each task as its partial will probably // contain the list name $tasks = $this->getIncompletedTasks(); foreach ($tasks as $task) { $task->save(); } }
/** * Returns all the contexts. * Similar to getContexts() BUT: * Every element of the array is a contextName, having the contextId as a key * * @param boolean $returnLowercase (=false) * @return array */ public function getContextsArray($returnLowercase = false) { if ($cache = PcCache::getInstance()) { $key = __METHOD__ . $this->getId(); if ($cache->has($key)) { return $cache->get($key); } } $criteria = new Criteria(); $criteria->add(PcUsersContextsPeer::USER_ID, $this->getId(), Criteria::EQUAL); $contexts = PcUsersContextsPeer::doSelect($criteria); foreach ($contexts as $context) { $contextName = $returnLowercase ? strtolower($context->getContext()) : $context->getContext(); $ret[$context->getId()] = $contextName; } if ($cache) { $cache->set($key, $ret); } return $ret; }