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

Source for file _commentlist.class.php

Documentation is available at _commentlist.class.php

  1. <?php
  2. /**
  3.  * This file implements the CommentList class.
  4.  *
  5.  * This file is part of the Quam Plures project - {@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)2004-2005 by Daniel HAHLER - {@link http://thequod.de/contact}.
  11.  *
  12.  * @license http://quamplures.net/license.html GNU General Public License (GPL)
  13.  *
  14.  *  {@internal Open Source relicensing agreement:
  15.  *  Daniel HAHLER grants Francois PLANQUE the right to license
  16.  *  Daniel HAHLER's contributions to this file and the b2evolution project
  17.  *  under any OSI approved OSS license (http://www.opensource.org/licenses/).
  18.  *  }}}
  19.  *
  20.  *  {@internal Below is a list of authors who have contributed to design/coding of this file: }}
  21.  * @author blueyed: Daniel HAHLER.
  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('_core/model/dataobjects/_dataobjectlist.class.php');
  29.  
  30. /**
  31.  * CommentList Class
  32.  *
  33.  * @package pond
  34.  */
  35. class CommentList extends DataObjectList
  36. {
  37.     /**
  38.      * Constructor
  39.      *
  40.      * @param Blog can pass NULL if $p is passed
  41.      * @param string 
  42.      * @param array 
  43.      * @param integer Restrict to specific post
  44.      * @param string Order ("ASC"/"DESC")
  45.      * @param string List of fields to order by (separated by " ")
  46.      * @param integer Limit
  47.      */
  48.     function CommentList(
  49.         $Blog,
  50.         $comment_types "'comment'",
  51.         $show_statuses array'published' ),    // Restrict to these statuses
  52.         $p '',                                                            // Restrict to specific post
  53.         $author '',                                                    // Not used yet
  54.         $order 'DESC',                                            // ASC or DESC
  55.         $orderby '',                                                // list of fields to order by
  56.         $limit ''                                                     // # of comments to display on the page
  57.         )
  58.     {
  59.         global $DB;
  60.  
  61.         // Call parent constructor:
  62.         parent::DataObjectList'T_comments''comment_''comment_ID''Item'NULL$limit );
  63.  
  64.         $this->sql = 'SELECT DISTINCT T_comments.*
  65.                                     FROM T_comments INNER JOIN T_items__item ON comment_post_ID = post_ID ';
  66.  
  67.         if!empty$p ) )
  68.         {    // Restrict to comments on selected post
  69.             $this->sql .= 'WHERE comment_post_ID = '.$p;
  70.         }
  71.         else
  72.         {
  73.             $this->sql .= 'INNER JOIN T_postcats ON post_ID = postcat_post_ID
  74.                                         INNER JOIN T_categories othercats ON postcat_cat_ID = othercats.cat_ID ';
  75.  
  76.             $this->sql .= 'WHERE '.$Blog->get_sql_where_aggregate_coll_IDs('othercats.cat_blog_ID');
  77.         }
  78.  
  79.         $this->sql .= ' AND comment_type IN ('.$comment_types.') ';
  80.  
  81.         /*
  82.          * ----------------------------------------------------
  83.          *  Restrict to the statuses we want to show:
  84.          * ----------------------------------------------------
  85.          */
  86.         ifempty$show_statuses ) )
  87.         {
  88.             $this->sql .= ' AND comment_status IN (\''.implode"', '"$show_statuses ).'\')';
  89.         }
  90.  
  91.         // This one restricts to post statuses, but it doesn't work completely right:
  92.         // TODO: handle status dependencies with post
  93.         $this->sql .= ' AND '.statuses_where_clause();
  94.  
  95.  
  96.         // order by stuff
  97.         if( (!empty($order)) && !in_arraystrtoupper($order)array'ASC''DESC''RAND' ) ) )
  98.         {
  99.             $order='DESC';
  100.         }
  101.  
  102.         if(empty($orderby))
  103.         {
  104.             $orderby 'comment_date '.$order.', comment_ID '.$order;
  105.         }
  106.         else
  107.         {
  108.             $orderby_array explode(' ',$orderby);
  109.             $orderby $orderby_array[0].' '.$order;
  110.             if (count($orderby_array)>1)
  111.             {
  112.                 for($i 1$i (count($orderby_array))$i++)
  113.                 {
  114.                     $orderby .= ', comment_'.$orderby_array[$i].' '.$order;
  115.                 }
  116.             }
  117.         }
  118.  
  119.         if$order == 'RAND' $orderby 'RAND()';
  120.  
  121.         $this->sql .= "ORDER BY $orderby";
  122.         if!empty$this->limit ) )
  123.         {
  124.             $this->sql .= ' LIMIT '.$this->limit;
  125.         }
  126.  
  127.         $this->rows $DB->get_results$this->sqlARRAY_A );
  128.  
  129.         // Prebuild and cache objects:
  130.         if$this->result_num_rows $DB->num_rows )
  131.         {    // fplanque>> why this test??
  132.  
  133.             $i 0;
  134.             foreach$this->rows as $row )
  135.             {
  136.                 // Prebuild object:
  137.                 $this->Obj[$inew Comment$row )// COPY (function)
  138.  
  139.                 // To avoid potential future waste, cache this object:
  140.                 // $this->DataObjectCache->add( $this->Obj[$i] );
  141.  
  142.                 $i++;
  143.             }
  144.         }
  145.     }
  146.  
  147.  
  148.     /**
  149.      * T-Tag: Display a message if CommentList is empty
  150.      *
  151.      * <code>
  152.      * $params = array_merge( array(
  153.      *   'msg_empty' => T_('No comment yet...'),
  154.      * ), $params );
  155.      * </code>
  156.      *
  157.      * @uses Results::display_if_empty()
  158.      */
  159.     function display_if_empty$params array() )
  160.     {
  161.         // Make sure we are not missing any param:
  162.         $params array_mergearray(
  163.                 'msg_empty' => T_('No comment yet...'),
  164.             )$params );
  165.  
  166.         return parent::display_if_empty$params );
  167.     }
  168.  
  169. }
  170.  
  171. ?>