1
0

block_iassign_block.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. /**
  3. * Block iLM manager
  4. *
  5. * Release Notes:
  6. * - v 1.1 2013/11/01
  7. * + Fix bug in access when the iassign module not install.
  8. *
  9. * @author Patricia Alves Rodrigues
  10. * @author Leônidas O. Brandão
  11. * @author Luciano Oliveira Borges
  12. * @version v 1.1 2013/11/01
  13. * @package iassign_block
  14. * @since 2012/01/10
  15. * @copyright iMatica (<a href="http://www.matematica.br">iMath</a>) - Computer Science Dep. of IME-USP (Brazil)
  16. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  17. * @see block_base
  18. */
  19. defined('MOODLE_INTERNAL') || die();
  20. class block_iassign_block extends block_base {
  21. /**
  22. * Initialize funcion of class.
  23. */
  24. function init() {
  25. $this->title = get_string('blocktitle', 'block_iassign_block');
  26. $this->blockname = get_string('pluginname', 'block_iassign_block');
  27. }
  28. /**
  29. * Overwrite specialization function (Inheritance).
  30. */
  31. function specialization() {
  32. }
  33. /**
  34. * Function for allow applicable formats.
  35. * @return array Return an array with the formats.
  36. */
  37. function applicable_formats() {
  38. return array('all' => true);
  39. }
  40. /**
  41. * Function for allow multiple instances.
  42. * @return boolean Return false for multple instances.
  43. */
  44. function instance_allow_multiple() {
  45. return false;
  46. }
  47. /**
  48. * Function for return the content the block in page.
  49. * @return stdClass|NULL Return content or null.
  50. */
  51. function get_content() {
  52. global $USER, $CFG, $COURSE, $PAGE, $OUTPUT;
  53. if ($this->content !== NULL) {
  54. return $this->content;
  55. }
  56. if (empty($this->instance)) {
  57. return null;
  58. }
  59. if (isloggedin() && !isguestuser()) { // Show the block
  60. $this->content = new stdClass();
  61. if ($PAGE->pagelayout != 'frontpage') {
  62. if (has_capability('mod/iassign:editiassign', $this->context)) {//
  63. $code_javascript = "
  64. <script type='text/javascript'>
  65. //<![CDATA[
  66. function alert_iassign() {
  67. alert('".get_string('alert_iassign', 'block_iassign_block')."');
  68. }
  69. //]]>
  70. </script>";
  71. $this->content->text = $code_javascript;
  72. if(!file_exists($CFG->dirroot . '/mod/iassign/version.php')) {
  73. $options = array('id' => $COURSE->id);
  74. $url = "#";
  75. $confirmaction = new component_action('click', 'alert_iassign', array());
  76. } else {
  77. $options = array('id' => $COURSE->id, 'from' => 'block', 'returnurl' => $PAGE->url->out());
  78. $url = "$CFG->wwwroot/mod/iassign/ilm_manager.php";
  79. $confirmaction = '';
  80. }
  81. $button = new single_button(new moodle_url($url, $options), get_string('new_edit', 'block_iassign_block'), 'GET');
  82. if(!empty($confirmaction))
  83. $button->add_action($confirmaction);
  84. $this->content->text .= '<CENTER>'.$OUTPUT->render($button).'</CENTER>';
  85. }
  86. return $this->content;
  87. }
  88. }
  89. }
  90. }