We are moving to Git Issues for bug tracking in future releases. During transition, content will be in both tools. If you'd like to file a new bug, please create an issue.

View | Details | Raw Unified | Return to bug 8514 | Differences between
and this patch

Collapse All | Expand All

(-)file_not_specified_in_diff (-50 / +38 lines)
 Lines 14-15    Link Here 
14
14
 
15
import('lib.pkp.classes.db.DAO');
15
import('db.DAO');
16
--
Line 18    Link Here 
18
18
	
19
--
Line 20    Link Here 
20
	 * Gets the $num most popular articles in the last $months months.
20
	 * Gets the $num most popular articles in the last $months months. 
21
--
Line 23    Link Here 
23
	function getMostPopularArticles($journalId, $num = 10, $months = null) {
23
	function getMostPopularArticles( $journalId, $num = 10, $months = null){
24
--
 Lines 25-62    Link Here 
25
25
		
26
		import('lib.pkp.classes.db.DBResultRange');
26
		$returner = array();
27
		$journalDao =& DAORegistry::getDAO('JournalDAO'); /* @var $journalDao JournalDAO */
27
		
28
		$journal =& $journalDao->getJournal($journalId);
28
		if ( $months ) {
29
29
			$result =& $this->retrieveLimit(
30
		$metricsDao =& DAORegistry::getDAO('MetricsDAO'); /* @var $metricsDao MetricsDAO */
30
					sprintf('SELECT a.article_id
31
31
					FROM published_articles pa INNER JOIN articles a ON (a.article_id = pa.article_id)
32
		// Get old view statistics.
32
					WHERE a.journal_id = ? AND 
33
		PluginRegistry::loadCategory('reports');
33
					pa.date_published > %s
34
		$stats = $metricsDao->getMetrics(
34
					AND pa.views > 0
35
			array(OJS_METRIC_TYPE_LEGACY_DEFAULT, $journal->getDefaultMetricType()),
35
					ORDER BY views DESC', 
36
			array(STATISTICS_DIMENSION_SUBMISSION_ID),
36
					$this->datetimeToDB(strtotime('-' . $months . ' months'))),
37
			array(STATISTICS_DIMENSION_CONTEXT_ID => $journalId, STATISTICS_DIMENSION_ASSOC_TYPE => ASSOC_TYPE_ARTICLE),
37
					$journalId,
38
			array(STATISTICS_METRIC => STATISTICS_ORDER_DESC),
38
					$num);
39
			null,
39
		} else {
40
			false
40
			$result =& $this->retrieveLimit(
41
		);
41
					'SELECT a.article_id
42
42
					FROM published_articles pa INNER JOIN articles a ON (a.article_id = pa.article_id)
43
		$articlesInfo = array();
43
					WHERE a.journal_id = ? AND
44
		foreach ($stats as $statRecord) {
44
					views > 0
45
			if (count($articlesInfo) == $num) break;
45
					ORDER BY views DESC',
46
46
					$journalId,
47
			$articleId = $statRecord[STATISTICS_DIMENSION_SUBMISSION_ID];
47
					$num);
48
			$count = $statRecord[STATISTICS_METRIC];
48
		}
49
49
				
50
			$article = $publishedArticleDao->getPublishedArticleByArticleId($articleId); /* @var $article PublishedArticle */
50
		while (!$result->EOF) {
51
51
			$row = $result->GetRowAssoc(false);
52
			if (!is_a($article, 'PublishedArticle')) continue;
52
			$returner[] =& $publishedArticleDao->getPublishedArticleByArticleId($row['article_id']);
53
53
			$result->moveNext();
54
			if (!is_null($months)) {
55
				$limit = strtotime('-' . $months . ' months');
56
				if (strtotime($article->getDatePublished()) < $limit) continue;
57
			}
58
59
			$articlesInfo[$articleId] = array(
60
				'article' => $article,
61
				'views' => $count
62
			);
63
--
Line 64    Link Here 
55
		
56
		$result->Close();
57
		unset($result);
Line 65    Link Here 
65
		return $articlesInfo;
59
		return $returner;
66
--

Return to bug 8514