| 1454 | 
           ariadna | 
           1 | 
           <?php
  | 
        
        
            | 
            | 
           2 | 
           // This file is part of Moodle - http://moodle.org/
  | 
        
        
            | 
            | 
           3 | 
           //
  | 
        
        
            | 
            | 
           4 | 
           // Moodle is free software: you can redistribute it and/or modify
  | 
        
        
            | 
            | 
           5 | 
           // it under the terms of the GNU General Public License as published by
  | 
        
        
            | 
            | 
           6 | 
           // the Free Software Foundation, either version 3 of the License, or
  | 
        
        
            | 
            | 
           7 | 
           // (at your option) any later version.
  | 
        
        
            | 
            | 
           8 | 
           //
  | 
        
        
            | 
            | 
           9 | 
           // Moodle is distributed in the hope that it will be useful,
  | 
        
        
            | 
            | 
           10 | 
           // but WITHOUT ANY WARRANTY; without even the implied warranty of
  | 
        
        
            | 
            | 
           11 | 
           // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  | 
        
        
            | 
            | 
           12 | 
           // GNU General Public License for more details.
  | 
        
        
            | 
            | 
           13 | 
           //
  | 
        
        
            | 
            | 
           14 | 
           // You should have received a copy of the GNU General Public License
  | 
        
        
            | 
            | 
           15 | 
           // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  | 
        
        
            | 
            | 
           16 | 
              | 
        
        
            | 
            | 
           17 | 
           /**
  | 
        
        
            | 
            | 
           18 | 
            * The mynotes block
  | 
        
        
            | 
            | 
           19 | 
            *
  | 
        
        
            | 
            | 
           20 | 
            * @package    block_mynotes
  | 
        
        
            | 
            | 
           21 | 
            * @author     Gautam Kumar Das<gautam.arg@gmail.com>
  | 
        
        
            | 
            | 
           22 | 
            */
  | 
        
        
            | 
            | 
           23 | 
              | 
        
        
            | 
            | 
           24 | 
           defined('MOODLE_INTERNAL') || die();
  | 
        
        
            | 
            | 
           25 | 
              | 
        
        
            | 
            | 
           26 | 
           require_once($CFG->dirroot . '/blocks/mynotes/lib.php');
  | 
        
        
            | 
            | 
           27 | 
              | 
        
        
            | 
            | 
           28 | 
           /**
  | 
        
        
            | 
            | 
           29 | 
            * Mynotes block.
  | 
        
        
            | 
            | 
           30 | 
            *
  | 
        
        
            | 
            | 
           31 | 
            * @package    block_mynotes
  | 
        
        
            | 
            | 
           32 | 
            *
  | 
        
        
            | 
            | 
           33 | 
            */
  | 
        
        
            | 
            | 
           34 | 
           class block_mynotes extends block_base
  | 
        
        
            | 
            | 
           35 | 
           {
  | 
        
        
            | 
            | 
           36 | 
              | 
        
        
            | 
            | 
           37 | 
               public function init()
  | 
        
        
            | 
            | 
           38 | 
               {
  | 
        
        
            | 
            | 
           39 | 
                   $this->title = get_string('pluginname', 'block_mynotes');
  | 
        
        
            | 
            | 
           40 | 
               }
  | 
        
        
            | 
            | 
           41 | 
              | 
        
        
            | 
            | 
           42 | 
               public function has_config()
  | 
        
        
            | 
            | 
           43 | 
               {
  | 
        
        
            | 
            | 
           44 | 
                   return true;
  | 
        
        
            | 
            | 
           45 | 
               }
  | 
        
        
            | 
            | 
           46 | 
              | 
        
        
            | 
            | 
           47 | 
               public function applicable_formats()
  | 
        
        
            | 
            | 
           48 | 
               {
  | 
        
        
            | 
            | 
           49 | 
                   return array('all' => true);
  | 
        
        
            | 
            | 
           50 | 
               }
  | 
        
        
            | 
            | 
           51 | 
              | 
        
        
            | 
            | 
           52 | 
               public function instance_allow_multiple()
  | 
        
        
            | 
            | 
           53 | 
               {
  | 
        
        
            | 
            | 
           54 | 
                   return false;
  | 
        
        
            | 
            | 
           55 | 
               }
  | 
        
        
            | 
            | 
           56 | 
              | 
        
        
            | 
            | 
           57 | 
               public function hide_header()
  | 
        
        
            | 
            | 
           58 | 
               {
  | 
        
        
            | 
            | 
           59 | 
                   global $PAGE;
  | 
        
        
            | 
            | 
           60 | 
                   if (!$PAGE->user_is_editing()) {
  | 
        
        
            | 
            | 
           61 | 
                       return true;
  | 
        
        
            | 
            | 
           62 | 
                   }
  | 
        
        
            | 
            | 
           63 | 
               }
  | 
        
        
            | 
            | 
           64 | 
              | 
        
        
            | 
            | 
           65 | 
               /**
  | 
        
        
            | 
            | 
           66 | 
                * The content object.
  | 
        
        
            | 
            | 
           67 | 
                *
  | 
        
        
            | 
            | 
           68 | 
                * @return stdObject
  | 
        
        
            | 
            | 
           69 | 
                */
  | 
        
        
            | 
            | 
           70 | 
               public function get_content()
  | 
        
        
            | 
            | 
           71 | 
               {
  | 
        
        
            | 
            | 
           72 | 
                   global $CFG, $PAGE;
  | 
        
        
            | 
            | 
           73 | 
              | 
        
        
            | 
            | 
           74 | 
                   static $jscount = 0;
  | 
        
        
            | 
            | 
           75 | 
                   if ($this->content !== null) {
  | 
        
        
            | 
            | 
           76 | 
                       return $this->content;
  | 
        
        
            | 
            | 
           77 | 
                   }
  | 
        
        
            | 
            | 
           78 | 
              | 
        
        
            | 
            | 
           79 | 
                   if (!isloggedin() or isguestuser()) {
  | 
        
        
            | 
            | 
           80 | 
                       return '';      // Never useful unless you are logged in as real users
  | 
        
        
            | 
            | 
           81 | 
                   }
  | 
        
        
            | 
            | 
           82 | 
              | 
        
        
            | 
            | 
           83 | 
                   if (!in_array($PAGE->context->contextlevel, array(CONTEXT_COURSE, CONTEXT_SYSTEM, CONTEXT_MODULE, CONTEXT_USER))) {
  | 
        
        
            | 
            | 
           84 | 
                       return '';
  | 
        
        
            | 
            | 
           85 | 
                   }
  | 
        
        
            | 
            | 
           86 | 
              | 
        
        
            | 
            | 
           87 | 
                   $this->content = new stdClass();
  | 
        
        
            | 
            | 
           88 | 
                   $this->content->footer = '';
  | 
        
        
            | 
            | 
           89 | 
                   $this->content->text = '';
  | 
        
        
            | 
            | 
           90 | 
                   if (empty($this->instance)) {
  | 
        
        
            | 
            | 
           91 | 
                       return $this->content;
  | 
        
        
            | 
            | 
           92 | 
                   }
  | 
        
        
            | 
            | 
           93 | 
              | 
        
        
            | 
            | 
           94 | 
                   $this->content = new stdClass();
  | 
        
        
            | 
            | 
           95 | 
                   $this->content->text = '';
  | 
        
        
            | 
            | 
           96 | 
                   if ($PAGE->user_is_editing()) {
  | 
        
        
            | 
            | 
           97 | 
                       $this->content->text = '<div class="inline-mynotes-opener">' . get_string('showmynotes', 'block_mynotes') . '</div>';
  | 
        
        
            | 
            | 
           98 | 
                   }
  | 
        
        
            | 
            | 
           99 | 
                   $this->content->footer = '';
  | 
        
        
            | 
            | 
           100 | 
              | 
        
        
            | 
            | 
           101 | 
                   if ($jscount == 0) {
  | 
        
        
            | 
            | 
           102 | 
                       $this->block_mynotes_get_required_javascript();
  | 
        
        
            | 
            | 
           103 | 
                       $jscount++;
  | 
        
        
            | 
            | 
           104 | 
                   }
  | 
        
        
            | 
            | 
           105 | 
                   return $this->content;
  | 
        
        
            | 
            | 
           106 | 
               }
  | 
        
        
            | 
            | 
           107 | 
              | 
        
        
            | 
            | 
           108 | 
               /*
  | 
        
        
            | 
            | 
           109 | 
                * load JS that requires into the page.
  | 
        
        
            | 
            | 
           110 | 
                */
  | 
        
        
            | 
            | 
           111 | 
               private function block_mynotes_get_required_javascript()
  | 
        
        
            | 
            | 
           112 | 
               {
  | 
        
        
            | 
            | 
           113 | 
                   global $PAGE, $CFG;
  | 
        
        
            | 
            | 
           114 | 
                   list($context, $course, $cm) = get_context_info_array($PAGE->context->id);
  | 
        
        
            | 
            | 
           115 | 
                   $config = get_config('block_mynotes');
  | 
        
        
            | 
            | 
           116 | 
              | 
        
        
            | 
            | 
           117 | 
                   $mm = new block_mynotes_manager();
  | 
        
        
            | 
            | 
           118 | 
                   $currenttabindex = $mm->get_current_tab($context, $PAGE);
  | 
        
        
            | 
            | 
           119 | 
                   $arguments = array(
  | 
        
        
            | 
            | 
           120 | 
                       'arg' => array(
  | 
        
        
            | 
            | 
           121 | 
                           'instanceid' => $this->instance->id,
  | 
        
        
            | 
            | 
           122 | 
                           'editing' => ($PAGE->user_is_editing()),
  | 
        
        
            | 
            | 
           123 | 
                           'editingicon_pos' => ($PAGE->user_is_editing()) ? 'mynotes-pos-inline' : $config->icondisplayposition,
  | 
        
        
            | 
            | 
           124 | 
                           'maxallowedcharacters' => $config->characterlimit,
  | 
        
        
            | 
            | 
           125 | 
                           'contextid' => $context->id,
  | 
        
        
            | 
            | 
           126 | 
                           'maxallowedcharacters_warning' => get_string('notmorethan', 'block_mynotes', $config->characterlimit),
  | 
        
        
            | 
            | 
           127 | 
                           'contextareas' => $mm->get_available_contextareas(),
  | 
        
        
            | 
            | 
           128 | 
                           'currenttabindex' => ($currenttabindex == null ? 'site' : $currenttabindex),
  | 
        
        
            | 
            | 
           129 | 
                           'perpage' => $config->mynotesperpage,
  | 
        
        
            | 
            | 
           130 | 
                       ),
  | 
        
        
            | 
            | 
           131 | 
                   );
  | 
        
        
            | 
            | 
           132 | 
                   $PAGE->requires->string_for_js('charactersleft', 'block_mynotes');
  | 
        
        
            | 
            | 
           133 | 
                   $PAGE->requires->string_for_js('notmorethan', 'block_mynotes');
  | 
        
        
            | 
            | 
           134 | 
                   $PAGE->requires->string_for_js('mynotes', 'block_mynotes');
  | 
        
        
            | 
            | 
           135 | 
                   $PAGE->requires->string_for_js('showmynotes', 'block_mynotes');
  | 
        
        
            | 
            | 
           136 | 
                   $PAGE->requires->string_for_js('savedsuccess', 'block_mynotes');
  | 
        
        
            | 
            | 
           137 | 
                   $PAGE->requires->string_for_js('save', 'block_mynotes');
  | 
        
        
            | 
            | 
           138 | 
                   $PAGE->requires->string_for_js('placeholdercontent', 'block_mynotes');
  | 
        
        
            | 
            | 
           139 | 
                   $PAGE->requires->string_for_js('deletemynotes', 'block_mynotes');
  | 
        
        
            | 
            | 
           140 | 
                   $PAGE->requires->string_for_js('mynotescount', 'block_mynotes');
  | 
        
        
            | 
            | 
           141 | 
                   $PAGE->requires->string_for_js('previouspage', 'block_mynotes');
  | 
        
        
            | 
            | 
           142 | 
                   $PAGE->requires->string_for_js('nextpage', 'block_mynotes');
  | 
        
        
            | 
            | 
           143 | 
                   $PAGE->requires->string_for_js('nothingtodisplay', 'block_mynotes');
  | 
        
        
            | 
            | 
           144 | 
                   $PAGE->requires->string_for_js('mynotessavedundertab', 'block_mynotes');
  | 
        
        
            | 
            | 
           145 | 
                   $PAGE->requires->string_for_js('cancel', 'moodle');
  | 
        
        
            | 
            | 
           146 | 
                   $PAGE->requires->js_call_amd('block_mynotes/mynotes', 'init', $arguments);
  | 
        
        
            | 
            | 
           147 | 
               }
  | 
        
        
            | 
            | 
           148 | 
           }
  |