You are here

function course_uc_tokens in Course 7

Same name and namespace in other branches
  1. 8.3 modules/course_uc/course_uc.module \course_uc_tokens()
  2. 8.2 modules/course_uc/course_uc.module \course_uc_tokens()
  3. 7.2 modules/course_uc/course_uc.module \course_uc_tokens()

Implements hook_token_values().

File

modules/course_uc/course_uc.module, line 404

Code

function course_uc_tokens($type, $tokens, array $data = array(), array $options = array()) {
  if ($type == 'uc_order') {
    $object = $data['uc_order'];
    $show_header = FALSE;
    foreach ($object->products as $product) {
      $node = node_load($product->nid);
      if (course_node_is_course($node)) {
        $line = $node->title . ' - ' . l('View course page', "node/{$node->nid}");
        $result = course_take_course_access($node, NULL, TRUE);
        if (course_node_is_course($node) && $result['success']) {
          $line .= ' or ' . l('Take course now', "node/{$node->nid}/takecourse");
        }
        $courses[] = $line;
        $show_header = TRUE;
      }
      $items[] = l($node->title, "node/{$node->nid}");
    }
    $values = array();
    if ($show_header) {
      $values['course-products-header'] = t("Here are the courses you have purchased:");
      $values['course-products'] = theme('item_list', array(
        'title' => '',
        'items' => $courses,
      ));
    }
    $replacements = array();
    foreach ($tokens as $name => $original) {
      switch ($name) {
        case 'course-products-header':
          $replacements[$original] = $values['course-products-header'];
          break;
        case 'course-products':
          $replacements[$original] = $values['course-products'];
          break;
      }
    }
    return $replacements;
  }
}