evallink.class.php 3.8 KB

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