You are here

function course_outline_show_complete_links in Course 6

Render a landing page for course completion.

@todo change the name of this function (since it's more than just completion links).

Parameters

stdClass $course_node A course node.:

Return value

string HTML for the landing page.

1 string reference to 'course_outline_show_complete_links'
course_menu in ./course.module
Implements hook_menu().

File

includes/course.outline.inc, line 522
course_outline.inc

Code

function course_outline_show_complete_links($course_node) {
  global $user;
  $account = $user;
  $report = course_report_load($course_node, $account);
  $txt_out = '';
  if ($report->complete) {
    $txt_out .= '<p>' . t('Thank you for participating in this activity.') . '</p>';
    $links = array(
      'course' => array(
        'Return to course',
        "node/{$course_node->nid}",
        'Return to the course to view course details and material.',
      ),
    );

    // Allow modules to add links to the course completion landing page, such as
    // post-course actions.
    drupal_alter('course_outline_completion_links', $links, $course_node, $account);
    foreach ($links as $link) {

      // @todo change the way $links work. Replace the three element array with
      // something else. Maybe $element and $value from theme_form_element() if
      // we must be this controlling?
      // Example:
      // @code
      //   $element = t('A description');
      //   $value = l($text, $path);
      //   $links = array('element' => $element, 'value' => $value).
      // @endcode
      // But why not allow modules to alter the landing page however they want
      // (instead of requiring 'links' with this very specific output format)?
      $txt_out .= theme('form_element', array(
        '#description' => $link[2],
      ), l($link[0], $link[1]));
    }
  }
  else {
    $course = course_get_course($course_node, $account);
    $objects = $course
      ->getObjects();
    $requirements_outstanding = array();
    foreach ($objects as $courseObject) {

      // Find required course objects the user has not yet completed.
      if ($courseObject
        ->getOption('required') && !$courseObject
        ->getOption('complete')) {
        $requirements_outstanding[$courseObject
          ->getId()] = $courseObject
          ->getFulfillment();
      }
    }
    $items = array();
    foreach ($requirements_outstanding as $req) {
      $status_css = $req->complete ? 'complete' : 'incomplete';
      $status_img = $req->complete ? 'ok' : ($req->required ? 'error' : 'warning');
      $status_optional = $status_img == 'warning' ? ' (optional)' : '';
      $grade = $req->graded ? ' - Your grade: ' . $req->grade_result . '%, Pass grade: ' . $req->passing_grade . '%' : '';
      $items[] = array(
        array(
          'data' => theme('image', "misc/watchdog-{$status_img}.png", $status_css),
          'width' => 20,
        ),
        $req->title . $status_optional . $grade,
      );
    }
    $reqs_txt = theme('table', NULL, $items);
    $txt_out .= '<p>' . t('You must complete the remaining requirements to proceed.') . '</p>';
    $txt_out .= $reqs_txt . '<div class="homelink"><p>' . l($course_out_return_array['course_outline_link_text'], $course_out_return_array['course_outline_link']) . '</p></div>';
    $links = array(
      'course' => array(
        'Return to course',
        "node/{$course_node->nid}/takecourse",
        'Return to the course to view course details and material.',
      ),
    );

    // Allow modules to alter remaining requirement links on the course
    // completion landing page.
    drupal_alter('course_outline_incomplete_links', $links, $course_node, $account);
    foreach ($links as $link) {
      $txt_out .= theme('form_element', array(
        '#description' => $link[2],
      ), l($link[0], $link[1]));
    }
  }
  return $txt_out;
}