diff --git a/manager/module/call_log.php b/manager/module/call_log.php index c754b31..562ae80 100644 --- a/manager/module/call_log.php +++ b/manager/module/call_log.php @@ -102,13 +102,43 @@ // Système de poids -> 5 sms = 1 appel // 0 -> {number, name, calls, sms} (closest contact) // 1 -> {number, name, calls, sms} (2nd closest contact) + $tmp = $phone_directory; // Permet de ne pas efface $phone_directory + $maxNumber = -1; // Contiendra le numéro du plus gros + $maxVal = null; // Contiendra la valeur max (sms+5*cal ls) + $sorted_directory = array(); // Contiendra l'annuaire trié par nombre d'interraction + + /* (1) Tant qu'on a pas tout trié */ + while( count($tmp) > 0 ){ + $maxNumber = -1; + $maxVal = null; + + /* (2) On parcours toutes les entrées puor trouver le plus proche */ + foreach($tmp as $number=>$data) + if( $data['sms']+5*$data['calls'] > $maxVal || is_null($maxVal) ){ + // On met à jour la valeur max + $maxVal = $data['sms']+5*$data['calls']; + // On met à jour l'indice + $maxNumber = $number; + } + + /* (3) On supprime le plus proche qu'on a trouvé et on l'ajoute au tableau trié */ + array_push($sorted_directory, array( + 'number' => $maxNumber, + 'name' => $tmp[$maxNumber]['name'], + 'calls' => $tmp[$maxNumber]['calls'], + 'sms' => $tmp[$maxNumber]['sms'], + 'total' => $tmp[$maxNumber]['sms'] + 5*$tmp[$maxNumber]['calls'] + )); + + unset($tmp[$maxNumber]); + } /* [6] Gestion du retour =========================================================*/ return array( 'ModuleError' => ManagerError::Success, - 'directory' => $phone_directory, + 'directory' => $sorted_directory, 'logs' => $phone_logs ); }