[pLog-svn] r2048 - in plog/branches/plog-1.1-ben/class: cache dao
ork at devel.plogworld.net
ork at devel.plogworld.net
Sun May 22 19:21:00 GMT 2005
Author: ork
Date: 2005-05-22 19:21:00 +0000 (Sun, 22 May 2005)
New Revision: 2048
Added:
plog/branches/plog-1.1-ben/class/dao/bloglinks.class.php
Modified:
plog/branches/plog-1.1-ben/class/cache/cachemanager.class.php
plog/branches/plog-1.1-ben/class/dao/mylinks.class.php
Log:
now thats better.. :)
introducing BlogLinks, a cache only object to store all links of a blog. whenever any link of a blog gets requested, we'll create an blogLinks Object in the disk-cache, containg all links of the current blog. as long as you use myLinks->getLinks(), the cache object will be called, and we dont need any sql statement. the cache gets removed whenever a new link is added or an existing link is deleted/modified.
getMyLink() needs to be treated somewhen down the road, but this method will only be called by the admin panel (delete/edit single link), so it's not that important. getMyLink() works fine right now, but we might save another sql statement then :)
Modified: plog/branches/plog-1.1-ben/class/cache/cachemanager.class.php
===================================================================
--- plog/branches/plog-1.1-ben/class/cache/cachemanager.class.php 2005-05-22 17:05:27 UTC (rev 2047)
+++ plog/branches/plog-1.1-ben/class/cache/cachemanager.class.php 2005-05-22 19:21:00 UTC (rev 2048)
@@ -16,6 +16,9 @@
define( "CACHE_TRACKBACKS", "trackbacks" );
define( "CACHE_NUMTRACKBACKS", "trackbacks_size" );
define( "CACHE_CONFIGDBSTORAGE", "config_db_storage" );
+ define( "CACHE_SITEADMINS", "permissions_siteadmin" );
+ define( "CACHE_BLOGLINKS", "blogLinks" );
+ define( "CACHE_MYLINKS", "blogLinks" );
/**
* Provides a singleton for storing and retrieving data from a global cache.
Added: plog/branches/plog-1.1-ben/class/dao/bloglinks.class.php
===================================================================
--- plog/branches/plog-1.1-ben/class/dao/bloglinks.class.php 2005-05-22 17:05:27 UTC (rev 2047)
+++ plog/branches/plog-1.1-ben/class/dao/bloglinks.class.php 2005-05-22 19:21:00 UTC (rev 2048)
@@ -0,0 +1,86 @@
+<?php
+ include_once( PLOG_CLASS_PATH."class/database/dbobject.class.php" );
+
+ /**
+ * \ingroup DAO
+ *
+ * Cache Object to cache all links of a blog, this information will not be stored in the db
+ * but only in the disk-cache.
+ */
+ class BlogLinks extends Object {
+
+ var $_blogId;
+ var $_links = array();
+ var $_linksById = array();
+ var $_categories = array();
+
+ /**
+ * Constructor
+ *
+ * @param blogId The blogId of the links to fetch
+ * @links array containing link objects
+ */
+ function BlogLinks( $blogId, $blogLinks )
+ {
+ $this->_blogId = $blogId;
+
+ foreach ($blogLinks as $link) {
+ $this->_links[] = $link;
+ $this->_linksById[$link->getId()] = $link;
+ $this->_categories[$link->getCategoryId()][] = $link;
+ }
+ }
+
+ /**
+ * Get the BlogId for the links stored in this object
+ */
+ function getBlogId()
+ {
+ return $this->_blogId;
+ }
+
+ /**
+ * Get all Links for current blog
+ */
+ function getLinks()
+ {
+ return $this->_links;
+ }
+
+ /**
+ * Get Links for a specific category, use categoryId = 0 to get all links.
+ *
+ * @param categoryId Category of the links to get
+ * @return array of link objects
+ */
+
+ function getLinksForCategory( $categoryId )
+ {
+ if ( $categoryId == 0 )
+ return $this->getLinks();
+ elseif ( is_array( $this->_categories[$categoryId] ) )
+ return $this->_categories[$categoryId];
+ else
+ return array();
+ }
+
+ /**
+ * Get specific link of current blog
+ *
+ * TBD: this method is not yet used, we might change a few admin panels to use this method
+ * instead of myLinks->getMyLink().
+ * (2005-05-22 ork at devel.plogworld.net)
+ *
+ * @param linkId The id of the link to get
+ * @return link object of false
+ */
+
+ function getLink( $linkId )
+ {
+ if ( isset($this->_links[$linkId]) )
+ return $this->_links[$linkId];
+ else
+ return false;
+ }
+ }
+?>
Modified: plog/branches/plog-1.1-ben/class/dao/mylinks.class.php
===================================================================
--- plog/branches/plog-1.1-ben/class/dao/mylinks.class.php 2005-05-22 17:05:27 UTC (rev 2047)
+++ plog/branches/plog-1.1-ben/class/dao/mylinks.class.php 2005-05-22 19:21:00 UTC (rev 2048)
@@ -2,6 +2,7 @@
include_once( PLOG_CLASS_PATH."class/dao/model.class.php" );
include_once( PLOG_CLASS_PATH."class/dao/mylink.class.php" );
+ include_once( PLOG_CLASS_PATH."class/dao/bloglinks.class.php" );
include_once( PLOG_CLASS_PATH."class/dao/mylinkscategories.class.php" );
/**
@@ -22,41 +23,42 @@
*/
function getLinks( $blogId, $categoryId = 0, $page = -1, $itemsPerPage = 15 )
{
+ $blogLinks = $this->getBlogLinks( $blogId );
+
+ $myLinks = $blogLinks->getLinksForCategory( $categoryId );
+
+ // check if we're using any paging
+ if( $page > -1 ) {
+ $start = (($page - 1) * $itemsPerPage);
+ $myLinks = array_slice( $myLinks, $start, $itemsPerPage );
+ }
+
+ return $myLinks;
+ }
+
+ function getBlogLinks( $blogId )
+ {
$blogLinks = $this->_cache->getData( $blogId, CACHE_BLOGLINKS );
- if ( !$blogLinks || $page != -1) {
- // check if we're using any paging
- if( $page > -1 ) {
- $start = (($page - 1) * $itemsPerPage);
- $limits = " LIMIT $start, $itemsPerPage";
- }
- else
- $limits = "";
-
- $query = "SELECT * FROM ".$this->getPrefix()."mylinks WHERE blog_id = '".Db::qstr($blogId)."'";
- if( $categoryId != 0 )
- $query .= " AND category_id = '".Db::qstr($categoryId)."'";
- $query .= " ORDER BY id ASC $limits;";
-
+ if( !$blogLinks ) {
+ $query = "SELECT * FROM ".$this->getPrefix()."mylinks WHERE blog_id = '".Db::qstr($blogId)."' ORDER BY id;";
+
$result = $this->Execute( $query );
if( !$result )
return false;
- $blogLinks = Array();
+ $links = Array();
while( $row = $result->FetchRow()) {
- $blogLink = $this->_fillMyLinkInformation( $row );
- array_push( $blogLinks, $blogLink );
+ $link = $this->_fillMyLinkInformation( $row );
+ array_push( $links, $link );
}
-
- if ( $page != -1 )
- $this->_cache->setData( $blogId, CACHE_BLOGLINKS, $blogLinks );
-
+ $blogLinks = new BlogLinks( $blogId, $links );
+ $this->_cache->setData( $blogId, CACHE_BLOGLINKS, $blogLinks );
}
-
- return $blogLinks;
- }
+ return $blogLinks;
+ }
/**
* returns how many links a blog has
@@ -67,13 +69,9 @@
*/
function getNumLinks( $blogId, $categoryId = 0 )
{
- $prefix = $this->getPrefix();
- $table = "{$prefix}mylinks";
- $cond = "blog_id = '".Db::qstr($blogId)."'";
- if( $categoryId > 0 )
- $cond .= " AND category_id = '".Db::qstr($categoryId)."'";
-
- return( $this->getNumItems( $table, $cond ));
+ $blogLinks = $this->getBlogLinks( $blogId );
+ $categoryLinks = $blogLinks->getLinksForCategory( $categoryId );
+ return count( $categoryLinks );
}
/**
More information about the pLog-svn
mailing list