public function test_render_recommendations_above()
 {
     global $COURSE, $USER;
     $this->resetAfterTest();
     $this->setAdminUser();
     $resourcenumber = recommendations_renderer::MAX_RECOMMENDATIONS + 1;
     $course = $this->getDataGenerator()->create_course();
     $courseid = $course->id;
     $COURSE = $course;
     $resources = $this->create_resources($courseid, $resourcenumber);
     $recommendations = array();
     foreach ($resources as $index => $resource) {
         $recommendations[$index] = new stdClass();
         $recommendations[$index]->id = 0;
         $recommendations[$index]->resourceid = $resource->id;
         $recommendations[$index]->priority = $index;
     }
     $actual = recommendations_renderer::render_recommendations($recommendations);
     $expected = '<ol>';
     $resources = array_values($resources);
     foreach ($resources as $index => $resource) {
         if ($index === 3) {
             break;
         }
         $url = new \moodle_url('/blocks/mycourse_recommendations/redirect_to_resource.php', array('recommendationid' => 0, 'modname' => 'page', 'moduleid' => $resource->cmid));
         $expected .= '<li>';
         $expected .= "<a href='{$url}' target='_blank'>";
         $expected .= $resource->name;
         $expected .= '</a>';
         $expected .= '</li>';
     }
     $expected .= '</ol>';
     $this->assertEquals($expected, $actual);
 }
 /**
  * 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;
 }