// Estudiante lider de un equipo
 if (isset(current($members)->leader) && current($members)->leader == 1) {
     $profilelink = '<strong>' . $profilelink . '  (leader)' . '</strong>';
 }
 // ID del miembro del equipo
 $membervalue = blended_gen_idvalue(current($members), $blended);
 if ($membervalue == -1) {
     $membervalue = "\"\"";
     $stridnumber = get_string('withoutidnumber', 'blended');
 } else {
     if ($membervalue == -2) {
         $membervalue = "\"\"";
         $stridnumber = get_string('withoutuserinfodata', 'blended');
     } else {
         $stridnumber = "";
         $membervalue = blended_generate_memberid_field(current($members), $blended);
     }
 }
 if ($membervalue == ' ') {
     prev($members);
     continue;
 }
 // Foto
 echo "<td align=\"center\">{$userpic}</td>";
 // Campo de texto "Identificador" lleno.
 //Cuando un mismo identificador se repite en varios equipos el recuadro se remarca en rojo
 if ($user_count[$memberuserid] == 1) {
     echo "<td align=\"center\"><input type=\"text\" name=\"{$membername}\" id=\"ac-userid\" value=\"{$membervalue}\" size=\"7\"\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tmaxlength=\"8\"  align=\"center\"><br><font size=\"1\">{$profilelink}<font size=\"1\" color=\"#FF0000\">{$stridnumber}</font></td>";
 } else {
     echo "<td align=\"center\"><input type=\"text\" style=\"border-color:red\" title=\"id repetido\" name=\"{$membername}\" id=\"ac-userid\" value=\"{$membervalue}\" size=\"7\"\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tmaxlength=\"8\"  align=\"center\"><br><font size=\"1\">{$profilelink}<font size=\"1\" color=\"#FF0000\">{$stridnumber}</font></td>";
 }
