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

Source for file flatview_data_generator.class.php

Documentation is available at flatview_data_generator.class.php

  1. <?php
  2.  
  3. /**
  4.  * Class to select, sort and transform object data into array data,
  5.  * used for the teacher's flat view
  6.  * @author Bert Steppé
  7.  */
  8. {
  9.  
  10.     // Sorting types constants
  11.     const FVDG_SORT_LASTNAME 1;
  12.     const FVDG_SORT_FIRSTNAME 2;
  13.     const FVDG_SORT_ASC 4;
  14.     const FVDG_SORT_DESC 8;
  15.  
  16.     private $users;
  17.     private $evals;
  18.     private $links;
  19.     private $evals_links;
  20.  
  21.     /**
  22.      * Constructor
  23.      */
  24.     public function FlatViewDataGenerator ($usersarray ()$evalsarray ()$linksarray ())
  25.     {
  26.         $this->users = (isset($users$users array());
  27.         $this->evals = (isset($evals$evals array());
  28.         $this->links = (isset($links$links array());
  29.         $this->evals_links = array_merge($this->evals$this->links);
  30.     }
  31.  
  32.  
  33.     /**
  34.      * Get total number of users (rows)
  35.      */
  36.     public function get_total_users_count()
  37.     {
  38.         return count($this->users);
  39.     }
  40.     
  41.     /**
  42.      * Get total number of evaluations/links (columns) (the 2 users columns not included)
  43.      */
  44.     public function get_total_items_count()
  45.     {
  46.         return count($this->evals_links);
  47.     }
  48.     
  49.  
  50.     /**
  51.      * Get array containing column header names (incl user columns)
  52.      */
  53.     public function get_header_names ($items_start 0$items_count null)
  54.     {
  55.         $headers array();
  56.         $headers[get_lang('LastName');
  57.         $headers[get_lang('FirstName');
  58.  
  59.         if (!isset($items_count))
  60.             $items_count count($this->evals_links$items_start;
  61.  
  62.         for ($count=0;
  63.              ($count $items_count && ($items_start $count count($this->evals_links));
  64.              $count++)
  65.         {
  66.             $item $this->evals_links [$count $items_start];
  67.             $headers[$item->get_name();
  68.         }
  69.         
  70.         return $headers;
  71.     }
  72.  
  73.  
  74.     /**
  75.      * Get actual array data
  76.      * @return array 2-dimensional array - each array contains the elements:
  77.      *  0: user id
  78.      *  1: user lastname
  79.      *  2: user firstname
  80.      *  3+: evaluation/link scores
  81.      */
  82.     public function get_data ($users_sorting 0,
  83.                               $users_start 0$users_count null
  84.                               $items_start 0$items_count null,
  85.                               $ignore_score_color false)
  86.     {
  87.  
  88.         // do some checks on users/items counts, redefine if invalid values
  89.         if (!isset($users_count))
  90.             $users_count count ($this->users$users_start;
  91.         if ($users_count 0)
  92.             $users_count 0;
  93.         if (!isset($items_count))
  94.             $items_count count ($this->evalscount ($this->links$items_start;
  95.         if ($items_count 0)
  96.             $items_count 0;
  97.  
  98.         // copy users to a new array that we will sort
  99.         // TODO - needed ?
  100.         $usertable array ();
  101.         foreach ($this->users as $user)
  102.             $usertable[$user;
  103.  
  104.         // sort users array
  105.         if ($users_sorting self :: FVDG_SORT_LASTNAME)
  106.             usort($usertablearray ('FlatViewDataGenerator','sort_by_last_name'));
  107.         elseif ($users_sorting self :: FVDG_SORT_FIRSTNAME)
  108.             usort($usertablearray ('FlatViewDataGenerator','sort_by_first_name'));
  109.         if ($users_sorting self :: FVDG_SORT_DESC)
  110.             $usertable array_reverse($usertable);
  111.  
  112.         // select the requested users
  113.         $selected_users array_slice($usertable$users_start$users_count);
  114.         
  115.  
  116.         // generate actual data array
  117.  
  118.         $scoredisplay ScoreDisplay :: instance();
  119.         
  120.         $dataarray ();
  121.         $displaytype SCORE_DIV;
  122.         if ($ignore_score_color)
  123.             $displaytype |= SCORE_IGNORE_SPLIT;
  124.  
  125.         foreach ($selected_users as $user)
  126.         {
  127.             $row array ();
  128.             $row[$user[0];    // user id
  129.             $row[$user[1];    // last name
  130.             $row[$user[2];    // first name
  131.  
  132.             for ($count=0;
  133.                  ($count $items_count && ($items_start $count count($this->evals_links));
  134.                  $count++)
  135.             {
  136.                 $item $this->evals_links [$count $items_start];
  137.                 $score $item->calc_score($user[0]);
  138.                 $row[$scoredisplay->display_score($score,$displaytype);
  139.             }
  140.             unset($score);
  141.             $data[$row;
  142.         }
  143.  
  144.         return $data;
  145.  
  146.     }
  147.  
  148.  
  149.  
  150.  
  151.     // Sort functions - used internally
  152.  
  153.     function sort_by_last_name($item1$item2)
  154.     {
  155.         if (strtolower($item1[1]== strtolower($item2[1]))
  156.             return 0;
  157.         else
  158.             return (strtolower($item1[1]strtolower($item2[1]? -1);
  159.     }
  160.  
  161.     function sort_by_first_name($item1$item2)
  162.     {
  163.         if (strtolower($item1[2]== strtolower($item2[2]))
  164.             return $this->sort_by_last_name($item1$item2);
  165.         else
  166.             return (strtolower($item1[2]strtolower($item2[2]? -1);
  167.     }
  168.  
  169. }
  170. ?>

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