65 lines
1.3 KiB
PHP
Executable File
65 lines
1.3 KiB
PHP
Executable File
<?php define('__ROOT__', dirname(__DIR__));
|
|
|
|
require_once __ROOT__.'/autoloader.php';
|
|
|
|
debug();
|
|
|
|
use \lightdb\core\lightdb;
|
|
|
|
$sl = new lightdb('subject');
|
|
$cl = new lightdb('contact');
|
|
|
|
$LOG = true;
|
|
|
|
if( $LOG ){
|
|
|
|
var_dump('subjects');
|
|
foreach($sl->index() as $index=>$null)
|
|
var_dump( $index.' # '.$sl->fetch($index)['subject']['name'] );
|
|
|
|
$sub = $sl->fetch(1);
|
|
var_dump($sub['subject']);
|
|
|
|
var_dump( 'contacts: '.count($sub['contacts']) );
|
|
var_dump( 'relations: '.count($sub['relations']) );
|
|
|
|
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>";
|
|
}
|
|
|
|
$ct = $cl->fetch(595);
|
|
var_dump($ct);
|
|
|
|
}else{
|
|
|
|
/* [1] Remove contacts
|
|
=========================================================*/
|
|
$sub = $sl->fetch(1);
|
|
|
|
$cl->deleteAll( $sub['contacts'] );
|
|
|
|
$cl->flush(); // security
|
|
|
|
/* [2] Reset subject
|
|
=========================================================*/
|
|
|
|
unset( $sub['contacts'] );
|
|
unset( $sub['relations'] );
|
|
$sub['subject']['surveys'] = [];
|
|
|
|
$sl->delete(1);
|
|
$sl->insert(1, $sub);
|
|
|
|
}
|
|
|
|
$sl->close();
|
|
$cl->close();
|
|
|
|
|
|
?>
|