Example #1
0
/**
 * TODO document
 */
function print_grade_tree(&$gtree, $element, $moving, &$gpr, $switch, $switchedlast = false)
{
    global $CFG, $COURSE;
    /// fetch needed strings
    $strmove = get_string('move');
    $strmovehere = get_string('movehere');
    $strdelete = get_string('delete');
    $object = $element['object'];
    $eid = $element['eid'];
    /// prepare actions
    $actions = $gtree->get_edit_icon($element, $gpr);
    if ($element['type'] == 'item' or $element['type'] == 'category' and $element['depth'] > 1) {
        $actions .= '<a href="index.php?id=' . $COURSE->id . '&amp;action=delete&amp;eid=' . $eid . '&amp;sesskey=' . sesskey() . '"><img src="' . $CFG->pixpath . '/t/delete.gif" class="iconsmall" alt="' . $strdelete . '" title="' . $strdelete . '"/></a>';
        $actions .= '<a href="index.php?id=' . $COURSE->id . '&amp;action=moveselect&amp;eid=' . $eid . '&amp;sesskey=' . sesskey() . '"><img src="' . $CFG->pixpath . '/t/move.gif" class="iconsmall" alt="' . $strmove . '" title="' . $strmove . '"/></a>';
    }
    $actions .= $gtree->get_locking_icon($element, $gpr);
    $name = $object->get_name();
    //TODO: improve outcome visualisation
    if ($element['type'] == 'item' and !empty($object->outcomeid)) {
        $name = $name . ' (' . get_string('outcome', 'grades') . ')';
    }
    if ($object->is_hidden()) {
        $name = '<span class="dimmed_text">' . $name . '</span>';
    }
    $actions .= $gtree->get_hiding_icon($element, $gpr);
    /// prepare icon
    $icon = '<img src="' . $CFG->wwwroot . '/pix/spacer.gif" class="icon" alt=""/>';
    $last = '';
    $catcourseitem = false;
    switch ($element['type']) {
        case 'item':
            if ($object->itemtype == 'mod') {
                $icon = '<img src="' . $CFG->modpixpath . '/' . $object->itemmodule . '/icon.gif" class="icon" alt="' . get_string('modulename', $object->itemmodule) . '"/>';
            } else {
                if ($object->itemtype == 'manual') {
                    //TODO: add manual grading icon
                    if (empty($object->outcomeid)) {
                        $icon = '<img src="' . $CFG->pixpath . '/t/edit.gif" class="icon" alt="' . get_string('manualgrade', 'grades') . '"/>';
                        // TODO: localize
                    } else {
                        $icon = '<img src="' . $CFG->pixpath . '/i/outcomes.gif" class="icon" alt="' . get_string('outcome', 'grades') . '"/>';
                    }
                }
            }
            break;
        case 'courseitem':
        case 'categoryitem':
            $icon = '<img src="' . $CFG->pixpath . '/i/category_grade.gif" class="icon" alt="' . get_string('categorygrade') . '"/>';
            // TODO: localize
            $catcourseitem = true;
            break;
        case 'category':
            $icon = '<img src="' . $CFG->pixpath . '/f/folder.gif" class="icon" alt="' . get_string('category') . '"/>';
            break;
    }
    /// prepare move target if needed
    $moveto = '';
    if ($moving) {
        $actions = '';
        // no action icons when moving
        $moveto = '<li><a href="index.php?id=' . $COURSE->id . '&amp;action=move&amp;eid=' . $moving . '&amp;moveafter=' . $eid . '&amp;sesskey=' . sesskey() . '"><img class="movetarget" src="' . $CFG->wwwroot . '/pix/movehere.gif" alt="' . $strmovehere . '" title="' . $strmovehere . '" /></a></li>';
    }
    /// print the list items now
    if ($moving == $eid) {
        // do not diplay children
        echo '<li class="' . $element['type'] . ' moving">' . $icon . $name . '(' . get_string('move') . ')</li>';
    } else {
        if ($element['type'] != 'category') {
            if ($catcourseitem and $switch) {
                if ($switchedlast) {
                    echo '<li class="' . $element['type'] . '">' . $icon . $name . $actions . '</li>';
                } else {
                    echo $moveto;
                }
            } else {
                echo '<li class="' . $element['type'] . '">' . $icon . $name . $actions . '</li>' . $moveto;
            }
        } else {
            echo '<li class="' . $element['type'] . '">' . $icon . $name . $actions;
            echo '<ul class="catlevel' . $element['depth'] . '">';
            $last = null;
            foreach ($element['children'] as $child_el) {
                if ($switch and empty($last)) {
                    $last = $child_el;
                }
                print_grade_tree($gtree, $child_el, $moving, $gpr, $switch);
            }
            if ($last) {
                print_grade_tree($gtree, $last, $moving, $gpr, $switch, true);
            }
            echo '</ul></li>';
            if ($element['depth'] > 1) {
                echo $moveto;
                // can not move after the top category
            }
        }
    }
}
Example #2
0
/**
 * TODO document
 */
