block_session.class.php 5.2 KB

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