71 lines
2.1 KiB
PHP
71 lines
2.1 KiB
PHP
<?php
|
|
use CRM_Bij1migratie_ExtensionUtil as E;
|
|
|
|
/**
|
|
* Class voor BIJ1 migratie genereer lidnummer
|
|
*
|
|
* @author Erik Hommel (CiviCooP) <erik.hommel@civicoop.org>
|
|
* @date 27 Jan 2022
|
|
* @license AGPL-3.0
|
|
*/
|
|
class CRM_Bij1migratie_Lidnummer {
|
|
|
|
/**
|
|
* Method om lidnummers te genereren
|
|
*
|
|
* @return array
|
|
*/
|
|
public function genereer() {
|
|
$lid = new CRM_Bij1algemeen_Lid();
|
|
$sylvanaId = $this->vindSylvana();
|
|
// selecteer iedereen met een inschrijfdatum (behalve Sylvana)
|
|
if ($sylvanaId) {
|
|
$lid->bewaar($sylvanaId, 1);
|
|
$query = "SELECT entity_id AS contact_id
|
|
FROM civicrm_value_airtable_data
|
|
WHERE entity_id != %1 AND inschrijvingsdatum IS NOT NULL
|
|
ORDER BY inschrijvingsdatum";
|
|
$contact = CRM_Core_DAO::executeQuery($query, [1 => [$sylvanaId, "Integer"]]);
|
|
}
|
|
else {
|
|
$query = "SELECT entity_id AS contact_id
|
|
FROM civicrm_value_airtable_data
|
|
WHERE inschrijvingsdatum IS NOT NULL ORDER BY inschrijvingsdatum";
|
|
$contact = CRM_Core_DAO::executeQuery($query);
|
|
}
|
|
$maxLid = (int) Civi::settings()->get('bij1_laatste_lidnummer');
|
|
while ($contact->fetch()) {
|
|
$maxLid++;
|
|
$lid->bewaar((int) $contact->contact_id, $maxLid);
|
|
}
|
|
Civi::settings()->set("bij1_laatste_lidnummer", $maxLid);
|
|
}
|
|
|
|
/**
|
|
* Method om contact ID van Sylvana Simons te vinden
|
|
*
|
|
* @return int|FALSE
|
|
*/
|
|
private function vindSylvana() {
|
|
try {
|
|
$contacts = \Civi\Api4\Contact::get(FALSE)
|
|
->addSelect('id')
|
|
->addJoin('Email AS email', 'INNER', ['id', '=', 'email.contact_id'])
|
|
->addWhere('contact_type', '=', 'Individual')
|
|
->addWhere('first_name', '=', 'Sylvana')
|
|
->addWhere('last_name', '=', 'Simons')
|
|
->addWhere('email.email', '=', 'sylvana@bij1.org')
|
|
->execute();
|
|
$contact = $contacts->first();
|
|
if (isset($contact['id'])) {
|
|
return (int) $contact['id'];
|
|
}
|
|
}
|
|
catch (API_Exception $ex) {
|
|
Civi::log()->warning(E::ts("Kon geen contact ID voor Sylvana Simons vinden, er wordt geen lidnummer 1 aan haar verstrekt."));
|
|
}
|
|
return FALSE;
|
|
}
|
|
|
|
}
|