block_session.class.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <?php
  2. /**
  3. * This file is part of session block plugin for dashboard,
  4. * it should be required inside dashboard controller for showing it into dashboard interface from plattform.
  5. *
  6. * @package chamilo.dashboard
  7. *
  8. * @author Christian Fasanando
  9. */
  10. /**
  11. * This class is used like controller for this session block plugin,
  12. * the class name must be registered inside path.info file
  13. * (e.g: controller = "BlockSession"), so dashboard controller will be instantiate it.
  14. *
  15. * @package chamilo.dashboard
  16. */
  17. class BlockSession extends Block
  18. {
  19. private $user_id;
  20. private $sessions;
  21. private $path;
  22. private $permission = [DRH, SESSIONADMIN];
  23. /**
  24. * Constructor.
  25. */
  26. public function __construct($user_id)
  27. {
  28. $this->user_id = $user_id;
  29. $this->path = 'block_session';
  30. if ($this->is_block_visible_for_user($user_id)) {
  31. $this->sessions = SessionManager::get_sessions_followed_by_drh($user_id);
  32. }
  33. }
  34. /**
  35. * This method check if a user is allowed to see the block inside dashboard interface.
  36. *
  37. * @param int User id
  38. *
  39. * @return bool Is block visible for user
  40. */
  41. public function is_block_visible_for_user($user_id)
  42. {
  43. $user_info = api_get_user_info($user_id);
  44. $user_status = $user_info['status'];
  45. $is_block_visible_for_user = false;
  46. if (UserManager::is_admin($user_id) || in_array($user_status, $this->permission)) {
  47. $is_block_visible_for_user = true;
  48. }
  49. return $is_block_visible_for_user;
  50. }
  51. /**
  52. * This method return content html containing
  53. * information about sessions and its position for showing it inside dashboard interface
  54. * it's important to use the name 'get_block' for beeing used from dashboard controller.
  55. *
  56. * @return array column and content html
  57. */
  58. public function get_block()
  59. {
  60. global $charset;
  61. $column = 2;
  62. $data = [];
  63. $content = $this->get_content_html();
  64. $content_html = '<div class="panel panel-default" id="intro">
  65. <div class="panel-heading">
  66. '.get_lang('SessionsInformation').'
  67. <div class="pull-right"><a class="btn btn-danger btn-xs" onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES, $charset)).'\')) return false;" href="index.php?action=disable_block&path='.$this->path.'">
  68. <em class="fa fa-times"></em>
  69. </a></div>
  70. </div>
  71. <div class="panel-body">
  72. '.$content.'
  73. </div>
  74. </div>
  75. ';
  76. $data['column'] = $column;
  77. $data['content_html'] = $content_html;
  78. return $data;
  79. }
  80. /**
  81. * This method return a content html, it's used inside get_block method for showing it inside dashboard interface.
  82. *
  83. * @return string content html
  84. */
  85. public function get_content_html()
  86. {
  87. $content = '';
  88. $sessions = $this->sessions;
  89. $content .= '<h4>'.get_lang('YourSessionsList').'</h4>';
  90. if (count($sessions) > 0) {
  91. $sessions_table = '<table class="data_table" width:"95%">';
  92. $sessions_table .= '<tr>
  93. <th >'.get_lang('Title').'</th>
  94. <th >'.get_lang('Date').'</th>
  95. <th width="100px">'.get_lang('NbCoursesPerSession').'</th>
  96. </tr>';
  97. $i = 1;
  98. foreach ($sessions as $session) {
  99. $session_id = intval($session['id']);
  100. $title = $session['name'];
  101. if (!empty($session['access_start_date'])) {
  102. $dateFrom = api_convert_and_format_date(
  103. $session['access_start_date'],
  104. DATE_FORMAT_SHORT,
  105. date_default_timezone_get()
  106. );
  107. $dateUntil = api_convert_and_format_date(
  108. $session['access_end_date'],
  109. DATE_FORMAT_SHORT,
  110. date_default_timezone_get()
  111. );
  112. $date = vsprintf(get_lang('FromDateXToDateY'), [$dateFrom, $dateUntil]);
  113. } else {
  114. $date = ' - ';
  115. }
  116. $count_courses_in_session = count(Tracking::get_courses_list_from_session($session_id));
  117. if ($i % 2 == 0) {
  118. $class_tr = 'row_odd';
  119. } else {
  120. $class_tr = 'row_even';
  121. }
  122. $sessions_table .= '<tr class="'.$class_tr.'">
  123. <td>'.$title.'</td>
  124. <td align="center">'.$date.'</td>
  125. <td align="center">'.$count_courses_in_session.'</td>
  126. </tr>';
  127. $i++;
  128. }
  129. $sessions_table .= '</table>';
  130. $content .= $sessions_table;
  131. } else {
  132. $content .= get_lang('ThereIsNoInformationAboutYourSessions');
  133. }
  134. if (count($sessions) > 0) {
  135. $content .= '<div style="text-align:right;margin-top:10px;"><a href="'.api_get_path(WEB_CODE_PATH).'mySpace/session.php">'.get_lang('SeeMore').'</a></div>';
  136. }
  137. return $content;
  138. }
  139. /**
  140. * Get number of sessions.
  141. *
  142. * @return int
  143. */
  144. public function get_number_of_sessions()
  145. {
  146. return count($this->sessions);
  147. }
  148. }