enumerateBySymbolic(CATEGORY_SYMBOLIC, 0, 0); } /** * Rebuild the cache. */ function rebuildCache() { // Read the full set of categories into an associative array $categoryEntryDao =& $this->getEntryDAO(); $categoryControlledVocab =& $this->build(); $categoriesIterator =& $categoryEntryDao->getByControlledVocabId($categoryControlledVocab->getId()); $allCategories = array(); while ($category =& $categoriesIterator->next()) { $allCategories[$category->getId()] =& $category; unset($category); } // Prepare our results array to cache $categories = array(); // Add each journal's categories to the data structure $journalDao =& DAORegistry::getDAO('JournalDAO'); $journals =& $journalDao->getJournals(true); while ($journal =& $journals->next()) { $selectedCategories = $journal->getSetting('categories'); foreach ((array) $selectedCategories as $categoryId) { if (!isset($allCategories[$categoryId])) continue; if (!isset($categories[$categoryId])) $categories[$categoryId] = array( 'category' => $allCategories[$categoryId], 'journals' => array() ); $categories[$categoryId]['journals'][] = $journal; } unset($journal); } // Save the cache file $fp = fopen($this->getCacheFilename(), 'w'); if (!$fp) return false; fwrite($fp, serialize($categories)); fclose($fp); } /** * Get the cached set of categories, building it if necessary. * @return array */ function getCache() { // The following line is only for classloading purposes $categoryEntryDao =& $this->getEntryDAO(); $journalDao =& DAORegistry::getDAO('JournalDAO'); // Load and return the cache, building it if necessary. $filename = $this->getCacheFilename(); if (!file_exists($filename)) $this->rebuildCache(); $contents = file_get_contents($filename); if ($contents) return unserialize($contents); return null; } /** * Get the cache filename. * @return string */ function getCacheFilename() { return 'cache/fc-categories.php'; } } ?>