ThemePlugin.ini.php
public function init() { // Load language selection - #most read# HookRegistry::register ('TemplateManager::display', array($this, 'loadTemplateData')); } public function loadTemplateData($hookName, $args) { $templateMgr = $args[0]; $template = $args[1]; $request = Application::getRequest(); $site = $request->getSite(); $issueDao = DAORegistry::getDAO('IssueDAO'); $journalDao = DAORegistry::getDAO('JournalDAO'); // Start Language selector $templateMgr->assign('isPostRequest', $request->isPost()); if (!defined('SESSION_DISABLE_INIT')) { $locales = $site->getSupportedLocales(); } else { $locales = AppLocale::getAllLocales(); $templateMgr->assign('languageToggleNoUser', true); } if (isset($locales) && count($locales) > 1) { $templateMgr->assign('enableLanguageToggle', true); $templateMgr->assign('languageToggleLocales', $locales); } // End Language selector // Start Latest issues $issues = array(); $issueList = array(); $volLabel = __('issue.vol'); $numLabel = __('issue.no'); $result = $issueDao->retrieve("SELECT issue_id FROM issues WHERE published = '1' AND access_status= '1' AND year != '0' ORDER BY date_published DESC LIMIT 6"); while (!$result->EOF) { $resultRow = $result->GetRowAssoc(false); $issues[$resultRow['issue_id']] = $issueDao->getById($resultRow['issue_id']); $result->MoveNext(); } $result->Close(); foreach($issues as $issueId => $issue){ $journal = $journalDao->getById($issue->getJournalId()); $issueList[$issueId]['journal'] = $journal->getLocalizedName(); $issueList[$issueId]['journalPath'] = $journal->getPath(); if ($issue->getLocalizedCoverImageUrl()){ $issueList[$issueId]['cover'] = $issue->getLocalizedCoverImageUrl(); $issueList[$issueId]['contain'] = true; } else{ $issueList[$issueId]['cover'] = $request->getBaseUrl()."/plugins/themes/tsvSite/images/journalfi_default_cover.png"; } $issueList[$issueId]['path'] = $issue->getBestIssueId(); $volume = $issue->getVolume(); $number = $issue->getNumber(); $year = $issue->getyear(); $issueIdentification = ""; if ($year != "") $issueIdentification = "(".$year.")".$issueIdentification; if ($number != "0") $issueIdentification = $numLabel." ".$number." ".$issueIdentification; if ($volume != "0") $issueIdentification = $volLabel." ".$volume." ".$issueIdentification; $issueList[$issueId]['identification'] = $issueIdentification; } $templateMgr->assign('issueList', $issueList); // End Latest issues // Start Most read $metricsDao = DAORegistry::getDAO('MetricsDAO'); $cacheManager =& CacheManager::getManager(); $cache =& $cacheManager->getCache('mostreadsite', 0, array($this, '_cacheMiss')); $daysToStale = 1; $cachedMetrics = false; if (time() - $cache->getCacheTime() > 60 * 60 * 24 * $daysToStale) { $cachedMetrics = $cache->getContents(); $cache->flush(); } $resultMetrics = $cache->getContents(); if (!$resultMetrics && $cachedMetrics) { $resultMetrics = $cachedMetrics; $cache->setEntireCache($cachedMetrics); } elseif (!$resultMetrics) { $cache->flush(); } $templateMgr->assign('resultMetrics', $resultMetrics); // End Most read } function _cacheMiss($cache) { $metricsDao = DAORegistry::getDAO('MetricsDAO'); $publishedArticleDao = DAORegistry::getDAO('PublishedArticleDAO'); $journalDao = DAORegistry::getDAO('JournalDAO'); $currentDate = date('Ymd'); $weekAgo = date('Ymd', strtotime("-1 month")); $result = $metricsDao->retrieve("SELECT submission_id, SUM(metric) AS metric FROM metrics WHERE (day BETWEEN $weekAgo AND $currentDate) AND (assoc_type='515' AND submission_id IS NOT NULL) GROUP BY submission_id ORDER BY metric DESC LIMIT 4"); while (!$result->EOF) { $resultRow = $result->GetRowAssoc(false); $article = $publishedArticleDao->getById($resultRow['submission_id']); $journal = $journalDao->getById($article->getJournalId()); $articles[$resultRow['submission_id']]['journalPath'] = $journal->getPath(); $articles[$resultRow['submission_id']]['journalName'] = $journal->getLocalizedName(); $articles[$resultRow['submission_id']]['articleId'] = $article->getBestArticleId(); $articles[$resultRow['submission_id']]['articleTitle'] = $article->getLocalizedTitle(); $articles[$resultRow['submission_id']]['articleAuthors'] = $article->getAuthorString(); $articles[$resultRow['submission_id']]['datePublished'] = $article->getDatePublished(); $articles[$resultRow['submission_id']]['metric'] = $resultRow['metric']; $result->MoveNext(); } $result->Close(); $cache->setEntireCache($articles); return $result; }
indexjournal.tpl
<ul class="most_read"> {foreach from=$resultMetrics item=article} <li class="most_read_article"> <p><em>Open Access</em></p> <div class="most_read_article_title"><a href="{url journal=$article.journalPath page="article" op="view" path=$article.articleId}">{$article.articleTitle}</a></div> <div class="most_read_article_authors"> {$article.articleAuthors} </div> <div class="most-read-footer"> <div class="most_read_article_journal"><em>Read in the last month:</em> {$article.metric} times</div> <div class="most_read_article_published"><strong>Published:</strong> <span>{$article.datePublished}</span></div> </div> </li> {/foreach} </ul>