/** * @param string $type * * @return CategoriesConstraint */ protected function getConstraint($type) { $constraint = new CategoriesConstraint(); $constraint->setType($type); return $constraint; }
/** * @param FormInterface $form * @param array $categories */ protected function addRFMTypes(FormInterface $form, array $categories) { foreach (RFMMetricCategory::$types as $type) { $typeCategories = array_filter($categories, function (RFMMetricCategory $category) use($type) { return $category->getCategoryType() === $type; }); $collection = new PersistentCollection($this->doctrineHelper->getEntityManager($this->rfmCategoryClass), $this->doctrineHelper->getEntityMetadata($this->rfmCategoryClass), new ArrayCollection($typeCategories)); $collection->takeSnapshot(); $constraint = new CategoriesConstraint(); $constraint->setType($type); $form->add($type, RFMCategorySettingsType::NAME, [RFMCategorySettingsType::TYPE_OPTION => $type, 'label' => sprintf('orocrm.analytics.form.%s.label', $type), 'tooltip' => sprintf('orocrm.analytics.%s.tooltip', $type), 'mapped' => false, 'required' => false, 'error_bubbling' => false, 'is_increasing' => $type === RFMMetricCategory::TYPE_RECENCY, 'constraints' => [$constraint], 'data' => $collection]); } }