Initial commit: CloudOps infrastructure platform

This commit is contained in:
root
2026-04-09 19:58:57 +02:00
commit 1166a52f26
7762 changed files with 839452 additions and 0 deletions

View File

@@ -0,0 +1,105 @@
<?php
declare(strict_types=1);
namespace Mautic\LeadBundle\Report;
use Mautic\LeadBundle\Entity\DoNotContact as DNC;
use Mautic\LeadBundle\Helper\DncFormatterHelper;
use Mautic\LeadBundle\Model\DoNotContact;
class DncReportService
{
public const DEFAULT_DNC_OPTIONS = [
['reason' => DNC::UNSUBSCRIBED, 'channel' => 'email'],
['reason' => DNC::BOUNCED, 'channel' => 'email'],
['reason' => DNC::MANUAL, 'channel' => 'email'],
];
public function __construct(
private DoNotContact $doNotContactModel,
private DncFormatterHelper $dncFormatterHelper,
) {
}
/**
* Returns the configuration for DNC columns used in reports.
*
* @return array<string, array<string, string>> an associative array defining DNC columns, including alias, label, type, and SQL formula
*/
public function getDncColumns(): array
{
return [
'dnc_preferences' => [
'alias' => 'dnc_preferences',
'label' => 'mautic.lead.report.dnc_preferences',
'type' => 'string',
'formula' => '(SELECT GROUP_CONCAT(CONCAT(dnc.reason, \':\', dnc.channel) ORDER BY dnc.date_added DESC SEPARATOR \',\') FROM '.MAUTIC_TABLE_PREFIX.'lead_donotcontact dnc WHERE dnc.lead_id = l.id)',
],
];
}
/**
* Returns the configuration for DNC filters used in reports.
*
* @return array<string, array<string, mixed>> an associative array defining DNC filters, including label, type, list options, and operators
*/
public function getDncFilters(): array
{
$dncOptions = $this->doNotContactModel->getReasonChannelCombinations();
$mergedOptions = array_unique(
array_merge($dncOptions, self::DEFAULT_DNC_OPTIONS),
SORT_REGULAR
);
$listOptions = [];
foreach ($mergedOptions as $dncOption) {
$key = "{$dncOption['channel']}:{$dncOption['reason']}";
$label = $this->dncFormatterHelper->printReasonWithChannel($dncOption['reason'], $dncOption['channel']);
$listOptions[$key] = $label;
}
return [
'dnc_preferences' => [
'label' => 'mautic.lead.report.dnc_preferences',
'type' => 'multiselect',
'list' => $listOptions,
'operators' => [
'in' => 'mautic.core.operator.in',
'notIn' => 'mautic.core.operator.notin',
'empty' => 'mautic.core.operator.isempty',
'notEmpty' => 'mautic.core.operator.isnotempty',
],
],
];
}
/**
* Processes and formats the DNC status display for each entry in the data array.
*
* @param array<int, array<string, mixed>> $data an array of data rows, each containing a 'dnc_preferences' key
*
* @return array<int, array<string, mixed>> the modified data array with formatted 'dnc_preferences' entries
*/
public function processDncStatusDisplay(array $data): array
{
if (empty($data) || !array_key_exists('dnc_preferences', $data[0])) {
return $data;
}
foreach ($data as &$row) {
if (!empty($row['dnc_preferences'])) {
$dncEntries = explode(',', $row['dnc_preferences']);
$dncText = array_map(function ($entry) {
list($reason, $channel) = explode(':', $entry);
return $this->dncFormatterHelper->printReasonWithChannel((int) $reason, $channel);
}, $dncEntries);
$row['dnc_preferences'] = implode(', ', $dncText);
}
}
return $data;
}
}

View File

