/**
  * Gets the required context.
  *
  * Getting a context you get access to all the steps
  * that uses direct API calls; steps returning step chains
  * can not be executed like this.
  *
  * @throws coding_exception
  * @param string $classname Context identifier (the class name).
  * @return behat_base
  */
 public static function get($classname)
 {
     if (!($subcontext = self::$environment->getContext($classname))) {
         throw coding_exception('The required "' . $classname . '" class does not exist');
     }
     return $subcontext;
 }
 /**
  * Gets the required context.
  *
  * Getting a context you get access to all the steps
  * that uses direct API calls; steps returning step chains
  * can not be executed like this.
  *
  * @throws coding_exception
  * @param string $classname Context identifier (the class name).
  * @return behat_base
  */
 public static function get($classname)
 {
     if (!self::init_context($classname)) {
         throw coding_exception('The required "' . $classname . '" class does not exist');
     }
     return self::$contexts[$classname];
 }
 /**
  * Gets the required context.
  *
  * Getting a context you get access to all the steps
  * that uses direct API calls; steps returning step chains
  * can not be executed like this.
  *
  * @throws coding_exception
  * @param string $classname Context identifier (the class name).
  * @return behat_base
  */
 public static function get($classname)
 {
     if (!($subcontext = self::$maincontext->getSubcontextByClassName($classname))) {
         throw coding_exception('The required "' . $classname . '" class does not exist');
     }
     return $subcontext;
 }
Exemple #4
0
 /**
  * A proxy constructor
  *
  * @param mixed $navnode A navigation_node or an array
  */
 public function __construct($navnode)
 {
     if (is_array($navnode)) {
         parent::__construct($navnode);
     } else {
         if ($navnode instanceof navigation_node) {
             // Just clone everything.
             $objvalues = get_object_vars($navnode);
             foreach ($objvalues as $key => $value) {
                 $this->{$key} = $value;
             }
         } else {
             throw coding_exception('Not a valid breadcrumb_navigation_node');
         }
     }
 }
Exemple #5
0
 /**
  * Returns the result of {@link core_component::get_plugin_types()} ordered for humans
  *
  * @see self::reorder_plugin_types()
  * @return array (string)name => (string)location
  */
 public function get_plugin_types()
 {
     if (func_num_args() > 0) {
         if (!func_get_arg(0)) {
             throw coding_exception('core_plugin_manager->get_plugin_types() does not support relative paths.');
         }
     }
     if ($this->plugintypes) {
         return $this->plugintypes;
     }
     $this->plugintypes = $this->reorder_plugin_types(core_component::get_plugin_types());
     return $this->plugintypes;
 }
Exemple #6
0
 public function set_usage_id($usageid)
 {
     coding_exception('Cannot modify a question_attempt_with_restricted_history.');
 }
Exemple #7
0
 /**
  * Moves the tag collection in the list one position up or down
  *
  * @param stdClass $tagcoll existing record in DB table tag_coll
  * @param int $direction move direction: +1 or -1
  * @return bool
  */
 public static function change_sortorder($tagcoll, $direction)
 {
     global $DB;
     if ($direction != -1 && $direction != 1) {
         throw coding_exception('Second argument in tag_coll_change_sortorder() can be only 1 or -1');
     }
     $tagcolls = self::get_collections();
     $keys = array_keys($tagcolls);
     $idx = array_search($tagcoll->id, $keys);
     if ($idx === false || $idx == 0 || $idx + $direction < 1 || $idx + $direction >= count($tagcolls)) {
         return false;
     }
     $otherid = $keys[$idx + $direction];
     $DB->update_record('tag_coll', array('id' => $tagcoll->id, 'sortorder' => $idx + $direction));
     $DB->update_record('tag_coll', array('id' => $otherid, 'sortorder' => $idx));
     // Reset cache.
     cache::make('core', 'tags')->delete('tag_coll');
     return true;
 }
Exemple #8
0
/**
 * Checks whether a plugin supports a specified feature.
 *
 * @param string $type Plugin type e.g. 'mod'
 * @param string $name Plugin name e.g. 'forum'
 * @param string $feature Feature code (FEATURE_xx constant)
 * @param mixed $default default value if feature support unknown
 * @return mixed Feature result (false if not supported, null if feature is unknown,
 *         otherwise usually true but may have other feature-specific value such as array)
 */
