Skip to content

Commit

Permalink
commits from other repo
Browse files Browse the repository at this point in the history
  • Loading branch information
Максим Пешехонов committed May 25, 2020
1 parent a45a8e4 commit 9767fca
Show file tree
Hide file tree
Showing 29 changed files with 909 additions and 134 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea
1 change: 1 addition & 0 deletions Controller/DatatableController.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ private function normalizeValue(string $originalTypeOfField, $value)
{
switch ($originalTypeOfField) {
case Type::DATETIME:
case Type::TIME:
$value = new DateTime($value);

break;
Expand Down
30 changes: 30 additions & 0 deletions Datatable/Action/Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,14 @@ class Action
*/
protected $datatableName;

/**
* Put dropdown divider div before the dropdown action.
* Default: false.
*
* @var bool
*/
protected $dropdownDivider;

/**
* @param string $datatableName
*/
Expand Down Expand Up @@ -152,6 +160,7 @@ public function configureOptions(OptionsResolver $resolver)
'render_if' => null,
'start_html' => null,
'end_html' => null,
'dropdown_divider' => false,
]);

$resolver->setAllowedTypes('route', ['null', 'string']);
Expand All @@ -167,6 +176,7 @@ public function configureOptions(OptionsResolver $resolver)
$resolver->setAllowedTypes('render_if', ['null', 'Closure']);
$resolver->setAllowedTypes('start_html', ['null', 'string']);
$resolver->setAllowedTypes('end_html', ['null', 'string']);
$resolver->setAllowedTypes('dropdown_divider', 'bool');

return $this;
}
Expand Down Expand Up @@ -406,4 +416,24 @@ public function setDatatableName($datatableName)

return $this;
}

/**
* @return bool
*/
public function isDropdownDivider()
{
return $this->dropdownDivider;
}

/**
* @param bool $dorpdownDivider
*
* @return $this
*/
public function setDropdownDivider($dorpdownDivider)
{
$this->dropdownDivider = $dorpdownDivider;

return $this;
}
}
169 changes: 165 additions & 4 deletions Datatable/Column/AbstractColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,39 @@ abstract class AbstractColumn implements ColumnInterface
* @var bool
*/
protected $sentInResponse;

/**
* If this column displays the total of its cells in its head
* Default: false.
*
* @var bool
*/
protected $computeTotal;

/**
* Contains the eventually computed total of the column.
*
* @var mixed
*/
protected $total;

/**
* If the column represents a real column in the database.
*
* @var bool
*/
protected $mapped;

/**
* Force the association property.
*/
protected $isAssociation;

/**
* The source of data, if different from title and no dql specified.
*/
protected $dataSource;

//-------------------------------------------------
// Options
//-------------------------------------------------
Expand Down Expand Up @@ -326,6 +359,10 @@ public function configureOptions(OptionsResolver $resolver)
'type_of_field' => null,
'responsive_priority' => null,
'sent_in_response' => true,
'compute_total' => false,
'mapped' => true,
'is_association' => false,
'data_source' => null,
]);

$resolver->setAllowedTypes('cell_type', ['null', 'string']);
Expand All @@ -347,6 +384,10 @@ public function configureOptions(OptionsResolver $resolver)
$resolver->setAllowedTypes('type_of_field', ['null', 'string']);
$resolver->setAllowedTypes('responsive_priority', ['null', 'int']);
$resolver->setAllowedTypes('sent_in_response', ['bool']);
$resolver->setAllowedTypes('compute_total', ['bool']);
$resolver->setAllowedTypes('mapped', ['bool']);
$resolver->setAllowedTypes('is_association', ['bool']);
$resolver->setAllowedTypes('data_source', ['string', 'null']);

$resolver->setAllowedValues('cell_type', [null, 'th', 'td']);
$resolver->setAllowedValues('join_type', [null, 'join', 'leftJoin', 'innerJoin']);
Expand Down Expand Up @@ -392,6 +433,10 @@ public function isAssociation()
*/
public function isToManyAssociation()
{
if ($this->isAssociation) {
return true;
}

if (true === $this->isAssociation() && null !== $this->typeOfAssociation) {
if (\in_array(ClassMetadataInfo::ONE_TO_MANY, $this->typeOfAssociation, true) || \in_array(ClassMetadataInfo::MANY_TO_MANY, $this->typeOfAssociation, true)) {
return true;
Expand Down Expand Up @@ -430,9 +475,9 @@ public function addDataToOutputArray(array &$row)
/**
* {@inheritdoc}
*/
public function renderCellContent(array &$row)
public function renderCellContent(array &$row, array &$resultRow)
{
$this->isToManyAssociation() ? $this->renderToMany($row) : $this->renderSingleField($row);
$this->isToManyAssociation() ? $this->renderToMany($row, $resultRow) : $this->renderSingleField($row, $resultRow);
}

/**
Expand Down Expand Up @@ -976,8 +1021,6 @@ public function setTypeOfAssociation($typeOfAssociation)
}

/**
* Add a typeOfAssociation.
*
* @param int $typeOfAssociation
*
* @return $this
Expand Down Expand Up @@ -1028,4 +1071,122 @@ public function setSentInResponse($sentInResponse)

return $this;
}

/**
* Get computeTotal.
*
* @return bool
*/
public function getComputeTotal()
{
return $this->computeTotal;
}

/**
* Set sentIntResponse.
*
* @param bool $computeTotal
*
* @return $this
*/
public function setComputeTotal($computeTotal)
{
$this->computeTotal = $computeTotal;

return $this;
}

/**
* Get total.
*/
public function getTotal()
{
return $this->total;
}

/**
* Set total.
*
* @param $total
*
* @return $this
*/
public function setTotal($total)
{
$this->total = $total;

return $this;
}

/**
* Get mapped.
*
* @return bool
*/
public function getMapped()
{
return $this->mapped;
}

/**
* Set mapped.
*
* @param bool $mapped
*
* @return $this
*/
public function setMapped($mapped)
{
$this->mapped = $mapped;

return $this;
}

/**
* Get isAssociation.
*
* @return bool
*/
public function getIsAssociation()
{
return $this->isAssociation;
}

/**
* Set isAssociation.
*
* @param bool $isAssociation
*
* @return $this
*/
public function setIsAssociation($isAssociation)
{
$this->isAssociation = $isAssociation;

return $this;
}

/**
* Get data source.
*
* @return string|null
*/
public function getDataSource()
{
return $this->isAssociation;
}

/**
* Set data source.
*
* @param string|null $dataSource
*
* @return $this
*/
public function setDataSource($dataSource)
{
$this->dataSource = $dataSource;

return $this;
}
}
40 changes: 26 additions & 14 deletions Datatable/Column/ActionColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,13 @@ public function addDataToOutputArray(array &$row)
}

/**
* {@inheritdoc}
* Helper function to get render template variables.
*
* @param array $row
*
* @return array
*/
public function renderSingleField(array &$row)
protected function getCellContentTemplateVars(array $row)
{
$parameters = [];
$attributes = [];
Expand Down Expand Up @@ -131,25 +135,33 @@ public function renderSingleField(array &$row)
}
}
}

$row[$this->getIndex()] = $this->twig->render(

return [
'actions' => $this->actions,
'route_parameters' => $parameters,
'attributes' => $attributes,
'values' => $values,
'render_if_actions' => $row['sg_datatables_actions'][$this->index],
'start_html_container' => $this->startHtml,
'end_html_container' => $this->endHtml,
];
}

/**
* {@inheritdoc}
*/
public function renderSingleField(array &$row, array &$resultRow)
{
$resultRow[$this->getIndex()] = $this->twig->render(
$this->getCellContentTemplate(),
[
'actions' => $this->actions,
'route_parameters' => $parameters,
'attributes' => $attributes,
'values' => $values,
'render_if_actions' => $row['sg_datatables_actions'][$this->index],
'start_html_container' => $this->startHtml,
'end_html_container' => $this->endHtml,
]
$this->getCellContentTemplateVars($row)
);
}

/**
* {@inheritdoc}
*/
public function renderToMany(array &$row)
public function renderToMany(array &$row, array &$resultRow)
{
throw new Exception('ActionColumn::renderToMany(): This function should never be called.');
}
Expand Down
4 changes: 2 additions & 2 deletions Datatable/Column/ArrayColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ class ArrayColumn extends Column
/**
* {@inheritdoc}
*/
public function renderSingleField(array &$row)
public function renderSingleField(array &$row, array &$resultRow)
{
$row[$this->data] = $this->arrayToString($row[$this->data] ?? []);

return parent::renderSingleField($row);
return parent::renderSingleField($row, $resultRow);
}

/**
Expand Down
Loading

0 comments on commit 9767fca

Please sign in to comment.