Example #2
0
function blended_generate_groups_table($item, $blended, $is_grading = true)
{
    global $DB, $OUTPUT, $CFG;
    $context_course = context_course::instance($item->courseid);
    $context = context_module::instance($blended->id);
    //Obtenci�n de los grupos del agrupamiento asociado a la tarea elegida
    //Obtengo los parámetros del agrupamiento
    $grouping = blended_get_grouping($item, $blended);
    $groups = groups_get_all_groups($item->courseid, null, $grouping->id);
    $i = 0;
    //Introducci�n de los miembros del agrupamiento en un vector
    // array[groupid][userid] for group/members
    $group_members = [];
    $users_in_teams = [];
    $numteams = count($groups) + 1;
    $nummembers = 0;
    foreach ($groups as $gr) {
        $members_loc = groups_get_members($gr->id);
        // obtengo el numero de cuadros a poner en el formulario segun la
        // maxima longitud del mayor equipo
        if ($nummembers < count($members_loc)) {
            $nummembers = count($members_loc);
        }
        $group_members[$gr->id] = $members_loc;
        $users_in_teams = array_merge($users_in_teams, $members_loc);
    }
    //Contador del numero de repticiones de cada miembro
    $repetir_miembro = blended_num_members($context_course, $group_members, 'teamsmanagement');
    //Introduzco un cuadro m�s por si se desea introducir otro miembro
    $nummembers = $nummembers + 1;
    $t = 0;
    $stridteam = get_string('idteam', 'blended');
    $stridmembers = get_string('idmembers', 'blended');
    $strgrade = get_string('grade', 'blended');
    $stralertcol = get_string('viewalertsdesc', "blended");
    $strnone = get_string('nograded', 'blended');
    $strrewritegrades = get_string('rewritegrades', 'blended');
    //Grading
    //Obtengo las calificaciones(Si existen) de los miembros tanto de la tabla "blended_grade" con de "grade_grades"
    if ($is_grading) {
        $user_grades = blended_get_users_grades($item, $users_in_teams);
        $gradearray = blended_get_scale_array($item);
        $grademax = $item->grademax;
        $gradelength = 3;
    }
    $table = new html_table();
    $table->align = array("left");
    if ($is_grading) {
        $table->head = array($stridteam, $stridmembers, $strgrade, $stralertcol);
    } else {
        $table->head = array($stridteam, $stridmembers, $stralertcol);
    }
    $table->headspan = array(1, $nummembers, 1, 1);
    // Realizo el formulario rellenado con los campos que corresponden
    foreach ($groups as $group) {
        $rewriteteam = "rewrite_team_" . $t;
        $fontsize = 1;
        $gradealert = "";
        $idteam = "team_" . $t . "_id";
        $teamname = "team_" . $t . "_name";
        $tablerow = new html_table_row();
        //Obtengo los grupos por su id
        $teamfield = "<input type=\"hidden\" name=\"{$idteam}\" id=\"{$group->id}\" value=\"{$group->id}\" >" . "<input type=\"text\" name=\"{$teamname}\" id=\"{$teamname}\" value=\"{$group->name}\" size=\"6\" maxlength=\"8\"  align=\"center\">";
        $tablerow->cells[] = $teamfield;
        // Obtengo los miembros de cada grupo
        $mem = $group_members[$group->id];
        // bucle miembros
        for ($f = 0; $f < $nummembers; $f++) {
            $membername = "team_" . $t . "_member_" . $f;
            // Nombre actual del campo de texto "Identificador" (utilizando el contador)
            $emptyteam = false;
            $member = current($mem);
            if ($f < count($mem)) {
                // Objeto `user`
                $memberuserid = $member->id;
                if (!($user = $DB->get_record('user', array('id' => $memberuserid)))) {
                    $emptyteam = true;
                }
                if (!$emptyteam) {
                    // Foto y vinculo a perfil de `user`
                    if ($piclink = has_capability('moodle/user:viewdetails', $context) || has_capability('moodle/user:viewdetails', $usercontext)) {
                        $userpic = $OUTPUT->user_picture($user);
                        $profilelink = '<a href="' . $CFG->wwwroot . '/user/view.php?id=' . $user->id . '&course=' . $item->courseid . '">' . fullname($user, true) . '</a>';
                    }
                    // Estudiante lider de un equipo
                    if (isset($member->leader) && $member->leader == 1) {
                        $profilelink = '<strong>' . $profilelink . '  (leader)' . '</strong>';
                    }
                    // ID del miembro del equipo
                    $membervalue = blended_gen_idvalue($member, $blended);
                    if ($membervalue == -1) {
                        $membervalue = "\"\"";
                        $stridnumber = get_string('withoutidnumber', 'blended');
                    } else {
                        if ($membervalue == -2) {
                            $membervalue = "\"\"";
                            $stridnumber = get_string('withoutuserinfodata', 'blended');
                        } else {
                            $stridnumber = "";
                            $membervalue = blended_generate_memberid_field($member, $blended);
                        }
                    }
                    if ($membervalue == ' ') {
                        prev($mem);
                        continue;
                    }
                    $teammember_field = $userpic;
                    /* Si la calificaci�n de "blended_grade" y "grade_grades"
                     * no coincide se muestra un mensaje de alerta al usuario */
                    if ($is_grading) {
                        $user_grade = $user_grades[$memberuserid];
                        if ($user_grade->blended != '' && $user_grade->grade != '' && (double) $user_grade->blended != (double) $user_grade->grade) {
                            $grade_string = grade_format_gradevalue($user_grade->grade, $item);
                            $icon_url = $OUTPUT->pix_url('alerta', 'blended');
                            //									$teammember_field = "$userpic <img alt=\"$stralertanota.Nota individual: $cal_gr_int\" title=\"$stralertanota.Nota individual: $cal_gr_int\" src=\"../../../mod/blended/pix/alerta.jpg\">";
                            $a = new stdClass();
                            $a->grade = $grade_string;
                            $a->finalgrade = $user_grade->grade;
                            $stralertanota = get_string('alertgrade', "blended", $a);
                            $stralertanota = htmlentities($stralertanota);
                            $teammember_grade_alert = " <img alt=\"{$stralertanota}\" title=\"{$stralertanota}\" src=\"{$icon_url}\">";
                            $teammember_field .= $teammember_grade_alert;
                        }
                    }
                    /* Si existe un miembro repetido en distintos grupos se recuadra
                     * el miembro en color rojo */
                    if ($repetir_miembro[$memberuserid] == 1) {
                        $teammember_field .= "<input type=\"text\" name=\"{$membername}\" id=\"ac-userid\" value=\"{$membervalue}\" size=\"7\"\r\n                                                                maxlength=\"8\"  align=\"center\"><br><font size=\"1\">{$profilelink}<font size=\"1\" color=\"#FF0000\">{$stridnumber}</font>";
                    } else {
                        $teammember_field .= "<input type=\"text\" style=\"border-color:red\" title=\"Id repetido la calificacion individual puede ser distinta a la grupal\" name=\"{$membername}\" id=\"ac-userid\" value=\"{$membervalue}\" size=\"7\"\r\n                                                                maxlength=\"8\"  align=\"center\"><br><font size=\"1\">{$profilelink}<font size=\"1\" color=\"#FF0000\">{$stridnumber}</font>";
                    }
                    next($mem);
                } else {
                    // Campo de texto "Identificador" vacio.
                    $teammember_field = "<input type=\"text\" name=\"{$membername}\" id=\"ac-userid\" value=\"\" size=\"7\"\r\n                                                        maxlength=\"8\"  align=\"center\">";
                }
            } else {
                // Campo de texto "Identificador" vacio.
                $teammember_field = "<input type=\"text\" name=\"{$membername}\" id=\"ac-userid\" value=\"\" size=\"7\" maxlength=\"8\"  align=\"center\">";
            }
            //
            $tablerow->cells[] = $teammember_field;
        }
        //Fin del bucle MEMBERS
        //GRADES:
        $alert = false;
        $rewriteteam = "rewrite_team_" . $t;
        // Si equipo vac�o
        if ($emptyteam == true) {
            $gradealert = get_string('teamempty', 'blended');
        }
        if ($is_grading) {
            list($grade, $alert) = blended_get_team_grade($group, $item);
            // Nombre del campo de texto "Calificación"
            $grade_text_input_name = "team_" . $t . "_grade";
            // Nombre para las opciones de la lista deplegable "Calificación"
            $grade_select_input_name = "team_" . $t . "_gradelist";
            //Si equipo no calificado
            if (!$grade) {
                if ($emptyteam == true) {
                    $gradealert = get_string('teamempty', 'blended');
                } else {
                    $gradealert = get_string('teamnotgraded', 'blended');
                }
                //Fin if-else
                $gvalue = null;
                $fontsize = 2;
                $gradehidden_field = '';
            } else {
                // Si calificación individual distinta a la de grupo
                if ($alert) {
                    $gradealert = $strrewritegrades;
                    $gradealert = $gradealert . "<center><input type=\"checkbox\" name=\"{$rewriteteam}\" id=\"{$rewriteteam}\" value=\"rewrite\" checked=\"true\"></center>";
                    $fontsize = 1;
                } else {
                    $gradealert = "" . "<input type=\"hidden\" name=\"{$rewriteteam}\" id=\"{$rewriteteam}\" value=\"rewrite\">";
                    $fontsize = null;
                }
                //Fin if-else
                if (empty($teamsfromassignmentid) || !empty($grade)) {
                    // `id` de la tabla "blended_grade"
                    $idgradevalue = $grade->id;
                    // `grade` de la tabla "blended_grade"
                    $gvalue = $grade->grade;
                    // Nombre del campo oculto `id` de "blended_grade"
                    $idgrade = "team_" . $t . "_gradeid";
                    // Campo oculto con `id` de la tabla "blended_grade"
                    $gradehidden_field = "<input type=\"hidden\" name=\"{$idgrade}\" id=\"{$idgrade}\" value= \"{$idgradevalue}\" >";
                } else {
                    $gvalue = null;
                }
                //Fin if-else
            }
            // Fin if-else
            if ($gradearray !== null) {
                // Campo de texto "Calificación"
                // Lista desplegable "Calificación"
                $gvalue = $gvalue !== null ? (int) $gvalue : null;
                // scales uses integer values
                $grade_select_field = "<select name=\"{$grade_select_input_name}\" id=\"{$grade_select_input_name}\" align=\"left\" onchange=\"setGradeTextField(this,{$grade_text_input_name})\">";
                $grade_select_field .= "<option value=\"-1\">{$strnone}</option>";
                foreach ($gradearray as $key => $val) {
                    if ($gvalue !== null && $key == $gvalue) {
                        $grade_select_field .= "<option value=\"{$key}\" selected=\"selected\">{$val}</option>";
                    } else {
                        $grade_select_field .= "<option value=\"{$key}\">{$val}</option>";
                    }
                }
                $grade_select_field .= "</select>";
            } else {
                $grade_select_field = '';
            }
            $grade_field = "<input type=\"text\" name=\"{$grade_text_input_name}\" id=\"{$grade_text_input_name}\" value=\"{$gvalue}\"  size=\"{$gradelength}\" maxlength=\"{$gradelength}\"  align=\"center\" onkeyup=\"setGradeSelect(this,{$grade_select_input_name},{$gradelength},null,{$grademax})\">";
            //                                        $grade_field="<input type=\"text\" name=\"$gname\" id=\"$gname\" value=\"$gvalue\"  size=\"$gradelength\" maxlength=\"$gradelength\"  align=\"center\" >";
            $tablerow->cells[] = $gradehidden_field . $grade_field . $grade_select_field;
        }
        $tablerow->cells[] = $gradealert;
        $t++;
        $table->data[] = $tablerow;
    }
    //Fin bucle TEAMS groups
    $tablerow = new html_table_row();
    //Introducci�n de un grupo vac�o
    $groups = groups_get_all_groups($item->courseid);
    $idteam = "team_" . $t . "_id";
    $teamname = "team_" . $t . "_name";
    $tablerow->cells[] = "<input type=\"hidden\" name=\"{$idteam}\" id=\"newTeam\" value=\"\" > <input type=\"text\" name=\"{$teamname}\" id=\"newTeamName\" value=\"\" size=\"6\"\r\n\t\t\t    maxlength=\"8\"  align=\"center\">";
    // mostramos los identificadores de los miembros del grupo
    // bucle miembros
    for ($f = 0; $f < $nummembers; $f++) {
        $membername = "team_" . $t . "_member_" . $f;
        // Campo de texto "Identificador" vacio.
        $tablerow->cells[] = "<input type=\"text\" name=\"{$membername}\" id=\"ac-userid\" value=\"\" size=\"7\" maxlength=\"8\"  align=\"center\">";
    }
    $gradealert = get_string('teamempty', 'blended');
    if ($is_grading) {
        $gvalue = null;
        $fontsize = 2;
        // Nombre del campo de texto "Calificación"
        $grade_text_input_name = "team_" . $t . "_grade";
        // Nombre para las opciones de la lista deplegable "Calificación"
        $grade_select_input_name = "team_" . $t . "_gradelist";
        // Campo de texto "Calificación"
        $gradehidden_field = "<input type=\"text\" name=\"{$grade_text_input_name}\" id=\"{$grade_text_input_name}\" value=\"{$gvalue}\"  size=\"{$gradelength}\" maxlength=\"{$gradelength}\"  align=\"center\" onkeyup=\"setGradeSelect(this,{$grade_select_input_name},{$gradelength},null,{$grademax})\">";
        //                            $gradehidden_field = "<input type=\"text\" name=\"$gname\" id=\"$gname\" value=\"$gvalue\"  size=\"$gradelength\" maxlength=\"$gradelength\"  align=\"center\" >";
        // Lista desplegable "Calificación"
        $grade_select_field = "<select name=\"{$grade_select_input_name}\" id=\"{$grade_select_input_name}\" align=\"left\" onchange=\"setGradeTextField(this,{$grade_text_input_name})\">";
        $grade_select_field .= "<option value=\"-1\">{$strnone}</option>";
        foreach ($gradearray as $key => $val) {
            if ($gvalue !== null && $val == $gvalue) {
                $grade_select_field = $grade_select_field . "<option value=\"{$key}\" selected=\"selected\">{$val}</option>";
            } else {
                $grade_select_field = $grade_select_field . "<option value=\"{$key}\">{$val}</option>";
            }
        }
        $grade_select_field .= "</select>";
        $tablerow->cells[] = "{$gradehidden_field} {$grade_select_field}";
    }
    $tablerow->cells[] = $gradealert;
    $table->data[] = $tablerow;
    //Fin de la tabla
    return $table;
}