/**
  * @param FieldConfigId $field
  * @param array         $columnOptions
  */
 protected function prepareColumnOptions(FieldConfigId $field, array &$columnOptions)
 {
     $fieldName = $field->getFieldName();
     // if field is visible as mandatory it is required in grid settings and rendered
     // and not required and hidden by default otherwise.
     $isMandatory = $this->getFieldConfig('datagrid', $field)->get('is_visible') === DatagridScope::IS_VISIBLE_MANDATORY;
     $columnOptions = [DatagridGuesser::FORMATTER => ['label' => $this->getFieldConfig('entity', $field)->get('label') ?: $fieldName, 'renderable' => $isMandatory, 'required' => $isMandatory], DatagridGuesser::SORTER => ['data_name' => $fieldName], DatagridGuesser::FILTER => ['data_name' => $fieldName, 'enabled' => false]];
     $this->datagridGuesser->applyColumnGuesses($field->getClassName(), $fieldName, $field->getFieldType(), $columnOptions);
 }
 /**
  * @param FieldConfigId $field
  * @param array         $columnOptions
  */
 protected function prepareColumnOptions(FieldConfigId $field, array &$columnOptions)
 {
     $fieldName = $field->getFieldName();
     // if field is "visible as mandatory" it is required in grid settings and rendered
     // if field is just "visible" it's rendered by default and manageable in grid settings
     // otherwise - not required and hidden by default.
     $gridVisibilityValue = $this->getFieldConfig('datagrid', $field)->get('is_visible');
     $isRequired = $gridVisibilityValue === DatagridScope::IS_VISIBLE_MANDATORY;
     $isRenderable = $isRequired ?: $gridVisibilityValue === DatagridScope::IS_VISIBLE_TRUE;
     $columnOptions = [DatagridGuesser::FORMATTER => ['label' => $this->getFieldConfig('entity', $field)->get('label') ?: $fieldName, 'renderable' => $isRenderable, 'required' => $isRequired], DatagridGuesser::SORTER => ['data_name' => $fieldName], DatagridGuesser::FILTER => ['data_name' => $fieldName, 'enabled' => false]];
     $this->datagridGuesser->applyColumnGuesses($field->getClassName(), $fieldName, $field->getFieldType(), $columnOptions);
 }
 /**
  * {@inheritdoc}
  */
 protected function addSelectColumn($entityClassName, $tableAlias, $fieldName, $columnExpr, $columnAlias, $columnLabel, $functionExpr, $functionReturnType, $isDistinct = false)
 {
     if ($isDistinct) {
         $columnExpr = 'DISTINCT ' . $columnExpr;
     }
     if ($functionExpr !== null) {
         $functionExpr = $this->prepareFunctionExpression($functionExpr, $tableAlias, $fieldName, $columnExpr, $columnAlias);
     }
     $this->selectColumns[] = sprintf('%s as %s', $functionExpr !== null ? $functionExpr : $columnExpr, $columnAlias);
     $fieldType = $functionReturnType;
     if ($fieldType === null) {
         $fieldType = $this->getFieldType($entityClassName, $fieldName);
     }
     $columnOptions = [DatagridGuesser::FORMATTER => ['label' => $columnLabel, 'translatable' => false], DatagridGuesser::SORTER => ['data_name' => $columnAlias], DatagridGuesser::FILTER => ['data_name' => $this->getFilterByExpr($entityClassName, $tableAlias, $fieldName, $columnAlias), 'translatable' => false]];
     if ($functionExpr !== null) {
         $columnOptions[DatagridGuesser::FILTER][FilterUtility::BY_HAVING_KEY] = true;
     }
     $this->datagridGuesser->applyColumnGuesses($entityClassName, $fieldName, $fieldType, $columnOptions);
     $this->datagridGuesser->setColumnOptions($this->config, $columnAlias, $columnOptions);
 }
 public function testApplyColumnGuesses()
 {
     $class = 'TestClass';
     $property = 'testProp';
     $type = 'integer';
     $guesser1 = $this->getMock('Oro\\Bundle\\DataGridBundle\\Datagrid\\ColumnOptionsGuesserInterface');
     $guesser2 = $this->getMock('Oro\\Bundle\\DataGridBundle\\Datagrid\\ColumnOptionsGuesserInterface');
     $formatterGuess = new ColumnGuess(['formatter_prop1' => 'prop1', 'formatter_prop2' => 'prop2'], ColumnGuess::LOW_CONFIDENCE);
     $sorterGuess = new ColumnGuess(['sorter_prop1' => 'prop1', 'sorter_prop2' => 'prop2'], ColumnGuess::LOW_CONFIDENCE);
     $filterGuess = new ColumnGuess(['filter_prop1' => 'prop1', 'filter_prop2' => 'prop2'], ColumnGuess::LOW_CONFIDENCE);
     $container = new ContainerBuilder();
     $container->set('guesser1', $guesser1);
     $container->set('guesser2', $guesser2);
     $guesser1->expects($this->once())->method('guessFormatter')->with($class, $property, $type)->will($this->returnValue(null));
     $guesser2->expects($this->once())->method('guessFormatter')->with($class, $property, $type)->will($this->returnValue($formatterGuess));
     $guesser1->expects($this->once())->method('guessSorter')->with($class, $property, $type)->will($this->returnValue(null));
     $guesser2->expects($this->once())->method('guessSorter')->with($class, $property, $type)->will($this->returnValue($sorterGuess));
     $guesser1->expects($this->once())->method('guessFilter')->with($class, $property, $type)->will($this->returnValue(null));
     $guesser2->expects($this->once())->method('guessFilter')->with($class, $property, $type)->will($this->returnValue($filterGuess));
     $datagridGuesser = new DatagridGuesser($container, ['guesser1', 'guesser2']);
     $columnOptions = [DatagridGuesser::FORMATTER => ['formatter_prop1' => 'prop1_initial', 'formatter_prop3' => 'prop3_initial'], DatagridGuesser::SORTER => ['sorter_prop1' => 'prop1_initial', 'sorter_prop3' => 'prop1_initial'], DatagridGuesser::FILTER => ['filter_prop1' => 'prop1_initial', 'filter_prop3' => 'prop3_initial']];
     $datagridGuesser->applyColumnGuesses($class, $property, $type, $columnOptions);
     $this->assertEquals([DatagridGuesser::FORMATTER => ['formatter_prop1' => 'prop1_initial', 'formatter_prop2' => 'prop2', 'formatter_prop3' => 'prop3_initial'], DatagridGuesser::SORTER => ['sorter_prop1' => 'prop1_initial', 'sorter_prop2' => 'prop2', 'sorter_prop3' => 'prop1_initial'], DatagridGuesser::FILTER => ['filter_prop1' => 'prop1_initial', 'filter_prop2' => 'prop2', 'filter_prop3' => 'prop3_initial']], $columnOptions);
 }
 /**
  * @param FieldConfigId $field
  * @param array         $columnOptions
  */
 protected function prepareColumnOptions(FieldConfigId $field, array &$columnOptions)
 {
     $fieldName = $field->getFieldName();
     $columnOptions = [DatagridGuesser::FORMATTER => ['label' => $this->getFieldConfig('entity', $field)->get('label') ?: $fieldName], DatagridGuesser::SORTER => ['data_name' => $fieldName], DatagridGuesser::FILTER => ['data_name' => $fieldName, 'enabled' => false]];
     $this->datagridGuesser->applyColumnGuesses($field->getClassName(), $fieldName, $field->getFieldType(), $columnOptions);
 }