block_session.class.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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 information about sessions and its position for showing it inside dashboard interface
  48. * it's important to use the name 'get_block' for beeing used from dashboard controller
  49. * @return array column and content html
  50. */
  51. public function get_block()
  52. {
  53. global $charset;
  54. $column = 2;
  55. $data = array();
  56. $content = $this->get_content_html();
  57. $content_html = '
  58. <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 = '<div style="margin:10px;">';
  83. $content .= '<h4>'.get_lang('YourSessionsList').'</h4>';
  84. if (count($sessions) > 0) {
  85. $sessions_table = '<table class="data_table" width:"95%">';
  86. $sessions_table .= '<tr>
  87. <th >'.get_lang('Title').'</th>
  88. <th >'.get_lang('Date').'</th>
  89. <th width="100px">'.get_lang('NbCoursesPerSession').'</th>
  90. </tr>';
  91. $i = 1;
  92. foreach ($sessions as $session) {
  93. $session_id = intval($session['id']);
  94. $title = $session['name'];
  95. if ($session['access_start_date'] != '0000-00-00 00:00:00' && $session['access_end_date'] != '0000-00-00 00:00:00') {
  96. $date = get_lang('From').' '.api_convert_and_format_date($session['access_start_date'], DATE_FORMAT_SHORT, date_default_timezone_get()).' '.get_lang('To').' '.api_convert_and_format_date($session['access_end_date'], DATE_FORMAT_SHORT, date_default_timezone_get());
  97. } else {
  98. $date = ' - ';
  99. }
  100. $count_courses_in_session = count(Tracking::get_courses_list_from_session($session_id));
  101. if ($i%2 == 0) $class_tr = 'row_odd';
  102. else $class_tr = 'row_even';
  103. $sessions_table .= '<tr class="'.$class_tr.'">
  104. <td>'.$title.'</td>
  105. <td align="center">'.$date.'</td>
  106. <td align="center">'.$count_courses_in_session.'</td>
  107. </tr>';
  108. $i++;
  109. }
  110. $sessions_table .= '</table>';
  111. $content .= $sessions_table;
  112. } else {
  113. $content .= get_lang('ThereIsNoInformationAboutYourSessions');
  114. }
  115. if (count($sessions) > 0) {
  116. $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>';
  117. }
  118. //$content .= '</div>';
  119. return $content;
  120. }
  121. /**
  122. * Get number of sessions
  123. * @return int
  124. */
  125. function get_number_of_sessions()
  126. {
  127. return count($this->sessions);
  128. }
  129. }