You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
2.0 KiB
59 lines
2.0 KiB
<?php
|
|
|
|
namespace Zitec\RuleEngineBundle\Admin;
|
|
|
|
use Zitec\RuleEngineBundle\DoctrineBehaviors\PreconditionInterface;
|
|
use Zitec\RuleEngineBundle\DoctrineBehaviors\RuleInterface;
|
|
use Zitec\RuleEngineBundle\Service\RuleConditionsManager;
|
|
use Zitec\RuleEngineBundle\Service\RuleJsonConverter;
|
|
use Sonata\AdminBundle\Datagrid\ListMapper;
|
|
use Sonata\AdminBundle\Form\FormMapper;
|
|
use Sonata\AdminBundle\Form\Type\AdminType;
|
|
|
|
|
|
/**
|
|
* Class RuleAdminTrait
|
|
* A trait that should be used in Sonata Admin classes for RuleEngine-aware entities.
|
|
*/
|
|
trait PostconditionAdminTrait
|
|
{
|
|
|
|
/**
|
|
* @param RuleInterface $subject
|
|
* @return array
|
|
*/
|
|
public function formatPostcondition(PostconditionInterface $subject)
|
|
{
|
|
$ruleManager = $this->getRuleManager($subject);
|
|
$formatter = new RuleJsonConverter();
|
|
if($subject->getPostcondition()===null){
|
|
return $formatter->formatForDisplay('{}', $ruleManager);
|
|
}
|
|
return $formatter->formatForDisplay($subject->getPostcondition()->getJson(), $ruleManager);
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* @param FormMapper $formMapper
|
|
* @param array $options
|
|
*/
|
|
protected function addPostconditionFormElement(FormMapper $formMapper, array $options = [])
|
|
{
|
|
$ruleManager = $this->getRuleManager();
|
|
$options = $options + ['label' => false];
|
|
$formMapper->add('postcondition', AdminType::class, $options, ['rule_manager' => $ruleManager,'admin_code' => 'postcondition.admin']);
|
|
}
|
|
|
|
|
|
protected function addPostconditionListColumns(ListMapper $list)
|
|
{
|
|
$list->add('postcondition.name')
|
|
->add('postcondition.active', 'boolean', ['editable' => true])
|
|
->add('postcondition', null, ['template' => 'ZitecRuleEngineBundle:Admin:json_postcondition_field.html.twig']);
|
|
// In dev environment, display the expression too.
|
|
if ($this->getConfigurationPool()->getContainer()->has('kernel.debug')) {
|
|
$list->add('postcondition.expression', null, ['header_style' => 'width: 20%; text-align: center']);
|
|
}
|
|
}
|
|
}
|