Skip to content

Instantly share code, notes, and snippets.

@sevein
Created April 21, 2013 18:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sevein/5430608 to your computer and use it in GitHub Desktop.
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.
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