Initial commit: CloudOps infrastructure platform
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace Mautic\FormBundle\ProgressiveProfiling;
|
||||
|
||||
use Mautic\FormBundle\Entity\Field;
|
||||
use Mautic\FormBundle\Entity\Form;
|
||||
|
||||
class DisplayCounter
|
||||
{
|
||||
private int $displayedFields = 0;
|
||||
|
||||
private int $alreadyAlwaysDisplayed = 0;
|
||||
|
||||
public function __construct(
|
||||
private Form $form,
|
||||
) {
|
||||
}
|
||||
|
||||
public function increaseDisplayedFields(): void
|
||||
{
|
||||
++$this->displayedFields;
|
||||
}
|
||||
|
||||
public function getDisplayFields(): int
|
||||
{
|
||||
return $this->displayedFields;
|
||||
}
|
||||
|
||||
public function increaseAlreadyAlwaysDisplayed(): void
|
||||
{
|
||||
++$this->alreadyAlwaysDisplayed;
|
||||
}
|
||||
|
||||
public function getAlreadyAlwaysDisplayed(): int
|
||||
{
|
||||
return $this->alreadyAlwaysDisplayed;
|
||||
}
|
||||
|
||||
public function getAlwaysDisplayFields(): int
|
||||
{
|
||||
$i= 0;
|
||||
/** @var Field $field */
|
||||
foreach ($this->form->getFields()->toArray() as $field) {
|
||||
if ($field->isAlwaysDisplay()) {
|
||||
++$i;
|
||||
}
|
||||
}
|
||||
|
||||
return $i;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
namespace Mautic\FormBundle\ProgressiveProfiling;
|
||||
|
||||
use Mautic\FormBundle\Entity\Field;
|
||||
use Mautic\FormBundle\Entity\Form;
|
||||
|
||||
class DisplayManager
|
||||
{
|
||||
private DisplayCounter $displayCounter;
|
||||
|
||||
public function __construct(
|
||||
private Form $form,
|
||||
private array $viewOnlyFields = [],
|
||||
) {
|
||||
$this->displayCounter = new DisplayCounter($form);
|
||||
}
|
||||
|
||||
public function showForField(Field $field): bool
|
||||
{
|
||||
if (in_array($field->getType(), $this->viewOnlyFields)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Always Display field priority until hit limit
|
||||
if ($field->isAlwaysDisplay()) {
|
||||
if ($this->form->getProgressiveProfilingLimit() <= $this->displayCounter->getDisplayFields()) {
|
||||
return false;
|
||||
} else {
|
||||
$this->displayCounter->increaseAlreadyAlwaysDisplayed();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->shouldDisplayNotAlwaysDisplayField($field)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private function shouldDisplayNotAlwaysDisplayField(Field $field): bool
|
||||
{
|
||||
$fields = $this->form->getFields()->toArray();
|
||||
foreach ($fields as $fieldFromArray) {
|
||||
if (in_array($field->getType(), $this->viewOnlyFields)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/** @var Field $fieldFromArray */
|
||||
if ($field->getId() === $fieldFromArray->getId()) {
|
||||
if (($this->displayCounter->getDisplayFields() + ($this->displayCounter->getAlwaysDisplayFields() - $this->displayCounter->getAlreadyAlwaysDisplayed())) >= $this->form->getProgressiveProfilingLimit()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function useProgressiveProfilingLimit(): bool
|
||||
{
|
||||
return '' != $this->form->getProgressiveProfilingLimit();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return DisplayCounter
|
||||
*/
|
||||
public function getDisplayCounter()
|
||||
{
|
||||
return $this->displayCounter;
|
||||
}
|
||||
|
||||
public function increaseDisplayedFields(Field $field): void
|
||||
{
|
||||
if (!in_array($field->getType(), $this->viewOnlyFields)) {
|
||||
$this->displayCounter->increaseDisplayedFields();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user