本文整理汇总了PHP中coursecat::has_courses方法的典型用法代码示例。如果您正苦于以下问题:PHP coursecat::has_courses方法的具体用法?PHP coursecat::has_courses怎么用?PHP coursecat::has_courses使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类coursecat
的用法示例。
在下文中一共展示了coursecat::has_courses方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: definition
/**
* Defines the form.
*/
public function definition()
{
$mform = $this->_form;
$this->coursecat = $this->_customdata;
$categorycontext = context_coursecat::instance($this->coursecat->id);
$categoryname = $this->coursecat->get_formatted_name();
// Check permissions, to see if it OK to give the option to delete
// the contents, rather than move elsewhere.
$candeletecontent = $this->coursecat->can_delete_full();
// Get the list of categories we might be able to move to.
$displaylist = $this->coursecat->move_content_targets_list();
// Now build the options.
$options = array();
if ($displaylist) {
$options[0] = get_string('movecontentstoanothercategory');
}
if ($candeletecontent) {
$options[1] = get_string('deleteallcannotundo');
}
if (empty($options)) {
print_error('youcannotdeletecategory', 'error', 'index.php', $categoryname);
}
// Now build the form.
$mform->addElement('header', 'general', get_string('categorycurrentcontents', '', $categoryname));
// Describe the contents of this category.
$contents = '';
if ($this->coursecat->has_children()) {
$contents .= '<li>' . get_string('subcategories') . '</li>';
}
if ($this->coursecat->has_courses()) {
$contents .= '<li>' . get_string('courses') . '</li>';
}
if (question_context_has_any_questions($categorycontext)) {
$contents .= '<li>' . get_string('questionsinthequestionbank') . '</li>';
}
if (!empty($contents)) {
$mform->addElement('static', 'emptymessage', get_string('thiscategorycontains'), html_writer::tag('ul', $contents));
} else {
$mform->addElement('static', 'emptymessage', '', get_string('deletecategoryempty'));
}
// Give the options for what to do.
$mform->addElement('select', 'fulldelete', get_string('whattodo'), $options);
if (count($options) == 1) {
$optionkeys = array_keys($options);
$option = reset($optionkeys);
$mform->hardFreeze('fulldelete');
$mform->setConstant('fulldelete', $option);
}
if ($displaylist) {
$mform->addElement('select', 'newparent', get_string('movecategorycontentto'), $displaylist);
if (in_array($this->coursecat->parent, $displaylist)) {
$mform->setDefault('newparent', $this->coursecat->parent);
}
$mform->disabledIf('newparent', 'fulldelete', 'eq', '1');
}
$mform->addElement('hidden', 'categoryid', $this->coursecat->id);
$mform->setType('categoryid', PARAM_ALPHANUM);
$mform->addElement('hidden', 'action', 'deletecategory');
$mform->setType('action', PARAM_ALPHANUM);
$mform->addElement('hidden', 'sure');
// This gets set by default to ensure that if the user changes it manually we can detect it.
$mform->setDefault('sure', md5(serialize($this->coursecat)));
$mform->setType('sure', PARAM_ALPHANUM);
$this->add_action_buttons(true, get_string('delete'));
}