You are here

class context_to_string_translator in Quiz 6.6

Same name and namespace in other branches
  1. 6.5 includes/moodle/lib/questionlib.php \context_to_string_translator

Hierarchy

Expanded class hierarchy of context_to_string_translator

File

includes/moodle/lib/questionlib.php, line 2126

View source
class context_to_string_translator {

  /**
   * @var array used to translate between contextids and strings for this context.
   */
  var $contexttostringarray = array();
  function context_to_string_translator($contexts) {
    $this
      ->generate_context_to_string_array($contexts);
  }
  function context_to_string($contextid) {
    return $this->contexttostringarray[$contextid];
  }
  function string_to_context($contextname) {
    $contextid = array_search($contextname, $this->contexttostringarray);
    return $contextid;
  }
  function generate_context_to_string_array($contexts) {
    if (!$this->contexttostringarray) {
      $catno = 1;
      foreach ($contexts as $context) {
        switch ($context->contextlevel) {
          case CONTEXT_MODULE:
            $contextstring = 'module';
            break;
          case CONTEXT_COURSE:
            $contextstring = 'course';
            break;
          case CONTEXT_COURSECAT:
            $contextstring = "cat{$catno}";
            $catno++;
            break;
          case CONTEXT_SYSTEM:
            $contextstring = 'system';
            break;
        }
        $this->contexttostringarray[$context->id] = $contextstring;
      }
    }
  }

}

Members