repository_name
stringlengths
5
67
func_path_in_repository
stringlengths
4
234
func_name
stringlengths
0
314
whole_func_string
stringlengths
52
3.87M
language
stringclasses
6 values
func_code_string
stringlengths
52
3.87M
func_code_tokens
listlengths
15
672k
func_documentation_string
stringlengths
1
47.2k
func_documentation_tokens
listlengths
1
3.92k
split_name
stringclasses
1 value
func_code_url
stringlengths
85
339
koolphp/koolreport
src/processes/ValueMap.php
ValueMap.onInit
protected function onInit() { if (is_array($this->params)) { foreach ($this->params as $cName => $cMap) { $cFunc = Utility::get($cMap, "{func}"); if (is_callable($cFunc)) { $this->mapFuncs[$cName] = $cFunc; } } } }
php
protected function onInit() { if (is_array($this->params)) { foreach ($this->params as $cName => $cMap) { $cFunc = Utility::get($cMap, "{func}"); if (is_callable($cFunc)) { $this->mapFuncs[$cName] = $cFunc; } } } }
[ "protected", "function", "onInit", "(", ")", "{", "if", "(", "is_array", "(", "$", "this", "->", "params", ")", ")", "{", "foreach", "(", "$", "this", "->", "params", "as", "$", "cName", "=>", "$", "cMap", ")", "{", "$", "cFunc", "=", "Utility", "::", "get", "(", "$", "cMap", ",", "\"{func}\"", ")", ";", "if", "(", "is_callable", "(", "$", "cFunc", ")", ")", "{", "$", "this", "->", "mapFuncs", "[", "$", "cName", "]", "=", "$", "cFunc", ";", "}", "}", "}", "}" ]
Handle on initation @return null
[ "Handle", "on", "initation" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/processes/ValueMap.php#L56-L68
koolphp/koolreport
src/processes/ValueMap.php
ValueMap.onMetaReceived
protected function onMetaReceived($metaData) { if (is_array($this->params)) { foreach ($this->params as $cName => $cMap) { if (is_array($cMap)) { $cMeta = Utility::get($cMap, "{meta}"); if ($cMeta) { $override = Utility::get($cMeta, "{override}", false); if (isset($cMeta["{override}"])) { unset($cMeta["{override}"]); } if ($override) { $metaData["columns"][$cName] = $cMeta; } else { $metaData["columns"][$cName] = array_merge($metaData["columns"][$cName], $cMeta); } } } } } return $metaData; }
php
protected function onMetaReceived($metaData) { if (is_array($this->params)) { foreach ($this->params as $cName => $cMap) { if (is_array($cMap)) { $cMeta = Utility::get($cMap, "{meta}"); if ($cMeta) { $override = Utility::get($cMeta, "{override}", false); if (isset($cMeta["{override}"])) { unset($cMeta["{override}"]); } if ($override) { $metaData["columns"][$cName] = $cMeta; } else { $metaData["columns"][$cName] = array_merge($metaData["columns"][$cName], $cMeta); } } } } } return $metaData; }
[ "protected", "function", "onMetaReceived", "(", "$", "metaData", ")", "{", "if", "(", "is_array", "(", "$", "this", "->", "params", ")", ")", "{", "foreach", "(", "$", "this", "->", "params", "as", "$", "cName", "=>", "$", "cMap", ")", "{", "if", "(", "is_array", "(", "$", "cMap", ")", ")", "{", "$", "cMeta", "=", "Utility", "::", "get", "(", "$", "cMap", ",", "\"{meta}\"", ")", ";", "if", "(", "$", "cMeta", ")", "{", "$", "override", "=", "Utility", "::", "get", "(", "$", "cMeta", ",", "\"{override}\"", ",", "false", ")", ";", "if", "(", "isset", "(", "$", "cMeta", "[", "\"{override}\"", "]", ")", ")", "{", "unset", "(", "$", "cMeta", "[", "\"{override}\"", "]", ")", ";", "}", "if", "(", "$", "override", ")", "{", "$", "metaData", "[", "\"columns\"", "]", "[", "$", "cName", "]", "=", "$", "cMeta", ";", "}", "else", "{", "$", "metaData", "[", "\"columns\"", "]", "[", "$", "cName", "]", "=", "array_merge", "(", "$", "metaData", "[", "\"columns\"", "]", "[", "$", "cName", "]", ",", "$", "cMeta", ")", ";", "}", "}", "}", "}", "}", "return", "$", "metaData", ";", "}" ]
Handle on meta received @param array $metaData The meta data @return array New meta data
[ "Handle", "on", "meta", "received" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/processes/ValueMap.php#L77-L99
koolphp/koolreport
src/processes/ValueMap.php
ValueMap.onInput
protected function onInput($row) { if (is_array($this->params)) { foreach ($this->params as $cName => $cMap) { if (isset($this->mapFuncs[$cName])) { $row[$cName] = $this->mapFuncs[$cName]($row[$cName]); } else if (is_array($cMap)) { $row[$cName] = Utility::get($cMap, $row[$cName], $row[$cName]); } } } else if (is_callable($this->params)) { $func = $this->params; $pos = 0; foreach ($row as $cName => $value) { $row[$cName] = $func($value, $cName, $this->metaData['columns'][$cName], $pos); $pos++; } } $this->next($row); }
php
protected function onInput($row) { if (is_array($this->params)) { foreach ($this->params as $cName => $cMap) { if (isset($this->mapFuncs[$cName])) { $row[$cName] = $this->mapFuncs[$cName]($row[$cName]); } else if (is_array($cMap)) { $row[$cName] = Utility::get($cMap, $row[$cName], $row[$cName]); } } } else if (is_callable($this->params)) { $func = $this->params; $pos = 0; foreach ($row as $cName => $value) { $row[$cName] = $func($value, $cName, $this->metaData['columns'][$cName], $pos); $pos++; } } $this->next($row); }
[ "protected", "function", "onInput", "(", "$", "row", ")", "{", "if", "(", "is_array", "(", "$", "this", "->", "params", ")", ")", "{", "foreach", "(", "$", "this", "->", "params", "as", "$", "cName", "=>", "$", "cMap", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "mapFuncs", "[", "$", "cName", "]", ")", ")", "{", "$", "row", "[", "$", "cName", "]", "=", "$", "this", "->", "mapFuncs", "[", "$", "cName", "]", "(", "$", "row", "[", "$", "cName", "]", ")", ";", "}", "else", "if", "(", "is_array", "(", "$", "cMap", ")", ")", "{", "$", "row", "[", "$", "cName", "]", "=", "Utility", "::", "get", "(", "$", "cMap", ",", "$", "row", "[", "$", "cName", "]", ",", "$", "row", "[", "$", "cName", "]", ")", ";", "}", "}", "}", "else", "if", "(", "is_callable", "(", "$", "this", "->", "params", ")", ")", "{", "$", "func", "=", "$", "this", "->", "params", ";", "$", "pos", "=", "0", ";", "foreach", "(", "$", "row", "as", "$", "cName", "=>", "$", "value", ")", "{", "$", "row", "[", "$", "cName", "]", "=", "$", "func", "(", "$", "value", ",", "$", "cName", ",", "$", "this", "->", "metaData", "[", "'columns'", "]", "[", "$", "cName", "]", ",", "$", "pos", ")", ";", "$", "pos", "++", ";", "}", "}", "$", "this", "->", "next", "(", "$", "row", ")", ";", "}" ]
Handle on data input @param array $row The data row @return null
[ "Handle", "on", "data", "input" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/processes/ValueMap.php#L108-L128
koolphp/koolreport
src/processes/DateTimeFormat.php
DateTimeFormat.onInit
protected function onInit() { foreach ($this->params as $cName => $cParams) { if (gettype($cParams) == "string") { $this->params[$cName] = array( "to" => $cParams, ); } } }
php
protected function onInit() { foreach ($this->params as $cName => $cParams) { if (gettype($cParams) == "string") { $this->params[$cName] = array( "to" => $cParams, ); } } }
[ "protected", "function", "onInit", "(", ")", "{", "foreach", "(", "$", "this", "->", "params", "as", "$", "cName", "=>", "$", "cParams", ")", "{", "if", "(", "gettype", "(", "$", "cParams", ")", "==", "\"string\"", ")", "{", "$", "this", "->", "params", "[", "$", "cName", "]", "=", "array", "(", "\"to\"", "=>", "$", "cParams", ",", ")", ";", "}", "}", "}" ]
Process initiation @return null
[ "Process", "initiation" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/processes/DateTimeFormat.php#L45-L54
koolphp/koolreport
src/processes/DateTimeFormat.php
DateTimeFormat.onMetaReceived
protected function onMetaReceived($metaData) { foreach ($this->params as $cName => $cParams) { $from = Utility::get($cParams, "from"); if (!$from) { $from = Utility::get( $metaData["columns"][$cName], "format", "Y-m-d H:i:s" ); } $to = Utility::get($cParams, "to", "Y-m-d H:i:s"); $this->params[$cName] = array( "from" => $from, "to" => $to, ); $metaData["columns"][$cName] = array_merge( $metaData["columns"][$cName], array( "type" => "datetime", "format" => $to, ) ); } return $metaData; }
php
protected function onMetaReceived($metaData) { foreach ($this->params as $cName => $cParams) { $from = Utility::get($cParams, "from"); if (!$from) { $from = Utility::get( $metaData["columns"][$cName], "format", "Y-m-d H:i:s" ); } $to = Utility::get($cParams, "to", "Y-m-d H:i:s"); $this->params[$cName] = array( "from" => $from, "to" => $to, ); $metaData["columns"][$cName] = array_merge( $metaData["columns"][$cName], array( "type" => "datetime", "format" => $to, ) ); } return $metaData; }
[ "protected", "function", "onMetaReceived", "(", "$", "metaData", ")", "{", "foreach", "(", "$", "this", "->", "params", "as", "$", "cName", "=>", "$", "cParams", ")", "{", "$", "from", "=", "Utility", "::", "get", "(", "$", "cParams", ",", "\"from\"", ")", ";", "if", "(", "!", "$", "from", ")", "{", "$", "from", "=", "Utility", "::", "get", "(", "$", "metaData", "[", "\"columns\"", "]", "[", "$", "cName", "]", ",", "\"format\"", ",", "\"Y-m-d H:i:s\"", ")", ";", "}", "$", "to", "=", "Utility", "::", "get", "(", "$", "cParams", ",", "\"to\"", ",", "\"Y-m-d H:i:s\"", ")", ";", "$", "this", "->", "params", "[", "$", "cName", "]", "=", "array", "(", "\"from\"", "=>", "$", "from", ",", "\"to\"", "=>", "$", "to", ",", ")", ";", "$", "metaData", "[", "\"columns\"", "]", "[", "$", "cName", "]", "=", "array_merge", "(", "$", "metaData", "[", "\"columns\"", "]", "[", "$", "cName", "]", ",", "array", "(", "\"type\"", "=>", "\"datetime\"", ",", "\"format\"", "=>", "$", "to", ",", ")", ")", ";", "}", "return", "$", "metaData", ";", "}" ]
Handle on meta received @param array $metaData The meta data @return array New meta data
[ "Handle", "on", "meta", "received" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/processes/DateTimeFormat.php#L63-L89
koolphp/koolreport
src/processes/DateTimeFormat.php
DateTimeFormat.onInput
protected function onInput($data) { //Process data here foreach ($this->params as $cName => $cParams) { $from = Utility::get($cParams, "from", "Y-m-d H:i:s"); $to = Utility::get($cParams, "to", "Y-m-d H:i:s"); if ($data[$cName] && $from != $to) { $obj = \DateTime::createFromFormat($from, $data[$cName]); $data[$cName] = ($obj) ? $obj->format($to) : null; } } $this->next($data); }
php
protected function onInput($data) { //Process data here foreach ($this->params as $cName => $cParams) { $from = Utility::get($cParams, "from", "Y-m-d H:i:s"); $to = Utility::get($cParams, "to", "Y-m-d H:i:s"); if ($data[$cName] && $from != $to) { $obj = \DateTime::createFromFormat($from, $data[$cName]); $data[$cName] = ($obj) ? $obj->format($to) : null; } } $this->next($data); }
[ "protected", "function", "onInput", "(", "$", "data", ")", "{", "//Process data here", "foreach", "(", "$", "this", "->", "params", "as", "$", "cName", "=>", "$", "cParams", ")", "{", "$", "from", "=", "Utility", "::", "get", "(", "$", "cParams", ",", "\"from\"", ",", "\"Y-m-d H:i:s\"", ")", ";", "$", "to", "=", "Utility", "::", "get", "(", "$", "cParams", ",", "\"to\"", ",", "\"Y-m-d H:i:s\"", ")", ";", "if", "(", "$", "data", "[", "$", "cName", "]", "&&", "$", "from", "!=", "$", "to", ")", "{", "$", "obj", "=", "\\", "DateTime", "::", "createFromFormat", "(", "$", "from", ",", "$", "data", "[", "$", "cName", "]", ")", ";", "$", "data", "[", "$", "cName", "]", "=", "(", "$", "obj", ")", "?", "$", "obj", "->", "format", "(", "$", "to", ")", ":", "null", ";", "}", "}", "$", "this", "->", "next", "(", "$", "data", ")", ";", "}" ]
Handle on data input @param array $data The input data row @return null
[ "Handle", "on", "data", "input" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/processes/DateTimeFormat.php#L98-L110
koolphp/koolreport
src/processes/Join.php
Join.input
public function input($row, $source) { for ($i = 0; $i < count($this->container); $i++) { if ($this->container[$i]["source"] === $source) { $key = ""; foreach ($this->container[$i]["keys"] as $cName) { $key .= $row[$cName]; } if (!isset($this->container[$i]['data'][$key])) { $this->container[$i]['data'][$key] = array($row); } else { array_push($this->container[$i]['data'][$key], $row); } break; } } }
php
public function input($row, $source) { for ($i = 0; $i < count($this->container); $i++) { if ($this->container[$i]["source"] === $source) { $key = ""; foreach ($this->container[$i]["keys"] as $cName) { $key .= $row[$cName]; } if (!isset($this->container[$i]['data'][$key])) { $this->container[$i]['data'][$key] = array($row); } else { array_push($this->container[$i]['data'][$key], $row); } break; } } }
[ "public", "function", "input", "(", "$", "row", ",", "$", "source", ")", "{", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "count", "(", "$", "this", "->", "container", ")", ";", "$", "i", "++", ")", "{", "if", "(", "$", "this", "->", "container", "[", "$", "i", "]", "[", "\"source\"", "]", "===", "$", "source", ")", "{", "$", "key", "=", "\"\"", ";", "foreach", "(", "$", "this", "->", "container", "[", "$", "i", "]", "[", "\"keys\"", "]", "as", "$", "cName", ")", "{", "$", "key", ".=", "$", "row", "[", "$", "cName", "]", ";", "}", "if", "(", "!", "isset", "(", "$", "this", "->", "container", "[", "$", "i", "]", "[", "'data'", "]", "[", "$", "key", "]", ")", ")", "{", "$", "this", "->", "container", "[", "$", "i", "]", "[", "'data'", "]", "[", "$", "key", "]", "=", "array", "(", "$", "row", ")", ";", "}", "else", "{", "array_push", "(", "$", "this", "->", "container", "[", "$", "i", "]", "[", "'data'", "]", "[", "$", "key", "]", ",", "$", "row", ")", ";", "}", "break", ";", "}", "}", "}" ]
Input @param array $row The input data row @param Node $source The source sending data @return null
[ "Input" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/processes/Join.php#L74-L91
koolphp/koolreport
src/processes/Join.php
Join.onInputEnd
protected function onInputEnd() { foreach ($this->container[0]["data"] as $key => $rows) { if (isset($this->container[1]["data"][$key])) { foreach ($rows as $first) { foreach ($this->container[1]["data"][$key] as $second) { $this->next(array_merge($first, $second)); } } } } }
php
protected function onInputEnd() { foreach ($this->container[0]["data"] as $key => $rows) { if (isset($this->container[1]["data"][$key])) { foreach ($rows as $first) { foreach ($this->container[1]["data"][$key] as $second) { $this->next(array_merge($first, $second)); } } } } }
[ "protected", "function", "onInputEnd", "(", ")", "{", "foreach", "(", "$", "this", "->", "container", "[", "0", "]", "[", "\"data\"", "]", "as", "$", "key", "=>", "$", "rows", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "container", "[", "1", "]", "[", "\"data\"", "]", "[", "$", "key", "]", ")", ")", "{", "foreach", "(", "$", "rows", "as", "$", "first", ")", "{", "foreach", "(", "$", "this", "->", "container", "[", "1", "]", "[", "\"data\"", "]", "[", "$", "key", "]", "as", "$", "second", ")", "{", "$", "this", "->", "next", "(", "array_merge", "(", "$", "first", ",", "$", "second", ")", ")", ";", "}", "}", "}", "}", "}" ]
Handle on input end @return null
[ "Handle", "on", "input", "end" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/processes/Join.php#L98-L109
koolphp/koolreport
src/processes/Join.php
Join.receiveMeta
public function receiveMeta($metaData, $source) { if ($source === $this->container[0]["source"]) { $this->container[0]["meta"] = $metaData; } else { $this->container[1]["meta"] = $metaData; } if ($this->container[0]["meta"] && $this->container[1]["meta"]) { $meta = array( "columns" => array_merge( $this->container[0]["meta"]["columns"], $this->container[1]["meta"]["columns"] ), ); $this->sendMeta($meta); } }
php
public function receiveMeta($metaData, $source) { if ($source === $this->container[0]["source"]) { $this->container[0]["meta"] = $metaData; } else { $this->container[1]["meta"] = $metaData; } if ($this->container[0]["meta"] && $this->container[1]["meta"]) { $meta = array( "columns" => array_merge( $this->container[0]["meta"]["columns"], $this->container[1]["meta"]["columns"] ), ); $this->sendMeta($meta); } }
[ "public", "function", "receiveMeta", "(", "$", "metaData", ",", "$", "source", ")", "{", "if", "(", "$", "source", "===", "$", "this", "->", "container", "[", "0", "]", "[", "\"source\"", "]", ")", "{", "$", "this", "->", "container", "[", "0", "]", "[", "\"meta\"", "]", "=", "$", "metaData", ";", "}", "else", "{", "$", "this", "->", "container", "[", "1", "]", "[", "\"meta\"", "]", "=", "$", "metaData", ";", "}", "if", "(", "$", "this", "->", "container", "[", "0", "]", "[", "\"meta\"", "]", "&&", "$", "this", "->", "container", "[", "1", "]", "[", "\"meta\"", "]", ")", "{", "$", "meta", "=", "array", "(", "\"columns\"", "=>", "array_merge", "(", "$", "this", "->", "container", "[", "0", "]", "[", "\"meta\"", "]", "[", "\"columns\"", "]", ",", "$", "this", "->", "container", "[", "1", "]", "[", "\"meta\"", "]", "[", "\"columns\"", "]", ")", ",", ")", ";", "$", "this", "->", "sendMeta", "(", "$", "meta", ")", ";", "}", "}" ]
Handle on meta data received @param array $metaData The meta data received @param Node $source The source sending data @return null
[ "Handle", "on", "meta", "data", "received" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/processes/Join.php#L119-L135
koolphp/koolreport
src/widgets/google/Timeline.php
Timeline.newClientDate
protected function newClientDate($value, $meta) { $format = Utility::get($meta, "format"); $type = Utility::get($meta, "type"); if ($format == null) { switch ($type) { case "date": $format = "Y-m-d"; $toFormat = "Y,(n-1),d"; break; case "time": $format = "H:i:s"; $toFormat = "0,0,0,H,i,s"; break; case "datetime": default: $format = "Y-m-d H:i:s"; $toFormat = "Y,(n-1),d,H,i,s"; break; } } //The (n-1) above is because in Javascript, month start from 0 to 11 $date = \DateTime::createFromFormat($format, $value); if ($date) { return "new Date(" . \DateTime::createFromFormat($format, $value)->format($toFormat) . ")"; } return "null"; }
php
protected function newClientDate($value, $meta) { $format = Utility::get($meta, "format"); $type = Utility::get($meta, "type"); if ($format == null) { switch ($type) { case "date": $format = "Y-m-d"; $toFormat = "Y,(n-1),d"; break; case "time": $format = "H:i:s"; $toFormat = "0,0,0,H,i,s"; break; case "datetime": default: $format = "Y-m-d H:i:s"; $toFormat = "Y,(n-1),d,H,i,s"; break; } } //The (n-1) above is because in Javascript, month start from 0 to 11 $date = \DateTime::createFromFormat($format, $value); if ($date) { return "new Date(" . \DateTime::createFromFormat($format, $value)->format($toFormat) . ")"; } return "null"; }
[ "protected", "function", "newClientDate", "(", "$", "value", ",", "$", "meta", ")", "{", "$", "format", "=", "Utility", "::", "get", "(", "$", "meta", ",", "\"format\"", ")", ";", "$", "type", "=", "Utility", "::", "get", "(", "$", "meta", ",", "\"type\"", ")", ";", "if", "(", "$", "format", "==", "null", ")", "{", "switch", "(", "$", "type", ")", "{", "case", "\"date\"", ":", "$", "format", "=", "\"Y-m-d\"", ";", "$", "toFormat", "=", "\"Y,(n-1),d\"", ";", "break", ";", "case", "\"time\"", ":", "$", "format", "=", "\"H:i:s\"", ";", "$", "toFormat", "=", "\"0,0,0,H,i,s\"", ";", "break", ";", "case", "\"datetime\"", ":", "default", ":", "$", "format", "=", "\"Y-m-d H:i:s\"", ";", "$", "toFormat", "=", "\"Y,(n-1),d,H,i,s\"", ";", "break", ";", "}", "}", "//The (n-1) above is because in Javascript, month start from 0 to 11", "$", "date", "=", "\\", "DateTime", "::", "createFromFormat", "(", "$", "format", ",", "$", "value", ")", ";", "if", "(", "$", "date", ")", "{", "return", "\"new Date(\"", ".", "\\", "DateTime", "::", "createFromFormat", "(", "$", "format", ",", "$", "value", ")", "->", "format", "(", "$", "toFormat", ")", ".", "\")\"", ";", "}", "return", "\"null\"", ";", "}" ]
Convert server-side date to client-side format @param string $value The datetime @param array $meta The meta data @return string The client-side date format
[ "Convert", "server", "-", "side", "date", "to", "client", "-", "side", "format" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/widgets/google/Timeline.php#L50-L78
koolphp/koolreport
src/widgets/google/Timeline.php
Timeline.onRender
protected function onRender() { $columns = $this->getColumnSettings(); //Update options $options = $this->options; if ($this->title) { $options["title"] = $this->title; } if ($this->colorScheme) { $options["colors"] = $this->colorScheme; } $this->template( 'Timeline', array( "options" => $options, "columns" => $columns, "loader"=>array( "package"=>$this->package, "stability"=>$this->stability, "mapsApiKey"=>$this->mapsApiKey ) ) ); }
php
protected function onRender() { $columns = $this->getColumnSettings(); //Update options $options = $this->options; if ($this->title) { $options["title"] = $this->title; } if ($this->colorScheme) { $options["colors"] = $this->colorScheme; } $this->template( 'Timeline', array( "options" => $options, "columns" => $columns, "loader"=>array( "package"=>$this->package, "stability"=>$this->stability, "mapsApiKey"=>$this->mapsApiKey ) ) ); }
[ "protected", "function", "onRender", "(", ")", "{", "$", "columns", "=", "$", "this", "->", "getColumnSettings", "(", ")", ";", "//Update options", "$", "options", "=", "$", "this", "->", "options", ";", "if", "(", "$", "this", "->", "title", ")", "{", "$", "options", "[", "\"title\"", "]", "=", "$", "this", "->", "title", ";", "}", "if", "(", "$", "this", "->", "colorScheme", ")", "{", "$", "options", "[", "\"colors\"", "]", "=", "$", "this", "->", "colorScheme", ";", "}", "$", "this", "->", "template", "(", "'Timeline'", ",", "array", "(", "\"options\"", "=>", "$", "options", ",", "\"columns\"", "=>", "$", "columns", ",", "\"loader\"", "=>", "array", "(", "\"package\"", "=>", "$", "this", "->", "package", ",", "\"stability\"", "=>", "$", "this", "->", "stability", ",", "\"mapsApiKey\"", "=>", "$", "this", "->", "mapsApiKey", ")", ")", ")", ";", "}" ]
Handle on render @return null
[ "Handle", "on", "render" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/widgets/google/Timeline.php#L85-L111
koolphp/koolreport
src/processes/Sort.php
Sort.sortProcess
public function sortProcess() { $sorts = []; foreach ($this->params as $field => $direction) { $sorts[trim($field)] = is_string($direction) ? trim($direction) : $direction; } usort( $this->data, function ($a1, $a2) use ($sorts) { $cmp = 0; foreach ($sorts as $field => $direction) { $v1 = Util::get($a1, $field, 0); $v2 = Util::get($a2, $field, 0); if ($direction === 'asc' || $direction === 'desc') { if (is_numeric($v1) && is_numeric($v2)) { if ($v1 < $v2) { $cmp = -1; } elseif ($v1 > $v2) { $cmp = 1; } } else { $cmp = strcmp($v1, $v2); } if ($direction === 'desc') { $cmp = -$cmp; } } else if (is_callable($direction)) { $cmp = $direction($v1, $v2); } if ($cmp !== 0) { break; } } return $cmp; } ); }
php
public function sortProcess() { $sorts = []; foreach ($this->params as $field => $direction) { $sorts[trim($field)] = is_string($direction) ? trim($direction) : $direction; } usort( $this->data, function ($a1, $a2) use ($sorts) { $cmp = 0; foreach ($sorts as $field => $direction) { $v1 = Util::get($a1, $field, 0); $v2 = Util::get($a2, $field, 0); if ($direction === 'asc' || $direction === 'desc') { if (is_numeric($v1) && is_numeric($v2)) { if ($v1 < $v2) { $cmp = -1; } elseif ($v1 > $v2) { $cmp = 1; } } else { $cmp = strcmp($v1, $v2); } if ($direction === 'desc') { $cmp = -$cmp; } } else if (is_callable($direction)) { $cmp = $direction($v1, $v2); } if ($cmp !== 0) { break; } } return $cmp; } ); }
[ "public", "function", "sortProcess", "(", ")", "{", "$", "sorts", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "params", "as", "$", "field", "=>", "$", "direction", ")", "{", "$", "sorts", "[", "trim", "(", "$", "field", ")", "]", "=", "is_string", "(", "$", "direction", ")", "?", "trim", "(", "$", "direction", ")", ":", "$", "direction", ";", "}", "usort", "(", "$", "this", "->", "data", ",", "function", "(", "$", "a1", ",", "$", "a2", ")", "use", "(", "$", "sorts", ")", "{", "$", "cmp", "=", "0", ";", "foreach", "(", "$", "sorts", "as", "$", "field", "=>", "$", "direction", ")", "{", "$", "v1", "=", "Util", "::", "get", "(", "$", "a1", ",", "$", "field", ",", "0", ")", ";", "$", "v2", "=", "Util", "::", "get", "(", "$", "a2", ",", "$", "field", ",", "0", ")", ";", "if", "(", "$", "direction", "===", "'asc'", "||", "$", "direction", "===", "'desc'", ")", "{", "if", "(", "is_numeric", "(", "$", "v1", ")", "&&", "is_numeric", "(", "$", "v2", ")", ")", "{", "if", "(", "$", "v1", "<", "$", "v2", ")", "{", "$", "cmp", "=", "-", "1", ";", "}", "elseif", "(", "$", "v1", ">", "$", "v2", ")", "{", "$", "cmp", "=", "1", ";", "}", "}", "else", "{", "$", "cmp", "=", "strcmp", "(", "$", "v1", ",", "$", "v2", ")", ";", "}", "if", "(", "$", "direction", "===", "'desc'", ")", "{", "$", "cmp", "=", "-", "$", "cmp", ";", "}", "}", "else", "if", "(", "is_callable", "(", "$", "direction", ")", ")", "{", "$", "cmp", "=", "$", "direction", "(", "$", "v1", ",", "$", "v2", ")", ";", "}", "if", "(", "$", "cmp", "!==", "0", ")", "{", "break", ";", "}", "}", "return", "$", "cmp", ";", "}", ")", ";", "}" ]
Do sorting @return null
[ "Do", "sorting" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/processes/Sort.php#L55-L97
koolphp/koolreport
src/processes/Sort.php
Sort.onInputEnd
public function onInputEnd() { $this->sortProcess(); foreach ($this->data as $row) { $this->next($row); } unset($this->data); }
php
public function onInputEnd() { $this->sortProcess(); foreach ($this->data as $row) { $this->next($row); } unset($this->data); }
[ "public", "function", "onInputEnd", "(", ")", "{", "$", "this", "->", "sortProcess", "(", ")", ";", "foreach", "(", "$", "this", "->", "data", "as", "$", "row", ")", "{", "$", "this", "->", "next", "(", "$", "row", ")", ";", "}", "unset", "(", "$", "this", "->", "data", ")", ";", "}" ]
Handle on input end @return null
[ "Handle", "on", "input", "end" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/processes/Sort.php#L104-L111
koolphp/koolreport
src/widgets/koolphp/Table.php
Table.onInit
protected function onInit() { $this->useLanguage(); $this->useDataSource(); $this->useAutoName("ktable"); $this->emptyValue = Utility::get($this->params, "emptyValue", 0); $this->clientEvents = Utility::get($this->params, "clientEvents"); $this->columns = Utility::get($this->params, "columns", array()); if ($this->dataStore == null) { $data = Utility::get($this->params, "data"); if (is_array($data)) { if (count($data) > 0) { $this->dataStore = new DataStore; $this->dataStore->data($data); $row = $data[0]; $meta = array("columns" => array()); foreach ($row as $cKey => $cValue) { $meta["columns"][$cKey] = array( "type" => Utility::guessType($cValue), ); } $this->dataStore->meta($meta); } else { $this->dataStore = new DataStore; $this->dataStore->data(array()); $metaColumns = array(); foreach ($this->columns as $cKey => $cValue) { if (gettype($cValue) == "array") { $metaColumns[$cKey] = $cValue; } else { $metaColumns[$cValue] = array(); } } $this->dataStore->meta(array("columns" => $metaColumns)); } } if ($this->dataStore == null) { throw new \Exception("dataSource is required for Table"); return; } } if ($this->dataStore->countData() == 0 && count($this->dataStore->meta()["columns"]) == 0) { $meta = array("columns" => array()); foreach ($this->columns as $cKey => $cValue) { if (gettype($cValue) == "array") { $meta["columns"][$cKey] = $cValue; } else { $meta["columns"][$cValue] = array(); } } $this->dataStore->meta($meta); } $this->removeDuplicate = Utility::get($this->params, "removeDuplicate", array()); $this->cssClass = Utility::get($this->params, "cssClass", array()); $this->excludedColumns = Utility::get($this->params, "excludedColumns", array()); $this->showFooter = Utility::get($this->params, "showFooter"); $this->showHeader = Utility::get($this->params, "showHeader", true); $this->paging = Utility::get($this->params, "paging"); if ($this->paging !== null) { $this->paging = array( "pageSize" => Utility::get($this->paging, "pageSize", 10), "pageIndex" => Utility::get($this->paging, "pageIndex", 0), "align" => Utility::get($this->paging, "align", "left"), ); $this->paging["itemCount"] = $this->dataStore->countData(); $this->paging["pageCount"] = ceil($this->paging["itemCount"] / $this->paging["pageSize"]); } //Header Group $this->headers = Utility::get($this->params, "headers", array()); $this->responsive = Utility::get($this->params, "responsive", false); $this->sorting = Utility::get($this->params, "sorting", array()); $group = Utility::get($this->params, "grouping"); $this->group = array(); if ($group) { foreach ($group as $cKey => $cValue) { if (gettype($cValue) == "array") { $this->group[$cKey] = $cValue; } else if (gettype($cValue) == "string") { $this->group[$cValue] = array( "top" => "<strong>{" . $cValue . "}</strong>", ); } } } }
php
protected function onInit() { $this->useLanguage(); $this->useDataSource(); $this->useAutoName("ktable"); $this->emptyValue = Utility::get($this->params, "emptyValue", 0); $this->clientEvents = Utility::get($this->params, "clientEvents"); $this->columns = Utility::get($this->params, "columns", array()); if ($this->dataStore == null) { $data = Utility::get($this->params, "data"); if (is_array($data)) { if (count($data) > 0) { $this->dataStore = new DataStore; $this->dataStore->data($data); $row = $data[0]; $meta = array("columns" => array()); foreach ($row as $cKey => $cValue) { $meta["columns"][$cKey] = array( "type" => Utility::guessType($cValue), ); } $this->dataStore->meta($meta); } else { $this->dataStore = new DataStore; $this->dataStore->data(array()); $metaColumns = array(); foreach ($this->columns as $cKey => $cValue) { if (gettype($cValue) == "array") { $metaColumns[$cKey] = $cValue; } else { $metaColumns[$cValue] = array(); } } $this->dataStore->meta(array("columns" => $metaColumns)); } } if ($this->dataStore == null) { throw new \Exception("dataSource is required for Table"); return; } } if ($this->dataStore->countData() == 0 && count($this->dataStore->meta()["columns"]) == 0) { $meta = array("columns" => array()); foreach ($this->columns as $cKey => $cValue) { if (gettype($cValue) == "array") { $meta["columns"][$cKey] = $cValue; } else { $meta["columns"][$cValue] = array(); } } $this->dataStore->meta($meta); } $this->removeDuplicate = Utility::get($this->params, "removeDuplicate", array()); $this->cssClass = Utility::get($this->params, "cssClass", array()); $this->excludedColumns = Utility::get($this->params, "excludedColumns", array()); $this->showFooter = Utility::get($this->params, "showFooter"); $this->showHeader = Utility::get($this->params, "showHeader", true); $this->paging = Utility::get($this->params, "paging"); if ($this->paging !== null) { $this->paging = array( "pageSize" => Utility::get($this->paging, "pageSize", 10), "pageIndex" => Utility::get($this->paging, "pageIndex", 0), "align" => Utility::get($this->paging, "align", "left"), ); $this->paging["itemCount"] = $this->dataStore->countData(); $this->paging["pageCount"] = ceil($this->paging["itemCount"] / $this->paging["pageSize"]); } //Header Group $this->headers = Utility::get($this->params, "headers", array()); $this->responsive = Utility::get($this->params, "responsive", false); $this->sorting = Utility::get($this->params, "sorting", array()); $group = Utility::get($this->params, "grouping"); $this->group = array(); if ($group) { foreach ($group as $cKey => $cValue) { if (gettype($cValue) == "array") { $this->group[$cKey] = $cValue; } else if (gettype($cValue) == "string") { $this->group[$cValue] = array( "top" => "<strong>{" . $cValue . "}</strong>", ); } } } }
[ "protected", "function", "onInit", "(", ")", "{", "$", "this", "->", "useLanguage", "(", ")", ";", "$", "this", "->", "useDataSource", "(", ")", ";", "$", "this", "->", "useAutoName", "(", "\"ktable\"", ")", ";", "$", "this", "->", "emptyValue", "=", "Utility", "::", "get", "(", "$", "this", "->", "params", ",", "\"emptyValue\"", ",", "0", ")", ";", "$", "this", "->", "clientEvents", "=", "Utility", "::", "get", "(", "$", "this", "->", "params", ",", "\"clientEvents\"", ")", ";", "$", "this", "->", "columns", "=", "Utility", "::", "get", "(", "$", "this", "->", "params", ",", "\"columns\"", ",", "array", "(", ")", ")", ";", "if", "(", "$", "this", "->", "dataStore", "==", "null", ")", "{", "$", "data", "=", "Utility", "::", "get", "(", "$", "this", "->", "params", ",", "\"data\"", ")", ";", "if", "(", "is_array", "(", "$", "data", ")", ")", "{", "if", "(", "count", "(", "$", "data", ")", ">", "0", ")", "{", "$", "this", "->", "dataStore", "=", "new", "DataStore", ";", "$", "this", "->", "dataStore", "->", "data", "(", "$", "data", ")", ";", "$", "row", "=", "$", "data", "[", "0", "]", ";", "$", "meta", "=", "array", "(", "\"columns\"", "=>", "array", "(", ")", ")", ";", "foreach", "(", "$", "row", "as", "$", "cKey", "=>", "$", "cValue", ")", "{", "$", "meta", "[", "\"columns\"", "]", "[", "$", "cKey", "]", "=", "array", "(", "\"type\"", "=>", "Utility", "::", "guessType", "(", "$", "cValue", ")", ",", ")", ";", "}", "$", "this", "->", "dataStore", "->", "meta", "(", "$", "meta", ")", ";", "}", "else", "{", "$", "this", "->", "dataStore", "=", "new", "DataStore", ";", "$", "this", "->", "dataStore", "->", "data", "(", "array", "(", ")", ")", ";", "$", "metaColumns", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "columns", "as", "$", "cKey", "=>", "$", "cValue", ")", "{", "if", "(", "gettype", "(", "$", "cValue", ")", "==", "\"array\"", ")", "{", "$", "metaColumns", "[", "$", "cKey", "]", "=", "$", "cValue", ";", "}", "else", "{", "$", "metaColumns", "[", "$", "cValue", "]", "=", "array", "(", ")", ";", "}", "}", "$", "this", "->", "dataStore", "->", "meta", "(", "array", "(", "\"columns\"", "=>", "$", "metaColumns", ")", ")", ";", "}", "}", "if", "(", "$", "this", "->", "dataStore", "==", "null", ")", "{", "throw", "new", "\\", "Exception", "(", "\"dataSource is required for Table\"", ")", ";", "return", ";", "}", "}", "if", "(", "$", "this", "->", "dataStore", "->", "countData", "(", ")", "==", "0", "&&", "count", "(", "$", "this", "->", "dataStore", "->", "meta", "(", ")", "[", "\"columns\"", "]", ")", "==", "0", ")", "{", "$", "meta", "=", "array", "(", "\"columns\"", "=>", "array", "(", ")", ")", ";", "foreach", "(", "$", "this", "->", "columns", "as", "$", "cKey", "=>", "$", "cValue", ")", "{", "if", "(", "gettype", "(", "$", "cValue", ")", "==", "\"array\"", ")", "{", "$", "meta", "[", "\"columns\"", "]", "[", "$", "cKey", "]", "=", "$", "cValue", ";", "}", "else", "{", "$", "meta", "[", "\"columns\"", "]", "[", "$", "cValue", "]", "=", "array", "(", ")", ";", "}", "}", "$", "this", "->", "dataStore", "->", "meta", "(", "$", "meta", ")", ";", "}", "$", "this", "->", "removeDuplicate", "=", "Utility", "::", "get", "(", "$", "this", "->", "params", ",", "\"removeDuplicate\"", ",", "array", "(", ")", ")", ";", "$", "this", "->", "cssClass", "=", "Utility", "::", "get", "(", "$", "this", "->", "params", ",", "\"cssClass\"", ",", "array", "(", ")", ")", ";", "$", "this", "->", "excludedColumns", "=", "Utility", "::", "get", "(", "$", "this", "->", "params", ",", "\"excludedColumns\"", ",", "array", "(", ")", ")", ";", "$", "this", "->", "showFooter", "=", "Utility", "::", "get", "(", "$", "this", "->", "params", ",", "\"showFooter\"", ")", ";", "$", "this", "->", "showHeader", "=", "Utility", "::", "get", "(", "$", "this", "->", "params", ",", "\"showHeader\"", ",", "true", ")", ";", "$", "this", "->", "paging", "=", "Utility", "::", "get", "(", "$", "this", "->", "params", ",", "\"paging\"", ")", ";", "if", "(", "$", "this", "->", "paging", "!==", "null", ")", "{", "$", "this", "->", "paging", "=", "array", "(", "\"pageSize\"", "=>", "Utility", "::", "get", "(", "$", "this", "->", "paging", ",", "\"pageSize\"", ",", "10", ")", ",", "\"pageIndex\"", "=>", "Utility", "::", "get", "(", "$", "this", "->", "paging", ",", "\"pageIndex\"", ",", "0", ")", ",", "\"align\"", "=>", "Utility", "::", "get", "(", "$", "this", "->", "paging", ",", "\"align\"", ",", "\"left\"", ")", ",", ")", ";", "$", "this", "->", "paging", "[", "\"itemCount\"", "]", "=", "$", "this", "->", "dataStore", "->", "countData", "(", ")", ";", "$", "this", "->", "paging", "[", "\"pageCount\"", "]", "=", "ceil", "(", "$", "this", "->", "paging", "[", "\"itemCount\"", "]", "/", "$", "this", "->", "paging", "[", "\"pageSize\"", "]", ")", ";", "}", "//Header Group", "$", "this", "->", "headers", "=", "Utility", "::", "get", "(", "$", "this", "->", "params", ",", "\"headers\"", ",", "array", "(", ")", ")", ";", "$", "this", "->", "responsive", "=", "Utility", "::", "get", "(", "$", "this", "->", "params", ",", "\"responsive\"", ",", "false", ")", ";", "$", "this", "->", "sorting", "=", "Utility", "::", "get", "(", "$", "this", "->", "params", ",", "\"sorting\"", ",", "array", "(", ")", ")", ";", "$", "group", "=", "Utility", "::", "get", "(", "$", "this", "->", "params", ",", "\"grouping\"", ")", ";", "$", "this", "->", "group", "=", "array", "(", ")", ";", "if", "(", "$", "group", ")", "{", "foreach", "(", "$", "group", "as", "$", "cKey", "=>", "$", "cValue", ")", "{", "if", "(", "gettype", "(", "$", "cValue", ")", "==", "\"array\"", ")", "{", "$", "this", "->", "group", "[", "$", "cKey", "]", "=", "$", "cValue", ";", "}", "else", "if", "(", "gettype", "(", "$", "cValue", ")", "==", "\"string\"", ")", "{", "$", "this", "->", "group", "[", "$", "cValue", "]", "=", "array", "(", "\"top\"", "=>", "\"<strong>{\"", ".", "$", "cValue", ".", "\"}</strong>\"", ",", ")", ";", "}", "}", "}", "}" ]
Handle the initation @return null
[ "Handle", "the", "initation" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/widgets/koolphp/Table.php#L81-L172
koolphp/koolreport
src/widgets/koolphp/Table.php
Table.groupLevel
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); } } ); }
php
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); } } ); }
[ "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", ")", ";", "}", "}", ")", ";", "}" ]
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
[ "Group", "the", "level" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/widgets/koolphp/Table.php#L210-L293
koolphp/koolreport
src/widgets/koolphp/Table.php
Table.generateGroups
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); Table::groupLevel($meta, $this->group, $this->dataStore, $result); return $result; } return false; }
php
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); Table::groupLevel($meta, $this->group, $this->dataStore, $result); return $result; } return false; }
[ "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", ")", ";", "Table", "::", "groupLevel", "(", "$", "meta", ",", "$", "this", "->", "group", ",", "$", "this", "->", "dataStore", ",", "$", "result", ")", ";", "return", "$", "result", ";", "}", "return", "false", ";", "}" ]
Generate groups for table grouping @param array $meta The meta data of table @return array List of results
[ "Generate", "groups", "for", "table", "grouping" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/widgets/koolphp/Table.php#L302-L316
koolphp/koolreport
src/widgets/koolphp/Table.php
Table.renderRowGroup
protected function renderRowGroup($groups, $index, $colspan) { if ($groups && isset($groups[$index])) { foreach ($groups[$index] as $grow) { if ($this->paging) { $grow[3] = "display:none;" . $grow[3]; } echo "<tr from='$grow[0]' to='$grow[1]' class='row-group" . ($grow[4] ? " $grow[4]" : "") . "' " . ($grow[3] ? "style='$grow[3]'" : "") . ">"; if (strpos($grow[2], "<td") === 0) { echo $grow[2]; } else { echo "<td colspan='$colspan'>$grow[2]</td>"; } echo "</tr>"; } } }
php
protected function renderRowGroup($groups, $index, $colspan) { if ($groups && isset($groups[$index])) { foreach ($groups[$index] as $grow) { if ($this->paging) { $grow[3] = "display:none;" . $grow[3]; } echo "<tr from='$grow[0]' to='$grow[1]' class='row-group" . ($grow[4] ? " $grow[4]" : "") . "' " . ($grow[3] ? "style='$grow[3]'" : "") . ">"; if (strpos($grow[2], "<td") === 0) { echo $grow[2]; } else { echo "<td colspan='$colspan'>$grow[2]</td>"; } echo "</tr>"; } } }
[ "protected", "function", "renderRowGroup", "(", "$", "groups", ",", "$", "index", ",", "$", "colspan", ")", "{", "if", "(", "$", "groups", "&&", "isset", "(", "$", "groups", "[", "$", "index", "]", ")", ")", "{", "foreach", "(", "$", "groups", "[", "$", "index", "]", "as", "$", "grow", ")", "{", "if", "(", "$", "this", "->", "paging", ")", "{", "$", "grow", "[", "3", "]", "=", "\"display:none;\"", ".", "$", "grow", "[", "3", "]", ";", "}", "echo", "\"<tr from='$grow[0]' to='$grow[1]' class='row-group\"", ".", "(", "$", "grow", "[", "4", "]", "?", "\" $grow[4]\"", ":", "\"\"", ")", ".", "\"' \"", ".", "(", "$", "grow", "[", "3", "]", "?", "\"style='$grow[3]'\"", ":", "\"\"", ")", ".", "\">\"", ";", "if", "(", "strpos", "(", "$", "grow", "[", "2", "]", ",", "\"<td\"", ")", "===", "0", ")", "{", "echo", "$", "grow", "[", "2", "]", ";", "}", "else", "{", "echo", "\"<td colspan='$colspan'>$grow[2]</td>\"", ";", "}", "echo", "\"</tr>\"", ";", "}", "}", "}" ]
Echo the row group content in html @param array $groups The groups @param integer $index The index of data rows @param integer $colspan The number of colspan @return null
[ "Echo", "the", "row", "group", "content", "in", "html" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/widgets/koolphp/Table.php#L327-L343
koolphp/koolreport
src/widgets/koolphp/Table.php
Table.onRender
public function onRender() { $meta = $this->dataStore->meta(); $showColumnKeys = array(); if ($this->columns == array()) { if ($row = $this->dataStore[0]) { $showColumnKeys = array_keys($row); } else if (count($meta["columns"]) > 0) { $showColumnKeys = array_keys($meta["columns"]); } } else { foreach ($this->columns as $cKey => $cValue) { if ($cKey === "{others}") { $allKeys = array_keys($this->dataStore[0]); foreach ($allKeys as $k) { if (!in_array($k, $showColumnKeys)) { $meta["columns"][$k] = array_merge($meta["columns"][$k], $cValue); array_push($showColumnKeys, $k); } } } else { if (gettype($cValue) == "array") { if ($cKey === "#") { $meta["columns"][$cKey] = array( "type" => "number", "label" => "#", "start" => 1, ); } $meta["columns"][$cKey] = array_merge($meta["columns"][$cKey], $cValue); if (!in_array($cKey, $showColumnKeys)) { array_push($showColumnKeys, $cKey); } } else { if ($cValue === "#") { $meta["columns"][$cValue] = array( "type" => "number", "label" => "#", "start" => 1, ); } if (!in_array($cValue, $showColumnKeys)) { array_push($showColumnKeys, $cValue); } } } } } $cleanColumnKeys = array(); foreach ($showColumnKeys as $key) { if (!in_array($key, $this->excludedColumns)) { array_push($cleanColumnKeys, $key); } } $showColumnKeys = $cleanColumnKeys; if (count($this->group) === 0 && count($this->sorting)>0) { $this->dataStore->sort($this->sorting); } //Prepare data $this->template( "Table", array( "showColumnKeys" => $showColumnKeys, "meta" => $meta, ) ); }
php
public function onRender() { $meta = $this->dataStore->meta(); $showColumnKeys = array(); if ($this->columns == array()) { if ($row = $this->dataStore[0]) { $showColumnKeys = array_keys($row); } else if (count($meta["columns"]) > 0) { $showColumnKeys = array_keys($meta["columns"]); } } else { foreach ($this->columns as $cKey => $cValue) { if ($cKey === "{others}") { $allKeys = array_keys($this->dataStore[0]); foreach ($allKeys as $k) { if (!in_array($k, $showColumnKeys)) { $meta["columns"][$k] = array_merge($meta["columns"][$k], $cValue); array_push($showColumnKeys, $k); } } } else { if (gettype($cValue) == "array") { if ($cKey === "#") { $meta["columns"][$cKey] = array( "type" => "number", "label" => "#", "start" => 1, ); } $meta["columns"][$cKey] = array_merge($meta["columns"][$cKey], $cValue); if (!in_array($cKey, $showColumnKeys)) { array_push($showColumnKeys, $cKey); } } else { if ($cValue === "#") { $meta["columns"][$cValue] = array( "type" => "number", "label" => "#", "start" => 1, ); } if (!in_array($cValue, $showColumnKeys)) { array_push($showColumnKeys, $cValue); } } } } } $cleanColumnKeys = array(); foreach ($showColumnKeys as $key) { if (!in_array($key, $this->excludedColumns)) { array_push($cleanColumnKeys, $key); } } $showColumnKeys = $cleanColumnKeys; if (count($this->group) === 0 && count($this->sorting)>0) { $this->dataStore->sort($this->sorting); } //Prepare data $this->template( "Table", array( "showColumnKeys" => $showColumnKeys, "meta" => $meta, ) ); }
[ "public", "function", "onRender", "(", ")", "{", "$", "meta", "=", "$", "this", "->", "dataStore", "->", "meta", "(", ")", ";", "$", "showColumnKeys", "=", "array", "(", ")", ";", "if", "(", "$", "this", "->", "columns", "==", "array", "(", ")", ")", "{", "if", "(", "$", "row", "=", "$", "this", "->", "dataStore", "[", "0", "]", ")", "{", "$", "showColumnKeys", "=", "array_keys", "(", "$", "row", ")", ";", "}", "else", "if", "(", "count", "(", "$", "meta", "[", "\"columns\"", "]", ")", ">", "0", ")", "{", "$", "showColumnKeys", "=", "array_keys", "(", "$", "meta", "[", "\"columns\"", "]", ")", ";", "}", "}", "else", "{", "foreach", "(", "$", "this", "->", "columns", "as", "$", "cKey", "=>", "$", "cValue", ")", "{", "if", "(", "$", "cKey", "===", "\"{others}\"", ")", "{", "$", "allKeys", "=", "array_keys", "(", "$", "this", "->", "dataStore", "[", "0", "]", ")", ";", "foreach", "(", "$", "allKeys", "as", "$", "k", ")", "{", "if", "(", "!", "in_array", "(", "$", "k", ",", "$", "showColumnKeys", ")", ")", "{", "$", "meta", "[", "\"columns\"", "]", "[", "$", "k", "]", "=", "array_merge", "(", "$", "meta", "[", "\"columns\"", "]", "[", "$", "k", "]", ",", "$", "cValue", ")", ";", "array_push", "(", "$", "showColumnKeys", ",", "$", "k", ")", ";", "}", "}", "}", "else", "{", "if", "(", "gettype", "(", "$", "cValue", ")", "==", "\"array\"", ")", "{", "if", "(", "$", "cKey", "===", "\"#\"", ")", "{", "$", "meta", "[", "\"columns\"", "]", "[", "$", "cKey", "]", "=", "array", "(", "\"type\"", "=>", "\"number\"", ",", "\"label\"", "=>", "\"#\"", ",", "\"start\"", "=>", "1", ",", ")", ";", "}", "$", "meta", "[", "\"columns\"", "]", "[", "$", "cKey", "]", "=", "array_merge", "(", "$", "meta", "[", "\"columns\"", "]", "[", "$", "cKey", "]", ",", "$", "cValue", ")", ";", "if", "(", "!", "in_array", "(", "$", "cKey", ",", "$", "showColumnKeys", ")", ")", "{", "array_push", "(", "$", "showColumnKeys", ",", "$", "cKey", ")", ";", "}", "}", "else", "{", "if", "(", "$", "cValue", "===", "\"#\"", ")", "{", "$", "meta", "[", "\"columns\"", "]", "[", "$", "cValue", "]", "=", "array", "(", "\"type\"", "=>", "\"number\"", ",", "\"label\"", "=>", "\"#\"", ",", "\"start\"", "=>", "1", ",", ")", ";", "}", "if", "(", "!", "in_array", "(", "$", "cValue", ",", "$", "showColumnKeys", ")", ")", "{", "array_push", "(", "$", "showColumnKeys", ",", "$", "cValue", ")", ";", "}", "}", "}", "}", "}", "$", "cleanColumnKeys", "=", "array", "(", ")", ";", "foreach", "(", "$", "showColumnKeys", "as", "$", "key", ")", "{", "if", "(", "!", "in_array", "(", "$", "key", ",", "$", "this", "->", "excludedColumns", ")", ")", "{", "array_push", "(", "$", "cleanColumnKeys", ",", "$", "key", ")", ";", "}", "}", "$", "showColumnKeys", "=", "$", "cleanColumnKeys", ";", "if", "(", "count", "(", "$", "this", "->", "group", ")", "===", "0", "&&", "count", "(", "$", "this", "->", "sorting", ")", ">", "0", ")", "{", "$", "this", "->", "dataStore", "->", "sort", "(", "$", "this", "->", "sorting", ")", ";", "}", "//Prepare data", "$", "this", "->", "template", "(", "\"Table\"", ",", "array", "(", "\"showColumnKeys\"", "=>", "$", "showColumnKeys", ",", "\"meta\"", "=>", "$", "meta", ",", ")", ")", ";", "}" ]
Handle on widget rendering @return null
[ "Handle", "on", "widget", "rendering" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/widgets/koolphp/Table.php#L350-L424
koolphp/koolreport
src/clients/BootstrapCSS.php
BootstrapCSS.__constructBootstrapCSS
public function __constructBootstrapCSS() { $this->registerEvent( 'OnResourceInit', function () { $bootstrapAssetUrl = $this->getResourceManager() ->publishAssetFolder(realpath(dirname(__FILE__)."/bootstrap")); $resources = array( "css"=>array( $bootstrapAssetUrl."/css/bootstrap.min.css", $bootstrapAssetUrl."/css/bootstrap-theme.min.css" ) ); $this->getResourceManager() ->addScriptOnBegin("KoolReport.load.resources(".json_encode($resources).");"); } ); }
php
public function __constructBootstrapCSS() { $this->registerEvent( 'OnResourceInit', function () { $bootstrapAssetUrl = $this->getResourceManager() ->publishAssetFolder(realpath(dirname(__FILE__)."/bootstrap")); $resources = array( "css"=>array( $bootstrapAssetUrl."/css/bootstrap.min.css", $bootstrapAssetUrl."/css/bootstrap-theme.min.css" ) ); $this->getResourceManager() ->addScriptOnBegin("KoolReport.load.resources(".json_encode($resources).");"); } ); }
[ "public", "function", "__constructBootstrapCSS", "(", ")", "{", "$", "this", "->", "registerEvent", "(", "'OnResourceInit'", ",", "function", "(", ")", "{", "$", "bootstrapAssetUrl", "=", "$", "this", "->", "getResourceManager", "(", ")", "->", "publishAssetFolder", "(", "realpath", "(", "dirname", "(", "__FILE__", ")", ".", "\"/bootstrap\"", ")", ")", ";", "$", "resources", "=", "array", "(", "\"css\"", "=>", "array", "(", "$", "bootstrapAssetUrl", ".", "\"/css/bootstrap.min.css\"", ",", "$", "bootstrapAssetUrl", ".", "\"/css/bootstrap-theme.min.css\"", ")", ")", ";", "$", "this", "->", "getResourceManager", "(", ")", "->", "addScriptOnBegin", "(", "\"KoolReport.load.resources(\"", ".", "json_encode", "(", "$", "resources", ")", ".", "\");\"", ")", ";", "}", ")", ";", "}" ]
Service construction @return null
[ "Service", "construction" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/clients/BootstrapCSS.php#L33-L51
koolphp/koolreport
src/datasources/ArrayDataSource.php
ArrayDataSource.load
public function load($data,$dataFormat=null) { if ($dataFormat) { $this->dataFormat = $dataFormat; } $this->params["data"] = $data; return $this; }
php
public function load($data,$dataFormat=null) { if ($dataFormat) { $this->dataFormat = $dataFormat; } $this->params["data"] = $data; return $this; }
[ "public", "function", "load", "(", "$", "data", ",", "$", "dataFormat", "=", "null", ")", "{", "if", "(", "$", "dataFormat", ")", "{", "$", "this", "->", "dataFormat", "=", "$", "dataFormat", ";", "}", "$", "this", "->", "params", "[", "\"data\"", "]", "=", "$", "data", ";", "return", "$", "this", ";", "}" ]
Load data The data is loaded in form of "table" or "associate" of your choice @param array $data Data @param string $dataFormat Either "table" or "associate" @return ArrayDataSource This datasource object
[ "Load", "data" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/datasources/ArrayDataSource.php#L96-L103
koolphp/koolreport
src/datasources/ArrayDataSource.php
ArrayDataSource.start
public function start() { $data = Utility::get($this->params, "data", array()); if ($data && count($data)>0) { switch($this->dataFormat) { case "table": $columnNames = $data[0]; $metaData = array("columns"=>array()); for ($i=0;$i<count($columnNames);$i++) { $metaData["columns"][$columnNames[$i]] = array( "type"=>(isset($data[1])) ?$this->guessType($data[1][$i]):"unknown", );; } $this->sendMeta($metaData, $this); $this->startInput(null); $rowNum = count($data); for ($i=1;$i<$rowNum;$i++) { $this->next(array_combine($columnNames, $data[$i]), $this); } break; case "associate": default: $metaData = array("columns"=>array()); foreach ($data[0] as $key=>$value) { $metaData["columns"][$key]=array( "type"=>$this->guessType($value), ); } $this->sendMeta($metaData, $this); $this->startInput(null); foreach ($data as $row) { $this->next($row); } break; } } $this->endInput(null); }
php
public function start() { $data = Utility::get($this->params, "data", array()); if ($data && count($data)>0) { switch($this->dataFormat) { case "table": $columnNames = $data[0]; $metaData = array("columns"=>array()); for ($i=0;$i<count($columnNames);$i++) { $metaData["columns"][$columnNames[$i]] = array( "type"=>(isset($data[1])) ?$this->guessType($data[1][$i]):"unknown", );; } $this->sendMeta($metaData, $this); $this->startInput(null); $rowNum = count($data); for ($i=1;$i<$rowNum;$i++) { $this->next(array_combine($columnNames, $data[$i]), $this); } break; case "associate": default: $metaData = array("columns"=>array()); foreach ($data[0] as $key=>$value) { $metaData["columns"][$key]=array( "type"=>$this->guessType($value), ); } $this->sendMeta($metaData, $this); $this->startInput(null); foreach ($data as $row) { $this->next($row); } break; } } $this->endInput(null); }
[ "public", "function", "start", "(", ")", "{", "$", "data", "=", "Utility", "::", "get", "(", "$", "this", "->", "params", ",", "\"data\"", ",", "array", "(", ")", ")", ";", "if", "(", "$", "data", "&&", "count", "(", "$", "data", ")", ">", "0", ")", "{", "switch", "(", "$", "this", "->", "dataFormat", ")", "{", "case", "\"table\"", ":", "$", "columnNames", "=", "$", "data", "[", "0", "]", ";", "$", "metaData", "=", "array", "(", "\"columns\"", "=>", "array", "(", ")", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "count", "(", "$", "columnNames", ")", ";", "$", "i", "++", ")", "{", "$", "metaData", "[", "\"columns\"", "]", "[", "$", "columnNames", "[", "$", "i", "]", "]", "=", "array", "(", "\"type\"", "=>", "(", "isset", "(", "$", "data", "[", "1", "]", ")", ")", "?", "$", "this", "->", "guessType", "(", "$", "data", "[", "1", "]", "[", "$", "i", "]", ")", ":", "\"unknown\"", ",", ")", ";", ";", "}", "$", "this", "->", "sendMeta", "(", "$", "metaData", ",", "$", "this", ")", ";", "$", "this", "->", "startInput", "(", "null", ")", ";", "$", "rowNum", "=", "count", "(", "$", "data", ")", ";", "for", "(", "$", "i", "=", "1", ";", "$", "i", "<", "$", "rowNum", ";", "$", "i", "++", ")", "{", "$", "this", "->", "next", "(", "array_combine", "(", "$", "columnNames", ",", "$", "data", "[", "$", "i", "]", ")", ",", "$", "this", ")", ";", "}", "break", ";", "case", "\"associate\"", ":", "default", ":", "$", "metaData", "=", "array", "(", "\"columns\"", "=>", "array", "(", ")", ")", ";", "foreach", "(", "$", "data", "[", "0", "]", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "metaData", "[", "\"columns\"", "]", "[", "$", "key", "]", "=", "array", "(", "\"type\"", "=>", "$", "this", "->", "guessType", "(", "$", "value", ")", ",", ")", ";", "}", "$", "this", "->", "sendMeta", "(", "$", "metaData", ",", "$", "this", ")", ";", "$", "this", "->", "startInput", "(", "null", ")", ";", "foreach", "(", "$", "data", "as", "$", "row", ")", "{", "$", "this", "->", "next", "(", "$", "row", ")", ";", "}", "break", ";", "}", "}", "$", "this", "->", "endInput", "(", "null", ")", ";", "}" ]
Start piping data @return null
[ "Start", "piping", "data" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/datasources/ArrayDataSource.php#L110-L149
koolphp/koolreport
src/processes/CalculatedColumn.php
CalculatedColumn.onInit
protected function onInit() { $params = array(); foreach ($this->params as $cKey=>$cValue) { switch(gettype($cValue)) { case "string": case "number": case "object": $params[$cKey] = array( "exp"=>$cValue, "type"=>"number", ); break; case "array": if (!isset($cValue['exp'])) { $cValue['exp']="'no expression'"; } if (!isset($cValue['type'])) { $cValue['type']="unknown"; } $params[$cKey] = $cValue; break; } } $this->params = $params; }
php
protected function onInit() { $params = array(); foreach ($this->params as $cKey=>$cValue) { switch(gettype($cValue)) { case "string": case "number": case "object": $params[$cKey] = array( "exp"=>$cValue, "type"=>"number", ); break; case "array": if (!isset($cValue['exp'])) { $cValue['exp']="'no expression'"; } if (!isset($cValue['type'])) { $cValue['type']="unknown"; } $params[$cKey] = $cValue; break; } } $this->params = $params; }
[ "protected", "function", "onInit", "(", ")", "{", "$", "params", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "params", "as", "$", "cKey", "=>", "$", "cValue", ")", "{", "switch", "(", "gettype", "(", "$", "cValue", ")", ")", "{", "case", "\"string\"", ":", "case", "\"number\"", ":", "case", "\"object\"", ":", "$", "params", "[", "$", "cKey", "]", "=", "array", "(", "\"exp\"", "=>", "$", "cValue", ",", "\"type\"", "=>", "\"number\"", ",", ")", ";", "break", ";", "case", "\"array\"", ":", "if", "(", "!", "isset", "(", "$", "cValue", "[", "'exp'", "]", ")", ")", "{", "$", "cValue", "[", "'exp'", "]", "=", "\"'no expression'\"", ";", "}", "if", "(", "!", "isset", "(", "$", "cValue", "[", "'type'", "]", ")", ")", "{", "$", "cValue", "[", "'type'", "]", "=", "\"unknown\"", ";", "}", "$", "params", "[", "$", "cKey", "]", "=", "$", "cValue", ";", "break", ";", "}", "}", "$", "this", "->", "params", "=", "$", "params", ";", "}" ]
Process initiation @return null
[ "Process", "initiation" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/processes/CalculatedColumn.php#L66-L92
koolphp/koolreport
src/processes/CalculatedColumn.php
CalculatedColumn.onMetaReceived
protected function onMetaReceived($metaData) { foreach ($this->params as $cKey=>$cValue) { unset($cValue["exp"]); $metaData["columns"][$cKey] = $cValue; } return $metaData; }
php
protected function onMetaReceived($metaData) { foreach ($this->params as $cKey=>$cValue) { unset($cValue["exp"]); $metaData["columns"][$cKey] = $cValue; } return $metaData; }
[ "protected", "function", "onMetaReceived", "(", "$", "metaData", ")", "{", "foreach", "(", "$", "this", "->", "params", "as", "$", "cKey", "=>", "$", "cValue", ")", "{", "unset", "(", "$", "cValue", "[", "\"exp\"", "]", ")", ";", "$", "metaData", "[", "\"columns\"", "]", "[", "$", "cKey", "]", "=", "$", "cValue", ";", "}", "return", "$", "metaData", ";", "}" ]
Handle on meta received @param array $metaData The meta data @return array New meta data
[ "Handle", "on", "meta", "received" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/processes/CalculatedColumn.php#L101-L108
koolphp/koolreport
src/processes/CalculatedColumn.php
CalculatedColumn.onInput
protected function onInput($data) { // print_r($data); $this->rowNum++; foreach ($this->params as $cKey=>$cValue) { switch(gettype($cValue["exp"])) { case "string": $expression = $cValue["exp"]; // echo $expression . ' || '; foreach ($data as $k=>$v) { if (is_string($v) || is_numeric($v)) { $expression = str_replace("{".$k."}", $v, $expression); } } //predefined row $expression = str_replace("{#}", $this->rowNum, $expression); // echo $expression . ' <br> '; eval('$data[$cKey]='.$expression.';'); break; case "object": $function = $cValue["exp"]; $data[$cKey] = $function($data); break; } } $this->next($data); }
php
protected function onInput($data) { // print_r($data); $this->rowNum++; foreach ($this->params as $cKey=>$cValue) { switch(gettype($cValue["exp"])) { case "string": $expression = $cValue["exp"]; // echo $expression . ' || '; foreach ($data as $k=>$v) { if (is_string($v) || is_numeric($v)) { $expression = str_replace("{".$k."}", $v, $expression); } } //predefined row $expression = str_replace("{#}", $this->rowNum, $expression); // echo $expression . ' <br> '; eval('$data[$cKey]='.$expression.';'); break; case "object": $function = $cValue["exp"]; $data[$cKey] = $function($data); break; } } $this->next($data); }
[ "protected", "function", "onInput", "(", "$", "data", ")", "{", "// print_r($data);", "$", "this", "->", "rowNum", "++", ";", "foreach", "(", "$", "this", "->", "params", "as", "$", "cKey", "=>", "$", "cValue", ")", "{", "switch", "(", "gettype", "(", "$", "cValue", "[", "\"exp\"", "]", ")", ")", "{", "case", "\"string\"", ":", "$", "expression", "=", "$", "cValue", "[", "\"exp\"", "]", ";", "// echo $expression . ' || ';", "foreach", "(", "$", "data", "as", "$", "k", "=>", "$", "v", ")", "{", "if", "(", "is_string", "(", "$", "v", ")", "||", "is_numeric", "(", "$", "v", ")", ")", "{", "$", "expression", "=", "str_replace", "(", "\"{\"", ".", "$", "k", ".", "\"}\"", ",", "$", "v", ",", "$", "expression", ")", ";", "}", "}", "//predefined row", "$", "expression", "=", "str_replace", "(", "\"{#}\"", ",", "$", "this", "->", "rowNum", ",", "$", "expression", ")", ";", "// echo $expression . ' <br> ';", "eval", "(", "'$data[$cKey]='", ".", "$", "expression", ".", "';'", ")", ";", "break", ";", "case", "\"object\"", ":", "$", "function", "=", "$", "cValue", "[", "\"exp\"", "]", ";", "$", "data", "[", "$", "cKey", "]", "=", "$", "function", "(", "$", "data", ")", ";", "break", ";", "}", "}", "$", "this", "->", "next", "(", "$", "data", ")", ";", "}" ]
Handle on data input @param array $data The row data @return null
[ "Handle", "on", "data", "input" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/processes/CalculatedColumn.php#L117-L145
koolphp/koolreport
src/processes/Map.php
Map.onInit
public function onInit() { $func = Util::get($this->params, '{init}', null); if (is_callable($func)) { $this->mapState = $func($data); } }
php
public function onInit() { $func = Util::get($this->params, '{init}', null); if (is_callable($func)) { $this->mapState = $func($data); } }
[ "public", "function", "onInit", "(", ")", "{", "$", "func", "=", "Util", "::", "get", "(", "$", "this", "->", "params", ",", "'{init}'", ",", "null", ")", ";", "if", "(", "is_callable", "(", "$", "func", ")", ")", "{", "$", "this", "->", "mapState", "=", "$", "func", "(", "$", "data", ")", ";", "}", "}" ]
Handle on initiation @return null
[ "Handle", "on", "initiation" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/processes/Map.php#L64-L70
koolphp/koolreport
src/processes/Map.php
Map.receiveMeta
public function receiveMeta($metaData, $source) { $this->streamingSource = $source; $this->newMeta = $this->metaData = $metaData; $func = Util::get($this->params, '{meta}', null); if (is_callable($func)) { $this->newMeta = $func($metaData); } }
php
public function receiveMeta($metaData, $source) { $this->streamingSource = $source; $this->newMeta = $this->metaData = $metaData; $func = Util::get($this->params, '{meta}', null); if (is_callable($func)) { $this->newMeta = $func($metaData); } }
[ "public", "function", "receiveMeta", "(", "$", "metaData", ",", "$", "source", ")", "{", "$", "this", "->", "streamingSource", "=", "$", "source", ";", "$", "this", "->", "newMeta", "=", "$", "this", "->", "metaData", "=", "$", "metaData", ";", "$", "func", "=", "Util", "::", "get", "(", "$", "this", "->", "params", ",", "'{meta}'", ",", "null", ")", ";", "if", "(", "is_callable", "(", "$", "func", ")", ")", "{", "$", "this", "->", "newMeta", "=", "$", "func", "(", "$", "metaData", ")", ";", "}", "}" ]
Handle on data recieved @param array $metaData Metadata received @param Node $source The source sending data @return null
[ "Handle", "on", "data", "recieved" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/processes/Map.php#L80-L88
koolphp/koolreport
src/processes/Map.php
Map.to2DArray
protected function to2DArray($arr) { if (empty($arr) || !is_array($arr)) { return []; } if (count($arr) == count($arr, COUNT_RECURSIVE)) { return [$arr]; } return $arr; }
php
protected function to2DArray($arr) { if (empty($arr) || !is_array($arr)) { return []; } if (count($arr) == count($arr, COUNT_RECURSIVE)) { return [$arr]; } return $arr; }
[ "protected", "function", "to2DArray", "(", "$", "arr", ")", "{", "if", "(", "empty", "(", "$", "arr", ")", "||", "!", "is_array", "(", "$", "arr", ")", ")", "{", "return", "[", "]", ";", "}", "if", "(", "count", "(", "$", "arr", ")", "==", "count", "(", "$", "arr", ",", "COUNT_RECURSIVE", ")", ")", "{", "return", "[", "$", "arr", "]", ";", "}", "return", "$", "arr", ";", "}" ]
Convert to 2D array @param array $arr The array @return array The coverted array
[ "Convert", "to", "2D", "array" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/processes/Map.php#L125-L134
koolphp/koolreport
src/processes/Map.php
Map.onInput
protected function onInput($row) { $func = Util::get($this->params, '{value}', null); if (is_callable($func)) { $return = $func( $row, $this->metaData, $this->index, $this->mapState ); if (is_array($return) && (array_key_exists('{rows}', $return) ||array_key_exists('{state}', $return)) ) { $newRows = Util::get($return, '{rows}', []); $this->mapState = Util::get($return, '{state}', $this->mapState); } else { $newRows = $return; } $newRows = $this->to2DArray($newRows); if (!$this->metaSent) { $colMetas = $this->newMeta['columns']; $newRow = Util::get($newRows, 0, []); foreach (array_keys($newRow) as $newCol) { if (!isset($colMetas[$newCol])) { $type = $this->guessType($newRow[$newCol]); $colMetas[$newCol] = ['type' => $type]; } } $this->newMeta['columns'] = $colMetas; $this->sendMeta($this->newMeta); $this->metaSent = true; } foreach ($newRows as $row) { $this->next($row); } } else { if (!$this->metaSent) { $this->sendMeta($this->newMeta); $this->metaSent = true; } $this->next($row); } $this->index++; }
php
protected function onInput($row) { $func = Util::get($this->params, '{value}', null); if (is_callable($func)) { $return = $func( $row, $this->metaData, $this->index, $this->mapState ); if (is_array($return) && (array_key_exists('{rows}', $return) ||array_key_exists('{state}', $return)) ) { $newRows = Util::get($return, '{rows}', []); $this->mapState = Util::get($return, '{state}', $this->mapState); } else { $newRows = $return; } $newRows = $this->to2DArray($newRows); if (!$this->metaSent) { $colMetas = $this->newMeta['columns']; $newRow = Util::get($newRows, 0, []); foreach (array_keys($newRow) as $newCol) { if (!isset($colMetas[$newCol])) { $type = $this->guessType($newRow[$newCol]); $colMetas[$newCol] = ['type' => $type]; } } $this->newMeta['columns'] = $colMetas; $this->sendMeta($this->newMeta); $this->metaSent = true; } foreach ($newRows as $row) { $this->next($row); } } else { if (!$this->metaSent) { $this->sendMeta($this->newMeta); $this->metaSent = true; } $this->next($row); } $this->index++; }
[ "protected", "function", "onInput", "(", "$", "row", ")", "{", "$", "func", "=", "Util", "::", "get", "(", "$", "this", "->", "params", ",", "'{value}'", ",", "null", ")", ";", "if", "(", "is_callable", "(", "$", "func", ")", ")", "{", "$", "return", "=", "$", "func", "(", "$", "row", ",", "$", "this", "->", "metaData", ",", "$", "this", "->", "index", ",", "$", "this", "->", "mapState", ")", ";", "if", "(", "is_array", "(", "$", "return", ")", "&&", "(", "array_key_exists", "(", "'{rows}'", ",", "$", "return", ")", "||", "array_key_exists", "(", "'{state}'", ",", "$", "return", ")", ")", ")", "{", "$", "newRows", "=", "Util", "::", "get", "(", "$", "return", ",", "'{rows}'", ",", "[", "]", ")", ";", "$", "this", "->", "mapState", "=", "Util", "::", "get", "(", "$", "return", ",", "'{state}'", ",", "$", "this", "->", "mapState", ")", ";", "}", "else", "{", "$", "newRows", "=", "$", "return", ";", "}", "$", "newRows", "=", "$", "this", "->", "to2DArray", "(", "$", "newRows", ")", ";", "if", "(", "!", "$", "this", "->", "metaSent", ")", "{", "$", "colMetas", "=", "$", "this", "->", "newMeta", "[", "'columns'", "]", ";", "$", "newRow", "=", "Util", "::", "get", "(", "$", "newRows", ",", "0", ",", "[", "]", ")", ";", "foreach", "(", "array_keys", "(", "$", "newRow", ")", "as", "$", "newCol", ")", "{", "if", "(", "!", "isset", "(", "$", "colMetas", "[", "$", "newCol", "]", ")", ")", "{", "$", "type", "=", "$", "this", "->", "guessType", "(", "$", "newRow", "[", "$", "newCol", "]", ")", ";", "$", "colMetas", "[", "$", "newCol", "]", "=", "[", "'type'", "=>", "$", "type", "]", ";", "}", "}", "$", "this", "->", "newMeta", "[", "'columns'", "]", "=", "$", "colMetas", ";", "$", "this", "->", "sendMeta", "(", "$", "this", "->", "newMeta", ")", ";", "$", "this", "->", "metaSent", "=", "true", ";", "}", "foreach", "(", "$", "newRows", "as", "$", "row", ")", "{", "$", "this", "->", "next", "(", "$", "row", ")", ";", "}", "}", "else", "{", "if", "(", "!", "$", "this", "->", "metaSent", ")", "{", "$", "this", "->", "sendMeta", "(", "$", "this", "->", "newMeta", ")", ";", "$", "this", "->", "metaSent", "=", "true", ";", "}", "$", "this", "->", "next", "(", "$", "row", ")", ";", "}", "$", "this", "->", "index", "++", ";", "}" ]
Handle on data input @param array $row The input data row @return null
[ "Handle", "on", "data", "input" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/processes/Map.php#L143-L187
koolphp/koolreport
src/processes/Map.php
Map.endInput
public function endInput($source) { if (!$this->metaSent) { $this->sendMeta($this->newMeta); } $func = Util::get($this->params, '{end}', null); if (is_callable($func)) { $newRows = $func($this->index, $this->mapState); $newRows = $this->to2DArray($newRows); foreach ($newRows as $row) { $this->next($row); } } parent::endInput($source); }
php
public function endInput($source) { if (!$this->metaSent) { $this->sendMeta($this->newMeta); } $func = Util::get($this->params, '{end}', null); if (is_callable($func)) { $newRows = $func($this->index, $this->mapState); $newRows = $this->to2DArray($newRows); foreach ($newRows as $row) { $this->next($row); } } parent::endInput($source); }
[ "public", "function", "endInput", "(", "$", "source", ")", "{", "if", "(", "!", "$", "this", "->", "metaSent", ")", "{", "$", "this", "->", "sendMeta", "(", "$", "this", "->", "newMeta", ")", ";", "}", "$", "func", "=", "Util", "::", "get", "(", "$", "this", "->", "params", ",", "'{end}'", ",", "null", ")", ";", "if", "(", "is_callable", "(", "$", "func", ")", ")", "{", "$", "newRows", "=", "$", "func", "(", "$", "this", "->", "index", ",", "$", "this", "->", "mapState", ")", ";", "$", "newRows", "=", "$", "this", "->", "to2DArray", "(", "$", "newRows", ")", ";", "foreach", "(", "$", "newRows", "as", "$", "row", ")", "{", "$", "this", "->", "next", "(", "$", "row", ")", ";", "}", "}", "parent", "::", "endInput", "(", "$", "source", ")", ";", "}" ]
Handle on input end @param Node $source The source sending @return null
[ "Handle", "on", "input", "end" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/processes/Map.php#L196-L210
koolphp/koolreport
src/processes/Transpose.php
Transpose.onInputEnd
protected function onInputEnd() { //Send meta $countRow = count($this->data); $newMeta = array( "columns" => array(), ); for ($i = 0; $i <= $countRow; $i++) { $newMeta["columns"]["c$i"] = array("type" => "unknown"); } $newMeta["columns"]["c0"]["type"] = "string"; $this->sendMeta($newMeta); $keys = ($countRow > 0) ? array_keys($this->data[0]) : array_keys($this->metaData["columns"]); //Send each rows foreach ($keys as $cKey) { $row = array("c0" => isset($this->metaData["columns"][$cKey]["label"]) ? $this->metaData["columns"][$cKey]["label"] : $cKey); for ($i = 0; $i < $countRow; $i++) { $row["c" . ($i + 1)] = $this->data[$i][$cKey]; unset($this->data[$i][$cKey]); } $this->next($row); } }
php
protected function onInputEnd() { //Send meta $countRow = count($this->data); $newMeta = array( "columns" => array(), ); for ($i = 0; $i <= $countRow; $i++) { $newMeta["columns"]["c$i"] = array("type" => "unknown"); } $newMeta["columns"]["c0"]["type"] = "string"; $this->sendMeta($newMeta); $keys = ($countRow > 0) ? array_keys($this->data[0]) : array_keys($this->metaData["columns"]); //Send each rows foreach ($keys as $cKey) { $row = array("c0" => isset($this->metaData["columns"][$cKey]["label"]) ? $this->metaData["columns"][$cKey]["label"] : $cKey); for ($i = 0; $i < $countRow; $i++) { $row["c" . ($i + 1)] = $this->data[$i][$cKey]; unset($this->data[$i][$cKey]); } $this->next($row); } }
[ "protected", "function", "onInputEnd", "(", ")", "{", "//Send meta", "$", "countRow", "=", "count", "(", "$", "this", "->", "data", ")", ";", "$", "newMeta", "=", "array", "(", "\"columns\"", "=>", "array", "(", ")", ",", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<=", "$", "countRow", ";", "$", "i", "++", ")", "{", "$", "newMeta", "[", "\"columns\"", "]", "[", "\"c$i\"", "]", "=", "array", "(", "\"type\"", "=>", "\"unknown\"", ")", ";", "}", "$", "newMeta", "[", "\"columns\"", "]", "[", "\"c0\"", "]", "[", "\"type\"", "]", "=", "\"string\"", ";", "$", "this", "->", "sendMeta", "(", "$", "newMeta", ")", ";", "$", "keys", "=", "(", "$", "countRow", ">", "0", ")", "?", "array_keys", "(", "$", "this", "->", "data", "[", "0", "]", ")", ":", "array_keys", "(", "$", "this", "->", "metaData", "[", "\"columns\"", "]", ")", ";", "//Send each rows", "foreach", "(", "$", "keys", "as", "$", "cKey", ")", "{", "$", "row", "=", "array", "(", "\"c0\"", "=>", "isset", "(", "$", "this", "->", "metaData", "[", "\"columns\"", "]", "[", "$", "cKey", "]", "[", "\"label\"", "]", ")", "?", "$", "this", "->", "metaData", "[", "\"columns\"", "]", "[", "$", "cKey", "]", "[", "\"label\"", "]", ":", "$", "cKey", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "countRow", ";", "$", "i", "++", ")", "{", "$", "row", "[", "\"c\"", ".", "(", "$", "i", "+", "1", ")", "]", "=", "$", "this", "->", "data", "[", "$", "i", "]", "[", "$", "cKey", "]", ";", "unset", "(", "$", "this", "->", "data", "[", "$", "i", "]", "[", "$", "cKey", "]", ")", ";", "}", "$", "this", "->", "next", "(", "$", "row", ")", ";", "}", "}" ]
Handle on data input end @return null
[ "Handle", "on", "data", "input", "end" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/processes/Transpose.php#L81-L107
koolphp/koolreport
src/processes/NumberBucket.php
NumberBucket.onMetaReceived
protected function onMetaReceived($metaData) { foreach ($this->params as $cName => $cParam) { $metaData["columns"][$cName] = array( "type" => "string", ); $this->params[$cName]["formatString"] = Utility::get($cParam, "formatString", "{from} - {to}"); $this->params[$cName]["decimals"] = Utility::get($cParam, "decimals", 0); $this->params[$cName]["thousandSeparator"] = Utility::get($cParam, "thousandSeparator", ","); $this->params[$cName]["decimalPoint"] = Utility::get($cParam, "decimalPoint", "."); $this->params[$cName]["prefix"] = Utility::get($cParam, "prefix", ""); $this->params[$cName]["suffix"] = Utility::get($cParam, "suffix", ""); } return $metaData; }
php
protected function onMetaReceived($metaData) { foreach ($this->params as $cName => $cParam) { $metaData["columns"][$cName] = array( "type" => "string", ); $this->params[$cName]["formatString"] = Utility::get($cParam, "formatString", "{from} - {to}"); $this->params[$cName]["decimals"] = Utility::get($cParam, "decimals", 0); $this->params[$cName]["thousandSeparator"] = Utility::get($cParam, "thousandSeparator", ","); $this->params[$cName]["decimalPoint"] = Utility::get($cParam, "decimalPoint", "."); $this->params[$cName]["prefix"] = Utility::get($cParam, "prefix", ""); $this->params[$cName]["suffix"] = Utility::get($cParam, "suffix", ""); } return $metaData; }
[ "protected", "function", "onMetaReceived", "(", "$", "metaData", ")", "{", "foreach", "(", "$", "this", "->", "params", "as", "$", "cName", "=>", "$", "cParam", ")", "{", "$", "metaData", "[", "\"columns\"", "]", "[", "$", "cName", "]", "=", "array", "(", "\"type\"", "=>", "\"string\"", ",", ")", ";", "$", "this", "->", "params", "[", "$", "cName", "]", "[", "\"formatString\"", "]", "=", "Utility", "::", "get", "(", "$", "cParam", ",", "\"formatString\"", ",", "\"{from} - {to}\"", ")", ";", "$", "this", "->", "params", "[", "$", "cName", "]", "[", "\"decimals\"", "]", "=", "Utility", "::", "get", "(", "$", "cParam", ",", "\"decimals\"", ",", "0", ")", ";", "$", "this", "->", "params", "[", "$", "cName", "]", "[", "\"thousandSeparator\"", "]", "=", "Utility", "::", "get", "(", "$", "cParam", ",", "\"thousandSeparator\"", ",", "\",\"", ")", ";", "$", "this", "->", "params", "[", "$", "cName", "]", "[", "\"decimalPoint\"", "]", "=", "Utility", "::", "get", "(", "$", "cParam", ",", "\"decimalPoint\"", ",", "\".\"", ")", ";", "$", "this", "->", "params", "[", "$", "cName", "]", "[", "\"prefix\"", "]", "=", "Utility", "::", "get", "(", "$", "cParam", ",", "\"prefix\"", ",", "\"\"", ")", ";", "$", "this", "->", "params", "[", "$", "cName", "]", "[", "\"suffix\"", "]", "=", "Utility", "::", "get", "(", "$", "cParam", ",", "\"suffix\"", ",", "\"\"", ")", ";", "}", "return", "$", "metaData", ";", "}" ]
Handle on meta received @param array $metaData The meta data @return array New meta data
[ "Handle", "on", "meta", "received" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/processes/NumberBucket.php#L52-L66
koolphp/koolreport
src/processes/NumberBucket.php
NumberBucket.onInput
protected function onInput($data) { //Process data here foreach ($this->params as $cName => $cParam) { $numberFormat = array_merge($cParam, array("type" => "number")); //print_r($numberFormat); $from = Utility::format(floor($data[$cName] / $cParam["step"]) * $cParam["step"], $numberFormat); $to = Utility::format(floor($data[$cName] / $cParam["step"] + 1) * $cParam["step"], $numberFormat); $data[$cName] = Utility::strReplace( $cParam["formatString"], array( "{from}" => $from, "{to}" => $to, ) ); } $this->next($data); }
php
protected function onInput($data) { //Process data here foreach ($this->params as $cName => $cParam) { $numberFormat = array_merge($cParam, array("type" => "number")); //print_r($numberFormat); $from = Utility::format(floor($data[$cName] / $cParam["step"]) * $cParam["step"], $numberFormat); $to = Utility::format(floor($data[$cName] / $cParam["step"] + 1) * $cParam["step"], $numberFormat); $data[$cName] = Utility::strReplace( $cParam["formatString"], array( "{from}" => $from, "{to}" => $to, ) ); } $this->next($data); }
[ "protected", "function", "onInput", "(", "$", "data", ")", "{", "//Process data here", "foreach", "(", "$", "this", "->", "params", "as", "$", "cName", "=>", "$", "cParam", ")", "{", "$", "numberFormat", "=", "array_merge", "(", "$", "cParam", ",", "array", "(", "\"type\"", "=>", "\"number\"", ")", ")", ";", "//print_r($numberFormat);", "$", "from", "=", "Utility", "::", "format", "(", "floor", "(", "$", "data", "[", "$", "cName", "]", "/", "$", "cParam", "[", "\"step\"", "]", ")", "*", "$", "cParam", "[", "\"step\"", "]", ",", "$", "numberFormat", ")", ";", "$", "to", "=", "Utility", "::", "format", "(", "floor", "(", "$", "data", "[", "$", "cName", "]", "/", "$", "cParam", "[", "\"step\"", "]", "+", "1", ")", "*", "$", "cParam", "[", "\"step\"", "]", ",", "$", "numberFormat", ")", ";", "$", "data", "[", "$", "cName", "]", "=", "Utility", "::", "strReplace", "(", "$", "cParam", "[", "\"formatString\"", "]", ",", "array", "(", "\"{from}\"", "=>", "$", "from", ",", "\"{to}\"", "=>", "$", "to", ",", ")", ")", ";", "}", "$", "this", "->", "next", "(", "$", "data", ")", ";", "}" ]
Handle on data input @param array $data The input data row @return null
[ "Handle", "on", "data", "input" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/processes/NumberBucket.php#L75-L93
koolphp/koolreport
src/processes/StringCase.php
StringCase.onInit
protected function onInit() { foreach ($this->params as $key => $value) { $columnList = explode(",", $value); foreach ($columnList as $k => $v) { $columnList[$k] = trim($v); } $this->params[$key] = $columnList; } }
php
protected function onInit() { foreach ($this->params as $key => $value) { $columnList = explode(",", $value); foreach ($columnList as $k => $v) { $columnList[$k] = trim($v); } $this->params[$key] = $columnList; } }
[ "protected", "function", "onInit", "(", ")", "{", "foreach", "(", "$", "this", "->", "params", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "columnList", "=", "explode", "(", "\",\"", ",", "$", "value", ")", ";", "foreach", "(", "$", "columnList", "as", "$", "k", "=>", "$", "v", ")", "{", "$", "columnList", "[", "$", "k", "]", "=", "trim", "(", "$", "v", ")", ";", "}", "$", "this", "->", "params", "[", "$", "key", "]", "=", "$", "columnList", ";", "}", "}" ]
Handle on initiation @return null
[ "Handle", "on", "initiation" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/processes/StringCase.php#L44-L53
koolphp/koolreport
src/processes/StringCase.php
StringCase.onInput
protected function onInput($data) { //Process data here foreach ($this->params as $func => $columns) { switch ($func) { case "upper": foreach ($columns as $col) { $data[$col] = strtoupper($data[$col]); } break; case "lower": foreach ($columns as $col) { $data[$col] = strtolower($data[$col]); } break; case "first-cap": foreach ($columns as $col) { $data[$col] = ucfirst($data[$col]); } break; case "all-cap": foreach ($columns as $col) { $data[$col] = ucwords($data[$col]); } break; } } $this->next($data); }
php
protected function onInput($data) { //Process data here foreach ($this->params as $func => $columns) { switch ($func) { case "upper": foreach ($columns as $col) { $data[$col] = strtoupper($data[$col]); } break; case "lower": foreach ($columns as $col) { $data[$col] = strtolower($data[$col]); } break; case "first-cap": foreach ($columns as $col) { $data[$col] = ucfirst($data[$col]); } break; case "all-cap": foreach ($columns as $col) { $data[$col] = ucwords($data[$col]); } break; } } $this->next($data); }
[ "protected", "function", "onInput", "(", "$", "data", ")", "{", "//Process data here", "foreach", "(", "$", "this", "->", "params", "as", "$", "func", "=>", "$", "columns", ")", "{", "switch", "(", "$", "func", ")", "{", "case", "\"upper\"", ":", "foreach", "(", "$", "columns", "as", "$", "col", ")", "{", "$", "data", "[", "$", "col", "]", "=", "strtoupper", "(", "$", "data", "[", "$", "col", "]", ")", ";", "}", "break", ";", "case", "\"lower\"", ":", "foreach", "(", "$", "columns", "as", "$", "col", ")", "{", "$", "data", "[", "$", "col", "]", "=", "strtolower", "(", "$", "data", "[", "$", "col", "]", ")", ";", "}", "break", ";", "case", "\"first-cap\"", ":", "foreach", "(", "$", "columns", "as", "$", "col", ")", "{", "$", "data", "[", "$", "col", "]", "=", "ucfirst", "(", "$", "data", "[", "$", "col", "]", ")", ";", "}", "break", ";", "case", "\"all-cap\"", ":", "foreach", "(", "$", "columns", "as", "$", "col", ")", "{", "$", "data", "[", "$", "col", "]", "=", "ucwords", "(", "$", "data", "[", "$", "col", "]", ")", ";", "}", "break", ";", "}", "}", "$", "this", "->", "next", "(", "$", "data", ")", ";", "}" ]
Handle on data input @param array $data The input data row @return null
[ "Handle", "on", "data", "input" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/processes/StringCase.php#L62-L90
koolphp/koolreport
src/processes/RemoveColumn.php
RemoveColumn.onInput
protected function onInput($data) { //Process data here foreach ($this->params as $column) { unset($data[$column]); } $this->next($data); }
php
protected function onInput($data) { //Process data here foreach ($this->params as $column) { unset($data[$column]); } $this->next($data); }
[ "protected", "function", "onInput", "(", "$", "data", ")", "{", "//Process data here", "foreach", "(", "$", "this", "->", "params", "as", "$", "column", ")", "{", "unset", "(", "$", "data", "[", "$", "column", "]", ")", ";", "}", "$", "this", "->", "next", "(", "$", "data", ")", ";", "}" ]
Handle on data input @param array $data The input data row @return null
[ "Handle", "on", "data", "input" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/processes/RemoveColumn.php#L59-L66
koolphp/koolreport
src/datasources/SQLSRVDataSource.php
SQLSRVDataSource.onInit
protected function onInit() { $host = Util::get($this->params, "host", "");//host\instanceName $username = Util::get($this->params, "username", ""); $password = Util::get($this->params, "password", ""); $dbname = Util::get($this->params, "dbname", ""); $returnDatesAsStrings = Util::get($this->params, "returnDatesAsStrings", true); $charset = Util::get($this->params, "charset", 'utf-8'); $connectionInfo = array( "Database"=>$dbname, "UID"=>$username, "PWD"=>$password, "ReturnDatesAsStrings" => $returnDatesAsStrings, "CharacterSet" => $charset ); $key = md5($host.$username.$password.$dbname); if (isset(SQLSRVDataSource::$connections[$key])) { $this->connection = SQLSRVDataSource::$connections[$key]; } else { $conn = sqlsrv_connect($host, $connectionInfo); if ($conn) { $this->connection = $conn; } else { throw new \Exception( "Connection could not be established: " .print_r(sqlsrv_errors(), true) ); } SQLSRVDataSource::$connections[$key] = $this->connection; } }
php
protected function onInit() { $host = Util::get($this->params, "host", "");//host\instanceName $username = Util::get($this->params, "username", ""); $password = Util::get($this->params, "password", ""); $dbname = Util::get($this->params, "dbname", ""); $returnDatesAsStrings = Util::get($this->params, "returnDatesAsStrings", true); $charset = Util::get($this->params, "charset", 'utf-8'); $connectionInfo = array( "Database"=>$dbname, "UID"=>$username, "PWD"=>$password, "ReturnDatesAsStrings" => $returnDatesAsStrings, "CharacterSet" => $charset ); $key = md5($host.$username.$password.$dbname); if (isset(SQLSRVDataSource::$connections[$key])) { $this->connection = SQLSRVDataSource::$connections[$key]; } else { $conn = sqlsrv_connect($host, $connectionInfo); if ($conn) { $this->connection = $conn; } else { throw new \Exception( "Connection could not be established: " .print_r(sqlsrv_errors(), true) ); } SQLSRVDataSource::$connections[$key] = $this->connection; } }
[ "protected", "function", "onInit", "(", ")", "{", "$", "host", "=", "Util", "::", "get", "(", "$", "this", "->", "params", ",", "\"host\"", ",", "\"\"", ")", ";", "//host\\instanceName", "$", "username", "=", "Util", "::", "get", "(", "$", "this", "->", "params", ",", "\"username\"", ",", "\"\"", ")", ";", "$", "password", "=", "Util", "::", "get", "(", "$", "this", "->", "params", ",", "\"password\"", ",", "\"\"", ")", ";", "$", "dbname", "=", "Util", "::", "get", "(", "$", "this", "->", "params", ",", "\"dbname\"", ",", "\"\"", ")", ";", "$", "returnDatesAsStrings", "=", "Util", "::", "get", "(", "$", "this", "->", "params", ",", "\"returnDatesAsStrings\"", ",", "true", ")", ";", "$", "charset", "=", "Util", "::", "get", "(", "$", "this", "->", "params", ",", "\"charset\"", ",", "'utf-8'", ")", ";", "$", "connectionInfo", "=", "array", "(", "\"Database\"", "=>", "$", "dbname", ",", "\"UID\"", "=>", "$", "username", ",", "\"PWD\"", "=>", "$", "password", ",", "\"ReturnDatesAsStrings\"", "=>", "$", "returnDatesAsStrings", ",", "\"CharacterSet\"", "=>", "$", "charset", ")", ";", "$", "key", "=", "md5", "(", "$", "host", ".", "$", "username", ".", "$", "password", ".", "$", "dbname", ")", ";", "if", "(", "isset", "(", "SQLSRVDataSource", "::", "$", "connections", "[", "$", "key", "]", ")", ")", "{", "$", "this", "->", "connection", "=", "SQLSRVDataSource", "::", "$", "connections", "[", "$", "key", "]", ";", "}", "else", "{", "$", "conn", "=", "sqlsrv_connect", "(", "$", "host", ",", "$", "connectionInfo", ")", ";", "if", "(", "$", "conn", ")", "{", "$", "this", "->", "connection", "=", "$", "conn", ";", "}", "else", "{", "throw", "new", "\\", "Exception", "(", "\"Connection could not be established: \"", ".", "print_r", "(", "sqlsrv_errors", "(", ")", ",", "true", ")", ")", ";", "}", "SQLSRVDataSource", "::", "$", "connections", "[", "$", "key", "]", "=", "$", "this", "->", "connection", ";", "}", "}" ]
Datasource initiation @return null
[ "Datasource", "initiation" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/datasources/SQLSRVDataSource.php#L97-L128
koolphp/koolreport
src/datasources/SQLSRVDataSource.php
SQLSRVDataSource.escape
protected function escape($str) { if (is_string($str) OR (is_object($str) && method_exists($str, '__toString'))) { return "'".$this->escapeStr($str)."'"; } elseif (is_bool($str)) { return ($str === false) ? 0 : 1; } elseif ($str === null) { return 'NULL'; } return $str; }
php
protected function escape($str) { if (is_string($str) OR (is_object($str) && method_exists($str, '__toString'))) { return "'".$this->escapeStr($str)."'"; } elseif (is_bool($str)) { return ($str === false) ? 0 : 1; } elseif ($str === null) { return 'NULL'; } return $str; }
[ "protected", "function", "escape", "(", "$", "str", ")", "{", "if", "(", "is_string", "(", "$", "str", ")", "OR", "(", "is_object", "(", "$", "str", ")", "&&", "method_exists", "(", "$", "str", ",", "'__toString'", ")", ")", ")", "{", "return", "\"'\"", ".", "$", "this", "->", "escapeStr", "(", "$", "str", ")", ".", "\"'\"", ";", "}", "elseif", "(", "is_bool", "(", "$", "str", ")", ")", "{", "return", "(", "$", "str", "===", "false", ")", "?", "0", ":", "1", ";", "}", "elseif", "(", "$", "str", "===", "null", ")", "{", "return", "'NULL'", ";", "}", "return", "$", "str", ";", "}" ]
Escape value for SQL safe @param string $str The string need to be escape @return null
[ "Escape", "value", "for", "SQL", "safe" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/datasources/SQLSRVDataSource.php#L250-L260
koolphp/koolreport
src/datasources/SQLSRVDataSource.php
SQLSRVDataSource.start
public function start() { // echo "query=" . $this->query . '<br>'; $metaData = array("columns"=>array()); if ($this->countTotal) { $query = $this->bindParams($this->totalQuery, $this->sqlParams); $stmt = sqlsrv_query($this->connection, $query); if ($stmt === false) { die(print_r(sqlsrv_errors(), true)); } $row = sqlsrv_fetch_array($stmt); $total = $row[0]; $metaData['totalRecords'] = $total; } if ($this->countFilter) { $query = $this->bindParams($this->filterQuery, $this->sqlParams); $stmt = sqlsrv_query($this->connection, $query); if ($stmt === false) { die(print_r(sqlsrv_errors(), true)); } $row = sqlsrv_fetch_array($stmt); $total = $row[0]; $metaData['filterRecords'] = $total; } $query = $this->bindParams($this->query, $this->sqlParams); $stmt = sqlsrv_query($this->connection, $query); if ($stmt === false) { die(print_r(sqlsrv_errors(), true)); } $finfo = sqlsrv_field_metadata($stmt); $numcols = count($finfo); for ($i=0; $i<$numcols; $i++) { $type = $this->mapFieldTypeToBindType($finfo[$i]['Type']); $metaData["columns"][$finfo[$i]['Name']] = array( "type"=>$type, ); switch($type) { case "datetime": $metaData["columns"][$finfo[$i]['Name']]["format"] = "Y-m-d H:i:s"; break; case "date": $metaData["columns"][$finfo[$i]['Name']]["format"] = "Y-m-d"; break; } } $this->sendMeta($metaData, $this); $this->startInput(null); while ( $row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC) ) { $this->next($row, $this); } $this->endInput(null); }
php
public function start() { // echo "query=" . $this->query . '<br>'; $metaData = array("columns"=>array()); if ($this->countTotal) { $query = $this->bindParams($this->totalQuery, $this->sqlParams); $stmt = sqlsrv_query($this->connection, $query); if ($stmt === false) { die(print_r(sqlsrv_errors(), true)); } $row = sqlsrv_fetch_array($stmt); $total = $row[0]; $metaData['totalRecords'] = $total; } if ($this->countFilter) { $query = $this->bindParams($this->filterQuery, $this->sqlParams); $stmt = sqlsrv_query($this->connection, $query); if ($stmt === false) { die(print_r(sqlsrv_errors(), true)); } $row = sqlsrv_fetch_array($stmt); $total = $row[0]; $metaData['filterRecords'] = $total; } $query = $this->bindParams($this->query, $this->sqlParams); $stmt = sqlsrv_query($this->connection, $query); if ($stmt === false) { die(print_r(sqlsrv_errors(), true)); } $finfo = sqlsrv_field_metadata($stmt); $numcols = count($finfo); for ($i=0; $i<$numcols; $i++) { $type = $this->mapFieldTypeToBindType($finfo[$i]['Type']); $metaData["columns"][$finfo[$i]['Name']] = array( "type"=>$type, ); switch($type) { case "datetime": $metaData["columns"][$finfo[$i]['Name']]["format"] = "Y-m-d H:i:s"; break; case "date": $metaData["columns"][$finfo[$i]['Name']]["format"] = "Y-m-d"; break; } } $this->sendMeta($metaData, $this); $this->startInput(null); while ( $row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC) ) { $this->next($row, $this); } $this->endInput(null); }
[ "public", "function", "start", "(", ")", "{", "// echo \"query=\" . $this->query . '<br>';", "$", "metaData", "=", "array", "(", "\"columns\"", "=>", "array", "(", ")", ")", ";", "if", "(", "$", "this", "->", "countTotal", ")", "{", "$", "query", "=", "$", "this", "->", "bindParams", "(", "$", "this", "->", "totalQuery", ",", "$", "this", "->", "sqlParams", ")", ";", "$", "stmt", "=", "sqlsrv_query", "(", "$", "this", "->", "connection", ",", "$", "query", ")", ";", "if", "(", "$", "stmt", "===", "false", ")", "{", "die", "(", "print_r", "(", "sqlsrv_errors", "(", ")", ",", "true", ")", ")", ";", "}", "$", "row", "=", "sqlsrv_fetch_array", "(", "$", "stmt", ")", ";", "$", "total", "=", "$", "row", "[", "0", "]", ";", "$", "metaData", "[", "'totalRecords'", "]", "=", "$", "total", ";", "}", "if", "(", "$", "this", "->", "countFilter", ")", "{", "$", "query", "=", "$", "this", "->", "bindParams", "(", "$", "this", "->", "filterQuery", ",", "$", "this", "->", "sqlParams", ")", ";", "$", "stmt", "=", "sqlsrv_query", "(", "$", "this", "->", "connection", ",", "$", "query", ")", ";", "if", "(", "$", "stmt", "===", "false", ")", "{", "die", "(", "print_r", "(", "sqlsrv_errors", "(", ")", ",", "true", ")", ")", ";", "}", "$", "row", "=", "sqlsrv_fetch_array", "(", "$", "stmt", ")", ";", "$", "total", "=", "$", "row", "[", "0", "]", ";", "$", "metaData", "[", "'filterRecords'", "]", "=", "$", "total", ";", "}", "$", "query", "=", "$", "this", "->", "bindParams", "(", "$", "this", "->", "query", ",", "$", "this", "->", "sqlParams", ")", ";", "$", "stmt", "=", "sqlsrv_query", "(", "$", "this", "->", "connection", ",", "$", "query", ")", ";", "if", "(", "$", "stmt", "===", "false", ")", "{", "die", "(", "print_r", "(", "sqlsrv_errors", "(", ")", ",", "true", ")", ")", ";", "}", "$", "finfo", "=", "sqlsrv_field_metadata", "(", "$", "stmt", ")", ";", "$", "numcols", "=", "count", "(", "$", "finfo", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "numcols", ";", "$", "i", "++", ")", "{", "$", "type", "=", "$", "this", "->", "mapFieldTypeToBindType", "(", "$", "finfo", "[", "$", "i", "]", "[", "'Type'", "]", ")", ";", "$", "metaData", "[", "\"columns\"", "]", "[", "$", "finfo", "[", "$", "i", "]", "[", "'Name'", "]", "]", "=", "array", "(", "\"type\"", "=>", "$", "type", ",", ")", ";", "switch", "(", "$", "type", ")", "{", "case", "\"datetime\"", ":", "$", "metaData", "[", "\"columns\"", "]", "[", "$", "finfo", "[", "$", "i", "]", "[", "'Name'", "]", "]", "[", "\"format\"", "]", "=", "\"Y-m-d H:i:s\"", ";", "break", ";", "case", "\"date\"", ":", "$", "metaData", "[", "\"columns\"", "]", "[", "$", "finfo", "[", "$", "i", "]", "[", "'Name'", "]", "]", "[", "\"format\"", "]", "=", "\"Y-m-d\"", ";", "break", ";", "}", "}", "$", "this", "->", "sendMeta", "(", "$", "metaData", ",", "$", "this", ")", ";", "$", "this", "->", "startInput", "(", "null", ")", ";", "while", "(", "$", "row", "=", "sqlsrv_fetch_array", "(", "$", "stmt", ",", "SQLSRV_FETCH_ASSOC", ")", ")", "{", "$", "this", "->", "next", "(", "$", "row", ",", "$", "this", ")", ";", "}", "$", "this", "->", "endInput", "(", "null", ")", ";", "}" ]
Start piping data @return null
[ "Start", "piping", "data" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/datasources/SQLSRVDataSource.php#L319-L380
koolphp/koolreport
src/core/SubReport.php
SubReport.__constructSubReport
public function __constructSubReport() { $this->registerEvent( "OnInit", function () { $params = array_merge($this->params, $_POST); if (isset($params["@subReport"])) { $name = $params["@subReport"]; unset($params["@subReport"]); $settings = $this->settings(); $subReports = Utility::get($settings, "subReports"); $class = Utility::get($subReports, $name); if ($class!=null) { $params["@reportName"] = $name; $r = new $class($params); echo "<subreport-partial>"; $r->run()->render(); echo "</subreport-partial>"; } else { header("HTTP/1.1 404 Could not find [$name] sub report"); } exit; } } ); $this->registerEvent( "OnResourceInit", function () { $this->getResourceManager()->addScriptFileOnBegin( $this->getResourceManager()->publishAssetFolder( realpath(dirname(__FILE__)."/../clients/core") )."/KoolReport.subReport.js" ); } ); }
php
public function __constructSubReport() { $this->registerEvent( "OnInit", function () { $params = array_merge($this->params, $_POST); if (isset($params["@subReport"])) { $name = $params["@subReport"]; unset($params["@subReport"]); $settings = $this->settings(); $subReports = Utility::get($settings, "subReports"); $class = Utility::get($subReports, $name); if ($class!=null) { $params["@reportName"] = $name; $r = new $class($params); echo "<subreport-partial>"; $r->run()->render(); echo "</subreport-partial>"; } else { header("HTTP/1.1 404 Could not find [$name] sub report"); } exit; } } ); $this->registerEvent( "OnResourceInit", function () { $this->getResourceManager()->addScriptFileOnBegin( $this->getResourceManager()->publishAssetFolder( realpath(dirname(__FILE__)."/../clients/core") )."/KoolReport.subReport.js" ); } ); }
[ "public", "function", "__constructSubReport", "(", ")", "{", "$", "this", "->", "registerEvent", "(", "\"OnInit\"", ",", "function", "(", ")", "{", "$", "params", "=", "array_merge", "(", "$", "this", "->", "params", ",", "$", "_POST", ")", ";", "if", "(", "isset", "(", "$", "params", "[", "\"@subReport\"", "]", ")", ")", "{", "$", "name", "=", "$", "params", "[", "\"@subReport\"", "]", ";", "unset", "(", "$", "params", "[", "\"@subReport\"", "]", ")", ";", "$", "settings", "=", "$", "this", "->", "settings", "(", ")", ";", "$", "subReports", "=", "Utility", "::", "get", "(", "$", "settings", ",", "\"subReports\"", ")", ";", "$", "class", "=", "Utility", "::", "get", "(", "$", "subReports", ",", "$", "name", ")", ";", "if", "(", "$", "class", "!=", "null", ")", "{", "$", "params", "[", "\"@reportName\"", "]", "=", "$", "name", ";", "$", "r", "=", "new", "$", "class", "(", "$", "params", ")", ";", "echo", "\"<subreport-partial>\"", ";", "$", "r", "->", "run", "(", ")", "->", "render", "(", ")", ";", "echo", "\"</subreport-partial>\"", ";", "}", "else", "{", "header", "(", "\"HTTP/1.1 404 Could not find [$name] sub report\"", ")", ";", "}", "exit", ";", "}", "}", ")", ";", "$", "this", "->", "registerEvent", "(", "\"OnResourceInit\"", ",", "function", "(", ")", "{", "$", "this", "->", "getResourceManager", "(", ")", "->", "addScriptFileOnBegin", "(", "$", "this", "->", "getResourceManager", "(", ")", "->", "publishAssetFolder", "(", "realpath", "(", "dirname", "(", "__FILE__", ")", ".", "\"/../clients/core\"", ")", ")", ".", "\"/KoolReport.subReport.js\"", ")", ";", "}", ")", ";", "}" ]
Initiate sub report @return null
[ "Initiate", "sub", "report" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/core/SubReport.php#L32-L67
koolphp/koolreport
src/core/SubReport.php
SubReport.subReport
public function subReport($name,$params=array()) { $subReports = Utility::get($this->reportSettings, "subReports"); $class = Utility::get($subReports, $name); if ($class!=null) { $params["@reportName"] = $name; $r = new $class($params); echo "<sub-report id='$name' name='$name'>"; $r->run()->render(); echo "</sub-report>"; $GLOBALS["__ACTIVE_KOOLREPORT__"] = $this; } else { trigger_error( "Could not find [$name] subreport, please define this report in the " .Utility::getClassName($this) ."::settings()", E_USER_WARNING ); } }
php
public function subReport($name,$params=array()) { $subReports = Utility::get($this->reportSettings, "subReports"); $class = Utility::get($subReports, $name); if ($class!=null) { $params["@reportName"] = $name; $r = new $class($params); echo "<sub-report id='$name' name='$name'>"; $r->run()->render(); echo "</sub-report>"; $GLOBALS["__ACTIVE_KOOLREPORT__"] = $this; } else { trigger_error( "Could not find [$name] subreport, please define this report in the " .Utility::getClassName($this) ."::settings()", E_USER_WARNING ); } }
[ "public", "function", "subReport", "(", "$", "name", ",", "$", "params", "=", "array", "(", ")", ")", "{", "$", "subReports", "=", "Utility", "::", "get", "(", "$", "this", "->", "reportSettings", ",", "\"subReports\"", ")", ";", "$", "class", "=", "Utility", "::", "get", "(", "$", "subReports", ",", "$", "name", ")", ";", "if", "(", "$", "class", "!=", "null", ")", "{", "$", "params", "[", "\"@reportName\"", "]", "=", "$", "name", ";", "$", "r", "=", "new", "$", "class", "(", "$", "params", ")", ";", "echo", "\"<sub-report id='$name' name='$name'>\"", ";", "$", "r", "->", "run", "(", ")", "->", "render", "(", ")", ";", "echo", "\"</sub-report>\"", ";", "$", "GLOBALS", "[", "\"__ACTIVE_KOOLREPORT__\"", "]", "=", "$", "this", ";", "}", "else", "{", "trigger_error", "(", "\"Could not find [$name] subreport, please define this report in the \"", ".", "Utility", "::", "getClassName", "(", "$", "this", ")", ".", "\"::settings()\"", ",", "E_USER_WARNING", ")", ";", "}", "}" ]
Render a sub report inside report @param string $name The name of subrepor that defined in report settings @param array $params Parameters that you want to send to sub report @return null
[ "Render", "a", "sub", "report", "inside", "report" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/core/SubReport.php#L77-L96
koolphp/koolreport
src/widgets/google/DonutChart.php
DonutChart.onInit
protected function onInit() { parent::onInit(); $this->type = "PieChart"; if (!isset($this->options["pieHole"])) { $this->options["pieHole"] = 0.4; } }
php
protected function onInit() { parent::onInit(); $this->type = "PieChart"; if (!isset($this->options["pieHole"])) { $this->options["pieHole"] = 0.4; } }
[ "protected", "function", "onInit", "(", ")", "{", "parent", "::", "onInit", "(", ")", ";", "$", "this", "->", "type", "=", "\"PieChart\"", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "options", "[", "\"pieHole\"", "]", ")", ")", "{", "$", "this", "->", "options", "[", "\"pieHole\"", "]", "=", "0.4", ";", "}", "}" ]
Handle on widget init @return null
[ "Handle", "on", "widget", "init" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/widgets/google/DonutChart.php#L32-L39
koolphp/koolreport
src/widgets/google/ComboChart.php
ComboChart.onInit
protected function onInit() { parent::onInit(); $series_option = Utility::get($this->options, "series", array()); $columns = parent::getColumnSettings(); $cKeys = array_keys($columns); foreach ($cKeys as $i => $cKey) { if ($i > 0) { $chartType = Utility::get($columns[$cKey], "chartType", "bars"); if ($chartType != "bars") { if (!isset($series_option[$i - 1])) { $series_option[$i - 1] = array(); } $series_option[$i - 1]["type"] = $chartType; } } } $this->options["seriesType"] = Utility::get($this->options, "seriesType", "bars"); $this->options["series"] = $series_option; }
php
protected function onInit() { parent::onInit(); $series_option = Utility::get($this->options, "series", array()); $columns = parent::getColumnSettings(); $cKeys = array_keys($columns); foreach ($cKeys as $i => $cKey) { if ($i > 0) { $chartType = Utility::get($columns[$cKey], "chartType", "bars"); if ($chartType != "bars") { if (!isset($series_option[$i - 1])) { $series_option[$i - 1] = array(); } $series_option[$i - 1]["type"] = $chartType; } } } $this->options["seriesType"] = Utility::get($this->options, "seriesType", "bars"); $this->options["series"] = $series_option; }
[ "protected", "function", "onInit", "(", ")", "{", "parent", "::", "onInit", "(", ")", ";", "$", "series_option", "=", "Utility", "::", "get", "(", "$", "this", "->", "options", ",", "\"series\"", ",", "array", "(", ")", ")", ";", "$", "columns", "=", "parent", "::", "getColumnSettings", "(", ")", ";", "$", "cKeys", "=", "array_keys", "(", "$", "columns", ")", ";", "foreach", "(", "$", "cKeys", "as", "$", "i", "=>", "$", "cKey", ")", "{", "if", "(", "$", "i", ">", "0", ")", "{", "$", "chartType", "=", "Utility", "::", "get", "(", "$", "columns", "[", "$", "cKey", "]", ",", "\"chartType\"", ",", "\"bars\"", ")", ";", "if", "(", "$", "chartType", "!=", "\"bars\"", ")", "{", "if", "(", "!", "isset", "(", "$", "series_option", "[", "$", "i", "-", "1", "]", ")", ")", "{", "$", "series_option", "[", "$", "i", "-", "1", "]", "=", "array", "(", ")", ";", "}", "$", "series_option", "[", "$", "i", "-", "1", "]", "[", "\"type\"", "]", "=", "$", "chartType", ";", "}", "}", "}", "$", "this", "->", "options", "[", "\"seriesType\"", "]", "=", "Utility", "::", "get", "(", "$", "this", "->", "options", ",", "\"seriesType\"", ",", "\"bars\"", ")", ";", "$", "this", "->", "options", "[", "\"series\"", "]", "=", "$", "series_option", ";", "}" ]
Handle on widget init @return null
[ "Handle", "on", "widget", "init" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/widgets/google/ComboChart.php#L34-L55
koolphp/koolreport
src/processes/Custom.php
Custom.onInput
protected function onInput($data) { $func = $this->params; $data = $func($data); if ($data) { $this->next($data); } }
php
protected function onInput($data) { $func = $this->params; $data = $func($data); if ($data) { $this->next($data); } }
[ "protected", "function", "onInput", "(", "$", "data", ")", "{", "$", "func", "=", "$", "this", "->", "params", ";", "$", "data", "=", "$", "func", "(", "$", "data", ")", ";", "if", "(", "$", "data", ")", "{", "$", "this", "->", "next", "(", "$", "data", ")", ";", "}", "}" ]
Handle on data input @param array $data The input data row @return null
[ "Handle", "on", "data", "input" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/processes/Custom.php#L37-L45
koolphp/koolreport
src/processes/Group.php
Group.parseGroups
protected function parseGroups($params) { if ($params == null) { return array(); } if (is_array($params)) { return $params; } if (is_string($params)) { $list = explode(",", $params); foreach ($list as &$item) { $item = trim($item); } return $list; } return array(); }
php
protected function parseGroups($params) { if ($params == null) { return array(); } if (is_array($params)) { return $params; } if (is_string($params)) { $list = explode(",", $params); foreach ($list as &$item) { $item = trim($item); } return $list; } return array(); }
[ "protected", "function", "parseGroups", "(", "$", "params", ")", "{", "if", "(", "$", "params", "==", "null", ")", "{", "return", "array", "(", ")", ";", "}", "if", "(", "is_array", "(", "$", "params", ")", ")", "{", "return", "$", "params", ";", "}", "if", "(", "is_string", "(", "$", "params", ")", ")", "{", "$", "list", "=", "explode", "(", "\",\"", ",", "$", "params", ")", ";", "foreach", "(", "$", "list", "as", "&", "$", "item", ")", "{", "$", "item", "=", "trim", "(", "$", "item", ")", ";", "}", "return", "$", "list", ";", "}", "return", "array", "(", ")", ";", "}" ]
Parse group @param array $params List of params @return array Parsed group
[ "Parse", "group" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/processes/Group.php#L56-L74
koolphp/koolreport
src/processes/Group.php
Group.onInit
protected function onInit() { $this->groupColumns = $this->parseGroups(Utility::get($this->params, "by")); $this->sumColumns = $this->parseGroups(Utility::get($this->params, "sum")); $this->countColumns = $this->parseGroups(Utility::get($this->params, "count")); $this->avgColumns = $this->parseGroups(Utility::get($this->params, "avg")); $this->minColumns = $this->parseGroups(Utility::get($this->params, "min")); $this->maxColumns = $this->parseGroups(Utility::get($this->params, "max")); $this->sort = Utility::get($this->params, "sort", true); $this->gData = array(); $this->cData = array(); }
php
protected function onInit() { $this->groupColumns = $this->parseGroups(Utility::get($this->params, "by")); $this->sumColumns = $this->parseGroups(Utility::get($this->params, "sum")); $this->countColumns = $this->parseGroups(Utility::get($this->params, "count")); $this->avgColumns = $this->parseGroups(Utility::get($this->params, "avg")); $this->minColumns = $this->parseGroups(Utility::get($this->params, "min")); $this->maxColumns = $this->parseGroups(Utility::get($this->params, "max")); $this->sort = Utility::get($this->params, "sort", true); $this->gData = array(); $this->cData = array(); }
[ "protected", "function", "onInit", "(", ")", "{", "$", "this", "->", "groupColumns", "=", "$", "this", "->", "parseGroups", "(", "Utility", "::", "get", "(", "$", "this", "->", "params", ",", "\"by\"", ")", ")", ";", "$", "this", "->", "sumColumns", "=", "$", "this", "->", "parseGroups", "(", "Utility", "::", "get", "(", "$", "this", "->", "params", ",", "\"sum\"", ")", ")", ";", "$", "this", "->", "countColumns", "=", "$", "this", "->", "parseGroups", "(", "Utility", "::", "get", "(", "$", "this", "->", "params", ",", "\"count\"", ")", ")", ";", "$", "this", "->", "avgColumns", "=", "$", "this", "->", "parseGroups", "(", "Utility", "::", "get", "(", "$", "this", "->", "params", ",", "\"avg\"", ")", ")", ";", "$", "this", "->", "minColumns", "=", "$", "this", "->", "parseGroups", "(", "Utility", "::", "get", "(", "$", "this", "->", "params", ",", "\"min\"", ")", ")", ";", "$", "this", "->", "maxColumns", "=", "$", "this", "->", "parseGroups", "(", "Utility", "::", "get", "(", "$", "this", "->", "params", ",", "\"max\"", ")", ")", ";", "$", "this", "->", "sort", "=", "Utility", "::", "get", "(", "$", "this", "->", "params", ",", "\"sort\"", ",", "true", ")", ";", "$", "this", "->", "gData", "=", "array", "(", ")", ";", "$", "this", "->", "cData", "=", "array", "(", ")", ";", "}" ]
Handle on initiation @return null
[ "Handle", "on", "initiation" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/processes/Group.php#L81-L93
koolphp/koolreport
src/processes/Group.php
Group.onMetaReceived
protected function onMetaReceived($metaData) { foreach ($this->groupColumns as $column) { $metaData["columns"][$column]["method"] = "group"; } foreach ($this->sumColumns as $column) { $metaData["columns"][$column]["method"] = "sum"; } foreach ($this->countColumns as $column) { $metaData["columns"][$column]["method"] = "count"; $metaData["columns"][$column]["type"] = "number"; } foreach ($this->avgColumns as $column) { $metaData["columns"][$column]["method"] = "avg"; } foreach ($this->minColumns as $column) { $metaData["columns"][$column]["method"] = "min"; } foreach ($this->maxColumns as $column) { $metaData["columns"][$column]["method"] = "max"; } return $metaData; }
php
protected function onMetaReceived($metaData) { foreach ($this->groupColumns as $column) { $metaData["columns"][$column]["method"] = "group"; } foreach ($this->sumColumns as $column) { $metaData["columns"][$column]["method"] = "sum"; } foreach ($this->countColumns as $column) { $metaData["columns"][$column]["method"] = "count"; $metaData["columns"][$column]["type"] = "number"; } foreach ($this->avgColumns as $column) { $metaData["columns"][$column]["method"] = "avg"; } foreach ($this->minColumns as $column) { $metaData["columns"][$column]["method"] = "min"; } foreach ($this->maxColumns as $column) { $metaData["columns"][$column]["method"] = "max"; } return $metaData; }
[ "protected", "function", "onMetaReceived", "(", "$", "metaData", ")", "{", "foreach", "(", "$", "this", "->", "groupColumns", "as", "$", "column", ")", "{", "$", "metaData", "[", "\"columns\"", "]", "[", "$", "column", "]", "[", "\"method\"", "]", "=", "\"group\"", ";", "}", "foreach", "(", "$", "this", "->", "sumColumns", "as", "$", "column", ")", "{", "$", "metaData", "[", "\"columns\"", "]", "[", "$", "column", "]", "[", "\"method\"", "]", "=", "\"sum\"", ";", "}", "foreach", "(", "$", "this", "->", "countColumns", "as", "$", "column", ")", "{", "$", "metaData", "[", "\"columns\"", "]", "[", "$", "column", "]", "[", "\"method\"", "]", "=", "\"count\"", ";", "$", "metaData", "[", "\"columns\"", "]", "[", "$", "column", "]", "[", "\"type\"", "]", "=", "\"number\"", ";", "}", "foreach", "(", "$", "this", "->", "avgColumns", "as", "$", "column", ")", "{", "$", "metaData", "[", "\"columns\"", "]", "[", "$", "column", "]", "[", "\"method\"", "]", "=", "\"avg\"", ";", "}", "foreach", "(", "$", "this", "->", "minColumns", "as", "$", "column", ")", "{", "$", "metaData", "[", "\"columns\"", "]", "[", "$", "column", "]", "[", "\"method\"", "]", "=", "\"min\"", ";", "}", "foreach", "(", "$", "this", "->", "maxColumns", "as", "$", "column", ")", "{", "$", "metaData", "[", "\"columns\"", "]", "[", "$", "column", "]", "[", "\"method\"", "]", "=", "\"max\"", ";", "}", "return", "$", "metaData", ";", "}" ]
Handle on meta received @param array $metaData The meta data @return array New meta data
[ "Handle", "on", "meta", "received" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/processes/Group.php#L102-L126
koolphp/koolreport
src/processes/Group.php
Group.onInput
protected function onInput($row) { $index = ""; foreach ($this->groupColumns as $gColumn) { $index .= $row[$gColumn]; } $index = strtolower($index) . md5($index); if (isset($this->gData[$index])) { $res = $this->gData[$index]; $this->cData[$index]++; foreach ($this->sumColumns as $sumColumn) { $res[$sumColumn] += $row[$sumColumn]; } foreach ($this->countColumns as $countColumn) { $res[$countColumn] = $this->cData[$index]; } foreach ($this->minColumns as $minColumn) { if ($res[$minColumn] > $row[$minColumn]) { $res[$minColumn] = $row[$minColumn]; } } foreach ($this->maxColumns as $maxColumn) { if ($res[$maxColumn] < $row[$maxColumn]) { $res[$maxColumn] = $row[$maxColumn]; } } foreach ($this->avgColumns as $avgColumn) { $res[$avgColumn] = ($res[$avgColumn] * ($this->cData[$index] - 1) + $row[$avgColumn]) / $this->cData[$index]; } $this->gData[$index] = $res; } else { $this->cData[$index] = 1; foreach ($this->countColumns as $countColumn) { $row[$countColumn] = 1; } $this->gData[$index] = $row; } }
php
protected function onInput($row) { $index = ""; foreach ($this->groupColumns as $gColumn) { $index .= $row[$gColumn]; } $index = strtolower($index) . md5($index); if (isset($this->gData[$index])) { $res = $this->gData[$index]; $this->cData[$index]++; foreach ($this->sumColumns as $sumColumn) { $res[$sumColumn] += $row[$sumColumn]; } foreach ($this->countColumns as $countColumn) { $res[$countColumn] = $this->cData[$index]; } foreach ($this->minColumns as $minColumn) { if ($res[$minColumn] > $row[$minColumn]) { $res[$minColumn] = $row[$minColumn]; } } foreach ($this->maxColumns as $maxColumn) { if ($res[$maxColumn] < $row[$maxColumn]) { $res[$maxColumn] = $row[$maxColumn]; } } foreach ($this->avgColumns as $avgColumn) { $res[$avgColumn] = ($res[$avgColumn] * ($this->cData[$index] - 1) + $row[$avgColumn]) / $this->cData[$index]; } $this->gData[$index] = $res; } else { $this->cData[$index] = 1; foreach ($this->countColumns as $countColumn) { $row[$countColumn] = 1; } $this->gData[$index] = $row; } }
[ "protected", "function", "onInput", "(", "$", "row", ")", "{", "$", "index", "=", "\"\"", ";", "foreach", "(", "$", "this", "->", "groupColumns", "as", "$", "gColumn", ")", "{", "$", "index", ".=", "$", "row", "[", "$", "gColumn", "]", ";", "}", "$", "index", "=", "strtolower", "(", "$", "index", ")", ".", "md5", "(", "$", "index", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "gData", "[", "$", "index", "]", ")", ")", "{", "$", "res", "=", "$", "this", "->", "gData", "[", "$", "index", "]", ";", "$", "this", "->", "cData", "[", "$", "index", "]", "++", ";", "foreach", "(", "$", "this", "->", "sumColumns", "as", "$", "sumColumn", ")", "{", "$", "res", "[", "$", "sumColumn", "]", "+=", "$", "row", "[", "$", "sumColumn", "]", ";", "}", "foreach", "(", "$", "this", "->", "countColumns", "as", "$", "countColumn", ")", "{", "$", "res", "[", "$", "countColumn", "]", "=", "$", "this", "->", "cData", "[", "$", "index", "]", ";", "}", "foreach", "(", "$", "this", "->", "minColumns", "as", "$", "minColumn", ")", "{", "if", "(", "$", "res", "[", "$", "minColumn", "]", ">", "$", "row", "[", "$", "minColumn", "]", ")", "{", "$", "res", "[", "$", "minColumn", "]", "=", "$", "row", "[", "$", "minColumn", "]", ";", "}", "}", "foreach", "(", "$", "this", "->", "maxColumns", "as", "$", "maxColumn", ")", "{", "if", "(", "$", "res", "[", "$", "maxColumn", "]", "<", "$", "row", "[", "$", "maxColumn", "]", ")", "{", "$", "res", "[", "$", "maxColumn", "]", "=", "$", "row", "[", "$", "maxColumn", "]", ";", "}", "}", "foreach", "(", "$", "this", "->", "avgColumns", "as", "$", "avgColumn", ")", "{", "$", "res", "[", "$", "avgColumn", "]", "=", "(", "$", "res", "[", "$", "avgColumn", "]", "*", "(", "$", "this", "->", "cData", "[", "$", "index", "]", "-", "1", ")", "+", "$", "row", "[", "$", "avgColumn", "]", ")", "/", "$", "this", "->", "cData", "[", "$", "index", "]", ";", "}", "$", "this", "->", "gData", "[", "$", "index", "]", "=", "$", "res", ";", "}", "else", "{", "$", "this", "->", "cData", "[", "$", "index", "]", "=", "1", ";", "foreach", "(", "$", "this", "->", "countColumns", "as", "$", "countColumn", ")", "{", "$", "row", "[", "$", "countColumn", "]", "=", "1", ";", "}", "$", "this", "->", "gData", "[", "$", "index", "]", "=", "$", "row", ";", "}", "}" ]
Handle on data input @param array $row The input row @return null
[ "Handle", "on", "data", "input" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/processes/Group.php#L135-L176
koolphp/koolreport
src/processes/Group.php
Group.onInputEnd
protected function onInputEnd() { if ($this->sort) { ksort($this->gData, SORT_STRING); } foreach ($this->gData as $index => $data) { $this->next($data); } }
php
protected function onInputEnd() { if ($this->sort) { ksort($this->gData, SORT_STRING); } foreach ($this->gData as $index => $data) { $this->next($data); } }
[ "protected", "function", "onInputEnd", "(", ")", "{", "if", "(", "$", "this", "->", "sort", ")", "{", "ksort", "(", "$", "this", "->", "gData", ",", "SORT_STRING", ")", ";", "}", "foreach", "(", "$", "this", "->", "gData", "as", "$", "index", "=>", "$", "data", ")", "{", "$", "this", "->", "next", "(", "$", "data", ")", ";", "}", "}" ]
Handle on input end @return null
[ "Handle", "on", "input", "end" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/processes/Group.php#L183-L191
koolphp/koolreport
src/datasources/OracleDataSource.php
OracleDataSource.onInit
protected function onInit() { $username = Util::get($this->params, "username", ""); $password = Util::get($this->params, "password", ""); $connString = Util::get($this->params, "connectionString", ""); $key = md5($username.$password.$connString); if (isset(OracleDataSource::$connections[$key])) { $this->connection = OracleDataSource::$connections[$key]; } else { $conn = oci_connect($username, $password, $connString); if ($conn) { $this->connection = $conn; } else { throw new \Exception("Connection failed: " . print_r(oci_error(), true)); } OracleDataSource::$connections[$key] = $this->connection; } }
php
protected function onInit() { $username = Util::get($this->params, "username", ""); $password = Util::get($this->params, "password", ""); $connString = Util::get($this->params, "connectionString", ""); $key = md5($username.$password.$connString); if (isset(OracleDataSource::$connections[$key])) { $this->connection = OracleDataSource::$connections[$key]; } else { $conn = oci_connect($username, $password, $connString); if ($conn) { $this->connection = $conn; } else { throw new \Exception("Connection failed: " . print_r(oci_error(), true)); } OracleDataSource::$connections[$key] = $this->connection; } }
[ "protected", "function", "onInit", "(", ")", "{", "$", "username", "=", "Util", "::", "get", "(", "$", "this", "->", "params", ",", "\"username\"", ",", "\"\"", ")", ";", "$", "password", "=", "Util", "::", "get", "(", "$", "this", "->", "params", ",", "\"password\"", ",", "\"\"", ")", ";", "$", "connString", "=", "Util", "::", "get", "(", "$", "this", "->", "params", ",", "\"connectionString\"", ",", "\"\"", ")", ";", "$", "key", "=", "md5", "(", "$", "username", ".", "$", "password", ".", "$", "connString", ")", ";", "if", "(", "isset", "(", "OracleDataSource", "::", "$", "connections", "[", "$", "key", "]", ")", ")", "{", "$", "this", "->", "connection", "=", "OracleDataSource", "::", "$", "connections", "[", "$", "key", "]", ";", "}", "else", "{", "$", "conn", "=", "oci_connect", "(", "$", "username", ",", "$", "password", ",", "$", "connString", ")", ";", "if", "(", "$", "conn", ")", "{", "$", "this", "->", "connection", "=", "$", "conn", ";", "}", "else", "{", "throw", "new", "\\", "Exception", "(", "\"Connection failed: \"", ".", "print_r", "(", "oci_error", "(", ")", ",", "true", ")", ")", ";", "}", "OracleDataSource", "::", "$", "connections", "[", "$", "key", "]", "=", "$", "this", "->", "connection", ";", "}", "}" ]
Called for initiation @return null
[ "Called", "for", "initiation" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/datasources/OracleDataSource.php#L110-L129
koolphp/koolreport
src/datasources/OracleDataSource.php
OracleDataSource.processQuery
static function processQuery($query, $queryParams) { $search = Util::get($queryParams, 'search', '1=1'); $searchSql = "WHERE $search"; $order = Util::get($queryParams, 'order', ''); $orderSql = ! empty($order) ? "ORDER BY $order" : ""; $start = (int) Util::get($queryParams, 'start', 0) + 1; $length = (int) Util::get($queryParams, 'length', -1); $end = $start + $length; $limitSearchSql = $searchSql . ($length > -1 ? " AND rownum < $end" : ""); // Oracle version >= 12 // $limit = $length > -1 ? // "OFFSET $start ROWS FETCH NEXT $length ROWS ONLY" : ""; $filterQuery = "SELECT count(*) FROM ($query) tmp $searchSql"; $totalQuery = "SELECT count(*) FROM ($query) tmp"; $processedQuery = "select * from (select a.*, rownum as rnum from (select * from ($query) $orderSql) a $limitSearchSql ) tmp where rnum >= $start"; // echo "query=" . $processedQuery . '<br>'; return [$processedQuery, $totalQuery, $filterQuery]; }
php
static function processQuery($query, $queryParams) { $search = Util::get($queryParams, 'search', '1=1'); $searchSql = "WHERE $search"; $order = Util::get($queryParams, 'order', ''); $orderSql = ! empty($order) ? "ORDER BY $order" : ""; $start = (int) Util::get($queryParams, 'start', 0) + 1; $length = (int) Util::get($queryParams, 'length', -1); $end = $start + $length; $limitSearchSql = $searchSql . ($length > -1 ? " AND rownum < $end" : ""); // Oracle version >= 12 // $limit = $length > -1 ? // "OFFSET $start ROWS FETCH NEXT $length ROWS ONLY" : ""; $filterQuery = "SELECT count(*) FROM ($query) tmp $searchSql"; $totalQuery = "SELECT count(*) FROM ($query) tmp"; $processedQuery = "select * from (select a.*, rownum as rnum from (select * from ($query) $orderSql) a $limitSearchSql ) tmp where rnum >= $start"; // echo "query=" . $processedQuery . '<br>'; return [$processedQuery, $totalQuery, $filterQuery]; }
[ "static", "function", "processQuery", "(", "$", "query", ",", "$", "queryParams", ")", "{", "$", "search", "=", "Util", "::", "get", "(", "$", "queryParams", ",", "'search'", ",", "'1=1'", ")", ";", "$", "searchSql", "=", "\"WHERE $search\"", ";", "$", "order", "=", "Util", "::", "get", "(", "$", "queryParams", ",", "'order'", ",", "''", ")", ";", "$", "orderSql", "=", "!", "empty", "(", "$", "order", ")", "?", "\"ORDER BY $order\"", ":", "\"\"", ";", "$", "start", "=", "(", "int", ")", "Util", "::", "get", "(", "$", "queryParams", ",", "'start'", ",", "0", ")", "+", "1", ";", "$", "length", "=", "(", "int", ")", "Util", "::", "get", "(", "$", "queryParams", ",", "'length'", ",", "-", "1", ")", ";", "$", "end", "=", "$", "start", "+", "$", "length", ";", "$", "limitSearchSql", "=", "$", "searchSql", ".", "(", "$", "length", ">", "-", "1", "?", "\" AND rownum < $end\"", ":", "\"\"", ")", ";", "// Oracle version >= 12", "// $limit = $length > -1 ? ", "// \"OFFSET $start ROWS FETCH NEXT $length ROWS ONLY\" : \"\"; ", "$", "filterQuery", "=", "\"SELECT count(*) FROM ($query) tmp $searchSql\"", ";", "$", "totalQuery", "=", "\"SELECT count(*) FROM ($query) tmp\"", ";", "$", "processedQuery", "=", "\"select * from (select a.*, rownum as rnum \n from (select * from ($query) $orderSql) a $limitSearchSql ) tmp \n where rnum >= $start\"", ";", "// echo \"query=\" . $processedQuery . '<br>';", "return", "[", "$", "processedQuery", ",", "$", "totalQuery", ",", "$", "filterQuery", "]", ";", "}" ]
Process query to additional condition @param string $query The SQL query statement @param array $queryParams The parameters of SQL query @return array Information of additional condition
[ "Process", "query", "to", "additional", "condition" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/datasources/OracleDataSource.php#L156-L179
koolphp/koolreport
src/datasources/OracleDataSource.php
OracleDataSource.mapFieldTypeToBindType
protected function mapFieldTypeToBindType($native_type) { $oracleDatatypeMap = array( 'varchar2' => 'string', 'nvarchar2' => 'string', 'number' => 'number', 'long' => 'number', 'date' => 'datetime', 'binary_float' => 'number', 'binary_double' => 'number', 'timestamp' => 'datetime', 'interval year' => 'datetime', 'interval day' => 'datetime', 'raw' => 'string', 'long raw' => 'string', 'rowid' => 'string', 'urowid' => 'string', 'char' => 'string', 'nchar' => 'string', 'clob' => 'string', 'nclob' => 'string', 'blob' => 'string', 'bfile' => 'string', ); $native_type = strtolower($native_type); if (isset($oracleDatatypeMap[$native_type])) { return $oracleDatatypeMap[$native_type]; } else { return "unknown"; } }
php
protected function mapFieldTypeToBindType($native_type) { $oracleDatatypeMap = array( 'varchar2' => 'string', 'nvarchar2' => 'string', 'number' => 'number', 'long' => 'number', 'date' => 'datetime', 'binary_float' => 'number', 'binary_double' => 'number', 'timestamp' => 'datetime', 'interval year' => 'datetime', 'interval day' => 'datetime', 'raw' => 'string', 'long raw' => 'string', 'rowid' => 'string', 'urowid' => 'string', 'char' => 'string', 'nchar' => 'string', 'clob' => 'string', 'nclob' => 'string', 'blob' => 'string', 'bfile' => 'string', ); $native_type = strtolower($native_type); if (isset($oracleDatatypeMap[$native_type])) { return $oracleDatatypeMap[$native_type]; } else { return "unknown"; } }
[ "protected", "function", "mapFieldTypeToBindType", "(", "$", "native_type", ")", "{", "$", "oracleDatatypeMap", "=", "array", "(", "'varchar2'", "=>", "'string'", ",", "'nvarchar2'", "=>", "'string'", ",", "'number'", "=>", "'number'", ",", "'long'", "=>", "'number'", ",", "'date'", "=>", "'datetime'", ",", "'binary_float'", "=>", "'number'", ",", "'binary_double'", "=>", "'number'", ",", "'timestamp'", "=>", "'datetime'", ",", "'interval year'", "=>", "'datetime'", ",", "'interval day'", "=>", "'datetime'", ",", "'raw'", "=>", "'string'", ",", "'long raw'", "=>", "'string'", ",", "'rowid'", "=>", "'string'", ",", "'urowid'", "=>", "'string'", ",", "'char'", "=>", "'string'", ",", "'nchar'", "=>", "'string'", ",", "'clob'", "=>", "'string'", ",", "'nclob'", "=>", "'string'", ",", "'blob'", "=>", "'string'", ",", "'bfile'", "=>", "'string'", ",", ")", ";", "$", "native_type", "=", "strtolower", "(", "$", "native_type", ")", ";", "if", "(", "isset", "(", "$", "oracleDatatypeMap", "[", "$", "native_type", "]", ")", ")", "{", "return", "$", "oracleDatatypeMap", "[", "$", "native_type", "]", ";", "}", "else", "{", "return", "\"unknown\"", ";", "}", "}" ]
Map field type to bind type @param string $native_type The type of field @return string KoolReport type of field
[ "Map", "field", "type", "to", "bind", "type" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/datasources/OracleDataSource.php#L287-L318
koolphp/koolreport
src/datasources/OracleDataSource.php
OracleDataSource.start
public function start() { $metaData = array("columns"=>array()); if ($this->countTotal) { $totalQuery = $this->bindParams($this->totalQuery, $this->sqlParams); $totalResult = oci_parse($this->connection, $totalQuery); if (! $totalResult) { echo oci_error(); exit; } oci_execute($totalResult); $row = oci_fetch_array($totalResult, OCI_BOTH+OCI_RETURN_NULLS); $total = $row[0]; $metaData['totalRecords'] = $total; } if ($this->countFilter) { $filterQuery = $this->bindParams($this->filterQuery, $this->sqlParams); $filterResult = oci_parse($this->connection, $filterQuery); if (! $filterResult) { echo oci_error(); exit; } oci_execute($filterResult); $row = oci_fetch_array($filterResult, OCI_BOTH+OCI_RETURN_NULLS); $total = $row[0]; $metaData['filterRecords'] = $total; } $query = $this->bindParams($this->query, $this->sqlParams); $stid = oci_parse($this->connection, $query); if (! $stid) { echo oci_error(); exit; } oci_execute($stid); $num_fields = oci_num_fields($stid); // $metaData = array("columns"=>array()); for ($i=0; $i<$num_fields; $i++) { $name = oci_field_name($stid, $i+1); $type = oci_field_type($stid, $i+1); $type = $this->mapFieldTypeToBindType($type); $metaData["columns"][$name] = array( "type"=>$type, ); switch($type) { case "datetime": $metaData["columns"][$name]["format"] = "Y-m-d H:i:s"; break; case "date": $metaData["columns"][$name]["format"] = "Y-m-d"; break; } } $this->sendMeta($metaData, $this); $this->startInput(null); while ($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)) { $this->next($row, $this); } $this->endInput(null); }
php
public function start() { $metaData = array("columns"=>array()); if ($this->countTotal) { $totalQuery = $this->bindParams($this->totalQuery, $this->sqlParams); $totalResult = oci_parse($this->connection, $totalQuery); if (! $totalResult) { echo oci_error(); exit; } oci_execute($totalResult); $row = oci_fetch_array($totalResult, OCI_BOTH+OCI_RETURN_NULLS); $total = $row[0]; $metaData['totalRecords'] = $total; } if ($this->countFilter) { $filterQuery = $this->bindParams($this->filterQuery, $this->sqlParams); $filterResult = oci_parse($this->connection, $filterQuery); if (! $filterResult) { echo oci_error(); exit; } oci_execute($filterResult); $row = oci_fetch_array($filterResult, OCI_BOTH+OCI_RETURN_NULLS); $total = $row[0]; $metaData['filterRecords'] = $total; } $query = $this->bindParams($this->query, $this->sqlParams); $stid = oci_parse($this->connection, $query); if (! $stid) { echo oci_error(); exit; } oci_execute($stid); $num_fields = oci_num_fields($stid); // $metaData = array("columns"=>array()); for ($i=0; $i<$num_fields; $i++) { $name = oci_field_name($stid, $i+1); $type = oci_field_type($stid, $i+1); $type = $this->mapFieldTypeToBindType($type); $metaData["columns"][$name] = array( "type"=>$type, ); switch($type) { case "datetime": $metaData["columns"][$name]["format"] = "Y-m-d H:i:s"; break; case "date": $metaData["columns"][$name]["format"] = "Y-m-d"; break; } } $this->sendMeta($metaData, $this); $this->startInput(null); while ($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)) { $this->next($row, $this); } $this->endInput(null); }
[ "public", "function", "start", "(", ")", "{", "$", "metaData", "=", "array", "(", "\"columns\"", "=>", "array", "(", ")", ")", ";", "if", "(", "$", "this", "->", "countTotal", ")", "{", "$", "totalQuery", "=", "$", "this", "->", "bindParams", "(", "$", "this", "->", "totalQuery", ",", "$", "this", "->", "sqlParams", ")", ";", "$", "totalResult", "=", "oci_parse", "(", "$", "this", "->", "connection", ",", "$", "totalQuery", ")", ";", "if", "(", "!", "$", "totalResult", ")", "{", "echo", "oci_error", "(", ")", ";", "exit", ";", "}", "oci_execute", "(", "$", "totalResult", ")", ";", "$", "row", "=", "oci_fetch_array", "(", "$", "totalResult", ",", "OCI_BOTH", "+", "OCI_RETURN_NULLS", ")", ";", "$", "total", "=", "$", "row", "[", "0", "]", ";", "$", "metaData", "[", "'totalRecords'", "]", "=", "$", "total", ";", "}", "if", "(", "$", "this", "->", "countFilter", ")", "{", "$", "filterQuery", "=", "$", "this", "->", "bindParams", "(", "$", "this", "->", "filterQuery", ",", "$", "this", "->", "sqlParams", ")", ";", "$", "filterResult", "=", "oci_parse", "(", "$", "this", "->", "connection", ",", "$", "filterQuery", ")", ";", "if", "(", "!", "$", "filterResult", ")", "{", "echo", "oci_error", "(", ")", ";", "exit", ";", "}", "oci_execute", "(", "$", "filterResult", ")", ";", "$", "row", "=", "oci_fetch_array", "(", "$", "filterResult", ",", "OCI_BOTH", "+", "OCI_RETURN_NULLS", ")", ";", "$", "total", "=", "$", "row", "[", "0", "]", ";", "$", "metaData", "[", "'filterRecords'", "]", "=", "$", "total", ";", "}", "$", "query", "=", "$", "this", "->", "bindParams", "(", "$", "this", "->", "query", ",", "$", "this", "->", "sqlParams", ")", ";", "$", "stid", "=", "oci_parse", "(", "$", "this", "->", "connection", ",", "$", "query", ")", ";", "if", "(", "!", "$", "stid", ")", "{", "echo", "oci_error", "(", ")", ";", "exit", ";", "}", "oci_execute", "(", "$", "stid", ")", ";", "$", "num_fields", "=", "oci_num_fields", "(", "$", "stid", ")", ";", "// $metaData = array(\"columns\"=>array());", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "num_fields", ";", "$", "i", "++", ")", "{", "$", "name", "=", "oci_field_name", "(", "$", "stid", ",", "$", "i", "+", "1", ")", ";", "$", "type", "=", "oci_field_type", "(", "$", "stid", ",", "$", "i", "+", "1", ")", ";", "$", "type", "=", "$", "this", "->", "mapFieldTypeToBindType", "(", "$", "type", ")", ";", "$", "metaData", "[", "\"columns\"", "]", "[", "$", "name", "]", "=", "array", "(", "\"type\"", "=>", "$", "type", ",", ")", ";", "switch", "(", "$", "type", ")", "{", "case", "\"datetime\"", ":", "$", "metaData", "[", "\"columns\"", "]", "[", "$", "name", "]", "[", "\"format\"", "]", "=", "\"Y-m-d H:i:s\"", ";", "break", ";", "case", "\"date\"", ":", "$", "metaData", "[", "\"columns\"", "]", "[", "$", "name", "]", "[", "\"format\"", "]", "=", "\"Y-m-d\"", ";", "break", ";", "}", "}", "$", "this", "->", "sendMeta", "(", "$", "metaData", ",", "$", "this", ")", ";", "$", "this", "->", "startInput", "(", "null", ")", ";", "while", "(", "$", "row", "=", "oci_fetch_array", "(", "$", "stid", ",", "OCI_ASSOC", "+", "OCI_RETURN_NULLS", ")", ")", "{", "$", "this", "->", "next", "(", "$", "row", ",", "$", "this", ")", ";", "}", "$", "this", "->", "endInput", "(", "null", ")", ";", "}" ]
Start piping data @return null
[ "Start", "piping", "data" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/datasources/OracleDataSource.php#L325-L391
koolphp/koolreport
src/clients/Bootstrap.php
Bootstrap.__constructBootstrap
public function __constructBootstrap() { $this->registerEvent( 'OnResourceInit', function () { $bootstrapAssetUrl = $this->getResourceManager() ->publishAssetFolder(realpath(dirname(__FILE__)."/bootstrap")); $jqueryAssetUrl = $this->getResourceManager() ->publishAssetFolder(realpath(dirname(__FILE__)."/jquery")); $resources = array( "js"=>array( $jqueryAssetUrl."/jquery.min.js", array( $bootstrapAssetUrl."/js/bootstrap.min.js" ) ), "css"=>array( $bootstrapAssetUrl."/css/bootstrap.min.css", $bootstrapAssetUrl."/css/bootstrap-theme.min.css" ) ); $this->getResourceManager() ->addScriptOnBegin("KoolReport.load.resources(".json_encode($resources).");"); } ); }
php
public function __constructBootstrap() { $this->registerEvent( 'OnResourceInit', function () { $bootstrapAssetUrl = $this->getResourceManager() ->publishAssetFolder(realpath(dirname(__FILE__)."/bootstrap")); $jqueryAssetUrl = $this->getResourceManager() ->publishAssetFolder(realpath(dirname(__FILE__)."/jquery")); $resources = array( "js"=>array( $jqueryAssetUrl."/jquery.min.js", array( $bootstrapAssetUrl."/js/bootstrap.min.js" ) ), "css"=>array( $bootstrapAssetUrl."/css/bootstrap.min.css", $bootstrapAssetUrl."/css/bootstrap-theme.min.css" ) ); $this->getResourceManager() ->addScriptOnBegin("KoolReport.load.resources(".json_encode($resources).");"); } ); }
[ "public", "function", "__constructBootstrap", "(", ")", "{", "$", "this", "->", "registerEvent", "(", "'OnResourceInit'", ",", "function", "(", ")", "{", "$", "bootstrapAssetUrl", "=", "$", "this", "->", "getResourceManager", "(", ")", "->", "publishAssetFolder", "(", "realpath", "(", "dirname", "(", "__FILE__", ")", ".", "\"/bootstrap\"", ")", ")", ";", "$", "jqueryAssetUrl", "=", "$", "this", "->", "getResourceManager", "(", ")", "->", "publishAssetFolder", "(", "realpath", "(", "dirname", "(", "__FILE__", ")", ".", "\"/jquery\"", ")", ")", ";", "$", "resources", "=", "array", "(", "\"js\"", "=>", "array", "(", "$", "jqueryAssetUrl", ".", "\"/jquery.min.js\"", ",", "array", "(", "$", "bootstrapAssetUrl", ".", "\"/js/bootstrap.min.js\"", ")", ")", ",", "\"css\"", "=>", "array", "(", "$", "bootstrapAssetUrl", ".", "\"/css/bootstrap.min.css\"", ",", "$", "bootstrapAssetUrl", ".", "\"/css/bootstrap-theme.min.css\"", ")", ")", ";", "$", "this", "->", "getResourceManager", "(", ")", "->", "addScriptOnBegin", "(", "\"KoolReport.load.resources(\"", ".", "json_encode", "(", "$", "resources", ")", ".", "\");\"", ")", ";", "}", ")", ";", "}" ]
Service construction @return null
[ "Service", "construction" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/clients/Bootstrap.php#L34-L59
koolphp/koolreport
src/processes/Filter.php
Filter.isFiltered
public function isFiltered($condition, $value, $type) { $isFiltered = true; switch ($condition[1]) { case '=': case '==': case 'equal': if ($type === 'string' && is_string($value) && is_string($condition[2])) { $isFiltered = strcmp($value, $condition[2]) == 0; } else { $isFiltered = $value == $condition[2]; } break; case '!=': case 'notEqual': if ($type === 'string' && is_string($value) && is_string($condition[2])) { $isFiltered = strcmp($value, $condition[2]) != 0; } else { $isFiltered = $value != $condition[2]; } break; case '>': case 'gt': if ($type === 'string') { $isFiltered = strcmp($value, $condition[2]) > 0; } else { $isFiltered = $value > $condition[2]; } break; case '>=': if ($type === 'string') { $isFiltered = strcmp($value, $condition[2]) >= 0; } else { $isFiltered = $value >= $condition[2]; } break; case '<': case 'lt': if ($type === 'string') { $isFiltered = strcmp($value, $condition[2]) < 0; } else { $isFiltered = $value < $condition[2]; } break; case '<=': if ($type === 'string') { $isFiltered = strcmp($value, $condition[2]) <= 0; } else { $isFiltered = $value <= $condition[2]; } break; case 'contain': case 'contains': $isFiltered = strpos(strtolower($value), strtolower($condition[2])) !== false; break; case 'notContain': case 'notContains': $isFiltered = strpos(strtolower($value), strtolower($condition[2])) === false; break; case 'startWith': case 'startsWith': $isFiltered = strpos(strtolower($value), strtolower($condition[2])) === 0; break; case 'notStartWith': case 'notStartsWith': $isFiltered = strpos(strtolower($value), strtolower($condition[2])) !== 0; break; case 'endWith': case 'endsWith': $isFiltered = strpos(strrev(strtolower($value)), strrev(strtolower($condition[2]))) === 0; break; case 'notEndWith': case 'notEndsWith': $isFiltered = strpos(strrev(strtolower($value)), strrev(strtolower($condition[2]))) !== 0; break; case 'between': $isFiltered = $value > $condition[2] && $value < $condition[3]; break; case 'notBetween': $isFiltered = !($value > $condition[2] && $value < $condition[3]); break; case "in": if (!is_array($condition[2])) { $condition[2] = array($condition[2]); } $isFiltered = in_array($value, $condition[2]); break; case "notIn": if (!is_array($condition[2])) { $condition[2] = array($condition[2]); } $isFiltered = !in_array($value, $condition[2]); break; default: break; } return $isFiltered; }
php
public function isFiltered($condition, $value, $type) { $isFiltered = true; switch ($condition[1]) { case '=': case '==': case 'equal': if ($type === 'string' && is_string($value) && is_string($condition[2])) { $isFiltered = strcmp($value, $condition[2]) == 0; } else { $isFiltered = $value == $condition[2]; } break; case '!=': case 'notEqual': if ($type === 'string' && is_string($value) && is_string($condition[2])) { $isFiltered = strcmp($value, $condition[2]) != 0; } else { $isFiltered = $value != $condition[2]; } break; case '>': case 'gt': if ($type === 'string') { $isFiltered = strcmp($value, $condition[2]) > 0; } else { $isFiltered = $value > $condition[2]; } break; case '>=': if ($type === 'string') { $isFiltered = strcmp($value, $condition[2]) >= 0; } else { $isFiltered = $value >= $condition[2]; } break; case '<': case 'lt': if ($type === 'string') { $isFiltered = strcmp($value, $condition[2]) < 0; } else { $isFiltered = $value < $condition[2]; } break; case '<=': if ($type === 'string') { $isFiltered = strcmp($value, $condition[2]) <= 0; } else { $isFiltered = $value <= $condition[2]; } break; case 'contain': case 'contains': $isFiltered = strpos(strtolower($value), strtolower($condition[2])) !== false; break; case 'notContain': case 'notContains': $isFiltered = strpos(strtolower($value), strtolower($condition[2])) === false; break; case 'startWith': case 'startsWith': $isFiltered = strpos(strtolower($value), strtolower($condition[2])) === 0; break; case 'notStartWith': case 'notStartsWith': $isFiltered = strpos(strtolower($value), strtolower($condition[2])) !== 0; break; case 'endWith': case 'endsWith': $isFiltered = strpos(strrev(strtolower($value)), strrev(strtolower($condition[2]))) === 0; break; case 'notEndWith': case 'notEndsWith': $isFiltered = strpos(strrev(strtolower($value)), strrev(strtolower($condition[2]))) !== 0; break; case 'between': $isFiltered = $value > $condition[2] && $value < $condition[3]; break; case 'notBetween': $isFiltered = !($value > $condition[2] && $value < $condition[3]); break; case "in": if (!is_array($condition[2])) { $condition[2] = array($condition[2]); } $isFiltered = in_array($value, $condition[2]); break; case "notIn": if (!is_array($condition[2])) { $condition[2] = array($condition[2]); } $isFiltered = !in_array($value, $condition[2]); break; default: break; } return $isFiltered; }
[ "public", "function", "isFiltered", "(", "$", "condition", ",", "$", "value", ",", "$", "type", ")", "{", "$", "isFiltered", "=", "true", ";", "switch", "(", "$", "condition", "[", "1", "]", ")", "{", "case", "'='", ":", "case", "'=='", ":", "case", "'equal'", ":", "if", "(", "$", "type", "===", "'string'", "&&", "is_string", "(", "$", "value", ")", "&&", "is_string", "(", "$", "condition", "[", "2", "]", ")", ")", "{", "$", "isFiltered", "=", "strcmp", "(", "$", "value", ",", "$", "condition", "[", "2", "]", ")", "==", "0", ";", "}", "else", "{", "$", "isFiltered", "=", "$", "value", "==", "$", "condition", "[", "2", "]", ";", "}", "break", ";", "case", "'!='", ":", "case", "'notEqual'", ":", "if", "(", "$", "type", "===", "'string'", "&&", "is_string", "(", "$", "value", ")", "&&", "is_string", "(", "$", "condition", "[", "2", "]", ")", ")", "{", "$", "isFiltered", "=", "strcmp", "(", "$", "value", ",", "$", "condition", "[", "2", "]", ")", "!=", "0", ";", "}", "else", "{", "$", "isFiltered", "=", "$", "value", "!=", "$", "condition", "[", "2", "]", ";", "}", "break", ";", "case", "'>'", ":", "case", "'gt'", ":", "if", "(", "$", "type", "===", "'string'", ")", "{", "$", "isFiltered", "=", "strcmp", "(", "$", "value", ",", "$", "condition", "[", "2", "]", ")", ">", "0", ";", "}", "else", "{", "$", "isFiltered", "=", "$", "value", ">", "$", "condition", "[", "2", "]", ";", "}", "break", ";", "case", "'>='", ":", "if", "(", "$", "type", "===", "'string'", ")", "{", "$", "isFiltered", "=", "strcmp", "(", "$", "value", ",", "$", "condition", "[", "2", "]", ")", ">=", "0", ";", "}", "else", "{", "$", "isFiltered", "=", "$", "value", ">=", "$", "condition", "[", "2", "]", ";", "}", "break", ";", "case", "'<'", ":", "case", "'lt'", ":", "if", "(", "$", "type", "===", "'string'", ")", "{", "$", "isFiltered", "=", "strcmp", "(", "$", "value", ",", "$", "condition", "[", "2", "]", ")", "<", "0", ";", "}", "else", "{", "$", "isFiltered", "=", "$", "value", "<", "$", "condition", "[", "2", "]", ";", "}", "break", ";", "case", "'<='", ":", "if", "(", "$", "type", "===", "'string'", ")", "{", "$", "isFiltered", "=", "strcmp", "(", "$", "value", ",", "$", "condition", "[", "2", "]", ")", "<=", "0", ";", "}", "else", "{", "$", "isFiltered", "=", "$", "value", "<=", "$", "condition", "[", "2", "]", ";", "}", "break", ";", "case", "'contain'", ":", "case", "'contains'", ":", "$", "isFiltered", "=", "strpos", "(", "strtolower", "(", "$", "value", ")", ",", "strtolower", "(", "$", "condition", "[", "2", "]", ")", ")", "!==", "false", ";", "break", ";", "case", "'notContain'", ":", "case", "'notContains'", ":", "$", "isFiltered", "=", "strpos", "(", "strtolower", "(", "$", "value", ")", ",", "strtolower", "(", "$", "condition", "[", "2", "]", ")", ")", "===", "false", ";", "break", ";", "case", "'startWith'", ":", "case", "'startsWith'", ":", "$", "isFiltered", "=", "strpos", "(", "strtolower", "(", "$", "value", ")", ",", "strtolower", "(", "$", "condition", "[", "2", "]", ")", ")", "===", "0", ";", "break", ";", "case", "'notStartWith'", ":", "case", "'notStartsWith'", ":", "$", "isFiltered", "=", "strpos", "(", "strtolower", "(", "$", "value", ")", ",", "strtolower", "(", "$", "condition", "[", "2", "]", ")", ")", "!==", "0", ";", "break", ";", "case", "'endWith'", ":", "case", "'endsWith'", ":", "$", "isFiltered", "=", "strpos", "(", "strrev", "(", "strtolower", "(", "$", "value", ")", ")", ",", "strrev", "(", "strtolower", "(", "$", "condition", "[", "2", "]", ")", ")", ")", "===", "0", ";", "break", ";", "case", "'notEndWith'", ":", "case", "'notEndsWith'", ":", "$", "isFiltered", "=", "strpos", "(", "strrev", "(", "strtolower", "(", "$", "value", ")", ")", ",", "strrev", "(", "strtolower", "(", "$", "condition", "[", "2", "]", ")", ")", ")", "!==", "0", ";", "break", ";", "case", "'between'", ":", "$", "isFiltered", "=", "$", "value", ">", "$", "condition", "[", "2", "]", "&&", "$", "value", "<", "$", "condition", "[", "3", "]", ";", "break", ";", "case", "'notBetween'", ":", "$", "isFiltered", "=", "!", "(", "$", "value", ">", "$", "condition", "[", "2", "]", "&&", "$", "value", "<", "$", "condition", "[", "3", "]", ")", ";", "break", ";", "case", "\"in\"", ":", "if", "(", "!", "is_array", "(", "$", "condition", "[", "2", "]", ")", ")", "{", "$", "condition", "[", "2", "]", "=", "array", "(", "$", "condition", "[", "2", "]", ")", ";", "}", "$", "isFiltered", "=", "in_array", "(", "$", "value", ",", "$", "condition", "[", "2", "]", ")", ";", "break", ";", "case", "\"notIn\"", ":", "if", "(", "!", "is_array", "(", "$", "condition", "[", "2", "]", ")", ")", "{", "$", "condition", "[", "2", "]", "=", "array", "(", "$", "condition", "[", "2", "]", ")", ";", "}", "$", "isFiltered", "=", "!", "in_array", "(", "$", "value", ",", "$", "condition", "[", "2", "]", ")", ";", "break", ";", "default", ":", "break", ";", "}", "return", "$", "isFiltered", ";", "}" ]
Return true if result is filtered @param array $condition Condition @param mixed $value The value @param string $type The type of value @return bool Whether result is filtered
[ "Return", "true", "if", "result", "is", "filtered" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/processes/Filter.php#L60-L165
koolphp/koolreport
src/processes/Filter.php
Filter.onInput
protected function onInput($data) { $columnsMeta = $this->metaData['columns']; $filters = $this->filters; $logicalOperator = 'and'; $isFiltered = true; foreach ($filters as $i => $filter) { if (is_array($filter)) { $field = $filter[0]; $type = $columnsMeta[$field]['type']; if (!isset($data[$field])) { continue; } $filterResult = $this->isFiltered($filter, $data[$field], $type); if ($logicalOperator === 'and') { $isFiltered = $isFiltered && $filterResult; } if ($logicalOperator === 'or') { $isFiltered = $isFiltered || $filterResult; } } else if ($filter === 'and' || $filter === 'or') { $logicalOperator = $filter; if ($filter === 'or' && $i === 0) { $isFiltered = false; } } } if ($isFiltered) { $this->next($data); } }
php
protected function onInput($data) { $columnsMeta = $this->metaData['columns']; $filters = $this->filters; $logicalOperator = 'and'; $isFiltered = true; foreach ($filters as $i => $filter) { if (is_array($filter)) { $field = $filter[0]; $type = $columnsMeta[$field]['type']; if (!isset($data[$field])) { continue; } $filterResult = $this->isFiltered($filter, $data[$field], $type); if ($logicalOperator === 'and') { $isFiltered = $isFiltered && $filterResult; } if ($logicalOperator === 'or') { $isFiltered = $isFiltered || $filterResult; } } else if ($filter === 'and' || $filter === 'or') { $logicalOperator = $filter; if ($filter === 'or' && $i === 0) { $isFiltered = false; } } } if ($isFiltered) { $this->next($data); } }
[ "protected", "function", "onInput", "(", "$", "data", ")", "{", "$", "columnsMeta", "=", "$", "this", "->", "metaData", "[", "'columns'", "]", ";", "$", "filters", "=", "$", "this", "->", "filters", ";", "$", "logicalOperator", "=", "'and'", ";", "$", "isFiltered", "=", "true", ";", "foreach", "(", "$", "filters", "as", "$", "i", "=>", "$", "filter", ")", "{", "if", "(", "is_array", "(", "$", "filter", ")", ")", "{", "$", "field", "=", "$", "filter", "[", "0", "]", ";", "$", "type", "=", "$", "columnsMeta", "[", "$", "field", "]", "[", "'type'", "]", ";", "if", "(", "!", "isset", "(", "$", "data", "[", "$", "field", "]", ")", ")", "{", "continue", ";", "}", "$", "filterResult", "=", "$", "this", "->", "isFiltered", "(", "$", "filter", ",", "$", "data", "[", "$", "field", "]", ",", "$", "type", ")", ";", "if", "(", "$", "logicalOperator", "===", "'and'", ")", "{", "$", "isFiltered", "=", "$", "isFiltered", "&&", "$", "filterResult", ";", "}", "if", "(", "$", "logicalOperator", "===", "'or'", ")", "{", "$", "isFiltered", "=", "$", "isFiltered", "||", "$", "filterResult", ";", "}", "}", "else", "if", "(", "$", "filter", "===", "'and'", "||", "$", "filter", "===", "'or'", ")", "{", "$", "logicalOperator", "=", "$", "filter", ";", "if", "(", "$", "filter", "===", "'or'", "&&", "$", "i", "===", "0", ")", "{", "$", "isFiltered", "=", "false", ";", "}", "}", "}", "if", "(", "$", "isFiltered", ")", "{", "$", "this", "->", "next", "(", "$", "data", ")", ";", "}", "}" ]
Handle on data input @param array $data The input data row @return null
[ "Handle", "on", "data", "input" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/processes/Filter.php#L174-L206
koolphp/koolreport
src/core/Theme.php
Theme.colorScheme
public function colorScheme($key=null) { $all = $this->allColorSchemes(); $allKeys = array_keys($all); if (count($allKeys)>0) { if ($key && isset($all[strtolower($key)])) { return $all[strtolower($key)]; } return $all[$allKeys[0]]; } return null; }
php
public function colorScheme($key=null) { $all = $this->allColorSchemes(); $allKeys = array_keys($all); if (count($allKeys)>0) { if ($key && isset($all[strtolower($key)])) { return $all[strtolower($key)]; } return $all[$allKeys[0]]; } return null; }
[ "public", "function", "colorScheme", "(", "$", "key", "=", "null", ")", "{", "$", "all", "=", "$", "this", "->", "allColorSchemes", "(", ")", ";", "$", "allKeys", "=", "array_keys", "(", "$", "all", ")", ";", "if", "(", "count", "(", "$", "allKeys", ")", ">", "0", ")", "{", "if", "(", "$", "key", "&&", "isset", "(", "$", "all", "[", "strtolower", "(", "$", "key", ")", "]", ")", ")", "{", "return", "$", "all", "[", "strtolower", "(", "$", "key", ")", "]", ";", "}", "return", "$", "all", "[", "$", "allKeys", "[", "0", "]", "]", ";", "}", "return", "null", ";", "}" ]
Get color scheme @param string $key Name of color scheme we want to get, if null the first color scheme will be return. @return array Array of colors, null if there is no available
[ "Get", "color", "scheme" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/core/Theme.php#L108-L119
koolphp/koolreport
src/core/Theme.php
Theme.doesSupport
public function doesSupport($widget) { if (gettype($widget)!="string") { $widget = get_class($widget); } return isset($this->themeWidgets()[$widget]); }
php
public function doesSupport($widget) { if (gettype($widget)!="string") { $widget = get_class($widget); } return isset($this->themeWidgets()[$widget]); }
[ "public", "function", "doesSupport", "(", "$", "widget", ")", "{", "if", "(", "gettype", "(", "$", "widget", ")", "!=", "\"string\"", ")", "{", "$", "widget", "=", "get_class", "(", "$", "widget", ")", ";", "}", "return", "isset", "(", "$", "this", "->", "themeWidgets", "(", ")", "[", "$", "widget", "]", ")", ";", "}" ]
Whether theme support a widget @param Widget $widget String of classname or object @return boolean Whether theme support a widget
[ "Whether", "theme", "support", "a", "widget" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/core/Theme.php#L158-L164
koolphp/koolreport
src/core/Theme.php
Theme.getWidgetResourcesFor
public function getWidgetResourcesFor($widget) { $resources = array( "js"=>array(), "css"=>array(), "replacingCss"=>array(), "replacingJs"=>array(), ); if (gettype($widget)!="string") { $widget = get_class($widget); } $settings = $this->themeWidgets()[$widget]; if (isset($settings["folder"])) { $version = Utility::get($this->themeInfo(), "version", ""); $assetUrl = $this->getReport() ->getResourceManager() ->publishAssetFolder( realpath( dirname(Utility::getClassPath($this))."/".$settings["folder"] ), $version ); $replacingCss = Utility::get($settings, "replacingCss", array()); $resources["replacingCss"] = $this->addingAssetUrl( $assetUrl, $replacingCss ); $css = Utility::get($settings, "css", array()); $resources["css"] = $this->addingAssetUrl($assetUrl, $css); $replacingJs = Utility::get($settings, "replacingJs", array()); $resources["replacingJs"] = $this->addingAssetUrl($assetUrl, $replacingJs); $js = Utility::get($settings, "js", array()); $resources["js"] = $this->addingAssetUrl($assetUrl, $js); } return $resources; }
php
public function getWidgetResourcesFor($widget) { $resources = array( "js"=>array(), "css"=>array(), "replacingCss"=>array(), "replacingJs"=>array(), ); if (gettype($widget)!="string") { $widget = get_class($widget); } $settings = $this->themeWidgets()[$widget]; if (isset($settings["folder"])) { $version = Utility::get($this->themeInfo(), "version", ""); $assetUrl = $this->getReport() ->getResourceManager() ->publishAssetFolder( realpath( dirname(Utility::getClassPath($this))."/".$settings["folder"] ), $version ); $replacingCss = Utility::get($settings, "replacingCss", array()); $resources["replacingCss"] = $this->addingAssetUrl( $assetUrl, $replacingCss ); $css = Utility::get($settings, "css", array()); $resources["css"] = $this->addingAssetUrl($assetUrl, $css); $replacingJs = Utility::get($settings, "replacingJs", array()); $resources["replacingJs"] = $this->addingAssetUrl($assetUrl, $replacingJs); $js = Utility::get($settings, "js", array()); $resources["js"] = $this->addingAssetUrl($assetUrl, $js); } return $resources; }
[ "public", "function", "getWidgetResourcesFor", "(", "$", "widget", ")", "{", "$", "resources", "=", "array", "(", "\"js\"", "=>", "array", "(", ")", ",", "\"css\"", "=>", "array", "(", ")", ",", "\"replacingCss\"", "=>", "array", "(", ")", ",", "\"replacingJs\"", "=>", "array", "(", ")", ",", ")", ";", "if", "(", "gettype", "(", "$", "widget", ")", "!=", "\"string\"", ")", "{", "$", "widget", "=", "get_class", "(", "$", "widget", ")", ";", "}", "$", "settings", "=", "$", "this", "->", "themeWidgets", "(", ")", "[", "$", "widget", "]", ";", "if", "(", "isset", "(", "$", "settings", "[", "\"folder\"", "]", ")", ")", "{", "$", "version", "=", "Utility", "::", "get", "(", "$", "this", "->", "themeInfo", "(", ")", ",", "\"version\"", ",", "\"\"", ")", ";", "$", "assetUrl", "=", "$", "this", "->", "getReport", "(", ")", "->", "getResourceManager", "(", ")", "->", "publishAssetFolder", "(", "realpath", "(", "dirname", "(", "Utility", "::", "getClassPath", "(", "$", "this", ")", ")", ".", "\"/\"", ".", "$", "settings", "[", "\"folder\"", "]", ")", ",", "$", "version", ")", ";", "$", "replacingCss", "=", "Utility", "::", "get", "(", "$", "settings", ",", "\"replacingCss\"", ",", "array", "(", ")", ")", ";", "$", "resources", "[", "\"replacingCss\"", "]", "=", "$", "this", "->", "addingAssetUrl", "(", "$", "assetUrl", ",", "$", "replacingCss", ")", ";", "$", "css", "=", "Utility", "::", "get", "(", "$", "settings", ",", "\"css\"", ",", "array", "(", ")", ")", ";", "$", "resources", "[", "\"css\"", "]", "=", "$", "this", "->", "addingAssetUrl", "(", "$", "assetUrl", ",", "$", "css", ")", ";", "$", "replacingJs", "=", "Utility", "::", "get", "(", "$", "settings", ",", "\"replacingJs\"", ",", "array", "(", ")", ")", ";", "$", "resources", "[", "\"replacingJs\"", "]", "=", "$", "this", "->", "addingAssetUrl", "(", "$", "assetUrl", ",", "$", "replacingJs", ")", ";", "$", "js", "=", "Utility", "::", "get", "(", "$", "settings", ",", "\"js\"", ",", "array", "(", ")", ")", ";", "$", "resources", "[", "\"js\"", "]", "=", "$", "this", "->", "addingAssetUrl", "(", "$", "assetUrl", ",", "$", "js", ")", ";", "}", "return", "$", "resources", ";", "}" ]
Return resources information of an widget The method will check if the theme support this widget and if yes, it will return supported resources provided by the theme. @param mixed $widget We can input either name of widget class or the widget object @return array Associated array contaning resources for widget.
[ "Return", "resources", "information", "of", "an", "widget" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/core/Theme.php#L177-L219
koolphp/koolreport
src/core/Theme.php
Theme.addingAssetUrl
protected function addingAssetUrl($assetUrl,$resources) { foreach ($resources as &$resource) { if (gettype($resource)=="string") { $resource = $assetUrl."/".$resource; } else if (gettype($resource)=="array") { $resource = $this->addingAssetUrl($assetUrl, $resource); } } return $resources; }
php
protected function addingAssetUrl($assetUrl,$resources) { foreach ($resources as &$resource) { if (gettype($resource)=="string") { $resource = $assetUrl."/".$resource; } else if (gettype($resource)=="array") { $resource = $this->addingAssetUrl($assetUrl, $resource); } } return $resources; }
[ "protected", "function", "addingAssetUrl", "(", "$", "assetUrl", ",", "$", "resources", ")", "{", "foreach", "(", "$", "resources", "as", "&", "$", "resource", ")", "{", "if", "(", "gettype", "(", "$", "resource", ")", "==", "\"string\"", ")", "{", "$", "resource", "=", "$", "assetUrl", ".", "\"/\"", ".", "$", "resource", ";", "}", "else", "if", "(", "gettype", "(", "$", "resource", ")", "==", "\"array\"", ")", "{", "$", "resource", "=", "$", "this", "->", "addingAssetUrl", "(", "$", "assetUrl", ",", "$", "resource", ")", ";", "}", "}", "return", "$", "resources", ";", "}" ]
Get resources in short format and return full url to each component of resources @param string $assetUrl The url to asset folder @param array $resources Resources in short form @return array Resource in long form.
[ "Get", "resources", "in", "short", "format", "and", "return", "full", "url", "to", "each", "component", "of", "resources" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/core/Theme.php#L229-L239
koolphp/koolreport
src/core/DataStore.php
DataStore.meta
public function meta($metaData=null) { if ($metaData) { $this->metaData = $metaData; return $this; } else { return $this->metaData; } }
php
public function meta($metaData=null) { if ($metaData) { $this->metaData = $metaData; return $this; } else { return $this->metaData; } }
[ "public", "function", "meta", "(", "$", "metaData", "=", "null", ")", "{", "if", "(", "$", "metaData", ")", "{", "$", "this", "->", "metaData", "=", "$", "metaData", ";", "return", "$", "this", ";", "}", "else", "{", "return", "$", "this", "->", "metaData", ";", "}", "}" ]
Get or set the meta data of datastore If there is no parameter, the method will return current meta data. If metaData is input, it will save that new meta data @param array $metaData Associate array contaning meta data @return array Meta data in array form @since 1.0.0
[ "Get", "or", "set", "the", "meta", "data", "of", "datastore" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/core/DataStore.php#L125-L133
koolphp/koolreport
src/core/DataStore.php
DataStore.data
public function data($rows=null) { if ($rows!==null) { $this->rows = $rows; return $this; } else { return $this->rows; } }
php
public function data($rows=null) { if ($rows!==null) { $this->rows = $rows; return $this; } else { return $this->rows; } }
[ "public", "function", "data", "(", "$", "rows", "=", "null", ")", "{", "if", "(", "$", "rows", "!==", "null", ")", "{", "$", "this", "->", "rows", "=", "$", "rows", ";", "return", "$", "this", ";", "}", "else", "{", "return", "$", "this", "->", "rows", ";", "}", "}" ]
Get or set data inside DataStore If no parameter is input, the method will return all rows. If rows parameter is input, method will save it @param array $rows Rows of data @return array Rows of data @since 1.0.0
[ "Get", "or", "set", "data", "inside", "DataStore" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/core/DataStore.php#L147-L155
koolphp/koolreport
src/core/DataStore.php
DataStore.get
public function get($index=0,$colName=null) { if (isset($this->rows[$index])) { if ($colName!==null) { if (isset($this->rows[$index][$colName])) { return $this->rows[$index][$colName]; } } else { return $this->rows[$index]; } } return null; }
php
public function get($index=0,$colName=null) { if (isset($this->rows[$index])) { if ($colName!==null) { if (isset($this->rows[$index][$colName])) { return $this->rows[$index][$colName]; } } else { return $this->rows[$index]; } } return null; }
[ "public", "function", "get", "(", "$", "index", "=", "0", ",", "$", "colName", "=", "null", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "rows", "[", "$", "index", "]", ")", ")", "{", "if", "(", "$", "colName", "!==", "null", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "rows", "[", "$", "index", "]", "[", "$", "colName", "]", ")", ")", "{", "return", "$", "this", "->", "rows", "[", "$", "index", "]", "[", "$", "colName", "]", ";", "}", "}", "else", "{", "return", "$", "this", "->", "rows", "[", "$", "index", "]", ";", "}", "}", "return", "null", ";", "}" ]
Return a data row at index or single value at column name @param integer $index At what index you want to get row @param string $colName What field you want to get value from @return mixed Could be array of row or single value
[ "Return", "a", "data", "row", "at", "index", "or", "single", "value", "at", "column", "name" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/core/DataStore.php#L199-L211
koolphp/koolreport
src/core/DataStore.php
DataStore.breakGroup
public function breakGroup($key,$func) { $data = array(); $start = 0; foreach ($this->rows as $i=>$row) { if (!isset($oldValue)) { $oldValue = $row[$key]; } if ($row[$key]==$oldValue) { $oldValue = $row[$key]; array_push($data, $row); } else { $func(new DataStore($data, $this->metaData), $start); $start = $i; $data = array($row); $oldValue = $row[$key]; } } $func(new DataStore($data, $this->metaData), $start); }
php
public function breakGroup($key,$func) { $data = array(); $start = 0; foreach ($this->rows as $i=>$row) { if (!isset($oldValue)) { $oldValue = $row[$key]; } if ($row[$key]==$oldValue) { $oldValue = $row[$key]; array_push($data, $row); } else { $func(new DataStore($data, $this->metaData), $start); $start = $i; $data = array($row); $oldValue = $row[$key]; } } $func(new DataStore($data, $this->metaData), $start); }
[ "public", "function", "breakGroup", "(", "$", "key", ",", "$", "func", ")", "{", "$", "data", "=", "array", "(", ")", ";", "$", "start", "=", "0", ";", "foreach", "(", "$", "this", "->", "rows", "as", "$", "i", "=>", "$", "row", ")", "{", "if", "(", "!", "isset", "(", "$", "oldValue", ")", ")", "{", "$", "oldValue", "=", "$", "row", "[", "$", "key", "]", ";", "}", "if", "(", "$", "row", "[", "$", "key", "]", "==", "$", "oldValue", ")", "{", "$", "oldValue", "=", "$", "row", "[", "$", "key", "]", ";", "array_push", "(", "$", "data", ",", "$", "row", ")", ";", "}", "else", "{", "$", "func", "(", "new", "DataStore", "(", "$", "data", ",", "$", "this", "->", "metaData", ")", ",", "$", "start", ")", ";", "$", "start", "=", "$", "i", ";", "$", "data", "=", "array", "(", "$", "row", ")", ";", "$", "oldValue", "=", "$", "row", "[", "$", "key", "]", ";", "}", "}", "$", "func", "(", "new", "DataStore", "(", "$", "data", ",", "$", "this", "->", "metaData", ")", ",", "$", "start", ")", ";", "}" ]
Break datastore into smaller group by specific column value @param string $key The key column used to break datastore into groups @param function $func Anonymous function to be called when a group is form @return null
[ "Break", "datastore", "into", "smaller", "group", "by", "specific", "column", "value" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/core/DataStore.php#L221-L241
koolphp/koolreport
src/core/DataStore.php
DataStore.filter
public function filter() { $condition = func_get_args(); $cName = Utility::get($condition, 0); if (gettype($cName)=="object" && is_callable($cName)) { //Able to filter by function return $this->filterByFunc($cName); } $operator = Utility::get($condition, 1); $value = Utility::get($condition, 2); $optional_value = Utility::get($condition, 3); if ($cName===null||$operator===null) { throw new \Exception('dataStore->filter() requires condition in array form ($colname,$operator,$value)'); } $result = array(); $cType = $this->metaData["columns"][$cName]["type"]; $dtFormat = null; if (in_array($cType, array("datetime", "date", "time"))) { switch ($cType) { case "datetime": $dtFormat = Utility::get($this->metaData["columns"][$cName], "format", "Y-m-d H:i:s"); break; case "date": $dtFormat = Utility::get($this->metaData["columns"][$cName], "format", "Y-m-d"); break; case "time": $dtFormat = Utility::get($this->metaData["columns"][$cName], "format", "H:i:s"); break; } $value = \DateTime::createFromFormat($dtFormat, $value); } foreach ($this->rows as $row) { $columnValue = $row[$cName]; if ($dtFormat!==null) { $columnValue = \DateTime::createFromFormat($dtFormat, $columnValue); } switch($operator) { case "=": case "==": case "equal": if ($columnValue==$value) { array_push($result, $row); } break; case "===": if ($columnValue===$value) { array_push($result, $row); } break; case "!=": case "notEqual": if ($columnValue!=$value) { array_push($result, $row); } break; case "!==": if ($columnValue!==$value) { array_push($result, $row); } break; case ">": case "gt": if ($columnValue>$value) { array_push($result, $row); } break; case ">=": if ($columnValue>=$value) { array_push($result, $row); } break; case "<": case "lt": if ($columnValue<$value) { array_push($result, $row); } break; case "<=": if ($columnValue<=$value) { array_push($result, $row); } break; case "contain": case "contains": if (strpos(strtolower($columnValue), strtolower($value))!==false) { array_push($result, $row); } break; case "notContain": case "notContains": if (strpos(strtolower($columnValue), strtolower($value))===false) { array_push($result, $row); } break; case "between": if ($value<$columnValue && $columnValue<$optional_value) { array_push($result, $row); } break; case "notBetween": if (!($value<$columnValue && $columnValue<$optional_value)) { array_push($result, $row); } break; case "in": if (!is_array($value)) { $value = array($value); } if (in_array($columnValue, $value)) { array_push($result, $row); } break; case "notIn": if (!is_array($value)) { $value = array($value); } if (!in_array($columnValue, $value)) { array_push($result, $row); } break; case "startWith": case "startsWith": if (strpos(strtolower($columnValue), strtolower($value)) === 0) { array_push($result, $row); } break; case "notStartWith": case "notStartsWith": if (strpos(strtolower($columnValue), strtolower($value)) !== 0) { array_push($result, $row); } break; case "endWith": case "endsWith": if (strpos(strrev(strtolower($columnValue)), strrev(strtolower($value))) === 0) { array_push($result, $row); } break; case "notEndWith": case "notEndsWith": if (strpos(strrev(strtolower($columnValue)), strrev(strtolower($value))) !== 0) { array_push($result, $row); } break; default: throw new \Exception("Unknown operator [$operator]"); return $this; break; } } return new DataStore($result, $this->metaData); }
php
public function filter() { $condition = func_get_args(); $cName = Utility::get($condition, 0); if (gettype($cName)=="object" && is_callable($cName)) { //Able to filter by function return $this->filterByFunc($cName); } $operator = Utility::get($condition, 1); $value = Utility::get($condition, 2); $optional_value = Utility::get($condition, 3); if ($cName===null||$operator===null) { throw new \Exception('dataStore->filter() requires condition in array form ($colname,$operator,$value)'); } $result = array(); $cType = $this->metaData["columns"][$cName]["type"]; $dtFormat = null; if (in_array($cType, array("datetime", "date", "time"))) { switch ($cType) { case "datetime": $dtFormat = Utility::get($this->metaData["columns"][$cName], "format", "Y-m-d H:i:s"); break; case "date": $dtFormat = Utility::get($this->metaData["columns"][$cName], "format", "Y-m-d"); break; case "time": $dtFormat = Utility::get($this->metaData["columns"][$cName], "format", "H:i:s"); break; } $value = \DateTime::createFromFormat($dtFormat, $value); } foreach ($this->rows as $row) { $columnValue = $row[$cName]; if ($dtFormat!==null) { $columnValue = \DateTime::createFromFormat($dtFormat, $columnValue); } switch($operator) { case "=": case "==": case "equal": if ($columnValue==$value) { array_push($result, $row); } break; case "===": if ($columnValue===$value) { array_push($result, $row); } break; case "!=": case "notEqual": if ($columnValue!=$value) { array_push($result, $row); } break; case "!==": if ($columnValue!==$value) { array_push($result, $row); } break; case ">": case "gt": if ($columnValue>$value) { array_push($result, $row); } break; case ">=": if ($columnValue>=$value) { array_push($result, $row); } break; case "<": case "lt": if ($columnValue<$value) { array_push($result, $row); } break; case "<=": if ($columnValue<=$value) { array_push($result, $row); } break; case "contain": case "contains": if (strpos(strtolower($columnValue), strtolower($value))!==false) { array_push($result, $row); } break; case "notContain": case "notContains": if (strpos(strtolower($columnValue), strtolower($value))===false) { array_push($result, $row); } break; case "between": if ($value<$columnValue && $columnValue<$optional_value) { array_push($result, $row); } break; case "notBetween": if (!($value<$columnValue && $columnValue<$optional_value)) { array_push($result, $row); } break; case "in": if (!is_array($value)) { $value = array($value); } if (in_array($columnValue, $value)) { array_push($result, $row); } break; case "notIn": if (!is_array($value)) { $value = array($value); } if (!in_array($columnValue, $value)) { array_push($result, $row); } break; case "startWith": case "startsWith": if (strpos(strtolower($columnValue), strtolower($value)) === 0) { array_push($result, $row); } break; case "notStartWith": case "notStartsWith": if (strpos(strtolower($columnValue), strtolower($value)) !== 0) { array_push($result, $row); } break; case "endWith": case "endsWith": if (strpos(strrev(strtolower($columnValue)), strrev(strtolower($value))) === 0) { array_push($result, $row); } break; case "notEndWith": case "notEndsWith": if (strpos(strrev(strtolower($columnValue)), strrev(strtolower($value))) !== 0) { array_push($result, $row); } break; default: throw new \Exception("Unknown operator [$operator]"); return $this; break; } } return new DataStore($result, $this->metaData); }
[ "public", "function", "filter", "(", ")", "{", "$", "condition", "=", "func_get_args", "(", ")", ";", "$", "cName", "=", "Utility", "::", "get", "(", "$", "condition", ",", "0", ")", ";", "if", "(", "gettype", "(", "$", "cName", ")", "==", "\"object\"", "&&", "is_callable", "(", "$", "cName", ")", ")", "{", "//Able to filter by function", "return", "$", "this", "->", "filterByFunc", "(", "$", "cName", ")", ";", "}", "$", "operator", "=", "Utility", "::", "get", "(", "$", "condition", ",", "1", ")", ";", "$", "value", "=", "Utility", "::", "get", "(", "$", "condition", ",", "2", ")", ";", "$", "optional_value", "=", "Utility", "::", "get", "(", "$", "condition", ",", "3", ")", ";", "if", "(", "$", "cName", "===", "null", "||", "$", "operator", "===", "null", ")", "{", "throw", "new", "\\", "Exception", "(", "'dataStore->filter() requires condition in array form ($colname,$operator,$value)'", ")", ";", "}", "$", "result", "=", "array", "(", ")", ";", "$", "cType", "=", "$", "this", "->", "metaData", "[", "\"columns\"", "]", "[", "$", "cName", "]", "[", "\"type\"", "]", ";", "$", "dtFormat", "=", "null", ";", "if", "(", "in_array", "(", "$", "cType", ",", "array", "(", "\"datetime\"", ",", "\"date\"", ",", "\"time\"", ")", ")", ")", "{", "switch", "(", "$", "cType", ")", "{", "case", "\"datetime\"", ":", "$", "dtFormat", "=", "Utility", "::", "get", "(", "$", "this", "->", "metaData", "[", "\"columns\"", "]", "[", "$", "cName", "]", ",", "\"format\"", ",", "\"Y-m-d H:i:s\"", ")", ";", "break", ";", "case", "\"date\"", ":", "$", "dtFormat", "=", "Utility", "::", "get", "(", "$", "this", "->", "metaData", "[", "\"columns\"", "]", "[", "$", "cName", "]", ",", "\"format\"", ",", "\"Y-m-d\"", ")", ";", "break", ";", "case", "\"time\"", ":", "$", "dtFormat", "=", "Utility", "::", "get", "(", "$", "this", "->", "metaData", "[", "\"columns\"", "]", "[", "$", "cName", "]", ",", "\"format\"", ",", "\"H:i:s\"", ")", ";", "break", ";", "}", "$", "value", "=", "\\", "DateTime", "::", "createFromFormat", "(", "$", "dtFormat", ",", "$", "value", ")", ";", "}", "foreach", "(", "$", "this", "->", "rows", "as", "$", "row", ")", "{", "$", "columnValue", "=", "$", "row", "[", "$", "cName", "]", ";", "if", "(", "$", "dtFormat", "!==", "null", ")", "{", "$", "columnValue", "=", "\\", "DateTime", "::", "createFromFormat", "(", "$", "dtFormat", ",", "$", "columnValue", ")", ";", "}", "switch", "(", "$", "operator", ")", "{", "case", "\"=\"", ":", "case", "\"==\"", ":", "case", "\"equal\"", ":", "if", "(", "$", "columnValue", "==", "$", "value", ")", "{", "array_push", "(", "$", "result", ",", "$", "row", ")", ";", "}", "break", ";", "case", "\"===\"", ":", "if", "(", "$", "columnValue", "===", "$", "value", ")", "{", "array_push", "(", "$", "result", ",", "$", "row", ")", ";", "}", "break", ";", "case", "\"!=\"", ":", "case", "\"notEqual\"", ":", "if", "(", "$", "columnValue", "!=", "$", "value", ")", "{", "array_push", "(", "$", "result", ",", "$", "row", ")", ";", "}", "break", ";", "case", "\"!==\"", ":", "if", "(", "$", "columnValue", "!==", "$", "value", ")", "{", "array_push", "(", "$", "result", ",", "$", "row", ")", ";", "}", "break", ";", "case", "\">\"", ":", "case", "\"gt\"", ":", "if", "(", "$", "columnValue", ">", "$", "value", ")", "{", "array_push", "(", "$", "result", ",", "$", "row", ")", ";", "}", "break", ";", "case", "\">=\"", ":", "if", "(", "$", "columnValue", ">=", "$", "value", ")", "{", "array_push", "(", "$", "result", ",", "$", "row", ")", ";", "}", "break", ";", "case", "\"<\"", ":", "case", "\"lt\"", ":", "if", "(", "$", "columnValue", "<", "$", "value", ")", "{", "array_push", "(", "$", "result", ",", "$", "row", ")", ";", "}", "break", ";", "case", "\"<=\"", ":", "if", "(", "$", "columnValue", "<=", "$", "value", ")", "{", "array_push", "(", "$", "result", ",", "$", "row", ")", ";", "}", "break", ";", "case", "\"contain\"", ":", "case", "\"contains\"", ":", "if", "(", "strpos", "(", "strtolower", "(", "$", "columnValue", ")", ",", "strtolower", "(", "$", "value", ")", ")", "!==", "false", ")", "{", "array_push", "(", "$", "result", ",", "$", "row", ")", ";", "}", "break", ";", "case", "\"notContain\"", ":", "case", "\"notContains\"", ":", "if", "(", "strpos", "(", "strtolower", "(", "$", "columnValue", ")", ",", "strtolower", "(", "$", "value", ")", ")", "===", "false", ")", "{", "array_push", "(", "$", "result", ",", "$", "row", ")", ";", "}", "break", ";", "case", "\"between\"", ":", "if", "(", "$", "value", "<", "$", "columnValue", "&&", "$", "columnValue", "<", "$", "optional_value", ")", "{", "array_push", "(", "$", "result", ",", "$", "row", ")", ";", "}", "break", ";", "case", "\"notBetween\"", ":", "if", "(", "!", "(", "$", "value", "<", "$", "columnValue", "&&", "$", "columnValue", "<", "$", "optional_value", ")", ")", "{", "array_push", "(", "$", "result", ",", "$", "row", ")", ";", "}", "break", ";", "case", "\"in\"", ":", "if", "(", "!", "is_array", "(", "$", "value", ")", ")", "{", "$", "value", "=", "array", "(", "$", "value", ")", ";", "}", "if", "(", "in_array", "(", "$", "columnValue", ",", "$", "value", ")", ")", "{", "array_push", "(", "$", "result", ",", "$", "row", ")", ";", "}", "break", ";", "case", "\"notIn\"", ":", "if", "(", "!", "is_array", "(", "$", "value", ")", ")", "{", "$", "value", "=", "array", "(", "$", "value", ")", ";", "}", "if", "(", "!", "in_array", "(", "$", "columnValue", ",", "$", "value", ")", ")", "{", "array_push", "(", "$", "result", ",", "$", "row", ")", ";", "}", "break", ";", "case", "\"startWith\"", ":", "case", "\"startsWith\"", ":", "if", "(", "strpos", "(", "strtolower", "(", "$", "columnValue", ")", ",", "strtolower", "(", "$", "value", ")", ")", "===", "0", ")", "{", "array_push", "(", "$", "result", ",", "$", "row", ")", ";", "}", "break", ";", "case", "\"notStartWith\"", ":", "case", "\"notStartsWith\"", ":", "if", "(", "strpos", "(", "strtolower", "(", "$", "columnValue", ")", ",", "strtolower", "(", "$", "value", ")", ")", "!==", "0", ")", "{", "array_push", "(", "$", "result", ",", "$", "row", ")", ";", "}", "break", ";", "case", "\"endWith\"", ":", "case", "\"endsWith\"", ":", "if", "(", "strpos", "(", "strrev", "(", "strtolower", "(", "$", "columnValue", ")", ")", ",", "strrev", "(", "strtolower", "(", "$", "value", ")", ")", ")", "===", "0", ")", "{", "array_push", "(", "$", "result", ",", "$", "row", ")", ";", "}", "break", ";", "case", "\"notEndWith\"", ":", "case", "\"notEndsWith\"", ":", "if", "(", "strpos", "(", "strrev", "(", "strtolower", "(", "$", "columnValue", ")", ")", ",", "strrev", "(", "strtolower", "(", "$", "value", ")", ")", ")", "!==", "0", ")", "{", "array_push", "(", "$", "result", ",", "$", "row", ")", ";", "}", "break", ";", "default", ":", "throw", "new", "\\", "Exception", "(", "\"Unknown operator [$operator]\"", ")", ";", "return", "$", "this", ";", "break", ";", "}", "}", "return", "new", "DataStore", "(", "$", "result", ",", "$", "this", "->", "metaData", ")", ";", "}" ]
Filter the data set with condition Examples: $dataStore->filter('age','>',45); $dataStore->filter('age','between',45,65); @return DataStore New datastore with filtered result
[ "Filter", "the", "data", "set", "with", "condition" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/core/DataStore.php#L253-L409
koolphp/koolreport
src/core/DataStore.php
DataStore.top
public function top($num,$offset=0) { $count = $this->countData(); $result = array(); for ($i=$offset;$i<$num+$offset && $i<$count;$i++) { array_push($result, $this->rows[$i]); } return new DataStore($result, $this->metaData); }
php
public function top($num,$offset=0) { $count = $this->countData(); $result = array(); for ($i=$offset;$i<$num+$offset && $i<$count;$i++) { array_push($result, $this->rows[$i]); } return new DataStore($result, $this->metaData); }
[ "public", "function", "top", "(", "$", "num", ",", "$", "offset", "=", "0", ")", "{", "$", "count", "=", "$", "this", "->", "countData", "(", ")", ";", "$", "result", "=", "array", "(", ")", ";", "for", "(", "$", "i", "=", "$", "offset", ";", "$", "i", "<", "$", "num", "+", "$", "offset", "&&", "$", "i", "<", "$", "count", ";", "$", "i", "++", ")", "{", "array_push", "(", "$", "result", ",", "$", "this", "->", "rows", "[", "$", "i", "]", ")", ";", "}", "return", "new", "DataStore", "(", "$", "result", ",", "$", "this", "->", "metaData", ")", ";", "}" ]
Return top number of rows It will return top rows starting at specified offset. If offset is not specified, the default value is 0. @param integer $num Number of top row you want to get @param integer $offset At what index you want to start getting rows @return DataStore New DataStore containing result
[ "Return", "top", "number", "of", "rows" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/core/DataStore.php#L438-L446
koolphp/koolreport
src/core/DataStore.php
DataStore.topByPercent
public function topByPercent($num) { $count = $this->countData(); return $this->top(round($num*$count/100)); }
php
public function topByPercent($num) { $count = $this->countData(); return $this->top(round($num*$count/100)); }
[ "public", "function", "topByPercent", "(", "$", "num", ")", "{", "$", "count", "=", "$", "this", "->", "countData", "(", ")", ";", "return", "$", "this", "->", "top", "(", "round", "(", "$", "num", "*", "$", "count", "/", "100", ")", ")", ";", "}" ]
Return top percent of row @param float $num What top percent of row you want to return @return DataStore New datastore containing result.
[ "Return", "top", "percent", "of", "row" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/core/DataStore.php#L455-L459
koolphp/koolreport
src/core/DataStore.php
DataStore.bottom
public function bottom($num) { $count = $this->countData(); $result = array(); $start = ($count>$num)?$count-$num:0; for ($i=$start;$i<$count;$i++) { array_push($result, $this->rows[$i]); } return new DataStore($result, $this->metaData); }
php
public function bottom($num) { $count = $this->countData(); $result = array(); $start = ($count>$num)?$count-$num:0; for ($i=$start;$i<$count;$i++) { array_push($result, $this->rows[$i]); } return new DataStore($result, $this->metaData); }
[ "public", "function", "bottom", "(", "$", "num", ")", "{", "$", "count", "=", "$", "this", "->", "countData", "(", ")", ";", "$", "result", "=", "array", "(", ")", ";", "$", "start", "=", "(", "$", "count", ">", "$", "num", ")", "?", "$", "count", "-", "$", "num", ":", "0", ";", "for", "(", "$", "i", "=", "$", "start", ";", "$", "i", "<", "$", "count", ";", "$", "i", "++", ")", "{", "array_push", "(", "$", "result", ",", "$", "this", "->", "rows", "[", "$", "i", "]", ")", ";", "}", "return", "new", "DataStore", "(", "$", "result", ",", "$", "this", "->", "metaData", ")", ";", "}" ]
Return bottom rows of dataset @param float $num Number of rows you want to return @return DataStore New datastore containing result.
[ "Return", "bottom", "rows", "of", "dataset" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/core/DataStore.php#L468-L477
koolphp/koolreport
src/core/DataStore.php
DataStore.bottomByPercent
public function bottomByPercent($num) { $count = $this->countData(); return $this->bottom(round($num*$count/100)); }
php
public function bottomByPercent($num) { $count = $this->countData(); return $this->bottom(round($num*$count/100)); }
[ "public", "function", "bottomByPercent", "(", "$", "num", ")", "{", "$", "count", "=", "$", "this", "->", "countData", "(", ")", ";", "return", "$", "this", "->", "bottom", "(", "round", "(", "$", "num", "*", "$", "count", "/", "100", ")", ")", ";", "}" ]
Return the bottom rows by percent Example: Return 20% bottom rows $dataSore->bottomByPercent(20); @param float $num The number in percent @return DataStore The new datastore containing result
[ "Return", "the", "bottom", "rows", "by", "percent" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/core/DataStore.php#L488-L492
koolphp/koolreport
src/core/DataStore.php
DataStore.sum
public function sum($colName) { $sum = 0; foreach ($this->rows as $row) { $sum+=$row[$colName]; } return $sum; }
php
public function sum($colName) { $sum = 0; foreach ($this->rows as $row) { $sum+=$row[$colName]; } return $sum; }
[ "public", "function", "sum", "(", "$", "colName", ")", "{", "$", "sum", "=", "0", ";", "foreach", "(", "$", "this", "->", "rows", "as", "$", "row", ")", "{", "$", "sum", "+=", "$", "row", "[", "$", "colName", "]", ";", "}", "return", "$", "sum", ";", "}" ]
Return the sum of a field Examples: $totalSales = $dataStore->sum("saleAmount"); @param string $colName Name of column you want to sum @return float Sum of column
[ "Return", "the", "sum", "of", "a", "field" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/core/DataStore.php#L504-L511
koolphp/koolreport
src/core/DataStore.php
DataStore.min
public function min($colName) { $min = INF; foreach ($this->rows as $row) { if ($min>$row[$colName]) { $min = $row[$colName]; } } return $min; }
php
public function min($colName) { $min = INF; foreach ($this->rows as $row) { if ($min>$row[$colName]) { $min = $row[$colName]; } } return $min; }
[ "public", "function", "min", "(", "$", "colName", ")", "{", "$", "min", "=", "INF", ";", "foreach", "(", "$", "this", "->", "rows", "as", "$", "row", ")", "{", "if", "(", "$", "min", ">", "$", "row", "[", "$", "colName", "]", ")", "{", "$", "min", "=", "$", "row", "[", "$", "colName", "]", ";", "}", "}", "return", "$", "min", ";", "}" ]
Return the min value of a field Examples: $minSale = $dataStore->min("saleAmount"); @param string $colName Name of column you want to get min @return float Min value of column
[ "Return", "the", "min", "value", "of", "a", "field" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/core/DataStore.php#L522-L532
koolphp/koolreport
src/core/DataStore.php
DataStore.max
public function max($colName) { $max = -INF; foreach ($this->rows as $row) { if ($max<$row[$colName]) { $max = $row[$colName]; } } return $max; }
php
public function max($colName) { $max = -INF; foreach ($this->rows as $row) { if ($max<$row[$colName]) { $max = $row[$colName]; } } return $max; }
[ "public", "function", "max", "(", "$", "colName", ")", "{", "$", "max", "=", "-", "INF", ";", "foreach", "(", "$", "this", "->", "rows", "as", "$", "row", ")", "{", "if", "(", "$", "max", "<", "$", "row", "[", "$", "colName", "]", ")", "{", "$", "max", "=", "$", "row", "[", "$", "colName", "]", ";", "}", "}", "return", "$", "max", ";", "}" ]
Return the max of a field Examples: $maxSale = $dataStore->max("saleAmount"); @param string $colName Name of column you want to get max @return float Max value of column
[ "Return", "the", "max", "of", "a", "field" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/core/DataStore.php#L542-L551
koolphp/koolreport
src/core/DataStore.php
DataStore.avg
public function avg($colName) { if ($this->countData()>0) { return $this->sum($colName)/$this->countData(); } return false; }
php
public function avg($colName) { if ($this->countData()>0) { return $this->sum($colName)/$this->countData(); } return false; }
[ "public", "function", "avg", "(", "$", "colName", ")", "{", "if", "(", "$", "this", "->", "countData", "(", ")", ">", "0", ")", "{", "return", "$", "this", "->", "sum", "(", "$", "colName", ")", "/", "$", "this", "->", "countData", "(", ")", ";", "}", "return", "false", ";", "}" ]
Return the average value of a field Examples: $averageSale = $dataStore->avg("saleAmount"); @param string $colName Name of column you want to get average @return float Average value of column
[ "Return", "the", "average", "value", "of", "a", "field" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/core/DataStore.php#L562-L568
koolphp/koolreport
src/core/DataStore.php
DataStore.process
public function process($process) { $ds = new DataStore; $process->pipe($ds); $top_process = $process; while ($top_process->previous()!=null) { $top_process = $top_process->previous(); } $top_process->receiveMeta($this->metaData, $this); $top_process->startInput($this); foreach ($this->rows as $row) { $top_process->input($row, $this); } $top_process->endInput($this); return $ds; }
php
public function process($process) { $ds = new DataStore; $process->pipe($ds); $top_process = $process; while ($top_process->previous()!=null) { $top_process = $top_process->previous(); } $top_process->receiveMeta($this->metaData, $this); $top_process->startInput($this); foreach ($this->rows as $row) { $top_process->input($row, $this); } $top_process->endInput($this); return $ds; }
[ "public", "function", "process", "(", "$", "process", ")", "{", "$", "ds", "=", "new", "DataStore", ";", "$", "process", "->", "pipe", "(", "$", "ds", ")", ";", "$", "top_process", "=", "$", "process", ";", "while", "(", "$", "top_process", "->", "previous", "(", ")", "!=", "null", ")", "{", "$", "top_process", "=", "$", "top_process", "->", "previous", "(", ")", ";", "}", "$", "top_process", "->", "receiveMeta", "(", "$", "this", "->", "metaData", ",", "$", "this", ")", ";", "$", "top_process", "->", "startInput", "(", "$", "this", ")", ";", "foreach", "(", "$", "this", "->", "rows", "as", "$", "row", ")", "{", "$", "top_process", "->", "input", "(", "$", "row", ",", "$", "this", ")", ";", "}", "$", "top_process", "->", "endInput", "(", "$", "this", ")", ";", "return", "$", "ds", ";", "}" ]
Pipe rows of data to process and get result Sometime you may need to further process data event they has reach datastore, you may do so with this method. Examples: $groupData = $dataStore->process(Group::process(["by"=>"date"])); @param string $process A new series of process you want data to go through @return DataStore New datastore containing result
[ "Pipe", "rows", "of", "data", "to", "process", "and", "get", "result" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/core/DataStore.php#L582-L598
koolphp/koolreport
src/core/DataStore.php
DataStore.each
public function each($cb) { foreach ($this->rows as $index=>$row) { $result = $cb($row, $index); if (is_array($result)) { $this->rows[$index] = $result; } else if ($result===false) { break; } } return $this; }
php
public function each($cb) { foreach ($this->rows as $index=>$row) { $result = $cb($row, $index); if (is_array($result)) { $this->rows[$index] = $result; } else if ($result===false) { break; } } return $this; }
[ "public", "function", "each", "(", "$", "cb", ")", "{", "foreach", "(", "$", "this", "->", "rows", "as", "$", "index", "=>", "$", "row", ")", "{", "$", "result", "=", "$", "cb", "(", "$", "row", ",", "$", "index", ")", ";", "if", "(", "is_array", "(", "$", "result", ")", ")", "{", "$", "this", "->", "rows", "[", "$", "index", "]", "=", "$", "result", ";", "}", "else", "if", "(", "$", "result", "===", "false", ")", "{", "break", ";", "}", "}", "return", "$", "this", ";", "}" ]
Loop through each rows of data set Examples: $store->each(function($row,$index){ //Do something }); @param function $cb A function that take row as parameter @return DataStore This datastore
[ "Loop", "through", "each", "rows", "of", "data", "set" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/core/DataStore.php#L709-L720
koolphp/koolreport
src/core/DataStore.php
DataStore.except
public function except() { $cols = func_get_args(); //method returns all rows in the collection except for those with the specified keys $dstore = new DataStore; foreach ($this->rows as $row) { foreach ($cols as $col) { if (isset($row[$col])) { unset($row[$col]); } } $dstore->append($row); } $columnsMeta = Utility::get($this->metaData, "columns"); if ($columnsMeta) { foreach ($cols as $col) { if (isset($columnsMeta[$col])) { unset($columnsMeta[$col]); } } } $dstore->meta(array("columns"=>$columnsMeta)); return $dstore; }
php
public function except() { $cols = func_get_args(); //method returns all rows in the collection except for those with the specified keys $dstore = new DataStore; foreach ($this->rows as $row) { foreach ($cols as $col) { if (isset($row[$col])) { unset($row[$col]); } } $dstore->append($row); } $columnsMeta = Utility::get($this->metaData, "columns"); if ($columnsMeta) { foreach ($cols as $col) { if (isset($columnsMeta[$col])) { unset($columnsMeta[$col]); } } } $dstore->meta(array("columns"=>$columnsMeta)); return $dstore; }
[ "public", "function", "except", "(", ")", "{", "$", "cols", "=", "func_get_args", "(", ")", ";", "//method returns all rows in the collection except for those with the specified keys", "$", "dstore", "=", "new", "DataStore", ";", "foreach", "(", "$", "this", "->", "rows", "as", "$", "row", ")", "{", "foreach", "(", "$", "cols", "as", "$", "col", ")", "{", "if", "(", "isset", "(", "$", "row", "[", "$", "col", "]", ")", ")", "{", "unset", "(", "$", "row", "[", "$", "col", "]", ")", ";", "}", "}", "$", "dstore", "->", "append", "(", "$", "row", ")", ";", "}", "$", "columnsMeta", "=", "Utility", "::", "get", "(", "$", "this", "->", "metaData", ",", "\"columns\"", ")", ";", "if", "(", "$", "columnsMeta", ")", "{", "foreach", "(", "$", "cols", "as", "$", "col", ")", "{", "if", "(", "isset", "(", "$", "columnsMeta", "[", "$", "col", "]", ")", ")", "{", "unset", "(", "$", "columnsMeta", "[", "$", "col", "]", ")", ";", "}", "}", "}", "$", "dstore", "->", "meta", "(", "array", "(", "\"columns\"", "=>", "$", "columnsMeta", ")", ")", ";", "return", "$", "dstore", ";", "}" ]
Return new datastore with all columns except some Examples $newStore = $store->except("age","city"); @return DataStore New datastore containing result
[ "Return", "new", "datastore", "with", "all", "columns", "except", "some" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/core/DataStore.php#L731-L755
koolphp/koolreport
src/core/DataStore.php
DataStore.only
public function only() { //Only colname $cols = func_get_args(); $dstore = new DataStore; foreach ($this->rows as $row) { $new_row = array(); foreach ($cols as $col) { $new_row[$col] = $row[$col]; } $dstore->push($new_row); } $columnsMeta = Utility::get($this->metaData, "columns"); $newColumnsMeta = array(); if ($columnsMeta) { foreach ($cols as $col) { $newColumnsMeta[$col] = $columnsMeta[$col]; } } $dstore->meta(array("columns"=>$newColumnsMeta)); return $dstore; }
php
public function only() { //Only colname $cols = func_get_args(); $dstore = new DataStore; foreach ($this->rows as $row) { $new_row = array(); foreach ($cols as $col) { $new_row[$col] = $row[$col]; } $dstore->push($new_row); } $columnsMeta = Utility::get($this->metaData, "columns"); $newColumnsMeta = array(); if ($columnsMeta) { foreach ($cols as $col) { $newColumnsMeta[$col] = $columnsMeta[$col]; } } $dstore->meta(array("columns"=>$newColumnsMeta)); return $dstore; }
[ "public", "function", "only", "(", ")", "{", "//Only colname", "$", "cols", "=", "func_get_args", "(", ")", ";", "$", "dstore", "=", "new", "DataStore", ";", "foreach", "(", "$", "this", "->", "rows", "as", "$", "row", ")", "{", "$", "new_row", "=", "array", "(", ")", ";", "foreach", "(", "$", "cols", "as", "$", "col", ")", "{", "$", "new_row", "[", "$", "col", "]", "=", "$", "row", "[", "$", "col", "]", ";", "}", "$", "dstore", "->", "push", "(", "$", "new_row", ")", ";", "}", "$", "columnsMeta", "=", "Utility", "::", "get", "(", "$", "this", "->", "metaData", ",", "\"columns\"", ")", ";", "$", "newColumnsMeta", "=", "array", "(", ")", ";", "if", "(", "$", "columnsMeta", ")", "{", "foreach", "(", "$", "cols", "as", "$", "col", ")", "{", "$", "newColumnsMeta", "[", "$", "col", "]", "=", "$", "columnsMeta", "[", "$", "col", "]", ";", "}", "}", "$", "dstore", "->", "meta", "(", "array", "(", "\"columns\"", "=>", "$", "newColumnsMeta", ")", ")", ";", "return", "$", "dstore", ";", "}" ]
Get new datastore containing some of the columns Examples: $newStore = $store->only("name","age"); @return DataStore New datastore containing result
[ "Get", "new", "datastore", "containing", "some", "of", "the", "columns" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/core/DataStore.php#L766-L788
koolphp/koolreport
src/core/DataStore.php
DataStore.filterByFunc
public function filterByFunc($cb) { //method filters the collection using the given callback, keeping only those rows that pass a given truth test $dstore = new DataStore; $dstore->meta($this->metaData); foreach ($this->rows as $index=>$row) { if ($cb($row, $index)===true) { $dstore->append($row); } } return $dstore; }
php
public function filterByFunc($cb) { //method filters the collection using the given callback, keeping only those rows that pass a given truth test $dstore = new DataStore; $dstore->meta($this->metaData); foreach ($this->rows as $index=>$row) { if ($cb($row, $index)===true) { $dstore->append($row); } } return $dstore; }
[ "public", "function", "filterByFunc", "(", "$", "cb", ")", "{", "//method filters the collection using the given callback, keeping only those rows that pass a given truth test", "$", "dstore", "=", "new", "DataStore", ";", "$", "dstore", "->", "meta", "(", "$", "this", "->", "metaData", ")", ";", "foreach", "(", "$", "this", "->", "rows", "as", "$", "index", "=>", "$", "row", ")", "{", "if", "(", "$", "cb", "(", "$", "row", ",", "$", "index", ")", "===", "true", ")", "{", "$", "dstore", "->", "append", "(", "$", "row", ")", ";", "}", "}", "return", "$", "dstore", ";", "}" ]
Get filtered results by function A row will go through if function return true @param function $cb Callback function @return DataSore New datastore containing filtered results.
[ "Get", "filtered", "results", "by", "function" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/core/DataStore.php#L799-L810
koolphp/koolreport
src/core/DataStore.php
DataStore.first
public function first($cb=null) { if ($cb==null) { return $this->isNotEmpty()?$this->rows[0]:null; } else { // method returns the first element in the collection that passes //a given truth test foreach ($this->rows as $index=>$row) { if ($cb($row, $index)===true) { return $row; } } } return null; }
php
public function first($cb=null) { if ($cb==null) { return $this->isNotEmpty()?$this->rows[0]:null; } else { // method returns the first element in the collection that passes //a given truth test foreach ($this->rows as $index=>$row) { if ($cb($row, $index)===true) { return $row; } } } return null; }
[ "public", "function", "first", "(", "$", "cb", "=", "null", ")", "{", "if", "(", "$", "cb", "==", "null", ")", "{", "return", "$", "this", "->", "isNotEmpty", "(", ")", "?", "$", "this", "->", "rows", "[", "0", "]", ":", "null", ";", "}", "else", "{", "// method returns the first element in the collection that passes ", "//a given truth test", "foreach", "(", "$", "this", "->", "rows", "as", "$", "index", "=>", "$", "row", ")", "{", "if", "(", "$", "cb", "(", "$", "row", ",", "$", "index", ")", "===", "true", ")", "{", "return", "$", "row", ";", "}", "}", "}", "return", "null", ";", "}" ]
Return a first row meet a condition defined by callback function $row = $store->first(fucntion($row){ return $row["age"]>20; }); @param function $cb Callback function that return true if a row meets condition @return array The first row that meets condition.
[ "Return", "a", "first", "row", "meet", "a", "condition", "defined", "by", "callback", "function" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/core/DataStore.php#L823-L837
koolphp/koolreport
src/core/DataStore.php
DataStore.last
public function last($cb=null) { if ($cb==null) { return $this->isNotEmpty()?$this->rows[$this->count()-1]:null; } else { //method returns the last element in the collection that passes a given truth test: $count = $this->count(); for ($i=0;$i<$count;$i++) { if ($cb($this->rows[$count-$i], $count-$i)===true) { return $this->rows[$count-$i]; } } } return null; }
php
public function last($cb=null) { if ($cb==null) { return $this->isNotEmpty()?$this->rows[$this->count()-1]:null; } else { //method returns the last element in the collection that passes a given truth test: $count = $this->count(); for ($i=0;$i<$count;$i++) { if ($cb($this->rows[$count-$i], $count-$i)===true) { return $this->rows[$count-$i]; } } } return null; }
[ "public", "function", "last", "(", "$", "cb", "=", "null", ")", "{", "if", "(", "$", "cb", "==", "null", ")", "{", "return", "$", "this", "->", "isNotEmpty", "(", ")", "?", "$", "this", "->", "rows", "[", "$", "this", "->", "count", "(", ")", "-", "1", "]", ":", "null", ";", "}", "else", "{", "//method returns the last element in the collection that passes a given truth test:", "$", "count", "=", "$", "this", "->", "count", "(", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "count", ";", "$", "i", "++", ")", "{", "if", "(", "$", "cb", "(", "$", "this", "->", "rows", "[", "$", "count", "-", "$", "i", "]", ",", "$", "count", "-", "$", "i", ")", "===", "true", ")", "{", "return", "$", "this", "->", "rows", "[", "$", "count", "-", "$", "i", "]", ";", "}", "}", "}", "return", "null", ";", "}" ]
Return the last row that meets a condition set by callback function Examples: $lastRow = $store->last(function($row){ return $row["age"]<65; }); @param function $cb Callback function @return array The last row that meet conditon
[ "Return", "the", "last", "row", "that", "meets", "a", "condition", "set", "by", "callback", "function" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/core/DataStore.php#L866-L880
koolphp/koolreport
src/core/DataStore.php
DataStore.mode
public function mode($colName) { $counts = array(); foreach ($this->rows as $row) { $counts[$row[$colName]] = isset($counts[$row[$colName]])? $counts[$row[$colName]]+1:1; } arsort($counts); $list = array_keys($counts); return $list[0]; }
php
public function mode($colName) { $counts = array(); foreach ($this->rows as $row) { $counts[$row[$colName]] = isset($counts[$row[$colName]])? $counts[$row[$colName]]+1:1; } arsort($counts); $list = array_keys($counts); return $list[0]; }
[ "public", "function", "mode", "(", "$", "colName", ")", "{", "$", "counts", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "rows", "as", "$", "row", ")", "{", "$", "counts", "[", "$", "row", "[", "$", "colName", "]", "]", "=", "isset", "(", "$", "counts", "[", "$", "row", "[", "$", "colName", "]", "]", ")", "?", "$", "counts", "[", "$", "row", "[", "$", "colName", "]", "]", "+", "1", ":", "1", ";", "}", "arsort", "(", "$", "counts", ")", ";", "$", "list", "=", "array_keys", "(", "$", "counts", ")", ";", "return", "$", "list", "[", "0", "]", ";", "}" ]
Return the mode value of a field @param string $colName Column name @return float The mode value of the column
[ "Return", "the", "mode", "value", "of", "a", "field" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/core/DataStore.php#L889-L899
koolphp/koolreport
src/core/DataStore.php
DataStore.pluck
public function pluck($colName) { $result = array(); foreach ($this->rows as $row) { array_push($result, $row[$colName]); } return $result; }
php
public function pluck($colName) { $result = array(); foreach ($this->rows as $row) { array_push($result, $row[$colName]); } return $result; }
[ "public", "function", "pluck", "(", "$", "colName", ")", "{", "$", "result", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "rows", "as", "$", "row", ")", "{", "array_push", "(", "$", "result", ",", "$", "row", "[", "$", "colName", "]", ")", ";", "}", "return", "$", "result", ";", "}" ]
Return all value of a column in array @param string $colName Column name @return array Array containing all values of the column
[ "Return", "all", "value", "of", "a", "column", "in", "array" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/core/DataStore.php#L908-L915
koolphp/koolreport
src/core/DataStore.php
DataStore.reject
public function reject($cb) { $dstore = new DataStore; $dstore->meta($this->metaData); foreach ($this->rows as $index=>$row) { if ($cb($row, $index)===false) { $dstore->append($row); } } return $dstore; }
php
public function reject($cb) { $dstore = new DataStore; $dstore->meta($this->metaData); foreach ($this->rows as $index=>$row) { if ($cb($row, $index)===false) { $dstore->append($row); } } return $dstore; }
[ "public", "function", "reject", "(", "$", "cb", ")", "{", "$", "dstore", "=", "new", "DataStore", ";", "$", "dstore", "->", "meta", "(", "$", "this", "->", "metaData", ")", ";", "foreach", "(", "$", "this", "->", "rows", "as", "$", "index", "=>", "$", "row", ")", "{", "if", "(", "$", "cb", "(", "$", "row", ",", "$", "index", ")", "===", "false", ")", "{", "$", "dstore", "->", "append", "(", "$", "row", ")", ";", "}", "}", "return", "$", "dstore", ";", "}" ]
Reject some rows that meets condition @param function $cb Callback function @return DataStore New datastore containing results.
[ "Reject", "some", "rows", "that", "meets", "condition" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/core/DataStore.php#L924-L934
koolphp/koolreport
src/core/DataStore.php
DataStore.slice
public function slice($offset, $length = null) { return new DataStore( array_slice($this->rows, $offset, $length), $this->metaData ); }
php
public function slice($offset, $length = null) { return new DataStore( array_slice($this->rows, $offset, $length), $this->metaData ); }
[ "public", "function", "slice", "(", "$", "offset", ",", "$", "length", "=", "null", ")", "{", "return", "new", "DataStore", "(", "array_slice", "(", "$", "this", "->", "rows", ",", "$", "offset", ",", "$", "length", ")", ",", "$", "this", "->", "metaData", ")", ";", "}" ]
Get slice of data @param integer $offset Starting row to get offset @param integer $length Number of rows to take, if not specified, all row after $offset will be returned. @return DataStore New datastore containing results.
[ "Get", "slice", "of", "data" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/core/DataStore.php#L944-L950
koolphp/koolreport
src/core/DataStore.php
DataStore.sort
public function sort($sorts) { usort($this->rows, function ($a, $b) use ($sorts) { $cmp = 0; foreach ($sorts as $sort => $direction) { if (is_string($direction)) { $cmp = is_numeric($a[$sort]) && is_numeric($b[$sort]) ? $a[$sort] - $b[$sort] : strcmp($a[$sort], $b[$sort]); $cmp = $direction === 'asc' ? $cmp : - $cmp; } else if (is_callable($direction)) { $cmp = $direction($a[$sort], $b[$sort]); } if ($cmp !== 0) { break; } } return $cmp; } ); return $this; }
php
public function sort($sorts) { usort($this->rows, function ($a, $b) use ($sorts) { $cmp = 0; foreach ($sorts as $sort => $direction) { if (is_string($direction)) { $cmp = is_numeric($a[$sort]) && is_numeric($b[$sort]) ? $a[$sort] - $b[$sort] : strcmp($a[$sort], $b[$sort]); $cmp = $direction === 'asc' ? $cmp : - $cmp; } else if (is_callable($direction)) { $cmp = $direction($a[$sort], $b[$sort]); } if ($cmp !== 0) { break; } } return $cmp; } ); return $this; }
[ "public", "function", "sort", "(", "$", "sorts", ")", "{", "usort", "(", "$", "this", "->", "rows", ",", "function", "(", "$", "a", ",", "$", "b", ")", "use", "(", "$", "sorts", ")", "{", "$", "cmp", "=", "0", ";", "foreach", "(", "$", "sorts", "as", "$", "sort", "=>", "$", "direction", ")", "{", "if", "(", "is_string", "(", "$", "direction", ")", ")", "{", "$", "cmp", "=", "is_numeric", "(", "$", "a", "[", "$", "sort", "]", ")", "&&", "is_numeric", "(", "$", "b", "[", "$", "sort", "]", ")", "?", "$", "a", "[", "$", "sort", "]", "-", "$", "b", "[", "$", "sort", "]", ":", "strcmp", "(", "$", "a", "[", "$", "sort", "]", ",", "$", "b", "[", "$", "sort", "]", ")", ";", "$", "cmp", "=", "$", "direction", "===", "'asc'", "?", "$", "cmp", ":", "-", "$", "cmp", ";", "}", "else", "if", "(", "is_callable", "(", "$", "direction", ")", ")", "{", "$", "cmp", "=", "$", "direction", "(", "$", "a", "[", "$", "sort", "]", ",", "$", "b", "[", "$", "sort", "]", ")", ";", "}", "if", "(", "$", "cmp", "!==", "0", ")", "{", "break", ";", "}", "}", "return", "$", "cmp", ";", "}", ")", ";", "return", "$", "this", ";", "}" ]
Sort the rows of data Examples: $store->sort(array("age"=>"desc")); @param array $sorts Condition of sorting @return DataStore This datastore
[ "Sort", "the", "rows", "of", "data" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/core/DataStore.php#L963-L984
koolphp/koolreport
src/core/DataStore.php
DataStore.sortKeys
public function sortKeys() { if ($this->isNotEmpty()) { foreach ($this->rows as &$row) { ksort($row); } } return $this; }
php
public function sortKeys() { if ($this->isNotEmpty()) { foreach ($this->rows as &$row) { ksort($row); } } return $this; }
[ "public", "function", "sortKeys", "(", ")", "{", "if", "(", "$", "this", "->", "isNotEmpty", "(", ")", ")", "{", "foreach", "(", "$", "this", "->", "rows", "as", "&", "$", "row", ")", "{", "ksort", "(", "$", "row", ")", ";", "}", "}", "return", "$", "this", ";", "}" ]
Sort asc data rows by column name @return DataStore This datastore after sorted.
[ "Sort", "asc", "data", "rows", "by", "column", "name" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/core/DataStore.php#L1004-L1012
koolphp/koolreport
src/core/DataStore.php
DataStore.sortKeysDesc
public function sortKeysDesc() { if ($this->isNotEmpty()) { foreach ($this->rows as &$row) { krsort($row); } } return $this; }
php
public function sortKeysDesc() { if ($this->isNotEmpty()) { foreach ($this->rows as &$row) { krsort($row); } } return $this; }
[ "public", "function", "sortKeysDesc", "(", ")", "{", "if", "(", "$", "this", "->", "isNotEmpty", "(", ")", ")", "{", "foreach", "(", "$", "this", "->", "rows", "as", "&", "$", "row", ")", "{", "krsort", "(", "$", "row", ")", ";", "}", "}", "return", "$", "this", ";", "}" ]
Sort desc data rows by column name @return DataStore This datastore after sorted.
[ "Sort", "desc", "data", "rows", "by", "column", "name" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/core/DataStore.php#L1018-L1026
koolphp/koolreport
src/core/DataStore.php
DataStore.splice
public function splice($offset, $length = null, $replacement = []) { if (func_num_args() == 1) { return new DataStore( array_splice($this->rows, $offset), $this->metaData ); } return new DataStore( array_splice($this->rows, $offset, $length, $replacement), $this->metaData ); }
php
public function splice($offset, $length = null, $replacement = []) { if (func_num_args() == 1) { return new DataStore( array_splice($this->rows, $offset), $this->metaData ); } return new DataStore( array_splice($this->rows, $offset, $length, $replacement), $this->metaData ); }
[ "public", "function", "splice", "(", "$", "offset", ",", "$", "length", "=", "null", ",", "$", "replacement", "=", "[", "]", ")", "{", "if", "(", "func_num_args", "(", ")", "==", "1", ")", "{", "return", "new", "DataStore", "(", "array_splice", "(", "$", "this", "->", "rows", ",", "$", "offset", ")", ",", "$", "this", "->", "metaData", ")", ";", "}", "return", "new", "DataStore", "(", "array_splice", "(", "$", "this", "->", "rows", ",", "$", "offset", ",", "$", "length", ",", "$", "replacement", ")", ",", "$", "this", "->", "metaData", ")", ";", "}" ]
Splice the data and replace @param integer $offset Starting row to get @param integer $length How many rows to get @param array $replacement Optional! Replaced rows @return DataStore New dataStore containing results.
[ "Splice", "the", "data", "and", "replace" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/core/DataStore.php#L1037-L1050
koolphp/koolreport
src/core/DataStore.php
DataStore.where
public function where($key,$value) { $dstore= new DataStore; $dstore->meta($this->metaData); foreach ($this->rows as $row) { if ($row[$key]==$value) { $dstore->append($row); } } return $dstore; }
php
public function where($key,$value) { $dstore= new DataStore; $dstore->meta($this->metaData); foreach ($this->rows as $row) { if ($row[$key]==$value) { $dstore->append($row); } } return $dstore; }
[ "public", "function", "where", "(", "$", "key", ",", "$", "value", ")", "{", "$", "dstore", "=", "new", "DataStore", ";", "$", "dstore", "->", "meta", "(", "$", "this", "->", "metaData", ")", ";", "foreach", "(", "$", "this", "->", "rows", "as", "$", "row", ")", "{", "if", "(", "$", "row", "[", "$", "key", "]", "==", "$", "value", ")", "{", "$", "dstore", "->", "append", "(", "$", "row", ")", ";", "}", "}", "return", "$", "dstore", ";", "}" ]
Return rows that has column equal to certain value @param string $key Column name @param mixed $value Value to compare @return DataStore New dataStore containing results
[ "Return", "rows", "that", "has", "column", "equal", "to", "certain", "value" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/core/DataStore.php#L1087-L1097
koolphp/koolreport
src/core/DataStore.php
DataStore.whereIn
public function whereIn($key,$values=array()) { $dstore= new DataStore; $dstore->meta($this->metaData); foreach ($this->rows as $row) { if (in_array($row[$key], $values)) { $dstore->append($row); } } return $dstore; }
php
public function whereIn($key,$values=array()) { $dstore= new DataStore; $dstore->meta($this->metaData); foreach ($this->rows as $row) { if (in_array($row[$key], $values)) { $dstore->append($row); } } return $dstore; }
[ "public", "function", "whereIn", "(", "$", "key", ",", "$", "values", "=", "array", "(", ")", ")", "{", "$", "dstore", "=", "new", "DataStore", ";", "$", "dstore", "->", "meta", "(", "$", "this", "->", "metaData", ")", ";", "foreach", "(", "$", "this", "->", "rows", "as", "$", "row", ")", "{", "if", "(", "in_array", "(", "$", "row", "[", "$", "key", "]", ",", "$", "values", ")", ")", "{", "$", "dstore", "->", "append", "(", "$", "row", ")", ";", "}", "}", "return", "$", "dstore", ";", "}" ]
Return rows that column contains value in an array. @param string $key Column name @param array $values List of values @return DataStore New datastore containing results.
[ "Return", "rows", "that", "column", "contains", "value", "in", "an", "array", "." ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/core/DataStore.php#L1107-L1117
koolphp/koolreport
src/core/DataStore.php
DataStore._mapKeyIndex
private function _mapKeyIndex($arr,$keys) { $maps = array(); foreach ($arr as $index=>$row) { $key = "n"; foreach ($keys as $cName) { $key.=$row[$cName]; } if (!isset($maps[$key])) { $maps[$key] = array(); } array_push($maps[$key], $index); } return $maps; }
php
private function _mapKeyIndex($arr,$keys) { $maps = array(); foreach ($arr as $index=>$row) { $key = "n"; foreach ($keys as $cName) { $key.=$row[$cName]; } if (!isset($maps[$key])) { $maps[$key] = array(); } array_push($maps[$key], $index); } return $maps; }
[ "private", "function", "_mapKeyIndex", "(", "$", "arr", ",", "$", "keys", ")", "{", "$", "maps", "=", "array", "(", ")", ";", "foreach", "(", "$", "arr", "as", "$", "index", "=>", "$", "row", ")", "{", "$", "key", "=", "\"n\"", ";", "foreach", "(", "$", "keys", "as", "$", "cName", ")", "{", "$", "key", ".=", "$", "row", "[", "$", "cName", "]", ";", "}", "if", "(", "!", "isset", "(", "$", "maps", "[", "$", "key", "]", ")", ")", "{", "$", "maps", "[", "$", "key", "]", "=", "array", "(", ")", ";", "}", "array_push", "(", "$", "maps", "[", "$", "key", "]", ",", "$", "index", ")", ";", "}", "return", "$", "maps", ";", "}" ]
Map Key Index @param array $arr Array to map @param array $keys List of keys @return array Return new map
[ "Map", "Key", "Index" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/core/DataStore.php#L1145-L1159
koolphp/koolreport
src/core/DataStore.php
DataStore.join
public function join($secondStore,$matching) { $dstore = new DataStore; // join with other datasource to produce new one with above condition $firstKeys = array_keys($matching); $secondKeys = array_values($matching); $firstMaps = $this->_mapKeyIndex($this->rows, $firstKeys); $secondMaps = $this->_mapKeyIndex($secondStore->all(), $secondKeys); foreach ($firstMaps as $key=>$indices) { if (isset($secondMaps[$key])) { foreach ($indices as $i) { foreach ($secondMaps[$key] as $j) { $dstore->push( array_merge( $this->rows[$i], $secondStore->get($j) ) ); } } } } $columnMeta = array_merge($this->metaData["columns"], $secondStore->meta()["columns"]); $dstore->meta(array("columns"=>$columnMeta)); return $dstore; }
php
public function join($secondStore,$matching) { $dstore = new DataStore; // join with other datasource to produce new one with above condition $firstKeys = array_keys($matching); $secondKeys = array_values($matching); $firstMaps = $this->_mapKeyIndex($this->rows, $firstKeys); $secondMaps = $this->_mapKeyIndex($secondStore->all(), $secondKeys); foreach ($firstMaps as $key=>$indices) { if (isset($secondMaps[$key])) { foreach ($indices as $i) { foreach ($secondMaps[$key] as $j) { $dstore->push( array_merge( $this->rows[$i], $secondStore->get($j) ) ); } } } } $columnMeta = array_merge($this->metaData["columns"], $secondStore->meta()["columns"]); $dstore->meta(array("columns"=>$columnMeta)); return $dstore; }
[ "public", "function", "join", "(", "$", "secondStore", ",", "$", "matching", ")", "{", "$", "dstore", "=", "new", "DataStore", ";", "// join with other datasource to produce new one with above condition", "$", "firstKeys", "=", "array_keys", "(", "$", "matching", ")", ";", "$", "secondKeys", "=", "array_values", "(", "$", "matching", ")", ";", "$", "firstMaps", "=", "$", "this", "->", "_mapKeyIndex", "(", "$", "this", "->", "rows", ",", "$", "firstKeys", ")", ";", "$", "secondMaps", "=", "$", "this", "->", "_mapKeyIndex", "(", "$", "secondStore", "->", "all", "(", ")", ",", "$", "secondKeys", ")", ";", "foreach", "(", "$", "firstMaps", "as", "$", "key", "=>", "$", "indices", ")", "{", "if", "(", "isset", "(", "$", "secondMaps", "[", "$", "key", "]", ")", ")", "{", "foreach", "(", "$", "indices", "as", "$", "i", ")", "{", "foreach", "(", "$", "secondMaps", "[", "$", "key", "]", "as", "$", "j", ")", "{", "$", "dstore", "->", "push", "(", "array_merge", "(", "$", "this", "->", "rows", "[", "$", "i", "]", ",", "$", "secondStore", "->", "get", "(", "$", "j", ")", ")", ")", ";", "}", "}", "}", "}", "$", "columnMeta", "=", "array_merge", "(", "$", "this", "->", "metaData", "[", "\"columns\"", "]", ",", "$", "secondStore", "->", "meta", "(", ")", "[", "\"columns\"", "]", ")", ";", "$", "dstore", "->", "meta", "(", "array", "(", "\"columns\"", "=>", "$", "columnMeta", ")", ")", ";", "return", "$", "dstore", ";", "}" ]
Join with another datastore on a matching keys Examples $store1->join($store2,array("id"=>"userId")); @param DataStore $secondStore Second datastore @param array $matching Matching keys @return DataStore New datastore containing results.
[ "Join", "with", "another", "datastore", "on", "a", "matching", "keys" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/core/DataStore.php#L1183-L1212
koolphp/koolreport
src/core/DataStore.php
DataStore.leftJoin
public function leftJoin($secondStore,$matching) { $dstore = new DataStore; // join with other datasource to produce new one with above condition $firstKeys = array_keys($matching); $secondKeys = array_values($matching); $firstMaps = $this->_mapKeyIndex($this->rows, $firstKeys); $secondMaps = $this->_mapKeyIndex($secondStore->all(), $secondKeys); $secondNullRow = array(); foreach ($secondStore->first() as $k=>$v) { $secondNullRow[$k] = null; } foreach ($firstMaps as $key=>$indices) { foreach ($indices as $i) { if (isset($secondMaps[$key])) { foreach ($secondMaps[$key] as $j) { $dstore->push( array_merge( $this->rows[$i], $secondStore->get($j) ) ); } } else { $dstore->push( array_merge( $this->rows[$i], $secondNullRow ) ); } } } $columnMeta = array_merge( $this->metaData["columns"], $secondStore->meta()["columns"] ); $dstore->meta(array("columns"=>$columnMeta)); return $dstore; }
php
public function leftJoin($secondStore,$matching) { $dstore = new DataStore; // join with other datasource to produce new one with above condition $firstKeys = array_keys($matching); $secondKeys = array_values($matching); $firstMaps = $this->_mapKeyIndex($this->rows, $firstKeys); $secondMaps = $this->_mapKeyIndex($secondStore->all(), $secondKeys); $secondNullRow = array(); foreach ($secondStore->first() as $k=>$v) { $secondNullRow[$k] = null; } foreach ($firstMaps as $key=>$indices) { foreach ($indices as $i) { if (isset($secondMaps[$key])) { foreach ($secondMaps[$key] as $j) { $dstore->push( array_merge( $this->rows[$i], $secondStore->get($j) ) ); } } else { $dstore->push( array_merge( $this->rows[$i], $secondNullRow ) ); } } } $columnMeta = array_merge( $this->metaData["columns"], $secondStore->meta()["columns"] ); $dstore->meta(array("columns"=>$columnMeta)); return $dstore; }
[ "public", "function", "leftJoin", "(", "$", "secondStore", ",", "$", "matching", ")", "{", "$", "dstore", "=", "new", "DataStore", ";", "// join with other datasource to produce new one with above condition", "$", "firstKeys", "=", "array_keys", "(", "$", "matching", ")", ";", "$", "secondKeys", "=", "array_values", "(", "$", "matching", ")", ";", "$", "firstMaps", "=", "$", "this", "->", "_mapKeyIndex", "(", "$", "this", "->", "rows", ",", "$", "firstKeys", ")", ";", "$", "secondMaps", "=", "$", "this", "->", "_mapKeyIndex", "(", "$", "secondStore", "->", "all", "(", ")", ",", "$", "secondKeys", ")", ";", "$", "secondNullRow", "=", "array", "(", ")", ";", "foreach", "(", "$", "secondStore", "->", "first", "(", ")", "as", "$", "k", "=>", "$", "v", ")", "{", "$", "secondNullRow", "[", "$", "k", "]", "=", "null", ";", "}", "foreach", "(", "$", "firstMaps", "as", "$", "key", "=>", "$", "indices", ")", "{", "foreach", "(", "$", "indices", "as", "$", "i", ")", "{", "if", "(", "isset", "(", "$", "secondMaps", "[", "$", "key", "]", ")", ")", "{", "foreach", "(", "$", "secondMaps", "[", "$", "key", "]", "as", "$", "j", ")", "{", "$", "dstore", "->", "push", "(", "array_merge", "(", "$", "this", "->", "rows", "[", "$", "i", "]", ",", "$", "secondStore", "->", "get", "(", "$", "j", ")", ")", ")", ";", "}", "}", "else", "{", "$", "dstore", "->", "push", "(", "array_merge", "(", "$", "this", "->", "rows", "[", "$", "i", "]", ",", "$", "secondNullRow", ")", ")", ";", "}", "}", "}", "$", "columnMeta", "=", "array_merge", "(", "$", "this", "->", "metaData", "[", "\"columns\"", "]", ",", "$", "secondStore", "->", "meta", "(", ")", "[", "\"columns\"", "]", ")", ";", "$", "dstore", "->", "meta", "(", "array", "(", "\"columns\"", "=>", "$", "columnMeta", ")", ")", ";", "return", "$", "dstore", ";", "}" ]
Left join with another datastore on matching keys Examples $store1->join($store2,array("id"=>"userId")); @param DataStore $secondStore Second datastore @param array $matching Matching keys @return DataStore New datastore containing results.
[ "Left", "join", "with", "another", "datastore", "on", "matching", "keys" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/core/DataStore.php#L1226-L1270
koolphp/koolreport
src/core/DataStore.php
DataStore.columnMeta
public function columnMeta($settings) { foreach ($settings as $cName=>$cMeta) { if (isset($this->metaData["columns"]) && $this->metaData["columns"][$cName]) { $this->metaData["columns"][$cName] = array_merge( $this->metaData["columns"][$cName], $cMeta ); } } return $this; }
php
public function columnMeta($settings) { foreach ($settings as $cName=>$cMeta) { if (isset($this->metaData["columns"]) && $this->metaData["columns"][$cName]) { $this->metaData["columns"][$cName] = array_merge( $this->metaData["columns"][$cName], $cMeta ); } } return $this; }
[ "public", "function", "columnMeta", "(", "$", "settings", ")", "{", "foreach", "(", "$", "settings", "as", "$", "cName", "=>", "$", "cMeta", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "metaData", "[", "\"columns\"", "]", ")", "&&", "$", "this", "->", "metaData", "[", "\"columns\"", "]", "[", "$", "cName", "]", ")", "{", "$", "this", "->", "metaData", "[", "\"columns\"", "]", "[", "$", "cName", "]", "=", "array_merge", "(", "$", "this", "->", "metaData", "[", "\"columns\"", "]", "[", "$", "cName", "]", ",", "$", "cMeta", ")", ";", "}", "}", "return", "$", "this", ";", "}" ]
Add extra column meta to existing Examples $store1->columnMeta(array( "age"=>array( "name"=>"Age" ) )); @param DataStore $settings The additional settings for column @return DataStore New datastore containing results.
[ "Add", "extra", "column", "meta", "to", "existing" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/core/DataStore.php#L1287-L1298
koolphp/koolreport
src/core/DataStore.php
DataStore.offsetSet
public function offsetSet($index, $row) { if (is_null($index)) { $this->rows[] = $row; } else { $this->rows[$index] = $row; } }
php
public function offsetSet($index, $row) { if (is_null($index)) { $this->rows[] = $row; } else { $this->rows[$index] = $row; } }
[ "public", "function", "offsetSet", "(", "$", "index", ",", "$", "row", ")", "{", "if", "(", "is_null", "(", "$", "index", ")", ")", "{", "$", "this", "->", "rows", "[", "]", "=", "$", "row", ";", "}", "else", "{", "$", "this", "->", "rows", "[", "$", "index", "]", "=", "$", "row", ";", "}", "}" ]
Implement offsetSet for ArrayAccess interface @param integer $index The index of row needed to be added @param array $row The row need to add @return null
[ "Implement", "offsetSet", "for", "ArrayAccess", "interface" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/core/DataStore.php#L1317-L1324
koolphp/koolreport
src/core/DataStore.php
DataStore.offsetGet
public function offsetGet($index) { return isset($this->rows[$index]) ? $this->rows[$index] : null; }
php
public function offsetGet($index) { return isset($this->rows[$index]) ? $this->rows[$index] : null; }
[ "public", "function", "offsetGet", "(", "$", "index", ")", "{", "return", "isset", "(", "$", "this", "->", "rows", "[", "$", "index", "]", ")", "?", "$", "this", "->", "rows", "[", "$", "index", "]", ":", "null", ";", "}" ]
Implement offsetGet for ArrayAccess interface @param integer $index The index of row need to be removed @return array The row data at the context
[ "Implement", "offsetGet", "for", "ArrayAccess", "interface" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/core/DataStore.php#L1357-L1360
koolphp/koolreport
src/processes/NumberRange.php
NumberRange.onMetaReceived
protected function onMetaReceived($metaData) { foreach ($this->params as $cName => $cParams) { $metaData["columns"][$cName] = array( "type" => "string", ); } return $metaData; }
php
protected function onMetaReceived($metaData) { foreach ($this->params as $cName => $cParams) { $metaData["columns"][$cName] = array( "type" => "string", ); } return $metaData; }
[ "protected", "function", "onMetaReceived", "(", "$", "metaData", ")", "{", "foreach", "(", "$", "this", "->", "params", "as", "$", "cName", "=>", "$", "cParams", ")", "{", "$", "metaData", "[", "\"columns\"", "]", "[", "$", "cName", "]", "=", "array", "(", "\"type\"", "=>", "\"string\"", ",", ")", ";", "}", "return", "$", "metaData", ";", "}" ]
Handle on meta received @param array $metaData The meta data @return array New meta data
[ "Handle", "on", "meta", "received" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/processes/NumberRange.php#L48-L56
koolphp/koolreport
src/processes/NumberRange.php
NumberRange.onInput
protected function onInput($data) { //Process data here foreach ($this->params as $cName => $cParams) { $value = null; foreach ($cParams as $cValue => $criteria) { $from = Utility::get($criteria, 0); $to = Utility::get($criteria, 1); if (($from == null || $from <= $data[$cName]) && ($to == null || $data[$cName] < $to)) { $value = $cValue; } } $data[$cName] = ($value) ? $value : null; } $this->next($data); }
php
protected function onInput($data) { //Process data here foreach ($this->params as $cName => $cParams) { $value = null; foreach ($cParams as $cValue => $criteria) { $from = Utility::get($criteria, 0); $to = Utility::get($criteria, 1); if (($from == null || $from <= $data[$cName]) && ($to == null || $data[$cName] < $to)) { $value = $cValue; } } $data[$cName] = ($value) ? $value : null; } $this->next($data); }
[ "protected", "function", "onInput", "(", "$", "data", ")", "{", "//Process data here", "foreach", "(", "$", "this", "->", "params", "as", "$", "cName", "=>", "$", "cParams", ")", "{", "$", "value", "=", "null", ";", "foreach", "(", "$", "cParams", "as", "$", "cValue", "=>", "$", "criteria", ")", "{", "$", "from", "=", "Utility", "::", "get", "(", "$", "criteria", ",", "0", ")", ";", "$", "to", "=", "Utility", "::", "get", "(", "$", "criteria", ",", "1", ")", ";", "if", "(", "(", "$", "from", "==", "null", "||", "$", "from", "<=", "$", "data", "[", "$", "cName", "]", ")", "&&", "(", "$", "to", "==", "null", "||", "$", "data", "[", "$", "cName", "]", "<", "$", "to", ")", ")", "{", "$", "value", "=", "$", "cValue", ";", "}", "}", "$", "data", "[", "$", "cName", "]", "=", "(", "$", "value", ")", "?", "$", "value", ":", "null", ";", "}", "$", "this", "->", "next", "(", "$", "data", ")", ";", "}" ]
Handle on data input @param array $data The input data row @return null
[ "Handle", "on", "data", "input" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/processes/NumberRange.php#L65-L80
koolphp/koolreport
src/core/ResourceManager.php
ResourceManager.publishAssetFolder
public function publishAssetFolder($fullLocalPath,$version="") { $fullLocalPath = Utility::standardizePathSeparator($fullLocalPath); $fullLocalPath = Utility::getSymbolicPath($fullLocalPath); $assets = Utility::get($this->report->getSettings(), "assets"); $document_root = Utility::getDocumentRoot(); $assetUrl = ""; if (!$assets) { $assetUrl = str_replace($document_root, "", $fullLocalPath); if ($assetUrl==$fullLocalPath) { /** * Happens when koolreport library is not within document root * setup assets settings that move to the script folder */ $script_folder = Utility::standardizePathSeparator( realpath(dirname($_SERVER["SCRIPT_FILENAME"])) ); $asset_path = $script_folder."/koolreport_assets"; $asset_url = Utility::str_replace_first( $document_root, "", $script_folder )."/koolreport_assets"; if (!is_dir($asset_path)) { mkdir($asset_path, 0755); } $assets = array( "path"=>$asset_path, "url"=>$asset_url, ); $assetUrl = ""; } } if ($assets) { $targetAssetPath = Utility::get($assets, "path"); $targetAssetUrl = Utility::get($assets, "url"); if (!$targetAssetPath) { throw new \Exception("Could not find path to report's assets folder"); } $reportClassFolder = Utility::standardizePathSeparator( dirname(Utility::getClassPath($this->report)) ); if (strpos($targetAssetPath, "/")!== 0 && is_dir($reportClassFolder."/".$targetAssetPath) ) { //Check if relative targetAssetPath existed $targetAssetPath = Utility::standardizePathSeparator( realpath($reportClassFolder."/".$targetAssetPath) ); } else if (is_dir($targetAssetPath)) { //Check if full targetAssetPath existed $targetAssetPath = Utility::standardizePathSeparator( realpath($targetAssetPath) ); } else { throw new \Exception("Report's assets folder not existed"); } //----------------------- $objectFolderName = str_replace( dirname($fullLocalPath)."/", "", $fullLocalPath ); $objectHashFolderName = crc32( "koolreport" .$fullLocalPath .@filemtime($fullLocalPath) .$this->report->version().$version ); $objectHashFolderName = ($objectHashFolderName<0) ?abs($objectHashFolderName)."0" :"$objectHashFolderName"; //------------------------- $objectTargetPath = $targetAssetPath."/".$objectHashFolderName; if (!is_dir($objectTargetPath)) { Utility::recurse_copy($fullLocalPath, $objectTargetPath); } else { //Do the check if file in widgetSourceAssetPath is changed, //If there is then copy again. //Currently do nothing for now } if ($targetAssetUrl) { $assetUrl = $targetAssetUrl."/".$objectHashFolderName; } else { $assetUrl = str_replace($document_root, "", $objectTargetPath); } } return $assetUrl; }
php
public function publishAssetFolder($fullLocalPath,$version="") { $fullLocalPath = Utility::standardizePathSeparator($fullLocalPath); $fullLocalPath = Utility::getSymbolicPath($fullLocalPath); $assets = Utility::get($this->report->getSettings(), "assets"); $document_root = Utility::getDocumentRoot(); $assetUrl = ""; if (!$assets) { $assetUrl = str_replace($document_root, "", $fullLocalPath); if ($assetUrl==$fullLocalPath) { /** * Happens when koolreport library is not within document root * setup assets settings that move to the script folder */ $script_folder = Utility::standardizePathSeparator( realpath(dirname($_SERVER["SCRIPT_FILENAME"])) ); $asset_path = $script_folder."/koolreport_assets"; $asset_url = Utility::str_replace_first( $document_root, "", $script_folder )."/koolreport_assets"; if (!is_dir($asset_path)) { mkdir($asset_path, 0755); } $assets = array( "path"=>$asset_path, "url"=>$asset_url, ); $assetUrl = ""; } } if ($assets) { $targetAssetPath = Utility::get($assets, "path"); $targetAssetUrl = Utility::get($assets, "url"); if (!$targetAssetPath) { throw new \Exception("Could not find path to report's assets folder"); } $reportClassFolder = Utility::standardizePathSeparator( dirname(Utility::getClassPath($this->report)) ); if (strpos($targetAssetPath, "/")!== 0 && is_dir($reportClassFolder."/".$targetAssetPath) ) { //Check if relative targetAssetPath existed $targetAssetPath = Utility::standardizePathSeparator( realpath($reportClassFolder."/".$targetAssetPath) ); } else if (is_dir($targetAssetPath)) { //Check if full targetAssetPath existed $targetAssetPath = Utility::standardizePathSeparator( realpath($targetAssetPath) ); } else { throw new \Exception("Report's assets folder not existed"); } //----------------------- $objectFolderName = str_replace( dirname($fullLocalPath)."/", "", $fullLocalPath ); $objectHashFolderName = crc32( "koolreport" .$fullLocalPath .@filemtime($fullLocalPath) .$this->report->version().$version ); $objectHashFolderName = ($objectHashFolderName<0) ?abs($objectHashFolderName)."0" :"$objectHashFolderName"; //------------------------- $objectTargetPath = $targetAssetPath."/".$objectHashFolderName; if (!is_dir($objectTargetPath)) { Utility::recurse_copy($fullLocalPath, $objectTargetPath); } else { //Do the check if file in widgetSourceAssetPath is changed, //If there is then copy again. //Currently do nothing for now } if ($targetAssetUrl) { $assetUrl = $targetAssetUrl."/".$objectHashFolderName; } else { $assetUrl = str_replace($document_root, "", $objectTargetPath); } } return $assetUrl; }
[ "public", "function", "publishAssetFolder", "(", "$", "fullLocalPath", ",", "$", "version", "=", "\"\"", ")", "{", "$", "fullLocalPath", "=", "Utility", "::", "standardizePathSeparator", "(", "$", "fullLocalPath", ")", ";", "$", "fullLocalPath", "=", "Utility", "::", "getSymbolicPath", "(", "$", "fullLocalPath", ")", ";", "$", "assets", "=", "Utility", "::", "get", "(", "$", "this", "->", "report", "->", "getSettings", "(", ")", ",", "\"assets\"", ")", ";", "$", "document_root", "=", "Utility", "::", "getDocumentRoot", "(", ")", ";", "$", "assetUrl", "=", "\"\"", ";", "if", "(", "!", "$", "assets", ")", "{", "$", "assetUrl", "=", "str_replace", "(", "$", "document_root", ",", "\"\"", ",", "$", "fullLocalPath", ")", ";", "if", "(", "$", "assetUrl", "==", "$", "fullLocalPath", ")", "{", "/**\n * Happens when koolreport library is not within document root\n * setup assets settings that move to the script folder\n */", "$", "script_folder", "=", "Utility", "::", "standardizePathSeparator", "(", "realpath", "(", "dirname", "(", "$", "_SERVER", "[", "\"SCRIPT_FILENAME\"", "]", ")", ")", ")", ";", "$", "asset_path", "=", "$", "script_folder", ".", "\"/koolreport_assets\"", ";", "$", "asset_url", "=", "Utility", "::", "str_replace_first", "(", "$", "document_root", ",", "\"\"", ",", "$", "script_folder", ")", ".", "\"/koolreport_assets\"", ";", "if", "(", "!", "is_dir", "(", "$", "asset_path", ")", ")", "{", "mkdir", "(", "$", "asset_path", ",", "0755", ")", ";", "}", "$", "assets", "=", "array", "(", "\"path\"", "=>", "$", "asset_path", ",", "\"url\"", "=>", "$", "asset_url", ",", ")", ";", "$", "assetUrl", "=", "\"\"", ";", "}", "}", "if", "(", "$", "assets", ")", "{", "$", "targetAssetPath", "=", "Utility", "::", "get", "(", "$", "assets", ",", "\"path\"", ")", ";", "$", "targetAssetUrl", "=", "Utility", "::", "get", "(", "$", "assets", ",", "\"url\"", ")", ";", "if", "(", "!", "$", "targetAssetPath", ")", "{", "throw", "new", "\\", "Exception", "(", "\"Could not find path to report's assets folder\"", ")", ";", "}", "$", "reportClassFolder", "=", "Utility", "::", "standardizePathSeparator", "(", "dirname", "(", "Utility", "::", "getClassPath", "(", "$", "this", "->", "report", ")", ")", ")", ";", "if", "(", "strpos", "(", "$", "targetAssetPath", ",", "\"/\"", ")", "!==", "0", "&&", "is_dir", "(", "$", "reportClassFolder", ".", "\"/\"", ".", "$", "targetAssetPath", ")", ")", "{", "//Check if relative targetAssetPath existed", "$", "targetAssetPath", "=", "Utility", "::", "standardizePathSeparator", "(", "realpath", "(", "$", "reportClassFolder", ".", "\"/\"", ".", "$", "targetAssetPath", ")", ")", ";", "}", "else", "if", "(", "is_dir", "(", "$", "targetAssetPath", ")", ")", "{", "//Check if full targetAssetPath existed", "$", "targetAssetPath", "=", "Utility", "::", "standardizePathSeparator", "(", "realpath", "(", "$", "targetAssetPath", ")", ")", ";", "}", "else", "{", "throw", "new", "\\", "Exception", "(", "\"Report's assets folder not existed\"", ")", ";", "}", "//-----------------------", "$", "objectFolderName", "=", "str_replace", "(", "dirname", "(", "$", "fullLocalPath", ")", ".", "\"/\"", ",", "\"\"", ",", "$", "fullLocalPath", ")", ";", "$", "objectHashFolderName", "=", "crc32", "(", "\"koolreport\"", ".", "$", "fullLocalPath", ".", "@", "filemtime", "(", "$", "fullLocalPath", ")", ".", "$", "this", "->", "report", "->", "version", "(", ")", ".", "$", "version", ")", ";", "$", "objectHashFolderName", "=", "(", "$", "objectHashFolderName", "<", "0", ")", "?", "abs", "(", "$", "objectHashFolderName", ")", ".", "\"0\"", ":", "\"$objectHashFolderName\"", ";", "//-------------------------", "$", "objectTargetPath", "=", "$", "targetAssetPath", ".", "\"/\"", ".", "$", "objectHashFolderName", ";", "if", "(", "!", "is_dir", "(", "$", "objectTargetPath", ")", ")", "{", "Utility", "::", "recurse_copy", "(", "$", "fullLocalPath", ",", "$", "objectTargetPath", ")", ";", "}", "else", "{", "//Do the check if file in widgetSourceAssetPath is changed,", "//If there is then copy again.", "//Currently do nothing for now", "}", "if", "(", "$", "targetAssetUrl", ")", "{", "$", "assetUrl", "=", "$", "targetAssetUrl", ".", "\"/\"", ".", "$", "objectHashFolderName", ";", "}", "else", "{", "$", "assetUrl", "=", "str_replace", "(", "$", "document_root", ",", "\"\"", ",", "$", "objectTargetPath", ")", ";", "}", "}", "return", "$", "assetUrl", ";", "}" ]
Copy private asset folder to public place and return public asset url @param string $fullLocalPath Full local path to the asset folder @param string $version Version of the asset folder, normally it is the version of widget @return string The public url to asset folder
[ "Copy", "private", "asset", "folder", "to", "public", "place", "and", "return", "public", "asset", "url" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/core/ResourceManager.php#L75-L174
koolphp/koolreport
src/core/ResourceManager.php
ResourceManager.addScriptFile
protected function addScriptFile($src, $options=array(), $at="begin") { $options["type"] = Utility::get($options, "type", "text/javascript"); $options["src"] = $src; $this->tags[md5($src)] = array( "at"=>$at, "tag"=>"script", "options"=>$options, "content"=>"", ); return $this; }
php
protected function addScriptFile($src, $options=array(), $at="begin") { $options["type"] = Utility::get($options, "type", "text/javascript"); $options["src"] = $src; $this->tags[md5($src)] = array( "at"=>$at, "tag"=>"script", "options"=>$options, "content"=>"", ); return $this; }
[ "protected", "function", "addScriptFile", "(", "$", "src", ",", "$", "options", "=", "array", "(", ")", ",", "$", "at", "=", "\"begin\"", ")", "{", "$", "options", "[", "\"type\"", "]", "=", "Utility", "::", "get", "(", "$", "options", ",", "\"type\"", ",", "\"text/javascript\"", ")", ";", "$", "options", "[", "\"src\"", "]", "=", "$", "src", ";", "$", "this", "->", "tags", "[", "md5", "(", "$", "src", ")", "]", "=", "array", "(", "\"at\"", "=>", "$", "at", ",", "\"tag\"", "=>", "\"script\"", ",", "\"options\"", "=>", "$", "options", ",", "\"content\"", "=>", "\"\"", ",", ")", ";", "return", "$", "this", ";", "}" ]
Add script file to report @param string $src Url link to javascript file @param array $options Additional options for script tag @param string $at The location of the script whether at "begin" of report or at "end" of report @return ResourceManager this resource manager object
[ "Add", "script", "file", "to", "report" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/core/ResourceManager.php#L212-L223
koolphp/koolreport
src/core/ResourceManager.php
ResourceManager.addScript
protected function addScript($script,$options=array(),$at='begin') { $options["type"] = Utility::get($options, "type", "text/javascript"); $this->tags[md5($script)] = array( "at"=>$at, "tag"=>"script", "options"=>$options, "content"=>$script, ); return $this; }
php
protected function addScript($script,$options=array(),$at='begin') { $options["type"] = Utility::get($options, "type", "text/javascript"); $this->tags[md5($script)] = array( "at"=>$at, "tag"=>"script", "options"=>$options, "content"=>$script, ); return $this; }
[ "protected", "function", "addScript", "(", "$", "script", ",", "$", "options", "=", "array", "(", ")", ",", "$", "at", "=", "'begin'", ")", "{", "$", "options", "[", "\"type\"", "]", "=", "Utility", "::", "get", "(", "$", "options", ",", "\"type\"", ",", "\"text/javascript\"", ")", ";", "$", "this", "->", "tags", "[", "md5", "(", "$", "script", ")", "]", "=", "array", "(", "\"at\"", "=>", "$", "at", ",", "\"tag\"", "=>", "\"script\"", ",", "\"options\"", "=>", "$", "options", ",", "\"content\"", "=>", "$", "script", ",", ")", ";", "return", "$", "this", ";", "}" ]
Add a custom script to the report @param string $script Javascript code we want to run @param array $options Any additional options you want to put to script tag @param string $at The location you want to add the script to whether at "begin" of report or at the "end" of report @return ResourceManager This resource manager object
[ "Add", "a", "custom", "script", "to", "the", "report" ]
train
https://github.com/koolphp/koolreport/blob/1ffa6c481535eac59df0852a6eeaa9ff87170e98/src/core/ResourceManager.php#L262-L272