function print_grade_tree(&$gtree, $element, $moving, &$gpr, $switch, $switchedlast = false)
{
    global $CFG, $COURSE;
    /// fetch needed strings
    $strmove = get_string('move');
    $strmovehere = get_string('movehere');
    $strdelete = get_string('delete');
    $object = $element['object'];
    $eid = $element['eid'];
    $header = $gtree->get_element_header($element, true, true, true);
    if ($object->is_hidden()) {
        $header = '<span class="dimmed_text">' . $header . '</span>';
    }
    /// prepare actions
    $actions = $gtree->get_edit_icon($element, $gpr);
    $actions .= $gtree->get_calculation_icon($element, $gpr);
    if ($element['type'] == 'item' or $element['type'] == 'category' and $element['depth'] > 1) {
        if (!($element['type'] == 'item' and $object->is_external_item() and !$object->is_outcome_item() and $object->gradetype != GRADE_TYPE_NONE)) {
            $actions .= '<a href="index.php?id=' . $COURSE->id . '&amp;action=delete&amp;eid=' . $eid . '&amp;sesskey=' . sesskey() . '"><img src="' . $CFG->pixpath . '/t/delete.gif" class="iconsmall" alt="' . $strdelete . '" title="' . $strdelete . '"/></a>';
        }
        $actions .= '<a href="index.php?id=' . $COURSE->id . '&amp;action=moveselect&amp;eid=' . $eid . '&amp;sesskey=' . sesskey() . '"><img src="' . $CFG->pixpath . '/t/move.gif" class="iconsmall" alt="' . $strmove . '" title="' . $strmove . '"/></a>';
    }
    $actions .= $gtree->get_hiding_icon($element, $gpr);
    $actions .= $gtree->get_locking_icon($element, $gpr);
    /// prepare move target if needed
    $last = '';
    $catcourseitem = ($element['type'] == 'courseitem' or $element['type'] == 'categoryitem');
    $moveto = '';
    if ($moving) {
        $actions = '';
        // no action icons when moving
        $moveto = '<li><a href="index.php?id=' . $COURSE->id . '&amp;action=move&amp;eid=' . $moving . '&amp;moveafter=' . $eid . '&amp;sesskey=' . sesskey() . '"><img class="movetarget" src="' . $CFG->wwwroot . '/pix/movehere.gif" alt="' . $strmovehere . '" title="' . $strmovehere . '" /></a></li>';
    }
    /// print the list items now
    if ($moving == $eid) {
        // do not diplay children
        echo '<li class="' . $element['type'] . ' moving">' . $header . '(' . get_string('move') . ')</li>';
    } else {
        if ($element['type'] != 'category') {
            if ($catcourseitem and $switch) {
                if ($switchedlast) {
                    echo '<li class="' . $element['type'] . '">' . $header . $actions . '</li>';
                } else {
                    echo $moveto;
                }
            } else {
                echo '<li class="' . $element['type'] . '">' . $header . $actions . '</li>' . $moveto;
            }
        } else {
            echo '<li class="' . $element['type'] . '">' . $header . $actions;
            echo '<ul class="catlevel' . $element['depth'] . '">';
            $last = null;
            foreach ($element['children'] as $child_el) {
                if ($switch and empty($last)) {
                    $last = $child_el;
                }
                print_grade_tree($gtree, $child_el, $moving, $gpr, $switch);
            }
            if ($last) {
                print_grade_tree($gtree, $last, $moving, $gpr, $switch, true);
            }
            echo '</ul></li>';
            if ($element['depth'] > 1) {
                echo $moveto;
                // can not move after the top category
            }
        }
    }
}