b2evolution

Multilingual multiuser multiblog engine

b2evolution Technical Documentation (CVS HEAD) [ class tree: evocore ] [ index: evocore ] [ all elements ]

Source for file _dataobjectlist2.class.php

Documentation is available at _dataobjectlist2.class.php

  1. <?php
  2. /**
  3.  * This file implements the abstract DataObjectList2 base class.
  4.  *
  5.  * This file is part of the evoCore framework - {@link http://evocore.net/}
  6.  * See also {@link http://sourceforge.net/projects/evocms/}.
  7.  *
  8.  * @copyright (c)2003-2010 by Francois PLANQUE - {@link http://fplanque.net/}
  9.  *
  10.  *  {@internal License choice
  11.  *  - If you have received this file as part of a package, please find the license.txt file in
  12.  *    the same folder or the closest folder above for complete license terms.
  13.  *  - If you have received this file individually (e-g: from http://evocms.cvs.sourceforge.net/)
  14.  *    then you must choose one of the following licenses before using the file:
  15.  *    - GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php
  16.  *    - Mozilla Public License 1.1 (MPL) - http://www.opensource.org/licenses/mozilla1.1.php
  17.  *  }}}
  18.  *
  19.  *  {@internal Open Source relicensing agreement:
  20.  *  }}}
  21.  *
  22.  * @package evocore
  23.  *
  24.  *  {@internal Below is a list of authors who have contributed to design/coding of this file: }}
  25.  * @author fplanque: Francois PLANQUE
  26.  *
  27.  * @version $Id: _dataobjectlist2.class.php,v 1.14 2010/02/08 17:51:50 efy-yury Exp $
  28.  */
  29. if!defined('EVO_MAIN_INIT') ) die'Please, do not access this page directly.' );
  30.  
  31. load_class('_core/ui/results/_results.class.php''Results' );
  32.  
  33.  
  34. /**
  35.  * @package evocore
  36.  */
  37. class FilteredResults extends Results
  38. {
  39.     /**
  40.      * Default filter set (used if no specific params are passed)
  41.      */
  42.     var $default_filters = array();
  43.  
  44.     /**
  45.      * Current filter set (depending on user input)
  46.      */
  47.     var $filters = array();
  48.  
  49.  
  50.     /**
  51.      * Check if the Result set is filtered or not
  52.      */
  53.     function is_filtered()
  54.     {
  55.         ifempty$this->filters ) )
  56.         {
  57.             return false;
  58.         }
  59.  
  60.         return $this->filters != $this->default_filters );
  61.     }
  62.  
  63.  
  64.     /**
  65.      * Get a specific active filter
  66.      */
  67.     function get_active_filter$key )
  68.     {
  69.         ifisset($this->filters[$key]) )
  70.         {
  71.             return $this->filters[$key];
  72.         }
  73.  
  74.         return NULL;
  75.     }
  76.  
  77.  
  78.     /**
  79.      * Get every active filter that is not the same as the defaults
  80.      */
  81.     function get_active_filters()
  82.     {
  83.         $r array();
  84.  
  85.         foreach$this->default_filters as $key => $value )
  86.         {
  87.             if!isset$this->filters[$key) )
  88.             {    // Some value has not been copied over from defaults to active or specifically set:
  89.                 if!is_null($value)) // Note: NULL value are not copied over. that's normal.
  90.                 {    // A NON NULL value is missing
  91.                     $r[$key;
  92.                 }
  93.             }
  94.             elseif$value != $this->filters[$key)
  95.             {
  96.                 $r[$key;
  97.             }
  98.         }
  99.         return $r;
  100.     }
  101.  
  102.  
  103.     /**
  104.      * Show every active filter that is not the same as the defaults
  105.      */
  106.     function dump_active_filters()
  107.     {
  108.         foreach$this->default_filters as $key => $value )
  109.         {
  110.             if!isset$this->filters[$key) )
  111.             {    // SOme value has not been copied over from defaults to active or specifically set:
  112.                 if!is_null($value)) // Note: NULL value ar enot copied over. that's normal.
  113.                 {    // A NON NULL value is missing
  114.                     pre_dump'no active value for default '.$key );
  115.                 }
  116.             }
  117.             elseif$value != $this->filters[$key)
  118.             {
  119.                 pre_dump'default '.$key$value );
  120.                 pre_dump'active '.$key$this->filters[$key);
  121.             }
  122.         }
  123.     }
  124. }
  125.  
  126.  
  127.  
  128. /**
  129.  * Data Object List Base Class 2
  130.  *
  131.  * This is typically an abstract class, useful only when derived.
  132.  * Holds DataObjects in an array and allows walking through...
  133.  *
  134.  * This SECOND implementation will deprecate the first one when finished.
  135.  *
  136.  * @package evocore
  137.  * @version beta
  138.  * @abstract
  139.  */
  140. {
  141.  
  142.  
  143.     /**
  144.      * Constructor
  145.      *
  146.      * If provided, executes SQL query via parent Results object
  147.      *
  148.      * @param DataObjectCache 
  149.      * @param integer number of lines displayed on one screen (null for default [20])
  150.      * @param string prefix to differentiate page/order params when multiple Results appear on same page
  151.      * @param string default ordering of columns (special syntax)
  152.      */
  153.     function DataObjectList2$Cache$limit null$param_prefix ''$default_order NULL )
  154.     {
  155.         // WARNING: we are not passing any SQL query to the Results object
  156.         // This will make the Results object behave a little bit differently than usual:
  157.         parent::ResultsNULL$param_prefix$default_order$limitNULLfalse );
  158.  
  159.         // The list objects will also be cached in this cache.
  160.         // The Cache object may also be useful to get table information for the Items.
  161.         $this->Cache = $Cache;
  162.  
  163.         // Colum used for IDs
  164.         $this->ID_col = $Cache->dbIDname;
  165.     }
  166.  
  167.  
  168.     function get_row_by_idx$idx )
  169.     {
  170.         return $this->rows$idx ];
  171.     }
  172.  
  173.  
  174.     /**
  175.      * Instantiate an object for requested row and cache it:
  176.      */
  177.     function get_by_idx$idx )
  178.     {
  179.         return $this->Cache->instantiate$this->rows[$idx)// pass by reference: creates $rows[$idx]!
  180.     }
  181.  
  182.  
  183.     /**
  184.      * Get next object in list
  185.      */
  186.     function get_next()
  187.     {
  188.         // echo '<br />Get next, current idx was: '.$this->current_idx.'/'.$this->result_num_rows;
  189.  
  190.         if$this->current_idx >= $this->result_num_rows )
  191.         {    // No more object in list
  192.             $this->current_Obj = NULL;
  193.             $r false// TODO: try with NULL
  194.             return $r;
  195.         }
  196.  
  197.         // We also keep a local ref in case we want to use it for display:
  198.         $this->current_Obj = $this->get_by_idx$this->current_idx );
  199.         $this->next_idx();
  200.  
  201.         return $this->current_Obj;
  202.     }
  203.  
  204.  
  205.     /**
  206.      * Display a global title matching filter params
  207.      *
  208.      * @todo implement $order
  209.      *
  210.      * @param string prefix to display if a title is generated
  211.      * @param string suffix to display if a title is generated
  212.      * @param string glue to use if multiple title elements are generated
  213.      * @param string comma separated list of titles inthe order we would like to display them
  214.      * @param string format to output, default 'htmlbody'
  215.      */
  216.     function get_filter_title$prefix ' '$suffix ''$glue ' - '$order NULL$format 'htmlbody' )
  217.     {
  218.         $title_array $this->get_filter_titles();
  219.  
  220.         ifempty$title_array ) )
  221.         {
  222.             return '';
  223.         }
  224.  
  225.         // We have something to display:
  226.         $r implode$glue$title_array );
  227.         $r $prefix.format_to_output$r$format ).$suffix;
  228.         return $r;
  229.     }
  230.  
  231.  
  232.     /**
  233.      * Move up the element order in database
  234.      *
  235.      * @param integer id element
  236.      * @return unknown 
  237.      */
  238.     function move_up$id )
  239.     {
  240.         global $DB$Messages$result_fadeout;
  241.  
  242.         $DB->begin();
  243.  
  244.         if( ($obj $this->Cache->get_by_ID$id )) === false )
  245.         {
  246.             $Messages->addsprintfT_('Requested &laquo;%s&raquo; object does not exist any longer.')T_('Entry') )'error' );
  247.             $DB->commit();
  248.             return false;
  249.         }
  250.         $order $obj->order;
  251.  
  252.         // Get the ID of the inferior element which his order is the nearest
  253.         $rows $DB->get_results'SELECT '.$this->Cache->dbIDname
  254.                  .' FROM '.$this->Cache->dbtablename
  255.                 .' WHERE '.$this->Cache->dbprefix.'order < '.$order
  256.                 .' ORDER BY '.$this->Cache->dbprefix.'order DESC'
  257.                 .' LIMIT 0,1' );
  258.  
  259.         ifcount$rows ) )
  260.         {
  261.             // instantiate the inferior element
  262.             $obj_inf $this->Cache->get_by_ID$rows[0]->{$this->Cache->dbIDname);
  263.  
  264.             //  Update element order
  265.             $obj->set'order'$obj_inf->order );
  266.             $obj->dbupdate();
  267.  
  268.             // Update inferior element order
  269.             $obj_inf->set'order'$order );
  270.             $obj_inf->dbupdate();
  271.  
  272.             // EXPERIMENTAL FOR FADEOUT RESULT
  273.             $result_fadeout[$this->Cache->dbIDname][$id;
  274.             $result_fadeout[$this->Cache->dbIDname][$obj_inf->ID;
  275.         }
  276.         else
  277.         {
  278.             $Messages->addT_('This element is already at the top.')'error' );
  279.         }
  280.         $DB->commit();
  281.     }
  282.  
  283.  
  284.     /**
  285.      * Move down the element order in database
  286.      *
  287.      * @param integer id element
  288.      * @return unknown 
  289.      */
  290.     function move_down$id )
  291.     {
  292.         global $DB$Messages$result_fadeout;
  293.  
  294.         $DB->begin();
  295.  
  296.         if( ($obj $this->Cache->get_by_ID$id )) === false )
  297.         {
  298.             $Messages->addsprintfT_('Requested &laquo;%s&raquo; object does not exist any longer.')T_('Entry') )'error' );
  299.             $DB->commit();
  300.             return false;
  301.         }
  302.         $order $obj->order;
  303.  
  304.         // Get the ID of the inferior element which his order is the nearest
  305.         $rows $DB->get_results'SELECT '.$this->Cache->dbIDname
  306.                                                              .' FROM '.$this->Cache->dbtablename
  307.                                                          .' WHERE '.$this->Cache->dbprefix.'order > '.$order
  308.                                                     .' ORDER BY '.$this->Cache->dbprefix.'order ASC
  309.                                                                  LIMIT 0,1' );
  310.  
  311.         ifcount$rows ) )
  312.         {
  313.             // instantiate the inferior element
  314.             $obj_sup $this->Cache->get_by_ID$rows[0]->{$this->Cache->dbIDname);
  315.  
  316.             //  Update element order
  317.             $obj->set'order'$obj_sup->order );
  318.             $obj->dbupdate();
  319.  
  320.             // Update inferior element order
  321.             $obj_sup->set'order'$order );
  322.             $obj_sup->dbupdate();
  323.  
  324.             // EXPERIMENTAL FOR FADEOUT RESULT
  325.             $result_fadeout[$this->Cache->dbIDname][$id;
  326.             $result_fadeout[$this->Cache->dbIDname][$obj_sup->ID;
  327.         }
  328.         else
  329.         {
  330.             $Messages->addT_('This element is already at the bottom.')'error' );
  331.         }
  332.         $DB->commit();
  333.     }
  334. }
  335.  
  336. /*
  337.  * $Log: _dataobjectlist2.class.php,v $
  338.  * Revision 1.14  2010/02/08 17:51:50  efy-yury
  339.  * copyright 2009 -> 2010
  340.  *
  341.  * Revision 1.13  2009/12/01 20:58:27  blueyed
  342.  * doc, indent
  343.  *
  344.  * Revision 1.12  2009/11/30 22:56:09  blueyed
  345.  * typo
  346.  *
  347.  * Revision 1.11  2009/09/14 10:38:23  efy-arrin
  348.  * Include the ClassName in the load_class() with proper UpperCase
  349.  *
  350.  * Revision 1.10  2009/08/30 19:54:25  fplanque
  351.  * less translation messgaes for infrequent errors
  352.  *
  353.  * Revision 1.9  2009/08/30 00:30:52  fplanque
  354.  * increased modularity
  355.  *
  356.  * Revision 1.8  2009/03/08 23:57:40  fplanque
  357.  * 2009
  358.  *
  359.  * Revision 1.7  2009/02/26 22:16:54  blueyed
  360.  * Use load_class for classes (.class.php), and load_funcs for funcs (.funcs.php)
  361.  *
  362.  * Revision 1.6  2008/01/21 09:35:24  fplanque
  363.  * (c) 2008
  364.  *
  365.  * Revision 1.5  2007/11/25 19:47:15  fplanque
  366.  * cleaned up photo/media index a little bit
  367.  *
  368.  * Revision 1.4  2007/11/25 14:28:17  fplanque
  369.  * additional SEO settings
  370.  *
  371.  * Revision 1.3  2007/09/28 09:28:36  fplanque
  372.  * per blog advanced SEO settings
  373.  *
  374.  * Revision 1.2  2007/09/23 18:57:15  fplanque
  375.  * filter handling fixes
  376.  *
  377.  * Revision 1.1  2007/06/25 10:58:57  fplanque
  378.  * MODULES (refactored MVC)
  379.  *
  380.  * Revision 1.10  2007/06/11 22:01:52  blueyed
  381.  * doc fixes
  382.  *
  383.  * Revision 1.9  2007/05/26 22:21:32  blueyed
  384.  * Made $limit for Results configurable per user
  385.  *
  386.  * Revision 1.8  2007/04/26 00:11:09  fplanque
  387.  * (c) 2007
  388.  *
  389.  * Revision 1.7  2006/11/24 18:27:24  blueyed
  390.  * Fixed link to b2evo CVS browsing interface in file docblocks
  391.  */
  392. ?>

Documentation generated on Sat, 06 Mar 2010 04:07:58 +0100 by phpDocumentor 1.4.2. This site is hosted and maintained by Daniel HAHLER (Contact).