Source for file _chaptercache.class.php
Documentation is available at _chaptercache.class.php
* This file implements the ChapterCache class.
* This file is part of Quam Plures - {@link http://quamplures.net/}
* See also {@link https://launchpad.net/quam-plures}.
* @copyright (c) 2009 - 2011 by the Quam Plures developers - {@link http://quamplures.net/}
* @copyright (c)2003-2009 by Francois PLANQUE - {@link http://fplanque.net/}
* {@internal License choice
* - If you have received this file as part of a package, please find the license.txt file in
* the same folder or the closest folder above for complete license terms.
* - If you have received this file individually (e-g: from http://evocms.cvs.sourceforge.net/)
* then you must choose one of the following licenses before using the file:
* - GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php
* - Mozilla Public License 1.1 (MPL) - http://www.opensource.org/licenses/mozilla1.1.php
* @author fplanque: Francois PLANQUE
if( !defined('QP_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
load_class( 'generic/model/_genericcategorycache.class.php' );
load_class( 'chapters/model/_chapter.class.php' );
* Lazy filled index of url titles
if( $Settings->get('chapter_ordering') == 'manual' )
parent::GenericCategoryCache( 'Chapter', false, 'T_categories', 'cat_', 'cat_ID', 'cat_name', 'blog_ID', $order_by );
* Get an object from cache by ID
* Load the cache if necessary (all at once if allowed).
* @param integer ID of object to load
* @param boolean true if function should die on error
* @param boolean true if function should die on empty/null
* @param integer|NULLNULL for all subsets
* @return Chapter Reference on cached object or false.
function & get_by_ID( $req_ID, $halt_on_error = true, $halt_on_empty = true, $subset_ID = NULL )
if( !empty( $this->cache[ $req_ID ] ) )
$Debuglog->add( "Accessing Chapter($req_ID) from cache", 'dataobjects' );
return $this->cache[ $req_ID ];
{ // Not in cache, but not everything is loaded yet
{ // It's ok to just load everything:
{ // Load just the requested object:
$Debuglog->add( "Loading <strong>$this->objtype($req_ID)</strong> into cache", 'dataobjects' );
// Note: $req_ID MUST be an unsigned integer. This is how DataObject works.
AND cat_blog_ID = ". $subset_ID;
if( $row = $DB->get_row( $sql, OBJECT, 0, 'ChapterCache::get_by_ID()' ) )
$Debuglog->add( 'Could not add() object to cache!', 'dataobjects' );
$Debuglog->add( 'Could not get DataObject by ID. Query: '. $sql, 'dataobjects' );
if( empty( $this->cache[ $req_ID ] ) )
{ // Requested object does not exist
// $Debuglog->add( 'failure', 'dataobjects' );
return $this->cache[ $req_ID ];
* Get an object from cache by urlname
* Load the cache if necessary (all at once if allowed).
* @param string ID of object to load
* @param boolean true if function should die on error
* @return reference on cached object
// Load just the requested object:
$Debuglog->add( "Loading <strong>$this->objtype($req_urlname)</strong> into cache", 'dataobjects' );
WHERE cat_urlname = ". $DB->quote($req_urlname);
$row = $DB->get_row( $sql );
{ // Requested object does not exist
$Debuglog->add( "Retrieving <strong>$this->objtype($req_urlname)</strong> from cache" );
* Load a keyed subset of the cache
* @param integer|NULLNULL for all subsets
// fp> TODO: This kills other subsets. BAD if we want to handle multiple subsets independently
$Debuglog->add( 'ChapterCache - Loading <strong>chapters('. $subset_ID. ')</strong> into cache', 'dataobjects' );
WHERE cat_blog_ID = '. $subset_ID;
if( $Settings->get('chapter_ordering') == 'manual' )
$sql .= ' ORDER BY cat_order';
$sql .= ' ORDER BY cat_name';
foreach( $DB->get_results( $sql, OBJECT, 'Loading chapters('. $subset_ID. ') into cache' ) as $row )
// Instantiate a custom object
* Move a chapter and its descendants to a different collection
// Make sure children have been revealed for specific subset:
// fp>We get the Chapter AFTER reveal_children, because something is wrong with reveal_children or get_by_ID
// I don't know what right now, but if we get Chapter earlier, we'll be stuck with an old copy of it that does NOT have the children
// TODO: find out what's freakin wrong
$chapters_to_move = array();
// Get $chapters_to_move:
if( $parent_Chapter = $Chapter->get_parent_Chapter() )
{ // Was not already at root, cut it and move it:
$Chapter->set( 'parent_ID', NULL );
// Move Chapters to new Blog:
$sql = 'UPDATE T_categories
SET cat_blog_ID = '. $dest_collection_ID. '
WHERE cat_blog_ID = '. $src_collection_ID /* extra security */ . '
AND cat_ID IN ('. implode( ',', $chapters_to_move ). ')';
// Now the cache is badly screwed. Reseting it is fair enough, because this won't happen very often.
* Support function for move_Chapter_subtree
$list_array[] = $Chapter->ID;
foreach( $Chapter->children as $child_Chapter )
* Instanciate a new object within this cache
* @param integer|NULLsubset to use for new object
function & new_obj( $row = NULL, $subset_ID = NULL )
// Instantiate a custom object
$Chapter = new Chapter( $row, $subset_ID ); // Copy
|