Parsage des journaux d'appels v2

This commit is contained in:
xdrm-brackets 2016-04-18 16:21:24 +02:00
parent e3e829d524
commit 1ba67b9175
6 changed files with 242 additions and 653 deletions

View File

@ -10,7 +10,7 @@
use \api\client;
debug();
/* PARSAGE DE JOURNAUX D'APPEL
@ -23,11 +23,12 @@
=========================================================*/
$file_content = file_get_contents('doc/sample.xml');
var_dump( $file_content ); return;
/* [2] On cree la requete
=========================================================*/
$request = new ModuleRequest('call_log/unserialize', array('filecontent'=>$file_content));
$request = new ModuleRequest('call_log/unserialize', array(
'file_content' => $file_content,
'phone_number' => '01 02 03 04 05'));
$answer = $request->dispatch(); // on l'execute
/* [3] Si erreur
@ -42,36 +43,15 @@
/* [4] Sinon on recupere le resultat
=========================================================*/
$sms = $answer->get('sms');
$call = $answer->get('call');
$contact = $answer->get('contact');
$directory = $answer->get('directory');
$logs = $answer->get('logs');
/* [5] On debug les donnees recues
=========================================================*/
var_dump( "Il y a ".count($contact)." personnes :" );
var_dump( "- ".count($sms)." par SMS/MMS" );
var_dump( "- ".count($call)." par telephone" );
echo "<br>";
echo "TOP 10 DES APPELS<br>";
echo "=================<br>";
foreach($call as $v)
var_dump( $v[0] ." (".$contact[$v[0]].") \t\t\t". $v[1] ." appels");
echo "TOP 10 DES MMS/SMS<br>";
echo "==================<br>";
foreach($sms as $v)
var_dump( $v[0] ." (".$contact[$v[0]].") \t\t\t". $v[1] ." appels");
var_dump("\n\n\nOBJET COMPLET");
var_dump( $sms );
var_dump( $call );
var_dump( $contact );
foreach($directory as $num=>$name)
echo $num.' <> '.$name.'<br>';
}
parseCallLog();
debug();
/* () Test du client de l'API generique */

View File

@ -81,9 +81,10 @@
"call_log": {
"unserialize": {
"description": "Recupere le contenu d'un fichier XML de journal d'appel.",
"permissions": ["admin"],
"permissions": [],
"parameters": {
"filecontent": { "description": "Contenu du fichier XML", "type": "text" }
"file_content": { "description": "Contenu du fichier XML", "type": "text" },
"phone_number": { "description": "Numéro de téléphone de l'interrogé.", "type": "phone_number" }
}
}
},

View File

