2016-11-22 10:06:03 +00:00
|
|
|
<?php define('__ROOT__', dirname(__DIR__));
|
|
|
|
|
|
|
|
require_once __ROOT__.'/autoloader.php';
|
|
|
|
|
2016-11-23 11:12:53 +00:00
|
|
|
debug();
|
|
|
|
|
2016-11-22 10:06:03 +00:00
|
|
|
use \lightdb\core\lightdb;
|
|
|
|
|
|
|
|
$sl = new lightdb('subject');
|
|
|
|
$cl = new lightdb('contact');
|
|
|
|
|
2016-11-23 12:38:15 +00:00
|
|
|
$LOG = true;
|
|
|
|
|
|
|
|
if( $LOG ){
|
|
|
|
|
2016-11-24 15:15:00 +00:00
|
|
|
var_dump('subjects');
|
|
|
|
foreach($sl->index() as $index=>$null)
|
|
|
|
var_dump( $index.' # '.$sl->fetch($index)['subject']['name'] );
|
|
|
|
|
2016-11-23 12:38:15 +00:00
|
|
|
$sub = $sl->fetch(1);
|
|
|
|
|
2016-11-23 15:57:52 +00:00
|
|
|
var_dump( count($sub['relations']) );
|
|
|
|
|
2016-11-23 12:38:15 +00:00
|
|
|
foreach($sub['relations'] as $rel){
|
|
|
|
if( $rel['idA'] == 1 )
|
|
|
|
$Aname = $sub['subject']['name'];
|
|
|
|
else
|
|
|
|
$Aname = $cl->fetch((int)$rel['idA'])['name'];
|
|
|
|
|
|
|
|
echo $Aname.'('.$rel['idA'].') + '.$cl->fetch((int)$rel['idB'])['name'].'('.$rel['idB'].') = '.$rel['type']."<br>";
|
|
|
|
}
|
|
|
|
|
|
|
|
}else{
|
2016-11-23 11:12:53 +00:00
|
|
|
|
|
|
|
/* [1] Remove contacts
|
|
|
|
=========================================================*/
|
|
|
|
$sub = $sl->fetch(1);
|
|
|
|
|
|
|
|
$cl->deleteAll( $sub['contacts'] );
|
|
|
|
|
2016-11-23 15:36:25 +00:00
|
|
|
$cl->flush(); // security
|
|
|
|
|
2016-11-23 11:12:53 +00:00
|
|
|
/* [2] Reset subject
|
|
|
|
=========================================================*/
|
|
|
|
|
|
|
|
unset( $sub['contacts'] );
|
|
|
|
unset( $sub['relations'] );
|
|
|
|
$sub['subject']['surveys'] = [];
|
2016-11-22 16:17:04 +00:00
|
|
|
|
2016-11-23 11:12:53 +00:00
|
|
|
$sl->delete(1);
|
|
|
|
$sl->insert(1, $sub);
|
2016-11-22 16:17:04 +00:00
|
|
|
|
2016-11-23 11:12:53 +00:00
|
|
|
}
|
2016-11-22 16:17:04 +00:00
|
|
|
|
2016-11-23 11:12:53 +00:00
|
|
|
$sl->close();
|
|
|
|
$cl->close();
|
2016-11-22 10:06:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
?>
|