当前位置: 首页>>代码示例>>PHP>>正文


PHP question_is_only_toplevel_category_in_context函数代码示例

本文整理汇总了PHP中question_is_only_toplevel_category_in_context函数的典型用法代码示例。如果您正苦于以下问题:PHP question_is_only_toplevel_category_in_context函数的具体用法?PHP question_is_only_toplevel_category_in_context怎么用?PHP question_is_only_toplevel_category_in_context使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了question_is_only_toplevel_category_in_context函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: definition

 function definition()
 {
     global $CFG, $DB;
     $mform =& $this->_form;
     $contexts = $this->_customdata['contexts'];
     $currentcat = $this->_customdata['currentcat'];
     //--------------------------------------------------------------------------------
     $mform->addElement('header', 'categoryheader', get_string('addcategory', 'quiz'));
     $questioncategoryel = $mform->addElement('questioncategory', 'parent', get_string('parent', 'quiz'), array('contexts' => $contexts, 'top' => true, 'currentcat' => $currentcat, 'nochildrenof' => $currentcat));
     $mform->setType('parent', PARAM_SEQUENCE);
     if (question_is_only_toplevel_category_in_context($currentcat)) {
         $mform->hardFreeze('parent');
     }
     $mform->setHelpButton('parent', array('categoryparent', get_string('parent', 'quiz'), 'question'));
     $mform->addElement('text', 'name', get_string('name'), 'maxlength="254" size="50"');
     $mform->setDefault('name', '');
     $mform->addRule('name', get_string('categorynamecantbeblank', 'quiz'), 'required', null, 'client');
     $mform->setType('name', PARAM_MULTILANG);
     $mform->addElement('textarea', 'info', get_string('categoryinfo', 'quiz'), array('rows' => '10', 'cols' => '45'));
     $mform->setDefault('info', '');
     $mform->setType('info', PARAM_MULTILANG);
     //--------------------------------------------------------------------------------
     $this->add_action_buttons(false, get_string('addcategory', 'quiz'));
     //--------------------------------------------------------------------------------
     $mform->addElement('hidden', 'id', 0);
     $mform->setType('id', PARAM_INT);
 }
开发者ID:ajv,项目名称:Offline-Caching,代码行数:27,代码来源:category_form.php

示例2: question_can_delete_cat

/**
 * Check whether this user is allowed to delete this category.
 *
 * @param integer $todelete a category id.
 */
function question_can_delete_cat($todelete)
{
    if (question_is_only_toplevel_category_in_context($todelete)) {
        error('You can\'t delete that category it is the default category for this context.');
    } else {
        $contextid = get_field('question_categories', 'contextid', 'id', $todelete);
        require_capability('moodle/question:managecategory', get_context_instance_by_id($contextid));
    }
}
开发者ID:edwinphillips,项目名称:moodle-485cb39,代码行数:14,代码来源:editlib.php

示例3: question_can_delete_cat

/**
 * Check whether this user is allowed to delete this category.
 *
 * @param int $todelete a category id.
 */
function question_can_delete_cat($todelete)
{
    global $DB;
    if (question_is_only_toplevel_category_in_context($todelete)) {
        print_error('cannotdeletecate', 'question');
    } else {
        $contextid = $DB->get_field('question_categories', 'contextid', array('id' => $todelete));
        require_capability('moodle/question:managecategory', context::instance_by_id($contextid));
    }
}
开发者ID:janaece,项目名称:globalclassroom4_clean,代码行数:15,代码来源:editlib.php

示例4: update_category

    /**
     * Updates an existing category with given params
     */
    public function update_category($updateid, $newparent, $newname, $newinfo) {
        global $CFG, $DB;
        if (empty($newname)) {
            print_error('categorynamecantbeblank', 'question');
        }

        // Get the record we are updating.
        $oldcat = $DB->get_record('question_categories', array('id' => $updateid));
        $lastcategoryinthiscontext = question_is_only_toplevel_category_in_context($updateid);

        if (!empty($newparent) && !$lastcategoryinthiscontext) {
            list($parentid, $tocontextid) = explode(',', $newparent);
        } else {
            $parentid = $oldcat->parent;
            $tocontextid = $oldcat->contextid;
        }

        // Check permissions.
        $fromcontext = context::instance_by_id($oldcat->contextid);
        require_capability('moodle/question:managecategory', $fromcontext);

        // If moving to another context, check permissions some more.
        if ($oldcat->contextid != $tocontextid) {
            $tocontext = context::instance_by_id($tocontextid);
            require_capability('moodle/question:managecategory', $tocontext);
        }

        // Update the category record.
        $cat = new stdClass();
        $cat->id = $updateid;
        $cat->name = $newname;
        $cat->info = $newinfo;
        $cat->parent = $parentid;
        $cat->contextid = $tocontextid;
        $DB->update_record('question_categories', $cat);

        // If the category name has changed, rename any random questions in that category.
        if ($oldcat->name != $cat->name) {
            $where = "qtype = 'random' AND category = ? AND " . $DB->sql_compare_text('questiontext') . " = ?";

            $randomqtype = question_bank::get_qtype('random');
            $randomqname = $randomqtype->question_name($cat, false);
            $DB->set_field_select('question', 'name', $randomqname, $where, array($cat->id, '0'));

            $randomqname = $randomqtype->question_name($cat, true);
            $DB->set_field_select('question', 'name', $randomqname, $where, array($cat->id, '1'));
        }

        if ($oldcat->contextid != $tocontextid) {
            // Moving to a new context. Must move files belonging to questions.
            question_move_category_to_context($cat->id, $oldcat->contextid, $tocontextid);
        }

        // Cat param depends on the context id, so update it.
        $this->pageurl->param('cat', $updateid . ',' . $tocontextid);
        redirect($this->pageurl);
    }
