Skip to content

Commit

Permalink
Merge pull request #6388 from kuzmany/points-each-page
Browse files Browse the repository at this point in the history
Add repeatable points action
  • Loading branch information
Woeler committed Nov 10, 2018
2 parents 02f42e7 + 1046518 commit 1ff9ef6
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 13 deletions.
28 changes: 28 additions & 0 deletions app/bundles/PointBundle/Entity/Point.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ class Point extends FormEntity
*/
private $type;

/** @var bool */
private $repeatable;

/**
* @var \DateTime
*/
Expand Down Expand Up @@ -108,6 +111,9 @@ public static function loadMetadata(ORM\ClassMetadata $metadata)

$builder->addPublishDates();

$builder->createField('repeatable', 'boolean')
->build();

$builder->addField('delta', 'integer');

$builder->addField('properties', 'array');
Expand Down Expand Up @@ -163,6 +169,7 @@ public static function loadApiMetadata(ApiMetadataDriver $metadata)
'publishDown',
'delta',
'properties',
'repeatable',
]
)
->build();
Expand Down Expand Up @@ -402,4 +409,25 @@ public function setDelta($delta)
{
$this->delta = (int) $delta;
}

/**
* @param bool $repeatable
*
* @return Point
*/
public function setRepeatable($repeatable)
{
$this->isChanged('repeatable', $repeatable);
$this->repeatable = $repeatable;

return $this;
}

/**
* @return bool
*/
public function getRepeatable()
{
return $this->repeatable;
}
}
2 changes: 1 addition & 1 deletion app/bundles/PointBundle/Entity/PointRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function getTableAlias()
public function getPublishedByType($type)
{
$q = $this->createQueryBuilder('p')
->select('partial p.{id, type, name, delta, properties}')
->select('partial p.{id, type, name, delta, repeatable, properties}')
->setParameter('type', $type);

//make sure the published up and down dates are good
Expand Down
9 changes: 9 additions & 0 deletions app/bundles/PointBundle/Form/Type/PointType.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,15 @@ public function buildForm(FormBuilderInterface $builder, array $options)
'data' => $data,
]);

$builder->add(
'repeatable',
'yesno_button_group',
[
'label' => 'mautic.point.form.repeat',
'data' => $options['data']->getRepeatable() ?: false,
]
);

$builder->add('publishUp', 'datetime', [
'widget' => 'single_text',
'label' => 'mautic.core.form.publishup',
Expand Down
27 changes: 15 additions & 12 deletions app/bundles/PointBundle/Model/PointModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,12 +233,12 @@ public function triggerAction($type, $eventDetails = null, $typeId = null, Lead
$completedActions = $repo->getCompletedLeadActions($type, $lead->getId());

$persist = [];
/** @var Point $action */
foreach ($availablePoints as $action) {
//if it's already been done, then skip it
if (isset($completedActions[$action->getId()])) {
//if it's already been done or not repeatable, then skip it
if (!$action->getRepeatable() && isset($completedActions[$action->getId()])) {
continue;
}

//make sure the action still exists
if (!isset($availableActions['actions'][$action->getType()])) {
continue;
Expand Down Expand Up @@ -296,24 +296,27 @@ public function triggerAction($type, $eventDetails = null, $typeId = null, Lead
$event = new PointActionEvent($action, $lead);
$this->dispatcher->dispatch(PointEvents::POINT_ON_ACTION, $event);

$log = new LeadPointLog();
$log->setIpAddress($ipAddress);
$log->setPoint($action);
$log->setLead($lead);
$log->setDateFired(new \DateTime());

$persist[] = $log;
if (!$action->getRepeatable()) {
$log = new LeadPointLog();
$log->setIpAddress($ipAddress);
$log->setPoint($action);
$log->setLead($lead);
$log->setDateFired(new \DateTime());
$persist[] = $log;
}
}
}
}

if (!empty($persist)) {
$this->leadModel->saveEntity($lead);
$this->getRepository()->saveEntities($persist);

// Detach logs to reserve memory
$this->em->clear('Mautic\PointBundle\Entity\LeadPointLog');
}

if (!empty($lead->getpointchanges())) {
$this->leadModel->saveEntity($lead);
}
}

/**
Expand Down
1 change: 1 addition & 0 deletions app/bundles/PointBundle/Translations/en_US/messages.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ mautic.point.event.gained="Point gained"
mautic.point.form.addaction="Use the list to the right to add an action."
mautic.point.form.confirmbatchdelete="Delete the selected point actions?"
mautic.point.form.confirmdelete="Delete the point action, %name%?"
mautic.point.form.repeat="Allow repeat the action"
mautic.point.form.type="When a contact..."
mautic.point.menu.edit="Edit Point Action"
mautic.point.menu.index="Manage Actions"
Expand Down
1 change: 1 addition & 0 deletions app/bundles/PointBundle/Views/Point/form.html.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
<?php
echo $view['form']->row($form['category']);
echo $view['form']->row($form['isPublished']);
echo $view['form']->row($form['repeatable']);
echo $view['form']->row($form['publishUp']);
echo $view['form']->row($form['publishDown']);
?>
Expand Down
42 changes: 42 additions & 0 deletions app/migrations/Version20180730070549.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

/*
* @package Mautic
* @copyright 2018 Mautic Contributors. All rights reserved.
* @author Mautic
* @link http://mautic.org
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
*/

namespace Mautic\Migrations;

use Doctrine\DBAL\Migrations\SkipMigrationException;
use Doctrine\DBAL\Schema\Schema;
use Mautic\CoreBundle\Doctrine\AbstractMauticMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
class Version20180730070549 extends AbstractMauticMigration
{
/**
* @param Schema $schema
*
* @throws SkipMigrationException
* @throws \Doctrine\DBAL\Schema\SchemaException
*/
public function preUp(Schema $schema)
{
if ($schema->getTable($this->prefix.'points')->hasColumn('repeatable')) {
throw new SkipMigrationException('Schema includes this migration');
}
}

/**
* @param Schema $schema
*/
public function up(Schema $schema)
{
$this->addSql('ALTER TABLE '.$this->prefix.'points ADD repeatable TINYINT(1) NOT NULL;');
}
}

0 comments on commit 1ff9ef6

Please sign in to comment.