phpDocumentor pond
[ class tree: pond ] [ index: pond ] [ 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 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.  *
  11.  *  {@internal License choice
  12.  *  - If you have received this file as part of a package, please find the license.txt file in
  13.  *    the same folder or the closest folder above for complete license terms.
  14.  *  - If you have received this file individually (e-g: from http://evocms.cvs.sourceforge.net/)
  15.  *    then you must choose one of the following licenses before using the file:
  16.  *    - GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php
  17.  *    - Mozilla Public License 1.1 (MPL) - http://www.opensource.org/licenses/mozilla1.1.php
  18.  *  }}}
  19.  *
  20.  *  {@internal Open Source relicensing agreement:
  21.  *  }}}
  22.  *
  23.  *  {@internal Below is a list of authors who have contributed to design/coding of this file: }}
  24.  * @author fplanque: Francois PLANQUE
  25.  *
  26.  * @package pond
  27.  */
  28. if!defined('QP_MAIN_INIT') ) die'Please, do not access this page directly.' );
  29.  
  30. load_class('_core/ui/results/_results.class.php');
  31.  
  32.  
  33. /**
  34.  * FilteredResults > Results
  35.  *
  36.  * @package pond
  37.  */
  38. class FilteredResults extends Results
  39. {
  40.     /**
  41.      * Default filter set (used if no specific params are passed)
  42.      */
  43.     var $default_filters = array();
  44.  
  45.     /**
  46.      * Current filter set (depending on user input)
  47.      */
  48.     var $filters = array();
  49.  
  50.  
  51.     /**
  52.      * Check if the Result set is filtered or not
  53.      */
  54.     function is_filtered()
  55.     {
  56.         ifempty$this->filters ) )
  57.         {
  58.             return false;
  59.         }
  60.  
  61.         return $this->filters != $this->default_filters );
  62.     }
  63.  
  64.  
  65.     /**
  66.      * Get a specific active filter
  67.      */
  68.     function get_active_filter$key )
  69.     {
  70.         ifisset($this->filters[$key]) )
  71.         {
  72.             return $this->filters[$key];
  73.         }
  74.  
  75.         return NULL;
  76.     }
  77.  
  78.  
  79.   /**
  80.      * Get every active filter that is not the same as the defaults
  81.      */
  82.     function get_active_filters()
  83.     {
  84.         $r array();
  85.  
  86.         foreach$this->default_filters as $key => $value )
  87.         {
  88.             if!isset$this->filters[$key) )
  89.             {    // Some value has not been copied over from defaults to active or specifically set:
  90.                 if!is_null($value)) // Note: NULL value are not copied over. that's normal.
  91.                 {    // A NON NULL value is missing
  92.                     $r[$key;
  93.                 }
  94.             }
  95.             elseif$value != $this->filters[$key)
  96.             {
  97.                 $r[$key;
  98.             }
  99.         }
  100.         return $r;
  101.     }
  102.  
  103.  
  104.   /**
  105.      * Show every active filter that is not the same as the defaults
  106.      */
  107.     function dump_active_filters()
  108.     {
  109.         foreach$this->default_filters as $key => $value )
  110.         {
  111.             if!isset$this->filters[$key) )
  112.             {    // SOme value has not been copied over from defaults to active or specifically set:
  113.                 if!is_null($value)) // Note: NULL value ar enot copied over. that's normal.
  114.                 {    // A NON NULL value is missing
  115.                     pre_dump'no active value for default '.$key );
  116.                 }
  117.             }
  118.             elseif$value != $this->filters[$key)
  119.             {
  120.                 pre_dump'default '.$key$value );
  121.                 pre_dump'active '.$key$this->filters[$key);
  122.             }
  123.         }
  124.     }
  125. }
  126.  
  127.  
  128.  
  129. /**
  130.  * Data Object List Base Class 2
  131.  *
  132.  * This is typically an abstract class, useful only when derived.
  133.  * Holds DataObjects in an array and allows walking through...
  134.  *
  135.  * This SECOND implementation will deprecate the first one when finished.
  136.  *
  137.  * @version beta
  138.  * @abstract
  139.  *
  140.  * @package pond
  141.  */
  142. {
  143.  
  144.  
  145.     /**
  146.      * Constructor
  147.      *
  148.      * If provided, executes SQL query via parent Results object
  149.      *
  150.      * @param DataObjectCache 
  151.      * @param integer number of lines displayed on one screen (null for default [20])
  152.      * @param string prefix to differentiate page/order params when multiple Results appear one same page
  153.      * @param string default ordering of columns (special syntax)
  154.      */
  155.     function DataObjectList2$Cache$limit null$param_prefix ''$default_order NULL )
  156.     {
  157.         // WARNING: we are not passing any SQL query to the Results object
  158.         // This will make the Results object behave a little bit differently than usual:
  159.         parent::ResultsNULL$param_prefix$default_order$limitNULLfalse );
  160.  
  161.         // The list objects will also be cached in this cache.
  162.         // Tje Cache object may also be useful to get table information for the Items.
  163.         $this->Cache = $Cache;
  164.  
  165.         // Colum used for IDs
  166.         $this->ID_col = $Cache->dbIDname;
  167.     }
  168.  
  169.  
  170. /**
  171.  * dummy docblock makes error-free autodocs
  172.  */
  173.     function get_row_by_idx$idx )
  174.     {
  175.         return $this->rows$idx ];
  176.     }
  177.  
  178.  
  179.     /**
  180.      * Instantiate an object for requested row and cache it:
  181.      */
  182.     function get_by_idx$idx )
  183.     {
  184.         return $this->Cache->instantiate$this->rows[$idx);
  185.     }
  186.  
  187.  
  188.     /**
  189.      * Get next object in list
  190.      */
  191.     function get_next()
  192.     {
  193.         if$this->current_idx >= $this->result_num_rows )
  194.         {    // No more object in list
  195.             $this->current_Obj = NULL;
  196.             $r false// TODO: try with NULL
  197.             return $r;
  198.         }
  199.  
  200.         // We also keep a local ref in case we want to use it for display:
  201.         $this->current_Obj = $this->get_by_idx$this->current_idx );
  202.         $this->next_idx();
  203.  
  204.         return $this->current_Obj;
  205.     }
  206.  
  207.  
  208.     /**
  209.      * Display a global title matching filter params
  210.      *
  211.      * @todo implement $order
  212.      *
  213.      * @param string prefix to display if a title is generated
  214.      * @param string suffix to display if a title is generated
  215.      * @param string glue to use if multiple title elements are generated
  216.      * @param string comma separated list of titles inthe order we would like to display them
  217.      * @param string format to output, default 'htmlbody'
  218.      */
  219.     function get_filter_title$prefix ' '$suffix ''$glue ' - '$order NULL$format 'htmlbody' )
  220.     {
  221.         $title_array $this->get_filter_titles();
  222.  
  223.       ifempty$title_array ) )
  224.       {
  225.             return '';
  226.         }
  227.  
  228.         // We have something to display:
  229.         $r implode$glue$title_array );
  230.         $r $prefix.format_to_output$r$format ).$suffix;
  231.         return $r;
  232.     }
  233.  
  234.  
  235.     /**
  236.      * Move up the element order in database
  237.      *
  238.      * @param integer id element
  239.      * @return unknown 
  240.      */
  241.     function move_up$id )
  242.     {
  243.         global $DB$Messages$result_fadeout;
  244.  
  245.         $DB->begin();
  246.  
  247.         if( ($obj $this->Cache->get_by_ID$id )) === false )
  248.         {
  249.             $Messages->head T_('Cannot edit entry!');
  250.             $Messages->addT_('Requested entry does not exist any longer.')'error' );
  251.             $DB->commit();
  252.             return false;
  253.         }
  254.         $order $obj->order;
  255.  
  256.         // Get the ID of the inferior element which his order is the nearest
  257.         $rows $DB->get_results'SELECT '.$this->Cache->dbIDname
  258.                                                              .' FROM '.$this->Cache->dbtablename
  259.                                                          .' WHERE '.$this->Cache->dbprefix.'order < '.$order
  260.                                                     .' ORDER BY '.$this->Cache->dbprefix.'order DESC
  261.                                                                  LIMIT 0,1' );
  262.  
  263.         ifcount$rows ) )
  264.         {
  265.             // instantiate the inferior element
  266.             $obj_inf $this->Cache->get_by_ID$rows[0]->{$this->Cache->dbIDname);
  267.  
  268.             //  Update element order
  269.             $obj->set'order'$obj_inf->order );
  270.             $obj->dbupdate();
  271.  
  272.             // Update inferior element order
  273.             $obj_inf->set'order'$order );
  274.             $obj_inf->dbupdate();
  275.  
  276.             // EXPERIMENTAL FOR FADEOUT RESULT
  277.             $result_fadeout[$this->Cache->dbIDname][$id;
  278.             $result_fadeout[$this->Cache->dbIDname][$obj_inf->ID;
  279.         }
  280.         else
  281.         {
  282.             $Messages->addT_('This element is already at the top.')'error' );
  283.         }
  284.         $DB->commit();
  285.     }
  286.  
  287.  
  288.     /**
  289.      * Move down the element order in database
  290.      *
  291.      * @param integer id element
  292.      * @return unknown 
  293.      */
  294.     function move_down$id )
  295.     {
  296.         global $DB$Messages$result_fadeout;
  297.  
  298.         $DB->begin();
  299.  
  300.         if( ($obj $this->Cache->get_by_ID$id )) === false )
  301.         {
  302.             $Messages->head T_('Cannot edit entry!');
  303.             $Messages->addT_('Requested entry does not exist any longer.')'error' );
  304.             $DB->commit();
  305.             return false;
  306.         }
  307.         $order $obj->order;
  308.  
  309.         // Get the ID of the inferior element which his order is the nearest
  310.         $rows $DB->get_results'SELECT '.$this->Cache->dbIDname
  311.                                                              .' FROM '.$this->Cache->dbtablename
  312.                                                          .' WHERE '.$this->Cache->dbprefix.'order > '.$order
  313.                                                     .' ORDER BY '.$this->Cache->dbprefix.'order ASC
  314.                                                                  LIMIT 0,1' );
  315.  
  316.         ifcount$rows ) )
  317.         {
  318.             // instantiate the inferior element
  319.             $obj_sup $this->Cache->get_by_ID$rows[0]->{$this->Cache->dbIDname);
  320.  
  321.             //  Update element order
  322.             $obj->set'order'$obj_sup->order );
  323.             $obj->dbupdate();
  324.  
  325.             // Update inferior element order
  326.             $obj_sup->set'order'$order );
  327.             $obj_sup->dbupdate();
  328.  
  329.             // EXPERIMENTAL FOR FADEOUT RESULT
  330.             $result_fadeout[$this->Cache->dbIDname][$id;
  331.             $result_fadeout[$this->Cache->dbIDname][$obj_sup->ID;
  332.         }
  333.         else
  334.         {
  335.             $Messages->addT_('This element is already at the bottom.')'error' );
  336.         }
  337.         $DB->commit();
  338.     }
  339. }
  340.  
  341. ?>