/**
  * Performs all the operations in order to display the block output:
  *  - Checks if it is the first time that the block is loaded in the course, to check if the course is personalizable
  *    or not.
  *  - Checks if the current user is selected to receive the recommendations.
  *  - Retrieves the recommendations from the database.
  *
  * @return string The content of the block.
  */
 public function get_content()
 {
     global $COURSE, $USER, $DB;
     if ($this->content !== null) {
         return $this->content;
     }
     if (empty($this->instance)) {
         $this->content = '';
         return $this->content;
     }
     $this->content = new stdClass();
     $this->content->text = '';
     $context = context_course::instance($COURSE->id);
     if (has_capability('block/mycourse_recommendations:importfromcsv', $context)) {
         $this->content->footer = $this->generate_footer_import_url($COURSE->id);
     } else {
         $this->content->footer = '';
     }
     $courseyear = $this->db->get_course_start_week_and_year($COURSE->id)['year'];
     $firstinstance = $this->db->is_blocks_first_instance($COURSE->id);
     if ($firstinstance) {
         $this->initialize_course($COURSE->id, $courseyear);
     }
     $isuser = has_capability('block/mycourse_recommendations:recommendationstext', $context);
     if ($isuser) {
         $personalizable = $this->db->is_course_personalizable($COURSE->id);
         if ($personalizable) {
             $active = $this->db->is_course_active($COURSE->id);
             if ($active) {
                 $userselected = $this->db->is_user_selected_for_course($USER->id, $COURSE->id);
                 if (!$userselected) {
                     $this->content->text = get_string('usernotselected', 'block_mycourse_recommendations');
                 } else {
                     $currentweek = $this->get_current_week();
                     $recommendations = $this->db->get_recommendations($COURSE->id, $USER->id, $currentweek);
                     $this->content->text = recommendations_renderer::render_recommendations($recommendations);
                 }
             } else {
                 $this->content->text = get_string('inactive', 'block_mycourse_recommendations');
             }
         } else {
             $this->content->text = get_string('notpersonalizable', 'block_mycourse_recommendations');
         }
     } else {
         $this->content->text = get_string('notastudent', 'block_mycourse_recommendations');
     }
     return $this->content;
 }