Source for file anchortablelist.php

Documentation is available at anchortablelist.php

  1. <?php
  2. /**
  3. * Anchor list similar to AnchorList, but this time in a table not dot points
  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. *  path (bumblebee root)/inc/formslib/anchortablelist.php
  13. */
  14.  
  15. /** Load ancillary functions */
  16. require_once 'inc/typeinfo.php';
  17.  
  18. /** anchorlist parent object */
  19. require_once 'anchorlist.php';
  20. require_once 'bbstring.php';
  21.  
  22. /**
  23. * Anchor list similar to AnchorList, but this time in a table not dot points
  24. *
  25. @package    Bumblebee
  26. @subpackage FormsLibrary
  27. *
  28. */
  29. class AnchorTableList extends AnchorList {
  30.     /** @var integer  number of columns in the table*/
  31.     var $numcols    = '';
  32.     /** @var string   html/css class for the header row of the table */
  33.     var $headerRowClass = 'tableHeader';
  34.     /** @var string   html/css class for each row in the table  */
  35.     var $trclass    = 'itemrow';
  36.     /** @var string   html/css class for left-side table cell */
  37.     var $tdlclass   = 'itemL';
  38.     /** @var string   html/css class for right-side table cell */
  39.     var $tdrclass   = 'itemR';
  40.     /** @var string   html/css class for anchors */
  41.     var $aclass     = 'itemR';
  42.     /** @var string   html/css class for entire table */
  43.     var $tableclass = 'selectlist';
  44.     /** @var array    list of table headings to be put at the top of the table */
  45.     var $tableHeading;
  46.     /** @var boolean  make all columns in the table link to the target URL not just the first */
  47.     var $linkAll = true;
  48.     /** @var boolean  controls the generation of header links to sort the table by */
  49.     var $useSortByHeadings = false;
  50.     /** @var string   tells which header to sort by. null for default. This value will be
  51.      *  superseeded by the sortby paramater in connectDB */
  52.     var $defaultSortByHeading = 'name';
  53.     /** @var array    data source from which the column to sort by will be read */
  54.     var $data = null;
  55.     /** @var string   key in $data in which the column name should be stored */
  56.     var $sortbyKey;
  57.  
  58.     /**
  59.     *  Create a new AnchorTableList
  60.     *
  61.     * @param string $name   the name of the field (db name, and html field name
  62.     * @param string $description  used in the html title of the list
  63.     * @param integer $numcols (optional) number of columns in the table
  64.     */
  65.     function AnchorTableList($name$description=''$numcols=2{
  66.       $this->AnchorList($name$description);
  67.       $this->numcols = $numcols;
  68.       $this->sortbyKey = $this->name.'_sortby';
  69.     //end function AnchorTableList
  70.  
  71.     
  72.     /**
  73.     *  Accessor method to set the table column headings
  74.     *
  75.     * @param array   new headings to use for the table
  76.     */
  77.     function setTableHeadings($headings{
  78.  
  79.       $this->tableHeadings $headings;
  80.  
  81.     //end function setTableHeadings
  82.  
  83.     
  84.     /**
  85.      * Sets which heading to sort by
  86.      *
  87.      * @param boolean turn the sort by links on and off
  88.      * @param array   data source to find which heading to sort by
  89.      * @param string  (optional) the default heading to sort by
  90.      *
  91.      */
  92.     function sortByHeadings($sort$data$heading 'name'{
  93.       $this->useSortByHeadings = $sort;
  94.       $this->data = $data;
  95.       $this->defaultSortByHeading = $heading;
  96.     //end function sortByHeadings
  97.  
  98.     
  99.     function format($data{
  100.       //preDump($this);
  101.       $aclass  (isset($this->aclass" class='$this->aclass''');
  102.       $trclass  (isset($this->trclass" class='$this->trclass''');
  103.       $tdlclass  (isset($this->tdlclass" class='$this->tdlclass''');
  104.       $tdrclass  (isset($this->tdrclass" class='$this->tdrclass''');
  105.       $linkformat "<a href='".str_replace('__id__'$data[$this->formatid]$this->hrefbase)."'$aclass>"
  106.           ."%s</a>";
  107.       $t  "<tr $trclass>"
  108.           ."<td $tdlclass>";
  109.       $t .= sprintf($linkformat$this->formatter[0]->format($data));
  110.       $t .= "</td>\n";
  111.  
  112.       for ($i=2$i<=$this->numcols$i++{
  113.  
  114.         $t .= "<td $tdrclass>";
  115.  
  116.         if ($this->linkAll{
  117.             $t .= sprintf($linkformat$this->formatter[$i-1]->format($data));
  118.         else {
  119.             $t .= $this->formatter[$i-1]->format($data);
  120.         //end if-else
  121.  
  122.           $t .= "</td>";
  123.       //end for
  124.  
  125.       $t .= "</tr>\n";
  126.       return $t;
  127.     //end function format
  128.  
  129.     
  130.     function display({
  131.       $tableclass (isset($this->tableclass" class='$this->tableclass''');
  132.       $t  "<table title='$this->description$tableclass>\n";
  133.  
  134.       if (isset($this->tableHeadings)) {
  135.  
  136.         $t .= "<tr class='{$this->headerRowClass}'>";
  137.  
  138.         if(! $this->useSortByHeadings{
  139.           foreach ($this->tableHeadings as $heading{
  140.  
  141.             if(type_is_a($heading, 'bbString')) {
  142.                 $t .='<th>'.$heading->getExternalRep().'</th>';
  143.  
  144.             } else {
  145.                 $t .= "<th>$heading</th>";
  146.             } //end if-else
  147.           } //end foreach
  148.         } else {
  149.  
  150.           $aclass = (isset($this->aclass" class='{$this->aclass}'" : '');
  151.  
  152.           foreach($this->tableHeadings as $heading{
  153.             $text   = type_is_a($heading, 'bbString')
  154.                                         ? $heading->getExternalRep($heading;
  155.             $sortby type_is_a($heading'bbString')
  156.                                         ? $heading->getInternalRep($heading;
  157.             $href str_replace('__sortby__'$sortby$this->sortByHref);
  158.  
  159.             $t .=  "<th><a href='".$href."$aclass title='".T_('Sort by this column')."'>".$text.'</a></th>';
  160.           } //end foreach
  161.         } //end if-else
  162.         $t .= "</tr>\n";
  163.       } //end if
  164.       if (is_array($this->list->choicelist)) {
  165.         foreach ($this->list->choicelist as $v{
  166.           $t .= $this->format($v);
  167.         } //end foreach
  168.       } //end if
  169.       $t .= "</table>\n";
  170.       return $t;
  171.     } //end function display()
  172.     /**
  173.     *  overloading of ChoiceList's connectDB to allow for remembering the
  174.     *     sortby column
  175.     */
  176.     function connectDB($table, $fields = '', $restriction = '', $order = 'name',
  177.             $idfield = 'id', $limit = '', $join = '', $distinct = false) {
  178.  
  179.       if ($this->useSortByHeadings{
  180.         $order = q(issetSet($this->data$this->sortbyKey$this->defaultSortByHeading));
  181.       }
  182.       parent::connectDB($table, $fields, $restriction, $order, $idfield, $limit,
  183.                     $join, $distinct);
  184.  
  185.     } //end function connectDB
  186. } // class AnchorList

Documentation generated on Tue, 06 Mar 2007 10:00:32 +0000 by phpDocumentor 1.3.0