PageRenderTime 40ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/php/lib/assessment_manager/component/results_viewer.class.php

https://bitbucket.org/chamilo/chamilo-app-assessment-dev/
PHP | 213 lines | 163 code | 36 blank | 14 comment | 7 complexity | b42be6f0e4a4f77452b16ca174bdd133 MD5 | raw file
  1. <?php
  2. namespace application\assessment;
  3. use common\libraries\BreadcrumbTrail;
  4. use common\libraries\Request;
  5. use common\libraries\EqualityCondition;
  6. use common\libraries\Translation;
  7. use common\libraries\Breadcrumb;
  8. use repository\ComplexDisplay;
  9. use common\libraries\Path;
  10. use reporting\ReportingDataManager;
  11. use common\libraries\AndCondition;
  12. /**
  13. * $Id: results_viewer.class.php 193 2009-11-13 11:53:37Z chellee $
  14. * @package application.lib.assessment.assessment_manager.component
  15. */
  16. require_once dirname(__FILE__) . '/../assessment_manager.class.php';
  17. require_once dirname(__FILE__) . '/../../../trackers/assessment_question_attempts_tracker.class.php';
  18. require_once dirname(__FILE__) . '/../../../trackers/assessment_assessment_attempts_tracker.class.php';
  19. /**
  20. * Component to create a new assessment_publication object
  21. * @author Sven Vanpoucke
  22. * @author
  23. */
  24. class AssessmentManagerResultsViewerComponent extends AssessmentManager
  25. {
  26. private $current_attempt_id;
  27. private $object;
  28. /**
  29. * Runs this component and displays its output.
  30. */
  31. function run()
  32. {
  33. $this->trail = $trail = BreadcrumbTrail :: get_instance();
  34. $pid = Request :: get(AssessmentManager :: PARAM_ASSESSMENT_PUBLICATION);
  35. $delete = Request :: get('delete');
  36. if ($delete)
  37. {
  38. $split = explode('_', $delete);
  39. $id = $split[1];
  40. if ($split[0] == 'aid')
  41. {
  42. $condition = new EqualityCondition(AssessmentAssessmentAttemptsTracker :: PROPERTY_ASSESSMENT_ID, $id);
  43. }
  44. else
  45. {
  46. $condition = new EqualityCondition(AssessmentAssessmentAttemptsTracker :: PROPERTY_ID, $id);
  47. $parameters = array(AssessmentManager :: PARAM_ASSESSMENT_PUBLICATION => $pid);
  48. }
  49. $dummy = new AssessmentAssessmentAttemptsTracker();
  50. $trackers = $dummy->retrieve_tracker_items($condition);
  51. foreach ($trackers as $tracker)
  52. {
  53. $tracker->delete();
  54. }
  55. $this->redirect(Translation :: get('AssessmentAttemptsDeleted'), false, $parameters);
  56. exit();
  57. }
  58. if (! $pid)
  59. {
  60. $this->display_header();
  61. echo $this->display_summary_results();
  62. $this->display_footer();
  63. }
  64. else
  65. {
  66. $trail->add(new Breadcrumb($this->get_url(array(AssessmentManager :: PARAM_ASSESSMENT_PUBLICATION => $pid)), Translation :: get('ViewAssessmentResults')));
  67. $details = Request :: get('details');
  68. if ($details)
  69. {
  70. $trail->add(new Breadcrumb($this->get_url(array(
  71. AssessmentManager :: PARAM_ASSESSMENT_PUBLICATION => $pid, 'details' => $details)), Translation :: get('ViewAssessmentDetails')));
  72. $this->current_attempt_id = $details;
  73. $pub = AssessmentDataManager :: get_instance()->retrieve_assessment_publication($pid);
  74. $object = $pub->get_publication_object();
  75. $_GET['display_action'] = AssessmentManager :: ACTION_VIEW_ASSESSMENT_PUBLICATION_RESULTS;
  76. $this->set_parameter('details', $details);
  77. $this->set_parameter(AssessmentManager :: PARAM_ASSESSMENT_PUBLICATION, $pid);
  78. $this->object = $object;
  79. ComplexDisplay :: launch($object->get_type(), $this);
  80. }
  81. else
  82. {
  83. $this->display_header();
  84. echo $this->display_assessment_results($pid);
  85. $this->display_footer();
  86. }
  87. }
  88. }
  89. function get_root_content_object()
  90. {
  91. return $this->object;
  92. }
  93. function display_header($trail)
  94. {
  95. if ($trail)
  96. {
  97. $this->trail->merge($trail);
  98. }
  99. parent :: display_header($this->trail);
  100. }
  101. function display_summary_results()
  102. {
  103. require_once (Path :: get_application_path() . '/assessment/php/reporting/templates/assessment_attempts_summary_template.class.php');
  104. $current_category = Request :: get('category');
  105. $current_category = $current_category ? $current_category : 0;
  106. $parameters = array('category' => $current_category, 'url' => $this->get_url());
  107. $database = ReportingDataManager :: get_instance();
  108. $template_obj = $database->retrieve_reporting_template_object('assessment_attempts_summary_template');
  109. $template = new AssessmentAttemptsSummaryTemplate($this, $template_obj->get_id(), $parameters, null);
  110. //$template->set_reporting_blocks_function_parameters($parameters);
  111. return $template->to_html();
  112. }
  113. function display_assessment_results($pid)
  114. {
  115. require_once (Path :: get_application_path() . '/assessment/php/reporting/templates/assessment_attempts_template.class.php');
  116. $url = $this->get_url(array(AssessmentManager :: PARAM_ASSESSMENT_PUBLICATION => $pid));
  117. $results_export_url = $this->get_results_exporter_url();
  118. $parameters = array(AssessmentManager :: PARAM_ASSESSMENT_PUBLICATION => $pid, 'url' => $url,
  119. 'results_export_url' => $results_export_url);
  120. $database = ReportingDataManager :: get_instance();
  121. $template_obj = $database->retrieve_reporting_template_object('assessment_attempts_template');
  122. $template = new AssessmentAttemptsTemplate($this, $template_obj->get_id(), $parameters, null, $pid);
  123. //$template->set_reporting_blocks_function_parameters($parameters);
  124. return $template->to_html();
  125. }
  126. function retrieve_assessment_results()
  127. {
  128. $condition = new EqualityCondition(AssessmentQuestionAttemptsTracker :: PROPERTY_ASSESSMENT_ATTEMPT_ID, $this->current_attempt_id);
  129. $dummy = new AssessmentQuestionAttemptsTracker();
  130. $trackers = $dummy->retrieve_tracker_items($condition);
  131. $results = array();
  132. foreach ($trackers as $tracker)
  133. {
  134. $results[$tracker->get_question_cid()] = array('answer' => $tracker->get_answer(),
  135. 'feedback' => $tracker->get_feedback(), 'score' => $tracker->get_score());
  136. }
  137. return $results;
  138. }
  139. function change_answer_data($question_cid, $score, $feedback)
  140. {
  141. $conditions[] = new EqualityCondition(AssessmentQuestionAttemptsTracker :: PROPERTY_ASSESSMENT_ATTEMPT_ID, $this->current_attempt_id);
  142. $conditions[] = new EqualityCondition(AssessmentQuestionAttemptsTracker :: PROPERTY_QUESTION_CID, $question_cid);
  143. $condition = new AndCondition($conditions);
  144. $dummy = new AssessmentQuestionAttemptsTracker();
  145. $trackers = $dummy->retrieve_tracker_items($condition);
  146. $tracker = $trackers[0];
  147. $tracker->set_score($score);
  148. $tracker->set_feedback($feedback);
  149. $tracker->update();
  150. }
  151. function change_total_score($total_score)
  152. {
  153. $condition = new EqualityCondition(AssessmentAssessmentAttemptsTracker :: PROPERTY_ID, $this->current_attempt_id);
  154. $dummy = new AssessmentAssessmentAttemptsTracker();
  155. $trackers = $dummy->retrieve_tracker_items($condition);
  156. $tracker = $trackers[0];
  157. if (! $tracker)
  158. return;
  159. $tracker->set_total_score($total_score);
  160. $tracker->update();
  161. }
  162. function can_change_answer_data()
  163. {
  164. return true;
  165. }
  166. function add_additional_breadcrumbs(BreadcrumbTrail $breadcrumbtrail)
  167. {
  168. $breadcrumbtrail->add_help('assessment_results_viewer');
  169. $breadcrumbtrail->add(new Breadcrumb($this->get_url(array(
  170. AssessmentManager :: PARAM_ACTION => AssessmentManager :: ACTION_BROWSE_ASSESSMENT_PUBLICATIONS)), Translation :: get('AssessmentManagerBrowserComponent')));
  171. }
  172. function get_additional_parameters()
  173. {
  174. return array(self :: PARAM_ASSESSMENT_PUBLICATION);
  175. }
  176. }
  177. ?>