block_session.class.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. /**
  12. * This class is used like controller for this session block plugin,
  13. * the class name must be registered inside path.info file (e.g: controller = "BlockSession"), so dashboard controller will be instantiate it
  14. * @package chamilo.dashboard
  15. */
  16. class BlockSession extends Block {
  17. private $user_id;
  18. private $sessions;
  19. private $path;
  20. private $permission = array(DRH, SESSIONADMIN);
  21. /**
  22. * Constructor
  23. */
  24. public function __construct ($user_id) {
  25. $this->user_id = $user_id;
  26. $this->path = 'block_session';
  27. if ($this->is_block_visible_for_user($user_id)) {
  28. /*if (api_is_platform_admin()) {
  29. $this->sessions = SessionManager::get_sessions_list();
  30. } else {*/
  31. $this->sessions = SessionManager::get_sessions_followed_by_drh($user_id);
  32. //}
  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. $user_info = api_get_user_info($user_id);
  42. $user_status = $user_info['status'];
  43. $is_block_visible_for_user = false;
  44. if (UserManager::is_admin($user_id) || in_array($user_status, $this->permission)) {
  45. $is_block_visible_for_user = true;
  46. }
  47. return $is_block_visible_for_user;
  48. }
  49. /**
  50. * This method return content html containing information about sessions and its position for showing it inside dashboard interface
  51. * it's important to use the name 'get_block' for beeing used from dashboard controller
  52. * @return array column and content html
  53. */
  54. public function get_block() {
  55. global $charset;
  56. $column = 2;
  57. $data = array();
  58. $content = $this->get_content_html();
  59. $content_html = '
  60. <li class="widget color-red" id="intro">
  61. <div class="widget-head">
  62. <h3>'.get_lang('SessionsInformation').'</h3>
  63. <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>
  64. </div>
  65. <div class="widget-content">
  66. '.$content.'
  67. </div>
  68. </li>
  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. $content = '';
  80. $sessions = $this->sessions;
  81. $content = '<div style="margin:10px;">';
  82. $content .= '<h3><font color="#000">'.get_lang('YourSessionsList').'</font></h3>';
  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. $date_string = SessionManager::parse_session_dates($session);
  95. $count_courses_in_session = count(Tracking::get_courses_list_from_session($session_id));
  96. if ($i%2 == 0) $class_tr = 'row_odd';
  97. else $class_tr = 'row_even';
  98. $sessions_table .= '<tr class="'.$class_tr.'">
  99. <td>'.$title.'</td>
  100. <td align="center">'.$date_string.'</td>
  101. <td align="center">'.$count_courses_in_session.'</td>
  102. </tr>';
  103. $i++;
  104. }
  105. $sessions_table .= '</table>';
  106. $content .= $sessions_table;
  107. } else {
  108. $content .= get_lang('ThereIsNoInformationAboutYourSessions');
  109. }
  110. if (count($sessions) > 0) {
  111. $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>';
  112. }
  113. $content .= '</div>';
  114. return $content;
  115. }
  116. /**
  117. * Get number of sessions
  118. * @return int
  119. */
  120. function get_number_of_sessions() {
  121. return count($this->sessions);
  122. }
  123. }