/** * Recursive function to print all the categories ready for editing. * * @param html_table $table The table to add data to. * @param coursecat $category The category to render * @param int $depth The depth of the category. * @param bool $up True if this category can be moved up. * @param bool $down True if this category can be moved down. */ function print_category_edit(html_table $table, coursecat $category, $depth = -1, $up = false, $down = false) { global $OUTPUT; static $str = null; if (is_null($str)) { $str = new stdClass; $str->edit = new lang_string('edit'); $str->delete = new lang_string('delete'); $str->moveup = new lang_string('moveup'); $str->movedown = new lang_string('movedown'); $str->edit = new lang_string('editthiscategory'); $str->hide = new lang_string('hide'); $str->show = new lang_string('show'); $str->cohorts = new lang_string('cohorts', 'cohort'); $str->spacer = $OUTPUT->spacer().' '; } if ($category->id) { $categorycontext = context_coursecat::instance($category->id); $attributes = array(); $attributes['class'] = $category->visible ? '' : 'dimmed'; $attributes['title'] = $str->edit; $categoryurl = new moodle_url('/course/manage.php', array('categoryid' => $category->id, 'sesskey' => sesskey())); $categoryname = $category->get_formatted_name(); $categorypadding = str_repeat(' ', $depth); $categoryname = $categorypadding . html_writer::link($categoryurl, $categoryname, $attributes); $icons = array(); if (has_capability('moodle/category:manage', $categorycontext)) { // Edit category. $icons[] = $OUTPUT->action_icon( new moodle_url('/course/editcategory.php', array('id' => $category->id)), new pix_icon('t/edit', $str->edit, 'moodle', array('class' => 'iconsmall')), null, array('title' => $str->edit) ); // Delete category. $icons[] = $OUTPUT->action_icon( new moodle_url('/course/manage.php', array('deletecat' => $category->id, 'sesskey' => sesskey())), new pix_icon('t/delete', $str->delete, 'moodle', array('class' => 'iconsmall')), null, array('title' => $str->delete) ); // Change visibility. if (!empty($category->visible)) { $icons[] = $OUTPUT->action_icon( new moodle_url('/course/manage.php', array('hidecat' => $category->id, 'sesskey' => sesskey())), new pix_icon('t/hide', $str->hide, 'moodle', array('class' => 'iconsmall')), null, array('title' => $str->hide) ); } else { $icons[] = $OUTPUT->action_icon( new moodle_url('/course/manage.php', array('showcat' => $category->id, 'sesskey' => sesskey())), new pix_icon('t/show', $str->show, 'moodle', array('class' => 'iconsmall')), null, array('title' => $str->show) ); } // Cohorts. if (has_any_capability(array('moodle/cohort:manage', 'moodle/cohort:view'), $categorycontext)) { $icons[] = $OUTPUT->action_icon( new moodle_url('/cohort/index.php', array('contextid' => $categorycontext->id)), new pix_icon('t/cohort', $str->cohorts, 'moodle', array('class' => 'iconsmall')), null, array('title' => $str->cohorts) ); } // Move up/down. if ($up) { $icons[] = $OUTPUT->action_icon( new moodle_url('/course/manage.php', array('moveupcat' => $category->id, 'sesskey' => sesskey())), new pix_icon('t/up', $str->moveup, 'moodle', array('class' => 'iconsmall')), null, array('title' => $str->moveup) ); } else { $icons[] = $str->spacer; } if ($down) { $icons[] = $OUTPUT->action_icon( new moodle_url('/course/manage.php', array('movedowncat' => $category->id, 'sesskey' => sesskey())), new pix_icon('t/down', $str->movedown, 'moodle', array('class' => 'iconsmall')), null, array('title' => $str->movedown) ); } else { $icons[] = $str->spacer; } } $actions = ''; if (has_capability('moodle/category:manage', $categorycontext)) { $popupurl = new moodle_url('/course/manage.php', array('movecat' => $category->id, 'sesskey' => sesskey())); $tempdisplaylist = array(0 => get_string('top')) + coursecat::make_categories_list('moodle/category:manage', $category->id); $select = new single_select($popupurl, 'movetocat', $tempdisplaylist, $category->parent, null, "moveform$category->id"); $select->set_label(get_string('frontpagecategorynames'), array('class' => 'accesshide')); $actions = $OUTPUT->render($select); } $table->data[] = new html_table_row(array( // Category name. new html_table_cell($categoryname), // Course count. new html_table_cell($category->coursecount), // Icons. new html_table_cell(join(' ', $icons)), // Actions. new html_table_cell($actions) )); } if ($categories = $category->get_children()) { // 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_category_edit($table, $cat, $depth+1, $up, $down); } } }
function print_category_edit($category, $displaylist, $parentslist, $depth = -1, $up = false, $down = false) { /// Recursive function to print all the categories ready for editing global $CFG, $USER, $OUTPUT; static $str = NULL; if (is_null($str)) { $str = new stdClass(); $str->edit = get_string('edit'); $str->delete = get_string('delete'); $str->moveup = get_string('moveup'); $str->movedown = get_string('movedown'); $str->edit = 'Editar materia'; $str->hide = get_string('hide'); $str->show = get_string('show'); $str->cohorts = get_string('cohorts', 'cohort'); $str->spacer = $OUTPUT->spacer() . ' '; } if (!empty($category)) { if (!isset($category->context)) { $category->context = get_context_instance(CONTEXT_COURSECAT, $category->id); } echo '<tr><td align="left" class="name">'; for ($i = 0; $i < $depth; $i++) { echo ' '; } $linkcss = $category->visible ? '' : ' class="dimmed" '; echo '<a ' . $linkcss . ' title="' . $str->edit . '" ' . ' href="category.php?id=' . $category->id . '&categoryedit=on&sesskey=' . sesskey() . '">' . format_string($category->name) . '</a>'; echo '</td>'; echo '<td class="count">' . $category->coursecount . '</td>'; echo '<td class="icons">'; /// Print little icons if (has_capability('moodle/category:manage', $category->context)) { echo '<a title="' . $str->edit . '" href="editcategory.php?id=' . $category->id . '"><img' . ' src="' . $OUTPUT->pix_url('t/edit') . '" class="iconsmall" alt="' . $str->edit . '" /></a> '; echo '<a title="' . $str->delete . '" href="index.php?delete=' . $category->id . '&sesskey=' . sesskey() . '"><img' . ' src="' . $OUTPUT->pix_url('t/delete') . '" class="iconsmall" alt="' . $str->delete . '" /></a> '; /* if (!empty($category->visible)) { echo '<a title="'.$str->hide.'" href="index.php?hide='.$category->id.'&sesskey='.sesskey().'"><img'. ' src="'.$OUTPUT->pix_url('t/hide') . '" class="iconsmall" alt="'.$str->hide.'" /></a> '; } else { echo '<a title="'.$str->show.'" href="index.php?show='.$category->id.'&sesskey='.sesskey().'"><img'. ' src="'.$OUTPUT->pix_url('t/show') . '" class="iconsmall" alt="'.$str->show.'" /></a> '; } if (has_capability('moodle/cohort:manage', $category->context) or has_capability('moodle/cohort:view', $category->context)) { echo '<a title="'.$str->cohorts.'" href="'.$CFG->wwwroot.'/cohort/index.php?contextid='.$category->context->id.'"><img'. ' src="'.$OUTPUT->pix_url('i/cohort') . '" class="iconsmall" alt="'.$str->cohorts.'" /></a> '; } if ($up) { echo '<a title="'.$str->moveup.'" href="index.php?moveup='.$category->id.'&sesskey='.sesskey().'"><img'. ' src="'.$OUTPUT->pix_url('t/up') . '" class="iconsmall" alt="'.$str->moveup.'" /></a> '; } else { echo $str->spacer; } if ($down) { echo '<a title="'.$str->movedown.'" href="index.php?movedown='.$category->id.'&sesskey='.sesskey().'"><img'. ' src="'.$OUTPUT->pix_url('t/down') . '" class="iconsmall" alt="'.$str->movedown.'" /></a> '; } else { echo $str->spacer; }*/ } echo '</td>'; /* echo '<td align="left">'; if (has_capability('moodle/category:manage', $category->context)) { $tempdisplaylist = $displaylist; unset($tempdisplaylist[$category->id]); foreach ($parentslist as $key => $parents) { if (in_array($category->id, $parents)) { unset($tempdisplaylist[$key]); } } $popupurl = new moodle_url("index.php?move=$category->id&sesskey=".sesskey()); $select = new single_select($popupurl, 'moveto', $tempdisplaylist, $category->parent, null, "moveform$category->id"); echo $OUTPUT->render($select); } echo '</td>';*/ echo '</tr>'; } else { $category->id = '0'; } if ($categories = get_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_category_edit($cat, $displaylist, $parentslist, $depth + 1, $up, $down); } } }
function print_category_edit($category, $displaylist, $parentslist, $depth = -1, $up = false, $down = false) { /// Recursive function to print all the categories ready for editing global $CFG, $USER; static $str = ''; if (empty($str)) { $str->delete = get_string('delete'); $str->moveup = get_string('moveup'); $str->movedown = get_string('movedown'); $str->edit = get_string('editthiscategory'); $str->hide = get_string('hide'); $str->show = get_string('show'); } if ($category) { if (!isset($category->context)) { $category->context = get_context_instance(CONTEXT_COURSECAT, $category->id); } echo '<tr><td align="left" class="name">'; for ($i = 0; $i < $depth; $i++) { echo ' '; } $linkcss = $category->visible ? '' : ' class="dimmed" '; echo '<a ' . $linkcss . ' title="' . $str->edit . '" ' . ' href="category.php?id=' . $category->id . '&categoryedit=on&sesskey=' . sesskey() . '">' . format_string($category->name) . '</a>'; echo '</td>'; echo '<td class="count">' . $category->coursecount . '</td>'; echo '<td class="icons">'; /// Print little icons if (has_capability('moodle/category:delete', $category->context)) { echo '<a title="' . $str->delete . '" href="index.php?delete=' . $category->id . '&sesskey=' . sesskey() . '"><img' . ' src="' . $CFG->pixpath . '/t/delete.gif" class="iconsmall" alt="' . $str->delete . '" /></a> '; } if (has_capability('moodle/category:visibility', $category->context)) { if (!empty($category->visible)) { echo '<a title="' . $str->hide . '" href="index.php?hide=' . $category->id . '&sesskey=' . sesskey() . '"><img' . ' src="' . $CFG->pixpath . '/t/hide.gif" class="iconsmall" alt="' . $str->hide . '" /></a> '; } else { echo '<a title="' . $str->show . '" href="index.php?show=' . $category->id . '&sesskey=' . sesskey() . '"><img' . ' src="' . $CFG->pixpath . '/t/show.gif" class="iconsmall" alt="' . $str->show . '" /></a> '; } } if ($up) { echo '<a title="' . $str->moveup . '" href="index.php?moveup=' . $category->id . '&sesskey=' . sesskey() . '"><img' . ' src="' . $CFG->pixpath . '/t/up.gif" class="iconsmall" alt="' . $str->moveup . '" /></a> '; } if ($down) { echo '<a title="' . $str->movedown . '" href="index.php?movedown=' . $category->id . '&sesskey=' . sesskey() . '"><img' . ' src="' . $CFG->pixpath . '/t/down.gif" class="iconsmall" alt="' . $str->movedown . '" /></a> '; } echo '</td>'; echo '<td align="left">'; $tempdisplaylist = $displaylist; unset($tempdisplaylist[$category->id]); foreach ($parentslist as $key => $parents) { if (in_array($category->id, $parents)) { unset($tempdisplaylist[$key]); } } popup_form("index.php?move={$category->id}&sesskey={$USER->sesskey}&moveto=", $tempdisplaylist, "moveform{$category->id}", $category->parent, '', '', '', false); echo '</td>'; echo '</tr>'; } else { $category->id = '0'; } if ($categories = get_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_category_edit($cat, $displaylist, $parentslist, $depth + 1, $up, $down); } } }