variableRepository = $variableRepository; } /** * @param array $templates [description] * * @return VariableArrayView|bool [description] */ public function listByTwigsTemplates(array $templates) { $templateCommonVariables = []; $templateVariables = []; $criteriaObj = new Criteria(); $criteriaObj->orderBy(["position" => Criteria::ASC]); foreach ($templates as $template) { $twig = $template->getTwig(); if (null === $twig->getDeletedAt()) { $variables = $twig->getVariables(); foreach ($variables as $variable) { if (null === $variable->getDeletedAt()) { $subVar = []; $templateCommonVariables[$template->getName()][] = $variable->getName(); $inputs = $variable->getInputs(); if (!empty($inputs)) { foreach ($inputs as $input) { if (null === $input->getDeletedAt()) { $subVar[] = new InputView( $input->getId(), $input->getName(), $input->getVariableName(), !empty($input->getFieldType()) ? $input->getFieldType() : 'textarea', !empty($input->getVariableProject()) ? $input->getVariableProject()->getId() : null, !empty($input->getVariableProject()) ? $input->getVariableProject()->getName() : "" ); } } } $templateVariables[$template->getName()][] = new VariableView( $variable->getId(), $variable->getName(), $variable->getTwigVar(), $subVar, $twig->getId(), $twig->getName(), $template->getId(), $template->getName(), $variable->getForElement(), $variable->getFieldType(), !empty($variable->getVariableProject()) ? $variable->getVariableProject()->getId() : null, !empty($variable->getVariableProject()) ? $variable->getVariableProject()->getName() : "" ); } } } } if (empty($templateVariables)) { return false; } $arrayCommonVariables = $this->getCommon($templateCommonVariables); return new VariableArrayView( $arrayCommonVariables, /*$arrayVariables*/ $templateVariables ); } /** * @param array $common [description] * * @return array [description] */ protected function getCommon(array $common): array { $arrayFields = []; foreach ($common as $key => $value) { $common[$key] = array_unique($common[$key]); } $commonFields = []; if (!empty($common)) { $commonFields = $this->getIntersect($common); foreach ($commonFields as $commonField) { $arrayFields[] = new CommonTextView( $commonField ); } } return $arrayFields; } /** * @param array $common [description] * * @return array [description] */ protected function getIntersect(array $common): array { $commun = []; foreach ($common as $key => $value) { foreach ($common as $key2 => $value2) { if ($key !== $key2) { $com = array_intersect($value, $value2); foreach ($com as $field) { $commun[] = $field; } } } } $commun = array_unique($commun); return $commun; } public function listByTwigId(int $twigId) { $variables = $this->variableRepository->findByTwigId($twigId); $result = []; if (!empty($variables)) { foreach ($variables as $variable) { $result[] = ["id" => $variable->getId(), "twigVar" => $variable->getName(), "type" => "variable"]; if (!$variable->getInputs()->isEmpty()) { foreach ($variable->getInputs() as $input) { if ($input->getDeletedAt() === null) { $result[] = ["id" => $input->getId(), "twigVar" => $input->getName(), "type" => "input"]; } } } } } return $result; } }