evallink.class.php 4.4 KB

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