Skip to content

Commit

Permalink
Merge pull request #24314 from eileenmcnaughton/ql
Browse files Browse the repository at this point in the history
Improve activity demo data - more types
  • Loading branch information
colemanw authored Aug 20, 2022
2 parents f1c4a95 + e2b31ed commit ce2cb14
Show file tree
Hide file tree
Showing 2 changed files with 4,076 additions and 3,823 deletions.
39 changes: 30 additions & 9 deletions CRM/Core/CodeGen/GenerateData.php
Original file line number Diff line number Diff line change
Expand Up @@ -1295,43 +1295,64 @@ private function addNote() {

/**
* This method populates the civicrm_activity_history table
*
* @noinspection PhpUnusedPrivateMethodInspection
* @throws \Exception
*/
private function addActivity() {
private function addActivity(): void {
$contactDAO = new CRM_Contact_DAO_Contact();
$contactDAO->contact_type = 'Individual';
$contactDAO->selectAdd();
$contactDAO->selectAdd('id');
$contactDAO->orderBy('sort_name');
$contactDAO->find();

$activityTypes = CRM_Core_DAO::executeQuery(
"
SELECT label, name, value as activity_type_id
FROM civicrm_option_value
WHERE component_id IS NULL AND
-- this filter mostly gives us user-type actions like 'Phone' & 'Email'
-- but historically we have also included these two...
(filter = 0 OR name IN ('Tell A Friend', 'Pledge Acknowledgment'))
AND option_group_id IN (SELECT id from civicrm_option_group WHERE name = 'activity_type')
")->fetchAll();

$activityTypeOptions = [];
$nonAssignTypes = ['Pledge Acknowledgment', 'Print PDF Letter'];
foreach ($activityTypes as $activityType) {
$activityTypeOptions[$activityType['activity_type_id']] = ['label' => $activityType['label'], 'name' => $activityType['label']];
$activityTypeOptions[$activityType['activity_type_id']]['is_add_targets'] = !in_array($nonAssignTypes, $activityType['name'], TRUE);
}
$count = 0;
$activityContacts = CRM_Activity_BAO_ActivityContact::buildOptions('record_type_id', 'validate');
$activityContacts = array_flip(CRM_Activity_BAO_ActivityContact::buildOptions('record_type_id', 'validate'));

while ($contactDAO->fetch()) {
if ($count++ > 2) {
break;
}
for ($i = 0; $i < self::NUM_ACTIVITY; $i++) {
$activityTypeID = array_rand($activityTypeOptions);
$activityType = $activityTypeOptions[$activityTypeID];
$activityDAO = new CRM_Activity_DAO_Activity();
$activityId = CRM_Core_OptionGroup::values('activity_type', NULL, NULL, NULL, ' AND v.name IN ("Tell A Friend", "Pledge Acknowledgment")');
$activityTypeID = $this->randomIndex($activityId);
$activity = CRM_Core_PseudoConstant::activityType();
$activityDAO->activity_type_id = $activityTypeID;
$activityDAO->subject = "Subject for $activity[$activityTypeID]";
$activityDAO->subject = "Subject for {$activityType['label']}";
$activityDAO->duration = random_int(1, 6);
$activityDAO->activity_date_time = $this->randomDate();
$activityDAO->status_id = 2;
$this->_insert($activityDAO);

$activityContactDAO = new CRM_Activity_DAO_ActivityContact();
$activityContactDAO->activity_id = $activityDAO->id;
$activityContactDAO->contact_id = $contactDAO->id;
$activityContactDAO->record_type_id = CRM_Utils_Array::key('Activity Source', $activityContacts);
$activityContactDAO->record_type_id = $activityContacts['Activity Source'];
$this->_insert($activityContactDAO);

if ($activityTypeID == 9) {
if ($activityType['is_add_targets']) {
$activityContactDAO = new CRM_Activity_DAO_ActivityContact();
$activityContactDAO->activity_id = $activityDAO->id;
$activityContactDAO->contact_id = $this->randomInt(1, 101);
$activityContactDAO->record_type_id = CRM_Utils_Array::key('Activity Targets', $activityContacts);
$activityContactDAO->record_type_id = $activityContacts['Activity Targets'];
$this->_insert($activityContactDAO);
}
}
Expand Down
Loading

0 comments on commit ce2cb14

Please sign in to comment.