@ -22,8 +22,6 @@ function sociogramClass(container){
/* [2] Construction de la classe
=========================================================*/
sociogramClass.prototype = {
@ -89,32 +87,6 @@ sociogramClass.prototype = {
/* SURCHARGE DU GRAPH (@this.sigma.graph) -> Ajout de méthodes
*
*/
@ -122,25 +94,7 @@ sociogramClass.prototype.overloadGraph = function(){
sigma.classes.graph.addMethod('nodeNeighbors', this.overload.nodeNeighbors);
sigma.classes.graph.addMethod('nodeDirectNeighbors', this.overload.nodeDirectNeighbors);
this.log('graph overloaded');
}
};
@ -232,12 +186,6 @@ sociogramClass.prototype.load = function(){
@ -274,12 +222,6 @@ sociogramClass.prototype.nodeAt = function(x, y){
/* POSITIONNE LES VOISINS AUTOUR DU NOEUD COURANT
*
* @nodeId<String> Id du noeud courant
@ -308,12 +250,6 @@ sociogramClass.prototype.arrange = function(nodeId, pos, alone){
}
}
@ -326,12 +262,6 @@ sociogramClass.prototype.arrange = function(nodeId, pos, alone){
var neighborsCount = 0;
for( neighborId in neighborsId ){
neighbors[neighborId] = this.sigma.graph.nodes(neighborId);
@ -380,12 +310,6 @@ sociogramClass.prototype.arrange = function(nodeId, pos, alone){
/* RENVOIE LA LISTE DES VOISINS (DIRECTS & INDIRECTS) D'UN NOEUD DONNÉ
*
* @nodeId<String> Id du noeud en question
@ -426,12 +350,6 @@ sociogramClass.prototype.overload.nodeNeighbors = function(nodeId){
/* RENVOIE LA LISTE DES VOISINS DIRECTS D'UN NOEUD DONNÉ
*
* @nodeId<String> Id du noeud en question
@ -451,12 +369,6 @@ sociogramClass.prototype.overload.nodeDirectNeighbors = function(nodeId){
/* EXTRAIT LES NOEUDS DE LA RÉPONSE DE L'API
*
*/
@ -483,12 +395,6 @@ sociogramClass.prototype.extractNodesFromResponse = function(){
/* EXTRAIT LES NOEUDS DE LA RÉPONSE DE L'API
*
*/
@ -512,12 +418,6 @@ sociogramClass.prototype.extractEdgesFromResponse = function(){
/* AJOUTE LES NOEUDS AU RENDU (SIGMA GRAPH)
*
*/
@ -534,12 +434,6 @@ sociogramClass.prototype.addNodes = function(){
/* AJOUTE LES LIENS AU RENDU (SIGMA GRAPH)
*
*/
@ -551,12 +445,6 @@ sociogramClass.prototype.addEdges = function(){
/* FONCTION ACTIVÉE LORS DU CLIC SUR UN NOEUD
*
*/
@ -578,12 +466,6 @@ sociogramClass.prototype.bindings.clickNode = function(thisPtr, e){
/* FONCTION ACTIVÉE LORS DU CLIC DANS LE VIDE
*
*/
@ -599,396 +481,6 @@ sociogramClass.prototype.bindings.clickStage = function(thisPtr, e){
//
//
//
// /* (0.5) Surcharge graph */
// // On recupere les voisins d'un noeud
// if( typeof sigma.classes.graph.nodeNeighbors !== 'function ')
// sigma.classes.graph.addMethod('nodeNeighbors', function(nodeId){
// // On recupere les voisins du noeud courant
// var neighbors = this.allNeighborsIndex[nodeId];
//
// // Pile des voisins pour lesquels il faut chercher leurs voisins
// var stack = [];
// for( neighborId in neighbors ) stack.push(neighborId);
//
// // Tant qu'il reste des voisins a trouver
// while( stack.length > 0 ){
// var subneighbors = this.allNeighborsIndex[stack[0]];
// for( subId in subneighbors )
// // Si le voisin est pas deja dans la liste/pile, on l'ajoute a la liste des voisins
// if( neighbors[subId] == null ){
// stack.push(subId); // On ajoute a la pile
// neighbors[subId] = subneighbors[subId]; // On ajoute a la liste complete
// }
//
// stack.shift();
// }
//
//
// // On retourne le resultat
// return neighbors;
// });
//
// // On recupere les voisins directs d'un noeud
// if( typeof sigma.classes.graph.nodeDirectNeighbors !== 'function ')
// sigma.classes.graph.addMethod('nodeDirectNeighbors', function(nodeId){
// // On retourne les voisins directs
// return this.allNeighborsIndex[nodeId];
// });
//
//
//
//
//
//
//
// /* (0.8) Initialisation de SIGMA */
// SOCIOGRAM.sigma = new sigma({renderer: { container: SOCIOGRAM.container, 'type': 'canvas' }});
//
//
//
//
//
//
//
//
//
//
// /* (1) On recupere les informations via l'API */
// api.send(SOCIOGRAM.request, function(response){
// console.log( response );
// // Si erreur, on quitte
// if( response.ModuleError != 0 ) return;
//
// // Sinon on enregistre
// SOCIOGRAM.response = response;
//
//
//
//
//
//
//
// /* (2) Parametrage de SIGMA */
// SOCIOGRAM.sigma.settings({
// defaultNodeColor: '#348ed8',
// defaultLabelSize: 14,
// defaultLabelBGColor: "#ddd",
// defaultHoverLabelBGColor: "#002147",
// defaultLabelHoverColor: "#fff",
// labelThreshold: 10,
// defaultEdgeType: "line"
// });
//
//
//
//
//
//
//
// /* (3) On recupere la liste des noeuds */
// SOCIOGRAM.nodes = [];
//
// // Pour chaque alter
// for( var i = 0 ; i < SOCIOGRAM.response.data.alter.length ; i++ ){
// SOCIOGRAM.nodes.push({
// 'id': 'n-'+SOCIOGRAM.response.data.alter[i][0],
// 'label': SOCIOGRAM.response.data.alter[i][1],
// 'x': 0,
// 'y': 0,
// 'size': SOCIOGRAM.response.data.alter[i][2]
// });
// }
//
//
//
//
//
//
//
//
// /* (4) On recupere la liste des liens */
// SOCIOGRAM.edges = [];
//
// for( var i = 0 ; i < SOCIOGRAM.response.data.inter.length ; i++ ){
// SOCIOGRAM.edges.push({
// 'id': 'e-'+SOCIOGRAM.response.data.inter[i][0]+'-'+SOCIOGRAM.response.data.inter[i][1],
// 'source': 'n-'+SOCIOGRAM.response.data.inter[i][0],
// 'target': 'n-'+SOCIOGRAM.response.data.inter[i][1]
// });
// }
//
//
//
//
//
//
//
//
// /* (5) On ajoute nos noeuds */
// for( var i = 0 ; i < SOCIOGRAM.nodes.length ; i++)
// SOCIOGRAM.sigma.graph.addNode(SOCIOGRAM.nodes[i]);
//
//
//
//
//
//
// /* (6) On ajoute nos liens */
// for( var i = 0 ; i < SOCIOGRAM.edges.length ; i++)
// SOCIOGRAM.sigma.graph.addEdge(SOCIOGRAM.edges[i]);
//
//
//
//
//
//
// /* (7) Gestion des interactions */
// /* RETOURNE LA DISTANCE AVEC LE NOEUD LE PLUS PRES
// *
// * @x<float> Abscisse du point
// * @y<float> Ordonnees du point
// *
// * @return distance<float> Retourne la distance du noeud le plus proche
// *
// */
// SOCIOGRAM.nodeAt = function(x, y){
// var nodes = SOCIOGRAM.sigma.graph.nodes();
// var minDistance = null;
//
// for( nodeId in nodes ){
// var distance = Math.sqrt( Math.pow(x-nodes[nodeId].x, 2) + Math.pow(y-nodes[nodeId].y, 2) );
// if( minDistance == null || distance < minDistance )
// minDistance = distance;
// }
//
// return minDistance;
// };
//
//
//
// /* POSITIONNE LES VOISINS AUTOUR DU NOEUD COURANT
// *
// * @nodeId<String> Id du noeud courant
// * @pos<Object> Contient {x, y} position initiale, sinon la position actuelle du noeud
// *
// */
// SOCIOGRAM.arrange = function(nodeId, pos, alone){
// var node = SOCIOGRAM.sigma.graph.nodes(nodeId);
//
// // Si le noeud est deja place, on ne fais rien
// if( node.x != 0 || node.y != 0 ) return;
//
// var pos = (pos==null) ? {x: node.x, y: node.y} : pos; // On recupere la position
//
// // Tant que le noeud est trop proche d'un autre, on l'eloigne
// // UNIQUEMENT si alone n'est pas NULL
// if( alone ){
// while( SOCIOGRAM.nodeAt(pos.x, pos.y) < 2*SOCIOGRAM.nodeDistance ){
// pos = {
// x: pos.x + 2*SOCIOGRAM.nodeDistance*Math.cos(Math.random()*2*Math.PI),
// y: pos.y + 2*SOCIOGRAM.nodeDistance*Math.sin(Math.random()*2*Math.PI)
// };
// }
// }
//
// // On recupere les voisins directs
// var neighborsId = SOCIOGRAM.sigma.graph.nodeDirectNeighbors(nodeId);
// var neighbors = {};
// var neighborsCount = 0;
// for( neighborId in neighborsId ){
// neighbors[neighborId] = SOCIOGRAM.sigma.graph.nodes(neighborId);
// neighborsCount++;
// }
//
//
// // On positionne le noeud
// node.x = pos.x;
// node.y = pos.y;
//
// var angles = [];
//
// // On positionne chaque voisin si c'est pas deja fait
// for( neighborId in neighbors ){
// var current = SOCIOGRAM.sigma.graph.nodes(neighborId);
// // Si n'est pas deja positionne
// if( current.x == 0 && current.y == 0 ){
// // On cherche un angle tant qu'il est pas trop pres d'un deja pris
// var angle, alreadyUsed = false;
// do{
// angle = Math.random()*2*Math.PI;
// for( var i = 0 ; i < angles.length ; i++ )
// if( Math.abs(angle-angles[i]) > Math.PI/10 ){
// alreadyUsed = true;
// break;
// }
//
// }while( alreadyUsed );
//
// current.x = pos.x + SOCIOGRAM.nodeDistance*Math.cos(angle);
// current.y = pos.y + SOCIOGRAM.nodeDistance*Math.sin(angle);
// SOCIOGRAM.arrange(current.id);
// }
// }
//
// SOCIOGRAM.sigma.refresh();
// };
//
// // On affiche que les voisins d'un noeud
// SOCIOGRAM.sigma.bind('clickNode', function(e){
// var nodeId = e.data.node.id;
// // On recupere les voisins
// var neighborNodes = SOCIOGRAM.sigma.graph.nodeNeighbors(nodeId);
// neighborNodes[nodeId] = e.data.node; // on ajoute le noeud clique
//
// SOCIOGRAM.sigma.graph.nodes().forEach(function(n) {
// if( neighborNodes[n.id] != null ) n.color = n.originalColor;
// else n.color = '#eee';
// });
//
// SOCIOGRAM.sigma.refresh();
// });
//
// // On affiche tous les noeuds quand on clique dans le vide
// SOCIOGRAM.sigma.bind('clickStage', function(e){
// SOCIOGRAM.sigma.graph.nodes().forEach(function(n){ n.color = n.originalColor; });
//
// SOCIOGRAM.sigma.refresh();
// });
//
//
//
//
//
//
// /* (8) On affiche le graphique */
// SOCIOGRAM.sigma.camera.ratio = 1.2;
//
// // On repartit les noeuds
// SOCIOGRAM.sigma.refresh();
// SOCIOGRAM.sigma.graph.nodes().forEach(function(n){ SOCIOGRAM.arrange(n.id, null, true); });
//
// SOCIOGRAM.sigma.refresh();
//
// });
@ -1033,10 +525,6 @@ sociogramClass.prototype.bindings.clickStage = function(thisPtr, e){
// ['x', 'y', 'size', 'color'].forEach(function(val) {
// o[val] = o['grid_' + val];
// });

View File

@ -1,10 +1,10 @@
<?php
namespace manager;
class DataBase{
/* ATTRIBUTS STATIQUES */
public static $config_path = array(
'local' => 'f/json/database-local/conf',
@ -29,8 +29,8 @@
$this->dbname = $dbname;
$this->username = $username;
$this->password = $password;
try{
try{
self::$pdo = new \PDO('mysql:host='.$this->host.';dbname='.$this->dbname, $this->username, $this->password);
// On signale que tout s'est bien passe
@ -57,7 +57,7 @@
self::$instance = new DataBase($conf['host'], $conf['dbname'], $conf['user'], $conf['password']);
}
return self::$instance;
}
@ -104,7 +104,7 @@
* @fetchData<Array> le résultat d'une $requeteSQL->fetchAll()
* @oneDimension<Boolean> FAUX <=> fetchAll ; VRAI <=> fetch
*
* @return newFetchData<Array> retourne le tableau donné en paramètre mais sans les valeurs à clés numériques
* @return newFetchData<Array> retourne le tableau donné en paramètre mais sans les valeurs à clés numériques
*
*/
public static function delNumeric($fetchData, $oneDimension=false){
@ -121,19 +121,19 @@
// on supprime les doublons des entrées (indice numérique)
for( $i = 0 ; $i < count($fetchData) ; $i++ ) // pour tout les utilisateurs
foreach($fetchData[$i] as $col => $val){ // pour toutes les entrées
if( !mb_detect_encoding($val, 'UTF-8') )
$fetchData[$i][$col] = utf8_encode($val);
if( is_int($col) ){ // Si indice numerique
if( $nextEquivalent ) // Si suit un indice textuel
unset( $fetchData[$i][$col] ); // on supprime l'indice
$nextEquivalent = false; // Dans tous les cas, on dit que le prochain ne pourra pas etre supprime si numerique
}else // Si l'indice n'est pas un entier
$nextEquivalent = true; // On signale qu'il y aura peut etre un indice numerique suivant
}
/* [2] 1 dimensions
@ -142,14 +142,14 @@
// on supprime les doublons des entrées (indice numérique)
foreach($fetchData as $i=>$val){ // pour toutes les entrées
if( !mb_detect_encoding($val, 'UTF-8') )
$fetchData[$i] = utf8_encode($val);
if( is_int($i) ){ // Si indice numerique
if( $nextEquivalent ) // Si suit un indice textuel
unset( $fetchData[$i] ); // on supprime l'indice
$nextEquivalent = false; // Dans tous les cas, on dit que le prochain ne pourra pas etre supprime si numerique
}else // Si l'indice n'est pas un entier
@ -165,8 +165,8 @@
////////////////////////////////////////////////////////////////
// _ __ _ _ _
// __ _____ _ __(_)/ _(_) ___ __ _| |_(_) ___ _ __ ___
// _ __ _ _ _
// __ _____ _ __(_)/ _(_) ___ __ _| |_(_) ___ _ __ ___
// \ \ / / _ \ '__| | |_| |/ __/ _` | __| |/ _ \| '_ \/ __|
// \ V / __/ | | | _| | (_| (_| | |_| | (_) | | | \__ \
// \_/ \___|_| |_|_| |_|\___\__,_|\__|_|\___/|_| |_|___/
@ -223,9 +223,9 @@
return true;
}
/* [n] Sinon, tous les autres types definis
=========================================================*/
=========================================================*/
switch($type){
// Entier positif (id dans BDD)
case 'id':
@ -240,12 +240,18 @@
case 'mail':
return $checker && is_string($value) && strlen($value) <= 50 && preg_match('/^[\w\.-]+@[\w\.-]+\.[a-z]{2,4}$/i', $value);
break;
// Hash sha1
case 'sha1':
return $checker && is_string($value) && preg_match('/^[\da-f]{40}$/i', $value);
break;
break;
// Numéro de téléphone
case 'phone_number':
return $checker && is_string($value) && preg_match('/^(?:0|\+33 ?|0?0?33 ?|)([1-9] ?(?:[0-9] ?){8})$/i', $value);
break;
default:
return false;
break;
@ -257,8 +263,8 @@
////////////////////////////////////
// _ _
// __| | __ _| |_ ___ ___
// _ _
// __| | __ _| |_ ___ ___
// / _` |/ _` | __/ _ \/ __|
// | (_| | (_| | || __/\__ \
// \__,_|\__,_|\__\___||___/

View File

@ -9,6 +9,34 @@
class call_log{
/* FONCTION QUI FORMATTE UN NUMÉRO DE TÉLÉPHONE
*
* @number<String> Numéro de téléphone en +336/336/06
*
* @return formatted<String> Numéro formatté (06), on FALSE si erreur
*
*/
private static function formatNumber($number){
// On met en <string> quel que soit le type
$number = (string) $number;
// On supprime tous les espaces
$number = str_replace(' ', '', $number);
// On formatte le numéro
if( preg_match("/^(?:\+33|0?0?33|0)(.+)/", $number, $m) )
$number = '0'.$m[1];
// On retourne le numéro formatté
return $number;
}
/* DESERIALISATION D'UN JOURNAL D'APPEL
*
* @content<String> Le contenu du journal d'appel a deserialiser
@ -19,93 +47,42 @@
*
*/
public static function unserialize($params){
$content = null;
$file_content = null;
extract($params);
/* [2] On recupere le xml
// On formatte le numéro de téléphone
$phone_number = self::formatNumber($phone_number);
/* [1] On parse/récupère le xml
=========================================================*/
$xml = simplexml_load_string($content);
$xml = simplexml_load_string($file_content);
// Si le format XML n'est pas bon, on retourne une erreur
if( $xml === false )
return array('ModuleError' => ManagerError::ParsingFailed);
/* [3] Initialisation des variables
/* [2] On lit chaque élément
=========================================================*/
$names = array(); // Contiendra les correspondances numero/contact
$msms = array(); // Contiendra les personnes utilisant SMS/MMS
$call = array(); // Contiendra les personnes utilisant CALL
$phone_directory = array(); // Contiendra les correspondances num->Nom
$phone_logs = array(); // Contiendra nos logs (appels/sms)
/* [4] On traite les donnees pour chaque champ du xml
=========================================================*/
foreach($xml->Item as $log){
// On recupere le numero en string
$num = (string) $log['Number'];
/* (1) On formatte le numéro */
$number = self::formatNumber($log['Number']);
// On formatte le numero
if( preg_match("/^(?:\+33|33|0)(.+)/", $num, $m) )
$num = '0'.$m[1];
// Si pas un numero, on sort de la boucle
else
continue;
/* (2) On enregistre le contact dans l'annuaire s'il y est pas déjà */
if( !isset($phone_directory[$number]) )
$phone_directory[$number] = strlen($log['Name']) ? $log['Name'] : null;
/* (1) Si le type est MMS ou SMS */
if( $log['Type'] == 'SMS' || $log['Type'] == 'MMS' ){
// Si la personne n'est pas referencee, on l'ajoute
// Sinon on incremente son nombre d'apparition
if( isset($msms[$num]) )
$msms[$num]+= 1;
else
$msms[$num] = 1;
// On enregistre le nom si c'est pas fait
if( !isset($names[$num]) ) $names[$num] = $log['Name'];
/* (2) Si le type est PHONE */
}else if( $log['Type'] == 'PHONE' ){
// Si la personne n'est pas referencee, on l'ajoute
// Sinon on incremente son nombre d'apparition
if( isset($call[$num]) )
$call[$num]+= 1;
else
$call[$num] = 1;
// On enregistre le nom si c'est pas fait
if( !isset($names[$num]) ) $names[$num] = $log['Name'];
}
}
/* [4] On trie par nombre d'interactions (sms/appel)
=========================================================*/
$tmp = $msms;
/* (1) Tri des SMS/MMS */
$sortedMSMS = array();
// On fait le tri pour les 10 premiers elements sauf s'il en a moins
for( $i = 0 ; $i < 10 && $i < count($tmp) ; $i++ ){
$maxval = max($tmp);
$maxkey = array_search($maxval, $tmp);
array_push( $sortedMSMS, array($maxkey, $maxval) );
unset($tmp[$maxkey]);
}
$tmp = $call;
/* (2) Tri des appels */
$sortedCALL = array();
// On fait le tri pour les 10 premiers elements sauf s'il en a moins
for( $i = 0 ; $i < 10 && $i < count($tmp) ; $i++ ){
$maxval = max($tmp);
$maxkey = array_search($maxval, $tmp);
array_push( $sortedCALL, array($maxkey, $maxval) );
unset($tmp[$maxkey]);
/* (3) On complète le log */
$phone_log = array(
'source' => ($log['Direction']=='INCOMING') ? $number : self::formatNumber($phone_number),
'target' => ($log['Direction']=='INCOMING') ? self::formatNumber($phone_number) : $number,
'type' => strtolower($log['Type']),
'date' => strtotime($log['Date']),
'duration' => (int) $log['Duration']
);
array_push($phone_logs, $phone_log);
}
@ -113,15 +90,144 @@
=========================================================*/
return array(
'ModuleError' => ManagerError::Success,
'sms' => $sortedMSMS,
'call' => $sortedCALL,
'contact' => $names
'directory' => $phone_directory,
'logs' => $phone_logs
);
}
/* DESERIALISATION D'UN JOURNAL D'APPEL
*
* @content<String> Le contenu du journal d'appel a deserialiser
*
* @return sms<Array> Retourne un tableau associatif contenant les sms triees
* @return call<Array> Retourne un tableau associatif contenant les appels triees
* @return contact<Array> Retourne un tableau associatif contenant les correspondances numero/nom de contact
*
*/
private static function unserializeOld($params){
$filecontent = null;
extract($params);
/* [2] On recupere le xml
=========================================================*/
$xml = simplexml_load_string($filecontent);
// Si le format XML n'est pas bon, on retourne une erreur
if( $xml === false )
return array('ModuleError' => ManagerError::ParsingFailed);
return array( 'ModuleError' => ManagerError::Success, 'xml' => $xml );
/* [3] Initialisation des variables
=========================================================*/
$names = array(); // Contiendra les correspondances numero/contact
$msms = array(); // Contiendra les personnes utilisant SMS/MMS
$call = array(); // Contiendra les personnes utilisant CALL
/* [4] On traite les donnees pour chaque champ du xml
=========================================================*/
foreach($xml->Item as $log){
// On recupere le numero en string
$num = (string) $log['Number'];
// On formatte le numero
if( preg_match("/^(?:\+33|33|0)(.+)/", $num, $m) )
$num = '0'.$m[1];
// Si pas un numero, on sort de la boucle
else
continue;
/* (1) Si le type est MMS ou SMS */
if( $log['Type'] == 'SMS' || $log['Type'] == 'MMS' ){
// Si la personne n'est pas referencee, on l'ajoute
// Sinon on incremente son nombre d'apparition
if( isset($msms[$num]) )
$msms[$num]+= 1;
else
$msms[$num] = 1;
// On enregistre le nom si c'est pas fait
if( !isset($names[$num]) ) $names[$num] = $log['Name'];
/* (2) Si le type est PHONE */
}else if( $log['Type'] == 'PHONE' ){
// Si la personne n'est pas referencee, on l'ajoute
// Sinon on incremente son nombre d'apparition
if( isset($call[$num]) )
$call[$num]+= 1;
else
$call[$num] = 1;
// On enregistre le nom si c'est pas fait
if( !isset($names[$num]) ) $names[$num] = $log['Name'];
}
}
/* [4] On trie par nombre d'interactions (sms/appel)
=========================================================*/
$tmp = $msms;
/* (1) Tri des SMS/MMS */
$sortedMSMS = array();
// On fait le tri pour les 10 premiers elements sauf s'il en a moins
for( $i = 0 ; $i < 10 && $i < count($tmp) ; $i++ ){
$maxval = max($tmp);
$maxkey = array_search($maxval, $tmp);
array_push( $sortedMSMS, array($maxkey, $maxval) );
unset($tmp[$maxkey]);
}
$tmp = $call;
/* (2) Tri des appels */
$sortedCALL = array();
// On fait le tri pour les 10 premiers elements sauf s'il en a moins
for( $i = 0 ; $i < 10 && $i < count($tmp) ; $i++ ){
$maxval = max($tmp);
$maxkey = array_search($maxval, $tmp);
array_push( $sortedCALL, array($maxkey, $maxval) );
unset($tmp[$maxkey]);
}
/* [5] Gestion du retour
=========================================================*/
return array(
'ModuleError' => ManagerError::Success,
'sms' => $sortedMSMS,
'call' => $sortedCALL,
'contact' => $names
);
}
}

34
tags

File diff suppressed because one or more lines are too long