function plugin_supports($type, $name, $feature, $default = NULL)
{
    global $CFG;
    if ($type === 'mod' and $name === 'NEWMODULE') {
        //somebody forgot to rename the module template
        return false;
    }
    $component = clean_param($type . '_' . $name, PARAM_COMPONENT);
    if (empty($component)) {
        throw coding_exception('Invalid component used in plugin_supports():' . $type . '_' . $name);
    }
    $function = null;
    if ($type === 'mod') {
        // we need this special case because we support subplugins in modules,
        // otherwise it would end up in infinite loop
        if (file_exists("{$CFG->dirroot}/mod/{$name}/lib.php")) {
            include_once "{$CFG->dirroot}/mod/{$name}/lib.php";
            $function = $component . '_supports';
            if (!function_exists($function)) {
                // legacy non-frankenstyle function name
                $function = $name . '_supports';
            }
        } else {
            // invalid module
        }
    } else {
        if (!($path = get_plugin_directory($type, $name))) {
            // non existent plugin type
            return false;
        }
        if (file_exists("{$path}/lib.php")) {
            include_once "{$path}/lib.php";
            $function = $component . '_supports';
        }
    }
    if ($function and function_exists($function)) {
        $supports = $function($feature);
        if (is_null($supports)) {
            // plugin does not know - use default
            return $default;
        } else {
            return $supports;
        }
    }
    //plugin does not care, so use default
    return $default;
}
 /**
  * Loads all categories (top level or if an id is specified for that category)
  *
  * @param int $categoryid The category id to load or null/0 to load all base level categories
  * @param bool $showbasecategories If set to true all base level categories will be loaded as well
  *        as the requested category and any parent categories.
  * @return void
  */
 protected function load_all_categories($categoryid = null, $showbasecategories = false)
 {
     global $DB;
     // Check if this category has already been loaded
     if ($categoryid !== null && array_key_exists($categoryid, $this->addedcategories) && $this->addedcategories[$categoryid]->children->count() > 0) {
         return $this->addedcategories[$categoryid];
     }
     $coursestoload = array();
     if (empty($categoryid)) {
         // can be 0
         // We are going to load all of the first level categories (categories without parents)
         $categories = $DB->get_records('course_categories', array('parent' => '0'), 'sortorder ASC, id ASC');
     } else {
         if (array_key_exists($categoryid, $this->addedcategories)) {
             // The category itself has been loaded already so we just need to ensure its subcategories
             // have been loaded
             list($sql, $params) = $DB->get_in_or_equal(array_keys($this->addedcategories), SQL_PARAMS_NAMED, 'parent', false);
             if ($showbasecategories) {
                 // We need to include categories with parent = 0 as well
                 $sql = "SELECT *\n                          FROM {course_categories} cc\n                         WHERE (parent = :categoryid OR parent = 0) AND\n                               parent {$sql}\n                      ORDER BY depth DESC, sortorder ASC, id ASC";
             } else {
                 $sql = "SELECT *\n                          FROM {course_categories} cc\n                         WHERE parent = :categoryid AND\n                               parent {$sql}\n                      ORDER BY depth DESC, sortorder ASC, id ASC";
             }
             $params['categoryid'] = $categoryid;
             $categories = $DB->get_records_sql($sql, $params);
             if (count($categories) == 0) {
                 // There are no further categories that require loading.
                 return;
             }
         } else {
             // This category hasn't been loaded yet so we need to fetch it, work out its category path
             // and load this category plus all its parents and subcategories
             $category = $DB->get_record('course_categories', array('id' => $categoryid), 'path', MUST_EXIST);
             $coursestoload = explode('/', trim($category->path, '/'));
             list($select, $params) = $DB->get_in_or_equal($coursestoload);
             $select = 'id ' . $select . ' OR parent ' . $select;
             if ($showbasecategories) {
                 $select .= ' OR parent = 0';
             }
             $params = array_merge($params, $params);
             $categories = $DB->get_records_select('course_categories', $select, $params, 'sortorder');
         }
     }
     // Now we have an array of categories we need to add them to the navigation.
     while (!empty($categories)) {
         $category = reset($categories);
         if (array_key_exists($category->id, $this->addedcategories)) {
             // Do nothing
         } else {
             if ($category->parent == '0') {
                 $this->add_category($category, $this->rootnodes['courses']);
             } else {
                 if (array_key_exists($category->parent, $this->addedcategories)) {
                     $this->add_category($category, $this->addedcategories[$category->parent]);
                 } else {
                     // This category isn't in the navigation and niether is it's parent (yet).
                     // We need to go through the category path and add all of its components in order.
                     $path = explode('/', trim($category->path, '/'));
                     foreach ($path as $catid) {
                         if (!array_key_exists($catid, $this->addedcategories)) {
                             // This category isn't in the navigation yet so add it.
                             $subcategory = $categories[$catid];
                             if ($subcategory->parent == '0') {
                                 // Yay we have a root category - this likely means we will now be able
                                 // to add categories without problems.
                                 $this->add_category($subcategory, $this->rootnodes['courses']);
                             } else {
                                 if (array_key_exists($subcategory->parent, $this->addedcategories)) {
                                     // The parent is in the category (as we'd expect) so add it now.
                                     $this->add_category($subcategory, $this->addedcategories[$subcategory->parent]);
                                     // Remove the category from the categories array.
                                     unset($categories[$catid]);
                                 } else {
                                     // We should never ever arrive here - if we have then there is a bigger
                                     // problem at hand.
                                     throw coding_exception('Category path order is incorrect and/or there are missing categories');
                                 }
                             }
                         }
                     }
                 }
             }
         }
         // Remove the category from the categories array now that we know it has been added.
         unset($categories[$category->id]);
     }
     // Check if there are any categories to load.
     if (count($coursestoload) > 0) {
         $this->load_all_courses($coursestoload);
     }
 }