phpDocumentor pond
[ class tree: pond ] [ index: pond ] [ all elements ]

Source for file _chapter.class.php

Documentation is available at _chapter.class.php

  1. <?php
  2. /**
  3.  * This file implements the Chapter class.
  4.  *
  5.  * This file is part of Quam Plures - {@link http://quamplures.net/}
  6.  * See also {@link https://launchpad.net/quam-plures}.
  7.  *
  8.  * @copyright (c) 2009 - 2011 by the Quam Plures developers - {@link http://quamplures.net/}
  9.  * @copyright (c)2003-2009 by Francois PLANQUE - {@link http://fplanque.net/}
  10.  *  Parts of this file are copyright (c)2005-2006 by PROGIDISTRI - {@link http://progidistri.com/}.
  11.  *
  12.  *  {@internal License choice
  13.  *  - If you have received this file as part of a package, please find the license.txt file in
  14.  *    the same folder or the closest folder above for complete license terms.
  15.  *  - If you have received this file individually (e-g: from http://evocms.cvs.sourceforge.net/)
  16.  *    then you must choose one of the following licenses before using the file:
  17.  *    - GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php
  18.  *    - Mozilla Public License 1.1 (MPL) - http://www.opensource.org/licenses/mozilla1.1.php
  19.  *  }}}
  20.  *
  21.  *  {@internal Below is a list of authors who have contributed to design/coding of this file: }}
  22.  * @author fplanque: Francois PLANQUE.
  23.  *
  24.  * @package pond
  25.  */
  26. if!defined('QP_MAIN_INIT') ) die'Please, do not access this page directly.' );
  27.  
  28. load_class('generic/model/_genericcategory.class.php');
  29.  
  30.  
  31. /**
  32.  * Chapter Class
  33.  *
  34.  * @package pond
  35.  */
  36. class Chapter extends GenericCategory
  37. {
  38.     /**
  39.      * @var integer 
  40.      */
  41.     var $blog_ID;
  42.     /**
  43.      * The Blog of the Item (lazy filled, use {@link get_Blog()} to access it.
  44.      * @access protected
  45.      * @var Blog 
  46.      */
  47.     var $Blog;
  48.  
  49.     var $urlname;
  50.     var $description;
  51.     var $order;
  52.  
  53.     /**
  54.      * Lazy filled
  55.      * @var Chapter 
  56.      */
  57.     var $parent_Chapter;
  58.  
  59.     /**
  60.      * Constructor
  61.      *
  62.      * @param table Database row
  63.       * @param integer|NULLsubset to use for new object
  64.      */
  65.     function Chapter$db_row NULL$subset_ID NULL )
  66.     {
  67.         // Call parent constructor:
  68.         parent::GenericCategory'T_categories''cat_''cat_ID'$db_row );
  69.  
  70.         ifis_null($db_row) )
  71.         {    // We are creating an object here:
  72.             $this->set'blog_ID'$subset_ID );
  73.         }
  74.         else
  75.         {    // Wa are loading an object:
  76.             $this->blog_ID = $db_row->cat_blog_ID;
  77.             $this->urlname = $db_row->cat_urlname;
  78.             $this->description = $db_row->cat_description;
  79.             $this->order = $db_row->cat_order;
  80.         }
  81.     }
  82.  
  83.  
  84.     /**
  85.      * Load data from Request form fields.
  86.      *
  87.      * @return boolean true if loaded data seems valid.
  88.      */
  89.     function load_from_request()
  90.     {
  91.         global $DB$Settings;
  92.  
  93.         parent::load_from_Request();
  94.  
  95.         // Check url name
  96.         param'cat_urlname''string' );
  97.         $this->set_from_Request'urlname' );
  98.  
  99.         // Check description
  100.         param'cat_description''string' );
  101.         $this->set_from_Request'description' );
  102.  
  103.         if$Settings->get('chapter_ordering'== 'manual' )
  104.         {    // Manual ordering
  105.             param'cat_order''integer' );
  106.             $this->set_from_Request'order' );
  107.         }
  108.  
  109.         return param_errors_detected();
  110.     }
  111.  
  112.  
  113.     /**
  114.      *
  115.      */
  116.     function get_parent_Chapter()
  117.     {
  118.         ifisset$this->parent_Chapter ) )
  119.         {    // Not resoleved yet!
  120.             ifempty$this->parent_ID ) )
  121.             {
  122.                 $this->parent_Chapter = NULL;
  123.             }
  124.             else
  125.             {
  126.                 $ChapterCache get_Cache'ChapterCache' );
  127.                 $this->parent_Chapter = $ChapterCache->get_by_ID$this->parent_ID );
  128.             }
  129.         }
  130.  
  131.         return $this->parent_Chapter;
  132.     }
  133.  
  134.  
  135.     /**
  136.      * Get URL path (made of URL names) back to the root
  137.      */
  138.     function get_url_path()
  139.     {
  140.         $r $this->urlname.'/';
  141.  
  142.         $parent_Chapter $this->get_parent_Chapter();
  143.         if!is_null$parent_Chapter ) )
  144.         {    // Recurse:
  145.             $r $parent_Chapter->get_url_path().$r;
  146.         }
  147.  
  148.         return $r;
  149.     }
  150.  
  151.  
  152.     /**
  153.      * Generate the URL to access the category.
  154.      *
  155.      * @param string|NULL'param_num', 'subchap', 'chapters'
  156.      * @param string|NULLurl to use
  157.      * @param integer category page to link to, default:1
  158.      * @param integer|NULLnumber of posts per page (used for param_num only)
  159.      * @param string glue between url params
  160.      */
  161.     function get_permanent_url$link_type NULL$blogurl NULL$paged 1$chapter_posts_per_page NULL$glue '&amp;' )
  162.     {
  163.         global $DB$cacheweekly$Settings;
  164.  
  165.         ifempty$link_type ) )
  166.         {    // Use default from settings:
  167.             $this->get_Blog();
  168.             $link_type $this->Blog->get_setting'chapter_links' );
  169.         }
  170.  
  171.         ifempty$blogurl ) )
  172.         {
  173.             $this->get_Blog();
  174.             $blogurl $this->Blog->gen_blogurl();
  175.         }
  176.  
  177.         switch$link_type )
  178.         {
  179.             case 'param_num':
  180.                 $r url_add_param$blogurl'cat='.$this->ID$glue );
  181.                 ifempty($chapter_posts_per_page) )
  182.                 {    // Use default from Blog
  183.                     $this->get_Blog();
  184.                     $chapter_posts_per_page $this->Blog->get_setting'chapter_posts_per_page' );
  185.                 }
  186.                 if!empty($chapter_posts_per_page&& $chapter_posts_per_page != $this->Blog->get_setting'posts_per_page' ) )
  187.                 {    // We want a specific post per page count:
  188.                     $r url_add_param$r'posts='.$chapter_posts_per_page$glue );
  189.                 }
  190.                 break;
  191.  
  192.             case 'subchap':
  193.                 $this->get_Blog();
  194.                 $category_prefix $this->Blog->get_setting('category_prefix');
  195.                 if!empty$category_prefix ) )
  196.                 {
  197.                     $r url_add_tail$blogurl'/'.$category_prefix.'/'.$this->urlname.'/' );
  198.                 }
  199.                 else
  200.                 {
  201.                     $r url_add_tail$blogurl'/'.$this->urlname.'/' );
  202.                 }
  203.                 break;
  204.  
  205.             case 'chapters':
  206.             default:
  207.                 $this->get_Blog();
  208.                 $category_prefix $this->Blog->get_setting('category_prefix');
  209.                 if!empty$category_prefix ) )
  210.                 {
  211.                     $r url_add_tail$blogurl'/'.$category_prefix.'/'.$this->get_url_path() );
  212.                 }
  213.                 else
  214.                 {
  215.                     $r url_add_tail$blogurl'/'.$this->get_url_path() );
  216.                 }
  217.                 break;
  218.         }
  219.  
  220.         if$paged )
  221.         {
  222.             $r url_add_param$r'paged='.$paged$glue );
  223.         }
  224.  
  225.         return $r;
  226.     }
  227.  
  228.  
  229.     /**
  230.      * Get the Blog object for the Chapter.
  231.      *
  232.      * @return Blog 
  233.      */
  234.     function get_Blog()
  235.     {
  236.         ifis_null($this->Blog) )
  237.         {
  238.             $this->load_Blog();
  239.         }
  240.  
  241.         return $this->Blog;
  242.     }
  243.  
  244.  
  245.     /**
  246.      * Load the Blog object for the Chapter, without returning it.
  247.      */
  248.     function load_Blog()
  249.     {
  250.         ifis_null($this->Blog) )
  251.         {
  252.             $BlogCache get_Cache'BlogCache' );
  253.             $this->Blog = $BlogCache->get_by_ID$this->blog_ID );
  254.         }
  255.     }
  256.  
  257.  
  258.     /**
  259.      * Insert object into DB based on previously recorded changes.
  260.      *
  261.      * @param boolean Whether to notify the user when the url title has been changed.
  262.      * @return boolean true on success
  263.      */
  264.     function dbinsert$urlname_verbose_change true )
  265.     {
  266.         global $DB;
  267.  
  268.         if$this->ID != debug_die'Existing object cannot be inserted!' );
  269.  
  270.         $DB->begin();
  271.  
  272.         // validate url title / slug
  273.         $this->set'urlname'urltitle_validate$this->urlname$this->name,
  274.                 $this->IDfalse$this->dbprefix.'urlname'$this->dbIDname,
  275.                 $this->dbtablename$urlname_verbose_change ) );
  276.  
  277.         $r parent::dbinsert();
  278.  
  279.         $DB->commit();
  280.  
  281.         return $r;
  282.     }
  283.  
  284.     /**
  285.      * Update the DB based on previously recorded changes
  286.      *
  287.      * @return boolean true on success
  288.      */
  289.     function dbupdate()
  290.     {
  291.         global $DB;
  292.  
  293.         $DB->begin();
  294.  
  295.         // validate url title / slug
  296.         ifempty($this->urlname|| isset($this->dbchanges['cat_urlname']) )
  297.         // Url title has changed or is empty
  298.             $this->set'urlname'urltitle_validate$this->urlname$this->name$this->IDfalse$this->dbprefix.'urlname'$this->dbIDname$this->dbtablename) );
  299.         }
  300.  
  301.         $r parent::dbupdate();
  302.  
  303.         $DB->commit();
  304.  
  305.         return $r;
  306.     }
  307. }
  308.  
  309.  
  310. ?>