Created
April 21, 2013 18:54
-
-
Save sevein/5430608 to your computer and use it in GitHub Desktop.
Simple example on how to avoid static taxonomies by caching their IDs in a cache.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/filter/QubitSettingsFilter.class.php b/lib/filter/QubitSettingsFilter.class.php | |
index 8894026..6e091fc 100644 | |
--- a/lib/filter/QubitSettingsFilter.class.php | |
+++ b/lib/filter/QubitSettingsFilter.class.php | |
@@ -27,7 +27,34 @@ class QubitSettingsFilter extends sfFilter | |
// Overwrite/populate settings into sfConfig object | |
sfConfig::add(QubitSetting::getSettingsArray()); | |
+ // Load custom taxonomies | |
+ $this->loadCustomTaxonomies(); | |
+ | |
// Execute next filter | |
$filterChain->execute(); | |
} | |
+ | |
+ protected function loadCustomTaxonomies() | |
+ { | |
+ $cache = new sfAPCCache; | |
+ | |
+ if (null === $taxonomyId = $cache->get('id_taxonomy_repository_types')) | |
+ { | |
+ $criteria = new Criteria; | |
+ $criteria->addJoin(QubitTaxonomy::ID, QubitTaxonomyI18n::ID); | |
+ // $criteria->add(QubitTaxonomy::USAGE, 'Custom taxonomy (usask.ca)'); | |
+ $criteria->add(QubitTaxonomyI18n::CULTURE, 'en'); | |
+ $criteria->add(QubitTaxonomyI18n::NAME, 'Repository Types'); | |
+ if (null !== $taxonomy = QubitTaxonomy::getOne($criteria)) | |
+ { | |
+ $taxonomyId = $taxonomy->id; | |
+ | |
+ $cache->set('id_taxonomy_repository_types', $taxonomyId); | |
+ } | |
+ } | |
+ | |
+ // Store the ID in the app configuration | |
+ sfConfig::set('id_taxonomy_repository_types', $taxonomyId); | |
+ } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment