id
int32
0
241k
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
28,400
novaway/BehatCommonContext
src/Context/FormContext.php
FormContext.iFillInFieldWithoutLoosingFocus
public function iFillInFieldWithoutLoosingFocus($field, $value) { $driver = $this->getSession()->getDriver(); if ('Behat\Mink\Driver\Selenium2Driver' != get_class($driver)) { $field = $this->fixStepArgument($field); $value = $this->fixStepArgument($value); $this->getSession()->getPage()->fillField($field, $value); } else { if (null === ($locator = $this->getSession()->getPage()->findField($field))) { throw new \Exception(sprintf('Field "%s" not found.', $field)); } if (!($element = $driver->getWebDriverSession()->element('xpath', $locator->getXpath()))) { throw new \Exception(sprintf('Field "%s" not found.', $field)); } $element->postValue(['value' => [$value]]); } }
php
public function iFillInFieldWithoutLoosingFocus($field, $value) { $driver = $this->getSession()->getDriver(); if ('Behat\Mink\Driver\Selenium2Driver' != get_class($driver)) { $field = $this->fixStepArgument($field); $value = $this->fixStepArgument($value); $this->getSession()->getPage()->fillField($field, $value); } else { if (null === ($locator = $this->getSession()->getPage()->findField($field))) { throw new \Exception(sprintf('Field "%s" not found.', $field)); } if (!($element = $driver->getWebDriverSession()->element('xpath', $locator->getXpath()))) { throw new \Exception(sprintf('Field "%s" not found.', $field)); } $element->postValue(['value' => [$value]]); } }
[ "public", "function", "iFillInFieldWithoutLoosingFocus", "(", "$", "field", ",", "$", "value", ")", "{", "$", "driver", "=", "$", "this", "->", "getSession", "(", ")", "->", "getDriver", "(", ")", ";", "if", "(", "'Behat\\Mink\\Driver\\Selenium2Driver'", "!=", "get_class", "(", "$", "driver", ")", ")", "{", "$", "field", "=", "$", "this", "->", "fixStepArgument", "(", "$", "field", ")", ";", "$", "value", "=", "$", "this", "->", "fixStepArgument", "(", "$", "value", ")", ";", "$", "this", "->", "getSession", "(", ")", "->", "getPage", "(", ")", "->", "fillField", "(", "$", "field", ",", "$", "value", ")", ";", "}", "else", "{", "if", "(", "null", "===", "(", "$", "locator", "=", "$", "this", "->", "getSession", "(", ")", "->", "getPage", "(", ")", "->", "findField", "(", "$", "field", ")", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "sprintf", "(", "'Field \"%s\" not found.'", ",", "$", "field", ")", ")", ";", "}", "if", "(", "!", "(", "$", "element", "=", "$", "driver", "->", "getWebDriverSession", "(", ")", "->", "element", "(", "'xpath'", ",", "$", "locator", "->", "getXpath", "(", ")", ")", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "sprintf", "(", "'Field \"%s\" not found.'", ",", "$", "field", ")", ")", ";", "}", "$", "element", "->", "postValue", "(", "[", "'value'", "=>", "[", "$", "value", "]", "]", ")", ";", "}", "}" ]
Fills in form field with specified id|name|label|value without unfocus field @When /^(?:|I )fill in "(?P<field>(?:[^"]|\\")*)" with "(?P<value>(?:[^"]|\\")*)" without loosing focus$/ @When /^(?:|I )fill in "(?P<value>(?:[^"]|\\")*)" for "(?P<field>(?:[^"]|\\")*)" without loosing focus$/
[ "Fills", "in", "form", "field", "with", "specified", "id|name|label|value", "without", "unfocus", "field" ]
b5349bd6a36c0e0ca71465a5349f8d68c1d1e102
https://github.com/novaway/BehatCommonContext/blob/b5349bd6a36c0e0ca71465a5349f8d68c1d1e102/src/Context/FormContext.php#L13-L32
28,401
novaway/BehatCommonContext
src/Context/Select2Context.php
Select2Context.iFillInSelect2Field
public function iFillInSelect2Field($field, $value) { $page = $this->getSession()->getPage(); $this->openField($page, $field); $this->selectValue($page, $field, $value, $this->timeout); }
php
public function iFillInSelect2Field($field, $value) { $page = $this->getSession()->getPage(); $this->openField($page, $field); $this->selectValue($page, $field, $value, $this->timeout); }
[ "public", "function", "iFillInSelect2Field", "(", "$", "field", ",", "$", "value", ")", "{", "$", "page", "=", "$", "this", "->", "getSession", "(", ")", "->", "getPage", "(", ")", ";", "$", "this", "->", "openField", "(", "$", "page", ",", "$", "field", ")", ";", "$", "this", "->", "selectValue", "(", "$", "page", ",", "$", "field", ",", "$", "value", ",", "$", "this", "->", "timeout", ")", ";", "}" ]
Fills in Select2 field with specified @When /^(?:|I )fill in select2 "(?P<field>(?:[^"]|\\")*)" with "(?P<value>(?:[^"]|\\")*)"$/ @When /^(?:|I )fill in select2 "(?P<value>(?:[^"]|\\")*)" for "(?P<field>(?:[^"]|\\")*)"$/
[ "Fills", "in", "Select2", "field", "with", "specified" ]
b5349bd6a36c0e0ca71465a5349f8d68c1d1e102
https://github.com/novaway/BehatCommonContext/blob/b5349bd6a36c0e0ca71465a5349f8d68c1d1e102/src/Context/Select2Context.php#L30-L36
28,402
novaway/BehatCommonContext
src/Context/Select2Context.php
Select2Context.iFillInSelect2FieldWaitUntilResultsAreLoaded
public function iFillInSelect2FieldWaitUntilResultsAreLoaded($field, $value, $time) { $page = $this->getSession()->getPage(); $this->openField($page, $field); $this->selectValue($page, $field, $value, $time); }
php
public function iFillInSelect2FieldWaitUntilResultsAreLoaded($field, $value, $time) { $page = $this->getSession()->getPage(); $this->openField($page, $field); $this->selectValue($page, $field, $value, $time); }
[ "public", "function", "iFillInSelect2FieldWaitUntilResultsAreLoaded", "(", "$", "field", ",", "$", "value", ",", "$", "time", ")", "{", "$", "page", "=", "$", "this", "->", "getSession", "(", ")", "->", "getPage", "(", ")", ";", "$", "this", "->", "openField", "(", "$", "page", ",", "$", "field", ")", ";", "$", "this", "->", "selectValue", "(", "$", "page", ",", "$", "field", ",", "$", "value", ",", "$", "time", ")", ";", "}" ]
Fills in Select2 field with specified and wait for results @When /^(?:|I )fill in select2 "(?P<field>(?:[^"]|\\")*)" with "(?P<value>(?:[^"]|\\")*)" and wait (?P<time>(?:[^"]|\\")*) seconds until results are loaded$/ @When /^(?:|I )fill in select2 "(?P<value>(?:[^"]|\\")*)" for "(?P<field>(?:[^"]|\\")*)" and wait (?P<time>(?:[^"]|\\")*) seconds until results are loaded$/
[ "Fills", "in", "Select2", "field", "with", "specified", "and", "wait", "for", "results" ]
b5349bd6a36c0e0ca71465a5349f8d68c1d1e102
https://github.com/novaway/BehatCommonContext/blob/b5349bd6a36c0e0ca71465a5349f8d68c1d1e102/src/Context/Select2Context.php#L44-L50
28,403
novaway/BehatCommonContext
src/Context/Select2Context.php
Select2Context.iFillInSelect2InputWithAndSelect
public function iFillInSelect2InputWithAndSelect($field, $value, $entry) { $page = $this->getSession()->getPage(); $this->openField($page, $field); $this->fillSearchField($page, $field, $value); $this->selectValue($page, $field, $entry, $this->timeout); }
php
public function iFillInSelect2InputWithAndSelect($field, $value, $entry) { $page = $this->getSession()->getPage(); $this->openField($page, $field); $this->fillSearchField($page, $field, $value); $this->selectValue($page, $field, $entry, $this->timeout); }
[ "public", "function", "iFillInSelect2InputWithAndSelect", "(", "$", "field", ",", "$", "value", ",", "$", "entry", ")", "{", "$", "page", "=", "$", "this", "->", "getSession", "(", ")", "->", "getPage", "(", ")", ";", "$", "this", "->", "openField", "(", "$", "page", ",", "$", "field", ")", ";", "$", "this", "->", "fillSearchField", "(", "$", "page", ",", "$", "field", ",", "$", "value", ")", ";", "$", "this", "->", "selectValue", "(", "$", "page", ",", "$", "field", ",", "$", "entry", ",", "$", "this", "->", "timeout", ")", ";", "}" ]
Fill Select2 input field and select a value @When /^(?:|I )fill in select2 input "(?P<field>(?:[^"]|\\")*)" with "(?P<value>(?:[^"]|\\")*)" and select "(?P<entry>(?:[^"]|\\")*)"$/
[ "Fill", "Select2", "input", "field", "and", "select", "a", "value" ]
b5349bd6a36c0e0ca71465a5349f8d68c1d1e102
https://github.com/novaway/BehatCommonContext/blob/b5349bd6a36c0e0ca71465a5349f8d68c1d1e102/src/Context/Select2Context.php#L70-L77
28,404
novaway/BehatCommonContext
src/Context/Select2Context.php
Select2Context.waitForLoadingResults
private function waitForLoadingResults($time) { for ($i = 0; $i < $time; $i++) { if (!$this->getSession()->getPage()->find('css', '.select2-results__option.loading-results')) { return; } sleep(1); } }
php
private function waitForLoadingResults($time) { for ($i = 0; $i < $time; $i++) { if (!$this->getSession()->getPage()->find('css', '.select2-results__option.loading-results')) { return; } sleep(1); } }
[ "private", "function", "waitForLoadingResults", "(", "$", "time", ")", "{", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "time", ";", "$", "i", "++", ")", "{", "if", "(", "!", "$", "this", "->", "getSession", "(", ")", "->", "getPage", "(", ")", "->", "find", "(", "'css'", ",", "'.select2-results__option.loading-results'", ")", ")", "{", "return", ";", "}", "sleep", "(", "1", ")", ";", "}", "}" ]
Wait the end of fetching Select2 results @param int $time Time to wait in seconds
[ "Wait", "the", "end", "of", "fetching", "Select2", "results" ]
b5349bd6a36c0e0ca71465a5349f8d68c1d1e102
https://github.com/novaway/BehatCommonContext/blob/b5349bd6a36c0e0ca71465a5349f8d68c1d1e102/src/Context/Select2Context.php#L175-L184
28,405
novaway/BehatCommonContext
src/Context/FormstoneContext.php
FormstoneContext.selectValue
private function selectValue($component, $field, $value) { $page = $this->getSession()->getPage(); $this->openComponent($page, $component, $field); $this->selectComponentValue($page, $component, $field, $value); }
php
private function selectValue($component, $field, $value) { $page = $this->getSession()->getPage(); $this->openComponent($page, $component, $field); $this->selectComponentValue($page, $component, $field, $value); }
[ "private", "function", "selectValue", "(", "$", "component", ",", "$", "field", ",", "$", "value", ")", "{", "$", "page", "=", "$", "this", "->", "getSession", "(", ")", "->", "getPage", "(", ")", ";", "$", "this", "->", "openComponent", "(", "$", "page", ",", "$", "component", ",", "$", "field", ")", ";", "$", "this", "->", "selectComponentValue", "(", "$", "page", ",", "$", "component", ",", "$", "field", ",", "$", "value", ")", ";", "}" ]
Select value in component @param string $component @param string $field @param string $value @throws \Exception
[ "Select", "value", "in", "component" ]
b5349bd6a36c0e0ca71465a5349f8d68c1d1e102
https://github.com/novaway/BehatCommonContext/blob/b5349bd6a36c0e0ca71465a5349f8d68c1d1e102/src/Context/FormstoneContext.php#L43-L49
28,406
novaway/BehatCommonContext
src/Context/FormstoneContext.php
FormstoneContext.openComponent
private function openComponent(DocumentElement $page, $component, $field) { $select = $page->find('css', sprintf('#%s', $field)); if (!$select) { throw new \Exception(sprintf('No select "%s" found', $field)); } $fieldName = sprintf('.fs-%1$s .fs-%1$s-selected', $component); $choices = $select->getParent()->find('css', $fieldName); if (!$choices) { throw new \Exception(sprintf('No field "%s" found', $field)); } $choices->press(); }
php
private function openComponent(DocumentElement $page, $component, $field) { $select = $page->find('css', sprintf('#%s', $field)); if (!$select) { throw new \Exception(sprintf('No select "%s" found', $field)); } $fieldName = sprintf('.fs-%1$s .fs-%1$s-selected', $component); $choices = $select->getParent()->find('css', $fieldName); if (!$choices) { throw new \Exception(sprintf('No field "%s" found', $field)); } $choices->press(); }
[ "private", "function", "openComponent", "(", "DocumentElement", "$", "page", ",", "$", "component", ",", "$", "field", ")", "{", "$", "select", "=", "$", "page", "->", "find", "(", "'css'", ",", "sprintf", "(", "'#%s'", ",", "$", "field", ")", ")", ";", "if", "(", "!", "$", "select", ")", "{", "throw", "new", "\\", "Exception", "(", "sprintf", "(", "'No select \"%s\" found'", ",", "$", "field", ")", ")", ";", "}", "$", "fieldName", "=", "sprintf", "(", "'.fs-%1$s .fs-%1$s-selected'", ",", "$", "component", ")", ";", "$", "choices", "=", "$", "select", "->", "getParent", "(", ")", "->", "find", "(", "'css'", ",", "$", "fieldName", ")", ";", "if", "(", "!", "$", "choices", ")", "{", "throw", "new", "\\", "Exception", "(", "sprintf", "(", "'No field \"%s\" found'", ",", "$", "field", ")", ")", ";", "}", "$", "choices", "->", "press", "(", ")", ";", "}" ]
Open component choice list @param DocumentElement $page @param string $component @param string $field @throws \Exception
[ "Open", "component", "choice", "list" ]
b5349bd6a36c0e0ca71465a5349f8d68c1d1e102
https://github.com/novaway/BehatCommonContext/blob/b5349bd6a36c0e0ca71465a5349f8d68c1d1e102/src/Context/FormstoneContext.php#L59-L73
28,407
graphaware/neo4j-php-ogm
src/Metadata/NodeEntityMetadata.php
NodeEntityMetadata.getNonLazyRelationships
public function getNonLazyRelationships() { $rels = []; foreach ($this->relationships as $relationship) { if (!$relationship->isLazy()) { $rels[] = $relationship; } } return $rels; }
php
public function getNonLazyRelationships() { $rels = []; foreach ($this->relationships as $relationship) { if (!$relationship->isLazy()) { $rels[] = $relationship; } } return $rels; }
[ "public", "function", "getNonLazyRelationships", "(", ")", "{", "$", "rels", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "relationships", "as", "$", "relationship", ")", "{", "if", "(", "!", "$", "relationship", "->", "isLazy", "(", ")", ")", "{", "$", "rels", "[", "]", "=", "$", "relationship", ";", "}", "}", "return", "$", "rels", ";", "}" ]
Returns non-lazy relationships. Note that currently relationships that are not of type "collection" are considered non-lazy. @return RelationshipMetadata[]
[ "Returns", "non", "-", "lazy", "relationships", ".", "Note", "that", "currently", "relationships", "that", "are", "not", "of", "type", "collection", "are", "considered", "non", "-", "lazy", "." ]
390c0413582933ffae9597edfa57d6df6c570b03
https://github.com/graphaware/neo4j-php-ogm/blob/390c0413582933ffae9597edfa57d6df6c570b03/src/Metadata/NodeEntityMetadata.php#L142-L152
28,408
graphaware/neo4j-php-ogm
src/Persister/EntityPersister.php
EntityPersister.refresh
public function refresh($id, $entity) { $label = $this->classMetadata->getLabel(); $query = sprintf('MATCH (n:%s) WHERE id(n) = {%s} RETURN n', $label, 'id'); $result = $this->entityManager->getDatabaseDriver()->run($query, ['id' => $id]); if ($result->size() > 0) { $node = $result->firstRecord()->nodeValue('n'); $this->entityManager->getEntityHydrator($this->className)->refresh($node, $entity); } }
php
public function refresh($id, $entity) { $label = $this->classMetadata->getLabel(); $query = sprintf('MATCH (n:%s) WHERE id(n) = {%s} RETURN n', $label, 'id'); $result = $this->entityManager->getDatabaseDriver()->run($query, ['id' => $id]); if ($result->size() > 0) { $node = $result->firstRecord()->nodeValue('n'); $this->entityManager->getEntityHydrator($this->className)->refresh($node, $entity); } }
[ "public", "function", "refresh", "(", "$", "id", ",", "$", "entity", ")", "{", "$", "label", "=", "$", "this", "->", "classMetadata", "->", "getLabel", "(", ")", ";", "$", "query", "=", "sprintf", "(", "'MATCH (n:%s) WHERE id(n) = {%s} RETURN n'", ",", "$", "label", ",", "'id'", ")", ";", "$", "result", "=", "$", "this", "->", "entityManager", "->", "getDatabaseDriver", "(", ")", "->", "run", "(", "$", "query", ",", "[", "'id'", "=>", "$", "id", "]", ")", ";", "if", "(", "$", "result", "->", "size", "(", ")", ">", "0", ")", "{", "$", "node", "=", "$", "result", "->", "firstRecord", "(", ")", "->", "nodeValue", "(", "'n'", ")", ";", "$", "this", "->", "entityManager", "->", "getEntityHydrator", "(", "$", "this", "->", "className", ")", "->", "refresh", "(", "$", "node", ",", "$", "entity", ")", ";", "}", "}" ]
Refreshes a managed entity. @param int $id @param object $entity The entity to refresh
[ "Refreshes", "a", "managed", "entity", "." ]
390c0413582933ffae9597edfa57d6df6c570b03
https://github.com/graphaware/neo4j-php-ogm/blob/390c0413582933ffae9597edfa57d6df6c570b03/src/Persister/EntityPersister.php#L142-L152
28,409
graphaware/neo4j-php-ogm
src/UnitOfWork.php
UnitOfWork.getOriginalEntityState
public function getOriginalEntityState($id) { if (isset($this->entityStateReferences[$id])) { return $this->entityStateReferences[$id]; } return null; }
php
public function getOriginalEntityState($id) { if (isset($this->entityStateReferences[$id])) { return $this->entityStateReferences[$id]; } return null; }
[ "public", "function", "getOriginalEntityState", "(", "$", "id", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "entityStateReferences", "[", "$", "id", "]", ")", ")", "{", "return", "$", "this", "->", "entityStateReferences", "[", "$", "id", "]", ";", "}", "return", "null", ";", "}" ]
Get the original state of an entity when it was loaded from the database. @param int $id @return object|null
[ "Get", "the", "original", "state", "of", "an", "entity", "when", "it", "was", "loaded", "from", "the", "database", "." ]
390c0413582933ffae9597edfa57d6df6c570b03
https://github.com/graphaware/neo4j-php-ogm/blob/390c0413582933ffae9597edfa57d6df6c570b03/src/UnitOfWork.php#L791-L798
28,410
BabDev/Transifex-API
src/Connector/Projects.php
Projects.buildProjectRequest
private function buildProjectRequest(array $options): array { $data = []; // Valid options to check $validOptions = [ 'long_description', 'private', 'homepage', 'trans_instructions', 'tags', 'maintainers', 'team', 'auto_join', 'license', 'fill_up_resources', 'repository_url', 'organization', 'archived', 'type', ]; // Loop through the valid options and if we have them, add them to the request data foreach ($validOptions as $option) { if (isset($options[$option])) { $data[$option] = $options[$option]; } } // Set the license if present if (isset($options['license'])) { $this->checkLicense($options['license']); $data['license'] = $options['license']; } return $data; }
php
private function buildProjectRequest(array $options): array { $data = []; // Valid options to check $validOptions = [ 'long_description', 'private', 'homepage', 'trans_instructions', 'tags', 'maintainers', 'team', 'auto_join', 'license', 'fill_up_resources', 'repository_url', 'organization', 'archived', 'type', ]; // Loop through the valid options and if we have them, add them to the request data foreach ($validOptions as $option) { if (isset($options[$option])) { $data[$option] = $options[$option]; } } // Set the license if present if (isset($options['license'])) { $this->checkLicense($options['license']); $data['license'] = $options['license']; } return $data; }
[ "private", "function", "buildProjectRequest", "(", "array", "$", "options", ")", ":", "array", "{", "$", "data", "=", "[", "]", ";", "// Valid options to check", "$", "validOptions", "=", "[", "'long_description'", ",", "'private'", ",", "'homepage'", ",", "'trans_instructions'", ",", "'tags'", ",", "'maintainers'", ",", "'team'", ",", "'auto_join'", ",", "'license'", ",", "'fill_up_resources'", ",", "'repository_url'", ",", "'organization'", ",", "'archived'", ",", "'type'", ",", "]", ";", "// Loop through the valid options and if we have them, add them to the request data", "foreach", "(", "$", "validOptions", "as", "$", "option", ")", "{", "if", "(", "isset", "(", "$", "options", "[", "$", "option", "]", ")", ")", "{", "$", "data", "[", "$", "option", "]", "=", "$", "options", "[", "$", "option", "]", ";", "}", "}", "// Set the license if present", "if", "(", "isset", "(", "$", "options", "[", "'license'", "]", ")", ")", "{", "$", "this", "->", "checkLicense", "(", "$", "options", "[", "'license'", "]", ")", ";", "$", "data", "[", "'license'", "]", "=", "$", "options", "[", "'license'", "]", ";", "}", "return", "$", "data", ";", "}" ]
Build the data array to send with create and update requests. @param array $options Optional additional params to send with the request @return array
[ "Build", "the", "data", "array", "to", "send", "with", "create", "and", "update", "requests", "." ]
9e0ccd7980127db88f7c55a36afbd2a49d9e8436
https://github.com/BabDev/Transifex-API/blob/9e0ccd7980127db88f7c55a36afbd2a49d9e8436/src/Connector/Projects.php#L22-L58
28,411
BabDev/Transifex-API
src/Connector/Projects.php
Projects.checkLicense
private function checkLicense(string $license): void { $accepted = ['proprietary', 'permissive_open_source', 'other_open_source']; // Ensure the license option is an allowed value if (!\in_array($license, $accepted)) { throw new \InvalidArgumentException( \sprintf( 'The license %s is not valid, accepted license values are %s', $license, \implode(', ', $accepted) ) ); } }
php
private function checkLicense(string $license): void { $accepted = ['proprietary', 'permissive_open_source', 'other_open_source']; // Ensure the license option is an allowed value if (!\in_array($license, $accepted)) { throw new \InvalidArgumentException( \sprintf( 'The license %s is not valid, accepted license values are %s', $license, \implode(', ', $accepted) ) ); } }
[ "private", "function", "checkLicense", "(", "string", "$", "license", ")", ":", "void", "{", "$", "accepted", "=", "[", "'proprietary'", ",", "'permissive_open_source'", ",", "'other_open_source'", "]", ";", "// Ensure the license option is an allowed value", "if", "(", "!", "\\", "in_array", "(", "$", "license", ",", "$", "accepted", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "\\", "sprintf", "(", "'The license %s is not valid, accepted license values are %s'", ",", "$", "license", ",", "\\", "implode", "(", "', '", ",", "$", "accepted", ")", ")", ")", ";", "}", "}" ]
Checks that a license is an accepted value. @param string $license The license to check @throws \InvalidArgumentException
[ "Checks", "that", "a", "license", "is", "an", "accepted", "value", "." ]
9e0ccd7980127db88f7c55a36afbd2a49d9e8436
https://github.com/BabDev/Transifex-API/blob/9e0ccd7980127db88f7c55a36afbd2a49d9e8436/src/Connector/Projects.php#L67-L81
28,412
BabDev/Transifex-API
src/Connector/Projects.php
Projects.getOrganizationProjects
public function getOrganizationProjects(string $organization): ResponseInterface { // This API endpoint uses the newer `api.transifex.com` subdomain, only change if the default www was given $currentBaseUri = $this->getOption('base_uri'); if (!$currentBaseUri || $currentBaseUri === 'https://www.transifex.com') { $this->setOption('base_uri', 'https://api.transifex.com'); } try { return $this->client->sendRequest($this->createRequest('GET', $this->createUri("/organizations/$organization/projects/"))); } finally { $this->setOption('base_uri', $currentBaseUri); } }
php
public function getOrganizationProjects(string $organization): ResponseInterface { // This API endpoint uses the newer `api.transifex.com` subdomain, only change if the default www was given $currentBaseUri = $this->getOption('base_uri'); if (!$currentBaseUri || $currentBaseUri === 'https://www.transifex.com') { $this->setOption('base_uri', 'https://api.transifex.com'); } try { return $this->client->sendRequest($this->createRequest('GET', $this->createUri("/organizations/$organization/projects/"))); } finally { $this->setOption('base_uri', $currentBaseUri); } }
[ "public", "function", "getOrganizationProjects", "(", "string", "$", "organization", ")", ":", "ResponseInterface", "{", "// This API endpoint uses the newer `api.transifex.com` subdomain, only change if the default www was given", "$", "currentBaseUri", "=", "$", "this", "->", "getOption", "(", "'base_uri'", ")", ";", "if", "(", "!", "$", "currentBaseUri", "||", "$", "currentBaseUri", "===", "'https://www.transifex.com'", ")", "{", "$", "this", "->", "setOption", "(", "'base_uri'", ",", "'https://api.transifex.com'", ")", ";", "}", "try", "{", "return", "$", "this", "->", "client", "->", "sendRequest", "(", "$", "this", "->", "createRequest", "(", "'GET'", ",", "$", "this", "->", "createUri", "(", "\"/organizations/$organization/projects/\"", ")", ")", ")", ";", "}", "finally", "{", "$", "this", "->", "setOption", "(", "'base_uri'", ",", "$", "currentBaseUri", ")", ";", "}", "}" ]
Get a list of projects belonging to an organization. @return ResponseInterface
[ "Get", "a", "list", "of", "projects", "belonging", "to", "an", "organization", "." ]
9e0ccd7980127db88f7c55a36afbd2a49d9e8436
https://github.com/BabDev/Transifex-API/blob/9e0ccd7980127db88f7c55a36afbd2a49d9e8436/src/Connector/Projects.php#L147-L161
28,413
QoboLtd/cakephp-search
src/Widgets/Reports/BaseReportGraphs.php
BaseReportGraphs.setContainerId
public function setContainerId(array $data = []) : void { $config = empty($data) ? $this->getConfig() : $data; $this->containerId = self::GRAPH_PREFIX . $config['slug']; }
php
public function setContainerId(array $data = []) : void { $config = empty($data) ? $this->getConfig() : $data; $this->containerId = self::GRAPH_PREFIX . $config['slug']; }
[ "public", "function", "setContainerId", "(", "array", "$", "data", "=", "[", "]", ")", ":", "void", "{", "$", "config", "=", "empty", "(", "$", "data", ")", "?", "$", "this", "->", "getConfig", "(", ")", ":", "$", "data", ";", "$", "this", "->", "containerId", "=", "self", "::", "GRAPH_PREFIX", ".", "$", "config", "[", "'slug'", "]", ";", "}" ]
setContainerId method. Sets the placeholder unique identifier for the widget. @param mixed[] $data of the config. @return void
[ "setContainerId", "method", ".", "Sets", "the", "placeholder", "unique", "identifier", "for", "the", "widget", "." ]
095a0e822781ac11eade0c03c7729b693daa1ba8
https://github.com/QoboLtd/cakephp-search/blob/095a0e822781ac11eade0c03c7729b693daa1ba8/src/Widgets/Reports/BaseReportGraphs.php#L71-L76
28,414
QoboLtd/cakephp-search
src/Widgets/Reports/BaseReportGraphs.php
BaseReportGraphs.validate
public function validate(array $data = []) : array { $validated = false; $errors = []; if (empty($this->requiredFields)) { $errors[] = "Missing requiredFields in the report object"; } foreach ($this->requiredFields as $field) { if (!isset($data['info'][$field])) { $errors[] = "Required field [$field] must be set"; } if (empty($data['info'][$field])) { $errors[] = "Required Field [$field] cannot be empty"; } } if (empty($errors)) { $validated = true; $this->errors = []; } else { $this->errors = $errors; } return ['status' => $validated, 'messages' => $errors]; }
php
public function validate(array $data = []) : array { $validated = false; $errors = []; if (empty($this->requiredFields)) { $errors[] = "Missing requiredFields in the report object"; } foreach ($this->requiredFields as $field) { if (!isset($data['info'][$field])) { $errors[] = "Required field [$field] must be set"; } if (empty($data['info'][$field])) { $errors[] = "Required Field [$field] cannot be empty"; } } if (empty($errors)) { $validated = true; $this->errors = []; } else { $this->errors = $errors; } return ['status' => $validated, 'messages' => $errors]; }
[ "public", "function", "validate", "(", "array", "$", "data", "=", "[", "]", ")", ":", "array", "{", "$", "validated", "=", "false", ";", "$", "errors", "=", "[", "]", ";", "if", "(", "empty", "(", "$", "this", "->", "requiredFields", ")", ")", "{", "$", "errors", "[", "]", "=", "\"Missing requiredFields in the report object\"", ";", "}", "foreach", "(", "$", "this", "->", "requiredFields", "as", "$", "field", ")", "{", "if", "(", "!", "isset", "(", "$", "data", "[", "'info'", "]", "[", "$", "field", "]", ")", ")", "{", "$", "errors", "[", "]", "=", "\"Required field [$field] must be set\"", ";", "}", "if", "(", "empty", "(", "$", "data", "[", "'info'", "]", "[", "$", "field", "]", ")", ")", "{", "$", "errors", "[", "]", "=", "\"Required Field [$field] cannot be empty\"", ";", "}", "}", "if", "(", "empty", "(", "$", "errors", ")", ")", "{", "$", "validated", "=", "true", ";", "$", "this", "->", "errors", "=", "[", "]", ";", "}", "else", "{", "$", "this", "->", "errors", "=", "$", "errors", ";", "}", "return", "[", "'status'", "=>", "$", "validated", ",", "'messages'", "=>", "$", "errors", "]", ";", "}" ]
validate method. Checks all the required fields of the report if any. @param array $data with report configuration @return mixed[] result of validation
[ "validate", "method", "." ]
095a0e822781ac11eade0c03c7729b693daa1ba8
https://github.com/QoboLtd/cakephp-search/blob/095a0e822781ac11eade0c03c7729b693daa1ba8/src/Widgets/Reports/BaseReportGraphs.php#L147-L174
28,415
QoboLtd/cakephp-search
src/Widgets/Reports/BaseReportGraphs.php
BaseReportGraphs.getChartColors
public function getChartColors(int $count, string $myString, bool $shade = true) : array { $grad = []; // Generate first color if ($shade && $count > 0) { $color = substr(dechex(crc32($myString)), 0, 6); list($r, $g, $b) = array_map(function ($n) { return hexdec($n); }, str_split($color, 2)); // Generate second color $color2 = substr(dechex(crc32($myString . ' ')), 0, 6); list($r2, $g2, $b2) = array_map(function ($n) { return hexdec($n); }, str_split($color2, 2)); $rl = ( $r2 - $r) / $count - 1; $gl = ( $g2 - $g) / $count - 1; $bl = ( $b2 - $b) / $count - 1; // Create a shade from the first color to the second for ($i = 0; $i < $count; $i++) { $grad[] = '#' . str_pad(dechex($r + $rl * $i), 2, "0", 0) . str_pad(dechex($g + $gl * $i), 2, "0", 0) . str_pad(dechex($b + $bl * $i), 2, "0", 0); } return $grad; } $my_palette = Configure::read("Widget.colors"); for ($i = 0; $i < $count; $i++) { $grad[] = $my_palette[(crc32($myString) + $i) % count($my_palette)]; } return $grad; }
php
public function getChartColors(int $count, string $myString, bool $shade = true) : array { $grad = []; // Generate first color if ($shade && $count > 0) { $color = substr(dechex(crc32($myString)), 0, 6); list($r, $g, $b) = array_map(function ($n) { return hexdec($n); }, str_split($color, 2)); // Generate second color $color2 = substr(dechex(crc32($myString . ' ')), 0, 6); list($r2, $g2, $b2) = array_map(function ($n) { return hexdec($n); }, str_split($color2, 2)); $rl = ( $r2 - $r) / $count - 1; $gl = ( $g2 - $g) / $count - 1; $bl = ( $b2 - $b) / $count - 1; // Create a shade from the first color to the second for ($i = 0; $i < $count; $i++) { $grad[] = '#' . str_pad(dechex($r + $rl * $i), 2, "0", 0) . str_pad(dechex($g + $gl * $i), 2, "0", 0) . str_pad(dechex($b + $bl * $i), 2, "0", 0); } return $grad; } $my_palette = Configure::read("Widget.colors"); for ($i = 0; $i < $count; $i++) { $grad[] = $my_palette[(crc32($myString) + $i) % count($my_palette)]; } return $grad; }
[ "public", "function", "getChartColors", "(", "int", "$", "count", ",", "string", "$", "myString", ",", "bool", "$", "shade", "=", "true", ")", ":", "array", "{", "$", "grad", "=", "[", "]", ";", "// Generate first color", "if", "(", "$", "shade", "&&", "$", "count", ">", "0", ")", "{", "$", "color", "=", "substr", "(", "dechex", "(", "crc32", "(", "$", "myString", ")", ")", ",", "0", ",", "6", ")", ";", "list", "(", "$", "r", ",", "$", "g", ",", "$", "b", ")", "=", "array_map", "(", "function", "(", "$", "n", ")", "{", "return", "hexdec", "(", "$", "n", ")", ";", "}", ",", "str_split", "(", "$", "color", ",", "2", ")", ")", ";", "// Generate second color", "$", "color2", "=", "substr", "(", "dechex", "(", "crc32", "(", "$", "myString", ".", "' '", ")", ")", ",", "0", ",", "6", ")", ";", "list", "(", "$", "r2", ",", "$", "g2", ",", "$", "b2", ")", "=", "array_map", "(", "function", "(", "$", "n", ")", "{", "return", "hexdec", "(", "$", "n", ")", ";", "}", ",", "str_split", "(", "$", "color2", ",", "2", ")", ")", ";", "$", "rl", "=", "(", "$", "r2", "-", "$", "r", ")", "/", "$", "count", "-", "1", ";", "$", "gl", "=", "(", "$", "g2", "-", "$", "g", ")", "/", "$", "count", "-", "1", ";", "$", "bl", "=", "(", "$", "b2", "-", "$", "b", ")", "/", "$", "count", "-", "1", ";", "// Create a shade from the first color to the second", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "count", ";", "$", "i", "++", ")", "{", "$", "grad", "[", "]", "=", "'#'", ".", "str_pad", "(", "dechex", "(", "$", "r", "+", "$", "rl", "*", "$", "i", ")", ",", "2", ",", "\"0\"", ",", "0", ")", ".", "str_pad", "(", "dechex", "(", "$", "g", "+", "$", "gl", "*", "$", "i", ")", ",", "2", ",", "\"0\"", ",", "0", ")", ".", "str_pad", "(", "dechex", "(", "$", "b", "+", "$", "bl", "*", "$", "i", ")", ",", "2", ",", "\"0\"", ",", "0", ")", ";", "}", "return", "$", "grad", ";", "}", "$", "my_palette", "=", "Configure", "::", "read", "(", "\"Widget.colors\"", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "count", ";", "$", "i", "++", ")", "{", "$", "grad", "[", "]", "=", "$", "my_palette", "[", "(", "crc32", "(", "$", "myString", ")", "+", "$", "i", ")", "%", "count", "(", "$", "my_palette", ")", "]", ";", "}", "return", "$", "grad", ";", "}" ]
Generate an array whit the colors for the chars. @param int $count How many element in the array. @param string $myString The color have to be calculated on a fix string to be constant in every refresh. @param bool $shade Shade the default color with another generated one. If false, the colors will be from a pre-set palette. @return string[]
[ "Generate", "an", "array", "whit", "the", "colors", "for", "the", "chars", "." ]
095a0e822781ac11eade0c03c7729b693daa1ba8
https://github.com/QoboLtd/cakephp-search/blob/095a0e822781ac11eade0c03c7729b693daa1ba8/src/Widgets/Reports/BaseReportGraphs.php#L199-L235
28,416
aimeos/ai-client-jsonapi
client/jsonapi/src/Client/JsonApi/Subscription/Standard.php
Standard.delete
public function delete( ServerRequestInterface $request, ResponseInterface $response ) { $view = $this->getView(); try { $cntl = \Aimeos\Controller\Frontend::create( $this->getContext(), 'subscription' ); $view->items = $cntl->cancel( $view->param( 'id' ) ); $view->total = 1; $status = 200; } catch( \Aimeos\Controller\Frontend\Exception $e ) { $status = 403; $view->errors = $this->getErrorDetails( $e, 'controller/frontend' ); } catch( \Aimeos\MShop\Exception $e ) { $status = 404; $view->errors = $this->getErrorDetails( $e, 'mshop' ); } catch( \Exception $e ) { $status = 500; $view->errors = $this->getErrorDetails( $e ); } return $this->render( $response, $view, $status ); }
php
public function delete( ServerRequestInterface $request, ResponseInterface $response ) { $view = $this->getView(); try { $cntl = \Aimeos\Controller\Frontend::create( $this->getContext(), 'subscription' ); $view->items = $cntl->cancel( $view->param( 'id' ) ); $view->total = 1; $status = 200; } catch( \Aimeos\Controller\Frontend\Exception $e ) { $status = 403; $view->errors = $this->getErrorDetails( $e, 'controller/frontend' ); } catch( \Aimeos\MShop\Exception $e ) { $status = 404; $view->errors = $this->getErrorDetails( $e, 'mshop' ); } catch( \Exception $e ) { $status = 500; $view->errors = $this->getErrorDetails( $e ); } return $this->render( $response, $view, $status ); }
[ "public", "function", "delete", "(", "ServerRequestInterface", "$", "request", ",", "ResponseInterface", "$", "response", ")", "{", "$", "view", "=", "$", "this", "->", "getView", "(", ")", ";", "try", "{", "$", "cntl", "=", "\\", "Aimeos", "\\", "Controller", "\\", "Frontend", "::", "create", "(", "$", "this", "->", "getContext", "(", ")", ",", "'subscription'", ")", ";", "$", "view", "->", "items", "=", "$", "cntl", "->", "cancel", "(", "$", "view", "->", "param", "(", "'id'", ")", ")", ";", "$", "view", "->", "total", "=", "1", ";", "$", "status", "=", "200", ";", "}", "catch", "(", "\\", "Aimeos", "\\", "Controller", "\\", "Frontend", "\\", "Exception", "$", "e", ")", "{", "$", "status", "=", "403", ";", "$", "view", "->", "errors", "=", "$", "this", "->", "getErrorDetails", "(", "$", "e", ",", "'controller/frontend'", ")", ";", "}", "catch", "(", "\\", "Aimeos", "\\", "MShop", "\\", "Exception", "$", "e", ")", "{", "$", "status", "=", "404", ";", "$", "view", "->", "errors", "=", "$", "this", "->", "getErrorDetails", "(", "$", "e", ",", "'mshop'", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "$", "status", "=", "500", ";", "$", "view", "->", "errors", "=", "$", "this", "->", "getErrorDetails", "(", "$", "e", ")", ";", "}", "return", "$", "this", "->", "render", "(", "$", "response", ",", "$", "view", ",", "$", "status", ")", ";", "}" ]
Cancels the subscription @param \Psr\Http\Message\ServerRequestInterface $request Request object @param \Psr\Http\Message\ResponseInterface $response Response object @return \Psr\Http\Message\ResponseInterface Modified response object
[ "Cancels", "the", "subscription" ]
b0dfb018ae0a1f7196b18322e28a1b3224aa9045
https://github.com/aimeos/ai-client-jsonapi/blob/b0dfb018ae0a1f7196b18322e28a1b3224aa9045/client/jsonapi/src/Client/JsonApi/Subscription/Standard.php#L34-L64
28,417
mmoreram/ControllerExtraBundle
ControllerExtraBundle.php
ControllerExtraBundle.registerAnnotations
private function registerAnnotations(array $annotations) { $kernel = $this ->container ->get('kernel'); foreach ($annotations as $annotation) { AnnotationRegistry::registerFile($kernel ->locateResource($annotation) ); } }
php
private function registerAnnotations(array $annotations) { $kernel = $this ->container ->get('kernel'); foreach ($annotations as $annotation) { AnnotationRegistry::registerFile($kernel ->locateResource($annotation) ); } }
[ "private", "function", "registerAnnotations", "(", "array", "$", "annotations", ")", "{", "$", "kernel", "=", "$", "this", "->", "container", "->", "get", "(", "'kernel'", ")", ";", "foreach", "(", "$", "annotations", "as", "$", "annotation", ")", "{", "AnnotationRegistry", "::", "registerFile", "(", "$", "kernel", "->", "locateResource", "(", "$", "annotation", ")", ")", ";", "}", "}" ]
Register annotations. @param string[] Annotations
[ "Register", "annotations", "." ]
b5841b6ca8f0022a2d88fdfbf743f0b76c4644e3
https://github.com/mmoreram/ControllerExtraBundle/blob/b5841b6ca8f0022a2d88fdfbf743f0b76c4644e3/ControllerExtraBundle.php#L81-L92
28,418
BabDev/Transifex-API
src/ApiConnector.php
ApiConnector.createAuthorizationHeader
protected function createAuthorizationHeader(): string { $username = $this->getOption('api.username'); $password = $this->getOption('api.password'); // The API requires HTTP Basic Authentication, we can't proceed without credentials if ($username === null || $password === null) { throw new \InvalidArgumentException('Missing credentials for API authentication.'); } return 'Basic ' . \base64_encode("$username:$password"); }
php
protected function createAuthorizationHeader(): string { $username = $this->getOption('api.username'); $password = $this->getOption('api.password'); // The API requires HTTP Basic Authentication, we can't proceed without credentials if ($username === null || $password === null) { throw new \InvalidArgumentException('Missing credentials for API authentication.'); } return 'Basic ' . \base64_encode("$username:$password"); }
[ "protected", "function", "createAuthorizationHeader", "(", ")", ":", "string", "{", "$", "username", "=", "$", "this", "->", "getOption", "(", "'api.username'", ")", ";", "$", "password", "=", "$", "this", "->", "getOption", "(", "'api.password'", ")", ";", "// The API requires HTTP Basic Authentication, we can't proceed without credentials", "if", "(", "$", "username", "===", "null", "||", "$", "password", "===", "null", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Missing credentials for API authentication.'", ")", ";", "}", "return", "'Basic '", ".", "\\", "base64_encode", "(", "\"$username:$password\"", ")", ";", "}" ]
Creates the Authorization header for the request @return string @throws \InvalidArgumentException if credentials are not set
[ "Creates", "the", "Authorization", "header", "for", "the", "request" ]
9e0ccd7980127db88f7c55a36afbd2a49d9e8436
https://github.com/BabDev/Transifex-API/blob/9e0ccd7980127db88f7c55a36afbd2a49d9e8436/src/ApiConnector.php#L81-L92
28,419
BabDev/Transifex-API
src/ApiConnector.php
ApiConnector.createRequest
protected function createRequest(string $method, UriInterface $uri): RequestInterface { $request = $this->requestFactory->createRequest($method, $uri); return $request->withHeader('Authorization', $this->createAuthorizationHeader()); }
php
protected function createRequest(string $method, UriInterface $uri): RequestInterface { $request = $this->requestFactory->createRequest($method, $uri); return $request->withHeader('Authorization', $this->createAuthorizationHeader()); }
[ "protected", "function", "createRequest", "(", "string", "$", "method", ",", "UriInterface", "$", "uri", ")", ":", "RequestInterface", "{", "$", "request", "=", "$", "this", "->", "requestFactory", "->", "createRequest", "(", "$", "method", ",", "$", "uri", ")", ";", "return", "$", "request", "->", "withHeader", "(", "'Authorization'", ",", "$", "this", "->", "createAuthorizationHeader", "(", ")", ")", ";", "}" ]
Create a Request object for the given URI This method will also set the Authorization header for the request @param string $method @param UriInterface $uri @return RequestInterface
[ "Create", "a", "Request", "object", "for", "the", "given", "URI" ]
9e0ccd7980127db88f7c55a36afbd2a49d9e8436
https://github.com/BabDev/Transifex-API/blob/9e0ccd7980127db88f7c55a36afbd2a49d9e8436/src/ApiConnector.php#L104-L109
28,420
BabDev/Transifex-API
src/ApiConnector.php
ApiConnector.createUri
protected function createUri(string $path): UriInterface { $baseUrl = $this->getOption('base_uri', 'https://www.transifex.com'); return $this->uriFactory->createUri($baseUrl . $path); }
php
protected function createUri(string $path): UriInterface { $baseUrl = $this->getOption('base_uri', 'https://www.transifex.com'); return $this->uriFactory->createUri($baseUrl . $path); }
[ "protected", "function", "createUri", "(", "string", "$", "path", ")", ":", "UriInterface", "{", "$", "baseUrl", "=", "$", "this", "->", "getOption", "(", "'base_uri'", ",", "'https://www.transifex.com'", ")", ";", "return", "$", "this", "->", "uriFactory", "->", "createUri", "(", "$", "baseUrl", ".", "$", "path", ")", ";", "}" ]
Create a Uri object for the path @param string $path @return UriInterface
[ "Create", "a", "Uri", "object", "for", "the", "path" ]
9e0ccd7980127db88f7c55a36afbd2a49d9e8436
https://github.com/BabDev/Transifex-API/blob/9e0ccd7980127db88f7c55a36afbd2a49d9e8436/src/ApiConnector.php#L118-L123
28,421
BabDev/Transifex-API
src/ApiConnector.php
ApiConnector.updateResource
protected function updateResource(UriInterface $uri, string $content, string $type): ResponseInterface { // Verify the content type is allowed if (!\in_array($type, ['string', 'file'])) { throw new \InvalidArgumentException('The content type must be specified as file or string.'); } $request = $this->createRequest('PUT', $uri); $request = $request->withHeader('Content-Type', 'application/json'); if ($type == 'file') { if (!\file_exists($content)) { throw new \InvalidArgumentException( \sprintf('The specified file, "%s", does not exist.', $content) ); } $request = $request->withBody($this->streamFactory->createStreamFromFile($content)); } else { $data = [ 'content' => $content, ]; $request = $request->withBody($this->streamFactory->createStream(\json_encode($data))); } return $this->client->sendRequest($request); }
php
protected function updateResource(UriInterface $uri, string $content, string $type): ResponseInterface { // Verify the content type is allowed if (!\in_array($type, ['string', 'file'])) { throw new \InvalidArgumentException('The content type must be specified as file or string.'); } $request = $this->createRequest('PUT', $uri); $request = $request->withHeader('Content-Type', 'application/json'); if ($type == 'file') { if (!\file_exists($content)) { throw new \InvalidArgumentException( \sprintf('The specified file, "%s", does not exist.', $content) ); } $request = $request->withBody($this->streamFactory->createStreamFromFile($content)); } else { $data = [ 'content' => $content, ]; $request = $request->withBody($this->streamFactory->createStream(\json_encode($data))); } return $this->client->sendRequest($request); }
[ "protected", "function", "updateResource", "(", "UriInterface", "$", "uri", ",", "string", "$", "content", ",", "string", "$", "type", ")", ":", "ResponseInterface", "{", "// Verify the content type is allowed", "if", "(", "!", "\\", "in_array", "(", "$", "type", ",", "[", "'string'", ",", "'file'", "]", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'The content type must be specified as file or string.'", ")", ";", "}", "$", "request", "=", "$", "this", "->", "createRequest", "(", "'PUT'", ",", "$", "uri", ")", ";", "$", "request", "=", "$", "request", "->", "withHeader", "(", "'Content-Type'", ",", "'application/json'", ")", ";", "if", "(", "$", "type", "==", "'file'", ")", "{", "if", "(", "!", "\\", "file_exists", "(", "$", "content", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "\\", "sprintf", "(", "'The specified file, \"%s\", does not exist.'", ",", "$", "content", ")", ")", ";", "}", "$", "request", "=", "$", "request", "->", "withBody", "(", "$", "this", "->", "streamFactory", "->", "createStreamFromFile", "(", "$", "content", ")", ")", ";", "}", "else", "{", "$", "data", "=", "[", "'content'", "=>", "$", "content", ",", "]", ";", "$", "request", "=", "$", "request", "->", "withBody", "(", "$", "this", "->", "streamFactory", "->", "createStream", "(", "\\", "json_encode", "(", "$", "data", ")", ")", ")", ";", "}", "return", "$", "this", "->", "client", "->", "sendRequest", "(", "$", "request", ")", ";", "}" ]
Update an API endpoint with resource content. @param UriInterface $uri URI object representing the API path to request @param string $content The content of the resource, this can either be a string of data or a file path @param string $type The type of content in the $content variable, this should be either string or file @return ResponseInterface @throws \InvalidArgumentException
[ "Update", "an", "API", "endpoint", "with", "resource", "content", "." ]
9e0ccd7980127db88f7c55a36afbd2a49d9e8436
https://github.com/BabDev/Transifex-API/blob/9e0ccd7980127db88f7c55a36afbd2a49d9e8436/src/ApiConnector.php#L164-L191
28,422
mitchdav/st-george-ipg
src/Client.php
Client.purchase
public function purchase($amount, $cardNumber, $month, $year, $cvc = NULL, $clientReference = NULL, $comment = NULL, $description = NULL, $cardHolderName = NULL, $taxAmount = NULL) { $request = Request::createFromClient($this); $request->setTransactionType(Request::TRANSACTION_TYPE_PURCHASE) ->setTotalAmount($amount) ->setCardData($cardNumber) ->setCardExpiryDate($month, $year) ->setCVC2($cvc) ->setClientReference($clientReference) ->setComment($comment) ->setMerchantDescription($description) ->setMerchantCardHolderName($cardHolderName) ->setTaxAmount($taxAmount); return $request; }
php
public function purchase($amount, $cardNumber, $month, $year, $cvc = NULL, $clientReference = NULL, $comment = NULL, $description = NULL, $cardHolderName = NULL, $taxAmount = NULL) { $request = Request::createFromClient($this); $request->setTransactionType(Request::TRANSACTION_TYPE_PURCHASE) ->setTotalAmount($amount) ->setCardData($cardNumber) ->setCardExpiryDate($month, $year) ->setCVC2($cvc) ->setClientReference($clientReference) ->setComment($comment) ->setMerchantDescription($description) ->setMerchantCardHolderName($cardHolderName) ->setTaxAmount($taxAmount); return $request; }
[ "public", "function", "purchase", "(", "$", "amount", ",", "$", "cardNumber", ",", "$", "month", ",", "$", "year", ",", "$", "cvc", "=", "NULL", ",", "$", "clientReference", "=", "NULL", ",", "$", "comment", "=", "NULL", ",", "$", "description", "=", "NULL", ",", "$", "cardHolderName", "=", "NULL", ",", "$", "taxAmount", "=", "NULL", ")", "{", "$", "request", "=", "Request", "::", "createFromClient", "(", "$", "this", ")", ";", "$", "request", "->", "setTransactionType", "(", "Request", "::", "TRANSACTION_TYPE_PURCHASE", ")", "->", "setTotalAmount", "(", "$", "amount", ")", "->", "setCardData", "(", "$", "cardNumber", ")", "->", "setCardExpiryDate", "(", "$", "month", ",", "$", "year", ")", "->", "setCVC2", "(", "$", "cvc", ")", "->", "setClientReference", "(", "$", "clientReference", ")", "->", "setComment", "(", "$", "comment", ")", "->", "setMerchantDescription", "(", "$", "description", ")", "->", "setMerchantCardHolderName", "(", "$", "cardHolderName", ")", "->", "setTaxAmount", "(", "$", "taxAmount", ")", ";", "return", "$", "request", ";", "}" ]
Create a purchase request. @param $amount @param $cardNumber @param $month @param $year @param null $cvc @param null $clientReference @param null $comment @param null $description @param null $cardHolderName @param null $taxAmount @return \StGeorgeIPG\Request
[ "Create", "a", "purchase", "request", "." ]
2ed1a458d9bb24b3e8c554c20ba4ea75ed6548bc
https://github.com/mitchdav/st-george-ipg/blob/2ed1a458d9bb24b3e8c554c20ba4ea75ed6548bc/src/Client.php#L157-L173
28,423
mitchdav/st-george-ipg
src/Client.php
Client.refund
public function refund($amount, $originalTransactionReference, $clientReference = NULL, $comment = NULL, $description = NULL, $cardHolderName = NULL, $taxAmount = NULL) { $request = Request::createFromClient($this); $request->setTransactionType(Request::TRANSACTION_TYPE_REFUND) ->setTotalAmount($amount) ->setOriginalTransactionReference($originalTransactionReference) ->setClientReference($clientReference) ->setComment($comment) ->setMerchantDescription($description) ->setMerchantCardHolderName($cardHolderName) ->setTaxAmount($taxAmount); return $request; }
php
public function refund($amount, $originalTransactionReference, $clientReference = NULL, $comment = NULL, $description = NULL, $cardHolderName = NULL, $taxAmount = NULL) { $request = Request::createFromClient($this); $request->setTransactionType(Request::TRANSACTION_TYPE_REFUND) ->setTotalAmount($amount) ->setOriginalTransactionReference($originalTransactionReference) ->setClientReference($clientReference) ->setComment($comment) ->setMerchantDescription($description) ->setMerchantCardHolderName($cardHolderName) ->setTaxAmount($taxAmount); return $request; }
[ "public", "function", "refund", "(", "$", "amount", ",", "$", "originalTransactionReference", ",", "$", "clientReference", "=", "NULL", ",", "$", "comment", "=", "NULL", ",", "$", "description", "=", "NULL", ",", "$", "cardHolderName", "=", "NULL", ",", "$", "taxAmount", "=", "NULL", ")", "{", "$", "request", "=", "Request", "::", "createFromClient", "(", "$", "this", ")", ";", "$", "request", "->", "setTransactionType", "(", "Request", "::", "TRANSACTION_TYPE_REFUND", ")", "->", "setTotalAmount", "(", "$", "amount", ")", "->", "setOriginalTransactionReference", "(", "$", "originalTransactionReference", ")", "->", "setClientReference", "(", "$", "clientReference", ")", "->", "setComment", "(", "$", "comment", ")", "->", "setMerchantDescription", "(", "$", "description", ")", "->", "setMerchantCardHolderName", "(", "$", "cardHolderName", ")", "->", "setTaxAmount", "(", "$", "taxAmount", ")", ";", "return", "$", "request", ";", "}" ]
Create a refund request. @param $amount @param $originalTransactionReference @param null $clientReference @param null $comment @param null $description @param null $cardHolderName @param null $taxAmount @return \StGeorgeIPG\Request
[ "Create", "a", "refund", "request", "." ]
2ed1a458d9bb24b3e8c554c20ba4ea75ed6548bc
https://github.com/mitchdav/st-george-ipg/blob/2ed1a458d9bb24b3e8c554c20ba4ea75ed6548bc/src/Client.php#L188-L202
28,424
mitchdav/st-george-ipg
src/Client.php
Client.completion
public function completion($amount, $originalTransactionReference, $authorisationNumber, $clientReference = NULL, $comment = NULL, $description = NULL, $cardHolderName = NULL, $taxAmount = NULL) { $request = Request::createFromClient($this); $request->setTransactionType(Request::TRANSACTION_TYPE_COMPLETION) ->setTotalAmount($amount) ->setOriginalTransactionReference($originalTransactionReference) ->setAuthorisationNumber($authorisationNumber) ->setClientReference($clientReference) ->setComment($comment) ->setMerchantDescription($description) ->setMerchantCardHolderName($cardHolderName) ->setTaxAmount($taxAmount); return $request; }
php
public function completion($amount, $originalTransactionReference, $authorisationNumber, $clientReference = NULL, $comment = NULL, $description = NULL, $cardHolderName = NULL, $taxAmount = NULL) { $request = Request::createFromClient($this); $request->setTransactionType(Request::TRANSACTION_TYPE_COMPLETION) ->setTotalAmount($amount) ->setOriginalTransactionReference($originalTransactionReference) ->setAuthorisationNumber($authorisationNumber) ->setClientReference($clientReference) ->setComment($comment) ->setMerchantDescription($description) ->setMerchantCardHolderName($cardHolderName) ->setTaxAmount($taxAmount); return $request; }
[ "public", "function", "completion", "(", "$", "amount", ",", "$", "originalTransactionReference", ",", "$", "authorisationNumber", ",", "$", "clientReference", "=", "NULL", ",", "$", "comment", "=", "NULL", ",", "$", "description", "=", "NULL", ",", "$", "cardHolderName", "=", "NULL", ",", "$", "taxAmount", "=", "NULL", ")", "{", "$", "request", "=", "Request", "::", "createFromClient", "(", "$", "this", ")", ";", "$", "request", "->", "setTransactionType", "(", "Request", "::", "TRANSACTION_TYPE_COMPLETION", ")", "->", "setTotalAmount", "(", "$", "amount", ")", "->", "setOriginalTransactionReference", "(", "$", "originalTransactionReference", ")", "->", "setAuthorisationNumber", "(", "$", "authorisationNumber", ")", "->", "setClientReference", "(", "$", "clientReference", ")", "->", "setComment", "(", "$", "comment", ")", "->", "setMerchantDescription", "(", "$", "description", ")", "->", "setMerchantCardHolderName", "(", "$", "cardHolderName", ")", "->", "setTaxAmount", "(", "$", "taxAmount", ")", ";", "return", "$", "request", ";", "}" ]
Create a completion request. @param $amount @param $originalTransactionReference @param $authorisationNumber @param null $clientReference @param null $comment @param null $description @param null $cardHolderName @param null $taxAmount @return \StGeorgeIPG\Request
[ "Create", "a", "completion", "request", "." ]
2ed1a458d9bb24b3e8c554c20ba4ea75ed6548bc
https://github.com/mitchdav/st-george-ipg/blob/2ed1a458d9bb24b3e8c554c20ba4ea75ed6548bc/src/Client.php#L252-L267
28,425
mitchdav/st-george-ipg
src/Client.php
Client.status
public function status($transactionReference) { $request = Request::createFromClient($this, FALSE); $request->setTransactionType(Request::TRANSACTION_TYPE_STATUS) ->setTransactionReference($transactionReference); return $request; }
php
public function status($transactionReference) { $request = Request::createFromClient($this, FALSE); $request->setTransactionType(Request::TRANSACTION_TYPE_STATUS) ->setTransactionReference($transactionReference); return $request; }
[ "public", "function", "status", "(", "$", "transactionReference", ")", "{", "$", "request", "=", "Request", "::", "createFromClient", "(", "$", "this", ",", "FALSE", ")", ";", "$", "request", "->", "setTransactionType", "(", "Request", "::", "TRANSACTION_TYPE_STATUS", ")", "->", "setTransactionReference", "(", "$", "transactionReference", ")", ";", "return", "$", "request", ";", "}" ]
Create a status request. @param $transactionReference @return \StGeorgeIPG\Request
[ "Create", "a", "status", "request", "." ]
2ed1a458d9bb24b3e8c554c20ba4ea75ed6548bc
https://github.com/mitchdav/st-george-ipg/blob/2ed1a458d9bb24b3e8c554c20ba4ea75ed6548bc/src/Client.php#L276-L284
28,426
mitchdav/st-george-ipg
src/Client.php
Client.getResponse
public function getResponse(Request $request, $maxTries = 3) { $request->validate(); $response = $this->getProvider() ->getResponse($request, $canSafelyTryAgain); if ($canSafelyTryAgain) { if ($response->getTransactionReference() !== NULL) { if ($maxTries > 0) { $response = $this->getResponse($this->status($response->getTransactionReference()), $maxTries - 1); } else { throw new TransactionFailedException($request, $response, $maxTries); } } else { if ($maxTries > 0) { return $this->getResponse($request, $maxTries - 1); } else { throw new TransactionFailedException($request, $response, $maxTries); } } } else { if ($response->isCodeInProgress()) { if ($maxTries > 0) { if ($request->isTransactionTypeStatus()) { $response = $this->getResponse($request, $maxTries - 1); } else { $response = $this->getResponse($this->status($response->getTransactionReference()), $maxTries - 1); } } else { throw new TransactionInProgressException($request, $response, $maxTries); } } } return $response; }
php
public function getResponse(Request $request, $maxTries = 3) { $request->validate(); $response = $this->getProvider() ->getResponse($request, $canSafelyTryAgain); if ($canSafelyTryAgain) { if ($response->getTransactionReference() !== NULL) { if ($maxTries > 0) { $response = $this->getResponse($this->status($response->getTransactionReference()), $maxTries - 1); } else { throw new TransactionFailedException($request, $response, $maxTries); } } else { if ($maxTries > 0) { return $this->getResponse($request, $maxTries - 1); } else { throw new TransactionFailedException($request, $response, $maxTries); } } } else { if ($response->isCodeInProgress()) { if ($maxTries > 0) { if ($request->isTransactionTypeStatus()) { $response = $this->getResponse($request, $maxTries - 1); } else { $response = $this->getResponse($this->status($response->getTransactionReference()), $maxTries - 1); } } else { throw new TransactionInProgressException($request, $response, $maxTries); } } } return $response; }
[ "public", "function", "getResponse", "(", "Request", "$", "request", ",", "$", "maxTries", "=", "3", ")", "{", "$", "request", "->", "validate", "(", ")", ";", "$", "response", "=", "$", "this", "->", "getProvider", "(", ")", "->", "getResponse", "(", "$", "request", ",", "$", "canSafelyTryAgain", ")", ";", "if", "(", "$", "canSafelyTryAgain", ")", "{", "if", "(", "$", "response", "->", "getTransactionReference", "(", ")", "!==", "NULL", ")", "{", "if", "(", "$", "maxTries", ">", "0", ")", "{", "$", "response", "=", "$", "this", "->", "getResponse", "(", "$", "this", "->", "status", "(", "$", "response", "->", "getTransactionReference", "(", ")", ")", ",", "$", "maxTries", "-", "1", ")", ";", "}", "else", "{", "throw", "new", "TransactionFailedException", "(", "$", "request", ",", "$", "response", ",", "$", "maxTries", ")", ";", "}", "}", "else", "{", "if", "(", "$", "maxTries", ">", "0", ")", "{", "return", "$", "this", "->", "getResponse", "(", "$", "request", ",", "$", "maxTries", "-", "1", ")", ";", "}", "else", "{", "throw", "new", "TransactionFailedException", "(", "$", "request", ",", "$", "response", ",", "$", "maxTries", ")", ";", "}", "}", "}", "else", "{", "if", "(", "$", "response", "->", "isCodeInProgress", "(", ")", ")", "{", "if", "(", "$", "maxTries", ">", "0", ")", "{", "if", "(", "$", "request", "->", "isTransactionTypeStatus", "(", ")", ")", "{", "$", "response", "=", "$", "this", "->", "getResponse", "(", "$", "request", ",", "$", "maxTries", "-", "1", ")", ";", "}", "else", "{", "$", "response", "=", "$", "this", "->", "getResponse", "(", "$", "this", "->", "status", "(", "$", "response", "->", "getTransactionReference", "(", ")", ")", ",", "$", "maxTries", "-", "1", ")", ";", "}", "}", "else", "{", "throw", "new", "TransactionInProgressException", "(", "$", "request", ",", "$", "response", ",", "$", "maxTries", ")", ";", "}", "}", "}", "return", "$", "response", ";", "}" ]
Get a response for the given request, following the flow diagram provided by St.George. @param \StGeorgeIPG\Request $request @param integer $maxTries @return \StGeorgeIPG\Response @throws \StGeorgeIPG\Exceptions\TransactionFailedException @throws \StGeorgeIPG\Exceptions\TransactionInProgressException
[ "Get", "a", "response", "for", "the", "given", "request", "following", "the", "flow", "diagram", "provided", "by", "St", ".", "George", "." ]
2ed1a458d9bb24b3e8c554c20ba4ea75ed6548bc
https://github.com/mitchdav/st-george-ipg/blob/2ed1a458d9bb24b3e8c554c20ba4ea75ed6548bc/src/Client.php#L296-L332
28,427
mitchdav/st-george-ipg
src/Client.php
Client.execute
public function execute(Request $request, $maxTries = 3) { try { $response = $this->getResponse($request, $maxTries); return $this->validateResponse($response); } catch (TransactionInProgressException $ex) { throw new TransactionInProgressException($ex->getRequest(), $ex->getResponse(), $maxTries); // Throw a new exception with the correct maximum tries. } }
php
public function execute(Request $request, $maxTries = 3) { try { $response = $this->getResponse($request, $maxTries); return $this->validateResponse($response); } catch (TransactionInProgressException $ex) { throw new TransactionInProgressException($ex->getRequest(), $ex->getResponse(), $maxTries); // Throw a new exception with the correct maximum tries. } }
[ "public", "function", "execute", "(", "Request", "$", "request", ",", "$", "maxTries", "=", "3", ")", "{", "try", "{", "$", "response", "=", "$", "this", "->", "getResponse", "(", "$", "request", ",", "$", "maxTries", ")", ";", "return", "$", "this", "->", "validateResponse", "(", "$", "response", ")", ";", "}", "catch", "(", "TransactionInProgressException", "$", "ex", ")", "{", "throw", "new", "TransactionInProgressException", "(", "$", "ex", "->", "getRequest", "(", ")", ",", "$", "ex", "->", "getResponse", "(", ")", ",", "$", "maxTries", ")", ";", "// Throw a new exception with the correct maximum tries.", "}", "}" ]
Get the response, and then pass it to the validator. @param \StGeorgeIPG\Request $request @param integer $maxTries @return \StGeorgeIPG\Response @throws \StGeorgeIPG\Exceptions\TransactionInProgressException
[ "Get", "the", "response", "and", "then", "pass", "it", "to", "the", "validator", "." ]
2ed1a458d9bb24b3e8c554c20ba4ea75ed6548bc
https://github.com/mitchdav/st-george-ipg/blob/2ed1a458d9bb24b3e8c554c20ba4ea75ed6548bc/src/Client.php#L344-L353
28,428
mmoreram/ControllerExtraBundle
Resolver/FormAnnotationResolver.php
FormAnnotationResolver.getBuiltObject
private function getBuiltObject( Request $request, FormFactoryInterface $formFactory, CreateForm $annotation, string $parameterClass, AbstractType $type ) { /** * Checks if parameter typehinting is AbstractType * In this case, form type as defined method parameter. */ if (AbstractType::class == $parameterClass) { return $type; } $entity = $request->attributes->get($annotation->getEntity()); /** * Creates form object from type. */ $form = $formFactory->create(get_class($type), $entity); /** * Handling request if needed. */ if ($annotation->getHandleRequest()) { $form->handleRequest($request); if ($annotation->getValidate()) { $request->attributes->set( $annotation->getValidate(), ($form->isSubmitted() && $form->isValid()) ); } } /** * Checks if parameter typehinting is Form * In this case, inject form as defined method parameter. */ if (in_array( $parameterClass, [ Form::class, FormInterface::class, ] )) { return $form; } /** * Checks if parameter typehinting is FormView * In this case, inject form's view as defined method parameter. */ if (FormView::class == $parameterClass) { return $form->createView(); } }
php
private function getBuiltObject( Request $request, FormFactoryInterface $formFactory, CreateForm $annotation, string $parameterClass, AbstractType $type ) { /** * Checks if parameter typehinting is AbstractType * In this case, form type as defined method parameter. */ if (AbstractType::class == $parameterClass) { return $type; } $entity = $request->attributes->get($annotation->getEntity()); /** * Creates form object from type. */ $form = $formFactory->create(get_class($type), $entity); /** * Handling request if needed. */ if ($annotation->getHandleRequest()) { $form->handleRequest($request); if ($annotation->getValidate()) { $request->attributes->set( $annotation->getValidate(), ($form->isSubmitted() && $form->isValid()) ); } } /** * Checks if parameter typehinting is Form * In this case, inject form as defined method parameter. */ if (in_array( $parameterClass, [ Form::class, FormInterface::class, ] )) { return $form; } /** * Checks if parameter typehinting is FormView * In this case, inject form's view as defined method parameter. */ if (FormView::class == $parameterClass) { return $form->createView(); } }
[ "private", "function", "getBuiltObject", "(", "Request", "$", "request", ",", "FormFactoryInterface", "$", "formFactory", ",", "CreateForm", "$", "annotation", ",", "string", "$", "parameterClass", ",", "AbstractType", "$", "type", ")", "{", "/**\n * Checks if parameter typehinting is AbstractType\n * In this case, form type as defined method parameter.\n */", "if", "(", "AbstractType", "::", "class", "==", "$", "parameterClass", ")", "{", "return", "$", "type", ";", "}", "$", "entity", "=", "$", "request", "->", "attributes", "->", "get", "(", "$", "annotation", "->", "getEntity", "(", ")", ")", ";", "/**\n * Creates form object from type.\n */", "$", "form", "=", "$", "formFactory", "->", "create", "(", "get_class", "(", "$", "type", ")", ",", "$", "entity", ")", ";", "/**\n * Handling request if needed.\n */", "if", "(", "$", "annotation", "->", "getHandleRequest", "(", ")", ")", "{", "$", "form", "->", "handleRequest", "(", "$", "request", ")", ";", "if", "(", "$", "annotation", "->", "getValidate", "(", ")", ")", "{", "$", "request", "->", "attributes", "->", "set", "(", "$", "annotation", "->", "getValidate", "(", ")", ",", "(", "$", "form", "->", "isSubmitted", "(", ")", "&&", "$", "form", "->", "isValid", "(", ")", ")", ")", ";", "}", "}", "/**\n * Checks if parameter typehinting is Form\n * In this case, inject form as defined method parameter.\n */", "if", "(", "in_array", "(", "$", "parameterClass", ",", "[", "Form", "::", "class", ",", "FormInterface", "::", "class", ",", "]", ")", ")", "{", "return", "$", "form", ";", "}", "/**\n * Checks if parameter typehinting is FormView\n * In this case, inject form's view as defined method parameter.\n */", "if", "(", "FormView", "::", "class", "==", "$", "parameterClass", ")", "{", "return", "$", "form", "->", "createView", "(", ")", ";", "}", "}" ]
Built and return desired object. @param Request $request @param FormFactoryInterface $formFactory @param CreateForm $annotation @param string $parameterClass @param AbstractType $type @return mixed
[ "Built", "and", "return", "desired", "object", "." ]
b5841b6ca8f0022a2d88fdfbf743f0b76c4644e3
https://github.com/mmoreram/ControllerExtraBundle/blob/b5841b6ca8f0022a2d88fdfbf743f0b76c4644e3/Resolver/FormAnnotationResolver.php#L141-L197
28,429
QoboLtd/cakephp-search
src/Model/Table/WidgetsTable.php
WidgetsTable.getWidgets
public function getWidgets(): array { // get widgets through Event broadcast $event = new Event((string)EventName::MODEL_DASHBOARDS_GET_WIDGETS(), $this); $this->getEventManager()->dispatch($event); if (empty($event->getResult())) { return []; } // assembling all widgets in one $result = []; foreach ((array)$event->getResult() as $widget) { if (empty($widget['data'])) { continue; } $instance = WidgetFactory::create($widget['type']); foreach ($widget['data'] as $data) { array_push($result, [ 'type' => $widget['type'], 'title' => $instance->getTitle(), 'icon' => $instance->getIcon(), 'color' => $instance->getColor(), 'data' => $data ]); } } return $result; }
php
public function getWidgets(): array { // get widgets through Event broadcast $event = new Event((string)EventName::MODEL_DASHBOARDS_GET_WIDGETS(), $this); $this->getEventManager()->dispatch($event); if (empty($event->getResult())) { return []; } // assembling all widgets in one $result = []; foreach ((array)$event->getResult() as $widget) { if (empty($widget['data'])) { continue; } $instance = WidgetFactory::create($widget['type']); foreach ($widget['data'] as $data) { array_push($result, [ 'type' => $widget['type'], 'title' => $instance->getTitle(), 'icon' => $instance->getIcon(), 'color' => $instance->getColor(), 'data' => $data ]); } } return $result; }
[ "public", "function", "getWidgets", "(", ")", ":", "array", "{", "// get widgets through Event broadcast", "$", "event", "=", "new", "Event", "(", "(", "string", ")", "EventName", "::", "MODEL_DASHBOARDS_GET_WIDGETS", "(", ")", ",", "$", "this", ")", ";", "$", "this", "->", "getEventManager", "(", ")", "->", "dispatch", "(", "$", "event", ")", ";", "if", "(", "empty", "(", "$", "event", "->", "getResult", "(", ")", ")", ")", "{", "return", "[", "]", ";", "}", "// assembling all widgets in one", "$", "result", "=", "[", "]", ";", "foreach", "(", "(", "array", ")", "$", "event", "->", "getResult", "(", ")", "as", "$", "widget", ")", "{", "if", "(", "empty", "(", "$", "widget", "[", "'data'", "]", ")", ")", "{", "continue", ";", "}", "$", "instance", "=", "WidgetFactory", "::", "create", "(", "$", "widget", "[", "'type'", "]", ")", ";", "foreach", "(", "$", "widget", "[", "'data'", "]", "as", "$", "data", ")", "{", "array_push", "(", "$", "result", ",", "[", "'type'", "=>", "$", "widget", "[", "'type'", "]", ",", "'title'", "=>", "$", "instance", "->", "getTitle", "(", ")", ",", "'icon'", "=>", "$", "instance", "->", "getIcon", "(", ")", ",", "'color'", "=>", "$", "instance", "->", "getColor", "(", ")", ",", "'data'", "=>", "$", "data", "]", ")", ";", "}", "}", "return", "$", "result", ";", "}" ]
getWidgets method. @return mixed[] $result containing all widgets
[ "getWidgets", "method", "." ]
095a0e822781ac11eade0c03c7729b693daa1ba8
https://github.com/QoboLtd/cakephp-search/blob/095a0e822781ac11eade0c03c7729b693daa1ba8/src/Model/Table/WidgetsTable.php#L123-L154
28,430
QoboLtd/cakephp-search
src/Model/Table/WidgetsTable.php
WidgetsTable.saveDashboardWidgets
public function saveDashboardWidgets(string $dashboardId, array $widgets = []): bool { $result = false; if (empty($widgets)) { return $result; } foreach ($widgets as $item) { $widget = [ 'dashboard_id' => $dashboardId, 'widget_id' => $item['id'], 'widget_type' => $item['type'], 'widget_options' => json_encode($item), 'row' => 0, 'column' => 0, ]; $entity = $this->newEntity(); $entity = $this->patchEntity($entity, $widget); if ($this->save($entity)) { $result = true; } } return $result; }
php
public function saveDashboardWidgets(string $dashboardId, array $widgets = []): bool { $result = false; if (empty($widgets)) { return $result; } foreach ($widgets as $item) { $widget = [ 'dashboard_id' => $dashboardId, 'widget_id' => $item['id'], 'widget_type' => $item['type'], 'widget_options' => json_encode($item), 'row' => 0, 'column' => 0, ]; $entity = $this->newEntity(); $entity = $this->patchEntity($entity, $widget); if ($this->save($entity)) { $result = true; } } return $result; }
[ "public", "function", "saveDashboardWidgets", "(", "string", "$", "dashboardId", ",", "array", "$", "widgets", "=", "[", "]", ")", ":", "bool", "{", "$", "result", "=", "false", ";", "if", "(", "empty", "(", "$", "widgets", ")", ")", "{", "return", "$", "result", ";", "}", "foreach", "(", "$", "widgets", "as", "$", "item", ")", "{", "$", "widget", "=", "[", "'dashboard_id'", "=>", "$", "dashboardId", ",", "'widget_id'", "=>", "$", "item", "[", "'id'", "]", ",", "'widget_type'", "=>", "$", "item", "[", "'type'", "]", ",", "'widget_options'", "=>", "json_encode", "(", "$", "item", ")", ",", "'row'", "=>", "0", ",", "'column'", "=>", "0", ",", "]", ";", "$", "entity", "=", "$", "this", "->", "newEntity", "(", ")", ";", "$", "entity", "=", "$", "this", "->", "patchEntity", "(", "$", "entity", ",", "$", "widget", ")", ";", "if", "(", "$", "this", "->", "save", "(", "$", "entity", ")", ")", "{", "$", "result", "=", "true", ";", "}", "}", "return", "$", "result", ";", "}" ]
Save Dashboard Widgets @param string $dashboardId of the instance @param mixed[] $widgets of the dashboard @return bool $result of the save operation.
[ "Save", "Dashboard", "Widgets" ]
095a0e822781ac11eade0c03c7729b693daa1ba8
https://github.com/QoboLtd/cakephp-search/blob/095a0e822781ac11eade0c03c7729b693daa1ba8/src/Model/Table/WidgetsTable.php#L200-L227
28,431
rinvex/cortex-pages
src/Http/Controllers/Adminarea/PagesMediaController.php
PagesMediaController.index
public function index(Page $page, MediaDataTable $mediaDataTable) { return $mediaDataTable->with([ 'resource' => $page, 'tabs' => 'adminarea.pages.tabs', 'id' => "adminarea-pages-{$page->getRouteKey()}-media-table", 'url' => route('adminarea.pages.media.store', ['page' => $page]), ])->render('cortex/foundation::adminarea.pages.datatable-dropzone'); }
php
public function index(Page $page, MediaDataTable $mediaDataTable) { return $mediaDataTable->with([ 'resource' => $page, 'tabs' => 'adminarea.pages.tabs', 'id' => "adminarea-pages-{$page->getRouteKey()}-media-table", 'url' => route('adminarea.pages.media.store', ['page' => $page]), ])->render('cortex/foundation::adminarea.pages.datatable-dropzone'); }
[ "public", "function", "index", "(", "Page", "$", "page", ",", "MediaDataTable", "$", "mediaDataTable", ")", "{", "return", "$", "mediaDataTable", "->", "with", "(", "[", "'resource'", "=>", "$", "page", ",", "'tabs'", "=>", "'adminarea.pages.tabs'", ",", "'id'", "=>", "\"adminarea-pages-{$page->getRouteKey()}-media-table\"", ",", "'url'", "=>", "route", "(", "'adminarea.pages.media.store'", ",", "[", "'page'", "=>", "$", "page", "]", ")", ",", "]", ")", "->", "render", "(", "'cortex/foundation::adminarea.pages.datatable-dropzone'", ")", ";", "}" ]
List all page media. @param \Cortex\Foundation\DataTables\MediaDataTable $mediaDataTable @param \Cortex\Pages\Models\Page $page @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
[ "List", "all", "page", "media", "." ]
7229fedb34d352fda0e721f950c55074f0fb0dce
https://github.com/rinvex/cortex-pages/blob/7229fedb34d352fda0e721f950c55074f0fb0dce/src/Http/Controllers/Adminarea/PagesMediaController.php#L48-L56
28,432
rinvex/cortex-pages
src/Http/Controllers/Adminarea/PagesMediaController.php
PagesMediaController.store
public function store(ImageFormRequest $request, Page $page): void { $page->addMediaFromRequest('file') ->sanitizingFileName(function ($fileName) { return md5($fileName).'.'.pathinfo($fileName, PATHINFO_EXTENSION); }) ->toMediaCollection('default', config('cortex.pages.media.disk')); }
php
public function store(ImageFormRequest $request, Page $page): void { $page->addMediaFromRequest('file') ->sanitizingFileName(function ($fileName) { return md5($fileName).'.'.pathinfo($fileName, PATHINFO_EXTENSION); }) ->toMediaCollection('default', config('cortex.pages.media.disk')); }
[ "public", "function", "store", "(", "ImageFormRequest", "$", "request", ",", "Page", "$", "page", ")", ":", "void", "{", "$", "page", "->", "addMediaFromRequest", "(", "'file'", ")", "->", "sanitizingFileName", "(", "function", "(", "$", "fileName", ")", "{", "return", "md5", "(", "$", "fileName", ")", ".", "'.'", ".", "pathinfo", "(", "$", "fileName", ",", "PATHINFO_EXTENSION", ")", ";", "}", ")", "->", "toMediaCollection", "(", "'default'", ",", "config", "(", "'cortex.pages.media.disk'", ")", ")", ";", "}" ]
Store new page media. @param \Cortex\Foundation\Http\Requests\ImageFormRequest $request @param \Cortex\Pages\Models\Page $page @return void
[ "Store", "new", "page", "media", "." ]
7229fedb34d352fda0e721f950c55074f0fb0dce
https://github.com/rinvex/cortex-pages/blob/7229fedb34d352fda0e721f950c55074f0fb0dce/src/Http/Controllers/Adminarea/PagesMediaController.php#L66-L73
28,433
rinvex/cortex-pages
src/Http/Controllers/Adminarea/PagesMediaController.php
PagesMediaController.destroy
public function destroy(Page $page, Media $media) { $page->media()->where($media->getKeyName(), $media->getKey())->first()->delete(); return intend([ 'url' => route('adminarea.pages.media.index', ['page' => $page]), 'with' => ['warning' => trans('cortex/foundation::messages.resource_deleted', ['resource' => trans('cortex/foundation::common.media'), 'identifier' => $media->getRouteKey()])], ]); }
php
public function destroy(Page $page, Media $media) { $page->media()->where($media->getKeyName(), $media->getKey())->first()->delete(); return intend([ 'url' => route('adminarea.pages.media.index', ['page' => $page]), 'with' => ['warning' => trans('cortex/foundation::messages.resource_deleted', ['resource' => trans('cortex/foundation::common.media'), 'identifier' => $media->getRouteKey()])], ]); }
[ "public", "function", "destroy", "(", "Page", "$", "page", ",", "Media", "$", "media", ")", "{", "$", "page", "->", "media", "(", ")", "->", "where", "(", "$", "media", "->", "getKeyName", "(", ")", ",", "$", "media", "->", "getKey", "(", ")", ")", "->", "first", "(", ")", "->", "delete", "(", ")", ";", "return", "intend", "(", "[", "'url'", "=>", "route", "(", "'adminarea.pages.media.index'", ",", "[", "'page'", "=>", "$", "page", "]", ")", ",", "'with'", "=>", "[", "'warning'", "=>", "trans", "(", "'cortex/foundation::messages.resource_deleted'", ",", "[", "'resource'", "=>", "trans", "(", "'cortex/foundation::common.media'", ")", ",", "'identifier'", "=>", "$", "media", "->", "getRouteKey", "(", ")", "]", ")", "]", ",", "]", ")", ";", "}" ]
Destroy given page media. @param \Cortex\Pages\Models\Page $page @param \Spatie\MediaLibrary\Models\Media $media @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
[ "Destroy", "given", "page", "media", "." ]
7229fedb34d352fda0e721f950c55074f0fb0dce
https://github.com/rinvex/cortex-pages/blob/7229fedb34d352fda0e721f950c55074f0fb0dce/src/Http/Controllers/Adminarea/PagesMediaController.php#L83-L91
28,434
QoboLtd/cakephp-search
src/Utility/Search.php
Search.execute
public function execute(array $data) : QueryInterface { $data = Validator::validateData($this->table, $data, $this->user); // initialize query $query = $this->table->find('all'); $where = $this->getWhereClause($data); $group = $this->getGroupByClause($data); $select = $this->getSelectClause($data); $order = [$this->table->aliasField($data['sort_by_field']) => $data['sort_by_order']]; $joins = $this->byAssociations($data); // set joins and append to where and select parameters foreach ($joins as $name => $params) { $query->leftJoinWith($name); if (!empty($params['where'])) { $where = array_merge($where, $params['where']); } if (!empty($params['select'])) { $select = array_merge($select, $params['select']); } } $select = !empty($group) ? $group : $select; if (!empty($group)) { $select = $group; $select[static::GROUP_BY_FIELD] = $query->func()->count($group[0]); } // add query clauses $query->select($select)->where([$data['aggregator'] => $where])->order($order)->group($group); return $query; }
php
public function execute(array $data) : QueryInterface { $data = Validator::validateData($this->table, $data, $this->user); // initialize query $query = $this->table->find('all'); $where = $this->getWhereClause($data); $group = $this->getGroupByClause($data); $select = $this->getSelectClause($data); $order = [$this->table->aliasField($data['sort_by_field']) => $data['sort_by_order']]; $joins = $this->byAssociations($data); // set joins and append to where and select parameters foreach ($joins as $name => $params) { $query->leftJoinWith($name); if (!empty($params['where'])) { $where = array_merge($where, $params['where']); } if (!empty($params['select'])) { $select = array_merge($select, $params['select']); } } $select = !empty($group) ? $group : $select; if (!empty($group)) { $select = $group; $select[static::GROUP_BY_FIELD] = $query->func()->count($group[0]); } // add query clauses $query->select($select)->where([$data['aggregator'] => $where])->order($order)->group($group); return $query; }
[ "public", "function", "execute", "(", "array", "$", "data", ")", ":", "QueryInterface", "{", "$", "data", "=", "Validator", "::", "validateData", "(", "$", "this", "->", "table", ",", "$", "data", ",", "$", "this", "->", "user", ")", ";", "// initialize query", "$", "query", "=", "$", "this", "->", "table", "->", "find", "(", "'all'", ")", ";", "$", "where", "=", "$", "this", "->", "getWhereClause", "(", "$", "data", ")", ";", "$", "group", "=", "$", "this", "->", "getGroupByClause", "(", "$", "data", ")", ";", "$", "select", "=", "$", "this", "->", "getSelectClause", "(", "$", "data", ")", ";", "$", "order", "=", "[", "$", "this", "->", "table", "->", "aliasField", "(", "$", "data", "[", "'sort_by_field'", "]", ")", "=>", "$", "data", "[", "'sort_by_order'", "]", "]", ";", "$", "joins", "=", "$", "this", "->", "byAssociations", "(", "$", "data", ")", ";", "// set joins and append to where and select parameters", "foreach", "(", "$", "joins", "as", "$", "name", "=>", "$", "params", ")", "{", "$", "query", "->", "leftJoinWith", "(", "$", "name", ")", ";", "if", "(", "!", "empty", "(", "$", "params", "[", "'where'", "]", ")", ")", "{", "$", "where", "=", "array_merge", "(", "$", "where", ",", "$", "params", "[", "'where'", "]", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "params", "[", "'select'", "]", ")", ")", "{", "$", "select", "=", "array_merge", "(", "$", "select", ",", "$", "params", "[", "'select'", "]", ")", ";", "}", "}", "$", "select", "=", "!", "empty", "(", "$", "group", ")", "?", "$", "group", ":", "$", "select", ";", "if", "(", "!", "empty", "(", "$", "group", ")", ")", "{", "$", "select", "=", "$", "group", ";", "$", "select", "[", "static", "::", "GROUP_BY_FIELD", "]", "=", "$", "query", "->", "func", "(", ")", "->", "count", "(", "$", "group", "[", "0", "]", ")", ";", "}", "// add query clauses", "$", "query", "->", "select", "(", "$", "select", ")", "->", "where", "(", "[", "$", "data", "[", "'aggregator'", "]", "=>", "$", "where", "]", ")", "->", "order", "(", "$", "order", ")", "->", "group", "(", "$", "group", ")", ";", "return", "$", "query", ";", "}" ]
Search method. @param mixed[] $data Request data @return \Cake\Datasource\QueryInterface
[ "Search", "method", "." ]
095a0e822781ac11eade0c03c7729b693daa1ba8
https://github.com/QoboLtd/cakephp-search/blob/095a0e822781ac11eade0c03c7729b693daa1ba8/src/Utility/Search.php#L97-L133
28,435
QoboLtd/cakephp-search
src/Utility/Search.php
Search.create
public function create(array $searchData): string { $searchData = Validator::validateData($this->table, $searchData, $this->user); // pre-save search return $this->preSave($searchData); }
php
public function create(array $searchData): string { $searchData = Validator::validateData($this->table, $searchData, $this->user); // pre-save search return $this->preSave($searchData); }
[ "public", "function", "create", "(", "array", "$", "searchData", ")", ":", "string", "{", "$", "searchData", "=", "Validator", "::", "validateData", "(", "$", "this", "->", "table", ",", "$", "searchData", ",", "$", "this", "->", "user", ")", ";", "// pre-save search", "return", "$", "this", "->", "preSave", "(", "$", "searchData", ")", ";", "}" ]
Create search. @param mixed[] $searchData Request data @return string
[ "Create", "search", "." ]
095a0e822781ac11eade0c03c7729b693daa1ba8
https://github.com/QoboLtd/cakephp-search/blob/095a0e822781ac11eade0c03c7729b693daa1ba8/src/Utility/Search.php#L141-L147
28,436
QoboLtd/cakephp-search
src/Utility/Search.php
Search.update
public function update(array $searchData, string $id) { /** * @var \Search\Model\Entity\SavedSearch */ $entity = $this->searchTable->get($id); $entity = $this->normalize($entity, $entity->get('content'), $searchData); return $this->searchTable->save($entity); }
php
public function update(array $searchData, string $id) { /** * @var \Search\Model\Entity\SavedSearch */ $entity = $this->searchTable->get($id); $entity = $this->normalize($entity, $entity->get('content'), $searchData); return $this->searchTable->save($entity); }
[ "public", "function", "update", "(", "array", "$", "searchData", ",", "string", "$", "id", ")", "{", "/**\n * @var \\Search\\Model\\Entity\\SavedSearch\n */", "$", "entity", "=", "$", "this", "->", "searchTable", "->", "get", "(", "$", "id", ")", ";", "$", "entity", "=", "$", "this", "->", "normalize", "(", "$", "entity", ",", "$", "entity", "->", "get", "(", "'content'", ")", ",", "$", "searchData", ")", ";", "return", "$", "this", "->", "searchTable", "->", "save", "(", "$", "entity", ")", ";", "}" ]
Update search. @param mixed[] $searchData Request data @param string $id Existing search id @return \Cake\Datasource\EntityInterface|false
[ "Update", "search", "." ]
095a0e822781ac11eade0c03c7729b693daa1ba8
https://github.com/QoboLtd/cakephp-search/blob/095a0e822781ac11eade0c03c7729b693daa1ba8/src/Utility/Search.php#L156-L165
28,437
QoboLtd/cakephp-search
src/Utility/Search.php
Search.get
public function get(string $id): SavedSearch { $id = !empty($id) ? $id : $this->create([]); /** * @var \Search\Model\Entity\SavedSearch */ $entity = $this->searchTable->get($id); $entity = $this->normalize($entity, $entity->get('content'), $entity->get('content')); return $entity; }
php
public function get(string $id): SavedSearch { $id = !empty($id) ? $id : $this->create([]); /** * @var \Search\Model\Entity\SavedSearch */ $entity = $this->searchTable->get($id); $entity = $this->normalize($entity, $entity->get('content'), $entity->get('content')); return $entity; }
[ "public", "function", "get", "(", "string", "$", "id", ")", ":", "SavedSearch", "{", "$", "id", "=", "!", "empty", "(", "$", "id", ")", "?", "$", "id", ":", "$", "this", "->", "create", "(", "[", "]", ")", ";", "/**\n * @var \\Search\\Model\\Entity\\SavedSearch\n */", "$", "entity", "=", "$", "this", "->", "searchTable", "->", "get", "(", "$", "id", ")", ";", "$", "entity", "=", "$", "this", "->", "normalize", "(", "$", "entity", ",", "$", "entity", "->", "get", "(", "'content'", ")", ",", "$", "entity", "->", "get", "(", "'content'", ")", ")", ";", "return", "$", "entity", ";", "}" ]
Get search. @param string $id Existing search id @return \Search\Model\Entity\SavedSearch
[ "Get", "search", "." ]
095a0e822781ac11eade0c03c7729b693daa1ba8
https://github.com/QoboLtd/cakephp-search/blob/095a0e822781ac11eade0c03c7729b693daa1ba8/src/Utility/Search.php#L173-L183
28,438
QoboLtd/cakephp-search
src/Utility/Search.php
Search.reset
public function reset(SavedSearch $entity) : ?SavedSearch { $content = $entity->get('content'); // for backward compatibility $saved = isset($content['saved']) ? $content['saved'] : $content; $entity = $this->normalize($entity, $saved, $saved); return $this->searchTable->save($entity) ? $entity : null; }
php
public function reset(SavedSearch $entity) : ?SavedSearch { $content = $entity->get('content'); // for backward compatibility $saved = isset($content['saved']) ? $content['saved'] : $content; $entity = $this->normalize($entity, $saved, $saved); return $this->searchTable->save($entity) ? $entity : null; }
[ "public", "function", "reset", "(", "SavedSearch", "$", "entity", ")", ":", "?", "SavedSearch", "{", "$", "content", "=", "$", "entity", "->", "get", "(", "'content'", ")", ";", "// for backward compatibility", "$", "saved", "=", "isset", "(", "$", "content", "[", "'saved'", "]", ")", "?", "$", "content", "[", "'saved'", "]", ":", "$", "content", ";", "$", "entity", "=", "$", "this", "->", "normalize", "(", "$", "entity", ",", "$", "saved", ",", "$", "saved", ")", ";", "return", "$", "this", "->", "searchTable", "->", "save", "(", "$", "entity", ")", "?", "$", "entity", ":", "null", ";", "}" ]
Reset search. @param \Search\Model\Entity\SavedSearch $entity Search entity @return \Search\Model\Entity\SavedSearch|null
[ "Reset", "search", "." ]
095a0e822781ac11eade0c03c7729b693daa1ba8
https://github.com/QoboLtd/cakephp-search/blob/095a0e822781ac11eade0c03c7729b693daa1ba8/src/Utility/Search.php#L191-L200
28,439
QoboLtd/cakephp-search
src/Utility/Search.php
Search.prepareData
public function prepareData(ServerRequest $request): array { $result = $request->getData(); $event = new Event((string)EventName::MODEL_SEARCH_CHILD_ITEMS(), $this, [ 'criteria' => $result ]); EventManager::instance()->dispatch($event); $result = $event->result ? $event->result : $result; $value = Hash::get($result, 'criteria.query'); // advanced search if (!$value) { return $result; } // basic search query, converted to search criteria $result['aggregator'] = 'OR'; $basicSearch = new BasicSearch($this->table, $this->user); $result['criteria'] = $basicSearch->getCriteria($value); return $result; }
php
public function prepareData(ServerRequest $request): array { $result = $request->getData(); $event = new Event((string)EventName::MODEL_SEARCH_CHILD_ITEMS(), $this, [ 'criteria' => $result ]); EventManager::instance()->dispatch($event); $result = $event->result ? $event->result : $result; $value = Hash::get($result, 'criteria.query'); // advanced search if (!$value) { return $result; } // basic search query, converted to search criteria $result['aggregator'] = 'OR'; $basicSearch = new BasicSearch($this->table, $this->user); $result['criteria'] = $basicSearch->getCriteria($value); return $result; }
[ "public", "function", "prepareData", "(", "ServerRequest", "$", "request", ")", ":", "array", "{", "$", "result", "=", "$", "request", "->", "getData", "(", ")", ";", "$", "event", "=", "new", "Event", "(", "(", "string", ")", "EventName", "::", "MODEL_SEARCH_CHILD_ITEMS", "(", ")", ",", "$", "this", ",", "[", "'criteria'", "=>", "$", "result", "]", ")", ";", "EventManager", "::", "instance", "(", ")", "->", "dispatch", "(", "$", "event", ")", ";", "$", "result", "=", "$", "event", "->", "result", "?", "$", "event", "->", "result", ":", "$", "result", ";", "$", "value", "=", "Hash", "::", "get", "(", "$", "result", ",", "'criteria.query'", ")", ";", "// advanced search", "if", "(", "!", "$", "value", ")", "{", "return", "$", "result", ";", "}", "// basic search query, converted to search criteria", "$", "result", "[", "'aggregator'", "]", "=", "'OR'", ";", "$", "basicSearch", "=", "new", "BasicSearch", "(", "$", "this", "->", "table", ",", "$", "this", "->", "user", ")", ";", "$", "result", "[", "'criteria'", "]", "=", "$", "basicSearch", "->", "getCriteria", "(", "$", "value", ")", ";", "return", "$", "result", ";", "}" ]
Prepare search data from request data. @param \Cake\Http\ServerRequest $request Request object @return mixed[]
[ "Prepare", "search", "data", "from", "request", "data", "." ]
095a0e822781ac11eade0c03c7729b693daa1ba8
https://github.com/QoboLtd/cakephp-search/blob/095a0e822781ac11eade0c03c7729b693daa1ba8/src/Utility/Search.php#L208-L232
28,440
QoboLtd/cakephp-search
src/Utility/Search.php
Search.byAssociations
protected function byAssociations(array $data): array { $result = []; foreach ($this->getAssociationsBySearchData($data) as $association) { // skip non-supported associations if (!in_array($association->type(), Options::getSearchableAssociations())) { continue; } $targetTable = $association->getTarget(); // skip associations with itself if ($targetTable->getTable() === $this->table->getTable()) { continue; } $primaryKeys = []; foreach ((array)$targetTable->getPrimaryKey() as $primaryKey) { $primaryKeys[] = $targetTable->aliasField($primaryKey); } // instantiate Search on related table $search = new Search($targetTable, $this->user); $select = array_diff($search->getSelectClause($data), $primaryKeys); if (!empty($select)) { $result[$association->getName()]['select'] = $select; } $where = $search->getWhereClause($data); if (!empty($where)) { $result[$association->getName()]['where'] = $where; } } return $result; }
php
protected function byAssociations(array $data): array { $result = []; foreach ($this->getAssociationsBySearchData($data) as $association) { // skip non-supported associations if (!in_array($association->type(), Options::getSearchableAssociations())) { continue; } $targetTable = $association->getTarget(); // skip associations with itself if ($targetTable->getTable() === $this->table->getTable()) { continue; } $primaryKeys = []; foreach ((array)$targetTable->getPrimaryKey() as $primaryKey) { $primaryKeys[] = $targetTable->aliasField($primaryKey); } // instantiate Search on related table $search = new Search($targetTable, $this->user); $select = array_diff($search->getSelectClause($data), $primaryKeys); if (!empty($select)) { $result[$association->getName()]['select'] = $select; } $where = $search->getWhereClause($data); if (!empty($where)) { $result[$association->getName()]['where'] = $where; } } return $result; }
[ "protected", "function", "byAssociations", "(", "array", "$", "data", ")", ":", "array", "{", "$", "result", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "getAssociationsBySearchData", "(", "$", "data", ")", "as", "$", "association", ")", "{", "// skip non-supported associations", "if", "(", "!", "in_array", "(", "$", "association", "->", "type", "(", ")", ",", "Options", "::", "getSearchableAssociations", "(", ")", ")", ")", "{", "continue", ";", "}", "$", "targetTable", "=", "$", "association", "->", "getTarget", "(", ")", ";", "// skip associations with itself", "if", "(", "$", "targetTable", "->", "getTable", "(", ")", "===", "$", "this", "->", "table", "->", "getTable", "(", ")", ")", "{", "continue", ";", "}", "$", "primaryKeys", "=", "[", "]", ";", "foreach", "(", "(", "array", ")", "$", "targetTable", "->", "getPrimaryKey", "(", ")", "as", "$", "primaryKey", ")", "{", "$", "primaryKeys", "[", "]", "=", "$", "targetTable", "->", "aliasField", "(", "$", "primaryKey", ")", ";", "}", "// instantiate Search on related table", "$", "search", "=", "new", "Search", "(", "$", "targetTable", ",", "$", "this", "->", "user", ")", ";", "$", "select", "=", "array_diff", "(", "$", "search", "->", "getSelectClause", "(", "$", "data", ")", ",", "$", "primaryKeys", ")", ";", "if", "(", "!", "empty", "(", "$", "select", ")", ")", "{", "$", "result", "[", "$", "association", "->", "getName", "(", ")", "]", "[", "'select'", "]", "=", "$", "select", ";", "}", "$", "where", "=", "$", "search", "->", "getWhereClause", "(", "$", "data", ")", ";", "if", "(", "!", "empty", "(", "$", "where", ")", ")", "{", "$", "result", "[", "$", "association", "->", "getName", "(", ")", "]", "[", "'where'", "]", "=", "$", "where", ";", "}", "}", "return", "$", "result", ";", "}" ]
Search by current Table associations. @param mixed[] $data Search data @return mixed[]
[ "Search", "by", "current", "Table", "associations", "." ]
095a0e822781ac11eade0c03c7729b693daa1ba8
https://github.com/QoboLtd/cakephp-search/blob/095a0e822781ac11eade0c03c7729b693daa1ba8/src/Utility/Search.php#L240-L276
28,441
QoboLtd/cakephp-search
src/Utility/Search.php
Search.getAssociationsBySearchData
private function getAssociationsBySearchData(array $data) : array { $fields = []; if (array_key_exists('criteria', $data)) { foreach (array_keys($data['criteria']) as $field) { $field = $this->table->aliasField((string)$field); if (! in_array($field, $fields)) { $fields[] = $field; } } } if (array_key_exists('display_columns', $data)) { foreach ($data['display_columns'] as $field) { if (is_string($field) && ! in_array($field, $fields)) { $fields[] = $field; } } } $result = []; foreach ($fields as $field) { list($name) = explode('.', $this->table->aliasField($field), 2); if ($name === $this->table->getAlias()) { continue; } if (! $this->table->hasAssociation($name)) { throw new \RuntimeException(sprintf('Table "%s" does not have association "%s"', $this->table->getAlias(), $name)); } $association = $this->table->getAssociation($name); if (array_key_exists($association->getName(), $result)) { continue; } $result[$association->getName()] = $association; } return $result; }
php
private function getAssociationsBySearchData(array $data) : array { $fields = []; if (array_key_exists('criteria', $data)) { foreach (array_keys($data['criteria']) as $field) { $field = $this->table->aliasField((string)$field); if (! in_array($field, $fields)) { $fields[] = $field; } } } if (array_key_exists('display_columns', $data)) { foreach ($data['display_columns'] as $field) { if (is_string($field) && ! in_array($field, $fields)) { $fields[] = $field; } } } $result = []; foreach ($fields as $field) { list($name) = explode('.', $this->table->aliasField($field), 2); if ($name === $this->table->getAlias()) { continue; } if (! $this->table->hasAssociation($name)) { throw new \RuntimeException(sprintf('Table "%s" does not have association "%s"', $this->table->getAlias(), $name)); } $association = $this->table->getAssociation($name); if (array_key_exists($association->getName(), $result)) { continue; } $result[$association->getName()] = $association; } return $result; }
[ "private", "function", "getAssociationsBySearchData", "(", "array", "$", "data", ")", ":", "array", "{", "$", "fields", "=", "[", "]", ";", "if", "(", "array_key_exists", "(", "'criteria'", ",", "$", "data", ")", ")", "{", "foreach", "(", "array_keys", "(", "$", "data", "[", "'criteria'", "]", ")", "as", "$", "field", ")", "{", "$", "field", "=", "$", "this", "->", "table", "->", "aliasField", "(", "(", "string", ")", "$", "field", ")", ";", "if", "(", "!", "in_array", "(", "$", "field", ",", "$", "fields", ")", ")", "{", "$", "fields", "[", "]", "=", "$", "field", ";", "}", "}", "}", "if", "(", "array_key_exists", "(", "'display_columns'", ",", "$", "data", ")", ")", "{", "foreach", "(", "$", "data", "[", "'display_columns'", "]", "as", "$", "field", ")", "{", "if", "(", "is_string", "(", "$", "field", ")", "&&", "!", "in_array", "(", "$", "field", ",", "$", "fields", ")", ")", "{", "$", "fields", "[", "]", "=", "$", "field", ";", "}", "}", "}", "$", "result", "=", "[", "]", ";", "foreach", "(", "$", "fields", "as", "$", "field", ")", "{", "list", "(", "$", "name", ")", "=", "explode", "(", "'.'", ",", "$", "this", "->", "table", "->", "aliasField", "(", "$", "field", ")", ",", "2", ")", ";", "if", "(", "$", "name", "===", "$", "this", "->", "table", "->", "getAlias", "(", ")", ")", "{", "continue", ";", "}", "if", "(", "!", "$", "this", "->", "table", "->", "hasAssociation", "(", "$", "name", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "sprintf", "(", "'Table \"%s\" does not have association \"%s\"'", ",", "$", "this", "->", "table", "->", "getAlias", "(", ")", ",", "$", "name", ")", ")", ";", "}", "$", "association", "=", "$", "this", "->", "table", "->", "getAssociation", "(", "$", "name", ")", ";", "if", "(", "array_key_exists", "(", "$", "association", "->", "getName", "(", ")", ",", "$", "result", ")", ")", "{", "continue", ";", "}", "$", "result", "[", "$", "association", "->", "getName", "(", ")", "]", "=", "$", "association", ";", "}", "return", "$", "result", ";", "}" ]
Retrieves search-required associations based on the provided search data. @param mixed[] $data Search data @return mixed[]
[ "Retrieves", "search", "-", "required", "associations", "based", "on", "the", "provided", "search", "data", "." ]
095a0e822781ac11eade0c03c7729b693daa1ba8
https://github.com/QoboLtd/cakephp-search/blob/095a0e822781ac11eade0c03c7729b693daa1ba8/src/Utility/Search.php#L284-L326
28,442
QoboLtd/cakephp-search
src/Utility/Search.php
Search.getWhereClause
protected function getWhereClause(array $data): array { $result = []; if (empty($data['criteria'])) { return $result; } // get current module searchable fields. $moduleFields = $this->filterFields(array_keys($this->searchFields)); foreach ($data['criteria'] as $fieldName => $criterias) { if (empty($criterias)) { continue; } $fieldName = $this->table->aliasField($fieldName); if (!in_array($fieldName, $moduleFields)) { continue; } foreach ($criterias as $criteria) { $condition = $this->getWhereCondition($fieldName, $criteria); if (empty($condition)) { continue; } $result[] = $condition; } } return $result; }
php
protected function getWhereClause(array $data): array { $result = []; if (empty($data['criteria'])) { return $result; } // get current module searchable fields. $moduleFields = $this->filterFields(array_keys($this->searchFields)); foreach ($data['criteria'] as $fieldName => $criterias) { if (empty($criterias)) { continue; } $fieldName = $this->table->aliasField($fieldName); if (!in_array($fieldName, $moduleFields)) { continue; } foreach ($criterias as $criteria) { $condition = $this->getWhereCondition($fieldName, $criteria); if (empty($condition)) { continue; } $result[] = $condition; } } return $result; }
[ "protected", "function", "getWhereClause", "(", "array", "$", "data", ")", ":", "array", "{", "$", "result", "=", "[", "]", ";", "if", "(", "empty", "(", "$", "data", "[", "'criteria'", "]", ")", ")", "{", "return", "$", "result", ";", "}", "// get current module searchable fields.", "$", "moduleFields", "=", "$", "this", "->", "filterFields", "(", "array_keys", "(", "$", "this", "->", "searchFields", ")", ")", ";", "foreach", "(", "$", "data", "[", "'criteria'", "]", "as", "$", "fieldName", "=>", "$", "criterias", ")", "{", "if", "(", "empty", "(", "$", "criterias", ")", ")", "{", "continue", ";", "}", "$", "fieldName", "=", "$", "this", "->", "table", "->", "aliasField", "(", "$", "fieldName", ")", ";", "if", "(", "!", "in_array", "(", "$", "fieldName", ",", "$", "moduleFields", ")", ")", "{", "continue", ";", "}", "foreach", "(", "$", "criterias", "as", "$", "criteria", ")", "{", "$", "condition", "=", "$", "this", "->", "getWhereCondition", "(", "$", "fieldName", ",", "$", "criteria", ")", ";", "if", "(", "empty", "(", "$", "condition", ")", ")", "{", "continue", ";", "}", "$", "result", "[", "]", "=", "$", "condition", ";", "}", "}", "return", "$", "result", ";", "}" ]
Prepare search query's where statement @param mixed[] $data request data @return mixed[]
[ "Prepare", "search", "query", "s", "where", "statement" ]
095a0e822781ac11eade0c03c7729b693daa1ba8
https://github.com/QoboLtd/cakephp-search/blob/095a0e822781ac11eade0c03c7729b693daa1ba8/src/Utility/Search.php#L334-L366
28,443
QoboLtd/cakephp-search
src/Utility/Search.php
Search.filterFields
protected function filterFields(array $fields): array { if (empty($fields)) { return []; } foreach ($fields as $k => $v) { if (false !== strpos($v, $this->table->getAlias() . '.')) { continue; } unset($fields[$k]); } return $fields; }
php
protected function filterFields(array $fields): array { if (empty($fields)) { return []; } foreach ($fields as $k => $v) { if (false !== strpos($v, $this->table->getAlias() . '.')) { continue; } unset($fields[$k]); } return $fields; }
[ "protected", "function", "filterFields", "(", "array", "$", "fields", ")", ":", "array", "{", "if", "(", "empty", "(", "$", "fields", ")", ")", "{", "return", "[", "]", ";", "}", "foreach", "(", "$", "fields", "as", "$", "k", "=>", "$", "v", ")", "{", "if", "(", "false", "!==", "strpos", "(", "$", "v", ",", "$", "this", "->", "table", "->", "getAlias", "(", ")", ".", "'.'", ")", ")", "{", "continue", ";", "}", "unset", "(", "$", "fields", "[", "$", "k", "]", ")", ";", "}", "return", "$", "fields", ";", "}" ]
Filter only current module fields. @param mixed[] $fields Search fields @return mixed[]
[ "Filter", "only", "current", "module", "fields", "." ]
095a0e822781ac11eade0c03c7729b693daa1ba8
https://github.com/QoboLtd/cakephp-search/blob/095a0e822781ac11eade0c03c7729b693daa1ba8/src/Utility/Search.php#L374-L389
28,444
QoboLtd/cakephp-search
src/Utility/Search.php
Search.getWhereCondition
protected function getWhereCondition(string $field, array $criteria): array { $value = is_array($criteria['value']) ? $criteria['value'] : trim($criteria['value']); if ('' === $value) { return $this->getEmptyWhereCondition($field, $criteria); } $value = $this->handleMagicValue($value); $operator = $this->searchFields[$field]['operators'][$criteria['operator']]; if (isset($operator['pattern'])) { $pattern = $operator['pattern']; $value = str_replace('{{value}}', $value, $pattern); } $type = 'string'; if (! empty($this->searchFields[$field]['type']) && array_key_exists($this->searchFields[$field]['type'], (array)Type::getMap()) ) { $type = $this->searchFields[$field]['type']; } if (in_array($operator['operator'], ['IN', 'NOT IN'])) { $type .= '[]'; $value = (array)$value; } if ($operator['operator'] === 'NOT IN') { return [ 'OR' => [ $field . ' IS NULL', new Comparison(new IdentifierExpression($field), $value, $type, $operator['operator']) ]]; } return [ new Comparison(new IdentifierExpression($field), $value, $type, $operator['operator']) ]; }
php
protected function getWhereCondition(string $field, array $criteria): array { $value = is_array($criteria['value']) ? $criteria['value'] : trim($criteria['value']); if ('' === $value) { return $this->getEmptyWhereCondition($field, $criteria); } $value = $this->handleMagicValue($value); $operator = $this->searchFields[$field]['operators'][$criteria['operator']]; if (isset($operator['pattern'])) { $pattern = $operator['pattern']; $value = str_replace('{{value}}', $value, $pattern); } $type = 'string'; if (! empty($this->searchFields[$field]['type']) && array_key_exists($this->searchFields[$field]['type'], (array)Type::getMap()) ) { $type = $this->searchFields[$field]['type']; } if (in_array($operator['operator'], ['IN', 'NOT IN'])) { $type .= '[]'; $value = (array)$value; } if ($operator['operator'] === 'NOT IN') { return [ 'OR' => [ $field . ' IS NULL', new Comparison(new IdentifierExpression($field), $value, $type, $operator['operator']) ]]; } return [ new Comparison(new IdentifierExpression($field), $value, $type, $operator['operator']) ]; }
[ "protected", "function", "getWhereCondition", "(", "string", "$", "field", ",", "array", "$", "criteria", ")", ":", "array", "{", "$", "value", "=", "is_array", "(", "$", "criteria", "[", "'value'", "]", ")", "?", "$", "criteria", "[", "'value'", "]", ":", "trim", "(", "$", "criteria", "[", "'value'", "]", ")", ";", "if", "(", "''", "===", "$", "value", ")", "{", "return", "$", "this", "->", "getEmptyWhereCondition", "(", "$", "field", ",", "$", "criteria", ")", ";", "}", "$", "value", "=", "$", "this", "->", "handleMagicValue", "(", "$", "value", ")", ";", "$", "operator", "=", "$", "this", "->", "searchFields", "[", "$", "field", "]", "[", "'operators'", "]", "[", "$", "criteria", "[", "'operator'", "]", "]", ";", "if", "(", "isset", "(", "$", "operator", "[", "'pattern'", "]", ")", ")", "{", "$", "pattern", "=", "$", "operator", "[", "'pattern'", "]", ";", "$", "value", "=", "str_replace", "(", "'{{value}}'", ",", "$", "value", ",", "$", "pattern", ")", ";", "}", "$", "type", "=", "'string'", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "searchFields", "[", "$", "field", "]", "[", "'type'", "]", ")", "&&", "array_key_exists", "(", "$", "this", "->", "searchFields", "[", "$", "field", "]", "[", "'type'", "]", ",", "(", "array", ")", "Type", "::", "getMap", "(", ")", ")", ")", "{", "$", "type", "=", "$", "this", "->", "searchFields", "[", "$", "field", "]", "[", "'type'", "]", ";", "}", "if", "(", "in_array", "(", "$", "operator", "[", "'operator'", "]", ",", "[", "'IN'", ",", "'NOT IN'", "]", ")", ")", "{", "$", "type", ".=", "'[]'", ";", "$", "value", "=", "(", "array", ")", "$", "value", ";", "}", "if", "(", "$", "operator", "[", "'operator'", "]", "===", "'NOT IN'", ")", "{", "return", "[", "'OR'", "=>", "[", "$", "field", ".", "' IS NULL'", ",", "new", "Comparison", "(", "new", "IdentifierExpression", "(", "$", "field", ")", ",", "$", "value", ",", "$", "type", ",", "$", "operator", "[", "'operator'", "]", ")", "]", "]", ";", "}", "return", "[", "new", "Comparison", "(", "new", "IdentifierExpression", "(", "$", "field", ")", ",", "$", "value", ",", "$", "type", ",", "$", "operator", "[", "'operator'", "]", ")", "]", ";", "}" ]
Prepare and return where statement condition. @param string $field Field name @param mixed[] $criteria Criteria properties @return mixed[]
[ "Prepare", "and", "return", "where", "statement", "condition", "." ]
095a0e822781ac11eade0c03c7729b693daa1ba8
https://github.com/QoboLtd/cakephp-search/blob/095a0e822781ac11eade0c03c7729b693daa1ba8/src/Utility/Search.php#L398-L431
28,445
QoboLtd/cakephp-search
src/Utility/Search.php
Search.handleMagicValue
protected function handleMagicValue($value) { switch (gettype($value)) { case 'string': $value = (new MagicValue($value, $this->user))->get(); break; case 'array': foreach ($value as $key => $val) { $value[$key] = (new MagicValue($val, $this->user))->get(); } break; } return $value; }
php
protected function handleMagicValue($value) { switch (gettype($value)) { case 'string': $value = (new MagicValue($value, $this->user))->get(); break; case 'array': foreach ($value as $key => $val) { $value[$key] = (new MagicValue($val, $this->user))->get(); } break; } return $value; }
[ "protected", "function", "handleMagicValue", "(", "$", "value", ")", "{", "switch", "(", "gettype", "(", "$", "value", ")", ")", "{", "case", "'string'", ":", "$", "value", "=", "(", "new", "MagicValue", "(", "$", "value", ",", "$", "this", "->", "user", ")", ")", "->", "get", "(", ")", ";", "break", ";", "case", "'array'", ":", "foreach", "(", "$", "value", "as", "$", "key", "=>", "$", "val", ")", "{", "$", "value", "[", "$", "key", "]", "=", "(", "new", "MagicValue", "(", "$", "val", ",", "$", "this", "->", "user", ")", ")", "->", "get", "(", ")", ";", "}", "break", ";", "}", "return", "$", "value", ";", "}" ]
Magic value handler. @param mixed $value Field value @return mixed
[ "Magic", "value", "handler", "." ]
095a0e822781ac11eade0c03c7729b693daa1ba8
https://github.com/QoboLtd/cakephp-search/blob/095a0e822781ac11eade0c03c7729b693daa1ba8/src/Utility/Search.php#L439-L454
28,446
QoboLtd/cakephp-search
src/Utility/Search.php
Search.getEmptyWhereCondition
protected function getEmptyWhereCondition(string $field, array $criteria): array { $emptyCriteria = $this->searchFields[$field]['operators'][$criteria['operator']]['emptyCriteria']; $result = []; foreach ($emptyCriteria['values'] as $value) { $result[$emptyCriteria['aggregator']][] = $field . ' ' . trim($value); } return $result; }
php
protected function getEmptyWhereCondition(string $field, array $criteria): array { $emptyCriteria = $this->searchFields[$field]['operators'][$criteria['operator']]['emptyCriteria']; $result = []; foreach ($emptyCriteria['values'] as $value) { $result[$emptyCriteria['aggregator']][] = $field . ' ' . trim($value); } return $result; }
[ "protected", "function", "getEmptyWhereCondition", "(", "string", "$", "field", ",", "array", "$", "criteria", ")", ":", "array", "{", "$", "emptyCriteria", "=", "$", "this", "->", "searchFields", "[", "$", "field", "]", "[", "'operators'", "]", "[", "$", "criteria", "[", "'operator'", "]", "]", "[", "'emptyCriteria'", "]", ";", "$", "result", "=", "[", "]", ";", "foreach", "(", "$", "emptyCriteria", "[", "'values'", "]", "as", "$", "value", ")", "{", "$", "result", "[", "$", "emptyCriteria", "[", "'aggregator'", "]", "]", "[", "]", "=", "$", "field", ".", "' '", ".", "trim", "(", "$", "value", ")", ";", "}", "return", "$", "result", ";", "}" ]
Prepare and return where statement condition for empty value. @param string $field Field name @param mixed[] $criteria Criteria properties @return mixed[]
[ "Prepare", "and", "return", "where", "statement", "condition", "for", "empty", "value", "." ]
095a0e822781ac11eade0c03c7729b693daa1ba8
https://github.com/QoboLtd/cakephp-search/blob/095a0e822781ac11eade0c03c7729b693daa1ba8/src/Utility/Search.php#L463-L473
28,447
QoboLtd/cakephp-search
src/Utility/Search.php
Search.getSelectClause
public function getSelectClause(array $data): array { if (empty($data['display_columns'])) { return []; } $result = (array)$data['display_columns']; foreach ((array)$this->table->getPrimaryKey() as $primaryKey) { $primaryKey = $this->table->aliasField($primaryKey); if (! in_array($primaryKey, $result)) { array_unshift($result, $primaryKey); } } $result = $this->filterFields($result); return $result; }
php
public function getSelectClause(array $data): array { if (empty($data['display_columns'])) { return []; } $result = (array)$data['display_columns']; foreach ((array)$this->table->getPrimaryKey() as $primaryKey) { $primaryKey = $this->table->aliasField($primaryKey); if (! in_array($primaryKey, $result)) { array_unshift($result, $primaryKey); } } $result = $this->filterFields($result); return $result; }
[ "public", "function", "getSelectClause", "(", "array", "$", "data", ")", ":", "array", "{", "if", "(", "empty", "(", "$", "data", "[", "'display_columns'", "]", ")", ")", "{", "return", "[", "]", ";", "}", "$", "result", "=", "(", "array", ")", "$", "data", "[", "'display_columns'", "]", ";", "foreach", "(", "(", "array", ")", "$", "this", "->", "table", "->", "getPrimaryKey", "(", ")", "as", "$", "primaryKey", ")", "{", "$", "primaryKey", "=", "$", "this", "->", "table", "->", "aliasField", "(", "$", "primaryKey", ")", ";", "if", "(", "!", "in_array", "(", "$", "primaryKey", ",", "$", "result", ")", ")", "{", "array_unshift", "(", "$", "result", ",", "$", "primaryKey", ")", ";", "}", "}", "$", "result", "=", "$", "this", "->", "filterFields", "(", "$", "result", ")", ";", "return", "$", "result", ";", "}" ]
Get fields for Query's select statement. @param mixed[] $data request data @return string[]
[ "Get", "fields", "for", "Query", "s", "select", "statement", "." ]
095a0e822781ac11eade0c03c7729b693daa1ba8
https://github.com/QoboLtd/cakephp-search/blob/095a0e822781ac11eade0c03c7729b693daa1ba8/src/Utility/Search.php#L481-L498
28,448
QoboLtd/cakephp-search
src/Utility/Search.php
Search.preSave
protected function preSave(array $data): string { /** * @var \Search\Model\Entity\SavedSearch */ $entity = $this->searchTable->newEntity(); $entity = $this->normalize($entity, $data, $data); $this->searchTable->save($entity); return $entity->id; }
php
protected function preSave(array $data): string { /** * @var \Search\Model\Entity\SavedSearch */ $entity = $this->searchTable->newEntity(); $entity = $this->normalize($entity, $data, $data); $this->searchTable->save($entity); return $entity->id; }
[ "protected", "function", "preSave", "(", "array", "$", "data", ")", ":", "string", "{", "/**\n * @var \\Search\\Model\\Entity\\SavedSearch\n */", "$", "entity", "=", "$", "this", "->", "searchTable", "->", "newEntity", "(", ")", ";", "$", "entity", "=", "$", "this", "->", "normalize", "(", "$", "entity", ",", "$", "data", ",", "$", "data", ")", ";", "$", "this", "->", "searchTable", "->", "save", "(", "$", "entity", ")", ";", "return", "$", "entity", "->", "id", ";", "}" ]
Method that pre-saves search and returns saved record id. @param mixed[] $data Search data @return string
[ "Method", "that", "pre", "-", "saves", "search", "and", "returns", "saved", "record", "id", "." ]
095a0e822781ac11eade0c03c7729b693daa1ba8
https://github.com/QoboLtd/cakephp-search/blob/095a0e822781ac11eade0c03c7729b693daa1ba8/src/Utility/Search.php#L517-L528
28,449
QoboLtd/cakephp-search
src/Utility/Search.php
Search.normalize
protected function normalize(SavedSearch $entity, array $saved, array $latest) : SavedSearch { // Backward compatibility: search content must always contain 'saved' and 'latest' keys. $saved = isset($saved['saved']) ? $saved['saved'] : $saved; $latest = isset($latest['latest']) ? $latest['latest'] : (isset($latest['saved']) ? $latest['saved'] : $latest); // Backward compatibility: always prefix search criteria, display columns and sort by fields with table name. $filterFunc = function ($data) { if (array_key_exists('criteria', $data)) { foreach ($data['criteria'] as $field => $option) { unset($data['criteria'][$field]); $data['criteria'][$this->table->aliasField($field)] = $option; } } if (array_key_exists('display_columns', $data)) { $data['display_columns'] = array_values($data['display_columns']); foreach ($data['display_columns'] as &$field) { $field = $this->table->aliasField($field); } } if (array_key_exists('sort_by_field', $data)) { $data['sort_by_field'] = $this->table->aliasField($data['sort_by_field']); } return $data; }; $saved = $filterFunc($saved); $latest = $filterFunc($latest); $entity->set('user_id', $this->user['id']); $entity->set('model', $this->table->getRegistryAlias()); $entity->set('content', ['saved' => $saved, 'latest' => $latest]); return $entity; }
php
protected function normalize(SavedSearch $entity, array $saved, array $latest) : SavedSearch { // Backward compatibility: search content must always contain 'saved' and 'latest' keys. $saved = isset($saved['saved']) ? $saved['saved'] : $saved; $latest = isset($latest['latest']) ? $latest['latest'] : (isset($latest['saved']) ? $latest['saved'] : $latest); // Backward compatibility: always prefix search criteria, display columns and sort by fields with table name. $filterFunc = function ($data) { if (array_key_exists('criteria', $data)) { foreach ($data['criteria'] as $field => $option) { unset($data['criteria'][$field]); $data['criteria'][$this->table->aliasField($field)] = $option; } } if (array_key_exists('display_columns', $data)) { $data['display_columns'] = array_values($data['display_columns']); foreach ($data['display_columns'] as &$field) { $field = $this->table->aliasField($field); } } if (array_key_exists('sort_by_field', $data)) { $data['sort_by_field'] = $this->table->aliasField($data['sort_by_field']); } return $data; }; $saved = $filterFunc($saved); $latest = $filterFunc($latest); $entity->set('user_id', $this->user['id']); $entity->set('model', $this->table->getRegistryAlias()); $entity->set('content', ['saved' => $saved, 'latest' => $latest]); return $entity; }
[ "protected", "function", "normalize", "(", "SavedSearch", "$", "entity", ",", "array", "$", "saved", ",", "array", "$", "latest", ")", ":", "SavedSearch", "{", "// Backward compatibility: search content must always contain 'saved' and 'latest' keys.", "$", "saved", "=", "isset", "(", "$", "saved", "[", "'saved'", "]", ")", "?", "$", "saved", "[", "'saved'", "]", ":", "$", "saved", ";", "$", "latest", "=", "isset", "(", "$", "latest", "[", "'latest'", "]", ")", "?", "$", "latest", "[", "'latest'", "]", ":", "(", "isset", "(", "$", "latest", "[", "'saved'", "]", ")", "?", "$", "latest", "[", "'saved'", "]", ":", "$", "latest", ")", ";", "// Backward compatibility: always prefix search criteria, display columns and sort by fields with table name.", "$", "filterFunc", "=", "function", "(", "$", "data", ")", "{", "if", "(", "array_key_exists", "(", "'criteria'", ",", "$", "data", ")", ")", "{", "foreach", "(", "$", "data", "[", "'criteria'", "]", "as", "$", "field", "=>", "$", "option", ")", "{", "unset", "(", "$", "data", "[", "'criteria'", "]", "[", "$", "field", "]", ")", ";", "$", "data", "[", "'criteria'", "]", "[", "$", "this", "->", "table", "->", "aliasField", "(", "$", "field", ")", "]", "=", "$", "option", ";", "}", "}", "if", "(", "array_key_exists", "(", "'display_columns'", ",", "$", "data", ")", ")", "{", "$", "data", "[", "'display_columns'", "]", "=", "array_values", "(", "$", "data", "[", "'display_columns'", "]", ")", ";", "foreach", "(", "$", "data", "[", "'display_columns'", "]", "as", "&", "$", "field", ")", "{", "$", "field", "=", "$", "this", "->", "table", "->", "aliasField", "(", "$", "field", ")", ";", "}", "}", "if", "(", "array_key_exists", "(", "'sort_by_field'", ",", "$", "data", ")", ")", "{", "$", "data", "[", "'sort_by_field'", "]", "=", "$", "this", "->", "table", "->", "aliasField", "(", "$", "data", "[", "'sort_by_field'", "]", ")", ";", "}", "return", "$", "data", ";", "}", ";", "$", "saved", "=", "$", "filterFunc", "(", "$", "saved", ")", ";", "$", "latest", "=", "$", "filterFunc", "(", "$", "latest", ")", ";", "$", "entity", "->", "set", "(", "'user_id'", ",", "$", "this", "->", "user", "[", "'id'", "]", ")", ";", "$", "entity", "->", "set", "(", "'model'", ",", "$", "this", "->", "table", "->", "getRegistryAlias", "(", ")", ")", ";", "$", "entity", "->", "set", "(", "'content'", ",", "[", "'saved'", "=>", "$", "saved", ",", "'latest'", "=>", "$", "latest", "]", ")", ";", "return", "$", "entity", ";", "}" ]
Normalize search. @param \Search\Model\Entity\SavedSearch $entity Search entity @param mixed[] $saved Saved search data @param mixed[] $latest Latest search data @return \Search\Model\Entity\SavedSearch
[ "Normalize", "search", "." ]
095a0e822781ac11eade0c03c7729b693daa1ba8
https://github.com/QoboLtd/cakephp-search/blob/095a0e822781ac11eade0c03c7729b693daa1ba8/src/Utility/Search.php#L538-L577
28,450
TYPO3-CMS/redirects
Classes/Hooks/DataHandlerCacheFlushingHook.php
DataHandlerCacheFlushingHook.rebuildRedirectCacheIfNecessary
public function rebuildRedirectCacheIfNecessary(array $parameters, DataHandler $dataHandler) { if (isset($dataHandler->datamap['sys_redirect']) || isset($dataHandler->cmdmap['sys_redirect'])) { GeneralUtility::makeInstance(RedirectCacheService::class)->rebuild(); } }
php
public function rebuildRedirectCacheIfNecessary(array $parameters, DataHandler $dataHandler) { if (isset($dataHandler->datamap['sys_redirect']) || isset($dataHandler->cmdmap['sys_redirect'])) { GeneralUtility::makeInstance(RedirectCacheService::class)->rebuild(); } }
[ "public", "function", "rebuildRedirectCacheIfNecessary", "(", "array", "$", "parameters", ",", "DataHandler", "$", "dataHandler", ")", "{", "if", "(", "isset", "(", "$", "dataHandler", "->", "datamap", "[", "'sys_redirect'", "]", ")", "||", "isset", "(", "$", "dataHandler", "->", "cmdmap", "[", "'sys_redirect'", "]", ")", ")", "{", "GeneralUtility", "::", "makeInstance", "(", "RedirectCacheService", "::", "class", ")", "->", "rebuild", "(", ")", ";", "}", "}" ]
Check if the data handler processed a sys_redirect record, if so, rebuild the redirect index cache @param array $parameters unused @param DataHandler $dataHandler the data handler object
[ "Check", "if", "the", "data", "handler", "processed", "a", "sys_redirect", "record", "if", "so", "rebuild", "the", "redirect", "index", "cache" ]
c617ec21dac92873bf9890fa0bfc1576afc86b5a
https://github.com/TYPO3-CMS/redirects/blob/c617ec21dac92873bf9890fa0bfc1576afc86b5a/Classes/Hooks/DataHandlerCacheFlushingHook.php#L34-L39
28,451
mitchdav/st-george-ipg
src/Request.php
Request.createFromClient
public static function createFromClient(Client $client, $includeTerminalType = TRUE) { $request = new Request(); $request->setInterface($client->getInterface()); if ($includeTerminalType) { $request->setTerminalType($client->getTerminalType()); } return $request; }
php
public static function createFromClient(Client $client, $includeTerminalType = TRUE) { $request = new Request(); $request->setInterface($client->getInterface()); if ($includeTerminalType) { $request->setTerminalType($client->getTerminalType()); } return $request; }
[ "public", "static", "function", "createFromClient", "(", "Client", "$", "client", ",", "$", "includeTerminalType", "=", "TRUE", ")", "{", "$", "request", "=", "new", "Request", "(", ")", ";", "$", "request", "->", "setInterface", "(", "$", "client", "->", "getInterface", "(", ")", ")", ";", "if", "(", "$", "includeTerminalType", ")", "{", "$", "request", "->", "setTerminalType", "(", "$", "client", "->", "getTerminalType", "(", ")", ")", ";", "}", "return", "$", "request", ";", "}" ]
Creates the request using information from the client. @param \StGeorgeIPG\Client $client @param boolean $includeTerminalType @return \StGeorgeIPG\Request
[ "Creates", "the", "request", "using", "information", "from", "the", "client", "." ]
2ed1a458d9bb24b3e8c554c20ba4ea75ed6548bc
https://github.com/mitchdav/st-george-ipg/blob/2ed1a458d9bb24b3e8c554c20ba4ea75ed6548bc/src/Request.php#L195-L206
28,452
mitchdav/st-george-ipg
src/Request.php
Request.validate
public function validate() { $this->validateAttributes([ Request::ATTRIBUTE_INTERFACE, Request::ATTRIBUTE_TRANSACTION_TYPE, ]); $transactionType = $this->getTransactionType(); switch ($transactionType) { case Request::TRANSACTION_TYPE_PURCHASE: case Request::TRANSACTION_TYPE_PRE_AUTH: { $this->validateAttributes([ Request::ATTRIBUTE_TOTAL_AMOUNT, Request::ATTRIBUTE_CARD_DATA, Request::ATTRIBUTE_CARD_EXPIRY_DATE, ], [ Request::ATTRIBUTE_TRANSACTION_REFERENCE, Request::ATTRIBUTE_ORIGINAL_TRANSACTION_REFERENCE, Request::ATTRIBUTE_PRE_AUTH_NUMBER, Request::ATTRIBUTE_AUTH_NUMBER, Request::ATTRIBUTE_AUTHORISATION_CODE, Request::ATTRIBUTE_AUTHORISATION_NUMBER, ]); break; } case Request::TRANSACTION_TYPE_REFUND: { $this->validateAttributes([ Request::ATTRIBUTE_TOTAL_AMOUNT, Request::ATTRIBUTE_ORIGINAL_TRANSACTION_REFERENCE, ], [ Request::ATTRIBUTE_CARD_DATA, Request::ATTRIBUTE_CARD_EXPIRY_DATE, Request::ATTRIBUTE_TRANSACTION_REFERENCE, Request::ATTRIBUTE_PRE_AUTH_NUMBER, Request::ATTRIBUTE_AUTH_NUMBER, Request::ATTRIBUTE_AUTHORISATION_CODE, Request::ATTRIBUTE_AUTHORISATION_NUMBER, ]); break; } case Request::TRANSACTION_TYPE_COMPLETION: { $this->validateAttributes([ Request::ATTRIBUTE_TOTAL_AMOUNT, [ Request::ATTRIBUTE_ORIGINAL_TRANSACTION_REFERENCE, Request::ATTRIBUTE_PRE_AUTH_NUMBER, ], [ Request::ATTRIBUTE_AUTH_CODE, Request::ATTRIBUTE_AUTH_NUMBER, Request::ATTRIBUTE_AUTHORISATION_CODE, Request::ATTRIBUTE_AUTHORISATION_NUMBER, ], ], [ Request::ATTRIBUTE_CARD_DATA, Request::ATTRIBUTE_CARD_EXPIRY_DATE, Request::ATTRIBUTE_TRANSACTION_REFERENCE, ]); break; } case Request::TRANSACTION_TYPE_STATUS: { $this->validateAttributes([ Request::ATTRIBUTE_TRANSACTION_REFERENCE, ], [ Request::ATTRIBUTE_TOTAL_AMOUNT, Request::ATTRIBUTE_TAX_AMOUNT, Request::ATTRIBUTE_CARD_DATA, Request::ATTRIBUTE_CARD_EXPIRY_DATE, Request::ATTRIBUTE_ORIGINAL_TRANSACTION_REFERENCE, Request::ATTRIBUTE_PRE_AUTH_NUMBER, Request::ATTRIBUTE_AUTH_CODE, Request::ATTRIBUTE_AUTH_NUMBER, Request::ATTRIBUTE_AUTHORISATION_CODE, Request::ATTRIBUTE_AUTHORISATION_NUMBER, Request::ATTRIBUTE_CLIENT_REFERENCE, Request::ATTRIBUTE_COMMENT, Request::ATTRIBUTE_MERCHANT_CARD_HOLDER_NAME, Request::ATTRIBUTE_MERCHANT_DESCRIPTION, Request::ATTRIBUTE_TERMINAL_TYPE, Request::ATTRIBUTE_CVC2, ]); break; } } return TRUE; }
php
public function validate() { $this->validateAttributes([ Request::ATTRIBUTE_INTERFACE, Request::ATTRIBUTE_TRANSACTION_TYPE, ]); $transactionType = $this->getTransactionType(); switch ($transactionType) { case Request::TRANSACTION_TYPE_PURCHASE: case Request::TRANSACTION_TYPE_PRE_AUTH: { $this->validateAttributes([ Request::ATTRIBUTE_TOTAL_AMOUNT, Request::ATTRIBUTE_CARD_DATA, Request::ATTRIBUTE_CARD_EXPIRY_DATE, ], [ Request::ATTRIBUTE_TRANSACTION_REFERENCE, Request::ATTRIBUTE_ORIGINAL_TRANSACTION_REFERENCE, Request::ATTRIBUTE_PRE_AUTH_NUMBER, Request::ATTRIBUTE_AUTH_NUMBER, Request::ATTRIBUTE_AUTHORISATION_CODE, Request::ATTRIBUTE_AUTHORISATION_NUMBER, ]); break; } case Request::TRANSACTION_TYPE_REFUND: { $this->validateAttributes([ Request::ATTRIBUTE_TOTAL_AMOUNT, Request::ATTRIBUTE_ORIGINAL_TRANSACTION_REFERENCE, ], [ Request::ATTRIBUTE_CARD_DATA, Request::ATTRIBUTE_CARD_EXPIRY_DATE, Request::ATTRIBUTE_TRANSACTION_REFERENCE, Request::ATTRIBUTE_PRE_AUTH_NUMBER, Request::ATTRIBUTE_AUTH_NUMBER, Request::ATTRIBUTE_AUTHORISATION_CODE, Request::ATTRIBUTE_AUTHORISATION_NUMBER, ]); break; } case Request::TRANSACTION_TYPE_COMPLETION: { $this->validateAttributes([ Request::ATTRIBUTE_TOTAL_AMOUNT, [ Request::ATTRIBUTE_ORIGINAL_TRANSACTION_REFERENCE, Request::ATTRIBUTE_PRE_AUTH_NUMBER, ], [ Request::ATTRIBUTE_AUTH_CODE, Request::ATTRIBUTE_AUTH_NUMBER, Request::ATTRIBUTE_AUTHORISATION_CODE, Request::ATTRIBUTE_AUTHORISATION_NUMBER, ], ], [ Request::ATTRIBUTE_CARD_DATA, Request::ATTRIBUTE_CARD_EXPIRY_DATE, Request::ATTRIBUTE_TRANSACTION_REFERENCE, ]); break; } case Request::TRANSACTION_TYPE_STATUS: { $this->validateAttributes([ Request::ATTRIBUTE_TRANSACTION_REFERENCE, ], [ Request::ATTRIBUTE_TOTAL_AMOUNT, Request::ATTRIBUTE_TAX_AMOUNT, Request::ATTRIBUTE_CARD_DATA, Request::ATTRIBUTE_CARD_EXPIRY_DATE, Request::ATTRIBUTE_ORIGINAL_TRANSACTION_REFERENCE, Request::ATTRIBUTE_PRE_AUTH_NUMBER, Request::ATTRIBUTE_AUTH_CODE, Request::ATTRIBUTE_AUTH_NUMBER, Request::ATTRIBUTE_AUTHORISATION_CODE, Request::ATTRIBUTE_AUTHORISATION_NUMBER, Request::ATTRIBUTE_CLIENT_REFERENCE, Request::ATTRIBUTE_COMMENT, Request::ATTRIBUTE_MERCHANT_CARD_HOLDER_NAME, Request::ATTRIBUTE_MERCHANT_DESCRIPTION, Request::ATTRIBUTE_TERMINAL_TYPE, Request::ATTRIBUTE_CVC2, ]); break; } } return TRUE; }
[ "public", "function", "validate", "(", ")", "{", "$", "this", "->", "validateAttributes", "(", "[", "Request", "::", "ATTRIBUTE_INTERFACE", ",", "Request", "::", "ATTRIBUTE_TRANSACTION_TYPE", ",", "]", ")", ";", "$", "transactionType", "=", "$", "this", "->", "getTransactionType", "(", ")", ";", "switch", "(", "$", "transactionType", ")", "{", "case", "Request", "::", "TRANSACTION_TYPE_PURCHASE", ":", "case", "Request", "::", "TRANSACTION_TYPE_PRE_AUTH", ":", "{", "$", "this", "->", "validateAttributes", "(", "[", "Request", "::", "ATTRIBUTE_TOTAL_AMOUNT", ",", "Request", "::", "ATTRIBUTE_CARD_DATA", ",", "Request", "::", "ATTRIBUTE_CARD_EXPIRY_DATE", ",", "]", ",", "[", "Request", "::", "ATTRIBUTE_TRANSACTION_REFERENCE", ",", "Request", "::", "ATTRIBUTE_ORIGINAL_TRANSACTION_REFERENCE", ",", "Request", "::", "ATTRIBUTE_PRE_AUTH_NUMBER", ",", "Request", "::", "ATTRIBUTE_AUTH_NUMBER", ",", "Request", "::", "ATTRIBUTE_AUTHORISATION_CODE", ",", "Request", "::", "ATTRIBUTE_AUTHORISATION_NUMBER", ",", "]", ")", ";", "break", ";", "}", "case", "Request", "::", "TRANSACTION_TYPE_REFUND", ":", "{", "$", "this", "->", "validateAttributes", "(", "[", "Request", "::", "ATTRIBUTE_TOTAL_AMOUNT", ",", "Request", "::", "ATTRIBUTE_ORIGINAL_TRANSACTION_REFERENCE", ",", "]", ",", "[", "Request", "::", "ATTRIBUTE_CARD_DATA", ",", "Request", "::", "ATTRIBUTE_CARD_EXPIRY_DATE", ",", "Request", "::", "ATTRIBUTE_TRANSACTION_REFERENCE", ",", "Request", "::", "ATTRIBUTE_PRE_AUTH_NUMBER", ",", "Request", "::", "ATTRIBUTE_AUTH_NUMBER", ",", "Request", "::", "ATTRIBUTE_AUTHORISATION_CODE", ",", "Request", "::", "ATTRIBUTE_AUTHORISATION_NUMBER", ",", "]", ")", ";", "break", ";", "}", "case", "Request", "::", "TRANSACTION_TYPE_COMPLETION", ":", "{", "$", "this", "->", "validateAttributes", "(", "[", "Request", "::", "ATTRIBUTE_TOTAL_AMOUNT", ",", "[", "Request", "::", "ATTRIBUTE_ORIGINAL_TRANSACTION_REFERENCE", ",", "Request", "::", "ATTRIBUTE_PRE_AUTH_NUMBER", ",", "]", ",", "[", "Request", "::", "ATTRIBUTE_AUTH_CODE", ",", "Request", "::", "ATTRIBUTE_AUTH_NUMBER", ",", "Request", "::", "ATTRIBUTE_AUTHORISATION_CODE", ",", "Request", "::", "ATTRIBUTE_AUTHORISATION_NUMBER", ",", "]", ",", "]", ",", "[", "Request", "::", "ATTRIBUTE_CARD_DATA", ",", "Request", "::", "ATTRIBUTE_CARD_EXPIRY_DATE", ",", "Request", "::", "ATTRIBUTE_TRANSACTION_REFERENCE", ",", "]", ")", ";", "break", ";", "}", "case", "Request", "::", "TRANSACTION_TYPE_STATUS", ":", "{", "$", "this", "->", "validateAttributes", "(", "[", "Request", "::", "ATTRIBUTE_TRANSACTION_REFERENCE", ",", "]", ",", "[", "Request", "::", "ATTRIBUTE_TOTAL_AMOUNT", ",", "Request", "::", "ATTRIBUTE_TAX_AMOUNT", ",", "Request", "::", "ATTRIBUTE_CARD_DATA", ",", "Request", "::", "ATTRIBUTE_CARD_EXPIRY_DATE", ",", "Request", "::", "ATTRIBUTE_ORIGINAL_TRANSACTION_REFERENCE", ",", "Request", "::", "ATTRIBUTE_PRE_AUTH_NUMBER", ",", "Request", "::", "ATTRIBUTE_AUTH_CODE", ",", "Request", "::", "ATTRIBUTE_AUTH_NUMBER", ",", "Request", "::", "ATTRIBUTE_AUTHORISATION_CODE", ",", "Request", "::", "ATTRIBUTE_AUTHORISATION_NUMBER", ",", "Request", "::", "ATTRIBUTE_CLIENT_REFERENCE", ",", "Request", "::", "ATTRIBUTE_COMMENT", ",", "Request", "::", "ATTRIBUTE_MERCHANT_CARD_HOLDER_NAME", ",", "Request", "::", "ATTRIBUTE_MERCHANT_DESCRIPTION", ",", "Request", "::", "ATTRIBUTE_TERMINAL_TYPE", ",", "Request", "::", "ATTRIBUTE_CVC2", ",", "]", ")", ";", "break", ";", "}", "}", "return", "TRUE", ";", "}" ]
Validates the request attributes based on the transaction type, and the rules specified by St.George. @return boolean @throws \StGeorgeIPG\Exceptions\InvalidAttributeValueException
[ "Validates", "the", "request", "attributes", "based", "on", "the", "transaction", "type", "and", "the", "rules", "specified", "by", "St", ".", "George", "." ]
2ed1a458d9bb24b3e8c554c20ba4ea75ed6548bc
https://github.com/mitchdav/st-george-ipg/blob/2ed1a458d9bb24b3e8c554c20ba4ea75ed6548bc/src/Request.php#L502-L596
28,453
TYPO3-CMS/redirects
Classes/Repository/RedirectRepository.php
RedirectRepository.findRedirectsByDemand
public function findRedirectsByDemand(): array { return $this->getQueryBuilderForDemand() ->setMaxResults($this->demand->getLimit()) ->setFirstResult($this->demand->getOffset()) ->execute() ->fetchAll(); }
php
public function findRedirectsByDemand(): array { return $this->getQueryBuilderForDemand() ->setMaxResults($this->demand->getLimit()) ->setFirstResult($this->demand->getOffset()) ->execute() ->fetchAll(); }
[ "public", "function", "findRedirectsByDemand", "(", ")", ":", "array", "{", "return", "$", "this", "->", "getQueryBuilderForDemand", "(", ")", "->", "setMaxResults", "(", "$", "this", "->", "demand", "->", "getLimit", "(", ")", ")", "->", "setFirstResult", "(", "$", "this", "->", "demand", "->", "getOffset", "(", ")", ")", "->", "execute", "(", ")", "->", "fetchAll", "(", ")", ";", "}" ]
Used within the backend module, which also includes the hidden records, but never deleted records. @return array
[ "Used", "within", "the", "backend", "module", "which", "also", "includes", "the", "hidden", "records", "but", "never", "deleted", "records", "." ]
c617ec21dac92873bf9890fa0bfc1576afc86b5a
https://github.com/TYPO3-CMS/redirects/blob/c617ec21dac92873bf9890fa0bfc1576afc86b5a/Classes/Repository/RedirectRepository.php#L49-L56
28,454
TYPO3-CMS/redirects
Classes/Repository/RedirectRepository.php
RedirectRepository.getQueryBuilderForDemand
protected function getQueryBuilderForDemand(): QueryBuilder { $queryBuilder = $this->getQueryBuilder(); $queryBuilder ->select('*') ->from('sys_redirect') ->orderBy('source_host') ->addOrderBy('source_path'); $constraints = []; if ($this->demand->hasSourceHost()) { $constraints[] =$queryBuilder->expr()->eq( 'source_host', $queryBuilder->createNamedParameter($this->demand->getSourceHost(), \PDO::PARAM_STR) ); } if ($this->demand->hasSourcePath()) { $escapedLikeString = '%' . $queryBuilder->escapeLikeWildcards($this->demand->getSourcePath()) . '%'; $constraints[] = $queryBuilder->expr()->like( 'source_path', $queryBuilder->createNamedParameter($escapedLikeString, \PDO::PARAM_STR) ); } if ($this->demand->hasTarget()) { $escapedLikeString = '%' . $queryBuilder->escapeLikeWildcards($this->demand->getTarget()) . '%'; $constraints[] = $queryBuilder->expr()->like( 'target', $queryBuilder->createNamedParameter($escapedLikeString, \PDO::PARAM_STR) ); } if ($this->demand->hasStatusCode()) { $constraints[] =$queryBuilder->expr()->eq( 'target_statuscode', $queryBuilder->createNamedParameter($this->demand->getStatusCode(), \PDO::PARAM_INT) ); } if (!empty($constraints)) { $queryBuilder->where(...$constraints); } return $queryBuilder; }
php
protected function getQueryBuilderForDemand(): QueryBuilder { $queryBuilder = $this->getQueryBuilder(); $queryBuilder ->select('*') ->from('sys_redirect') ->orderBy('source_host') ->addOrderBy('source_path'); $constraints = []; if ($this->demand->hasSourceHost()) { $constraints[] =$queryBuilder->expr()->eq( 'source_host', $queryBuilder->createNamedParameter($this->demand->getSourceHost(), \PDO::PARAM_STR) ); } if ($this->demand->hasSourcePath()) { $escapedLikeString = '%' . $queryBuilder->escapeLikeWildcards($this->demand->getSourcePath()) . '%'; $constraints[] = $queryBuilder->expr()->like( 'source_path', $queryBuilder->createNamedParameter($escapedLikeString, \PDO::PARAM_STR) ); } if ($this->demand->hasTarget()) { $escapedLikeString = '%' . $queryBuilder->escapeLikeWildcards($this->demand->getTarget()) . '%'; $constraints[] = $queryBuilder->expr()->like( 'target', $queryBuilder->createNamedParameter($escapedLikeString, \PDO::PARAM_STR) ); } if ($this->demand->hasStatusCode()) { $constraints[] =$queryBuilder->expr()->eq( 'target_statuscode', $queryBuilder->createNamedParameter($this->demand->getStatusCode(), \PDO::PARAM_INT) ); } if (!empty($constraints)) { $queryBuilder->where(...$constraints); } return $queryBuilder; }
[ "protected", "function", "getQueryBuilderForDemand", "(", ")", ":", "QueryBuilder", "{", "$", "queryBuilder", "=", "$", "this", "->", "getQueryBuilder", "(", ")", ";", "$", "queryBuilder", "->", "select", "(", "'*'", ")", "->", "from", "(", "'sys_redirect'", ")", "->", "orderBy", "(", "'source_host'", ")", "->", "addOrderBy", "(", "'source_path'", ")", ";", "$", "constraints", "=", "[", "]", ";", "if", "(", "$", "this", "->", "demand", "->", "hasSourceHost", "(", ")", ")", "{", "$", "constraints", "[", "]", "=", "$", "queryBuilder", "->", "expr", "(", ")", "->", "eq", "(", "'source_host'", ",", "$", "queryBuilder", "->", "createNamedParameter", "(", "$", "this", "->", "demand", "->", "getSourceHost", "(", ")", ",", "\\", "PDO", "::", "PARAM_STR", ")", ")", ";", "}", "if", "(", "$", "this", "->", "demand", "->", "hasSourcePath", "(", ")", ")", "{", "$", "escapedLikeString", "=", "'%'", ".", "$", "queryBuilder", "->", "escapeLikeWildcards", "(", "$", "this", "->", "demand", "->", "getSourcePath", "(", ")", ")", ".", "'%'", ";", "$", "constraints", "[", "]", "=", "$", "queryBuilder", "->", "expr", "(", ")", "->", "like", "(", "'source_path'", ",", "$", "queryBuilder", "->", "createNamedParameter", "(", "$", "escapedLikeString", ",", "\\", "PDO", "::", "PARAM_STR", ")", ")", ";", "}", "if", "(", "$", "this", "->", "demand", "->", "hasTarget", "(", ")", ")", "{", "$", "escapedLikeString", "=", "'%'", ".", "$", "queryBuilder", "->", "escapeLikeWildcards", "(", "$", "this", "->", "demand", "->", "getTarget", "(", ")", ")", ".", "'%'", ";", "$", "constraints", "[", "]", "=", "$", "queryBuilder", "->", "expr", "(", ")", "->", "like", "(", "'target'", ",", "$", "queryBuilder", "->", "createNamedParameter", "(", "$", "escapedLikeString", ",", "\\", "PDO", "::", "PARAM_STR", ")", ")", ";", "}", "if", "(", "$", "this", "->", "demand", "->", "hasStatusCode", "(", ")", ")", "{", "$", "constraints", "[", "]", "=", "$", "queryBuilder", "->", "expr", "(", ")", "->", "eq", "(", "'target_statuscode'", ",", "$", "queryBuilder", "->", "createNamedParameter", "(", "$", "this", "->", "demand", "->", "getStatusCode", "(", ")", ",", "\\", "PDO", "::", "PARAM_INT", ")", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "constraints", ")", ")", "{", "$", "queryBuilder", "->", "where", "(", "...", "$", "constraints", ")", ";", "}", "return", "$", "queryBuilder", ";", "}" ]
Prepares the QueryBuilder with Constraints from the Demand @return QueryBuilder
[ "Prepares", "the", "QueryBuilder", "with", "Constraints", "from", "the", "Demand" ]
c617ec21dac92873bf9890fa0bfc1576afc86b5a
https://github.com/TYPO3-CMS/redirects/blob/c617ec21dac92873bf9890fa0bfc1576afc86b5a/Classes/Repository/RedirectRepository.php#L71-L115
28,455
gocom/rah_sitemap
src/Rah/Sitemap.php
Rah_Sitemap.cleanUrlHandler
public function cleanUrlHandler(): void { global $pretext; $basename = explode('?', (string) $pretext['request_uri']); $basename = basename(array_shift($basename)); if ($basename === 'robots.txt') { $this->sendRobots(); } if ($basename === 'sitemap.xml' || $basename === 'sitemap.xml.gz') { $this->populateArticleFields()->sendSitemap(); } }
php
public function cleanUrlHandler(): void { global $pretext; $basename = explode('?', (string) $pretext['request_uri']); $basename = basename(array_shift($basename)); if ($basename === 'robots.txt') { $this->sendRobots(); } if ($basename === 'sitemap.xml' || $basename === 'sitemap.xml.gz') { $this->populateArticleFields()->sendSitemap(); } }
[ "public", "function", "cleanUrlHandler", "(", ")", ":", "void", "{", "global", "$", "pretext", ";", "$", "basename", "=", "explode", "(", "'?'", ",", "(", "string", ")", "$", "pretext", "[", "'request_uri'", "]", ")", ";", "$", "basename", "=", "basename", "(", "array_shift", "(", "$", "basename", ")", ")", ";", "if", "(", "$", "basename", "===", "'robots.txt'", ")", "{", "$", "this", "->", "sendRobots", "(", ")", ";", "}", "if", "(", "$", "basename", "===", "'sitemap.xml'", "||", "$", "basename", "===", "'sitemap.xml.gz'", ")", "{", "$", "this", "->", "populateArticleFields", "(", ")", "->", "sendSitemap", "(", ")", ";", "}", "}" ]
Handles routing clean URLs.
[ "Handles", "routing", "clean", "URLs", "." ]
a01e380b6695ad283fbdf402fb2ea1a640c607f9
https://github.com/gocom/rah_sitemap/blob/a01e380b6695ad283fbdf402fb2ea1a640c607f9/src/Rah/Sitemap.php#L122-L136
28,456
gocom/rah_sitemap
src/Rah/Sitemap.php
Rah_Sitemap.addUrl
private function addUrl($url, $lastmod = null): self { if (strpos($url, 'http://') !== 0 && strpos($url, 'https://') !== 0) { $url = hu.ltrim($url, '/'); } if (preg_match('/[\'"<>]/', $url)) { $url = htmlspecialchars($url, ENT_QUOTES); } if (isset($this->addUrlset[$url])) { return $this; } if ($lastmod !== null) { if (!is_int($lastmod)) { $lastmod = strtotime($lastmod); } if ($lastmod !== false) { $lastmod = safe_strftime('iso8601', $lastmod); } } $this->addUrlset[$url] = '<url>'. '<loc>'.$url.'</loc>'. ($lastmod ? '<lastmod>'.$lastmod.'</lastmod>' : ''). '</url>'; return $this; }
php
private function addUrl($url, $lastmod = null): self { if (strpos($url, 'http://') !== 0 && strpos($url, 'https://') !== 0) { $url = hu.ltrim($url, '/'); } if (preg_match('/[\'"<>]/', $url)) { $url = htmlspecialchars($url, ENT_QUOTES); } if (isset($this->addUrlset[$url])) { return $this; } if ($lastmod !== null) { if (!is_int($lastmod)) { $lastmod = strtotime($lastmod); } if ($lastmod !== false) { $lastmod = safe_strftime('iso8601', $lastmod); } } $this->addUrlset[$url] = '<url>'. '<loc>'.$url.'</loc>'. ($lastmod ? '<lastmod>'.$lastmod.'</lastmod>' : ''). '</url>'; return $this; }
[ "private", "function", "addUrl", "(", "$", "url", ",", "$", "lastmod", "=", "null", ")", ":", "self", "{", "if", "(", "strpos", "(", "$", "url", ",", "'http://'", ")", "!==", "0", "&&", "strpos", "(", "$", "url", ",", "'https://'", ")", "!==", "0", ")", "{", "$", "url", "=", "hu", ".", "ltrim", "(", "$", "url", ",", "'/'", ")", ";", "}", "if", "(", "preg_match", "(", "'/[\\'\"<>]/'", ",", "$", "url", ")", ")", "{", "$", "url", "=", "htmlspecialchars", "(", "$", "url", ",", "ENT_QUOTES", ")", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "addUrlset", "[", "$", "url", "]", ")", ")", "{", "return", "$", "this", ";", "}", "if", "(", "$", "lastmod", "!==", "null", ")", "{", "if", "(", "!", "is_int", "(", "$", "lastmod", ")", ")", "{", "$", "lastmod", "=", "strtotime", "(", "$", "lastmod", ")", ";", "}", "if", "(", "$", "lastmod", "!==", "false", ")", "{", "$", "lastmod", "=", "safe_strftime", "(", "'iso8601'", ",", "$", "lastmod", ")", ";", "}", "}", "$", "this", "->", "addUrlset", "[", "$", "url", "]", "=", "'<url>'", ".", "'<loc>'", ".", "$", "url", ".", "'</loc>'", ".", "(", "$", "lastmod", "?", "'<lastmod>'", ".", "$", "lastmod", ".", "'</lastmod>'", ":", "''", ")", ".", "'</url>'", ";", "return", "$", "this", ";", "}" ]
Renders a &lt;url&gt; element to the XML document. @param string $url The URL @param int|string $lastmod The modification date @return $this
[ "Renders", "a", "&lt", ";", "url&gt", ";", "element", "to", "the", "XML", "document", "." ]
a01e380b6695ad283fbdf402fb2ea1a640c607f9
https://github.com/gocom/rah_sitemap/blob/a01e380b6695ad283fbdf402fb2ea1a640c607f9/src/Rah/Sitemap.php#L268-L299
28,457
gocom/rah_sitemap
src/Rah/Sitemap.php
Rah_Sitemap.populateArticleFields
private function populateArticleFields(): self { $columns = (array) @getThings('describe '.safe_pfx('textpattern')); foreach ($columns as $name) { $this->articleFields[strtolower($name)] = $name; } foreach (getCustomFields() as $id => $name) { $this->articleFields[$name] = 'custom_'.intval($id); } return $this; }
php
private function populateArticleFields(): self { $columns = (array) @getThings('describe '.safe_pfx('textpattern')); foreach ($columns as $name) { $this->articleFields[strtolower($name)] = $name; } foreach (getCustomFields() as $id => $name) { $this->articleFields[$name] = 'custom_'.intval($id); } return $this; }
[ "private", "function", "populateArticleFields", "(", ")", ":", "self", "{", "$", "columns", "=", "(", "array", ")", "@", "getThings", "(", "'describe '", ".", "safe_pfx", "(", "'textpattern'", ")", ")", ";", "foreach", "(", "$", "columns", "as", "$", "name", ")", "{", "$", "this", "->", "articleFields", "[", "strtolower", "(", "$", "name", ")", "]", "=", "$", "name", ";", "}", "foreach", "(", "getCustomFields", "(", ")", "as", "$", "id", "=>", "$", "name", ")", "{", "$", "this", "->", "articleFields", "[", "$", "name", "]", "=", "'custom_'", ".", "intval", "(", "$", "id", ")", ";", "}", "return", "$", "this", ";", "}" ]
Picks up names of article fields. @return $this
[ "Picks", "up", "names", "of", "article", "fields", "." ]
a01e380b6695ad283fbdf402fb2ea1a640c607f9
https://github.com/gocom/rah_sitemap/blob/a01e380b6695ad283fbdf402fb2ea1a640c607f9/src/Rah/Sitemap.php#L306-L319
28,458
gocom/rah_sitemap
src/Rah/Sitemap.php
Rah_Sitemap.prefs
public function prefs(): void { pagetop(gTxt('rah_sitemap')); echo graf( href(gTxt('rah_sitemap_view_prefs'), ['event' => 'prefs']) . br . href(gTxt('rah_sitemap_view_sitemap'), hu . '?rah_sitemap=sitemap') ); }
php
public function prefs(): void { pagetop(gTxt('rah_sitemap')); echo graf( href(gTxt('rah_sitemap_view_prefs'), ['event' => 'prefs']) . br . href(gTxt('rah_sitemap_view_sitemap'), hu . '?rah_sitemap=sitemap') ); }
[ "public", "function", "prefs", "(", ")", ":", "void", "{", "pagetop", "(", "gTxt", "(", "'rah_sitemap'", ")", ")", ";", "echo", "graf", "(", "href", "(", "gTxt", "(", "'rah_sitemap_view_prefs'", ")", ",", "[", "'event'", "=>", "'prefs'", "]", ")", ".", "br", ".", "href", "(", "gTxt", "(", "'rah_sitemap_view_sitemap'", ")", ",", "hu", ".", "'?rah_sitemap=sitemap'", ")", ")", ";", "}" ]
Options panel.
[ "Options", "panel", "." ]
a01e380b6695ad283fbdf402fb2ea1a640c607f9
https://github.com/gocom/rah_sitemap/blob/a01e380b6695ad283fbdf402fb2ea1a640c607f9/src/Rah/Sitemap.php#L324-L332
28,459
gocom/rah_sitemap
src/Rah/Sitemap.php
Rah_Sitemap.renderSectionOptions
public function renderSectionOptions($event, $step, $void, $r): string { if ($r['name'] !== 'default') { return inputLabel( 'rah_sitemap_include_in', yesnoradio('rah_sitemap_include_in', !empty($r['rah_sitemap_include_in']), '', ''), '', 'rah_sitemap_include_in' ); } }
php
public function renderSectionOptions($event, $step, $void, $r): string { if ($r['name'] !== 'default') { return inputLabel( 'rah_sitemap_include_in', yesnoradio('rah_sitemap_include_in', !empty($r['rah_sitemap_include_in']), '', ''), '', 'rah_sitemap_include_in' ); } }
[ "public", "function", "renderSectionOptions", "(", "$", "event", ",", "$", "step", ",", "$", "void", ",", "$", "r", ")", ":", "string", "{", "if", "(", "$", "r", "[", "'name'", "]", "!==", "'default'", ")", "{", "return", "inputLabel", "(", "'rah_sitemap_include_in'", ",", "yesnoradio", "(", "'rah_sitemap_include_in'", ",", "!", "empty", "(", "$", "r", "[", "'rah_sitemap_include_in'", "]", ")", ",", "''", ",", "''", ")", ",", "''", ",", "'rah_sitemap_include_in'", ")", ";", "}", "}" ]
Shows settings at the Sections panel. @param string $event The event @param string $step The step @param bool $void Not used @param array $r The section data as an array @return string HTML
[ "Shows", "settings", "at", "the", "Sections", "panel", "." ]
a01e380b6695ad283fbdf402fb2ea1a640c607f9
https://github.com/gocom/rah_sitemap/blob/a01e380b6695ad283fbdf402fb2ea1a640c607f9/src/Rah/Sitemap.php#L343-L353
28,460
QoboLtd/cakephp-search
src/Controller/SearchTrait.php
SearchTrait.getAjaxViewVars
protected function getAjaxViewVars(array $searchData, RepositoryInterface $table, Search $search): array { /** @var \Cake\ORM\Table */ $table = $table; $searchData['sort_by_field'] = Hash::get($this->request->getQueryParams(), 'sort', ''); $searchData['sort_by_order'] = Hash::get( $this->request->getQueryParams(), 'direction', SearchOptions::DEFAULT_SORT_BY_ORDER ); /** @var \Cake\ORM\Query */ $query = $search->execute($searchData); $resultSet = $this->paginate($query); $event = new Event( (string)SearchEventName::MODEL_SEARCH_AFTER_FIND(), $this, ['entities' => $resultSet, 'table' => $table] ); $this->getEventManager()->dispatch($event); $resultSet = $event->getResult() instanceof ResultSetInterface ? $event->getResult() : $resultSet; $primaryKeys = []; foreach ((array)$table->getPrimaryKey() as $primaryKey) { $primaryKeys[] = $table->aliasField($primaryKey); } $displayColumns = empty($searchData['group_by']) ? $searchData['display_columns'] : [$searchData['group_by'], pluginSplit($searchData['group_by'])[0] . '.' . Search::GROUP_BY_FIELD]; $displayColumns = array_merge($primaryKeys, $displayColumns); return [ 'success' => true, 'data' => Utility::instance()->formatter($resultSet, $displayColumns, $table, $this->Auth->user()), 'pagination' => ['count' => $query->count()], '_serialize' => ['success', 'data', 'pagination'] ]; }
php
protected function getAjaxViewVars(array $searchData, RepositoryInterface $table, Search $search): array { /** @var \Cake\ORM\Table */ $table = $table; $searchData['sort_by_field'] = Hash::get($this->request->getQueryParams(), 'sort', ''); $searchData['sort_by_order'] = Hash::get( $this->request->getQueryParams(), 'direction', SearchOptions::DEFAULT_SORT_BY_ORDER ); /** @var \Cake\ORM\Query */ $query = $search->execute($searchData); $resultSet = $this->paginate($query); $event = new Event( (string)SearchEventName::MODEL_SEARCH_AFTER_FIND(), $this, ['entities' => $resultSet, 'table' => $table] ); $this->getEventManager()->dispatch($event); $resultSet = $event->getResult() instanceof ResultSetInterface ? $event->getResult() : $resultSet; $primaryKeys = []; foreach ((array)$table->getPrimaryKey() as $primaryKey) { $primaryKeys[] = $table->aliasField($primaryKey); } $displayColumns = empty($searchData['group_by']) ? $searchData['display_columns'] : [$searchData['group_by'], pluginSplit($searchData['group_by'])[0] . '.' . Search::GROUP_BY_FIELD]; $displayColumns = array_merge($primaryKeys, $displayColumns); return [ 'success' => true, 'data' => Utility::instance()->formatter($resultSet, $displayColumns, $table, $this->Auth->user()), 'pagination' => ['count' => $query->count()], '_serialize' => ['success', 'data', 'pagination'] ]; }
[ "protected", "function", "getAjaxViewVars", "(", "array", "$", "searchData", ",", "RepositoryInterface", "$", "table", ",", "Search", "$", "search", ")", ":", "array", "{", "/** @var \\Cake\\ORM\\Table */", "$", "table", "=", "$", "table", ";", "$", "searchData", "[", "'sort_by_field'", "]", "=", "Hash", "::", "get", "(", "$", "this", "->", "request", "->", "getQueryParams", "(", ")", ",", "'sort'", ",", "''", ")", ";", "$", "searchData", "[", "'sort_by_order'", "]", "=", "Hash", "::", "get", "(", "$", "this", "->", "request", "->", "getQueryParams", "(", ")", ",", "'direction'", ",", "SearchOptions", "::", "DEFAULT_SORT_BY_ORDER", ")", ";", "/** @var \\Cake\\ORM\\Query */", "$", "query", "=", "$", "search", "->", "execute", "(", "$", "searchData", ")", ";", "$", "resultSet", "=", "$", "this", "->", "paginate", "(", "$", "query", ")", ";", "$", "event", "=", "new", "Event", "(", "(", "string", ")", "SearchEventName", "::", "MODEL_SEARCH_AFTER_FIND", "(", ")", ",", "$", "this", ",", "[", "'entities'", "=>", "$", "resultSet", ",", "'table'", "=>", "$", "table", "]", ")", ";", "$", "this", "->", "getEventManager", "(", ")", "->", "dispatch", "(", "$", "event", ")", ";", "$", "resultSet", "=", "$", "event", "->", "getResult", "(", ")", "instanceof", "ResultSetInterface", "?", "$", "event", "->", "getResult", "(", ")", ":", "$", "resultSet", ";", "$", "primaryKeys", "=", "[", "]", ";", "foreach", "(", "(", "array", ")", "$", "table", "->", "getPrimaryKey", "(", ")", "as", "$", "primaryKey", ")", "{", "$", "primaryKeys", "[", "]", "=", "$", "table", "->", "aliasField", "(", "$", "primaryKey", ")", ";", "}", "$", "displayColumns", "=", "empty", "(", "$", "searchData", "[", "'group_by'", "]", ")", "?", "$", "searchData", "[", "'display_columns'", "]", ":", "[", "$", "searchData", "[", "'group_by'", "]", ",", "pluginSplit", "(", "$", "searchData", "[", "'group_by'", "]", ")", "[", "0", "]", ".", "'.'", ".", "Search", "::", "GROUP_BY_FIELD", "]", ";", "$", "displayColumns", "=", "array_merge", "(", "$", "primaryKeys", ",", "$", "displayColumns", ")", ";", "return", "[", "'success'", "=>", "true", ",", "'data'", "=>", "Utility", "::", "instance", "(", ")", "->", "formatter", "(", "$", "resultSet", ",", "$", "displayColumns", ",", "$", "table", ",", "$", "this", "->", "Auth", "->", "user", "(", ")", ")", ",", "'pagination'", "=>", "[", "'count'", "=>", "$", "query", "->", "count", "(", ")", "]", ",", "'_serialize'", "=>", "[", "'success'", ",", "'data'", ",", "'pagination'", "]", "]", ";", "}" ]
Get AJAX response view variables @param mixed[] $searchData Search data @param \Cake\Datasource\RepositoryInterface $table Table instance @param \Search\Utility\Search $search Search instance @return mixed[] Variables and values for AJAX response
[ "Get", "AJAX", "response", "view", "variables" ]
095a0e822781ac11eade0c03c7729b693daa1ba8
https://github.com/QoboLtd/cakephp-search/blob/095a0e822781ac11eade0c03c7729b693daa1ba8/src/Controller/SearchTrait.php#L137-L177
28,461
QoboLtd/cakephp-search
src/Controller/SearchTrait.php
SearchTrait.exportSearch
public function exportSearch(string $id, string $filename) { $filename = '' === trim($filename) ? $this->name : $filename; $export = new Export($id, $filename, $this->Auth->user()); if ($this->request->is('ajax') && $this->request->accepts('application/json')) { $page = (int)Hash::get($this->request->getQueryParams(), 'page', 1); $limit = (int)Hash::get($this->request->getQueryParams(), 'limit', Configure::read('Search.export.limit')); $export->execute($page, $limit); $result = [ 'success' => true, 'data' => ['path' => $export->getUrl()], '_serialize' => ['success', 'data'] ]; $this->set($result); return; } $this->set('count', $export->count()); $this->set('filename', $filename); $this->render('Search.Search/export'); }
php
public function exportSearch(string $id, string $filename) { $filename = '' === trim($filename) ? $this->name : $filename; $export = new Export($id, $filename, $this->Auth->user()); if ($this->request->is('ajax') && $this->request->accepts('application/json')) { $page = (int)Hash::get($this->request->getQueryParams(), 'page', 1); $limit = (int)Hash::get($this->request->getQueryParams(), 'limit', Configure::read('Search.export.limit')); $export->execute($page, $limit); $result = [ 'success' => true, 'data' => ['path' => $export->getUrl()], '_serialize' => ['success', 'data'] ]; $this->set($result); return; } $this->set('count', $export->count()); $this->set('filename', $filename); $this->render('Search.Search/export'); }
[ "public", "function", "exportSearch", "(", "string", "$", "id", ",", "string", "$", "filename", ")", "{", "$", "filename", "=", "''", "===", "trim", "(", "$", "filename", ")", "?", "$", "this", "->", "name", ":", "$", "filename", ";", "$", "export", "=", "new", "Export", "(", "$", "id", ",", "$", "filename", ",", "$", "this", "->", "Auth", "->", "user", "(", ")", ")", ";", "if", "(", "$", "this", "->", "request", "->", "is", "(", "'ajax'", ")", "&&", "$", "this", "->", "request", "->", "accepts", "(", "'application/json'", ")", ")", "{", "$", "page", "=", "(", "int", ")", "Hash", "::", "get", "(", "$", "this", "->", "request", "->", "getQueryParams", "(", ")", ",", "'page'", ",", "1", ")", ";", "$", "limit", "=", "(", "int", ")", "Hash", "::", "get", "(", "$", "this", "->", "request", "->", "getQueryParams", "(", ")", ",", "'limit'", ",", "Configure", "::", "read", "(", "'Search.export.limit'", ")", ")", ";", "$", "export", "->", "execute", "(", "$", "page", ",", "$", "limit", ")", ";", "$", "result", "=", "[", "'success'", "=>", "true", ",", "'data'", "=>", "[", "'path'", "=>", "$", "export", "->", "getUrl", "(", ")", "]", ",", "'_serialize'", "=>", "[", "'success'", ",", "'data'", "]", "]", ";", "$", "this", "->", "set", "(", "$", "result", ")", ";", "return", ";", "}", "$", "this", "->", "set", "(", "'count'", ",", "$", "export", "->", "count", "(", ")", ")", ";", "$", "this", "->", "set", "(", "'filename'", ",", "$", "filename", ")", ";", "$", "this", "->", "render", "(", "'Search.Search/export'", ")", ";", "}" ]
Export Search results Method responsible for exporting search results into a CSV file and forcing file download. @param string $id Pre-saved search id @param string $filename Export filename @return \Cake\Http\Response|void
[ "Export", "Search", "results" ]
095a0e822781ac11eade0c03c7729b693daa1ba8
https://github.com/QoboLtd/cakephp-search/blob/095a0e822781ac11eade0c03c7729b693daa1ba8/src/Controller/SearchTrait.php#L288-L313
28,462
BabDev/Transifex-API
src/Connector/Resources.php
Resources.deleteResource
public function deleteResource(string $project, string $resource): ResponseInterface { return $this->client->sendRequest($this->createRequest('DELETE', $this->createUri("/api/2/project/$project/resource/$resource"))); }
php
public function deleteResource(string $project, string $resource): ResponseInterface { return $this->client->sendRequest($this->createRequest('DELETE', $this->createUri("/api/2/project/$project/resource/$resource"))); }
[ "public", "function", "deleteResource", "(", "string", "$", "project", ",", "string", "$", "resource", ")", ":", "ResponseInterface", "{", "return", "$", "this", "->", "client", "->", "sendRequest", "(", "$", "this", "->", "createRequest", "(", "'DELETE'", ",", "$", "this", "->", "createUri", "(", "\"/api/2/project/$project/resource/$resource\"", ")", ")", ")", ";", "}" ]
Delete a resource within a project. @param string $project The slug for the project the resource is part of @param string $resource The resource slug within the project @return ResponseInterface
[ "Delete", "a", "resource", "within", "a", "project", "." ]
9e0ccd7980127db88f7c55a36afbd2a49d9e8436
https://github.com/BabDev/Transifex-API/blob/9e0ccd7980127db88f7c55a36afbd2a49d9e8436/src/Connector/Resources.php#L84-L87
28,463
BabDev/Transifex-API
src/Connector/Resources.php
Resources.getResource
public function getResource(string $project, string $resource, bool $details = false): ResponseInterface { $uri = $this->createUri("/api/2/project/$project/resource/$resource/"); if ($details) { $uri = $uri->withQuery('details'); } return $this->client->sendRequest($this->createRequest('GET', $uri)); }
php
public function getResource(string $project, string $resource, bool $details = false): ResponseInterface { $uri = $this->createUri("/api/2/project/$project/resource/$resource/"); if ($details) { $uri = $uri->withQuery('details'); } return $this->client->sendRequest($this->createRequest('GET', $uri)); }
[ "public", "function", "getResource", "(", "string", "$", "project", ",", "string", "$", "resource", ",", "bool", "$", "details", "=", "false", ")", ":", "ResponseInterface", "{", "$", "uri", "=", "$", "this", "->", "createUri", "(", "\"/api/2/project/$project/resource/$resource/\"", ")", ";", "if", "(", "$", "details", ")", "{", "$", "uri", "=", "$", "uri", "->", "withQuery", "(", "'details'", ")", ";", "}", "return", "$", "this", "->", "client", "->", "sendRequest", "(", "$", "this", "->", "createRequest", "(", "'GET'", ",", "$", "uri", ")", ")", ";", "}" ]
Get information about a resource within a project. @param string $project The slug for the project the resource is part of @param string $resource The resource slug within the project @param bool $details True to retrieve additional project details @return ResponseInterface
[ "Get", "information", "about", "a", "resource", "within", "a", "project", "." ]
9e0ccd7980127db88f7c55a36afbd2a49d9e8436
https://github.com/BabDev/Transifex-API/blob/9e0ccd7980127db88f7c55a36afbd2a49d9e8436/src/Connector/Resources.php#L98-L107
28,464
BabDev/Transifex-API
src/Connector/Resources.php
Resources.updateResourceContent
public function updateResourceContent( string $project, string $resource, string $content, string $type = 'string' ): ResponseInterface { return $this->updateResource($this->createUri("/api/2/project/$project/resource/$resource/content/"), $content, $type); }
php
public function updateResourceContent( string $project, string $resource, string $content, string $type = 'string' ): ResponseInterface { return $this->updateResource($this->createUri("/api/2/project/$project/resource/$resource/content/"), $content, $type); }
[ "public", "function", "updateResourceContent", "(", "string", "$", "project", ",", "string", "$", "resource", ",", "string", "$", "content", ",", "string", "$", "type", "=", "'string'", ")", ":", "ResponseInterface", "{", "return", "$", "this", "->", "updateResource", "(", "$", "this", "->", "createUri", "(", "\"/api/2/project/$project/resource/$resource/content/\"", ")", ",", "$", "content", ",", "$", "type", ")", ";", "}" ]
Update the content of a resource within a project. @param string $project The slug for the project the resource is part of @param string $resource The resource slug within the project @param string $content The content of the resource, this can either be a string of data or a file path @param string $type The type of content in the $content variable, this should be either string or file @return ResponseInterface
[ "Update", "the", "content", "of", "a", "resource", "within", "a", "project", "." ]
9e0ccd7980127db88f7c55a36afbd2a49d9e8436
https://github.com/BabDev/Transifex-API/blob/9e0ccd7980127db88f7c55a36afbd2a49d9e8436/src/Connector/Resources.php#L144-L151
28,465
QoboLtd/cakephp-search
src/Utility/MagicValue.php
MagicValue.get
public function get() { $value = str_replace(static::WRAPPER, '', $this->value); if (! method_exists($this, $value)) { return $this->value; } return $this->{$value}(); }
php
public function get() { $value = str_replace(static::WRAPPER, '', $this->value); if (! method_exists($this, $value)) { return $this->value; } return $this->{$value}(); }
[ "public", "function", "get", "(", ")", "{", "$", "value", "=", "str_replace", "(", "static", "::", "WRAPPER", ",", "''", ",", "$", "this", "->", "value", ")", ";", "if", "(", "!", "method_exists", "(", "$", "this", ",", "$", "value", ")", ")", "{", "return", "$", "this", "->", "value", ";", "}", "return", "$", "this", "->", "{", "$", "value", "}", "(", ")", ";", "}" ]
Magic value getter. @return mixed
[ "Magic", "value", "getter", "." ]
095a0e822781ac11eade0c03c7729b693daa1ba8
https://github.com/QoboLtd/cakephp-search/blob/095a0e822781ac11eade0c03c7729b693daa1ba8/src/Utility/MagicValue.php#L68-L77
28,466
QoboLtd/cakephp-search
src/Model/Table/DashboardsTable.php
DashboardsTable.getUserDashboards
public function getUserDashboards(array $user): QueryInterface { // get all dashboards $query = $this->find('all')->order('name'); // return all dashboards if current user is superuser if (isset($user['is_superuser']) && $user['is_superuser']) { return $query; } $roles = []; /** @var \Groups\Model\Table\GroupsTable */ $table = $this->Roles->Groups->getTarget(); $groups = $table->getUserGroups($user['id']); // get group(s) roles if (!empty($groups)) { $roles = $this->Roles->Capabilities->getGroupsRoles($groups); } if (empty($roles)) { // get all dashboards not assigned to any role $query->where(['Dashboards.role_id IS NULL']); return $query; } // return all dashboards for Admins if (in_array(Configure::read('RolesCapabilities.Roles.Admin.name'), $roles)) { return $query; } // get role(s) dashboards $query->where(['OR' => [ ['Dashboards.role_id IN' => array_keys($roles)], ['Dashboards.role_id IS NULL'] ]]); return $query; }
php
public function getUserDashboards(array $user): QueryInterface { // get all dashboards $query = $this->find('all')->order('name'); // return all dashboards if current user is superuser if (isset($user['is_superuser']) && $user['is_superuser']) { return $query; } $roles = []; /** @var \Groups\Model\Table\GroupsTable */ $table = $this->Roles->Groups->getTarget(); $groups = $table->getUserGroups($user['id']); // get group(s) roles if (!empty($groups)) { $roles = $this->Roles->Capabilities->getGroupsRoles($groups); } if (empty($roles)) { // get all dashboards not assigned to any role $query->where(['Dashboards.role_id IS NULL']); return $query; } // return all dashboards for Admins if (in_array(Configure::read('RolesCapabilities.Roles.Admin.name'), $roles)) { return $query; } // get role(s) dashboards $query->where(['OR' => [ ['Dashboards.role_id IN' => array_keys($roles)], ['Dashboards.role_id IS NULL'] ]]); return $query; }
[ "public", "function", "getUserDashboards", "(", "array", "$", "user", ")", ":", "QueryInterface", "{", "// get all dashboards", "$", "query", "=", "$", "this", "->", "find", "(", "'all'", ")", "->", "order", "(", "'name'", ")", ";", "// return all dashboards if current user is superuser", "if", "(", "isset", "(", "$", "user", "[", "'is_superuser'", "]", ")", "&&", "$", "user", "[", "'is_superuser'", "]", ")", "{", "return", "$", "query", ";", "}", "$", "roles", "=", "[", "]", ";", "/** @var \\Groups\\Model\\Table\\GroupsTable */", "$", "table", "=", "$", "this", "->", "Roles", "->", "Groups", "->", "getTarget", "(", ")", ";", "$", "groups", "=", "$", "table", "->", "getUserGroups", "(", "$", "user", "[", "'id'", "]", ")", ";", "// get group(s) roles", "if", "(", "!", "empty", "(", "$", "groups", ")", ")", "{", "$", "roles", "=", "$", "this", "->", "Roles", "->", "Capabilities", "->", "getGroupsRoles", "(", "$", "groups", ")", ";", "}", "if", "(", "empty", "(", "$", "roles", ")", ")", "{", "// get all dashboards not assigned to any role", "$", "query", "->", "where", "(", "[", "'Dashboards.role_id IS NULL'", "]", ")", ";", "return", "$", "query", ";", "}", "// return all dashboards for Admins", "if", "(", "in_array", "(", "Configure", "::", "read", "(", "'RolesCapabilities.Roles.Admin.name'", ")", ",", "$", "roles", ")", ")", "{", "return", "$", "query", ";", "}", "// get role(s) dashboards", "$", "query", "->", "where", "(", "[", "'OR'", "=>", "[", "[", "'Dashboards.role_id IN'", "=>", "array_keys", "(", "$", "roles", ")", "]", ",", "[", "'Dashboards.role_id IS NULL'", "]", "]", "]", ")", ";", "return", "$", "query", ";", "}" ]
Get specified user accessible dashboards. @param mixed[] $user user details @return \Cake\Datasource\QueryInterface
[ "Get", "specified", "user", "accessible", "dashboards", "." ]
095a0e822781ac11eade0c03c7729b693daa1ba8
https://github.com/QoboLtd/cakephp-search/blob/095a0e822781ac11eade0c03c7729b693daa1ba8/src/Model/Table/DashboardsTable.php#L95-L133
28,467
mmoreram/ControllerExtraBundle
Resolver/LogAnnotationResolver.php
LogAnnotationResolver.logMessage
private function logMessage( LoggerInterface $logger, string $level, string $value ) { /** * Logs content, using specified level. */ $logger->$level($value); }
php
private function logMessage( LoggerInterface $logger, string $level, string $value ) { /** * Logs content, using specified level. */ $logger->$level($value); }
[ "private", "function", "logMessage", "(", "LoggerInterface", "$", "logger", ",", "string", "$", "level", ",", "string", "$", "value", ")", "{", "/**\n * Logs content, using specified level.\n */", "$", "logger", "->", "$", "level", "(", "$", "value", ")", ";", "}" ]
Send value to log. @param LoggerInterface $logger @param string $level @param string $value
[ "Send", "value", "to", "log", "." ]
b5841b6ca8f0022a2d88fdfbf743f0b76c4644e3
https://github.com/mmoreram/ControllerExtraBundle/blob/b5841b6ca8f0022a2d88fdfbf743f0b76c4644e3/Resolver/LogAnnotationResolver.php#L166-L175
28,468
aimeos/ai-client-jsonapi
client/jsonapi/src/Client/JsonApi/Order/Standard.php
Standard.createOrder
protected function createOrder( $baseId ) { $context = $this->getContext(); $cntl = \Aimeos\Controller\Frontend::create( $context, 'order' ); $item = $cntl->add( $baseId, ['order.type' => 'jsonapi'] )->store(); $context->getSession()->set( 'aimeos/orderid', $item->getId() ); return $item; }
php
protected function createOrder( $baseId ) { $context = $this->getContext(); $cntl = \Aimeos\Controller\Frontend::create( $context, 'order' ); $item = $cntl->add( $baseId, ['order.type' => 'jsonapi'] )->store(); $context->getSession()->set( 'aimeos/orderid', $item->getId() ); return $item; }
[ "protected", "function", "createOrder", "(", "$", "baseId", ")", "{", "$", "context", "=", "$", "this", "->", "getContext", "(", ")", ";", "$", "cntl", "=", "\\", "Aimeos", "\\", "Controller", "\\", "Frontend", "::", "create", "(", "$", "context", ",", "'order'", ")", ";", "$", "item", "=", "$", "cntl", "->", "add", "(", "$", "baseId", ",", "[", "'order.type'", "=>", "'jsonapi'", "]", ")", "->", "store", "(", ")", ";", "$", "context", "->", "getSession", "(", ")", "->", "set", "(", "'aimeos/orderid'", ",", "$", "item", "->", "getId", "(", ")", ")", ";", "return", "$", "item", ";", "}" ]
Adds and returns a new order item for the given order base ID @param string $baseId Unique order base ID @return \Aimeos\MShop\Order\Item\Iface New order item
[ "Adds", "and", "returns", "a", "new", "order", "item", "for", "the", "given", "order", "base", "ID" ]
b0dfb018ae0a1f7196b18322e28a1b3224aa9045
https://github.com/aimeos/ai-client-jsonapi/blob/b0dfb018ae0a1f7196b18322e28a1b3224aa9045/client/jsonapi/src/Client/JsonApi/Order/Standard.php#L175-L184
28,469
aimeos/ai-client-jsonapi
client/jsonapi/src/Client/JsonApi/Order/Standard.php
Standard.getBasket
protected function getBasket( $basketId ) { $context = $this->getContext(); $baseId = $context->getSession()->get( 'aimeos/order.baseid' ); if( $baseId != $basketId ) { $msg = sprintf( 'No basket for the "order.baseid" ("%1$s") found', $basketId ); throw new \Aimeos\Client\JsonApi\Exception( $msg, 403 ); } $parts = \Aimeos\MShop\Order\Item\Base\Base::PARTS_SERVICE; $cntl = \Aimeos\Controller\Frontend::create( $context, 'basket' ); return $cntl->load( $baseId, $parts, false ); }
php
protected function getBasket( $basketId ) { $context = $this->getContext(); $baseId = $context->getSession()->get( 'aimeos/order.baseid' ); if( $baseId != $basketId ) { $msg = sprintf( 'No basket for the "order.baseid" ("%1$s") found', $basketId ); throw new \Aimeos\Client\JsonApi\Exception( $msg, 403 ); } $parts = \Aimeos\MShop\Order\Item\Base\Base::PARTS_SERVICE; $cntl = \Aimeos\Controller\Frontend::create( $context, 'basket' ); return $cntl->load( $baseId, $parts, false ); }
[ "protected", "function", "getBasket", "(", "$", "basketId", ")", "{", "$", "context", "=", "$", "this", "->", "getContext", "(", ")", ";", "$", "baseId", "=", "$", "context", "->", "getSession", "(", ")", "->", "get", "(", "'aimeos/order.baseid'", ")", ";", "if", "(", "$", "baseId", "!=", "$", "basketId", ")", "{", "$", "msg", "=", "sprintf", "(", "'No basket for the \"order.baseid\" (\"%1$s\") found'", ",", "$", "basketId", ")", ";", "throw", "new", "\\", "Aimeos", "\\", "Client", "\\", "JsonApi", "\\", "Exception", "(", "$", "msg", ",", "403", ")", ";", "}", "$", "parts", "=", "\\", "Aimeos", "\\", "MShop", "\\", "Order", "\\", "Item", "\\", "Base", "\\", "Base", "::", "PARTS_SERVICE", ";", "$", "cntl", "=", "\\", "Aimeos", "\\", "Controller", "\\", "Frontend", "::", "create", "(", "$", "context", ",", "'basket'", ")", ";", "return", "$", "cntl", "->", "load", "(", "$", "baseId", ",", "$", "parts", ",", "false", ")", ";", "}" ]
Returns the basket object for the given ID @param string $basketId Unique order base ID @return \Aimeos\MShop\Order\Item\Base\Iface Basket object including only the services @throws \Aimeos\Client\JsonApi\Exception If basket ID is not the same as stored before in the current session
[ "Returns", "the", "basket", "object", "for", "the", "given", "ID" ]
b0dfb018ae0a1f7196b18322e28a1b3224aa9045
https://github.com/aimeos/ai-client-jsonapi/blob/b0dfb018ae0a1f7196b18322e28a1b3224aa9045/client/jsonapi/src/Client/JsonApi/Order/Standard.php#L194-L209
28,470
aimeos/ai-client-jsonapi
client/jsonapi/src/Client/JsonApi/Order/Standard.php
Standard.render
protected function render( ResponseInterface $response, \Aimeos\MW\View\Iface $view, $status ) { /** client/jsonapi/order/standard/template * Relative path to the order JSON API template * * The template file contains the code and processing instructions * to generate the result shown in the JSON API body. The * configuration string is the path to the template file relative * to the templates directory (usually in client/jsonapi/templates). * * You can overwrite the template file configuration in extensions and * provide alternative templates. These alternative templates should be * named like the default one but with the string "standard" replaced by * an unique name. You may use the name of your project for this. If * you've implemented an alternative client class as well, "standard" * should be replaced by the name of the new class. * * @param string Relative path to the template creating the body of the JSON API * @since 2017.03 * @category Developer */ $tplconf = 'client/jsonapi/order/standard/template'; $default = 'order/standard'; $body = $view->render( $view->config( $tplconf, $default ) ); return $response->withHeader( 'Allow', 'GET,OPTIONS,POST' ) ->withHeader( 'Cache-Control', 'no-cache, private' ) ->withHeader( 'Content-Type', 'application/vnd.api+json' ) ->withBody( $view->response()->createStreamFromString( $body ) ) ->withStatus( $status ); }
php
protected function render( ResponseInterface $response, \Aimeos\MW\View\Iface $view, $status ) { /** client/jsonapi/order/standard/template * Relative path to the order JSON API template * * The template file contains the code and processing instructions * to generate the result shown in the JSON API body. The * configuration string is the path to the template file relative * to the templates directory (usually in client/jsonapi/templates). * * You can overwrite the template file configuration in extensions and * provide alternative templates. These alternative templates should be * named like the default one but with the string "standard" replaced by * an unique name. You may use the name of your project for this. If * you've implemented an alternative client class as well, "standard" * should be replaced by the name of the new class. * * @param string Relative path to the template creating the body of the JSON API * @since 2017.03 * @category Developer */ $tplconf = 'client/jsonapi/order/standard/template'; $default = 'order/standard'; $body = $view->render( $view->config( $tplconf, $default ) ); return $response->withHeader( 'Allow', 'GET,OPTIONS,POST' ) ->withHeader( 'Cache-Control', 'no-cache, private' ) ->withHeader( 'Content-Type', 'application/vnd.api+json' ) ->withBody( $view->response()->createStreamFromString( $body ) ) ->withStatus( $status ); }
[ "protected", "function", "render", "(", "ResponseInterface", "$", "response", ",", "\\", "Aimeos", "\\", "MW", "\\", "View", "\\", "Iface", "$", "view", ",", "$", "status", ")", "{", "/** client/jsonapi/order/standard/template\n\t\t * Relative path to the order JSON API template\n\t\t *\n\t\t * The template file contains the code and processing instructions\n\t\t * to generate the result shown in the JSON API body. The\n\t\t * configuration string is the path to the template file relative\n\t\t * to the templates directory (usually in client/jsonapi/templates).\n\t\t *\n\t\t * You can overwrite the template file configuration in extensions and\n\t\t * provide alternative templates. These alternative templates should be\n\t\t * named like the default one but with the string \"standard\" replaced by\n\t\t * an unique name. You may use the name of your project for this. If\n\t\t * you've implemented an alternative client class as well, \"standard\"\n\t\t * should be replaced by the name of the new class.\n\t\t *\n\t\t * @param string Relative path to the template creating the body of the JSON API\n\t\t * @since 2017.03\n\t\t * @category Developer\n\t\t */", "$", "tplconf", "=", "'client/jsonapi/order/standard/template'", ";", "$", "default", "=", "'order/standard'", ";", "$", "body", "=", "$", "view", "->", "render", "(", "$", "view", "->", "config", "(", "$", "tplconf", ",", "$", "default", ")", ")", ";", "return", "$", "response", "->", "withHeader", "(", "'Allow'", ",", "'GET,OPTIONS,POST'", ")", "->", "withHeader", "(", "'Cache-Control'", ",", "'no-cache, private'", ")", "->", "withHeader", "(", "'Content-Type'", ",", "'application/vnd.api+json'", ")", "->", "withBody", "(", "$", "view", "->", "response", "(", ")", "->", "createStreamFromString", "(", "$", "body", ")", ")", "->", "withStatus", "(", "$", "status", ")", ";", "}" ]
Returns the response object with the rendered header and body @param \Psr\Http\Message\ResponseInterface $response Response object @param \Aimeos\MW\View\Iface $view View instance @param integer $status HTTP status code @return \Psr\Http\Message\ResponseInterface Modified response object
[ "Returns", "the", "response", "object", "with", "the", "rendered", "header", "and", "body" ]
b0dfb018ae0a1f7196b18322e28a1b3224aa9045
https://github.com/aimeos/ai-client-jsonapi/blob/b0dfb018ae0a1f7196b18322e28a1b3224aa9045/client/jsonapi/src/Client/JsonApi/Order/Standard.php#L322-L353
28,471
QoboLtd/cakephp-search
src/Event/Model/WidgetsListener.php
WidgetsListener.getWidgets
public function getWidgets(Event $event): void { $result = array_merge( (array)$event->result, $this->getSavedSearchWidgets(), $this->getReportWidgets(), $this->getAppWidgets() ); $event->result = array_filter($result); }
php
public function getWidgets(Event $event): void { $result = array_merge( (array)$event->result, $this->getSavedSearchWidgets(), $this->getReportWidgets(), $this->getAppWidgets() ); $event->result = array_filter($result); }
[ "public", "function", "getWidgets", "(", "Event", "$", "event", ")", ":", "void", "{", "$", "result", "=", "array_merge", "(", "(", "array", ")", "$", "event", "->", "result", ",", "$", "this", "->", "getSavedSearchWidgets", "(", ")", ",", "$", "this", "->", "getReportWidgets", "(", ")", ",", "$", "this", "->", "getAppWidgets", "(", ")", ")", ";", "$", "event", "->", "result", "=", "array_filter", "(", "$", "result", ")", ";", "}" ]
Add widgets for Search plugin's Dashboards. @param \Cake\Event\Event $event Event instance @return void
[ "Add", "widgets", "for", "Search", "plugin", "s", "Dashboards", "." ]
095a0e822781ac11eade0c03c7729b693daa1ba8
https://github.com/QoboLtd/cakephp-search/blob/095a0e822781ac11eade0c03c7729b693daa1ba8/src/Event/Model/WidgetsListener.php#L41-L51
28,472
QoboLtd/cakephp-search
src/Event/Model/WidgetsListener.php
WidgetsListener.getSavedSearchWidgets
private function getSavedSearchWidgets(): array { $table = TableRegistry::get('Search.SavedSearches'); $query = $table->find('all') ->where([ 'SavedSearches.name IS NOT' => null, 'SavedSearches.name !=' => '', 'SavedSearches.system' => false ]) ->enableHydration(false) ->indexBy('id'); if ($query->isEmpty()) { return []; } return [ ['type' => 'saved_search', 'data' => $query->toArray()] ]; }
php
private function getSavedSearchWidgets(): array { $table = TableRegistry::get('Search.SavedSearches'); $query = $table->find('all') ->where([ 'SavedSearches.name IS NOT' => null, 'SavedSearches.name !=' => '', 'SavedSearches.system' => false ]) ->enableHydration(false) ->indexBy('id'); if ($query->isEmpty()) { return []; } return [ ['type' => 'saved_search', 'data' => $query->toArray()] ]; }
[ "private", "function", "getSavedSearchWidgets", "(", ")", ":", "array", "{", "$", "table", "=", "TableRegistry", "::", "get", "(", "'Search.SavedSearches'", ")", ";", "$", "query", "=", "$", "table", "->", "find", "(", "'all'", ")", "->", "where", "(", "[", "'SavedSearches.name IS NOT'", "=>", "null", ",", "'SavedSearches.name !='", "=>", "''", ",", "'SavedSearches.system'", "=>", "false", "]", ")", "->", "enableHydration", "(", "false", ")", "->", "indexBy", "(", "'id'", ")", ";", "if", "(", "$", "query", "->", "isEmpty", "(", ")", ")", "{", "return", "[", "]", ";", "}", "return", "[", "[", "'type'", "=>", "'saved_search'", ",", "'data'", "=>", "$", "query", "->", "toArray", "(", ")", "]", "]", ";", "}" ]
Fetch all saved searches from the database. @return mixed[]
[ "Fetch", "all", "saved", "searches", "from", "the", "database", "." ]
095a0e822781ac11eade0c03c7729b693daa1ba8
https://github.com/QoboLtd/cakephp-search/blob/095a0e822781ac11eade0c03c7729b693daa1ba8/src/Event/Model/WidgetsListener.php#L58-L78
28,473
QoboLtd/cakephp-search
src/Event/Model/WidgetsListener.php
WidgetsListener.getReportWidgets
private function getReportWidgets(): array { $event = new Event((string)EventName::MODEL_DASHBOARDS_GET_REPORTS(), $this); EventManager::instance()->dispatch($event); if (empty($event->result)) { return []; } $result = []; foreach ($event->result as $reports) { foreach ($reports as $report) { if (! isset($result[$report['widget_type']])) { $result[$report['widget_type']] = ['type' => $report['widget_type'], 'data' => []]; } $result[$report['widget_type']]['data'][$report['id']] = $report; } } return array_values($result); }
php
private function getReportWidgets(): array { $event = new Event((string)EventName::MODEL_DASHBOARDS_GET_REPORTS(), $this); EventManager::instance()->dispatch($event); if (empty($event->result)) { return []; } $result = []; foreach ($event->result as $reports) { foreach ($reports as $report) { if (! isset($result[$report['widget_type']])) { $result[$report['widget_type']] = ['type' => $report['widget_type'], 'data' => []]; } $result[$report['widget_type']]['data'][$report['id']] = $report; } } return array_values($result); }
[ "private", "function", "getReportWidgets", "(", ")", ":", "array", "{", "$", "event", "=", "new", "Event", "(", "(", "string", ")", "EventName", "::", "MODEL_DASHBOARDS_GET_REPORTS", "(", ")", ",", "$", "this", ")", ";", "EventManager", "::", "instance", "(", ")", "->", "dispatch", "(", "$", "event", ")", ";", "if", "(", "empty", "(", "$", "event", "->", "result", ")", ")", "{", "return", "[", "]", ";", "}", "$", "result", "=", "[", "]", ";", "foreach", "(", "$", "event", "->", "result", "as", "$", "reports", ")", "{", "foreach", "(", "$", "reports", "as", "$", "report", ")", "{", "if", "(", "!", "isset", "(", "$", "result", "[", "$", "report", "[", "'widget_type'", "]", "]", ")", ")", "{", "$", "result", "[", "$", "report", "[", "'widget_type'", "]", "]", "=", "[", "'type'", "=>", "$", "report", "[", "'widget_type'", "]", ",", "'data'", "=>", "[", "]", "]", ";", "}", "$", "result", "[", "$", "report", "[", "'widget_type'", "]", "]", "[", "'data'", "]", "[", "$", "report", "[", "'id'", "]", "]", "=", "$", "report", ";", "}", "}", "return", "array_values", "(", "$", "result", ")", ";", "}" ]
Fetch all reports through Event broadcast. @return mixed[]
[ "Fetch", "all", "reports", "through", "Event", "broadcast", "." ]
095a0e822781ac11eade0c03c7729b693daa1ba8
https://github.com/QoboLtd/cakephp-search/blob/095a0e822781ac11eade0c03c7729b693daa1ba8/src/Event/Model/WidgetsListener.php#L85-L105
28,474
QoboLtd/cakephp-search
src/Event/Model/WidgetsListener.php
WidgetsListener.getAppWidgets
private function getAppWidgets(): array { $table = TableRegistry::get('Search.AppWidgets'); $query = $table->find('all') ->select(['id', 'name', 'content']); if ($query->isEmpty()) { return []; } $data = []; // normalize app widget data foreach ($query->all() as $entity) { $data[] = [ 'id' => $entity->get('id'), 'model' => $entity->get('content')['model'], 'name' => $entity->get('name'), 'path' => $entity->get('content')['path'] ]; } return [ ['type' => 'app', 'data' => $data] ]; }
php
private function getAppWidgets(): array { $table = TableRegistry::get('Search.AppWidgets'); $query = $table->find('all') ->select(['id', 'name', 'content']); if ($query->isEmpty()) { return []; } $data = []; // normalize app widget data foreach ($query->all() as $entity) { $data[] = [ 'id' => $entity->get('id'), 'model' => $entity->get('content')['model'], 'name' => $entity->get('name'), 'path' => $entity->get('content')['path'] ]; } return [ ['type' => 'app', 'data' => $data] ]; }
[ "private", "function", "getAppWidgets", "(", ")", ":", "array", "{", "$", "table", "=", "TableRegistry", "::", "get", "(", "'Search.AppWidgets'", ")", ";", "$", "query", "=", "$", "table", "->", "find", "(", "'all'", ")", "->", "select", "(", "[", "'id'", ",", "'name'", ",", "'content'", "]", ")", ";", "if", "(", "$", "query", "->", "isEmpty", "(", ")", ")", "{", "return", "[", "]", ";", "}", "$", "data", "=", "[", "]", ";", "// normalize app widget data", "foreach", "(", "$", "query", "->", "all", "(", ")", "as", "$", "entity", ")", "{", "$", "data", "[", "]", "=", "[", "'id'", "=>", "$", "entity", "->", "get", "(", "'id'", ")", ",", "'model'", "=>", "$", "entity", "->", "get", "(", "'content'", ")", "[", "'model'", "]", ",", "'name'", "=>", "$", "entity", "->", "get", "(", "'name'", ")", ",", "'path'", "=>", "$", "entity", "->", "get", "(", "'content'", ")", "[", "'path'", "]", "]", ";", "}", "return", "[", "[", "'type'", "=>", "'app'", ",", "'data'", "=>", "$", "data", "]", "]", ";", "}" ]
Returns list of widgets defined in the application scope. @return mixed[]
[ "Returns", "list", "of", "widgets", "defined", "in", "the", "application", "scope", "." ]
095a0e822781ac11eade0c03c7729b693daa1ba8
https://github.com/QoboLtd/cakephp-search/blob/095a0e822781ac11eade0c03c7729b693daa1ba8/src/Event/Model/WidgetsListener.php#L112-L137
28,475
aimeos/ai-client-jsonapi
client/jsonapi/src/Client/JsonApi.php
JsonApi.create
public static function create( \Aimeos\MShop\Context\Item\Iface $context, $path, $name = null ) { $path = trim( $path, '/' ); if( empty( $path ) ) { return self::createRoot( $context, $path, $name ); } $parts = explode( '/', $path ); foreach( $parts as $key => $part ) { if( ctype_alnum( $part ) === false ) { $msg = sprintf( 'Invalid client "%1$s"', $path ); throw new \Aimeos\Client\JsonApi\Exception( $msg, 400 ); } $parts[$key] = ucfirst( $part ); } $factory = '\\Aimeos\\Client\\JsonApi\\' . join( '\\', $parts ) . '\\Factory'; if( class_exists( $factory ) === true ) { if( ( $client = @call_user_func_array( [$factory, 'create'], [$context, $path, $name] ) ) === false ) { throw new \Aimeos\Client\JsonApi\Exception( sprintf( 'Invalid factory "%1$s"', $factory ), 400 ); } } else { $client = self::createRoot( $context, $path, $name ); } return $client; }
php
public static function create( \Aimeos\MShop\Context\Item\Iface $context, $path, $name = null ) { $path = trim( $path, '/' ); if( empty( $path ) ) { return self::createRoot( $context, $path, $name ); } $parts = explode( '/', $path ); foreach( $parts as $key => $part ) { if( ctype_alnum( $part ) === false ) { $msg = sprintf( 'Invalid client "%1$s"', $path ); throw new \Aimeos\Client\JsonApi\Exception( $msg, 400 ); } $parts[$key] = ucfirst( $part ); } $factory = '\\Aimeos\\Client\\JsonApi\\' . join( '\\', $parts ) . '\\Factory'; if( class_exists( $factory ) === true ) { if( ( $client = @call_user_func_array( [$factory, 'create'], [$context, $path, $name] ) ) === false ) { throw new \Aimeos\Client\JsonApi\Exception( sprintf( 'Invalid factory "%1$s"', $factory ), 400 ); } } else { $client = self::createRoot( $context, $path, $name ); } return $client; }
[ "public", "static", "function", "create", "(", "\\", "Aimeos", "\\", "MShop", "\\", "Context", "\\", "Item", "\\", "Iface", "$", "context", ",", "$", "path", ",", "$", "name", "=", "null", ")", "{", "$", "path", "=", "trim", "(", "$", "path", ",", "'/'", ")", ";", "if", "(", "empty", "(", "$", "path", ")", ")", "{", "return", "self", "::", "createRoot", "(", "$", "context", ",", "$", "path", ",", "$", "name", ")", ";", "}", "$", "parts", "=", "explode", "(", "'/'", ",", "$", "path", ")", ";", "foreach", "(", "$", "parts", "as", "$", "key", "=>", "$", "part", ")", "{", "if", "(", "ctype_alnum", "(", "$", "part", ")", "===", "false", ")", "{", "$", "msg", "=", "sprintf", "(", "'Invalid client \"%1$s\"'", ",", "$", "path", ")", ";", "throw", "new", "\\", "Aimeos", "\\", "Client", "\\", "JsonApi", "\\", "Exception", "(", "$", "msg", ",", "400", ")", ";", "}", "$", "parts", "[", "$", "key", "]", "=", "ucfirst", "(", "$", "part", ")", ";", "}", "$", "factory", "=", "'\\\\Aimeos\\\\Client\\\\JsonApi\\\\'", ".", "join", "(", "'\\\\'", ",", "$", "parts", ")", ".", "'\\\\Factory'", ";", "if", "(", "class_exists", "(", "$", "factory", ")", "===", "true", ")", "{", "if", "(", "(", "$", "client", "=", "@", "call_user_func_array", "(", "[", "$", "factory", ",", "'create'", "]", ",", "[", "$", "context", ",", "$", "path", ",", "$", "name", "]", ")", ")", "===", "false", ")", "{", "throw", "new", "\\", "Aimeos", "\\", "Client", "\\", "JsonApi", "\\", "Exception", "(", "sprintf", "(", "'Invalid factory \"%1$s\"'", ",", "$", "factory", ")", ",", "400", ")", ";", "}", "}", "else", "{", "$", "client", "=", "self", "::", "createRoot", "(", "$", "context", ",", "$", "path", ",", "$", "name", ")", ";", "}", "return", "$", "client", ";", "}" ]
Creates the required client specified by the given path of client names Clients are created by providing only the domain name, e.g. "product" for the \Aimeos\Client\JsonApi\Product\Standard or a path of names to retrieve a specific sub-client, e.g. "product/type" for the \Aimeos\Client\JsonApi\Product\Type\Standard client. @param \Aimeos\MShop\Context\Item\Iface $context Context object required by clients @param string $path Name of the client separated by slashes, e.g "order/base" @param string|null $name Name of the client implementation ("Standard" if null) @return \Aimeos\Client\JsonApi\Iface JSON client instance @throws \Aimeos\Client\JsonApi\Exception If the given path is invalid
[ "Creates", "the", "required", "client", "specified", "by", "the", "given", "path", "of", "client", "names" ]
b0dfb018ae0a1f7196b18322e28a1b3224aa9045
https://github.com/aimeos/ai-client-jsonapi/blob/b0dfb018ae0a1f7196b18322e28a1b3224aa9045/client/jsonapi/src/Client/JsonApi.php#L36-L71
28,476
BabDev/Transifex-API
src/Connector/Languageinfo.php
Languageinfo.getLanguage
public function getLanguage(string $lang): ResponseInterface { return $this->client->sendRequest($this->createRequest('GET', $this->createUri("/api/2/language/$lang/"))); }
php
public function getLanguage(string $lang): ResponseInterface { return $this->client->sendRequest($this->createRequest('GET', $this->createUri("/api/2/language/$lang/"))); }
[ "public", "function", "getLanguage", "(", "string", "$", "lang", ")", ":", "ResponseInterface", "{", "return", "$", "this", "->", "client", "->", "sendRequest", "(", "$", "this", "->", "createRequest", "(", "'GET'", ",", "$", "this", "->", "createUri", "(", "\"/api/2/language/$lang/\"", ")", ")", ")", ";", "}" ]
Get data on the specified language. @param string $lang The language code to retrieve @return ResponseInterface
[ "Get", "data", "on", "the", "specified", "language", "." ]
9e0ccd7980127db88f7c55a36afbd2a49d9e8436
https://github.com/BabDev/Transifex-API/blob/9e0ccd7980127db88f7c55a36afbd2a49d9e8436/src/Connector/Languageinfo.php#L22-L25
28,477
BabDev/Transifex-API
src/Connector/Translationstrings.php
Translationstrings.getStrings
public function getStrings( string $project, string $resource, string $lang, bool $details = false, array $options = [] ): ResponseInterface { $uri = $this->createUri("/api/2/project/$project/resource/$resource/translation/$lang/strings/"); $query = []; if ($details) { // Add details now because `http_build_query()` can't handle something that isn't a key/value pair $uri = $uri->withQuery('details'); } if (isset($options['key'])) { $query['key'] = $options['key']; } if (isset($options['context'])) { $query['context'] = $options['context']; } if (!empty($query)) { if ($uri->getQuery() === '') { $uri = $uri->withQuery(\http_build_query($query)); } else { $uri = $uri->withQuery($uri->getQuery() . '&' . \http_build_query($query)); } } return $this->client->sendRequest($this->createRequest('GET', $uri)); }
php
public function getStrings( string $project, string $resource, string $lang, bool $details = false, array $options = [] ): ResponseInterface { $uri = $this->createUri("/api/2/project/$project/resource/$resource/translation/$lang/strings/"); $query = []; if ($details) { // Add details now because `http_build_query()` can't handle something that isn't a key/value pair $uri = $uri->withQuery('details'); } if (isset($options['key'])) { $query['key'] = $options['key']; } if (isset($options['context'])) { $query['context'] = $options['context']; } if (!empty($query)) { if ($uri->getQuery() === '') { $uri = $uri->withQuery(\http_build_query($query)); } else { $uri = $uri->withQuery($uri->getQuery() . '&' . \http_build_query($query)); } } return $this->client->sendRequest($this->createRequest('GET', $uri)); }
[ "public", "function", "getStrings", "(", "string", "$", "project", ",", "string", "$", "resource", ",", "string", "$", "lang", ",", "bool", "$", "details", "=", "false", ",", "array", "$", "options", "=", "[", "]", ")", ":", "ResponseInterface", "{", "$", "uri", "=", "$", "this", "->", "createUri", "(", "\"/api/2/project/$project/resource/$resource/translation/$lang/strings/\"", ")", ";", "$", "query", "=", "[", "]", ";", "if", "(", "$", "details", ")", "{", "// Add details now because `http_build_query()` can't handle something that isn't a key/value pair", "$", "uri", "=", "$", "uri", "->", "withQuery", "(", "'details'", ")", ";", "}", "if", "(", "isset", "(", "$", "options", "[", "'key'", "]", ")", ")", "{", "$", "query", "[", "'key'", "]", "=", "$", "options", "[", "'key'", "]", ";", "}", "if", "(", "isset", "(", "$", "options", "[", "'context'", "]", ")", ")", "{", "$", "query", "[", "'context'", "]", "=", "$", "options", "[", "'context'", "]", ";", "}", "if", "(", "!", "empty", "(", "$", "query", ")", ")", "{", "if", "(", "$", "uri", "->", "getQuery", "(", ")", "===", "''", ")", "{", "$", "uri", "=", "$", "uri", "->", "withQuery", "(", "\\", "http_build_query", "(", "$", "query", ")", ")", ";", "}", "else", "{", "$", "uri", "=", "$", "uri", "->", "withQuery", "(", "$", "uri", "->", "getQuery", "(", ")", ".", "'&'", ".", "\\", "http_build_query", "(", "$", "query", ")", ")", ";", "}", "}", "return", "$", "this", "->", "client", "->", "sendRequest", "(", "$", "this", "->", "createRequest", "(", "'GET'", ",", "$", "uri", ")", ")", ";", "}" ]
Method to get the translation strings on a specified resource. @param string $project The slug for the project to pull from @param string $resource The slug for the resource to pull from @param string $lang The language to return the translation for @param bool $details Flag to retrieve additional details on the strings @param array $options An array of additional options for the request @return ResponseInterface
[ "Method", "to", "get", "the", "translation", "strings", "on", "a", "specified", "resource", "." ]
9e0ccd7980127db88f7c55a36afbd2a49d9e8436
https://github.com/BabDev/Transifex-API/blob/9e0ccd7980127db88f7c55a36afbd2a49d9e8436/src/Connector/Translationstrings.php#L39-L71
28,478
techdivision/import-category
src/Subjects/BunchSubject.php
BunchSubject.getDisplayModeByValue
public function getDisplayModeByValue($displayMode) { // query whether or not, the requested display mode is available if (isset($this->availableDisplayModes[$displayMode])) { return $this->availableDisplayModes[$displayMode]; } // throw an exception, if not throw new \Exception(sprintf('Found invalid display mode %s', $displayMode)); }
php
public function getDisplayModeByValue($displayMode) { // query whether or not, the requested display mode is available if (isset($this->availableDisplayModes[$displayMode])) { return $this->availableDisplayModes[$displayMode]; } // throw an exception, if not throw new \Exception(sprintf('Found invalid display mode %s', $displayMode)); }
[ "public", "function", "getDisplayModeByValue", "(", "$", "displayMode", ")", "{", "// query whether or not, the requested display mode is available", "if", "(", "isset", "(", "$", "this", "->", "availableDisplayModes", "[", "$", "displayMode", "]", ")", ")", "{", "return", "$", "this", "->", "availableDisplayModes", "[", "$", "displayMode", "]", ";", "}", "// throw an exception, if not", "throw", "new", "\\", "Exception", "(", "sprintf", "(", "'Found invalid display mode %s'", ",", "$", "displayMode", ")", ")", ";", "}" ]
Return's the display mode for the passed display mode string. @param string $displayMode The display mode string to return the key for @return integer The requested display mode @throws \Exception Is thrown, if the requested display mode is not available
[ "Return", "s", "the", "display", "mode", "for", "the", "passed", "display", "mode", "string", "." ]
6e4dfba08c69fd051587cbdeb92c9a9606d956ee
https://github.com/techdivision/import-category/blob/6e4dfba08c69fd051587cbdeb92c9a9606d956ee/src/Subjects/BunchSubject.php#L146-L156
28,479
techdivision/import-category
src/Subjects/BunchSubject.php
BunchSubject.getPageLayoutByValue
public function getPageLayoutByValue($pageLayout) { // query whether or not, the requested display mode is available if (isset($this->availablePageLayouts[$pageLayout])) { return $this->availablePageLayouts[$pageLayout]; } // throw an exception, if not throw new \Exception(printf('Found invalid page layout %s', $pageLayout)); }
php
public function getPageLayoutByValue($pageLayout) { // query whether or not, the requested display mode is available if (isset($this->availablePageLayouts[$pageLayout])) { return $this->availablePageLayouts[$pageLayout]; } // throw an exception, if not throw new \Exception(printf('Found invalid page layout %s', $pageLayout)); }
[ "public", "function", "getPageLayoutByValue", "(", "$", "pageLayout", ")", "{", "// query whether or not, the requested display mode is available", "if", "(", "isset", "(", "$", "this", "->", "availablePageLayouts", "[", "$", "pageLayout", "]", ")", ")", "{", "return", "$", "this", "->", "availablePageLayouts", "[", "$", "pageLayout", "]", ";", "}", "// throw an exception, if not", "throw", "new", "\\", "Exception", "(", "printf", "(", "'Found invalid page layout %s'", ",", "$", "pageLayout", ")", ")", ";", "}" ]
Return's the page layout for the passed page layout string. @param string $pageLayout The page layout string to return the key for @return integer The requested page layout @throws \Exception Is thrown, if the requested page layout is not available
[ "Return", "s", "the", "page", "layout", "for", "the", "passed", "page", "layout", "string", "." ]
6e4dfba08c69fd051587cbdeb92c9a9606d956ee
https://github.com/techdivision/import-category/blob/6e4dfba08c69fd051587cbdeb92c9a9606d956ee/src/Subjects/BunchSubject.php#L166-L176
28,480
techdivision/import-category
src/Subjects/BunchSubject.php
BunchSubject.getRootCategoryStoreViewCodes
public function getRootCategoryStoreViewCodes($path) { // explode the path of the root category list ($rootCategoryPath, ) = explode('/', $path); // query whether or not a root category with the given path exists if ($rootCategory = $this->getCategoryByPath($rootCategoryPath)) { // initialize the array with the store view codes $storeViewCodes = array(); // try to assemble the store view codes by iterating over the available root categories foreach ($this->rootCategories as $storeViewCode => $category) { // query whether or not the entity ID of the root category matches if ((integer) $category[$this->getPrimaryKeyMemberName()] === (integer) $rootCategory[$this->getPrimaryKeyMemberName()]) { $storeViewCodes[] = $storeViewCode; } } // return the array with the store view codes return $storeViewCodes; } // throw an exception, if the root category is NOT available throw new \Exception(printf('Can\'t load root category "%s" for path "%s"', $rootCategoryPath, $path)); }
php
public function getRootCategoryStoreViewCodes($path) { // explode the path of the root category list ($rootCategoryPath, ) = explode('/', $path); // query whether or not a root category with the given path exists if ($rootCategory = $this->getCategoryByPath($rootCategoryPath)) { // initialize the array with the store view codes $storeViewCodes = array(); // try to assemble the store view codes by iterating over the available root categories foreach ($this->rootCategories as $storeViewCode => $category) { // query whether or not the entity ID of the root category matches if ((integer) $category[$this->getPrimaryKeyMemberName()] === (integer) $rootCategory[$this->getPrimaryKeyMemberName()]) { $storeViewCodes[] = $storeViewCode; } } // return the array with the store view codes return $storeViewCodes; } // throw an exception, if the root category is NOT available throw new \Exception(printf('Can\'t load root category "%s" for path "%s"', $rootCategoryPath, $path)); }
[ "public", "function", "getRootCategoryStoreViewCodes", "(", "$", "path", ")", "{", "// explode the path of the root category", "list", "(", "$", "rootCategoryPath", ",", ")", "=", "explode", "(", "'/'", ",", "$", "path", ")", ";", "// query whether or not a root category with the given path exists", "if", "(", "$", "rootCategory", "=", "$", "this", "->", "getCategoryByPath", "(", "$", "rootCategoryPath", ")", ")", "{", "// initialize the array with the store view codes", "$", "storeViewCodes", "=", "array", "(", ")", ";", "// try to assemble the store view codes by iterating over the available root categories", "foreach", "(", "$", "this", "->", "rootCategories", "as", "$", "storeViewCode", "=>", "$", "category", ")", "{", "// query whether or not the entity ID of the root category matches", "if", "(", "(", "integer", ")", "$", "category", "[", "$", "this", "->", "getPrimaryKeyMemberName", "(", ")", "]", "===", "(", "integer", ")", "$", "rootCategory", "[", "$", "this", "->", "getPrimaryKeyMemberName", "(", ")", "]", ")", "{", "$", "storeViewCodes", "[", "]", "=", "$", "storeViewCode", ";", "}", "}", "// return the array with the store view codes", "return", "$", "storeViewCodes", ";", "}", "// throw an exception, if the root category is NOT available", "throw", "new", "\\", "Exception", "(", "printf", "(", "'Can\\'t load root category \"%s\" for path \"%s\"'", ",", "$", "rootCategoryPath", ",", "$", "path", ")", ")", ";", "}" ]
Returns the store view codes relevant to the category represented by the current row. @param string $path The path to return the root category's store view codes for @return array The store view codes for the given root category @throws \Exception Is thrown, if the root category of the passed path is NOT available
[ "Returns", "the", "store", "view", "codes", "relevant", "to", "the", "category", "represented", "by", "the", "current", "row", "." ]
6e4dfba08c69fd051587cbdeb92c9a9606d956ee
https://github.com/techdivision/import-category/blob/6e4dfba08c69fd051587cbdeb92c9a9606d956ee/src/Subjects/BunchSubject.php#L196-L221
28,481
hiqdev/hipanel-module-finance
src/cart/AbstractCartPosition.php
AbstractCartPosition.serializationMap
protected function serializationMap() { return [ 'attributes' => $this->getAttributes(), '_quantity' => $this->_quantity, '_price' => $this->_price, '_value' => $this->_value, '_id' => $this->_id, ]; }
php
protected function serializationMap() { return [ 'attributes' => $this->getAttributes(), '_quantity' => $this->_quantity, '_price' => $this->_price, '_value' => $this->_value, '_id' => $this->_id, ]; }
[ "protected", "function", "serializationMap", "(", ")", "{", "return", "[", "'attributes'", "=>", "$", "this", "->", "getAttributes", "(", ")", ",", "'_quantity'", "=>", "$", "this", "->", "_quantity", ",", "'_price'", "=>", "$", "this", "->", "_price", ",", "'_value'", "=>", "$", "this", "->", "_value", ",", "'_id'", "=>", "$", "this", "->", "_id", ",", "]", ";", "}" ]
Method stores map of attributes that must be serialized. @return array key is the attribute name where the value should be extracted In case when the value shoule be assigned in a special way, use [[unserializationMap]] to map key to a closure, that will set the value @see unserializationMap
[ "Method", "stores", "map", "of", "attributes", "that", "must", "be", "serialized", "." ]
fa027420ddc1d6de22a6d830e14dde587c837220
https://github.com/hiqdev/hipanel-module-finance/blob/fa027420ddc1d6de22a6d830e14dde587c837220/src/cart/AbstractCartPosition.php#L188-L197
28,482
aimeos/ai-client-jsonapi
client/jsonapi/src/Client/JsonApi/Product/Standard.php
Standard.aggregate
protected function aggregate( \Aimeos\MW\View\Iface $view, ServerRequestInterface $request, ResponseInterface $response ) { $view->data = $this->getController( $view )->sort() ->slice( $view->param( 'page/offset', 0 ), $view->param( 'page/limit', 10000 ) ) ->aggregate( $view->param( 'aggregate' ) ); return $response; }
php
protected function aggregate( \Aimeos\MW\View\Iface $view, ServerRequestInterface $request, ResponseInterface $response ) { $view->data = $this->getController( $view )->sort() ->slice( $view->param( 'page/offset', 0 ), $view->param( 'page/limit', 10000 ) ) ->aggregate( $view->param( 'aggregate' ) ); return $response; }
[ "protected", "function", "aggregate", "(", "\\", "Aimeos", "\\", "MW", "\\", "View", "\\", "Iface", "$", "view", ",", "ServerRequestInterface", "$", "request", ",", "ResponseInterface", "$", "response", ")", "{", "$", "view", "->", "data", "=", "$", "this", "->", "getController", "(", "$", "view", ")", "->", "sort", "(", ")", "->", "slice", "(", "$", "view", "->", "param", "(", "'page/offset'", ",", "0", ")", ",", "$", "view", "->", "param", "(", "'page/limit'", ",", "10000", ")", ")", "->", "aggregate", "(", "$", "view", "->", "param", "(", "'aggregate'", ")", ")", ";", "return", "$", "response", ";", "}" ]
Counts the number of products for the requested key @param \Aimeos\MW\View\Iface $view View instance @param \Psr\Http\Message\ServerRequestInterface $request Request object @param \Psr\Http\Message\ResponseInterface $response Response object @return \Psr\Http\Message\ResponseInterface Modified response object
[ "Counts", "the", "number", "of", "products", "for", "the", "requested", "key" ]
b0dfb018ae0a1f7196b18322e28a1b3224aa9045
https://github.com/aimeos/ai-client-jsonapi/blob/b0dfb018ae0a1f7196b18322e28a1b3224aa9045/client/jsonapi/src/Client/JsonApi/Product/Standard.php#L202-L209
28,483
aimeos/ai-client-jsonapi
client/jsonapi/src/Client/JsonApi/Product/Standard.php
Standard.getController
protected function getController( \Aimeos\MW\View\Iface $view ) { $context = $this->getContext(); $cntl = \Aimeos\Controller\Frontend::create( $context, 'product' ); /** client/jsonapi/product/levels * Include products of sub-categories in the product list of the current category * * Sometimes it may be useful to show products of sub-categories in the * current category product list, e.g. if the current category contains * no products at all or if there are only a few products in all categories. * * Possible constant values for this setting are: * * 1 : Only products from the current category * * 2 : Products from the current category and the direct child categories * * 3 : Products from the current category and the whole category sub-tree * * Caution: Please keep in mind that displaying products of sub-categories * can slow down your shop, especially if it contains more than a few * products! You have no real control over the positions of the products * in the result list too because all products from different categories * with the same position value are placed randomly. * * Usually, a better way is to associate products to all categories they * should be listed in. This can be done manually if there are only a few * ones or during the product import automatically. * * @param integer Tree level constant * @since 2017.03 * @category Developer */ $level = $context->getConfig()->get( 'client/jsonapi/product/levels', \Aimeos\MW\Tree\Manager\Base::LEVEL_ONE ); foreach( (array) $view->param( 'filter/f_oneid', [] ) as $list ) { $cntl->oneOf( $list ); } $cntl->allOf( $view->param( 'filter/f_attrid', [] ) ) ->oneOf( $view->param( 'filter/f_optid', [] ) ) ->text( $view->param( 'filter/f_search' ) ) ->supplier( $view->param( 'filter/f_supid', [] ), $view->param( 'filter/f_listtype', 'default' ) ) ->category( $view->param( 'filter/f_catid' ), $view->param( 'filter/f_listtype', 'default' ), $level ); $params = (array) $view->param( 'filter', [] ); unset( $params['f_supid'], $params['f_search'] ); unset( $params['f_catid'], $params['f_listtype'] ); unset( $params['f_attrid'], $params['f_optid'], $params['f_oneid'] ); return $cntl->parse( $params ) ->sort( $view->param( 'sort', 'relevance' ) ) ->slice( $view->param( 'page/offset', 0 ), $view->param( 'page/limit', 48 ) ); }
php
protected function getController( \Aimeos\MW\View\Iface $view ) { $context = $this->getContext(); $cntl = \Aimeos\Controller\Frontend::create( $context, 'product' ); /** client/jsonapi/product/levels * Include products of sub-categories in the product list of the current category * * Sometimes it may be useful to show products of sub-categories in the * current category product list, e.g. if the current category contains * no products at all or if there are only a few products in all categories. * * Possible constant values for this setting are: * * 1 : Only products from the current category * * 2 : Products from the current category and the direct child categories * * 3 : Products from the current category and the whole category sub-tree * * Caution: Please keep in mind that displaying products of sub-categories * can slow down your shop, especially if it contains more than a few * products! You have no real control over the positions of the products * in the result list too because all products from different categories * with the same position value are placed randomly. * * Usually, a better way is to associate products to all categories they * should be listed in. This can be done manually if there are only a few * ones or during the product import automatically. * * @param integer Tree level constant * @since 2017.03 * @category Developer */ $level = $context->getConfig()->get( 'client/jsonapi/product/levels', \Aimeos\MW\Tree\Manager\Base::LEVEL_ONE ); foreach( (array) $view->param( 'filter/f_oneid', [] ) as $list ) { $cntl->oneOf( $list ); } $cntl->allOf( $view->param( 'filter/f_attrid', [] ) ) ->oneOf( $view->param( 'filter/f_optid', [] ) ) ->text( $view->param( 'filter/f_search' ) ) ->supplier( $view->param( 'filter/f_supid', [] ), $view->param( 'filter/f_listtype', 'default' ) ) ->category( $view->param( 'filter/f_catid' ), $view->param( 'filter/f_listtype', 'default' ), $level ); $params = (array) $view->param( 'filter', [] ); unset( $params['f_supid'], $params['f_search'] ); unset( $params['f_catid'], $params['f_listtype'] ); unset( $params['f_attrid'], $params['f_optid'], $params['f_oneid'] ); return $cntl->parse( $params ) ->sort( $view->param( 'sort', 'relevance' ) ) ->slice( $view->param( 'page/offset', 0 ), $view->param( 'page/limit', 48 ) ); }
[ "protected", "function", "getController", "(", "\\", "Aimeos", "\\", "MW", "\\", "View", "\\", "Iface", "$", "view", ")", "{", "$", "context", "=", "$", "this", "->", "getContext", "(", ")", ";", "$", "cntl", "=", "\\", "Aimeos", "\\", "Controller", "\\", "Frontend", "::", "create", "(", "$", "context", ",", "'product'", ")", ";", "/** client/jsonapi/product/levels\n\t\t * Include products of sub-categories in the product list of the current category\n\t\t *\n\t\t * Sometimes it may be useful to show products of sub-categories in the\n\t\t * current category product list, e.g. if the current category contains\n\t\t * no products at all or if there are only a few products in all categories.\n\t\t *\n\t\t * Possible constant values for this setting are:\n\t\t * * 1 : Only products from the current category\n\t\t * * 2 : Products from the current category and the direct child categories\n\t\t * * 3 : Products from the current category and the whole category sub-tree\n\t\t *\n\t\t * Caution: Please keep in mind that displaying products of sub-categories\n\t\t * can slow down your shop, especially if it contains more than a few\n\t\t * products! You have no real control over the positions of the products\n\t\t * in the result list too because all products from different categories\n\t\t * with the same position value are placed randomly.\n\t\t *\n\t\t * Usually, a better way is to associate products to all categories they\n\t\t * should be listed in. This can be done manually if there are only a few\n\t\t * ones or during the product import automatically.\n\t\t *\n\t\t * @param integer Tree level constant\n\t\t * @since 2017.03\n\t\t * @category Developer\n\t\t */", "$", "level", "=", "$", "context", "->", "getConfig", "(", ")", "->", "get", "(", "'client/jsonapi/product/levels'", ",", "\\", "Aimeos", "\\", "MW", "\\", "Tree", "\\", "Manager", "\\", "Base", "::", "LEVEL_ONE", ")", ";", "foreach", "(", "(", "array", ")", "$", "view", "->", "param", "(", "'filter/f_oneid'", ",", "[", "]", ")", "as", "$", "list", ")", "{", "$", "cntl", "->", "oneOf", "(", "$", "list", ")", ";", "}", "$", "cntl", "->", "allOf", "(", "$", "view", "->", "param", "(", "'filter/f_attrid'", ",", "[", "]", ")", ")", "->", "oneOf", "(", "$", "view", "->", "param", "(", "'filter/f_optid'", ",", "[", "]", ")", ")", "->", "text", "(", "$", "view", "->", "param", "(", "'filter/f_search'", ")", ")", "->", "supplier", "(", "$", "view", "->", "param", "(", "'filter/f_supid'", ",", "[", "]", ")", ",", "$", "view", "->", "param", "(", "'filter/f_listtype'", ",", "'default'", ")", ")", "->", "category", "(", "$", "view", "->", "param", "(", "'filter/f_catid'", ")", ",", "$", "view", "->", "param", "(", "'filter/f_listtype'", ",", "'default'", ")", ",", "$", "level", ")", ";", "$", "params", "=", "(", "array", ")", "$", "view", "->", "param", "(", "'filter'", ",", "[", "]", ")", ";", "unset", "(", "$", "params", "[", "'f_supid'", "]", ",", "$", "params", "[", "'f_search'", "]", ")", ";", "unset", "(", "$", "params", "[", "'f_catid'", "]", ",", "$", "params", "[", "'f_listtype'", "]", ")", ";", "unset", "(", "$", "params", "[", "'f_attrid'", "]", ",", "$", "params", "[", "'f_optid'", "]", ",", "$", "params", "[", "'f_oneid'", "]", ")", ";", "return", "$", "cntl", "->", "parse", "(", "$", "params", ")", "->", "sort", "(", "$", "view", "->", "param", "(", "'sort'", ",", "'relevance'", ")", ")", "->", "slice", "(", "$", "view", "->", "param", "(", "'page/offset'", ",", "0", ")", ",", "$", "view", "->", "param", "(", "'page/limit'", ",", "48", ")", ")", ";", "}" ]
Returns the initialized product controller @param \Aimeos\MW\View\Iface $view View instance @return \Aimeos\Controller\Frontend\Product\Iface Initialized product controller
[ "Returns", "the", "initialized", "product", "controller" ]
b0dfb018ae0a1f7196b18322e28a1b3224aa9045
https://github.com/aimeos/ai-client-jsonapi/blob/b0dfb018ae0a1f7196b18322e28a1b3224aa9045/client/jsonapi/src/Client/JsonApi/Product/Standard.php#L218-L270
28,484
mmoreram/ControllerExtraBundle
Resolver/AnnotationResolver.php
AnnotationResolver.getParameterType
public function getParameterType( ReflectionMethod $method, string $parameterName, ? string $default = null ) : ? string { $parameters = $method->getParameters(); foreach ($parameters as $parameter) { if ($parameter->getName() === $parameterName) { $class = $parameter->getClass(); return $class ? $class->getName() : $default; } } return $default; }
php
public function getParameterType( ReflectionMethod $method, string $parameterName, ? string $default = null ) : ? string { $parameters = $method->getParameters(); foreach ($parameters as $parameter) { if ($parameter->getName() === $parameterName) { $class = $parameter->getClass(); return $class ? $class->getName() : $default; } } return $default; }
[ "public", "function", "getParameterType", "(", "ReflectionMethod", "$", "method", ",", "string", "$", "parameterName", ",", "?", "string", "$", "default", "=", "null", ")", ":", "?", "string", "{", "$", "parameters", "=", "$", "method", "->", "getParameters", "(", ")", ";", "foreach", "(", "$", "parameters", "as", "$", "parameter", ")", "{", "if", "(", "$", "parameter", "->", "getName", "(", ")", "===", "$", "parameterName", ")", "{", "$", "class", "=", "$", "parameter", "->", "getClass", "(", ")", ";", "return", "$", "class", "?", "$", "class", "->", "getName", "(", ")", ":", "$", "default", ";", "}", "}", "return", "$", "default", ";", "}" ]
Return parameter type. @param ReflectionMethod $method @param string $parameterName @param string|null $default @return string|null
[ "Return", "parameter", "type", "." ]
b5841b6ca8f0022a2d88fdfbf743f0b76c4644e3
https://github.com/mmoreram/ControllerExtraBundle/blob/b5841b6ca8f0022a2d88fdfbf743f0b76c4644e3/Resolver/AnnotationResolver.php#L37-L55
28,485
MetaModels/filter_perimetersearch
src/FilterHelper/ProviderInterface.php
ProviderInterface.getFullCountryName
public function getFullCountryName($shortTag) { $countries = $this->getCountries(); if (\array_key_exists($shortTag, $countries)) { return $countries[$shortTag]; } return null; }
php
public function getFullCountryName($shortTag) { $countries = $this->getCountries(); if (\array_key_exists($shortTag, $countries)) { return $countries[$shortTag]; } return null; }
[ "public", "function", "getFullCountryName", "(", "$", "shortTag", ")", "{", "$", "countries", "=", "$", "this", "->", "getCountries", "(", ")", ";", "if", "(", "\\", "array_key_exists", "(", "$", "shortTag", ",", "$", "countries", ")", ")", "{", "return", "$", "countries", "[", "$", "shortTag", "]", ";", "}", "return", "null", ";", "}" ]
Search the full name of a country. @param string $shortTag The short tag for the country. @return null|string Null on error or the full name as string.
[ "Search", "the", "full", "name", "of", "a", "country", "." ]
953d55881a1855972c5f47a7552863986702163c
https://github.com/MetaModels/filter_perimetersearch/blob/953d55881a1855972c5f47a7552863986702163c/src/FilterHelper/ProviderInterface.php#L51-L59
28,486
MetaModels/filter_perimetersearch
src/FilterHelper/ProviderInterface.php
ProviderInterface.getQueryString
public function getQueryString( $street = null, $postal = null, $city = null, $country = null, $fullAddress = null ) { // If we have a full address use it. if ($fullAddress) { // If there is a country try to use the long form. if ((null !== $country) && (null !== ($fullCountryName = $this->getFullCountryName($country)))) { return \sprintf('%s, %s', $fullAddress, $fullCountryName); } if (null !== $country) { // If there is no long form use it as is it. return \sprintf('%s, %s', $fullAddress, $country); } // Or just the full one. return $fullAddress; } // Try to solve the country. if ((null !== $country) && (null !== ($fullCountryName = $this->getFullCountryName($country)))) { $country = $fullCountryName; } return \sprintf( '%s, %s %s, %s', $street, $postal, $city, $country ); }
php
public function getQueryString( $street = null, $postal = null, $city = null, $country = null, $fullAddress = null ) { // If we have a full address use it. if ($fullAddress) { // If there is a country try to use the long form. if ((null !== $country) && (null !== ($fullCountryName = $this->getFullCountryName($country)))) { return \sprintf('%s, %s', $fullAddress, $fullCountryName); } if (null !== $country) { // If there is no long form use it as is it. return \sprintf('%s, %s', $fullAddress, $country); } // Or just the full one. return $fullAddress; } // Try to solve the country. if ((null !== $country) && (null !== ($fullCountryName = $this->getFullCountryName($country)))) { $country = $fullCountryName; } return \sprintf( '%s, %s %s, %s', $street, $postal, $city, $country ); }
[ "public", "function", "getQueryString", "(", "$", "street", "=", "null", ",", "$", "postal", "=", "null", ",", "$", "city", "=", "null", ",", "$", "country", "=", "null", ",", "$", "fullAddress", "=", "null", ")", "{", "// If we have a full address use it.", "if", "(", "$", "fullAddress", ")", "{", "// If there is a country try to use the long form.", "if", "(", "(", "null", "!==", "$", "country", ")", "&&", "(", "null", "!==", "(", "$", "fullCountryName", "=", "$", "this", "->", "getFullCountryName", "(", "$", "country", ")", ")", ")", ")", "{", "return", "\\", "sprintf", "(", "'%s, %s'", ",", "$", "fullAddress", ",", "$", "fullCountryName", ")", ";", "}", "if", "(", "null", "!==", "$", "country", ")", "{", "// If there is no long form use it as is it.", "return", "\\", "sprintf", "(", "'%s, %s'", ",", "$", "fullAddress", ",", "$", "country", ")", ";", "}", "// Or just the full one.", "return", "$", "fullAddress", ";", "}", "// Try to solve the country.", "if", "(", "(", "null", "!==", "$", "country", ")", "&&", "(", "null", "!==", "(", "$", "fullCountryName", "=", "$", "this", "->", "getFullCountryName", "(", "$", "country", ")", ")", ")", ")", "{", "$", "country", "=", "$", "fullCountryName", ";", "}", "return", "\\", "sprintf", "(", "'%s, %s %s, %s'", ",", "$", "street", ",", "$", "postal", ",", "$", "city", ",", "$", "country", ")", ";", "}" ]
Build the query string. @param string $street The street. @param string $postal The postal code. @param string $city Name of city. @param string $country A 2-letter country code. @param string $fullAddress Address string without specific format. @return string
[ "Build", "the", "query", "string", "." ]
953d55881a1855972c5f47a7552863986702163c
https://github.com/MetaModels/filter_perimetersearch/blob/953d55881a1855972c5f47a7552863986702163c/src/FilterHelper/ProviderInterface.php#L72-L107
28,487
mmoreram/ControllerExtraBundle
Provider/RequestParameterProvider.php
RequestParameterProvider.resolveValueFromParameterBag
protected function resolveValueFromParameterBag( ParameterBag $parameterBag, string $delimiter, string $value ) { $trimmedValue = trim($value, $delimiter); if ( ($delimiter . $trimmedValue . $delimiter === $value) && $parameterBag->has($trimmedValue) ) { $value = $parameterBag->get($trimmedValue); } return $value; }
php
protected function resolveValueFromParameterBag( ParameterBag $parameterBag, string $delimiter, string $value ) { $trimmedValue = trim($value, $delimiter); if ( ($delimiter . $trimmedValue . $delimiter === $value) && $parameterBag->has($trimmedValue) ) { $value = $parameterBag->get($trimmedValue); } return $value; }
[ "protected", "function", "resolveValueFromParameterBag", "(", "ParameterBag", "$", "parameterBag", ",", "string", "$", "delimiter", ",", "string", "$", "value", ")", "{", "$", "trimmedValue", "=", "trim", "(", "$", "value", ",", "$", "delimiter", ")", ";", "if", "(", "(", "$", "delimiter", ".", "$", "trimmedValue", ".", "$", "delimiter", "===", "$", "value", ")", "&&", "$", "parameterBag", "->", "has", "(", "$", "trimmedValue", ")", ")", "{", "$", "value", "=", "$", "parameterBag", "->", "get", "(", "$", "trimmedValue", ")", ";", "}", "return", "$", "value", ";", "}" ]
Given a bag and a delimiter, return the resolved value. @param ParameterBag $parameterBag @param string $delimiter @param string $value @return mixed
[ "Given", "a", "bag", "and", "a", "delimiter", "return", "the", "resolved", "value", "." ]
b5841b6ca8f0022a2d88fdfbf743f0b76c4644e3
https://github.com/mmoreram/ControllerExtraBundle/blob/b5841b6ca8f0022a2d88fdfbf743f0b76c4644e3/Provider/RequestParameterProvider.php#L124-L139
28,488
techdivision/import-category
src/Subjects/AbstractCategorySubject.php
AbstractCategorySubject.getRowStoreId
public function getRowStoreId($default = null) { // initialize the default store view code, if not passed if ($default == null) { $defaultStore = $this->getDefaultStore(); $default = $defaultStore[MemberNames::CODE]; } // load the store view code the create the product/attributes for $storeViewCode = $this->getStoreViewCode($default); // query whether or not, the requested store is available if (isset($this->stores[$storeViewCode])) { return (integer) $this->stores[$storeViewCode][MemberNames::STORE_ID]; } // throw an exception, if not throw new \Exception(sprintf('Found invalid store view code "%s"', $storeViewCode)); }
php
public function getRowStoreId($default = null) { // initialize the default store view code, if not passed if ($default == null) { $defaultStore = $this->getDefaultStore(); $default = $defaultStore[MemberNames::CODE]; } // load the store view code the create the product/attributes for $storeViewCode = $this->getStoreViewCode($default); // query whether or not, the requested store is available if (isset($this->stores[$storeViewCode])) { return (integer) $this->stores[$storeViewCode][MemberNames::STORE_ID]; } // throw an exception, if not throw new \Exception(sprintf('Found invalid store view code "%s"', $storeViewCode)); }
[ "public", "function", "getRowStoreId", "(", "$", "default", "=", "null", ")", "{", "// initialize the default store view code, if not passed", "if", "(", "$", "default", "==", "null", ")", "{", "$", "defaultStore", "=", "$", "this", "->", "getDefaultStore", "(", ")", ";", "$", "default", "=", "$", "defaultStore", "[", "MemberNames", "::", "CODE", "]", ";", "}", "// load the store view code the create the product/attributes for", "$", "storeViewCode", "=", "$", "this", "->", "getStoreViewCode", "(", "$", "default", ")", ";", "// query whether or not, the requested store is available", "if", "(", "isset", "(", "$", "this", "->", "stores", "[", "$", "storeViewCode", "]", ")", ")", "{", "return", "(", "integer", ")", "$", "this", "->", "stores", "[", "$", "storeViewCode", "]", "[", "MemberNames", "::", "STORE_ID", "]", ";", "}", "// throw an exception, if not", "throw", "new", "\\", "Exception", "(", "sprintf", "(", "'Found invalid store view code \"%s\"'", ",", "$", "storeViewCode", ")", ")", ";", "}" ]
Return's the store ID of the actual row, or of the default store if no store view code is set in the CSV file. @param string|null $default The default store view code to use, if no store view code is set in the CSV file @return integer The ID of the actual store @throws \Exception Is thrown, if the store with the actual code is not available
[ "Return", "s", "the", "store", "ID", "of", "the", "actual", "row", "or", "of", "the", "default", "store", "if", "no", "store", "view", "code", "is", "set", "in", "the", "CSV", "file", "." ]
6e4dfba08c69fd051587cbdeb92c9a9606d956ee
https://github.com/techdivision/import-category/blob/6e4dfba08c69fd051587cbdeb92c9a9606d956ee/src/Subjects/AbstractCategorySubject.php#L349-L368
28,489
techdivision/import-category
src/Subjects/AbstractCategorySubject.php
AbstractCategorySubject.getStoreWebsiteIdByCode
public function getStoreWebsiteIdByCode($code) { // query whether or not, the requested store website is available if (isset($this->storeWebsites[$code])) { return (integer) $this->storeWebsites[$code][MemberNames::WEBSITE_ID]; } // throw an exception, if not throw new \Exception(sprintf('Found invalid website code "%s"', $code)); }
php
public function getStoreWebsiteIdByCode($code) { // query whether or not, the requested store website is available if (isset($this->storeWebsites[$code])) { return (integer) $this->storeWebsites[$code][MemberNames::WEBSITE_ID]; } // throw an exception, if not throw new \Exception(sprintf('Found invalid website code "%s"', $code)); }
[ "public", "function", "getStoreWebsiteIdByCode", "(", "$", "code", ")", "{", "// query whether or not, the requested store website is available", "if", "(", "isset", "(", "$", "this", "->", "storeWebsites", "[", "$", "code", "]", ")", ")", "{", "return", "(", "integer", ")", "$", "this", "->", "storeWebsites", "[", "$", "code", "]", "[", "MemberNames", "::", "WEBSITE_ID", "]", ";", "}", "// throw an exception, if not", "throw", "new", "\\", "Exception", "(", "sprintf", "(", "'Found invalid website code \"%s\"'", ",", "$", "code", ")", ")", ";", "}" ]
Return's the store website for the passed code. @param string $code The code of the store website to return the ID for @return integer The store website ID @throws \Exception Is thrown, if the store website with the requested code is not available
[ "Return", "s", "the", "store", "website", "for", "the", "passed", "code", "." ]
6e4dfba08c69fd051587cbdeb92c9a9606d956ee
https://github.com/techdivision/import-category/blob/6e4dfba08c69fd051587cbdeb92c9a9606d956ee/src/Subjects/AbstractCategorySubject.php#L378-L388
28,490
techdivision/import-category
src/Subjects/AbstractCategorySubject.php
AbstractCategorySubject.updateCategory
public function updateCategory($path, $category) { $this->categories[$path] = array_merge($this->categories[$path], $category); }
php
public function updateCategory($path, $category) { $this->categories[$path] = array_merge($this->categories[$path], $category); }
[ "public", "function", "updateCategory", "(", "$", "path", ",", "$", "category", ")", "{", "$", "this", "->", "categories", "[", "$", "path", "]", "=", "array_merge", "(", "$", "this", "->", "categories", "[", "$", "path", "]", ",", "$", "category", ")", ";", "}" ]
Updates the category with the passed path. @param string $path The path of the category to update @param array $category The category data to update @return void @deprecated Since 7.0.0
[ "Updates", "the", "category", "with", "the", "passed", "path", "." ]
6e4dfba08c69fd051587cbdeb92c9a9606d956ee
https://github.com/techdivision/import-category/blob/6e4dfba08c69fd051587cbdeb92c9a9606d956ee/src/Subjects/AbstractCategorySubject.php#L435-L438
28,491
techdivision/import-category
src/Plugins/ChildrenCountPlugin.php
ChildrenCountPlugin.process
public function process() { // load all available categories $categories = $this->getImportProcessor()->getCategories(); // update the categories children count foreach ($categories as $category) { // load the category itself $this->category = $this->loadCategory($pk = $this->getPrimaryKey($category)); // update the category's children count $this->persistCategory($this->initializeCategory($this->prepareAttributes())); // write a log message $this->getSystemLogger()->debug( sprintf('Successfully updated category with primary key %d', $pk) ); } }
php
public function process() { // load all available categories $categories = $this->getImportProcessor()->getCategories(); // update the categories children count foreach ($categories as $category) { // load the category itself $this->category = $this->loadCategory($pk = $this->getPrimaryKey($category)); // update the category's children count $this->persistCategory($this->initializeCategory($this->prepareAttributes())); // write a log message $this->getSystemLogger()->debug( sprintf('Successfully updated category with primary key %d', $pk) ); } }
[ "public", "function", "process", "(", ")", "{", "// load all available categories", "$", "categories", "=", "$", "this", "->", "getImportProcessor", "(", ")", "->", "getCategories", "(", ")", ";", "// update the categories children count", "foreach", "(", "$", "categories", "as", "$", "category", ")", "{", "// load the category itself", "$", "this", "->", "category", "=", "$", "this", "->", "loadCategory", "(", "$", "pk", "=", "$", "this", "->", "getPrimaryKey", "(", "$", "category", ")", ")", ";", "// update the category's children count", "$", "this", "->", "persistCategory", "(", "$", "this", "->", "initializeCategory", "(", "$", "this", "->", "prepareAttributes", "(", ")", ")", ")", ";", "// write a log message", "$", "this", "->", "getSystemLogger", "(", ")", "->", "debug", "(", "sprintf", "(", "'Successfully updated category with primary key %d'", ",", "$", "pk", ")", ")", ";", "}", "}" ]
Process the plugin functionality. @return void @throws \Exception Is thrown, if the plugin can not be processed
[ "Process", "the", "plugin", "functionality", "." ]
6e4dfba08c69fd051587cbdeb92c9a9606d956ee
https://github.com/techdivision/import-category/blob/6e4dfba08c69fd051587cbdeb92c9a9606d956ee/src/Plugins/ChildrenCountPlugin.php#L70-L89
28,492
mmoreram/ControllerExtraBundle
Resolver/PaginatorAnnotationResolver.php
PaginatorAnnotationResolver.createQueryBuilder
private function createQueryBuilder(string $entityNamespace) : QueryBuilder { return $this ->doctrine ->getManagerForClass($entityNamespace) ->createQueryBuilder() ->select(['x']) ->from($entityNamespace, 'x'); }
php
private function createQueryBuilder(string $entityNamespace) : QueryBuilder { return $this ->doctrine ->getManagerForClass($entityNamespace) ->createQueryBuilder() ->select(['x']) ->from($entityNamespace, 'x'); }
[ "private", "function", "createQueryBuilder", "(", "string", "$", "entityNamespace", ")", ":", "QueryBuilder", "{", "return", "$", "this", "->", "doctrine", "->", "getManagerForClass", "(", "$", "entityNamespace", ")", "->", "createQueryBuilder", "(", ")", "->", "select", "(", "[", "'x'", "]", ")", "->", "from", "(", "$", "entityNamespace", ",", "'x'", ")", ";", "}" ]
Generate QueryBuilder. @param string $entityNamespace @return QueryBuilder
[ "Generate", "QueryBuilder", "." ]
b5841b6ca8f0022a2d88fdfbf743f0b76c4644e3
https://github.com/mmoreram/ControllerExtraBundle/blob/b5841b6ca8f0022a2d88fdfbf743f0b76c4644e3/Resolver/PaginatorAnnotationResolver.php#L250-L258
28,493
mmoreram/ControllerExtraBundle
Resolver/PaginatorAnnotationResolver.php
PaginatorAnnotationResolver.evaluateAttributes
private function evaluateAttributes( Request $request, CreatePaginator $annotation, DoctrinePaginator $paginator, int $limitPerPage, int $page ) { if ($annotation->getAttributes()) { $total = $paginator->count(); $paginatorAttributes = new PaginatorAttributes( (int) ceil($total / $limitPerPage), $total, $page, $limitPerPage ); $request->attributes->set( trim($annotation->getAttributes()), $paginatorAttributes ); } }
php
private function evaluateAttributes( Request $request, CreatePaginator $annotation, DoctrinePaginator $paginator, int $limitPerPage, int $page ) { if ($annotation->getAttributes()) { $total = $paginator->count(); $paginatorAttributes = new PaginatorAttributes( (int) ceil($total / $limitPerPage), $total, $page, $limitPerPage ); $request->attributes->set( trim($annotation->getAttributes()), $paginatorAttributes ); } }
[ "private", "function", "evaluateAttributes", "(", "Request", "$", "request", ",", "CreatePaginator", "$", "annotation", ",", "DoctrinePaginator", "$", "paginator", ",", "int", "$", "limitPerPage", ",", "int", "$", "page", ")", "{", "if", "(", "$", "annotation", "->", "getAttributes", "(", ")", ")", "{", "$", "total", "=", "$", "paginator", "->", "count", "(", ")", ";", "$", "paginatorAttributes", "=", "new", "PaginatorAttributes", "(", "(", "int", ")", "ceil", "(", "$", "total", "/", "$", "limitPerPage", ")", ",", "$", "total", ",", "$", "page", ",", "$", "limitPerPage", ")", ";", "$", "request", "->", "attributes", "->", "set", "(", "trim", "(", "$", "annotation", "->", "getAttributes", "(", ")", ")", ",", "$", "paginatorAttributes", ")", ";", "}", "}" ]
Evaluates Paginator attributes. @param Request $request @param CreatePaginator $annotation @param DoctrinePaginator $paginator @param int $limitPerPage @param int $page
[ "Evaluates", "Paginator", "attributes", "." ]
b5841b6ca8f0022a2d88fdfbf743f0b76c4644e3
https://github.com/mmoreram/ControllerExtraBundle/blob/b5841b6ca8f0022a2d88fdfbf743f0b76c4644e3/Resolver/PaginatorAnnotationResolver.php#L269-L290
28,494
mmoreram/ControllerExtraBundle
Resolver/PaginatorAnnotationResolver.php
PaginatorAnnotationResolver.decidePaginatorFormat
private function decidePaginatorFormat( DoctrinePaginator $paginator, string $parameterType, int $limitPerPage, int $page ) { if (Pagerfanta::class === $parameterType) { $paginator = new Pagerfanta(new DoctrineORMAdapter($paginator->getQuery())); $paginator->setMaxPerPage($limitPerPage); $paginator->setCurrentPage($page); } if (PaginationInterface::class === $parameterType) { $knp = new KnpPaginator(); $paginator = $knp->paginate($paginator->getQuery(), $page, $limitPerPage); } return $paginator; }
php
private function decidePaginatorFormat( DoctrinePaginator $paginator, string $parameterType, int $limitPerPage, int $page ) { if (Pagerfanta::class === $parameterType) { $paginator = new Pagerfanta(new DoctrineORMAdapter($paginator->getQuery())); $paginator->setMaxPerPage($limitPerPage); $paginator->setCurrentPage($page); } if (PaginationInterface::class === $parameterType) { $knp = new KnpPaginator(); $paginator = $knp->paginate($paginator->getQuery(), $page, $limitPerPage); } return $paginator; }
[ "private", "function", "decidePaginatorFormat", "(", "DoctrinePaginator", "$", "paginator", ",", "string", "$", "parameterType", ",", "int", "$", "limitPerPage", ",", "int", "$", "page", ")", "{", "if", "(", "Pagerfanta", "::", "class", "===", "$", "parameterType", ")", "{", "$", "paginator", "=", "new", "Pagerfanta", "(", "new", "DoctrineORMAdapter", "(", "$", "paginator", "->", "getQuery", "(", ")", ")", ")", ";", "$", "paginator", "->", "setMaxPerPage", "(", "$", "limitPerPage", ")", ";", "$", "paginator", "->", "setCurrentPage", "(", "$", "page", ")", ";", "}", "if", "(", "PaginationInterface", "::", "class", "===", "$", "parameterType", ")", "{", "$", "knp", "=", "new", "KnpPaginator", "(", ")", ";", "$", "paginator", "=", "$", "knp", "->", "paginate", "(", "$", "paginator", "->", "getQuery", "(", ")", ",", "$", "page", ",", "$", "limitPerPage", ")", ";", "}", "return", "$", "paginator", ";", "}" ]
Return real usable Paginator instance given the definition type. @param DoctrinePaginator $paginator @param string $parameterType @param int $limitPerPage @param int $page @return mixed
[ "Return", "real", "usable", "Paginator", "instance", "given", "the", "definition", "type", "." ]
b5841b6ca8f0022a2d88fdfbf743f0b76c4644e3
https://github.com/mmoreram/ControllerExtraBundle/blob/b5841b6ca8f0022a2d88fdfbf743f0b76c4644e3/Resolver/PaginatorAnnotationResolver.php#L302-L319
28,495
techdivision/import-category
src/Repositories/CategoryRepository.php
CategoryRepository.countChildren
public function countChildren($path) { // load and return the category with the passed path $this->categoryCountChildrenStmt->execute(array(MemberNames::PATH => $path)); return $this->categoryCountChildrenStmt->fetchColumn(); }
php
public function countChildren($path) { // load and return the category with the passed path $this->categoryCountChildrenStmt->execute(array(MemberNames::PATH => $path)); return $this->categoryCountChildrenStmt->fetchColumn(); }
[ "public", "function", "countChildren", "(", "$", "path", ")", "{", "// load and return the category with the passed path", "$", "this", "->", "categoryCountChildrenStmt", "->", "execute", "(", "array", "(", "MemberNames", "::", "PATH", "=>", "$", "path", ")", ")", ";", "return", "$", "this", "->", "categoryCountChildrenStmt", "->", "fetchColumn", "(", ")", ";", "}" ]
Return's the children count of the category with the passed path. @param string $path The path of the category to count the children for @return integer The children count of the category with the passed path
[ "Return", "s", "the", "children", "count", "of", "the", "category", "with", "the", "passed", "path", "." ]
6e4dfba08c69fd051587cbdeb92c9a9606d956ee
https://github.com/techdivision/import-category/blob/6e4dfba08c69fd051587cbdeb92c9a9606d956ee/src/Repositories/CategoryRepository.php#L114-L119
28,496
QoboLtd/cakephp-search
src/Utility/Validator.php
Validator.validateData
public static function validateData(RepositoryInterface $table, array $data, array $user): array { $fields = Utility::instance()->getSearchableFields($table, $user); $fields = array_keys($fields); // merge default options $data += Options::getDefaults($table); if (!empty($data['criteria'])) { $data['criteria'] = static::validateCriteria($data['criteria'], $fields); } $data['display_columns'] = static::validateDisplayColumns($data['display_columns'], $fields); $data['sort_by_field'] = static::validateSortByField( $data['sort_by_field'], $fields, $data['display_columns'], $table ); $data['sort_by_order'] = static::validateSortByOrder($data['sort_by_order']); $data['aggregator'] = static::validateAggregator($data['aggregator']); return $data; }
php
public static function validateData(RepositoryInterface $table, array $data, array $user): array { $fields = Utility::instance()->getSearchableFields($table, $user); $fields = array_keys($fields); // merge default options $data += Options::getDefaults($table); if (!empty($data['criteria'])) { $data['criteria'] = static::validateCriteria($data['criteria'], $fields); } $data['display_columns'] = static::validateDisplayColumns($data['display_columns'], $fields); $data['sort_by_field'] = static::validateSortByField( $data['sort_by_field'], $fields, $data['display_columns'], $table ); $data['sort_by_order'] = static::validateSortByOrder($data['sort_by_order']); $data['aggregator'] = static::validateAggregator($data['aggregator']); return $data; }
[ "public", "static", "function", "validateData", "(", "RepositoryInterface", "$", "table", ",", "array", "$", "data", ",", "array", "$", "user", ")", ":", "array", "{", "$", "fields", "=", "Utility", "::", "instance", "(", ")", "->", "getSearchableFields", "(", "$", "table", ",", "$", "user", ")", ";", "$", "fields", "=", "array_keys", "(", "$", "fields", ")", ";", "// merge default options", "$", "data", "+=", "Options", "::", "getDefaults", "(", "$", "table", ")", ";", "if", "(", "!", "empty", "(", "$", "data", "[", "'criteria'", "]", ")", ")", "{", "$", "data", "[", "'criteria'", "]", "=", "static", "::", "validateCriteria", "(", "$", "data", "[", "'criteria'", "]", ",", "$", "fields", ")", ";", "}", "$", "data", "[", "'display_columns'", "]", "=", "static", "::", "validateDisplayColumns", "(", "$", "data", "[", "'display_columns'", "]", ",", "$", "fields", ")", ";", "$", "data", "[", "'sort_by_field'", "]", "=", "static", "::", "validateSortByField", "(", "$", "data", "[", "'sort_by_field'", "]", ",", "$", "fields", ",", "$", "data", "[", "'display_columns'", "]", ",", "$", "table", ")", ";", "$", "data", "[", "'sort_by_order'", "]", "=", "static", "::", "validateSortByOrder", "(", "$", "data", "[", "'sort_by_order'", "]", ")", ";", "$", "data", "[", "'aggregator'", "]", "=", "static", "::", "validateAggregator", "(", "$", "data", "[", "'aggregator'", "]", ")", ";", "return", "$", "data", ";", "}" ]
Base search data validation method. Retrieves current searchable table columns, validates and filters criteria, display columns and sort by field against them. Then validates sort by order againt available options and sets it to the default option if they fail validation. @param \Cake\Datasource\RepositoryInterface $table Table instace @param mixed[] $data Search data @param mixed[] $user User info @return mixed[]
[ "Base", "search", "data", "validation", "method", "." ]
095a0e822781ac11eade0c03c7729b693daa1ba8
https://github.com/QoboLtd/cakephp-search/blob/095a0e822781ac11eade0c03c7729b693daa1ba8/src/Utility/Validator.php#L40-L63
28,497
QoboLtd/cakephp-search
src/Utility/Validator.php
Validator.validateCriteria
protected static function validateCriteria(array $data, array $fields): array { foreach (array_keys($data) as $key) { if (in_array($key, $fields)) { continue; } unset($data[$key]); } return $data; }
php
protected static function validateCriteria(array $data, array $fields): array { foreach (array_keys($data) as $key) { if (in_array($key, $fields)) { continue; } unset($data[$key]); } return $data; }
[ "protected", "static", "function", "validateCriteria", "(", "array", "$", "data", ",", "array", "$", "fields", ")", ":", "array", "{", "foreach", "(", "array_keys", "(", "$", "data", ")", "as", "$", "key", ")", "{", "if", "(", "in_array", "(", "$", "key", ",", "$", "fields", ")", ")", "{", "continue", ";", "}", "unset", "(", "$", "data", "[", "$", "key", "]", ")", ";", "}", "return", "$", "data", ";", "}" ]
Validate search criteria. @param mixed[] $data Criteria values @param mixed[] $fields Searchable fields @return mixed[]
[ "Validate", "search", "criteria", "." ]
095a0e822781ac11eade0c03c7729b693daa1ba8
https://github.com/QoboLtd/cakephp-search/blob/095a0e822781ac11eade0c03c7729b693daa1ba8/src/Utility/Validator.php#L72-L82
28,498
QoboLtd/cakephp-search
src/Utility/Validator.php
Validator.validateSortByField
protected static function validateSortByField(string $data, array $fields, array $displayColumns, RepositoryInterface $table): string { /** @var \Cake\ORM\Table */ $table = $table; // use sort field if is searchable if (in_array($data, $fields)) { return $data; } // set display field as sort field $data = $table->getDisplayField(); // check if display field exists in the database table if ($table->getSchema()->getColumn($data)) { return $table->aliasField($data); } // use first display column which exists in the database table foreach ($displayColumns as $displayColumn) { // remove table prefix list(, $displayColumn) = explode('.', $displayColumn); if (!$table->getSchema()->getColumn($displayColumn)) { continue; } return $table->aliasField($displayColumn); } // use primary key as a last resort return $table->aliasField(current((array)$table->getPrimaryKey())); }
php
protected static function validateSortByField(string $data, array $fields, array $displayColumns, RepositoryInterface $table): string { /** @var \Cake\ORM\Table */ $table = $table; // use sort field if is searchable if (in_array($data, $fields)) { return $data; } // set display field as sort field $data = $table->getDisplayField(); // check if display field exists in the database table if ($table->getSchema()->getColumn($data)) { return $table->aliasField($data); } // use first display column which exists in the database table foreach ($displayColumns as $displayColumn) { // remove table prefix list(, $displayColumn) = explode('.', $displayColumn); if (!$table->getSchema()->getColumn($displayColumn)) { continue; } return $table->aliasField($displayColumn); } // use primary key as a last resort return $table->aliasField(current((array)$table->getPrimaryKey())); }
[ "protected", "static", "function", "validateSortByField", "(", "string", "$", "data", ",", "array", "$", "fields", ",", "array", "$", "displayColumns", ",", "RepositoryInterface", "$", "table", ")", ":", "string", "{", "/** @var \\Cake\\ORM\\Table */", "$", "table", "=", "$", "table", ";", "// use sort field if is searchable", "if", "(", "in_array", "(", "$", "data", ",", "$", "fields", ")", ")", "{", "return", "$", "data", ";", "}", "// set display field as sort field", "$", "data", "=", "$", "table", "->", "getDisplayField", "(", ")", ";", "// check if display field exists in the database table", "if", "(", "$", "table", "->", "getSchema", "(", ")", "->", "getColumn", "(", "$", "data", ")", ")", "{", "return", "$", "table", "->", "aliasField", "(", "$", "data", ")", ";", "}", "// use first display column which exists in the database table", "foreach", "(", "$", "displayColumns", "as", "$", "displayColumn", ")", "{", "// remove table prefix", "list", "(", ",", "$", "displayColumn", ")", "=", "explode", "(", "'.'", ",", "$", "displayColumn", ")", ";", "if", "(", "!", "$", "table", "->", "getSchema", "(", ")", "->", "getColumn", "(", "$", "displayColumn", ")", ")", "{", "continue", ";", "}", "return", "$", "table", "->", "aliasField", "(", "$", "displayColumn", ")", ";", "}", "// use primary key as a last resort", "return", "$", "table", "->", "aliasField", "(", "current", "(", "(", "array", ")", "$", "table", "->", "getPrimaryKey", "(", ")", ")", ")", ";", "}" ]
Validate search sort by field. @param string $data Sort by field value @param mixed[] $fields Searchable fields @param mixed[] $displayColumns Display columns @param \Cake\Datasource\RepositoryInterface $table Table instance @return string
[ "Validate", "search", "sort", "by", "field", "." ]
095a0e822781ac11eade0c03c7729b693daa1ba8
https://github.com/QoboLtd/cakephp-search/blob/095a0e822781ac11eade0c03c7729b693daa1ba8/src/Utility/Validator.php#L112-L142
28,499
QoboLtd/cakephp-search
src/Utility/Validator.php
Validator.validateSortByOrder
protected static function validateSortByOrder(string $data): string { $options = array_keys(Options::getSortByOrders()); if (!in_array($data, $options)) { $data = Options::DEFAULT_SORT_BY_ORDER; } return $data; }
php
protected static function validateSortByOrder(string $data): string { $options = array_keys(Options::getSortByOrders()); if (!in_array($data, $options)) { $data = Options::DEFAULT_SORT_BY_ORDER; } return $data; }
[ "protected", "static", "function", "validateSortByOrder", "(", "string", "$", "data", ")", ":", "string", "{", "$", "options", "=", "array_keys", "(", "Options", "::", "getSortByOrders", "(", ")", ")", ";", "if", "(", "!", "in_array", "(", "$", "data", ",", "$", "options", ")", ")", "{", "$", "data", "=", "Options", "::", "DEFAULT_SORT_BY_ORDER", ";", "}", "return", "$", "data", ";", "}" ]
Validate search sort by order. @param string $data Sort by order value @return string
[ "Validate", "search", "sort", "by", "order", "." ]
095a0e822781ac11eade0c03c7729b693daa1ba8
https://github.com/QoboLtd/cakephp-search/blob/095a0e822781ac11eade0c03c7729b693daa1ba8/src/Utility/Validator.php#L150-L158