本文整理汇总了PHP中get_child_categories函数的典型用法代码示例。如果您正苦于以下问题:PHP get_child_categories函数的具体用法?PHP get_child_categories怎么用?PHP get_child_categories使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_child_categories函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: categories2xml
private function categories2xml($categories)
{
foreach ($categories as $category) {
if (!is_object($category)) {
echo "not an object\n";
var_dump($category);
debug_print_backtrace();
die;
}
$category->categories = get_child_categories($category->id);
echo "<category oldid='{$category->id}' ";
$name = str_replace(array("&", "<", ">", '"', "'"), array("&", "<", ">", """, "'"), $category->name);
echo "name='{$name}'>";
foreach ($category->categories as $categories2) {
$this->categories2xml(array($categories2));
}
echo "</category>\n";
}
}
示例2: print_courses
/**
* Category is 0 (for all courses) or an object
*/
function print_courses($category)
{
global $CFG, $OUTPUT;
if (!is_object($category) && $category == 0) {
$categories = get_child_categories(0);
// Parent = 0 ie top-level categories only
if (is_array($categories) && count($categories) == 1) {
$category = array_shift($categories);
$courses = get_courses_wmanagers($category->id, 'c.sortorder ASC', array('summary', 'summaryformat'));
} else {
$courses = get_courses_wmanagers('all', 'c.sortorder ASC', array('summary', 'summaryformat'));
}
unset($categories);
} else {
$courses = get_courses_wmanagers($category->id, 'c.sortorder ASC', array('summary', 'summaryformat'));
}
if ($courses) {
echo html_writer::start_tag('ul', array('class' => 'unlist'));
foreach ($courses as $course) {
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
if ($course->visible == 1 || has_capability('moodle/course:viewhiddencourses', $coursecontext)) {
echo html_writer::start_tag('li');
print_course($course);
echo html_writer::end_tag('li');
}
}
echo html_writer::end_tag('ul');
} else {
echo $OUTPUT->heading(get_string("nocoursesyet"));
$context = get_context_instance(CONTEXT_SYSTEM);
if (has_capability('moodle/course:create', $context)) {
$options = array();
if (!empty($category->id)) {
$options['category'] = $category->id;
} else {
$options['category'] = $CFG->defaultrequestcategory;
}
echo html_writer::start_tag('div', array('class' => 'addcoursebutton'));
echo $OUTPUT->single_button(new moodle_url('/course/edit.php', $options), get_string("addnewcourse"));
echo html_writer::end_tag('div');
}
}
}
示例3: implode
$tmp_groups = implode(',', $_SESSION['groups']);
$course_id = $_SESSION['course_id'];
$sql = '';
$sqlParams = array();
if (!empty($tmp_groups)) {
$sql = 'SELECT * FROM %slinks L INNER JOIN %slinks_categories C USING (cat_id) WHERE ((owner_id=%d AND owner_type=%s) OR (owner_id IN (%s) AND owner_type=%s)) AND L.Approved=1';
array_push($sqlParams, TABLE_PREFIX, TABLE_PREFIX, $course_id, LINK_CAT_COURSE, $tmp_groups, LINK_CAT_GROUP);
} else {
$sql = 'SELECT * FROM %slinks L INNER JOIN %slinks_categories C USING (cat_id) WHERE (owner_id=%d AND owner_type=%s) AND L.Approved=1';
array_push($sqlParams, TABLE_PREFIX, TABLE_PREFIX, $course_id, LINK_CAT_COURSE);
}
//view links of a child category
$cat_parent_id = $_GET['cat_parent_id'];
if ($cat_parent_id) {
$cat_parent_id = intval($cat_parent_id);
$children = get_child_categories($cat_parent_id, $categories);
$cat_sql = sprintf(' AND C.cat_id IN (%s %s)', $children, $cat_parent_id);
$sql .= $cat_sql;
$parent_id = $cat_parent_id;
} else {
$parent_id = 0;
}
//search
$search = $_GET['search'];
if ($search) {
$search = trim($search);
$page_string .= SEP . 'search=' . urlencode($search);
$search = str_replace(array('%', '_'), array('', '\\_'), $search);
$search = '%%' . $search . '%%';
$search_sql = sprintf(' AND ((LinkName LIKE "%s") OR (description LIKE "%s"))', $search, $search);
$sql .= $search_sql;
示例4: definition
function definition()
{
global $CFG, $DB;
$mform =& $this->_form;
$category = $this->_customdata;
$categorycontext = context_coursecat::instance($category->id);
$this->_category = $category;
/// Check permissions, to see if it OK to give the option to delete
/// the contents, rather than move elsewhere.
/// Are there any subcategories of this one, can they be deleted?
$candeletecontent = true;
$tocheck = get_child_categories($category->id);
$containscategories = !empty($tocheck);
$categoryids = array($category->id);
while (!empty($tocheck)) {
$checkcat = array_pop($tocheck);
$childcategoryids[] = $checkcat->id;
$tocheck = $tocheck + get_child_categories($checkcat->id);
$chcontext = context_coursecat::instance($checkcat->id);
if ($candeletecontent && !has_capability('moodle/category:manage', $chcontext)) {
$candeletecontent = false;
}
}
/// Are there any courses in here, can they be deleted?
list($test, $params) = $DB->get_in_or_equal($categoryids);
$containedcourses = $DB->get_records_sql("SELECT id,1 FROM {course} c WHERE c.category {$test}", $params);
$containscourses = false;
if ($containedcourses) {
$containscourses = true;
foreach ($containedcourses as $courseid => $notused) {
if ($candeletecontent && !can_delete_course($courseid)) {
$candeletecontent = false;
break;
}
}
}
/// Are there any questions in the question bank here?
$containsquestions = question_context_has_any_questions($categorycontext);
/// Get the list of categories we might be able to move to.
$testcaps = array();
if ($containscourses) {
$testcaps[] = 'moodle/course:create';
}
if ($containscategories || $containsquestions) {
$testcaps[] = 'moodle/category:manage';
}
$displaylist = array();
$notused = array();
if (!empty($testcaps)) {
make_categories_list($displaylist, $notused, $testcaps, $category->id);
}
/// Now build the options.
$options = array();
if ($displaylist) {
$options[0] = get_string('movecontentstoanothercategory');
}
if ($candeletecontent) {
$options[1] = get_string('deleteallcannotundo');
}
/// Now build the form.
$mform->addElement('header', 'general', get_string('categorycurrentcontents', '', format_string($category->name, true, array('context' => $categorycontext))));
if ($containscourses || $containscategories || $containsquestions) {
if (empty($options)) {
print_error('youcannotdeletecategory', 'error', 'index.php', format_string($category->name, true, array('context' => $categorycontext)));
}
/// Describe the contents of this category.
$contents = '<ul>';
if ($containscategories) {
$contents .= '<li>' . get_string('subcategories') . '</li>';
}
if ($containscourses) {
$contents .= '<li>' . get_string('courses') . '</li>';
}
if ($containsquestions) {
$contents .= '<li>' . get_string('questionsinthequestionbank') . '</li>';
}
$contents .= '</ul>';
$mform->addElement('static', 'emptymessage', get_string('thiscategorycontains'), $contents);
/// 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($category->parent, $displaylist)) {
$mform->setDefault('newparent', $category->parent);
}
$mform->disabledIf('newparent', 'fulldelete', 'eq', '1');
}
} else {
$mform->addElement('hidden', 'fulldelete', 1);
$mform->setType('fulldelete', PARAM_INT);
$mform->addElement('static', 'emptymessage', '', get_string('deletecategoryempty'));
}
$mform->addElement('hidden', 'delete');
$mform->setType('delete', PARAM_ALPHANUM);
//.........这里部分代码省略.........
示例5: print_courses
function print_courses($category)
{
/// Category is 0 (for all courses) or an object
global $CFG;
if (!is_object($category) && $category == 0) {
$categories = get_child_categories(0);
// Parent = 0 ie top-level categories only
if (is_array($categories) && count($categories) == 1) {
$category = array_shift($categories);
$courses = get_courses_wmanagers($category->id, 'c.sortorder ASC', array('password', 'summary', 'currency'));
} else {
$courses = get_courses_wmanagers('all', 'c.sortorder ASC', array('password', 'summary', 'currency'));
}
unset($categories);
} else {
$courses = get_courses_wmanagers($category->id, 'c.sortorder ASC', array('password', 'summary', 'currency'));
}
if ($courses) {
echo '<ul class="unlist">';
foreach ($courses as $course) {
if ($course->visible == 1 || has_capability('moodle/course:viewhiddencourses', $course->context)) {
echo '<li>';
print_course($course);
echo "</li>\n";
}
}
echo "</ul>\n";
} else {
print_heading(get_string("nocoursesyet"));
$context = get_context_instance(CONTEXT_SYSTEM);
if (has_capability('moodle/course:create', $context)) {
$options = array();
$options['category'] = $category->id;
echo '<div class="addcoursebutton">';
print_single_button($CFG->wwwroot . '/course/edit.php', $options, get_string("addnewcourse"));
echo '</div>';
}
}
}
示例6: base_url
<?php
$cat_id = $cat['cat_id'];
?>
<a href="<?php
echo base_url('category/?cat_id=' . $cat_id . '&per_page=');
?>
" class="cat" rel="<?php
echo $cat['cat_id'];
?>
"><?php
echo $cat['cat_title'];
?>
</a>
<ul class="dropdown">
<?php
$child_cats = get_child_categories($cat['cat_id']);
if ($child_cats) {
foreach ($child_cats as $child_cat) {
$cat_id = $child_cat['cat_id'];
?>
<li>
<a href="<?php
echo base_url('category?cat_id=' . $cat_id . '&per_page=');
?>
"><?php
echo $child_cat['cat_title'];
?>
</a>
</li>
<?php
}
示例7: related_categories
function related_categories($cat_id)
{
$child_cat = get_child_categories($cat_id);
$related_html = '<ul class="treeMenu">';
if ($child_cat) {
foreach ($child_cat as $category) {
$related_html .= '<li><span></span><a href="' . base_url("category?cat_id=" . $category['cat_id']) . '&per_page=">' . $category['cat_name'] . '</a><br clear="all" /></li>';
}
}
$related_html .= '</ul>';
return $related_html;
}
示例8: trim
//search
if ($_GET['search']) {
$_GET['search'] = trim($_GET['search']);
$page_string .= SEP.'search='.urlencode($_GET['search']);
$search = $addslashes($_GET['search']);
$search = str_replace(array('%','_'), array('\%', '\_'), $search);
$search = '%'.$search.'%';
$search = "((LinkName LIKE '$search') OR (description LIKE '$search'))";
} else {
$search = '1';
}
//view links of a child category
if ($_GET['cat_parent_id']) {
$children = get_child_categories ($_GET['cat_parent_id'], $categories);
$cat_sql = "C.cat_id IN ($children $_GET[cat_parent_id])";
$parent_id = intval($_GET['cat_parent_id']);
} else {
$cat_sql = '1';
$parent_id = 0;
}
//get links
$tmp_groups = implode(',', $_SESSION['groups']);
if (!empty($tmp_groups)) {
$sql = "SELECT * FROM ".TABLE_PREFIX."links L INNER JOIN ".TABLE_PREFIX."links_categories C USING (cat_id) WHERE ((owner_id=$_SESSION[course_id] AND owner_type=".LINK_CAT_COURSE.") OR (owner_id IN ($tmp_groups) AND owner_type=".LINK_CAT_GROUP.")) AND L.Approved=1 AND $search AND $cat_sql ORDER BY $col $order";
} else {
$sql = "SELECT * FROM ".TABLE_PREFIX."links L INNER JOIN ".TABLE_PREFIX."links_categories C USING (cat_id) WHERE (owner_id=$_SESSION[course_id] AND owner_type=".LINK_CAT_COURSE.") AND L.Approved=1 AND $search AND $cat_sql ORDER BY $col $order";
}
示例9: print_whole_category_list2
function print_whole_category_list2($category = NULL, $displaylist = NULL, $parentslist = NULL, $depth = -1, $showcourses = true)
{
global $CFG;
// maxcategorydepth == 0 meant no limit
if (!empty($CFG->maxcategorydepth) && $depth >= $CFG->maxcategorydepth) {
return;
}
if (!$displaylist) {
make_categories_list($displaylist, $parentslist);
}
if ($category) {
if ($category->visible or has_capability('moodle/category:viewhiddencategories', get_context_instance(CONTEXT_SYSTEM))) {
print_category_info2($category, $depth, $showcourses);
} else {
return;
// Don't bother printing children of invisible categories
}
} else {
$category->id = "0";
}
if ($categories = get_child_categories($category->id)) {
// Print all the children recursively
$countcats = count($categories);
$count = 0;
$first = true;
$last = false;
foreach ($categories as $cat) {
$count++;
if ($count == $countcats) {
$last = true;
}
$up = $first ? false : true;
$down = $last ? false : true;
$first = false;
print_whole_category_list2($cat, $displaylist, $parentslist, $depth + 1, $showcourses);
}
}
}
示例10: offline_get_dynamic_files
/**
* Retrieve all dynamic files
*
* @return string[] The array of dynamic files
*/
function offline_get_dynamic_files()
{
global $CFG, $COURSE, $USER, $DB;
require_once $CFG->dirroot . '/course/lib.php';
// Include homepage and accessible course pages
$files = array('.', $CFG->wwwroot . '/', $CFG->wwwroot . '/index.php', $CFG->wwwroot . '/lib/offline/go_offline.js', $CFG->wwwroot . '/user/editadvanced.php?id=' . $USER->id);
// get all accessible courses
if (isloggedin() and !has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM)) and !isguest() and empty($CFG->disablemycourses)) {
$courses = get_my_courses($USER->id, 'visible DESC,sortorder ASC', array('summary'));
} else {
if (!has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM)) and !isguest() or $DB->count_records('course') <= FRONTPAGECOURSELIMIT) {
$categories = get_child_categories(0);
if (is_array($categories) && count($categories) == 1) {
$category = array_shift($categories);
$courses = get_courses_wmanagers($category->id, 'c.sortorder ASC', array('password', 'summary', 'currency'));
} else {
$courses = get_courses_wmanagers('all', 'c.sortorder ASC', array('password', 'summary', 'currency'));
}
unset($categories);
}
}
// make sure the course is visible and retrieve other modules and main course pages
foreach ($courses as $course) {
if ($course->visible == 1 || has_capability('moodle/course:viewhiddencourses', $course->context)) {
$files[] = $CFG->wwwroot . '/course/view.php?id=' . $course->id;
//Get all the module main pages
foreach (get_list_of_plugins() as $module) {
if ($module != 'label') {
$files[] = $CFG->wwwroot . '/mod/' . $module . '/index.php?id=' . $course->id;
}
}
//Get all the relevant forums
require_once $CFG->dirroot . '/mod/forum/lib.php';
$forums = forum_get_readable_forums($USER->id, $course->id);
foreach ($forums as $forum) {
$files[] = $CFG->wwwroot . '/mod/forum/view.php?f=' . $forum->id;
}
$modinfo =& get_fast_modinfo($course);
get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused);
foreach ($mods as $mod) {
if ($mod->modname == 'forum') {
$files[] = $CFG->wwwroot . '/mod/forum/view.php?id=' . $mod->id;
$cm = get_coursemodule_from_id('forum', $mod->id);
$discussions = forum_get_discussions($cm);
foreach ($discussions as $d) {
$files[] = $CFG->wwwroot . '/mod/forum/discuss.php?d=' . $d->discussion;
}
}
}
//Get all the relevant assignments
foreach ($modinfo->instances['assignment'] as $cm) {
if (!$cm->uservisible) {
continue;
}
$files[] = $CFG->wwwroot . '/mod/assignment/view.php?id=' . $cm->id;
}
}
}
$files = str_replace('&', '&', $files);
return $files;
}