Commit 95b3b4fa authored by Mikael Salson's avatar Mikael Salson
Browse files

UE.php: Code factorization

parent 5603e933
......@@ -66,8 +66,8 @@ class NotesExporterController extends AlecsiaController {
else{
$this->setSuccess("tout les sujets sont gelés!");
}
//Meme les si les notes sont pas gelé on prend les notes avec la fonction getFrozenAndNonFrozenNotes,
$notes = $ue_obj->getFrozenAndNonFrozenNotes();
//Meme les si les notes sont pas gelé on prend toutes les notes (true)
$notes = $ue_obj->getNotes(true);
if (empty($notes['student'])) {
......
......@@ -233,11 +233,12 @@ class Sujet {
* @pre The marks must have been frozen.
* @param group_id an array of group_ids, from which the marks must be taken.
* the array can be null
* @param all_marks: get all marks even if the subject is not frozen
*/
public function getNotes($group_id = null) {
public function getNotes($group_id = null, $all_marks = false) {
$notes = array();
if ($this->getStatus() == self::STATUS_FROZEN) {
if ($all_marks || $this->getStatus() == self::STATUS_FROZEN) {
$rendus = $this->getRendus();
foreach ($rendus as $rendu) {
......
......@@ -73,13 +73,17 @@ class UE extends AlecsiaEntity {
$this->addGroup(Group::getDefaultGroup());
}
public function getNotes() {
/**
* @return marks for all the subjects
* @param all_marks: return also marks for not frozen subjects
*/
public function getNotes($all_marks = false) {
$notes = array();
$notes['student'] = array();
$notes['group'] = array();
foreach ($this->sujets as $sujet) {
if ($sujet->isFrozen()) {
$notes_tp = $sujet->getNotes();
if ($all_marks || $sujet->isFrozen()) {
$notes_tp = $sujet->getNotes(null, $all_marks);
$notes['notes'][$sujet->getId()] = array();
$notes['sujet'][] = $sujet;
......@@ -93,27 +97,6 @@ class UE extends AlecsiaEntity {
return $notes;
}
//this function allow to get note from frozen and nonfrozen subject
public function getFrozenAndNonFrozenNotes() {
$notes = array();
$notes['student'] = array();
$notes['group'] = array();
foreach ($this->sujets as $sujet) {
$notes_tp = $sujet->getFrozenAndNonFrozenNotes();
$notes['notes'][$sujet->getId()] = array();
$notes['sujet'][] = $sujet;
foreach ($notes_tp as $info) {
$notes['student'] += array($info['student']->getId() => $info['student']);
$notes['group'] += array($info['student']->getId() => $info['group']);
$notes['notes'][$sujet->getId()] += array($info['student']->getId() => $info['note']);
}
}
return $notes;
}
//retunr boolean
// check retun False if one subjet not frozen yet
public function isAllSujetFrozen(){
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment