コード例 #1
0
 private static function assertColumnEquals(ColumnInterface $column, string $name, string $type = ColumnType::class, array $options = null)
 {
     self::assertEquals($name, $column->getName());
     self::assertInstanceOf($type, $column->getType()->getInnerType());
     if (null !== $options) {
         self::assertEquals($options, $column->getOptions());
     }
 }
コード例 #2
0
ファイル: TextType.php プロジェクト: rollerworks/datagrid
 /**
  * {@inheritdoc}
  */
 public function buildColumn(ColumnInterface $column, array $options)
 {
     $transformer = new ChainTransformer();
     if (null !== $options['empty_value']) {
         $transformer->append(new EmptyValueTransformer($options['empty_value']));
     }
     if (null !== $options['value_format'] || null !== $options['value_glue']) {
         $transformer->append(new ValueFormatTransformer($options['value_glue'], $options['value_format']));
     }
     $column->setViewTransformer($transformer);
 }
コード例 #3
0
ファイル: DateTimeType.php プロジェクト: rollerworks/datagrid
 /**
  * {@inheritdoc}
  */
 public function buildColumn(ColumnInterface $column, array $options)
 {
     $transformer = new ChainTransformer();
     if ('string' === $options['input']) {
         $transformer->append(new StringToDateTimeTransformer($options['model_timezone'], $options['model_timezone']));
     } elseif ('timestamp' === $options['input']) {
         $transformer->append(new TimestampToDateTimeTransformer($options['model_timezone'], $options['model_timezone']));
     }
     $transformer->append(new DateTimeToLocalizedStringTransformer($options['model_timezone'], $options['view_timezone'], $options['date_format'], $options['time_format'], $options['calendar'], $options['format']));
     $column->setViewTransformer($transformer);
 }
コード例 #4
0
ファイル: ColumnType.php プロジェクト: rollerworks/datagrid
 private function createDataProviderPath(ColumnInterface $column, $data, $customPath) : PropertyPath
 {
     try {
         if (null === $customPath) {
             $name = $column->getName();
             if (!$this->propertyAccessor->isReadable($data, $path = new PropertyPath(sprintf('[%s]', $name))) && !$this->propertyAccessor->isReadable($data, $path = new PropertyPath($name))) {
                 throw DataProviderException::autoAccessorUnableToGetValue($name);
             }
             return $path;
         }
         if (!$this->propertyAccessor->isReadable($data, $path = new PropertyPath($customPath))) {
             throw DataProviderException::pathAccessorUnableToGetValue($column->getName(), $path);
         }
         return $path;
     } catch (InvalidPropertyPathException $e) {
         throw DataProviderException::invalidPropertyPath($column->getName(), $e);
     }
 }
コード例 #5
0
 /**
  * {@inheritdoc}
  */
 public function buildCellView(CellView $view, ColumnInterface $column, array $options)
 {
     $parent = $view->column;
     // Set shared information from the header.
     // This information is not recomputed for better performance.
     // Each header is created once, but this method will be called
     // 5000 times for a grid with 500 rows!
     $view->vars = array_replace($view->vars, ['cell_attr' => $options['cell_attr'], 'unique_block_prefix' => $parent->vars['unique_block_prefix'], 'block_prefixes' => $parent->vars['block_prefixes'], 'cache_key' => $parent->vars['cache_key']]);
     $cells = [];
     $headers = $view->column->vars['_sub_headers'];
     /** @var CompoundColumn $column */
     foreach ($column->getColumns() as $subColumn) {
         $name = $subColumn->getName();
         $subView = $subColumn->createCellView($headers[$name], $view->source, $view->vars['row']);
         $subView->vars['compound'] = true;
         $cells[$name] = $subView;
     }
     return $view->value = $cells;
 }
コード例 #6
0
ファイル: BaseType.php プロジェクト: rollerworks/datagrid
 public function buildHeaderView(HeaderView $view, ColumnInterface $column, array $options)
 {
     $blockName = (string) $options['block_name'];
     if ('' === $blockName) {
         $blockName = $view->datagrid->name . '_';
         // Child-columns must be prefixed with there parents name to prevent collisions.
         if (isset($options['parent_column'])) {
             $blockName .= $options['parent_column']->getName() . '_';
         }
         $blockName .= $column->getName();
     }
     $uniqueBlockPrefix = '_' . $blockName;
     $blockPrefixes = [];
     for ($type = $column->getType(); null !== $type; $type = $type->getParent()) {
         array_unshift($blockPrefixes, $type->getBlockPrefix());
     }
     $blockPrefixes[] = $uniqueBlockPrefix;
     $view->vars = array_replace($view->vars, ['label_attr' => $options['label_attr'], 'header_attr' => $options['header_attr'], 'cell_attr' => $options['header_attr'], 'label_translation_domain' => $options['label_translation_domain'], 'unique_block_prefix' => $uniqueBlockPrefix, 'block_prefixes' => $blockPrefixes, 'cache_key' => $uniqueBlockPrefix . '_' . $column->getType()->getBlockPrefix()]);
 }
コード例 #7
0
ファイル: NumberType.php プロジェクト: rollerworks/datagrid
 /**
  * {@inheritdoc}
  */
 public function buildColumn(ColumnInterface $column, array $options)
 {
     $column->setViewTransformer(new NumberToLocalizedStringTransformer($options['precision'], $options['grouping'], $options['rounding_mode']));
 }
コード例 #8
0
ファイル: HeaderView.php プロジェクト: rollerworks/datagrid
 /**
  * @param ColumnInterface $column
  * @param DatagridView    $datagrid
  * @param string          $label
  */
 public function __construct(ColumnInterface $column, DatagridView $datagrid, string $label = null)
 {
     $this->datagrid = $datagrid;
     $this->name = $column->getName();
     $this->label = $label;
 }
コード例 #9
0
 /**
  * {@inheritdoc}
  */
 public function set(ColumnInterface $column)
 {
     $this->columns[$column->getName()] = $column;
     unset($this->unresolvedColumns[$column->getName()]);
     return $this;
 }
コード例 #10
0
 /**
  * {@inheritdoc}
  */
 public function getValue(ColumnInterface $column, $object)
 {
     $dataProvider = $column->getDataProvider();
     $value = $dataProvider($object);
     if (null !== ($transformer = $column->getViewTransformer())) {
         $value = $transformer->transform($value);
     }
     return $value;
 }