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
guzzle/cache-subscriber
src/CacheStorage.php
CacheStorage.deleteVary
private function deleteVary(RequestInterface $request) { $key = $this->getVaryKey($request); $this->cache->delete($key); }
php
private function deleteVary(RequestInterface $request) { $key = $this->getVaryKey($request); $this->cache->delete($key); }
[ "private", "function", "deleteVary", "(", "RequestInterface", "$", "request", ")", "{", "$", "key", "=", "$", "this", "->", "getVaryKey", "(", "$", "request", ")", ";", "$", "this", "->", "cache", "->", "delete", "(", "$", "key", ")", ";", "}" ]
Delete the headers associated with a Vary request. @param RequestInterface $request The Request to delete headers for.
[ "Delete", "the", "headers", "associated", "with", "a", "Vary", "request", "." ]
1377567481d6d96224c9bd66aac475fbfbeec776
https://github.com/guzzle/cache-subscriber/blob/1377567481d6d96224c9bd66aac475fbfbeec776/src/CacheStorage.php#L384-L388
train
guzzle/cache-subscriber
src/CacheStorage.php
CacheStorage.getVaryKey
private function getVaryKey(RequestInterface $request) { $key = $this->keyPrefix . md5('vary ' . $this->getCacheKey($request)); return $key; }
php
private function getVaryKey(RequestInterface $request) { $key = $this->keyPrefix . md5('vary ' . $this->getCacheKey($request)); return $key; }
[ "private", "function", "getVaryKey", "(", "RequestInterface", "$", "request", ")", "{", "$", "key", "=", "$", "this", "->", "keyPrefix", ".", "md5", "(", "'vary '", ".", "$", "this", "->", "getCacheKey", "(", "$", "request", ")", ")", ";", "return", "$...
Get the cache key for Vary headers. @param RequestInterface $request The Request to fetch the key for. @return string The generated key.
[ "Get", "the", "cache", "key", "for", "Vary", "headers", "." ]
1377567481d6d96224c9bd66aac475fbfbeec776
https://github.com/guzzle/cache-subscriber/blob/1377567481d6d96224c9bd66aac475fbfbeec776/src/CacheStorage.php#L397-L402
train
guzzle/cache-subscriber
src/CacheSubscriber.php
CacheSubscriber.attach
public static function attach( HasEmitterInterface $subject, array $options = [] ) { if (!isset($options['storage'])) { $options['storage'] = new CacheStorage(new ArrayCache()); } if (!isset($options['can_cache'])) { $options['can_cache'] = [ 'GuzzleHttp\Subscriber\Cache\Utils', 'canCacheRequest', ]; } $emitter = $subject->getEmitter(); $cache = new self($options['storage'], $options['can_cache']); $emitter->attach($cache); if (!isset($options['validate']) || $options['validate'] === true) { $emitter->attach(new ValidationSubscriber( $options['storage'], $options['can_cache']) ); } if (!isset($options['purge']) || $options['purge'] === true) { $emitter->attach(new PurgeSubscriber($options['storage'])); } return ['subscriber' => $cache, 'storage' => $options['storage']]; }
php
public static function attach( HasEmitterInterface $subject, array $options = [] ) { if (!isset($options['storage'])) { $options['storage'] = new CacheStorage(new ArrayCache()); } if (!isset($options['can_cache'])) { $options['can_cache'] = [ 'GuzzleHttp\Subscriber\Cache\Utils', 'canCacheRequest', ]; } $emitter = $subject->getEmitter(); $cache = new self($options['storage'], $options['can_cache']); $emitter->attach($cache); if (!isset($options['validate']) || $options['validate'] === true) { $emitter->attach(new ValidationSubscriber( $options['storage'], $options['can_cache']) ); } if (!isset($options['purge']) || $options['purge'] === true) { $emitter->attach(new PurgeSubscriber($options['storage'])); } return ['subscriber' => $cache, 'storage' => $options['storage']]; }
[ "public", "static", "function", "attach", "(", "HasEmitterInterface", "$", "subject", ",", "array", "$", "options", "=", "[", "]", ")", "{", "if", "(", "!", "isset", "(", "$", "options", "[", "'storage'", "]", ")", ")", "{", "$", "options", "[", "'st...
Helper method used to easily attach a cache to a request or client. This method accepts an array of options that are used to control the caching behavior: - storage: An optional GuzzleHttp\Subscriber\Cache\CacheStorageInterface. If no value is not provided, an in-memory array cache will be used. - validate: Boolean value that determines if cached response are ever validated against the origin server. Defaults to true but can be disabled by passing false. - purge: Boolean value that determines if cached responses are purged when non-idempotent requests are sent to their URI. Defaults to true but can be disabled by passing false. - can_cache: An optional callable used to determine if a request can be cached. The callable accepts a RequestInterface and returns a boolean value. If no value is provided, the default behavior is utilized. @param HasEmitterInterface $subject Client or request to attach to, @param array $options Options used to control the cache. @return array Returns an associative array containing a 'subscriber' key that holds the created CacheSubscriber, and a 'storage' key that contains the cache storage used by the subscriber.
[ "Helper", "method", "used", "to", "easily", "attach", "a", "cache", "to", "a", "request", "or", "client", "." ]
1377567481d6d96224c9bd66aac475fbfbeec776
https://github.com/guzzle/cache-subscriber/blob/1377567481d6d96224c9bd66aac475fbfbeec776/src/CacheSubscriber.php#L77-L108
train
guzzle/cache-subscriber
src/CacheSubscriber.php
CacheSubscriber.onBefore
public function onBefore(BeforeEvent $event) { $request = $event->getRequest(); if (!$this->canCacheRequest($request)) { $this->cacheMiss($request); return; } if (!($response = $this->storage->fetch($request))) { $this->cacheMiss($request); return; } $response->setHeader('Age', Utils::getResponseAge($response)); $valid = $this->validate($request, $response); // Validate that the response satisfies the request if ($valid) { $request->getConfig()->set('cache_lookup', 'HIT'); $request->getConfig()->set('cache_hit', true); $event->intercept($response); } else { $this->cacheMiss($request); } }
php
public function onBefore(BeforeEvent $event) { $request = $event->getRequest(); if (!$this->canCacheRequest($request)) { $this->cacheMiss($request); return; } if (!($response = $this->storage->fetch($request))) { $this->cacheMiss($request); return; } $response->setHeader('Age', Utils::getResponseAge($response)); $valid = $this->validate($request, $response); // Validate that the response satisfies the request if ($valid) { $request->getConfig()->set('cache_lookup', 'HIT'); $request->getConfig()->set('cache_hit', true); $event->intercept($response); } else { $this->cacheMiss($request); } }
[ "public", "function", "onBefore", "(", "BeforeEvent", "$", "event", ")", "{", "$", "request", "=", "$", "event", "->", "getRequest", "(", ")", ";", "if", "(", "!", "$", "this", "->", "canCacheRequest", "(", "$", "request", ")", ")", "{", "$", "this",...
Checks if a request can be cached, and if so, intercepts with a cached response is available. @param BeforeEvent $event
[ "Checks", "if", "a", "request", "can", "be", "cached", "and", "if", "so", "intercepts", "with", "a", "cached", "response", "is", "available", "." ]
1377567481d6d96224c9bd66aac475fbfbeec776
https://github.com/guzzle/cache-subscriber/blob/1377567481d6d96224c9bd66aac475fbfbeec776/src/CacheSubscriber.php#L125-L150
train
guzzle/cache-subscriber
src/CacheSubscriber.php
CacheSubscriber.onComplete
public function onComplete(CompleteEvent $event) { $request = $event->getRequest(); $response = $event->getResponse(); // Cache the response if it can be cached and isn't already if ($request->getConfig()->get('cache_lookup') === 'MISS' && call_user_func($this->canCache, $request) && Utils::canCacheResponse($response) ) { // Store the date when the response was cached $response->setHeader('X-Guzzle-Cache-Date', gmdate('D, d M Y H:i:s T', time())); $this->storage->cache($request, $response); } $this->addResponseHeaders($request, $response); }
php
public function onComplete(CompleteEvent $event) { $request = $event->getRequest(); $response = $event->getResponse(); // Cache the response if it can be cached and isn't already if ($request->getConfig()->get('cache_lookup') === 'MISS' && call_user_func($this->canCache, $request) && Utils::canCacheResponse($response) ) { // Store the date when the response was cached $response->setHeader('X-Guzzle-Cache-Date', gmdate('D, d M Y H:i:s T', time())); $this->storage->cache($request, $response); } $this->addResponseHeaders($request, $response); }
[ "public", "function", "onComplete", "(", "CompleteEvent", "$", "event", ")", "{", "$", "request", "=", "$", "event", "->", "getRequest", "(", ")", ";", "$", "response", "=", "$", "event", "->", "getResponse", "(", ")", ";", "// Cache the response if it can b...
Checks if the request and response can be cached, and if so, store it. @param CompleteEvent $event
[ "Checks", "if", "the", "request", "and", "response", "can", "be", "cached", "and", "if", "so", "store", "it", "." ]
1377567481d6d96224c9bd66aac475fbfbeec776
https://github.com/guzzle/cache-subscriber/blob/1377567481d6d96224c9bd66aac475fbfbeec776/src/CacheSubscriber.php#L157-L173
train
guzzle/cache-subscriber
src/CacheSubscriber.php
CacheSubscriber.onError
public function onError(ErrorEvent $event) { $request = $event->getRequest(); if (!call_user_func($this->canCache, $request)) { return; } $response = $this->storage->fetch($request); // Intercept the failed response if possible if ($response && $this->validateFailed($request, $response)) { $request->getConfig()->set('cache_hit', 'error'); $response->setHeader('Age', Utils::getResponseAge($response)); $event->intercept($response); } }
php
public function onError(ErrorEvent $event) { $request = $event->getRequest(); if (!call_user_func($this->canCache, $request)) { return; } $response = $this->storage->fetch($request); // Intercept the failed response if possible if ($response && $this->validateFailed($request, $response)) { $request->getConfig()->set('cache_hit', 'error'); $response->setHeader('Age', Utils::getResponseAge($response)); $event->intercept($response); } }
[ "public", "function", "onError", "(", "ErrorEvent", "$", "event", ")", "{", "$", "request", "=", "$", "event", "->", "getRequest", "(", ")", ";", "if", "(", "!", "call_user_func", "(", "$", "this", "->", "canCache", ",", "$", "request", ")", ")", "{"...
If the request failed, then check if a cached response would suffice. @param ErrorEvent $event
[ "If", "the", "request", "failed", "then", "check", "if", "a", "cached", "response", "would", "suffice", "." ]
1377567481d6d96224c9bd66aac475fbfbeec776
https://github.com/guzzle/cache-subscriber/blob/1377567481d6d96224c9bd66aac475fbfbeec776/src/CacheSubscriber.php#L180-L196
train
guzzle/cache-subscriber
src/Utils.php
Utils.getDirective
public static function getDirective(MessageInterface $message, $part) { $parts = AbstractMessage::parseHeader($message, 'Cache-Control'); foreach ($parts as $line) { if (isset($line[$part])) { return $line[$part]; } elseif (in_array($part, $line)) { return true; } } return null; }
php
public static function getDirective(MessageInterface $message, $part) { $parts = AbstractMessage::parseHeader($message, 'Cache-Control'); foreach ($parts as $line) { if (isset($line[$part])) { return $line[$part]; } elseif (in_array($part, $line)) { return true; } } return null; }
[ "public", "static", "function", "getDirective", "(", "MessageInterface", "$", "message", ",", "$", "part", ")", "{", "$", "parts", "=", "AbstractMessage", "::", "parseHeader", "(", "$", "message", ",", "'Cache-Control'", ")", ";", "foreach", "(", "$", "parts...
Get a cache control directive from a message. @param MessageInterface $message Message to retrieve @param string $part Cache directive to retrieve @return mixed|bool|null
[ "Get", "a", "cache", "control", "directive", "from", "a", "message", "." ]
1377567481d6d96224c9bd66aac475fbfbeec776
https://github.com/guzzle/cache-subscriber/blob/1377567481d6d96224c9bd66aac475fbfbeec776/src/Utils.php#L22-L35
train
guzzle/cache-subscriber
src/Utils.php
Utils.getResponseAge
public static function getResponseAge(ResponseInterface $response) { if ($response->hasHeader('Age')) { return (int) $response->getHeader('Age'); } $date = strtotime($response->getHeader('Date') ?: 'now'); return time() - $date; }
php
public static function getResponseAge(ResponseInterface $response) { if ($response->hasHeader('Age')) { return (int) $response->getHeader('Age'); } $date = strtotime($response->getHeader('Date') ?: 'now'); return time() - $date; }
[ "public", "static", "function", "getResponseAge", "(", "ResponseInterface", "$", "response", ")", "{", "if", "(", "$", "response", "->", "hasHeader", "(", "'Age'", ")", ")", "{", "return", "(", "int", ")", "$", "response", "->", "getHeader", "(", "'Age'", ...
Gets the age of a response in seconds. @param ResponseInterface $response @return int
[ "Gets", "the", "age", "of", "a", "response", "in", "seconds", "." ]
1377567481d6d96224c9bd66aac475fbfbeec776
https://github.com/guzzle/cache-subscriber/blob/1377567481d6d96224c9bd66aac475fbfbeec776/src/Utils.php#L44-L53
train
guzzle/cache-subscriber
src/Utils.php
Utils.getMaxAge
public static function getMaxAge(ResponseInterface $response) { $smaxage = Utils::getDirective($response, 's-maxage'); if (is_numeric($smaxage)) { return (int) $smaxage; } $maxage = Utils::getDirective($response, 'max-age'); if (is_numeric($maxage)) { return (int) $maxage; } if ($response->hasHeader('Expires')) { return strtotime($response->getHeader('Expires')) - time(); } return null; }
php
public static function getMaxAge(ResponseInterface $response) { $smaxage = Utils::getDirective($response, 's-maxage'); if (is_numeric($smaxage)) { return (int) $smaxage; } $maxage = Utils::getDirective($response, 'max-age'); if (is_numeric($maxage)) { return (int) $maxage; } if ($response->hasHeader('Expires')) { return strtotime($response->getHeader('Expires')) - time(); } return null; }
[ "public", "static", "function", "getMaxAge", "(", "ResponseInterface", "$", "response", ")", "{", "$", "smaxage", "=", "Utils", "::", "getDirective", "(", "$", "response", ",", "'s-maxage'", ")", ";", "if", "(", "is_numeric", "(", "$", "smaxage", ")", ")",...
Gets the number of seconds from the current time in which a response is still considered fresh. @param ResponseInterface $response @return int|null Returns the number of seconds
[ "Gets", "the", "number", "of", "seconds", "from", "the", "current", "time", "in", "which", "a", "response", "is", "still", "considered", "fresh", "." ]
1377567481d6d96224c9bd66aac475fbfbeec776
https://github.com/guzzle/cache-subscriber/blob/1377567481d6d96224c9bd66aac475fbfbeec776/src/Utils.php#L63-L80
train
guzzle/cache-subscriber
src/Utils.php
Utils.getFreshness
public static function getFreshness(ResponseInterface $response) { $maxAge = self::getMaxAge($response); $age = self::getResponseAge($response); return is_int($maxAge) && is_int($age) ? ($maxAge - $age) : null; }
php
public static function getFreshness(ResponseInterface $response) { $maxAge = self::getMaxAge($response); $age = self::getResponseAge($response); return is_int($maxAge) && is_int($age) ? ($maxAge - $age) : null; }
[ "public", "static", "function", "getFreshness", "(", "ResponseInterface", "$", "response", ")", "{", "$", "maxAge", "=", "self", "::", "getMaxAge", "(", "$", "response", ")", ";", "$", "age", "=", "self", "::", "getResponseAge", "(", "$", "response", ")", ...
Get the freshness of a response by returning the difference of the maximum lifetime of the response and the age of the response. Freshness values less than 0 mean that the response is no longer fresh and is ABS(freshness) seconds expired. Freshness values of greater than zero is the number of seconds until the response is no longer fresh. A NULL result means that no freshness information is available. @param ResponseInterface $response Response to get freshness of @return int|null
[ "Get", "the", "freshness", "of", "a", "response", "by", "returning", "the", "difference", "of", "the", "maximum", "lifetime", "of", "the", "response", "and", "the", "age", "of", "the", "response", "." ]
1377567481d6d96224c9bd66aac475fbfbeec776
https://github.com/guzzle/cache-subscriber/blob/1377567481d6d96224c9bd66aac475fbfbeec776/src/Utils.php#L95-L101
train
guzzle/cache-subscriber
src/Utils.php
Utils.canCacheRequest
public static function canCacheRequest(RequestInterface $request) { $method = $request->getMethod(); // Only GET and HEAD requests can be cached if ($method !== 'GET' && $method !== 'HEAD') { return false; } // Don't fool with Range requests for now if ($request->hasHeader('Range')) { return false; } return self::getDirective($request, 'no-store') === null; }
php
public static function canCacheRequest(RequestInterface $request) { $method = $request->getMethod(); // Only GET and HEAD requests can be cached if ($method !== 'GET' && $method !== 'HEAD') { return false; } // Don't fool with Range requests for now if ($request->hasHeader('Range')) { return false; } return self::getDirective($request, 'no-store') === null; }
[ "public", "static", "function", "canCacheRequest", "(", "RequestInterface", "$", "request", ")", "{", "$", "method", "=", "$", "request", "->", "getMethod", "(", ")", ";", "// Only GET and HEAD requests can be cached", "if", "(", "$", "method", "!==", "'GET'", "...
Default function used to determine if a request can be cached. @param RequestInterface $request Request to check @return bool
[ "Default", "function", "used", "to", "determine", "if", "a", "request", "can", "be", "cached", "." ]
1377567481d6d96224c9bd66aac475fbfbeec776
https://github.com/guzzle/cache-subscriber/blob/1377567481d6d96224c9bd66aac475fbfbeec776/src/Utils.php#L110-L125
train
guzzle/cache-subscriber
src/Utils.php
Utils.canCacheResponse
public static function canCacheResponse(ResponseInterface $response) { static $cacheCodes = [200, 203, 300, 301, 410]; // Check if the response is cacheable based on the code if (!in_array((int) $response->getStatusCode(), $cacheCodes)) { return false; } // Make sure a valid body was returned and can be cached $body = $response->getBody(); if ($body && (!$body->isReadable() || !$body->isSeekable())) { return false; } // Never cache no-store resources (this is a private cache, so private // can be cached) if (self::getDirective($response, 'no-store')) { return false; } // Don't fool with Content-Range requests for now if ($response->hasHeader('Content-Range')) { return false; } $freshness = self::getFreshness($response); return $freshness === null // No freshness info. || $freshness >= 0 // It's fresh || $response->hasHeader('ETag') // Can validate || $response->hasHeader('Last-Modified'); // Can validate }
php
public static function canCacheResponse(ResponseInterface $response) { static $cacheCodes = [200, 203, 300, 301, 410]; // Check if the response is cacheable based on the code if (!in_array((int) $response->getStatusCode(), $cacheCodes)) { return false; } // Make sure a valid body was returned and can be cached $body = $response->getBody(); if ($body && (!$body->isReadable() || !$body->isSeekable())) { return false; } // Never cache no-store resources (this is a private cache, so private // can be cached) if (self::getDirective($response, 'no-store')) { return false; } // Don't fool with Content-Range requests for now if ($response->hasHeader('Content-Range')) { return false; } $freshness = self::getFreshness($response); return $freshness === null // No freshness info. || $freshness >= 0 // It's fresh || $response->hasHeader('ETag') // Can validate || $response->hasHeader('Last-Modified'); // Can validate }
[ "public", "static", "function", "canCacheResponse", "(", "ResponseInterface", "$", "response", ")", "{", "static", "$", "cacheCodes", "=", "[", "200", ",", "203", ",", "300", ",", "301", ",", "410", "]", ";", "// Check if the response is cacheable based on the cod...
Determines if a response can be cached. @param ResponseInterface $response Response to check @return bool
[ "Determines", "if", "a", "response", "can", "be", "cached", "." ]
1377567481d6d96224c9bd66aac475fbfbeec776
https://github.com/guzzle/cache-subscriber/blob/1377567481d6d96224c9bd66aac475fbfbeec776/src/Utils.php#L134-L166
train
guzzle/cache-subscriber
src/ValidationSubscriber.php
ValidationSubscriber.handleBadResponse
private function handleBadResponse(BadResponseException $e) { if (isset(self::$gone[$e->getResponse()->getStatusCode()])) { $this->storage->delete($e->getRequest()); } throw $e; }
php
private function handleBadResponse(BadResponseException $e) { if (isset(self::$gone[$e->getResponse()->getStatusCode()])) { $this->storage->delete($e->getRequest()); } throw $e; }
[ "private", "function", "handleBadResponse", "(", "BadResponseException", "$", "e", ")", "{", "if", "(", "isset", "(", "self", "::", "$", "gone", "[", "$", "e", "->", "getResponse", "(", ")", "->", "getStatusCode", "(", ")", "]", ")", ")", "{", "$", "...
Handles a bad response when attempting to validate. If the resource no longer exists, then remove from the cache. @param BadResponseException $e Exception encountered @throws BadResponseException
[ "Handles", "a", "bad", "response", "when", "attempting", "to", "validate", "." ]
1377567481d6d96224c9bd66aac475fbfbeec776
https://github.com/guzzle/cache-subscriber/blob/1377567481d6d96224c9bd66aac475fbfbeec776/src/ValidationSubscriber.php#L126-L133
train
guzzle/cache-subscriber
src/ValidationSubscriber.php
ValidationSubscriber.createRevalidationRequest
private function createRevalidationRequest( RequestInterface $request, ResponseInterface $response ) { $validate = clone $request; $validate->getConfig()->set('cache.disable', true); $validate->removeHeader('Pragma'); $validate->removeHeader('Cache-Control'); $responseDate = $response->getHeader('Last-Modified') ?: $response->getHeader('Date'); $validate->setHeader('If-Modified-Since', $responseDate); if ($etag = $response->getHeader('ETag')) { $validate->setHeader('If-None-Match', $etag); } return $validate; }
php
private function createRevalidationRequest( RequestInterface $request, ResponseInterface $response ) { $validate = clone $request; $validate->getConfig()->set('cache.disable', true); $validate->removeHeader('Pragma'); $validate->removeHeader('Cache-Control'); $responseDate = $response->getHeader('Last-Modified') ?: $response->getHeader('Date'); $validate->setHeader('If-Modified-Since', $responseDate); if ($etag = $response->getHeader('ETag')) { $validate->setHeader('If-None-Match', $etag); } return $validate; }
[ "private", "function", "createRevalidationRequest", "(", "RequestInterface", "$", "request", ",", "ResponseInterface", "$", "response", ")", "{", "$", "validate", "=", "clone", "$", "request", ";", "$", "validate", "->", "getConfig", "(", ")", "->", "set", "("...
Creates a request to use for revalidation. @param RequestInterface $request Request @param ResponseInterface $response Response to validate @return RequestInterface returns a revalidation request
[ "Creates", "a", "request", "to", "use", "for", "revalidation", "." ]
1377567481d6d96224c9bd66aac475fbfbeec776
https://github.com/guzzle/cache-subscriber/blob/1377567481d6d96224c9bd66aac475fbfbeec776/src/ValidationSubscriber.php#L143-L160
train
Peekmo/JsonPath
src/Peekmo/JsonPath/JsonStore.php
JsonStore.setData
public function setData($data) { $this->data = $data; if (is_string($this->data)) { $this->data = json_decode($this->data, true); } else if (is_object($data)) { $this->data = json_decode(json_encode($this->data), true); } else if (!is_array($data)) { throw new \InvalidArgumentException(sprintf('Invalid data type in JsonStore. Expected object, array or string, got %s', gettype($data))); } }
php
public function setData($data) { $this->data = $data; if (is_string($this->data)) { $this->data = json_decode($this->data, true); } else if (is_object($data)) { $this->data = json_decode(json_encode($this->data), true); } else if (!is_array($data)) { throw new \InvalidArgumentException(sprintf('Invalid data type in JsonStore. Expected object, array or string, got %s', gettype($data))); } }
[ "public", "function", "setData", "(", "$", "data", ")", "{", "$", "this", "->", "data", "=", "$", "data", ";", "if", "(", "is_string", "(", "$", "this", "->", "data", ")", ")", "{", "$", "this", "->", "data", "=", "json_decode", "(", "$", "this",...
Sets JsonStore's manipulated data @param string|array|\stdClass $data
[ "Sets", "JsonStore", "s", "manipulated", "data" ]
0b339171b7eab5791bbb71549305a7e0e2a4ca52
https://github.com/Peekmo/JsonPath/blob/0b339171b7eab5791bbb71549305a7e0e2a4ca52/src/Peekmo/JsonPath/JsonStore.php#L40-L51
train
Peekmo/JsonPath
src/Peekmo/JsonPath/JsonStore.php
JsonStore.get
public function get($expr, $unique = false) { if ((($exprs = $this->normalizedFirst($expr)) !== false) && (is_array($exprs) || $exprs instanceof \Traversable) ) { $values = array(); foreach ($exprs as $expr) { $o =& $this->data; $keys = preg_split( "/([\"'])?\]\[([\"'])?/", preg_replace(array("/^\\$\[[\"']?/", "/[\"']?\]$/"), "", $expr) ); for ($i = 0; $i < count($keys); $i++) { $o =& $o[$keys[$i]]; } $values[] = & $o; } if (true === $unique) { if (!empty($values) && is_array($values[0])) { array_walk($values, function(&$value) { $value = json_encode($value); }); $values = array_unique($values); array_walk($values, function(&$value) { $value = json_decode($value, true); }); return array_values($values); } return array_unique($values); } return $values; } return self::$emptyArray; }
php
public function get($expr, $unique = false) { if ((($exprs = $this->normalizedFirst($expr)) !== false) && (is_array($exprs) || $exprs instanceof \Traversable) ) { $values = array(); foreach ($exprs as $expr) { $o =& $this->data; $keys = preg_split( "/([\"'])?\]\[([\"'])?/", preg_replace(array("/^\\$\[[\"']?/", "/[\"']?\]$/"), "", $expr) ); for ($i = 0; $i < count($keys); $i++) { $o =& $o[$keys[$i]]; } $values[] = & $o; } if (true === $unique) { if (!empty($values) && is_array($values[0])) { array_walk($values, function(&$value) { $value = json_encode($value); }); $values = array_unique($values); array_walk($values, function(&$value) { $value = json_decode($value, true); }); return array_values($values); } return array_unique($values); } return $values; } return self::$emptyArray; }
[ "public", "function", "get", "(", "$", "expr", ",", "$", "unique", "=", "false", ")", "{", "if", "(", "(", "(", "$", "exprs", "=", "$", "this", "->", "normalizedFirst", "(", "$", "expr", ")", ")", "!==", "false", ")", "&&", "(", "is_array", "(", ...
Gets elements matching the given JsonPath expression @param string $expr JsonPath expression @param bool $unique Gets unique results or not @return array
[ "Gets", "elements", "matching", "the", "given", "JsonPath", "expression" ]
0b339171b7eab5791bbb71549305a7e0e2a4ca52
https://github.com/Peekmo/JsonPath/blob/0b339171b7eab5791bbb71549305a7e0e2a4ca52/src/Peekmo/JsonPath/JsonStore.php#L86-L128
train
Peekmo/JsonPath
src/Peekmo/JsonPath/JsonStore.php
JsonStore.set
function set($expr, $value) { $get = $this->get($expr); if ($res =& $get) { foreach ($res as &$r) { $r = $value; } return true; } return false; }
php
function set($expr, $value) { $get = $this->get($expr); if ($res =& $get) { foreach ($res as &$r) { $r = $value; } return true; } return false; }
[ "function", "set", "(", "$", "expr", ",", "$", "value", ")", "{", "$", "get", "=", "$", "this", "->", "get", "(", "$", "expr", ")", ";", "if", "(", "$", "res", "=", "&", "$", "get", ")", "{", "foreach", "(", "$", "res", "as", "&", "$", "r...
Sets the value for all elements matching the given JsonPath expression @param string $expr JsonPath expression @param mixed $value Value to set @return bool returns true if success
[ "Sets", "the", "value", "for", "all", "elements", "matching", "the", "given", "JsonPath", "expression" ]
0b339171b7eab5791bbb71549305a7e0e2a4ca52
https://github.com/Peekmo/JsonPath/blob/0b339171b7eab5791bbb71549305a7e0e2a4ca52/src/Peekmo/JsonPath/JsonStore.php#L136-L148
train
Peekmo/JsonPath
src/Peekmo/JsonPath/JsonStore.php
JsonStore.add
public function add($parentexpr, $value, $name = "") { $get = $this->get($parentexpr); if ($parents =& $get) { foreach ($parents as &$parent) { $parent = is_array($parent) ? $parent : array(); if ($name != "") { $parent[$name] = $value; } else { $parent[] = $value; } } return true; } return false; }
php
public function add($parentexpr, $value, $name = "") { $get = $this->get($parentexpr); if ($parents =& $get) { foreach ($parents as &$parent) { $parent = is_array($parent) ? $parent : array(); if ($name != "") { $parent[$name] = $value; } else { $parent[] = $value; } } return true; } return false; }
[ "public", "function", "add", "(", "$", "parentexpr", ",", "$", "value", ",", "$", "name", "=", "\"\"", ")", "{", "$", "get", "=", "$", "this", "->", "get", "(", "$", "parentexpr", ")", ";", "if", "(", "$", "parents", "=", "&", "$", "get", ")", ...
Adds one or more elements matching the given json path expression @param string $parentexpr JsonPath expression to the parent @param mixed $value Value to add @param string $name Key name @return bool returns true if success
[ "Adds", "one", "or", "more", "elements", "matching", "the", "given", "json", "path", "expression" ]
0b339171b7eab5791bbb71549305a7e0e2a4ca52
https://github.com/Peekmo/JsonPath/blob/0b339171b7eab5791bbb71549305a7e0e2a4ca52/src/Peekmo/JsonPath/JsonStore.php#L157-L176
train
Peekmo/JsonPath
src/Peekmo/JsonPath/JsonStore.php
JsonStore.remove
public function remove($expr) { if ((($exprs = $this->normalizedFirst($expr)) !== false) && (is_array($exprs) || $exprs instanceof \Traversable) ) { foreach ($exprs as &$expr) { $o =& $this->data; $keys = preg_split( "/([\"'])?\]\[([\"'])?/", preg_replace(array("/^\\$\[[\"']?/", "/[\"']?\]$/"), "", $expr) ); for ($i = 0; $i < count($keys) - 1; $i++) { $o =& $o[$keys[$i]]; } unset($o[$keys[$i]]); } return true; } return false; }
php
public function remove($expr) { if ((($exprs = $this->normalizedFirst($expr)) !== false) && (is_array($exprs) || $exprs instanceof \Traversable) ) { foreach ($exprs as &$expr) { $o =& $this->data; $keys = preg_split( "/([\"'])?\]\[([\"'])?/", preg_replace(array("/^\\$\[[\"']?/", "/[\"']?\]$/"), "", $expr) ); for ($i = 0; $i < count($keys) - 1; $i++) { $o =& $o[$keys[$i]]; } unset($o[$keys[$i]]); } return true; } return false; }
[ "public", "function", "remove", "(", "$", "expr", ")", "{", "if", "(", "(", "(", "$", "exprs", "=", "$", "this", "->", "normalizedFirst", "(", "$", "expr", ")", ")", "!==", "false", ")", "&&", "(", "is_array", "(", "$", "exprs", ")", "||", "$", ...
Removes all elements matching the given jsonpath expression @param string $expr JsonPath expression @return bool returns true if success
[ "Removes", "all", "elements", "matching", "the", "given", "jsonpath", "expression" ]
0b339171b7eab5791bbb71549305a7e0e2a4ca52
https://github.com/Peekmo/JsonPath/blob/0b339171b7eab5791bbb71549305a7e0e2a4ca52/src/Peekmo/JsonPath/JsonStore.php#L183-L205
train
Peekmo/JsonPath
src/Peekmo/JsonPath/JsonPath.php
JsonPath.normalize
private function normalize($expression) { // Replaces filters by #0 #1... $expression = preg_replace_callback( array("/[\['](\??\(.*?\))[\]']/", "/\['(.*?)'\]/"), array(&$this, "tempFilters"), $expression ); // ; separator between each elements $expression = preg_replace( array("/'?\.'?|\['?/", "/;;;|;;/", "/;$|'?\]|'$/"), array(";", ";..;", ""), $expression ); // Restore filters $expression = preg_replace_callback("/#([0-9]+)/", array(&$this, "restoreFilters"), $expression); $this->result = array(); // result array was temporarily used as a buffer .. return $expression; }
php
private function normalize($expression) { // Replaces filters by #0 #1... $expression = preg_replace_callback( array("/[\['](\??\(.*?\))[\]']/", "/\['(.*?)'\]/"), array(&$this, "tempFilters"), $expression ); // ; separator between each elements $expression = preg_replace( array("/'?\.'?|\['?/", "/;;;|;;/", "/;$|'?\]|'$/"), array(";", ";..;", ""), $expression ); // Restore filters $expression = preg_replace_callback("/#([0-9]+)/", array(&$this, "restoreFilters"), $expression); $this->result = array(); // result array was temporarily used as a buffer .. return $expression; }
[ "private", "function", "normalize", "(", "$", "expression", ")", "{", "// Replaces filters by #0 #1...\r", "$", "expression", "=", "preg_replace_callback", "(", "array", "(", "\"/[\\['](\\??\\(.*?\\))[\\]']/\"", ",", "\"/\\['(.*?)'\\]/\"", ")", ",", "array", "(", "&", ...
normalize path expression
[ "normalize", "path", "expression" ]
0b339171b7eab5791bbb71549305a7e0e2a4ca52
https://github.com/Peekmo/JsonPath/blob/0b339171b7eab5791bbb71549305a7e0e2a4ca52/src/Peekmo/JsonPath/JsonPath.php#L44-L64
train
Peekmo/JsonPath
src/Peekmo/JsonPath/JsonPath.php
JsonPath.tempFilters
private function tempFilters($filter) { $f = $filter[1]; $elements = explode('\'', $f); // Hack to make "dot" works on filters for ($i=0, $m=0; $i<count($elements); $i++) { if ($m%2 == 0) { if ($i > 0 && substr($elements[$i-1], 0, 1) == '\\') { continue; } $e = explode('.', $elements[$i]); $str = ''; $first = true; foreach ($e as $substr) { if ($first) { $str = $substr; $first = false; continue; } $end = null; if (false !== $pos = $this->strpos_array($substr, $this->keywords)) { list($substr, $end) = array(substr($substr, 0, $pos), substr($substr, $pos, strlen($substr))); } $str .= '[' . $substr . ']'; if (null !== $end) { $str .= $end; } } $elements[$i] = $str; } $m++; } return "[#" . (array_push($this->result, implode('\'', $elements)) - 1) . "]"; }
php
private function tempFilters($filter) { $f = $filter[1]; $elements = explode('\'', $f); // Hack to make "dot" works on filters for ($i=0, $m=0; $i<count($elements); $i++) { if ($m%2 == 0) { if ($i > 0 && substr($elements[$i-1], 0, 1) == '\\') { continue; } $e = explode('.', $elements[$i]); $str = ''; $first = true; foreach ($e as $substr) { if ($first) { $str = $substr; $first = false; continue; } $end = null; if (false !== $pos = $this->strpos_array($substr, $this->keywords)) { list($substr, $end) = array(substr($substr, 0, $pos), substr($substr, $pos, strlen($substr))); } $str .= '[' . $substr . ']'; if (null !== $end) { $str .= $end; } } $elements[$i] = $str; } $m++; } return "[#" . (array_push($this->result, implode('\'', $elements)) - 1) . "]"; }
[ "private", "function", "tempFilters", "(", "$", "filter", ")", "{", "$", "f", "=", "$", "filter", "[", "1", "]", ";", "$", "elements", "=", "explode", "(", "'\\''", ",", "$", "f", ")", ";", "// Hack to make \"dot\" works on filters\r", "for", "(", "$", ...
Pushs the filter into the list @param string $filter @return string
[ "Pushs", "the", "filter", "into", "the", "list" ]
0b339171b7eab5791bbb71549305a7e0e2a4ca52
https://github.com/Peekmo/JsonPath/blob/0b339171b7eab5791bbb71549305a7e0e2a4ca52/src/Peekmo/JsonPath/JsonPath.php#L71-L109
train
Peekmo/JsonPath
src/Peekmo/JsonPath/JsonPath.php
JsonPath.asPath
private function asPath($path) { $expr = explode(";", $path); $fullPath = "$"; for ($i = 1, $n = count($expr); $i < $n; $i++) { $fullPath .= preg_match("/^[0-9*]+$/", $expr[$i]) ? ("[" . $expr[$i] . "]") : ("['" . $expr[$i] . "']"); } return $fullPath; }
php
private function asPath($path) { $expr = explode(";", $path); $fullPath = "$"; for ($i = 1, $n = count($expr); $i < $n; $i++) { $fullPath .= preg_match("/^[0-9*]+$/", $expr[$i]) ? ("[" . $expr[$i] . "]") : ("['" . $expr[$i] . "']"); } return $fullPath; }
[ "private", "function", "asPath", "(", "$", "path", ")", "{", "$", "expr", "=", "explode", "(", "\";\"", ",", "$", "path", ")", ";", "$", "fullPath", "=", "\"$\"", ";", "for", "(", "$", "i", "=", "1", ",", "$", "n", "=", "count", "(", "$", "ex...
Builds json path expression @param string $path @return string
[ "Builds", "json", "path", "expression" ]
0b339171b7eab5791bbb71549305a7e0e2a4ca52
https://github.com/Peekmo/JsonPath/blob/0b339171b7eab5791bbb71549305a7e0e2a4ca52/src/Peekmo/JsonPath/JsonPath.php#L126-L135
train
Peekmo/JsonPath
src/Peekmo/JsonPath/JsonPath.php
JsonPath.strpos_array
private function strpos_array($haystack, array $needles) { $closer = 10000; foreach($needles as $needle) { if (false !== $pos = strpos($haystack, $needle)) { if ($pos < $closer) { $closer = $pos; } } } return 10000 === $closer ? false : $closer; }
php
private function strpos_array($haystack, array $needles) { $closer = 10000; foreach($needles as $needle) { if (false !== $pos = strpos($haystack, $needle)) { if ($pos < $closer) { $closer = $pos; } } } return 10000 === $closer ? false : $closer; }
[ "private", "function", "strpos_array", "(", "$", "haystack", ",", "array", "$", "needles", ")", "{", "$", "closer", "=", "10000", ";", "foreach", "(", "$", "needles", "as", "$", "needle", ")", "{", "if", "(", "false", "!==", "$", "pos", "=", "strpos"...
Search one of the given needs in the array @param string $haystack @param array $needles @return bool|string
[ "Search", "one", "of", "the", "given", "needs", "in", "the", "array" ]
0b339171b7eab5791bbb71549305a7e0e2a4ca52
https://github.com/Peekmo/JsonPath/blob/0b339171b7eab5791bbb71549305a7e0e2a4ca52/src/Peekmo/JsonPath/JsonPath.php#L266-L278
train
silverstripe/silverstripe-tagfield
src/ReadonlyTagField.php
ReadonlyTagField.Field
public function Field($properties = array()) { $options = array(); foreach ($this->getOptions()->filter('Selected', true) as $option) { $options[] = $option->Title; } $field = ReadonlyField::create($this->name . '_Readonly', $this->title); $field->setForm($this->form); $field->setValue(implode(', ', $options)); return $field->Field(); }
php
public function Field($properties = array()) { $options = array(); foreach ($this->getOptions()->filter('Selected', true) as $option) { $options[] = $option->Title; } $field = ReadonlyField::create($this->name . '_Readonly', $this->title); $field->setForm($this->form); $field->setValue(implode(', ', $options)); return $field->Field(); }
[ "public", "function", "Field", "(", "$", "properties", "=", "array", "(", ")", ")", "{", "$", "options", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "getOptions", "(", ")", "->", "filter", "(", "'Selected'", ",", "true", ")", "a...
Render the readonly field as HTML. @param array $properties @return HTMLText
[ "Render", "the", "readonly", "field", "as", "HTML", "." ]
b5ca874591e4add7c6ba5c4dc6699c39e97299f5
https://github.com/silverstripe/silverstripe-tagfield/blob/b5ca874591e4add7c6ba5c4dc6699c39e97299f5/src/ReadonlyTagField.php#L26-L39
train
silverstripe/silverstripe-tagfield
src/TagField.php
TagField.getOrCreateTag
protected function getOrCreateTag($term) { // Check if existing record can be found $source = $this->getSourceList(); $titleField = $this->getTitleField(); $record = $source ->filter($titleField, $term) ->first(); if ($record) { return $record; } // Create new instance if not yet saved if ($this->getCanCreate()) { $dataClass = $source->dataClass(); $record = Injector::inst()->create($dataClass); $record->{$titleField} = $term; $record->write(); if ($source instanceof SS_List) { $source->add($record); } return $record; } return false; }
php
protected function getOrCreateTag($term) { // Check if existing record can be found $source = $this->getSourceList(); $titleField = $this->getTitleField(); $record = $source ->filter($titleField, $term) ->first(); if ($record) { return $record; } // Create new instance if not yet saved if ($this->getCanCreate()) { $dataClass = $source->dataClass(); $record = Injector::inst()->create($dataClass); $record->{$titleField} = $term; $record->write(); if ($source instanceof SS_List) { $source->add($record); } return $record; } return false; }
[ "protected", "function", "getOrCreateTag", "(", "$", "term", ")", "{", "// Check if existing record can be found", "$", "source", "=", "$", "this", "->", "getSourceList", "(", ")", ";", "$", "titleField", "=", "$", "this", "->", "getTitleField", "(", ")", ";",...
Get or create tag with the given value @param string $term @return DataObject|bool
[ "Get", "or", "create", "tag", "with", "the", "given", "value" ]
b5ca874591e4add7c6ba5c4dc6699c39e97299f5
https://github.com/silverstripe/silverstripe-tagfield/blob/b5ca874591e4add7c6ba5c4dc6699c39e97299f5/src/TagField.php#L375-L400
train
silverstripe/silverstripe-tagfield
src/TagField.php
TagField.getTags
protected function getTags($term) { $source = $this->getSourceList(); $titleField = $this->getTitleField(); $query = $source ->filter($titleField . ':PartialMatch:nocase', $term) ->sort($titleField) ->limit($this->getLazyLoadItemLimit()); // Map into a distinct list $items = []; $titleField = $this->getTitleField(); foreach ($query->map('ID', $titleField) as $id => $title) { $items[$title] = [ 'id' => $title, 'text' => $title, ]; } return array_values($items); }
php
protected function getTags($term) { $source = $this->getSourceList(); $titleField = $this->getTitleField(); $query = $source ->filter($titleField . ':PartialMatch:nocase', $term) ->sort($titleField) ->limit($this->getLazyLoadItemLimit()); // Map into a distinct list $items = []; $titleField = $this->getTitleField(); foreach ($query->map('ID', $titleField) as $id => $title) { $items[$title] = [ 'id' => $title, 'text' => $title, ]; } return array_values($items); }
[ "protected", "function", "getTags", "(", "$", "term", ")", "{", "$", "source", "=", "$", "this", "->", "getSourceList", "(", ")", ";", "$", "titleField", "=", "$", "this", "->", "getTitleField", "(", ")", ";", "$", "query", "=", "$", "source", "->", ...
Returns array of arrays representing tags. @param string $term @return array
[ "Returns", "array", "of", "arrays", "representing", "tags", "." ]
b5ca874591e4add7c6ba5c4dc6699c39e97299f5
https://github.com/silverstripe/silverstripe-tagfield/blob/b5ca874591e4add7c6ba5c4dc6699c39e97299f5/src/TagField.php#L425-L447
train
silverstripe/silverstripe-tagfield
src/TagField.php
TagField.performReadonlyTransformation
public function performReadonlyTransformation() { /** @var ReadonlyTagField $copy */ $copy = $this->castedCopy(ReadonlyTagField::class); $copy->setSourceList($this->getSourceList()); return $copy; }
php
public function performReadonlyTransformation() { /** @var ReadonlyTagField $copy */ $copy = $this->castedCopy(ReadonlyTagField::class); $copy->setSourceList($this->getSourceList()); return $copy; }
[ "public", "function", "performReadonlyTransformation", "(", ")", "{", "/** @var ReadonlyTagField $copy */", "$", "copy", "=", "$", "this", "->", "castedCopy", "(", "ReadonlyTagField", "::", "class", ")", ";", "$", "copy", "->", "setSourceList", "(", "$", "this", ...
Converts the field to a readonly variant. @return ReadonlyTagField
[ "Converts", "the", "field", "to", "a", "readonly", "variant", "." ]
b5ca874591e4add7c6ba5c4dc6699c39e97299f5
https://github.com/silverstripe/silverstripe-tagfield/blob/b5ca874591e4add7c6ba5c4dc6699c39e97299f5/src/TagField.php#L466-L472
train
silverstripe/silverstripe-tagfield
src/StringTagField.php
StringTagField.getSchemaDataDefaults
public function getSchemaDataDefaults() { $schema = array_merge( parent::getSchemaDataDefaults(), [ 'name' => $this->getName() . '[]', 'lazyLoad' => $this->getShouldLazyLoad(), 'creatable' => $this->getCanCreate(), 'multi' => $this->getIsMultiple(), 'value' => $this->formatOptions($this->Value()), 'disabled' => $this->isDisabled() || $this->isReadonly(), ] ); if (!$this->getShouldLazyLoad()) { $schema['options'] = $this->getOptions()->toNestedArray(); } else { $schema['optionUrl'] = $this->getSuggestURL(); } return $schema; }
php
public function getSchemaDataDefaults() { $schema = array_merge( parent::getSchemaDataDefaults(), [ 'name' => $this->getName() . '[]', 'lazyLoad' => $this->getShouldLazyLoad(), 'creatable' => $this->getCanCreate(), 'multi' => $this->getIsMultiple(), 'value' => $this->formatOptions($this->Value()), 'disabled' => $this->isDisabled() || $this->isReadonly(), ] ); if (!$this->getShouldLazyLoad()) { $schema['options'] = $this->getOptions()->toNestedArray(); } else { $schema['optionUrl'] = $this->getSuggestURL(); } return $schema; }
[ "public", "function", "getSchemaDataDefaults", "(", ")", "{", "$", "schema", "=", "array_merge", "(", "parent", "::", "getSchemaDataDefaults", "(", ")", ",", "[", "'name'", "=>", "$", "this", "->", "getName", "(", ")", ".", "'[]'", ",", "'lazyLoad'", "=>",...
Provide TagField data to the JSON schema for the frontend component @return array
[ "Provide", "TagField", "data", "to", "the", "JSON", "schema", "for", "the", "frontend", "component" ]
b5ca874591e4add7c6ba5c4dc6699c39e97299f5
https://github.com/silverstripe/silverstripe-tagfield/blob/b5ca874591e4add7c6ba5c4dc6699c39e97299f5/src/StringTagField.php#L159-L180
train
silverstripe/silverstripe-tagfield
src/StringTagField.php
StringTagField.suggest
public function suggest(HTTPRequest $request) { $responseBody = json_encode( ['items' => $this->getTags($request->getVar('term'))] ); $response = HTTPResponse::create(); $response->addHeader('Content-Type', 'application/json'); $response->setBody($responseBody); return $response; }
php
public function suggest(HTTPRequest $request) { $responseBody = json_encode( ['items' => $this->getTags($request->getVar('term'))] ); $response = HTTPResponse::create(); $response->addHeader('Content-Type', 'application/json'); $response->setBody($responseBody); return $response; }
[ "public", "function", "suggest", "(", "HTTPRequest", "$", "request", ")", "{", "$", "responseBody", "=", "json_encode", "(", "[", "'items'", "=>", "$", "this", "->", "getTags", "(", "$", "request", "->", "getVar", "(", "'term'", ")", ")", "]", ")", ";"...
Returns a JSON string of tags, for lazy loading. @param HTTPRequest $request @return HTTPResponse
[ "Returns", "a", "JSON", "string", "of", "tags", "for", "lazy", "loading", "." ]
b5ca874591e4add7c6ba5c4dc6699c39e97299f5
https://github.com/silverstripe/silverstripe-tagfield/blob/b5ca874591e4add7c6ba5c4dc6699c39e97299f5/src/StringTagField.php#L292-L303
train
silverstripe/silverstripe-tagfield
src/StringTagField.php
StringTagField.getTags
protected function getTags($term) { $items = []; foreach ($this->getOptions() as $i => $tag) { /** @var ArrayData $tag */ $tagValue = $tag->Value; // Map into a distinct list (prevent duplicates) if (stripos($tagValue, $term) !== false && !array_key_exists($tagValue, $items)) { $items[$tagValue] = [ 'id' => $tag->Title, 'text' => $tag->Value, ]; } } // @todo do we actually need lazy loading limits for StringTagField? return array_slice(array_values($items), 0, $this->getLazyLoadItemLimit()); }
php
protected function getTags($term) { $items = []; foreach ($this->getOptions() as $i => $tag) { /** @var ArrayData $tag */ $tagValue = $tag->Value; // Map into a distinct list (prevent duplicates) if (stripos($tagValue, $term) !== false && !array_key_exists($tagValue, $items)) { $items[$tagValue] = [ 'id' => $tag->Title, 'text' => $tag->Value, ]; } } // @todo do we actually need lazy loading limits for StringTagField? return array_slice(array_values($items), 0, $this->getLazyLoadItemLimit()); }
[ "protected", "function", "getTags", "(", "$", "term", ")", "{", "$", "items", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "getOptions", "(", ")", "as", "$", "i", "=>", "$", "tag", ")", "{", "/** @var ArrayData $tag */", "$", "tagValue", "=...
Returns array of arrays representing tags that partially match the given search term @param string $term @return array
[ "Returns", "array", "of", "arrays", "representing", "tags", "that", "partially", "match", "the", "given", "search", "term" ]
b5ca874591e4add7c6ba5c4dc6699c39e97299f5
https://github.com/silverstripe/silverstripe-tagfield/blob/b5ca874591e4add7c6ba5c4dc6699c39e97299f5/src/StringTagField.php#L311-L327
train
laravel-doctrine/extensions
src/BeberleiExtensionsServiceProvider.php
BeberleiExtensionsServiceProvider.boot
public function boot(DoctrineManager $manager) { $manager->extendAll(function (Configuration $configuration) { $configuration->setCustomDatetimeFunctions($this->datetime); $configuration->setCustomNumericFunctions($this->numeric); $configuration->setCustomStringFunctions($this->string); }); }
php
public function boot(DoctrineManager $manager) { $manager->extendAll(function (Configuration $configuration) { $configuration->setCustomDatetimeFunctions($this->datetime); $configuration->setCustomNumericFunctions($this->numeric); $configuration->setCustomStringFunctions($this->string); }); }
[ "public", "function", "boot", "(", "DoctrineManager", "$", "manager", ")", "{", "$", "manager", "->", "extendAll", "(", "function", "(", "Configuration", "$", "configuration", ")", "{", "$", "configuration", "->", "setCustomDatetimeFunctions", "(", "$", "this", ...
Register the metadata @param DoctrineManager $manager
[ "Register", "the", "metadata" ]
a2e7896100559ecc64504252dbc74ec18ad59813
https://github.com/laravel-doctrine/extensions/blob/a2e7896100559ecc64504252dbc74ec18ad59813/src/BeberleiExtensionsServiceProvider.php#L96-L103
train
silverstripe/silverstripe-spamprotection
code/EditableSpamProtectionField.php
EditableSpamProtectionField.getCandidateFields
protected function getCandidateFields() { // Get list of all configured classes available for spam detection $types = $this->config()->get('check_fields'); $typesInherit = array(); foreach ($types as $type) { $subTypes = ClassInfo::subclassesFor($type); $typesInherit = array_merge($typesInherit, $subTypes); } // Get all candidates of the above types return $this ->Parent() ->Fields() ->filter('ClassName', $typesInherit) ->exclude('Title', ''); // Ignore this field and those without titles }
php
protected function getCandidateFields() { // Get list of all configured classes available for spam detection $types = $this->config()->get('check_fields'); $typesInherit = array(); foreach ($types as $type) { $subTypes = ClassInfo::subclassesFor($type); $typesInherit = array_merge($typesInherit, $subTypes); } // Get all candidates of the above types return $this ->Parent() ->Fields() ->filter('ClassName', $typesInherit) ->exclude('Title', ''); // Ignore this field and those without titles }
[ "protected", "function", "getCandidateFields", "(", ")", "{", "// Get list of all configured classes available for spam detection", "$", "types", "=", "$", "this", "->", "config", "(", ")", "->", "get", "(", "'check_fields'", ")", ";", "$", "typesInherit", "=", "arr...
Gets the list of all candidate spam detectable fields on this field's form @return DataList
[ "Gets", "the", "list", "of", "all", "candidate", "spam", "detectable", "fields", "on", "this", "field", "s", "form" ]
b88a706ae77fa8e1c1113694f986b4dc35a20212
https://github.com/silverstripe/silverstripe-spamprotection/blob/b88a706ae77fa8e1c1113694f986b4dc35a20212/code/EditableSpamProtectionField.php#L99-L116
train
silverstripe/silverstripe-spamprotection
code/EditableSpamProtectionField.php
EditableSpamProtectionField.onBeforeWrite
public function onBeforeWrite() { $fieldMap = json_decode($this->SpamFieldSettings, true); if (empty($fieldMap)) { $fieldMap = array(); } foreach ($this->record as $key => $value) { if (substr($key, 0, 8) === 'spammap-') { $fieldMap[substr($key, 8)] = $value; } } $this->setField('SpamFieldSettings', json_encode($fieldMap)); return parent::onBeforeWrite(); }
php
public function onBeforeWrite() { $fieldMap = json_decode($this->SpamFieldSettings, true); if (empty($fieldMap)) { $fieldMap = array(); } foreach ($this->record as $key => $value) { if (substr($key, 0, 8) === 'spammap-') { $fieldMap[substr($key, 8)] = $value; } } $this->setField('SpamFieldSettings', json_encode($fieldMap)); return parent::onBeforeWrite(); }
[ "public", "function", "onBeforeWrite", "(", ")", "{", "$", "fieldMap", "=", "json_decode", "(", "$", "this", "->", "SpamFieldSettings", ",", "true", ")", ";", "if", "(", "empty", "(", "$", "fieldMap", ")", ")", "{", "$", "fieldMap", "=", "array", "(", ...
Write the spam field mapping values to a serialised DB field {@inheritDoc}
[ "Write", "the", "spam", "field", "mapping", "values", "to", "a", "serialised", "DB", "field" ]
b88a706ae77fa8e1c1113694f986b4dc35a20212
https://github.com/silverstripe/silverstripe-spamprotection/blob/b88a706ae77fa8e1c1113694f986b4dc35a20212/code/EditableSpamProtectionField.php#L123-L138
train
silverstripe/silverstripe-spamprotection
code/EditableSpamProtectionField.php
EditableSpamProtectionField.getCMSFields
public function getCMSFields() { /** @var FieldList $fields */ $fields = parent::getCMSFields(); // Get protector $protector = FormSpamProtectionExtension::get_protector(); if (!$protector) { return $fields; } if ($this->Parent()->Fields() instanceof UnsavedRelationList) { return $fields; } // Each other text field in this group can be assigned a field mapping $mapGroup = FieldGroup::create() ->setTitle(_t(__CLASS__.'.SPAMFIELDMAPPING', 'Spam Field Mapping')) ->setName('SpamFieldMapping') ->setDescription(_t( __CLASS__.'.SPAMFIELDMAPPINGDESCRIPTION', 'Select the form fields that correspond to any relevant spam protection identifiers' )); // Generate field specific settings $mappableFields = FormSpamProtectionExtension::config()->get('mappable_fields'); $mappableFieldsMerged = array_combine($mappableFields, $mappableFields); foreach ($this->getCandidateFields() as $otherField) { $mapSetting = "Map-{$otherField->Name}"; $fieldOption = DropdownField::create( 'spammap-' . $mapSetting, $otherField->Title, $mappableFieldsMerged, $this->spamMapValue($mapSetting) )->setEmptyString(''); $mapGroup->push($fieldOption); } $fields->addFieldToTab('Root.Main', $mapGroup); return $fields; }
php
public function getCMSFields() { /** @var FieldList $fields */ $fields = parent::getCMSFields(); // Get protector $protector = FormSpamProtectionExtension::get_protector(); if (!$protector) { return $fields; } if ($this->Parent()->Fields() instanceof UnsavedRelationList) { return $fields; } // Each other text field in this group can be assigned a field mapping $mapGroup = FieldGroup::create() ->setTitle(_t(__CLASS__.'.SPAMFIELDMAPPING', 'Spam Field Mapping')) ->setName('SpamFieldMapping') ->setDescription(_t( __CLASS__.'.SPAMFIELDMAPPINGDESCRIPTION', 'Select the form fields that correspond to any relevant spam protection identifiers' )); // Generate field specific settings $mappableFields = FormSpamProtectionExtension::config()->get('mappable_fields'); $mappableFieldsMerged = array_combine($mappableFields, $mappableFields); foreach ($this->getCandidateFields() as $otherField) { $mapSetting = "Map-{$otherField->Name}"; $fieldOption = DropdownField::create( 'spammap-' . $mapSetting, $otherField->Title, $mappableFieldsMerged, $this->spamMapValue($mapSetting) )->setEmptyString(''); $mapGroup->push($fieldOption); } $fields->addFieldToTab('Root.Main', $mapGroup); return $fields; }
[ "public", "function", "getCMSFields", "(", ")", "{", "/** @var FieldList $fields */", "$", "fields", "=", "parent", "::", "getCMSFields", "(", ")", ";", "// Get protector", "$", "protector", "=", "FormSpamProtectionExtension", "::", "get_protector", "(", ")", ";", ...
Used in userforms 3.x and above {@inheritDoc}
[ "Used", "in", "userforms", "3", ".", "x", "and", "above" ]
b88a706ae77fa8e1c1113694f986b4dc35a20212
https://github.com/silverstripe/silverstripe-spamprotection/blob/b88a706ae77fa8e1c1113694f986b4dc35a20212/code/EditableSpamProtectionField.php#L145-L185
train
silverstripe/silverstripe-spamprotection
code/EditableSpamProtectionField.php
EditableSpamProtectionField.spamMapValue
public function spamMapValue($mapSetting) { $map = json_decode($this->SpamFieldSettings, true); if (empty($map)) { $map = array(); } if (array_key_exists($mapSetting, $map)) { return $map[$mapSetting]; } return ''; }
php
public function spamMapValue($mapSetting) { $map = json_decode($this->SpamFieldSettings, true); if (empty($map)) { $map = array(); } if (array_key_exists($mapSetting, $map)) { return $map[$mapSetting]; } return ''; }
[ "public", "function", "spamMapValue", "(", "$", "mapSetting", ")", "{", "$", "map", "=", "json_decode", "(", "$", "this", "->", "SpamFieldSettings", ",", "true", ")", ";", "if", "(", "empty", "(", "$", "map", ")", ")", "{", "$", "map", "=", "array", ...
Try to retrieve a value for the given spam field map name from the serialised data @param string $mapSetting @return string
[ "Try", "to", "retrieve", "a", "value", "for", "the", "given", "spam", "field", "map", "name", "from", "the", "serialised", "data" ]
b88a706ae77fa8e1c1113694f986b4dc35a20212
https://github.com/silverstripe/silverstripe-spamprotection/blob/b88a706ae77fa8e1c1113694f986b4dc35a20212/code/EditableSpamProtectionField.php#L193-L204
train
silverstripe/silverstripe-spamprotection
code/Extension/FormSpamProtectionExtension.php
FormSpamProtectionExtension.get_protector
public static function get_protector($options = null) { // generate the spam protector if (isset($options['protector'])) { $protector = $options['protector']; } else { $protector = self::config()->get('default_spam_protector'); } if ($protector && class_exists($protector)) { return Injector::inst()->create($protector); } else { return null; } }
php
public static function get_protector($options = null) { // generate the spam protector if (isset($options['protector'])) { $protector = $options['protector']; } else { $protector = self::config()->get('default_spam_protector'); } if ($protector && class_exists($protector)) { return Injector::inst()->create($protector); } else { return null; } }
[ "public", "static", "function", "get_protector", "(", "$", "options", "=", "null", ")", "{", "// generate the spam protector", "if", "(", "isset", "(", "$", "options", "[", "'protector'", "]", ")", ")", "{", "$", "protector", "=", "$", "options", "[", "'pr...
Instantiate a SpamProtector instance @param array $options Configuration options @return SpamProtector|null
[ "Instantiate", "a", "SpamProtector", "instance" ]
b88a706ae77fa8e1c1113694f986b4dc35a20212
https://github.com/silverstripe/silverstripe-spamprotection/blob/b88a706ae77fa8e1c1113694f986b4dc35a20212/code/Extension/FormSpamProtectionExtension.php#L67-L81
train
silverstripe/silverstripe-spamprotection
code/Extension/FormSpamProtectionExtension.php
FormSpamProtectionExtension.enableSpamProtection
public function enableSpamProtection($options = array()) { // captcha form field name (must be unique) if (isset($options['name'])) { $name = $options['name']; } else { $name = $this->config()->get('field_name'); } // captcha field title if (isset($options['title'])) { $title = $options['title']; } else { $title = ''; } // set custom mapping on this form $protector = self::get_protector($options); if (isset($options['mapping'])) { $protector->setFieldMapping($options['mapping']); } if ($protector) { // add the form field if ($field = $protector->getFormField($name, $title)) { $field->setForm($this->owner); // Add before field specified by insertBefore $inserted = false; if (!empty($options['insertBefore'])) { $inserted = $this->owner->Fields()->insertBefore($field, $options['insertBefore']); } if (!$inserted) { // Add field to end if not added already $this->owner->Fields()->push($field); } } } return $this->owner; }
php
public function enableSpamProtection($options = array()) { // captcha form field name (must be unique) if (isset($options['name'])) { $name = $options['name']; } else { $name = $this->config()->get('field_name'); } // captcha field title if (isset($options['title'])) { $title = $options['title']; } else { $title = ''; } // set custom mapping on this form $protector = self::get_protector($options); if (isset($options['mapping'])) { $protector->setFieldMapping($options['mapping']); } if ($protector) { // add the form field if ($field = $protector->getFormField($name, $title)) { $field->setForm($this->owner); // Add before field specified by insertBefore $inserted = false; if (!empty($options['insertBefore'])) { $inserted = $this->owner->Fields()->insertBefore($field, $options['insertBefore']); } if (!$inserted) { // Add field to end if not added already $this->owner->Fields()->push($field); } } } return $this->owner; }
[ "public", "function", "enableSpamProtection", "(", "$", "options", "=", "array", "(", ")", ")", "{", "// captcha form field name (must be unique)", "if", "(", "isset", "(", "$", "options", "[", "'name'", "]", ")", ")", "{", "$", "name", "=", "$", "options", ...
Activates the spam protection module. @param array $options @return Object
[ "Activates", "the", "spam", "protection", "module", "." ]
b88a706ae77fa8e1c1113694f986b4dc35a20212
https://github.com/silverstripe/silverstripe-spamprotection/blob/b88a706ae77fa8e1c1113694f986b4dc35a20212/code/Extension/FormSpamProtectionExtension.php#L89-L131
train
lovata/oc-toolbox-plugin
classes/helper/PageHelper.php
PageHelper.getPageNameList
public function getPageNameList() { if (!empty($this->arPageNameList)) { return $this->arPageNameList; } $arResult = []; //Get page list $obPageList = $this->getPageList(); if (empty($obPageList)) { return $arResult; } //Process page list foreach ($obPageList as $obPage) { $arResult[$obPage->id] = $obPage->title; } $this->arPageNameList = $arResult; return $arResult; }
php
public function getPageNameList() { if (!empty($this->arPageNameList)) { return $this->arPageNameList; } $arResult = []; //Get page list $obPageList = $this->getPageList(); if (empty($obPageList)) { return $arResult; } //Process page list foreach ($obPageList as $obPage) { $arResult[$obPage->id] = $obPage->title; } $this->arPageNameList = $arResult; return $arResult; }
[ "public", "function", "getPageNameList", "(", ")", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "arPageNameList", ")", ")", "{", "return", "$", "this", "->", "arPageNameList", ";", "}", "$", "arResult", "=", "[", "]", ";", "//Get page list", "...
Get array with names of pages @return array
[ "Get", "array", "with", "names", "of", "pages" ]
e28f6cfd63f9091d5a215171568648ca5a0e4716
https://github.com/lovata/oc-toolbox-plugin/blob/e28f6cfd63f9091d5a215171568648ca5a0e4716/classes/helper/PageHelper.php#L87-L109
train
lovata/oc-toolbox-plugin
classes/helper/PageHelper.php
PageHelper.getPageObject
protected function getPageObject($sPageCode) { if (isset($this->arPageList[$sPageCode])) { return $this->arPageList[$sPageCode]; } if (empty($sPageCode) || empty($this->obTheme)) { return null; } $this->arPageList[$sPageCode] = CmsPage::loadCached($this->obTheme, $sPageCode); return $this->arPageList[$sPageCode]; }
php
protected function getPageObject($sPageCode) { if (isset($this->arPageList[$sPageCode])) { return $this->arPageList[$sPageCode]; } if (empty($sPageCode) || empty($this->obTheme)) { return null; } $this->arPageList[$sPageCode] = CmsPage::loadCached($this->obTheme, $sPageCode); return $this->arPageList[$sPageCode]; }
[ "protected", "function", "getPageObject", "(", "$", "sPageCode", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "arPageList", "[", "$", "sPageCode", "]", ")", ")", "{", "return", "$", "this", "->", "arPageList", "[", "$", "sPageCode", "]", ";", ...
Get page object @param string $sPageCode @return CmsPage|null
[ "Get", "page", "object" ]
e28f6cfd63f9091d5a215171568648ca5a0e4716
https://github.com/lovata/oc-toolbox-plugin/blob/e28f6cfd63f9091d5a215171568648ca5a0e4716/classes/helper/PageHelper.php#L149-L162
train
lovata/oc-toolbox-plugin
classes/helper/PageHelper.php
PageHelper.getCachedData
protected function getCachedData($sKey) { if (isset($this->arCachedData[$sKey])) { return $this->arCachedData[$sKey]; } return null; }
php
protected function getCachedData($sKey) { if (isset($this->arCachedData[$sKey])) { return $this->arCachedData[$sKey]; } return null; }
[ "protected", "function", "getCachedData", "(", "$", "sKey", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "arCachedData", "[", "$", "sKey", "]", ")", ")", "{", "return", "$", "this", "->", "arCachedData", "[", "$", "sKey", "]", ";", "}", "r...
Get cached data @param string $sKey @return mixed|null
[ "Get", "cached", "data" ]
e28f6cfd63f9091d5a215171568648ca5a0e4716
https://github.com/lovata/oc-toolbox-plugin/blob/e28f6cfd63f9091d5a215171568648ca5a0e4716/classes/helper/PageHelper.php#L169-L176
train
lovata/oc-toolbox-plugin
classes/helper/PageHelper.php
PageHelper.getPageList
protected function getPageList() { //Get CMS page list $obPageList = $this->getCmsPageList(); //Get static page list $obStaticPageList = $this->getStaticPageList(); if (!empty($obStaticPageList)) { if (empty($obPageList)) { return $obStaticPageList; } $obPageList = $obPageList->merge($obStaticPageList->all()); } return $obPageList; }
php
protected function getPageList() { //Get CMS page list $obPageList = $this->getCmsPageList(); //Get static page list $obStaticPageList = $this->getStaticPageList(); if (!empty($obStaticPageList)) { if (empty($obPageList)) { return $obStaticPageList; } $obPageList = $obPageList->merge($obStaticPageList->all()); } return $obPageList; }
[ "protected", "function", "getPageList", "(", ")", "{", "//Get CMS page list", "$", "obPageList", "=", "$", "this", "->", "getCmsPageList", "(", ")", ";", "//Get static page list", "$", "obStaticPageList", "=", "$", "this", "->", "getStaticPageList", "(", ")", ";...
Get page list @return array|\Cms\Classes\CmsObjectCollection|CmsPage[]|null
[ "Get", "page", "list" ]
e28f6cfd63f9091d5a215171568648ca5a0e4716
https://github.com/lovata/oc-toolbox-plugin/blob/e28f6cfd63f9091d5a215171568648ca5a0e4716/classes/helper/PageHelper.php#L201-L217
train
lovata/oc-toolbox-plugin
classes/helper/PageHelper.php
PageHelper.getStaticPageList
protected function getStaticPageList() { if (!PluginManager::instance()->hasPlugin('RainLab.Pages') || empty($this->obTheme)) { return null; } //Get Static page list /** @var \Cms\Classes\CmsObjectCollection|\Cms\Classes\Page[] $obStaticPageList */ $obStaticPage = new \RainLab\Pages\Classes\PageList($this->obTheme); $obStaticPageList = $obStaticPage->listPages(true); return $obStaticPageList; }
php
protected function getStaticPageList() { if (!PluginManager::instance()->hasPlugin('RainLab.Pages') || empty($this->obTheme)) { return null; } //Get Static page list /** @var \Cms\Classes\CmsObjectCollection|\Cms\Classes\Page[] $obStaticPageList */ $obStaticPage = new \RainLab\Pages\Classes\PageList($this->obTheme); $obStaticPageList = $obStaticPage->listPages(true); return $obStaticPageList; }
[ "protected", "function", "getStaticPageList", "(", ")", "{", "if", "(", "!", "PluginManager", "::", "instance", "(", ")", "->", "hasPlugin", "(", "'RainLab.Pages'", ")", "||", "empty", "(", "$", "this", "->", "obTheme", ")", ")", "{", "return", "null", "...
Get Static page list @return array|\Cms\Classes\CmsObjectCollection|CmsPage[]|null
[ "Get", "Static", "page", "list" ]
e28f6cfd63f9091d5a215171568648ca5a0e4716
https://github.com/lovata/oc-toolbox-plugin/blob/e28f6cfd63f9091d5a215171568648ca5a0e4716/classes/helper/PageHelper.php#L239-L251
train
lovata/oc-toolbox-plugin
traits/helpers/TraitCached.php
TraitCached.addCachedField
public function addCachedField($arFieldList) { if (empty($arFieldList)) { return; } if (empty($this->cached) || !is_array($this->cached)) { $this->cached = []; } if (is_string($arFieldList)) { $arFieldList = [$arFieldList]; } $this->cached = array_merge($this->cached, $arFieldList); $this->cached = array_unique($this->cached); }
php
public function addCachedField($arFieldList) { if (empty($arFieldList)) { return; } if (empty($this->cached) || !is_array($this->cached)) { $this->cached = []; } if (is_string($arFieldList)) { $arFieldList = [$arFieldList]; } $this->cached = array_merge($this->cached, $arFieldList); $this->cached = array_unique($this->cached); }
[ "public", "function", "addCachedField", "(", "$", "arFieldList", ")", "{", "if", "(", "empty", "(", "$", "arFieldList", ")", ")", "{", "return", ";", "}", "if", "(", "empty", "(", "$", "this", "->", "cached", ")", "||", "!", "is_array", "(", "$", "...
Add fields to cached field list @param array|string $arFieldList
[ "Add", "fields", "to", "cached", "field", "list" ]
e28f6cfd63f9091d5a215171568648ca5a0e4716
https://github.com/lovata/oc-toolbox-plugin/blob/e28f6cfd63f9091d5a215171568648ca5a0e4716/traits/helpers/TraitCached.php#L16-L32
train
lovata/oc-toolbox-plugin
traits/helpers/TraitCached.php
TraitCached.getCachedField
public function getCachedField(): array { if (empty($this->cached) || !is_array($this->cached)) { $this->cached = []; } return $this->cached; }
php
public function getCachedField(): array { if (empty($this->cached) || !is_array($this->cached)) { $this->cached = []; } return $this->cached; }
[ "public", "function", "getCachedField", "(", ")", ":", "array", "{", "if", "(", "empty", "(", "$", "this", "->", "cached", ")", "||", "!", "is_array", "(", "$", "this", "->", "cached", ")", ")", "{", "$", "this", "->", "cached", "=", "[", "]", ";...
Get cached field list @return array
[ "Get", "cached", "field", "list" ]
e28f6cfd63f9091d5a215171568648ca5a0e4716
https://github.com/lovata/oc-toolbox-plugin/blob/e28f6cfd63f9091d5a215171568648ca5a0e4716/traits/helpers/TraitCached.php#L38-L45
train
lovata/oc-toolbox-plugin
models/CommonSettings.php
CommonSettings.getValue
public static function getValue($sCode, $sDefaultValue = null) { if (empty($sCode)) { return $sDefaultValue; } //Get settings object $obSettings = static::where('item', static::SETTINGS_CODE)->first(); if (empty($obSettings)) { return static::get($sCode, $sDefaultValue); } $sValue = $obSettings->$sCode; if (empty($sValue)) { return $sDefaultValue; } return $sValue; }
php
public static function getValue($sCode, $sDefaultValue = null) { if (empty($sCode)) { return $sDefaultValue; } //Get settings object $obSettings = static::where('item', static::SETTINGS_CODE)->first(); if (empty($obSettings)) { return static::get($sCode, $sDefaultValue); } $sValue = $obSettings->$sCode; if (empty($sValue)) { return $sDefaultValue; } return $sValue; }
[ "public", "static", "function", "getValue", "(", "$", "sCode", ",", "$", "sDefaultValue", "=", "null", ")", "{", "if", "(", "empty", "(", "$", "sCode", ")", ")", "{", "return", "$", "sDefaultValue", ";", "}", "//Get settings object", "$", "obSettings", "...
Get setting value @param string $sCode @param string $sDefaultValue @return null|string
[ "Get", "setting", "value" ]
e28f6cfd63f9091d5a215171568648ca5a0e4716
https://github.com/lovata/oc-toolbox-plugin/blob/e28f6cfd63f9091d5a215171568648ca5a0e4716/models/CommonSettings.php#L32-L50
train
lovata/oc-toolbox-plugin
classes/event/AbstractModelRelationHandler.php
AbstractModelRelationHandler.checkRelationName
protected function checkRelationName($sRelationName) : bool { $sCheckedRelationName = $this->getRelationName(); if (empty($sCheckedRelationName)) { return true; } if (is_array($sCheckedRelationName) && in_array($sRelationName, $sCheckedRelationName)) { return true; } $bResult = $sRelationName == $sCheckedRelationName; return $bResult; }
php
protected function checkRelationName($sRelationName) : bool { $sCheckedRelationName = $this->getRelationName(); if (empty($sCheckedRelationName)) { return true; } if (is_array($sCheckedRelationName) && in_array($sRelationName, $sCheckedRelationName)) { return true; } $bResult = $sRelationName == $sCheckedRelationName; return $bResult; }
[ "protected", "function", "checkRelationName", "(", "$", "sRelationName", ")", ":", "bool", "{", "$", "sCheckedRelationName", "=", "$", "this", "->", "getRelationName", "(", ")", ";", "if", "(", "empty", "(", "$", "sCheckedRelationName", ")", ")", "{", "retur...
Check relation name @param string $sRelationName @return bool
[ "Check", "relation", "name" ]
e28f6cfd63f9091d5a215171568648ca5a0e4716
https://github.com/lovata/oc-toolbox-plugin/blob/e28f6cfd63f9091d5a215171568648ca5a0e4716/classes/event/AbstractModelRelationHandler.php#L68-L82
train
lovata/oc-toolbox-plugin
traits/helpers/TraitComponentNotFoundResponse.php
TraitComponentNotFoundResponse.getErrorResponse
protected function getErrorResponse() { if (Request::ajax()) { throw new AjaxException('Element not found'); } return Response::make($this->controller->run('404')->getContent(), 404); }
php
protected function getErrorResponse() { if (Request::ajax()) { throw new AjaxException('Element not found'); } return Response::make($this->controller->run('404')->getContent(), 404); }
[ "protected", "function", "getErrorResponse", "(", ")", "{", "if", "(", "Request", "::", "ajax", "(", ")", ")", "{", "throw", "new", "AjaxException", "(", "'Element not found'", ")", ";", "}", "return", "Response", "::", "make", "(", "$", "this", "->", "c...
Get error response for 404 page @throws AjaxException @return \Illuminate\Http\Response
[ "Get", "error", "response", "for", "404", "page" ]
e28f6cfd63f9091d5a215171568648ca5a0e4716
https://github.com/lovata/oc-toolbox-plugin/blob/e28f6cfd63f9091d5a215171568648ca5a0e4716/traits/helpers/TraitComponentNotFoundResponse.php#L51-L58
train
lovata/oc-toolbox-plugin
traits/helpers/PriceHelperTrait.php
PriceHelperTrait.addPriceFiledMethods
protected static function addPriceFiledMethods($obElement) { if (empty($obElement->arPriceField) || !is_array($obElement->arPriceField)) { return; } foreach ($obElement->arPriceField as $sFieldName) { if (empty($sFieldName) || !is_string($sFieldName)) { continue; } $sFieldConvert = Str::studly($sFieldName); self::addGetPriceFieldMethod($obElement, $sFieldName, $sFieldConvert); if ($obElement instanceof Model) { self::addSetPriceFieldMethod($obElement, $sFieldName, $sFieldConvert); self::addGetPriceValueFieldMethod($obElement, $sFieldName, $sFieldConvert); self::addScopePriceFieldMethod($obElement, $sFieldName, $sFieldConvert); } } }
php
protected static function addPriceFiledMethods($obElement) { if (empty($obElement->arPriceField) || !is_array($obElement->arPriceField)) { return; } foreach ($obElement->arPriceField as $sFieldName) { if (empty($sFieldName) || !is_string($sFieldName)) { continue; } $sFieldConvert = Str::studly($sFieldName); self::addGetPriceFieldMethod($obElement, $sFieldName, $sFieldConvert); if ($obElement instanceof Model) { self::addSetPriceFieldMethod($obElement, $sFieldName, $sFieldConvert); self::addGetPriceValueFieldMethod($obElement, $sFieldName, $sFieldConvert); self::addScopePriceFieldMethod($obElement, $sFieldName, $sFieldConvert); } } }
[ "protected", "static", "function", "addPriceFiledMethods", "(", "$", "obElement", ")", "{", "if", "(", "empty", "(", "$", "obElement", "->", "arPriceField", ")", "||", "!", "is_array", "(", "$", "obElement", "->", "arPriceField", ")", ")", "{", "return", "...
Check arPriceField array and add price methods to model object @param \Model|\Eloquent|\Lovata\Toolbox\Classes\Item\ElementItem $obElement $obElement
[ "Check", "arPriceField", "array", "and", "add", "price", "methods", "to", "model", "object" ]
e28f6cfd63f9091d5a215171568648ca5a0e4716
https://github.com/lovata/oc-toolbox-plugin/blob/e28f6cfd63f9091d5a215171568648ca5a0e4716/traits/helpers/PriceHelperTrait.php#L29-L51
train
lovata/oc-toolbox-plugin
classes/item/ElementItem.php
ElementItem.clearCache
public static function clearCache($iElementID) { if (empty($iElementID)) { return; } ItemStorage::clear(static::class, $iElementID); CCache::clear(static::getCacheTag(), $iElementID); }
php
public static function clearCache($iElementID) { if (empty($iElementID)) { return; } ItemStorage::clear(static::class, $iElementID); CCache::clear(static::getCacheTag(), $iElementID); }
[ "public", "static", "function", "clearCache", "(", "$", "iElementID", ")", "{", "if", "(", "empty", "(", "$", "iElementID", ")", ")", "{", "return", ";", "}", "ItemStorage", "::", "clear", "(", "static", "::", "class", ",", "$", "iElementID", ")", ";",...
Remove model data from cache @link https://github.com/lovata/oc-toolbox-plugin/wiki/ElementItem#clearcacheielementid @param int $iElementID
[ "Remove", "model", "data", "from", "cache" ]
e28f6cfd63f9091d5a215171568648ca5a0e4716
https://github.com/lovata/oc-toolbox-plugin/blob/e28f6cfd63f9091d5a215171568648ca5a0e4716/classes/item/ElementItem.php#L193-L201
train
lovata/oc-toolbox-plugin
classes/item/ElementItem.php
ElementItem.setData
protected function setData() { $this->initElementObject(); if (empty($this->obElement)) { return; } //Set default lang (if update cache with non default lang) if (self::$bLangInit && !empty(self::$sDefaultLang) && $this->obElement->isClassExtendedWith('RainLab.Translate.Behaviors.TranslatableModel')) { $this->obElement->lang(self::$sDefaultLang); } //Get cached field list from model and add fields to cache array $this->setCachedFieldList(); //Get element data $arResult = $this->getElementData(); if (empty($arResult) || !is_array($arResult)) { $arResult = []; } //Add fields values to cached array foreach ($arResult as $sField => $sValue) { $this->setAttribute($sField, $sValue); } //Save lang properties (integration with Translate plugin) $this->setLangProperties(); //Run methods from $arExtendResult array $this->setExtendData(); }
php
protected function setData() { $this->initElementObject(); if (empty($this->obElement)) { return; } //Set default lang (if update cache with non default lang) if (self::$bLangInit && !empty(self::$sDefaultLang) && $this->obElement->isClassExtendedWith('RainLab.Translate.Behaviors.TranslatableModel')) { $this->obElement->lang(self::$sDefaultLang); } //Get cached field list from model and add fields to cache array $this->setCachedFieldList(); //Get element data $arResult = $this->getElementData(); if (empty($arResult) || !is_array($arResult)) { $arResult = []; } //Add fields values to cached array foreach ($arResult as $sField => $sValue) { $this->setAttribute($sField, $sValue); } //Save lang properties (integration with Translate plugin) $this->setLangProperties(); //Run methods from $arExtendResult array $this->setExtendData(); }
[ "protected", "function", "setData", "(", ")", "{", "$", "this", "->", "initElementObject", "(", ")", ";", "if", "(", "empty", "(", "$", "this", "->", "obElement", ")", ")", "{", "return", ";", "}", "//Set default lang (if update cache with non default lang)", ...
Set data from model object
[ "Set", "data", "from", "model", "object" ]
e28f6cfd63f9091d5a215171568648ca5a0e4716
https://github.com/lovata/oc-toolbox-plugin/blob/e28f6cfd63f9091d5a215171568648ca5a0e4716/classes/item/ElementItem.php#L259-L290
train
lovata/oc-toolbox-plugin
classes/item/ElementItem.php
ElementItem.setCachedFieldList
protected function setCachedFieldList() { if (!method_exists($this->obElement, 'getCachedField')) { return; } //Get cached field list $arFieldList = $this->obElement->getCachedField(); if (empty($arFieldList)) { return; } foreach ($arFieldList as $sField) { if (array_key_exists($sField, (array) $this->obElement->attachOne)) { $arFileData = $this->getUploadFileData($this->obElement->$sField); $sFieldName = 'attachOne|'.$sField; $this->setAttribute($sFieldName, $arFileData); } elseif (array_key_exists($sField, (array) $this->obElement->attachMany)) { $arFileList = []; $obFileList = $this->obElement->$sField; foreach ($obFileList as $obFile) { $arFileData = $this->getUploadFileData($obFile); $arFileList[] = $arFileData; } $sFieldName = 'attachMany|'.$sField; $this->setAttribute($sFieldName, $arFileList); } else { $this->setAttribute($sField, $this->obElement->$sField); } } }
php
protected function setCachedFieldList() { if (!method_exists($this->obElement, 'getCachedField')) { return; } //Get cached field list $arFieldList = $this->obElement->getCachedField(); if (empty($arFieldList)) { return; } foreach ($arFieldList as $sField) { if (array_key_exists($sField, (array) $this->obElement->attachOne)) { $arFileData = $this->getUploadFileData($this->obElement->$sField); $sFieldName = 'attachOne|'.$sField; $this->setAttribute($sFieldName, $arFileData); } elseif (array_key_exists($sField, (array) $this->obElement->attachMany)) { $arFileList = []; $obFileList = $this->obElement->$sField; foreach ($obFileList as $obFile) { $arFileData = $this->getUploadFileData($obFile); $arFileList[] = $arFileData; } $sFieldName = 'attachMany|'.$sField; $this->setAttribute($sFieldName, $arFileList); } else { $this->setAttribute($sField, $this->obElement->$sField); } } }
[ "protected", "function", "setCachedFieldList", "(", ")", "{", "if", "(", "!", "method_exists", "(", "$", "this", "->", "obElement", ",", "'getCachedField'", ")", ")", "{", "return", ";", "}", "//Get cached field list", "$", "arFieldList", "=", "$", "this", "...
Get cached field list from model and add fields to cache array
[ "Get", "cached", "field", "list", "from", "model", "and", "add", "fields", "to", "cache", "array" ]
e28f6cfd63f9091d5a215171568648ca5a0e4716
https://github.com/lovata/oc-toolbox-plugin/blob/e28f6cfd63f9091d5a215171568648ca5a0e4716/classes/item/ElementItem.php#L295-L326
train
lovata/oc-toolbox-plugin
classes/item/ElementItem.php
ElementItem.setCachedData
protected function setCachedData() { if (empty($this->iElementID)) { return; } $arCacheTags = static::getCacheTag(); $sCacheKey = $this->iElementID; $this->arModelData = CCache::get($arCacheTags, $sCacheKey); if (!$this->isEmpty()) { return; } $this->setData(); //Set cache data CCache::forever($arCacheTags, $sCacheKey, $this->arModelData); }
php
protected function setCachedData() { if (empty($this->iElementID)) { return; } $arCacheTags = static::getCacheTag(); $sCacheKey = $this->iElementID; $this->arModelData = CCache::get($arCacheTags, $sCacheKey); if (!$this->isEmpty()) { return; } $this->setData(); //Set cache data CCache::forever($arCacheTags, $sCacheKey, $this->arModelData); }
[ "protected", "function", "setCachedData", "(", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "iElementID", ")", ")", "{", "return", ";", "}", "$", "arCacheTags", "=", "static", "::", "getCacheTag", "(", ")", ";", "$", "sCacheKey", "=", "$", "...
Set cached brand data
[ "Set", "cached", "brand", "data" ]
e28f6cfd63f9091d5a215171568648ca5a0e4716
https://github.com/lovata/oc-toolbox-plugin/blob/e28f6cfd63f9091d5a215171568648ca5a0e4716/classes/item/ElementItem.php#L351-L369
train
lovata/oc-toolbox-plugin
classes/item/ElementItem.php
ElementItem.initElementObject
protected function initElementObject() { $sModelClass = static::MODEL_CLASS; if (!empty($this->obElement) && !$this->obElement instanceof $sModelClass) { $this->obElement = null; } if (!empty($this->obElement) || empty($this->iElementID)) { return; } $this->setElementObject(); }
php
protected function initElementObject() { $sModelClass = static::MODEL_CLASS; if (!empty($this->obElement) && !$this->obElement instanceof $sModelClass) { $this->obElement = null; } if (!empty($this->obElement) || empty($this->iElementID)) { return; } $this->setElementObject(); }
[ "protected", "function", "initElementObject", "(", ")", "{", "$", "sModelClass", "=", "static", "::", "MODEL_CLASS", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "obElement", ")", "&&", "!", "$", "this", "->", "obElement", "instanceof", "$", "sM...
Init element object
[ "Init", "element", "object" ]
e28f6cfd63f9091d5a215171568648ca5a0e4716
https://github.com/lovata/oc-toolbox-plugin/blob/e28f6cfd63f9091d5a215171568648ca5a0e4716/classes/item/ElementItem.php#L422-L434
train
lovata/oc-toolbox-plugin
classes/item/ElementItem.php
ElementItem.setLangProperties
private function setLangProperties() { if (empty($this->obElement) || !$this->obElement->isClassExtendedWith('RainLab.Translate.Behaviors.TranslatableModel')) { return; } //Check translate model property if (empty($this->obElement->translatable) || !is_array($this->obElement->translatable)) { return; } //Get active lang list from Translate plugin $arLangList = self::getActiveLangList(); if (empty($arLangList)) { return; } //Process translatable fields foreach ($this->obElement->translatable as $sField) { //Check field name if (empty($sField) || (!is_string($sField) && !is_array($sField))) { continue; } if (is_array($sField)) { $sField = array_shift($sField); } if (!isset($this->arModelData[$sField]) || array_key_exists($sField, (array) $this->obElement->attachOne) || array_key_exists($sField, (array) $this->obElement->attachMany)) { continue; } //Save field value with different lang code foreach ($arLangList as $sLangCode) { $sLangField = $sField.'|'.$sLangCode; $sValue = $this->obElement->lang($sLangCode)->$sField; $this->setAttribute($sLangField, $sValue); } } }
php
private function setLangProperties() { if (empty($this->obElement) || !$this->obElement->isClassExtendedWith('RainLab.Translate.Behaviors.TranslatableModel')) { return; } //Check translate model property if (empty($this->obElement->translatable) || !is_array($this->obElement->translatable)) { return; } //Get active lang list from Translate plugin $arLangList = self::getActiveLangList(); if (empty($arLangList)) { return; } //Process translatable fields foreach ($this->obElement->translatable as $sField) { //Check field name if (empty($sField) || (!is_string($sField) && !is_array($sField))) { continue; } if (is_array($sField)) { $sField = array_shift($sField); } if (!isset($this->arModelData[$sField]) || array_key_exists($sField, (array) $this->obElement->attachOne) || array_key_exists($sField, (array) $this->obElement->attachMany)) { continue; } //Save field value with different lang code foreach ($arLangList as $sLangCode) { $sLangField = $sField.'|'.$sLangCode; $sValue = $this->obElement->lang($sLangCode)->$sField; $this->setAttribute($sLangField, $sValue); } } }
[ "private", "function", "setLangProperties", "(", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "obElement", ")", "||", "!", "$", "this", "->", "obElement", "->", "isClassExtendedWith", "(", "'RainLab.Translate.Behaviors.TranslatableModel'", ")", ")", "{"...
Process translatable fields and save values, how 'field_name|lang_code'
[ "Process", "translatable", "fields", "and", "save", "values", "how", "field_name|lang_code" ]
e28f6cfd63f9091d5a215171568648ca5a0e4716
https://github.com/lovata/oc-toolbox-plugin/blob/e28f6cfd63f9091d5a215171568648ca5a0e4716/classes/item/ElementItem.php#L457-L496
train
lovata/oc-toolbox-plugin
classes/item/ElementItem.php
ElementItem.getUploadFileData
private function getUploadFileData($obFile) : array { if (empty($obFile)) { return []; } //Set default lang in image object if (!empty(self::$sDefaultLang) && $obFile->isClassExtendedWith('RainLab.Translate.Behaviors.TranslatableModel')) { $obFile->lang(self::$sDefaultLang); } //Convert image data to array $arFileData = $obFile->toArray(); $arLangList = $this->getActiveLangList(); if (empty($arLangList) || !$obFile->isClassExtendedWith('RainLab.Translate.Behaviors.TranslatableModel')) { return $arFileData; } //Add lang fields to array foreach ($arLangList as $sLangCode) { $arFileData[$sLangCode] = []; foreach ($obFile->translatable as $sLangField) { $arFileData[$sLangCode][$sLangField] = $obFile->lang($sLangCode)->$sLangField; } } return $arFileData; }
php
private function getUploadFileData($obFile) : array { if (empty($obFile)) { return []; } //Set default lang in image object if (!empty(self::$sDefaultLang) && $obFile->isClassExtendedWith('RainLab.Translate.Behaviors.TranslatableModel')) { $obFile->lang(self::$sDefaultLang); } //Convert image data to array $arFileData = $obFile->toArray(); $arLangList = $this->getActiveLangList(); if (empty($arLangList) || !$obFile->isClassExtendedWith('RainLab.Translate.Behaviors.TranslatableModel')) { return $arFileData; } //Add lang fields to array foreach ($arLangList as $sLangCode) { $arFileData[$sLangCode] = []; foreach ($obFile->translatable as $sLangField) { $arFileData[$sLangCode][$sLangField] = $obFile->lang($sLangCode)->$sLangField; } } return $arFileData; }
[ "private", "function", "getUploadFileData", "(", "$", "obFile", ")", ":", "array", "{", "if", "(", "empty", "(", "$", "obFile", ")", ")", "{", "return", "[", "]", ";", "}", "//Set default lang in image object", "if", "(", "!", "empty", "(", "self", "::",...
Get image data from image object @param \System\Models\File $obFile @return []
[ "Get", "image", "data", "from", "image", "object" ]
e28f6cfd63f9091d5a215171568648ca5a0e4716
https://github.com/lovata/oc-toolbox-plugin/blob/e28f6cfd63f9091d5a215171568648ca5a0e4716/classes/item/ElementItem.php#L503-L530
train
lovata/oc-toolbox-plugin
Plugin.php
Plugin.boot
public function boot() { if (env('APP_ENV') == 'testing') { $this->app->bind(\Lovata\Toolbox\Classes\Item\TestItem::class, \Lovata\Toolbox\Classes\Item\TestItem::class); $this->app->bind(\Lovata\Toolbox\Classes\Collection\TestCollection::class, \Lovata\Toolbox\Classes\Collection\TestCollection::class); } }
php
public function boot() { if (env('APP_ENV') == 'testing') { $this->app->bind(\Lovata\Toolbox\Classes\Item\TestItem::class, \Lovata\Toolbox\Classes\Item\TestItem::class); $this->app->bind(\Lovata\Toolbox\Classes\Collection\TestCollection::class, \Lovata\Toolbox\Classes\Collection\TestCollection::class); } }
[ "public", "function", "boot", "(", ")", "{", "if", "(", "env", "(", "'APP_ENV'", ")", "==", "'testing'", ")", "{", "$", "this", "->", "app", "->", "bind", "(", "\\", "Lovata", "\\", "Toolbox", "\\", "Classes", "\\", "Item", "\\", "TestItem", "::", ...
Plugin boot method
[ "Plugin", "boot", "method" ]
e28f6cfd63f9091d5a215171568648ca5a0e4716
https://github.com/lovata/oc-toolbox-plugin/blob/e28f6cfd63f9091d5a215171568648ca5a0e4716/Plugin.php#L61-L67
train
lovata/oc-toolbox-plugin
models/CommonProperty.php
CommonProperty.getWidgetData
public function getWidgetData() { $arResult = []; switch ($this->type) { case self::TYPE_INPUT: $arResult = $this->getInputFieldSettings(); break; case self::TYPE_NUMBER: $arResult = $this->getNumberFieldSettings(); break; case self::TYPE_TEXT_AREA: $arResult = $this->getTextareaFieldSettings(); break; case self::TYPE_RICH_EDITOR: $arResult = $this->getRichEditorFieldSettings(); break; case self::TYPE_SINGLE_CHECKBOX: $arResult = $this->getSingleCheckboxFieldSettings(); break; case self::TYPE_SWITCH: $arResult = $this->getSwitchFieldSettings(); break; case self::TYPE_CHECKBOX: $arResult = $this->getCheckboxListSettings(); break; case self::TYPE_BALLOON: $arResult = $this->getBalloonSettings(); break; case self::TYPE_TAG_LIST: $arResult = $this->getTagListSettings(); break; case self::TYPE_SELECT: $arResult = $this->getSelectSettings(); break; case self::TYPE_RADIO: $arResult = $this->getRadioSettings(); break; case self::TYPE_DATE: $arResult = $this->getDateSettings(); break; case self::TYPE_COLOR_PICKER: $arResult = $this->getColorPickerSettings(); break; /** FILE FINDER TYPE */ case self::TYPE_MEDIA_FINDER: $arResult = $this->getMediaFinderSettings(); break; default: return $arResult; } //Get common widget settings if (empty($arResult)) { return $arResult; } $arResult = array_merge($arResult, $this->getDefaultConfigSettings()); return $arResult; }
php
public function getWidgetData() { $arResult = []; switch ($this->type) { case self::TYPE_INPUT: $arResult = $this->getInputFieldSettings(); break; case self::TYPE_NUMBER: $arResult = $this->getNumberFieldSettings(); break; case self::TYPE_TEXT_AREA: $arResult = $this->getTextareaFieldSettings(); break; case self::TYPE_RICH_EDITOR: $arResult = $this->getRichEditorFieldSettings(); break; case self::TYPE_SINGLE_CHECKBOX: $arResult = $this->getSingleCheckboxFieldSettings(); break; case self::TYPE_SWITCH: $arResult = $this->getSwitchFieldSettings(); break; case self::TYPE_CHECKBOX: $arResult = $this->getCheckboxListSettings(); break; case self::TYPE_BALLOON: $arResult = $this->getBalloonSettings(); break; case self::TYPE_TAG_LIST: $arResult = $this->getTagListSettings(); break; case self::TYPE_SELECT: $arResult = $this->getSelectSettings(); break; case self::TYPE_RADIO: $arResult = $this->getRadioSettings(); break; case self::TYPE_DATE: $arResult = $this->getDateSettings(); break; case self::TYPE_COLOR_PICKER: $arResult = $this->getColorPickerSettings(); break; /** FILE FINDER TYPE */ case self::TYPE_MEDIA_FINDER: $arResult = $this->getMediaFinderSettings(); break; default: return $arResult; } //Get common widget settings if (empty($arResult)) { return $arResult; } $arResult = array_merge($arResult, $this->getDefaultConfigSettings()); return $arResult; }
[ "public", "function", "getWidgetData", "(", ")", "{", "$", "arResult", "=", "[", "]", ";", "switch", "(", "$", "this", "->", "type", ")", "{", "case", "self", "::", "TYPE_INPUT", ":", "$", "arResult", "=", "$", "this", "->", "getInputFieldSettings", "(...
Get widget data @return array
[ "Get", "widget", "data" ]
e28f6cfd63f9091d5a215171568648ca5a0e4716
https://github.com/lovata/oc-toolbox-plugin/blob/e28f6cfd63f9091d5a215171568648ca5a0e4716/models/CommonProperty.php#L83-L143
train
lovata/oc-toolbox-plugin
models/CommonProperty.php
CommonProperty.getPropertyVariants
public function getPropertyVariants() { $arValueList = []; //Get and check settings array $arSettings = $this->settings; if (empty($arSettings) || !isset($arSettings['list']) || empty($arSettings['list'])) { return $arValueList; } //Get property value variants foreach ($arSettings['list'] as $arValue) { if (!isset($arValue['value']) || empty($arValue['value'])) { continue; } $arValueList[$arValue['value']] = $arValue['value']; } natsort($arValueList); return $arValueList; }
php
public function getPropertyVariants() { $arValueList = []; //Get and check settings array $arSettings = $this->settings; if (empty($arSettings) || !isset($arSettings['list']) || empty($arSettings['list'])) { return $arValueList; } //Get property value variants foreach ($arSettings['list'] as $arValue) { if (!isset($arValue['value']) || empty($arValue['value'])) { continue; } $arValueList[$arValue['value']] = $arValue['value']; } natsort($arValueList); return $arValueList; }
[ "public", "function", "getPropertyVariants", "(", ")", "{", "$", "arValueList", "=", "[", "]", ";", "//Get and check settings array", "$", "arSettings", "=", "$", "this", "->", "settings", ";", "if", "(", "empty", "(", "$", "arSettings", ")", "||", "!", "i...
Get property variants from settings @return array
[ "Get", "property", "variants", "from", "settings" ]
e28f6cfd63f9091d5a215171568648ca5a0e4716
https://github.com/lovata/oc-toolbox-plugin/blob/e28f6cfd63f9091d5a215171568648ca5a0e4716/models/CommonProperty.php#L149-L171
train
lovata/oc-toolbox-plugin
models/CommonProperty.php
CommonProperty.getTypeOptions
public function getTypeOptions() { $sLangPath = 'lovata.toolbox::lang.type.'; return [ self::TYPE_INPUT => Lang::get($sLangPath.self::TYPE_INPUT), self::TYPE_NUMBER => Lang::get($sLangPath.self::TYPE_NUMBER), self::TYPE_TEXT_AREA => Lang::get($sLangPath.self::TYPE_TEXT_AREA), self::TYPE_RICH_EDITOR => Lang::get($sLangPath.self::TYPE_RICH_EDITOR), self::TYPE_SINGLE_CHECKBOX => Lang::get($sLangPath.self::TYPE_SINGLE_CHECKBOX), self::TYPE_SWITCH => Lang::get($sLangPath.self::TYPE_SWITCH), self::TYPE_CHECKBOX => Lang::get($sLangPath.self::TYPE_CHECKBOX), self::TYPE_TAG_LIST => Lang::get($sLangPath.self::TYPE_TAG_LIST), self::TYPE_SELECT => Lang::get($sLangPath.self::TYPE_SELECT), self::TYPE_RADIO => Lang::get($sLangPath.self::TYPE_RADIO), self::TYPE_BALLOON => Lang::get($sLangPath.self::TYPE_BALLOON), self::TYPE_DATE => Lang::get($sLangPath.self::TYPE_DATE), self::TYPE_COLOR_PICKER => Lang::get($sLangPath.self::TYPE_COLOR_PICKER), self::TYPE_MEDIA_FINDER => Lang::get($sLangPath.self::TYPE_MEDIA_FINDER), ]; }
php
public function getTypeOptions() { $sLangPath = 'lovata.toolbox::lang.type.'; return [ self::TYPE_INPUT => Lang::get($sLangPath.self::TYPE_INPUT), self::TYPE_NUMBER => Lang::get($sLangPath.self::TYPE_NUMBER), self::TYPE_TEXT_AREA => Lang::get($sLangPath.self::TYPE_TEXT_AREA), self::TYPE_RICH_EDITOR => Lang::get($sLangPath.self::TYPE_RICH_EDITOR), self::TYPE_SINGLE_CHECKBOX => Lang::get($sLangPath.self::TYPE_SINGLE_CHECKBOX), self::TYPE_SWITCH => Lang::get($sLangPath.self::TYPE_SWITCH), self::TYPE_CHECKBOX => Lang::get($sLangPath.self::TYPE_CHECKBOX), self::TYPE_TAG_LIST => Lang::get($sLangPath.self::TYPE_TAG_LIST), self::TYPE_SELECT => Lang::get($sLangPath.self::TYPE_SELECT), self::TYPE_RADIO => Lang::get($sLangPath.self::TYPE_RADIO), self::TYPE_BALLOON => Lang::get($sLangPath.self::TYPE_BALLOON), self::TYPE_DATE => Lang::get($sLangPath.self::TYPE_DATE), self::TYPE_COLOR_PICKER => Lang::get($sLangPath.self::TYPE_COLOR_PICKER), self::TYPE_MEDIA_FINDER => Lang::get($sLangPath.self::TYPE_MEDIA_FINDER), ]; }
[ "public", "function", "getTypeOptions", "(", ")", "{", "$", "sLangPath", "=", "'lovata.toolbox::lang.type.'", ";", "return", "[", "self", "::", "TYPE_INPUT", "=>", "Lang", "::", "get", "(", "$", "sLangPath", ".", "self", "::", "TYPE_INPUT", ")", ",", "self",...
Get type list @return array
[ "Get", "type", "list" ]
e28f6cfd63f9091d5a215171568648ca5a0e4716
https://github.com/lovata/oc-toolbox-plugin/blob/e28f6cfd63f9091d5a215171568648ca5a0e4716/models/CommonProperty.php#L186-L206
train
lovata/oc-toolbox-plugin
models/CommonProperty.php
CommonProperty.getMediaFinderSettings
protected function getMediaFinderSettings() : array { $sMode = $this->getSettingValue(self::TYPE_MEDIA_FINDER); if (!in_array($sMode, ['file', 'image'])) { return []; } $arResult = [ 'type' => self::TYPE_MEDIA_FINDER, 'mode' => $sMode, ]; return $arResult; }
php
protected function getMediaFinderSettings() : array { $sMode = $this->getSettingValue(self::TYPE_MEDIA_FINDER); if (!in_array($sMode, ['file', 'image'])) { return []; } $arResult = [ 'type' => self::TYPE_MEDIA_FINDER, 'mode' => $sMode, ]; return $arResult; }
[ "protected", "function", "getMediaFinderSettings", "(", ")", ":", "array", "{", "$", "sMode", "=", "$", "this", "->", "getSettingValue", "(", "self", "::", "TYPE_MEDIA_FINDER", ")", ";", "if", "(", "!", "in_array", "(", "$", "sMode", ",", "[", "'file'", ...
Get field setting with type "media finder" @return array
[ "Get", "field", "setting", "with", "type", "media", "finder" ]
e28f6cfd63f9091d5a215171568648ca5a0e4716
https://github.com/lovata/oc-toolbox-plugin/blob/e28f6cfd63f9091d5a215171568648ca5a0e4716/models/CommonProperty.php#L447-L460
train
lovata/oc-toolbox-plugin
models/CommonProperty.php
CommonProperty.getDefaultConfigSettings
protected function getDefaultConfigSettings() : array { $arResult = [ 'tab' => 'lovata.toolbox::lang.tab.properties', 'span' => 'left', 'label' => $this->name, 'comment' => $this->description, ]; //Get property tab $sTabName = $this->getSettingValue('tab'); if (!empty($sTabName)) { $arResult['tab'] = $sTabName; } return $arResult; }
php
protected function getDefaultConfigSettings() : array { $arResult = [ 'tab' => 'lovata.toolbox::lang.tab.properties', 'span' => 'left', 'label' => $this->name, 'comment' => $this->description, ]; //Get property tab $sTabName = $this->getSettingValue('tab'); if (!empty($sTabName)) { $arResult['tab'] = $sTabName; } return $arResult; }
[ "protected", "function", "getDefaultConfigSettings", "(", ")", ":", "array", "{", "$", "arResult", "=", "[", "'tab'", "=>", "'lovata.toolbox::lang.tab.properties'", ",", "'span'", "=>", "'left'", ",", "'label'", "=>", "$", "this", "->", "name", ",", "'comment'",...
Get default config field settings @return array
[ "Get", "default", "config", "field", "settings" ]
e28f6cfd63f9091d5a215171568648ca5a0e4716
https://github.com/lovata/oc-toolbox-plugin/blob/e28f6cfd63f9091d5a215171568648ca5a0e4716/models/CommonProperty.php#L466-L482
train
lovata/oc-toolbox-plugin
models/CommonProperty.php
CommonProperty.getSettingValue
protected function getSettingValue($sKey) { $arSettings = $this->settings; if (empty($sKey) || empty($arSettings) || !isset($arSettings[$sKey])) { return null; } return $arSettings[$sKey]; }
php
protected function getSettingValue($sKey) { $arSettings = $this->settings; if (empty($sKey) || empty($arSettings) || !isset($arSettings[$sKey])) { return null; } return $arSettings[$sKey]; }
[ "protected", "function", "getSettingValue", "(", "$", "sKey", ")", "{", "$", "arSettings", "=", "$", "this", "->", "settings", ";", "if", "(", "empty", "(", "$", "sKey", ")", "||", "empty", "(", "$", "arSettings", ")", "||", "!", "isset", "(", "$", ...
Get property settings value @param string $sKey @return mixed|null
[ "Get", "property", "settings", "value" ]
e28f6cfd63f9091d5a215171568648ca5a0e4716
https://github.com/lovata/oc-toolbox-plugin/blob/e28f6cfd63f9091d5a215171568648ca5a0e4716/models/CommonProperty.php#L488-L496
train
lovata/oc-toolbox-plugin
classes/store/AbstractListStore.php
AbstractListStore.addToStoreList
protected function addToStoreList($sFieldName, $sClassName) { if (empty($sFieldName) || empty($sClassName) || !class_exists($sClassName)) { return; } $this->arStoreList[$sFieldName] = $sClassName::instance(); }
php
protected function addToStoreList($sFieldName, $sClassName) { if (empty($sFieldName) || empty($sClassName) || !class_exists($sClassName)) { return; } $this->arStoreList[$sFieldName] = $sClassName::instance(); }
[ "protected", "function", "addToStoreList", "(", "$", "sFieldName", ",", "$", "sClassName", ")", "{", "if", "(", "empty", "(", "$", "sFieldName", ")", "||", "empty", "(", "$", "sClassName", ")", "||", "!", "class_exists", "(", "$", "sClassName", ")", ")",...
Add store class to list and get store object @param string $sFieldName @param string $sClassName
[ "Add", "store", "class", "to", "list", "and", "get", "store", "object" ]
e28f6cfd63f9091d5a215171568648ca5a0e4716
https://github.com/lovata/oc-toolbox-plugin/blob/e28f6cfd63f9091d5a215171568648ca5a0e4716/classes/store/AbstractListStore.php#L35-L42
train
lovata/oc-toolbox-plugin
classes/helper/AbstractImportModel.php
AbstractImportModel.deactivateElements
public function deactivateElements() { if (!$this->bDeactivate) { return; } $arDeactivateIDList = array_diff((array) $this->arExistIDList, (array) $this->arProcessedIDList); if (empty($arDeactivateIDList)) { return; } //Get element list $sModelClass = $this->getModelClass(); $obElementList = $sModelClass::whereIn('external_id', $arDeactivateIDList)->get(); foreach ($obElementList as $obElement) { $obElement->active = false; $obElement->save(); } }
php
public function deactivateElements() { if (!$this->bDeactivate) { return; } $arDeactivateIDList = array_diff((array) $this->arExistIDList, (array) $this->arProcessedIDList); if (empty($arDeactivateIDList)) { return; } //Get element list $sModelClass = $this->getModelClass(); $obElementList = $sModelClass::whereIn('external_id', $arDeactivateIDList)->get(); foreach ($obElementList as $obElement) { $obElement->active = false; $obElement->save(); } }
[ "public", "function", "deactivateElements", "(", ")", "{", "if", "(", "!", "$", "this", "->", "bDeactivate", ")", "{", "return", ";", "}", "$", "arDeactivateIDList", "=", "array_diff", "(", "(", "array", ")", "$", "this", "->", "arExistIDList", ",", "(",...
Deactivate active elements
[ "Deactivate", "active", "elements" ]
e28f6cfd63f9091d5a215171568648ca5a0e4716
https://github.com/lovata/oc-toolbox-plugin/blob/e28f6cfd63f9091d5a215171568648ca5a0e4716/classes/helper/AbstractImportModel.php#L99-L117
train
lovata/oc-toolbox-plugin
classes/helper/AbstractImportModel.php
AbstractImportModel.run
protected function run() { $this->prepareImportData(); $this->fireBeforeImportEvent(); $this->findByExternalID(); if (!empty($this->obModel)) { $this->updateItem(); } else { $this->createItem(); } if (empty($this->obModel)) { return; } $this->processModelObject(); Event::fire(self::EVENT_AFTER_IMPORT, [$this->obModel, $this->arImportData]); }
php
protected function run() { $this->prepareImportData(); $this->fireBeforeImportEvent(); $this->findByExternalID(); if (!empty($this->obModel)) { $this->updateItem(); } else { $this->createItem(); } if (empty($this->obModel)) { return; } $this->processModelObject(); Event::fire(self::EVENT_AFTER_IMPORT, [$this->obModel, $this->arImportData]); }
[ "protected", "function", "run", "(", ")", "{", "$", "this", "->", "prepareImportData", "(", ")", ";", "$", "this", "->", "fireBeforeImportEvent", "(", ")", ";", "$", "this", "->", "findByExternalID", "(", ")", ";", "if", "(", "!", "empty", "(", "$", ...
Run import item
[ "Run", "import", "item" ]
e28f6cfd63f9091d5a215171568648ca5a0e4716
https://github.com/lovata/oc-toolbox-plugin/blob/e28f6cfd63f9091d5a215171568648ca5a0e4716/classes/helper/AbstractImportModel.php#L146-L164
train
lovata/oc-toolbox-plugin
classes/helper/AbstractImportModel.php
AbstractImportModel.findByExternalID
protected function findByExternalID() { $sModelClass = $this->getModelClass(); if ($this->bWithTrashed) { $this->obModel = $sModelClass::withTrashed()->getByExternalID($this->sExternalID)->first(); } else { $this->obModel = $sModelClass::getByExternalID($this->sExternalID)->first(); } }
php
protected function findByExternalID() { $sModelClass = $this->getModelClass(); if ($this->bWithTrashed) { $this->obModel = $sModelClass::withTrashed()->getByExternalID($this->sExternalID)->first(); } else { $this->obModel = $sModelClass::getByExternalID($this->sExternalID)->first(); } }
[ "protected", "function", "findByExternalID", "(", ")", "{", "$", "sModelClass", "=", "$", "this", "->", "getModelClass", "(", ")", ";", "if", "(", "$", "this", "->", "bWithTrashed", ")", "{", "$", "this", "->", "obModel", "=", "$", "sModelClass", "::", ...
Find item by external ID
[ "Find", "item", "by", "external", "ID" ]
e28f6cfd63f9091d5a215171568648ca5a0e4716
https://github.com/lovata/oc-toolbox-plugin/blob/e28f6cfd63f9091d5a215171568648ca5a0e4716/classes/helper/AbstractImportModel.php#L208-L216
train
lovata/oc-toolbox-plugin
classes/helper/AbstractImportModel.php
AbstractImportModel.fireBeforeImportEvent
protected function fireBeforeImportEvent() { $arEventData = [$this->getModelClass(), $this->arImportData]; $arEventData = Event::fire(self::EVENT_BEFORE_IMPORT, $arEventData); if (empty($arEventData)) { return; } foreach ($arEventData as $arModelData) { if (empty($arModelData)) { continue; } foreach ($arModelData as $sKey => $sValue) { $this->arImportData[$sKey] = $sValue; } } }
php
protected function fireBeforeImportEvent() { $arEventData = [$this->getModelClass(), $this->arImportData]; $arEventData = Event::fire(self::EVENT_BEFORE_IMPORT, $arEventData); if (empty($arEventData)) { return; } foreach ($arEventData as $arModelData) { if (empty($arModelData)) { continue; } foreach ($arModelData as $sKey => $sValue) { $this->arImportData[$sKey] = $sValue; } } }
[ "protected", "function", "fireBeforeImportEvent", "(", ")", "{", "$", "arEventData", "=", "[", "$", "this", "->", "getModelClass", "(", ")", ",", "$", "this", "->", "arImportData", "]", ";", "$", "arEventData", "=", "Event", "::", "fire", "(", "self", ":...
Fire beforeImport event and update import data array
[ "Fire", "beforeImport", "event", "and", "update", "import", "data", "array" ]
e28f6cfd63f9091d5a215171568648ca5a0e4716
https://github.com/lovata/oc-toolbox-plugin/blob/e28f6cfd63f9091d5a215171568648ca5a0e4716/classes/helper/AbstractImportModel.php#L246-L264
train
lovata/oc-toolbox-plugin
classes/helper/AbstractImportModel.php
AbstractImportModel.initImageList
protected function initImageList() { if (!array_key_exists('images', $this->arImportData)) { $this->bNeedUpdateImageList = false; return; } $this->bNeedUpdateImageList = true; $this->arImageList = explode(',', array_get($this->arImportData, 'images')); array_forget($this->arImportData, 'images'); if (empty($this->arImageList)) { return; } foreach ($this->arImageList as $iKey => $sPath) { $sPath = trim($sPath); if (empty($sPath)) { unset($this->arImageList[$iKey]); continue; } $sFilePath = storage_path($sPath); if (!file_exists($sFilePath)) { unset($this->arImageList[$iKey]); } else { $this->arImageList[$iKey] = $sFilePath; } } }
php
protected function initImageList() { if (!array_key_exists('images', $this->arImportData)) { $this->bNeedUpdateImageList = false; return; } $this->bNeedUpdateImageList = true; $this->arImageList = explode(',', array_get($this->arImportData, 'images')); array_forget($this->arImportData, 'images'); if (empty($this->arImageList)) { return; } foreach ($this->arImageList as $iKey => $sPath) { $sPath = trim($sPath); if (empty($sPath)) { unset($this->arImageList[$iKey]); continue; } $sFilePath = storage_path($sPath); if (!file_exists($sFilePath)) { unset($this->arImageList[$iKey]); } else { $this->arImageList[$iKey] = $sFilePath; } } }
[ "protected", "function", "initImageList", "(", ")", "{", "if", "(", "!", "array_key_exists", "(", "'images'", ",", "$", "this", "->", "arImportData", ")", ")", "{", "$", "this", "->", "bNeedUpdateImageList", "=", "false", ";", "return", ";", "}", "$", "t...
Init image list
[ "Init", "image", "list" ]
e28f6cfd63f9091d5a215171568648ca5a0e4716
https://github.com/lovata/oc-toolbox-plugin/blob/e28f6cfd63f9091d5a215171568648ca5a0e4716/classes/helper/AbstractImportModel.php#L269-L298
train
lovata/oc-toolbox-plugin
classes/helper/AbstractImportModel.php
AbstractImportModel.importImageList
protected function importImageList() { if (!$this->bNeedUpdateImageList) { return; } if (empty($this->arImageList)) { $this->removeAllImages(); return; } //Update old images $obImageList = $this->obModel->images; if (!$obImageList->isEmpty()) { /** @var File $obImage */ foreach ($obImageList as $obImage) { $sFilePath = array_shift($this->arImageList); //Check image if (!empty($sFilePath) && (!file_exists($obImage->getLocalPath()) || md5_file($sFilePath) != md5_file($obImage->getLocalPath()))) { $obImage->deleteThumbs(); $obImage->fromFile($sFilePath); $obImage->save(); } elseif (empty($sFilePath)) { $obImage->deleteThumbs(); $obImage->delete(); } } } //Create new images if (!empty($this->arImageList)) { foreach ($this->arImageList as $sFilePath) { $obImage = new File(); $obImage->fromFile($sFilePath); $this->obModel->images()->add($obImage); } } }
php
protected function importImageList() { if (!$this->bNeedUpdateImageList) { return; } if (empty($this->arImageList)) { $this->removeAllImages(); return; } //Update old images $obImageList = $this->obModel->images; if (!$obImageList->isEmpty()) { /** @var File $obImage */ foreach ($obImageList as $obImage) { $sFilePath = array_shift($this->arImageList); //Check image if (!empty($sFilePath) && (!file_exists($obImage->getLocalPath()) || md5_file($sFilePath) != md5_file($obImage->getLocalPath()))) { $obImage->deleteThumbs(); $obImage->fromFile($sFilePath); $obImage->save(); } elseif (empty($sFilePath)) { $obImage->deleteThumbs(); $obImage->delete(); } } } //Create new images if (!empty($this->arImageList)) { foreach ($this->arImageList as $sFilePath) { $obImage = new File(); $obImage->fromFile($sFilePath); $this->obModel->images()->add($obImage); } } }
[ "protected", "function", "importImageList", "(", ")", "{", "if", "(", "!", "$", "this", "->", "bNeedUpdateImageList", ")", "{", "return", ";", "}", "if", "(", "empty", "(", "$", "this", "->", "arImageList", ")", ")", "{", "$", "this", "->", "removeAllI...
Import obProductModel images
[ "Import", "obProductModel", "images" ]
e28f6cfd63f9091d5a215171568648ca5a0e4716
https://github.com/lovata/oc-toolbox-plugin/blob/e28f6cfd63f9091d5a215171568648ca5a0e4716/classes/helper/AbstractImportModel.php#L303-L343
train
lovata/oc-toolbox-plugin
classes/helper/AbstractImportModel.php
AbstractImportModel.initPreviewImage
protected function initPreviewImage() { if (!array_key_exists('preview_image', $this->arImportData)) { $this->bNeedUpdatePreviewImage = false; return; } $this->bNeedUpdatePreviewImage = true; $this->sPreviewImage = trim(array_get($this->arImportData, 'preview_image')); if (empty($this->sPreviewImage)) { return; } $this->sPreviewImage = storage_path($this->sPreviewImage); if (!file_exists($this->sPreviewImage)) { $this->sPreviewImage = null; } }
php
protected function initPreviewImage() { if (!array_key_exists('preview_image', $this->arImportData)) { $this->bNeedUpdatePreviewImage = false; return; } $this->bNeedUpdatePreviewImage = true; $this->sPreviewImage = trim(array_get($this->arImportData, 'preview_image')); if (empty($this->sPreviewImage)) { return; } $this->sPreviewImage = storage_path($this->sPreviewImage); if (!file_exists($this->sPreviewImage)) { $this->sPreviewImage = null; } }
[ "protected", "function", "initPreviewImage", "(", ")", "{", "if", "(", "!", "array_key_exists", "(", "'preview_image'", ",", "$", "this", "->", "arImportData", ")", ")", "{", "$", "this", "->", "bNeedUpdatePreviewImage", "=", "false", ";", "return", ";", "}"...
Init preview image path
[ "Init", "preview", "image", "path" ]
e28f6cfd63f9091d5a215171568648ca5a0e4716
https://github.com/lovata/oc-toolbox-plugin/blob/e28f6cfd63f9091d5a215171568648ca5a0e4716/classes/helper/AbstractImportModel.php#L348-L366
train
lovata/oc-toolbox-plugin
classes/helper/AbstractImportModel.php
AbstractImportModel.importPreviewImage
protected function importPreviewImage() { if (!$this->bNeedUpdatePreviewImage) { return; } $obPreviewImage = $this->obModel->preview_image; if (empty($obPreviewImage) && empty($this->sPreviewImage)) { return; } if (empty($obPreviewImage) && !empty($this->sPreviewImage)) { //Create new preview $obPreviewImage = new File(); $obPreviewImage->fromFile($this->sPreviewImage); $this->obModel->preview_image()->add($obPreviewImage); return; } if (!file_exists($obPreviewImage->getLocalPath())) { $obPreviewImage->fromFile($this->sPreviewImage); $obPreviewImage->save(); } elseif (!empty($this->sPreviewImage) && file_exists($obPreviewImage->getLocalPath()) && md5_file($this->sPreviewImage) != md5_file($obPreviewImage->getLocalPath())) { //Update preview image $obPreviewImage->deleteThumbs(); $obPreviewImage->fromFile($this->sPreviewImage); $obPreviewImage->save(); } elseif (!empty($obPreviewImage) && empty($this->sPreviewImage)) { $obPreviewImage->deleteThumbs(); $obPreviewImage->delete(); } }
php
protected function importPreviewImage() { if (!$this->bNeedUpdatePreviewImage) { return; } $obPreviewImage = $this->obModel->preview_image; if (empty($obPreviewImage) && empty($this->sPreviewImage)) { return; } if (empty($obPreviewImage) && !empty($this->sPreviewImage)) { //Create new preview $obPreviewImage = new File(); $obPreviewImage->fromFile($this->sPreviewImage); $this->obModel->preview_image()->add($obPreviewImage); return; } if (!file_exists($obPreviewImage->getLocalPath())) { $obPreviewImage->fromFile($this->sPreviewImage); $obPreviewImage->save(); } elseif (!empty($this->sPreviewImage) && file_exists($obPreviewImage->getLocalPath()) && md5_file($this->sPreviewImage) != md5_file($obPreviewImage->getLocalPath())) { //Update preview image $obPreviewImage->deleteThumbs(); $obPreviewImage->fromFile($this->sPreviewImage); $obPreviewImage->save(); } elseif (!empty($obPreviewImage) && empty($this->sPreviewImage)) { $obPreviewImage->deleteThumbs(); $obPreviewImage->delete(); } }
[ "protected", "function", "importPreviewImage", "(", ")", "{", "if", "(", "!", "$", "this", "->", "bNeedUpdatePreviewImage", ")", "{", "return", ";", "}", "$", "obPreviewImage", "=", "$", "this", "->", "obModel", "->", "preview_image", ";", "if", "(", "empt...
Import preview image
[ "Import", "preview", "image" ]
e28f6cfd63f9091d5a215171568648ca5a0e4716
https://github.com/lovata/oc-toolbox-plugin/blob/e28f6cfd63f9091d5a215171568648ca5a0e4716/classes/helper/AbstractImportModel.php#L371-L403
train
lovata/oc-toolbox-plugin
classes/helper/AbstractImportModel.php
AbstractImportModel.removeAllImages
protected function removeAllImages() { //Delete old images $obImageList = $this->obModel->images; if ($obImageList->isEmpty()) { return; } /** @var \System\Models\File $obFile */ foreach ($obImageList as $obFile) { $obFile->deleteThumbs(); $obFile->delete(); } }
php
protected function removeAllImages() { //Delete old images $obImageList = $this->obModel->images; if ($obImageList->isEmpty()) { return; } /** @var \System\Models\File $obFile */ foreach ($obImageList as $obFile) { $obFile->deleteThumbs(); $obFile->delete(); } }
[ "protected", "function", "removeAllImages", "(", ")", "{", "//Delete old images", "$", "obImageList", "=", "$", "this", "->", "obModel", "->", "images", ";", "if", "(", "$", "obImageList", "->", "isEmpty", "(", ")", ")", "{", "return", ";", "}", "/** @var ...
Remove all images
[ "Remove", "all", "images" ]
e28f6cfd63f9091d5a215171568648ca5a0e4716
https://github.com/lovata/oc-toolbox-plugin/blob/e28f6cfd63f9091d5a215171568648ca5a0e4716/classes/helper/AbstractImportModel.php#L408-L421
train
lovata/oc-toolbox-plugin
classes/helper/AbstractImportModel.php
AbstractImportModel.setActiveField
protected function setActiveField() { $bActive = array_get($this->arImportData, 'active'); if ($bActive === null) { $this->arImportData['active'] = true; } else { $this->arImportData['active'] = (bool) $bActive; } }
php
protected function setActiveField() { $bActive = array_get($this->arImportData, 'active'); if ($bActive === null) { $this->arImportData['active'] = true; } else { $this->arImportData['active'] = (bool) $bActive; } }
[ "protected", "function", "setActiveField", "(", ")", "{", "$", "bActive", "=", "array_get", "(", "$", "this", "->", "arImportData", ",", "'active'", ")", ";", "if", "(", "$", "bActive", "===", "null", ")", "{", "$", "this", "->", "arImportData", "[", "...
Set active filed value, if active value is not null
[ "Set", "active", "filed", "value", "if", "active", "value", "is", "not", "null" ]
e28f6cfd63f9091d5a215171568648ca5a0e4716
https://github.com/lovata/oc-toolbox-plugin/blob/e28f6cfd63f9091d5a215171568648ca5a0e4716/classes/helper/AbstractImportModel.php#L426-L434
train
lovata/oc-toolbox-plugin
classes/helper/AbstractImportModel.php
AbstractImportModel.createJob
protected function createJob() { $sQueueName = Settings::getValue('import_queue_name'); $arQueueData = [ 'class' => static::class, 'data' => $this->arImportData, ]; if (empty($sQueueName)) { Queue::push(ImportItemQueue::class, $arQueueData); } else { Queue::pushOn($sQueueName, ImportItemQueue::class, $arQueueData); } $this->setResultMethod(); }
php
protected function createJob() { $sQueueName = Settings::getValue('import_queue_name'); $arQueueData = [ 'class' => static::class, 'data' => $this->arImportData, ]; if (empty($sQueueName)) { Queue::push(ImportItemQueue::class, $arQueueData); } else { Queue::pushOn($sQueueName, ImportItemQueue::class, $arQueueData); } $this->setResultMethod(); }
[ "protected", "function", "createJob", "(", ")", "{", "$", "sQueueName", "=", "Settings", "::", "getValue", "(", "'import_queue_name'", ")", ";", "$", "arQueueData", "=", "[", "'class'", "=>", "static", "::", "class", ",", "'data'", "=>", "$", "this", "->",...
Create queue job with import single item @throws \Throwable
[ "Create", "queue", "job", "with", "import", "single", "item" ]
e28f6cfd63f9091d5a215171568648ca5a0e4716
https://github.com/lovata/oc-toolbox-plugin/blob/e28f6cfd63f9091d5a215171568648ca5a0e4716/classes/helper/AbstractImportModel.php#L440-L456
train
lovata/oc-toolbox-plugin
traits/helpers/TraitValidationHelper.php
TraitValidationHelper.processValidationError
protected function processValidationError(&$obException) { $arFiledList = array_keys($obException->getFields()); Result::setFalse(['field' => array_shift($arFiledList)]) ->setMessage($obException->getMessage()) ->setCode($obException->getCode()); }
php
protected function processValidationError(&$obException) { $arFiledList = array_keys($obException->getFields()); Result::setFalse(['field' => array_shift($arFiledList)]) ->setMessage($obException->getMessage()) ->setCode($obException->getCode()); }
[ "protected", "function", "processValidationError", "(", "&", "$", "obException", ")", "{", "$", "arFiledList", "=", "array_keys", "(", "$", "obException", "->", "getFields", "(", ")", ")", ";", "Result", "::", "setFalse", "(", "[", "'field'", "=>", "array_sh...
Process validation error data @param \October\Rain\Database\ModelException $obException
[ "Process", "validation", "error", "data" ]
e28f6cfd63f9091d5a215171568648ca5a0e4716
https://github.com/lovata/oc-toolbox-plugin/blob/e28f6cfd63f9091d5a215171568648ca5a0e4716/traits/helpers/TraitValidationHelper.php#L16-L23
train
lovata/oc-toolbox-plugin
traits/helpers/TraitInitActiveLang.php
TraitInitActiveLang.getActiveLangList
protected function getActiveLangList() { if (self::$arActiveLangList !== null || !PluginManager::instance()->hasPlugin('RainLab.Translate')) { return self::$arActiveLangList; } self::$arActiveLangList = \RainLab\Translate\Models\Locale::isEnabled()->lists('code'); if (empty(self::$arActiveLangList)) { return self::$arActiveLangList; } //Remove default lang from list foreach (self::$arActiveLangList as $iKey => $sLangCode) { if ($sLangCode == self::$sDefaultLang) { unset(self::$arActiveLangList[$iKey]); break; } } return self::$arActiveLangList; }
php
protected function getActiveLangList() { if (self::$arActiveLangList !== null || !PluginManager::instance()->hasPlugin('RainLab.Translate')) { return self::$arActiveLangList; } self::$arActiveLangList = \RainLab\Translate\Models\Locale::isEnabled()->lists('code'); if (empty(self::$arActiveLangList)) { return self::$arActiveLangList; } //Remove default lang from list foreach (self::$arActiveLangList as $iKey => $sLangCode) { if ($sLangCode == self::$sDefaultLang) { unset(self::$arActiveLangList[$iKey]); break; } } return self::$arActiveLangList; }
[ "protected", "function", "getActiveLangList", "(", ")", "{", "if", "(", "self", "::", "$", "arActiveLangList", "!==", "null", "||", "!", "PluginManager", "::", "instance", "(", ")", "->", "hasPlugin", "(", "'RainLab.Translate'", ")", ")", "{", "return", "sel...
Get and save active lang list
[ "Get", "and", "save", "active", "lang", "list" ]
e28f6cfd63f9091d5a215171568648ca5a0e4716
https://github.com/lovata/oc-toolbox-plugin/blob/e28f6cfd63f9091d5a215171568648ca5a0e4716/traits/helpers/TraitInitActiveLang.php#L27-L47
train
lovata/oc-toolbox-plugin
traits/helpers/TraitInitActiveLang.php
TraitInitActiveLang.initActiveLang
protected function initActiveLang() { if (self::$bLangInit || !PluginManager::instance()->hasPlugin('RainLab.Translate')) { return; } self::$bLangInit = true; $obTranslate = \RainLab\Translate\Classes\Translator::instance(); self::$sDefaultLang = $obTranslate->getDefaultLocale(); $sActiveLangCode = $obTranslate->getLocale(); if (empty($sActiveLangCode) || $obTranslate->getDefaultLocale() == $sActiveLangCode) { return; } self::$sActiveLang = $sActiveLangCode; }
php
protected function initActiveLang() { if (self::$bLangInit || !PluginManager::instance()->hasPlugin('RainLab.Translate')) { return; } self::$bLangInit = true; $obTranslate = \RainLab\Translate\Classes\Translator::instance(); self::$sDefaultLang = $obTranslate->getDefaultLocale(); $sActiveLangCode = $obTranslate->getLocale(); if (empty($sActiveLangCode) || $obTranslate->getDefaultLocale() == $sActiveLangCode) { return; } self::$sActiveLang = $sActiveLangCode; }
[ "protected", "function", "initActiveLang", "(", ")", "{", "if", "(", "self", "::", "$", "bLangInit", "||", "!", "PluginManager", "::", "instance", "(", ")", "->", "hasPlugin", "(", "'RainLab.Translate'", ")", ")", "{", "return", ";", "}", "self", "::", "...
Get and save active lang from Translate plugin
[ "Get", "and", "save", "active", "lang", "from", "Translate", "plugin" ]
e28f6cfd63f9091d5a215171568648ca5a0e4716
https://github.com/lovata/oc-toolbox-plugin/blob/e28f6cfd63f9091d5a215171568648ca5a0e4716/traits/helpers/TraitInitActiveLang.php#L52-L69
train
lovata/oc-toolbox-plugin
traits/models/SetPropertyAttributeTrait.php
SetPropertyAttributeTrait.setPropertyAttribute
protected function setPropertyAttribute($arValue) { if (is_string($arValue)) { $arValue = $this->fromJson($arValue); } if (empty($arValue) || !is_array($arValue)) { return; } $arPropertyList = $this->property; if (empty($arPropertyList)) { $arPropertyList = []; } foreach ($arValue as $sKey => $sValue) { $arPropertyList[$sKey] = $sValue; } $this->attributes['property'] = $this->asJson($arPropertyList); }
php
protected function setPropertyAttribute($arValue) { if (is_string($arValue)) { $arValue = $this->fromJson($arValue); } if (empty($arValue) || !is_array($arValue)) { return; } $arPropertyList = $this->property; if (empty($arPropertyList)) { $arPropertyList = []; } foreach ($arValue as $sKey => $sValue) { $arPropertyList[$sKey] = $sValue; } $this->attributes['property'] = $this->asJson($arPropertyList); }
[ "protected", "function", "setPropertyAttribute", "(", "$", "arValue", ")", "{", "if", "(", "is_string", "(", "$", "arValue", ")", ")", "{", "$", "arValue", "=", "$", "this", "->", "fromJson", "(", "$", "arValue", ")", ";", "}", "if", "(", "empty", "(...
Set property attribute, nerge new values with old values @param array $arValue
[ "Set", "property", "attribute", "nerge", "new", "values", "with", "old", "values" ]
e28f6cfd63f9091d5a215171568648ca5a0e4716
https://github.com/lovata/oc-toolbox-plugin/blob/e28f6cfd63f9091d5a215171568648ca5a0e4716/traits/models/SetPropertyAttributeTrait.php#L15-L35
train
lovata/oc-toolbox-plugin
classes/component/SortingElementList.php
SortingElementList.setActiveSorting
protected function setActiveSorting() { $this->sSorting = Input::get('sort'); if (empty($this->sSorting)) { $this->sSorting = $this->property('sorting'); } }
php
protected function setActiveSorting() { $this->sSorting = Input::get('sort'); if (empty($this->sSorting)) { $this->sSorting = $this->property('sorting'); } }
[ "protected", "function", "setActiveSorting", "(", ")", "{", "$", "this", "->", "sSorting", "=", "Input", "::", "get", "(", "'sort'", ")", ";", "if", "(", "empty", "(", "$", "this", "->", "sSorting", ")", ")", "{", "$", "this", "->", "sSorting", "=", ...
Set active sorting
[ "Set", "active", "sorting" ]
e28f6cfd63f9091d5a215171568648ca5a0e4716
https://github.com/lovata/oc-toolbox-plugin/blob/e28f6cfd63f9091d5a215171568648ca5a0e4716/classes/component/SortingElementList.php#L37-L43
train
lovata/oc-toolbox-plugin
classes/collection/ElementCollection.php
ElementCollection.make
public static function make($arElementIDList = []) { /** @var ElementCollection $obCollection */ $obCollection = app()->make(static::class); if (!empty($arElementIDList) && is_array($arElementIDList)) { $obCollection->arElementIDList = $arElementIDList; } return $obCollection->returnThis(); }
php
public static function make($arElementIDList = []) { /** @var ElementCollection $obCollection */ $obCollection = app()->make(static::class); if (!empty($arElementIDList) && is_array($arElementIDList)) { $obCollection->arElementIDList = $arElementIDList; } return $obCollection->returnThis(); }
[ "public", "static", "function", "make", "(", "$", "arElementIDList", "=", "[", "]", ")", "{", "/** @var ElementCollection $obCollection */", "$", "obCollection", "=", "app", "(", ")", "->", "make", "(", "static", "::", "class", ")", ";", "if", "(", "!", "e...
Make new list store @see \Lovata\Toolbox\Tests\Unit\CollectionTest::testMakeMethod() @link https://github.com/lovata/oc-toolbox-plugin/wiki/ElementCollection#makearelementidlist-- @param array $arElementIDList - element ID list @return $this
[ "Make", "new", "list", "store" ]
e28f6cfd63f9091d5a215171568648ca5a0e4716
https://github.com/lovata/oc-toolbox-plugin/blob/e28f6cfd63f9091d5a215171568648ca5a0e4716/classes/collection/ElementCollection.php#L41-L51
train
lovata/oc-toolbox-plugin
classes/collection/ElementCollection.php
ElementCollection.has
public function has($iElementID) { if (empty($iElementID) || $this->isEmpty()) { return false; } return in_array($iElementID, (array) $this->arElementIDList); }
php
public function has($iElementID) { if (empty($iElementID) || $this->isEmpty()) { return false; } return in_array($iElementID, (array) $this->arElementIDList); }
[ "public", "function", "has", "(", "$", "iElementID", ")", "{", "if", "(", "empty", "(", "$", "iElementID", ")", "||", "$", "this", "->", "isEmpty", "(", ")", ")", "{", "return", "false", ";", "}", "return", "in_array", "(", "$", "iElementID", ",", ...
Checking, has collection ID @see \Lovata\Toolbox\Tests\Unit\CollectionTest::testHasMethod() @link https://github.com/lovata/oc-toolbox-plugin/wiki/ElementCollection#hasielementid @param int $iElementID @return bool
[ "Checking", "has", "collection", "ID" ]
e28f6cfd63f9091d5a215171568648ca5a0e4716
https://github.com/lovata/oc-toolbox-plugin/blob/e28f6cfd63f9091d5a215171568648ca5a0e4716/classes/collection/ElementCollection.php#L124-L131
train
lovata/oc-toolbox-plugin
classes/collection/ElementCollection.php
ElementCollection.find
public function find($iElementID) { if (!$this->has($iElementID)) { return $this->makeItem(null); } return $this->makeItem($iElementID); }
php
public function find($iElementID) { if (!$this->has($iElementID)) { return $this->makeItem(null); } return $this->makeItem($iElementID); }
[ "public", "function", "find", "(", "$", "iElementID", ")", "{", "if", "(", "!", "$", "this", "->", "has", "(", "$", "iElementID", ")", ")", "{", "return", "$", "this", "->", "makeItem", "(", "null", ")", ";", "}", "return", "$", "this", "->", "ma...
Get element item with ID @see \Lovata\Toolbox\Tests\Unit\CollectionTest::testFindMethod() @link https://github.com/lovata/oc-toolbox-plugin/wiki/ElementCollection#findielementid @param int $iElementID @return \Lovata\Toolbox\Classes\Item\ElementItem
[ "Get", "element", "item", "with", "ID" ]
e28f6cfd63f9091d5a215171568648ca5a0e4716
https://github.com/lovata/oc-toolbox-plugin/blob/e28f6cfd63f9091d5a215171568648ca5a0e4716/classes/collection/ElementCollection.php#L140-L147
train
lovata/oc-toolbox-plugin
classes/collection/ElementCollection.php
ElementCollection.intersect
public function intersect($arElementIDList) { if (empty($arElementIDList)) { return $this->clear(); } if ($this->isClear()) { $this->arElementIDList = $arElementIDList; return $this->returnThis(); } $this->arElementIDList = array_combine($this->arElementIDList, $this->arElementIDList); $arElementIDList = array_combine($arElementIDList, $arElementIDList); $this->arElementIDList = array_intersect_key($this->arElementIDList, $arElementIDList); return $this->returnThis(); }
php
public function intersect($arElementIDList) { if (empty($arElementIDList)) { return $this->clear(); } if ($this->isClear()) { $this->arElementIDList = $arElementIDList; return $this->returnThis(); } $this->arElementIDList = array_combine($this->arElementIDList, $this->arElementIDList); $arElementIDList = array_combine($arElementIDList, $arElementIDList); $this->arElementIDList = array_intersect_key($this->arElementIDList, $arElementIDList); return $this->returnThis(); }
[ "public", "function", "intersect", "(", "$", "arElementIDList", ")", "{", "if", "(", "empty", "(", "$", "arElementIDList", ")", ")", "{", "return", "$", "this", "->", "clear", "(", ")", ";", "}", "if", "(", "$", "this", "->", "isClear", "(", ")", "...
Apply array_intersect for element array list @see \Lovata\Toolbox\Tests\Unit\CollectionTest::testIntersectMethod() @link https://github.com/lovata/oc-toolbox-plugin/wiki/ElementCollection#intersectarelementidlist @param array $arElementIDList @return $this
[ "Apply", "array_intersect", "for", "element", "array", "list" ]
e28f6cfd63f9091d5a215171568648ca5a0e4716
https://github.com/lovata/oc-toolbox-plugin/blob/e28f6cfd63f9091d5a215171568648ca5a0e4716/classes/collection/ElementCollection.php#L184-L202
train
lovata/oc-toolbox-plugin
classes/collection/ElementCollection.php
ElementCollection.merge
public function merge($arElementIDList) { if (empty($arElementIDList)) { return $this->returnThis(); } if ($this->isClear()) { $this->arElementIDList = $arElementIDList; return $this->returnThis(); } $this->arElementIDList = array_merge($this->arElementIDList, $arElementIDList); $this->arElementIDList = array_unique($this->arElementIDList); return $this->returnThis(); }
php
public function merge($arElementIDList) { if (empty($arElementIDList)) { return $this->returnThis(); } if ($this->isClear()) { $this->arElementIDList = $arElementIDList; return $this->returnThis(); } $this->arElementIDList = array_merge($this->arElementIDList, $arElementIDList); $this->arElementIDList = array_unique($this->arElementIDList); return $this->returnThis(); }
[ "public", "function", "merge", "(", "$", "arElementIDList", ")", "{", "if", "(", "empty", "(", "$", "arElementIDList", ")", ")", "{", "return", "$", "this", "->", "returnThis", "(", ")", ";", "}", "if", "(", "$", "this", "->", "isClear", "(", ")", ...
Apply array_merge for element array list @see \Lovata\Toolbox\Tests\Unit\CollectionTest::testMergeMethod() @link https://github.com/lovata/oc-toolbox-plugin/wiki/ElementCollection#mergearelementidlist @param array $arElementIDList @return $this
[ "Apply", "array_merge", "for", "element", "array", "list" ]
e28f6cfd63f9091d5a215171568648ca5a0e4716
https://github.com/lovata/oc-toolbox-plugin/blob/e28f6cfd63f9091d5a215171568648ca5a0e4716/classes/collection/ElementCollection.php#L240-L256
train
lovata/oc-toolbox-plugin
classes/collection/ElementCollection.php
ElementCollection.diff
public function diff($arExcludeIDList = []) { if (empty($arExcludeIDList) || $this->isEmpty()) { return $this->returnThis(); } $this->arElementIDList = array_diff($this->arElementIDList, $arExcludeIDList); return $this->returnThis(); }
php
public function diff($arExcludeIDList = []) { if (empty($arExcludeIDList) || $this->isEmpty()) { return $this->returnThis(); } $this->arElementIDList = array_diff($this->arElementIDList, $arExcludeIDList); return $this->returnThis(); }
[ "public", "function", "diff", "(", "$", "arExcludeIDList", "=", "[", "]", ")", "{", "if", "(", "empty", "(", "$", "arExcludeIDList", ")", "||", "$", "this", "->", "isEmpty", "(", ")", ")", "{", "return", "$", "this", "->", "returnThis", "(", ")", "...
Apply array_diff for element array list @see \Lovata\Toolbox\Tests\Unit\CollectionTest::testDiffMethod() @link https://github.com/lovata/oc-toolbox-plugin/wiki/ElementCollection#diffarelementidlist @param array $arExcludeIDList @return $this
[ "Apply", "array_diff", "for", "element", "array", "list" ]
e28f6cfd63f9091d5a215171568648ca5a0e4716
https://github.com/lovata/oc-toolbox-plugin/blob/e28f6cfd63f9091d5a215171568648ca5a0e4716/classes/collection/ElementCollection.php#L265-L274
train
lovata/oc-toolbox-plugin
classes/collection/ElementCollection.php
ElementCollection.all
public function all() { if ($this->isEmpty()) { return []; } $arResult = []; foreach ($this->arElementIDList as $iElementID) { $obElementItem = $this->makeItem($iElementID, null); if ($obElementItem->isEmpty()) { continue; } $arResult[$iElementID] = $obElementItem; } return $arResult; }
php
public function all() { if ($this->isEmpty()) { return []; } $arResult = []; foreach ($this->arElementIDList as $iElementID) { $obElementItem = $this->makeItem($iElementID, null); if ($obElementItem->isEmpty()) { continue; } $arResult[$iElementID] = $obElementItem; } return $arResult; }
[ "public", "function", "all", "(", ")", "{", "if", "(", "$", "this", "->", "isEmpty", "(", ")", ")", "{", "return", "[", "]", ";", "}", "$", "arResult", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "arElementIDList", "as", "$", "iElement...
Get element item list @see \Lovata\Toolbox\Tests\Unit\CollectionTest::testAllMethod() @link https://github.com/lovata/oc-toolbox-plugin/wiki/ElementCollection#all @return array|\Lovata\Toolbox\Classes\Item\ElementItem[]
[ "Get", "element", "item", "list" ]
e28f6cfd63f9091d5a215171568648ca5a0e4716
https://github.com/lovata/oc-toolbox-plugin/blob/e28f6cfd63f9091d5a215171568648ca5a0e4716/classes/collection/ElementCollection.php#L282-L299
train
lovata/oc-toolbox-plugin
classes/collection/ElementCollection.php
ElementCollection.take
public function take($iCount = 0) { $iCount = (int) trim($iCount); if ($this->isEmpty()) { return []; } if (empty($iCount)) { $iCount = null; } $arResultIDList = array_slice($this->arElementIDList, $this->iSkip, $iCount); if (empty($arResultIDList)) { return []; } $arResult = []; foreach ($arResultIDList as $iElementID) { $obElementItem = $this->makeItem($iElementID, null); if ($obElementItem->isEmpty()) { continue; } $arResult[$iElementID] = $obElementItem; } return $arResult; }
php
public function take($iCount = 0) { $iCount = (int) trim($iCount); if ($this->isEmpty()) { return []; } if (empty($iCount)) { $iCount = null; } $arResultIDList = array_slice($this->arElementIDList, $this->iSkip, $iCount); if (empty($arResultIDList)) { return []; } $arResult = []; foreach ($arResultIDList as $iElementID) { $obElementItem = $this->makeItem($iElementID, null); if ($obElementItem->isEmpty()) { continue; } $arResult[$iElementID] = $obElementItem; } return $arResult; }
[ "public", "function", "take", "(", "$", "iCount", "=", "0", ")", "{", "$", "iCount", "=", "(", "int", ")", "trim", "(", "$", "iCount", ")", ";", "if", "(", "$", "this", "->", "isEmpty", "(", ")", ")", "{", "return", "[", "]", ";", "}", "if", ...
Take array with element items @see \Lovata\Toolbox\Tests\Unit\CollectionTest::testTakeMethod() @link https://github.com/lovata/oc-toolbox-plugin/wiki/ElementCollection#takeicount--0 @param int $iCount @return array|\Lovata\Toolbox\Classes\Item\ElementItem[]
[ "Take", "array", "with", "element", "items" ]
e28f6cfd63f9091d5a215171568648ca5a0e4716
https://github.com/lovata/oc-toolbox-plugin/blob/e28f6cfd63f9091d5a215171568648ca5a0e4716/classes/collection/ElementCollection.php#L323-L350
train
lovata/oc-toolbox-plugin
classes/collection/ElementCollection.php
ElementCollection.exclude
public function exclude($iElementID = null) { if (empty($iElementID) || $this->isEmpty()) { return $this->returnThis(); } $iElementIDKey = array_search($iElementID, $this->arElementIDList); if ($iElementIDKey === false) { return $this->returnThis(); } unset($this->arElementIDList[$iElementIDKey]); return $this->returnThis(); }
php
public function exclude($iElementID = null) { if (empty($iElementID) || $this->isEmpty()) { return $this->returnThis(); } $iElementIDKey = array_search($iElementID, $this->arElementIDList); if ($iElementIDKey === false) { return $this->returnThis(); } unset($this->arElementIDList[$iElementIDKey]); return $this->returnThis(); }
[ "public", "function", "exclude", "(", "$", "iElementID", "=", "null", ")", "{", "if", "(", "empty", "(", "$", "iElementID", ")", "||", "$", "this", "->", "isEmpty", "(", ")", ")", "{", "return", "$", "this", "->", "returnThis", "(", ")", ";", "}", ...
Exclude element id from collection @see \Lovata\Toolbox\Tests\Unit\CollectionTest::testExcludeMethod() @link https://github.com/lovata/oc-toolbox-plugin/wiki/ElementCollection#excludeielementid @param int $iElementID @return $this
[ "Exclude", "element", "id", "from", "collection" ]
e28f6cfd63f9091d5a215171568648ca5a0e4716
https://github.com/lovata/oc-toolbox-plugin/blob/e28f6cfd63f9091d5a215171568648ca5a0e4716/classes/collection/ElementCollection.php#L359-L373
train
lovata/oc-toolbox-plugin
classes/collection/ElementCollection.php
ElementCollection.random
public function random($iCount = 1) { if ($this->isEmpty()) { return []; } $iCount = (int) trim($iCount); if ($iCount < 1) { $iCount = 1; } if (count($this->arElementIDList) < $iCount) { $iCount = count($this->arElementIDList); } $obThis = $this->copy(); shuffle($obThis->arElementIDList); return $obThis->take($iCount); }
php
public function random($iCount = 1) { if ($this->isEmpty()) { return []; } $iCount = (int) trim($iCount); if ($iCount < 1) { $iCount = 1; } if (count($this->arElementIDList) < $iCount) { $iCount = count($this->arElementIDList); } $obThis = $this->copy(); shuffle($obThis->arElementIDList); return $obThis->take($iCount); }
[ "public", "function", "random", "(", "$", "iCount", "=", "1", ")", "{", "if", "(", "$", "this", "->", "isEmpty", "(", ")", ")", "{", "return", "[", "]", ";", "}", "$", "iCount", "=", "(", "int", ")", "trim", "(", "$", "iCount", ")", ";", "if"...
Take array with random element items @link https://github.com/lovata/oc-toolbox-plugin/wiki/ElementCollection#randomicount @param int $iCount @return array|\Lovata\Toolbox\Classes\Item\ElementItem[]
[ "Take", "array", "with", "random", "element", "items" ]
e28f6cfd63f9091d5a215171568648ca5a0e4716
https://github.com/lovata/oc-toolbox-plugin/blob/e28f6cfd63f9091d5a215171568648ca5a0e4716/classes/collection/ElementCollection.php#L381-L400
train
lovata/oc-toolbox-plugin
classes/collection/ElementCollection.php
ElementCollection.first
public function first() { if ($this->isEmpty()) { return $this->makeItem(null); } $arResultIDList = $this->arElementIDList; $iElementID = array_shift($arResultIDList); return $this->makeItem($iElementID); }
php
public function first() { if ($this->isEmpty()) { return $this->makeItem(null); } $arResultIDList = $this->arElementIDList; $iElementID = array_shift($arResultIDList); return $this->makeItem($iElementID); }
[ "public", "function", "first", "(", ")", "{", "if", "(", "$", "this", "->", "isEmpty", "(", ")", ")", "{", "return", "$", "this", "->", "makeItem", "(", "null", ")", ";", "}", "$", "arResultIDList", "=", "$", "this", "->", "arElementIDList", ";", "...
Get first element item @see \Lovata\Toolbox\Tests\Unit\CollectionTest::testFirstMethod() @link https://github.com/lovata/oc-toolbox-plugin/wiki/ElementCollection#first @return \Lovata\Toolbox\Classes\Item\ElementItem|null
[ "Get", "first", "element", "item" ]
e28f6cfd63f9091d5a215171568648ca5a0e4716
https://github.com/lovata/oc-toolbox-plugin/blob/e28f6cfd63f9091d5a215171568648ca5a0e4716/classes/collection/ElementCollection.php#L433-L444
train
lovata/oc-toolbox-plugin
classes/collection/ElementCollection.php
ElementCollection.last
public function last() { if ($this->isEmpty()) { return $this->makeItem(null); } $arResultIDList = $this->arElementIDList; $iElementID = array_pop($arResultIDList); return $this->makeItem($iElementID); }
php
public function last() { if ($this->isEmpty()) { return $this->makeItem(null); } $arResultIDList = $this->arElementIDList; $iElementID = array_pop($arResultIDList); return $this->makeItem($iElementID); }
[ "public", "function", "last", "(", ")", "{", "if", "(", "$", "this", "->", "isEmpty", "(", ")", ")", "{", "return", "$", "this", "->", "makeItem", "(", "null", ")", ";", "}", "$", "arResultIDList", "=", "$", "this", "->", "arElementIDList", ";", "$...
Get last element item @see \Lovata\Toolbox\Tests\Unit\CollectionTest::testLastMethod() @link https://github.com/lovata/oc-toolbox-plugin/wiki/ElementCollection#last @return \Lovata\Toolbox\Classes\Item\ElementItem|null
[ "Get", "last", "element", "item" ]
e28f6cfd63f9091d5a215171568648ca5a0e4716
https://github.com/lovata/oc-toolbox-plugin/blob/e28f6cfd63f9091d5a215171568648ca5a0e4716/classes/collection/ElementCollection.php#L452-L463
train
lovata/oc-toolbox-plugin
classes/collection/ElementCollection.php
ElementCollection.shift
public function shift() { if (empty($this->arElementIDList)) { return $this->makeItem(null); } $iElementID = array_shift($this->arElementIDList); return $this->makeItem($iElementID); }
php
public function shift() { if (empty($this->arElementIDList)) { return $this->makeItem(null); } $iElementID = array_shift($this->arElementIDList); return $this->makeItem($iElementID); }
[ "public", "function", "shift", "(", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "arElementIDList", ")", ")", "{", "return", "$", "this", "->", "makeItem", "(", "null", ")", ";", "}", "$", "iElementID", "=", "array_shift", "(", "$", "this", ...
Apply array_shift to element ID list and get first element item @see \Lovata\Toolbox\Tests\Unit\CollectionTest::testShiftMethod() @link https://github.com/lovata/oc-toolbox-plugin/wiki/ElementCollection#shift @return \Lovata\Toolbox\Classes\Item\ElementItem|null
[ "Apply", "array_shift", "to", "element", "ID", "list", "and", "get", "first", "element", "item" ]
e28f6cfd63f9091d5a215171568648ca5a0e4716
https://github.com/lovata/oc-toolbox-plugin/blob/e28f6cfd63f9091d5a215171568648ca5a0e4716/classes/collection/ElementCollection.php#L471-L480
train
lovata/oc-toolbox-plugin
classes/collection/ElementCollection.php
ElementCollection.unshift
public function unshift($iElementID) { if (empty($iElementID)) { return $this->returnThis(); } if ($this->isEmpty()) { $this->arElementIDList = [$iElementID]; return $this->returnThis(); } array_unshift($this->arElementIDList, $iElementID); return $this->returnThis(); }
php
public function unshift($iElementID) { if (empty($iElementID)) { return $this->returnThis(); } if ($this->isEmpty()) { $this->arElementIDList = [$iElementID]; return $this->returnThis(); } array_unshift($this->arElementIDList, $iElementID); return $this->returnThis(); }
[ "public", "function", "unshift", "(", "$", "iElementID", ")", "{", "if", "(", "empty", "(", "$", "iElementID", ")", ")", "{", "return", "$", "this", "->", "returnThis", "(", ")", ";", "}", "if", "(", "$", "this", "->", "isEmpty", "(", ")", ")", "...
Apply array_unshift to element ID @param int $iElementID @see \Lovata\Toolbox\Tests\Unit\CollectionTest::testUnshiftMethod() @link https://github.com/lovata/oc-toolbox-plugin/wiki/ElementCollection#unshiftielementid @return $this
[ "Apply", "array_unshift", "to", "element", "ID" ]
e28f6cfd63f9091d5a215171568648ca5a0e4716
https://github.com/lovata/oc-toolbox-plugin/blob/e28f6cfd63f9091d5a215171568648ca5a0e4716/classes/collection/ElementCollection.php#L489-L504
train
lovata/oc-toolbox-plugin
classes/collection/ElementCollection.php
ElementCollection.pop
public function pop() { if ($this->isEmpty()) { return $this->makeItem(null); } $iElementID = array_pop($this->arElementIDList); return $this->makeItem($iElementID); }
php
public function pop() { if ($this->isEmpty()) { return $this->makeItem(null); } $iElementID = array_pop($this->arElementIDList); return $this->makeItem($iElementID); }
[ "public", "function", "pop", "(", ")", "{", "if", "(", "$", "this", "->", "isEmpty", "(", ")", ")", "{", "return", "$", "this", "->", "makeItem", "(", "null", ")", ";", "}", "$", "iElementID", "=", "array_pop", "(", "$", "this", "->", "arElementIDL...
Apply array_pop to element ID list and get first element item @see \Lovata\Toolbox\Tests\Unit\CollectionTest::testPopMethod() @link https://github.com/lovata/oc-toolbox-plugin/wiki/ElementCollection#pop @return \Lovata\Toolbox\Classes\Item\ElementItem|null
[ "Apply", "array_pop", "to", "element", "ID", "list", "and", "get", "first", "element", "item" ]
e28f6cfd63f9091d5a215171568648ca5a0e4716
https://github.com/lovata/oc-toolbox-plugin/blob/e28f6cfd63f9091d5a215171568648ca5a0e4716/classes/collection/ElementCollection.php#L512-L521
train
lovata/oc-toolbox-plugin
classes/collection/ElementCollection.php
ElementCollection.push
public function push($iElementID) { if (empty($iElementID)) { return $this->returnThis(); } if ($this->isEmpty()) { $this->arElementIDList = [$iElementID]; return $this->returnThis(); } $this->arElementIDList[] = $iElementID; return $this->returnThis(); }
php
public function push($iElementID) { if (empty($iElementID)) { return $this->returnThis(); } if ($this->isEmpty()) { $this->arElementIDList = [$iElementID]; return $this->returnThis(); } $this->arElementIDList[] = $iElementID; return $this->returnThis(); }
[ "public", "function", "push", "(", "$", "iElementID", ")", "{", "if", "(", "empty", "(", "$", "iElementID", ")", ")", "{", "return", "$", "this", "->", "returnThis", "(", ")", ";", "}", "if", "(", "$", "this", "->", "isEmpty", "(", ")", ")", "{",...
Push element ID to end of list @param int $iElementID @see \Lovata\Toolbox\Tests\Unit\CollectionTest::testUnshiftMethod() @link https://github.com/lovata/oc-toolbox-plugin/wiki/ElementCollection#pushielementid @return $this
[ "Push", "element", "ID", "to", "end", "of", "list" ]
e28f6cfd63f9091d5a215171568648ca5a0e4716
https://github.com/lovata/oc-toolbox-plugin/blob/e28f6cfd63f9091d5a215171568648ca5a0e4716/classes/collection/ElementCollection.php#L530-L545
train
lovata/oc-toolbox-plugin
classes/helper/PriceHelper.php
PriceHelper.format
public static function format($fPrice) { $fPrice = (float) $fPrice; $obThis = self::instance(); return number_format($fPrice, $obThis->iDecimal, $obThis->sDecPoint, $obThis->sThousandsSep); }
php
public static function format($fPrice) { $fPrice = (float) $fPrice; $obThis = self::instance(); return number_format($fPrice, $obThis->iDecimal, $obThis->sDecPoint, $obThis->sThousandsSep); }
[ "public", "static", "function", "format", "(", "$", "fPrice", ")", "{", "$", "fPrice", "=", "(", "float", ")", "$", "fPrice", ";", "$", "obThis", "=", "self", "::", "instance", "(", ")", ";", "return", "number_format", "(", "$", "fPrice", ",", "$", ...
Apply custom format for price float value @param float $fPrice @return string
[ "Apply", "custom", "format", "for", "price", "float", "value" ]
e28f6cfd63f9091d5a215171568648ca5a0e4716
https://github.com/lovata/oc-toolbox-plugin/blob/e28f6cfd63f9091d5a215171568648ca5a0e4716/classes/helper/PriceHelper.php#L29-L36
train
lovata/oc-toolbox-plugin
classes/helper/PriceHelper.php
PriceHelper.toFloat
public static function toFloat($sValue) { $sValue = str_replace(',', '.', $sValue); $fPrice = (float) preg_replace("/[^0-9\.]/", "", $sValue); return $fPrice; }
php
public static function toFloat($sValue) { $sValue = str_replace(',', '.', $sValue); $fPrice = (float) preg_replace("/[^0-9\.]/", "", $sValue); return $fPrice; }
[ "public", "static", "function", "toFloat", "(", "$", "sValue", ")", "{", "$", "sValue", "=", "str_replace", "(", "','", ",", "'.'", ",", "$", "sValue", ")", ";", "$", "fPrice", "=", "(", "float", ")", "preg_replace", "(", "\"/[^0-9\\.]/\"", ",", "\"\""...
Convert price string to float value @param string $sValue @return float
[ "Convert", "price", "string", "to", "float", "value" ]
e28f6cfd63f9091d5a215171568648ca5a0e4716
https://github.com/lovata/oc-toolbox-plugin/blob/e28f6cfd63f9091d5a215171568648ca5a0e4716/classes/helper/PriceHelper.php#L43-L49
train
lovata/oc-toolbox-plugin
classes/helper/PriceHelper.php
PriceHelper.init
protected function init() { //Get options from settings $iDecimalValue = (int) Settings::getValue('decimals'); if ($iDecimalValue >= 0) { $this->iDecimal = $iDecimalValue; } $sDecPointValue = Settings::getValue('dec_point'); switch ($sDecPointValue) { case 'comma': $this->sDecPoint = ','; break; default: $this->sDecPoint = '.'; } $sThousandsSepValue = Settings::getValue('thousands_sep'); switch ($sThousandsSepValue) { case 'space': $this->sThousandsSep = ' '; break; default: $this->sThousandsSep = ''; } }
php
protected function init() { //Get options from settings $iDecimalValue = (int) Settings::getValue('decimals'); if ($iDecimalValue >= 0) { $this->iDecimal = $iDecimalValue; } $sDecPointValue = Settings::getValue('dec_point'); switch ($sDecPointValue) { case 'comma': $this->sDecPoint = ','; break; default: $this->sDecPoint = '.'; } $sThousandsSepValue = Settings::getValue('thousands_sep'); switch ($sThousandsSepValue) { case 'space': $this->sThousandsSep = ' '; break; default: $this->sThousandsSep = ''; } }
[ "protected", "function", "init", "(", ")", "{", "//Get options from settings", "$", "iDecimalValue", "=", "(", "int", ")", "Settings", "::", "getValue", "(", "'decimals'", ")", ";", "if", "(", "$", "iDecimalValue", ">=", "0", ")", "{", "$", "this", "->", ...
PriceHelper constructor.
[ "PriceHelper", "constructor", "." ]
e28f6cfd63f9091d5a215171568648ca5a0e4716
https://github.com/lovata/oc-toolbox-plugin/blob/e28f6cfd63f9091d5a215171568648ca5a0e4716/classes/helper/PriceHelper.php#L65-L90
train
lovata/oc-toolbox-plugin
classes/component/ElementPage.php
ElementPage.checkTransSlug
protected function checkTransSlug($obElement, $sElementSlug) { if (empty($obElement) || empty($sElementSlug)) { return false; } $bResult = $obElement->slug == $sElementSlug; return $bResult; }
php
protected function checkTransSlug($obElement, $sElementSlug) { if (empty($obElement) || empty($sElementSlug)) { return false; } $bResult = $obElement->slug == $sElementSlug; return $bResult; }
[ "protected", "function", "checkTransSlug", "(", "$", "obElement", ",", "$", "sElementSlug", ")", "{", "if", "(", "empty", "(", "$", "obElement", ")", "||", "empty", "(", "$", "sElementSlug", ")", ")", "{", "return", "false", ";", "}", "$", "bResult", "...
Checks trans value, if value is not form active lang, then return false @param \Model $obElement @param string $sElementSlug @return bool
[ "Checks", "trans", "value", "if", "value", "is", "not", "form", "active", "lang", "then", "return", "false" ]
e28f6cfd63f9091d5a215171568648ca5a0e4716
https://github.com/lovata/oc-toolbox-plugin/blob/e28f6cfd63f9091d5a215171568648ca5a0e4716/classes/component/ElementPage.php#L115-L124
train
lovata/oc-toolbox-plugin
classes/component/ElementPage.php
ElementPage.smartUrlCheck
protected function smartUrlCheck() { if (empty($this->obElementItem)) { return false; } $sCurrentURL = $this->currentPageUrl(); $sValidURL = $this->obElementItem->getPageUrl($this->page->id); $bResult = $sCurrentURL == $sValidURL; return $bResult; }
php
protected function smartUrlCheck() { if (empty($this->obElementItem)) { return false; } $sCurrentURL = $this->currentPageUrl(); $sValidURL = $this->obElementItem->getPageUrl($this->page->id); $bResult = $sCurrentURL == $sValidURL; return $bResult; }
[ "protected", "function", "smartUrlCheck", "(", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "obElementItem", ")", ")", "{", "return", "false", ";", "}", "$", "sCurrentURL", "=", "$", "this", "->", "currentPageUrl", "(", ")", ";", "$", "sValidU...
Smart check URL with additional checking @return bool
[ "Smart", "check", "URL", "with", "additional", "checking" ]
e28f6cfd63f9091d5a215171568648ca5a0e4716
https://github.com/lovata/oc-toolbox-plugin/blob/e28f6cfd63f9091d5a215171568648ca5a0e4716/classes/component/ElementPage.php#L130-L141
train