Initial commit: CloudOps infrastructure platform
This commit is contained in:
@@ -0,0 +1,593 @@
|
||||
<?php
|
||||
|
||||
namespace MauticPlugin\MauticFocusBundle\Entity;
|
||||
|
||||
use ApiPlatform\Metadata\ApiResource;
|
||||
use ApiPlatform\Metadata\Delete;
|
||||
use ApiPlatform\Metadata\Get;
|
||||
use ApiPlatform\Metadata\GetCollection;
|
||||
use ApiPlatform\Metadata\Patch;
|
||||
use ApiPlatform\Metadata\Post;
|
||||
use ApiPlatform\Metadata\Put;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Mautic\ApiBundle\Serializer\Driver\ApiMetadataDriver;
|
||||
use Mautic\CoreBundle\Doctrine\Mapping\ClassMetadataBuilder;
|
||||
use Mautic\CoreBundle\Entity\FormEntity;
|
||||
use Mautic\CoreBundle\Entity\UuidInterface;
|
||||
use Mautic\CoreBundle\Entity\UuidTrait;
|
||||
use Mautic\FormBundle\Entity\Form;
|
||||
use Mautic\ProjectBundle\Entity\ProjectTrait;
|
||||
use Symfony\Component\Serializer\Attribute\Groups;
|
||||
use Symfony\Component\Validator\Constraints\NotBlank;
|
||||
use Symfony\Component\Validator\Mapping\ClassMetadata;
|
||||
|
||||
#[ApiResource(
|
||||
operations: [
|
||||
new GetCollection(uriTemplate: '/focus_items', security: "is_granted('focus:items:viewown')"),
|
||||
new Get(uriTemplate: '/focus_items/{id}', security: "is_granted('focus:items:viewown')"),
|
||||
new Post(uriTemplate: '/focus_items', security: "is_granted('focus:items:create')"),
|
||||
new Put(uriTemplate: '/focus_items/{id}', security: "is_granted('focus:items:editown')"),
|
||||
new Patch(uriTemplate: '/focus_items/{id}', security: "is_granted('focus:items:editother')"),
|
||||
new Delete(uriTemplate: '/focus_items/{id}', security: "is_granted('focus:items:deleteown')"),
|
||||
],
|
||||
normalizationContext: [
|
||||
'groups' => ['focus:read'],
|
||||
'swagger_definition_name' => 'Read',
|
||||
],
|
||||
denormalizationContext: [
|
||||
'groups' => ['focus:write'],
|
||||
'swagger_definition_name' => 'Write',
|
||||
]
|
||||
)]
|
||||
class Focus extends FormEntity implements UuidInterface
|
||||
{
|
||||
use UuidTrait;
|
||||
use ProjectTrait;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
#[Groups(['focus:read'])]
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
#[Groups(['focus:read', 'focus:write'])]
|
||||
private $description;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
#[Groups(['focus:read', 'focus:write'])]
|
||||
private $editor;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
#[Groups(['focus:read', 'focus:write'])]
|
||||
private $html;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
#[Groups(['focus:read', 'focus:write'])]
|
||||
private $htmlMode;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
#[Groups(['focus:read', 'focus:write'])]
|
||||
private $name;
|
||||
|
||||
#[Groups(['focus:read', 'focus:write'])]
|
||||
private $category;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
#[Groups(['focus:read', 'focus:write'])]
|
||||
private $type;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
#[Groups(['focus:read', 'focus:write'])]
|
||||
private $website;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
#[Groups(['focus:read', 'focus:write'])]
|
||||
private $style;
|
||||
|
||||
/**
|
||||
* @var \DateTimeInterface
|
||||
*/
|
||||
#[Groups(['focus:read', 'focus:write'])]
|
||||
private $publishUp;
|
||||
|
||||
/**
|
||||
* @var \DateTimeInterface
|
||||
*/
|
||||
#[Groups(['focus:read', 'focus:write'])]
|
||||
private $publishDown;
|
||||
|
||||
/**
|
||||
* @var array<mixed>
|
||||
*/
|
||||
#[Groups(['focus:read', 'focus:write'])]
|
||||
private $properties = [];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
#[Groups(['focus:read', 'focus:write'])]
|
||||
private $utmTags = [];
|
||||
|
||||
/**
|
||||
* @var int|null
|
||||
*/
|
||||
private $form;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
private $cache;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->initializeProjects();
|
||||
}
|
||||
|
||||
public static function loadValidatorMetadata(ClassMetadata $metadata): void
|
||||
{
|
||||
$metadata->addPropertyConstraint(
|
||||
'name',
|
||||
new NotBlank(
|
||||
[
|
||||
'message' => 'mautic.core.name.required',
|
||||
]
|
||||
)
|
||||
);
|
||||
|
||||
$metadata->addPropertyConstraint(
|
||||
'type',
|
||||
new NotBlank(
|
||||
['message' => 'mautic.focus.error.select_type']
|
||||
)
|
||||
);
|
||||
|
||||
$metadata->addPropertyConstraint(
|
||||
'style',
|
||||
new NotBlank(
|
||||
['message' => 'mautic.focus.error.select_style']
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function __clone()
|
||||
{
|
||||
$this->id = null;
|
||||
|
||||
parent::__clone();
|
||||
}
|
||||
|
||||
public static function loadMetadata(ORM\ClassMetadata $metadata): void
|
||||
{
|
||||
$builder = new ClassMetadataBuilder($metadata);
|
||||
|
||||
$builder->setTable('focus')
|
||||
->setCustomRepositoryClass(FocusRepository::class)
|
||||
->addIndex(['focus_type'], 'focus_type')
|
||||
->addIndex(['style'], 'focus_style')
|
||||
->addIndex(['form_id'], 'focus_form')
|
||||
->addIndex(['name'], 'focus_name');
|
||||
|
||||
$builder->addIdColumns();
|
||||
|
||||
$builder->addCategory();
|
||||
|
||||
$builder->addNamedField('type', 'string', 'focus_type');
|
||||
|
||||
$builder->addField('style', 'string');
|
||||
|
||||
$builder->addNullableField('website', 'string');
|
||||
|
||||
$builder->addPublishDates();
|
||||
|
||||
$builder->addNullableField('properties', 'array');
|
||||
|
||||
$builder->createField('utmTags', 'array')
|
||||
->columnName('utm_tags')
|
||||
->nullable()
|
||||
->build();
|
||||
|
||||
$builder->addNamedField('form', 'integer', 'form_id', true);
|
||||
|
||||
$builder->addNullableField('cache', 'text');
|
||||
|
||||
$builder->createField('htmlMode', 'string')
|
||||
->columnName('html_mode')
|
||||
->nullable()
|
||||
->build();
|
||||
|
||||
$builder->addNullableField('editor', 'text');
|
||||
|
||||
$builder->addNullableField('html', 'text');
|
||||
|
||||
static::addUuidField($builder);
|
||||
self::addProjectsField($builder, 'focus_projects_xref', 'focus_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares the metadata for API usage.
|
||||
*/
|
||||
public static function loadApiMetadata(ApiMetadataDriver $metadata): void
|
||||
{
|
||||
$metadata->setGroupPrefix('focus')
|
||||
->addListProperties(
|
||||
[
|
||||
'id',
|
||||
'name',
|
||||
'category',
|
||||
]
|
||||
)
|
||||
->addProperties(
|
||||
[
|
||||
'description',
|
||||
'type',
|
||||
'website',
|
||||
'style',
|
||||
'publishUp',
|
||||
'publishDown',
|
||||
'properties',
|
||||
'utmTags',
|
||||
'form',
|
||||
'htmlMode',
|
||||
'html',
|
||||
'editor',
|
||||
'cache',
|
||||
]
|
||||
)
|
||||
->build();
|
||||
|
||||
self::addProjectsInLoadApiMetadata($metadata, 'focus');
|
||||
}
|
||||
|
||||
public function toArray(): array
|
||||
{
|
||||
return get_object_vars($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getDescription()
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $description
|
||||
*
|
||||
* @return Focus
|
||||
*/
|
||||
public function setDescription($description)
|
||||
{
|
||||
$this->isChanged('description', $description);
|
||||
|
||||
$this->description = $description;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getEditor()
|
||||
{
|
||||
return $this->editor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Focus
|
||||
*/
|
||||
public function setEditor($editor)
|
||||
{
|
||||
$this->isChanged('editor', $editor);
|
||||
|
||||
$this->editor = $editor;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getHtml()
|
||||
{
|
||||
return $this->html;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Focus
|
||||
*/
|
||||
public function setHtml($html)
|
||||
{
|
||||
$this->isChanged('html', $html);
|
||||
|
||||
$this->html = $html;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getHtmlMode()
|
||||
{
|
||||
return $this->htmlMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Focus
|
||||
*/
|
||||
public function setHtmlMode($htmlMode)
|
||||
{
|
||||
$this->isChanged('htmlMode', $htmlMode);
|
||||
|
||||
$this->htmlMode = $htmlMode;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $name
|
||||
*
|
||||
* @return Focus
|
||||
*/
|
||||
public function setName($name)
|
||||
{
|
||||
$this->isChanged('name', $name);
|
||||
|
||||
$this->name = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getCategory()
|
||||
{
|
||||
return $this->category;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $category
|
||||
*
|
||||
* @return Focus
|
||||
*/
|
||||
public function setCategory($category)
|
||||
{
|
||||
$this->isChanged('category', $category);
|
||||
|
||||
$this->category = $category;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getPublishUp()
|
||||
{
|
||||
return $this->publishUp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $publishUp
|
||||
*
|
||||
* @return Focus
|
||||
*/
|
||||
public function setPublishUp($publishUp)
|
||||
{
|
||||
$this->isChanged('publishUp', $publishUp);
|
||||
|
||||
$this->publishUp = $publishUp;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getPublishDown()
|
||||
{
|
||||
return $this->publishDown;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $publishDown
|
||||
*
|
||||
* @return Focus
|
||||
*/
|
||||
public function setPublishDown($publishDown)
|
||||
{
|
||||
$this->isChanged('publishDown', $publishDown);
|
||||
|
||||
$this->publishDown = $publishDown;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<mixed>
|
||||
*/
|
||||
public function getProperties()
|
||||
{
|
||||
return $this->properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<mixed> $properties
|
||||
*
|
||||
* @return Focus
|
||||
*/
|
||||
public function setProperties($properties)
|
||||
{
|
||||
$this->isChanged('properties', $properties);
|
||||
|
||||
$this->properties = $properties;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getUtmTags()
|
||||
{
|
||||
return $this->utmTags;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $utmTags
|
||||
*/
|
||||
public function setUtmTags($utmTags)
|
||||
{
|
||||
$this->isChanged('utmTags', $utmTags);
|
||||
$this->utmTags = $utmTags;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $type
|
||||
*
|
||||
* @return Focus
|
||||
*/
|
||||
public function setType($type)
|
||||
{
|
||||
$this->isChanged('type', $type);
|
||||
|
||||
$this->type = $type;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getStyle()
|
||||
{
|
||||
return $this->style;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $style
|
||||
*
|
||||
* @return Focus
|
||||
*/
|
||||
public function setStyle($style)
|
||||
{
|
||||
$this->isChanged('style', $style);
|
||||
|
||||
$this->style = $style;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getWebsite()
|
||||
{
|
||||
return $this->website;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $website
|
||||
*
|
||||
* @return Focus
|
||||
*/
|
||||
public function setWebsite($website)
|
||||
{
|
||||
$this->isChanged('website', $website);
|
||||
|
||||
$this->website = $website;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getForm()
|
||||
{
|
||||
return $this->form;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $form
|
||||
*
|
||||
* @return Focus
|
||||
*/
|
||||
public function setForm($form)
|
||||
{
|
||||
if ($form instanceof Form) {
|
||||
$form = $form->getId();
|
||||
}
|
||||
|
||||
$this->isChanged('form', $form);
|
||||
|
||||
$this->form = $form;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getCache()
|
||||
{
|
||||
return $this->cache;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $cache
|
||||
*
|
||||
* @return Focus
|
||||
*/
|
||||
public function setCache($cache)
|
||||
{
|
||||
$this->cache = $cache;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
|
||||
namespace MauticPlugin\MauticFocusBundle\Entity;
|
||||
|
||||
use Mautic\CoreBundle\Entity\CommonRepository;
|
||||
use Mautic\ProjectBundle\Entity\ProjectRepositoryTrait;
|
||||
|
||||
/**
|
||||
* @extends CommonRepository<Focus>
|
||||
*/
|
||||
class FocusRepository extends CommonRepository
|
||||
{
|
||||
use ProjectRepositoryTrait;
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function findByForm($formId)
|
||||
{
|
||||
return $this->findBy(
|
||||
[
|
||||
'form' => (int) $formId,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
public function getEntities(array $args = [])
|
||||
{
|
||||
$alias = $this->getTableAlias();
|
||||
|
||||
$q = $this->_em
|
||||
->createQueryBuilder()
|
||||
->select($alias)
|
||||
->from(Focus::class, $alias, $alias.'.id');
|
||||
|
||||
if (empty($args['iterable_mode'])) {
|
||||
$q->leftJoin($alias.'.category', 'c');
|
||||
}
|
||||
|
||||
$args['qb'] = $q;
|
||||
|
||||
return parent::getEntities($args);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Doctrine\ORM\QueryBuilder|\Doctrine\DBAL\Query\QueryBuilder $q
|
||||
*/
|
||||
protected function addCatchAllWhereClause($q, $filter): array
|
||||
{
|
||||
return $this->addStandardCatchAllWhereClause($q, $filter, ['f.name', 'f.website']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Doctrine\ORM\QueryBuilder|\Doctrine\DBAL\Query\QueryBuilder $q
|
||||
*/
|
||||
protected function addSearchCommandWhereClause($q, $filter): array
|
||||
{
|
||||
return match ($filter->command) {
|
||||
$this->translator->trans('mautic.project.searchcommand.name'),
|
||||
$this->translator->trans('mautic.project.searchcommand.name', [], null, 'en_US') => $this->handleProjectFilter(
|
||||
$this->_em->getConnection()->createQueryBuilder(),
|
||||
'focus_id',
|
||||
'focus_projects_xref',
|
||||
$this->getTableAlias(),
|
||||
$filter->string,
|
||||
$filter->not
|
||||
),
|
||||
default => $this->addStandardSearchCommandWhereClause($q, $filter),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getSearchCommands(): array
|
||||
{
|
||||
return array_merge([
|
||||
'mautic.project.searchcommand.name',
|
||||
], $this->getStandardSearchCommands());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<array<string>>
|
||||
*/
|
||||
protected function getDefaultOrder(): array
|
||||
{
|
||||
return [
|
||||
[$this->getTableAlias().'.name', 'ASC'],
|
||||
];
|
||||
}
|
||||
|
||||
public function getTableAlias(): string
|
||||
{
|
||||
return 'f';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getFocusList($currentId)
|
||||
{
|
||||
$q = $this->createQueryBuilder('f');
|
||||
$q->select('partial f.{id, name, description}')->orderBy('f.name');
|
||||
|
||||
return $q->getQuery()->getArrayResult();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,178 @@
|
||||
<?php
|
||||
|
||||
namespace MauticPlugin\MauticFocusBundle\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Mautic\CoreBundle\Doctrine\Mapping\ClassMetadataBuilder;
|
||||
use Mautic\LeadBundle\Entity\Lead;
|
||||
|
||||
class Stat
|
||||
{
|
||||
// Used for querying stats
|
||||
public const TYPE_FORM = 'submission';
|
||||
|
||||
public const TYPE_CLICK = 'click';
|
||||
|
||||
public const TYPE_NOTIFICATION = 'view';
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @var Focus
|
||||
*/
|
||||
private $focus;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $type;
|
||||
|
||||
/**
|
||||
* @var int|null
|
||||
*/
|
||||
private $typeId;
|
||||
|
||||
/**
|
||||
* @var \DateTimeInterface
|
||||
*/
|
||||
private $dateAdded;
|
||||
|
||||
/**
|
||||
* @var ?Lead
|
||||
*/
|
||||
private $lead;
|
||||
|
||||
public static function loadMetadata(ORM\ClassMetadata $metadata): void
|
||||
{
|
||||
$builder = new ClassMetadataBuilder($metadata);
|
||||
|
||||
$builder->setTable('focus_stats')
|
||||
->setCustomRepositoryClass(StatRepository::class)
|
||||
->addIndex(['type'], 'focus_type')
|
||||
->addIndex(['type', 'type_id'], 'focus_type_id')
|
||||
->addIndex(['date_added'], 'focus_date_added');
|
||||
|
||||
$builder->addId();
|
||||
|
||||
$builder->createManyToOne('focus', 'Focus')
|
||||
->addJoinColumn('focus_id', 'id', false, false, 'CASCADE')
|
||||
->build();
|
||||
|
||||
$builder->addField('type', 'string');
|
||||
|
||||
$builder->addNamedField('typeId', 'integer', 'type_id', true);
|
||||
|
||||
$builder->addNamedField('dateAdded', 'datetime', 'date_added');
|
||||
|
||||
$builder->addLead(true, 'SET NULL');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getFocus()
|
||||
{
|
||||
return $this->focus;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $focus
|
||||
*
|
||||
* @return Stat
|
||||
*/
|
||||
public function setFocus($focus)
|
||||
{
|
||||
$this->focus = $focus;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $type
|
||||
*
|
||||
* @return Stat
|
||||
*/
|
||||
public function setType($type)
|
||||
{
|
||||
$this->type = $type;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getTypeId()
|
||||
{
|
||||
return $this->typeId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $typeId
|
||||
*
|
||||
* @return Stat
|
||||
*/
|
||||
public function setTypeId($typeId)
|
||||
{
|
||||
$this->typeId = $typeId;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getDateAdded()
|
||||
{
|
||||
return $this->dateAdded;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $dateAdded
|
||||
*
|
||||
* @return Stat
|
||||
*/
|
||||
public function setDateAdded($dateAdded)
|
||||
{
|
||||
$this->dateAdded = $dateAdded;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ?Lead
|
||||
*/
|
||||
public function getLead()
|
||||
{
|
||||
return $this->lead;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Stat
|
||||
*/
|
||||
public function setLead(Lead $lead)
|
||||
{
|
||||
$this->lead = $lead;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
<?php
|
||||
|
||||
namespace MauticPlugin\MauticFocusBundle\Entity;
|
||||
|
||||
use Mautic\CoreBundle\Entity\CommonRepository;
|
||||
use Mautic\LeadBundle\Entity\TimelineTrait;
|
||||
|
||||
/**
|
||||
* @extends CommonRepository<Stat>
|
||||
*/
|
||||
class StatRepository extends CommonRepository
|
||||
{
|
||||
use TimelineTrait;
|
||||
|
||||
/**
|
||||
* Fetch the base stat data from the database.
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getStats($id, $type, $fromDate = null)
|
||||
{
|
||||
$q = $this->createQueryBuilder('s');
|
||||
|
||||
$expr = $q->expr()->andX(
|
||||
$q->expr()->eq('IDENTITY(s.focus)', (int) $id),
|
||||
$q->expr()->eq('s.type', ':type')
|
||||
);
|
||||
|
||||
if ($fromDate) {
|
||||
$expr->add(
|
||||
$q->expr()->gte('s.dateAdded', ':fromDate')
|
||||
);
|
||||
$q->setParameter('fromDate', $fromDate);
|
||||
}
|
||||
|
||||
$q->where($expr)
|
||||
->setParameter('type', $type);
|
||||
|
||||
return $q->getQuery()->getArrayResult();
|
||||
}
|
||||
|
||||
public function getViewsCount(int $id): int
|
||||
{
|
||||
$q = $this->_em->getConnection()->createQueryBuilder();
|
||||
|
||||
$q->select('COUNT(s.id) as views_count')
|
||||
->from(MAUTIC_TABLE_PREFIX.'focus_stats', 's');
|
||||
|
||||
$expr = $q->expr()->and(
|
||||
$q->expr()->eq('s.focus_id', ':id'),
|
||||
$q->expr()->eq('s.type', ':type')
|
||||
);
|
||||
|
||||
$q->where($expr)
|
||||
->setParameter('id', $id)
|
||||
->setParameter('type', Stat::TYPE_NOTIFICATION);
|
||||
|
||||
return (int) $q->executeQuery()->fetchOne();
|
||||
}
|
||||
|
||||
public function getUniqueViewsCount(int $id): int
|
||||
{
|
||||
$q = $this->_em->getConnection()->createQueryBuilder();
|
||||
|
||||
$q->select('COUNT(DISTINCT s.lead_id) as views_count')
|
||||
->from(MAUTIC_TABLE_PREFIX.'focus_stats', 's');
|
||||
|
||||
$expr = $q->expr()->and(
|
||||
$q->expr()->eq('s.focus_id', ':id'),
|
||||
$q->expr()->eq('s.type', ':type')
|
||||
);
|
||||
|
||||
$q->where($expr)
|
||||
->setParameter('id', $id)
|
||||
->setParameter('type', Stat::TYPE_NOTIFICATION);
|
||||
|
||||
return (int) $q->executeQuery()->fetchOne();
|
||||
}
|
||||
|
||||
public function getClickThroughCount(int $id): int
|
||||
{
|
||||
$q = $this->_em->getConnection()->createQueryBuilder();
|
||||
|
||||
$q->select('COUNT(DISTINCT s.lead_id) as click_through_count')
|
||||
->from(MAUTIC_TABLE_PREFIX.'focus_stats', 's');
|
||||
|
||||
$expr = $q->expr()->and(
|
||||
$q->expr()->eq('s.focus_id', ':id'),
|
||||
$q->expr()->eq('s.type', ':type')
|
||||
);
|
||||
|
||||
$q->where($expr)
|
||||
->setParameter('id', $id)
|
||||
->setParameter('type', Stat::TYPE_CLICK);
|
||||
|
||||
return (int) $q->executeQuery()->fetchOne();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $options
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function getStatsViewByLead(?int $leadId=null, array $options = []): array
|
||||
{
|
||||
return $this->getStatsByLeadAndType(Stat::TYPE_NOTIFICATION, $leadId, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $options
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function getStatsClickByLead(?int $leadId=null, array $options = []): array
|
||||
{
|
||||
return $this->getStatsByLeadAndType(Stat::TYPE_CLICK, $leadId, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $options
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function getStatsByLeadAndType(string $type, ?int $leadId=null, array $options = []): array
|
||||
{
|
||||
$q = $this->getEntityManager()->getConnection()->createQueryBuilder();
|
||||
|
||||
$q->from(MAUTIC_TABLE_PREFIX.'focus_stats', 's')
|
||||
->select('s.id, s.lead_id, s.type, s.date_added, f.id as focus_id, f.name as focus_name')
|
||||
->leftJoin('s', MAUTIC_TABLE_PREFIX.'focus', 'f', 's.focus_id=f.id');
|
||||
|
||||
$q->where($q->expr()->eq('s.type', ':type'));
|
||||
|
||||
if ($leadId) {
|
||||
$q->andWhere($q->expr()->eq('s.lead_id', (int) $leadId));
|
||||
}
|
||||
|
||||
$q->setParameter('type', $type);
|
||||
|
||||
if (isset($options['search']) && $options['search']) {
|
||||
$q->andWhere($q->expr()->or(
|
||||
$q->expr()->like('f.name', $q->expr()->literal($options['search'].'%')),
|
||||
$q->expr()->eq('s.type', $q->expr()->literal($options['search']))
|
||||
));
|
||||
}
|
||||
|
||||
return $this->getTimelineResults($q, $options, 'f.name', 's.date_added');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user