<?php

/**
* Module Brainstorm V2
* Operator : scale
* @author Valery Fremaux
* @package Brainstorm
* @date 20/12/2007
*/
include_once $CFG->dirroot . "/mod/brainstorm/operators/{$page}/locallib.php";
include_once "{$CFG->dirroot}/mod/brainstorm/operators/operator.class.php";
$current_operator = new BrainstormOperator($brainstorm->id, $page);
$responses = brainstorm_get_responses($brainstorm->id, 0, $currentgroup, false);
$scalings = scale_get_scalings($brainstorm->id, null, 0, false, $current_operator->configdata);
print_heading(get_string('myscaling', 'brainstorm'));
scale_display($brainstorm, null, $currentgroup, $responses, $scalings);
print_heading(get_string('unscaled', 'brainstorm'));
scale_display_unscaled($brainstorm, null, $currentgroup, $responses, $scalings);
print_heading(get_string('otherscales', 'brainstorm'));
print_simple_box_start('center');
$otherscalings = scale_get_meanscalings($brainstorm->id, 0, $currentgroup, true, $current_operator->configdata);
if ($otherscalings) {
    $absscalebounds = scale_get_scalebounds($brainstorm->id, 0, $currentgroup, false, $current_operator->configdata);
}
?>
<table cellspacing="5" width="80%">
<?php 
if ($otherscalings && $absscalebounds->range != 0) {
    $i = 0;
    $absoffset = $absscalebounds->minvalue < 0 ? abs($absscalebounds->minvalue / $absscalebounds->range * $current_operator->configdata->barwidth) : 0;
    foreach ($otherscalings as $other) {
/**
*
*
*/
function scale_display_unscaled(&$brainstorm, $userid, $groupid, &$responses = null, &$scalings = null)
{
    /// get data if we do not have it yet
    $current_operator = new BrainstormOperator($brainstorm->id, 'scale');
    if (!$responses) {
        $responses = brainstorm_get_responses($brainstorm->id, 0, $groupid, false);
    }
    if (!$scalings) {
        $scalings = scale_get_scalings($brainstorm->id, $userid, $groupid, false, $current_operator->configdata);
    }
    /// compute unscaled
    if ($responses) {
        $unvaluated = $responses;
        foreach (array_keys($scalings) as $scaledid) {
            unset($unvaluated[$scaledid]);
        }
    }
    ?>
<table cellspacing="5" width="80%">
<?php 
    if (!empty($unvaluated)) {
        $i = 0;
        foreach ($unvaluated as $response) {
            ?>
    <tr valign="top">
        <th class="<?php 
            echo $matchclass;
            ?>
" width="10%">
            <?php 
            echo $i + 1;
            ?>
.
        </th>
        <td align="right">
            <?php 
            echo $response->response;
            ?>
        </td>
    </tr>
<?php 
            $i++;
        }
    } else {
        echo '<tr><td>';
        print_simple_box(get_string('allevaluated', 'brainstorm'));
        echo '</td></tr>';
    }
    ?>
</table>
<?php 
}