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

Source for file evallink.class.php

Documentation is available at evallink.class.php

  1. <?php
  2.  
  3. /**
  4.  * Class to be used as basis for links referring to Evaluation objects.
  5.  * @author Bert Steppé
  6.  * @package dokeos.gradebook
  7.  */
  8. abstract class EvalLink extends AbstractLink
  9. {
  10.  
  11.     protected $evaluation = null;
  12.  
  13.     /**
  14.      * Constructor
  15.      */
  16.     function EvalLink()
  17.     {
  18.  
  19.     }
  20.  
  21.  
  22. // Functions implementing AbstractLink
  23.  
  24.     public function has_results()
  25.     {
  26.         $eval $this->get_evaluation();
  27.         return $eval->has_results();
  28.     }
  29.     
  30.     public function calc_score($stud_id null)
  31.     {
  32.         $eval $this->get_evaluation();
  33.         return $eval->calc_score($stud_id);
  34.     }
  35.  
  36.     public function get_link()
  37.     {
  38.         $eval $this->get_evaluation();
  39.  
  40.         // course/platform admin can go to the view_results page
  41.         if (api_is_allowed_to_create_course())
  42.             return 'gradebook_view_result.php?selecteval=' $eval->get_id();
  43.         // students can go to the statistics page (if custom display enabled)
  44.         elseif (ScoreDisplay :: instance()->is_custom())
  45.             return 'gradebook_statistics.php?selecteval=' $eval->get_id();
  46.         else
  47.             return null;
  48.     }
  49.     
  50.  
  51.     public function get_name()
  52.     {
  53.         $eval $this->get_evaluation();
  54.         return $eval->get_name();
  55.     }
  56.     
  57.     public function get_description()
  58.     {
  59.         $eval $this->get_evaluation();
  60.         return $eval->get_description();
  61.     }
  62.     
  63.     public function get_max()
  64.     {
  65.         $eval $this->get_evaluation();
  66.         return $eval->get_max();
  67.     }
  68.  
  69.     public function is_valid_link()
  70.     {
  71.         $eval $this->get_evaluation();
  72.         return (isset($eval));
  73.     }
  74.  
  75.  
  76.     public function needs_name_and_description()
  77.     {
  78.         return true;
  79.     }
  80.     
  81.     public function needs_max()
  82.     {
  83.         return true;
  84.     }
  85.  
  86.     public function needs_results()
  87.     {
  88.         return true;
  89.     }
  90.  
  91.  
  92.     public function add_linked_data()
  93.     {
  94.         if ($this->is_valid_link())
  95.         {
  96.             $this->evaluation->add();
  97.             $this->set_ref_id($this->evaluation->get_id());
  98.         }
  99.     }
  100.     
  101.     public function save_linked_data()
  102.     {
  103.         if ($this->is_valid_link())
  104.             $this->evaluation->save();
  105.     }
  106.     
  107.     public function delete_linked_data()
  108.     {
  109.         if ($this->is_valid_link())
  110.             $this->evaluation->delete_with_results();
  111.     }
  112.  
  113.  
  114.     public function set_name ($name)
  115.     {
  116.         if ($this->is_valid_link())
  117.             $this->evaluation->set_name($name);
  118.     }
  119.     
  120.     public function set_description ($description)
  121.     {
  122.         if ($this->is_valid_link())
  123.             $this->evaluation->set_description($description);
  124.     }
  125.     
  126.     public function set_max ($max)
  127.     {
  128.         if ($this->is_valid_link())
  129.             $this->evaluation->set_max($max);
  130.     }
  131.  
  132.  
  133. // Functions overriding non-trivial implementations from AbstractLink
  134.  
  135.     public function set_date ($date)
  136.     {
  137.         $this->link_date = $date;
  138.         if ($this->is_valid_link())
  139.             $this->evaluation->set_date($date);
  140.     }
  141.     
  142.     public function set_weight ($weight)
  143.     {
  144.         $this->weight = $weight;
  145.         if ($this->is_valid_link())
  146.             $this->evaluation->set_weight($weight);
  147.     }
  148.     
  149.     public function set_visible ($visible)
  150.     {
  151.         $this->visible = $visible;
  152.         if ($this->is_valid_link())
  153.             $this->evaluation->set_visible($visible);
  154.     }
  155.  
  156.  
  157.  
  158. // INTERNAL FUNCTIONS
  159.  
  160.     /**
  161.      * Lazy load function to get the linked evaluation
  162.      */
  163.     protected function get_evaluation ()
  164.     {
  165.         if (!isset($this->evaluation))
  166.         {
  167.             if (isset($this->ref_id))
  168.             {
  169.                 $evalarray Evaluation::load($this->get_ref_id());
  170.                 $this->evaluation = $evalarray[0];
  171.             }
  172.             else
  173.             {
  174.                 $eval new Evaluation();
  175.                 $eval->set_category_id(-1);
  176.                 $eval->set_date(time())// these values will be changed
  177.                 $eval->set_weight(0);    //   when the link setter
  178.                 $eval->set_visible(0);   //     is called
  179.                 $eval->set_id(-1)// a 'real' id will be set when eval is added to db
  180.                 $eval->set_user_id($this->get_user_id());
  181.                 $eval->set_course_code($this->get_course_code());
  182.                 $this->evaluation = $eval;
  183.                 $this->set_ref_id($eval->get_id());
  184.                 
  185.             }
  186.         }
  187.         return $this->evaluation;
  188.     }
  189.     
  190.  
  191. }
  192. ?>

Documentation generated on Thu, 12 Jun 2008 13:23:22 -0500 by phpDocumentor 1.4.1