PageRenderTime 28ms CodeModel.GetById 0ms RepoModel.GetById 1ms app.codeStats 0ms

/php/reporting/blocks/survey_total_user_result_view_reporting_block.class.php

https://bitbucket.org/chamilo/chamilo-app-survey-dev/
PHP | 150 lines | 121 code | 29 blank | 0 comment | 9 complexity | 503df8ef2fdb1d70938494040200e410 MD5 | raw file
  1. <?php
  2. namespace application\survey;
  3. use common\libraries\Translation;
  4. use reporting\ReportingData;
  5. use common\libraries\EqualityCondition;
  6. use common\libraries\PatternMatchCondition;
  7. use common\libraries\AndCondition;
  8. use user\VisitTracker;
  9. use tracking\Tracker;
  10. use user\UserManager;
  11. use user\UserDataManager;
  12. class SurveyTotalUserResultViewReportingBlock extends SurveyReportingBlock
  13. {
  14. const NOT_VIEWED = 0;
  15. const VIEWED = 1;
  16. private $publication_id;
  17. private $viewed;
  18. private $parent;
  19. function __construct($parent, $publication_id, $viewed)
  20. {
  21. parent :: __construct($parent);
  22. $this->parent = $parent;
  23. $this->publication_id = $publication_id;
  24. $this->viewed = $viewed;
  25. }
  26. public function get_title()
  27. {
  28. if ($this->viewed == 1)
  29. {
  30. $viewed = Translation :: get('viewed');
  31. }
  32. else
  33. {
  34. $viewed = Translation :: get('notviewed');
  35. }
  36. $title = Translation :: get('TotalUserReportingResultView');
  37. $title = $title . ' ' . $viewed;
  38. return $title;
  39. }
  40. public function count_data()
  41. {
  42. return $this->create_reporting_data();
  43. }
  44. public function retrieve_data()
  45. {
  46. return $this->count_data();
  47. }
  48. function get_application()
  49. {
  50. return SurveyManager :: APPLICATION_NAME;
  51. }
  52. private function create_reporting_data()
  53. {
  54. $reporting_data = new ReportingData();
  55. $condition = new EqualityCondition(SurveyPublicationRelReportingTemplateRegistration :: PROPERTY_PUBLICATION_ID, $this->publication_id);
  56. $publicationrelreportingtemplates = SurveyDataManager :: get_instance()->retrieve_survey_publication_rel_reporting_template_registrations($condition);
  57. $user_ids = array();
  58. while ($publicationrelreportingtemplate = $publicationrelreportingtemplates->next_result())
  59. {
  60. $publication_rel_template_id = $publicationrelreportingtemplate->get_id();
  61. if ($this->parent->get_id() == $publicationrelreportingtemplate->get_reporting_template_registration_id())
  62. {
  63. continue;
  64. }
  65. $context_template_id = $publicationrelreportingtemplate->get_level();
  66. $conditions = array();
  67. $conditions[] = new PatternMatchCondition(VisitTracker :: PROPERTY_LOCATION, '*application=survey*');
  68. $conditions[] = new PatternMatchCondition(VisitTracker :: PROPERTY_LOCATION, '*action=reporting*');
  69. $conditions[] = new PatternMatchCondition(VisitTracker :: PROPERTY_LOCATION, '*go=reporting*');
  70. $conditions[] = new PatternMatchCondition(VisitTracker :: PROPERTY_LOCATION, '*publication_id=' . $this->publication_id . '*');
  71. $conditions[] = new PatternMatchCondition(VisitTracker :: PROPERTY_LOCATION, '*publication_rel_reporting_template_id=' . $publication_rel_template_id . '*');
  72. $conditions[] = new PatternMatchCondition(VisitTracker :: PROPERTY_LOCATION, '*context_template_id=' . $context_template_id . '*');
  73. $condition = new AndCondition($conditions);
  74. $trackers = Tracker :: get_data(VisitTracker :: CLASS_NAME, UserManager :: APPLICATION_NAME, $condition);
  75. while ($tracker = $trackers->next_result())
  76. {
  77. $user_ids[] = $tracker->get_user_id();
  78. }
  79. }
  80. $viewed_users = array_unique($user_ids);
  81. $reporting_users = SurveyRights :: get_allowed_users(SurveyRights :: RIGHT_REPORTING, $this->publication_id, SurveyRights :: TYPE_PUBLICATION);
  82. $reporting_users = array_unique($reporting_users);
  83. $not_viewed_users = array_diff($reporting_users, $viewed_users);
  84. $categories = array();
  85. $nr = 0;
  86. if ($this->viewed == 1)
  87. {
  88. $user_count = count($viewed_users);
  89. $user_ids = $viewed_users;
  90. }
  91. else
  92. {
  93. $user_count = count(array_unique($not_viewed_users));
  94. $user_ids = $not_viewed_users;
  95. }
  96. while ($user_count > 0)
  97. {
  98. $nr ++;
  99. $categories[] = $nr;
  100. $user_count --;
  101. }
  102. $firstname = Translation :: get('Firstname');
  103. $lastname = Translation :: get('Lastname');
  104. $email = Translation :: get('Email');
  105. $rows = array($firstname, $lastname, $email);
  106. $reporting_data = new ReportingData();
  107. $reporting_data->set_categories($categories);
  108. $reporting_data->set_rows($rows);
  109. $nr = 0;
  110. foreach ($user_ids as $user_id)
  111. {
  112. $nr ++;
  113. $user = UserDataManager :: get_instance()->retrieve_user($user_id);
  114. $reporting_data->add_data_category_row($nr, $firstname, $user->get_firstname());
  115. $reporting_data->add_data_category_row($nr, $lastname, $user->get_lastname());
  116. $reporting_data->add_data_category_row($nr, $email, $user->get_email());
  117. }
  118. return $reporting_data;
  119. }
  120. }
  121. ?>