diff --git a/.travis.yml b/.travis.yml index 9749e69e..f671d8af 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,10 +4,15 @@ language: php sudo: false php: - - 5.5 - 5.6 - 7 + - 7.1 - hhvm + - nightly + +matrix: + allow_failures: + - php: nightly env: matrix: diff --git a/composer.json b/composer.json index 03fcd160..52283f0a 100644 --- a/composer.json +++ b/composer.json @@ -24,25 +24,22 @@ }], "require": { - "php": "~5.5|~7.0", + "php": "~5.6|~7.0", - "zendframework/zend-mvc": "~2.7", + "zendframework/zend-mvc": "~2.7|~3.0", "zendframework/zend-modulemanager": "~2.5", "zendframework/zend-session": "~2.5", "zendframework/zend-view": "~2.5", "zendframework/zend-http": "~2.5", "zendframework/zend-paginator": "~2.5", "zendframework/zend-cache": "~2.5", - "zendframework/zend-servicemanager": "~2.7" + "zendframework/zend-servicemanager": "~2.7|~3.0" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.2", + "phpunit/phpunit": "^5.6.1", "friendsofphp/php-cs-fixer": "^1.11", - - "doctrine/orm": ">=2.5,<2.7", - "doctrine/dbal": ">=2.5,<2.7", - "doctrine/doctrine-orm-module": "^0.9", + "doctrine/doctrine-orm-module": "^1.1.0", "zendframework/zend-console": "~2.5", "zendframework/zend-db": "~2.5", @@ -53,10 +50,7 @@ "suggest" : { "ext-intl": "*", - - "doctrine/orm": ">=2.5,<2.7", - "doctrine/dbal": ">=2.5,<2.7", - "doctrine/doctrine-orm-module": "^0.9", + "doctrine/doctrine-orm-module": "for doctrine support", "phpoffice/phpexcel": "^1.8", "tecnickcom/tcpdf": "^6.2", @@ -64,11 +58,15 @@ "zendframework/zend-text": "~2.5", "zendframework/zend-json": "to support date ranges" }, - + "autoload": { - "psr-0": { - "ZfcDatagrid\\": "src/", - "ZfcDatagridTest\\": "tests/" + "psr-4": { + "ZfcDatagrid\\": "src/ZfcDatagrid" + } + }, + "autoload-dev": { + "psr-4": { + "ZfcDatagridTest\\": "tests/ZfcDatagridTest" } } } diff --git a/src/ZfcDatagrid/Action/Mass.php b/src/ZfcDatagrid/Action/Mass.php index 2b06117c..47ed72e5 100644 --- a/src/ZfcDatagrid/Action/Mass.php +++ b/src/ZfcDatagrid/Action/Mass.php @@ -1,31 +1,28 @@ userSortEnabled = (bool) ! $mode; + $this->userSortEnabled = (bool) !$mode; } /** * Is user sort enabled? * - * @return boolean + * @return bool */ public function isUserSortEnabled() { @@ -258,21 +250,21 @@ public function isUserSortEnabled() /** * The data will get sorted by this column (by default) - * If will be changed by the user per request (POST,GET....) + * If will be changed by the user per request (POST,GET....). * - * @param integer $priority - * @param string $direction + * @param int $priority + * @param string $direction */ public function setSortDefault($priority = 1, $direction = 'ASC') { $this->sortDefault = [ - 'priority' => $priority, + 'priority' => $priority, 'sortDirection' => $direction, ]; } /** - * Get the sort defaults + * Get the sort defaults. * * @return array */ @@ -284,7 +276,7 @@ public function getSortDefault() /** * Does this column has sort defaults? * - * @return boolean + * @return bool */ public function hasSortDefault() { @@ -296,7 +288,7 @@ public function hasSortDefault() } /** - * Set that the data is getting sorted by this columns + * Set that the data is getting sorted by this columns. * * @param string $direction */ @@ -306,8 +298,7 @@ public function setSortActive($direction = 'ASC') } /** - * - * @return boolean + * @return bool */ public function isSortActive() { @@ -319,7 +310,6 @@ public function isSortActive() } /** - * * @return string */ public function getSortActiveDirection() @@ -328,19 +318,18 @@ public function getSortActiveDirection() } /** - * - * @param boolean $mode + * @param bool $mode */ public function setUserFilterDisabled($mode = true) { - $this->userFilterEnabled = (bool) ! $mode; + $this->userFilterEnabled = (bool) !$mode; } /** * Set the default filterung value (used as long no user filtering getting applied) * Examples * $grid->setFilterDefaultValue('something'); - * $grid->setFilterDefaultValue('>20'); + * $grid->setFilterDefaultValue('>20');. * * OPERATORS are ALLOWED (like for the user) * @@ -354,7 +343,6 @@ public function setFilterDefaultValue($value = null) } /** - * * @return string */ public function getFilterDefaultValue() @@ -363,8 +351,7 @@ public function getFilterDefaultValue() } /** - * - * @return boolean + * @return bool */ public function hasFilterDefaultValue() { @@ -376,7 +363,6 @@ public function hasFilterDefaultValue() } /** - * * @param string $operation */ public function setFilterDefaultOperation($operation = Filter::LIKE) @@ -385,7 +371,6 @@ public function setFilterDefaultOperation($operation = Filter::LIKE) } /** - * * @return string */ public function getFilterDefaultOperation() @@ -398,9 +383,8 @@ public function getFilterDefaultOperation() } /** - * - * @param array $options - * @param boolean $noSelect + * @param array $options + * @param bool $noSelect */ public function setFilterSelectOptions(array $options = null, $noSelect = true) { @@ -416,7 +400,7 @@ public function setFilterSelectOptions(array $options = null, $noSelect = true) } /** - * Unset the filter select options (normal search) + * Unset the filter select options (normal search). */ public function unsetFilterSelectOptions() { @@ -424,7 +408,6 @@ public function unsetFilterSelectOptions() } /** - * * @return array null */ public function getFilterSelectOptions() @@ -433,8 +416,7 @@ public function getFilterSelectOptions() } /** - * - * @return boolean + * @return bool */ public function hasFilterSelectOptions() { @@ -446,18 +428,16 @@ public function hasFilterSelectOptions() } /** - * * @param mixed $value */ public function setFilterActive($value = '') { - $this->filterActive = (bool) true; + $this->filterActive = (bool) true; $this->filterActiveValue = $value; } /** - * - * @return boolean + * @return bool */ public function isFilterActive() { @@ -465,7 +445,6 @@ public function isFilterActive() } /** - * * @return string */ public function getFilterActiveValue() @@ -474,8 +453,7 @@ public function getFilterActiveValue() } /** - * - * @return boolean + * @return bool */ public function isUserFilterEnabled() { @@ -483,9 +461,9 @@ public function isUserFilterEnabled() } /** - * Enable data translation + * Enable data translation. * - * @param boolean $mode + * @param bool $mode */ public function setTranslationEnabled($mode = true) { @@ -495,7 +473,7 @@ public function setTranslationEnabled($mode = true) /** * Is data translation enabled? * - * @return boolean + * @return bool */ public function isTranslationEnabled() { @@ -503,14 +481,14 @@ public function isTranslationEnabled() } /** - * Replace the column values with the applied values + * Replace the column values with the applied values. * - * @param array $values - * @param boolean $notReplacedGetEmpty + * @param array $values + * @param bool $notReplacedGetEmpty */ public function setReplaceValues(array $values, $notReplacedGetEmpty = true) { - $this->replaceValues = $values; + $this->replaceValues = $values; $this->notReplacedGetEmpty = (bool) $notReplacedGetEmpty; $this->setFilterDefaultOperation(Filter::EQUAL); @@ -518,8 +496,7 @@ public function setReplaceValues(array $values, $notReplacedGetEmpty = true) } /** - * - * @return boolean + * @return bool */ public function hasReplaceValues() { @@ -527,7 +504,6 @@ public function hasReplaceValues() } /** - * * @return array */ public function getReplaceValues() @@ -536,8 +512,7 @@ public function getReplaceValues() } /** - * - * @return boolean + * @return bool */ public function notReplacedGetEmpty() { @@ -545,7 +520,7 @@ public function notReplacedGetEmpty() } /** - * Set parameter for a specific renderer (currently only supported for jqGrid) + * Set parameter for a specific renderer (currently only supported for jqGrid). * * @param string $name * @param mixed $value @@ -553,24 +528,24 @@ public function notReplacedGetEmpty() */ public function setRendererParameter($name, $value, $rendererType = 'jqGrid') { - if (! isset($this->rendererParameter[$rendererType])) { + if (!isset($this->rendererParameter[$rendererType])) { $this->rendererParameter[$rendererType] = []; } - $parameters = $this->rendererParameter[$rendererType]; + $parameters = $this->rendererParameter[$rendererType]; $parameters[$name] = $value; $this->rendererParameter[$rendererType] = $parameters; } /** + * @param string $rendererName * - * @param string $rendererName * @return array */ public function getRendererParameters($rendererName = 'jqGrid') { - if (! isset($this->rendererParameter[$rendererName])) { + if (!isset($this->rendererParameter[$rendererName])) { $this->rendererParameter[$rendererName] = []; } @@ -578,7 +553,7 @@ public function getRendererParameters($rendererName = 'jqGrid') } /** - * Set a template formatter and overwrite other formatter + * Set a template formatter and overwrite other formatter. * * @param AbstractFormatter[] $formatters */ @@ -588,9 +563,10 @@ public function setFormatters(array $formatters) } /** - * Set a template formatter and overwrite other formatter + * Set a template formatter and overwrite other formatter. * * @param AbstractFormatter $formatter + * * @deprecated please use setFormatters */ public function setFormatter(AbstractFormatter $formatter) @@ -601,7 +577,7 @@ public function setFormatter(AbstractFormatter $formatter) } /** - * add a template formatter in the list + * add a template formatter in the list. * * @param AbstractFormatter $formatter */ @@ -611,7 +587,7 @@ public function addFormatter(AbstractFormatter $formatter) } /** - * return a list of different formatter + * return a list of different formatter. * * @return AbstractFormatter[] */ @@ -621,9 +597,10 @@ public function getFormatters() } /** - * return a list of different formatter + * return a list of different formatter. * * @return AbstractFormatter[] + * * @deprecated please use getFormatters */ public function getFormatter() @@ -634,8 +611,7 @@ public function getFormatter() } /** - * - * @return boolean + * @return bool */ public function hasFormatters() { @@ -654,17 +630,15 @@ public function hasFormatter() } /** - * - * @param boolean $mode + * @param bool $mode */ public function setRowClickDisabled($mode = true) { - $this->rowClickEnabled = (bool) ! $mode; + $this->rowClickEnabled = (bool) !$mode; } /** - * - * @return boolean + * @return bool */ public function isRowClickEnabled() { diff --git a/src/ZfcDatagrid/Column/Action.php b/src/ZfcDatagrid/Column/Action.php index 4f8e4b9a..95afd6b1 100644 --- a/src/ZfcDatagrid/Column/Action.php +++ b/src/ZfcDatagrid/Column/Action.php @@ -1,12 +1,12 @@ getLinkColumnPlaceholders() as $col) { - $link = str_replace(':' . $col->getUniqueId() . ':', $row[$col->getUniqueId()], $link); + $link = str_replace(':'.$col->getUniqueId().':', $row[$col->getUniqueId()], $link); } return $link; @@ -85,20 +82,20 @@ public function getLinkReplaced(array $row) /** * Get the column row value placeholder - * $action->setLink('/myLink/something/id/'.$action->getRowIdPlaceholder().'/something/'.$action->getColumnRowPlaceholder($myCol)); + * $action->setLink('/myLink/something/id/'.$action->getRowIdPlaceholder().'/something/'.$action->getColumnRowPlaceholder($myCol));. + * + * @param AbstractColumn $col * - * @param AbstractColumn $col * @return string */ public function getColumnValuePlaceholder(AbstractColumn $col) { $this->linkColumnPlaceholders[] = $col; - return ':' . $col->getUniqueId() . ':'; + return ':'.$col->getUniqueId().':'; } /** - * * @return \ZfcDatagrid\Column\AbstractColumn[] */ public function getLinkColumnPlaceholders() @@ -109,7 +106,7 @@ public function getLinkColumnPlaceholders() /** * Returns the rowId placeholder * Can be used e.g. - * $action->setLink('/myLink/something/id/'.$action->getRowIdPlaceholder()); + * $action->setLink('/myLink/something/id/'.$action->getRowIdPlaceholder());. * * @return string */ @@ -119,7 +116,7 @@ public function getRowIdPlaceholder() } /** - * Set a HTML attributes + * Set a HTML attributes. * * @param string $name * @param string $value @@ -130,9 +127,10 @@ public function setAttribute($name, $value) } /** - * Get a HTML attribute + * Get a HTML attribute. + * + * @param string $name * - * @param string $name * @return string */ public function getAttribute($name) @@ -145,7 +143,7 @@ public function getAttribute($name) } /** - * Removes an HTML attribute + * Removes an HTML attribute. * * @param string $name */ @@ -157,7 +155,7 @@ public function removeAttribute($name) } /** - * Get all HTML attributes + * Get all HTML attributes. * * @return array */ @@ -167,9 +165,10 @@ public function getAttributes() } /** - * Get the string version of the attributes + * Get the string version of the attributes. + * + * @param array $row * - * @param array $row * @return string */ protected function getAttributesString(array $row) @@ -179,14 +178,14 @@ protected function getAttributesString(array $row) if ('href' === $attrKey) { $attrValue = $this->getLinkReplaced($row); } - $attributes[] = $attrKey . '="' . $attrValue . '"'; + $attributes[] = $attrKey.'="'.$attrValue.'"'; } return implode(' ', $attributes); } /** - * Set the title attribute + * Set the title attribute. * * @param string $name */ @@ -196,7 +195,7 @@ public function setTitle($name) } /** - * Get the title attribute + * Get the title attribute. * * @return string */ @@ -206,7 +205,7 @@ public function getTitle() } /** - * Add a css class + * Add a css class. * * @param string $className */ @@ -222,14 +221,14 @@ public function addClass($className) } /** - * Display the values with AND or OR (if multiple showOnValues are defined) + * Display the values with AND or OR (if multiple showOnValues are defined). * * @param string $operator */ public function setShowOnValueOperator($operator = 'OR') { if ($operator != 'AND' && $operator != 'OR') { - throw new \InvalidArgumentException('not allowed operator: "' . $operator . '" (AND / OR is allowed)'); + throw new \InvalidArgumentException('not allowed operator: "'.$operator.'" (AND / OR is allowed)'); } $this->showOnValueOperator = (string) $operator; @@ -237,7 +236,7 @@ public function setShowOnValueOperator($operator = 'OR') /** * Get the show on value operator, e.g. - * OR, AND + * OR, AND. * * @return string */ @@ -247,7 +246,7 @@ public function getShowOnValueOperator() } /** - * Show this action only on the values defined + * Show this action only on the values defined. * * @param Column\AbstractColumn $col * @param string $value @@ -256,14 +255,13 @@ public function getShowOnValueOperator() public function addShowOnValue(Column\AbstractColumn $col, $value = null, $comparison = Filter::EQUAL) { $this->showOnValues[] = [ - 'column' => $col, - 'value' => $value, + 'column' => $col, + 'value' => $value, 'comparison' => $comparison, ]; } /** - * * @return array */ public function getShowOnValues() @@ -272,8 +270,7 @@ public function getShowOnValues() } /** - * - * @return boolean + * @return bool */ public function hasShowOnValues() { @@ -287,8 +284,9 @@ public function hasShowOnValues() /** * Display this action on this row? * - * @param array $row - * @return boolean + * @param array $row + * + * @return bool */ public function isDisplayed(array $row) { @@ -328,19 +326,19 @@ public function isDisplayed(array $row) } /** - * Get the HTML from the type + * Get the HTML from the type. * * @return string */ abstract protected function getHtmlType(); /** + * @param array $row * - * @param array $row * @return string */ public function toHtml(array $row) { - return 'getAttributesString($row) . '>' . $this->getHtmlType() . ''; + return 'getAttributesString($row).'>'.$this->getHtmlType().''; } } diff --git a/src/ZfcDatagrid/Column/Action/Button.php b/src/ZfcDatagrid/Column/Action/Button.php index 7f8dbcdb..e8678d82 100644 --- a/src/ZfcDatagrid/Column/Action/Button.php +++ b/src/ZfcDatagrid/Column/Action/Button.php @@ -1,4 +1,5 @@ getUniqueId()]; } - return 'getAttributesString($row) . '>' . $label . ''; + return 'getAttributesString($row).'>'.$label.''; } } diff --git a/src/ZfcDatagrid/Column/Action/Checkbox.php b/src/ZfcDatagrid/Column/Action/Checkbox.php index 61450254..0f1471b2 100644 --- a/src/ZfcDatagrid/Column/Action/Checkbox.php +++ b/src/ZfcDatagrid/Column/Action/Checkbox.php @@ -1,8 +1,8 @@ removeAttribute('name'); $this->removeAttribute('value'); - return 'getAttributesString($row) . ' />'; + return 'getAttributesString($row).' />'; } } diff --git a/src/ZfcDatagrid/Column/Action/Icon.php b/src/ZfcDatagrid/Column/Action/Icon.php index a293ced1..f445beb3 100644 --- a/src/ZfcDatagrid/Column/Action/Icon.php +++ b/src/ZfcDatagrid/Column/Action/Icon.php @@ -1,4 +1,5 @@ hasIconClass() === true) { // a css class is provided, so use it - return ''; + return ''; } elseif ($this->hasIconLink() === true) { // no css class -> use the icon link instead - return ''; + return ''; } throw new \InvalidArgumentException('Either a link or a class for the icon is required'); diff --git a/src/ZfcDatagrid/Column/DataPopulation/DataPopulationInterface.php b/src/ZfcDatagrid/Column/DataPopulation/DataPopulationInterface.php index a9caac90..7bf9faf0 100644 --- a/src/ZfcDatagrid/Column/DataPopulation/DataPopulationInterface.php +++ b/src/ZfcDatagrid/Column/DataPopulation/DataPopulationInterface.php @@ -1,17 +1,18 @@ objectParameters[] = [ 'objectParameterName' => $objectParameterName, - 'column' => $column, + 'column' => $column, ]; } /** - * * @return array */ public function getObjectParametersColumn() @@ -63,7 +60,7 @@ public function getObjectParametersColumn() } /** - * Directly apply a "static" parameter + * Directly apply a "static" parameter. * * @param string $name * @param mixed $value @@ -74,7 +71,6 @@ public function setObjectParameter($name, $value) } /** - * * @return string */ public function toString() diff --git a/src/ZfcDatagrid/Column/DataPopulation/Object/Gravatar.php b/src/ZfcDatagrid/Column/DataPopulation/Object/Gravatar.php index a9313117..855b661e 100644 --- a/src/ZfcDatagrid/Column/DataPopulation/Object/Gravatar.php +++ b/src/ZfcDatagrid/Column/DataPopulation/Object/Gravatar.php @@ -1,17 +1,18 @@ email); } - return 'http://www.gravatar.com/avatar/' . $hash; + return 'http://www.gravatar.com/avatar/'.$hash; } } diff --git a/src/ZfcDatagrid/Column/DataPopulation/ObjectAwareInterface.php b/src/ZfcDatagrid/Column/DataPopulation/ObjectAwareInterface.php index a60a8006..95e585be 100644 --- a/src/ZfcDatagrid/Column/DataPopulation/ObjectAwareInterface.php +++ b/src/ZfcDatagrid/Column/DataPopulation/ObjectAwareInterface.php @@ -1,10 +1,11 @@ getRowData(); - return '' . $row[$column->getUniqueId()] . ''; + return ''.$row[$column->getUniqueId()].''; } } diff --git a/src/ZfcDatagrid/Column/Formatter/FileSize.php b/src/ZfcDatagrid/Column/Formatter/FileSize.php index 1fcddf6d..0d151097 100644 --- a/src/ZfcDatagrid/Column/Formatter/FileSize.php +++ b/src/ZfcDatagrid/Column/Formatter/FileSize.php @@ -1,4 +1,5 @@ getRowData(); + $row = $this->getRowData(); $value = $row[$column->getUniqueId()]; if ('' == $value) { @@ -50,7 +51,7 @@ public function getFormattedValue(AbstractColumn $column) $index = 0; while ($value >= 1024 && $index < count(self::$prefixes)) { $value = $value / 1024; - $index ++; + ++$index; } return sprintf('%1.2f %sB', $value, self::$prefixes[$index]); diff --git a/src/ZfcDatagrid/Column/Formatter/GenerateLink.php b/src/ZfcDatagrid/Column/Formatter/GenerateLink.php index 90438303..de8ea402 100644 --- a/src/ZfcDatagrid/Column/Formatter/GenerateLink.php +++ b/src/ZfcDatagrid/Column/Formatter/GenerateLink.php @@ -1,4 +1,5 @@ getRowData(); + $row = $this->getRowData(); $value = $row[$column->getUniqueId()]; $routeKey = !is_null($this->getRouteKey()) ? @@ -58,7 +60,7 @@ public function getFormattedValue(AbstractColumn $column) : $column->getUniqueId(); - $params = $this->getRouteParams(); + $params = $this->getRouteParams(); $params[$routeKey] = $value; $url = (string) $this->getViewRenderer()->url($this->getRoute(), $params); @@ -75,7 +77,8 @@ public function getViewRenderer() } /** - * @param \Zend\View\Renderer\PhpRenderer $viewRenderer + * @param \Zend\View\Renderer\PhpRenderer $viewRenderer + * * @return self */ public function setViewRenderer($viewRenderer) diff --git a/src/ZfcDatagrid/Column/Formatter/HtmlTag.php b/src/ZfcDatagrid/Column/Formatter/HtmlTag.php index 463a0d16..d34c392a 100644 --- a/src/ZfcDatagrid/Column/Formatter/HtmlTag.php +++ b/src/ZfcDatagrid/Column/Formatter/HtmlTag.php @@ -1,4 +1,5 @@ setLink('/myLink/something/'.$fmt->getColumnValuePlaceholder($myCol)); + * $fmt->setLink('/myLink/something/'.$fmt->getColumnValuePlaceholder($myCol));. + * + * @param AbstractColumn $col * - * @param AbstractColumn $col * @return string */ public function getColumnValuePlaceholder(AbstractColumn $col) { $this->linkColumnPlaceholders[] = $col; - return ':' . $col->getUniqueId() . ':'; + return ':'.$col->getUniqueId().':'; } /** - * * @return AbstractColumn[] */ public function getLinkColumnPlaceholders() @@ -139,7 +138,7 @@ public function getLinkColumnPlaceholders() } /** - * Returns the rowId placeholder + * Returns the rowId placeholder. * * @return string */ @@ -149,7 +148,8 @@ public function getRowIdPlaceholder() } /** - * @param AbstractColumn $col + * @param AbstractColumn $col + * * @return string */ public function getFormattedValue(AbstractColumn $col) @@ -160,9 +160,10 @@ public function getFormattedValue(AbstractColumn $col) } /** - * Get the string version of the attributes + * Get the string version of the attributes. + * + * @param AbstractColumn $col * - * @param AbstractColumn $col * @return string */ protected function getAttributesString(AbstractColumn $col) @@ -172,7 +173,7 @@ protected function getAttributesString(AbstractColumn $col) if ('href' === $attrKey) { $attrValue = $this->getLinkReplaced($col); } - $attributes[] = $attrKey . '="' . $attrValue . '"'; + $attributes[] = $attrKey.'="'.$attrValue.'"'; } return implode(' ', $attributes); @@ -181,7 +182,8 @@ protected function getAttributesString(AbstractColumn $col) /** * This is needed public for rowClickAction... * - * @param AbstractColumn $col + * @param AbstractColumn $col + * * @return string */ protected function getLinkReplaced(AbstractColumn $col) @@ -203,7 +205,7 @@ protected function getLinkReplaced(AbstractColumn $col) } foreach ($this->getLinkColumnPlaceholders() as $col) { - $link = str_replace(':' . $col->getUniqueId() . ':', rawurlencode($row[$col->getUniqueId()]), $link); + $link = str_replace(':'.$col->getUniqueId().':', rawurlencode($row[$col->getUniqueId()]), $link); } return $link; diff --git a/src/ZfcDatagrid/Column/Formatter/Image.php b/src/ZfcDatagrid/Column/Formatter/Image.php index 5c2ab409..646fbba6 100644 --- a/src/ZfcDatagrid/Column/Formatter/Image.php +++ b/src/ZfcDatagrid/Column/Formatter/Image.php @@ -1,4 +1,5 @@ getRowData(); - $value = $row[$column->getUniqueId()]; + $row = $this->getRowData(); + $value = $row[$column->getUniqueId()]; $prefix = $this->getPrefix(); if (is_array($value)) { @@ -70,20 +73,20 @@ public function getFormattedValue(AbstractColumn $column) $original = $thumb; } } else { - $thumb = $value; + $thumb = $value; $original = $value; } $linkAttributes = []; foreach ($this->getLinkAttributes() as $key => $value) { - $linkAttributes[] = $key . '="' . $value . '"'; + $linkAttributes[] = $key.'="'.$value.'"'; } $attributes = []; foreach ($this->getAttributes() as $key => $value) { - $attributes[] = $key . '="' . $value . '"'; + $attributes[] = $key.'="'.$value.'"'; } - return ''; + return ''; } } diff --git a/src/ZfcDatagrid/Column/Formatter/Link.php b/src/ZfcDatagrid/Column/Formatter/Link.php index 674729fb..f7e7dc3b 100644 --- a/src/ZfcDatagrid/Column/Formatter/Link.php +++ b/src/ZfcDatagrid/Column/Formatter/Link.php @@ -1,10 +1,10 @@ UNIQUE will be just the first parameter * $column = new Column('(SELECT GROUP_CONCAT....)', 'someAlias') - * Use the subselect -> UNIQUE will be the second parameter + * Use the subselect -> UNIQUE will be the second parameter. + * + * @param string|object $columnOrIndexOrObject + * @param string $tableOrAliasOrUniqueId * - * @param string|object $columnOrIndexOrObject - * @param string $tableOrAliasOrUniqueId * @throws \Exception */ public function __construct($columnOrIndexOrObject, $tableOrAliasOrUniqueId = null) { - if ($tableOrAliasOrUniqueId !== null && ! is_string($tableOrAliasOrUniqueId)) { + if ($tableOrAliasOrUniqueId !== null && !is_string($tableOrAliasOrUniqueId)) { throw new \Exception('Variable $tableOrAliasOrUniqueId must be null or a string'); } if (is_string($columnOrIndexOrObject) && $tableOrAliasOrUniqueId !== null) { // $column = new Column('id', 'user') - $this->setUniqueId($tableOrAliasOrUniqueId . '_' . $columnOrIndexOrObject); + $this->setUniqueId($tableOrAliasOrUniqueId.'_'.$columnOrIndexOrObject); $this->setSelect($tableOrAliasOrUniqueId, $columnOrIndexOrObject); } elseif (is_string($columnOrIndexOrObject)) { // $column = new Column('title') @@ -54,7 +56,6 @@ public function __construct($columnOrIndexOrObject, $tableOrAliasOrUniqueId = nu } /** - * * @params string $part1 * @params string|object|null $part2 */ @@ -65,7 +66,6 @@ public function setSelect($part1, $part2 = null) } /** - * * @return string */ public function getSelectPart1() @@ -74,7 +74,6 @@ public function getSelectPart1() } /** - * * @return string|object|null */ public function getSelectPart2() @@ -83,7 +82,6 @@ public function getSelectPart2() } /** - * * @param string $filterSelectExpression */ public function setFilterSelectExpression($filterSelectExpression) @@ -92,7 +90,6 @@ public function setFilterSelectExpression($filterSelectExpression) } /** - * * @return string */ public function getFilterSelectExpression() @@ -101,8 +98,7 @@ public function getFilterSelectExpression() } /** - * - * @return boolean + * @return bool */ public function hasFilterSelectExpression() { diff --git a/src/ZfcDatagrid/Column/Style/AbstractColor.php b/src/ZfcDatagrid/Column/Style/AbstractColor.php index cad1648d..99831ac5 100644 --- a/src/ZfcDatagrid/Column/Style/AbstractColor.php +++ b/src/ZfcDatagrid/Column/Style/AbstractColor.php @@ -1,13 +1,14 @@ red = (int) $red; + $this->red = (int) $red; $this->green = (int) $green; - $this->blue = (int) $blue; + $this->blue = (int) $blue; } /** - * Set the RGB + * Set the RGB. * - * @param int $red - * integer 0-255 - * @param integer $green - * 0-255 - * @param integer $blue - * 0-255 + * @param int $red + * integer 0-255 + * @param int $green + * 0-255 + * @param int $blue + * 0-255 */ public function setRgb($red, $green, $blue) { - $this->red = (int) $red; + $this->red = (int) $red; $this->green = (int) $green; - $this->blue = (int) $blue; + $this->blue = (int) $blue; } /** - * - * @param integer $red + * @param int $red */ public function setRed($red) { @@ -93,8 +91,7 @@ public function setRed($red) } /** - * - * @return integer + * @return int */ public function getRed() { @@ -102,8 +99,7 @@ public function getRed() } /** - * - * @param integer $green + * @param int $green */ public function setGreen($green) { @@ -111,8 +107,7 @@ public function setGreen($green) } /** - * - * @return integer + * @return int */ public function getGreen() { @@ -120,8 +115,7 @@ public function getGreen() } /** - * - * @param integer $blue + * @param int $blue */ public function setBlue($blue) { @@ -129,8 +123,7 @@ public function setBlue($blue) } /** - * - * @return integer + * @return int */ public function getBlue() { @@ -138,20 +131,19 @@ public function getBlue() } /** - * * @return array */ public function getRgbArray() { return [ - 'red' => $this->getRed(), + 'red' => $this->getRed(), 'green' => $this->getGreen(), - 'blue' => $this->getBlue(), + 'blue' => $this->getBlue(), ]; } /** - * Convert RGB dec to hex as a string + * Convert RGB dec to hex as a string. * * @return string */ @@ -159,17 +151,17 @@ public function getRgbHexString() { $red = dechex($this->getRed()); if (strlen($red) === 1) { - $red = '0' . $red; + $red = '0'.$red; } $green = dechex($this->getGreen()); if (strlen($green) === 1) { - $green = '0' . $green; + $green = '0'.$green; } $blue = dechex($this->getBlue()); if (strlen($blue) === 1) { - $blue = '0' . $blue; + $blue = '0'.$blue; } - return $red . $green . $blue; + return $red.$green.$blue; } } diff --git a/src/ZfcDatagrid/Column/Style/AbstractStyle.php b/src/ZfcDatagrid/Column/Style/AbstractStyle.php index 11bac4be..2ed7b78e 100644 --- a/src/ZfcDatagrid/Column/Style/AbstractStyle.php +++ b/src/ZfcDatagrid/Column/Style/AbstractStyle.php @@ -1,4 +1,5 @@ byValueOperator = (string) $operator; @@ -30,7 +30,7 @@ public function setByValueOperator($operator = 'OR') /** * Get the show on value operator, e.g. - * OR, AND + * OR, AND. * * @return string */ @@ -40,7 +40,7 @@ public function getByValueOperator() } /** - * Set the style value based and not general + * Set the style value based and not general. * * @param AbstractColumn $column * @param mixed $value @@ -49,14 +49,13 @@ public function getByValueOperator() public function addByValue(AbstractColumn $column, $value, $operator = Filter::EQUAL) { $this->byValues[] = [ - 'column' => $column, - 'value' => $value, + 'column' => $column, + 'value' => $value, 'operator' => $operator, ]; } /** - * * @return array */ public function getByValues() @@ -65,8 +64,7 @@ public function getByValues() } /** - * - * @return boolean + * @return bool */ public function hasByValues() { @@ -78,9 +76,9 @@ public function hasByValues() } /** + * @param array $row * - * @param array $row - * @return boolean + * @return bool */ public function isApply(array $row) { diff --git a/src/ZfcDatagrid/Column/Style/Align.php b/src/ZfcDatagrid/Column/Style/Align.php index 3162f422..72419426 100644 --- a/src/ZfcDatagrid/Column/Style/Align.php +++ b/src/ZfcDatagrid/Column/Style/Align.php @@ -1,34 +1,30 @@ class = $class; + $this->class = $class; } /** diff --git a/src/ZfcDatagrid/Column/Style/Color.php b/src/ZfcDatagrid/Column/Style/Color.php index 76802484..22318eb8 100644 --- a/src/ZfcDatagrid/Column/Style/Color.php +++ b/src/ZfcDatagrid/Column/Style/Color.php @@ -1,8 +1,7 @@ * Attribute specifier - one of the @@ -100,7 +102,7 @@ public function addAttribute($attr, $value) { $this->attributes[] = [ 'attribute' => $attr, - 'value' => $value, + 'value' => $value, ]; } @@ -145,7 +147,6 @@ public function getFilterDefaultOperation() } /** - * * @return NumberFormatter */ protected function getFormatter() @@ -162,8 +163,8 @@ protected function getFormatter() } /** + * @param string $val * - * @param string $val * @return string */ public function getFilterValue($val) @@ -174,7 +175,7 @@ public function getFilterValue($val) $val = substr($val, strlen($this->getPrefix())); } if (strlen($this->getSuffix()) > 0 && strpos($val, $this->getSuffix()) > 0) { - $val = substr($val, 0, - strlen($this->getSuffix())); + $val = substr($val, 0, -strlen($this->getSuffix())); } try { @@ -191,9 +192,10 @@ public function getFilterValue($val) } /** - * Convert the value from the source to the value, which the user will see + * Convert the value from the source to the value, which the user will see. + * + * @param string $val * - * @param string $val * @return string */ public function getUserValue($val) @@ -202,6 +204,6 @@ public function getUserValue($val) $formattedValue = $formatter->format($val, $this->getFormatType()); - return (string) $this->getPrefix() . $formattedValue . $this->getSuffix(); + return (string) $this->getPrefix().$formattedValue.$this->getSuffix(); } } diff --git a/src/ZfcDatagrid/Column/Type/PhpArray.php b/src/ZfcDatagrid/Column/Type/PhpArray.php index 7db7650c..c57eb115 100644 --- a/src/ZfcDatagrid/Column/Type/PhpArray.php +++ b/src/ZfcDatagrid/Column/Type/PhpArray.php @@ -1,17 +1,17 @@ sortConditions[] = [ - 'column' => $column, + 'column' => $column, 'sortDirection' => $sortDirection, ]; } @@ -90,7 +88,6 @@ public function setSortConditions(array $sortConditions) } /** - * * @return array */ public function getSortConditions() @@ -99,7 +96,7 @@ public function getSortConditions() } /** - * Add a filter rule + * Add a filter rule. * * @param Filter $filter */ @@ -109,7 +106,6 @@ public function addFilter(Filter $filter) } /** - * * @param array $filters */ public function setFilters(array $filters) @@ -118,7 +114,6 @@ public function setFilters(array $filters) } /** - * * @return \ZfcDatagrid\Filter[] */ public function getFilters() @@ -135,7 +130,6 @@ public function setPaginatorAdapter(PaginatorAdapterInterface $paginator) } /** - * * @return \Zend\Paginator\Adapter\AdapterInterface */ public function getPaginatorAdapter() @@ -144,7 +138,8 @@ public function getPaginatorAdapter() } /** - * Get the data back from construct + * Get the data back from construct. + * * @return mixed */ abstract public function getData(); @@ -152,7 +147,7 @@ abstract public function getData(); /** * Execute the query and set the paginator * - with sort statements - * - with filters statements + * - with filters statements. */ abstract public function execute(); } diff --git a/src/ZfcDatagrid/DataSource/DataSourceInterface.php b/src/ZfcDatagrid/DataSource/DataSourceInterface.php index 6a4c9b99..b622a10a 100644 --- a/src/ZfcDatagrid/DataSource/DataSourceInterface.php +++ b/src/ZfcDatagrid/DataSource/DataSourceInterface.php @@ -1,4 +1,5 @@ getSelectPart1(); if ($col->getSelectPart2() != '') { - $colString .= '.' . $col->getSelectPart2(); + $colString .= '.'.$col->getSelectPart2(); } - $colString .= ' ' . $col->getUniqueId(); + $colString .= ' '.$col->getUniqueId(); $selectColumns[] = $colString; } @@ -81,18 +80,18 @@ public function execute() $col = $sortCondition['column']; if (!$col instanceof Column\Select) { - throw new \Exception('This column cannot be sorted: ' . $col->getUniqueId()); + throw new \Exception('This column cannot be sorted: '.$col->getUniqueId()); } /* @var $col \ZfcDatagrid\Column\Select */ $colString = $col->getSelectPart1(); if ($col->getSelectPart2() != '') { - $colString .= '.' . $col->getSelectPart2(); + $colString .= '.'.$col->getSelectPart2(); } if ($col->getType() instanceof Type\Number) { - $qb->addSelect('ABS(' . $colString . ') sortColumn' . $key); - $qb->add('orderBy', new Expr\OrderBy('sortColumn' . $key, $sortCondition['sortDirection']), true); + $qb->addSelect('ABS('.$colString.') sortColumn'.$key); + $qb->add('orderBy', new Expr\OrderBy('sortColumn'.$key, $sortCondition['sortDirection']), true); } else { $qb->add('orderBy', new Expr\OrderBy($col->getUniqueId(), $sortCondition['sortDirection']), true); } diff --git a/src/ZfcDatagrid/DataSource/Doctrine2/Filter.php b/src/ZfcDatagrid/DataSource/Doctrine2/Filter.php index c7b9d796..be07d2d5 100644 --- a/src/ZfcDatagrid/DataSource/Doctrine2/Filter.php +++ b/src/ZfcDatagrid/DataSource/Doctrine2/Filter.php @@ -1,4 +1,5 @@ getQueryBuilder(); + $qb = $this->getQueryBuilder(); $expr = new Expr(); - $col = $filter->getColumn(); + $col = $filter->getColumn(); if (!$col instanceof Column\Select) { - throw new \Exception('This column cannot be filtered: ' . $col->getUniqueId()); + throw new \Exception('This column cannot be filtered: '.$col->getUniqueId()); } $colString = $col->getSelectPart1(); if ($col->getSelectPart2() != '') { - $colString .= '.' . $col->getSelectPart2(); + $colString .= '.'.$col->getSelectPart2(); } if ($col instanceof Column\Select && $col->hasFilterSelectExpression()) { $colString = sprintf($col->getFilterSelectExpression(), $colString); @@ -56,38 +56,38 @@ public function applyFilter(DatagridFilter $filter) $wheres = []; foreach ($values as $key => $value) { - $valueParameterName = ':' . str_replace('.', '', $col->getUniqueId() . $key); + $valueParameterName = ':'.str_replace('.', '', $col->getUniqueId().$key); switch ($filter->getOperator()) { case DatagridFilter::LIKE: $wheres[] = $expr->like($colString, $valueParameterName); - $qb->setParameter($valueParameterName, '%' . $value . '%'); + $qb->setParameter($valueParameterName, '%'.$value.'%'); break; case DatagridFilter::LIKE_LEFT: $wheres[] = $expr->like($colString, $valueParameterName); - $qb->setParameter($valueParameterName, '%' . $value); + $qb->setParameter($valueParameterName, '%'.$value); break; case DatagridFilter::LIKE_RIGHT: $wheres[] = $expr->like($colString, $valueParameterName); - $qb->setParameter($valueParameterName, $value . '%'); + $qb->setParameter($valueParameterName, $value.'%'); break; case DatagridFilter::NOT_LIKE: $wheres[] = $expr->notLike($colString, $valueParameterName); - $qb->setParameter($valueParameterName, '%' . $value . '%'); + $qb->setParameter($valueParameterName, '%'.$value.'%'); break; case DatagridFilter::NOT_LIKE_LEFT: $wheres[] = $expr->notLike($colString, $valueParameterName); - $qb->setParameter($valueParameterName, '%' . $value); + $qb->setParameter($valueParameterName, '%'.$value); break; case DatagridFilter::NOT_LIKE_RIGHT: $wheres[] = $expr->notLike($colString, $valueParameterName); - $qb->setParameter($valueParameterName, $value . '%'); + $qb->setParameter($valueParameterName, $value.'%'); break; case DatagridFilter::EQUAL: @@ -121,8 +121,8 @@ public function applyFilter(DatagridFilter $filter) break; case DatagridFilter::BETWEEN: - $minParameterName = ':' . str_replace('.', '', $colString . '0'); - $maxParameterName = ':' . str_replace('.', '', $colString . '1'); + $minParameterName = ':'.str_replace('.', '', $colString.'0'); + $maxParameterName = ':'.str_replace('.', '', $colString.'1'); $wheres[] = $expr->between($colString, $minParameterName, $maxParameterName); @@ -131,7 +131,7 @@ public function applyFilter(DatagridFilter $filter) break 2; default: - throw new \InvalidArgumentException('This operator is currently not supported: ' . $filter->getOperator()); + throw new \InvalidArgumentException('This operator is currently not supported: '.$filter->getOperator()); break; } } diff --git a/src/ZfcDatagrid/DataSource/Doctrine2/Paginator.php b/src/ZfcDatagrid/DataSource/Doctrine2/Paginator.php index c8e57035..80c92c55 100644 --- a/src/ZfcDatagrid/DataSource/Doctrine2/Paginator.php +++ b/src/ZfcDatagrid/DataSource/Doctrine2/Paginator.php @@ -1,8 +1,7 @@ getQueryBuilder(); + $qb = $this->getQueryBuilder(); $parts = $qb->getDQLParts(); if ($parts['having'] !== null || true === $parts['distinct']) { @@ -70,7 +65,6 @@ private function useCustomPaginator() } /** - * * @return \Doctrine\ORM\Tools\Pagination\Paginator */ private function getPaginator() @@ -92,8 +86,9 @@ private function getPaginator() /** * Returns an array of items for a page. * - * @param integer $offset - * @param integer $itemCountPerPage + * @param int $offset + * @param int $itemCountPerPage + * * @return array */ public function getItems($offset, $itemCountPerPage) @@ -113,7 +108,7 @@ public function getItems($offset, $itemCountPerPage) /** * Returns the total number of rows in the result set. * - * @return integer + * @return int */ public function count() { diff --git a/src/ZfcDatagrid/DataSource/Doctrine2/PaginatorFast.php b/src/ZfcDatagrid/DataSource/Doctrine2/PaginatorFast.php index 52c718cb..3127b0ca 100644 --- a/src/ZfcDatagrid/DataSource/Doctrine2/PaginatorFast.php +++ b/src/ZfcDatagrid/DataSource/Doctrine2/PaginatorFast.php @@ -1,4 +1,5 @@ getQueryBuilder(); - $qb = clone $qbOriginal; + $qb = clone $qbOriginal; - $dqlParts = $qb->getDQLParts(); + $dqlParts = $qb->getDQLParts(); $groupParts = $dqlParts['groupBy']; /* @@ -90,9 +89,9 @@ public function count() // more than one group part...tricky! // @todo finde something better... $qb->resetDQLPart('groupBy'); - $qb->select('CONCAT(' . implode(',', $groupParts) . ') as uniqueParts'); + $qb->select('CONCAT('.implode(',', $groupParts).') as uniqueParts'); - $items = []; + $items = []; $result = $qb->getQuery()->getResult(); foreach ($result as $row) { $items[] = $row['uniqueParts']; @@ -104,7 +103,7 @@ public function count() $groupPart = $groupParts[0]; $qb->resetDQLPart('groupBy'); - $qb->select('COUNT(DISTINCT ' . $groupPart . ')'); + $qb->select('COUNT(DISTINCT '.$groupPart.')'); $this->rowCount = $qb->getQuery()->getSingleScalarResult(); } else { @@ -116,7 +115,7 @@ public function count() $qb->select('COUNT_ONE() AS rowCount'); } else { $fromPart = $dqlParts['from']; - $qb->select('COUNT(' . $fromPart[0]->getAlias() . ')'); + $qb->select('COUNT('.$fromPart[0]->getAlias().')'); } $this->rowCount = $qb->getQuery()->getSingleScalarResult(); diff --git a/src/ZfcDatagrid/DataSource/Doctrine2Collection.php b/src/ZfcDatagrid/DataSource/Doctrine2Collection.php index 21817695..1375e293 100644 --- a/src/ZfcDatagrid/DataSource/Doctrine2Collection.php +++ b/src/ZfcDatagrid/DataSource/Doctrine2Collection.php @@ -1,4 +1,5 @@ em; } - /** - * - */ public function execute() { $hydrator = new DoctrineHydrator($this->getEntityManager()); diff --git a/src/ZfcDatagrid/DataSource/PhpArray.php b/src/ZfcDatagrid/DataSource/PhpArray.php index 3d52998c..1305bc49 100644 --- a/src/ZfcDatagrid/DataSource/PhpArray.php +++ b/src/ZfcDatagrid/DataSource/PhpArray.php @@ -1,4 +1,5 @@ data = $data; } else { - throw new \InvalidArgumentException("Unsupported data input, please provide an array"); + throw new \InvalidArgumentException('Unsupported data input, please provide an array'); } } /** - * * @return array */ public function getData() @@ -34,13 +34,13 @@ public function getData() /** * Execute the query and set the paginator * - with sort statements - * - with filters statements + * - with filters statements. */ public function execute() { $data = $this->getData(); - /** + /* * Step 1) Apply sorting * * @see http://php.net/manual/de/function.array-multisort.php @@ -50,7 +50,7 @@ public function execute() $data = $this->sortArrayMultiple($data, $this->getSortConditions()); } - /** + /* * Step 2) Apply filters */ foreach ($this->getFilters() as $filter) { @@ -64,7 +64,7 @@ public function execute() } /** - * Step 3) Remove unneeded columns + * Step 3) Remove unneeded columns. * * @todo ? Better performance or let it be? */ @@ -76,7 +76,7 @@ public function execute() $colString = $col->getSelectPart1(); if ($col->getSelectPart2() != '') { - $colString = $col->getSelectPart1() . '_' . $col->getSelectPart2(); + $colString = $col->getSelectPart1().'_'.$col->getSelectPart2(); } $selectedColumns[] = $colString; @@ -84,21 +84,21 @@ public function execute() foreach ($data as &$row) { foreach ($row as $keyRowCol => $rowCol) { - if (! in_array($keyRowCol, $selectedColumns)) { + if (!in_array($keyRowCol, $selectedColumns)) { unset($row[$keyRowCol]); } } } - /** + /* * Step 4) Pagination */ $this->setPaginatorAdapter(new PaginatorAdapter($data)); } /** + * @param array $sortCondition * - * @param array $sortCondition * @return array */ private function getSortArrayParameter($sortCondition) @@ -108,22 +108,22 @@ private function getSortArrayParameter($sortCondition) ]; if ('DESC' === $sortCondition['sortDirection']) { - $desc = SORT_DESC; + $desc = SORT_DESC; $sortArray[] = $desc; } else { - $asc = SORT_ASC; + $asc = SORT_ASC; $sortArray[] = $asc; } switch (get_class($sortCondition['column']->getType())) { case 'ZfcDatagrid\Column\Type\Number': - $numeric = SORT_NUMERIC; + $numeric = SORT_NUMERIC; $sortArray[] = $numeric; break; default: - $regular = SORT_REGULAR; + $regular = SORT_REGULAR; $sortArray[] = $regular; break; } @@ -132,9 +132,10 @@ private function getSortArrayParameter($sortCondition) } /** - * * @see http://php.net/manual/de/function.array-multisort.php Example in comments: array_orderby() + * * @author jimpoz at jimpoz dot com + * * @return array */ private function sortArrayMultiple(array $data, $sortConditions) @@ -148,7 +149,7 @@ private function sortArrayMultiple(array $data, $sortConditions) $dataCol = []; foreach ($data as $key => $row) { - if (! isset($row[$column])) { + if (!isset($row[$column])) { $value = ''; } else { $value = $row[$column]; @@ -167,10 +168,11 @@ private function sortArrayMultiple(array $data, $sortConditions) } /** - * Multisort an array + * Multisort an array. + * + * @param array $data + * @param array $sortArguments * - * @param array $data - * @param array $sortArguments * @throws \InvalidArgumentException * * @return array @@ -181,7 +183,7 @@ private function applyMultiSort(array $data, array $sortArguments) foreach ($sortArguments as $values) { $remain = count($values) % 3; if ($remain != 0) { - throw new \InvalidArgumentException('The parameter count for each sortArgument has to be three. Given count of: ' . count($values)); + throw new \InvalidArgumentException('The parameter count for each sortArgument has to be three. Given count of: '.count($values)); } $args[] = $values[0]; // column value $args[] = $values[1]; // sort direction diff --git a/src/ZfcDatagrid/DataSource/PhpArray/Filter.php b/src/ZfcDatagrid/DataSource/PhpArray/Filter.php index 08ba4485..0f8f2423 100644 --- a/src/ZfcDatagrid/DataSource/PhpArray/Filter.php +++ b/src/ZfcDatagrid/DataSource/PhpArray/Filter.php @@ -1,4 +1,5 @@ getFilter()->getValues() as $filterValue) { $filter = $this->getFilter(); - $col = $filter->getColumn(); + $col = $filter->getColumn(); $value = $row[$col->getUniqueId()]; $value = $col->getType()->getFilterValue($value); diff --git a/src/ZfcDatagrid/DataSource/ZendSelect.php b/src/ZfcDatagrid/DataSource/ZendSelect.php index e5664579..2efedf26 100644 --- a/src/ZfcDatagrid/DataSource/ZendSelect.php +++ b/src/ZfcDatagrid/DataSource/ZendSelect.php @@ -1,4 +1,5 @@ getAdapter() === null || ! $this->getAdapter() instanceof \Zend\Db\Sql\Sql) { + if ($this->getAdapter() === null || !$this->getAdapter() instanceof \Zend\Db\Sql\Sql) { throw new \Exception('Object "Zend\Db\Sql\Sql" is missing, please call setAdapter() first!'); } @@ -95,7 +93,7 @@ public function execute() $colString = $col->getSelectPart1(); if ($col->getSelectPart2() != '') { - $colString = new Expression($platform->quoteIdentifier($colString) . $platform->getIdentifierSeparator() . $platform->quoteIdentifier($col->getSelectPart2())); + $colString = new Expression($platform->quoteIdentifier($colString).$platform->getIdentifierSeparator().$platform->quoteIdentifier($col->getSelectPart2())); } $selectColumns[$col->getUniqueId()] = $colString; @@ -118,7 +116,7 @@ public function execute() foreach ($this->getSortConditions() as $sortCondition) { /** @var \ZfcDataGrid\Column\AbstractColumn $col */ $col = $sortCondition['column']; - $select->order($col->getUniqueId() . ' ' . $sortCondition['sortDirection']); + $select->order($col->getUniqueId().' '.$sortCondition['sortDirection']); } } diff --git a/src/ZfcDatagrid/DataSource/ZendSelect/Filter.php b/src/ZfcDatagrid/DataSource/ZendSelect/Filter.php index 726a8d14..e709c4b3 100644 --- a/src/ZfcDatagrid/DataSource/ZendSelect/Filter.php +++ b/src/ZfcDatagrid/DataSource/ZendSelect/Filter.php @@ -1,4 +1,5 @@ sql = $sql; + $this->sql = $sql; $this->select = $select; } /** - * * @return \Zend\Db\Sql\Sql */ public function getSql() @@ -38,7 +36,6 @@ public function getSql() } /** - * * @return \Zend\Db\Sql\Select */ public function getSelect() @@ -47,7 +44,8 @@ public function getSelect() } /** - * @param DatagridFilter $filter + * @param DatagridFilter $filter + * * @throws \Exception */ public function applyFilter(DatagridFilter $filter) @@ -55,18 +53,18 @@ public function applyFilter(DatagridFilter $filter) $select = $this->getSelect(); $adapter = $this->getSql()->getAdapter(); - $qi = function ($name) use ($adapter) { + $qi = function ($name) use ($adapter) { return $adapter->getPlatform()->quoteIdentifier($name); }; - $col = $filter->getColumn(); + $col = $filter->getColumn(); if (!$col instanceof Column\Select) { - throw new \Exception('This column cannot be filtered: ' . $col->getUniqueId()); + throw new \Exception('This column cannot be filtered: '.$col->getUniqueId()); } $colString = $col->getSelectPart1(); if ($col->getSelectPart2() != '') { - $colString .= '.' . $col->getSelectPart2(); + $colString .= '.'.$col->getSelectPart2(); } if ($col instanceof Column\Select && $col->hasFilterSelectExpression()) { $colString = sprintf($col->getFilterSelectExpression(), $colString); @@ -80,32 +78,32 @@ public function applyFilter(DatagridFilter $filter) switch ($filter->getOperator()) { case DatagridFilter::LIKE: - $wheres[] = $where->like($colString, '%' . $value . '%'); + $wheres[] = $where->like($colString, '%'.$value.'%'); break; case DatagridFilter::LIKE_LEFT: - $wheres[] = $where->like($colString, '%' . $value); + $wheres[] = $where->like($colString, '%'.$value); break; case DatagridFilter::LIKE_RIGHT: - $wheres[] = $where->like($colString, $value . '%'); + $wheres[] = $where->like($colString, $value.'%'); break; case DatagridFilter::NOT_LIKE: - $wheres[] = $where->literal($qi($colString) . 'NOT LIKE ?', [ - '%' . $value . '%', + $wheres[] = $where->literal($qi($colString).'NOT LIKE ?', [ + '%'.$value.'%', ]); break; case DatagridFilter::NOT_LIKE_LEFT: - $wheres[] = $where->literal($qi($colString) . 'NOT LIKE ?', [ - '%' . $value, + $wheres[] = $where->literal($qi($colString).'NOT LIKE ?', [ + '%'.$value, ]); break; case DatagridFilter::NOT_LIKE_RIGHT: - $wheres[] = $where->literal($qi($colString) . 'NOT LIKE ?', [ - $value . '%', + $wheres[] = $where->literal($qi($colString).'NOT LIKE ?', [ + $value.'%', ]); break; @@ -138,7 +136,7 @@ public function applyFilter(DatagridFilter $filter) break 2; default: - throw new \InvalidArgumentException('This operator is currently not supported: ' . $filter->getOperator()); + throw new \InvalidArgumentException('This operator is currently not supported: '.$filter->getOperator()); break; } } diff --git a/src/ZfcDatagrid/Datagrid.php b/src/ZfcDatagrid/Datagrid.php index 6976bef6..a8c12f36 100644 --- a/src/ZfcDatagrid/Datagrid.php +++ b/src/ZfcDatagrid/Datagrid.php @@ -1,9 +1,11 @@ cacheId) { $this->cacheId = md5($this->getSession() ->getManager() - ->getId() . '_' . $this->getId()); + ->getId().'_'.$this->getId()); } return $this->cacheId; @@ -367,11 +343,10 @@ public function getCacheId() public function setMvcEvent(MvcEvent $mvcEvent) { $this->mvcEvent = $mvcEvent; - $this->request = $mvcEvent->getRequest(); + $this->request = $mvcEvent->getRequest(); } /** - * * @return MvcEvent */ public function getMvcEvent() @@ -380,7 +355,6 @@ public function getMvcEvent() } /** - * * @return HttpRequest */ public function getRequest() @@ -389,14 +363,15 @@ public function getRequest() } /** - * Set the translator + * Set the translator. + * + * @param Translator $translator * - * @param Translator $translator * @throws \InvalidArgumentException */ public function setTranslator($translator = null) { - if (! $translator instanceof Translator && ! $translator instanceof \Zend\I18n\Translator\TranslatorInterface) { + if (!$translator instanceof Translator && !$translator instanceof \Zend\I18n\Translator\TranslatorInterface) { throw new \InvalidArgumentException('Translator must be an instanceof "Zend\I18n\Translator\Translator" or "Zend\I18n\Translator\TranslatorInterface"'); } @@ -404,7 +379,6 @@ public function setTranslator($translator = null) } /** - * * @return Translator */ public function getTranslator() @@ -413,8 +387,7 @@ public function getTranslator() } /** - * - * @return boolean + * @return bool */ public function hasTranslator() { @@ -426,9 +399,10 @@ public function hasTranslator() } /** - * Set the data source + * Set the data source. + * + * @param mixed $data * - * @param mixed $data * @throws \Exception */ public function setDataSource($data) @@ -441,14 +415,14 @@ public function setDataSource($data) $this->dataSource = new DataSource\Doctrine2($data); } elseif ($data instanceof ZendSelect) { $args = func_get_args(); - if (count($args) === 1 || (! $args[1] instanceof \Zend\Db\Adapter\Adapter && ! $args[1] instanceof \Zend\Db\Sql\Sql)) { + if (count($args) === 1 || (!$args[1] instanceof \Zend\Db\Adapter\Adapter && !$args[1] instanceof \Zend\Db\Sql\Sql)) { throw new \InvalidArgumentException('For "Zend\Db\Sql\Select" also a "Zend\Db\Adapter\Sql" or "Zend\Db\Sql\Sql" is needed.'); } $this->dataSource = new DataSource\ZendSelect($data); $this->dataSource->setAdapter($args[1]); } elseif ($data instanceof Collection) { $args = func_get_args(); - if (count($args) === 1 || ! $args[1] instanceof \Doctrine\ORM\EntityManager) { + if (count($args) === 1 || !$args[1] instanceof \Doctrine\ORM\EntityManager) { throw new \InvalidArgumentException('If providing a Collection, also the Doctrine\ORM\EntityManager is needed as a second parameter'); } $this->dataSource = new DataSource\Doctrine2Collection($data); @@ -459,7 +433,6 @@ public function setDataSource($data) } /** - * * @return \ZfcDatagrid\DataSource\DataSourceInterface */ public function getDataSource() @@ -470,7 +443,7 @@ public function getDataSource() /** * Datasource defined? * - * @return boolean + * @return bool */ public function hasDataSource() { @@ -482,9 +455,9 @@ public function hasDataSource() } /** - * Set default items per page (-1 for unlimited) + * Set default items per page (-1 for unlimited). * - * @param integer $count + * @param int $count */ public function setDefaultItemsPerPage($count = 25) { @@ -492,8 +465,7 @@ public function setDefaultItemsPerPage($count = 25) } /** - * - * @return integer + * @return int */ public function getDefaultItemsPerPage() { @@ -501,7 +473,7 @@ public function getDefaultItemsPerPage() } /** - * Set the title + * Set the title. * * @param string $title */ @@ -511,7 +483,6 @@ public function setTitle($title) } /** - * * @return string */ public function getTitle() @@ -520,7 +491,7 @@ public function getTitle() } /** - * Add a external parameter + * Add a external parameter. * * @param string $name * @param mixed $value @@ -531,7 +502,7 @@ public function addParameter($name, $value) } /** - * These parameters are handled to the view + over all grid actions + * These parameters are handled to the view + over all grid actions. * * @param array $parameters */ @@ -541,7 +512,6 @@ public function setParameters(array $parameters) } /** - * * @return array */ public function getParameters() @@ -552,7 +522,7 @@ public function getParameters() /** * Has parameters? * - * @return boolean + * @return bool */ public function hasParameters() { @@ -560,7 +530,7 @@ public function hasParameters() } /** - * Set the base url + * Set the base url. * * @param string $url */ @@ -570,7 +540,6 @@ public function setUrl($url) } /** - * * @return string */ public function getUrl() @@ -579,7 +548,7 @@ public function getUrl() } /** - * Set the export renderers (overwrite the config) + * Set the export renderers (overwrite the config). * * @param array $renderers */ @@ -589,14 +558,14 @@ public function setExportRenderers(array $renderers = []) } /** - * Get the export renderers + * Get the export renderers. * * @return array */ public function getExportRenderers() { if (null === $this->exportRenderers) { - $options = $this->getOptions(); + $options = $this->getOptions(); $this->exportRenderers = $options['settings']['export']['formats']; } @@ -604,7 +573,7 @@ public function getExportRenderers() } /** - * Create a column from array instanceof + * Create a column from array instanceof. * * @param array $config * @@ -616,21 +585,21 @@ private function createColumn($config) return $config; } - if (! is_array($config) && ! $config instanceof Column\AbstractColumn) { + if (!is_array($config) && !$config instanceof Column\AbstractColumn) { throw new \InvalidArgumentException('createColumn() supports only a config array or instanceof Column\AbstractColumn as a parameter'); } $colType = isset($config['colType']) ? $config['colType'] : 'Select'; if (class_exists($colType, true)) { $class = $colType; - } elseif (class_exists('ZfcDatagrid\\Column\\' . $colType, true)) { - $class = 'ZfcDatagrid\\Column\\' . $colType; + } elseif (class_exists('ZfcDatagrid\\Column\\'.$colType, true)) { + $class = 'ZfcDatagrid\\Column\\'.$colType; } else { throw new \InvalidArgumentException(sprintf('Column type: "%s" not found!', $colType)); } if ('ZfcDatagrid\\Column\\Select' == $class) { - if (! isset($config['select']['column'])) { + if (!isset($config['select']['column'])) { throw new \InvalidArgumentException('For "ZfcDatagrid\Column\Select" the option select[column] must be defined!'); } $table = isset($config['select']['table']) ? $config['select']['table'] : null; @@ -641,10 +610,10 @@ private function createColumn($config) } foreach ($config as $key => $value) { - $method = 'set' . ucfirst($key); + $method = 'set'.ucfirst($key); if (method_exists($instance, $method)) { if (in_array($key, $this->specialMethods)) { - if (! is_array($value)) { + if (!is_array($value)) { $value = [ $value, ]; @@ -666,7 +635,7 @@ private function createColumn($config) } /** - * Set multiple columns by array (willoverwrite all existing) + * Set multiple columns by array (willoverwrite all existing). * * @param array $columns */ @@ -675,7 +644,7 @@ public function setColumns(array $columns) $useColumns = []; foreach ($columns as $col) { - $col = $this->createColumn($col); + $col = $this->createColumn($col); $useColumns[$col->getUniqueId()] = $col; } @@ -683,18 +652,17 @@ public function setColumns(array $columns) } /** - * Add a column by array config or instanceof Column\AbstractColumn + * Add a column by array config or instanceof Column\AbstractColumn. * * @param array|Column\AbstractColumn $col */ public function addColumn($col) { - $col = $this->createColumn($col); + $col = $this->createColumn($col); $this->columns[$col->getUniqueId()] = $col; } /** - * * @return \ZfcDatagrid\Column\AbstractColumn[] */ public function getColumns() @@ -703,8 +671,8 @@ public function getColumns() } /** + * @param string $id * - * @param string $id * @return Column\AbstractColumn null */ public function getColumnByUniqueId($id) @@ -717,7 +685,6 @@ public function getColumnByUniqueId($id) } /** - * * @param Style\AbstractStyle $style */ public function addRowStyle(Style\AbstractStyle $style) @@ -726,7 +693,6 @@ public function addRowStyle(Style\AbstractStyle $style) } /** - * * @return Style\AbstractStyle[] */ public function getRowStyles() @@ -735,8 +701,7 @@ public function getRowStyles() } /** - * - * @return boolean + * @return bool */ public function hasRowStyles() { @@ -744,18 +709,17 @@ public function hasRowStyles() } /** - * If disabled, the toolbar filter will not be shown to the user + * If disabled, the toolbar filter will not be shown to the user. * - * @param boolean $mode + * @param bool $mode */ public function setUserFilterDisabled($mode = true) { - $this->isUserFilterEnabled = (bool) ! $mode; + $this->isUserFilterEnabled = (bool) !$mode; } /** - * - * @return boolean + * @return bool */ public function isUserFilterEnabled() { @@ -772,18 +736,13 @@ public function setRowClickAction(Column\Action\AbstractAction $action) $this->rowClickAction = $action; } - /** - * - * @return null Column\Action\AbstractAction - */ public function getRowClickAction() { return $this->rowClickAction; } /** - * - * @return boolean + * @return bool */ public function hasRowClickAction() { @@ -795,7 +754,7 @@ public function hasRowClickAction() } /** - * Add a mass action + * Add a mass action. * * @param Action\Mass $action */ @@ -805,7 +764,6 @@ public function addMassAction(Action\Mass $action) } /** - * * @return Action\Mass[] */ public function getMassActions() @@ -814,8 +772,7 @@ public function getMassActions() } /** - * - * @return boolean + * @return bool */ public function hasMassAction() { @@ -825,7 +782,7 @@ public function hasMassAction() /** * Overwrite the render * F.x. - * if you want to directly render a PDF + * if you want to directly render a PDF. * * @param string $name */ @@ -835,13 +792,13 @@ public function setRendererName($name = null) } /** - * Get the current renderer name + * Get the current renderer name. * * @return string */ public function getRendererName() { - $options = $this->getOptions(); + $options = $this->getOptions(); $parameterName = $options['generalParameterNames']['rendererType']; if ($this->forceRenderer !== null) { @@ -865,9 +822,10 @@ public function getRendererName() } /** - * Return the current renderer + * Return the current renderer. * * @throws \Exception + * * @return \ZfcDatagrid\Renderer\AbstractRenderer */ public function getRenderer() @@ -875,7 +833,7 @@ public function getRenderer() if (null === $this->renderer) { if (isset($this->rendererService)) { $renderer = $this->rendererService; - if (! $renderer instanceof Renderer\AbstractRenderer) { + if (!$renderer instanceof Renderer\AbstractRenderer) { throw new \Exception('Renderer service must implement "ZfcDatagrid\Renderer\AbstractRenderer"'); } $renderer->setOptions($this->getOptions()); @@ -904,8 +862,7 @@ public function getRenderer() } /** - * - * @return boolean + * @return bool */ public function isDataLoaded() { @@ -913,7 +870,7 @@ public function isDataLoaded() } /** - * Load the data + * Load the data. */ public function loadData() { @@ -930,29 +887,29 @@ public function loadData() } /** - * Apply cache + * Apply cache. */ $renderer = $this->getRenderer(); - /** + /* * Step 1) Apply needed columns + filters + sort * - from Request (HTML View) -> and save in cache for export * - or from cache (Export PDF / Excel) -> same view like HTML (without LIMIT/Pagination) */ { - /** + /* * Step 1.1) Only select needed columns (performance) */ $this->getDataSource()->setColumns($this->getColumns()); - /** + /* * Step 1.2) Sorting */ foreach ($renderer->getSortConditions() as $condition) { $this->getDataSource()->addSortCondition($condition['column'], $condition['sortDirection']); } - /** + /* * Step 1.3) Filtering */ foreach ($renderer->getFilters() as $filter) { @@ -975,7 +932,7 @@ public function loadData() /* @var $currentItems \ArrayIterator */ $data = $this->paginator->getCurrentItems(); - if (! is_array($data)) { + if (!is_array($data)) { if ($data instanceof \Zend\Db\ResultSet\ResultSet) { $data = $data->toArray(); } elseif ($data instanceof ArrayIterator) { @@ -1000,8 +957,8 @@ public function loadData() if ($this->getOptions()['settings']['export']['enabled'] && $renderer->isExport() === false) { $cacheData = [ 'sortConditions' => $renderer->getSortConditions(), - 'filters' => $renderer->getFilters(), - 'currentPage' => $this->getPaginator()->getCurrentPageNumber(), + 'filters' => $renderer->getFilters(), + 'currentPage' => $this->getPaginator()->getCurrentPageNumber(), ]; $success = $this->getCache()->setItem($this->getCacheId(), $cacheData); if ($success !== true) { @@ -1032,7 +989,7 @@ public function loadData() } /** - * Render the grid + * Render the grid. */ public function render() { @@ -1042,7 +999,7 @@ public function render() /** * Step 4) Render the data to the defined output format (HTML, PDF...) - * - Styling the values based on column (and value) + * - Styling the values based on column (and value). */ $renderer = $this->getRenderer(); $renderer->setTitle($this->getTitle()); @@ -1058,7 +1015,7 @@ public function render() /** * Is already rendered? * - * @return boolean + * @return bool */ public function isRendered() { @@ -1066,8 +1023,8 @@ public function isRendered() } /** - * * @throws \Exception + * * @return Paginator */ public function getPaginator() @@ -1080,7 +1037,6 @@ public function getPaginator() } /** - * * @return array */ private function getPreparedData() @@ -1089,7 +1045,7 @@ private function getPreparedData() } /** - * Set the toolbar view template + * Set the toolbar view template. * * @param string $name */ @@ -1100,7 +1056,7 @@ public function setToolbarTemplate($name) /** * Get the toolbar template name - * Return null if nothing custom set + * Return null if nothing custom set. * * @return string|null */ @@ -1110,7 +1066,7 @@ public function getToolbarTemplate() } /** - * Set the toolbar view template variables + * Set the toolbar view template variables. * * @param array $variables */ @@ -1120,7 +1076,7 @@ public function setToolbarTemplateVariables(array $variables) } /** - * Get the toolbar template variables + * Get the toolbar template variables. * * @return array */ @@ -1132,7 +1088,8 @@ public function getToolbarTemplateVariables() /** * Set a custom ViewModel...generally NOT necessary! * - * @param ViewModel $viewModel + * @param ViewModel $viewModel + * * @throws \Exception */ public function setViewModel(ViewModel $viewModel) @@ -1145,7 +1102,6 @@ public function setViewModel(ViewModel $viewModel) } /** - * * @return ViewModel */ public function getViewModel() @@ -1158,12 +1114,11 @@ public function getViewModel() } /** - * * @return \Zend\Stdlib\ResponseInterface|\Zend\Http\Response\Stream|\Zend\View\Model\ViewModel */ public function getResponse() { - if (! $this->isRendered()) { + if (!$this->isRendered()) { $this->render(); } @@ -1173,13 +1128,13 @@ public function getResponse() /** * Is this a HTML "init" response? * YES: loading the HTML for the grid - * NO: AJAX loading OR it's an export + * NO: AJAX loading OR it's an export. * - * @return boolean + * @return bool */ public function isHtmlInitReponse() { - if (! $this->getResponse() instanceof JsonModel && ! $this->getResponse() instanceof ResponseInterface) { + if (!$this->getResponse() instanceof JsonModel && !$this->getResponse() instanceof ResponseInterface) { return true; } @@ -1187,7 +1142,8 @@ public function isHtmlInitReponse() } /** - * @param Renderer\AbstractRenderer $rendererService + * @param Renderer\AbstractRenderer $rendererService + * * @return self */ public function setRendererService(Renderer\AbstractRenderer $rendererService) @@ -1196,4 +1152,28 @@ public function setRendererService(Renderer\AbstractRenderer $rendererService) return $this; } + + /** + * Set service locator. + * + * @param ContainerInterface $serviceLocator + * + * @return mixed + */ + public function setServiceLocator(ContainerInterface $serviceLocator) + { + $this->serviceLocator = $serviceLocator; + + return $this; + } + + /** + * Get service locator. + * + * @return ContainerInterface + */ + public function getServiceLocator() + { + return $this->serviceLocator; + } } diff --git a/src/ZfcDatagrid/Filter.php b/src/ZfcDatagrid/Filter.php index 6c353dbd..2f74d88f 100644 --- a/src/ZfcDatagrid/Filter.php +++ b/src/ZfcDatagrid/Filter.php @@ -1,4 +1,5 @@ %s'; /** - * * @var Column\AbstractColumn */ private $column; @@ -67,7 +67,7 @@ class Filter private $displayColumnValue; /** - * Apply a filter based on a column + * Apply a filter based on a column. * * @param Column\AbstractColumn $column * @param string $inputFilterValue @@ -79,14 +79,15 @@ public function setFromColumn(Column\AbstractColumn $column, $inputFilterValue) } /** - * Convert the input filter to operator + filter + display filter value + * Convert the input filter to operator + filter + display filter value. * * Partly idea taken from ZfDatagrid * * @see https://github.com/zfdatagrid/grid/blob/master/library/Bvb/Grid.php#L1438 * - * @param string $inputFilterValue - * @param mixed $defaultOperator + * @param string $inputFilterValue + * @param mixed $defaultOperator + * * @return array */ private function setColumnOperator($inputFilterValue, $defaultOperator = self::LIKE) @@ -97,23 +98,23 @@ private function setColumnOperator($inputFilterValue, $defaultOperator = self::L $this->displayColumnValue = $inputFilterValue; $operator = $defaultOperator; - $value = $inputFilterValue; + $value = $inputFilterValue; if (substr($inputFilterValue, 0, 2) == '=(') { $operator = self::IN; - $value = substr($inputFilterValue, 2); + $value = substr($inputFilterValue, 2); if (substr($value, -1) == ')') { $value = substr($value, 0, -1); } } elseif (substr($inputFilterValue, 0, 3) == '!=(') { $operator = self::NOT_IN; - $value = substr($inputFilterValue, 3); + $value = substr($inputFilterValue, 3); if (substr($value, -1) == ')') { $value = substr($value, 0, -1); } } elseif (substr($inputFilterValue, 0, 2) == '!=' || substr($inputFilterValue, 0, 2) == '<>') { $operator = self::NOT_EQUAL; - $value = substr($inputFilterValue, 2); + $value = substr($inputFilterValue, 2); } elseif (substr($inputFilterValue, 0, 2) == '!~' || substr($inputFilterValue, 0, 1) == '!') { // NOT LIKE or NOT EQUAL if (substr($inputFilterValue, 0, 2) == '!~') { @@ -126,14 +127,14 @@ private function setColumnOperator($inputFilterValue, $defaultOperator = self::L // NOT LIKE if ((substr($value, 0, 1) == '*' && substr($value, -1) == '*') || (substr($value, 0, 1) == '%' && substr($value, -1) == '%')) { $operator = self::NOT_LIKE; - $value = substr($value, 1); - $value = substr($value, 0, -1); + $value = substr($value, 1); + $value = substr($value, 0, -1); } elseif (substr($value, 0, 1) == '*' || substr($value, 0, 1) == '%') { $operator = self::NOT_LIKE_LEFT; - $value = substr($value, 1); + $value = substr($value, 1); } elseif (substr($value, -1) == '*' || substr($value, -1) == '%') { $operator = self::NOT_LIKE_RIGHT; - $value = substr($value, 0, -1); + $value = substr($value, 0, -1); } else { $operator = self::NOT_LIKE; } @@ -150,38 +151,38 @@ private function setColumnOperator($inputFilterValue, $defaultOperator = self::L if ((substr($value, 0, 1) == '*' && substr($value, -1) == '*') || (substr($value, 0, 1) == '%' && substr($value, -1) == '%')) { $operator = self::LIKE; - $value = substr($value, 1); - $value = substr($value, 0, -1); + $value = substr($value, 1); + $value = substr($value, 0, -1); } elseif (substr($value, 0, 1) == '*' || substr($value, 0, 1) == '%') { $operator = self::LIKE_LEFT; - $value = substr($value, 1); + $value = substr($value, 1); } elseif (substr($value, -1) == '*' || substr($value, -1) == '%') { $operator = self::LIKE_RIGHT; - $value = substr($value, 0, -1); + $value = substr($value, 0, -1); } else { $operator = self::LIKE; } } elseif (substr($inputFilterValue, 0, 2) == '==') { $operator = self::EQUAL; - $value = substr($inputFilterValue, 2); + $value = substr($inputFilterValue, 2); } elseif (substr($inputFilterValue, 0, 1) == '=') { $operator = self::EQUAL; - $value = substr($inputFilterValue, 1); + $value = substr($inputFilterValue, 1); } elseif (substr($inputFilterValue, 0, 2) == '>=') { $operator = self::GREATER_EQUAL; - $value = substr($inputFilterValue, 2); + $value = substr($inputFilterValue, 2); } elseif (substr($inputFilterValue, 0, 1) == '>') { $operator = self::GREATER; - $value = substr($inputFilterValue, 1); + $value = substr($inputFilterValue, 1); } elseif (substr($inputFilterValue, 0, 2) == '<=') { $operator = self::LESS_EQUAL; - $value = substr($inputFilterValue, 2); + $value = substr($inputFilterValue, 2); } elseif (substr($inputFilterValue, 0, 1) == '<') { $operator = self::LESS; - $value = substr($inputFilterValue, 1); + $value = substr($inputFilterValue, 1); } elseif (strpos($inputFilterValue, '<>') !== false) { $operator = self::BETWEEN; - $value = explode('<>', $inputFilterValue); + $value = explode('<>', $inputFilterValue); } $this->operator = $operator; @@ -220,7 +221,7 @@ private function setColumnOperator($inputFilterValue, $defaultOperator = self::L */ foreach ($value as &$val) { $type = $this->getColumn()->getType(); - $val = $type->getFilterValue($val); + $val = $type->getFilterValue($val); // @TODO Translation + Replace } @@ -229,9 +230,9 @@ private function setColumnOperator($inputFilterValue, $defaultOperator = self::L } /** - * Is this a column filter + * Is this a column filter. * - * @return boolean + * @return bool */ public function isColumnFilter() { @@ -243,7 +244,7 @@ public function isColumnFilter() } /** - * Only needed for column filter + * Only needed for column filter. * * @return Column\AbstractColumn */ @@ -253,7 +254,6 @@ public function getColumn() } /** - * * @return array */ public function getValues() @@ -262,7 +262,6 @@ public function getValues() } /** - * * @return string */ public function getOperator() @@ -271,7 +270,7 @@ public function getOperator() } /** - * Get the value displayed to the user + * Get the value displayed to the user. * * @return string */ @@ -281,7 +280,7 @@ public function getDisplayColumnValue() } /** - * Check if a value is the same (used for style, display actions) + * Check if a value is the same (used for style, display actions). * * @param mixed $currentValue * rowValue @@ -289,98 +288,98 @@ public function getDisplayColumnValue() * filterValue * @param string $operator * - * @return boolean + * @return bool */ - public static function isApply($currentValue, $expectedValue, $operator = Filter::EQUAL) + public static function isApply($currentValue, $expectedValue, $operator = self::EQUAL) { list($currentValue, $expectedValue) = self::convertValues($currentValue, $expectedValue, $operator); switch ($operator) { - case Filter::LIKE: + case self::LIKE: if (stripos($currentValue, $expectedValue) !== false) { return true; } break; - case Filter::LIKE_LEFT: - $length = strlen($expectedValue); - $start = 0 - $length; + case self::LIKE_LEFT: + $length = strlen($expectedValue); + $start = 0 - $length; $searchedValue = substr($currentValue, $start, $length); if (stripos($searchedValue, $expectedValue) !== false) { return true; } break; - case Filter::LIKE_RIGHT: - $length = strlen($expectedValue); + case self::LIKE_RIGHT: + $length = strlen($expectedValue); $searchedValue = substr($currentValue, 0, $length); if (stripos($searchedValue, $expectedValue) !== false) { return true; } break; - case Filter::NOT_LIKE: + case self::NOT_LIKE: if (stripos($currentValue, $expectedValue) === false) { return true; } break; - case Filter::NOT_LIKE_LEFT: - $length = strlen($expectedValue); - $start = 0 - $length; + case self::NOT_LIKE_LEFT: + $length = strlen($expectedValue); + $start = 0 - $length; $searchedValue = substr($currentValue, $start, $length); if (stripos($searchedValue, $expectedValue) === false) { return true; } break; - case Filter::NOT_LIKE_RIGHT: - $length = strlen($expectedValue); + case self::NOT_LIKE_RIGHT: + $length = strlen($expectedValue); $searchedValue = substr($currentValue, 0, $length); if (stripos($searchedValue, $expectedValue) === false) { return true; } break; - case Filter::EQUAL: - case Filter::IN: + case self::EQUAL: + case self::IN: return $currentValue == $expectedValue; break; - case Filter::NOT_EQUAL: - case Filter::NOT_IN: + case self::NOT_EQUAL: + case self::NOT_IN: return $currentValue != $expectedValue; break; - case Filter::GREATER_EQUAL: + case self::GREATER_EQUAL: return $currentValue >= $expectedValue; break; - case Filter::GREATER: + case self::GREATER: return $currentValue > $expectedValue; break; - case Filter::LESS_EQUAL: + case self::LESS_EQUAL: return $currentValue <= $expectedValue; break; - case Filter::LESS: + case self::LESS: return $currentValue < $expectedValue; break; - case Filter::BETWEEN: + case self::BETWEEN: if (count($expectedValue) >= 2) { if ($currentValue >= $expectedValue[0] && $currentValue <= $expectedValue[1]) { return true; } } else { - throw new InvalidArgumentException('Between needs exactly an array of two expected values. Give: "' . print_r($expectedValue, true)); + throw new InvalidArgumentException('Between needs exactly an array of two expected values. Give: "'.print_r($expectedValue, true)); } break; default: - throw new InvalidArgumentException('currently not implemented filter type: "' . $operator . '"'); + throw new InvalidArgumentException('currently not implemented filter type: "'.$operator.'"'); break; } @@ -388,23 +387,23 @@ public static function isApply($currentValue, $expectedValue, $operator = Filter } /** + * @param string $currentValue + * @param string $expectedValue + * @param string $operator * - * @param string $currentValue - * @param string $expectedValue - * @param string $operator * @return string[] */ - private static function convertValues($currentValue, $expectedValue, $operator = Filter::EQUAL) + private static function convertValues($currentValue, $expectedValue, $operator = self::EQUAL) { switch ($operator) { - case Filter::LIKE: - case Filter::LIKE_LEFT: - case Filter::LIKE_RIGHT: - case Filter::NOT_LIKE: - case Filter::NOT_LIKE_LEFT: - case Filter::NOT_LIKE_RIGHT: - $currentValue = (string) $currentValue; + case self::LIKE: + case self::LIKE_LEFT: + case self::LIKE_RIGHT: + case self::NOT_LIKE: + case self::NOT_LIKE_LEFT: + case self::NOT_LIKE_RIGHT: + $currentValue = (string) $currentValue; $expectedValue = (string) $expectedValue; break; } diff --git a/src/ZfcDatagrid/Library/ImageResize.php b/src/ZfcDatagrid/Library/ImageResize.php index eecc6d70..44439475 100644 --- a/src/ZfcDatagrid/Library/ImageResize.php +++ b/src/ZfcDatagrid/Library/ImageResize.php @@ -1,29 +1,31 @@ getUniqueId()] = $dataPopulation->toString(); } - if (! isset($row[$col->getUniqueId()])) { + if (!isset($row[$col->getUniqueId()])) { $row[$col->getUniqueId()] = ''; } diff --git a/src/ZfcDatagrid/Renderer/AbstractExport.php b/src/ZfcDatagrid/Renderer/AbstractExport.php index 7d5f03ae..72ace753 100644 --- a/src/ZfcDatagrid/Renderer/AbstractExport.php +++ b/src/ZfcDatagrid/Renderer/AbstractExport.php @@ -1,7 +1,6 @@ getColumns() as $column) { /* @var $column \ZfcDatagrid\Column\AbstractColumn */ - if (! $column instanceof Column\Action && $column->isHidden() === false && in_array(get_class($column->getType()), $this->allowedColumnTypes)) { + if (!$column instanceof Column\Action && $column->isHidden() === false && in_array(get_class($column->getType()), $this->allowedColumnTypes)) { $columnsToExport[] = $column; } } @@ -56,16 +54,17 @@ protected function getColumnsToExport() } /** - * Get the paper width in MM (milimeter) + * Get the paper width in MM (milimeter). * * @return float + * * @throws \Exception */ protected function getPaperWidth() { $optionsRenderer = $this->getOptionsRenderer(); - $papersize = $optionsRenderer['papersize']; + $papersize = $optionsRenderer['papersize']; $orientation = $optionsRenderer['orientation']; if (substr($papersize, 0, 1) != 'A') { @@ -78,7 +77,7 @@ protected function getPaperWidth() // A0 dimensions = 841 x 1189 mm $currentX = 841; $currentY = 1189; - for ($i = 0; $i < $divisor; $i ++) { + for ($i = 0; $i < $divisor; ++$i) { $tempY = $currentX; $tempX = floor($currentY / 2); @@ -95,20 +94,20 @@ protected function getPaperWidth() /** * Get a valid filename to save - * (WITHOUT the extension!) + * (WITHOUT the extension!). * * @return string */ protected function getFilename() { - $filenameParts = []; + $filenameParts = []; $filenameParts[] = date('Y-m-d_H-i-s'); if ($this->getTitle() != '') { $title = $this->getTitle(); $title = str_replace(' ', '_', $title); - $filenameParts[] = preg_replace("/[^a-z0-9_-]+/i", "", $title); + $filenameParts[] = preg_replace('/[^a-z0-9_-]+/i', '', $title); } return implode('_', $filenameParts); diff --git a/src/ZfcDatagrid/Renderer/AbstractRenderer.php b/src/ZfcDatagrid/Renderer/AbstractRenderer.php index f34bb92c..82b34e7d 100644 --- a/src/ZfcDatagrid/Renderer/AbstractRenderer.php +++ b/src/ZfcDatagrid/Renderer/AbstractRenderer.php @@ -1,4 +1,5 @@ getName() . '/' . $type; + return 'zfc-datagrid/renderer/'.$this->getName().'/'.$type; } elseif ('toolbar' === $type) { return 'zfc-datagrid/toolbar/toolbar'; } - throw new \Exception('Unknown type: "' . $type . '"'); + throw new \Exception('Unknown type: "'.$type.'"'); } /** - * Set the toolbar view template name + * Set the toolbar view template name. * * @param string $name */ @@ -214,6 +201,7 @@ public function setToolbarTemplate($name) /** * @return string + * * @throws \Exception */ public function getToolbarTemplate() @@ -226,7 +214,7 @@ public function getToolbarTemplate() } /** - * Set the toolbar view template variables + * Set the toolbar view template variables. * * @param array $variables */ @@ -236,7 +224,7 @@ public function setToolbarTemplateVariables(array $variables) } /** - * Get the toolbar template variables + * Get the toolbar template variables. * * @return array */ @@ -257,7 +245,6 @@ public function setPaginator(Paginator $paginator) } /** - * * @return \Zend\Paginator\Paginator */ public function getPaginator() @@ -266,7 +253,7 @@ public function getPaginator() } /** - * Set the columns + * Set the columns. * * @param array $columns */ @@ -276,7 +263,7 @@ public function setColumns(array $columns) } /** - * Get all columns + * Get all columns. * * @return \ZfcDatagrid\Column\AbstractColumn[] */ @@ -286,7 +273,6 @@ public function getColumns() } /** - * * @param \ZfcDataGrid\Column\Style\AbstractStyle[] $rowStyles */ public function setRowStyles($rowStyles = []) @@ -295,7 +281,6 @@ public function setRowStyles($rowStyles = []) } /** - * * @return \ZfcDataGrid\Column\Style\AbstractStyle[] */ public function getRowStyles() @@ -304,7 +289,7 @@ public function getRowStyles() } /** - * Calculate the sum of the displayed column width to 100% + * Calculate the sum of the displayed column width to 100%. * * @param array $columns */ @@ -327,7 +312,7 @@ protected function calculateColumnWidthPercent(array $columns) } /** - * The prepared data + * The prepared data. * * @param array $data */ @@ -337,7 +322,6 @@ public function setData(array $data) } /** - * * @return array */ public function getData() @@ -346,7 +330,6 @@ public function getData() } /** - * * @return array */ public function getCacheData() @@ -355,14 +338,14 @@ public function getCacheData() } /** - * * @throws \Exception + * * @return array|false */ private function getCacheSortConditions() { $cacheData = $this->getCacheData(); - if (! isset($cacheData['sortConditions'])) { + if (!isset($cacheData['sortConditions'])) { return false; } @@ -370,14 +353,14 @@ private function getCacheSortConditions() } /** - * * @throws \Exception + * * @return array|false */ private function getCacheFilters() { $cacheData = $this->getCacheData(); - if (! isset($cacheData['filters'])) { + if (!isset($cacheData['filters'])) { return false; } @@ -405,7 +388,6 @@ public function getMvcEvent() } /** - * * @return \Zend\Stdlib\RequestInterface */ public function getRequest() @@ -414,13 +396,13 @@ public function getRequest() } /** + * @param Translator $translator * - * @param Translator $translator * @throws \InvalidArgumentException */ public function setTranslator($translator) { - if (! $translator instanceof Translator && ! $translator instanceof \Zend\I18n\Translator\TranslatorInterface) { + if (!$translator instanceof Translator && !$translator instanceof \Zend\I18n\Translator\TranslatorInterface) { throw new \InvalidArgumentException('Translator must be an instanceof "Zend\I18n\Translator\Translator" or "Zend\I18n\Translator\TranslatorInterface"'); } @@ -428,7 +410,6 @@ public function setTranslator($translator) } /** - * * @return \Zend\I18n\Translator\Translator */ public function getTranslator() @@ -438,6 +419,7 @@ public function getTranslator() /** * @param $string + * * @return string */ public function translate($string) @@ -446,7 +428,7 @@ public function translate($string) } /** - * Set the title + * Set the title. * * @param string $title */ @@ -456,7 +438,6 @@ public function setTitle($title) } /** - * * @return string */ public function getTitle() @@ -473,7 +454,6 @@ public function setCache(Cache\Storage\StorageInterface $cache) } /** - * * @return Cache\Storage\StorageInterface */ public function getCache() @@ -482,7 +462,6 @@ public function getCache() } /** - * * @param string $cacheId */ public function setCacheId($cacheId) @@ -491,7 +470,6 @@ public function setCacheId($cacheId) } /** - * * @return string */ public function getCacheId() @@ -501,18 +479,18 @@ public function getCacheId() /** * Set the sort conditions explicit (e.g. - * from a custom form) + * from a custom form). * * @param array $sortConditions */ public function setSortConditions(array $sortConditions) { foreach ($sortConditions as $sortCondition) { - if (! is_array($sortCondition)) { + if (!is_array($sortCondition)) { throw new InvalidArgumentException('Sort condition have to be an array'); } - if (! array_key_exists('column', $sortCondition)) { + if (!array_key_exists('column', $sortCondition)) { throw new InvalidArgumentException('Sort condition missing array key column'); } } @@ -521,7 +499,6 @@ public function setSortConditions(array $sortConditions) } /** - * * @return array */ public function getSortConditions() @@ -543,7 +520,7 @@ public function getSortConditions() } /** - * Get the default sort conditions defined for the columns + * Get the default sort conditions defined for the columns. * * @return array */ @@ -556,7 +533,7 @@ public function getSortConditionsDefault() $sortDefaults = $column->getSortDefault(); $sortConditions[$sortDefaults['priority']] = [ - 'column' => $column, + 'column' => $column, 'sortDirection' => $sortDefaults['sortDirection'], ]; @@ -571,14 +548,14 @@ public function getSortConditionsDefault() /** * Set filters explicit (e.g. - * from a custom form) + * from a custom form). * * @param array $filters */ public function setFilters(array $filters) { foreach ($filters as $filter) { - if (! $filter instanceof Filter) { + if (!$filter instanceof Filter) { throw new InvalidArgumentException('Filter have to be an instanceof ZfcDatagrid\Filter'); } } @@ -587,7 +564,6 @@ public function setFilters(array $filters) } /** - * * @return Filter[] */ public function getFilters() @@ -609,7 +585,7 @@ public function getFilters() } /** - * Get the default filter conditions defined for the columns + * Get the default filter conditions defined for the columns. * * @return Filter[] */ @@ -632,9 +608,9 @@ public function getFiltersDefault() } /** - * Set the current page number + * Set the current page number. * - * @param integer $page + * @param int $page */ public function setCurrentPageNumber($page) { @@ -642,9 +618,9 @@ public function setCurrentPageNumber($page) } /** - * Should be implemented for each renderer itself (just default) + * Should be implemented for each renderer itself (just default). * - * @return integer + * @return int */ public function getCurrentPageNumber() { @@ -656,14 +632,14 @@ public function getCurrentPageNumber() } /** - * Should be implemented for each renderer itself (just default) + * Should be implemented for each renderer itself (just default). * - * @return integer + * @return int */ public function getItemsPerPage($defaultItems = 25) { if ($this->isExport() === true) { - return (int) - 1; + return (int) -1; } return $defaultItems; @@ -691,7 +667,7 @@ public function prepareViewModel(Datagrid $grid) } $viewModel->setVariable('rendererName', $this->getName()); - $options = $this->getOptions(); + $options = $this->getOptions(); $generalParameterNames = $options['generalParameterNames']; $viewModel->setVariable('generalParameterNames', $generalParameterNames); @@ -717,17 +693,17 @@ public function prepareViewModel(Datagrid $grid) $parameterNames = $optionsRenderer['parameterNames']; $viewModel->setVariable('parameterNames', $parameterNames); - $activeParameters = []; + $activeParameters = []; $activeParameters[$parameterNames['currentPage']] = $this->getCurrentPageNumber(); { - $sortColumns = []; + $sortColumns = []; $sortDirections = []; foreach ($this->getSortConditions() as $sortCondition) { - $sortColumns[] = $sortCondition['column']->getUniqueId(); + $sortColumns[] = $sortCondition['column']->getUniqueId(); $sortDirections[] = $sortCondition['sortDirection']; } - $activeParameters[$parameterNames['sortColumns']] = implode(',', $sortColumns); + $activeParameters[$parameterNames['sortColumns']] = implode(',', $sortColumns); $activeParameters[$parameterNames['sortDirections']] = implode(',', $sortDirections); } $viewModel->setVariable('activeParameters', $activeParameters); @@ -737,27 +713,31 @@ public function prepareViewModel(Datagrid $grid) } /** - * Return the name of the renderer + * Return the name of the renderer. + * * @return string */ abstract public function getName(); /** - * Determine if the renderer is for export - * @return boolean + * Determine if the renderer is for export. + * + * @return bool */ abstract public function isExport(); /** * Determin if the renderer is HTML * It can be export + html -> f.x. - * printing for HTML - * @return boolean + * printing for HTML. + * + * @return bool */ abstract public function isHtml(); /** * Execute all... + * * @return ViewModel Response\Stream */ abstract public function execute(); diff --git a/src/ZfcDatagrid/Renderer/BootstrapTable/Renderer.php b/src/ZfcDatagrid/Renderer/BootstrapTable/Renderer.php index 6aa1e25d..92cc808c 100644 --- a/src/ZfcDatagrid/Renderer/BootstrapTable/Renderer.php +++ b/src/ZfcDatagrid/Renderer/BootstrapTable/Renderer.php @@ -1,4 +1,5 @@ getRequest(); $optionsRenderer = $this->getOptionsRenderer(); - $parameterNames = $optionsRenderer['parameterNames']; + $parameterNames = $optionsRenderer['parameterNames']; $sortConditions = []; - $sortColumns = $request->getPost($parameterNames['sortColumns'], $request->getQuery($parameterNames['sortColumns'])); + $sortColumns = $request->getPost($parameterNames['sortColumns'], $request->getQuery($parameterNames['sortColumns'])); $sortDirections = $request->getPost($parameterNames['sortDirections'], $request->getQuery($parameterNames['sortDirections'])); if ($sortColumns != '') { - $sortColumns = explode(',', $sortColumns); + $sortColumns = explode(',', $sortColumns); $sortDirections = explode(',', $sortDirections); if (count($sortColumns) != count($sortDirections)) { @@ -88,7 +89,7 @@ public function getSortConditions() if ($column->getUniqueId() == $sortColumn) { $sortConditions[] = [ 'sortDirection' => $sortDirection, - 'column' => $column, + 'column' => $column, ]; $column->setSortActive($sortDirection); @@ -108,7 +109,6 @@ public function getSortConditions() } /** - * * @todo Make parameter config * * @see \ZfcDatagrid\Renderer\AbstractRenderer::getFilters() @@ -152,12 +152,13 @@ public function getFilters() /** * @return int + * * @throws \Exception */ public function getCurrentPageNumber() { $optionsRenderer = $this->getOptionsRenderer(); - $parameterNames = $optionsRenderer['parameterNames']; + $parameterNames = $optionsRenderer['parameterNames']; $request = $this->getRequest(); if ($request instanceof HttpRequest) { diff --git a/src/ZfcDatagrid/Renderer/BootstrapTable/View/Helper/TableRow.php b/src/ZfcDatagrid/Renderer/BootstrapTable/View/Helper/TableRow.php index 3e96acf1..678f3658 100644 --- a/src/ZfcDatagrid/Renderer/BootstrapTable/View/Helper/TableRow.php +++ b/src/ZfcDatagrid/Renderer/BootstrapTable/View/Helper/TableRow.php @@ -1,4 +1,5 @@ '; } else { if (isset($row['idConcated'])) { - return '
' . print_r($value, true) . ''; + $value = '
'.print_r($value, true).''; break; } @@ -130,19 +135,19 @@ public function __invoke($row, array $cols, AbstractAction $rowClickAction = nul break; case 'ZfcDatagrid\Column\Style\Color': - $cssStyles[] = 'color: #' . $style->getRgbHexString(); + $cssStyles[] = 'color: #'.$style->getRgbHexString(); break; case 'ZfcDatagrid\Column\Style\BackgroundColor': - $cssStyles[] = 'background-color: #' . $style->getRgbHexString(); + $cssStyles[] = 'background-color: #'.$style->getRgbHexString(); break; case 'ZfcDatagrid\Column\Style\Align': - $cssStyles[] = 'text-align: ' . $style->getAlignment(); + $cssStyles[] = 'text-align: '.$style->getAlignment(); break; case 'ZfcDatagrid\Column\Style\Strikethrough': - $value = '