Skip to content

Commit

Permalink
1. DataStore: Change clone() function name to makeCopy() to avo…
Browse files Browse the repository at this point in the history
…id reserved keywords `clone` in PHP 5.x
  • Loading branch information
dongnl committed Feb 15, 2019
1 parent d56917a commit 1ffa6c4
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 100 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Version 3.25.4

1. `DataStore`: Change `clone()` function name to `makeCopy()` to avoid reserved keywords `clone` in PHP 5.x
2. `Table`: Avoid duplication of `groupLevel()` function

## Version 3.25.3

Expand Down
199 changes: 99 additions & 100 deletions src/widgets/koolphp/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,104 @@ public static function formatValue($value, $format, $row = null)
}
}

/**
* Group the level
*
* @param array $meta The metadata
* @param array $groupModel The group model
* @param array $store The store
* @param array $result The previous result
* @param array $level The level
* @param array $start The starting position
* @param array $previousParams The previous parameters
*
* @return array Result
*/
static function groupLevel(
$meta,
$groupModel,
$store,
&$result,
$level = 0,
$start = 0,
$previousParams = array()
) {
$keys = array_keys($groupModel);
$store->breakGroup(
$keys[$level],
function ($store, $localStart) use ($meta, $groupModel, &$result, $keys, $level, $start, $previousParams) {
$by = $keys[$level];
$agroup = array_merge(
$previousParams,
array(
"{" . $by . "}" => $store->get(0, $by),
"{count}" => $store->count(),
)
);
$previousParams["{" . $by . "}"] = $agroup["{" . $by . "}"];
$calculate = Utility::get($groupModel[$by], "calculate", array());
$css = Utility::get($groupModel[$by], "css");
$cssClass = Utility::get($groupModel[$by], "cssClass");
foreach ($calculate as $paramName => $def) {
if (is_array($def)) {
$method = strtolower($def[0]);
if (in_array($method, array("sum", "count", "min", "max", "mode"))) {
$agroup[$paramName] = Table::formatValue($store->$method($def[1]), $meta["columns"][$def[1]]);
}

} else if (is_callable($def)) {
$agroup[$paramName] = $def($store);
}
}
$startTemplate = Utility::get($groupModel[$by], "top");
$endTemplate = Utility::get($groupModel[$by], "bottom");

if ($startTemplate) {
if (!isset($result[$start + $localStart])) {
$result[$start + $localStart] = array();
}
$item = array(
$start + $localStart,
$start + $localStart + $agroup["{count}"],
is_string($startTemplate) ? Utility::strReplace($startTemplate, $agroup) :
(is_callable($startTemplate) ? $startTemplate($agroup) : $startTemplate),
null, null,
);
if ($css) {
$item[3] = gettype($css) == "string" ? $css : $css($agroup);
}
if ($cssClass) {
$item[4] = gettype($cssClass) == "string" ? $cssClass : $cssClass($agroup);
}
array_push($result[$start + $localStart], $item);
}
if ($endTemplate) {
if (!isset($result[$start + $localStart + $agroup["{count}"]])) {
$result[$start + $localStart + $agroup["{count}"]] = array();
}

$item = array(
$start + $localStart,
$start + $localStart + $agroup["{count}"],
is_string($endTemplate) ? Utility::strReplace($endTemplate, $agroup) :
(is_callable($endTemplate) ? $endTemplate($agroup) : $endTemplate),
null, null,
);
if ($css) {
$item[3] = gettype($css) == "string" ? $css : $css($agroup);
}
if ($cssClass) {
$item[4] = gettype($cssClass) == "string" ? $cssClass : $cssClass($agroup);
}
array_unshift($result[$start + $localStart + $agroup["{count}"]], $item);
}
if ($level < count($keys) - 1) {
Table::groupLevel($meta, $groupModel, $store, $result, $level + 1, $start + $localStart, $previousParams);
}
}
);
}

/**
* Generate groups for table grouping
*
Expand All @@ -205,112 +303,13 @@ protected function generateGroups($meta)
{
if ($this->group) {
$result = array();

$sorts = array();
foreach ($this->group as $by => $settings) {
$sorts[$by] = Utility::get($settings, "sort", "asc");
}
$sorts = array_merge($sorts, $this->sorting);
$this->dataStore->sort($sorts);

/**
* Group the level
*
* @param array $meta The metadata
* @param array $groupModel The group model
* @param array $store The store
* @param array $result The previous result
* @param array $level The level
* @param array $start The starting position
* @param array $previousParams The previous parameters
*
* @return array Result
*/
function groupLevel(
$meta,
$groupModel,
$store,
&$result,
$level = 0,
$start = 0,
$previousParams = array()
) {
$keys = array_keys($groupModel);
$store->breakGroup(
$keys[$level],
function ($store, $localStart) use ($meta, $groupModel, &$result, $keys, $level, $start, $previousParams) {
$by = $keys[$level];
$agroup = array_merge(
$previousParams,
array(
"{" . $by . "}" => $store->get(0, $by),
"{count}" => $store->count(),
)
);
$previousParams["{" . $by . "}"] = $agroup["{" . $by . "}"];
$calculate = Utility::get($groupModel[$by], "calculate", array());
$css = Utility::get($groupModel[$by], "css");
$cssClass = Utility::get($groupModel[$by], "cssClass");
foreach ($calculate as $paramName => $def) {
if (is_array($def)) {
$method = strtolower($def[0]);
if (in_array($method, array("sum", "count", "min", "max", "mode"))) {
$agroup[$paramName] = Table::formatValue($store->$method($def[1]), $meta["columns"][$def[1]]);
}

} else if (is_callable($def)) {
$agroup[$paramName] = $def($store);
}
}
$startTemplate = Utility::get($groupModel[$by], "top");
$endTemplate = Utility::get($groupModel[$by], "bottom");

if ($startTemplate) {
if (!isset($result[$start + $localStart])) {
$result[$start + $localStart] = array();
}
$item = array(
$start + $localStart,
$start + $localStart + $agroup["{count}"],
is_string($startTemplate) ? Utility::strReplace($startTemplate, $agroup) :
(is_callable($startTemplate) ? $startTemplate($agroup) : $startTemplate),
null, null,
);
if ($css) {
$item[3] = gettype($css) == "string" ? $css : $css($agroup);
}
if ($cssClass) {
$item[4] = gettype($cssClass) == "string" ? $cssClass : $cssClass($agroup);
}
array_push($result[$start + $localStart], $item);
}
if ($endTemplate) {
if (!isset($result[$start + $localStart + $agroup["{count}"]])) {
$result[$start + $localStart + $agroup["{count}"]] = array();
}

$item = array(
$start + $localStart,
$start + $localStart + $agroup["{count}"],
is_string($endTemplate) ? Utility::strReplace($endTemplate, $agroup) :
(is_callable($endTemplate) ? $endTemplate($agroup) : $endTemplate),
null, null,
);
if ($css) {
$item[3] = gettype($css) == "string" ? $css : $css($agroup);
}
if ($cssClass) {
$item[4] = gettype($cssClass) == "string" ? $cssClass : $cssClass($agroup);
}
array_unshift($result[$start + $localStart + $agroup["{count}"]], $item);
}
if ($level < count($keys) - 1) {
groupLevel($meta, $groupModel, $store, $result, $level + 1, $start + $localStart, $previousParams);
}
}
);
}
groupLevel($meta, $this->group, $this->dataStore, $result);
Table::groupLevel($meta, $this->group, $this->dataStore, $result);
return $result;
}
return false;
Expand Down

0 comments on commit 1ffa6c4

Please sign in to comment.