/**
  * Returns coursecat object for requested category
  *
  * If category is not visible to user it is treated as non existing
  * unless $alwaysreturnhidden is set to true
  *
  * If id is 0, the pseudo object for root category is returned (convenient
  * for calling other functions such as get_children())
  *
  * @param int $id category id
  * @param int $strictness whether to throw an exception (MUST_EXIST) or
  *     return null (IGNORE_MISSING) in case the category is not found or
  *     not visible to current user
  * @param bool $alwaysreturnhidden set to true if you want an object to be
  *     returned even if this category is not visible to the current user
  *     (category is hidden and user does not have
  *     'moodle/category:viewhiddencategories' capability). Use with care!
  * @return null|coursecat
  * @throws moodle_exception
  */
 public static function get($id, $strictness = MUST_EXIST, $alwaysreturnhidden = false)
 {
     if (!$id) {
         if (!isset(self::$coursecat0)) {
             $record = new stdClass();
             $record->id = 0;
             $record->visible = 1;
             $record->depth = 0;
             $record->path = '';
             self::$coursecat0 = new coursecat($record);
         }
         return self::$coursecat0;
     }
     $coursecatrecordcache = cache::make('core', 'coursecatrecords');
     $coursecat = $coursecatrecordcache->get($id);
     if ($coursecat === false) {
         if ($records = self::get_records('cc.id = :id', array('id' => $id))) {
             $record = reset($records);
             $coursecat = new coursecat($record);
             // Store in cache.
             $coursecatrecordcache->set($id, $coursecat);
         }
     }
     if ($coursecat && ($alwaysreturnhidden || $coursecat->is_uservisible())) {
         return $coursecat;
     } else {
         if ($strictness == MUST_EXIST) {
             throw new moodle_exception('unknowncategory');
         }
     }
     return null;
 }