diff --git a/app/controllers/ClassesController.php b/app/controllers/ClassesController.php
index 29189f0d0..81fe930c6 100755
--- a/app/controllers/ClassesController.php
+++ b/app/controllers/ClassesController.php
@@ -461,6 +461,8 @@ public function actionGetFrequency()
$enrollments = StudentEnrollment::model()->findAllByAttributes(array('classroom_fk' => $_POST["classroom"]), $criteria);
if ($schedules != null) {
$scheduleDays = $this->getScheduleDays($schedules);
+ $schedulePerDays = $this->getSchedulePerDays($schedules);
+
if ($enrollments != null) {
$students = [];
$dayName = ["Domingo", "Segunda", "Terça", "Quarta", "Quinta", "Sexta", "Sábado"];
@@ -484,7 +486,8 @@ public function actionGetFrequency()
}
array_push($students, $array);
}
- echo json_encode(["valid" => true, "students" => $students, "scheduleDays" => $scheduleDays]);
+ echo json_encode(["valid" => true, "students" => $students, "scheduleDays"=>$scheduleDays, "schedulePerDays"=>$schedulePerDays]);
+
} else {
echo json_encode(["valid" => false, "error" => "Matricule alunos nesta turma para trazer o Quadro de Frequência."]);
}
@@ -492,12 +495,6 @@ public function actionGetFrequency()
echo json_encode(["valid" => false, "error" => "Mês/Ano " . ($_POST["fundamentalMaior"] == "1" ? "e Disciplina" : "") . " sem aula no Quadro de Horário."]);
}
}
- private function gerateDate($day, $month, $year)
- {
- $day = ($day < 10) ? '0' . $day : $day;
- $month = ($month < 10) ? '0' . $month : $month;
- return $day . "/" . $month . "/" . $year;
- }
private function getScheduleDays($schedules)
{
$result = [];
@@ -523,6 +520,27 @@ public function actionSaveFrequencies()
$this->saveFrequency($schedule);
}
}
+ private function gerateDate($day, $month, $year){
+ $day = ($day < 10) ? '0' . $day : $day;
+ $month = ($month < 10) ? '0' . $month : $month;
+ return $day . "/" . $month . "/" . $year;
+ }
+ private function getSchedulePerDays($schedules) {
+ $result = [];
+ foreach ($schedules as $schedule) {
+ $date = $this->gerateDate($schedule->day, $schedule->month, $schedule->year);
+ $index = array_search($date, array_column($result, 'date'));
+ if ($index === false) {
+ array_push($result, [
+ "schedulePerDays" => [$schedule->schedule],
+ "date" => $date
+ ]);
+ } else {
+ array_push($result[$index]["schedulePerDays"], $schedule->schedule);
+ }
+ }
+ return $result;
+ }
/**
* Save the frequency for each student and class.
diff --git a/js/classes/frequency/_initialization_instructor.js b/js/classes/frequency/_initialization_instructor.js
index cfd50f552..32d36899e 100644
--- a/js/classes/frequency/_initialization_instructor.js
+++ b/js/classes/frequency/_initialization_instructor.js
@@ -1,46 +1,46 @@
-function generateCheckboxItems(student, dia, mes, ano, fundamentalMaior, monthSplit, date) {
- const index = student.schedules.findIndex(schedule => schedule.date === date);
- const schedule = student.schedules[index];
-
- let checkboxItem = '';
- if (dia == schedule.day && mes == monthSplit[1] && ano == monthSplit[0]) {
- let justificationContainer = "";
- if (schedule.fault) {
- if (schedule.justification !== null) {
- justificationContainer +=
- "data-toggle='tooltip' data-placement='left' title='" + schedule.justification + "'";
+function generateCheckboxItems(student, dia, mes, ano, fundamentalMaior, monthSplit) {
+ return student.schedules.reduce((acc, schedule) => {
+ let checkboxItem = '';
+ if (dia == schedule.day && mes == monthSplit[1] && ano == monthSplit[0]) {
+ let justificationContainer = "";
+ if (schedule.fault) {
+ if (schedule.justification !== null) {
+ justificationContainer +=
+ "data-toggle='tooltip' data-placement='left' title='" + schedule.justification + "'";
+ }
}
+ checkboxItem = `
+
+
+
+
+ ${fundamentalMaior == 1 ? schedule.schedule+'°': ''}
+
+
+
+ `;
}
- checkboxItem = `
-
-
-
-
-
-
-
- `;
- }
- return checkboxItem;
+ return acc + checkboxItem;
+ }, '');
}
-function generateStudentLines(data, dia, mes, ano, fundamentalMaior, monthSplit, date) {
+function generateStudentLines(data, dia, mes, ano, fundamentalMaior, monthSplit) {
return data.students.reduce((line, student) => {
return line + `
${student.studentName}
- ${generateCheckboxItems(student, dia, mes, ano, fundamentalMaior, monthSplit, date)}
+ ${generateCheckboxItems(student, dia, mes, ano, fundamentalMaior, monthSplit)}
`;
}, '');
@@ -59,7 +59,7 @@ function generateScheduleDays(data, monthSplit, fundamentalMaior) {
- ${generateStudentLines(data, dia, mes, ano, fundamentalMaior, monthSplit, scheduleDays.date)}
+ ${generateStudentLines(data, dia, mes, ano, fundamentalMaior, monthSplit)}
`;
}, '');
@@ -95,7 +95,6 @@ function load() {
success: function (response) {
let data = JSON.parse(response);
- console.log(response)
if (data.valid) {
let accordion = $('');
@@ -199,33 +198,34 @@ $(".js-load-frequency").on("change", function () {
});
$(document).on("change", ".frequency-checkbox", function () {
- let checkbox = this
+ let checkbox = this;
let monthSplit = $("#month").val().split("-");
- $.ajax({
- type: "POST",
- url: "?r=classes/saveFrequencies",
- cache: false,
- data: {
- classroomId: $(this).attr("classroomId"),
- day: $(this).attr("day"),
- month: monthSplit[1],
- year: monthSplit[0],
- studentId: $(this).attr("studentId"),
- fault: $(this).is(":checked") ? 1 : 0,
- fundamentalMaior: $(this).attr("fundamentalMaior"),
- },
+ $.ajax({
+ type: "POST",
+ url: "?r=classes/saveFrequency",
+ cache: false,
+ data: {
+ classroomId: $(this).attr("classroomId"),
+ day: $(this).attr("day"),
+ month: monthSplit[1],
+ year: monthSplit[0],
+ schedule: $(this).attr("schedule"),
+ studentId: $(this).attr("studentId"),
+ fault: $(this).is(":checked") ? 1 : 0,
+ fundamentalMaior: $(this).attr("fundamentalMaior"),
+ },
- beforeSend: function () {
- $(".loading-frequency").css("display", "inline-block");
- $(".table-frequency").css("opacity", 0.3).css("pointer-events", "none");
- $(".table-frequency-head").css("opacity", 0.3).css("pointer-events", "none");
- $("#classroom, #month, #disciplines, #classesSearch").attr(
- "disabled",
- "disabled"
- );
- },
- complete: function () {
- $(checkbox).parent().parent().find('.frequency-justification-icon').toggleClass('hide')
+ beforeSend: function () {
+ $(".loading-frequency").css("display", "inline-block");
+ $(".table-frequency").css("opacity", 0.3).css("pointer-events", "none");
+ $(".table-frequency-head").css("opacity", 0.3).css("pointer-events", "none");
+ $("#classroom, #month, #disciplines, #classesSearch").attr(
+ "disabled",
+ "disabled"
+ );
+ },
+ complete: function () {
+ $(checkbox).parent().parent().find('.frequency-justification-icon').toggleClass('hide')
$(".loading-frequency").hide();
$(".table-frequency").css("opacity", 1).css("pointer-events", "auto");
@@ -256,42 +256,41 @@ $("#save-justification-modal").on("shown", function () {
});
$(document).on("click", ".btn-save-justification", function () {
- let justification = $(".frequency-checkbox[studentid=" + $("#justification-studentid").val() + "][schedule=" + $("#justification-schedule").val() + "][day=" + $("#justification-day").val() + "][month=" + $("#justification-month").val() + "][year=" + $("#justification-year").val() + "]").parent().parent().find(".frequency-justification-icon");
-
- $.ajax({
- type: "POST",
- url: "?r=classes/SaveJustifications",
- cache: false,
- data: {
- classroomId: $("#justification-classroomid").val(),
- studentId: $("#justification-studentid").val(),
- day: $("#justification-day").val(),
- month: $("#justification-month").val(),
- year: $("#justification-year").val(),
- fundamentalMaior: $("#justification-fundamentalmaior").val(),
- justification: $(".justification-text").val(),
- },
- beforeSend: function () {
- $("#save-justification-modal").find(".modal-body").css("opacity", 0.3).css("pointer-events", "none");
- $("#save-justification-modal").find("button").attr("disabled", "disabled");
- $("#save-justification-modal").find(".centered-loading-gif").show();
- },
- success: function (data) {
-
- if ($(".justification-text").val() == "") {
- justification.attr("title", "").tooltip("hide");
- } else {
- justification.parent().find(".frequency-checkbox").attr("title", $(".justification-text").val())
- justification.attr("title", $(".justification-text").val()).tooltip({container: "body"});
- }
- $("#save-justification-modal").modal("hide");
- },
- complete: function () {
- $("#save-justification-modal").find(".modal-body").css("opacity", 1).css("pointer-events", "auto");
- $("#save-justification-modal").find("button").removeAttr("disabled");
- $("#save-justification-modal").find(".centered-loading-gif").hide();
- },
- });
+ $.ajax({
+ type: "POST",
+ url: "?r=classes/saveJustification",
+ cache: false,
+ data: {
+ classroomId: $("#justification-classroomid").val(),
+ studentId: $("#justification-studentid").val(),
+ day: $("#justification-day").val(),
+ month: $("#justification-month").val(),
+ year: $("#justification-year").val(),
+ schedule: $("#justification-schedule").val(),
+ fundamentalMaior: $("#justification-fundamentalmaior").val(),
+ justification: $(".justification-text").val(),
+ },
+ beforeSend: function () {
+ $("#save-justification-modal").find(".modal-body").css("opacity", 0.3).css("pointer-events", "none");
+ $("#save-justification-modal").find("button").attr("disabled", "disabled");
+ $("#save-justification-modal").find(".centered-loading-gif").show();
+ },
+ success: function (data) {
+ let justification = $(".frequency-checkbox[studentid=" + $("#justification-studentid").val() + "][schedule=" + $("#justification-schedule").val() + "][day=" + $("#justification-day").val() + "][month=" + $("#justification-month").val() + "][year=" + $("#justification-year").val() + "]").parent().parent().find(".frequency-justification-icon");
+ if ($(".justification-text").val() == "") {
+ justification.attr("title", "").tooltip("hide");
+ } else {
+ justification.parent().find(".frequency-checkbox").attr("title", $(".justification-text").val())
+ justification.attr("title", $(".justification-text").val()).tooltip({container: "body"});
+ }
+ $("#save-justification-modal").modal("hide");
+ },
+ complete: function () {
+ $("#save-justification-modal").find(".modal-body").css("opacity", 1).css("pointer-events", "auto");
+ $("#save-justification-modal").find("button").removeAttr("disabled");
+ $("#save-justification-modal").find(".centered-loading-gif").hide();
+ },
+ });
});
$(document).on("keyup", ".justification-text", function (e) {