block_session.class.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. * required files for getting data
  10. */
  11. require_once api_get_path(LIBRARY_PATH).'course_description.lib.php';
  12. /**
  13. * This class is used like controller for this session block plugin,
  14. * the class name must be registered inside path.info file
  15. * (e.g: controller = "BlockSession"), so dashboard controller will be instantiate it
  16. * @package chamilo.dashboard
  17. */
  18. class BlockSession extends Block
  19. {
  20. private $user_id;
  21. private $sessions;
  22. private $path;
  23. private $permission = array(DRH, SESSIONADMIN);
  24. /**
  25. * Constructor
  26. */
  27. public function __construct ($user_id)
  28. {
  29. $this->user_id = $user_id;
  30. $this->path = 'block_session';
  31. if ($this->is_block_visible_for_user($user_id)) {
  32. $this->sessions = SessionManager::get_sessions_followed_by_drh($user_id);
  33. }
  34. }
  35. /**
  36. * This method check if a user is allowed to see the block inside dashboard interface
  37. * @param int User id
  38. * @return bool Is block visible for user
  39. */
  40. public function is_block_visible_for_user($user_id)
  41. {
  42. $user_info = api_get_user_info($user_id);
  43. $user_status = $user_info['status'];
  44. $is_block_visible_for_user = false;
  45. if (UserManager::is_admin($user_id) || in_array($user_status, $this->permission)) {
  46. $is_block_visible_for_user = true;
  47. }
  48. return $is_block_visible_for_user;
  49. }
  50. /**
  51. * This method return content html containing information about sessions and its position for showing it inside dashboard interface
  52. * it's important to use the name 'get_block' for beeing used from dashboard controller
  53. * @return array column and content html
  54. */
  55. public function get_block()
  56. {
  57. global $charset;
  58. $column = 2;
  59. $data = array();
  60. $content = $this->get_content_html();
  61. $content_html = '
  62. <li class="widget color-red" id="intro">
  63. <div class="widget-head">
  64. <h3>'.get_lang('SessionsInformation').'</h3>
  65. <div class="widget-actions"><a onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang('ConfirmYourChoice'),ENT_QUOTES,$charset)).'\')) return false;" href="index.php?action=disable_block&path='.$this->path.'">'.Display::return_icon('close.gif',get_lang('Close')).'</a></div>
  66. </div>
  67. <div class="widget-content">
  68. '.$content.'
  69. </div>
  70. </li>
  71. ';
  72. $data['column'] = $column;
  73. $data['content_html'] = $content_html;
  74. return $data;
  75. }
  76. /**
  77. * This method return a content html, it's used inside get_block method for showing it inside dashboard interface
  78. * @return string content html
  79. */
  80. public function get_content_html()
  81. {
  82. $content = '';
  83. $sessions = $this->sessions;
  84. $content = '<div style="margin:10px;">';
  85. $content .= '<h3><font color="#000">'.get_lang('YourSessionsList').'</font></h3>';
  86. if (count($sessions) > 0) {
  87. $sessions_table = '<table class="data_table" width:"95%">';
  88. $sessions_table .= '<tr>
  89. <th >'.get_lang('Title').'</th>
  90. <th >'.get_lang('Date').'</th>
  91. <th width="100px">'.get_lang('NbCoursesPerSession').'</th>
  92. </tr>';
  93. $i = 1;
  94. foreach ($sessions as $session) {
  95. $session_id = intval($session['id']);
  96. $title = $session['name'];
  97. if ($session['date_start'] != '0000-00-00' && $session['date_end'] != '0000-00-00') {
  98. $date = get_lang('From').' '.api_convert_and_format_date($session['date_start'], DATE_FORMAT_SHORT, date_default_timezone_get()).' '.get_lang('To').' '.api_convert_and_format_date($session['date_end'], DATE_FORMAT_SHORT, date_default_timezone_get());
  99. } else {
  100. $date = ' - ';
  101. }
  102. $count_courses_in_session = count(Tracking::get_courses_list_from_session($session_id));
  103. if ($i%2 == 0) $class_tr = 'row_odd';
  104. else $class_tr = 'row_even';
  105. $sessions_table .= '<tr class="'.$class_tr.'">
  106. <td>'.$title.'</td>
  107. <td align="center">'.$date.'</td>
  108. <td align="center">'.$count_courses_in_session.'</td>
  109. </tr>';
  110. $i++;
  111. }
  112. $sessions_table .= '</table>';
  113. $content .= $sessions_table;
  114. } else {
  115. $content .= get_lang('ThereIsNoInformationAboutYourSessions');
  116. }
  117. if (count($sessions) > 0) {
  118. $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>';
  119. }
  120. $content .= '</div>';
  121. return $content;
  122. }
  123. /**
  124. * Get number of sessions
  125. * @return int
  126. */
  127. function get_number_of_sessions()
  128. {
  129. return count($this->sessions);
  130. }
  131. }