2016-04-30 10:19:51 +00:00
|
|
|
<?php
|
|
|
|
|
2016-10-18 13:11:37 +00:00
|
|
|
namespace api\module;
|
2016-04-30 10:19:51 +00:00
|
|
|
use \manager\sessionManager;
|
2016-11-05 10:56:03 +00:00
|
|
|
use \database\core\DatabaseDriver;
|
2016-04-30 10:19:51 +00:00
|
|
|
use \manager\ManagerError;
|
2016-10-18 13:11:37 +00:00
|
|
|
use \api\core\ModuleRequest;
|
|
|
|
use \database\core\Repo;
|
|
|
|
use \lightdb\core\lightdb;
|
2016-04-30 10:19:51 +00:00
|
|
|
|
2016-06-20 05:54:40 +00:00
|
|
|
|
2016-04-30 10:19:51 +00:00
|
|
|
class input{
|
|
|
|
|
|
|
|
/* TRAITE LES DONNÉES D'UN FORMULAIRE DE TYPE TÉLÉPHONIQUE
|
|
|
|
*
|
2016-04-30 14:13:37 +00:00
|
|
|
* @subject<Array> Tableau contenant les données du sujet
|
|
|
|
* @contacts<Array> Tableau contenant les données des contacts
|
|
|
|
* @mini<Array> Tableau contenant les données des mini fiches relation
|
|
|
|
* @fiches<Array> Tableau contenant les données des fiches relation
|
2016-04-30 10:19:51 +00:00
|
|
|
*
|
|
|
|
* @return subject_id<int> Retourne l'id sujet de l'enquête
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static function phone($params){
|
|
|
|
extract($params);
|
|
|
|
|
2016-05-17 15:05:32 +00:00
|
|
|
/* [0] On récupère l'id unique actuel
|
2016-04-30 10:19:51 +00:00
|
|
|
=========================================================*/
|
2016-10-18 13:11:37 +00:00
|
|
|
$funiq = fopen( __BUILD__.'/src/dynamic/uniqid', 'r+' );
|
2016-05-17 15:05:32 +00:00
|
|
|
flock($funiq, LOCK_EX); // On verrouille le fichier
|
|
|
|
$uniqid = fgets( $funiq );
|
2016-05-17 14:51:24 +00:00
|
|
|
|
|
|
|
if( !is_numeric($uniqid) )
|
|
|
|
$uniqid = 0;
|
2016-05-09 09:01:43 +00:00
|
|
|
|
2016-05-17 14:51:24 +00:00
|
|
|
// Décalage à appliquer à tous les ids
|
2016-05-26 17:43:50 +00:00
|
|
|
$offset = intval($uniqid) + 1;
|
2016-05-09 09:01:43 +00:00
|
|
|
|
2016-05-18 08:08:34 +00:00
|
|
|
// on enregistre l'id du sujet
|
2016-05-26 17:43:50 +00:00
|
|
|
$subject_id = $subject['subject_id'];
|
2016-05-18 08:08:34 +00:00
|
|
|
|
2016-05-17 14:51:24 +00:00
|
|
|
// Contiendra la valeur de l'id maximum
|
2016-05-18 08:08:34 +00:00
|
|
|
$maxId = 0;
|
2016-05-17 14:51:24 +00:00
|
|
|
|
2016-05-09 09:01:43 +00:00
|
|
|
|
|
|
|
|
2016-05-09 09:46:12 +00:00
|
|
|
|
2016-05-17 15:05:32 +00:00
|
|
|
/* [1] On récupère les logs s'ils existent
|
2016-05-13 16:26:30 +00:00
|
|
|
=========================================================*/
|
|
|
|
// Contiendra le contenu du fichier
|
2016-09-12 16:04:53 +00:00
|
|
|
$file = [ 'logs' => [] ];
|
2016-05-09 09:46:12 +00:00
|
|
|
|
|
|
|
|
2016-05-18 07:41:36 +00:00
|
|
|
/* (1) On définit les 2 fichiers utiles */
|
2016-10-18 13:11:37 +00:00
|
|
|
$tmpfile = __BUILD__.'/tmp/phone_'.$subject['tmp_id'].'.json';
|
2016-05-09 09:46:12 +00:00
|
|
|
|
2016-05-18 07:41:36 +00:00
|
|
|
/* (2) Si on a déja crée le fichier avec le journal d'appel dedans, on le récupère */
|
|
|
|
$storage_already = is_string($subject['tmp_id']) && strlen($subject['tmp_id']) == 40 && file_exists($tmpfile);
|
|
|
|
|
2016-05-09 09:46:12 +00:00
|
|
|
|
2016-05-13 16:26:30 +00:00
|
|
|
/* (3) Si on a déja crée le fichier, on essaie de récupérer son contenu */
|
|
|
|
if( $storage_already ){
|
2016-05-17 14:51:24 +00:00
|
|
|
$file = json_decode( file_get_contents($tmpfile), true );
|
2016-05-09 09:46:12 +00:00
|
|
|
|
2016-05-13 16:26:30 +00:00
|
|
|
// erreur
|
|
|
|
if( $file == null )
|
2016-09-12 16:04:53 +00:00
|
|
|
return [ 'ModuleRequest' => ManagerError::ParsingFailed ];
|
2016-05-17 14:51:24 +00:00
|
|
|
|
|
|
|
// On incrémente tous les ids de l'offset
|
|
|
|
foreach($file['logs'] as $i=>$log){
|
|
|
|
$file['logs'][$i]['id'] = $offset + $log['id'];
|
2016-05-18 08:08:34 +00:00
|
|
|
|
2016-05-17 14:51:24 +00:00
|
|
|
if( $log['id'] > $maxId )
|
|
|
|
$maxId = (int) $log['id'];
|
|
|
|
}
|
2016-05-13 16:26:30 +00:00
|
|
|
}
|
2016-05-09 09:46:12 +00:00
|
|
|
|
2016-05-09 09:01:43 +00:00
|
|
|
|
2016-05-09 12:12:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2016-05-17 15:05:32 +00:00
|
|
|
/* [2] On enregistre les données du sujet
|
2016-05-09 12:12:02 +00:00
|
|
|
=========================================================*/
|
2016-09-12 16:04:53 +00:00
|
|
|
$file['subject'] = [ 'id' => $subject_id ];
|
2016-05-09 12:12:02 +00:00
|
|
|
|
|
|
|
|
2016-05-17 15:05:32 +00:00
|
|
|
/* [3] On enregistre les contacts des MINI
|
2016-05-13 16:26:30 +00:00
|
|
|
=========================================================*/
|
2016-09-12 16:04:53 +00:00
|
|
|
$file['contacts'] = [];
|
|
|
|
$file['relations'] = [];
|
2016-05-09 12:12:02 +00:00
|
|
|
|
2016-05-13 16:26:30 +00:00
|
|
|
foreach($mini as $miniData){
|
|
|
|
// On récupère les données du contact associé
|
|
|
|
$contact = $contacts[ $miniData['uid'] ];
|
2016-05-09 12:12:02 +00:00
|
|
|
|
2016-05-17 14:51:24 +00:00
|
|
|
if( $miniData['uid'] > $maxId )
|
|
|
|
$maxId = (int) $miniData['uid'];
|
|
|
|
|
2016-05-30 14:54:41 +00:00
|
|
|
$newId = $offset + $miniData['uid'];
|
|
|
|
|
2016-05-13 16:26:30 +00:00
|
|
|
// On remplit les données qui iront dans le fichier pour ce contact
|
2016-09-12 16:04:53 +00:00
|
|
|
array_push($file['contacts'], [
|
2016-05-30 14:54:41 +00:00
|
|
|
'id' => $newId,
|
2016-05-19 13:14:10 +00:00
|
|
|
'name' => $contact['username'],
|
2016-05-13 16:26:30 +00:00
|
|
|
'sexe' => $miniData['sexe'],
|
|
|
|
'age' => $miniData['age'],
|
|
|
|
'studies1' => $miniData['studies'],
|
|
|
|
'reltype' => ($miniData['reltype']==10) ? $miniData['reltypeSpecial'] : $miniData['reltype'], // si 'autre' -> valeur, sinon le code
|
|
|
|
'dist' => $miniData['loc']
|
2016-09-12 16:04:53 +00:00
|
|
|
]);
|
2016-05-09 12:12:02 +00:00
|
|
|
|
2016-05-30 14:54:41 +00:00
|
|
|
// On enregistre la relation avec EGO
|
2016-09-12 16:04:53 +00:00
|
|
|
array_push($file['relations'], [
|
2016-05-30 14:54:41 +00:00
|
|
|
'idA' => $subject_id,
|
|
|
|
'idB' => $newId,
|
|
|
|
'type' => 2 // relation cellulaire mineure
|
2016-09-12 16:04:53 +00:00
|
|
|
]);
|
2016-05-30 14:54:41 +00:00
|
|
|
|
2016-05-09 09:01:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-17 15:05:32 +00:00
|
|
|
/* [4] On enregistre les contacts des FICHES
|
2016-05-09 17:02:57 +00:00
|
|
|
=========================================================*/
|
2016-05-30 14:54:41 +00:00
|
|
|
foreach($fiches as $f=>$ficheData){
|
2016-05-13 16:26:30 +00:00
|
|
|
// On récupère les données du contact associé
|
|
|
|
$contact = $contacts[ $ficheData['uid'] ];
|
2016-05-09 17:02:57 +00:00
|
|
|
|
2016-05-17 14:51:24 +00:00
|
|
|
if( $ficheData['uid'] > $maxId )
|
|
|
|
$maxId = (int) $ficheData['uid'];
|
|
|
|
|
2016-05-30 14:54:41 +00:00
|
|
|
$newId = $offset + $ficheData['uid'];
|
|
|
|
|
2016-05-13 16:26:30 +00:00
|
|
|
// On remplit les données qui iront dans le fichier pour ce contact
|
2016-09-12 16:04:53 +00:00
|
|
|
array_push($file['contacts'], [
|
2016-05-30 14:54:41 +00:00
|
|
|
'id' => $newId,
|
2016-05-19 13:14:10 +00:00
|
|
|
'name' => $contact['username'],
|
2016-05-13 16:26:30 +00:00
|
|
|
'sexe' => $ficheData['sexe'],
|
|
|
|
'age' => $ficheData['age'],
|
|
|
|
'studies2' => $ficheData['studies'],
|
|
|
|
'reltype' => ($ficheData['reltype']==10) ? $ficheData['reltypeSpecial'] : $ficheData['reltype'], // si 'autre' -> valeur, sinon le code
|
|
|
|
'dist' => $ficheData['loc'],
|
|
|
|
'job' => $ficheData['job'],
|
|
|
|
'famsit' => $ficheData['famsit'],
|
|
|
|
'city' => $ficheData['city'],
|
|
|
|
'cp' => $ficheData['cp'],
|
2016-05-29 15:51:06 +00:00
|
|
|
'quartier' => $ficheData['quartier'],
|
2016-05-13 16:26:30 +00:00
|
|
|
'duration' => $ficheData['duration'],
|
|
|
|
'context' => $ficheData['context'],
|
|
|
|
'contextExtra' => $ficheData['contextSpecial'],
|
|
|
|
'freq' => $ficheData['freq'],
|
|
|
|
'connect' => $ficheData['connect'],
|
|
|
|
'connectExtra' => $ficheData['connectSpecial']
|
2016-09-12 16:04:53 +00:00
|
|
|
]);
|
2016-05-09 17:02:57 +00:00
|
|
|
|
2016-05-30 14:54:41 +00:00
|
|
|
// On enregistre la relation avec EGO
|
2016-09-12 16:04:53 +00:00
|
|
|
array_push($file['relations'], [
|
2016-05-30 14:54:41 +00:00
|
|
|
'idA' => $subject_id,
|
|
|
|
'idB' => $newId,
|
|
|
|
'type' => ($f<10) ? 4 : 5 // 4->appels 5->sms
|
2016-09-12 16:04:53 +00:00
|
|
|
]);
|
2016-05-30 14:54:41 +00:00
|
|
|
|
2016-05-13 16:26:30 +00:00
|
|
|
}
|
2016-05-09 17:02:57 +00:00
|
|
|
|
|
|
|
|
2016-05-17 15:05:32 +00:00
|
|
|
/* [5] On enregistre les relations de la MATRICE
|
2016-05-09 17:02:57 +00:00
|
|
|
=========================================================*/
|
2016-05-30 14:54:41 +00:00
|
|
|
$clen = count($file['contacts']);
|
|
|
|
|
|
|
|
/* (1) On récupére les ids des contacts */
|
2016-09-12 16:04:53 +00:00
|
|
|
$cIdList = [];
|
2016-05-30 14:54:41 +00:00
|
|
|
foreach($file['contacts'] as $c=>$contact){
|
|
|
|
$id = $contact['id'] - $offset;
|
|
|
|
if( !in_array($id, $cIdList) )
|
|
|
|
$cIdList[$id] = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
ksort($cIdList);
|
|
|
|
|
|
|
|
|
|
|
|
/* (2) On remplit les relations */
|
|
|
|
foreach($cIdList as $y=>$yNull){
|
|
|
|
foreach($cIdList as $x=>$xNull)
|
|
|
|
if( $x < $y ){ // On affiche que sous la diagonale
|
2016-05-12 19:47:52 +00:00
|
|
|
|
2016-05-30 14:54:41 +00:00
|
|
|
$idY = $file['contacts'][$y]['id'] - $offset;
|
|
|
|
$idX = $file['contacts'][$x]['id'] - $offset;
|
|
|
|
|
|
|
|
// Si relation alter-alter
|
|
|
|
$relationXY = isset($matrice[$y]) && in_array($x, $matrice[$y])
|
|
|
|
|| ( isset($matrice[$x]) && in_array($y, $matrice[$x]) );
|
|
|
|
|
2016-09-12 16:04:53 +00:00
|
|
|
array_push($file['relations'], [
|
2016-05-30 14:54:41 +00:00
|
|
|
'idA' => $offset + $x,
|
|
|
|
'idB' => $offset + $y,
|
|
|
|
'type' => $relationXY ? 1 : 0 // 0->aucune relation 1->relation alter alter
|
2016-09-12 16:04:53 +00:00
|
|
|
]);
|
2016-05-30 14:54:41 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2016-05-12 19:47:52 +00:00
|
|
|
|
|
|
|
|
2016-05-17 15:05:32 +00:00
|
|
|
/* [6] On enregistre tout dans 'lightdb'
|
2016-05-17 14:51:24 +00:00
|
|
|
=========================================================*/
|
2016-10-18 13:11:37 +00:00
|
|
|
$db = new lightdb('phone_db');
|
2016-05-18 14:04:17 +00:00
|
|
|
$db->insert( $subject_id, $file );
|
|
|
|
$db->close();
|
|
|
|
|
|
|
|
/* [7] On met à jour le nouvel ID unique
|
|
|
|
=========================================================*/
|
|
|
|
// $maxId += $offset;
|
|
|
|
rewind($funiq); // On revient au début du fichier
|
|
|
|
fwrite($funiq, $offset+$maxId); // On écrit la nouvelle valeur (forcément plus grande)
|
|
|
|
flock($funiq, LOCK_UN); // On débloque le verrou
|
|
|
|
fclose($funiq);
|
|
|
|
|
|
|
|
/* [8] On supprime le fichier temporaire si existe
|
|
|
|
=========================================================*/
|
|
|
|
if( file_exists($tmpfile) )
|
|
|
|
unlink($tmpfile);
|
|
|
|
|
|
|
|
|
|
|
|
/* [9] Gestion du retour
|
|
|
|
=========================================================*/
|
2016-09-12 16:04:53 +00:00
|
|
|
return [
|
2016-05-18 14:04:17 +00:00
|
|
|
'ModuleError' => ManagerError::Success,
|
|
|
|
'subject_id' => $subject_id
|
2016-09-12 16:04:53 +00:00
|
|
|
];
|
2016-05-18 14:04:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* TRAITE LES DONNÉES D'UN FORMULAIRE DE TYPE FACEBOOK
|
|
|
|
*
|
|
|
|
* @subject<Array> Tableau contenant les données du sujet
|
|
|
|
* @contacts<Array> Tableau contenant les données des contacts
|
|
|
|
* @mini<Array> Tableau contenant les données des mini fiches relation
|
|
|
|
* @fiches<Array> Tableau contenant les données des fiches relation
|
|
|
|
*
|
|
|
|
* @return subject_id<int> Retourne l'id sujet de l'enquête
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static function facebook($params){
|
|
|
|
extract($params);
|
|
|
|
|
|
|
|
/* [0] On récupère l'id unique actuel
|
|
|
|
=========================================================*/
|
2016-10-18 13:11:37 +00:00
|
|
|
$funiq = fopen( __BUILD__.'/src/dynamic/uniqid', 'r+' );
|
2016-05-18 14:04:17 +00:00
|
|
|
flock($funiq, LOCK_EX); // On verrouille le fichier
|
|
|
|
$uniqid = fgets( $funiq );
|
|
|
|
|
|
|
|
if( !is_numeric($uniqid) )
|
|
|
|
$uniqid = 0;
|
|
|
|
|
|
|
|
// Décalage à appliquer à tous les ids
|
2016-05-26 17:43:50 +00:00
|
|
|
$offset = intval($uniqid) + 1;
|
2016-05-18 14:04:17 +00:00
|
|
|
|
|
|
|
// on enregistre l'id du sujet
|
2016-05-26 17:43:50 +00:00
|
|
|
$subject_id = $subject['subject_id'];
|
2016-05-18 14:04:17 +00:00
|
|
|
|
|
|
|
// Contiendra la valeur de l'id maximum
|
|
|
|
$maxId = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-05-18 14:21:42 +00:00
|
|
|
/* [1] On enregistre les données du sujet
|
2016-05-18 14:04:17 +00:00
|
|
|
=========================================================*/
|
2016-09-12 16:04:53 +00:00
|
|
|
$file['subject'] = [ 'id' => $subject_id ];
|
2016-05-18 14:04:17 +00:00
|
|
|
|
|
|
|
|
2016-05-18 14:21:42 +00:00
|
|
|
/* [2] On enregistre les contacts des MINI
|
2016-05-18 14:04:17 +00:00
|
|
|
=========================================================*/
|
2016-09-12 16:04:53 +00:00
|
|
|
$file['contacts'] = [];
|
|
|
|
$file['relations'] = [];
|
2016-05-18 14:04:17 +00:00
|
|
|
|
|
|
|
foreach($mini as $miniData){
|
|
|
|
// On récupère les données du contact associé
|
|
|
|
$contact = $contacts[ $miniData['uid'] ];
|
|
|
|
|
|
|
|
if( $miniData['uid'] > $maxId )
|
|
|
|
$maxId = (int) $miniData['uid'];
|
|
|
|
|
2016-05-30 14:54:41 +00:00
|
|
|
$newId = $offset + $miniData['uid'];
|
|
|
|
|
2016-05-18 14:04:17 +00:00
|
|
|
// On remplit les données qui iront dans le fichier pour ce contact
|
2016-09-12 16:04:53 +00:00
|
|
|
array_push($file['contacts'], [
|
2016-05-30 14:54:41 +00:00
|
|
|
'id' => $newId,
|
2016-05-19 13:14:10 +00:00
|
|
|
'name' => $contact['username'],
|
2016-05-18 14:04:17 +00:00
|
|
|
'sexe' => $miniData['sexe'],
|
|
|
|
'age' => $miniData['age'],
|
|
|
|
'studies1' => $miniData['studies'],
|
|
|
|
'reltype' => ($miniData['reltype']==10) ? $miniData['reltypeSpecial'] : $miniData['reltype'], // si 'autre' -> valeur, sinon le code
|
|
|
|
'dist' => $miniData['loc']
|
2016-09-12 16:04:53 +00:00
|
|
|
]);
|
2016-05-18 14:04:17 +00:00
|
|
|
|
2016-05-30 14:54:41 +00:00
|
|
|
// On enregistre la relation avec EGO
|
2016-09-12 16:04:53 +00:00
|
|
|
array_push($file['relations'], [
|
2016-05-30 14:54:41 +00:00
|
|
|
'idA' => $subject_id,
|
|
|
|
'idB' => $newId,
|
|
|
|
'type' => 3 // relation facebook mineure
|
2016-09-12 16:04:53 +00:00
|
|
|
]);
|
2016-05-30 14:54:41 +00:00
|
|
|
|
2016-05-18 14:04:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-30 14:54:41 +00:00
|
|
|
/* [4] On enregistre les contacts des FICHES
|
2016-05-18 14:04:17 +00:00
|
|
|
=========================================================*/
|
2016-05-30 14:54:41 +00:00
|
|
|
foreach($fiches as $f=>$ficheData){
|
2016-05-18 14:04:17 +00:00
|
|
|
// On récupère les données du contact associé
|
|
|
|
$contact = $contacts[ $ficheData['uid'] ];
|
|
|
|
|
|
|
|
if( $ficheData['uid'] > $maxId )
|
|
|
|
$maxId = (int) $ficheData['uid'];
|
|
|
|
|
2016-05-30 14:54:41 +00:00
|
|
|
$newId = $offset + $ficheData['uid'];
|
|
|
|
|
2016-05-18 14:04:17 +00:00
|
|
|
// On remplit les données qui iront dans le fichier pour ce contact
|
2016-09-12 16:04:53 +00:00
|
|
|
array_push($file['contacts'], [
|
2016-05-30 14:54:41 +00:00
|
|
|
'id' => $newId,
|
2016-05-19 13:14:10 +00:00
|
|
|
'name' => $contact['username'],
|
2016-05-18 14:04:17 +00:00
|
|
|
'sexe' => $ficheData['sexe'],
|
|
|
|
'age' => $ficheData['age'],
|
|
|
|
'studies2' => $ficheData['studies'],
|
|
|
|
'reltype' => ($ficheData['reltype']==10) ? $ficheData['reltypeSpecial'] : $ficheData['reltype'], // si 'autre' -> valeur, sinon le code
|
|
|
|
'dist' => $ficheData['loc'],
|
|
|
|
'job' => $ficheData['job'],
|
|
|
|
'famsit' => $ficheData['famsit'],
|
|
|
|
'city' => $ficheData['city'],
|
|
|
|
'cp' => $ficheData['cp'],
|
2016-05-30 14:54:41 +00:00
|
|
|
'quartier' => $ficheData['quartier'],
|
2016-05-18 14:04:17 +00:00
|
|
|
'duration' => $ficheData['duration'],
|
|
|
|
'context' => $ficheData['context'],
|
|
|
|
'contextExtra' => $ficheData['contextSpecial'],
|
|
|
|
'freq' => $ficheData['freq'],
|
|
|
|
'connect' => $ficheData['connect'],
|
|
|
|
'connectExtra' => $ficheData['connectSpecial']
|
2016-09-12 16:04:53 +00:00
|
|
|
]);
|
2016-05-18 14:04:17 +00:00
|
|
|
|
2016-05-30 14:54:41 +00:00
|
|
|
// On enregistre la relation avec EGO
|
2016-09-12 16:04:53 +00:00
|
|
|
array_push($file['relations'], [
|
2016-05-30 14:54:41 +00:00
|
|
|
'idA' => $subject_id,
|
|
|
|
'idB' => $newId,
|
|
|
|
'type' => ($f<10) ? 6 : 7 // 6->historique 7->messenger
|
2016-09-12 16:04:53 +00:00
|
|
|
]);
|
2016-05-30 14:54:41 +00:00
|
|
|
|
2016-05-18 14:04:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-30 14:54:41 +00:00
|
|
|
/* [5] On enregistre les relations de la MATRICE
|
2016-05-18 14:04:17 +00:00
|
|
|
=========================================================*/
|
2016-05-30 14:54:41 +00:00
|
|
|
foreach($file['contacts'] as $y=>$yContact)
|
|
|
|
foreach($file['contacts'] as $x=>$xContact)
|
|
|
|
if( $x < $y ){ // On affiche que sous la diagonale
|
|
|
|
|
|
|
|
// Si relation alter-alter
|
|
|
|
$relationXY = isset($matrice[$yContact['id']]) && in_array($xContact['id'], $matrice[$yContact['id']]);
|
|
|
|
|
2016-09-12 16:04:53 +00:00
|
|
|
array_push($file['relations'], [
|
2016-05-30 14:54:41 +00:00
|
|
|
'idA' => $yContact['id'],
|
|
|
|
'idB' => $xContact['id'],
|
|
|
|
'type' => $relationXY ? 1 : 0 // 0->aucune relation 1->relation alter alter
|
2016-09-12 16:04:53 +00:00
|
|
|
]);
|
2016-05-18 14:04:17 +00:00
|
|
|
|
2016-05-30 14:54:41 +00:00
|
|
|
}
|
2016-05-18 14:04:17 +00:00
|
|
|
|
|
|
|
|
2016-05-18 14:21:42 +00:00
|
|
|
/* [5] On enregistre tout dans 'lightdb'
|
2016-05-18 14:04:17 +00:00
|
|
|
=========================================================*/
|
2016-10-18 13:11:37 +00:00
|
|
|
$db = new lightdb('facebook_db');
|
2016-05-17 14:51:24 +00:00
|
|
|
$db->insert( $subject_id, $file );
|
|
|
|
$db->close();
|
2016-05-12 19:47:52 +00:00
|
|
|
|
2016-05-18 14:21:42 +00:00
|
|
|
/* [6] On met à jour le nouvel ID unique
|
2016-05-17 14:18:45 +00:00
|
|
|
=========================================================*/
|
2016-05-18 08:08:34 +00:00
|
|
|
// $maxId += $offset;
|
2016-05-17 15:05:32 +00:00
|
|
|
rewind($funiq); // On revient au début du fichier
|
2016-05-18 08:08:34 +00:00
|
|
|
fwrite($funiq, $offset+$maxId); // On écrit la nouvelle valeur (forcément plus grande)
|
2016-05-17 15:05:32 +00:00
|
|
|
flock($funiq, LOCK_UN); // On débloque le verrou
|
|
|
|
fclose($funiq);
|
2016-05-17 14:51:24 +00:00
|
|
|
|
2016-05-17 14:18:45 +00:00
|
|
|
|
2016-05-18 14:29:02 +00:00
|
|
|
/* [7] Gestion du retour
|
2016-04-30 10:19:51 +00:00
|
|
|
=========================================================*/
|
2016-09-12 16:04:53 +00:00
|
|
|
return [
|
2016-04-30 10:19:51 +00:00
|
|
|
'ModuleError' => ManagerError::Success,
|
2016-05-13 16:26:30 +00:00
|
|
|
'subject_id' => $subject_id
|
2016-09-12 16:04:53 +00:00
|
|
|
];
|
2016-04-30 10:19:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
?>
|