@@ -0,0 +1,233 @@
<?php
namespace Mautic\LeadBundle\Report;
use Mautic\LeadBundle\Entity\LeadField;
use Mautic\LeadBundle\Model\FieldModel;
use Mautic\LeadBundle\Model\LeadModel;
use Mautic\LeadBundle\Model\ListModel;
use Mautic\UserBundle\Model\UserModel;
class FieldsBuilder
{
public function __construct(
private FieldModel $fieldModel,
private ListModel $listModel,
private UserModel $userModel,
private LeadModel $leadModel,
private DncReportService $dncReportService,
) {
}
/**
* @param string $prefix
*/
public function getLeadFieldsColumns($prefix): array
{
$baseColumns = $this->getBaseLeadColumns();
$leadFields = $this->fieldModel->getLeadFields();
$fieldColumns = $this->getFieldColumns($leadFields, $prefix);
return array_merge($baseColumns, $fieldColumns);
}
/**
* @param string $prefix
* @param string $segmentPrefix
*/
public function getLeadFilter($prefix, $segmentPrefix): array
{
$filters = $this->getLeadFieldsColumns($prefix);
$segmentPrefix = $this->sanitizePrefix($segmentPrefix);
$prefix = $this->sanitizePrefix($prefix);
// Append segment filters
$userSegments = $this->listModel->getUserLists();
$list = [];
foreach ($userSegments as $segment) {
$list[$segment['id']] = $segment['name'];
}
$segmentKey = $segmentPrefix.'leadlist_id';
$filters[$segmentKey] = [
'alias' => 'segment_id',
'label' => 'mautic.core.filter.lists',
'type' => 'select',
'list' => $list,
'operators' => [
'eq' => 'mautic.core.operator.equals',
],
];
$aTags = [];
$aTagsList = $this->leadModel->getTagList();
foreach ($aTagsList as $aTemp) {
$aTags[$aTemp['value']] = $aTemp['label'];
}
$filters['tag'] = [
'label' => 'mautic.core.filter.tags',
'type' => 'multiselect',
'list' => $aTags,
'operators' => [
'in' => 'mautic.core.operator.in',
'notIn' => 'mautic.core.operator.notin',
'empty' => 'mautic.core.operator.isempty',
'notEmpty' => 'mautic.core.operator.isnotempty',
],
];
// Add DNC Status filter
$filters = array_merge($filters, $this->dncReportService->getDncFilters());
$ownerPrefix = $prefix.'owner_id';
$ownersList = [];
$owners = $this->userModel->getUserList('', 0);
foreach ($owners as $owner) {
$ownersList[$owner['id']] = sprintf('%s %s', $owner['firstName'], $owner['lastName']);
}
$filters[$ownerPrefix] = [
'label' => 'mautic.lead.list.filter.owner',
'type' => 'select',
'list' => $ownersList,
];
return $filters;
}
/**
* @param string $prefix
*/
public function getCompanyFieldsColumns($prefix): array
{
$baseColumns = $this->getBaseCompanyColumns();
$companyFields = $this->fieldModel->getCompanyFields();
$fieldColumns = $this->getFieldColumns($companyFields, $prefix);
return array_merge($baseColumns, $fieldColumns);
}
private function getBaseLeadColumns(): array
{
return [
'l.id' => [
'label' => 'mautic.lead.report.contact_id',
'type' => 'int',
'link' => 'mautic_contact_action',
],
'i.ip_address' => [
'label' => 'mautic.core.ipaddress',
'type' => 'text',
],
'l.date_identified' => [
'label' => 'mautic.lead.report.date_identified',
'type' => 'datetime',
'groupByFormula' => 'DATE(l.date_identified)',
],
'l.date_added' => [
'label' => 'mautic.core.date.added',
'type' => 'datetime',
'groupByFormula' => 'DATE(l.date_added)',
],
'l.points' => [
'label' => 'mautic.lead.points',
'type' => 'int',
],
'l.owner_id' => [
'label' => 'mautic.lead.report.owner_id',
'type' => 'int',
],
'u.first_name' => [
'label' => 'mautic.lead.report.owner_firstname',
'type' => 'string',
],
'u.last_name' => [
'label' => 'mautic.lead.report.owner_lastname',
'type' => 'string',
],
'l.generated_email_domain' => [
'label' => 'mautic.lead.report.generated_email_domain',
'type' => 'string',
],
];
}
private function getBaseCompanyColumns(): array
{
return [
'comp.id' => [
'label' => 'mautic.lead.report.company.company_id',
'type' => 'int',
'link' => 'mautic_company_action',
],
'comp.companyname' => [
'label' => 'mautic.lead.report.company.company_name',
'type' => 'string',
'link' => 'mautic_company_action',
],
'comp.companycity' => [
'label' => 'mautic.lead.report.company.company_city',
'type' => 'string',
'link' => 'mautic_company_action',
],
'comp.companystate' => [
'label' => 'mautic.lead.report.company.company_state',
'type' => 'string',
'link' => 'mautic_company_action',
],
'comp.companycountry' => [
'label' => 'mautic.lead.report.company.company_country',
'type' => 'string',
'link' => 'mautic_company_action',
],
'comp.companyindustry' => [
'label' => 'mautic.lead.report.company.company_industry',
'type' => 'string',
'link' => 'mautic_company_action',
],
];
}
/**
* @param LeadField[] $fields
* @param string $prefix
*/
private function getFieldColumns($fields, $prefix): array
{
$prefix = $this->sanitizePrefix($prefix);
$columns = [];
foreach ($fields as $field) {
$type = match ($field->getType()) {
'boolean' => 'bool',
'date' => 'date',
'datetime' => 'datetime',
'time' => 'time',
'url' => 'url',
'email' => 'email',
'number' => 'float',
default => 'string',
};
$columns[$prefix.$field->getAlias()] = [
'label' => $field->getLabel(),
'type' => $type,
];
}
return $columns;
}
/**
* @param string $prefix
*/
private function sanitizePrefix($prefix): string
{
if (!str_contains($prefix, '.')) {
$prefix .= '.';
}
return $prefix;
}
}