[pLog-svn] r2375 - in plog/branches/plog-1.1-daochanges/class: dao
view
oscar at devel.plogworld.net
oscar at devel.plogworld.net
Thu Jul 28 20:38:13 GMT 2005
Author: oscar
Date: 2005-07-28 20:38:13 +0000 (Thu, 28 Jul 2005)
New Revision: 2375
Modified:
plog/branches/plog-1.1-daochanges/class/dao/articles.class.php
plog/branches/plog-1.1-daochanges/class/dao/model.class.php
plog/branches/plog-1.1-daochanges/class/dao/mylinks.class.php
plog/branches/plog-1.1-daochanges/class/dao/mylinkscategories.class.php
plog/branches/plog-1.1-daochanges/class/view/blogview.class.php
Log:
a few more changes
Modified: plog/branches/plog-1.1-daochanges/class/dao/articles.class.php
===================================================================
--- plog/branches/plog-1.1-daochanges/class/dao/articles.class.php 2005-07-28 09:43:32 UTC (rev 2374)
+++ plog/branches/plog-1.1-daochanges/class/dao/articles.class.php 2005-07-28 20:38:13 UTC (rev 2375)
@@ -249,7 +249,9 @@
'date',
1 );
- return( $this->_getBlogArticleFromQuery( $query, false ));
+ $article = $this->_getBlogArticleFromQuery( $query, false );
+
+ return( $article );
}
/**
@@ -283,7 +285,9 @@
'date',
1 );
- return( $this->_getBlogArticleFromQuery( $query, false ));
+ $article = $this->_getBlogArticleFromQuery( $query, false );
+
+ return( $article );
}
/**
@@ -331,10 +335,8 @@
$maxDate = 0,
$searchTerms = "" )
{
- if( $status != POST_STATUS_PUBLISHED ) {
- if( $article->getStatus() != $status )
- return false;
- }
+ if( $article->getStatus() != $status )
+ return false;
if( $categoryId > 0 ) {
$found = false;
foreach( $article->getCategoryIds() as $catId ) {
@@ -382,7 +384,6 @@
$searchTerms = "",
$page = -1 )
{
- include_once( PLOG_CLASS_PATH."class/dao/blogarticles.class.php" );
$articles = $this->getArticles( $blogId );
$result = Array();
@@ -412,6 +413,7 @@
{
$archives = $this->_cache->getData( $blogId, CACHE_ARTICLESPERMONTH );
+ $arcnives = false;
if( !$archives ) {
require_once( PLOG_CLASS_PATH . 'class/dao/blogs.class.php' );
@@ -419,21 +421,22 @@
$blogInfo = $blogs->getBlogInfo( $blogId );
$blogSettings = $blogInfo->getSettings();
+ $prefix = $this->getPrefix();
if( $blogSettings->getValue("show_future_posts_in_calendar") )
$numPostsPerMonthQuery = "SELECT COUNT(*) AS 'count',
- YEAR(date) AS 'year',
- MONTH(date) AS 'month'
- FROM ".$this->getPrefix().ARTICLES_TABLENAME."
- WHERE status = 1 AND blog_id = ".$blogId."
+ YEAR(date) AS 'year',
+ MONTH(date) AS 'month'
+ FROM {$prefix}articles
+ WHERE status = 1 AND blog_id = $blogId
GROUP BY YEAR(date),MONTH(date)
ORDER BY YEAR(date) DESC,MONTH(date) DESC;";
else
$numPostsPerMonthQuery = "SELECT COUNT(*) AS 'count',
YEAR(date) AS 'year',
MONTH(date) AS 'month'
- FROM ".$this->getPrefix().ARTICLES_TABLENAME."
- WHERE status = 1 AND blog_id = ".$blogId."
- AND date <= NOW()
+ FROM {$prefix}articles
+ WHERE status = 1 AND blog_id = $blogId
+ AND date <= NOW()
GROUP BY YEAR(date),MONTH(date)
ORDER BY YEAR(date) DESC,MONTH(date) DESC;";
@@ -458,22 +461,21 @@
*/
function getNumberPostsPerMonthAdmin( $blogId )
{
- // query to get the earliest post
- // this must be my longest and most complex SQL query ever :)
- $numPostsPerMonthQuery = "SELECT COUNT(*) AS 'count', YEAR(date) AS 'year',
- MONTH(date) AS 'month', DAYOFMONTH(date) AS 'daymonth'
- FROM ".$this->getPrefix()."articles
- WHERE blog_id = $blogId
- GROUP BY YEAR(date), MONTH(date)
+ $prefix = $this->getPrefix();
+ $numPostsPerMonthQuery = "SELECT date
+ FROM {$prefix}articles
+ WHERE blog_id = '".Db::qstr($blogId)."'
ORDER BY YEAR(date) DESC,MONTH(date) DESC;";
$result = $this->Execute( $numPostsPerMonthQuery);
- if( $result == false )
- return false;
+ if( !$result )
+ return Array();
while( $row = $result->FetchRow()) {
- $archives[$row["year"]][$row["month"]] = $row["count"];
- }
+ $year = substr($row["date"],0,4);
+ $month = substr($row["date"],4,2);
+ $archives[$year][$month] = 1;
+ }
return $archives;
}
@@ -482,45 +484,48 @@
* The same as the one above but for just one month
*
* @param blogId The identifier of the blog from which we'd like to calculate this
- * @param year Year
+ * @param year Yeardddd
* @param month Month from which we'd like to calculate this
* @return An associative array where the index is the day of the month and the value
* is the number of posts made that day.
*/
- function getNumberPostsPerDay( $blogId, $year = null , $month = null )
+ function getDaysWithPosts( $blogId, $year = null , $month = null )
{
include_once( PLOG_CLASS_PATH.'class/data/timestamp.class.php' );
+ $t = new Timestamp();
// if month and/or year are empty, get the current ones
- if( $year == null ) {
- $t = new Timestamp();
+ if( $year == null )
$year = $t->getYear();
- }
- if( $month == null ) {
- $t = new Timestamp();
+ if( $month == null )
$month = $t->getMonth();
- }
+
+ // build a valid timestamp for the query
+ $dateTimestamp = $year.$month."00000000";
- // another long sql query :) the id and date fields are there just in case we need to debug
- // but they're not included in the resulting array
$blogs = new Blogs();
$blogInfo = $blogs->getBlogInfo( $blogId );
$blogSettings = $blogInfo->getSettings();
// check whether we're supposed to show posts that happen in the future or not
- if( $blogSettings->getValue( "show_future_posts_in_calendar" ))
- $numPostsPerDayQuery = "SELECT COUNT(*) AS 'count', DAYOFMONTH(date) AS 'day', id AS 'id', date AS 'date' FROM ".$this->getPrefix()."articles WHERE status = 1 AND blog_id = ".$blogId." AND MONTH(date) = ".$month." AND YEAR(date) = ".$year." GROUP BY DAYOFMONTH(date);";
- else
- $numPostsPerDayQuery = "SELECT COUNT(*) AS 'count', DAYOFMONTH(date) AS 'day', id AS 'id', date AS 'date' FROM ".$this->getPrefix()."articles WHERE status = 1 AND blog_id = ".$blogId." AND date <= NOW() AND MONTH(date) = ".$month." AND YEAR(date) = ".$year." GROUP BY DAYOFMONTH(date);";
+ $prefix = $this->getPrefix();
+ $numPostsPerDayQuery = "SELECT date
+ FROM {$prefix}articles
+ WHERE status = 1
+ AND blog_id = $blogId
+ AND date >= $dateTimestamp";
+ if( !$blogSettings->getValue( "show_future_posts_in_calendar" ))
+ $numPostsPerDayQuery .= " AND date <= NOW()";
$result = $this->Execute( $numPostsPerDayQuery );
- if( $result == false )
- return 0;
+ if( !$result )
+ return Array();
$postPerDay = Array();
while( $row = $result->FetchRow()) {
- $postsPerDay[$row["day"]] = $row["count"];
- }
+ $day = substr($row['date'],6,2);
+ $postsPerDay[$day] = 1;
+ }
return $postsPerDay;
}
@@ -914,7 +919,7 @@
if( $article->getStatus() == POST_STATUS_PUBLISHED ) {
$blogs = new Blogs();
$blogInfo = $article->getBlogInfo();
- $blogInfo->setTotalArticles( $blogInfo->getTotalArticles() + 1 );
+ $blogInfo->setTotalArticles( $blogInfo->getTotalArticles() - 1 );
$blogs->updateBlog( $blogInfo );
}
Modified: plog/branches/plog-1.1-daochanges/class/dao/model.class.php
===================================================================
--- plog/branches/plog-1.1-daochanges/class/dao/model.class.php 2005-07-28 09:43:32 UTC (rev 2374)
+++ plog/branches/plog-1.1-daochanges/class/dao/model.class.php 2005-07-28 20:38:13 UTC (rev 2375)
@@ -248,9 +248,10 @@
$dbObjects = Array();
while( $row = $result->FetchRow()) {
- $dbObjects[] = $this->mapRow( $row );
+ $dbObject = $this->mapRow( $row );
+ $dbObjects[] = $dbObject;
if( $itemCaches ) {
- foreach( $caches as $cache => $getter ) {
+ foreach( $itemCaches as $cache => $getter ) {
$this->_cache->setData( $dbObject->$getter(), $cache, $dbObject );
}
}
Modified: plog/branches/plog-1.1-daochanges/class/dao/mylinks.class.php
===================================================================
--- plog/branches/plog-1.1-daochanges/class/dao/mylinks.class.php 2005-07-28 09:43:32 UTC (rev 2374)
+++ plog/branches/plog-1.1-daochanges/class/dao/mylinks.class.php 2005-07-28 20:38:13 UTC (rev 2375)
@@ -111,8 +111,8 @@
$linkCategories = new MyLinksCategories();
$linkCategory = $link->getMyLinkCategory();
$linkCategory->setLastModification( Timestamp::getNowTimestamp());
- $category->setNumLinks( $category->getNumLinks() - 1 );
- $linkCategories->updateMyLinkCategory( $linkCategory );
+ $linkCategory->setNumLinks( $linkCategory->getNumLinks() - 1 );
+ $linkCategories->updateMyLinksCategory( $linkCategory );
return( true );
}
else
Modified: plog/branches/plog-1.1-daochanges/class/dao/mylinkscategories.class.php
===================================================================
--- plog/branches/plog-1.1-daochanges/class/dao/mylinkscategories.class.php 2005-07-28 09:43:32 UTC (rev 2374)
+++ plog/branches/plog-1.1-daochanges/class/dao/mylinkscategories.class.php 2005-07-28 20:38:13 UTC (rev 2375)
@@ -72,7 +72,7 @@
$blogCategories = $this->getMany( "blog_id",
$blogId,
CACHE_MYLINKCATEGORIES_ALL,
- Array( CACHE_MYLINKCATEGORIES => "getId" ),
+ Array( CACHE_MYLINKSCATEGORIES => "getId" ),
$page,
$itemsPerPage );
@@ -87,7 +87,7 @@
*/
function addMyLinksCategory( &$myLinksCategory )
{
- if(( $result = $this->add( $myLinksCategory, Array( CACHE_MYLINKCATEGORIES => "getId" )))) {
+ if(( $result = $this->add( $myLinksCategory, Array( CACHE_MYLINKSCATEGORIES => "getId" )))) {
$this->_cache->removeData( "all", CACHE_MYLINKCATEGORIES_ALL );
}
@@ -188,7 +188,7 @@
include_once( PLOG_CLASS_PATH."class/data/timestamp.class.php" );
$category = $this->getMyLinksCategory( $categoryId );
if( $category ) {
- $category->setModificationDate( Timestamp::getNowTimestamp());
+ $category->setLastModification( Timestamp::getNowTimestamp());
return( $this->update( $category ));
}
else
Modified: plog/branches/plog-1.1-daochanges/class/view/blogview.class.php
===================================================================
--- plog/branches/plog-1.1-daochanges/class/view/blogview.class.php 2005-07-28 09:43:32 UTC (rev 2374)
+++ plog/branches/plog-1.1-daochanges/class/view/blogview.class.php 2005-07-28 20:38:13 UTC (rev 2375)
@@ -149,7 +149,7 @@
$month = $this->getValue( 'Month' );
$year = $this->getValue( 'Year' );
- return( $this->articles->getNumberPostsPerDay( $this->_blogInfo->getId(), $year, $month ));
+ return( $this->articles->getDaysWithPosts( $this->_blogInfo->getId(), $year, $month ));
}
/**
More information about the pLog-svn
mailing list