Source for file exampleentries.php

Documentation is available at exampleentries.php

  1. <?php
  2. /**
  3. * Provide example entries for existing values next to the choices in a list, e.g. radio list
  4. *
  5. @author    Stuart Prescott
  6. @copyright  Copyright Stuart Prescott
  7. @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  8. @version    $Id$
  9. @package    Bumblebee
  10. @subpackage FormsLibrary
  11. */
  12.  
  13. /** Load ancillary functions */
  14. require_once 'inc/typeinfo.php';
  15.  
  16. /** uses choice list object for examples */
  17. require_once 'dbchoicelist.php';
  18. /** sql manipulation routines */
  19. require_once 'sql.php';
  20.  
  21. /**
  22. * Provide example entries for existing values next to the choices in a list, e.g. radio list
  23. *
  24. @package    Bumblebee
  25. @subpackage FormsLibrary
  26. */
  27. class ExampleEntries {
  28.   /** @var string   field in the supplied data array supplied to format that should be used for looking up examples */
  29.   var $source;
  30.   /** @var string   table from which to take examples (SQL FROM $table) */
  31.   var $table;
  32.   /** @var string   column in the table that has to match the supplied data  (SQL: WHERE $columnmatch=$data[$source]) */
  33.   var $columnmatch;
  34.   /** @var string   column in the table to return for matched data (SQL: SELECT $columnreturn) */
  35.   var $columnreturn;
  36.   /** @var integer  number of entries to return in the list (SQL: LIMIT) */
  37.   var $limit;
  38.   /** @var string   order for in which entries should be returned (SQL: ORDER BY $order) */
  39.   var $order;
  40.   /** @var string   delimeter between example entries returned */
  41.   var $separator = ', ';
  42.   /** @var DBChoiceList  object that obtains the data from the db */
  43.   var $list;
  44.  
  45.   /**
  46.   * Create a new ExampleEntries object
  47.   *
  48.   * @param string $source   see $this->source
  49.   * @param string $table    see $this->table
  50.   * @param string $columnmatch see $this->columnmatch
  51.   * @param string $columnreturn see $this->columnreturn
  52.   * @param string $maxentries (optional, default 3 entries) see $this->limit
  53.   * @param string $order      (optional, use $columnreturn by default) see $this->order
  54.   */
  55.   function ExampleEntries($source$table$columnmatch$columnreturn,
  56.                           $maxentries=3$order=''{
  57.     $this->source = $source;
  58.     $this->table = $table;
  59.     $this->columnmatch = $columnmatch;
  60.     $this->columnreturn = $columnreturn;
  61.     $this->limit = $maxentries;
  62.     $this->order = ($order != '' $order $columnreturn);
  63.   }
  64.  
  65.   /**
  66.   * Obtain the example entries from the db
  67.   *
  68.   * @param string $id   the id number (or string) to match
  69.   */
  70.   function fill($id{
  71.     #echo "Filling for $id";
  72.     $ids join(','array_qw(explode(','$id)));
  73.     $this->list = new DBChoiceList($this->table$this->columnreturn,
  74.                              "{$this->columnmatchIN ($ids)",
  75.                              $this->order,
  76.                              $this->columnmatch$this->limit);
  77.   }
  78.  
  79.   /**
  80.   * Obtain the example entries and format them as appropriate
  81.   *
  82.   * @param array  $data  $data[$this->source] contains the id for which we should find examples
  83.   * (passed by ref for efficiency only)
  84.   * @return string list of examples
  85.   */
  86.   function format(&$data) {
  87.     #var_dump($data);
  88.     $this->fill($data[$this->source]);
  89.     $entries array();
  90.     foreach ($this->list->choicelist as $v{
  91.       $entries[] = xssqw($v[$this->columnreturn]);
  92.     }
  93.     $t = implode($this->separator$entries);
  94.     return $t;
  95.   }
  96.  
  97. } // class ExampleEntries
  98.  

Documentation generated on Tue, 06 Mar 2007 10:01:24 +0000 by phpDocumentor 1.3.0