block_session.class.php 5.6 KB

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