Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve activity demo data - more types #24314

Merged
merged 1 commit into from
Aug 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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