开发者ID:Jtgadbois,项目名称:Pedadida,代码行数:60,代码来源:category_class.php

示例5: update_category

 /**
  * Updates an existing category with given params
  */
 function update_category($updateid, $newparent, $newname, $newinfo)
 {
     global $CFG, $QTYPES;
     if (empty($newname)) {
         print_error('categorynamecantbeblank', 'quiz');
     }
     // Get the record we are updating.
     $oldcat = get_record('question_categories', 'id', $updateid);
     $lastcategoryinthiscontext = question_is_only_toplevel_category_in_context($updateid);
     if (!empty($newparent) && !$lastcategoryinthiscontext) {
         list($parentid, $tocontextid) = explode(',', $newparent);
     } else {
         $parentid = $oldcat->parent;
         $tocontextid = $oldcat->contextid;
     }
     // Check permissions.
     $fromcontext = get_context_instance_by_id($oldcat->contextid);
     require_capability('moodle/question:managecategory', $fromcontext);
     // If moving to another context, check permissions some more.
     if ($oldcat->contextid != $tocontextid) {
         $tocontext = get_context_instance_by_id($tocontextid);
         require_capability('moodle/question:managecategory', $tocontext);
     }
     // Update the category record.
     $cat = NULL;
     $cat->id = $updateid;
     $cat->name = $newname;
     $cat->info = $newinfo;
     $cat->parent = $parentid;
     // We don't change $cat->contextid here, if necessary we redirect to contextmove.php later.
     if (!update_record("question_categories", $cat)) {
         error("Could not update the category '{$newname}'", $this->pageurl->out());
     }
     // If the category name has changed, rename any random questions in that category.
     if (addslashes($oldcat->name) != $cat->name) {
         $randomqname = $QTYPES[RANDOM]->question_name($cat);
         set_field('question', 'name', addslashes($randomqname), 'category', $cat->id, 'qtype', RANDOM);
         // Ignore errors here. It is not a big deal if the questions are not renamed.
     }
     // Then redirect to an appropriate place.
     if ($oldcat->contextid == $tocontextid) {
         // not moving contexts
         redirect($this->pageurl->out());
     } else {
         redirect($CFG->wwwroot . '/question/contextmove.php?' . $this->pageurl->get_query_string(array('cattomove' => $updateid, 'toparent' => $newparent)));
     }
 }
开发者ID:kai707,项目名称:ITSA-backup,代码行数:50,代码来源:category_class.php

示例6: update_category

 /**
  * Updates an existing category with given params
  */
 public function update_category($updateid, $newparent, $newname, $newinfo)
 {
     global $CFG, $QTYPES, $DB;
     if (empty($newname)) {
         print_error('categorynamecantbeblank', 'quiz');
     }
     // Get the record we are updating.
     $oldcat = $DB->get_record('question_categories', array('id' => $updateid));
     $lastcategoryinthiscontext = question_is_only_toplevel_category_in_context($updateid);
     if (!empty($newparent) && !$lastcategoryinthiscontext) {
         list($parentid, $tocontextid) = explode(',', $newparent);
     } else {
         $parentid = $oldcat->parent;
         $tocontextid = $oldcat->contextid;
     }
     // Check permissions.
     $fromcontext = get_context_instance_by_id($oldcat->contextid);
     require_capability('moodle/question:managecategory', $fromcontext);
     // If moving to another context, check permissions some more.
     if ($oldcat->contextid != $tocontextid) {
         $tocontext = get_context_instance_by_id($tocontextid);
         require_capability('moodle/question:managecategory', $tocontext);
     }
     // Update the category record.
     $cat = NULL;
     $cat->id = $updateid;
     $cat->name = $newname;
     $cat->info = $newinfo;
     $cat->parent = $parentid;
     // We don't change $cat->contextid here, if necessary we redirect to contextmove.php later.
     if (!$DB->update_record('question_categories', $cat)) {
         print_error('cannotupdatecate', 'question', $this->pageurl->out(), $newname);
     }
     // If the category name has changed, rename any random questions in that category.
     if ($oldcat->name != $cat->name) {
         $where = "qtype = 'random' AND category = ? AND " . $DB->sql_compare_text('questiontext') . " = ?";
         $randomqname = $QTYPES[RANDOM]->question_name($cat, false);
         $DB->set_field_select('question', 'name', $randomqname, $where, array($cat->id, '0'));
         $randomqname = $QTYPES[RANDOM]->question_name($cat, true);
         $DB->set_field_select('question', 'name', $randomqname, $where, array($cat->id, '1'));
     }
     // Then redirect to an appropriate place.
     if ($oldcat->contextid == $tocontextid) {
         // not moving contexts
         redirect($this->pageurl->out());
     } else {
         redirect($CFG->wwwroot . '/question/contextmove.php?' . $this->pageurl->get_query_string(array('cattomove' => $updateid, 'toparent' => $newparent)));
     }
 }
开发者ID:nicolasconnault,项目名称:moodle2.0,代码行数:52,代码来源:category_class.php


注:本文中的question_is_only_toplevel_category_in_context函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。