66 lines
2.5 KiB
JavaScript
66 lines
2.5 KiB
JavaScript
// last execution: 2026-08-28 02:45:01
|
|
logAdd(log);
|
|
|
|
$entities = Entity\GetMany('TargetList', 1, 'name', 'asc', 'name=', 'Sympathisanten');
|
|
$n = array\length($entities);
|
|
|
|
ifThenElse($n == 0,
|
|
logAdd(log, 'warning', 'Geen "Sympathisanten" doellijst, maak deze eerst aan!');
|
|
,
|
|
logAdd(log, 'info', 'Sympathisanten doellijst aanwezig, leden worden vervangen...');
|
|
|
|
$doellijst = array\at($entities, 0);
|
|
$id = attr($doellijst, 'id');
|
|
|
|
logAdd(log, 'info', 'Verwijderen leden met regiocode <>40');
|
|
$rows = record\fetchRelatedManyHash('TargetList', $id,
|
|
'contacts', 'id, lastName, regiocode',
|
|
'lastName', 'asc'
|
|
);
|
|
$n = array\length($rows);
|
|
logAdd(log, 'info', 'Aantal gerelateerde leden: ', $n);
|
|
$i = 0;
|
|
$rcnt = 0;
|
|
while($i < $n,
|
|
$row = array\at($rows, $i);
|
|
$code = hash\get($row, 'regiocode');
|
|
ifThen($code != '40',
|
|
$lastname = hash\get($row, 'lastName');
|
|
$contact_id = hash\get($row, 'id');
|
|
logAdd(log, 'info', 'Verwijderen: ', $lastname, '; regiocode=', $code);
|
|
record\unrelate('TargetList', $id, 'contacts', $contact_id);
|
|
$rcnt = $rcnt + 1;
|
|
);
|
|
$i = $i + 1;
|
|
);
|
|
|
|
logAdd(log, 'info', 'Relateren leden met regiocode =40');
|
|
$rows = record\fetchManyHash('Contact', 'id, lastName, regiocode', 'lastName', 'asc');
|
|
$n = array\length($rows);
|
|
logAdd(log, 'info', 'Aantal leden om te beoordelen: ', $n);
|
|
$i = 0;
|
|
$cnt = 0;
|
|
$hom_cnt = 0;
|
|
while($i < $n,
|
|
$row = array\at($rows, $i);
|
|
$code = hash\get($row, 'regiocode');
|
|
ifThen($code == '40',
|
|
$hom_cnt = $hom_cnt + 1;
|
|
$contact_id = hash\get($row, 'id');
|
|
$r_id = record\findRelatedMany('TargetList', $id,
|
|
'contacts', 1, 'createdAt', 'desc',
|
|
'id=', $contact_id
|
|
);
|
|
ifThen(!$r_id,
|
|
$lastname = hash\get($row, 'lastName');
|
|
logAdd(log, 'info', 'Toevoegen lid: ', $lastname);
|
|
record\relate('TargetList', $id, 'contacts', $contact_id);
|
|
$cnt = $cnt + 1;
|
|
);
|
|
);
|
|
$i = $i + 1;
|
|
);
|
|
logAdd(log, 'info', $cnt, ' leden toegevoegd');
|
|
logAdd(log, 'info', $rcnt, ' leden verwijderd');
|
|
logAdd(log, 'info', $hom_cnt, ' leden in de lijst');
|
|
); |