Пример #1
0
/**
* Gives an array with worker stats:
* $stats['totalhours']
* $stats['monthhours'
* $stats['yearhours']
* $stats['termhours']
* $stats['totalearnings'] 
* $stats['monthearnings']
* $stats['yearearnings']
* $stats['termearnings']
* @return an array with useful values
*/
function get_worker_stats($userid, $courseid)
{
    global $DB;
    $stats['totalhours'] = get_total_hours($userid, $courseid);
    $stats['monthhours'] = get_hours_this_month($userid, $courseid);
    $stats['yearhours'] = get_hours_this_year($userid, $courseid);
    $stats['termhours'] = get_hours_this_term($userid, $courseid);
    $stats['totalearnings'] = get_total_earnings($userid, $courseid);
    $stats['monthearnings'] = get_earnings_this_month($userid, $courseid);
    $stats['yearearnings'] = get_earnings_this_year($userid, $courseid);
    $stats['termearnings'] = get_earnings_this_term($userid, $courseid);
    return $stats;
}
$MONTH = 12;
$YEAR = 2011;
$courses = get_courses(2, 'fullname ASC', 'c.id, c.shortname');
//find all workers
foreach ($courses as $course) {
    $workers = $DB->get_records('block_timetracker_workerinfo', array('courseid' => $course->id), 'lastname');
    foreach ($workers as $worker) {
        //demo courses, et. al.
        if ($worker->courseid >= 73 && $worker->courseid <= 76) {
            continue;
        }
        $course = $courses[$worker->courseid];
        if (!$course) {
            continue;
        }
        $earnings = get_hours_this_month($worker->id, $worker->courseid, $MONTH, $YEAR);
        //$earnings = get_earnings_this_term($worker->id, $worker->courseid);
        //$course = $DB->get_record('course', array('id'=>$worker->courseid));
        $id = str_replace('@mhc.edu', '', $worker->email);
        $id = str_replace('s000', '', strtolower($id));
        /*
        $remain = $worker->maxtermearnings - $earnings;
        if($remain <= 0){
            $hours_remain = 0;
        } else {
            $hours_remain = round($remain/$worker->currpayrate,2);
        }
        */
        echo '"' . $id . '","' . $earnings . '","' . $worker->lastname . '","' . $worker->firstname . '","' . $course->shortname . '"' . "\n";
        /*
        echo '"'.$worker->lastname.'","'.$worker->firstname.'","'.