repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
list
docstring
stringlengths
3
47.2k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
91
247
partition
stringclasses
1 value
picocms/Pico
lib/Pico.php
Pico.getPageUrl
public function getPageUrl($page, $queryData = null, $dropIndex = true) { if (is_array($queryData)) { $queryData = http_build_query($queryData, '', '&'); } elseif (($queryData !== null) && !is_string($queryData)) { throw new InvalidArgumentException( 'Argument 2 passed to ' . get_called_class() . '::getPageUrl() must be of the type array or string, ' . (is_object($queryData) ? get_class($queryData) : gettype($queryData)) . ' given' ); } // drop "index" if ($dropIndex) { if ($page === 'index') { $page = ''; } elseif (($pagePathLength = strrpos($page, '/')) !== false) { if (substr($page, $pagePathLength + 1) === 'index') { $page = substr($page, 0, $pagePathLength); } } } if ($queryData) { $queryData = ($this->isUrlRewritingEnabled() || !$page) ? '?' . $queryData : '&' . $queryData; } else { $queryData = ''; } if (!$page) { return $this->getBaseUrl() . $queryData; } elseif (!$this->isUrlRewritingEnabled()) { return $this->getBaseUrl() . '?' . rawurlencode($page) . $queryData; } else { return $this->getBaseUrl() . implode('/', array_map('rawurlencode', explode('/', $page))) . $queryData; } }
php
public function getPageUrl($page, $queryData = null, $dropIndex = true) { if (is_array($queryData)) { $queryData = http_build_query($queryData, '', '&'); } elseif (($queryData !== null) && !is_string($queryData)) { throw new InvalidArgumentException( 'Argument 2 passed to ' . get_called_class() . '::getPageUrl() must be of the type array or string, ' . (is_object($queryData) ? get_class($queryData) : gettype($queryData)) . ' given' ); } // drop "index" if ($dropIndex) { if ($page === 'index') { $page = ''; } elseif (($pagePathLength = strrpos($page, '/')) !== false) { if (substr($page, $pagePathLength + 1) === 'index') { $page = substr($page, 0, $pagePathLength); } } } if ($queryData) { $queryData = ($this->isUrlRewritingEnabled() || !$page) ? '?' . $queryData : '&' . $queryData; } else { $queryData = ''; } if (!$page) { return $this->getBaseUrl() . $queryData; } elseif (!$this->isUrlRewritingEnabled()) { return $this->getBaseUrl() . '?' . rawurlencode($page) . $queryData; } else { return $this->getBaseUrl() . implode('/', array_map('rawurlencode', explode('/', $page))) . $queryData; } }
[ "public", "function", "getPageUrl", "(", "$", "page", ",", "$", "queryData", "=", "null", ",", "$", "dropIndex", "=", "true", ")", "{", "if", "(", "is_array", "(", "$", "queryData", ")", ")", "{", "$", "queryData", "=", "http_build_query", "(", "$", "queryData", ",", "''", ",", "'&'", ")", ";", "}", "elseif", "(", "(", "$", "queryData", "!==", "null", ")", "&&", "!", "is_string", "(", "$", "queryData", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'Argument 2 passed to '", ".", "get_called_class", "(", ")", ".", "'::getPageUrl() must be of the type array or string, '", ".", "(", "is_object", "(", "$", "queryData", ")", "?", "get_class", "(", "$", "queryData", ")", ":", "gettype", "(", "$", "queryData", ")", ")", ".", "' given'", ")", ";", "}", "// drop \"index\"", "if", "(", "$", "dropIndex", ")", "{", "if", "(", "$", "page", "===", "'index'", ")", "{", "$", "page", "=", "''", ";", "}", "elseif", "(", "(", "$", "pagePathLength", "=", "strrpos", "(", "$", "page", ",", "'/'", ")", ")", "!==", "false", ")", "{", "if", "(", "substr", "(", "$", "page", ",", "$", "pagePathLength", "+", "1", ")", "===", "'index'", ")", "{", "$", "page", "=", "substr", "(", "$", "page", ",", "0", ",", "$", "pagePathLength", ")", ";", "}", "}", "}", "if", "(", "$", "queryData", ")", "{", "$", "queryData", "=", "(", "$", "this", "->", "isUrlRewritingEnabled", "(", ")", "||", "!", "$", "page", ")", "?", "'?'", ".", "$", "queryData", ":", "'&'", ".", "$", "queryData", ";", "}", "else", "{", "$", "queryData", "=", "''", ";", "}", "if", "(", "!", "$", "page", ")", "{", "return", "$", "this", "->", "getBaseUrl", "(", ")", ".", "$", "queryData", ";", "}", "elseif", "(", "!", "$", "this", "->", "isUrlRewritingEnabled", "(", ")", ")", "{", "return", "$", "this", "->", "getBaseUrl", "(", ")", ".", "'?'", ".", "rawurlencode", "(", "$", "page", ")", ".", "$", "queryData", ";", "}", "else", "{", "return", "$", "this", "->", "getBaseUrl", "(", ")", ".", "implode", "(", "'/'", ",", "array_map", "(", "'rawurlencode'", ",", "explode", "(", "'/'", ",", "$", "page", ")", ")", ")", ".", "$", "queryData", ";", "}", "}" ]
Returns the URL to a given page This method can be used in Twig templates by applying the `link` filter to a string representing a page ID. @param string $page ID of the page to link to @param array|string|null $queryData either an array of properties to create a URL-encoded query string from, or a already encoded string @param bool $dropIndex if the last path component is "index", passing TRUE (default) will remove this path component @return string URL
[ "Returns", "the", "URL", "to", "a", "given", "page" ]
2cf60e25af993961827e1bf9f54ec1aad7698b09
https://github.com/picocms/Pico/blob/2cf60e25af993961827e1bf9f54ec1aad7698b09/lib/Pico.php#L2119-L2154
train
picocms/Pico
lib/Pico.php
Pico.getPageId
public function getPageId($path) { $contentDir = $this->getConfig('content_dir'); $contentDirLength = strlen($contentDir); if (substr($path, 0, $contentDirLength) !== $contentDir) { return null; } $contentExt = $this->getConfig('content_ext'); $contentExtLength = strlen($contentExt); if (substr($path, -$contentExtLength) !== $contentExt) { return null; } return substr($path, $contentDirLength, -$contentExtLength) ?: null; }
php
public function getPageId($path) { $contentDir = $this->getConfig('content_dir'); $contentDirLength = strlen($contentDir); if (substr($path, 0, $contentDirLength) !== $contentDir) { return null; } $contentExt = $this->getConfig('content_ext'); $contentExtLength = strlen($contentExt); if (substr($path, -$contentExtLength) !== $contentExt) { return null; } return substr($path, $contentDirLength, -$contentExtLength) ?: null; }
[ "public", "function", "getPageId", "(", "$", "path", ")", "{", "$", "contentDir", "=", "$", "this", "->", "getConfig", "(", "'content_dir'", ")", ";", "$", "contentDirLength", "=", "strlen", "(", "$", "contentDir", ")", ";", "if", "(", "substr", "(", "$", "path", ",", "0", ",", "$", "contentDirLength", ")", "!==", "$", "contentDir", ")", "{", "return", "null", ";", "}", "$", "contentExt", "=", "$", "this", "->", "getConfig", "(", "'content_ext'", ")", ";", "$", "contentExtLength", "=", "strlen", "(", "$", "contentExt", ")", ";", "if", "(", "substr", "(", "$", "path", ",", "-", "$", "contentExtLength", ")", "!==", "$", "contentExt", ")", "{", "return", "null", ";", "}", "return", "substr", "(", "$", "path", ",", "$", "contentDirLength", ",", "-", "$", "contentExtLength", ")", "?", ":", "null", ";", "}" ]
Returns the page ID of a given content file @param string $path path to the content file @return string|null either the corresponding page ID or NULL
[ "Returns", "the", "page", "ID", "of", "a", "given", "content", "file" ]
2cf60e25af993961827e1bf9f54ec1aad7698b09
https://github.com/picocms/Pico/blob/2cf60e25af993961827e1bf9f54ec1aad7698b09/lib/Pico.php#L2163-L2180
train
picocms/Pico
lib/Pico.php
Pico.getBaseThemeUrl
public function getBaseThemeUrl() { $themeUrl = $this->getConfig('theme_url'); if ($themeUrl) { return $themeUrl; } if (isset($_SERVER['SCRIPT_FILENAME']) && ($_SERVER['SCRIPT_FILENAME'] !== 'index.php')) { $basePath = dirname($_SERVER['SCRIPT_FILENAME']); $basePath = !in_array($basePath, array('.', '/', '\\'), true) ? $basePath . '/' : '/'; $basePathLength = strlen($basePath); if (substr($this->getThemesDir(), 0, $basePathLength) === $basePath) { $this->config['theme_url'] = $this->getBaseUrl() . substr($this->getThemesDir(), $basePathLength); return $this->config['theme_url']; } } $this->config['theme_url'] = $this->getBaseUrl() . basename($this->getThemesDir()) . '/'; return $this->config['theme_url']; }
php
public function getBaseThemeUrl() { $themeUrl = $this->getConfig('theme_url'); if ($themeUrl) { return $themeUrl; } if (isset($_SERVER['SCRIPT_FILENAME']) && ($_SERVER['SCRIPT_FILENAME'] !== 'index.php')) { $basePath = dirname($_SERVER['SCRIPT_FILENAME']); $basePath = !in_array($basePath, array('.', '/', '\\'), true) ? $basePath . '/' : '/'; $basePathLength = strlen($basePath); if (substr($this->getThemesDir(), 0, $basePathLength) === $basePath) { $this->config['theme_url'] = $this->getBaseUrl() . substr($this->getThemesDir(), $basePathLength); return $this->config['theme_url']; } } $this->config['theme_url'] = $this->getBaseUrl() . basename($this->getThemesDir()) . '/'; return $this->config['theme_url']; }
[ "public", "function", "getBaseThemeUrl", "(", ")", "{", "$", "themeUrl", "=", "$", "this", "->", "getConfig", "(", "'theme_url'", ")", ";", "if", "(", "$", "themeUrl", ")", "{", "return", "$", "themeUrl", ";", "}", "if", "(", "isset", "(", "$", "_SERVER", "[", "'SCRIPT_FILENAME'", "]", ")", "&&", "(", "$", "_SERVER", "[", "'SCRIPT_FILENAME'", "]", "!==", "'index.php'", ")", ")", "{", "$", "basePath", "=", "dirname", "(", "$", "_SERVER", "[", "'SCRIPT_FILENAME'", "]", ")", ";", "$", "basePath", "=", "!", "in_array", "(", "$", "basePath", ",", "array", "(", "'.'", ",", "'/'", ",", "'\\\\'", ")", ",", "true", ")", "?", "$", "basePath", ".", "'/'", ":", "'/'", ";", "$", "basePathLength", "=", "strlen", "(", "$", "basePath", ")", ";", "if", "(", "substr", "(", "$", "this", "->", "getThemesDir", "(", ")", ",", "0", ",", "$", "basePathLength", ")", "===", "$", "basePath", ")", "{", "$", "this", "->", "config", "[", "'theme_url'", "]", "=", "$", "this", "->", "getBaseUrl", "(", ")", ".", "substr", "(", "$", "this", "->", "getThemesDir", "(", ")", ",", "$", "basePathLength", ")", ";", "return", "$", "this", "->", "config", "[", "'theme_url'", "]", ";", "}", "}", "$", "this", "->", "config", "[", "'theme_url'", "]", "=", "$", "this", "->", "getBaseUrl", "(", ")", ".", "basename", "(", "$", "this", "->", "getThemesDir", "(", ")", ")", ".", "'/'", ";", "return", "$", "this", "->", "config", "[", "'theme_url'", "]", ";", "}" ]
Returns the URL of the themes folder of this Pico instance We assume that the themes folder is a arbitrary deep sub folder of the script's base path (i.e. the directory {@path "index.php"} is in resp. the `httpdocs` directory). Usually the script's base path is identical to {@see Pico::$rootDir}, but this may aberrate when Pico got installed as a composer dependency. However, ultimately it allows us to use {@see Pico::getBaseUrl()} as origin of the theme URL. Otherwise Pico falls back to the basename of {@see Pico::$themesDir} (i.e. assuming that `Pico::$themesDir` is `foo/bar/baz`, the base URL of the themes folder will be `baz/`; this ensures BC to Pico < 2.0). Pico's base URL always gets prepended appropriately. @return string the URL of the themes folder
[ "Returns", "the", "URL", "of", "the", "themes", "folder", "of", "this", "Pico", "instance" ]
2cf60e25af993961827e1bf9f54ec1aad7698b09
https://github.com/picocms/Pico/blob/2cf60e25af993961827e1bf9f54ec1aad7698b09/lib/Pico.php#L2198-L2218
train
picocms/Pico
lib/Pico.php
Pico.filterVariable
protected function filterVariable($variable, $filter = '', $options = null, $flags = null) { $defaultValue = null; if (is_array($options)) { $defaultValue = isset($options['default']) ? $options['default'] : null; } elseif ($options !== null) { $defaultValue = $options; $options = array('default' => $defaultValue); } if ($variable === null) { return $defaultValue; } $filter = $filter ? (is_string($filter) ? filter_id($filter) : (int) $filter) : false; if (!$filter) { return false; } $filterOptions = array('options' => $options, 'flags' => 0); foreach ((array) $flags as $flag) { if (is_numeric($flag)) { $filterOptions['flags'] |= (int) $flag; } elseif (is_string($flag)) { $flag = strtoupper(preg_replace('/[^a-zA-Z0-9_]/', '', $flag)); if (($flag === 'NULL_ON_FAILURE') && ($filter === FILTER_VALIDATE_BOOLEAN)) { $filterOptions['flags'] |= FILTER_NULL_ON_FAILURE; } else { $filterOptions['flags'] |= (int) constant('FILTER_FLAG_' . $flag); } } } return filter_var($variable, $filter, $filterOptions); }
php
protected function filterVariable($variable, $filter = '', $options = null, $flags = null) { $defaultValue = null; if (is_array($options)) { $defaultValue = isset($options['default']) ? $options['default'] : null; } elseif ($options !== null) { $defaultValue = $options; $options = array('default' => $defaultValue); } if ($variable === null) { return $defaultValue; } $filter = $filter ? (is_string($filter) ? filter_id($filter) : (int) $filter) : false; if (!$filter) { return false; } $filterOptions = array('options' => $options, 'flags' => 0); foreach ((array) $flags as $flag) { if (is_numeric($flag)) { $filterOptions['flags'] |= (int) $flag; } elseif (is_string($flag)) { $flag = strtoupper(preg_replace('/[^a-zA-Z0-9_]/', '', $flag)); if (($flag === 'NULL_ON_FAILURE') && ($filter === FILTER_VALIDATE_BOOLEAN)) { $filterOptions['flags'] |= FILTER_NULL_ON_FAILURE; } else { $filterOptions['flags'] |= (int) constant('FILTER_FLAG_' . $flag); } } } return filter_var($variable, $filter, $filterOptions); }
[ "protected", "function", "filterVariable", "(", "$", "variable", ",", "$", "filter", "=", "''", ",", "$", "options", "=", "null", ",", "$", "flags", "=", "null", ")", "{", "$", "defaultValue", "=", "null", ";", "if", "(", "is_array", "(", "$", "options", ")", ")", "{", "$", "defaultValue", "=", "isset", "(", "$", "options", "[", "'default'", "]", ")", "?", "$", "options", "[", "'default'", "]", ":", "null", ";", "}", "elseif", "(", "$", "options", "!==", "null", ")", "{", "$", "defaultValue", "=", "$", "options", ";", "$", "options", "=", "array", "(", "'default'", "=>", "$", "defaultValue", ")", ";", "}", "if", "(", "$", "variable", "===", "null", ")", "{", "return", "$", "defaultValue", ";", "}", "$", "filter", "=", "$", "filter", "?", "(", "is_string", "(", "$", "filter", ")", "?", "filter_id", "(", "$", "filter", ")", ":", "(", "int", ")", "$", "filter", ")", ":", "false", ";", "if", "(", "!", "$", "filter", ")", "{", "return", "false", ";", "}", "$", "filterOptions", "=", "array", "(", "'options'", "=>", "$", "options", ",", "'flags'", "=>", "0", ")", ";", "foreach", "(", "(", "array", ")", "$", "flags", "as", "$", "flag", ")", "{", "if", "(", "is_numeric", "(", "$", "flag", ")", ")", "{", "$", "filterOptions", "[", "'flags'", "]", "|=", "(", "int", ")", "$", "flag", ";", "}", "elseif", "(", "is_string", "(", "$", "flag", ")", ")", "{", "$", "flag", "=", "strtoupper", "(", "preg_replace", "(", "'/[^a-zA-Z0-9_]/'", ",", "''", ",", "$", "flag", ")", ")", ";", "if", "(", "(", "$", "flag", "===", "'NULL_ON_FAILURE'", ")", "&&", "(", "$", "filter", "===", "FILTER_VALIDATE_BOOLEAN", ")", ")", "{", "$", "filterOptions", "[", "'flags'", "]", "|=", "FILTER_NULL_ON_FAILURE", ";", "}", "else", "{", "$", "filterOptions", "[", "'flags'", "]", "|=", "(", "int", ")", "constant", "(", "'FILTER_FLAG_'", ".", "$", "flag", ")", ";", "}", "}", "}", "return", "filter_var", "(", "$", "variable", ",", "$", "filter", ",", "$", "filterOptions", ")", ";", "}" ]
Filters a variable with a specified filter This method basically wraps around PHP's `filter_var()` function. It filters data by either validating or sanitizing it. This is especially useful when the data source contains unknown (or foreign) data, like user supplied input. Validation is used to validate or check if the data meets certain qualifications, but will not change the data itself. Sanitization will sanitize the data, so it may alter it by removing undesired characters. It doesn't actually validate the data! The behaviour of most filters can optionally be tweaked by flags. Heads up! Input validation is hard! Always validate your input data the most paranoid way you can imagine. Always prefer validation filters over sanitization filters; be very careful with sanitization filters, you might create cross-site scripting vulnerabilities! @see https://secure.php.net/manual/en/function.filter-var.php PHP's `filter_var()` function @see https://secure.php.net/manual/en/filter.filters.validate.php Validate filters @see https://secure.php.net/manual/en/filter.filters.sanitize.php Sanitize filters @param mixed $variable value to filter @param int|string $filter ID (int) or name (string) of the filter to apply; if omitted, the method will return FALSE @param mixed|array $options either a associative array of options to be used by the filter (e.g. `array('default' => 42)`), or a scalar default value that will be returned when the passed value is NULL (optional) @param int|string|int[]|string[] $flags either a bitwise disjunction of flags or a string with the significant part of a flag constant (the constant name is the result of "FILTER_FLAG_" and the given string in ASCII-only uppercase); you may also pass an array of flags and flag strings (optional) @return mixed with a validation filter, the method either returns the validated value or, provided that the value wasn't valid, the given default value or FALSE; with a sanitization filter, the method returns the sanitized value; if no value (i.e. NULL) was given, the method always returns either the provided default value or NULL
[ "Filters", "a", "variable", "with", "a", "specified", "filter" ]
2cf60e25af993961827e1bf9f54ec1aad7698b09
https://github.com/picocms/Pico/blob/2cf60e25af993961827e1bf9f54ec1aad7698b09/lib/Pico.php#L2317-L2351
train
picocms/Pico
lib/Pico.php
Pico.getFiles
public function getFiles($directory, $fileExtension = '', $order = self::SORT_ASC) { $directory = rtrim($directory, '/'); $result = array(); // scandir() reads files in alphabetical order $files = scandir($directory, $order); $fileExtensionLength = strlen($fileExtension); if ($files !== false) { foreach ($files as $file) { // exclude hidden files/dirs starting with a .; this also excludes the special dirs . and .. // exclude files ending with a ~ (vim/nano backup) or # (emacs backup) if (($file[0] === '.') || in_array(substr($file, -1), array('~', '#'), true)) { continue; } if (is_dir($directory . '/' . $file)) { // get files recursively $result = array_merge($result, $this->getFiles($directory . '/' . $file, $fileExtension, $order)); } elseif (!$fileExtension || (substr($file, -$fileExtensionLength) === $fileExtension)) { $result[] = $directory . '/' . $file; } } } return $result; }
php
public function getFiles($directory, $fileExtension = '', $order = self::SORT_ASC) { $directory = rtrim($directory, '/'); $result = array(); // scandir() reads files in alphabetical order $files = scandir($directory, $order); $fileExtensionLength = strlen($fileExtension); if ($files !== false) { foreach ($files as $file) { // exclude hidden files/dirs starting with a .; this also excludes the special dirs . and .. // exclude files ending with a ~ (vim/nano backup) or # (emacs backup) if (($file[0] === '.') || in_array(substr($file, -1), array('~', '#'), true)) { continue; } if (is_dir($directory . '/' . $file)) { // get files recursively $result = array_merge($result, $this->getFiles($directory . '/' . $file, $fileExtension, $order)); } elseif (!$fileExtension || (substr($file, -$fileExtensionLength) === $fileExtension)) { $result[] = $directory . '/' . $file; } } } return $result; }
[ "public", "function", "getFiles", "(", "$", "directory", ",", "$", "fileExtension", "=", "''", ",", "$", "order", "=", "self", "::", "SORT_ASC", ")", "{", "$", "directory", "=", "rtrim", "(", "$", "directory", ",", "'/'", ")", ";", "$", "result", "=", "array", "(", ")", ";", "// scandir() reads files in alphabetical order", "$", "files", "=", "scandir", "(", "$", "directory", ",", "$", "order", ")", ";", "$", "fileExtensionLength", "=", "strlen", "(", "$", "fileExtension", ")", ";", "if", "(", "$", "files", "!==", "false", ")", "{", "foreach", "(", "$", "files", "as", "$", "file", ")", "{", "// exclude hidden files/dirs starting with a .; this also excludes the special dirs . and ..", "// exclude files ending with a ~ (vim/nano backup) or # (emacs backup)", "if", "(", "(", "$", "file", "[", "0", "]", "===", "'.'", ")", "||", "in_array", "(", "substr", "(", "$", "file", ",", "-", "1", ")", ",", "array", "(", "'~'", ",", "'#'", ")", ",", "true", ")", ")", "{", "continue", ";", "}", "if", "(", "is_dir", "(", "$", "directory", ".", "'/'", ".", "$", "file", ")", ")", "{", "// get files recursively", "$", "result", "=", "array_merge", "(", "$", "result", ",", "$", "this", "->", "getFiles", "(", "$", "directory", ".", "'/'", ".", "$", "file", ",", "$", "fileExtension", ",", "$", "order", ")", ")", ";", "}", "elseif", "(", "!", "$", "fileExtension", "||", "(", "substr", "(", "$", "file", ",", "-", "$", "fileExtensionLength", ")", "===", "$", "fileExtension", ")", ")", "{", "$", "result", "[", "]", "=", "$", "directory", ".", "'/'", ".", "$", "file", ";", "}", "}", "}", "return", "$", "result", ";", "}" ]
Recursively walks through a directory and returns all containing files matching the specified file extension @param string $directory start directory @param string $fileExtension return files with the given file extension only (optional) @param int $order specify whether and how files should be sorted; use Pico::SORT_ASC for a alphabetical ascending order (this is the default behaviour), Pico::SORT_DESC for a descending order or Pico::SORT_NONE to leave the result unsorted @return array list of found files
[ "Recursively", "walks", "through", "a", "directory", "and", "returns", "all", "containing", "files", "matching", "the", "specified", "file", "extension" ]
2cf60e25af993961827e1bf9f54ec1aad7698b09
https://github.com/picocms/Pico/blob/2cf60e25af993961827e1bf9f54ec1aad7698b09/lib/Pico.php#L2367-L2393
train
picocms/Pico
lib/Pico.php
Pico.getAbsolutePath
public function getAbsolutePath($path) { if (DIRECTORY_SEPARATOR === '\\') { if (preg_match('/^(?>[a-zA-Z]:\\\\|\\\\\\\\)/', $path) !== 1) { $path = $this->getRootDir() . $path; } } else { if ($path[0] !== '/') { $path = $this->getRootDir() . $path; } } return rtrim($path, '/\\') . '/'; }
php
public function getAbsolutePath($path) { if (DIRECTORY_SEPARATOR === '\\') { if (preg_match('/^(?>[a-zA-Z]:\\\\|\\\\\\\\)/', $path) !== 1) { $path = $this->getRootDir() . $path; } } else { if ($path[0] !== '/') { $path = $this->getRootDir() . $path; } } return rtrim($path, '/\\') . '/'; }
[ "public", "function", "getAbsolutePath", "(", "$", "path", ")", "{", "if", "(", "DIRECTORY_SEPARATOR", "===", "'\\\\'", ")", "{", "if", "(", "preg_match", "(", "'/^(?>[a-zA-Z]:\\\\\\\\|\\\\\\\\\\\\\\\\)/'", ",", "$", "path", ")", "!==", "1", ")", "{", "$", "path", "=", "$", "this", "->", "getRootDir", "(", ")", ".", "$", "path", ";", "}", "}", "else", "{", "if", "(", "$", "path", "[", "0", "]", "!==", "'/'", ")", "{", "$", "path", "=", "$", "this", "->", "getRootDir", "(", ")", ".", "$", "path", ";", "}", "}", "return", "rtrim", "(", "$", "path", ",", "'/\\\\'", ")", ".", "'/'", ";", "}" ]
Makes a relative path absolute to Pico's root dir This method also guarantees a trailing slash. @param string $path relative or absolute path @return string absolute path
[ "Makes", "a", "relative", "path", "absolute", "to", "Pico", "s", "root", "dir" ]
2cf60e25af993961827e1bf9f54ec1aad7698b09
https://github.com/picocms/Pico/blob/2cf60e25af993961827e1bf9f54ec1aad7698b09/lib/Pico.php#L2439-L2451
train
picocms/Pico
lib/Pico.php
Pico.triggerEvent
public function triggerEvent($eventName, array $params = array()) { foreach ($this->nativePlugins as $plugin) { $plugin->handleEvent($eventName, $params); } }
php
public function triggerEvent($eventName, array $params = array()) { foreach ($this->nativePlugins as $plugin) { $plugin->handleEvent($eventName, $params); } }
[ "public", "function", "triggerEvent", "(", "$", "eventName", ",", "array", "$", "params", "=", "array", "(", ")", ")", "{", "foreach", "(", "$", "this", "->", "nativePlugins", "as", "$", "plugin", ")", "{", "$", "plugin", "->", "handleEvent", "(", "$", "eventName", ",", "$", "params", ")", ";", "}", "}" ]
Triggers events on plugins using the current API version Plugins using older API versions are handled by {@see PicoDeprecated}. Please note that {@see PicoDeprecated} also triggers custom events on plugins using older API versions, thus you can safely use this method to trigger custom events on all loaded plugins, no matter what API version - the event will be triggered in any case. You MUST NOT trigger events of Pico's core with a plugin! @see PicoPluginInterface @see AbstractPicoPlugin @see DummyPlugin @param string $eventName name of the event to trigger @param array $params optional parameters to pass @return void
[ "Triggers", "events", "on", "plugins", "using", "the", "current", "API", "version" ]
2cf60e25af993961827e1bf9f54ec1aad7698b09
https://github.com/picocms/Pico/blob/2cf60e25af993961827e1bf9f54ec1aad7698b09/lib/Pico.php#L2473-L2478
train
Ph3nol/NotificationPusher
src/Sly/NotificationPusher/ApnsPushService.php
ApnsPushService.feedback
public function feedback() { $adapterParams = []; $adapterParams['certificate'] = $this->certificatePath; $adapterParams['passPhrase'] = $this->passPhrase; // Development one by default (without argument). /** @var PushManager $pushManager */ $pushManager = new PushManager($this->environment); // Then declare an adapter. $apnsAdapter = new ApnsAdapter($adapterParams); $this->feedback = $pushManager->getFeedback($apnsAdapter); return $this->feedback; }
php
public function feedback() { $adapterParams = []; $adapterParams['certificate'] = $this->certificatePath; $adapterParams['passPhrase'] = $this->passPhrase; // Development one by default (without argument). /** @var PushManager $pushManager */ $pushManager = new PushManager($this->environment); // Then declare an adapter. $apnsAdapter = new ApnsAdapter($adapterParams); $this->feedback = $pushManager->getFeedback($apnsAdapter); return $this->feedback; }
[ "public", "function", "feedback", "(", ")", "{", "$", "adapterParams", "=", "[", "]", ";", "$", "adapterParams", "[", "'certificate'", "]", "=", "$", "this", "->", "certificatePath", ";", "$", "adapterParams", "[", "'passPhrase'", "]", "=", "$", "this", "->", "passPhrase", ";", "// Development one by default (without argument).", "/** @var PushManager $pushManager */", "$", "pushManager", "=", "new", "PushManager", "(", "$", "this", "->", "environment", ")", ";", "// Then declare an adapter.", "$", "apnsAdapter", "=", "new", "ApnsAdapter", "(", "$", "adapterParams", ")", ";", "$", "this", "->", "feedback", "=", "$", "pushManager", "->", "getFeedback", "(", "$", "apnsAdapter", ")", ";", "return", "$", "this", "->", "feedback", ";", "}" ]
Use feedback to get not registered tokens from last send and remove them from your DB @return array
[ "Use", "feedback", "to", "get", "not", "registered", "tokens", "from", "last", "send", "and", "remove", "them", "from", "your", "DB" ]
18d60465cb130fdda040b14a666cc2d00eaf844e
https://github.com/Ph3nol/NotificationPusher/blob/18d60465cb130fdda040b14a666cc2d00eaf844e/src/Sly/NotificationPusher/ApnsPushService.php#L136-L152
train
Ph3nol/NotificationPusher
src/Sly/NotificationPusher/Adapter/Apns.php
Apns.getOpenedServiceClient
protected function getOpenedServiceClient() { if (!isset($this->openedClient)) { $this->openedClient = $this->getOpenedClient(new ServiceClient()); } return $this->openedClient; }
php
protected function getOpenedServiceClient() { if (!isset($this->openedClient)) { $this->openedClient = $this->getOpenedClient(new ServiceClient()); } return $this->openedClient; }
[ "protected", "function", "getOpenedServiceClient", "(", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "openedClient", ")", ")", "{", "$", "this", "->", "openedClient", "=", "$", "this", "->", "getOpenedClient", "(", "new", "ServiceClient", "(", ")", ")", ";", "}", "return", "$", "this", "->", "openedClient", ";", "}" ]
Get opened ServiceClient @return ServiceClient
[ "Get", "opened", "ServiceClient" ]
18d60465cb130fdda040b14a666cc2d00eaf844e
https://github.com/Ph3nol/NotificationPusher/blob/18d60465cb130fdda040b14a666cc2d00eaf844e/src/Sly/NotificationPusher/Adapter/Apns.php#L153-L160
train
Ph3nol/NotificationPusher
src/Sly/NotificationPusher/Adapter/Apns.php
Apns.getOpenedFeedbackClient
private function getOpenedFeedbackClient() { if (!isset($this->feedbackClient)) { $this->feedbackClient = $this->getOpenedClient(new ServiceFeedbackClient()); } return $this->feedbackClient; }
php
private function getOpenedFeedbackClient() { if (!isset($this->feedbackClient)) { $this->feedbackClient = $this->getOpenedClient(new ServiceFeedbackClient()); } return $this->feedbackClient; }
[ "private", "function", "getOpenedFeedbackClient", "(", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "feedbackClient", ")", ")", "{", "$", "this", "->", "feedbackClient", "=", "$", "this", "->", "getOpenedClient", "(", "new", "ServiceFeedbackClient", "(", ")", ")", ";", "}", "return", "$", "this", "->", "feedbackClient", ";", "}" ]
Get opened ServiceFeedbackClient @return ServiceFeedbackClient
[ "Get", "opened", "ServiceFeedbackClient" ]
18d60465cb130fdda040b14a666cc2d00eaf844e
https://github.com/Ph3nol/NotificationPusher/blob/18d60465cb130fdda040b14a666cc2d00eaf844e/src/Sly/NotificationPusher/Adapter/Apns.php#L167-L174
train
Ph3nol/NotificationPusher
src/Sly/NotificationPusher/Adapter/Gcm.php
Gcm.setAdapterParameters
public function setAdapterParameters(array $config = []) { if (!is_array($config) || empty($config)) { throw new InvalidArgumentException('$config must be an associative array with at least 1 item.'); } if ($this->httpClient === null) { $this->httpClient = new HttpClient(); $this->httpClient->setAdapter(new HttpSocketAdapter()); } $this->httpClient->getAdapter()->setOptions($config); }
php
public function setAdapterParameters(array $config = []) { if (!is_array($config) || empty($config)) { throw new InvalidArgumentException('$config must be an associative array with at least 1 item.'); } if ($this->httpClient === null) { $this->httpClient = new HttpClient(); $this->httpClient->setAdapter(new HttpSocketAdapter()); } $this->httpClient->getAdapter()->setOptions($config); }
[ "public", "function", "setAdapterParameters", "(", "array", "$", "config", "=", "[", "]", ")", "{", "if", "(", "!", "is_array", "(", "$", "config", ")", "||", "empty", "(", "$", "config", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'$config must be an associative array with at least 1 item.'", ")", ";", "}", "if", "(", "$", "this", "->", "httpClient", "===", "null", ")", "{", "$", "this", "->", "httpClient", "=", "new", "HttpClient", "(", ")", ";", "$", "this", "->", "httpClient", "->", "setAdapter", "(", "new", "HttpSocketAdapter", "(", ")", ")", ";", "}", "$", "this", "->", "httpClient", "->", "getAdapter", "(", ")", "->", "setOptions", "(", "$", "config", ")", ";", "}" ]
Send custom parameters to the Http Adapter without overriding the Http Client. @param array $config @throws \InvalidArgumentException
[ "Send", "custom", "parameters", "to", "the", "Http", "Adapter", "without", "overriding", "the", "Http", "Client", "." ]
18d60465cb130fdda040b14a666cc2d00eaf844e
https://github.com/Ph3nol/NotificationPusher/blob/18d60465cb130fdda040b14a666cc2d00eaf844e/src/Sly/NotificationPusher/Adapter/Gcm.php#L227-L239
train
Ph3nol/NotificationPusher
src/Sly/NotificationPusher/Console/Command/PushCommand.php
PushCommand.getAdapterClassFromArgument
private function getAdapterClassFromArgument($argument) { if (!class_exists($adapterClass = $argument) && !class_exists($adapterClass = '\\Sly\\NotificationPusher\\Adapter\\' . ucfirst($argument))) { throw new AdapterException( sprintf( 'Adapter class %s does not exist', $adapterClass ) ); } return $adapterClass; }
php
private function getAdapterClassFromArgument($argument) { if (!class_exists($adapterClass = $argument) && !class_exists($adapterClass = '\\Sly\\NotificationPusher\\Adapter\\' . ucfirst($argument))) { throw new AdapterException( sprintf( 'Adapter class %s does not exist', $adapterClass ) ); } return $adapterClass; }
[ "private", "function", "getAdapterClassFromArgument", "(", "$", "argument", ")", "{", "if", "(", "!", "class_exists", "(", "$", "adapterClass", "=", "$", "argument", ")", "&&", "!", "class_exists", "(", "$", "adapterClass", "=", "'\\\\Sly\\\\NotificationPusher\\\\Adapter\\\\'", ".", "ucfirst", "(", "$", "argument", ")", ")", ")", "{", "throw", "new", "AdapterException", "(", "sprintf", "(", "'Adapter class %s does not exist'", ",", "$", "adapterClass", ")", ")", ";", "}", "return", "$", "adapterClass", ";", "}" ]
Get adapter class from argument. @param string $argument Given argument @return string @throws AdapterException When given adapter class doesn't exist
[ "Get", "adapter", "class", "from", "argument", "." ]
18d60465cb130fdda040b14a666cc2d00eaf844e
https://github.com/Ph3nol/NotificationPusher/blob/18d60465cb130fdda040b14a666cc2d00eaf844e/src/Sly/NotificationPusher/Console/Command/PushCommand.php#L106-L119
train
Ph3nol/NotificationPusher
src/Sly/NotificationPusher/GcmPushService.php
GcmPushService.push
public function push(array $tokens = [], array $notifications = [], array $params = []) { if (!$tokens || !$notifications) { return null; } $adapterParams = []; $deviceParams = []; $messageParams = []; if (isset($params) && !empty($params)) { if (isset($params['adapter'])) { $adapterParams = $params['adapter']; } if (isset($params['device'])) { $deviceParams = $params['device']; } if (isset($params['message'])) { $messageParams = $params['message']; } //because we have now notification and data separated if (isset($params['notificationData'])) { $messageParams['notificationData'] = $params['notificationData']; } } $adapterParams['apiKey'] = $this->apiKey; if (!$this->apiKey) { throw new \RuntimeException('Android api key must be set'); } // Development one by default (without argument). /** @var PushManager $pushManager */ $pushManager = new PushManager($this->environment); // Then declare an adapter. $gcmAdapter = new GcmAdapter($adapterParams); // Set the device(s) to push the notification to. $devices = new DeviceCollection([]); //devices foreach ($tokens as $token) { $devices->add(new Device($token, $deviceParams)); } foreach ($notifications as $notificationText) { // Then, create the push skel. $message = new Message($notificationText, $messageParams); // Finally, create and add the push to the manager, and push it! $push = new Push($gcmAdapter, $devices, $message); $pushManager->add($push); } // Returns a collection of notified devices $pushes = $pushManager->push(); $this->response = $gcmAdapter->getResponse(); return $this->response; }
php
public function push(array $tokens = [], array $notifications = [], array $params = []) { if (!$tokens || !$notifications) { return null; } $adapterParams = []; $deviceParams = []; $messageParams = []; if (isset($params) && !empty($params)) { if (isset($params['adapter'])) { $adapterParams = $params['adapter']; } if (isset($params['device'])) { $deviceParams = $params['device']; } if (isset($params['message'])) { $messageParams = $params['message']; } //because we have now notification and data separated if (isset($params['notificationData'])) { $messageParams['notificationData'] = $params['notificationData']; } } $adapterParams['apiKey'] = $this->apiKey; if (!$this->apiKey) { throw new \RuntimeException('Android api key must be set'); } // Development one by default (without argument). /** @var PushManager $pushManager */ $pushManager = new PushManager($this->environment); // Then declare an adapter. $gcmAdapter = new GcmAdapter($adapterParams); // Set the device(s) to push the notification to. $devices = new DeviceCollection([]); //devices foreach ($tokens as $token) { $devices->add(new Device($token, $deviceParams)); } foreach ($notifications as $notificationText) { // Then, create the push skel. $message = new Message($notificationText, $messageParams); // Finally, create and add the push to the manager, and push it! $push = new Push($gcmAdapter, $devices, $message); $pushManager->add($push); } // Returns a collection of notified devices $pushes = $pushManager->push(); $this->response = $gcmAdapter->getResponse(); return $this->response; }
[ "public", "function", "push", "(", "array", "$", "tokens", "=", "[", "]", ",", "array", "$", "notifications", "=", "[", "]", ",", "array", "$", "params", "=", "[", "]", ")", "{", "if", "(", "!", "$", "tokens", "||", "!", "$", "notifications", ")", "{", "return", "null", ";", "}", "$", "adapterParams", "=", "[", "]", ";", "$", "deviceParams", "=", "[", "]", ";", "$", "messageParams", "=", "[", "]", ";", "if", "(", "isset", "(", "$", "params", ")", "&&", "!", "empty", "(", "$", "params", ")", ")", "{", "if", "(", "isset", "(", "$", "params", "[", "'adapter'", "]", ")", ")", "{", "$", "adapterParams", "=", "$", "params", "[", "'adapter'", "]", ";", "}", "if", "(", "isset", "(", "$", "params", "[", "'device'", "]", ")", ")", "{", "$", "deviceParams", "=", "$", "params", "[", "'device'", "]", ";", "}", "if", "(", "isset", "(", "$", "params", "[", "'message'", "]", ")", ")", "{", "$", "messageParams", "=", "$", "params", "[", "'message'", "]", ";", "}", "//because we have now notification and data separated", "if", "(", "isset", "(", "$", "params", "[", "'notificationData'", "]", ")", ")", "{", "$", "messageParams", "[", "'notificationData'", "]", "=", "$", "params", "[", "'notificationData'", "]", ";", "}", "}", "$", "adapterParams", "[", "'apiKey'", "]", "=", "$", "this", "->", "apiKey", ";", "if", "(", "!", "$", "this", "->", "apiKey", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'Android api key must be set'", ")", ";", "}", "// Development one by default (without argument).", "/** @var PushManager $pushManager */", "$", "pushManager", "=", "new", "PushManager", "(", "$", "this", "->", "environment", ")", ";", "// Then declare an adapter.", "$", "gcmAdapter", "=", "new", "GcmAdapter", "(", "$", "adapterParams", ")", ";", "// Set the device(s) to push the notification to.", "$", "devices", "=", "new", "DeviceCollection", "(", "[", "]", ")", ";", "//devices", "foreach", "(", "$", "tokens", "as", "$", "token", ")", "{", "$", "devices", "->", "add", "(", "new", "Device", "(", "$", "token", ",", "$", "deviceParams", ")", ")", ";", "}", "foreach", "(", "$", "notifications", "as", "$", "notificationText", ")", "{", "// Then, create the push skel.", "$", "message", "=", "new", "Message", "(", "$", "notificationText", ",", "$", "messageParams", ")", ";", "// Finally, create and add the push to the manager, and push it!", "$", "push", "=", "new", "Push", "(", "$", "gcmAdapter", ",", "$", "devices", ",", "$", "message", ")", ";", "$", "pushManager", "->", "add", "(", "$", "push", ")", ";", "}", "// Returns a collection of notified devices", "$", "pushes", "=", "$", "pushManager", "->", "push", "(", ")", ";", "$", "this", "->", "response", "=", "$", "gcmAdapter", "->", "getResponse", "(", ")", ";", "return", "$", "this", "->", "response", ";", "}" ]
params keys adapter message device @param array $tokens @param array $notifications @param array $params @return ResponseInterface
[ "params", "keys", "adapter", "message", "device" ]
18d60465cb130fdda040b14a666cc2d00eaf844e
https://github.com/Ph3nol/NotificationPusher/blob/18d60465cb130fdda040b14a666cc2d00eaf844e/src/Sly/NotificationPusher/GcmPushService.php#L54-L118
train
Ph3nol/NotificationPusher
src/Sly/NotificationPusher/Model/Push.php
Push.checkDevicesTokens
private function checkDevicesTokens() { $devices = $this->getDevices(); $adapter = $this->getAdapter(); foreach ($devices as $device) { if (false === $adapter->supports($device->getToken())) { throw new AdapterException( sprintf( 'Adapter %s does not support %s token\'s device', (string)$adapter, $device->getToken() ) ); } } }
php
private function checkDevicesTokens() { $devices = $this->getDevices(); $adapter = $this->getAdapter(); foreach ($devices as $device) { if (false === $adapter->supports($device->getToken())) { throw new AdapterException( sprintf( 'Adapter %s does not support %s token\'s device', (string)$adapter, $device->getToken() ) ); } } }
[ "private", "function", "checkDevicesTokens", "(", ")", "{", "$", "devices", "=", "$", "this", "->", "getDevices", "(", ")", ";", "$", "adapter", "=", "$", "this", "->", "getAdapter", "(", ")", ";", "foreach", "(", "$", "devices", "as", "$", "device", ")", "{", "if", "(", "false", "===", "$", "adapter", "->", "supports", "(", "$", "device", "->", "getToken", "(", ")", ")", ")", "{", "throw", "new", "AdapterException", "(", "sprintf", "(", "'Adapter %s does not support %s token\\'s device'", ",", "(", "string", ")", "$", "adapter", ",", "$", "device", "->", "getToken", "(", ")", ")", ")", ";", "}", "}", "}" ]
Check devices tokens. @throws \Sly\NotificationPusher\Exception\AdapterException
[ "Check", "devices", "tokens", "." ]
18d60465cb130fdda040b14a666cc2d00eaf844e
https://github.com/Ph3nol/NotificationPusher/blob/18d60465cb130fdda040b14a666cc2d00eaf844e/src/Sly/NotificationPusher/Model/Push.php#L89-L105
train
Ph3nol/NotificationPusher
src/Sly/NotificationPusher/Model/Push.php
Push.addResponse
public function addResponse(DeviceInterface $device, $response) { $this->getResponses()->add($device->getToken(), $response); }
php
public function addResponse(DeviceInterface $device, $response) { $this->getResponses()->add($device->getToken(), $response); }
[ "public", "function", "addResponse", "(", "DeviceInterface", "$", "device", ",", "$", "response", ")", "{", "$", "this", "->", "getResponses", "(", ")", "->", "add", "(", "$", "device", "->", "getToken", "(", ")", ",", "$", "response", ")", ";", "}" ]
adds a response @param \Sly\NotificationPusher\Model\DeviceInterface $device @param mixed $response
[ "adds", "a", "response" ]
18d60465cb130fdda040b14a666cc2d00eaf844e
https://github.com/Ph3nol/NotificationPusher/blob/18d60465cb130fdda040b14a666cc2d00eaf844e/src/Sly/NotificationPusher/Model/Push.php#L245-L248
train
Ph3nol/NotificationPusher
src/Sly/NotificationPusher/PushManager.php
PushManager.getFeedback
public function getFeedback(AdapterInterface $adapter) { if (!$adapter instanceof FeedbackAdapterInterface) { throw new AdapterException( sprintf( '%s adapter has no dedicated "getFeedback" method', (string)$adapter ) ); } $adapter->setEnvironment($this->getEnvironment()); return $adapter->getFeedback(); }
php
public function getFeedback(AdapterInterface $adapter) { if (!$adapter instanceof FeedbackAdapterInterface) { throw new AdapterException( sprintf( '%s adapter has no dedicated "getFeedback" method', (string)$adapter ) ); } $adapter->setEnvironment($this->getEnvironment()); return $adapter->getFeedback(); }
[ "public", "function", "getFeedback", "(", "AdapterInterface", "$", "adapter", ")", "{", "if", "(", "!", "$", "adapter", "instanceof", "FeedbackAdapterInterface", ")", "{", "throw", "new", "AdapterException", "(", "sprintf", "(", "'%s adapter has no dedicated \"getFeedback\" method'", ",", "(", "string", ")", "$", "adapter", ")", ")", ";", "}", "$", "adapter", "->", "setEnvironment", "(", "$", "this", "->", "getEnvironment", "(", ")", ")", ";", "return", "$", "adapter", "->", "getFeedback", "(", ")", ";", "}" ]
Get feedback. @param \Sly\NotificationPusher\Adapter\AdapterInterface $adapter Adapter @return array @throws AdapterException When the adapter has no dedicated `getFeedback` method
[ "Get", "feedback", "." ]
18d60465cb130fdda040b14a666cc2d00eaf844e
https://github.com/Ph3nol/NotificationPusher/blob/18d60465cb130fdda040b14a666cc2d00eaf844e/src/Sly/NotificationPusher/PushManager.php#L112-L125
train
verot/class.upload.php
src/class.upload.php
upload.gdversion
function gdversion($full = false) { static $gd_version = null; static $gd_full_version = null; if ($gd_version === null) { if ($this->function_enabled('gd_info')) { $gd = gd_info(); $gd = $gd["GD Version"]; $regex = "/([\d\.]+)/i"; } else { ob_start(); phpinfo(8); $gd = ob_get_contents(); ob_end_clean(); $regex = "/\bgd\s+version\b[^\d\n\r]+?([\d\.]+)/i"; } if (preg_match($regex, $gd, $m)) { $gd_full_version = (string) $m[1]; $gd_version = (float) $m[1]; } else { $gd_full_version = 'none'; $gd_version = 0; } } if ($full) { return $gd_full_version; } else { return $gd_version; } }
php
function gdversion($full = false) { static $gd_version = null; static $gd_full_version = null; if ($gd_version === null) { if ($this->function_enabled('gd_info')) { $gd = gd_info(); $gd = $gd["GD Version"]; $regex = "/([\d\.]+)/i"; } else { ob_start(); phpinfo(8); $gd = ob_get_contents(); ob_end_clean(); $regex = "/\bgd\s+version\b[^\d\n\r]+?([\d\.]+)/i"; } if (preg_match($regex, $gd, $m)) { $gd_full_version = (string) $m[1]; $gd_version = (float) $m[1]; } else { $gd_full_version = 'none'; $gd_version = 0; } } if ($full) { return $gd_full_version; } else { return $gd_version; } }
[ "function", "gdversion", "(", "$", "full", "=", "false", ")", "{", "static", "$", "gd_version", "=", "null", ";", "static", "$", "gd_full_version", "=", "null", ";", "if", "(", "$", "gd_version", "===", "null", ")", "{", "if", "(", "$", "this", "->", "function_enabled", "(", "'gd_info'", ")", ")", "{", "$", "gd", "=", "gd_info", "(", ")", ";", "$", "gd", "=", "$", "gd", "[", "\"GD Version\"", "]", ";", "$", "regex", "=", "\"/([\\d\\.]+)/i\"", ";", "}", "else", "{", "ob_start", "(", ")", ";", "phpinfo", "(", "8", ")", ";", "$", "gd", "=", "ob_get_contents", "(", ")", ";", "ob_end_clean", "(", ")", ";", "$", "regex", "=", "\"/\\bgd\\s+version\\b[^\\d\\n\\r]+?([\\d\\.]+)/i\"", ";", "}", "if", "(", "preg_match", "(", "$", "regex", ",", "$", "gd", ",", "$", "m", ")", ")", "{", "$", "gd_full_version", "=", "(", "string", ")", "$", "m", "[", "1", "]", ";", "$", "gd_version", "=", "(", "float", ")", "$", "m", "[", "1", "]", ";", "}", "else", "{", "$", "gd_full_version", "=", "'none'", ";", "$", "gd_version", "=", "0", ";", "}", "}", "if", "(", "$", "full", ")", "{", "return", "$", "gd_full_version", ";", "}", "else", "{", "return", "$", "gd_version", ";", "}", "}" ]
Returns the version of GD @access public @param boolean $full Optional flag to get precise version @return float GD version
[ "Returns", "the", "version", "of", "GD" ]
28de54ee2ba5a30609eae26d76a15979a94568f1
https://github.com/verot/class.upload.php/blob/28de54ee2ba5a30609eae26d76a15979a94568f1/src/class.upload.php#L2598-L2626
train
verot/class.upload.php
src/class.upload.php
upload.function_enabled
function function_enabled($func) { // cache the list of disabled functions static $disabled = null; if ($disabled === null) $disabled = array_map('trim', array_map('strtolower', explode(',', ini_get('disable_functions')))); // cache the list of functions blacklisted by suhosin static $blacklist = null; if ($blacklist === null) $blacklist = extension_loaded('suhosin') ? array_map('trim', array_map('strtolower', explode(',', ini_get(' suhosin.executor.func.blacklist')))) : array(); // checks if the function is really enabled return (function_exists($func) && !in_array($func, $disabled) && !in_array($func, $blacklist)); }
php
function function_enabled($func) { // cache the list of disabled functions static $disabled = null; if ($disabled === null) $disabled = array_map('trim', array_map('strtolower', explode(',', ini_get('disable_functions')))); // cache the list of functions blacklisted by suhosin static $blacklist = null; if ($blacklist === null) $blacklist = extension_loaded('suhosin') ? array_map('trim', array_map('strtolower', explode(',', ini_get(' suhosin.executor.func.blacklist')))) : array(); // checks if the function is really enabled return (function_exists($func) && !in_array($func, $disabled) && !in_array($func, $blacklist)); }
[ "function", "function_enabled", "(", "$", "func", ")", "{", "// cache the list of disabled functions", "static", "$", "disabled", "=", "null", ";", "if", "(", "$", "disabled", "===", "null", ")", "$", "disabled", "=", "array_map", "(", "'trim'", ",", "array_map", "(", "'strtolower'", ",", "explode", "(", "','", ",", "ini_get", "(", "'disable_functions'", ")", ")", ")", ")", ";", "// cache the list of functions blacklisted by suhosin", "static", "$", "blacklist", "=", "null", ";", "if", "(", "$", "blacklist", "===", "null", ")", "$", "blacklist", "=", "extension_loaded", "(", "'suhosin'", ")", "?", "array_map", "(", "'trim'", ",", "array_map", "(", "'strtolower'", ",", "explode", "(", "','", ",", "ini_get", "(", "' suhosin.executor.func.blacklist'", ")", ")", ")", ")", ":", "array", "(", ")", ";", "// checks if the function is really enabled", "return", "(", "function_exists", "(", "$", "func", ")", "&&", "!", "in_array", "(", "$", "func", ",", "$", "disabled", ")", "&&", "!", "in_array", "(", "$", "func", ",", "$", "blacklist", ")", ")", ";", "}" ]
Checks if a function is available @access private @param string $func Function name @return boolean Success
[ "Checks", "if", "a", "function", "is", "available" ]
28de54ee2ba5a30609eae26d76a15979a94568f1
https://github.com/verot/class.upload.php/blob/28de54ee2ba5a30609eae26d76a15979a94568f1/src/class.upload.php#L2635-L2644
train
verot/class.upload.php
src/class.upload.php
upload.rmkdir
function rmkdir($path, $mode = 0755) { return is_dir($path) || ( $this->rmkdir(dirname($path), $mode) && $this->_mkdir($path, $mode) ); }
php
function rmkdir($path, $mode = 0755) { return is_dir($path) || ( $this->rmkdir(dirname($path), $mode) && $this->_mkdir($path, $mode) ); }
[ "function", "rmkdir", "(", "$", "path", ",", "$", "mode", "=", "0755", ")", "{", "return", "is_dir", "(", "$", "path", ")", "||", "(", "$", "this", "->", "rmkdir", "(", "dirname", "(", "$", "path", ")", ",", "$", "mode", ")", "&&", "$", "this", "->", "_mkdir", "(", "$", "path", ",", "$", "mode", ")", ")", ";", "}" ]
Creates directories recursively @access private @param string $path Path to create @param integer $mode Optional permissions @return boolean Success
[ "Creates", "directories", "recursively" ]
28de54ee2ba5a30609eae26d76a15979a94568f1
https://github.com/verot/class.upload.php/blob/28de54ee2ba5a30609eae26d76a15979a94568f1/src/class.upload.php#L2654-L2656
train
verot/class.upload.php
src/class.upload.php
upload.imagecreatenew
function imagecreatenew($x, $y, $fill = true, $trsp = false) { if ($x < 1) $x = 1; if ($y < 1) $y = 1; if ($this->gdversion() >= 2 && !$this->image_is_palette) { // create a true color image $dst_im = imagecreatetruecolor($x, $y); // this preserves transparency in PNGs, in true color if (empty($this->image_background_color) || $trsp) { imagealphablending($dst_im, false ); imagefilledrectangle($dst_im, 0, 0, $x, $y, imagecolorallocatealpha($dst_im, 0, 0, 0, 127)); } } else { // creates a palette image $dst_im = imagecreate($x, $y); // preserves transparency for palette images, if the original image has transparency if (($fill && $this->image_is_transparent && empty($this->image_background_color)) || $trsp) { imagefilledrectangle($dst_im, 0, 0, $x, $y, $this->image_transparent_color); imagecolortransparent($dst_im, $this->image_transparent_color); } } // fills with background color if any is set if ($fill && !empty($this->image_background_color) && !$trsp) { list($red, $green, $blue) = $this->getcolors($this->image_background_color); $background_color = imagecolorallocate($dst_im, $red, $green, $blue); imagefilledrectangle($dst_im, 0, 0, $x, $y, $background_color); } return $dst_im; }
php
function imagecreatenew($x, $y, $fill = true, $trsp = false) { if ($x < 1) $x = 1; if ($y < 1) $y = 1; if ($this->gdversion() >= 2 && !$this->image_is_palette) { // create a true color image $dst_im = imagecreatetruecolor($x, $y); // this preserves transparency in PNGs, in true color if (empty($this->image_background_color) || $trsp) { imagealphablending($dst_im, false ); imagefilledrectangle($dst_im, 0, 0, $x, $y, imagecolorallocatealpha($dst_im, 0, 0, 0, 127)); } } else { // creates a palette image $dst_im = imagecreate($x, $y); // preserves transparency for palette images, if the original image has transparency if (($fill && $this->image_is_transparent && empty($this->image_background_color)) || $trsp) { imagefilledrectangle($dst_im, 0, 0, $x, $y, $this->image_transparent_color); imagecolortransparent($dst_im, $this->image_transparent_color); } } // fills with background color if any is set if ($fill && !empty($this->image_background_color) && !$trsp) { list($red, $green, $blue) = $this->getcolors($this->image_background_color); $background_color = imagecolorallocate($dst_im, $red, $green, $blue); imagefilledrectangle($dst_im, 0, 0, $x, $y, $background_color); } return $dst_im; }
[ "function", "imagecreatenew", "(", "$", "x", ",", "$", "y", ",", "$", "fill", "=", "true", ",", "$", "trsp", "=", "false", ")", "{", "if", "(", "$", "x", "<", "1", ")", "$", "x", "=", "1", ";", "if", "(", "$", "y", "<", "1", ")", "$", "y", "=", "1", ";", "if", "(", "$", "this", "->", "gdversion", "(", ")", ">=", "2", "&&", "!", "$", "this", "->", "image_is_palette", ")", "{", "// create a true color image", "$", "dst_im", "=", "imagecreatetruecolor", "(", "$", "x", ",", "$", "y", ")", ";", "// this preserves transparency in PNGs, in true color", "if", "(", "empty", "(", "$", "this", "->", "image_background_color", ")", "||", "$", "trsp", ")", "{", "imagealphablending", "(", "$", "dst_im", ",", "false", ")", ";", "imagefilledrectangle", "(", "$", "dst_im", ",", "0", ",", "0", ",", "$", "x", ",", "$", "y", ",", "imagecolorallocatealpha", "(", "$", "dst_im", ",", "0", ",", "0", ",", "0", ",", "127", ")", ")", ";", "}", "}", "else", "{", "// creates a palette image", "$", "dst_im", "=", "imagecreate", "(", "$", "x", ",", "$", "y", ")", ";", "// preserves transparency for palette images, if the original image has transparency", "if", "(", "(", "$", "fill", "&&", "$", "this", "->", "image_is_transparent", "&&", "empty", "(", "$", "this", "->", "image_background_color", ")", ")", "||", "$", "trsp", ")", "{", "imagefilledrectangle", "(", "$", "dst_im", ",", "0", ",", "0", ",", "$", "x", ",", "$", "y", ",", "$", "this", "->", "image_transparent_color", ")", ";", "imagecolortransparent", "(", "$", "dst_im", ",", "$", "this", "->", "image_transparent_color", ")", ";", "}", "}", "// fills with background color if any is set", "if", "(", "$", "fill", "&&", "!", "empty", "(", "$", "this", "->", "image_background_color", ")", "&&", "!", "$", "trsp", ")", "{", "list", "(", "$", "red", ",", "$", "green", ",", "$", "blue", ")", "=", "$", "this", "->", "getcolors", "(", "$", "this", "->", "image_background_color", ")", ";", "$", "background_color", "=", "imagecolorallocate", "(", "$", "dst_im", ",", "$", "red", ",", "$", "green", ",", "$", "blue", ")", ";", "imagefilledrectangle", "(", "$", "dst_im", ",", "0", ",", "0", ",", "$", "x", ",", "$", "y", ",", "$", "background_color", ")", ";", "}", "return", "$", "dst_im", ";", "}" ]
Creates a container image @access private @param integer $x Width @param integer $y Height @param boolean $fill Optional flag to draw the background color or not @param boolean $trsp Optional flag to set the background to be transparent @return resource Container image
[ "Creates", "a", "container", "image" ]
28de54ee2ba5a30609eae26d76a15979a94568f1
https://github.com/verot/class.upload.php/blob/28de54ee2ba5a30609eae26d76a15979a94568f1/src/class.upload.php#L2845-L2871
train
verot/class.upload.php
src/class.upload.php
upload.imagetransfer
function imagetransfer($src_im, $dst_im) { if (is_resource($dst_im)) imagedestroy($dst_im); $dst_im = & $src_im; return $dst_im; }
php
function imagetransfer($src_im, $dst_im) { if (is_resource($dst_im)) imagedestroy($dst_im); $dst_im = & $src_im; return $dst_im; }
[ "function", "imagetransfer", "(", "$", "src_im", ",", "$", "dst_im", ")", "{", "if", "(", "is_resource", "(", "$", "dst_im", ")", ")", "imagedestroy", "(", "$", "dst_im", ")", ";", "$", "dst_im", "=", "&", "$", "src_im", ";", "return", "$", "dst_im", ";", "}" ]
Transfers an image from the container to the destination image @access private @param resource $src_im Container image @param resource $dst_im Destination image @return resource Destination image
[ "Transfers", "an", "image", "from", "the", "container", "to", "the", "destination", "image" ]
28de54ee2ba5a30609eae26d76a15979a94568f1
https://github.com/verot/class.upload.php/blob/28de54ee2ba5a30609eae26d76a15979a94568f1/src/class.upload.php#L2882-L2886
train
verot/class.upload.php
src/class.upload.php
upload.clean
function clean() { $this->log .= '<b>cleanup</b><br />'; $this->log .= '- delete temp file ' . $this->file_src_pathname . '<br />'; @unlink($this->file_src_pathname); }
php
function clean() { $this->log .= '<b>cleanup</b><br />'; $this->log .= '- delete temp file ' . $this->file_src_pathname . '<br />'; @unlink($this->file_src_pathname); }
[ "function", "clean", "(", ")", "{", "$", "this", "->", "log", ".=", "'<b>cleanup</b><br />'", ";", "$", "this", "->", "log", ".=", "'- delete temp file '", ".", "$", "this", "->", "file_src_pathname", ".", "'<br />'", ";", "@", "unlink", "(", "$", "this", "->", "file_src_pathname", ")", ";", "}" ]
Deletes the uploaded file from its temporary location When PHP uploads a file, it stores it in a temporary location. When you {@link process} the file, you actually copy the resulting file to the given location, it doesn't alter the original file. Once you have processed the file as many times as you wanted, you can delete the uploaded file. If there is open_basedir restrictions, the uploaded file is in fact a temporary file You might want not to use this function if you work on local files, as it will delete the source file @access public
[ "Deletes", "the", "uploaded", "file", "from", "its", "temporary", "location" ]
28de54ee2ba5a30609eae26d76a15979a94568f1
https://github.com/verot/class.upload.php/blob/28de54ee2ba5a30609eae26d76a15979a94568f1/src/class.upload.php#L4927-L4931
train
verot/class.upload.php
src/class.upload.php
upload.imagebmp
function imagebmp(&$im, $filename = "") { if (!$im) return false; $w = imagesx($im); $h = imagesy($im); $result = ''; // if the image is not true color, we convert it first if (!imageistruecolor($im)) { $tmp = imagecreatetruecolor($w, $h); imagecopy($tmp, $im, 0, 0, 0, 0, $w, $h); imagedestroy($im); $im = & $tmp; } $biBPLine = $w * 3; $biStride = ($biBPLine + 3) & ~3; $biSizeImage = $biStride * $h; $bfOffBits = 54; $bfSize = $bfOffBits + $biSizeImage; $result .= substr('BM', 0, 2); $result .= pack ('VvvV', $bfSize, 0, 0, $bfOffBits); $result .= pack ('VVVvvVVVVVV', 40, $w, $h, 1, 24, 0, $biSizeImage, 0, 0, 0, 0); $numpad = $biStride - $biBPLine; for ($y = $h - 1; $y >= 0; --$y) { for ($x = 0; $x < $w; ++$x) { $col = imagecolorat ($im, $x, $y); $result .= substr(pack ('V', $col), 0, 3); } for ($i = 0; $i < $numpad; ++$i) $result .= pack ('C', 0); } if($filename==""){ echo $result; } else { $file = fopen($filename, "wb"); fwrite($file, $result); fclose($file); } return true; }
php
function imagebmp(&$im, $filename = "") { if (!$im) return false; $w = imagesx($im); $h = imagesy($im); $result = ''; // if the image is not true color, we convert it first if (!imageistruecolor($im)) { $tmp = imagecreatetruecolor($w, $h); imagecopy($tmp, $im, 0, 0, 0, 0, $w, $h); imagedestroy($im); $im = & $tmp; } $biBPLine = $w * 3; $biStride = ($biBPLine + 3) & ~3; $biSizeImage = $biStride * $h; $bfOffBits = 54; $bfSize = $bfOffBits + $biSizeImage; $result .= substr('BM', 0, 2); $result .= pack ('VvvV', $bfSize, 0, 0, $bfOffBits); $result .= pack ('VVVvvVVVVVV', 40, $w, $h, 1, 24, 0, $biSizeImage, 0, 0, 0, 0); $numpad = $biStride - $biBPLine; for ($y = $h - 1; $y >= 0; --$y) { for ($x = 0; $x < $w; ++$x) { $col = imagecolorat ($im, $x, $y); $result .= substr(pack ('V', $col), 0, 3); } for ($i = 0; $i < $numpad; ++$i) $result .= pack ('C', 0); } if($filename==""){ echo $result; } else { $file = fopen($filename, "wb"); fwrite($file, $result); fclose($file); } return true; }
[ "function", "imagebmp", "(", "&", "$", "im", ",", "$", "filename", "=", "\"\"", ")", "{", "if", "(", "!", "$", "im", ")", "return", "false", ";", "$", "w", "=", "imagesx", "(", "$", "im", ")", ";", "$", "h", "=", "imagesy", "(", "$", "im", ")", ";", "$", "result", "=", "''", ";", "// if the image is not true color, we convert it first", "if", "(", "!", "imageistruecolor", "(", "$", "im", ")", ")", "{", "$", "tmp", "=", "imagecreatetruecolor", "(", "$", "w", ",", "$", "h", ")", ";", "imagecopy", "(", "$", "tmp", ",", "$", "im", ",", "0", ",", "0", ",", "0", ",", "0", ",", "$", "w", ",", "$", "h", ")", ";", "imagedestroy", "(", "$", "im", ")", ";", "$", "im", "=", "&", "$", "tmp", ";", "}", "$", "biBPLine", "=", "$", "w", "*", "3", ";", "$", "biStride", "=", "(", "$", "biBPLine", "+", "3", ")", "&", "~", "3", ";", "$", "biSizeImage", "=", "$", "biStride", "*", "$", "h", ";", "$", "bfOffBits", "=", "54", ";", "$", "bfSize", "=", "$", "bfOffBits", "+", "$", "biSizeImage", ";", "$", "result", ".=", "substr", "(", "'BM'", ",", "0", ",", "2", ")", ";", "$", "result", ".=", "pack", "(", "'VvvV'", ",", "$", "bfSize", ",", "0", ",", "0", ",", "$", "bfOffBits", ")", ";", "$", "result", ".=", "pack", "(", "'VVVvvVVVVVV'", ",", "40", ",", "$", "w", ",", "$", "h", ",", "1", ",", "24", ",", "0", ",", "$", "biSizeImage", ",", "0", ",", "0", ",", "0", ",", "0", ")", ";", "$", "numpad", "=", "$", "biStride", "-", "$", "biBPLine", ";", "for", "(", "$", "y", "=", "$", "h", "-", "1", ";", "$", "y", ">=", "0", ";", "--", "$", "y", ")", "{", "for", "(", "$", "x", "=", "0", ";", "$", "x", "<", "$", "w", ";", "++", "$", "x", ")", "{", "$", "col", "=", "imagecolorat", "(", "$", "im", ",", "$", "x", ",", "$", "y", ")", ";", "$", "result", ".=", "substr", "(", "pack", "(", "'V'", ",", "$", "col", ")", ",", "0", ",", "3", ")", ";", "}", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "numpad", ";", "++", "$", "i", ")", "$", "result", ".=", "pack", "(", "'C'", ",", "0", ")", ";", "}", "if", "(", "$", "filename", "==", "\"\"", ")", "{", "echo", "$", "result", ";", "}", "else", "{", "$", "file", "=", "fopen", "(", "$", "filename", ",", "\"wb\"", ")", ";", "fwrite", "(", "$", "file", ",", "$", "result", ")", ";", "fclose", "(", "$", "file", ")", ";", "}", "return", "true", ";", "}" ]
Saves a BMP image This function has been published on the PHP website, and can be used freely @access public
[ "Saves", "a", "BMP", "image" ]
28de54ee2ba5a30609eae26d76a15979a94568f1
https://github.com/verot/class.upload.php/blob/28de54ee2ba5a30609eae26d76a15979a94568f1/src/class.upload.php#L5016-L5059
train
atk4/ui
src/Table.php
Table.initChunks
public function initChunks() { if (!$this->t_head) { $this->t_head = $this->template->cloneRegion('Head'); $this->t_row_master = $this->template->cloneRegion('Row'); $this->t_totals = $this->template->cloneRegion('Totals'); $this->t_empty = $this->template->cloneRegion('Empty'); $this->template->del('Head'); $this->template->del('Body'); $this->template->del('Foot'); } }
php
public function initChunks() { if (!$this->t_head) { $this->t_head = $this->template->cloneRegion('Head'); $this->t_row_master = $this->template->cloneRegion('Row'); $this->t_totals = $this->template->cloneRegion('Totals'); $this->t_empty = $this->template->cloneRegion('Empty'); $this->template->del('Head'); $this->template->del('Body'); $this->template->del('Foot'); } }
[ "public", "function", "initChunks", "(", ")", "{", "if", "(", "!", "$", "this", "->", "t_head", ")", "{", "$", "this", "->", "t_head", "=", "$", "this", "->", "template", "->", "cloneRegion", "(", "'Head'", ")", ";", "$", "this", "->", "t_row_master", "=", "$", "this", "->", "template", "->", "cloneRegion", "(", "'Row'", ")", ";", "$", "this", "->", "t_totals", "=", "$", "this", "->", "template", "->", "cloneRegion", "(", "'Totals'", ")", ";", "$", "this", "->", "t_empty", "=", "$", "this", "->", "template", "->", "cloneRegion", "(", "'Empty'", ")", ";", "$", "this", "->", "template", "->", "del", "(", "'Head'", ")", ";", "$", "this", "->", "template", "->", "del", "(", "'Body'", ")", ";", "$", "this", "->", "template", "->", "del", "(", "'Foot'", ")", ";", "}", "}" ]
initChunks method will create one column object that will be used to render all columns in the table unless you have specified a different column object.
[ "initChunks", "method", "will", "create", "one", "column", "object", "that", "will", "be", "used", "to", "render", "all", "columns", "in", "the", "table", "unless", "you", "have", "specified", "a", "different", "column", "object", "." ]
f31c6674ff80999e29dd95375d4f3588bfdbad00
https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/Table.php#L148-L160
train
atk4/ui
src/Table.php
Table.setFilterColumn
public function setFilterColumn($cols = null) { if (!$this->model) { throw new Exception('Model need to be defined in order to use column filtering.'); } // set filter to all column when null. if (!$cols) { foreach ($this->model->elements as $key => $field) { if (isset($this->columns[$key]) && $this->columns[$key]) { $cols[] = $field->short_name; } } } // create column popup. foreach ($cols as $colName) { $col = $this->columns[$colName]; if ($col) { $pop = $col->addPopup(new FilterPopup(['field' => $this->model->getElement($colName), 'reload' => $this->reload, 'colTrigger' => '#'.$col->name.'_ac'])); $pop->isFilterOn() ? $col->setHeaderPopupIcon('green caret square down') : null; $pop->form->onSubmit(function ($f) use ($pop) { return new jsReload($this->reload); }); //apply condition according to popup form. $this->model = $pop->setFilterCondition($this->model); } } }
php
public function setFilterColumn($cols = null) { if (!$this->model) { throw new Exception('Model need to be defined in order to use column filtering.'); } // set filter to all column when null. if (!$cols) { foreach ($this->model->elements as $key => $field) { if (isset($this->columns[$key]) && $this->columns[$key]) { $cols[] = $field->short_name; } } } // create column popup. foreach ($cols as $colName) { $col = $this->columns[$colName]; if ($col) { $pop = $col->addPopup(new FilterPopup(['field' => $this->model->getElement($colName), 'reload' => $this->reload, 'colTrigger' => '#'.$col->name.'_ac'])); $pop->isFilterOn() ? $col->setHeaderPopupIcon('green caret square down') : null; $pop->form->onSubmit(function ($f) use ($pop) { return new jsReload($this->reload); }); //apply condition according to popup form. $this->model = $pop->setFilterCondition($this->model); } } }
[ "public", "function", "setFilterColumn", "(", "$", "cols", "=", "null", ")", "{", "if", "(", "!", "$", "this", "->", "model", ")", "{", "throw", "new", "Exception", "(", "'Model need to be defined in order to use column filtering.'", ")", ";", "}", "// set filter to all column when null.", "if", "(", "!", "$", "cols", ")", "{", "foreach", "(", "$", "this", "->", "model", "->", "elements", "as", "$", "key", "=>", "$", "field", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "columns", "[", "$", "key", "]", ")", "&&", "$", "this", "->", "columns", "[", "$", "key", "]", ")", "{", "$", "cols", "[", "]", "=", "$", "field", "->", "short_name", ";", "}", "}", "}", "// create column popup.", "foreach", "(", "$", "cols", "as", "$", "colName", ")", "{", "$", "col", "=", "$", "this", "->", "columns", "[", "$", "colName", "]", ";", "if", "(", "$", "col", ")", "{", "$", "pop", "=", "$", "col", "->", "addPopup", "(", "new", "FilterPopup", "(", "[", "'field'", "=>", "$", "this", "->", "model", "->", "getElement", "(", "$", "colName", ")", ",", "'reload'", "=>", "$", "this", "->", "reload", ",", "'colTrigger'", "=>", "'#'", ".", "$", "col", "->", "name", ".", "'_ac'", "]", ")", ")", ";", "$", "pop", "->", "isFilterOn", "(", ")", "?", "$", "col", "->", "setHeaderPopupIcon", "(", "'green caret square down'", ")", ":", "null", ";", "$", "pop", "->", "form", "->", "onSubmit", "(", "function", "(", "$", "f", ")", "use", "(", "$", "pop", ")", "{", "return", "new", "jsReload", "(", "$", "this", "->", "reload", ")", ";", "}", ")", ";", "//apply condition according to popup form.", "$", "this", "->", "model", "=", "$", "pop", "->", "setFilterCondition", "(", "$", "this", "->", "model", ")", ";", "}", "}", "}" ]
Set Popup action for columns filtering. @param array $cols An array with colomns name that need filtering. @throws Exception @throws \atk4\core\Exception
[ "Set", "Popup", "action", "for", "columns", "filtering", "." ]
f31c6674ff80999e29dd95375d4f3588bfdbad00
https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/Table.php#L264-L292
train
atk4/ui
src/Table.php
Table.addDecorator
public function addDecorator($name, $seed) { if (!$this->columns[$name]) { throw new Exception(['No such column, cannot decorate', 'name' => $name]); } $decorator = $this->_add($this->factory($seed, ['table' => $this], 'TableColumn')); if (!is_array($this->columns[$name])) { $this->columns[$name] = [$this->columns[$name]]; } $this->columns[$name][] = $decorator; return $decorator; }
php
public function addDecorator($name, $seed) { if (!$this->columns[$name]) { throw new Exception(['No such column, cannot decorate', 'name' => $name]); } $decorator = $this->_add($this->factory($seed, ['table' => $this], 'TableColumn')); if (!is_array($this->columns[$name])) { $this->columns[$name] = [$this->columns[$name]]; } $this->columns[$name][] = $decorator; return $decorator; }
[ "public", "function", "addDecorator", "(", "$", "name", ",", "$", "seed", ")", "{", "if", "(", "!", "$", "this", "->", "columns", "[", "$", "name", "]", ")", "{", "throw", "new", "Exception", "(", "[", "'No such column, cannot decorate'", ",", "'name'", "=>", "$", "name", "]", ")", ";", "}", "$", "decorator", "=", "$", "this", "->", "_add", "(", "$", "this", "->", "factory", "(", "$", "seed", ",", "[", "'table'", "=>", "$", "this", "]", ",", "'TableColumn'", ")", ")", ";", "if", "(", "!", "is_array", "(", "$", "this", "->", "columns", "[", "$", "name", "]", ")", ")", "{", "$", "this", "->", "columns", "[", "$", "name", "]", "=", "[", "$", "this", "->", "columns", "[", "$", "name", "]", "]", ";", "}", "$", "this", "->", "columns", "[", "$", "name", "]", "[", "]", "=", "$", "decorator", ";", "return", "$", "decorator", ";", "}" ]
Add column Decorator. @param string $name Column name @param mixed $seed Defaults to pass to factory() when decorator is initialized @return TableColumn\Generic
[ "Add", "column", "Decorator", "." ]
f31c6674ff80999e29dd95375d4f3588bfdbad00
https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/Table.php#L302-L315
train
atk4/ui
src/Table.php
Table.getColumnDecorators
public function getColumnDecorators($name) { $dec = $this->columns[$name]; return is_array($dec) ? $dec : [$dec]; }
php
public function getColumnDecorators($name) { $dec = $this->columns[$name]; return is_array($dec) ? $dec : [$dec]; }
[ "public", "function", "getColumnDecorators", "(", "$", "name", ")", "{", "$", "dec", "=", "$", "this", "->", "columns", "[", "$", "name", "]", ";", "return", "is_array", "(", "$", "dec", ")", "?", "$", "dec", ":", "[", "$", "dec", "]", ";", "}" ]
Return array of column decorators for particular column. @param string $name Column name @return array
[ "Return", "array", "of", "column", "decorators", "for", "particular", "column", "." ]
f31c6674ff80999e29dd95375d4f3588bfdbad00
https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/Table.php#L324-L329
train
atk4/ui
src/Table.php
Table.decoratorFactory
public function decoratorFactory(\atk4\data\Field $f, $seed = []) { $seed = $this->mergeSeeds( $seed, isset($f->ui['table']) ? $f->ui['table'] : null, isset($this->typeToDecorator[$f->type]) ? $this->typeToDecorator[$f->type] : null, [$this->default_column ? $this->default_column : 'Generic'] ); return $this->_add($this->factory($seed, ['table' => $this], 'TableColumn')); }
php
public function decoratorFactory(\atk4\data\Field $f, $seed = []) { $seed = $this->mergeSeeds( $seed, isset($f->ui['table']) ? $f->ui['table'] : null, isset($this->typeToDecorator[$f->type]) ? $this->typeToDecorator[$f->type] : null, [$this->default_column ? $this->default_column : 'Generic'] ); return $this->_add($this->factory($seed, ['table' => $this], 'TableColumn')); }
[ "public", "function", "decoratorFactory", "(", "\\", "atk4", "\\", "data", "\\", "Field", "$", "f", ",", "$", "seed", "=", "[", "]", ")", "{", "$", "seed", "=", "$", "this", "->", "mergeSeeds", "(", "$", "seed", ",", "isset", "(", "$", "f", "->", "ui", "[", "'table'", "]", ")", "?", "$", "f", "->", "ui", "[", "'table'", "]", ":", "null", ",", "isset", "(", "$", "this", "->", "typeToDecorator", "[", "$", "f", "->", "type", "]", ")", "?", "$", "this", "->", "typeToDecorator", "[", "$", "f", "->", "type", "]", ":", "null", ",", "[", "$", "this", "->", "default_column", "?", "$", "this", "->", "default_column", ":", "'Generic'", "]", ")", ";", "return", "$", "this", "->", "_add", "(", "$", "this", "->", "factory", "(", "$", "seed", ",", "[", "'table'", "=>", "$", "this", "]", ",", "'TableColumn'", ")", ")", ";", "}" ]
Will come up with a column object based on the field object supplied. By default will use default column. @param \atk4\data\Field $f Data model field @param mixed $seed Defaults to pass to factory() when decorator is initialized @return TableColumn\Generic
[ "Will", "come", "up", "with", "a", "column", "object", "based", "on", "the", "field", "object", "supplied", ".", "By", "default", "will", "use", "default", "column", "." ]
f31c6674ff80999e29dd95375d4f3588bfdbad00
https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/Table.php#L340-L350
train
atk4/ui
src/Table.php
Table.resizableColumn
public function resizableColumn($fx = null, $widths = null, $resizerOptions = null) { $options = []; if ($fx && is_callable($fx)) { $cb = $this->add('jsCallBack'); $cb->set($fx, ['widths'=>'widths']); $options['uri'] = $cb->getJSURL(); } elseif ($fx && is_array($fx)) { $widths = $fx; } if ($widths) { $options['widths'] = $widths; } if ($resizerOptions) { $options = array_merge($options, $resizerOptions); } $this->js(true, $this->js()->atkColumnResizer($options)); return $this; }
php
public function resizableColumn($fx = null, $widths = null, $resizerOptions = null) { $options = []; if ($fx && is_callable($fx)) { $cb = $this->add('jsCallBack'); $cb->set($fx, ['widths'=>'widths']); $options['uri'] = $cb->getJSURL(); } elseif ($fx && is_array($fx)) { $widths = $fx; } if ($widths) { $options['widths'] = $widths; } if ($resizerOptions) { $options = array_merge($options, $resizerOptions); } $this->js(true, $this->js()->atkColumnResizer($options)); return $this; }
[ "public", "function", "resizableColumn", "(", "$", "fx", "=", "null", ",", "$", "widths", "=", "null", ",", "$", "resizerOptions", "=", "null", ")", "{", "$", "options", "=", "[", "]", ";", "if", "(", "$", "fx", "&&", "is_callable", "(", "$", "fx", ")", ")", "{", "$", "cb", "=", "$", "this", "->", "add", "(", "'jsCallBack'", ")", ";", "$", "cb", "->", "set", "(", "$", "fx", ",", "[", "'widths'", "=>", "'widths'", "]", ")", ";", "$", "options", "[", "'uri'", "]", "=", "$", "cb", "->", "getJSURL", "(", ")", ";", "}", "elseif", "(", "$", "fx", "&&", "is_array", "(", "$", "fx", ")", ")", "{", "$", "widths", "=", "$", "fx", ";", "}", "if", "(", "$", "widths", ")", "{", "$", "options", "[", "'widths'", "]", "=", "$", "widths", ";", "}", "if", "(", "$", "resizerOptions", ")", "{", "$", "options", "=", "array_merge", "(", "$", "options", ",", "$", "resizerOptions", ")", ";", "}", "$", "this", "->", "js", "(", "true", ",", "$", "this", "->", "js", "(", ")", "->", "atkColumnResizer", "(", "$", "options", ")", ")", ";", "return", "$", "this", ";", "}" ]
Make columns resizable by dragging column header. The callback param function will receive two parameter, a jQuery chain object and a json string containing all table columns name and size. To retrieve columns width, simply json decode the $widths param in your callback function. ex: $table->resizableColumn(function($j, $w){ //do somethings with columns width $columns = json_decode($w); }); @param null $fx A callback function with columns widths as parameter. @param null $widths An array of widths value, integer only. ex: [100,200,300,100] @param null $resizerOptions An array of column-resizer module options. see https://www.npmjs.com/package/column-resizer @throws Exception @return $this
[ "Make", "columns", "resizable", "by", "dragging", "column", "header", "." ]
f31c6674ff80999e29dd95375d4f3588bfdbad00
https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/Table.php#L379-L401
train
atk4/ui
src/Table.php
Table.addJsPaginator
public function addJsPaginator($ipp, $options = [], $container = null, $scrollRegion = 'Body') { $options = array_merge($options, ['appendTo' => 'tbody']); return parent::addJsPaginator($ipp, $options, $container, $scrollRegion); }
php
public function addJsPaginator($ipp, $options = [], $container = null, $scrollRegion = 'Body') { $options = array_merge($options, ['appendTo' => 'tbody']); return parent::addJsPaginator($ipp, $options, $container, $scrollRegion); }
[ "public", "function", "addJsPaginator", "(", "$", "ipp", ",", "$", "options", "=", "[", "]", ",", "$", "container", "=", "null", ",", "$", "scrollRegion", "=", "'Body'", ")", "{", "$", "options", "=", "array_merge", "(", "$", "options", ",", "[", "'appendTo'", "=>", "'tbody'", "]", ")", ";", "return", "parent", "::", "addJsPaginator", "(", "$", "ipp", ",", "$", "options", ",", "$", "container", ",", "$", "scrollRegion", ")", ";", "}" ]
Add a dynamic paginator, i.e. when user is scrolling content. @param int $ipp Number of item per page to start with. @param array $options An array with js Scroll plugin options. @param View $container The container holding the lister for scrolling purpose. Default to view owner. @param string $scrollRegion A specific template region to render. Render output is append to container html element. @throws Exception @return $this|void
[ "Add", "a", "dynamic", "paginator", "i", ".", "e", ".", "when", "user", "is", "scrolling", "content", "." ]
f31c6674ff80999e29dd95375d4f3588bfdbad00
https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/Table.php#L415-L420
train
atk4/ui
src/Table.php
Table.setModel
public function setModel(\atk4\data\Model $m, $columns = null) { parent::setModel($m); if ($columns === null) { $columns = []; foreach ($m->elements as $name => $element) { if (!$element instanceof \atk4\data\Field) { continue; } if ($element->isVisible()) { $columns[] = $name; } } } elseif ($columns === false) { return $this->model; } foreach ($columns as $column) { $this->addColumn($column); } return $this->model; }
php
public function setModel(\atk4\data\Model $m, $columns = null) { parent::setModel($m); if ($columns === null) { $columns = []; foreach ($m->elements as $name => $element) { if (!$element instanceof \atk4\data\Field) { continue; } if ($element->isVisible()) { $columns[] = $name; } } } elseif ($columns === false) { return $this->model; } foreach ($columns as $column) { $this->addColumn($column); } return $this->model; }
[ "public", "function", "setModel", "(", "\\", "atk4", "\\", "data", "\\", "Model", "$", "m", ",", "$", "columns", "=", "null", ")", "{", "parent", "::", "setModel", "(", "$", "m", ")", ";", "if", "(", "$", "columns", "===", "null", ")", "{", "$", "columns", "=", "[", "]", ";", "foreach", "(", "$", "m", "->", "elements", "as", "$", "name", "=>", "$", "element", ")", "{", "if", "(", "!", "$", "element", "instanceof", "\\", "atk4", "\\", "data", "\\", "Field", ")", "{", "continue", ";", "}", "if", "(", "$", "element", "->", "isVisible", "(", ")", ")", "{", "$", "columns", "[", "]", "=", "$", "name", ";", "}", "}", "}", "elseif", "(", "$", "columns", "===", "false", ")", "{", "return", "$", "this", "->", "model", ";", "}", "foreach", "(", "$", "columns", "as", "$", "column", ")", "{", "$", "this", "->", "addColumn", "(", "$", "column", ")", ";", "}", "return", "$", "this", "->", "model", ";", "}" ]
Sets data Model of Table. If $columns is not defined, then automatically will add columns for all visible model fields. If $columns is set to false, then will not add columns at all. @param \atk4\data\Model $m Data model @param array|bool $columns @return \atk4\data\Model
[ "Sets", "data", "Model", "of", "Table", "." ]
f31c6674ff80999e29dd95375d4f3588bfdbad00
https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/Table.php#L449-L473
train
atk4/ui
src/Table.php
Table.updateTotals
public function updateTotals() { foreach ($this->totals_plan as $key => $val) { // if value is array, then we treat it as built-in or callable aggregate method if (is_array($val)) { $f = $val[0]; // shortcut // initial value is always 0 if (!isset($this->totals[$key])) { $this->totals[$key] = 0; } // closure support // arguments - current value, key, \atk4\ui\Table object if ($f instanceof \Closure) { $this->totals[$key] += ($f($this->model[$key], $key, $this) ?: 0); } // built-in methods elseif (is_string($f)) { switch ($f) { case 'sum': $this->totals[$key] += $this->model[$key]; break; case 'count': $this->totals[$key] += 1; break; case 'min': if ($this->model[$key] < $this->totals[$key]) { $this->totals[$key] = $this->model[$key]; } break; case 'max': if ($this->model[$key] > $this->totals[$key]) { $this->totals[$key] = $this->model[$key]; } break; default: throw new Exception(['Aggregation method does not exist', 'method' => $f]); } } } } }
php
public function updateTotals() { foreach ($this->totals_plan as $key => $val) { // if value is array, then we treat it as built-in or callable aggregate method if (is_array($val)) { $f = $val[0]; // shortcut // initial value is always 0 if (!isset($this->totals[$key])) { $this->totals[$key] = 0; } // closure support // arguments - current value, key, \atk4\ui\Table object if ($f instanceof \Closure) { $this->totals[$key] += ($f($this->model[$key], $key, $this) ?: 0); } // built-in methods elseif (is_string($f)) { switch ($f) { case 'sum': $this->totals[$key] += $this->model[$key]; break; case 'count': $this->totals[$key] += 1; break; case 'min': if ($this->model[$key] < $this->totals[$key]) { $this->totals[$key] = $this->model[$key]; } break; case 'max': if ($this->model[$key] > $this->totals[$key]) { $this->totals[$key] = $this->model[$key]; } break; default: throw new Exception(['Aggregation method does not exist', 'method' => $f]); } } } } }
[ "public", "function", "updateTotals", "(", ")", "{", "foreach", "(", "$", "this", "->", "totals_plan", "as", "$", "key", "=>", "$", "val", ")", "{", "// if value is array, then we treat it as built-in or callable aggregate method", "if", "(", "is_array", "(", "$", "val", ")", ")", "{", "$", "f", "=", "$", "val", "[", "0", "]", ";", "// shortcut", "// initial value is always 0", "if", "(", "!", "isset", "(", "$", "this", "->", "totals", "[", "$", "key", "]", ")", ")", "{", "$", "this", "->", "totals", "[", "$", "key", "]", "=", "0", ";", "}", "// closure support", "// arguments - current value, key, \\atk4\\ui\\Table object", "if", "(", "$", "f", "instanceof", "\\", "Closure", ")", "{", "$", "this", "->", "totals", "[", "$", "key", "]", "+=", "(", "$", "f", "(", "$", "this", "->", "model", "[", "$", "key", "]", ",", "$", "key", ",", "$", "this", ")", "?", ":", "0", ")", ";", "}", "// built-in methods", "elseif", "(", "is_string", "(", "$", "f", ")", ")", "{", "switch", "(", "$", "f", ")", "{", "case", "'sum'", ":", "$", "this", "->", "totals", "[", "$", "key", "]", "+=", "$", "this", "->", "model", "[", "$", "key", "]", ";", "break", ";", "case", "'count'", ":", "$", "this", "->", "totals", "[", "$", "key", "]", "+=", "1", ";", "break", ";", "case", "'min'", ":", "if", "(", "$", "this", "->", "model", "[", "$", "key", "]", "<", "$", "this", "->", "totals", "[", "$", "key", "]", ")", "{", "$", "this", "->", "totals", "[", "$", "key", "]", "=", "$", "this", "->", "model", "[", "$", "key", "]", ";", "}", "break", ";", "case", "'max'", ":", "if", "(", "$", "this", "->", "model", "[", "$", "key", "]", ">", "$", "this", "->", "totals", "[", "$", "key", "]", ")", "{", "$", "this", "->", "totals", "[", "$", "key", "]", "=", "$", "this", "->", "model", "[", "$", "key", "]", ";", "}", "break", ";", "default", ":", "throw", "new", "Exception", "(", "[", "'Aggregation method does not exist'", ",", "'method'", "=>", "$", "f", "]", ")", ";", "}", "}", "}", "}", "}" ]
Executed for each row if "totals" are enabled to add up values.
[ "Executed", "for", "each", "row", "if", "totals", "are", "enabled", "to", "add", "up", "values", "." ]
f31c6674ff80999e29dd95375d4f3588bfdbad00
https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/Table.php#L613-L656
train
atk4/ui
src/Table.php
Table.getHeaderRowHTML
public function getHeaderRowHTML() { $output = []; foreach ($this->columns as $name => $column) { // If multiple formatters are defined, use the first for the header cell if (is_array($column)) { $column = $column[0]; } if (!is_int($name)) { $field = $this->model->getElement($name); $output[] = $column->getHeaderCellHTML($field); } else { $output[] = $column->getHeaderCellHTML(); } } return implode('', $output); }
php
public function getHeaderRowHTML() { $output = []; foreach ($this->columns as $name => $column) { // If multiple formatters are defined, use the first for the header cell if (is_array($column)) { $column = $column[0]; } if (!is_int($name)) { $field = $this->model->getElement($name); $output[] = $column->getHeaderCellHTML($field); } else { $output[] = $column->getHeaderCellHTML(); } } return implode('', $output); }
[ "public", "function", "getHeaderRowHTML", "(", ")", "{", "$", "output", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "columns", "as", "$", "name", "=>", "$", "column", ")", "{", "// If multiple formatters are defined, use the first for the header cell", "if", "(", "is_array", "(", "$", "column", ")", ")", "{", "$", "column", "=", "$", "column", "[", "0", "]", ";", "}", "if", "(", "!", "is_int", "(", "$", "name", ")", ")", "{", "$", "field", "=", "$", "this", "->", "model", "->", "getElement", "(", "$", "name", ")", ";", "$", "output", "[", "]", "=", "$", "column", "->", "getHeaderCellHTML", "(", "$", "field", ")", ";", "}", "else", "{", "$", "output", "[", "]", "=", "$", "column", "->", "getHeaderCellHTML", "(", ")", ";", "}", "}", "return", "implode", "(", "''", ",", "$", "output", ")", ";", "}" ]
Responds with the HTML to be inserted in the header row that would contain captions of all columns. @return string
[ "Responds", "with", "the", "HTML", "to", "be", "inserted", "in", "the", "header", "row", "that", "would", "contain", "captions", "of", "all", "columns", "." ]
f31c6674ff80999e29dd95375d4f3588bfdbad00
https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/Table.php#L664-L684
train
atk4/ui
src/Table.php
Table.getTotalsRowHTML
public function getTotalsRowHTML() { $output = []; foreach ($this->columns as $name => $column) { // if no totals plan, then show dash, but keep column formatting if (!isset($this->totals_plan[$name])) { $output[] = $column->getTag('foot', '-'); continue; } // if totals plan is set as array, then show formatted value if (is_array($this->totals_plan[$name])) { // todo - format $field = $this->model->getElement($name); $output[] = $column->getTotalsCellHTML($field, $this->totals[$name]); continue; } // otherwise just show it, for example, "Totals:" cell $output[] = $column->getTag('foot', $this->totals_plan[$name]); } return implode('', $output); }
php
public function getTotalsRowHTML() { $output = []; foreach ($this->columns as $name => $column) { // if no totals plan, then show dash, but keep column formatting if (!isset($this->totals_plan[$name])) { $output[] = $column->getTag('foot', '-'); continue; } // if totals plan is set as array, then show formatted value if (is_array($this->totals_plan[$name])) { // todo - format $field = $this->model->getElement($name); $output[] = $column->getTotalsCellHTML($field, $this->totals[$name]); continue; } // otherwise just show it, for example, "Totals:" cell $output[] = $column->getTag('foot', $this->totals_plan[$name]); } return implode('', $output); }
[ "public", "function", "getTotalsRowHTML", "(", ")", "{", "$", "output", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "columns", "as", "$", "name", "=>", "$", "column", ")", "{", "// if no totals plan, then show dash, but keep column formatting", "if", "(", "!", "isset", "(", "$", "this", "->", "totals_plan", "[", "$", "name", "]", ")", ")", "{", "$", "output", "[", "]", "=", "$", "column", "->", "getTag", "(", "'foot'", ",", "'-'", ")", ";", "continue", ";", "}", "// if totals plan is set as array, then show formatted value", "if", "(", "is_array", "(", "$", "this", "->", "totals_plan", "[", "$", "name", "]", ")", ")", "{", "// todo - format", "$", "field", "=", "$", "this", "->", "model", "->", "getElement", "(", "$", "name", ")", ";", "$", "output", "[", "]", "=", "$", "column", "->", "getTotalsCellHTML", "(", "$", "field", ",", "$", "this", "->", "totals", "[", "$", "name", "]", ")", ";", "continue", ";", "}", "// otherwise just show it, for example, \"Totals:\" cell", "$", "output", "[", "]", "=", "$", "column", "->", "getTag", "(", "'foot'", ",", "$", "this", "->", "totals_plan", "[", "$", "name", "]", ")", ";", "}", "return", "implode", "(", "''", ",", "$", "output", ")", ";", "}" ]
Responds with HTML to be inserted in the footer row that would contain totals for all columns. @return string
[ "Responds", "with", "HTML", "to", "be", "inserted", "in", "the", "footer", "row", "that", "would", "contain", "totals", "for", "all", "columns", "." ]
f31c6674ff80999e29dd95375d4f3588bfdbad00
https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/Table.php#L692-L715
train
atk4/ui
src/Table.php
Table.getDataRowHTML
public function getDataRowHTML() { $output = []; foreach ($this->columns as $name => $column) { // If multiple formatters are defined, use the first for the header cell if (!is_int($name)) { $field = $this->model->getElement($name); } else { $field = null; } if (!is_array($column)) { $column = [$column]; } // we need to smartly wrap things up $cell = null; $cnt = count($column); $td_attr = []; foreach ($column as $c) { if (--$cnt) { $html = $c->getDataCellTemplate($field); $td_attr = $c->getTagAttributes('body', $td_attr); } else { // Last formatter, ask it to give us whole rendering $html = $c->getDataCellHTML($field, $td_attr); } if ($cell) { if ($name) { // if name is set, we can wrap things $cell = str_replace('{$'.$name.'}', $cell, $html); } else { $cell = $cell.' '.$html; } } else { $cell = $html; } } $output[] = $cell; } return implode('', $output); }
php
public function getDataRowHTML() { $output = []; foreach ($this->columns as $name => $column) { // If multiple formatters are defined, use the first for the header cell if (!is_int($name)) { $field = $this->model->getElement($name); } else { $field = null; } if (!is_array($column)) { $column = [$column]; } // we need to smartly wrap things up $cell = null; $cnt = count($column); $td_attr = []; foreach ($column as $c) { if (--$cnt) { $html = $c->getDataCellTemplate($field); $td_attr = $c->getTagAttributes('body', $td_attr); } else { // Last formatter, ask it to give us whole rendering $html = $c->getDataCellHTML($field, $td_attr); } if ($cell) { if ($name) { // if name is set, we can wrap things $cell = str_replace('{$'.$name.'}', $cell, $html); } else { $cell = $cell.' '.$html; } } else { $cell = $html; } } $output[] = $cell; } return implode('', $output); }
[ "public", "function", "getDataRowHTML", "(", ")", "{", "$", "output", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "columns", "as", "$", "name", "=>", "$", "column", ")", "{", "// If multiple formatters are defined, use the first for the header cell", "if", "(", "!", "is_int", "(", "$", "name", ")", ")", "{", "$", "field", "=", "$", "this", "->", "model", "->", "getElement", "(", "$", "name", ")", ";", "}", "else", "{", "$", "field", "=", "null", ";", "}", "if", "(", "!", "is_array", "(", "$", "column", ")", ")", "{", "$", "column", "=", "[", "$", "column", "]", ";", "}", "// we need to smartly wrap things up", "$", "cell", "=", "null", ";", "$", "cnt", "=", "count", "(", "$", "column", ")", ";", "$", "td_attr", "=", "[", "]", ";", "foreach", "(", "$", "column", "as", "$", "c", ")", "{", "if", "(", "--", "$", "cnt", ")", "{", "$", "html", "=", "$", "c", "->", "getDataCellTemplate", "(", "$", "field", ")", ";", "$", "td_attr", "=", "$", "c", "->", "getTagAttributes", "(", "'body'", ",", "$", "td_attr", ")", ";", "}", "else", "{", "// Last formatter, ask it to give us whole rendering", "$", "html", "=", "$", "c", "->", "getDataCellHTML", "(", "$", "field", ",", "$", "td_attr", ")", ";", "}", "if", "(", "$", "cell", ")", "{", "if", "(", "$", "name", ")", "{", "// if name is set, we can wrap things", "$", "cell", "=", "str_replace", "(", "'{$'", ".", "$", "name", ".", "'}'", ",", "$", "cell", ",", "$", "html", ")", ";", "}", "else", "{", "$", "cell", "=", "$", "cell", ".", "' '", ".", "$", "html", ";", "}", "}", "else", "{", "$", "cell", "=", "$", "html", ";", "}", "}", "$", "output", "[", "]", "=", "$", "cell", ";", "}", "return", "implode", "(", "''", ",", "$", "output", ")", ";", "}" ]
Collects cell templates from all the columns and combine them into row template. @return string
[ "Collects", "cell", "templates", "from", "all", "the", "columns", "and", "combine", "them", "into", "row", "template", "." ]
f31c6674ff80999e29dd95375d4f3588bfdbad00
https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/Table.php#L722-L768
train
atk4/ui
src/Persistence/UI.php
UI._typecastSaveField
public function _typecastSaveField(\atk4\data\Field $f, $value) { // serialize if we explicitly want that if ($f->serialize) { $value = $this->serializeSaveField($f, $value); } // work only on copied value not real one !!! $v = is_object($value) ? clone $value : $value; switch ($f->type) { case 'boolean': return $v ? $this->yes : $this->no; case 'money': return ($this->currency ? $this->currency.' ' : '').number_format($v, 2); case 'date': case 'datetime': case 'time': $dt_class = isset($f->dateTimeClass) ? $f->dateTimeClass : 'DateTime'; $tz_class = isset($f->dateTimeZoneClass) ? $f->dateTimeZoneClass : 'DateTimeZone'; if ($v instanceof $dt_class) { $format = ['date' => $this->date_format, 'datetime' => $this->datetime_format, 'time' => $this->time_format]; $format = $f->persist_format ?: $format[$f->type]; // datetime only - set to persisting timezone if ($f->type == 'datetime' && isset($f->persist_timezone)) { $v->setTimezone(new $tz_class($f->persist_timezone)); } $v = $v->format($format); } break; case 'array': case 'object': // don't encode if we already use some kind of serialization $v = $f->serialize ? $v : json_encode($v); break; } return $v; }
php
public function _typecastSaveField(\atk4\data\Field $f, $value) { // serialize if we explicitly want that if ($f->serialize) { $value = $this->serializeSaveField($f, $value); } // work only on copied value not real one !!! $v = is_object($value) ? clone $value : $value; switch ($f->type) { case 'boolean': return $v ? $this->yes : $this->no; case 'money': return ($this->currency ? $this->currency.' ' : '').number_format($v, 2); case 'date': case 'datetime': case 'time': $dt_class = isset($f->dateTimeClass) ? $f->dateTimeClass : 'DateTime'; $tz_class = isset($f->dateTimeZoneClass) ? $f->dateTimeZoneClass : 'DateTimeZone'; if ($v instanceof $dt_class) { $format = ['date' => $this->date_format, 'datetime' => $this->datetime_format, 'time' => $this->time_format]; $format = $f->persist_format ?: $format[$f->type]; // datetime only - set to persisting timezone if ($f->type == 'datetime' && isset($f->persist_timezone)) { $v->setTimezone(new $tz_class($f->persist_timezone)); } $v = $v->format($format); } break; case 'array': case 'object': // don't encode if we already use some kind of serialization $v = $f->serialize ? $v : json_encode($v); break; } return $v; }
[ "public", "function", "_typecastSaveField", "(", "\\", "atk4", "\\", "data", "\\", "Field", "$", "f", ",", "$", "value", ")", "{", "// serialize if we explicitly want that", "if", "(", "$", "f", "->", "serialize", ")", "{", "$", "value", "=", "$", "this", "->", "serializeSaveField", "(", "$", "f", ",", "$", "value", ")", ";", "}", "// work only on copied value not real one !!!", "$", "v", "=", "is_object", "(", "$", "value", ")", "?", "clone", "$", "value", ":", "$", "value", ";", "switch", "(", "$", "f", "->", "type", ")", "{", "case", "'boolean'", ":", "return", "$", "v", "?", "$", "this", "->", "yes", ":", "$", "this", "->", "no", ";", "case", "'money'", ":", "return", "(", "$", "this", "->", "currency", "?", "$", "this", "->", "currency", ".", "' '", ":", "''", ")", ".", "number_format", "(", "$", "v", ",", "2", ")", ";", "case", "'date'", ":", "case", "'datetime'", ":", "case", "'time'", ":", "$", "dt_class", "=", "isset", "(", "$", "f", "->", "dateTimeClass", ")", "?", "$", "f", "->", "dateTimeClass", ":", "'DateTime'", ";", "$", "tz_class", "=", "isset", "(", "$", "f", "->", "dateTimeZoneClass", ")", "?", "$", "f", "->", "dateTimeZoneClass", ":", "'DateTimeZone'", ";", "if", "(", "$", "v", "instanceof", "$", "dt_class", ")", "{", "$", "format", "=", "[", "'date'", "=>", "$", "this", "->", "date_format", ",", "'datetime'", "=>", "$", "this", "->", "datetime_format", ",", "'time'", "=>", "$", "this", "->", "time_format", "]", ";", "$", "format", "=", "$", "f", "->", "persist_format", "?", ":", "$", "format", "[", "$", "f", "->", "type", "]", ";", "// datetime only - set to persisting timezone", "if", "(", "$", "f", "->", "type", "==", "'datetime'", "&&", "isset", "(", "$", "f", "->", "persist_timezone", ")", ")", "{", "$", "v", "->", "setTimezone", "(", "new", "$", "tz_class", "(", "$", "f", "->", "persist_timezone", ")", ")", ";", "}", "$", "v", "=", "$", "v", "->", "format", "(", "$", "format", ")", ";", "}", "break", ";", "case", "'array'", ":", "case", "'object'", ":", "// don't encode if we already use some kind of serialization", "$", "v", "=", "$", "f", "->", "serialize", "?", "$", "v", ":", "json_encode", "(", "$", "v", ")", ";", "break", ";", "}", "return", "$", "v", ";", "}" ]
This method contains the logic of casting generic values into user-friendly format.
[ "This", "method", "contains", "the", "logic", "of", "casting", "generic", "values", "into", "user", "-", "friendly", "format", "." ]
f31c6674ff80999e29dd95375d4f3588bfdbad00
https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/Persistence/UI.php#L43-L83
train
atk4/ui
src/Persistence/UI.php
UI._typecastLoadField
public function _typecastLoadField(\atk4\data\Field $f, $value) { // serialize if we explicitly want that if ($f->serialize && $value) { try { $new_value = $this->serializeLoadField($f, $value); } catch (\Exception $e) { throw new Exception([ 'Value must be '.$f->serialize, 'serializator'=> $f->serialize, 'value' => $value, 'field' => $f, ]); } $value = $new_value; } switch ($f->type) { case 'string': case 'text': // Normalize line breaks $value = str_replace(["\r\n", "\r"], "\n", $value); break; case 'boolean': $value = (bool) $value; break; case 'money': return str_replace(',', '', $value); case 'date': case 'datetime': case 'time': $dt_class = isset($f->dateTimeClass) ? $f->dateTimeClass : 'DateTime'; $tz_class = isset($f->dateTimeZoneClass) ? $f->dateTimeZoneClass : 'DateTimeZone'; // ! symbol in date format is essential here to remove time part of DateTime - don't remove, this is not a bug $format = ['date' => '!+'.$this->date_format, 'datetime' => '!+'.$this->datetime_format, 'time' => '!+'.$this->time_format]; $format = $f->persist_format ?: $format[$f->type]; // datetime only - set from persisting timezone if ($f->type == 'datetime' && isset($f->persist_timezone)) { $v = $dt_class::createFromFormat($format, $value, new $tz_class($f->persist_timezone)); if ($v === false) { throw new Exception(['Incorrectly formatted datetime', 'format' => $format, 'value' => $value, 'field' => $f]); } $v->setTimeZone(new $tz_class(date_default_timezone_get())); return $v; } else { $v = $dt_class::createFromFormat($format, $value); if ($v === false) { throw new Exception(['Incorrectly formatted date/time', 'format' => $format, 'value' => $value, 'field' => $f]); } return $v; } break; } if (isset($f->reference)) { if (empty($value)) { $value = null; } } return $value; }
php
public function _typecastLoadField(\atk4\data\Field $f, $value) { // serialize if we explicitly want that if ($f->serialize && $value) { try { $new_value = $this->serializeLoadField($f, $value); } catch (\Exception $e) { throw new Exception([ 'Value must be '.$f->serialize, 'serializator'=> $f->serialize, 'value' => $value, 'field' => $f, ]); } $value = $new_value; } switch ($f->type) { case 'string': case 'text': // Normalize line breaks $value = str_replace(["\r\n", "\r"], "\n", $value); break; case 'boolean': $value = (bool) $value; break; case 'money': return str_replace(',', '', $value); case 'date': case 'datetime': case 'time': $dt_class = isset($f->dateTimeClass) ? $f->dateTimeClass : 'DateTime'; $tz_class = isset($f->dateTimeZoneClass) ? $f->dateTimeZoneClass : 'DateTimeZone'; // ! symbol in date format is essential here to remove time part of DateTime - don't remove, this is not a bug $format = ['date' => '!+'.$this->date_format, 'datetime' => '!+'.$this->datetime_format, 'time' => '!+'.$this->time_format]; $format = $f->persist_format ?: $format[$f->type]; // datetime only - set from persisting timezone if ($f->type == 'datetime' && isset($f->persist_timezone)) { $v = $dt_class::createFromFormat($format, $value, new $tz_class($f->persist_timezone)); if ($v === false) { throw new Exception(['Incorrectly formatted datetime', 'format' => $format, 'value' => $value, 'field' => $f]); } $v->setTimeZone(new $tz_class(date_default_timezone_get())); return $v; } else { $v = $dt_class::createFromFormat($format, $value); if ($v === false) { throw new Exception(['Incorrectly formatted date/time', 'format' => $format, 'value' => $value, 'field' => $f]); } return $v; } break; } if (isset($f->reference)) { if (empty($value)) { $value = null; } } return $value; }
[ "public", "function", "_typecastLoadField", "(", "\\", "atk4", "\\", "data", "\\", "Field", "$", "f", ",", "$", "value", ")", "{", "// serialize if we explicitly want that", "if", "(", "$", "f", "->", "serialize", "&&", "$", "value", ")", "{", "try", "{", "$", "new_value", "=", "$", "this", "->", "serializeLoadField", "(", "$", "f", ",", "$", "value", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "throw", "new", "Exception", "(", "[", "'Value must be '", ".", "$", "f", "->", "serialize", ",", "'serializator'", "=>", "$", "f", "->", "serialize", ",", "'value'", "=>", "$", "value", ",", "'field'", "=>", "$", "f", ",", "]", ")", ";", "}", "$", "value", "=", "$", "new_value", ";", "}", "switch", "(", "$", "f", "->", "type", ")", "{", "case", "'string'", ":", "case", "'text'", ":", "// Normalize line breaks", "$", "value", "=", "str_replace", "(", "[", "\"\\r\\n\"", ",", "\"\\r\"", "]", ",", "\"\\n\"", ",", "$", "value", ")", ";", "break", ";", "case", "'boolean'", ":", "$", "value", "=", "(", "bool", ")", "$", "value", ";", "break", ";", "case", "'money'", ":", "return", "str_replace", "(", "','", ",", "''", ",", "$", "value", ")", ";", "case", "'date'", ":", "case", "'datetime'", ":", "case", "'time'", ":", "$", "dt_class", "=", "isset", "(", "$", "f", "->", "dateTimeClass", ")", "?", "$", "f", "->", "dateTimeClass", ":", "'DateTime'", ";", "$", "tz_class", "=", "isset", "(", "$", "f", "->", "dateTimeZoneClass", ")", "?", "$", "f", "->", "dateTimeZoneClass", ":", "'DateTimeZone'", ";", "// ! symbol in date format is essential here to remove time part of DateTime - don't remove, this is not a bug", "$", "format", "=", "[", "'date'", "=>", "'!+'", ".", "$", "this", "->", "date_format", ",", "'datetime'", "=>", "'!+'", ".", "$", "this", "->", "datetime_format", ",", "'time'", "=>", "'!+'", ".", "$", "this", "->", "time_format", "]", ";", "$", "format", "=", "$", "f", "->", "persist_format", "?", ":", "$", "format", "[", "$", "f", "->", "type", "]", ";", "// datetime only - set from persisting timezone", "if", "(", "$", "f", "->", "type", "==", "'datetime'", "&&", "isset", "(", "$", "f", "->", "persist_timezone", ")", ")", "{", "$", "v", "=", "$", "dt_class", "::", "createFromFormat", "(", "$", "format", ",", "$", "value", ",", "new", "$", "tz_class", "(", "$", "f", "->", "persist_timezone", ")", ")", ";", "if", "(", "$", "v", "===", "false", ")", "{", "throw", "new", "Exception", "(", "[", "'Incorrectly formatted datetime'", ",", "'format'", "=>", "$", "format", ",", "'value'", "=>", "$", "value", ",", "'field'", "=>", "$", "f", "]", ")", ";", "}", "$", "v", "->", "setTimeZone", "(", "new", "$", "tz_class", "(", "date_default_timezone_get", "(", ")", ")", ")", ";", "return", "$", "v", ";", "}", "else", "{", "$", "v", "=", "$", "dt_class", "::", "createFromFormat", "(", "$", "format", ",", "$", "value", ")", ";", "if", "(", "$", "v", "===", "false", ")", "{", "throw", "new", "Exception", "(", "[", "'Incorrectly formatted date/time'", ",", "'format'", "=>", "$", "format", ",", "'value'", "=>", "$", "value", ",", "'field'", "=>", "$", "f", "]", ")", ";", "}", "return", "$", "v", ";", "}", "break", ";", "}", "if", "(", "isset", "(", "$", "f", "->", "reference", ")", ")", "{", "if", "(", "empty", "(", "$", "value", ")", ")", "{", "$", "value", "=", "null", ";", "}", "}", "return", "$", "value", ";", "}" ]
Interpret user-defined input for various types.
[ "Interpret", "user", "-", "defined", "input", "for", "various", "types", "." ]
f31c6674ff80999e29dd95375d4f3588bfdbad00
https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/Persistence/UI.php#L88-L154
train
atk4/ui
src/TableColumn/FilterModel/Generic.php
Generic.factoryType
public static function factoryType($field) { $data = []; $persistence = new Persistence_Array($data); $filterDomain = 'atk4\\ui\\TableColumn\\FilterModel\Type'; // check if field as a type and use string as default if (empty($type = $field->type)) { $type = 'string'; } $class = $filterDomain.ucfirst($type); /* * You can set your own filter model condition by extending * Field class and setting your filter model class. */ if (!empty($field->filterModel) && isset($field->filterModel)) { if ($field->filterModel instanceof Model) { return $field->filterModel; } $class = $field->filterModel; } return new $class($persistence, ['lookupField' => $field]); }
php
public static function factoryType($field) { $data = []; $persistence = new Persistence_Array($data); $filterDomain = 'atk4\\ui\\TableColumn\\FilterModel\Type'; // check if field as a type and use string as default if (empty($type = $field->type)) { $type = 'string'; } $class = $filterDomain.ucfirst($type); /* * You can set your own filter model condition by extending * Field class and setting your filter model class. */ if (!empty($field->filterModel) && isset($field->filterModel)) { if ($field->filterModel instanceof Model) { return $field->filterModel; } $class = $field->filterModel; } return new $class($persistence, ['lookupField' => $field]); }
[ "public", "static", "function", "factoryType", "(", "$", "field", ")", "{", "$", "data", "=", "[", "]", ";", "$", "persistence", "=", "new", "Persistence_Array", "(", "$", "data", ")", ";", "$", "filterDomain", "=", "'atk4\\\\ui\\\\TableColumn\\\\FilterModel\\Type'", ";", "// check if field as a type and use string as default", "if", "(", "empty", "(", "$", "type", "=", "$", "field", "->", "type", ")", ")", "{", "$", "type", "=", "'string'", ";", "}", "$", "class", "=", "$", "filterDomain", ".", "ucfirst", "(", "$", "type", ")", ";", "/*\n * You can set your own filter model condition by extending\n * Field class and setting your filter model class.\n */", "if", "(", "!", "empty", "(", "$", "field", "->", "filterModel", ")", "&&", "isset", "(", "$", "field", "->", "filterModel", ")", ")", "{", "if", "(", "$", "field", "->", "filterModel", "instanceof", "Model", ")", "{", "return", "$", "field", "->", "filterModel", ";", "}", "$", "class", "=", "$", "field", "->", "filterModel", ";", "}", "return", "new", "$", "class", "(", "$", "persistence", ",", "[", "'lookupField'", "=>", "$", "field", "]", ")", ";", "}" ]
Factory method that will return a FilerModel Type class. @param Field $field @param Persistence $persistence @return mixed
[ "Factory", "method", "that", "will", "return", "a", "FilerModel", "Type", "class", "." ]
f31c6674ff80999e29dd95375d4f3588bfdbad00
https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/TableColumn/FilterModel/Generic.php#L54-L78
train
atk4/ui
src/TableColumn/FilterModel/Generic.php
Generic.afterInit
public function afterInit() { $this->addField('name', ['default'=> $this->lookupField->short_name, 'system' => true]); if (isset($this->_sessionTrait) && $this->_sessionTrait) { // create a name for our filter model to save as session data. $this->name = 'filter_model_'.$this->lookupField->short_name; if (@$_GET['atk_clear_filter']) { $this->forget(); } if ($data = $this->recallData()) { $this->persistence->data['data'][] = $data; } // Add hook in order to persist data in session. $this->addHook('afterSave', function ($m) { $this->memorize('data', $m->get()); }); } }
php
public function afterInit() { $this->addField('name', ['default'=> $this->lookupField->short_name, 'system' => true]); if (isset($this->_sessionTrait) && $this->_sessionTrait) { // create a name for our filter model to save as session data. $this->name = 'filter_model_'.$this->lookupField->short_name; if (@$_GET['atk_clear_filter']) { $this->forget(); } if ($data = $this->recallData()) { $this->persistence->data['data'][] = $data; } // Add hook in order to persist data in session. $this->addHook('afterSave', function ($m) { $this->memorize('data', $m->get()); }); } }
[ "public", "function", "afterInit", "(", ")", "{", "$", "this", "->", "addField", "(", "'name'", ",", "[", "'default'", "=>", "$", "this", "->", "lookupField", "->", "short_name", ",", "'system'", "=>", "true", "]", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "_sessionTrait", ")", "&&", "$", "this", "->", "_sessionTrait", ")", "{", "// create a name for our filter model to save as session data.", "$", "this", "->", "name", "=", "'filter_model_'", ".", "$", "this", "->", "lookupField", "->", "short_name", ";", "if", "(", "@", "$", "_GET", "[", "'atk_clear_filter'", "]", ")", "{", "$", "this", "->", "forget", "(", ")", ";", "}", "if", "(", "$", "data", "=", "$", "this", "->", "recallData", "(", ")", ")", "{", "$", "this", "->", "persistence", "->", "data", "[", "'data'", "]", "[", "]", "=", "$", "data", ";", "}", "// Add hook in order to persist data in session.", "$", "this", "->", "addHook", "(", "'afterSave'", ",", "function", "(", "$", "m", ")", "{", "$", "this", "->", "memorize", "(", "'data'", ",", "$", "m", "->", "get", "(", ")", ")", ";", "}", ")", ";", "}", "}" ]
Perform further initialisation. @throws \atk4\core\Exception
[ "Perform", "further", "initialisation", "." ]
f31c6674ff80999e29dd95375d4f3588bfdbad00
https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/TableColumn/FilterModel/Generic.php#L97-L118
train
atk4/ui
src/Tabs.php
Tabs.addTabMenuItem
protected function addTabMenuItem($name) { if (is_object($name)) { $tab = $name; } else { $tab = new Tab($name); } $tab = $this->add([$tab, 'class' => ['item']], 'Menu') ->setElement('a') ->setAttr('data-tab', $tab->name); if (empty($this->activeTabName)) { $this->activeTabName = $tab->name; } return $tab; }
php
protected function addTabMenuItem($name) { if (is_object($name)) { $tab = $name; } else { $tab = new Tab($name); } $tab = $this->add([$tab, 'class' => ['item']], 'Menu') ->setElement('a') ->setAttr('data-tab', $tab->name); if (empty($this->activeTabName)) { $this->activeTabName = $tab->name; } return $tab; }
[ "protected", "function", "addTabMenuItem", "(", "$", "name", ")", "{", "if", "(", "is_object", "(", "$", "name", ")", ")", "{", "$", "tab", "=", "$", "name", ";", "}", "else", "{", "$", "tab", "=", "new", "Tab", "(", "$", "name", ")", ";", "}", "$", "tab", "=", "$", "this", "->", "add", "(", "[", "$", "tab", ",", "'class'", "=>", "[", "'item'", "]", "]", ",", "'Menu'", ")", "->", "setElement", "(", "'a'", ")", "->", "setAttr", "(", "'data-tab'", ",", "$", "tab", "->", "name", ")", ";", "if", "(", "empty", "(", "$", "this", "->", "activeTabName", ")", ")", "{", "$", "this", "->", "activeTabName", "=", "$", "tab", "->", "name", ";", "}", "return", "$", "tab", ";", "}" ]
Add a tab menu item. @param string|Tab $name Name of tab or Tab object. @throws Exception @return Tab|View Tab menu item view.
[ "Add", "a", "tab", "menu", "item", "." ]
f31c6674ff80999e29dd95375d4f3588bfdbad00
https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/Tabs.php#L70-L87
train
atk4/ui
src/jsNotify.php
jsNotify.setTransition
public function setTransition($openTransition, $closeTransition = null) { $this->options['openTransition'] = $openTransition; if ($closeTransition) { $this->options['closeTransition'] = $closeTransition; } return $this; }
php
public function setTransition($openTransition, $closeTransition = null) { $this->options['openTransition'] = $openTransition; if ($closeTransition) { $this->options['closeTransition'] = $closeTransition; } return $this; }
[ "public", "function", "setTransition", "(", "$", "openTransition", ",", "$", "closeTransition", "=", "null", ")", "{", "$", "this", "->", "options", "[", "'openTransition'", "]", "=", "$", "openTransition", ";", "if", "(", "$", "closeTransition", ")", "{", "$", "this", "->", "options", "[", "'closeTransition'", "]", "=", "$", "closeTransition", ";", "}", "return", "$", "this", ";", "}" ]
Set open and close transition for the notifier. - any transition define in semantic ui can be used. @param $openTransition @param null $closeTransition @return $this
[ "Set", "open", "and", "close", "transition", "for", "the", "notifier", ".", "-", "any", "transition", "define", "in", "semantic", "ui", "can", "be", "used", "." ]
f31c6674ff80999e29dd95375d4f3588bfdbad00
https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/jsNotify.php#L95-L104
train
atk4/ui
src/jsNotify.php
jsNotify.jsRender
public function jsRender() { if ($this->attachTo) { $final = $this->attachTo->js(); } else { $final = new jsChain(); } $final->atkNotify($this->options); return $final->jsRender(); }
php
public function jsRender() { if ($this->attachTo) { $final = $this->attachTo->js(); } else { $final = new jsChain(); } $final->atkNotify($this->options); return $final->jsRender(); }
[ "public", "function", "jsRender", "(", ")", "{", "if", "(", "$", "this", "->", "attachTo", ")", "{", "$", "final", "=", "$", "this", "->", "attachTo", "->", "js", "(", ")", ";", "}", "else", "{", "$", "final", "=", "new", "jsChain", "(", ")", ";", "}", "$", "final", "->", "atkNotify", "(", "$", "this", "->", "options", ")", ";", "return", "$", "final", "->", "jsRender", "(", ")", ";", "}" ]
Render the notifier. @return string
[ "Render", "the", "notifier", "." ]
f31c6674ff80999e29dd95375d4f3588bfdbad00
https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/jsNotify.php#L192-L203
train
atk4/ui
src/Modal.php
Modal.set
public function set($fx = [], $arg2 = null) { if (!is_object($fx) && !($fx instanceof Closure)) { throw new Exception('Error: Need to pass a function to Modal::set()'); } $this->fx = [$fx]; $this->enableCallback(); return $this; }
php
public function set($fx = [], $arg2 = null) { if (!is_object($fx) && !($fx instanceof Closure)) { throw new Exception('Error: Need to pass a function to Modal::set()'); } $this->fx = [$fx]; $this->enableCallback(); return $this; }
[ "public", "function", "set", "(", "$", "fx", "=", "[", "]", ",", "$", "arg2", "=", "null", ")", "{", "if", "(", "!", "is_object", "(", "$", "fx", ")", "&&", "!", "(", "$", "fx", "instanceof", "Closure", ")", ")", "{", "throw", "new", "Exception", "(", "'Error: Need to pass a function to Modal::set()'", ")", ";", "}", "$", "this", "->", "fx", "=", "[", "$", "fx", "]", ";", "$", "this", "->", "enableCallback", "(", ")", ";", "return", "$", "this", ";", "}" ]
Set callback function for this modal. @param array|string $fx @param array|string $arg2 @throws Exception @return $this
[ "Set", "callback", "function", "for", "this", "modal", "." ]
f31c6674ff80999e29dd95375d4f3588bfdbad00
https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/Modal.php#L67-L76
train
atk4/ui
src/Modal.php
Modal.enableCallback
public function enableCallback() { $this->cb_view = $this->add('View'); $this->cb_view->stickyGet('__atk_m', $this->name); $this->cb = $this->cb_view->add('CallbackLater'); $this->cb->set(function () { if ($this->cb->triggered() && $this->fx) { $this->fx[0]($this->cb_view); } $modalName = isset($_GET['__atk_m']) ? $_GET['__atk_m'] : null; if ($modalName === $this->name) { $this->app->terminate($this->cb_view->renderJSON()); } }); }
php
public function enableCallback() { $this->cb_view = $this->add('View'); $this->cb_view->stickyGet('__atk_m', $this->name); $this->cb = $this->cb_view->add('CallbackLater'); $this->cb->set(function () { if ($this->cb->triggered() && $this->fx) { $this->fx[0]($this->cb_view); } $modalName = isset($_GET['__atk_m']) ? $_GET['__atk_m'] : null; if ($modalName === $this->name) { $this->app->terminate($this->cb_view->renderJSON()); } }); }
[ "public", "function", "enableCallback", "(", ")", "{", "$", "this", "->", "cb_view", "=", "$", "this", "->", "add", "(", "'View'", ")", ";", "$", "this", "->", "cb_view", "->", "stickyGet", "(", "'__atk_m'", ",", "$", "this", "->", "name", ")", ";", "$", "this", "->", "cb", "=", "$", "this", "->", "cb_view", "->", "add", "(", "'CallbackLater'", ")", ";", "$", "this", "->", "cb", "->", "set", "(", "function", "(", ")", "{", "if", "(", "$", "this", "->", "cb", "->", "triggered", "(", ")", "&&", "$", "this", "->", "fx", ")", "{", "$", "this", "->", "fx", "[", "0", "]", "(", "$", "this", "->", "cb_view", ")", ";", "}", "$", "modalName", "=", "isset", "(", "$", "_GET", "[", "'__atk_m'", "]", ")", "?", "$", "_GET", "[", "'__atk_m'", "]", ":", "null", ";", "if", "(", "$", "modalName", "===", "$", "this", "->", "name", ")", "{", "$", "this", "->", "app", "->", "terminate", "(", "$", "this", "->", "cb_view", "->", "renderJSON", "(", ")", ")", ";", "}", "}", ")", ";", "}" ]
Add View to be loaded in this modal and attach CallbackLater to it. The cb_view only will be loaded dynamically within modal div.atk-content.
[ "Add", "View", "to", "be", "loaded", "in", "this", "modal", "and", "attach", "CallbackLater", "to", "it", ".", "The", "cb_view", "only", "will", "be", "loaded", "dynamically", "within", "modal", "div", ".", "atk", "-", "content", "." ]
f31c6674ff80999e29dd95375d4f3588bfdbad00
https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/Modal.php#L84-L99
train
atk4/ui
src/Modal.php
Modal.setOptions
public function setOptions($options) { if (isset($this->options['modal_option'])) { $this->options['modal_option'] = array_merge($this->options['modal_option'], $options); } else { $this->options['modal_option'] = $options; } return $this; }
php
public function setOptions($options) { if (isset($this->options['modal_option'])) { $this->options['modal_option'] = array_merge($this->options['modal_option'], $options); } else { $this->options['modal_option'] = $options; } return $this; }
[ "public", "function", "setOptions", "(", "$", "options", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "options", "[", "'modal_option'", "]", ")", ")", "{", "$", "this", "->", "options", "[", "'modal_option'", "]", "=", "array_merge", "(", "$", "this", "->", "options", "[", "'modal_option'", "]", ",", "$", "options", ")", ";", "}", "else", "{", "$", "this", "->", "options", "[", "'modal_option'", "]", "=", "$", "options", ";", "}", "return", "$", "this", ";", "}" ]
Set modal options passing an array. @param $options @return $this
[ "Set", "modal", "options", "passing", "an", "array", "." ]
f31c6674ff80999e29dd95375d4f3588bfdbad00
https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/Modal.php#L152-L161
train
atk4/ui
src/Modal.php
Modal.addDenyAction
public function addDenyAction($label, $jsAction) { $b = new Button(); $b->set($label)->addClass('red cancel'); $this->addButtonAction($b); $this->options['modal_option']['onDeny'] = $jsAction; return $this; }
php
public function addDenyAction($label, $jsAction) { $b = new Button(); $b->set($label)->addClass('red cancel'); $this->addButtonAction($b); $this->options['modal_option']['onDeny'] = $jsAction; return $this; }
[ "public", "function", "addDenyAction", "(", "$", "label", ",", "$", "jsAction", ")", "{", "$", "b", "=", "new", "Button", "(", ")", ";", "$", "b", "->", "set", "(", "$", "label", ")", "->", "addClass", "(", "'red cancel'", ")", ";", "$", "this", "->", "addButtonAction", "(", "$", "b", ")", ";", "$", "this", "->", "options", "[", "'modal_option'", "]", "[", "'onDeny'", "]", "=", "$", "jsAction", ";", "return", "$", "this", ";", "}" ]
Add a deny action to modal. @param $label. @param $jsAction : Javascript action that will run when deny is click. @return $this
[ "Add", "a", "deny", "action", "to", "modal", "." ]
f31c6674ff80999e29dd95375d4f3588bfdbad00
https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/Modal.php#L235-L243
train
atk4/ui
src/jsPaginator.php
jsPaginator.onScroll
public function onScroll($fx = null) { if (is_callable($fx)) { if ($this->triggered()) { $page = $this->getPage(); $this->set(function () use ($fx, $page) { return call_user_func_array($fx, [$page]); }); } } }
php
public function onScroll($fx = null) { if (is_callable($fx)) { if ($this->triggered()) { $page = $this->getPage(); $this->set(function () use ($fx, $page) { return call_user_func_array($fx, [$page]); }); } } }
[ "public", "function", "onScroll", "(", "$", "fx", "=", "null", ")", "{", "if", "(", "is_callable", "(", "$", "fx", ")", ")", "{", "if", "(", "$", "this", "->", "triggered", "(", ")", ")", "{", "$", "page", "=", "$", "this", "->", "getPage", "(", ")", ";", "$", "this", "->", "set", "(", "function", "(", ")", "use", "(", "$", "fx", ",", "$", "page", ")", "{", "return", "call_user_func_array", "(", "$", "fx", ",", "[", "$", "page", "]", ")", ";", "}", ")", ";", "}", "}", "}" ]
Callback when container has been scroll to bottom. @param null|callable $fx
[ "Callback", "when", "container", "has", "been", "scroll", "to", "bottom", "." ]
f31c6674ff80999e29dd95375d4f3588bfdbad00
https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/jsPaginator.php#L87-L97
train
atk4/ui
src/jsSSE.php
jsSSE.sendEvent
public function sendEvent($id, $data, $eventName) { $this->sendBlock($id, $data, $eventName); $this->flush(); }
php
public function sendEvent($id, $data, $eventName) { $this->sendBlock($id, $data, $eventName); $this->flush(); }
[ "public", "function", "sendEvent", "(", "$", "id", ",", "$", "data", ",", "$", "eventName", ")", "{", "$", "this", "->", "sendBlock", "(", "$", "id", ",", "$", "data", ",", "$", "eventName", ")", ";", "$", "this", "->", "flush", "(", ")", ";", "}" ]
Output a SSE Event. @param $id @param $data @param $eventName
[ "Output", "a", "SSE", "Event", "." ]
f31c6674ff80999e29dd95375d4f3588bfdbad00
https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/jsSSE.php#L72-L76
train
atk4/ui
src/FormLayout/_Abstract.php
_Abstract.getModelFields
protected function getModelFields(\atk4\data\Model $model) { $fields = []; foreach ($model->elements as $f) { if (!$f instanceof \atk4\data\Field) { continue; } if ($f->isEditable() || $f->isVisible()) { $fields[] = $f->short_name; } } return $fields; }
php
protected function getModelFields(\atk4\data\Model $model) { $fields = []; foreach ($model->elements as $f) { if (!$f instanceof \atk4\data\Field) { continue; } if ($f->isEditable() || $f->isVisible()) { $fields[] = $f->short_name; } } return $fields; }
[ "protected", "function", "getModelFields", "(", "\\", "atk4", "\\", "data", "\\", "Model", "$", "model", ")", "{", "$", "fields", "=", "[", "]", ";", "foreach", "(", "$", "model", "->", "elements", "as", "$", "f", ")", "{", "if", "(", "!", "$", "f", "instanceof", "\\", "atk4", "\\", "data", "\\", "Field", ")", "{", "continue", ";", "}", "if", "(", "$", "f", "->", "isEditable", "(", ")", "||", "$", "f", "->", "isVisible", "(", ")", ")", "{", "$", "fields", "[", "]", "=", "$", "f", "->", "short_name", ";", "}", "}", "return", "$", "fields", ";", "}" ]
Returns array of names of fields to automatically include them in form. This includes all editable or visible fields of the model. @param \atk4\data\Model $model @return array
[ "Returns", "array", "of", "names", "of", "fields", "to", "automatically", "include", "them", "in", "form", ".", "This", "includes", "all", "editable", "or", "visible", "fields", "of", "the", "model", "." ]
f31c6674ff80999e29dd95375d4f3588bfdbad00
https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/FormLayout/_Abstract.php#L100-L114
train
atk4/ui
src/FormLayout/_Abstract.php
_Abstract.getField
public function getField($name) { if (empty($this->form)) { throw new Exception(['Incorrect value for $form', 'form' => $this->form]); } return $this->form->getField($name); }
php
public function getField($name) { if (empty($this->form)) { throw new Exception(['Incorrect value for $form', 'form' => $this->form]); } return $this->form->getField($name); }
[ "public", "function", "getField", "(", "$", "name", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "form", ")", ")", "{", "throw", "new", "Exception", "(", "[", "'Incorrect value for $form'", ",", "'form'", "=>", "$", "this", "->", "form", "]", ")", ";", "}", "return", "$", "this", "->", "form", "->", "getField", "(", "$", "name", ")", ";", "}" ]
Return Field decorator associated with the form's field. @param string $name @return \atk4\ui\FormField\Generic
[ "Return", "Field", "decorator", "associated", "with", "the", "form", "s", "field", "." ]
f31c6674ff80999e29dd95375d4f3588bfdbad00
https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/FormLayout/_Abstract.php#L167-L174
train
atk4/ui
src/FormField/AutoComplete.php
AutoComplete.initDropdown
protected function initDropdown($chain) { $settings = array_merge([ 'fields' => ['name' => 'name', 'value' => 'id'/*, 'text' => 'description'*/], 'apiSettings' => array_merge(['url' => $this->getCallbackURL().'&q={query}'], $this->apiConfig), ], $this->settings); $chain->dropdown($settings); }
php
protected function initDropdown($chain) { $settings = array_merge([ 'fields' => ['name' => 'name', 'value' => 'id'/*, 'text' => 'description'*/], 'apiSettings' => array_merge(['url' => $this->getCallbackURL().'&q={query}'], $this->apiConfig), ], $this->settings); $chain->dropdown($settings); }
[ "protected", "function", "initDropdown", "(", "$", "chain", ")", "{", "$", "settings", "=", "array_merge", "(", "[", "'fields'", "=>", "[", "'name'", "=>", "'name'", ",", "'value'", "=>", "'id'", "/*, 'text' => 'description'*/", "]", ",", "'apiSettings'", "=>", "array_merge", "(", "[", "'url'", "=>", "$", "this", "->", "getCallbackURL", "(", ")", ".", "'&q={query}'", "]", ",", "$", "this", "->", "apiConfig", ")", ",", "]", ",", "$", "this", "->", "settings", ")", ";", "$", "chain", "->", "dropdown", "(", "$", "settings", ")", ";", "}" ]
Override this method if you want to add more logic to the initialization of the auto-complete field. @param jQuery
[ "Override", "this", "method", "if", "you", "want", "to", "add", "more", "logic", "to", "the", "initialization", "of", "the", "auto", "-", "complete", "field", "." ]
f31c6674ff80999e29dd95375d4f3588bfdbad00
https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/FormField/AutoComplete.php#L229-L237
train
atk4/ui
src/Template.php
Template.&
public function &getTagRef($tag) { if ($this->isTopTag($tag)) { return $this->template; } $a = explode('#', $tag); $tag = array_shift($a); //$ref = array_shift($a); // unused if (!isset($this->tags[$tag])) { throw $this->exception('Tag not found in Template') ->addMoreInfo('tag', $tag) ->addMoreInfo('tags', implode(', ', array_keys($this->tags))); } // return first array element only reset($this->tags[$tag]); $key = key($this->tags[$tag]) !== null ? key($this->tags[$tag]) : null; return $this->tags[$tag][$key]; }
php
public function &getTagRef($tag) { if ($this->isTopTag($tag)) { return $this->template; } $a = explode('#', $tag); $tag = array_shift($a); //$ref = array_shift($a); // unused if (!isset($this->tags[$tag])) { throw $this->exception('Tag not found in Template') ->addMoreInfo('tag', $tag) ->addMoreInfo('tags', implode(', ', array_keys($this->tags))); } // return first array element only reset($this->tags[$tag]); $key = key($this->tags[$tag]) !== null ? key($this->tags[$tag]) : null; return $this->tags[$tag][$key]; }
[ "public", "function", "&", "getTagRef", "(", "$", "tag", ")", "{", "if", "(", "$", "this", "->", "isTopTag", "(", "$", "tag", ")", ")", "{", "return", "$", "this", "->", "template", ";", "}", "$", "a", "=", "explode", "(", "'#'", ",", "$", "tag", ")", ";", "$", "tag", "=", "array_shift", "(", "$", "a", ")", ";", "//$ref = array_shift($a); // unused", "if", "(", "!", "isset", "(", "$", "this", "->", "tags", "[", "$", "tag", "]", ")", ")", "{", "throw", "$", "this", "->", "exception", "(", "'Tag not found in Template'", ")", "->", "addMoreInfo", "(", "'tag'", ",", "$", "tag", ")", "->", "addMoreInfo", "(", "'tags'", ",", "implode", "(", "', '", ",", "array_keys", "(", "$", "this", "->", "tags", ")", ")", ")", ";", "}", "// return first array element only", "reset", "(", "$", "this", "->", "tags", "[", "$", "tag", "]", ")", ";", "$", "key", "=", "key", "(", "$", "this", "->", "tags", "[", "$", "tag", "]", ")", "!==", "null", "?", "key", "(", "$", "this", "->", "tags", "[", "$", "tag", "]", ")", ":", "null", ";", "return", "$", "this", "->", "tags", "[", "$", "tag", "]", "[", "$", "key", "]", ";", "}" ]
This is a helper method which returns reference to element of template array referenced by a said tag. Because there might be multiple tags and getTagRef is returning only one template, it will return the first occurrence: {greeting}hello{/}, {greeting}world{/} calling &getTagRef('greeting') will return reference to &array('hello'); @param string $tag @return &array
[ "This", "is", "a", "helper", "method", "which", "returns", "reference", "to", "element", "of", "template", "array", "referenced", "by", "a", "said", "tag", "." ]
f31c6674ff80999e29dd95375d4f3588bfdbad00
https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/Template.php#L147-L167
train
atk4/ui
src/Template.php
Template.hasTag
public function hasTag($tag) { // check if all tags exist if (is_array($tag)) { foreach ($tag as $t) { if (!$this->hasTag($t)) { return false; } } return true; } // check if tag exist $a = explode('#', $tag); $tag = array_shift($a); //$ref = array_shift($a); // unused return isset($this->tags[$tag]) || $this->isTopTag($tag); }
php
public function hasTag($tag) { // check if all tags exist if (is_array($tag)) { foreach ($tag as $t) { if (!$this->hasTag($t)) { return false; } } return true; } // check if tag exist $a = explode('#', $tag); $tag = array_shift($a); //$ref = array_shift($a); // unused return isset($this->tags[$tag]) || $this->isTopTag($tag); }
[ "public", "function", "hasTag", "(", "$", "tag", ")", "{", "// check if all tags exist", "if", "(", "is_array", "(", "$", "tag", ")", ")", "{", "foreach", "(", "$", "tag", "as", "$", "t", ")", "{", "if", "(", "!", "$", "this", "->", "hasTag", "(", "$", "t", ")", ")", "{", "return", "false", ";", "}", "}", "return", "true", ";", "}", "// check if tag exist", "$", "a", "=", "explode", "(", "'#'", ",", "$", "tag", ")", ";", "$", "tag", "=", "array_shift", "(", "$", "a", ")", ";", "//$ref = array_shift($a); // unused", "return", "isset", "(", "$", "this", "->", "tags", "[", "$", "tag", "]", ")", "||", "$", "this", "->", "isTopTag", "(", "$", "tag", ")", ";", "}" ]
Checks if template has defined a specified tag. If multiple tags are passed in as array, then return true if all of them exist. @param string|array $tag @return bool
[ "Checks", "if", "template", "has", "defined", "a", "specified", "tag", ".", "If", "multiple", "tags", "are", "passed", "in", "as", "array", "then", "return", "true", "if", "all", "of", "them", "exist", "." ]
f31c6674ff80999e29dd95375d4f3588bfdbad00
https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/Template.php#L235-L254
train
atk4/ui
src/Template.php
Template.rebuildTagsRegion
protected function rebuildTagsRegion(&$template) { foreach ($template as $tag => &$val) { if (is_numeric($tag)) { continue; } $a = explode('#', $tag); $key = array_shift($a); $ref = array_shift($a); $this->tags[$key][$ref] = &$val; if (is_array($val)) { $this->rebuildTagsRegion($val); } } }
php
protected function rebuildTagsRegion(&$template) { foreach ($template as $tag => &$val) { if (is_numeric($tag)) { continue; } $a = explode('#', $tag); $key = array_shift($a); $ref = array_shift($a); $this->tags[$key][$ref] = &$val; if (is_array($val)) { $this->rebuildTagsRegion($val); } } }
[ "protected", "function", "rebuildTagsRegion", "(", "&", "$", "template", ")", "{", "foreach", "(", "$", "template", "as", "$", "tag", "=>", "&", "$", "val", ")", "{", "if", "(", "is_numeric", "(", "$", "tag", ")", ")", "{", "continue", ";", "}", "$", "a", "=", "explode", "(", "'#'", ",", "$", "tag", ")", ";", "$", "key", "=", "array_shift", "(", "$", "a", ")", ";", "$", "ref", "=", "array_shift", "(", "$", "a", ")", ";", "$", "this", "->", "tags", "[", "$", "key", "]", "[", "$", "ref", "]", "=", "&", "$", "val", ";", "if", "(", "is_array", "(", "$", "val", ")", ")", "{", "$", "this", "->", "rebuildTagsRegion", "(", "$", "val", ")", ";", "}", "}", "}" ]
Add tags from a specified region. @param array $template
[ "Add", "tags", "from", "a", "specified", "region", "." ]
f31c6674ff80999e29dd95375d4f3588bfdbad00
https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/Template.php#L271-L287
train
atk4/ui
src/Template.php
Template.setHTML
public function setHTML($tag, $value = null) { return $this->_setOrAppend($tag, $value, false, false, true); }
php
public function setHTML($tag, $value = null) { return $this->_setOrAppend($tag, $value, false, false, true); }
[ "public", "function", "setHTML", "(", "$", "tag", ",", "$", "value", "=", "null", ")", "{", "return", "$", "this", "->", "_setOrAppend", "(", "$", "tag", ",", "$", "value", ",", "false", ",", "false", ",", "true", ")", ";", "}" ]
Set value of a tag to a HTML content. The value is set without encoding, so you must be sure to sanitize. @param string|array|Model $tag @param string $value @return $this
[ "Set", "value", "of", "a", "tag", "to", "a", "HTML", "content", ".", "The", "value", "is", "set", "without", "encoding", "so", "you", "must", "be", "sure", "to", "sanitize", "." ]
f31c6674ff80999e29dd95375d4f3588bfdbad00
https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/Template.php#L402-L405
train
atk4/ui
src/Template.php
Template.appendHTML
public function appendHTML($tag, $value) { return $this->_setOrAppend($tag, $value, false, true, true); }
php
public function appendHTML($tag, $value) { return $this->_setOrAppend($tag, $value, false, true, true); }
[ "public", "function", "appendHTML", "(", "$", "tag", ",", "$", "value", ")", "{", "return", "$", "this", "->", "_setOrAppend", "(", "$", "tag", ",", "$", "value", ",", "false", ",", "true", ",", "true", ")", ";", "}" ]
Add more content inside a tag. The content is appended without encoding, so you must be sure to sanitize. @param string|array|Model $tag @param string $value @return $this
[ "Add", "more", "content", "inside", "a", "tag", ".", "The", "content", "is", "appended", "without", "encoding", "so", "you", "must", "be", "sure", "to", "sanitize", "." ]
f31c6674ff80999e29dd95375d4f3588bfdbad00
https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/Template.php#L459-L462
train
atk4/ui
src/Template.php
Template.eachTag
public function eachTag($tag, $callable) { if (!$this->hasTag($tag)) { return $this; } // array support if (is_array($tag)) { foreach ($tag as $t) { $this->eachTag($t, $callable); } return $this; } // $tag should be string here $template = $this->getTagRefList($tag); if ($template != $this->template) { foreach ($template as $key => $templ) { $ref = $tag.'#'.($key + 1); $this->tags[$tag][$key] = [call_user_func($callable, $this->recursiveRender($templ), $ref)]; } } else { $this->tags[$tag][0] = [call_user_func($callable, $this->recursiveRender($template), $tag)]; } return $this; }
php
public function eachTag($tag, $callable) { if (!$this->hasTag($tag)) { return $this; } // array support if (is_array($tag)) { foreach ($tag as $t) { $this->eachTag($t, $callable); } return $this; } // $tag should be string here $template = $this->getTagRefList($tag); if ($template != $this->template) { foreach ($template as $key => $templ) { $ref = $tag.'#'.($key + 1); $this->tags[$tag][$key] = [call_user_func($callable, $this->recursiveRender($templ), $ref)]; } } else { $this->tags[$tag][0] = [call_user_func($callable, $this->recursiveRender($template), $tag)]; } return $this; }
[ "public", "function", "eachTag", "(", "$", "tag", ",", "$", "callable", ")", "{", "if", "(", "!", "$", "this", "->", "hasTag", "(", "$", "tag", ")", ")", "{", "return", "$", "this", ";", "}", "// array support", "if", "(", "is_array", "(", "$", "tag", ")", ")", "{", "foreach", "(", "$", "tag", "as", "$", "t", ")", "{", "$", "this", "->", "eachTag", "(", "$", "t", ",", "$", "callable", ")", ";", "}", "return", "$", "this", ";", "}", "// $tag should be string here", "$", "template", "=", "$", "this", "->", "getTagRefList", "(", "$", "tag", ")", ";", "if", "(", "$", "template", "!=", "$", "this", "->", "template", ")", "{", "foreach", "(", "$", "template", "as", "$", "key", "=>", "$", "templ", ")", "{", "$", "ref", "=", "$", "tag", ".", "'#'", ".", "(", "$", "key", "+", "1", ")", ";", "$", "this", "->", "tags", "[", "$", "tag", "]", "[", "$", "key", "]", "=", "[", "call_user_func", "(", "$", "callable", ",", "$", "this", "->", "recursiveRender", "(", "$", "templ", ")", ",", "$", "ref", ")", "]", ";", "}", "}", "else", "{", "$", "this", "->", "tags", "[", "$", "tag", "]", "[", "0", "]", "=", "[", "call_user_func", "(", "$", "callable", ",", "$", "this", "->", "recursiveRender", "(", "$", "template", ")", ",", "$", "tag", ")", "]", ";", "}", "return", "$", "this", ";", "}" ]
Executes call-back for each matching tag in the template. @param string|array $tag @param callable $callable @return $this
[ "Executes", "call", "-", "back", "for", "each", "matching", "tag", "in", "the", "template", "." ]
f31c6674ff80999e29dd95375d4f3588bfdbad00
https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/Template.php#L578-L605
train
atk4/ui
src/Template.php
Template.cloneRegion
public function cloneRegion($tag) { if ($this->isTopTag($tag)) { return clone $this; } $cl = get_class($this); $n = new $cl(); $n->app = $this->app; $n->template = unserialize(serialize(['_top#1' => $this->get($tag)])); $n->rebuildTags(); $n->source = 'clone ('.$tag.') of template '.$this->source; return $n; }
php
public function cloneRegion($tag) { if ($this->isTopTag($tag)) { return clone $this; } $cl = get_class($this); $n = new $cl(); $n->app = $this->app; $n->template = unserialize(serialize(['_top#1' => $this->get($tag)])); $n->rebuildTags(); $n->source = 'clone ('.$tag.') of template '.$this->source; return $n; }
[ "public", "function", "cloneRegion", "(", "$", "tag", ")", "{", "if", "(", "$", "this", "->", "isTopTag", "(", "$", "tag", ")", ")", "{", "return", "clone", "$", "this", ";", "}", "$", "cl", "=", "get_class", "(", "$", "this", ")", ";", "$", "n", "=", "new", "$", "cl", "(", ")", ";", "$", "n", "->", "app", "=", "$", "this", "->", "app", ";", "$", "n", "->", "template", "=", "unserialize", "(", "serialize", "(", "[", "'_top#1'", "=>", "$", "this", "->", "get", "(", "$", "tag", ")", "]", ")", ")", ";", "$", "n", "->", "rebuildTags", "(", ")", ";", "$", "n", "->", "source", "=", "'clone ('", ".", "$", "tag", ".", "') of template '", ".", "$", "this", "->", "source", ";", "return", "$", "n", ";", "}" ]
Creates a new template using portion of existing template. @param string $tag @return self
[ "Creates", "a", "new", "template", "using", "portion", "of", "existing", "template", "." ]
f31c6674ff80999e29dd95375d4f3588bfdbad00
https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/Template.php#L614-L628
train
atk4/ui
src/Template.php
Template.load
public function load($filename) { if ($t = $this->tryLoad($filename)) { return $t; } throw new Exception([ 'Unable to read template from file', 'cwd' => getcwd(), 'file' => $filename, ]); }
php
public function load($filename) { if ($t = $this->tryLoad($filename)) { return $t; } throw new Exception([ 'Unable to read template from file', 'cwd' => getcwd(), 'file' => $filename, ]); }
[ "public", "function", "load", "(", "$", "filename", ")", "{", "if", "(", "$", "t", "=", "$", "this", "->", "tryLoad", "(", "$", "filename", ")", ")", "{", "return", "$", "t", ";", "}", "throw", "new", "Exception", "(", "[", "'Unable to read template from file'", ",", "'cwd'", "=>", "getcwd", "(", ")", ",", "'file'", "=>", "$", "filename", ",", "]", ")", ";", "}" ]
Loads template from a specified file. @param string $filename Template file name @throws Exception @return $this
[ "Loads", "template", "from", "a", "specified", "file", "." ]
f31c6674ff80999e29dd95375d4f3588bfdbad00
https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/Template.php#L643-L654
train
atk4/ui
src/Template.php
Template.loadTemplateFromString
public function loadTemplateFromString($str) { $this->source = 'string: '.$str; $this->template = $this->tags = []; if (!$str) { return; } $this->tag_cnt = []; /* First expand self-closing tags {$tag} -> {tag}{/tag} */ $str = preg_replace('/{\$([-_:\w]+)}/', '{\1}{/\1}', $str); $this->parseTemplate($str); return $this; }
php
public function loadTemplateFromString($str) { $this->source = 'string: '.$str; $this->template = $this->tags = []; if (!$str) { return; } $this->tag_cnt = []; /* First expand self-closing tags {$tag} -> {tag}{/tag} */ $str = preg_replace('/{\$([-_:\w]+)}/', '{\1}{/\1}', $str); $this->parseTemplate($str); return $this; }
[ "public", "function", "loadTemplateFromString", "(", "$", "str", ")", "{", "$", "this", "->", "source", "=", "'string: '", ".", "$", "str", ";", "$", "this", "->", "template", "=", "$", "this", "->", "tags", "=", "[", "]", ";", "if", "(", "!", "$", "str", ")", "{", "return", ";", "}", "$", "this", "->", "tag_cnt", "=", "[", "]", ";", "/* First expand self-closing tags {$tag} -> {tag}{/tag} */", "$", "str", "=", "preg_replace", "(", "'/{\\$([-_:\\w]+)}/'", ",", "'{\\1}{/\\1}'", ",", "$", "str", ")", ";", "$", "this", "->", "parseTemplate", "(", "$", "str", ")", ";", "return", "$", "this", ";", "}" ]
Initialize current template from the supplied string. @param string $str @return $this
[ "Initialize", "current", "template", "from", "the", "supplied", "string", "." ]
f31c6674ff80999e29dd95375d4f3588bfdbad00
https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/Template.php#L682-L697
train
atk4/ui
src/Template.php
Template.parseTemplateRecursive
protected function parseTemplateRecursive(&$input, &$template) { if (!is_array($input) || empty($input)) { return; } while (true) { $tag = current($input); next($input); if ($tag === false) { break; } $firstChar = substr($tag, 0, 1); switch ($firstChar) { // is closing TAG case '/': return substr($tag, 1); break; // is TAG case '$': $tag = substr($tag, 1); $full_tag = $this->regTag($tag); $template[$full_tag] = ''; // empty value $this->tags[$tag][] = &$template[$full_tag]; // eat next chunk $chunk = current($input); next($input); if ($chunk !== false && $chunk !== null) { $template[] = $chunk; } break; // recurse default: $full_tag = $this->regTag($tag); // next would be prefix $prefix = current($input); next($input); $template[$full_tag] = ($prefix === false || $prefix === null) ? [] : [$prefix]; $this->tags[$tag][] = &$template[$full_tag]; $this->parseTemplateRecursive($input, $template[$full_tag]); $chunk = current($input); next($input); if ($chunk !== false && !empty($chunk)) { $template[] = $chunk; } break; } } }
php
protected function parseTemplateRecursive(&$input, &$template) { if (!is_array($input) || empty($input)) { return; } while (true) { $tag = current($input); next($input); if ($tag === false) { break; } $firstChar = substr($tag, 0, 1); switch ($firstChar) { // is closing TAG case '/': return substr($tag, 1); break; // is TAG case '$': $tag = substr($tag, 1); $full_tag = $this->regTag($tag); $template[$full_tag] = ''; // empty value $this->tags[$tag][] = &$template[$full_tag]; // eat next chunk $chunk = current($input); next($input); if ($chunk !== false && $chunk !== null) { $template[] = $chunk; } break; // recurse default: $full_tag = $this->regTag($tag); // next would be prefix $prefix = current($input); next($input); $template[$full_tag] = ($prefix === false || $prefix === null) ? [] : [$prefix]; $this->tags[$tag][] = &$template[$full_tag]; $this->parseTemplateRecursive($input, $template[$full_tag]); $chunk = current($input); next($input); if ($chunk !== false && !empty($chunk)) { $template[] = $chunk; } break; } } }
[ "protected", "function", "parseTemplateRecursive", "(", "&", "$", "input", ",", "&", "$", "template", ")", "{", "if", "(", "!", "is_array", "(", "$", "input", ")", "||", "empty", "(", "$", "input", ")", ")", "{", "return", ";", "}", "while", "(", "true", ")", "{", "$", "tag", "=", "current", "(", "$", "input", ")", ";", "next", "(", "$", "input", ")", ";", "if", "(", "$", "tag", "===", "false", ")", "{", "break", ";", "}", "$", "firstChar", "=", "substr", "(", "$", "tag", ",", "0", ",", "1", ")", ";", "switch", "(", "$", "firstChar", ")", "{", "// is closing TAG", "case", "'/'", ":", "return", "substr", "(", "$", "tag", ",", "1", ")", ";", "break", ";", "// is TAG", "case", "'$'", ":", "$", "tag", "=", "substr", "(", "$", "tag", ",", "1", ")", ";", "$", "full_tag", "=", "$", "this", "->", "regTag", "(", "$", "tag", ")", ";", "$", "template", "[", "$", "full_tag", "]", "=", "''", ";", "// empty value", "$", "this", "->", "tags", "[", "$", "tag", "]", "[", "]", "=", "&", "$", "template", "[", "$", "full_tag", "]", ";", "// eat next chunk", "$", "chunk", "=", "current", "(", "$", "input", ")", ";", "next", "(", "$", "input", ")", ";", "if", "(", "$", "chunk", "!==", "false", "&&", "$", "chunk", "!==", "null", ")", "{", "$", "template", "[", "]", "=", "$", "chunk", ";", "}", "break", ";", "// recurse", "default", ":", "$", "full_tag", "=", "$", "this", "->", "regTag", "(", "$", "tag", ")", ";", "// next would be prefix", "$", "prefix", "=", "current", "(", "$", "input", ")", ";", "next", "(", "$", "input", ")", ";", "$", "template", "[", "$", "full_tag", "]", "=", "(", "$", "prefix", "===", "false", "||", "$", "prefix", "===", "null", ")", "?", "[", "]", ":", "[", "$", "prefix", "]", ";", "$", "this", "->", "tags", "[", "$", "tag", "]", "[", "]", "=", "&", "$", "template", "[", "$", "full_tag", "]", ";", "$", "this", "->", "parseTemplateRecursive", "(", "$", "input", ",", "$", "template", "[", "$", "full_tag", "]", ")", ";", "$", "chunk", "=", "current", "(", "$", "input", ")", ";", "next", "(", "$", "input", ")", ";", "if", "(", "$", "chunk", "!==", "false", "&&", "!", "empty", "(", "$", "chunk", ")", ")", "{", "$", "template", "[", "]", "=", "$", "chunk", ";", "}", "break", ";", "}", "}", "}" ]
Recursively find nested tags inside a string, converting them to array. @param array $input @param array $template @return string|null
[ "Recursively", "find", "nested", "tags", "inside", "a", "string", "converting", "them", "to", "array", "." ]
f31c6674ff80999e29dd95375d4f3588bfdbad00
https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/Template.php#L736-L796
train
atk4/ui
src/Template.php
Template.parseTemplate
protected function parseTemplate($str) { $tag = '/{([\/$]?[-_:\w]*)}/'; $input = preg_split($tag, $str, -1, PREG_SPLIT_DELIM_CAPTURE); $prefix = current($input); next($input); $this->template = [$prefix]; $this->parseTemplateRecursive($input, $this->template); }
php
protected function parseTemplate($str) { $tag = '/{([\/$]?[-_:\w]*)}/'; $input = preg_split($tag, $str, -1, PREG_SPLIT_DELIM_CAPTURE); $prefix = current($input); next($input); $this->template = [$prefix]; $this->parseTemplateRecursive($input, $this->template); }
[ "protected", "function", "parseTemplate", "(", "$", "str", ")", "{", "$", "tag", "=", "'/{([\\/$]?[-_:\\w]*)}/'", ";", "$", "input", "=", "preg_split", "(", "$", "tag", ",", "$", "str", ",", "-", "1", ",", "PREG_SPLIT_DELIM_CAPTURE", ")", ";", "$", "prefix", "=", "current", "(", "$", "input", ")", ";", "next", "(", "$", "input", ")", ";", "$", "this", "->", "template", "=", "[", "$", "prefix", "]", ";", "$", "this", "->", "parseTemplateRecursive", "(", "$", "input", ",", "$", "this", "->", "template", ")", ";", "}" ]
Deploys parse recursion. @param string $str
[ "Deploys", "parse", "recursion", "." ]
f31c6674ff80999e29dd95375d4f3588bfdbad00
https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/Template.php#L803-L814
train
atk4/ui
src/Template.php
Template.render
public function render($region = null) { if ($region) { return $this->recursiveRender($this->get($region)); } return $this->recursiveRender($this->template); }
php
public function render($region = null) { if ($region) { return $this->recursiveRender($this->get($region)); } return $this->recursiveRender($this->template); }
[ "public", "function", "render", "(", "$", "region", "=", "null", ")", "{", "if", "(", "$", "region", ")", "{", "return", "$", "this", "->", "recursiveRender", "(", "$", "this", "->", "get", "(", "$", "region", ")", ")", ";", "}", "return", "$", "this", "->", "recursiveRender", "(", "$", "this", "->", "template", ")", ";", "}" ]
Render either a whole template or a specified region. Returns current contents of a template. @param string $region @return string
[ "Render", "either", "a", "whole", "template", "or", "a", "specified", "region", ".", "Returns", "current", "contents", "of", "a", "template", "." ]
f31c6674ff80999e29dd95375d4f3588bfdbad00
https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/Template.php#L828-L835
train
atk4/ui
src/Template.php
Template.recursiveRender
protected function recursiveRender($template) { $output = ''; foreach ($template as $val) { if (is_array($val)) { $output .= $this->recursiveRender($val); } else { $output .= $val; } } return $output; }
php
protected function recursiveRender($template) { $output = ''; foreach ($template as $val) { if (is_array($val)) { $output .= $this->recursiveRender($val); } else { $output .= $val; } } return $output; }
[ "protected", "function", "recursiveRender", "(", "$", "template", ")", "{", "$", "output", "=", "''", ";", "foreach", "(", "$", "template", "as", "$", "val", ")", "{", "if", "(", "is_array", "(", "$", "val", ")", ")", "{", "$", "output", ".=", "$", "this", "->", "recursiveRender", "(", "$", "val", ")", ";", "}", "else", "{", "$", "output", ".=", "$", "val", ";", "}", "}", "return", "$", "output", ";", "}" ]
Walk through the template array collecting the values and returning them as a string. @param array $template @return string
[ "Walk", "through", "the", "template", "array", "collecting", "the", "values", "and", "returning", "them", "as", "a", "string", "." ]
f31c6674ff80999e29dd95375d4f3588bfdbad00
https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/Template.php#L845-L857
train
atk4/ui
src/TableColumn/jsHeader.php
jsHeader.onSelectItem
public function onSelectItem($fx) { if (is_callable($fx)) { if ($this->triggered()) { $param = [$_GET['id'], @$_GET['item']]; $this->set(function () use ($fx, $param) { return call_user_func_array($fx, $param); }); } } }
php
public function onSelectItem($fx) { if (is_callable($fx)) { if ($this->triggered()) { $param = [$_GET['id'], @$_GET['item']]; $this->set(function () use ($fx, $param) { return call_user_func_array($fx, $param); }); } } }
[ "public", "function", "onSelectItem", "(", "$", "fx", ")", "{", "if", "(", "is_callable", "(", "$", "fx", ")", ")", "{", "if", "(", "$", "this", "->", "triggered", "(", ")", ")", "{", "$", "param", "=", "[", "$", "_GET", "[", "'id'", "]", ",", "@", "$", "_GET", "[", "'item'", "]", "]", ";", "$", "this", "->", "set", "(", "function", "(", ")", "use", "(", "$", "fx", ",", "$", "param", ")", "{", "return", "call_user_func_array", "(", "$", "fx", ",", "$", "param", ")", ";", "}", ")", ";", "}", "}", "}" ]
Function to call when header menu item is select. @param callable $fx
[ "Function", "to", "call", "when", "header", "menu", "item", "is", "select", "." ]
f31c6674ff80999e29dd95375d4f3588bfdbad00
https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/TableColumn/jsHeader.php#L17-L27
train
atk4/ui
src/FormLayout/Section/Accordion.php
Accordion.addSection
public function addSection($title, $callback = null, $icon = 'dropdown') { $section = parent::addSection($title, $callback, $icon); return $section->add([$this->formLayout, 'form' => $this->form]); }
php
public function addSection($title, $callback = null, $icon = 'dropdown') { $section = parent::addSection($title, $callback, $icon); return $section->add([$this->formLayout, 'form' => $this->form]); }
[ "public", "function", "addSection", "(", "$", "title", ",", "$", "callback", "=", "null", ",", "$", "icon", "=", "'dropdown'", ")", "{", "$", "section", "=", "parent", "::", "addSection", "(", "$", "title", ",", "$", "callback", ",", "$", "icon", ")", ";", "return", "$", "section", "->", "add", "(", "[", "$", "this", "->", "formLayout", ",", "'form'", "=>", "$", "this", "->", "form", "]", ")", ";", "}" ]
Return an accordion section with a form layout associate with a form. @param string $title @param null|callable $callback @param string $icon @throws \atk4\ui\Exception @return \atk4\ui\FormLayout\Generic
[ "Return", "an", "accordion", "section", "with", "a", "form", "layout", "associate", "with", "a", "form", "." ]
f31c6674ff80999e29dd95375d4f3588bfdbad00
https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/FormLayout/Section/Accordion.php#L46-L51
train
atk4/ui
src/FormLayout/Section/Accordion.php
Accordion.getSectionIdx
public function getSectionIdx($section) { if ($section instanceof \atk4\ui\AccordionSection) { return parent::getSectionIdx($section); } return parent::getSectionIdx($section->owner); }
php
public function getSectionIdx($section) { if ($section instanceof \atk4\ui\AccordionSection) { return parent::getSectionIdx($section); } return parent::getSectionIdx($section->owner); }
[ "public", "function", "getSectionIdx", "(", "$", "section", ")", "{", "if", "(", "$", "section", "instanceof", "\\", "atk4", "\\", "ui", "\\", "AccordionSection", ")", "{", "return", "parent", "::", "getSectionIdx", "(", "$", "section", ")", ";", "}", "return", "parent", "::", "getSectionIdx", "(", "$", "section", "->", "owner", ")", ";", "}" ]
Return a section index. @param AccordionSection $section @return int
[ "Return", "a", "section", "index", "." ]
f31c6674ff80999e29dd95375d4f3588bfdbad00
https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/FormLayout/Section/Accordion.php#L60-L67
train
atk4/ui
src/Lister.php
Lister.addJsPaginator
public function addJsPaginator($ipp, $options = [], $container = null, $scrollRegion = null) { $this->ipp = $ipp; $this->jsPaginator = $this->add(['jsPaginator', 'view' => $container, 'options' => $options]); // set initial model limit. can be overwritten by onScroll $this->model->setLimit($ipp); // add onScroll callback $this->jsPaginator->onScroll(function ($p) use ($ipp, $scrollRegion) { // set/overwrite model limit $this->model->setLimit($ipp, ($p - 1) * $ipp); // render this View (it will count rendered records !) $json = $this->renderJSON(true, $scrollRegion); // if there will be no more pages, then replace message=Success to let JS know that there are no more records if ($this->_rendered_rows_count < $ipp) { $json = json_decode($json, true); $json['message'] = 'Done'; // Done status means - no more requests from JS side $json = json_encode($json); } // return json response $this->app->terminate($json); }); return $this; }
php
public function addJsPaginator($ipp, $options = [], $container = null, $scrollRegion = null) { $this->ipp = $ipp; $this->jsPaginator = $this->add(['jsPaginator', 'view' => $container, 'options' => $options]); // set initial model limit. can be overwritten by onScroll $this->model->setLimit($ipp); // add onScroll callback $this->jsPaginator->onScroll(function ($p) use ($ipp, $scrollRegion) { // set/overwrite model limit $this->model->setLimit($ipp, ($p - 1) * $ipp); // render this View (it will count rendered records !) $json = $this->renderJSON(true, $scrollRegion); // if there will be no more pages, then replace message=Success to let JS know that there are no more records if ($this->_rendered_rows_count < $ipp) { $json = json_decode($json, true); $json['message'] = 'Done'; // Done status means - no more requests from JS side $json = json_encode($json); } // return json response $this->app->terminate($json); }); return $this; }
[ "public", "function", "addJsPaginator", "(", "$", "ipp", ",", "$", "options", "=", "[", "]", ",", "$", "container", "=", "null", ",", "$", "scrollRegion", "=", "null", ")", "{", "$", "this", "->", "ipp", "=", "$", "ipp", ";", "$", "this", "->", "jsPaginator", "=", "$", "this", "->", "add", "(", "[", "'jsPaginator'", ",", "'view'", "=>", "$", "container", ",", "'options'", "=>", "$", "options", "]", ")", ";", "// set initial model limit. can be overwritten by onScroll", "$", "this", "->", "model", "->", "setLimit", "(", "$", "ipp", ")", ";", "// add onScroll callback", "$", "this", "->", "jsPaginator", "->", "onScroll", "(", "function", "(", "$", "p", ")", "use", "(", "$", "ipp", ",", "$", "scrollRegion", ")", "{", "// set/overwrite model limit", "$", "this", "->", "model", "->", "setLimit", "(", "$", "ipp", ",", "(", "$", "p", "-", "1", ")", "*", "$", "ipp", ")", ";", "// render this View (it will count rendered records !)", "$", "json", "=", "$", "this", "->", "renderJSON", "(", "true", ",", "$", "scrollRegion", ")", ";", "// if there will be no more pages, then replace message=Success to let JS know that there are no more records", "if", "(", "$", "this", "->", "_rendered_rows_count", "<", "$", "ipp", ")", "{", "$", "json", "=", "json_decode", "(", "$", "json", ",", "true", ")", ";", "$", "json", "[", "'message'", "]", "=", "'Done'", ";", "// Done status means - no more requests from JS side", "$", "json", "=", "json_encode", "(", "$", "json", ")", ";", "}", "// return json response", "$", "this", "->", "app", "->", "terminate", "(", "$", "json", ")", ";", "}", ")", ";", "return", "$", "this", ";", "}" ]
Add Dynamic paginator when scrolling content via Javascript. Will output x item in lister set per ipp until user scroll content to the end of page. When this happen, content will be reload x number of items. @param int $ipp Number of item per page @param array $options An array with js Scroll plugin options. @param View $container The container holding the lister for scrolling purpose. Default to view owner. @param string $scrollRegion A specific template region to render. Render output is append to container html element. @throws Exception @return $this|void
[ "Add", "Dynamic", "paginator", "when", "scrolling", "content", "via", "Javascript", ".", "Will", "output", "x", "item", "in", "lister", "set", "per", "ipp", "until", "user", "scroll", "content", "to", "the", "end", "of", "page", ".", "When", "this", "happen", "content", "will", "be", "reload", "x", "number", "of", "items", "." ]
f31c6674ff80999e29dd95375d4f3588bfdbad00
https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/Lister.php#L90-L118
train
atk4/ui
src/jsSortable.php
jsSortable.onReorder
public function onReorder($fx = null) { if (is_callable($fx)) { if ($this->triggered()) { $sortOrders = explode(',', @$_POST['order']); $source = @$_POST['source']; $newIdx = @$_POST['new_idx']; $orgIdx = @$_POST['org_idx']; $this->set(function () use ($fx, $sortOrders, $source, $newIdx, $orgIdx) { return call_user_func_array($fx, [$sortOrders, $source, $newIdx, $orgIdx]); }); } } }
php
public function onReorder($fx = null) { if (is_callable($fx)) { if ($this->triggered()) { $sortOrders = explode(',', @$_POST['order']); $source = @$_POST['source']; $newIdx = @$_POST['new_idx']; $orgIdx = @$_POST['org_idx']; $this->set(function () use ($fx, $sortOrders, $source, $newIdx, $orgIdx) { return call_user_func_array($fx, [$sortOrders, $source, $newIdx, $orgIdx]); }); } } }
[ "public", "function", "onReorder", "(", "$", "fx", "=", "null", ")", "{", "if", "(", "is_callable", "(", "$", "fx", ")", ")", "{", "if", "(", "$", "this", "->", "triggered", "(", ")", ")", "{", "$", "sortOrders", "=", "explode", "(", "','", ",", "@", "$", "_POST", "[", "'order'", "]", ")", ";", "$", "source", "=", "@", "$", "_POST", "[", "'source'", "]", ";", "$", "newIdx", "=", "@", "$", "_POST", "[", "'new_idx'", "]", ";", "$", "orgIdx", "=", "@", "$", "_POST", "[", "'org_idx'", "]", ";", "$", "this", "->", "set", "(", "function", "(", ")", "use", "(", "$", "fx", ",", "$", "sortOrders", ",", "$", "source", ",", "$", "newIdx", ",", "$", "orgIdx", ")", "{", "return", "call_user_func_array", "(", "$", "fx", ",", "[", "$", "sortOrders", ",", "$", "source", ",", "$", "newIdx", ",", "$", "orgIdx", "]", ")", ";", "}", ")", ";", "}", "}", "}" ]
Callback when container has been reorder. @param null|callable $fx
[ "Callback", "when", "container", "has", "been", "reorder", "." ]
f31c6674ff80999e29dd95375d4f3588bfdbad00
https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/jsSortable.php#L78-L91
train
atk4/ui
src/jsVueService.php
jsVueService.createAtkVue
public function createAtkVue($id, $component, $data = []) { return $this->service->createAtkVue($id, $component, $data); }
php
public function createAtkVue($id, $component, $data = []) { return $this->service->createAtkVue($id, $component, $data); }
[ "public", "function", "createAtkVue", "(", "$", "id", ",", "$", "component", ",", "$", "data", "=", "[", "]", ")", "{", "return", "$", "this", "->", "service", "->", "createAtkVue", "(", "$", "id", ",", "$", "component", ",", "$", "data", ")", ";", "}" ]
Create a new Vue instance using a component managed by ATK. This output js: atk.vueService.createAtkVue("id","component",{}); @param $id @param $component @param array $data @return mixed
[ "Create", "a", "new", "Vue", "instance", "using", "a", "component", "managed", "by", "ATK", "." ]
f31c6674ff80999e29dd95375d4f3588bfdbad00
https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/jsVueService.php#L37-L40
train
atk4/ui
src/jsVueService.php
jsVueService.createVue
public function createVue($id, $componentName, $component, $data = []) { return $this->service->createVue($id, $componentName, $component, $data); }
php
public function createVue($id, $componentName, $component, $data = []) { return $this->service->createVue($id, $componentName, $component, $data); }
[ "public", "function", "createVue", "(", "$", "id", ",", "$", "componentName", ",", "$", "component", ",", "$", "data", "=", "[", "]", ")", "{", "return", "$", "this", "->", "service", "->", "createVue", "(", "$", "id", ",", "$", "componentName", ",", "$", "component", ",", "$", "data", ")", ";", "}" ]
Create a new Vue instance using an external component. External component should be load via js file and define properly. This output js: atk.vueService.createVue("id","component",{}); @param $id @param $component @param array $data @return mixed
[ "Create", "a", "new", "Vue", "instance", "using", "an", "external", "component", ".", "External", "component", "should", "be", "load", "via", "js", "file", "and", "define", "properly", "." ]
f31c6674ff80999e29dd95375d4f3588bfdbad00
https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/jsVueService.php#L54-L57
train
atk4/ui
src/BreadCrumb.php
BreadCrumb.addCrumb
public function addCrumb($section = null, $link = null) { if (is_array($link)) { $link = $this->url($link); } $this->path[] = ['section'=>$section, 'link'=>$link, 'divider'=>$this->dividerClass]; }
php
public function addCrumb($section = null, $link = null) { if (is_array($link)) { $link = $this->url($link); } $this->path[] = ['section'=>$section, 'link'=>$link, 'divider'=>$this->dividerClass]; }
[ "public", "function", "addCrumb", "(", "$", "section", "=", "null", ",", "$", "link", "=", "null", ")", "{", "if", "(", "is_array", "(", "$", "link", ")", ")", "{", "$", "link", "=", "$", "this", "->", "url", "(", "$", "link", ")", ";", "}", "$", "this", "->", "path", "[", "]", "=", "[", "'section'", "=>", "$", "section", ",", "'link'", "=>", "$", "link", ",", "'divider'", "=>", "$", "this", "->", "dividerClass", "]", ";", "}" ]
Adds a new link that will appear on the right. @param string $section Title of link @param string|array $link Link itself
[ "Adds", "a", "new", "link", "that", "will", "appear", "on", "the", "right", "." ]
f31c6674ff80999e29dd95375d4f3588bfdbad00
https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/BreadCrumb.php#L30-L36
train
atk4/ui
src/BreadCrumb.php
BreadCrumb.addCrumbReverse
public function addCrumbReverse($section = null, $link = null) { array_unshift($this->path, ['section'=>$section, 'link'=>$link]); }
php
public function addCrumbReverse($section = null, $link = null) { array_unshift($this->path, ['section'=>$section, 'link'=>$link]); }
[ "public", "function", "addCrumbReverse", "(", "$", "section", "=", "null", ",", "$", "link", "=", "null", ")", "{", "array_unshift", "(", "$", "this", "->", "path", ",", "[", "'section'", "=>", "$", "section", ",", "'link'", "=>", "$", "link", "]", ")", ";", "}" ]
Adds a new link that will appear on the left. @param string $section Title of link @param string|array $link Link itself
[ "Adds", "a", "new", "link", "that", "will", "appear", "on", "the", "left", "." ]
f31c6674ff80999e29dd95375d4f3588bfdbad00
https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/BreadCrumb.php#L58-L61
train
atk4/ui
src/GridLayout.php
GridLayout.buildTemplate
protected function buildTemplate() { $this->t_wrap->del('rows'); $this->t_wrap->appendHTML('rows', '{rows}'); for ($row = 1; $row <= $this->rows; $row++) { $this->t_row->del('column'); for ($col = 1; $col <= $this->columns; $col++) { $this->t_col->set('Content', '{$r'.$row.'c'.$col.'}'); $this->t_row->appendHTML('column', $this->t_col->render()); } $this->t_wrap->appendHTML('rows', $this->t_row->render()); } $this->t_wrap->appendHTML('rows', '{/rows}'); $tmp = new Template($this->t_wrap->render()); $this->template->template['rows#1'] = $tmp->template['rows#1']; $this->template->rebuildTags(); $this->addClass($this->words[$this->columns].' column'); }
php
protected function buildTemplate() { $this->t_wrap->del('rows'); $this->t_wrap->appendHTML('rows', '{rows}'); for ($row = 1; $row <= $this->rows; $row++) { $this->t_row->del('column'); for ($col = 1; $col <= $this->columns; $col++) { $this->t_col->set('Content', '{$r'.$row.'c'.$col.'}'); $this->t_row->appendHTML('column', $this->t_col->render()); } $this->t_wrap->appendHTML('rows', $this->t_row->render()); } $this->t_wrap->appendHTML('rows', '{/rows}'); $tmp = new Template($this->t_wrap->render()); $this->template->template['rows#1'] = $tmp->template['rows#1']; $this->template->rebuildTags(); $this->addClass($this->words[$this->columns].' column'); }
[ "protected", "function", "buildTemplate", "(", ")", "{", "$", "this", "->", "t_wrap", "->", "del", "(", "'rows'", ")", ";", "$", "this", "->", "t_wrap", "->", "appendHTML", "(", "'rows'", ",", "'{rows}'", ")", ";", "for", "(", "$", "row", "=", "1", ";", "$", "row", "<=", "$", "this", "->", "rows", ";", "$", "row", "++", ")", "{", "$", "this", "->", "t_row", "->", "del", "(", "'column'", ")", ";", "for", "(", "$", "col", "=", "1", ";", "$", "col", "<=", "$", "this", "->", "columns", ";", "$", "col", "++", ")", "{", "$", "this", "->", "t_col", "->", "set", "(", "'Content'", ",", "'{$r'", ".", "$", "row", ".", "'c'", ".", "$", "col", ".", "'}'", ")", ";", "$", "this", "->", "t_row", "->", "appendHTML", "(", "'column'", ",", "$", "this", "->", "t_col", "->", "render", "(", ")", ")", ";", "}", "$", "this", "->", "t_wrap", "->", "appendHTML", "(", "'rows'", ",", "$", "this", "->", "t_row", "->", "render", "(", ")", ")", ";", "}", "$", "this", "->", "t_wrap", "->", "appendHTML", "(", "'rows'", ",", "'{/rows}'", ")", ";", "$", "tmp", "=", "new", "Template", "(", "$", "this", "->", "t_wrap", "->", "render", "(", ")", ")", ";", "$", "this", "->", "template", "->", "template", "[", "'rows#1'", "]", "=", "$", "tmp", "->", "template", "[", "'rows#1'", "]", ";", "$", "this", "->", "template", "->", "rebuildTags", "(", ")", ";", "$", "this", "->", "addClass", "(", "$", "this", "->", "words", "[", "$", "this", "->", "columns", "]", ".", "' column'", ")", ";", "}" ]
Build and set view template.
[ "Build", "and", "set", "view", "template", "." ]
f31c6674ff80999e29dd95375d4f3588bfdbad00
https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/GridLayout.php#L73-L96
train
atk4/ui
src/Console.php
Console.set
public function set($callback = null, $event = null) { if (!$callback) { throw new Exception('Please specify the $callback argument'); } if (isset($event)) { $this->event = $event; } $this->sse = $this->add('jsSSE'); $this->sse->set(function () use ($callback) { $this->sseInProgress = true; if (isset($this->app)) { $old_logger = $this->app->logger; $this->app->logger = $this; } try { ob_start(function ($content) { if ($this->_output_bypass) { return $content; } $output = ''; $this->sse->echoFunction = function ($str) use (&$output) { $output .= $str; }; $this->output($content); $this->sse->echoFunction = false; return $output; }, 2); call_user_func($callback, $this); } catch (\atk4\core\Exception $e) { $lines = explode("\n", $e->getHTMLText()); foreach ($lines as $line) { $this->outputHTML($line); } } catch (\Error $e) { $this->output('Error: '.$e->getMessage()); } catch (\Exception $e) { $this->output('Exception: '.$e->getMessage()); } if (isset($this->app)) { $this->app->logger = $old_logger; } $this->sseInProgress = false; }); if ($this->event) { $this->js($this->event, $this->jsExecute()); } return $this; }
php
public function set($callback = null, $event = null) { if (!$callback) { throw new Exception('Please specify the $callback argument'); } if (isset($event)) { $this->event = $event; } $this->sse = $this->add('jsSSE'); $this->sse->set(function () use ($callback) { $this->sseInProgress = true; if (isset($this->app)) { $old_logger = $this->app->logger; $this->app->logger = $this; } try { ob_start(function ($content) { if ($this->_output_bypass) { return $content; } $output = ''; $this->sse->echoFunction = function ($str) use (&$output) { $output .= $str; }; $this->output($content); $this->sse->echoFunction = false; return $output; }, 2); call_user_func($callback, $this); } catch (\atk4\core\Exception $e) { $lines = explode("\n", $e->getHTMLText()); foreach ($lines as $line) { $this->outputHTML($line); } } catch (\Error $e) { $this->output('Error: '.$e->getMessage()); } catch (\Exception $e) { $this->output('Exception: '.$e->getMessage()); } if (isset($this->app)) { $this->app->logger = $old_logger; } $this->sseInProgress = false; }); if ($this->event) { $this->js($this->event, $this->jsExecute()); } return $this; }
[ "public", "function", "set", "(", "$", "callback", "=", "null", ",", "$", "event", "=", "null", ")", "{", "if", "(", "!", "$", "callback", ")", "{", "throw", "new", "Exception", "(", "'Please specify the $callback argument'", ")", ";", "}", "if", "(", "isset", "(", "$", "event", ")", ")", "{", "$", "this", "->", "event", "=", "$", "event", ";", "}", "$", "this", "->", "sse", "=", "$", "this", "->", "add", "(", "'jsSSE'", ")", ";", "$", "this", "->", "sse", "->", "set", "(", "function", "(", ")", "use", "(", "$", "callback", ")", "{", "$", "this", "->", "sseInProgress", "=", "true", ";", "if", "(", "isset", "(", "$", "this", "->", "app", ")", ")", "{", "$", "old_logger", "=", "$", "this", "->", "app", "->", "logger", ";", "$", "this", "->", "app", "->", "logger", "=", "$", "this", ";", "}", "try", "{", "ob_start", "(", "function", "(", "$", "content", ")", "{", "if", "(", "$", "this", "->", "_output_bypass", ")", "{", "return", "$", "content", ";", "}", "$", "output", "=", "''", ";", "$", "this", "->", "sse", "->", "echoFunction", "=", "function", "(", "$", "str", ")", "use", "(", "&", "$", "output", ")", "{", "$", "output", ".=", "$", "str", ";", "}", ";", "$", "this", "->", "output", "(", "$", "content", ")", ";", "$", "this", "->", "sse", "->", "echoFunction", "=", "false", ";", "return", "$", "output", ";", "}", ",", "2", ")", ";", "call_user_func", "(", "$", "callback", ",", "$", "this", ")", ";", "}", "catch", "(", "\\", "atk4", "\\", "core", "\\", "Exception", "$", "e", ")", "{", "$", "lines", "=", "explode", "(", "\"\\n\"", ",", "$", "e", "->", "getHTMLText", "(", ")", ")", ";", "foreach", "(", "$", "lines", "as", "$", "line", ")", "{", "$", "this", "->", "outputHTML", "(", "$", "line", ")", ";", "}", "}", "catch", "(", "\\", "Error", "$", "e", ")", "{", "$", "this", "->", "output", "(", "'Error: '", ".", "$", "e", "->", "getMessage", "(", ")", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "$", "this", "->", "output", "(", "'Exception: '", ".", "$", "e", "->", "getMessage", "(", ")", ")", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "app", ")", ")", "{", "$", "this", "->", "app", "->", "logger", "=", "$", "old_logger", ";", "}", "$", "this", "->", "sseInProgress", "=", "false", ";", "}", ")", ";", "if", "(", "$", "this", "->", "event", ")", "{", "$", "this", "->", "js", "(", "$", "this", "->", "event", ",", "$", "this", "->", "jsExecute", "(", ")", ")", ";", "}", "return", "$", "this", ";", "}" ]
Set a callback method which will be executed with the output sent back to the terminal. Argument passed to your callback will be $this Console. You may perform calls to methods such as $console->output() $console->outputHTML() If you are using setModel, and if your model implements atk4\core\DebugTrait, then you you will see debug information generated by $this->debug() or $this->log(). This intercepts default application logging for the duration of the process. If you are using runCommand, then server command will be executed with it's output (STDOUT and STDERR) redirected to the console. While inside a callback you may execute runCommand or setModel multiple times. @param callable $callback callback which will be executed while displaying output inside console @param bool|string $event "true" would mean to execute on page load, string would indicate js event. See first argument for View::js() @return $this
[ "Set", "a", "callback", "method", "which", "will", "be", "executed", "with", "the", "output", "sent", "back", "to", "the", "terminal", "." ]
f31c6674ff80999e29dd95375d4f3588bfdbad00
https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/Console.php#L77-L137
train
atk4/ui
src/Console.php
Console.outputHTML
public function outputHTML($message, $context = []) { $message = preg_replace_callback('/{([a-z0-9_-]+)}/i', function ($match) use ($context) { if (isset($context[$match[1]]) && is_string($context[$match[1]])) { return $context[$match[1]]; } // don't change the original message return '{'.$match[1].'}'; }, $message); $this->_output_bypass = true; $this->sse->send($this->js()->append($message.'<br/>')); $this->_output_bypass = false; return $this; }
php
public function outputHTML($message, $context = []) { $message = preg_replace_callback('/{([a-z0-9_-]+)}/i', function ($match) use ($context) { if (isset($context[$match[1]]) && is_string($context[$match[1]])) { return $context[$match[1]]; } // don't change the original message return '{'.$match[1].'}'; }, $message); $this->_output_bypass = true; $this->sse->send($this->js()->append($message.'<br/>')); $this->_output_bypass = false; return $this; }
[ "public", "function", "outputHTML", "(", "$", "message", ",", "$", "context", "=", "[", "]", ")", "{", "$", "message", "=", "preg_replace_callback", "(", "'/{([a-z0-9_-]+)}/i'", ",", "function", "(", "$", "match", ")", "use", "(", "$", "context", ")", "{", "if", "(", "isset", "(", "$", "context", "[", "$", "match", "[", "1", "]", "]", ")", "&&", "is_string", "(", "$", "context", "[", "$", "match", "[", "1", "]", "]", ")", ")", "{", "return", "$", "context", "[", "$", "match", "[", "1", "]", "]", ";", "}", "// don't change the original message", "return", "'{'", ".", "$", "match", "[", "1", "]", ".", "'}'", ";", "}", ",", "$", "message", ")", ";", "$", "this", "->", "_output_bypass", "=", "true", ";", "$", "this", "->", "sse", "->", "send", "(", "$", "this", "->", "js", "(", ")", "->", "append", "(", "$", "message", ".", "'<br/>'", ")", ")", ";", "$", "this", "->", "_output_bypass", "=", "false", ";", "return", "$", "this", ";", "}" ]
Output un-escaped HTML line. Use this to send HTML. @todo Use $message as template and fill values from $context in there. @param string $message @param array $context @return $this
[ "Output", "un", "-", "escaped", "HTML", "line", ".", "Use", "this", "to", "send", "HTML", "." ]
f31c6674ff80999e29dd95375d4f3588bfdbad00
https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/Console.php#L174-L190
train
atk4/ui
src/Console.php
Console.send
public function send($js) { $this->_output_bypass = true; $this->sse->send($js); $this->_output_bypass = false; return $this; }
php
public function send($js) { $this->_output_bypass = true; $this->sse->send($js); $this->_output_bypass = false; return $this; }
[ "public", "function", "send", "(", "$", "js", ")", "{", "$", "this", "->", "_output_bypass", "=", "true", ";", "$", "this", "->", "sse", "->", "send", "(", "$", "js", ")", ";", "$", "this", "->", "_output_bypass", "=", "false", ";", "return", "$", "this", ";", "}" ]
Executes a JavaScript action. @param jsExpressionable $js @return $this
[ "Executes", "a", "JavaScript", "action", "." ]
f31c6674ff80999e29dd95375d4f3588bfdbad00
https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/Console.php#L206-L213
train
atk4/ui
src/Console.php
Console.exec
public function exec($exec, $args = []) { if (!$this->sseInProgress) { $this->set(function () use ($exec, $args) { $a = $args ? (' with '.count($args).' arguments') : ''; $this->output('--[ Executing '.$exec.$a.' ]--------------'); $this->exec($exec, $args); $this->output('--[ Exit code: '.$this->last_exit_code.' ]------------'); }); return; } list($proc, $pipes) = $this->execRaw($exec, $args); stream_set_blocking($pipes[1], false); stream_set_blocking($pipes[2], false); // $pipes contain streams that are still open and not EOF while ($pipes) { $read = $pipes; $j1 = $j2 = null; if (stream_select($read, $j1, $j2, 2) === false) { throw new Exception(['stream_select() returned false.']); } $stat = proc_get_status($proc); if (!$stat['running']) { proc_close($proc); break; } foreach ($read as $f) { $data = fgets($f); $data = rtrim($data); if (!$data) { continue; } if ($f === $pipes[2]) { // STDERR $this->warning($data); } else { // STDOUT $this->output($data); } } } $this->last_exit_code = $stat['exitcode']; return $this->last_exit_code ? false : $this; }
php
public function exec($exec, $args = []) { if (!$this->sseInProgress) { $this->set(function () use ($exec, $args) { $a = $args ? (' with '.count($args).' arguments') : ''; $this->output('--[ Executing '.$exec.$a.' ]--------------'); $this->exec($exec, $args); $this->output('--[ Exit code: '.$this->last_exit_code.' ]------------'); }); return; } list($proc, $pipes) = $this->execRaw($exec, $args); stream_set_blocking($pipes[1], false); stream_set_blocking($pipes[2], false); // $pipes contain streams that are still open and not EOF while ($pipes) { $read = $pipes; $j1 = $j2 = null; if (stream_select($read, $j1, $j2, 2) === false) { throw new Exception(['stream_select() returned false.']); } $stat = proc_get_status($proc); if (!$stat['running']) { proc_close($proc); break; } foreach ($read as $f) { $data = fgets($f); $data = rtrim($data); if (!$data) { continue; } if ($f === $pipes[2]) { // STDERR $this->warning($data); } else { // STDOUT $this->output($data); } } } $this->last_exit_code = $stat['exitcode']; return $this->last_exit_code ? false : $this; }
[ "public", "function", "exec", "(", "$", "exec", ",", "$", "args", "=", "[", "]", ")", "{", "if", "(", "!", "$", "this", "->", "sseInProgress", ")", "{", "$", "this", "->", "set", "(", "function", "(", ")", "use", "(", "$", "exec", ",", "$", "args", ")", "{", "$", "a", "=", "$", "args", "?", "(", "' with '", ".", "count", "(", "$", "args", ")", ".", "' arguments'", ")", ":", "''", ";", "$", "this", "->", "output", "(", "'--[ Executing '", ".", "$", "exec", ".", "$", "a", ".", "' ]--------------'", ")", ";", "$", "this", "->", "exec", "(", "$", "exec", ",", "$", "args", ")", ";", "$", "this", "->", "output", "(", "'--[ Exit code: '", ".", "$", "this", "->", "last_exit_code", ".", "' ]------------'", ")", ";", "}", ")", ";", "return", ";", "}", "list", "(", "$", "proc", ",", "$", "pipes", ")", "=", "$", "this", "->", "execRaw", "(", "$", "exec", ",", "$", "args", ")", ";", "stream_set_blocking", "(", "$", "pipes", "[", "1", "]", ",", "false", ")", ";", "stream_set_blocking", "(", "$", "pipes", "[", "2", "]", ",", "false", ")", ";", "// $pipes contain streams that are still open and not EOF", "while", "(", "$", "pipes", ")", "{", "$", "read", "=", "$", "pipes", ";", "$", "j1", "=", "$", "j2", "=", "null", ";", "if", "(", "stream_select", "(", "$", "read", ",", "$", "j1", ",", "$", "j2", ",", "2", ")", "===", "false", ")", "{", "throw", "new", "Exception", "(", "[", "'stream_select() returned false.'", "]", ")", ";", "}", "$", "stat", "=", "proc_get_status", "(", "$", "proc", ")", ";", "if", "(", "!", "$", "stat", "[", "'running'", "]", ")", "{", "proc_close", "(", "$", "proc", ")", ";", "break", ";", "}", "foreach", "(", "$", "read", "as", "$", "f", ")", "{", "$", "data", "=", "fgets", "(", "$", "f", ")", ";", "$", "data", "=", "rtrim", "(", "$", "data", ")", ";", "if", "(", "!", "$", "data", ")", "{", "continue", ";", "}", "if", "(", "$", "f", "===", "$", "pipes", "[", "2", "]", ")", "{", "// STDERR", "$", "this", "->", "warning", "(", "$", "data", ")", ";", "}", "else", "{", "// STDOUT", "$", "this", "->", "output", "(", "$", "data", ")", ";", "}", "}", "}", "$", "this", "->", "last_exit_code", "=", "$", "stat", "[", "'exitcode'", "]", ";", "return", "$", "this", "->", "last_exit_code", "?", "false", ":", "$", "this", ";", "}" ]
Executes command passing along escaped arguments. Will also stream stdout / stderr as the comand executes. once command terminates method will return the exit code. This method can be executed from inside callback or without it. Example: runCommand('ping', ['-c', '5', '8.8.8.8']); All arguments are escaped.
[ "Executes", "command", "passing", "along", "escaped", "arguments", "." ]
f31c6674ff80999e29dd95375d4f3588bfdbad00
https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/Console.php#L230-L283
train
atk4/ui
src/Popup.php
Popup.set
public function set($fx = null, $arg2 = null) { if (!is_object($fx) && !($fx instanceof Closure)) { throw new Exception('Error: Need to pass a function to Popup::set()'); } if ($arg2) { throw new Exception('Only one argument is needed by Popup::set()'); } $this->cb = $this->add('Callback'); if (!$this->minWidth) { $this->minWidth = '120px'; } if (!$this->minHeight) { $this->minHeight = '60px'; } if ($this->cb->triggered()) { //create content view to pass to callback. $content = $this->add($this->dynamicContent); $this->cb->set($fx, [$content]); //only render our content view. //PopupService will replace content with this one. $this->app->terminate($content->renderJSON()); } }
php
public function set($fx = null, $arg2 = null) { if (!is_object($fx) && !($fx instanceof Closure)) { throw new Exception('Error: Need to pass a function to Popup::set()'); } if ($arg2) { throw new Exception('Only one argument is needed by Popup::set()'); } $this->cb = $this->add('Callback'); if (!$this->minWidth) { $this->minWidth = '120px'; } if (!$this->minHeight) { $this->minHeight = '60px'; } if ($this->cb->triggered()) { //create content view to pass to callback. $content = $this->add($this->dynamicContent); $this->cb->set($fx, [$content]); //only render our content view. //PopupService will replace content with this one. $this->app->terminate($content->renderJSON()); } }
[ "public", "function", "set", "(", "$", "fx", "=", "null", ",", "$", "arg2", "=", "null", ")", "{", "if", "(", "!", "is_object", "(", "$", "fx", ")", "&&", "!", "(", "$", "fx", "instanceof", "Closure", ")", ")", "{", "throw", "new", "Exception", "(", "'Error: Need to pass a function to Popup::set()'", ")", ";", "}", "if", "(", "$", "arg2", ")", "{", "throw", "new", "Exception", "(", "'Only one argument is needed by Popup::set()'", ")", ";", "}", "$", "this", "->", "cb", "=", "$", "this", "->", "add", "(", "'Callback'", ")", ";", "if", "(", "!", "$", "this", "->", "minWidth", ")", "{", "$", "this", "->", "minWidth", "=", "'120px'", ";", "}", "if", "(", "!", "$", "this", "->", "minHeight", ")", "{", "$", "this", "->", "minHeight", "=", "'60px'", ";", "}", "if", "(", "$", "this", "->", "cb", "->", "triggered", "(", ")", ")", "{", "//create content view to pass to callback.", "$", "content", "=", "$", "this", "->", "add", "(", "$", "this", "->", "dynamicContent", ")", ";", "$", "this", "->", "cb", "->", "set", "(", "$", "fx", ",", "[", "$", "content", "]", ")", ";", "//only render our content view.", "//PopupService will replace content with this one.", "$", "this", "->", "app", "->", "terminate", "(", "$", "content", "->", "renderJSON", "(", ")", ")", ";", "}", "}" ]
Set callback for loading content dynamically. Callback will reveive a view attach to this popup for adding content to it. @param $fx @throws Exception
[ "Set", "callback", "for", "loading", "content", "dynamically", ".", "Callback", "will", "reveive", "a", "view", "attach", "to", "this", "popup", "for", "adding", "content", "to", "it", "." ]
f31c6674ff80999e29dd95375d4f3588bfdbad00
https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/Popup.php#L165-L193
train
atk4/ui
src/Popup.php
Popup.jsPopup
public function jsPopup() { $name = $this->triggerBy; if (!is_string($this->triggerBy)) { $name = '#'.$this->triggerBy->name; if ($this->triggerBy instanceof FormField\Generic) { $name = '#'.$this->triggerBy->name.'_input'; } } $chain = new jQuery($name); $chain->popup($this->popOptions); if ($this->stopClickEvent) { $chain->on('click', new jsExpression('function(e){e.stopPropagation();}')); } return $chain; }
php
public function jsPopup() { $name = $this->triggerBy; if (!is_string($this->triggerBy)) { $name = '#'.$this->triggerBy->name; if ($this->triggerBy instanceof FormField\Generic) { $name = '#'.$this->triggerBy->name.'_input'; } } $chain = new jQuery($name); $chain->popup($this->popOptions); if ($this->stopClickEvent) { $chain->on('click', new jsExpression('function(e){e.stopPropagation();}')); } return $chain; }
[ "public", "function", "jsPopup", "(", ")", "{", "$", "name", "=", "$", "this", "->", "triggerBy", ";", "if", "(", "!", "is_string", "(", "$", "this", "->", "triggerBy", ")", ")", "{", "$", "name", "=", "'#'", ".", "$", "this", "->", "triggerBy", "->", "name", ";", "if", "(", "$", "this", "->", "triggerBy", "instanceof", "FormField", "\\", "Generic", ")", "{", "$", "name", "=", "'#'", ".", "$", "this", "->", "triggerBy", "->", "name", ".", "'_input'", ";", "}", "}", "$", "chain", "=", "new", "jQuery", "(", "$", "name", ")", ";", "$", "chain", "->", "popup", "(", "$", "this", "->", "popOptions", ")", ";", "if", "(", "$", "this", "->", "stopClickEvent", ")", "{", "$", "chain", "->", "on", "(", "'click'", ",", "new", "jsExpression", "(", "'function(e){e.stopPropagation();}'", ")", ")", ";", "}", "return", "$", "chain", ";", "}" ]
Return js action need to display popup. When a grid is reloading, this method can be call in order to display the popup once again. @return jQuery
[ "Return", "js", "action", "need", "to", "display", "popup", ".", "When", "a", "grid", "is", "reloading", "this", "method", "can", "be", "call", "in", "order", "to", "display", "the", "popup", "once", "again", "." ]
f31c6674ff80999e29dd95375d4f3588bfdbad00
https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/Popup.php#L273-L289
train
atk4/ui
src/FormField/UploadImg.php
UploadImg.setThumbnailSrc
public function setThumbnailSrc($src) { $this->thumbnail->setAttr(['src' => $src]); $action = $this->thumbnail->js(); $action->attr('src', $src); $this->addJSAction($action); }
php
public function setThumbnailSrc($src) { $this->thumbnail->setAttr(['src' => $src]); $action = $this->thumbnail->js(); $action->attr('src', $src); $this->addJSAction($action); }
[ "public", "function", "setThumbnailSrc", "(", "$", "src", ")", "{", "$", "this", "->", "thumbnail", "->", "setAttr", "(", "[", "'src'", "=>", "$", "src", "]", ")", ";", "$", "action", "=", "$", "this", "->", "thumbnail", "->", "js", "(", ")", ";", "$", "action", "->", "attr", "(", "'src'", ",", "$", "src", ")", ";", "$", "this", "->", "addJSAction", "(", "$", "action", ")", ";", "}" ]
Set the thumbnail img src value. @param string $src
[ "Set", "the", "thumbnail", "img", "src", "value", "." ]
f31c6674ff80999e29dd95375d4f3588bfdbad00
https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/FormField/UploadImg.php#L56-L62
train
atk4/ui
src/FormField/UploadImg.php
UploadImg.clearThumbnail
public function clearThumbnail($defaultThumbnail = null) { $action = $this->thumbnail->js(); if (isset($defaultThumbnail)) { $action->attr('src', $defaultThumbnail); } else { $action->removeAttr('src'); } $this->addJSAction($action); }
php
public function clearThumbnail($defaultThumbnail = null) { $action = $this->thumbnail->js(); if (isset($defaultThumbnail)) { $action->attr('src', $defaultThumbnail); } else { $action->removeAttr('src'); } $this->addJSAction($action); }
[ "public", "function", "clearThumbnail", "(", "$", "defaultThumbnail", "=", "null", ")", "{", "$", "action", "=", "$", "this", "->", "thumbnail", "->", "js", "(", ")", ";", "if", "(", "isset", "(", "$", "defaultThumbnail", ")", ")", "{", "$", "action", "->", "attr", "(", "'src'", ",", "$", "defaultThumbnail", ")", ";", "}", "else", "{", "$", "action", "->", "removeAttr", "(", "'src'", ")", ";", "}", "$", "this", "->", "addJSAction", "(", "$", "action", ")", ";", "}" ]
Clear the thumbnail src. You can also supply a default thumbnail src. @param null $defaultThumbnail
[ "Clear", "the", "thumbnail", "src", ".", "You", "can", "also", "supply", "a", "default", "thumbnail", "src", "." ]
f31c6674ff80999e29dd95375d4f3588bfdbad00
https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/FormField/UploadImg.php#L70-L79
train
atk4/ui
src/jsChain.php
jsChain._renderArgs
private function _renderArgs($args = []) { return '('. implode(',', array_map(function ($arg) { if ($arg instanceof jsExpressionable) { return $arg->jsRender(); } return $this->_json_encode($arg); }, $args)). ')'; }
php
private function _renderArgs($args = []) { return '('. implode(',', array_map(function ($arg) { if ($arg instanceof jsExpressionable) { return $arg->jsRender(); } return $this->_json_encode($arg); }, $args)). ')'; }
[ "private", "function", "_renderArgs", "(", "$", "args", "=", "[", "]", ")", "{", "return", "'('", ".", "implode", "(", "','", ",", "array_map", "(", "function", "(", "$", "arg", ")", "{", "if", "(", "$", "arg", "instanceof", "jsExpressionable", ")", "{", "return", "$", "arg", "->", "jsRender", "(", ")", ";", "}", "return", "$", "this", "->", "_json_encode", "(", "$", "arg", ")", ";", "}", ",", "$", "args", ")", ")", ".", "')'", ";", "}" ]
Renders JS chain arguments. @param array $args @return string
[ "Renders", "JS", "chain", "arguments", "." ]
f31c6674ff80999e29dd95375d4f3588bfdbad00
https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/jsChain.php#L144-L155
train
atk4/ui
src/jsChain.php
jsChain.jsRender
public function jsRender() { $ret = ''; // start with constructor $ret .= $this->_library; // next perhaps we have arguments if ($this->_constructorArgs) { $ret .= $this->_renderArgs($this->_constructorArgs); } // next we do same with the calls foreach ($this->_chain as $chain) { if (is_array($chain)) { $ret .= '.'.$chain[0].$this->_renderArgs($chain[1]); } elseif (is_numeric($chain)) { $ret .= '['.$chain.']'; } else { $ret .= '.'.$chain; } } return $ret; }
php
public function jsRender() { $ret = ''; // start with constructor $ret .= $this->_library; // next perhaps we have arguments if ($this->_constructorArgs) { $ret .= $this->_renderArgs($this->_constructorArgs); } // next we do same with the calls foreach ($this->_chain as $chain) { if (is_array($chain)) { $ret .= '.'.$chain[0].$this->_renderArgs($chain[1]); } elseif (is_numeric($chain)) { $ret .= '['.$chain.']'; } else { $ret .= '.'.$chain; } } return $ret; }
[ "public", "function", "jsRender", "(", ")", "{", "$", "ret", "=", "''", ";", "// start with constructor", "$", "ret", ".=", "$", "this", "->", "_library", ";", "// next perhaps we have arguments", "if", "(", "$", "this", "->", "_constructorArgs", ")", "{", "$", "ret", ".=", "$", "this", "->", "_renderArgs", "(", "$", "this", "->", "_constructorArgs", ")", ";", "}", "// next we do same with the calls", "foreach", "(", "$", "this", "->", "_chain", "as", "$", "chain", ")", "{", "if", "(", "is_array", "(", "$", "chain", ")", ")", "{", "$", "ret", ".=", "'.'", ".", "$", "chain", "[", "0", "]", ".", "$", "this", "->", "_renderArgs", "(", "$", "chain", "[", "1", "]", ")", ";", "}", "elseif", "(", "is_numeric", "(", "$", "chain", ")", ")", "{", "$", "ret", ".=", "'['", ".", "$", "chain", ".", "']'", ";", "}", "else", "{", "$", "ret", ".=", "'.'", ".", "$", "chain", ";", "}", "}", "return", "$", "ret", ";", "}" ]
Produce String representing this JavaScript extension. @return string
[ "Produce", "String", "representing", "this", "JavaScript", "extension", "." ]
f31c6674ff80999e29dd95375d4f3588bfdbad00
https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/jsChain.php#L162-L186
train
atk4/ui
src/jsCallback.php
jsCallback.flatternArray
public function flatternArray($response) { if (!is_array($response)) { return [$response]; } $out = []; foreach ($response as $element) { $out = array_merge($out, $this->flatternArray($element)); } return $out; }
php
public function flatternArray($response) { if (!is_array($response)) { return [$response]; } $out = []; foreach ($response as $element) { $out = array_merge($out, $this->flatternArray($element)); } return $out; }
[ "public", "function", "flatternArray", "(", "$", "response", ")", "{", "if", "(", "!", "is_array", "(", "$", "response", ")", ")", "{", "return", "[", "$", "response", "]", ";", "}", "$", "out", "=", "[", "]", ";", "foreach", "(", "$", "response", "as", "$", "element", ")", "{", "$", "out", "=", "array_merge", "(", "$", "out", ",", "$", "this", "->", "flatternArray", "(", "$", "element", ")", ")", ";", "}", "return", "$", "out", ";", "}" ]
When multiple jsExpressionable's are collected inside an array and may have some degree of nesting, convert it into a one-dimensional array, so that it's easier for us to wrap it into a function body. @param [type] $response [description] @return [type] [description]
[ "When", "multiple", "jsExpressionable", "s", "are", "collected", "inside", "an", "array", "and", "may", "have", "some", "degree", "of", "nesting", "convert", "it", "into", "a", "one", "-", "dimensional", "array", "so", "that", "it", "s", "easier", "for", "us", "to", "wrap", "it", "into", "a", "function", "body", "." ]
f31c6674ff80999e29dd95375d4f3588bfdbad00
https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/jsCallback.php#L30-L43
train
atk4/ui
src/jsCallback.php
jsCallback.terminate
public function terminate($ajaxec, $msg = null, $success = true) { $this->app->terminate(json_encode(['success' => $success, 'message' => $msg, 'atkjs' => $ajaxec])); }
php
public function terminate($ajaxec, $msg = null, $success = true) { $this->app->terminate(json_encode(['success' => $success, 'message' => $msg, 'atkjs' => $ajaxec])); }
[ "public", "function", "terminate", "(", "$", "ajaxec", ",", "$", "msg", "=", "null", ",", "$", "success", "=", "true", ")", "{", "$", "this", "->", "app", "->", "terminate", "(", "json_encode", "(", "[", "'success'", "=>", "$", "success", ",", "'message'", "=>", "$", "msg", ",", "'atkjs'", "=>", "$", "ajaxec", "]", ")", ")", ";", "}" ]
A proper way to finish execution of AJAX response. Generates JSON which is returned to frontend. @param array|jsExpressionable $ajaxec Array of jsExpressionable @param string $msg General message, typically won't be displayed @param bool $success Was request successful or not @return [type] [description]
[ "A", "proper", "way", "to", "finish", "execution", "of", "AJAX", "response", ".", "Generates", "JSON", "which", "is", "returned", "to", "frontend", "." ]
f31c6674ff80999e29dd95375d4f3588bfdbad00
https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/jsCallback.php#L115-L118
train
atk4/ui
src/Loader.php
Loader.set
public function set($fx = [], $args = null) { if (!is_callable($fx)) { throw new Exception('Error: Need to pass a callable function to Loader::set()'); } $this->cb->set(function () use ($fx) { call_user_func($fx, $this); $this->app->terminate($this->renderJSON()); }); return $this; }
php
public function set($fx = [], $args = null) { if (!is_callable($fx)) { throw new Exception('Error: Need to pass a callable function to Loader::set()'); } $this->cb->set(function () use ($fx) { call_user_func($fx, $this); $this->app->terminate($this->renderJSON()); }); return $this; }
[ "public", "function", "set", "(", "$", "fx", "=", "[", "]", ",", "$", "args", "=", "null", ")", "{", "if", "(", "!", "is_callable", "(", "$", "fx", ")", ")", "{", "throw", "new", "Exception", "(", "'Error: Need to pass a callable function to Loader::set()'", ")", ";", "}", "$", "this", "->", "cb", "->", "set", "(", "function", "(", ")", "use", "(", "$", "fx", ")", "{", "call_user_func", "(", "$", "fx", ",", "$", "this", ")", ";", "$", "this", "->", "app", "->", "terminate", "(", "$", "this", "->", "renderJSON", "(", ")", ")", ";", "}", ")", ";", "return", "$", "this", ";", "}" ]
Set callback function for this loader. The loader view is pass as an argument to the loader callback function. This allow to easily update the loader view content within the callback. $l1 = $layout->add('Loader'); $l1->set(function ($loader_view) { do_long_processing_action(); $loader_view->set('new content'); }); Or $l1->set([$my_object, 'run_long_process']); NOTE: default values are like that due ot PHP 7.0 warning: Declaration of atk4\ui\Loader::set($fx, $args = Array) should be compatible with atk4\ui\View::set($arg1 = Array, $arg2 = NULL) @param callable $fx @param array $args @throws Exception @return $this
[ "Set", "callback", "function", "for", "this", "loader", "." ]
f31c6674ff80999e29dd95375d4f3588bfdbad00
https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/Loader.php#L72-L84
train
atk4/ui
src/Loader.php
Loader.renderView
public function renderView() { if (!$this->cb->triggered()) { if ($this->loadEvent) { $this->js($this->loadEvent, $this->jsLoad()); } $this->add($this->shim); } return parent::renderView(); }
php
public function renderView() { if (!$this->cb->triggered()) { if ($this->loadEvent) { $this->js($this->loadEvent, $this->jsLoad()); } $this->add($this->shim); } return parent::renderView(); }
[ "public", "function", "renderView", "(", ")", "{", "if", "(", "!", "$", "this", "->", "cb", "->", "triggered", "(", ")", ")", "{", "if", "(", "$", "this", "->", "loadEvent", ")", "{", "$", "this", "->", "js", "(", "$", "this", "->", "loadEvent", ",", "$", "this", "->", "jsLoad", "(", ")", ")", ";", "}", "$", "this", "->", "add", "(", "$", "this", "->", "shim", ")", ";", "}", "return", "parent", "::", "renderView", "(", ")", ";", "}" ]
Automatically call the jsLoad on a supplied event unless it was already triggered or if user have invoked jsLoad manually.
[ "Automatically", "call", "the", "jsLoad", "on", "a", "supplied", "event", "unless", "it", "was", "already", "triggered", "or", "if", "user", "have", "invoked", "jsLoad", "manually", "." ]
f31c6674ff80999e29dd95375d4f3588bfdbad00
https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/Loader.php#L90-L100
train
atk4/ui
src/Accordion.php
Accordion.addSection
public function addSection($title, $callback = null, $icon = 'dropdown') { $section = $this->add(['AccordionSection', 'title' => $title, 'icon' => $icon]); // if there is callback action, then use VirtualPage if ($callback) { $section->virtualPage = $section->add(['VirtualPage', 'ui' => '']); $section->virtualPage->stickyGet('__atk-dyn-section', '1'); $section->virtualPage->set($callback); } $this->sections[] = $section; return $section; }
php
public function addSection($title, $callback = null, $icon = 'dropdown') { $section = $this->add(['AccordionSection', 'title' => $title, 'icon' => $icon]); // if there is callback action, then use VirtualPage if ($callback) { $section->virtualPage = $section->add(['VirtualPage', 'ui' => '']); $section->virtualPage->stickyGet('__atk-dyn-section', '1'); $section->virtualPage->set($callback); } $this->sections[] = $section; return $section; }
[ "public", "function", "addSection", "(", "$", "title", ",", "$", "callback", "=", "null", ",", "$", "icon", "=", "'dropdown'", ")", "{", "$", "section", "=", "$", "this", "->", "add", "(", "[", "'AccordionSection'", ",", "'title'", "=>", "$", "title", ",", "'icon'", "=>", "$", "icon", "]", ")", ";", "// if there is callback action, then use VirtualPage", "if", "(", "$", "callback", ")", "{", "$", "section", "->", "virtualPage", "=", "$", "section", "->", "add", "(", "[", "'VirtualPage'", ",", "'ui'", "=>", "''", "]", ")", ";", "$", "section", "->", "virtualPage", "->", "stickyGet", "(", "'__atk-dyn-section'", ",", "'1'", ")", ";", "$", "section", "->", "virtualPage", "->", "set", "(", "$", "callback", ")", ";", "}", "$", "this", "->", "sections", "[", "]", "=", "$", "section", ";", "return", "$", "section", ";", "}" ]
Add an accordion section. You can add static View within your section or pass a callback for dynamic content. @param string $title @param null|callable $callback @param string $icon @throws Exception @return AccordionSection
[ "Add", "an", "accordion", "section", ".", "You", "can", "add", "static", "View", "within", "your", "section", "or", "pass", "a", "callback", "for", "dynamic", "content", "." ]
f31c6674ff80999e29dd95375d4f3588bfdbad00
https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/Accordion.php#L58-L72
train
atk4/ui
src/Accordion.php
Accordion.getSectionIdx
public function getSectionIdx($section) { $idx = -1; foreach ($this->sections as $key => $accordion_section) { if ($accordion_section->name === $section->name) { $idx = $key; break; } } return $idx; }
php
public function getSectionIdx($section) { $idx = -1; foreach ($this->sections as $key => $accordion_section) { if ($accordion_section->name === $section->name) { $idx = $key; break; } } return $idx; }
[ "public", "function", "getSectionIdx", "(", "$", "section", ")", "{", "$", "idx", "=", "-", "1", ";", "foreach", "(", "$", "this", "->", "sections", "as", "$", "key", "=>", "$", "accordion_section", ")", "{", "if", "(", "$", "accordion_section", "->", "name", "===", "$", "section", "->", "name", ")", "{", "$", "idx", "=", "$", "key", ";", "break", ";", "}", "}", "return", "$", "idx", ";", "}" ]
Return the index of an accordion section in collection. @param AccordionSection $section @return int
[ "Return", "the", "index", "of", "an", "accordion", "section", "in", "collection", "." ]
f31c6674ff80999e29dd95375d4f3588bfdbad00
https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/Accordion.php#L136-L147
train
atk4/ui
src/Menu.php
Menu.addMenu
public function addMenu($name) { if (is_array($name)) { $label = $name[0]; unset($name[0]); } else { $label = $name; $name = []; } $sub_menu = $this->add([new self(), 'defaultTemplate' => 'submenu.html', 'ui' => 'dropdown', 'in_dropdown' => true]); $sub_menu->set('label', $label); if (isset($name['icon']) && $name['icon']) { $sub_menu->add(new Icon($name['icon']), 'Icon')->removeClass('item'); } if (!$this->in_dropdown) { $sub_menu->js(true)->dropdown(['on' => 'hover', 'action' => 'hide']); } return $sub_menu; }
php
public function addMenu($name) { if (is_array($name)) { $label = $name[0]; unset($name[0]); } else { $label = $name; $name = []; } $sub_menu = $this->add([new self(), 'defaultTemplate' => 'submenu.html', 'ui' => 'dropdown', 'in_dropdown' => true]); $sub_menu->set('label', $label); if (isset($name['icon']) && $name['icon']) { $sub_menu->add(new Icon($name['icon']), 'Icon')->removeClass('item'); } if (!$this->in_dropdown) { $sub_menu->js(true)->dropdown(['on' => 'hover', 'action' => 'hide']); } return $sub_menu; }
[ "public", "function", "addMenu", "(", "$", "name", ")", "{", "if", "(", "is_array", "(", "$", "name", ")", ")", "{", "$", "label", "=", "$", "name", "[", "0", "]", ";", "unset", "(", "$", "name", "[", "0", "]", ")", ";", "}", "else", "{", "$", "label", "=", "$", "name", ";", "$", "name", "=", "[", "]", ";", "}", "$", "sub_menu", "=", "$", "this", "->", "add", "(", "[", "new", "self", "(", ")", ",", "'defaultTemplate'", "=>", "'submenu.html'", ",", "'ui'", "=>", "'dropdown'", ",", "'in_dropdown'", "=>", "true", "]", ")", ";", "$", "sub_menu", "->", "set", "(", "'label'", ",", "$", "label", ")", ";", "if", "(", "isset", "(", "$", "name", "[", "'icon'", "]", ")", "&&", "$", "name", "[", "'icon'", "]", ")", "{", "$", "sub_menu", "->", "add", "(", "new", "Icon", "(", "$", "name", "[", "'icon'", "]", ")", ",", "'Icon'", ")", "->", "removeClass", "(", "'item'", ")", ";", "}", "if", "(", "!", "$", "this", "->", "in_dropdown", ")", "{", "$", "sub_menu", "->", "js", "(", "true", ")", "->", "dropdown", "(", "[", "'on'", "=>", "'hover'", ",", "'action'", "=>", "'hide'", "]", ")", ";", "}", "return", "$", "sub_menu", ";", "}" ]
Adds sub-menu. @param string|array $name @return Menu
[ "Adds", "sub", "-", "menu", "." ]
f31c6674ff80999e29dd95375d4f3588bfdbad00
https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/Menu.php#L88-L110
train
atk4/ui
src/Menu.php
Menu.addGroup
public function addGroup($title) { $group = $this->add([new self(), 'defaultTemplate' => 'menugroup.html', 'ui' => false]); if (is_string($title)) { $group->set('title', $title); } else { if (isset($title['icon']) && $title['icon']) { $group->add(new Icon($title['icon']), 'Icon')->removeClass('item'); } $group->set('title', $title[0]); } return $group; }
php
public function addGroup($title) { $group = $this->add([new self(), 'defaultTemplate' => 'menugroup.html', 'ui' => false]); if (is_string($title)) { $group->set('title', $title); } else { if (isset($title['icon']) && $title['icon']) { $group->add(new Icon($title['icon']), 'Icon')->removeClass('item'); } $group->set('title', $title[0]); } return $group; }
[ "public", "function", "addGroup", "(", "$", "title", ")", "{", "$", "group", "=", "$", "this", "->", "add", "(", "[", "new", "self", "(", ")", ",", "'defaultTemplate'", "=>", "'menugroup.html'", ",", "'ui'", "=>", "false", "]", ")", ";", "if", "(", "is_string", "(", "$", "title", ")", ")", "{", "$", "group", "->", "set", "(", "'title'", ",", "$", "title", ")", ";", "}", "else", "{", "if", "(", "isset", "(", "$", "title", "[", "'icon'", "]", ")", "&&", "$", "title", "[", "'icon'", "]", ")", "{", "$", "group", "->", "add", "(", "new", "Icon", "(", "$", "title", "[", "'icon'", "]", ")", ",", "'Icon'", ")", "->", "removeClass", "(", "'item'", ")", ";", "}", "$", "group", "->", "set", "(", "'title'", ",", "$", "title", "[", "0", "]", ")", ";", "}", "return", "$", "group", ";", "}" ]
Adds menu group. @param string|array $title @return Menu
[ "Adds", "menu", "group", "." ]
f31c6674ff80999e29dd95375d4f3588bfdbad00
https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/Menu.php#L119-L132
train
atk4/ui
src/Menu.php
Menu.addMenuRight
public function addMenuRight() { $menu = $this->add([new self(), 'ui' => false], 'RightMenu'); $menu->removeClass('item')->addClass('right menu'); return $menu; }
php
public function addMenuRight() { $menu = $this->add([new self(), 'ui' => false], 'RightMenu'); $menu->removeClass('item')->addClass('right menu'); return $menu; }
[ "public", "function", "addMenuRight", "(", ")", "{", "$", "menu", "=", "$", "this", "->", "add", "(", "[", "new", "self", "(", ")", ",", "'ui'", "=>", "false", "]", ",", "'RightMenu'", ")", ";", "$", "menu", "->", "removeClass", "(", "'item'", ")", "->", "addClass", "(", "'right menu'", ")", ";", "return", "$", "menu", ";", "}" ]
Add right positioned menu. @return Menu
[ "Add", "right", "positioned", "menu", "." ]
f31c6674ff80999e29dd95375d4f3588bfdbad00
https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/Menu.php#L139-L145
train
atk4/ui
src/Menu.php
Menu.add
public function add($object, $region = null) { $item = parent::add($object, $region); $item->addClass('item'); return $item; }
php
public function add($object, $region = null) { $item = parent::add($object, $region); $item->addClass('item'); return $item; }
[ "public", "function", "add", "(", "$", "object", ",", "$", "region", "=", "null", ")", "{", "$", "item", "=", "parent", "::", "add", "(", "$", "object", ",", "$", "region", ")", ";", "$", "item", "->", "addClass", "(", "'item'", ")", ";", "return", "$", "item", ";", "}" ]
Add Item. @param View|string $object New object to add @param string|array $region (or array for full set of defaults) @return View
[ "Add", "Item", "." ]
f31c6674ff80999e29dd95375d4f3588bfdbad00
https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/Menu.php#L155-L161
train
atk4/ui
src/CRUD.php
CRUD.setModel
public function setModel(\atk4\data\Model $m, $defaultFields = null) { if ($defaultFields !== null) { $this->fieldsDefault = $defaultFields; } parent::setModel($m, $this->fieldsRead ?: $this->fieldsDefault); $this->model->unload(); if ($this->canCreate) { $this->initCreate(); } if ($this->canUpdate) { $this->initUpdate(); } if ($this->canDelete) { $this->initDelete(); } return $this->model; }
php
public function setModel(\atk4\data\Model $m, $defaultFields = null) { if ($defaultFields !== null) { $this->fieldsDefault = $defaultFields; } parent::setModel($m, $this->fieldsRead ?: $this->fieldsDefault); $this->model->unload(); if ($this->canCreate) { $this->initCreate(); } if ($this->canUpdate) { $this->initUpdate(); } if ($this->canDelete) { $this->initDelete(); } return $this->model; }
[ "public", "function", "setModel", "(", "\\", "atk4", "\\", "data", "\\", "Model", "$", "m", ",", "$", "defaultFields", "=", "null", ")", "{", "if", "(", "$", "defaultFields", "!==", "null", ")", "{", "$", "this", "->", "fieldsDefault", "=", "$", "defaultFields", ";", "}", "parent", "::", "setModel", "(", "$", "m", ",", "$", "this", "->", "fieldsRead", "?", ":", "$", "this", "->", "fieldsDefault", ")", ";", "$", "this", "->", "model", "->", "unload", "(", ")", ";", "if", "(", "$", "this", "->", "canCreate", ")", "{", "$", "this", "->", "initCreate", "(", ")", ";", "}", "if", "(", "$", "this", "->", "canUpdate", ")", "{", "$", "this", "->", "initUpdate", "(", ")", ";", "}", "if", "(", "$", "this", "->", "canDelete", ")", "{", "$", "this", "->", "initDelete", "(", ")", ";", "}", "return", "$", "this", "->", "model", ";", "}" ]
Sets data model of CRUD. @param \atk4\data\Model $m @param array $defaultFields @return \atk4\data\Model
[ "Sets", "data", "model", "of", "CRUD", "." ]
f31c6674ff80999e29dd95375d4f3588bfdbad00
https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/CRUD.php#L103-L125
train
atk4/ui
src/CRUD.php
CRUD.initCreate
public function initCreate() { // setting itemCreate manually is possible. if (!$this->itemCreate) { $this->itemCreate = $this->menu->addItem($this->itemCreate ?: ['Add new', 'icon' => 'plus']); $this->itemCreate->on('click.atk_CRUD', new jsModal('Add new', $this->pageCreate, [$this->name.'_sort' => $this->getSortBy()])); $this->itemCreate->set('Add New '.$this->model->getModelCaption()); } // setting callback for the page $this->pageCreate->set(function () { // formCreate may already be an object added inside pageCreate if (!is_object($this->formCreate) || !$this->formCreate->_initialized) { $this->formCreate = $this->pageCreate->add($this->formCreate ?: $this->formDefault); } // $form = $page->add($this->formCreate ?: ['Form', 'layout' => 'FormLayout/Columns']); $this->formCreate->setModel($this->model, $this->fieldsCreate ?: $this->fieldsDefault); if ($sortBy = $this->getSortBy()) { $this->formCreate->stickyGet($this->name.'_sort', $sortBy); } // set save handler with reload trigger // adds default submit hook if it is not already set for this form if (!$this->formCreate->hookHasCallbacks('submit')) { $this->formCreate->onSubmit(function ($form) { $form->model->save(); return $this->jsSaveCreate(); }); } }); }
php
public function initCreate() { // setting itemCreate manually is possible. if (!$this->itemCreate) { $this->itemCreate = $this->menu->addItem($this->itemCreate ?: ['Add new', 'icon' => 'plus']); $this->itemCreate->on('click.atk_CRUD', new jsModal('Add new', $this->pageCreate, [$this->name.'_sort' => $this->getSortBy()])); $this->itemCreate->set('Add New '.$this->model->getModelCaption()); } // setting callback for the page $this->pageCreate->set(function () { // formCreate may already be an object added inside pageCreate if (!is_object($this->formCreate) || !$this->formCreate->_initialized) { $this->formCreate = $this->pageCreate->add($this->formCreate ?: $this->formDefault); } // $form = $page->add($this->formCreate ?: ['Form', 'layout' => 'FormLayout/Columns']); $this->formCreate->setModel($this->model, $this->fieldsCreate ?: $this->fieldsDefault); if ($sortBy = $this->getSortBy()) { $this->formCreate->stickyGet($this->name.'_sort', $sortBy); } // set save handler with reload trigger // adds default submit hook if it is not already set for this form if (!$this->formCreate->hookHasCallbacks('submit')) { $this->formCreate->onSubmit(function ($form) { $form->model->save(); return $this->jsSaveCreate(); }); } }); }
[ "public", "function", "initCreate", "(", ")", "{", "// setting itemCreate manually is possible.", "if", "(", "!", "$", "this", "->", "itemCreate", ")", "{", "$", "this", "->", "itemCreate", "=", "$", "this", "->", "menu", "->", "addItem", "(", "$", "this", "->", "itemCreate", "?", ":", "[", "'Add new'", ",", "'icon'", "=>", "'plus'", "]", ")", ";", "$", "this", "->", "itemCreate", "->", "on", "(", "'click.atk_CRUD'", ",", "new", "jsModal", "(", "'Add new'", ",", "$", "this", "->", "pageCreate", ",", "[", "$", "this", "->", "name", ".", "'_sort'", "=>", "$", "this", "->", "getSortBy", "(", ")", "]", ")", ")", ";", "$", "this", "->", "itemCreate", "->", "set", "(", "'Add New '", ".", "$", "this", "->", "model", "->", "getModelCaption", "(", ")", ")", ";", "}", "// setting callback for the page", "$", "this", "->", "pageCreate", "->", "set", "(", "function", "(", ")", "{", "// formCreate may already be an object added inside pageCreate", "if", "(", "!", "is_object", "(", "$", "this", "->", "formCreate", ")", "||", "!", "$", "this", "->", "formCreate", "->", "_initialized", ")", "{", "$", "this", "->", "formCreate", "=", "$", "this", "->", "pageCreate", "->", "add", "(", "$", "this", "->", "formCreate", "?", ":", "$", "this", "->", "formDefault", ")", ";", "}", "// $form = $page->add($this->formCreate ?: ['Form', 'layout' => 'FormLayout/Columns']);", "$", "this", "->", "formCreate", "->", "setModel", "(", "$", "this", "->", "model", ",", "$", "this", "->", "fieldsCreate", "?", ":", "$", "this", "->", "fieldsDefault", ")", ";", "if", "(", "$", "sortBy", "=", "$", "this", "->", "getSortBy", "(", ")", ")", "{", "$", "this", "->", "formCreate", "->", "stickyGet", "(", "$", "this", "->", "name", ".", "'_sort'", ",", "$", "sortBy", ")", ";", "}", "// set save handler with reload trigger", "// adds default submit hook if it is not already set for this form", "if", "(", "!", "$", "this", "->", "formCreate", "->", "hookHasCallbacks", "(", "'submit'", ")", ")", "{", "$", "this", "->", "formCreate", "->", "onSubmit", "(", "function", "(", "$", "form", ")", "{", "$", "form", "->", "model", "->", "save", "(", ")", ";", "return", "$", "this", "->", "jsSaveCreate", "(", ")", ";", "}", ")", ";", "}", "}", ")", ";", "}" ]
Initializes interface elements for new record creation. @return array|jsExpression
[ "Initializes", "interface", "elements", "for", "new", "record", "creation", "." ]
f31c6674ff80999e29dd95375d4f3588bfdbad00
https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/CRUD.php#L132-L166
train
atk4/ui
src/CRUD.php
CRUD.initUpdate
public function initUpdate() { $this->addAction(['icon' => 'edit'], new jsModal('Edit', $this->pageUpdate, [$this->name => $this->jsRow()->data('id'), $this->name.'_sort' => $this->getSortBy()])); $this->pageUpdate->set(function () { $this->model->load($this->app->stickyGet($this->name)); // Maybe developer has already created form if (!is_object($this->formUpdate) || !$this->formUpdate->_initialized) { $this->formUpdate = $this->pageUpdate->add($this->formUpdate ?: $this->formDefault); } $this->formUpdate->setModel($this->model, $this->fieldsUpdate ?: $this->fieldsDefault); if ($sortBy = $this->getSortBy()) { $this->formUpdate->stickyGet($this->name.'_sort', $sortBy); } // set save handler with reload trigger // adds default submit hook if it is not already set for this form if (!$this->formUpdate->hookHasCallbacks('submit')) { $this->formUpdate->onSubmit(function ($form) { $form->model->save(); return $this->jsSaveUpdate(); }); } }); }
php
public function initUpdate() { $this->addAction(['icon' => 'edit'], new jsModal('Edit', $this->pageUpdate, [$this->name => $this->jsRow()->data('id'), $this->name.'_sort' => $this->getSortBy()])); $this->pageUpdate->set(function () { $this->model->load($this->app->stickyGet($this->name)); // Maybe developer has already created form if (!is_object($this->formUpdate) || !$this->formUpdate->_initialized) { $this->formUpdate = $this->pageUpdate->add($this->formUpdate ?: $this->formDefault); } $this->formUpdate->setModel($this->model, $this->fieldsUpdate ?: $this->fieldsDefault); if ($sortBy = $this->getSortBy()) { $this->formUpdate->stickyGet($this->name.'_sort', $sortBy); } // set save handler with reload trigger // adds default submit hook if it is not already set for this form if (!$this->formUpdate->hookHasCallbacks('submit')) { $this->formUpdate->onSubmit(function ($form) { $form->model->save(); return $this->jsSaveUpdate(); }); } }); }
[ "public", "function", "initUpdate", "(", ")", "{", "$", "this", "->", "addAction", "(", "[", "'icon'", "=>", "'edit'", "]", ",", "new", "jsModal", "(", "'Edit'", ",", "$", "this", "->", "pageUpdate", ",", "[", "$", "this", "->", "name", "=>", "$", "this", "->", "jsRow", "(", ")", "->", "data", "(", "'id'", ")", ",", "$", "this", "->", "name", ".", "'_sort'", "=>", "$", "this", "->", "getSortBy", "(", ")", "]", ")", ")", ";", "$", "this", "->", "pageUpdate", "->", "set", "(", "function", "(", ")", "{", "$", "this", "->", "model", "->", "load", "(", "$", "this", "->", "app", "->", "stickyGet", "(", "$", "this", "->", "name", ")", ")", ";", "// Maybe developer has already created form", "if", "(", "!", "is_object", "(", "$", "this", "->", "formUpdate", ")", "||", "!", "$", "this", "->", "formUpdate", "->", "_initialized", ")", "{", "$", "this", "->", "formUpdate", "=", "$", "this", "->", "pageUpdate", "->", "add", "(", "$", "this", "->", "formUpdate", "?", ":", "$", "this", "->", "formDefault", ")", ";", "}", "$", "this", "->", "formUpdate", "->", "setModel", "(", "$", "this", "->", "model", ",", "$", "this", "->", "fieldsUpdate", "?", ":", "$", "this", "->", "fieldsDefault", ")", ";", "if", "(", "$", "sortBy", "=", "$", "this", "->", "getSortBy", "(", ")", ")", "{", "$", "this", "->", "formUpdate", "->", "stickyGet", "(", "$", "this", "->", "name", ".", "'_sort'", ",", "$", "sortBy", ")", ";", "}", "// set save handler with reload trigger", "// adds default submit hook if it is not already set for this form", "if", "(", "!", "$", "this", "->", "formUpdate", "->", "hookHasCallbacks", "(", "'submit'", ")", ")", "{", "$", "this", "->", "formUpdate", "->", "onSubmit", "(", "function", "(", "$", "form", ")", "{", "$", "form", "->", "model", "->", "save", "(", ")", ";", "return", "$", "this", "->", "jsSaveUpdate", "(", ")", ";", "}", ")", ";", "}", "}", ")", ";", "}" ]
Initializes interface elements for editing records. @return array|jsExpression
[ "Initializes", "interface", "elements", "for", "editing", "records", "." ]
f31c6674ff80999e29dd95375d4f3588bfdbad00
https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/CRUD.php#L203-L231
train
atk4/ui
src/CRUD.php
CRUD.jsSave
public function jsSave($notifier) { return [ // close modal new jsExpression('$(".atk-dialog-content").trigger("close")'), // display notification $this->factory($notifier), // reload Grid Container. $this->container->jsReload([$this->name.'_sort' => $this->getSortBy()]), ]; }
php
public function jsSave($notifier) { return [ // close modal new jsExpression('$(".atk-dialog-content").trigger("close")'), // display notification $this->factory($notifier), // reload Grid Container. $this->container->jsReload([$this->name.'_sort' => $this->getSortBy()]), ]; }
[ "public", "function", "jsSave", "(", "$", "notifier", ")", "{", "return", "[", "// close modal", "new", "jsExpression", "(", "'$(\".atk-dialog-content\").trigger(\"close\")'", ")", ",", "// display notification", "$", "this", "->", "factory", "(", "$", "notifier", ")", ",", "// reload Grid Container.", "$", "this", "->", "container", "->", "jsReload", "(", "[", "$", "this", "->", "name", ".", "'_sort'", "=>", "$", "this", "->", "getSortBy", "(", ")", "]", ")", ",", "]", ";", "}" ]
Default js action when saving form. @throws \atk4\core\Exception @return array
[ "Default", "js", "action", "when", "saving", "form", "." ]
f31c6674ff80999e29dd95375d4f3588bfdbad00
https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/CRUD.php#L251-L263
train
atk4/ui
src/CRUD.php
CRUD.initDelete
public function initDelete() { $this->addAction(['icon' => 'red trash'], function ($jschain, $id) { $this->model->load($id)->delete(); return $jschain->closest('tr')->transition('fade left'); }, 'Are you sure?'); }
php
public function initDelete() { $this->addAction(['icon' => 'red trash'], function ($jschain, $id) { $this->model->load($id)->delete(); return $jschain->closest('tr')->transition('fade left'); }, 'Are you sure?'); }
[ "public", "function", "initDelete", "(", ")", "{", "$", "this", "->", "addAction", "(", "[", "'icon'", "=>", "'red trash'", "]", ",", "function", "(", "$", "jschain", ",", "$", "id", ")", "{", "$", "this", "->", "model", "->", "load", "(", "$", "id", ")", "->", "delete", "(", ")", ";", "return", "$", "jschain", "->", "closest", "(", "'tr'", ")", "->", "transition", "(", "'fade left'", ")", ";", "}", ",", "'Are you sure?'", ")", ";", "}" ]
Initialize UI for deleting records.
[ "Initialize", "UI", "for", "deleting", "records", "." ]
f31c6674ff80999e29dd95375d4f3588bfdbad00
https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/CRUD.php#L268-L275
train
atk4/ui
src/FormField/Upload.php
Upload.set
public function set($fileId = null, $fileName = null, $junk = null) { $this->setFileId($fileId); if (!$fileName) { $fileName = $fileId; } return $this->setInput($fileName, $junk); }
php
public function set($fileId = null, $fileName = null, $junk = null) { $this->setFileId($fileId); if (!$fileName) { $fileName = $fileId; } return $this->setInput($fileName, $junk); }
[ "public", "function", "set", "(", "$", "fileId", "=", "null", ",", "$", "fileName", "=", "null", ",", "$", "junk", "=", "null", ")", "{", "$", "this", "->", "setFileId", "(", "$", "fileId", ")", ";", "if", "(", "!", "$", "fileName", ")", "{", "$", "fileName", "=", "$", "fileId", ";", "}", "return", "$", "this", "->", "setInput", "(", "$", "fileName", ",", "$", "junk", ")", ";", "}" ]
Allow to set file id and file name - fileId will be the file id sent with onDelete callback. - fileName is the field value display to user. @param string $fileId // Field id for onDelete Callback. @param string|null $fileName // Field name display to user. @param mixed $junk @return $this|void
[ "Allow", "to", "set", "file", "id", "and", "file", "name", "-", "fileId", "will", "be", "the", "file", "id", "sent", "with", "onDelete", "callback", ".", "-", "fileName", "is", "the", "field", "value", "display", "to", "user", "." ]
f31c6674ff80999e29dd95375d4f3588bfdbad00
https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/FormField/Upload.php#L105-L114
train