dokeos
[ class tree: dokeos ] [ index: dokeos ] [ all elements ]

Source for file flatviewtable.class.php

Documentation is available at flatviewtable.class.php

  1. <?php
  2.  
  3. include_once (dirname(__FILE__).'/../../../inc/global.inc.php');
  4. include_once (dirname(__FILE__).'/../be.inc.php');
  5.  
  6. define ('LIMIT',10);
  7.  
  8. /**
  9.  * Table to display flat view (all evaluations and links for all students)
  10.  * @author Stijn Konings
  11.  * @author Bert Stepp� (refactored, optimised)
  12.  */
  13. class FlatViewTable extends SortableTable
  14. {
  15.  
  16.     private $selectcat;
  17.     private $datagen;
  18.     private $limit_enabled;
  19.     private $offset;
  20.  
  21.     
  22.     /**
  23.      * Constructor
  24.      */
  25.     function FlatViewTable ($selectcat$usersarray ()$evalsarray ()$linksarray ()$limit_enabled false$offset 0$addparams null)
  26.     {
  27.         parent :: SortableTable ('flatviewlist'nullnull0);
  28.  
  29.         $this->datagen = new FlatViewDataGenerator($users$evals$links);
  30.  
  31.         $this->selectcat = $selectcat;
  32.         $this->limit_enabled = $limit_enabled;
  33.         $this->offset = $offset;
  34.         
  35.         if (isset ($addparams))
  36.             $this->set_additional_parameters($addparams);
  37.     }
  38.  
  39.     /**
  40.      * Function used by SortableTable to get total number of items in the table
  41.      */
  42.     function get_total_number_of_items()
  43.     {
  44.         return $this->datagen->get_total_users_count();
  45.     }
  46.  
  47.     /** 
  48.      * Function used by SortableTable to generate the data to display
  49.      */
  50.     function get_table_data($from 1)
  51.     {
  52.  
  53.         // create page navigation if needed
  54.  
  55.         $totalitems $this->datagen->get_total_items_count();
  56.         if ($this->limit_enabled && $totalitems LIMIT)
  57.             $selectlimit LIMIT;
  58.         else
  59.             $selectlimit $totalitems;
  60.         
  61.         if ($this->limit_enabled && $totalitems LIMIT)
  62.         {
  63.               $calcprevious LIMIT;
  64.             $header .= '<div class="normal-message">'
  65.                         .'<table style="width: 100%; text-align: left; margin-left: auto; margin-right: auto;" border="0" cellpadding="2">'
  66.                         .'<tbody>'
  67.                         .'<tr>';
  68.  
  69.             // previous X
  70.               $header .= '<td style="width:40%;">';
  71.               if ($this->offset >= LIMIT)
  72.               {
  73.                   $header .= '<a href="'.api_get_self()
  74.                                       .'?selectcat='.Security::remove_XSS($_GET['selectcat'])
  75.                                       .'&offset='.(($this->offset)-LIMIT)
  76.                                     .(isset($_GET['search'])?'&search='.Security::remove_XSS($_GET['search']):'').'">'
  77.                               .'<img src="../img/lp_leftarrow.gif" alt="'.get_lang('Previous').'/" />'
  78.                               .get_lang('Previous').' '.$calcprevious ' ' get_lang('Evaluations')
  79.                               .'</a>';
  80.               }
  81.               else
  82.                   $header .= '<img src="../img/lp_leftarrow.gif" alt="'.get_lang('Previous').' ' get_lang('Evaluations').'/" />'.get_lang('Previous').' ' get_lang('Evaluations');
  83.               $header .= '</td>';
  84.  
  85.               // 'glue'
  86.               $header .= '<td style="width:20%;"></td>';
  87.  
  88.             // next X
  89.               $calcnext (($this->offset+(2*LIMIT)) $totalitems?
  90.                               ($totalitems-(LIMIT+$this->offset)) LIMIT;
  91.               $header .= '<td style="text-align: right; width: 40%;">';
  92.               if ($calcnext 0)
  93.               {
  94.                   $header .= '<a href="'.api_get_self()
  95.                                       .'?selectcat='.Security::remove_XSS($_GET['selectcat'])
  96.                                       .'&offset='.($this->offset+LIMIT)
  97.                                       .(isset($_GET['search'])?'&search='.Security::remove_XSS($_GET['search']):'').'">'
  98.                               .get_lang('Next').' '.$calcnext ' '.get_lang('Evaluations')
  99.                               .'<img src="../img/lp_rightarrow.gif" alt="'.get_lang('Next').'/" />'
  100.                               .'</a>';
  101.               }
  102.               else
  103.               {
  104.                   $header .= get_lang('Next').' '.get_lang('Evaluations').'<img src="../img/lp_rightarrow.gif" alt="'.get_lang('Next').'/" />';
  105.                           
  106.               }
  107.               $header .= '</td>';
  108.               $header .= '</tr></tbody></table></div>';
  109.             echo $header;
  110.         }
  111.  
  112.  
  113.         // retrieve sorting type
  114.         $users_sorting ($this->column == FlatViewDataGenerator :: FVDG_SORT_LASTNAME
  115.                                              : FlatViewDataGenerator :: FVDG_SORT_FIRSTNAME);
  116.         if ($this->direction == 'DESC')
  117.             $users_sorting |= FlatViewDataGenerator :: FVDG_SORT_DESC;
  118.         else
  119.             $users_sorting |= FlatViewDataGenerator :: FVDG_SORT_ASC;
  120.  
  121.  
  122.  
  123.         // step 1: generate columns: evaluations and links
  124.  
  125.         $header_names $this->datagen->get_header_names($this->offset$selectlimit);
  126.  
  127.         $column 0;
  128.         $this->set_header($column++$header_names[0]);
  129.         $this->set_header($column++$header_names[1]);
  130.  
  131.         while ($column count($header_names))
  132.         {
  133.             $this->set_header($column$header_names[$column]false);
  134.             $column++;
  135.         }
  136.  
  137.  
  138.         // step 2: generate rows: students
  139.         
  140.         $data_array $this->datagen->get_data($users_sorting,
  141.                                          $from$this->per_page,
  142.                                          $this->offset$selectlimit);
  143.  
  144.         $table_data array();
  145.         foreach ($data_array as $user_row)
  146.         {
  147.             $table_row array ();
  148.             $count 0;
  149.             $table_row[]$this->build_name_link($user_row[$count++]$user_row[$count++]);
  150.             $table_row[]$user_row[$count++];
  151.             while ($count count($user_row))
  152.                 $table_row[$user_row[$count++];
  153.             $table_data[]$table_row;
  154.         }
  155.         return $table_data;
  156.     }
  157.  
  158.  
  159.  
  160.  
  161.     // Other functions
  162.  
  163.     private function build_name_link ($user_id$lastname)
  164.     {
  165.         return '<a href="user_stats.php?userid='.$user_id.'&selectcat='.$this->selectcat->get_id().'">'.$lastname.'</a>';
  166.     }
  167.  
  168.     
  169. }
  170. ?>

Documentation generated on Thu, 12 Jun 2008 13:30:02 -0500 by phpDocumentor 1.4.1