block_session.class.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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 (e.g: controller = "BlockSession"), so dashboard controller will be instantiate it
  15. * @package chamilo.dashboard
  16. */
  17. class BlockSession extends Block {
  18. private $user_id;
  19. private $sessions;
  20. private $path;
  21. private $permission = array(DRH, SESSIONADMIN);
  22. /**
  23. * Constructor
  24. */
  25. public function __construct ($user_id) {
  26. $this->user_id = $user_id;
  27. $this->path = 'block_session';
  28. if ($this->is_block_visible_for_user($user_id)) {
  29. /*if (api_is_platform_admin()) {
  30. $this->sessions = SessionManager::get_sessions_list();
  31. } else {*/
  32. $this->sessions = SessionManager::get_sessions_followed_by_drh($user_id);
  33. //}
  34. }
  35. }
  36. /**
  37. * This method check if a user is allowed to see the block inside dashboard interface
  38. * @param int User id
  39. * @return bool Is block visible for user
  40. */
  41. public function is_block_visible_for_user($user_id) {
  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. global $charset;
  57. $column = 2;
  58. $data = array();
  59. $content = $this->get_content_html();
  60. $content_html = '
  61. <li class="widget color-red" id="intro">
  62. <div class="widget-head">
  63. <h3>'.get_lang('SessionsInformation').'</h3>
  64. <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>
  65. </div>
  66. <div class="widget-content">
  67. '.$content.'
  68. </div>
  69. </li>
  70. ';
  71. $data['column'] = $column;
  72. $data['content_html'] = $content_html;
  73. return $data;
  74. }
  75. /**
  76. * This method return a content html, it's used inside get_block method for showing it inside dashboard interface
  77. * @return string content html
  78. */
  79. public function get_content_html() {
  80. $content = '';
  81. $sessions = $this->sessions;
  82. $content = '<div style="margin:10px;">';
  83. $content .= '<h3><font color="#000">'.get_lang('YourSessionsList').'</font></h3>';
  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['date_start'] != '0000-00-00' && $session['date_end'] != '0000-00-00') {
  96. $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());
  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. return count($this->sessions);
  127. }
  128. }