[pLog-svn] r2206 - plog/trunk/class/dao
ork at devel.plogworld.net
ork at devel.plogworld.net
Sat Jun 11 23:49:36 GMT 2005
Author: ork
Date: 2005-06-11 23:49:35 +0000 (Sat, 11 Jun 2005)
New Revision: 2206
Modified:
plog/trunk/class/dao/model.class.php
Log:
just reformatted and added a few comment lines
Modified: plog/trunk/class/dao/model.class.php
===================================================================
--- plog/trunk/class/dao/model.class.php 2005-06-11 23:27:09 UTC (rev 2205)
+++ plog/trunk/class/dao/model.class.php 2005-06-11 23:49:35 UTC (rev 2206)
@@ -3,30 +3,43 @@
/**
* \defgroup DAO
*
- * DAO stands for "Data Access Object" and represents a data model according to the MVC architecture.
+ * DAO stands for "Data Access Object" and represents a data model
+ * according to the MVC architecture.
*
- * DAO classes isolate developers of all the intricacies of the database structure, so that for example
- * loading a post from the dabase is as easy as:
+ * DAO classes isolate developers of all the intricacies of the
+ * database structure, so that for example loading a post from the
+ * dabase is as easy as:
*
* <pre>
* $articles = new Articles();
* $userPost = $arcticles->getBlogArticle( 15 );
* </pre>
*
- * Otherwise, developers would need to write an SQL query every time we need to load an article from the database. In
- * general, DAO classes provide access to reading, updating and removing data from the database. In pLog, we usually
- * have two classes per entity: a smaller one that contains no database access logic and that only contains the
- * information necessary (usually, it represents a row from the database), and the second will be a bigger
- * class that includes SQL code and database logic and that provides all the methods outlined above (read, update
- * and remove from the database) Examples of this are Articles and Article, or Users and UserInfo.
+ * Otherwise, developers would need to write an SQL query every time we
+ * need to load an article from the database. In general, DAO classes
+ * provide access to reading, updating and removing data from the database.
+ * In pLog, we usually have two classes per entity: a smaller one that
+ * contains no database access logic and that only contains the information
+ * necessary (usually, it represents a row from the database), and the
+ * second will be a bigger class that includes SQL code and database logic
+ * and that provides all the methods outlined above (read, update and
+ * remove from the database) Examples of this are Articles and Article,
+ * or Users and UserInfo.
*
- * Other relevant DAO classes are ArticleComments and UserComment, MyLink and MyLinks, etc.
+ * Other relevant DAO classes are ArticleComments and UserComment,
+ * MyLink and MyLinks, etc.
*
- * All classes that extend the base Model class, automatically inherit an open connection to the database
- * (via the private attribute Model::_db) and several other database-related methods.
+ * All classes that extend the base Model class, automatically inherit
+ * an open connection to the database * (via the private attribute
+ * Model::_db) and several other database-related methods.
*
- * If you need to implement some kind of data access, please extend from Model.
+ * Furthermore all classes that extend the base Model class gets a
+ * reference to the global disk-based cache. More information on how
+ * to use the cache can be found in the Cache Group
*
+ * If you need to implement some kind of data access, please extend
+ * from Model.
+ *
*/
include_once( PLOG_CLASS_PATH."class/object/object.class.php" );
@@ -54,17 +67,20 @@
/**
* the names of the tables used in pLog
*/
- define( 'BLOGS_TABLENAME', 'blogs' );
- define( 'ARTICLES_TABLENAME', 'articles' );
- define( 'ARTICLETEXTS_TABLENAME', 'articles_text' );
- define( 'ARTICLE_CATEGORIES_RELATIONSHIP_TABLENAME', 'article_categories_link' );
+ define( 'BLOGS_TABLENAME', 'blogs' );
+ define( 'ARTICLES_TABLENAME', 'articles' );
+ define( 'ARTICLETEXTS_TABLENAME', 'articles_text' );
+ define( 'ARTICLE_CATEGORIES_RELATIONSHIP_TABLENAME',
+ 'article_categories_link' );
/**
* \ingroup DAO
*
- * This class provides all the classes extending it with a database connection so that classes don't have to
- * worry about that. Later on, the Model classes will be used by the corresponding action object.
+ * This class provides all the classes extending it with a database
+ * connection so that classes don't have to
+ * worry about that. Later on, the Model classes will be used by
+ * the corresponding action object.
*/
class Model extends Object
{
@@ -75,7 +91,7 @@
var $_dbInitialized = false;
/**
- * So far, it only initializes the connection to the database, using the ADOdb API.
+ * Basic constructor, setting up a cache for all classes extending Model
*
* @param useCache Some object might not need a cache and can disable it by passing false
*/
@@ -91,30 +107,41 @@
}
/**
- * executes a query with certain limits (for paging, for ex.
+ * executes a query with certain limits (for paging, for ex.)
*
- * @param query
- * @param page
- * @param itemsPerPage
+ * @param query The query to be executed
+ * @param page enable paging, pass page number or -1 to disable paging
+ * @param itemsPerPage number of items on a page
* @see Execute
* @return A ResultSet or false if errors
*/
- function Execute( $query, $page = DEFAULT_PAGING_ENABLED, $itemsPerPage = DEFAULT_ITEMS_PER_PAGE )
+ function Execute( $query,
+ $page = DEFAULT_PAGING_ENABLED,
+ $itemsPerPage = DEFAULT_ITEMS_PER_PAGE )
{
if( DEBUG_ENABLED && DEBUG_CHANNELS & DEBUG_CHANNEL_SQL )
- $this->debug->log("Executing SQL Query: $query", LOGGER_PRIO_INFO);
+ $this->debug->log("Executing SQL Query: $query",
+ LOGGER_PRIO_INFO);
+ // initialize the db when we have to execute the first query,
+ // not earlier.
$this->_initializeDb();
+ // see PDbDriverBase (or one of its drivers like PDbMySQLDriver
+ // for details)
$result = $this->_db->Execute( $query, $page, $itemsPerPage );
- // if the query generated an error, write a message to the sql error log file
+ // if the query generated an error, write a message to the sql
+ // error log file
if( !$result ) {
- include_once( PLOG_CLASS_PATH."class/logger/loggermanager.class.php" );
+ include_once( PLOG_CLASS_PATH . "class/logger/loggermanager.class.php" );
$log =& LoggerManager::getLogger( "sqlerr" );
$error = $this->DbError();
- $log->error( "The following query = \n{$query}\ngenerated the following error message = \n{$error}" );
+ $log->error( "The following query = \n" .
+ $query .
+ "generated the following error message = \n" .
+ $error );
}
return( $result );
@@ -131,6 +158,7 @@
/**
* returns the current database prefix
*
+ * @deprecated the prefix should be set/added by the Db Classes, not by the model
* @return the current database prefix
*/
function getPrefix()
@@ -181,56 +209,53 @@
$this->_db =& Db::getDb();
- // fetch the database prefix
- $this->getPrefix();
- // $this->_db->debug=DAO_DEBUG_ENABLED;
-
$this->_dbInitialized = true;
}
}
-
- /**
- * method to generate search conditions, should be implemented by child classes
- *
- * @param searchTerms
- */
- function buildSearchCondition( $searchTerms )
- {
- return( "" );
- }
-
- /**
- * given several conditions, concatenates them with an "AND" operator. If one of the
- * items of the array is an empty string, the condition will not be used
- *
- * @param conds
- * @return a string
- */
- function buildWhereCondition( $conds = Array(), $useWhere = true )
- {
- $valid = 0;
- $where = "";
-
- foreach( $conds as $cond ) {
- $this->log->debug( "Processing condition = ".$cond );
- if( $cond ) {
- // only if the condition is not empty...
-
- if( $valid > 0 )
- $where .= " AND ";
-
- // append the condition
- $where .= "$cond";
-
- // we've got a valid condition
- $valid++;
- }
- }
-
- if( $valid > 0 && $useWhere )
- $where = "WHERE $where";
-
- return( $where );
- }
+
+ /**
+ * method to generate search conditions, should be implemented by child classes
+ *
+ * @param searchTerms
+ */
+ function buildSearchCondition( $searchTerms )
+ {
+ return( "" );
+ }
+
+ /**
+ * given several conditions, concatenates them with an "AND" operator. If one of the
+ * items of the array is an empty string, the condition will not be used
+ *
+ * @deprecated use Db Class build(Select|Insert|...)Query instead
+ * @param conds
+ * @return a string
+ */
+ function buildWhereCondition( $conds = Array(), $useWhere = true )
+ {
+ $valid = 0;
+ $where = "";
+
+ foreach( $conds as $cond ) {
+ $this->log->debug( "Processing condition = ".$cond );
+ if( $cond ) {
+ // only if the condition is not empty...
+
+ if( $valid > 0 )
+ $where .= " AND ";
+
+ // append the condition
+ $where .= "$cond";
+
+ // we've got a valid condition
+ $valid++;
+ }
+ }
+
+ if( $valid > 0 && $useWhere )
+ $where = "WHERE $where";
+
+ return( $where );
+ }
}
?>
More information about the pLog-svn
mailing list