[pLog-svn] r2237 - plog/trunk/class/summary/dao
oscar at devel.plogworld.net
oscar at devel.plogworld.net
Wed Jun 15 17:13:22 GMT 2005
Author: oscar
Date: 2005-06-15 17:13:22 +0000 (Wed, 15 Jun 2005)
New Revision: 2237
Modified:
plog/trunk/class/summary/dao/summarystats.class.php
Log:
added a missing include
Modified: plog/trunk/class/summary/dao/summarystats.class.php
===================================================================
--- plog/trunk/class/summary/dao/summarystats.class.php 2005-06-15 16:54:14 UTC (rev 2236)
+++ plog/trunk/class/summary/dao/summarystats.class.php 2005-06-15 17:13:22 UTC (rev 2237)
@@ -4,6 +4,8 @@
include_once( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
include_once( PLOG_CLASS_PATH."class/dao/articlecommentstatus.class.php" );
include_once( PLOG_CLASS_PATH."class/dao/articlestatus.class.php" );
+ include_once( PLOG_CLASS_PATH."class/dao/articles.class.php" );
+ include_once( PLOG_CLASS_PATH."class/data/timestamp.class.php" );
/**
* maximum number of items that will be shown per page in the summary
@@ -22,11 +24,25 @@
*/
class SummaryStats extends Model
{
+
+ var $_now;
+ var $_sevenDaysAgo;
function SummaryStats()
{
// initialize ADOdb
$this->Model();
+
+ // common object for all methods so that we can reuse caches
+ $this->articles = new Articles();
+ $this->blogs = new Blogs();
+
+ // calculate the date limits
+ $t = new Timestamp();
+ $this->_now = $t->getTimestamp();
+ // 7 days ago
+ $t->subtractSeconds( 7 * 24 * 60 * 60 );
+ $this->_sevenDaysAgo = $t->getTimestamp();
}
/**
@@ -45,23 +61,14 @@
$query = " SELECT COUNT(*) as total_comments, a.*
FROM {$prefix}articles_comments AS c,
{$prefix}articles AS a,
- {$prefix}articles_text t,
{$prefix}blogs b
- WHERE c.article_id = a.id
- AND t.article_id = a.id
+ WHERE c.article_id = a.id
AND a.status = ".POST_STATUS_PUBLISHED."
AND c.status = ".COMMENT_STATUS_NONSPAM."
AND b.id = a.blog_id
AND b.status = ".BLOG_STATUS_ACTIVE."
- AND a.date <= NOW()";
+ AND a.date <= ".$this->_now;
- // ignore certain topics and/or certain texts
- /*if( $ignoreTopic != "" )
- $query .= " AND t.topic NOT LIKE '%".Db::qstr( $ignoreTopic )."%' ";
-
- if( $ignoreText != "" )
- $query .= " AND t.text NOT LIKE '%".Db::qstr( $ignoreTopic )."%' ";*/
-
$query .= " GROUP BY c.article_id ORDER BY total_comments DESC ";
if( $maxPosts > 0 )
@@ -75,9 +82,8 @@
}
$posts = Array();
- $articles = new Articles();
while( $row = $result->FetchRow()) {
- array_push( $posts, $articles->_fillArticleInformation($row));
+ array_push( $posts, $this->articles->_fillArticleInformation($row));
}
return $posts;
@@ -94,8 +100,9 @@
*/
function getMostReadArticles( $maxPosts = 0, $ignoreTopic = "", $ignoreText = "" )
{
- include_once( PLOG_CLASS_PATH."class/dao/articles.class.php" );
+
+ $prefix = $this->getPrefix();
$query = " SELECT
a.id as id,
a.properties as properties,
@@ -104,25 +111,11 @@
a.blog_id as blog_id,
a.status as status,
a.num_reads as num_reads,
- a.slug as slug,
- t.article_id as article_id,
- t.text as text,
- t.topic as topic,
- t.normalized_text as normalized_text,
- t.normalized_topic as normalized_topic,
- t.mangled_topic as mangled_topic
- FROM ".$this->getPrefix()."articles a, ".$this->getPrefix()."articles_text t
- WHERE a.id = t.article_id
- AND status = ".POST_STATUS_PUBLISHED."
- AND TO_DAYS(NOW()) - TO_DAYS(date) < 7 ";
+ a.slug as slug
+ FROM {$prefix}articles a
+ WHERE status = ".POST_STATUS_PUBLISHED."
+ AND a.date <= ".$this->_now." AND a.date > ".$this->_sevenDaysAgo;
- // ignore certain topics and/or certain texts
- if( $ignoreTopic != "" )
- $query .= " AND t.topic NOT LIKE '".Db::qstr( $ignoreTopic )."' ";
-
- /*if( $ignoreText != "" )
- $query .= " AND t.text NOT LIKE '".Db::qstr( $ignoreText )."' ";*/
-
$query .= " ORDER BY a.num_reads DESC ";
if( $maxPosts > 0 )
@@ -134,9 +127,8 @@
return Array();
$posts = Array();
- $articles = new Articles();
while( $row = $result->FetchRow()) {
- $post = $articles->_fillArticleInformation($row);
+ $post = $this->articles->_fillArticleInformation($row);
array_push( $posts, $post );
}
@@ -165,9 +157,8 @@
}
$blogs = Array();
- $blogdao = new Blogs();
while( $row = $result->FetchRow()) {
- $blog = $blogdao->_fillBlogInformation( $row );
+ $blog = $this->blogs->_fillBlogInformation( $row );
$blogs[$blog->getId()] = $blog;
}
@@ -188,7 +179,8 @@
FROM {$prefix}articles AS a
INNER JOIN {$prefix}blogs AS b
ON b.id=a.blog_id AND b.status=".BLOG_STATUS_ACTIVE.
- " GROUP BY a.blog_id ORDER BY rank DESC ";
+ " WHERE a.date >= ".$this->_sevenDaysAgo." AND a.date <= ".$this->_now."
+ GROUP BY a.blog_id ORDER BY rank DESC ";
if( $maxBlogs > 0 )
$query .= " LIMIT 0,".$maxBlogs;
@@ -200,9 +192,8 @@
}
$blogs = Array();
- $blogdao = new Blogs();
while( $row = $result->FetchRow()) {
- $blog = $blogdao->_fillBlogInformation( $row );
+ $blog = $this->blogs->_fillBlogInformation( $row );
$blogs[$blog->getId()] = $blog;
}
@@ -266,35 +257,18 @@
$date = $t->getTimestamp();
$prefix = $this->getPrefix();
- $query = "SELECT a.id as id, a.id,t.topic,t.text,a.date,
+ $query = "SELECT a.id as id, a.id,a.date,
a.user_id,a.blog_id, a.status, a.properties,
a.num_reads, a.slug
FROM {$prefix}articles a,
- {$prefix}articles_categories c,
- {$prefix}article_categories_link l,
- {$prefix}articles_text t,
{$prefix}blogs b
- WHERE t.article_id = a.id
- AND TO_DAYS(NOW()) - TO_DAYS(a.date) < 7
- AND l.article_id = a.id
- AND l.category_id = c.id
- AND c.in_main_page = 1
+ WHERE a.date >= ".$this->_sevenDaysAgo." AND a.date <= ".$this->_now."
AND a.blog_id = b.id
AND b.status = ".BLOG_STATUS_ACTIVE."
- AND a.status = ".POST_STATUS_PUBLISHED."
- AND a.date < NOW()";
+ AND a.status = ".POST_STATUS_PUBLISHED;
+ $query .= " ORDER BY a.date DESC LIMIT 0, $maxPosts";
- // in case we'd like to ignore certain posts based on a topic (like the registration message!)
- if( $ignoreTopic != "" ) {
- $query .= " AND t.topic NOT LIKE '".Db::qstr( $ignoreTopic )."' ";
- }
- // in case we'd like to ignore certain posts based on their contents (like the registration message!)
- /*if( $ignoreText != "" ) {
- $query .= " AND t.text NOT LIKE '".Db::qstr( $ignoreText )."' ";
- }*/
- $query .= " GROUP BY a.id ORDER BY a.date DESC LIMIT 0, $maxPosts";
-
$result = $this->Execute( $query );
if( !$result )
@@ -303,12 +277,12 @@
$blogs = Array();
$posts = Array();
$i = 0;
- $articles = new Articles();
+
while( ($row = $result->FetchRow()) && ($i < $maxPosts) ) {
if (!in_array($row["blog_id"], $blogs))
{
$blogs[] = $row["blog_id"];
- array_push( $posts, $articles->_fillArticleInformation($row) );
+ array_push( $posts, $this->articles->_fillArticleInformation($row) );
$i++;
}
}
@@ -347,13 +321,13 @@
if (empty($maxPosts))
{
- array_push( $posts, $articles->_fillArticleInformation($row));
+ array_push( $posts, $this->articles->_fillArticleInformation($row));
$count++;
}
else if($count <= $maxPosts && empty($ids[$row["blog_id"]]))
{
$ids[$row["blog_id"]] = true;
- array_push( $posts, $articles->_fillArticleInformation($row));
+ array_push( $posts, $this->articles->_fillArticleInformation($row));
$count++;
}
}
More information about the pLog-svn
mailing list