some outcomes code

This commit is contained in:
toyomoyo
2007-07-25 07:24:04 +00:00
parent 78091c4572
commit e41442e47f
4 changed files with 199 additions and 26 deletions
+17 -5
View File
@@ -1,3 +1,5 @@
<form action="course.php" method="post">
<div>
<table style="margin-left:auto;margin-right:auto">
<tr>
<td>
@@ -5,26 +7,36 @@
<?php
foreach ($outcomes as $outcome) {
echo '<option value="'.$outcome->id.'">'.$outcome->shortname.'</option>';
// do not include items already used in course
if (in_array($outcome->id, array_keys($courseoutcomes))) {
continue;
}
echo '<option value="'.$outcome->id.'">'.truncate($outcome->fullname, 150).'</option>';
}
?>
</select>
</td>
<td>
<p class="arrow_button">
<input name="add" id="add" type="submit" value="<?php echo '&nbsp;'.$THEME->larrow.' &nbsp; &nbsp; '.get_string('add'); ?>" title="<?php print_string('add'); ?>" />
<input name="add" id="add" type="submit" value="<?php echo '&nbsp; '.$THEME->rarrow.' &nbsp; &nbsp; '.get_string('add'); ?>" title="<?php print_string('add'); ?>" />
<br />
<input name="remove" id="remove" type="submit" value="<?php echo '&nbsp; '.$THEME->rarrow.' &nbsp; &nbsp; '.get_string('remove'); ?>" title="<?php print_string('remove'); ?>" />
<input name="remove" id="remove" type="submit" value="<?php echo '&nbsp;'.$THEME->larrow.' &nbsp; &nbsp; '.get_string('remove'); ?>" title="<?php print_string('remove'); ?>" />
</p>
</td>
<td>
<select id="removeoutcomes" size="20" name="removeoutcomes[]" multiple="multiple">
<?php
foreach ($courseoutcomes as $courseoutcome) {
echo '<option value="'.$courseoutcome->id.'">'.$courseoutcome->shortname.'</option>';
echo '<option value="'.$courseoutcome->id.'">'.truncate($courseoutcome->fullname, 150).'</option>';
}
?>
</select>
</td>
</tr>
</table>
</table>
<input name="id" type="hidden" value="<?php echo $courseid?>"/>
</div>
</form>
+151 -4
View File
@@ -4,10 +4,78 @@
*********************************/
include_once('../../../config.php');
$courseid = required_param('id', SITEID, PARAM_INT); // course id
require_once($CFG->libdir.'/tablelib.php');
$page = optional_param('page', 0, PARAM_INT); // current page
$search = optional_param('search', 0, PARAM_TEXT);
$deleteid = optional_param('deleteid', 0, PARAM_INT); // which outcome to delete
$confirm = optional_param('confirm', 0, PARAM_INT);
$perpage = 30;
$courseid = required_param('id', PARAM_INT); // course id
if (!$course = get_record('course', 'id', $courseid)) {
print_error('nocourseid');
}
require_login($courseid);
/// form processing
print_header();
if ($deleteid && confirm_sesskey()) {
if ($confirm) {
// delete all outcomes used in courses
// delete all outcomes used in grade items
delete_records('grade_outcomes_courses', 'outcomeid', $deleteid);
delete_records('grade_outcomes', 'id', $deleteid);
} else {
// prints confirmation
$strgrades = get_string('grades');
$stroutcomes = get_string('outcomes', 'grades');
$navlinks = array();
$navlinks[] = array('name' => $strgrades, 'link' => $CFG->wwwroot . '/grade/index.php?id='.$courseid, 'type' => 'misc');
$navlinks[] = array('name' => $stroutcomes, 'link' => '', 'type' => 'misc');
$navigation = build_navigation($navlinks);
/// Print header
print_header_simple($strgrades.':'.$stroutcomes, ':'.$strgrades, $navigation, '', '', true);
$strdeleteoutcomecheck = get_string('deleteoutcomecheck', 'grades');
notice_yesno($strdeleteoutcomecheck,
'course.php?id='.$courseid.'&amp;deleteid='.$deleteid.'&amp;confirm=1&amp;sesskey='.sesskey(),
'course.php?id='.$courseid.'&amp;');
print_footer();
exit;
}
}
if ($data = data_submitted()) {
if (!empty($data->add) && !empty($data->addoutcomes)) {
/// add all selected to course list
foreach ($data->addoutcomes as $add) {
$goc -> courseid = $courseid;
$goc -> outcomeid = $add;
insert_record('grade_outcomes_courses', $goc);
}
} else if (!empty($data->remove) && !empty($data->removeoutcomes)) {
/// remove all selected from course outcomes list
foreach ($data->removeoutcomes as $remove) {
delete_records('grade_outcomes_courses', 'courseid', $courseid, 'outcomeid', $remove);
}
}
}
// Build navigation
$strgrades = get_string('grades');
$stroutcomes = get_string('outcomes', 'grades');
$navlinks = array();
$navlinks[] = array('name' => $strgrades, 'link' => $CFG->wwwroot . '/grade/index.php?id='.$courseid, 'type' => 'misc');
$navlinks[] = array('name' => $stroutcomes, 'link' => '', 'type' => 'misc');
$navigation = build_navigation($navlinks);
/// Print header
print_header_simple($strgrades.':'.$stroutcomes, ':'.$strgrades, $navigation, '', '', true);
// Add tabs
$currenttab = 'outcomesettings';
@@ -15,11 +83,90 @@ $courseid = required_param('id', SITEID, PARAM_INT); // course id
/// listing of all site outcomes + this course specific outcomes
$outcomes = get_records_sql('SELECT * FROM '.$CFG->prefix.'grade_outcomes
WHERE ISNULL(courseid)');
get_records('grade_outcomes', 'courseid', $courseid);
WHERE courseid < 1');
$courseoutcomes = get_records_sql('SELECT go.id, go.fullname
FROM '.$CFG->prefix.'grade_outcomes_courses goc,
'.$CFG->prefix.'grade_outcomes go
WHERE goc.courseid = '.$courseid.'
AND goc.outcomeid = go.id');
if (empty($courseoutcomes)) {
$courseoutcomes = get_records('grade_outcomes', 'courseid', $courseid);
} elseif ($mcourseoutcomes = get_records('grade_outcomes', 'courseid', $courseid)) {
$courseoutcomes += $mcourseoutcomes;
}
check_theme_arrows();
include_once('course.html');
/// interface to add/edit/delete course specific outcomes
echo '<p/>';
print_string('coursespecoutcome', 'grades'); // course sepcific outcomes
$totalcount = count_records('grade_outcomes_courses', 'courseid', $courseid);
$baseurl = "course.php";
print_paging_bar($totalcount, $page, $perpage, $baseurl);
if ($outcomes = get_recordset('grade_outcomes', 'courseid', $courseid, '', '*', $page * $perpage, $perpage)) {
$tablecolumns = array('outcome', 'scale', 'edit', 'usedgradeitems');
$tableheaders = array(get_string('outcomes'),
get_string('scale'),
get_string('operations'),
get_string('usedgradeitem'));
$table = new flexible_table('outcomes');
$table->define_columns($tablecolumns);
$table->define_headers($tableheaders);
$table->define_baseurl($baseurl);
$table->set_attribute('cellspacing', '0');
$table->set_attribute('id', 'user-grade');
$table->set_attribute('class', 'boxaligncenter generaltable');
$table->setup();
foreach ($outcomes as $outcome) {
$data = array();
// full name of the outcome
$data[] = $outcome['fullname'];
// full name of the scale used by this outcomes
$scale= get_record('scale', 'id', $outcome['scaleid']);
$data[] = $scale->name;
// add operations
$data[] = '<a href="editoutcomes.php?id='.$outcome['id'].'&amp;courseid='.$courseid.'&amp;sesskey='.sesskey().'"><img alt="Update" class="iconsmall" src="'.$CFG->wwwroot.'/pix/t/edit.gif"/></a>
<a href="course.php?deleteid='.$outcome['id'].'&amp;id='.$courseid.'&amp;sesskey='.sesskey().'"><img alt="Delete" class="iconsmall" src="'.$CFG->wwwroot.'/pix/t/delete.gif"/></a>'; // icons and links
// num of gradeitems using this
$num = count_records('grade_items', 'outcomeid' ,$outcome['id']);
$data[] = (int) $num;
// num of courses using this outcome
$table->add_data($data);
}
$table->print_html();
}
echo '<a href="editoutcomes.php?courseid='.$courseid.'">Add a new outcome</a>';
print_footer();
/**
* truncates a string to a length of num
* @param string string
* @param int num
* @return string
*/
function truncate($string, $num) {
if (strlen($string) > $num + 3) {
$text = substr($string, 0, $num);
$text = $text."...";
}
return $string;
}
?>
+12 -3
View File
@@ -43,7 +43,8 @@ class edit_outcomes_form extends moodleform {
$id = optional_param('id', 0, PARAM_INT); // id of the outcome
if ($courseid = optional_param('courseid', 0, PARAM_INT)) {
// optional course id, if set, editting from course
$returnurl = $CFG->wwwroot."/grade/report/outcomes/course.php";
require_login($courseid);
$returnurl = $CFG->wwwroot."/grade/report/outcomes/course.php?id=$courseid";
} else {
// admin editting site level outcomes
$returnurl = $CFG->wwwroot."/grade/report/outcomes/site.php";
@@ -73,11 +74,19 @@ if ($data = $mform->get_data()) {
redirect($returnurl);
}
// Build navigation
$strgrades = get_string('grades');
$stroutcomes = get_string('outcomes', 'grades');
$navlinks = array();
$navlinks[] = array('name' => $strgrades, 'link' => $CFG->wwwroot . '/grade/index.php?id='.$courseid, 'type' => 'misc');
$navlinks[] = array('name' => $stroutcomes, 'link' => '', 'type' => 'misc');
$navigation = build_navigation($navlinks);
/// Print header
print_header_simple($strgrades.':'.$stroutcomes, ':'.$strgrades, $navigation, '', '', true);
// Add tabs
$currenttab = 'editoutcomes';
include('tabs.php');
print_header();
$mform->display();
print_footer();
?>
+19 -14
View File
@@ -26,17 +26,22 @@ $perpage = 30;
delete_records('grade_outcomes_courses', 'outcomeid', $deleteid);
delete_records('grade_outcomes', 'id', $deleteid);
} else {
$strgrades = get_string('grades');
$stroutcomes = get_string('outcomes', 'grades');
$navlinks = array();
$navlinks[] = array('name' => $strgrades, 'link' => $CFG->wwwroot . '/grade/index.php?id='.$courseid, 'type' => 'misc');
$navlinks[] = array('name' => $stroutcomes, 'link' => '', 'type' => 'misc');
$navigation = build_navigation($navlinks);
/// Print header
print_header_simple($strgrades.':'.$stroutcomes, ':'.$strgrades, $navigation, '', '', true);
// prints confirmation
print_header('');
echo '<form action="settings.php">';
echo '<div>';
echo '<input type="hidden" name="confirm" value="1" />';
echo '<input type="hidden" name="deleteid" value="'.$deleteid.'" />';
echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
echo 'Are you sure you want to delete this outcome?';
echo '<input type="submit" value="yes" />';
echo '</div>';
echo '</form>';
$strdeleteoutcomecheck = get_string('deleteoutcomecheck', 'grades');
notice_yesno($strdeleteoutcomecheck,
'site.php?deleteid='.$deleteid.'&amp;confirm=1&amp;sesskey='.sesskey(),
'site.php');
print_footer();
exit;
}
@@ -51,7 +56,7 @@ $perpage = 30;
include('tabs.php');
$totalcount = count_records('grade_outcomes');
$baseurl = "settings.php";
$baseurl = "site.php";
print_paging_bar($totalcount, $page, $perpage, $baseurl);
if ($outcomes = get_recordset('grade_outcomes', '', '', '', '*', $page * $perpage, $perpage)) {
@@ -94,14 +99,14 @@ $perpage = 30;
// add operations
$data[] = '<a href="editoutcomes.php?id='.$outcome['id'].'&amp;sesskey='.sesskey().'"><img alt="Update" class="iconsmall" src="'.$CFG->wwwroot.'/pix/t/edit.gif"/></a>
<a href="settings.php?deleteid='.$outcome['id'].'&amp;sesskey='.sesskey().'"><img alt="Delete" class="iconsmall" src="'.$CFG->wwwroot.'/pix/t/delete.gif"/></a>'; // icons and links
<a href="site.php?deleteid='.$outcome['id'].'&amp;sesskey='.sesskey().'"><img alt="Delete" class="iconsmall" src="'.$CFG->wwwroot.'/pix/t/delete.gif"/></a>'; // icons and links
// num of gradeitems using this
$num = count_records('grade_outcomes_courses', 'outcomeid' ,$outcome['id']);
$num = count_records('grade_items', 'outcomeid' ,$outcome['id']);
$data[] = (int) $num;
// num of courses using this outcome
$num = count_records('grade_items', 'outcomeid', $outcome['id']);
$num = count_records('grade_outcomes_courses', 'outcomeid', $outcome['id']);
$data[] = (int) $num;
$table->add_data($data);