Example #1
0
function bumpStudentClass($sid, $n)
{
    // get the student's group id
    $group_id = gidFromSid($sid);
    assert($group_id != 0);
    //dbg("group_id=$group_id");
    // get his current (old) class
    $oldclass = classForStudent($sid);
    assert($oldclass != 0);
    //dbg("oldclass=$oldclass");
    // compute his desired (new) class
    $newclass = $oldclass + $n;
    // wrap if necessary
    if ($newclass < 3) {
        $newclass = 6;
    }
    if ($newclass > 6) {
        $newclass = 3;
    }
    //dbg("newclass=$newclass");
    // get id of student (if any) that already has the desired class
    $othersid = sidFromGidAndClass($group_id, $newclass);
    //dbg("othersid=$othersid");
    // remove both students from group entirely
    if ($othersid != 0) {
        rmStudentFromGroup($othersid);
    }
    rmStudentFromGroup($sid);
    // re-add students using swapped class numbers
    assignStudentToGroupAndClass($sid, $group_id, $newclass);
    if ($othersid != 0) {
        assignStudentToGroupAndClass($othersid, $group_id, $oldclass);
    }
}
Example #2
0
<?php

$gid = gidFromSid($id);
dbg("id={$id}");
dbg("gid={$gid}");
$sql = "select id, last_name as ln from users where active=1 and group_id={$gid} and user_type='s'";
$rs = dbExec($sql);
$rc = $rs->RecordCount();
dbg("rc={$rc}");
assert($rc >= 1 && $rc <= 4);
$add = 0;
$avg = 0;
$tot = 0;
for ($i = 0; $i < 4; $i++) {
    if ($i < $rc) {
        $stid = $rs->fields[0];
        $name = $rs->fields[1];
        $sttr = tracking_rec($stid);
        $rm = $sttr["raisedmoney"];
        $tot += $rm;
        $add += $rm;
        $avg = $add / ($i + 1);
        $rs->MoveNext();
        dbg("name={$name} stid={$stid} rm={$rm} tot={$tot} add={$add} avg={$avg}");
    } else {
        $tot += $avg;
        dbg("(no one) tot={$tot} ({$tot} + {$avg})");
    }
}
dbg("final tot={$tot}");
$raisedbyteam = (int) $tot;