repo stringlengths 6 63 | path stringlengths 5 140 | func_name stringlengths 3 151 | original_string stringlengths 84 13k | language stringclasses 1 value | code stringlengths 84 13k | code_tokens list | docstring stringlengths 3 47.2k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 91 247 | partition stringclasses 1 value |
|---|---|---|---|---|---|---|---|---|---|---|---|
grom358/pharborist | src/NodeCollection.php | NodeCollection.replaceWith | public function replaceWith($nodes) {
$first = TRUE;
foreach ($this->nodes as $node) {
if (!$first) {
if (is_array($nodes)) {
$nodes = new NodeCollection($nodes, FALSE);
}
$nodes = clone $nodes;
}
$node->replaceWith($nodes);
$first = FALSE;
}
return $this;
} | php | public function replaceWith($nodes) {
$first = TRUE;
foreach ($this->nodes as $node) {
if (!$first) {
if (is_array($nodes)) {
$nodes = new NodeCollection($nodes, FALSE);
}
$nodes = clone $nodes;
}
$node->replaceWith($nodes);
$first = FALSE;
}
return $this;
} | [
"public",
"function",
"replaceWith",
"(",
"$",
"nodes",
")",
"{",
"$",
"first",
"=",
"TRUE",
";",
"foreach",
"(",
"$",
"this",
"->",
"nodes",
"as",
"$",
"node",
")",
"{",
"if",
"(",
"!",
"$",
"first",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
... | Replace each node in the set of matched nodes with the provided new nodes
and return the set of nodes that was removed.
@param Node|Node[]|NodeCollection $nodes Replacement nodes.
@return $this | [
"Replace",
"each",
"node",
"in",
"the",
"set",
"of",
"matched",
"nodes",
"with",
"the",
"provided",
"new",
"nodes",
"and",
"return",
"the",
"set",
"of",
"nodes",
"that",
"was",
"removed",
"."
] | 0db9e51299a80e95b06857ed1809f59bbbab1af6 | https://github.com/grom358/pharborist/blob/0db9e51299a80e95b06857ed1809f59bbbab1af6/src/NodeCollection.php#L592-L605 | train |
grom358/pharborist | src/NodeCollection.php | NodeCollection.replaceAll | public function replaceAll($targets) {
if ($targets instanceof Node) {
$targets->replaceWith($this->nodes);
}
elseif ($targets instanceof NodeCollection || is_array($targets)) {
$first = TRUE;
/** @var Node $target */
foreach ($targets as $target) {
$target->replaceWith($first ? $this->nodes : clone $this);
$first = FALSE;
}
}
return $this;
} | php | public function replaceAll($targets) {
if ($targets instanceof Node) {
$targets->replaceWith($this->nodes);
}
elseif ($targets instanceof NodeCollection || is_array($targets)) {
$first = TRUE;
/** @var Node $target */
foreach ($targets as $target) {
$target->replaceWith($first ? $this->nodes : clone $this);
$first = FALSE;
}
}
return $this;
} | [
"public",
"function",
"replaceAll",
"(",
"$",
"targets",
")",
"{",
"if",
"(",
"$",
"targets",
"instanceof",
"Node",
")",
"{",
"$",
"targets",
"->",
"replaceWith",
"(",
"$",
"this",
"->",
"nodes",
")",
";",
"}",
"elseif",
"(",
"$",
"targets",
"instanceo... | Replace each target node with the set of matched nodes.
@param Node|Node[]|NodeCollection $targets Targets to replace.
@return $this | [
"Replace",
"each",
"target",
"node",
"with",
"the",
"set",
"of",
"matched",
"nodes",
"."
] | 0db9e51299a80e95b06857ed1809f59bbbab1af6 | https://github.com/grom358/pharborist/blob/0db9e51299a80e95b06857ed1809f59bbbab1af6/src/NodeCollection.php#L612-L625 | train |
grom358/pharborist | src/NodeCollection.php | NodeCollection.add | public function add($nodes) {
if ($nodes instanceof Node) {
$this->nodes[] = $nodes;
}
elseif ($nodes instanceof NodeCollection) {
$this->nodes = array_merge($this->nodes, $nodes->nodes);
}
elseif (is_array($nodes)) {
$this->nodes = array_merge($this->nodes, $nodes);
}
else {
throw new \InvalidArgumentException();
}
$this->nodes = static::sortUnique($this->nodes);
return $this;
} | php | public function add($nodes) {
if ($nodes instanceof Node) {
$this->nodes[] = $nodes;
}
elseif ($nodes instanceof NodeCollection) {
$this->nodes = array_merge($this->nodes, $nodes->nodes);
}
elseif (is_array($nodes)) {
$this->nodes = array_merge($this->nodes, $nodes);
}
else {
throw new \InvalidArgumentException();
}
$this->nodes = static::sortUnique($this->nodes);
return $this;
} | [
"public",
"function",
"add",
"(",
"$",
"nodes",
")",
"{",
"if",
"(",
"$",
"nodes",
"instanceof",
"Node",
")",
"{",
"$",
"this",
"->",
"nodes",
"[",
"]",
"=",
"$",
"nodes",
";",
"}",
"elseif",
"(",
"$",
"nodes",
"instanceof",
"NodeCollection",
")",
... | Add nodes to this collection.
@param Node|Node[]|NodeCollection $nodes Nodes to add to collection.
@return $this
@throws \InvalidArgumentException | [
"Add",
"nodes",
"to",
"this",
"collection",
"."
] | 0db9e51299a80e95b06857ed1809f59bbbab1af6 | https://github.com/grom358/pharborist/blob/0db9e51299a80e95b06857ed1809f59bbbab1af6/src/NodeCollection.php#L633-L648 | train |
GrahamCampbell/Analyzer | src/ImportVisitor.php | ImportVisitor.enterNode | public function enterNode(Node $node)
{
if ($node instanceof UseUse) {
$this->imports[] = $node->name->toString();
}
return $node;
} | php | public function enterNode(Node $node)
{
if ($node instanceof UseUse) {
$this->imports[] = $node->name->toString();
}
return $node;
} | [
"public",
"function",
"enterNode",
"(",
"Node",
"$",
"node",
")",
"{",
"if",
"(",
"$",
"node",
"instanceof",
"UseUse",
")",
"{",
"$",
"this",
"->",
"imports",
"[",
"]",
"=",
"$",
"node",
"->",
"name",
"->",
"toString",
"(",
")",
";",
"}",
"return",... | Enter the node and record the import.
@param \PhpParser\Node $node
@return \PhpParser\Node | [
"Enter",
"the",
"node",
"and",
"record",
"the",
"import",
"."
] | e918797f052c001362bda65e7364026910608bef | https://github.com/GrahamCampbell/Analyzer/blob/e918797f052c001362bda65e7364026910608bef/src/ImportVisitor.php#L53-L60 | train |
thelia/core | lib/Thelia/Command/HookCleanCommand.php | HookCleanCommand.deleteHooks | protected function deleteHooks($module)
{
$query = ModuleHookQuery::create();
if (null !== $module) {
$query
->filterByModule($module)
->delete();
} else {
$query->deleteAll();
}
$query = IgnoredModuleHookQuery::create();
if (null !== $module) {
$query
->filterByModule($module)
->delete();
} else {
$query->deleteAll();
}
} | php | protected function deleteHooks($module)
{
$query = ModuleHookQuery::create();
if (null !== $module) {
$query
->filterByModule($module)
->delete();
} else {
$query->deleteAll();
}
$query = IgnoredModuleHookQuery::create();
if (null !== $module) {
$query
->filterByModule($module)
->delete();
} else {
$query->deleteAll();
}
} | [
"protected",
"function",
"deleteHooks",
"(",
"$",
"module",
")",
"{",
"$",
"query",
"=",
"ModuleHookQuery",
"::",
"create",
"(",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"module",
")",
"{",
"$",
"query",
"->",
"filterByModule",
"(",
"$",
"module",
")",... | Delete module hooks
@param Module|null $module if specified it will only delete hooks related to this module.
@throws \Exception
@throws \Propel\Runtime\Exception\PropelException | [
"Delete",
"module",
"hooks"
] | 38fbe7d5046bad6c0af9ea7c686b4655e8d84e67 | https://github.com/thelia/core/blob/38fbe7d5046bad6c0af9ea7c686b4655e8d84e67/lib/Thelia/Command/HookCleanCommand.php#L122-L141 | train |
thelia/core | lib/Thelia/Form/BaseForm.php | BaseForm.getFormDefinedUrl | public function getFormDefinedUrl($parameterName, $default = null)
{
$formDefinedUrl = $this->form->get($parameterName)->getData();
if (empty($formDefinedUrl)) {
if ($default === null) {
$default = ConfigQuery::read('base_url', '/');
}
$formDefinedUrl = $default;
}
return URL::getInstance()->absoluteUrl($formDefinedUrl);
} | php | public function getFormDefinedUrl($parameterName, $default = null)
{
$formDefinedUrl = $this->form->get($parameterName)->getData();
if (empty($formDefinedUrl)) {
if ($default === null) {
$default = ConfigQuery::read('base_url', '/');
}
$formDefinedUrl = $default;
}
return URL::getInstance()->absoluteUrl($formDefinedUrl);
} | [
"public",
"function",
"getFormDefinedUrl",
"(",
"$",
"parameterName",
",",
"$",
"default",
"=",
"null",
")",
"{",
"$",
"formDefinedUrl",
"=",
"$",
"this",
"->",
"form",
"->",
"get",
"(",
"$",
"parameterName",
")",
"->",
"getData",
"(",
")",
";",
"if",
... | Build an absolute URL using the value of a form parameter.
@param string $parameterName the form parameter name
@param string $default a default value for the form parameter. If not defined, the configured base URL is used.
@return string an absolute URL | [
"Build",
"an",
"absolute",
"URL",
"using",
"the",
"value",
"of",
"a",
"form",
"parameter",
"."
] | 38fbe7d5046bad6c0af9ea7c686b4655e8d84e67 | https://github.com/thelia/core/blob/38fbe7d5046bad6c0af9ea7c686b4655e8d84e67/lib/Thelia/Form/BaseForm.php#L337-L350 | train |
thelia/core | lib/Thelia/Core/Template/Loop/Image.php | Image.findNextPrev | private function findNextPrev(LoopResultRow $loopResultRow, $imageId, $imageType, $currentPosition)
{
if ($imageType == 'product') {
$imageRow = ProductImageQuery::create()
->filterById($imageId)
->findOne();
if ($imageRow != null) {
$previousQuery = ProductImageQuery::create()
->filterByProductId($imageRow->getProductId())
->filterByPosition($currentPosition, Criteria::LESS_THAN);
$nextQuery = ProductImageQuery::create()
->filterByProductId($imageRow->getProductId())
->filterByPosition($currentPosition, Criteria::GREATER_THAN);
if (!$this->getBackendContext()) {
$previousQuery->useProductQuery()
->filterByVisible(true)
->endUse();
$previousQuery->useProductQuery()
->filterByVisible(true)
->endUse();
}
$previous = $previousQuery
->orderByPosition(Criteria::DESC)
->findOne();
$next = $nextQuery
->orderByPosition(Criteria::ASC)
->findOne();
$loopResultRow
->set("HAS_PREVIOUS", $previous != null ? 1 : 0)
->set("HAS_NEXT", $next != null ? 1 : 0)
->set("PREVIOUS", $previous != null ? $previous->getId() : -1)
->set("NEXT", $next != null ? $next->getId() : -1);
return;
}
}
$loopResultRow
->set("HAS_PREVIOUS", 0)
->set("HAS_NEXT", 0);
} | php | private function findNextPrev(LoopResultRow $loopResultRow, $imageId, $imageType, $currentPosition)
{
if ($imageType == 'product') {
$imageRow = ProductImageQuery::create()
->filterById($imageId)
->findOne();
if ($imageRow != null) {
$previousQuery = ProductImageQuery::create()
->filterByProductId($imageRow->getProductId())
->filterByPosition($currentPosition, Criteria::LESS_THAN);
$nextQuery = ProductImageQuery::create()
->filterByProductId($imageRow->getProductId())
->filterByPosition($currentPosition, Criteria::GREATER_THAN);
if (!$this->getBackendContext()) {
$previousQuery->useProductQuery()
->filterByVisible(true)
->endUse();
$previousQuery->useProductQuery()
->filterByVisible(true)
->endUse();
}
$previous = $previousQuery
->orderByPosition(Criteria::DESC)
->findOne();
$next = $nextQuery
->orderByPosition(Criteria::ASC)
->findOne();
$loopResultRow
->set("HAS_PREVIOUS", $previous != null ? 1 : 0)
->set("HAS_NEXT", $next != null ? 1 : 0)
->set("PREVIOUS", $previous != null ? $previous->getId() : -1)
->set("NEXT", $next != null ? $next->getId() : -1);
return;
}
}
$loopResultRow
->set("HAS_PREVIOUS", 0)
->set("HAS_NEXT", 0);
} | [
"private",
"function",
"findNextPrev",
"(",
"LoopResultRow",
"$",
"loopResultRow",
",",
"$",
"imageId",
",",
"$",
"imageType",
",",
"$",
"currentPosition",
")",
"{",
"if",
"(",
"$",
"imageType",
"==",
"'product'",
")",
"{",
"$",
"imageRow",
"=",
"ProductImag... | Set the fields HAS_PREVIOUS, HAS_NEXT, PREVIOUS, NEXT for the image loop
@param LoopResultRow $loopResultRow
@param int $imageId Image id
@param string $imageType Type of the image. Only 'product' is currently supported to get the NEXT and PREVIOUS values
@param int $currentPosition The position of the image | [
"Set",
"the",
"fields",
"HAS_PREVIOUS",
"HAS_NEXT",
"PREVIOUS",
"NEXT",
"for",
"the",
"image",
"loop"
] | 38fbe7d5046bad6c0af9ea7c686b4655e8d84e67 | https://github.com/thelia/core/blob/38fbe7d5046bad6c0af9ea7c686b4655e8d84e67/lib/Thelia/Core/Template/Loop/Image.php#L412-L459 | train |
thelia/core | lib/Thelia/Action/Brand.php | Brand.update | public function update(BrandUpdateEvent $event, $eventName, EventDispatcherInterface $dispatcher)
{
if (null !== $brand = BrandQuery::create()->findPk($event->getBrandId())) {
$brand->setDispatcher($dispatcher);
$brand
->setVisible($event->getVisible())
->setLogoImageId(\intval($event->getLogoImageId()) == 0 ? null : $event->getLogoImageId())
->setLocale($event->getLocale())
->setTitle($event->getTitle())
->setDescription($event->getDescription())
->setChapo($event->getChapo())
->setPostscriptum($event->getPostscriptum())
->save()
;
$event->setBrand($brand);
}
} | php | public function update(BrandUpdateEvent $event, $eventName, EventDispatcherInterface $dispatcher)
{
if (null !== $brand = BrandQuery::create()->findPk($event->getBrandId())) {
$brand->setDispatcher($dispatcher);
$brand
->setVisible($event->getVisible())
->setLogoImageId(\intval($event->getLogoImageId()) == 0 ? null : $event->getLogoImageId())
->setLocale($event->getLocale())
->setTitle($event->getTitle())
->setDescription($event->getDescription())
->setChapo($event->getChapo())
->setPostscriptum($event->getPostscriptum())
->save()
;
$event->setBrand($brand);
}
} | [
"public",
"function",
"update",
"(",
"BrandUpdateEvent",
"$",
"event",
",",
"$",
"eventName",
",",
"EventDispatcherInterface",
"$",
"dispatcher",
")",
"{",
"if",
"(",
"null",
"!==",
"$",
"brand",
"=",
"BrandQuery",
"::",
"create",
"(",
")",
"->",
"findPk",
... | process update brand
@param BrandUpdateEvent $event
@param $eventName
@param EventDispatcherInterface $dispatcher | [
"process",
"update",
"brand"
] | 38fbe7d5046bad6c0af9ea7c686b4655e8d84e67 | https://github.com/thelia/core/blob/38fbe7d5046bad6c0af9ea7c686b4655e8d84e67/lib/Thelia/Action/Brand.php#L58-L76 | train |
thelia/core | lib/Thelia/Action/Brand.php | Brand.toggleVisibility | public function toggleVisibility(BrandToggleVisibilityEvent $event, $eventName, EventDispatcherInterface $dispatcher)
{
$brand = $event->getBrand();
$brand
->setDispatcher($dispatcher)
->setVisible(!$brand->getVisible())
->save();
$event->setBrand($brand);
} | php | public function toggleVisibility(BrandToggleVisibilityEvent $event, $eventName, EventDispatcherInterface $dispatcher)
{
$brand = $event->getBrand();
$brand
->setDispatcher($dispatcher)
->setVisible(!$brand->getVisible())
->save();
$event->setBrand($brand);
} | [
"public",
"function",
"toggleVisibility",
"(",
"BrandToggleVisibilityEvent",
"$",
"event",
",",
"$",
"eventName",
",",
"EventDispatcherInterface",
"$",
"dispatcher",
")",
"{",
"$",
"brand",
"=",
"$",
"event",
"->",
"getBrand",
"(",
")",
";",
"$",
"brand",
"->"... | Toggle Brand visibility
@param BrandToggleVisibilityEvent $event
@param string $eventName
@param EventDispatcherInterface $dispatcher
@throws \Exception
@throws \Propel\Runtime\Exception\PropelException | [
"Toggle",
"Brand",
"visibility"
] | 38fbe7d5046bad6c0af9ea7c686b4655e8d84e67 | https://github.com/thelia/core/blob/38fbe7d5046bad6c0af9ea7c686b4655e8d84e67/lib/Thelia/Action/Brand.php#L87-L97 | train |
thelia/core | lib/Thelia/Action/Brand.php | Brand.viewCheck | public function viewCheck(ViewCheckEvent $event, $eventName, EventDispatcherInterface $dispatcher)
{
if ($event->getView() == 'brand') {
$brand = BrandQuery::create()
->filterById($event->getViewId())
->filterByVisible(1)
->count();
if ($brand == 0) {
$dispatcher->dispatch(TheliaEvents::VIEW_BRAND_ID_NOT_VISIBLE, $event);
}
}
} | php | public function viewCheck(ViewCheckEvent $event, $eventName, EventDispatcherInterface $dispatcher)
{
if ($event->getView() == 'brand') {
$brand = BrandQuery::create()
->filterById($event->getViewId())
->filterByVisible(1)
->count();
if ($brand == 0) {
$dispatcher->dispatch(TheliaEvents::VIEW_BRAND_ID_NOT_VISIBLE, $event);
}
}
} | [
"public",
"function",
"viewCheck",
"(",
"ViewCheckEvent",
"$",
"event",
",",
"$",
"eventName",
",",
"EventDispatcherInterface",
"$",
"dispatcher",
")",
"{",
"if",
"(",
"$",
"event",
"->",
"getView",
"(",
")",
"==",
"'brand'",
")",
"{",
"$",
"brand",
"=",
... | Check if is a brand view and if brand_id is visible
@param ViewCheckEvent $event
@param string $eventName
@param EventDispatcherInterface $dispatcher | [
"Check",
"if",
"is",
"a",
"brand",
"view",
"and",
"if",
"brand_id",
"is",
"visible"
] | 38fbe7d5046bad6c0af9ea7c686b4655e8d84e67 | https://github.com/thelia/core/blob/38fbe7d5046bad6c0af9ea7c686b4655e8d84e67/lib/Thelia/Action/Brand.php#L133-L145 | train |
nattreid/cms | src/Control/Dockbar/Dockbar.php | Dockbar.addLeftLink | public function addLeftLink(string $name, string $link = null, bool $ajax = false): Item
{
return $this->leftItems[] = new Item($name, [
'link' => $link ?? '#',
'ajax' => $ajax
]);
} | php | public function addLeftLink(string $name, string $link = null, bool $ajax = false): Item
{
return $this->leftItems[] = new Item($name, [
'link' => $link ?? '#',
'ajax' => $ajax
]);
} | [
"public",
"function",
"addLeftLink",
"(",
"string",
"$",
"name",
",",
"string",
"$",
"link",
"=",
"null",
",",
"bool",
"$",
"ajax",
"=",
"false",
")",
":",
"Item",
"{",
"return",
"$",
"this",
"->",
"leftItems",
"[",
"]",
"=",
"new",
"Item",
"(",
"$... | Prida link do dockbaru vlevo
@param string $name
@param string $link
@param bool $ajax
@return Item | [
"Prida",
"link",
"do",
"dockbaru",
"vlevo"
] | 28eae564c6a8cdaf01d32ff5a1dffba58232f9c1 | https://github.com/nattreid/cms/blob/28eae564c6a8cdaf01d32ff5a1dffba58232f9c1/src/Control/Dockbar/Dockbar.php#L92-L98 | train |
nattreid/cms | src/Control/Dockbar/Dockbar.php | Dockbar.addRightLink | public function addRightLink(string $name, string $link = null, bool $ajax = false): Item
{
return $this->rightItems[] = new Item($name, [
'link' => $link ?? '#',
'ajax' => $ajax
]);
} | php | public function addRightLink(string $name, string $link = null, bool $ajax = false): Item
{
return $this->rightItems[] = new Item($name, [
'link' => $link ?? '#',
'ajax' => $ajax
]);
} | [
"public",
"function",
"addRightLink",
"(",
"string",
"$",
"name",
",",
"string",
"$",
"link",
"=",
"null",
",",
"bool",
"$",
"ajax",
"=",
"false",
")",
":",
"Item",
"{",
"return",
"$",
"this",
"->",
"rightItems",
"[",
"]",
"=",
"new",
"Item",
"(",
... | Prida link do dockbaru vpravo
@param string $name
@param string $link
@param bool $ajax
@return Item | [
"Prida",
"link",
"do",
"dockbaru",
"vpravo"
] | 28eae564c6a8cdaf01d32ff5a1dffba58232f9c1 | https://github.com/nattreid/cms/blob/28eae564c6a8cdaf01d32ff5a1dffba58232f9c1/src/Control/Dockbar/Dockbar.php#L107-L113 | train |
nattreid/cms | src/Control/Dockbar/Dockbar.php | Dockbar.isLinkAllowed | public function isLinkAllowed(string $link): bool
{
if (isset($this->allowedLinks[$link])) {
return true;
} else {
$pos = strrpos($link, ':');
$link = substr($link, 0, ($pos + 1));
return isset($this->allowedLinks[$link]);
}
} | php | public function isLinkAllowed(string $link): bool
{
if (isset($this->allowedLinks[$link])) {
return true;
} else {
$pos = strrpos($link, ':');
$link = substr($link, 0, ($pos + 1));
return isset($this->allowedLinks[$link]);
}
} | [
"public",
"function",
"isLinkAllowed",
"(",
"string",
"$",
"link",
")",
":",
"bool",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"allowedLinks",
"[",
"$",
"link",
"]",
")",
")",
"{",
"return",
"true",
";",
"}",
"else",
"{",
"$",
"pos",
"=",
... | Ma opravneni zobrazit stranku?
@param string $link
@return bool | [
"Ma",
"opravneni",
"zobrazit",
"stranku?"
] | 28eae564c6a8cdaf01d32ff5a1dffba58232f9c1 | https://github.com/nattreid/cms/blob/28eae564c6a8cdaf01d32ff5a1dffba58232f9c1/src/Control/Dockbar/Dockbar.php#L292-L301 | train |
nattreid/cms | src/Control/Dockbar/Dockbar.php | Dockbar.checkHandlerPermission | private function checkHandlerPermission(bool $ajax = true): void
{
if (!isset($this->allowedHandler[$this->presenter->getSignal()[1]])) {
$this->presenter->terminate();
}
if ($ajax && !$this->presenter->isAjax()) {
$this->presenter->terminate();
}
} | php | private function checkHandlerPermission(bool $ajax = true): void
{
if (!isset($this->allowedHandler[$this->presenter->getSignal()[1]])) {
$this->presenter->terminate();
}
if ($ajax && !$this->presenter->isAjax()) {
$this->presenter->terminate();
}
} | [
"private",
"function",
"checkHandlerPermission",
"(",
"bool",
"$",
"ajax",
"=",
"true",
")",
":",
"void",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"allowedHandler",
"[",
"$",
"this",
"->",
"presenter",
"->",
"getSignal",
"(",
")",
"[",
"1"... | Zkontroluje opravneni a pokud je nema, ukonci aplikaci
@param bool $ajax
@throws AbortException | [
"Zkontroluje",
"opravneni",
"a",
"pokud",
"je",
"nema",
"ukonci",
"aplikaci"
] | 28eae564c6a8cdaf01d32ff5a1dffba58232f9c1 | https://github.com/nattreid/cms/blob/28eae564c6a8cdaf01d32ff5a1dffba58232f9c1/src/Control/Dockbar/Dockbar.php#L376-L384 | train |
thelia/core | lib/Thelia/Module/AbstractDeliveryModule.php | AbstractDeliveryModule.getAreaForCountry | public function getAreaForCountry(Country $country)
{
$area = null;
if (null !== $areaDeliveryModule = AreaDeliveryModuleQuery::create()->findByCountryAndModule(
$country,
$this->getModuleModel()
)) {
$area = $areaDeliveryModule->getArea();
}
return $area;
} | php | public function getAreaForCountry(Country $country)
{
$area = null;
if (null !== $areaDeliveryModule = AreaDeliveryModuleQuery::create()->findByCountryAndModule(
$country,
$this->getModuleModel()
)) {
$area = $areaDeliveryModule->getArea();
}
return $area;
} | [
"public",
"function",
"getAreaForCountry",
"(",
"Country",
"$",
"country",
")",
"{",
"$",
"area",
"=",
"null",
";",
"if",
"(",
"null",
"!==",
"$",
"areaDeliveryModule",
"=",
"AreaDeliveryModuleQuery",
"::",
"create",
"(",
")",
"->",
"findByCountryAndModule",
"... | Return the first area that matches the given country for the given module
@param Country $country
@param BaseModule $module
@return Area|null | [
"Return",
"the",
"first",
"area",
"that",
"matches",
"the",
"given",
"country",
"for",
"the",
"given",
"module"
] | 38fbe7d5046bad6c0af9ea7c686b4655e8d84e67 | https://github.com/thelia/core/blob/38fbe7d5046bad6c0af9ea7c686b4655e8d84e67/lib/Thelia/Module/AbstractDeliveryModule.php#L39-L51 | train |
grom358/pharborist | src/Functions/AnonymousFunctionNode.php | AnonymousFunctionNode.createLexicalVariables | protected function createLexicalVariables() {
if (!$this->hasLexicalVariables()) {
$this->lexicalUse = Token::_use();
$this->lexicalOpenParen = Token::openParen();
$this->lexicalVariables = new CommaListNode();
$this->lexicalCloseParen = Token::closeParen();
$this->closeParen->after([
Token::space(),
$this->lexicalUse,
Token::space(),
$this->lexicalOpenParen,
$this->lexicalVariables,
$this->lexicalCloseParen,
]);
}
} | php | protected function createLexicalVariables() {
if (!$this->hasLexicalVariables()) {
$this->lexicalUse = Token::_use();
$this->lexicalOpenParen = Token::openParen();
$this->lexicalVariables = new CommaListNode();
$this->lexicalCloseParen = Token::closeParen();
$this->closeParen->after([
Token::space(),
$this->lexicalUse,
Token::space(),
$this->lexicalOpenParen,
$this->lexicalVariables,
$this->lexicalCloseParen,
]);
}
} | [
"protected",
"function",
"createLexicalVariables",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasLexicalVariables",
"(",
")",
")",
"{",
"$",
"this",
"->",
"lexicalUse",
"=",
"Token",
"::",
"_use",
"(",
")",
";",
"$",
"this",
"->",
"lexicalOpenPar... | Creates an empty lexical variables list if it does not already exist. | [
"Creates",
"an",
"empty",
"lexical",
"variables",
"list",
"if",
"it",
"does",
"not",
"already",
"exist",
"."
] | 0db9e51299a80e95b06857ed1809f59bbbab1af6 | https://github.com/grom358/pharborist/blob/0db9e51299a80e95b06857ed1809f59bbbab1af6/src/Functions/AnonymousFunctionNode.php#L122-L137 | train |
thelia/core | lib/Thelia/Controller/Admin/ProductController.php | ProductController.loadRelatedAjaxTabAction | public function loadRelatedAjaxTabAction()
{
return $this->render(
'ajax/product-related-tab',
array(
'product_id' => $this->getRequest()->get('product_id', 0),
'folder_id' => $this->getRequest()->get('folder_id', 0),
'accessory_category_id' => $this->getRequest()->get('accessory_category_id', 0)
)
);
} | php | public function loadRelatedAjaxTabAction()
{
return $this->render(
'ajax/product-related-tab',
array(
'product_id' => $this->getRequest()->get('product_id', 0),
'folder_id' => $this->getRequest()->get('folder_id', 0),
'accessory_category_id' => $this->getRequest()->get('accessory_category_id', 0)
)
);
} | [
"public",
"function",
"loadRelatedAjaxTabAction",
"(",
")",
"{",
"return",
"$",
"this",
"->",
"render",
"(",
"'ajax/product-related-tab'",
",",
"array",
"(",
"'product_id'",
"=>",
"$",
"this",
"->",
"getRequest",
"(",
")",
"->",
"get",
"(",
"'product_id'",
","... | Related information ajax tab loading | [
"Related",
"information",
"ajax",
"tab",
"loading"
] | 38fbe7d5046bad6c0af9ea7c686b4655e8d84e67 | https://github.com/thelia/core/blob/38fbe7d5046bad6c0af9ea7c686b4655e8d84e67/lib/Thelia/Controller/Admin/ProductController.php#L124-L134 | train |
thelia/core | lib/Thelia/Controller/Admin/ProductController.php | ProductController.getVirtualDocumentListAjaxAction | public function getVirtualDocumentListAjaxAction($productId, $pseId)
{
$this->checkAuth(AdminResources::PRODUCT, array(), AccessManager::VIEW);
$this->checkXmlHttpRequest();
$selectedId = \intval(MetaDataQuery::getVal('virtual', MetaData::PSE_KEY, $pseId));
$documents = ProductDocumentQuery::create()
->filterByProductId($productId)
->filterByVisible(0)
->orderByPosition()
->find()
;
$results = [];
if (null !== $documents) {
/** @var ProductDocument $document */
foreach ($documents as $document) {
$results[] = [
'id' => $document->getId(),
'title' => $document->getTitle(),
'file' => $document->getFile(),
'selected' => ($document->getId() == $selectedId)
];
}
}
return $this->jsonResponse(json_encode($results));
} | php | public function getVirtualDocumentListAjaxAction($productId, $pseId)
{
$this->checkAuth(AdminResources::PRODUCT, array(), AccessManager::VIEW);
$this->checkXmlHttpRequest();
$selectedId = \intval(MetaDataQuery::getVal('virtual', MetaData::PSE_KEY, $pseId));
$documents = ProductDocumentQuery::create()
->filterByProductId($productId)
->filterByVisible(0)
->orderByPosition()
->find()
;
$results = [];
if (null !== $documents) {
/** @var ProductDocument $document */
foreach ($documents as $document) {
$results[] = [
'id' => $document->getId(),
'title' => $document->getTitle(),
'file' => $document->getFile(),
'selected' => ($document->getId() == $selectedId)
];
}
}
return $this->jsonResponse(json_encode($results));
} | [
"public",
"function",
"getVirtualDocumentListAjaxAction",
"(",
"$",
"productId",
",",
"$",
"pseId",
")",
"{",
"$",
"this",
"->",
"checkAuth",
"(",
"AdminResources",
"::",
"PRODUCT",
",",
"array",
"(",
")",
",",
"AccessManager",
"::",
"VIEW",
")",
";",
"$",
... | return a list of document which will be displayed in AJAX
@param $productId
@param $pseId
@return Response | [
"return",
"a",
"list",
"of",
"document",
"which",
"will",
"be",
"displayed",
"in",
"AJAX"
] | 38fbe7d5046bad6c0af9ea7c686b4655e8d84e67 | https://github.com/thelia/core/blob/38fbe7d5046bad6c0af9ea7c686b4655e8d84e67/lib/Thelia/Controller/Admin/ProductController.php#L551-L580 | train |
thelia/core | lib/Thelia/Controller/Admin/ProductController.php | ProductController.updateAccessoryPositionAction | public function updateAccessoryPositionAction()
{
$accessory = AccessoryQuery::create()->findPk($this->getRequest()->get('accessory_id', null));
return $this->genericUpdatePositionAction(
$accessory,
TheliaEvents::PRODUCT_UPDATE_ACCESSORY_POSITION
);
} | php | public function updateAccessoryPositionAction()
{
$accessory = AccessoryQuery::create()->findPk($this->getRequest()->get('accessory_id', null));
return $this->genericUpdatePositionAction(
$accessory,
TheliaEvents::PRODUCT_UPDATE_ACCESSORY_POSITION
);
} | [
"public",
"function",
"updateAccessoryPositionAction",
"(",
")",
"{",
"$",
"accessory",
"=",
"AccessoryQuery",
"::",
"create",
"(",
")",
"->",
"findPk",
"(",
"$",
"this",
"->",
"getRequest",
"(",
")",
"->",
"get",
"(",
"'accessory_id'",
",",
"null",
")",
"... | Update accessory position | [
"Update",
"accessory",
"position"
] | 38fbe7d5046bad6c0af9ea7c686b4655e8d84e67 | https://github.com/thelia/core/blob/38fbe7d5046bad6c0af9ea7c686b4655e8d84e67/lib/Thelia/Controller/Admin/ProductController.php#L743-L751 | train |
thelia/core | lib/Thelia/Controller/Admin/ProductController.php | ProductController.updateContentPositionAction | public function updateContentPositionAction()
{
$content = ProductAssociatedContentQuery::create()->findPk($this->getRequest()->get('content_id', null));
return $this->genericUpdatePositionAction(
$content,
TheliaEvents::PRODUCT_UPDATE_CONTENT_POSITION
);
} | php | public function updateContentPositionAction()
{
$content = ProductAssociatedContentQuery::create()->findPk($this->getRequest()->get('content_id', null));
return $this->genericUpdatePositionAction(
$content,
TheliaEvents::PRODUCT_UPDATE_CONTENT_POSITION
);
} | [
"public",
"function",
"updateContentPositionAction",
"(",
")",
"{",
"$",
"content",
"=",
"ProductAssociatedContentQuery",
"::",
"create",
"(",
")",
"->",
"findPk",
"(",
"$",
"this",
"->",
"getRequest",
"(",
")",
"->",
"get",
"(",
"'content_id'",
",",
"null",
... | Update related content position | [
"Update",
"related",
"content",
"position"
] | 38fbe7d5046bad6c0af9ea7c686b4655e8d84e67 | https://github.com/thelia/core/blob/38fbe7d5046bad6c0af9ea7c686b4655e8d84e67/lib/Thelia/Controller/Admin/ProductController.php#L756-L764 | train |
thelia/core | lib/Thelia/Controller/Admin/ProductController.php | ProductController.setProductTemplateAction | public function setProductTemplateAction($productId)
{
// Check current user authorization
if (null !== $response = $this->checkAuth($this->resourceCode, array(), AccessManager::UPDATE)) {
return $response;
}
$product = ProductQuery::create()->findPk($productId);
if ($product != null) {
$template_id = \intval($this->getRequest()->get('template_id', 0));
$this->dispatch(
TheliaEvents::PRODUCT_SET_TEMPLATE,
new ProductSetTemplateEvent($product, $template_id, $this->getCurrentEditionCurrency()->getId())
);
}
return $this->redirectToEditionTemplate();
} | php | public function setProductTemplateAction($productId)
{
// Check current user authorization
if (null !== $response = $this->checkAuth($this->resourceCode, array(), AccessManager::UPDATE)) {
return $response;
}
$product = ProductQuery::create()->findPk($productId);
if ($product != null) {
$template_id = \intval($this->getRequest()->get('template_id', 0));
$this->dispatch(
TheliaEvents::PRODUCT_SET_TEMPLATE,
new ProductSetTemplateEvent($product, $template_id, $this->getCurrentEditionCurrency()->getId())
);
}
return $this->redirectToEditionTemplate();
} | [
"public",
"function",
"setProductTemplateAction",
"(",
"$",
"productId",
")",
"{",
"// Check current user authorization",
"if",
"(",
"null",
"!==",
"$",
"response",
"=",
"$",
"this",
"->",
"checkAuth",
"(",
"$",
"this",
"->",
"resourceCode",
",",
"array",
"(",
... | Change product template for a given product.
@param int $productId
@return mixed|\Symfony\Component\HttpFoundation\Response | [
"Change",
"product",
"template",
"for",
"a",
"given",
"product",
"."
] | 38fbe7d5046bad6c0af9ea7c686b4655e8d84e67 | https://github.com/thelia/core/blob/38fbe7d5046bad6c0af9ea7c686b4655e8d84e67/lib/Thelia/Controller/Admin/ProductController.php#L772-L791 | train |
thelia/core | lib/Thelia/Controller/Admin/ProductController.php | ProductController.updateAttributesAndFeaturesAction | public function updateAttributesAndFeaturesAction($productId)
{
$product = ProductQuery::create()->findPk($productId);
if ($product != null) {
$featureTemplate = FeatureTemplateQuery::create()->filterByTemplateId($product->getTemplateId())->find();
if ($featureTemplate !== null) {
// Get all features for the template attached to this product
$allFeatures = FeatureQuery::create()
->filterByFeatureTemplate($featureTemplate)
->find();
$updatedFeatures = array();
// Update all features values, starting with feature av. values
$featureValues = $this->getRequest()->get('feature_value', array());
foreach ($featureValues as $featureId => $featureValueList) {
// Delete all features av. for this feature.
$event = new FeatureProductDeleteEvent($productId, $featureId);
$this->dispatch(TheliaEvents::PRODUCT_FEATURE_DELETE_VALUE, $event);
// Add then all selected values
foreach ($featureValueList as $featureValue) {
$event = new FeatureProductUpdateEvent($productId, $featureId, $featureValue);
$this->dispatch(TheliaEvents::PRODUCT_FEATURE_UPDATE_VALUE, $event);
}
$updatedFeatures[] = $featureId;
}
// Update then features text values
$featureTextValues = $this->getRequest()->get('feature_text_value', array());
foreach ($featureTextValues as $featureId => $featureValue) {
// Check if a FeatureProduct exists for this product and this feature (for another lang)
$freeTextFeatureProduct = FeatureProductQuery::create()
->filterByProductId($productId)
->filterByIsFreeText(true)
->findOneByFeatureId($featureId);
// If no corresponding FeatureProduct exists AND if the feature_text_value is empty, do nothing
if (\is_null($freeTextFeatureProduct) && empty($featureValue)) {
continue;
}
$event = new FeatureProductUpdateEvent($productId, $featureId, $featureValue, true);
$event->setLocale($this->getCurrentEditionLocale());
$this->dispatch(TheliaEvents::PRODUCT_FEATURE_UPDATE_VALUE, $event);
$updatedFeatures[] = $featureId;
}
// Delete features which don't have any values
/** @var Feature $feature */
foreach ($allFeatures as $feature) {
if (! \in_array($feature->getId(), $updatedFeatures)) {
$event = new FeatureProductDeleteEvent($productId, $feature->getId());
$this->dispatch(TheliaEvents::PRODUCT_FEATURE_DELETE_VALUE, $event);
}
}
}
}
// If we have to stay on the same page, do not redirect to the successUrl,
// just redirect to the edit page again.
if ($this->getRequest()->get('save_mode') == 'stay') {
return $this->redirectToEditionTemplate();
}
// Redirect to the category/product list
return $this->redirectToListTemplate();
} | php | public function updateAttributesAndFeaturesAction($productId)
{
$product = ProductQuery::create()->findPk($productId);
if ($product != null) {
$featureTemplate = FeatureTemplateQuery::create()->filterByTemplateId($product->getTemplateId())->find();
if ($featureTemplate !== null) {
// Get all features for the template attached to this product
$allFeatures = FeatureQuery::create()
->filterByFeatureTemplate($featureTemplate)
->find();
$updatedFeatures = array();
// Update all features values, starting with feature av. values
$featureValues = $this->getRequest()->get('feature_value', array());
foreach ($featureValues as $featureId => $featureValueList) {
// Delete all features av. for this feature.
$event = new FeatureProductDeleteEvent($productId, $featureId);
$this->dispatch(TheliaEvents::PRODUCT_FEATURE_DELETE_VALUE, $event);
// Add then all selected values
foreach ($featureValueList as $featureValue) {
$event = new FeatureProductUpdateEvent($productId, $featureId, $featureValue);
$this->dispatch(TheliaEvents::PRODUCT_FEATURE_UPDATE_VALUE, $event);
}
$updatedFeatures[] = $featureId;
}
// Update then features text values
$featureTextValues = $this->getRequest()->get('feature_text_value', array());
foreach ($featureTextValues as $featureId => $featureValue) {
// Check if a FeatureProduct exists for this product and this feature (for another lang)
$freeTextFeatureProduct = FeatureProductQuery::create()
->filterByProductId($productId)
->filterByIsFreeText(true)
->findOneByFeatureId($featureId);
// If no corresponding FeatureProduct exists AND if the feature_text_value is empty, do nothing
if (\is_null($freeTextFeatureProduct) && empty($featureValue)) {
continue;
}
$event = new FeatureProductUpdateEvent($productId, $featureId, $featureValue, true);
$event->setLocale($this->getCurrentEditionLocale());
$this->dispatch(TheliaEvents::PRODUCT_FEATURE_UPDATE_VALUE, $event);
$updatedFeatures[] = $featureId;
}
// Delete features which don't have any values
/** @var Feature $feature */
foreach ($allFeatures as $feature) {
if (! \in_array($feature->getId(), $updatedFeatures)) {
$event = new FeatureProductDeleteEvent($productId, $feature->getId());
$this->dispatch(TheliaEvents::PRODUCT_FEATURE_DELETE_VALUE, $event);
}
}
}
}
// If we have to stay on the same page, do not redirect to the successUrl,
// just redirect to the edit page again.
if ($this->getRequest()->get('save_mode') == 'stay') {
return $this->redirectToEditionTemplate();
}
// Redirect to the category/product list
return $this->redirectToListTemplate();
} | [
"public",
"function",
"updateAttributesAndFeaturesAction",
"(",
"$",
"productId",
")",
"{",
"$",
"product",
"=",
"ProductQuery",
"::",
"create",
"(",
")",
"->",
"findPk",
"(",
"$",
"productId",
")",
";",
"if",
"(",
"$",
"product",
"!=",
"null",
")",
"{",
... | Update product attributes and features
@param int $productId
@return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
@throws \Propel\Runtime\Exception\PropelException | [
"Update",
"product",
"attributes",
"and",
"features"
] | 38fbe7d5046bad6c0af9ea7c686b4655e8d84e67 | https://github.com/thelia/core/blob/38fbe7d5046bad6c0af9ea7c686b4655e8d84e67/lib/Thelia/Controller/Admin/ProductController.php#L801-L878 | train |
thelia/core | lib/Thelia/Controller/Admin/ProductController.php | ProductController.processSingleProductSaleElementUpdate | protected function processSingleProductSaleElementUpdate($data)
{
$event = new ProductSaleElementUpdateEvent(
$this->getExistingObject(),
$data['product_sale_element_id']
);
$event
->setReference($data['reference'])
->setPrice($data['price'])
->setCurrencyId($data['currency'])
->setWeight($data['weight'])
->setQuantity($data['quantity'])
->setSalePrice($data['sale_price'])
->setOnsale($data['onsale'])
->setIsnew($data['isnew'])
->setIsdefault($data['isdefault'])
->setEanCode($data['ean_code'])
->setTaxRuleId($data['tax_rule'])
->setFromDefaultCurrency($data['use_exchange_rate'])
;
$this->dispatch(TheliaEvents::PRODUCT_UPDATE_PRODUCT_SALE_ELEMENT, $event);
// Log object modification
if (null !== $changedObject = $event->getProductSaleElement()) {
$this->adminLogAppend(
$this->resourceCode,
AccessManager::UPDATE,
sprintf(
"Product Sale Element (ID %s) for product reference %s modified",
$changedObject->getId(),
$event->getProduct()->getRef()
),
$changedObject->getId()
);
}
} | php | protected function processSingleProductSaleElementUpdate($data)
{
$event = new ProductSaleElementUpdateEvent(
$this->getExistingObject(),
$data['product_sale_element_id']
);
$event
->setReference($data['reference'])
->setPrice($data['price'])
->setCurrencyId($data['currency'])
->setWeight($data['weight'])
->setQuantity($data['quantity'])
->setSalePrice($data['sale_price'])
->setOnsale($data['onsale'])
->setIsnew($data['isnew'])
->setIsdefault($data['isdefault'])
->setEanCode($data['ean_code'])
->setTaxRuleId($data['tax_rule'])
->setFromDefaultCurrency($data['use_exchange_rate'])
;
$this->dispatch(TheliaEvents::PRODUCT_UPDATE_PRODUCT_SALE_ELEMENT, $event);
// Log object modification
if (null !== $changedObject = $event->getProductSaleElement()) {
$this->adminLogAppend(
$this->resourceCode,
AccessManager::UPDATE,
sprintf(
"Product Sale Element (ID %s) for product reference %s modified",
$changedObject->getId(),
$event->getProduct()->getRef()
),
$changedObject->getId()
);
}
} | [
"protected",
"function",
"processSingleProductSaleElementUpdate",
"(",
"$",
"data",
")",
"{",
"$",
"event",
"=",
"new",
"ProductSaleElementUpdateEvent",
"(",
"$",
"this",
"->",
"getExistingObject",
"(",
")",
",",
"$",
"data",
"[",
"'product_sale_element_id'",
"]",
... | Process a single PSE update, using form data array.
@param array $data the form data | [
"Process",
"a",
"single",
"PSE",
"update",
"using",
"form",
"data",
"array",
"."
] | 38fbe7d5046bad6c0af9ea7c686b4655e8d84e67 | https://github.com/thelia/core/blob/38fbe7d5046bad6c0af9ea7c686b4655e8d84e67/lib/Thelia/Controller/Admin/ProductController.php#L1061-L1098 | train |
thelia/core | lib/Thelia/Controller/Admin/ProductController.php | ProductController.processProductSaleElementUpdate | protected function processProductSaleElementUpdate($changeForm)
{
// Check current user authorization
if (null !== $response = $this->checkAuth($this->resourceCode, array(), AccessManager::UPDATE)) {
return $response;
}
try {
// Check the form against constraints violations
$form = $this->validateForm($changeForm, "POST");
// Get the form field values
$data = $form->getData();
if (\is_array($data['product_sale_element_id'])) {
// Common fields
$tmp_data = array(
'tax_rule' => $data['tax_rule'],
'currency' => $data['currency'],
'use_exchange_rate' => $data['use_exchange_rate'],
);
$count = \count($data['product_sale_element_id']);
for ($idx = 0; $idx < $count; $idx++) {
$tmp_data['product_sale_element_id'] = $pse_id = $data['product_sale_element_id'][$idx];
$tmp_data['reference'] = $data['reference'][$idx];
$tmp_data['price'] = $data['price'][$idx];
$tmp_data['weight'] = $data['weight'][$idx];
$tmp_data['quantity'] = $data['quantity'][$idx];
$tmp_data['sale_price'] = $data['sale_price'][$idx];
$tmp_data['onsale'] = isset($data['onsale'][$idx]) ? 1 : 0;
$tmp_data['isnew'] = isset($data['isnew'][$idx]) ? 1 : 0;
$tmp_data['isdefault'] = $data['default_pse'] == $pse_id;
$tmp_data['ean_code'] = $data['ean_code'][$idx];
$this->processSingleProductSaleElementUpdate($tmp_data);
}
} else {
// No need to preprocess data
$this->processSingleProductSaleElementUpdate($data);
}
// If we have to stay on the same page, do not redirect to the successUrl, just redirect to the edit page again.
if ($this->getRequest()->get('save_mode') == 'stay') {
return $this->redirectToEditionTemplate();
}
// Redirect to the success URL
return $this->generateSuccessRedirect($changeForm);
} catch (FormValidationException $ex) {
// Form cannot be validated
$error_msg = $this->createStandardFormValidationErrorMessage($ex);
} catch (\Exception $ex) {
// Any other error
$error_msg = $ex->getMessage();
}
$this->setupFormErrorContext(
$this->getTranslator()->trans("ProductSaleElement modification"),
$error_msg,
$changeForm,
$ex
);
// At this point, the form has errors, and should be redisplayed.
return $this->renderEditionTemplate();
} | php | protected function processProductSaleElementUpdate($changeForm)
{
// Check current user authorization
if (null !== $response = $this->checkAuth($this->resourceCode, array(), AccessManager::UPDATE)) {
return $response;
}
try {
// Check the form against constraints violations
$form = $this->validateForm($changeForm, "POST");
// Get the form field values
$data = $form->getData();
if (\is_array($data['product_sale_element_id'])) {
// Common fields
$tmp_data = array(
'tax_rule' => $data['tax_rule'],
'currency' => $data['currency'],
'use_exchange_rate' => $data['use_exchange_rate'],
);
$count = \count($data['product_sale_element_id']);
for ($idx = 0; $idx < $count; $idx++) {
$tmp_data['product_sale_element_id'] = $pse_id = $data['product_sale_element_id'][$idx];
$tmp_data['reference'] = $data['reference'][$idx];
$tmp_data['price'] = $data['price'][$idx];
$tmp_data['weight'] = $data['weight'][$idx];
$tmp_data['quantity'] = $data['quantity'][$idx];
$tmp_data['sale_price'] = $data['sale_price'][$idx];
$tmp_data['onsale'] = isset($data['onsale'][$idx]) ? 1 : 0;
$tmp_data['isnew'] = isset($data['isnew'][$idx]) ? 1 : 0;
$tmp_data['isdefault'] = $data['default_pse'] == $pse_id;
$tmp_data['ean_code'] = $data['ean_code'][$idx];
$this->processSingleProductSaleElementUpdate($tmp_data);
}
} else {
// No need to preprocess data
$this->processSingleProductSaleElementUpdate($data);
}
// If we have to stay on the same page, do not redirect to the successUrl, just redirect to the edit page again.
if ($this->getRequest()->get('save_mode') == 'stay') {
return $this->redirectToEditionTemplate();
}
// Redirect to the success URL
return $this->generateSuccessRedirect($changeForm);
} catch (FormValidationException $ex) {
// Form cannot be validated
$error_msg = $this->createStandardFormValidationErrorMessage($ex);
} catch (\Exception $ex) {
// Any other error
$error_msg = $ex->getMessage();
}
$this->setupFormErrorContext(
$this->getTranslator()->trans("ProductSaleElement modification"),
$error_msg,
$changeForm,
$ex
);
// At this point, the form has errors, and should be redisplayed.
return $this->renderEditionTemplate();
} | [
"protected",
"function",
"processProductSaleElementUpdate",
"(",
"$",
"changeForm",
")",
"{",
"// Check current user authorization",
"if",
"(",
"null",
"!==",
"$",
"response",
"=",
"$",
"this",
"->",
"checkAuth",
"(",
"$",
"this",
"->",
"resourceCode",
",",
"array... | Change a product sale element
@param BaseForm $changeForm
@return mixed|null|\Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response|Response | [
"Change",
"a",
"product",
"sale",
"element"
] | 38fbe7d5046bad6c0af9ea7c686b4655e8d84e67 | https://github.com/thelia/core/blob/38fbe7d5046bad6c0af9ea7c686b4655e8d84e67/lib/Thelia/Controller/Admin/ProductController.php#L1107-L1174 | train |
thelia/core | lib/Thelia/Controller/Admin/ProductController.php | ProductController.buildCombinationsAction | public function buildCombinationsAction()
{
// Check current user authorization
if (null !== $response = $this->checkAuth($this->resourceCode, array(), AccessManager::UPDATE)) {
return $response;
}
$changeForm = $this->createForm(AdminForm::PRODUCT_COMBINATION_GENERATION);
try {
// Check the form against constraints violations
$form = $this->validateForm($changeForm, "POST");
// Get the form field values
$data = $form->getData();
// Rework attributes_av array, to build an array which contains all combinations,
// in the form combination[] = array of combination attributes av IDs
//
// First, create an array of attributes_av ID in the form $attributes_av_list[$attribute_id] = array of attributes_av ID
// from the list of attribute_id:attributes_av ID from the form.
$combinations = $attributes_av_list = $tmp = array();
foreach ($data['attribute_av'] as $item) {
list($attribute_id, $attribute_av_id) = explode(':', $item);
if (! isset($attributes_av_list[$attribute_id])) {
$attributes_av_list[$attribute_id] = array();
}
$attributes_av_list[$attribute_id][] = $attribute_av_id;
}
// Next, recursively combine array
$this->combine($attributes_av_list, $combinations, $tmp);
// Create event
$event = new ProductCombinationGenerationEvent(
$this->getExistingObject(),
$data['currency'],
$combinations
);
$event
->setReference($data['reference'] == null ? '' : $data['reference'])
->setPrice($data['price'] == null ? 0 : $data['price'])
->setWeight($data['weight'] == null ? 0 : $data['weight'])
->setQuantity($data['quantity'] == null ? 0 : $data['quantity'])
->setSalePrice($data['sale_price'] == null ? 0 : $data['sale_price'])
->setOnsale($data['onsale'] == null ? false : $data['onsale'])
->setIsnew($data['isnew'] == null ? false : $data['isnew'])
->setEanCode($data['ean_code'] == null ? '' : $data['ean_code'])
;
$this->dispatch(TheliaEvents::PRODUCT_COMBINATION_GENERATION, $event);
// Log object modification
$this->adminLogAppend(
$this->resourceCode,
AccessManager::CREATE,
sprintf(
"Combination generation for product reference %s",
$event->getProduct()->getRef()
),
$event->getProduct()->getId()
);
// Redirect to the success URL
return $this->generateSuccessRedirect($changeForm);
} catch (FormValidationException $ex) {
// Form cannot be validated
$error_msg = $this->createStandardFormValidationErrorMessage($ex);
} catch (\Exception $ex) {
// Any other error
$error_msg = $ex->getMessage();
}
$this->setupFormErrorContext(
$this->getTranslator()->trans("Combination builder"),
$error_msg,
$changeForm,
$ex
);
// At this point, the form has errors, and should be redisplayed.
return $this->renderEditionTemplate();
} | php | public function buildCombinationsAction()
{
// Check current user authorization
if (null !== $response = $this->checkAuth($this->resourceCode, array(), AccessManager::UPDATE)) {
return $response;
}
$changeForm = $this->createForm(AdminForm::PRODUCT_COMBINATION_GENERATION);
try {
// Check the form against constraints violations
$form = $this->validateForm($changeForm, "POST");
// Get the form field values
$data = $form->getData();
// Rework attributes_av array, to build an array which contains all combinations,
// in the form combination[] = array of combination attributes av IDs
//
// First, create an array of attributes_av ID in the form $attributes_av_list[$attribute_id] = array of attributes_av ID
// from the list of attribute_id:attributes_av ID from the form.
$combinations = $attributes_av_list = $tmp = array();
foreach ($data['attribute_av'] as $item) {
list($attribute_id, $attribute_av_id) = explode(':', $item);
if (! isset($attributes_av_list[$attribute_id])) {
$attributes_av_list[$attribute_id] = array();
}
$attributes_av_list[$attribute_id][] = $attribute_av_id;
}
// Next, recursively combine array
$this->combine($attributes_av_list, $combinations, $tmp);
// Create event
$event = new ProductCombinationGenerationEvent(
$this->getExistingObject(),
$data['currency'],
$combinations
);
$event
->setReference($data['reference'] == null ? '' : $data['reference'])
->setPrice($data['price'] == null ? 0 : $data['price'])
->setWeight($data['weight'] == null ? 0 : $data['weight'])
->setQuantity($data['quantity'] == null ? 0 : $data['quantity'])
->setSalePrice($data['sale_price'] == null ? 0 : $data['sale_price'])
->setOnsale($data['onsale'] == null ? false : $data['onsale'])
->setIsnew($data['isnew'] == null ? false : $data['isnew'])
->setEanCode($data['ean_code'] == null ? '' : $data['ean_code'])
;
$this->dispatch(TheliaEvents::PRODUCT_COMBINATION_GENERATION, $event);
// Log object modification
$this->adminLogAppend(
$this->resourceCode,
AccessManager::CREATE,
sprintf(
"Combination generation for product reference %s",
$event->getProduct()->getRef()
),
$event->getProduct()->getId()
);
// Redirect to the success URL
return $this->generateSuccessRedirect($changeForm);
} catch (FormValidationException $ex) {
// Form cannot be validated
$error_msg = $this->createStandardFormValidationErrorMessage($ex);
} catch (\Exception $ex) {
// Any other error
$error_msg = $ex->getMessage();
}
$this->setupFormErrorContext(
$this->getTranslator()->trans("Combination builder"),
$error_msg,
$changeForm,
$ex
);
// At this point, the form has errors, and should be redisplayed.
return $this->renderEditionTemplate();
} | [
"public",
"function",
"buildCombinationsAction",
"(",
")",
"{",
"// Check current user authorization",
"if",
"(",
"null",
"!==",
"$",
"response",
"=",
"$",
"this",
"->",
"checkAuth",
"(",
"$",
"this",
"->",
"resourceCode",
",",
"array",
"(",
")",
",",
"AccessM... | Build combinations from the combination output builder | [
"Build",
"combinations",
"from",
"the",
"combination",
"output",
"builder"
] | 38fbe7d5046bad6c0af9ea7c686b4655e8d84e67 | https://github.com/thelia/core/blob/38fbe7d5046bad6c0af9ea7c686b4655e8d84e67/lib/Thelia/Controller/Admin/ProductController.php#L1219-L1305 | train |
thelia/core | lib/Thelia/Controller/Admin/ProductController.php | ProductController.priceCalculator | public function priceCalculator()
{
$return_price = 0;
$price = \floatval($this->getRequest()->query->get('price', 0));
$product_id = \intval($this->getRequest()->query->get('product_id', 0));
$action = $this->getRequest()->query->get('action', ''); // With ot without tax
$convert = \intval($this->getRequest()->query->get('convert_from_default_currency', 0));
if (null !== $product = ProductQuery::create()->findPk($product_id)) {
if ($action == 'to_tax') {
$return_price = $this->computePrice($price, 'without_tax', $product);
} elseif ($action == 'from_tax') {
$return_price = $this->computePrice($price, 'with_tax', $product);
} else {
$return_price = $price;
}
if ($convert != 0) {
$return_price = $price * Currency::getDefaultCurrency()->getRate();
}
}
return new JsonResponse(array('result' => $this->formatPrice($return_price)));
} | php | public function priceCalculator()
{
$return_price = 0;
$price = \floatval($this->getRequest()->query->get('price', 0));
$product_id = \intval($this->getRequest()->query->get('product_id', 0));
$action = $this->getRequest()->query->get('action', ''); // With ot without tax
$convert = \intval($this->getRequest()->query->get('convert_from_default_currency', 0));
if (null !== $product = ProductQuery::create()->findPk($product_id)) {
if ($action == 'to_tax') {
$return_price = $this->computePrice($price, 'without_tax', $product);
} elseif ($action == 'from_tax') {
$return_price = $this->computePrice($price, 'with_tax', $product);
} else {
$return_price = $price;
}
if ($convert != 0) {
$return_price = $price * Currency::getDefaultCurrency()->getRate();
}
}
return new JsonResponse(array('result' => $this->formatPrice($return_price)));
} | [
"public",
"function",
"priceCalculator",
"(",
")",
"{",
"$",
"return_price",
"=",
"0",
";",
"$",
"price",
"=",
"\\",
"floatval",
"(",
"$",
"this",
"->",
"getRequest",
"(",
")",
"->",
"query",
"->",
"get",
"(",
"'price'",
",",
"0",
")",
")",
";",
"$... | Invoked through Ajax; this method calculates the taxed price from the untaxed price, and vice versa.
@since version 2.2 | [
"Invoked",
"through",
"Ajax",
";",
"this",
"method",
"calculates",
"the",
"taxed",
"price",
"from",
"the",
"untaxed",
"price",
"and",
"vice",
"versa",
"."
] | 38fbe7d5046bad6c0af9ea7c686b4655e8d84e67 | https://github.com/thelia/core/blob/38fbe7d5046bad6c0af9ea7c686b4655e8d84e67/lib/Thelia/Controller/Admin/ProductController.php#L1311-L1335 | train |
thelia/core | lib/Thelia/Controller/Admin/ProductController.php | ProductController.loadConvertedPrices | public function loadConvertedPrices()
{
$product_sale_element_id = \intval($this->getRequest()->get('product_sale_element_id', 0));
$currency_id = \intval($this->getRequest()->get('currency_id', 0));
$price_with_tax = $price_without_tax = $sale_price_with_tax = $sale_price_without_tax = 0;
if (null !== $pse = ProductSaleElementsQuery::create()->findPk($product_sale_element_id)) {
if ($currency_id > 0
&&
$currency_id != Currency::getDefaultCurrency()->getId()
&&
null !== $currency = CurrencyQuery::create()->findPk($currency_id)) {
// Get the default currency price
$productPrice = ProductPriceQuery::create()
->filterByCurrency(Currency::getDefaultCurrency())
->filterByProductSaleElementsId($product_sale_element_id)
->findOne()
;
// Calculate the converted price
if (null !== $productPrice) {
$price_without_tax = $productPrice->getPrice() * $currency->getRate();
$sale_price_without_tax = $productPrice->getPromoPrice() * $currency->getRate();
}
}
if (null !== $product = $pse->getProduct()) {
$price_with_tax = $this->computePrice($price_without_tax, 'with_tax', $product);
$sale_price_with_tax = $this->computePrice($sale_price_without_tax, 'with_tax', $product);
}
}
return new JsonResponse(array(
'price_with_tax' => $this->formatPrice($price_with_tax),
'price_without_tax' => $this->formatPrice($price_without_tax),
'sale_price_with_tax' => $this->formatPrice($sale_price_with_tax),
'sale_price_without_tax' => $this->formatPrice($sale_price_without_tax)
));
} | php | public function loadConvertedPrices()
{
$product_sale_element_id = \intval($this->getRequest()->get('product_sale_element_id', 0));
$currency_id = \intval($this->getRequest()->get('currency_id', 0));
$price_with_tax = $price_without_tax = $sale_price_with_tax = $sale_price_without_tax = 0;
if (null !== $pse = ProductSaleElementsQuery::create()->findPk($product_sale_element_id)) {
if ($currency_id > 0
&&
$currency_id != Currency::getDefaultCurrency()->getId()
&&
null !== $currency = CurrencyQuery::create()->findPk($currency_id)) {
// Get the default currency price
$productPrice = ProductPriceQuery::create()
->filterByCurrency(Currency::getDefaultCurrency())
->filterByProductSaleElementsId($product_sale_element_id)
->findOne()
;
// Calculate the converted price
if (null !== $productPrice) {
$price_without_tax = $productPrice->getPrice() * $currency->getRate();
$sale_price_without_tax = $productPrice->getPromoPrice() * $currency->getRate();
}
}
if (null !== $product = $pse->getProduct()) {
$price_with_tax = $this->computePrice($price_without_tax, 'with_tax', $product);
$sale_price_with_tax = $this->computePrice($sale_price_without_tax, 'with_tax', $product);
}
}
return new JsonResponse(array(
'price_with_tax' => $this->formatPrice($price_with_tax),
'price_without_tax' => $this->formatPrice($price_without_tax),
'sale_price_with_tax' => $this->formatPrice($sale_price_with_tax),
'sale_price_without_tax' => $this->formatPrice($sale_price_without_tax)
));
} | [
"public",
"function",
"loadConvertedPrices",
"(",
")",
"{",
"$",
"product_sale_element_id",
"=",
"\\",
"intval",
"(",
"$",
"this",
"->",
"getRequest",
"(",
")",
"->",
"get",
"(",
"'product_sale_element_id'",
",",
"0",
")",
")",
";",
"$",
"currency_id",
"=",
... | Calculate all prices
@return \Symfony\Component\HttpFoundation\JsonResponse | [
"Calculate",
"all",
"prices"
] | 38fbe7d5046bad6c0af9ea7c686b4655e8d84e67 | https://github.com/thelia/core/blob/38fbe7d5046bad6c0af9ea7c686b4655e8d84e67/lib/Thelia/Controller/Admin/ProductController.php#L1380-L1419 | train |
grom358/pharborist | src/ExpressionParser.php | ExpressionParser.parse | public function parse($nodes, $filename = NULL) {
$this->nodes = $nodes;
$this->filename = $filename;
$this->position = 0;
$this->length = count($nodes);
$this->operators = [$this->sentinel];
$this->operands = [];
$this->E();
if ($this->next()) {
$next = $this->next();
throw new ParserException(
$this->filename,
$next->getLineNumber(),
$next->getColumnNumber(),
"invalid expression");
}
return self::arrayLast($this->operands);
} | php | public function parse($nodes, $filename = NULL) {
$this->nodes = $nodes;
$this->filename = $filename;
$this->position = 0;
$this->length = count($nodes);
$this->operators = [$this->sentinel];
$this->operands = [];
$this->E();
if ($this->next()) {
$next = $this->next();
throw new ParserException(
$this->filename,
$next->getLineNumber(),
$next->getColumnNumber(),
"invalid expression");
}
return self::arrayLast($this->operands);
} | [
"public",
"function",
"parse",
"(",
"$",
"nodes",
",",
"$",
"filename",
"=",
"NULL",
")",
"{",
"$",
"this",
"->",
"nodes",
"=",
"$",
"nodes",
";",
"$",
"this",
"->",
"filename",
"=",
"$",
"filename",
";",
"$",
"this",
"->",
"position",
"=",
"0",
... | Parse the expression nodes into a tree.
@param Node[] $nodes
Array of operands and operators
@param string $filename
Filename being parsed.
@return Node
@throws ParserException | [
"Parse",
"the",
"expression",
"nodes",
"into",
"a",
"tree",
"."
] | 0db9e51299a80e95b06857ed1809f59bbbab1af6 | https://github.com/grom358/pharborist/blob/0db9e51299a80e95b06857ed1809f59bbbab1af6/src/ExpressionParser.php#L76-L93 | train |
thelia/core | lib/Thelia/Controller/Admin/ConfigController.php | ConfigController.changeValuesAction | public function changeValuesAction()
{
// Check current user authorization
if (null !== $response = $this->checkAuth($this->resourceCode, array(), AccessManager::UPDATE)) {
return $response;
}
$variables = $this->getRequest()->get('variable', array());
// Process all changed variables
foreach ($variables as $id => $value) {
$event = new ConfigUpdateEvent($id);
$event->setValue($value);
$this->dispatch(TheliaEvents::CONFIG_SETVALUE, $event);
}
return $this->generateRedirectFromRoute('admin.configuration.variables.default');
} | php | public function changeValuesAction()
{
// Check current user authorization
if (null !== $response = $this->checkAuth($this->resourceCode, array(), AccessManager::UPDATE)) {
return $response;
}
$variables = $this->getRequest()->get('variable', array());
// Process all changed variables
foreach ($variables as $id => $value) {
$event = new ConfigUpdateEvent($id);
$event->setValue($value);
$this->dispatch(TheliaEvents::CONFIG_SETVALUE, $event);
}
return $this->generateRedirectFromRoute('admin.configuration.variables.default');
} | [
"public",
"function",
"changeValuesAction",
"(",
")",
"{",
"// Check current user authorization",
"if",
"(",
"null",
"!==",
"$",
"response",
"=",
"$",
"this",
"->",
"checkAuth",
"(",
"$",
"this",
"->",
"resourceCode",
",",
"array",
"(",
")",
",",
"AccessManage... | Change values modified directly from the variable list
@return \Thelia\Core\HttpFoundation\Response the response | [
"Change",
"values",
"modified",
"directly",
"from",
"the",
"variable",
"list"
] | 38fbe7d5046bad6c0af9ea7c686b4655e8d84e67 | https://github.com/thelia/core/blob/38fbe7d5046bad6c0af9ea7c686b4655e8d84e67/lib/Thelia/Controller/Admin/ConfigController.php#L186-L204 | train |
thelia/core | lib/Thelia/Coupon/Type/CouponAbstract.php | CouponAbstract.isExpired | public function isExpired()
{
$ret = true;
$now = new \DateTime();
if ($this->expirationDate > $now) {
$ret = false;
}
return $ret;
} | php | public function isExpired()
{
$ret = true;
$now = new \DateTime();
if ($this->expirationDate > $now) {
$ret = false;
}
return $ret;
} | [
"public",
"function",
"isExpired",
"(",
")",
"{",
"$",
"ret",
"=",
"true",
";",
"$",
"now",
"=",
"new",
"\\",
"DateTime",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"expirationDate",
">",
"$",
"now",
")",
"{",
"$",
"ret",
"=",
"false",
";",
"... | Check if the Coupon is already Expired
@return bool | [
"Check",
"if",
"the",
"Coupon",
"is",
"already",
"Expired"
] | 38fbe7d5046bad6c0af9ea7c686b4655e8d84e67 | https://github.com/thelia/core/blob/38fbe7d5046bad6c0af9ea7c686b4655e8d84e67/lib/Thelia/Coupon/Type/CouponAbstract.php#L364-L374 | train |
thelia/core | lib/Thelia/Coupon/Type/CouponAbstract.php | CouponAbstract.drawBackOfficeInputs | public function drawBackOfficeInputs()
{
return $this->facade->getParser()->render('coupon/type-fragments/remove-x.html', [
'label' => $this->getInputName(),
'fieldId' => self::AMOUNT_FIELD_NAME,
'fieldName' => $this->makeCouponFieldName(self::AMOUNT_FIELD_NAME),
'value' => $this->amount
]);
} | php | public function drawBackOfficeInputs()
{
return $this->facade->getParser()->render('coupon/type-fragments/remove-x.html', [
'label' => $this->getInputName(),
'fieldId' => self::AMOUNT_FIELD_NAME,
'fieldName' => $this->makeCouponFieldName(self::AMOUNT_FIELD_NAME),
'value' => $this->amount
]);
} | [
"public",
"function",
"drawBackOfficeInputs",
"(",
")",
"{",
"return",
"$",
"this",
"->",
"facade",
"->",
"getParser",
"(",
")",
"->",
"render",
"(",
"'coupon/type-fragments/remove-x.html'",
",",
"[",
"'label'",
"=>",
"$",
"this",
"->",
"getInputName",
"(",
")... | Draw the input displayed in the BackOffice
allowing Admin to set its Coupon effect
Override this method to do something useful
@return string HTML string | [
"Draw",
"the",
"input",
"displayed",
"in",
"the",
"BackOffice",
"allowing",
"Admin",
"to",
"set",
"its",
"Coupon",
"effect",
"Override",
"this",
"method",
"to",
"do",
"something",
"useful"
] | 38fbe7d5046bad6c0af9ea7c686b4655e8d84e67 | https://github.com/thelia/core/blob/38fbe7d5046bad6c0af9ea7c686b4655e8d84e67/lib/Thelia/Coupon/Type/CouponAbstract.php#L417-L425 | train |
thelia/core | lib/Thelia/Coupon/Type/CouponAbstract.php | CouponAbstract.getCouponFieldValue | protected function getCouponFieldValue($fieldName, $data, $defaultValue = null)
{
if (isset($data[self::COUPON_DATASET_NAME][$fieldName])) {
return $this->checkCouponFieldValue(
$fieldName,
$data[self::COUPON_DATASET_NAME][$fieldName]
);
} elseif (null !== $defaultValue) {
return $defaultValue;
} else {
throw new \InvalidArgumentException(sprintf("The coupon field name %s was not found in the coupon form", $fieldName));
}
} | php | protected function getCouponFieldValue($fieldName, $data, $defaultValue = null)
{
if (isset($data[self::COUPON_DATASET_NAME][$fieldName])) {
return $this->checkCouponFieldValue(
$fieldName,
$data[self::COUPON_DATASET_NAME][$fieldName]
);
} elseif (null !== $defaultValue) {
return $defaultValue;
} else {
throw new \InvalidArgumentException(sprintf("The coupon field name %s was not found in the coupon form", $fieldName));
}
} | [
"protected",
"function",
"getCouponFieldValue",
"(",
"$",
"fieldName",
",",
"$",
"data",
",",
"$",
"defaultValue",
"=",
"null",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"self",
"::",
"COUPON_DATASET_NAME",
"]",
"[",
"$",
"fieldName",
"]",
")"... | A helper to get the value of a standard field name
@param string $fieldName the field name
@param array $data the input form data (e.g. $form->getData())
@param mixed $defaultValue the default value if the field is not found.
@return mixed the input value, or the default one
@throws \InvalidArgumentException if the field is not found, and no default value has been defined. | [
"A",
"helper",
"to",
"get",
"the",
"value",
"of",
"a",
"standard",
"field",
"name"
] | 38fbe7d5046bad6c0af9ea7c686b4655e8d84e67 | https://github.com/thelia/core/blob/38fbe7d5046bad6c0af9ea7c686b4655e8d84e67/lib/Thelia/Coupon/Type/CouponAbstract.php#L454-L466 | train |
thelia/core | lib/Thelia/Coupon/Type/CouponAbstract.php | CouponAbstract.getEffects | public function getEffects($data)
{
$effects = [];
foreach ($this->getFieldList() as $fieldName) {
$effects[$fieldName] = $this->getCouponFieldValue($fieldName, $data);
}
return $effects;
} | php | public function getEffects($data)
{
$effects = [];
foreach ($this->getFieldList() as $fieldName) {
$effects[$fieldName] = $this->getCouponFieldValue($fieldName, $data);
}
return $effects;
} | [
"public",
"function",
"getEffects",
"(",
"$",
"data",
")",
"{",
"$",
"effects",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"getFieldList",
"(",
")",
"as",
"$",
"fieldName",
")",
"{",
"$",
"effects",
"[",
"$",
"fieldName",
"]",
"=",
"$",... | Create the effect array from the list of fields
@param array $data the input form data (e.g. $form->getData())
@return array a filedName => fieldValue array | [
"Create",
"the",
"effect",
"array",
"from",
"the",
"list",
"of",
"fields"
] | 38fbe7d5046bad6c0af9ea7c686b4655e8d84e67 | https://github.com/thelia/core/blob/38fbe7d5046bad6c0af9ea7c686b4655e8d84e67/lib/Thelia/Coupon/Type/CouponAbstract.php#L495-L504 | train |
thelia/core | lib/Thelia/Form/CustomerLogin.php | CustomerLogin.verifyAccount | public function verifyAccount($value, ExecutionContextInterface $context)
{
if ($value == 1) {
$data = $context->getRoot()->getData();
if (false === $data['password'] || (empty($data['password']) && '0' != $data['password'])) {
$context->getViolations()->add(new ConstraintViolation(
Translator::getInstance()->trans('This value should not be blank.'),
'account_password',
array(),
$context->getRoot(),
'children[password].data',
'propertyPath'
));
}
}
} | php | public function verifyAccount($value, ExecutionContextInterface $context)
{
if ($value == 1) {
$data = $context->getRoot()->getData();
if (false === $data['password'] || (empty($data['password']) && '0' != $data['password'])) {
$context->getViolations()->add(new ConstraintViolation(
Translator::getInstance()->trans('This value should not be blank.'),
'account_password',
array(),
$context->getRoot(),
'children[password].data',
'propertyPath'
));
}
}
} | [
"public",
"function",
"verifyAccount",
"(",
"$",
"value",
",",
"ExecutionContextInterface",
"$",
"context",
")",
"{",
"if",
"(",
"$",
"value",
"==",
"1",
")",
"{",
"$",
"data",
"=",
"$",
"context",
"->",
"getRoot",
"(",
")",
"->",
"getData",
"(",
")",
... | If the user select "Yes, I have a password", we check the password. | [
"If",
"the",
"user",
"select",
"Yes",
"I",
"have",
"a",
"password",
"we",
"check",
"the",
"password",
"."
] | 38fbe7d5046bad6c0af9ea7c686b4655e8d84e67 | https://github.com/thelia/core/blob/38fbe7d5046bad6c0af9ea7c686b4655e8d84e67/lib/Thelia/Form/CustomerLogin.php#L88-L103 | train |
thelia/core | lib/Thelia/Form/CustomerLogin.php | CustomerLogin.verifyExistingEmail | public function verifyExistingEmail($value, ExecutionContextInterface $context)
{
$data = $context->getRoot()->getData();
if ($data["account"] == 0) {
$customer = CustomerQuery::create()->findOneByEmail($value);
if ($customer) {
$context->addViolation(Translator::getInstance()->trans("A user already exists with this email address. Please login or if you've forgotten your password, go to Reset Your Password."));
}
}
} | php | public function verifyExistingEmail($value, ExecutionContextInterface $context)
{
$data = $context->getRoot()->getData();
if ($data["account"] == 0) {
$customer = CustomerQuery::create()->findOneByEmail($value);
if ($customer) {
$context->addViolation(Translator::getInstance()->trans("A user already exists with this email address. Please login or if you've forgotten your password, go to Reset Your Password."));
}
}
} | [
"public",
"function",
"verifyExistingEmail",
"(",
"$",
"value",
",",
"ExecutionContextInterface",
"$",
"context",
")",
"{",
"$",
"data",
"=",
"$",
"context",
"->",
"getRoot",
"(",
")",
"->",
"getData",
"(",
")",
";",
"if",
"(",
"$",
"data",
"[",
"\"accou... | If the user select "I'am a new customer", we make sure is email address does not exit in the database. | [
"If",
"the",
"user",
"select",
"I",
"am",
"a",
"new",
"customer",
"we",
"make",
"sure",
"is",
"email",
"address",
"does",
"not",
"exit",
"in",
"the",
"database",
"."
] | 38fbe7d5046bad6c0af9ea7c686b4655e8d84e67 | https://github.com/thelia/core/blob/38fbe7d5046bad6c0af9ea7c686b4655e8d84e67/lib/Thelia/Form/CustomerLogin.php#L108-L117 | train |
thelia/core | lib/Thelia/Action/Export.php | Export.exportChangePosition | public function exportChangePosition(UpdatePositionEvent $updatePositionEvent, $eventName, EventDispatcherInterface $dispatcher)
{
$this->handler->getExport($updatePositionEvent->getObjectId(), true);
$this->genericUpdatePosition(new ExportQuery, $updatePositionEvent, $dispatcher);
} | php | public function exportChangePosition(UpdatePositionEvent $updatePositionEvent, $eventName, EventDispatcherInterface $dispatcher)
{
$this->handler->getExport($updatePositionEvent->getObjectId(), true);
$this->genericUpdatePosition(new ExportQuery, $updatePositionEvent, $dispatcher);
} | [
"public",
"function",
"exportChangePosition",
"(",
"UpdatePositionEvent",
"$",
"updatePositionEvent",
",",
"$",
"eventName",
",",
"EventDispatcherInterface",
"$",
"dispatcher",
")",
"{",
"$",
"this",
"->",
"handler",
"->",
"getExport",
"(",
"$",
"updatePositionEvent",... | Handle export change position event
@param UpdatePositionEvent $updatePositionEvent
@param $eventName
@param EventDispatcherInterface $dispatcher | [
"Handle",
"export",
"change",
"position",
"event"
] | 38fbe7d5046bad6c0af9ea7c686b4655e8d84e67 | https://github.com/thelia/core/blob/38fbe7d5046bad6c0af9ea7c686b4655e8d84e67/lib/Thelia/Action/Export.php#L61-L65 | train |
thelia/core | lib/Thelia/Action/Export.php | Export.exportCategoryChangePosition | public function exportCategoryChangePosition(UpdatePositionEvent $updatePositionEvent, $eventName, EventDispatcherInterface $dispatcher)
{
$this->handler->getCategory($updatePositionEvent->getObjectId(), true);
$this->genericUpdatePosition(new ExportCategoryQuery, $updatePositionEvent, $dispatcher);
} | php | public function exportCategoryChangePosition(UpdatePositionEvent $updatePositionEvent, $eventName, EventDispatcherInterface $dispatcher)
{
$this->handler->getCategory($updatePositionEvent->getObjectId(), true);
$this->genericUpdatePosition(new ExportCategoryQuery, $updatePositionEvent, $dispatcher);
} | [
"public",
"function",
"exportCategoryChangePosition",
"(",
"UpdatePositionEvent",
"$",
"updatePositionEvent",
",",
"$",
"eventName",
",",
"EventDispatcherInterface",
"$",
"dispatcher",
")",
"{",
"$",
"this",
"->",
"handler",
"->",
"getCategory",
"(",
"$",
"updatePosit... | Handle export category change position event
@param UpdatePositionEvent $updatePositionEvent
@param $eventName
@param EventDispatcherInterface $dispatcher | [
"Handle",
"export",
"category",
"change",
"position",
"event"
] | 38fbe7d5046bad6c0af9ea7c686b4655e8d84e67 | https://github.com/thelia/core/blob/38fbe7d5046bad6c0af9ea7c686b4655e8d84e67/lib/Thelia/Action/Export.php#L74-L78 | train |
thelia/core | lib/Thelia/Model/ProductSaleElements.php | ProductSaleElements.getPricesByCurrency | public function getPricesByCurrency(Currency $currency, $discount = 0)
{
$defaultCurrency = Currency::getDefaultCurrency();
$productPrice = ProductPriceQuery::create()
->filterByProductSaleElementsId($this->getId())
->filterByCurrencyId($currency->getId())
->findOne();
if (null === $productPrice || $productPrice->getFromDefaultCurrency()) {
// need to calculate the prices based on the product prices for the default currency
$productPrice = ProductPriceQuery::create()
->filterByProductSaleElementsId($this->getId())
->filterByCurrencyId($defaultCurrency->getId())
->findOne();
if (null !== $productPrice) {
$price = $productPrice->getPrice() * $currency->getRate() / $defaultCurrency->getRate();
$promoPrice = $productPrice->getPromoPrice() * $currency->getRate() / $defaultCurrency->getRate();
} else {
throw new \RuntimeException('Cannot find product prices for currency id: `' . $currency->getId() . '`');
}
} else {
$price = $productPrice->getPrice();
$promoPrice = $productPrice->getPromoPrice();
}
if ($discount > 0) {
$price = $price * (1-($discount/100));
$promoPrice = $promoPrice * (1-($discount/100));
}
$productPriceTools = new ProductPriceTools($price, $promoPrice);
return $productPriceTools;
} | php | public function getPricesByCurrency(Currency $currency, $discount = 0)
{
$defaultCurrency = Currency::getDefaultCurrency();
$productPrice = ProductPriceQuery::create()
->filterByProductSaleElementsId($this->getId())
->filterByCurrencyId($currency->getId())
->findOne();
if (null === $productPrice || $productPrice->getFromDefaultCurrency()) {
// need to calculate the prices based on the product prices for the default currency
$productPrice = ProductPriceQuery::create()
->filterByProductSaleElementsId($this->getId())
->filterByCurrencyId($defaultCurrency->getId())
->findOne();
if (null !== $productPrice) {
$price = $productPrice->getPrice() * $currency->getRate() / $defaultCurrency->getRate();
$promoPrice = $productPrice->getPromoPrice() * $currency->getRate() / $defaultCurrency->getRate();
} else {
throw new \RuntimeException('Cannot find product prices for currency id: `' . $currency->getId() . '`');
}
} else {
$price = $productPrice->getPrice();
$promoPrice = $productPrice->getPromoPrice();
}
if ($discount > 0) {
$price = $price * (1-($discount/100));
$promoPrice = $promoPrice * (1-($discount/100));
}
$productPriceTools = new ProductPriceTools($price, $promoPrice);
return $productPriceTools;
} | [
"public",
"function",
"getPricesByCurrency",
"(",
"Currency",
"$",
"currency",
",",
"$",
"discount",
"=",
"0",
")",
"{",
"$",
"defaultCurrency",
"=",
"Currency",
"::",
"getDefaultCurrency",
"(",
")",
";",
"$",
"productPrice",
"=",
"ProductPriceQuery",
"::",
"c... | Get product prices for a specific currency.
When the currency is not the default currency, the product prices for this currency is :
- calculated according to the product price of the default currency. It happens when no product price exists for
the currency or when the `from_default_currency` flag is set to `true`
- set directly in the product price when `from_default_currency` is set to `false`
@param Currency $currency
@param int $discount
@return ProductPriceTools
@throws \RuntimeException
@throws PropelException | [
"Get",
"product",
"prices",
"for",
"a",
"specific",
"currency",
"."
] | 38fbe7d5046bad6c0af9ea7c686b4655e8d84e67 | https://github.com/thelia/core/blob/38fbe7d5046bad6c0af9ea7c686b4655e8d84e67/lib/Thelia/Model/ProductSaleElements.php#L96-L130 | train |
Webysther/composer-plugin-qa | src/Command/Lint/Lint.php | Lint.getAllFiles | public function getAllFiles($sources)
{
$files = array();
foreach ($sources as $source) {
if (!is_dir($source)) {
$files[] = $source;
continue;
}
$recursiveFiles = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($source)
);
foreach ($recursiveFiles as $file) {
if ($file->isDir()) {
continue;
}
$path = $file->getPathname();
$info = pathinfo(basename($path));
if (array_key_exists('extension', $info) && $info['extension'] == 'php') {
$files[] = $path;
}
}
}
return $files;
} | php | public function getAllFiles($sources)
{
$files = array();
foreach ($sources as $source) {
if (!is_dir($source)) {
$files[] = $source;
continue;
}
$recursiveFiles = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($source)
);
foreach ($recursiveFiles as $file) {
if ($file->isDir()) {
continue;
}
$path = $file->getPathname();
$info = pathinfo(basename($path));
if (array_key_exists('extension', $info) && $info['extension'] == 'php') {
$files[] = $path;
}
}
}
return $files;
} | [
"public",
"function",
"getAllFiles",
"(",
"$",
"sources",
")",
"{",
"$",
"files",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"sources",
"as",
"$",
"source",
")",
"{",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"source",
")",
")",
"{",
"$",
"files... | Check how of list is dir and find all files.
@param array $sources List of files/dirs
@return array List of files only | [
"Check",
"how",
"of",
"list",
"is",
"dir",
"and",
"find",
"all",
"files",
"."
] | 08d7a5a09eb22b55964c86fdbdd7d543ecec9318 | https://github.com/Webysther/composer-plugin-qa/blob/08d7a5a09eb22b55964c86fdbdd7d543ecec9318/src/Command/Lint/Lint.php#L119-L146 | train |
thelia/core | lib/Thelia/Core/Thelia.php | Thelia.addStandardModuleTemplatesToParserEnvironment | protected function addStandardModuleTemplatesToParserEnvironment($parser, $module)
{
$stdTpls = TemplateDefinition::getStandardTemplatesSubdirsIterator();
foreach ($stdTpls as $templateType => $templateSubdirName) {
$this->addModuleTemplateToParserEnvironment($parser, $module, $templateType, $templateSubdirName);
}
} | php | protected function addStandardModuleTemplatesToParserEnvironment($parser, $module)
{
$stdTpls = TemplateDefinition::getStandardTemplatesSubdirsIterator();
foreach ($stdTpls as $templateType => $templateSubdirName) {
$this->addModuleTemplateToParserEnvironment($parser, $module, $templateType, $templateSubdirName);
}
} | [
"protected",
"function",
"addStandardModuleTemplatesToParserEnvironment",
"(",
"$",
"parser",
",",
"$",
"module",
")",
"{",
"$",
"stdTpls",
"=",
"TemplateDefinition",
"::",
"getStandardTemplatesSubdirsIterator",
"(",
")",
";",
"foreach",
"(",
"$",
"stdTpls",
"as",
"... | Add all module's standard templates to the parser environment
@param Definition $parser the parser
@param Module $module the Module. | [
"Add",
"all",
"module",
"s",
"standard",
"templates",
"to",
"the",
"parser",
"environment"
] | 38fbe7d5046bad6c0af9ea7c686b4655e8d84e67 | https://github.com/thelia/core/blob/38fbe7d5046bad6c0af9ea7c686b4655e8d84e67/lib/Thelia/Core/Thelia.php#L188-L195 | train |
thelia/core | lib/Thelia/Core/Thelia.php | Thelia.addModuleTemplateToParserEnvironment | protected function addModuleTemplateToParserEnvironment($parser, $module, $templateType, $templateSubdirName)
{
// Get template path
$templateDirectory = $module->getAbsoluteTemplateDirectoryPath($templateSubdirName);
try {
$templateDirBrowser = new \DirectoryIterator($templateDirectory);
$code = ucfirst($module->getCode());
/* browse the directory */
foreach ($templateDirBrowser as $templateDirContent) {
/* is it a directory which is not . or .. ? */
if ($templateDirContent->isDir() && ! $templateDirContent->isDot()) {
$parser->addMethodCall(
'addTemplateDirectory',
array(
$templateType,
$templateDirContent->getFilename(),
$templateDirContent->getPathName(),
$code
)
);
}
}
} catch (\UnexpectedValueException $ex) {
// The directory does not exists, ignore it.
}
} | php | protected function addModuleTemplateToParserEnvironment($parser, $module, $templateType, $templateSubdirName)
{
// Get template path
$templateDirectory = $module->getAbsoluteTemplateDirectoryPath($templateSubdirName);
try {
$templateDirBrowser = new \DirectoryIterator($templateDirectory);
$code = ucfirst($module->getCode());
/* browse the directory */
foreach ($templateDirBrowser as $templateDirContent) {
/* is it a directory which is not . or .. ? */
if ($templateDirContent->isDir() && ! $templateDirContent->isDot()) {
$parser->addMethodCall(
'addTemplateDirectory',
array(
$templateType,
$templateDirContent->getFilename(),
$templateDirContent->getPathName(),
$code
)
);
}
}
} catch (\UnexpectedValueException $ex) {
// The directory does not exists, ignore it.
}
} | [
"protected",
"function",
"addModuleTemplateToParserEnvironment",
"(",
"$",
"parser",
",",
"$",
"module",
",",
"$",
"templateType",
",",
"$",
"templateSubdirName",
")",
"{",
"// Get template path",
"$",
"templateDirectory",
"=",
"$",
"module",
"->",
"getAbsoluteTemplat... | Add a module template directory to the parser environment
@param Definition $parser the parser
@param Module $module the Module.
@param string $templateType the template type (one of the TemplateDefinition type constants)
@param string $templateSubdirName the template subdirectory name (one of the TemplateDefinition::XXX_SUBDIR constants) | [
"Add",
"a",
"module",
"template",
"directory",
"to",
"the",
"parser",
"environment"
] | 38fbe7d5046bad6c0af9ea7c686b4655e8d84e67 | https://github.com/thelia/core/blob/38fbe7d5046bad6c0af9ea7c686b4655e8d84e67/lib/Thelia/Core/Thelia.php#L205-L232 | train |
thelia/core | lib/Thelia/Action/Folder.php | Folder.viewCheck | public function viewCheck(ViewCheckEvent $event, $eventName, EventDispatcherInterface $dispatcher)
{
if ($event->getView() == 'folder') {
$folder = FolderQuery::create()
->filterById($event->getViewId())
->filterByVisible(1)
->count();
if ($folder == 0) {
$dispatcher->dispatch(TheliaEvents::VIEW_FOLDER_ID_NOT_VISIBLE, $event);
}
}
} | php | public function viewCheck(ViewCheckEvent $event, $eventName, EventDispatcherInterface $dispatcher)
{
if ($event->getView() == 'folder') {
$folder = FolderQuery::create()
->filterById($event->getViewId())
->filterByVisible(1)
->count();
if ($folder == 0) {
$dispatcher->dispatch(TheliaEvents::VIEW_FOLDER_ID_NOT_VISIBLE, $event);
}
}
} | [
"public",
"function",
"viewCheck",
"(",
"ViewCheckEvent",
"$",
"event",
",",
"$",
"eventName",
",",
"EventDispatcherInterface",
"$",
"dispatcher",
")",
"{",
"if",
"(",
"$",
"event",
"->",
"getView",
"(",
")",
"==",
"'folder'",
")",
"{",
"$",
"folder",
"=",... | Check if is a folder view and if folder_id is visible
@param ViewCheckEvent $event
@param string $eventName
@param EventDispatcherInterface $dispatcher | [
"Check",
"if",
"is",
"a",
"folder",
"view",
"and",
"if",
"folder_id",
"is",
"visible"
] | 38fbe7d5046bad6c0af9ea7c686b4655e8d84e67 | https://github.com/thelia/core/blob/38fbe7d5046bad6c0af9ea7c686b4655e8d84e67/lib/Thelia/Action/Folder.php#L167-L179 | train |
nattreid/cms | src/LocaleService.php | LocaleService.setDefault | protected function setDefault(int $localeId): void
{
$this->orm->locales->getById($localeId)->setDefault();
} | php | protected function setDefault(int $localeId): void
{
$this->orm->locales->getById($localeId)->setDefault();
} | [
"protected",
"function",
"setDefault",
"(",
"int",
"$",
"localeId",
")",
":",
"void",
"{",
"$",
"this",
"->",
"orm",
"->",
"locales",
"->",
"getById",
"(",
"$",
"localeId",
")",
"->",
"setDefault",
"(",
")",
";",
"}"
] | Nastavi vychozi jazyk
@param int $localeId | [
"Nastavi",
"vychozi",
"jazyk"
] | 28eae564c6a8cdaf01d32ff5a1dffba58232f9c1 | https://github.com/nattreid/cms/blob/28eae564c6a8cdaf01d32ff5a1dffba58232f9c1/src/LocaleService.php#L123-L126 | train |
nattreid/cms | src/LocaleService.php | LocaleService.setAllowed | protected function setAllowed(array $allowed): void
{
$locales = $this->orm->locales->findAll();
foreach ($locales as $locale) {
/* @var $locale Locale */
if (in_array($locale->id, $allowed)) {
$locale->allowed = true;
} else {
$locale->allowed = false;
}
$this->orm->persist($locale);
}
$this->orm->flush();
} | php | protected function setAllowed(array $allowed): void
{
$locales = $this->orm->locales->findAll();
foreach ($locales as $locale) {
/* @var $locale Locale */
if (in_array($locale->id, $allowed)) {
$locale->allowed = true;
} else {
$locale->allowed = false;
}
$this->orm->persist($locale);
}
$this->orm->flush();
} | [
"protected",
"function",
"setAllowed",
"(",
"array",
"$",
"allowed",
")",
":",
"void",
"{",
"$",
"locales",
"=",
"$",
"this",
"->",
"orm",
"->",
"locales",
"->",
"findAll",
"(",
")",
";",
"foreach",
"(",
"$",
"locales",
"as",
"$",
"locale",
")",
"{",... | Nastavi povolene jazyky
@param int[] $allowed | [
"Nastavi",
"povolene",
"jazyky"
] | 28eae564c6a8cdaf01d32ff5a1dffba58232f9c1 | https://github.com/nattreid/cms/blob/28eae564c6a8cdaf01d32ff5a1dffba58232f9c1/src/LocaleService.php#L132-L145 | train |
thelia/core | lib/Thelia/Controller/Admin/TranslationsController.php | TranslationsController.checkWritableI18nDirectory | public function checkWritableI18nDirectory($dir)
{
if (file_exists($dir)) {
return is_writable($dir);
}
$parentDir = dirname($dir);
return file_exists($parentDir) && is_writable($parentDir);
} | php | public function checkWritableI18nDirectory($dir)
{
if (file_exists($dir)) {
return is_writable($dir);
}
$parentDir = dirname($dir);
return file_exists($parentDir) && is_writable($parentDir);
} | [
"public",
"function",
"checkWritableI18nDirectory",
"(",
"$",
"dir",
")",
"{",
"if",
"(",
"file_exists",
"(",
"$",
"dir",
")",
")",
"{",
"return",
"is_writable",
"(",
"$",
"dir",
")",
";",
"}",
"$",
"parentDir",
"=",
"dirname",
"(",
"$",
"dir",
")",
... | Check if a directory is writable or if the parent directory is writable
@param string $dir the directory to test
@return boolean return true if the directory is writable otr if the parent dir is writable. | [
"Check",
"if",
"a",
"directory",
"is",
"writable",
"or",
"if",
"the",
"parent",
"directory",
"is",
"writable"
] | 38fbe7d5046bad6c0af9ea7c686b4655e8d84e67 | https://github.com/thelia/core/blob/38fbe7d5046bad6c0af9ea7c686b4655e8d84e67/lib/Thelia/Controller/Admin/TranslationsController.php#L314-L323 | train |
NotifyMeHQ/notifyme | src/Adapters/Hipchat/HipchatFactory.php | HipchatFactory.make | public function make(array $config)
{
Arr::requires($config, ['token']);
$client = new Client();
return new HipchatGateway($client, $config);
} | php | public function make(array $config)
{
Arr::requires($config, ['token']);
$client = new Client();
return new HipchatGateway($client, $config);
} | [
"public",
"function",
"make",
"(",
"array",
"$",
"config",
")",
"{",
"Arr",
"::",
"requires",
"(",
"$",
"config",
",",
"[",
"'token'",
"]",
")",
";",
"$",
"client",
"=",
"new",
"Client",
"(",
")",
";",
"return",
"new",
"HipchatGateway",
"(",
"$",
"... | Create a new hipchat gateway instance.
@param string[] $config
@return \NotifyMeHQ\Adapters\Hipchat\HipchatGateway | [
"Create",
"a",
"new",
"hipchat",
"gateway",
"instance",
"."
] | 2af4bdcfe9df6db7ea79e2dce90b106ccb285b06 | https://github.com/NotifyMeHQ/notifyme/blob/2af4bdcfe9df6db7ea79e2dce90b106ccb285b06/src/Adapters/Hipchat/HipchatFactory.php#L27-L34 | train |
NotifyMeHQ/notifyme | src/Adapters/Ballou/BallouGateway.php | BallouGateway.parse | protected function parse($body)
{
$disableEntities = libxml_disable_entity_loader(true);
$internalErrors = libxml_use_internal_errors(true);
try {
$xml = new SimpleXMLElement((string) $body ?: '<root />', LIBXML_NONET);
return json_decode(json_encode($xml), true);
} catch (Exception $e) {
//
} catch (Throwable $e) {
//
} finally {
libxml_disable_entity_loader($disableEntities);
libxml_use_internal_errors($internalErrors);
}
} | php | protected function parse($body)
{
$disableEntities = libxml_disable_entity_loader(true);
$internalErrors = libxml_use_internal_errors(true);
try {
$xml = new SimpleXMLElement((string) $body ?: '<root />', LIBXML_NONET);
return json_decode(json_encode($xml), true);
} catch (Exception $e) {
//
} catch (Throwable $e) {
//
} finally {
libxml_disable_entity_loader($disableEntities);
libxml_use_internal_errors($internalErrors);
}
} | [
"protected",
"function",
"parse",
"(",
"$",
"body",
")",
"{",
"$",
"disableEntities",
"=",
"libxml_disable_entity_loader",
"(",
"true",
")",
";",
"$",
"internalErrors",
"=",
"libxml_use_internal_errors",
"(",
"true",
")",
";",
"try",
"{",
"$",
"xml",
"=",
"n... | Parse an xml string to an array.
@param string $body
@return array | [
"Parse",
"an",
"xml",
"string",
"to",
"an",
"array",
"."
] | 2af4bdcfe9df6db7ea79e2dce90b106ccb285b06 | https://github.com/NotifyMeHQ/notifyme/blob/2af4bdcfe9df6db7ea79e2dce90b106ccb285b06/src/Adapters/Ballou/BallouGateway.php#L115-L132 | train |
thelia/core | lib/Thelia/Model/Country.php | Country.getZipCodeRE | public function getZipCodeRE()
{
$zipCodeFormat = $this->getZipCodeFormat();
if (empty($zipCodeFormat)) {
return null;
}
$zipCodeRE = preg_replace("/\\s+/", ' ', $zipCodeFormat);
$trans = [
"N" => "\\d",
"L" => "[a-zA-Z]",
"C" => ".+",
" " => " +"
];
$zipCodeRE = "#^" . strtr($zipCodeRE, $trans) . "$#";
return $zipCodeRE;
} | php | public function getZipCodeRE()
{
$zipCodeFormat = $this->getZipCodeFormat();
if (empty($zipCodeFormat)) {
return null;
}
$zipCodeRE = preg_replace("/\\s+/", ' ', $zipCodeFormat);
$trans = [
"N" => "\\d",
"L" => "[a-zA-Z]",
"C" => ".+",
" " => " +"
];
$zipCodeRE = "#^" . strtr($zipCodeRE, $trans) . "$#";
return $zipCodeRE;
} | [
"public",
"function",
"getZipCodeRE",
"(",
")",
"{",
"$",
"zipCodeFormat",
"=",
"$",
"this",
"->",
"getZipCodeFormat",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"zipCodeFormat",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"zipCodeRE",
"=",
"preg... | get a regex pattern according to the zip code format field
to match a zip code for this country.
zip code format :
- N : number
- L : letter
- C : iso of a state
@return string|null will return a regex to match the zip code, otherwise null will be return
if zip code format is not defined | [
"get",
"a",
"regex",
"pattern",
"according",
"to",
"the",
"zip",
"code",
"format",
"field",
"to",
"match",
"a",
"zip",
"code",
"for",
"this",
"country",
"."
] | 38fbe7d5046bad6c0af9ea7c686b4655e8d84e67 | https://github.com/thelia/core/blob/38fbe7d5046bad6c0af9ea7c686b4655e8d84e67/lib/Thelia/Model/Country.php#L34-L55 | train |
thelia/core | lib/Thelia/Model/Country.php | Country.getAreaId | public function getAreaId()
{
$firstAreaCountry = CountryAreaQuery::create()->findOneByCountryId($this->getId());
if (null !== $firstAreaCountry) {
return $firstAreaCountry->getAreaId();
}
return null;
} | php | public function getAreaId()
{
$firstAreaCountry = CountryAreaQuery::create()->findOneByCountryId($this->getId());
if (null !== $firstAreaCountry) {
return $firstAreaCountry->getAreaId();
}
return null;
} | [
"public",
"function",
"getAreaId",
"(",
")",
"{",
"$",
"firstAreaCountry",
"=",
"CountryAreaQuery",
"::",
"create",
"(",
")",
"->",
"findOneByCountryId",
"(",
"$",
"this",
"->",
"getId",
"(",
")",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"firstAreaCountry"... | This method ensure backward compatibility to Thelia 2.1, where a country belongs to one and
only one shipping zone.
@deprecated a country may belong to several Areas (shipping zones). Use CountryArea queries instead | [
"This",
"method",
"ensure",
"backward",
"compatibility",
"to",
"Thelia",
"2",
".",
"1",
"where",
"a",
"country",
"belongs",
"to",
"one",
"and",
"only",
"one",
"shipping",
"zone",
"."
] | 38fbe7d5046bad6c0af9ea7c686b4655e8d84e67 | https://github.com/thelia/core/blob/38fbe7d5046bad6c0af9ea7c686b4655e8d84e67/lib/Thelia/Model/Country.php#L63-L72 | train |
thelia/core | lib/Thelia/Model/Country.php | Country.getDefaultCountry | public static function getDefaultCountry()
{
if (null === self::$defaultCountry) {
self::$defaultCountry = CountryQuery::create()->findOneByByDefault(true);
if (null === self::$defaultCountry) {
throw new \LogicException(Translator::getInstance()->trans("Cannot find a default country. Please define one."));
}
}
return self::$defaultCountry;
} | php | public static function getDefaultCountry()
{
if (null === self::$defaultCountry) {
self::$defaultCountry = CountryQuery::create()->findOneByByDefault(true);
if (null === self::$defaultCountry) {
throw new \LogicException(Translator::getInstance()->trans("Cannot find a default country. Please define one."));
}
}
return self::$defaultCountry;
} | [
"public",
"static",
"function",
"getDefaultCountry",
"(",
")",
"{",
"if",
"(",
"null",
"===",
"self",
"::",
"$",
"defaultCountry",
")",
"{",
"self",
"::",
"$",
"defaultCountry",
"=",
"CountryQuery",
"::",
"create",
"(",
")",
"->",
"findOneByByDefault",
"(",
... | Return the default country
@throws \LogicException if no default country is defined | [
"Return",
"the",
"default",
"country"
] | 38fbe7d5046bad6c0af9ea7c686b4655e8d84e67 | https://github.com/thelia/core/blob/38fbe7d5046bad6c0af9ea7c686b4655e8d84e67/lib/Thelia/Model/Country.php#L164-L175 | train |
thelia/core | lib/Thelia/Model/Country.php | Country.getShopLocation | public static function getShopLocation()
{
$countryId = ConfigQuery::getStoreCountry();
// return the default country if no shop country defined
if (empty($countryId)) {
return self::getDefaultCountry();
}
$shopCountry = CountryQuery::create()->findPk($countryId);
if ($shopCountry === null) {
throw new \LogicException(Translator::getInstance()->trans("Cannot find the shop country. Please select a shop country."));
}
return $shopCountry;
} | php | public static function getShopLocation()
{
$countryId = ConfigQuery::getStoreCountry();
// return the default country if no shop country defined
if (empty($countryId)) {
return self::getDefaultCountry();
}
$shopCountry = CountryQuery::create()->findPk($countryId);
if ($shopCountry === null) {
throw new \LogicException(Translator::getInstance()->trans("Cannot find the shop country. Please select a shop country."));
}
return $shopCountry;
} | [
"public",
"static",
"function",
"getShopLocation",
"(",
")",
"{",
"$",
"countryId",
"=",
"ConfigQuery",
"::",
"getStoreCountry",
"(",
")",
";",
"// return the default country if no shop country defined",
"if",
"(",
"empty",
"(",
"$",
"countryId",
")",
")",
"{",
"r... | Return the shop country
@throws LogicException if no shop country is defined | [
"Return",
"the",
"shop",
"country"
] | 38fbe7d5046bad6c0af9ea7c686b4655e8d84e67 | https://github.com/thelia/core/blob/38fbe7d5046bad6c0af9ea7c686b4655e8d84e67/lib/Thelia/Model/Country.php#L182-L197 | train |
MetaModels/attribute_tags | src/Attribute/AbstractTags.php | AbstractTags.getAliasColumn | protected function getAliasColumn()
{
$strColNameAlias = $this->get('tag_alias');
if ($this->isTreePicker() || !$strColNameAlias) {
$strColNameAlias = $this->getIdColumn();
}
return $strColNameAlias;
} | php | protected function getAliasColumn()
{
$strColNameAlias = $this->get('tag_alias');
if ($this->isTreePicker() || !$strColNameAlias) {
$strColNameAlias = $this->getIdColumn();
}
return $strColNameAlias;
} | [
"protected",
"function",
"getAliasColumn",
"(",
")",
"{",
"$",
"strColNameAlias",
"=",
"$",
"this",
"->",
"get",
"(",
"'tag_alias'",
")",
";",
"if",
"(",
"$",
"this",
"->",
"isTreePicker",
"(",
")",
"||",
"!",
"$",
"strColNameAlias",
")",
"{",
"$",
"st... | Determine the correct alias column to use.
@return string | [
"Determine",
"the",
"correct",
"alias",
"column",
"to",
"use",
"."
] | d09c2cd18b299a48532caa0de8c70b7944282a8e | https://github.com/MetaModels/attribute_tags/blob/d09c2cd18b299a48532caa0de8c70b7944282a8e/src/Attribute/AbstractTags.php#L184-L191 | train |
MetaModels/attribute_tags | src/Attribute/AbstractTags.php | AbstractTags.setDataForItem | private function setDataForItem($itemId, $tags, $thisExisting)
{
if ($tags === null) {
$tagIds = [];
} else {
$tagIds = \array_keys($tags);
}
// First pass, delete all not mentioned anymore.
$valuesToRemove = \array_diff($thisExisting, $tagIds);
if ($valuesToRemove) {
$this->connection
->createQueryBuilder()
->delete('tl_metamodel_tag_relation')
->where('att_id=:attId')
->andWhere('item_id=:itemId')
->andWhere('value_id IN (:valueIds)')
->setParameter('attId', $this->get('id'))
->setParameter('itemId', $itemId)
->setParameter('valueIds', $valuesToRemove, Connection::PARAM_STR_ARRAY)
->execute();
}
// Second pass, add all new values in a row.
$valuesToAdd = \array_diff($tagIds, $thisExisting);
$insertValues = [];
if ($valuesToAdd) {
foreach ($valuesToAdd as $valueId) {
$insertValues[] = [
'attId' => $this->get('id'),
'itemId' => $itemId,
'sorting' => (int) $tags[$valueId]['tag_value_sorting'],
'valueId' => $valueId
];
}
}
// Third pass, update all sorting values.
$valuesToUpdate = \array_diff($tagIds, $valuesToAdd);
if ($valuesToUpdate) {
$query = $this->connection
->createQueryBuilder()
->update('tl_metamodel_tag_relation')
->set('value_sorting', ':sorting')
->where('att_id=:attId')
->andWhere('item_id=:itemId')
->andWhere('value_id=:valueId')
->setParameter('attId', $this->get('id'))
->setParameter('itemId', $itemId);
foreach ($valuesToUpdate as $valueId) {
if (!array_key_exists('tag_value_sorting', $tags[$valueId])) {
continue;
}
$query
->setParameter('sorting', (int) $tags[$valueId]['tag_value_sorting'])
->setParameter('valueId', $valueId)
->execute();
}
}
return $insertValues;
} | php | private function setDataForItem($itemId, $tags, $thisExisting)
{
if ($tags === null) {
$tagIds = [];
} else {
$tagIds = \array_keys($tags);
}
// First pass, delete all not mentioned anymore.
$valuesToRemove = \array_diff($thisExisting, $tagIds);
if ($valuesToRemove) {
$this->connection
->createQueryBuilder()
->delete('tl_metamodel_tag_relation')
->where('att_id=:attId')
->andWhere('item_id=:itemId')
->andWhere('value_id IN (:valueIds)')
->setParameter('attId', $this->get('id'))
->setParameter('itemId', $itemId)
->setParameter('valueIds', $valuesToRemove, Connection::PARAM_STR_ARRAY)
->execute();
}
// Second pass, add all new values in a row.
$valuesToAdd = \array_diff($tagIds, $thisExisting);
$insertValues = [];
if ($valuesToAdd) {
foreach ($valuesToAdd as $valueId) {
$insertValues[] = [
'attId' => $this->get('id'),
'itemId' => $itemId,
'sorting' => (int) $tags[$valueId]['tag_value_sorting'],
'valueId' => $valueId
];
}
}
// Third pass, update all sorting values.
$valuesToUpdate = \array_diff($tagIds, $valuesToAdd);
if ($valuesToUpdate) {
$query = $this->connection
->createQueryBuilder()
->update('tl_metamodel_tag_relation')
->set('value_sorting', ':sorting')
->where('att_id=:attId')
->andWhere('item_id=:itemId')
->andWhere('value_id=:valueId')
->setParameter('attId', $this->get('id'))
->setParameter('itemId', $itemId);
foreach ($valuesToUpdate as $valueId) {
if (!array_key_exists('tag_value_sorting', $tags[$valueId])) {
continue;
}
$query
->setParameter('sorting', (int) $tags[$valueId]['tag_value_sorting'])
->setParameter('valueId', $valueId)
->execute();
}
}
return $insertValues;
} | [
"private",
"function",
"setDataForItem",
"(",
"$",
"itemId",
",",
"$",
"tags",
",",
"$",
"thisExisting",
")",
"{",
"if",
"(",
"$",
"tags",
"===",
"null",
")",
"{",
"$",
"tagIds",
"=",
"[",
"]",
";",
"}",
"else",
"{",
"$",
"tagIds",
"=",
"\\",
"ar... | Update the tag ids for a given item.
@param int $itemId The item for which data shall be set for.
@param array $tags The tag ids that shall be set for the item.
@param array $thisExisting The existing item ids.
@return array | [
"Update",
"the",
"tag",
"ids",
"for",
"a",
"given",
"item",
"."
] | d09c2cd18b299a48532caa0de8c70b7944282a8e | https://github.com/MetaModels/attribute_tags/blob/d09c2cd18b299a48532caa0de8c70b7944282a8e/src/Attribute/AbstractTags.php#L401-L463 | train |
BoldGrid/library | src/Library/ReleaseChannel.php | ReleaseChannel.updateChannel | public function updateChannel( $old, $new, $option ) {
$old['release_channel'] = ! empty( $old['release_channel'] ) ?
$old['release_channel'] : null;
$new['release_channel'] = ! empty( $new['release_channel'] ) ?
$new['release_channel'] : 'stable';
$old['theme_release_channel'] = ! empty( $old['theme_release_channel'] ) ?
$old['theme_release_channel'] : null;
$new['theme_release_channel'] = ! empty( $new['theme_release_channel'] ) ?
$new['theme_release_channel'] : 'stable';
// Plugin checks.
if ( $old['release_channel'] !== $new['release_channel'] ) {
Util\Option::deletePluginTransients();
wp_update_plugins();
}
// Theme checks.
if ( $old['theme_release_channel'] !== $new['theme_release_channel'] ) {
/**
* Action to take when theme release channel has changed.
*
* @since 1.1
*
* @param string $old Old theme release channel.
* @param string $new New theme release channel.
*/
do_action( 'Boldgrid\Library\Library\ReleaseChannel\theme_channel_updated', $old['theme_release_channel'], $new['theme_release_channel'] );
delete_site_transient( 'boldgrid_api_data' );
delete_site_transient( 'update_themes' );
wp_update_themes();
}
return $new;
} | php | public function updateChannel( $old, $new, $option ) {
$old['release_channel'] = ! empty( $old['release_channel'] ) ?
$old['release_channel'] : null;
$new['release_channel'] = ! empty( $new['release_channel'] ) ?
$new['release_channel'] : 'stable';
$old['theme_release_channel'] = ! empty( $old['theme_release_channel'] ) ?
$old['theme_release_channel'] : null;
$new['theme_release_channel'] = ! empty( $new['theme_release_channel'] ) ?
$new['theme_release_channel'] : 'stable';
// Plugin checks.
if ( $old['release_channel'] !== $new['release_channel'] ) {
Util\Option::deletePluginTransients();
wp_update_plugins();
}
// Theme checks.
if ( $old['theme_release_channel'] !== $new['theme_release_channel'] ) {
/**
* Action to take when theme release channel has changed.
*
* @since 1.1
*
* @param string $old Old theme release channel.
* @param string $new New theme release channel.
*/
do_action( 'Boldgrid\Library\Library\ReleaseChannel\theme_channel_updated', $old['theme_release_channel'], $new['theme_release_channel'] );
delete_site_transient( 'boldgrid_api_data' );
delete_site_transient( 'update_themes' );
wp_update_themes();
}
return $new;
} | [
"public",
"function",
"updateChannel",
"(",
"$",
"old",
",",
"$",
"new",
",",
"$",
"option",
")",
"{",
"$",
"old",
"[",
"'release_channel'",
"]",
"=",
"!",
"empty",
"(",
"$",
"old",
"[",
"'release_channel'",
"]",
")",
"?",
"$",
"old",
"[",
"'release_... | Update Plugin Channel.
This methods fires when boldgrid_settings is updated. We check the values
for the new plugin release channel to see if it changed here.
@since 1.0.0
@link https://developer.wordpress.org/reference/hooks/update_option_option/
@link https://developer.wordpress.org/reference/hooks/update_site_option_option/
@hook: update_option_boldgrid_settings
@param mixed $old Old option value being set.
@param mixed $new New option value being set.
@param string $option The option name.
@return mixed $new The new option being set. | [
"Update",
"Plugin",
"Channel",
"."
] | 51afe070e211cff9cf78454ff97912a0d943805c | https://github.com/BoldGrid/library/blob/51afe070e211cff9cf78454ff97912a0d943805c/src/Library/ReleaseChannel.php#L85-L119 | train |
thelia/core | lib/Thelia/Core/Template/TemplateDefinition.php | TemplateDefinition.getParentList | public function getParentList()
{
if (null === $this->parentList) {
$this->parentList = [];
$parent = $this->getDescriptor()->getParent();
for ($index = 1; null !== $parent; $index++) {
$this->parentList[$parent->getName() . '-'] = $parent;
$parent = $parent->getDescriptor()->getParent();
}
}
return $this->parentList;
} | php | public function getParentList()
{
if (null === $this->parentList) {
$this->parentList = [];
$parent = $this->getDescriptor()->getParent();
for ($index = 1; null !== $parent; $index++) {
$this->parentList[$parent->getName() . '-'] = $parent;
$parent = $parent->getDescriptor()->getParent();
}
}
return $this->parentList;
} | [
"public",
"function",
"getParentList",
"(",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"parentList",
")",
"{",
"$",
"this",
"->",
"parentList",
"=",
"[",
"]",
";",
"$",
"parent",
"=",
"$",
"this",
"->",
"getDescriptor",
"(",
")",
"->",
... | Return the template parent list
@return array|null | [
"Return",
"the",
"template",
"parent",
"list"
] | 38fbe7d5046bad6c0af9ea7c686b4655e8d84e67 | https://github.com/thelia/core/blob/38fbe7d5046bad6c0af9ea7c686b4655e8d84e67/lib/Thelia/Core/Template/TemplateDefinition.php#L180-L195 | train |
thelia/core | lib/Thelia/Core/Template/TemplateDefinition.php | TemplateDefinition.getTemplateFilePath | public function getTemplateFilePath($templateName)
{
$templateList = array_merge(
[ $this ],
$this->getParentList()
);
/** @var TemplateDefinition $templateDefinition */
foreach ($templateList as $templateDefinition) {
$templateFilePath = sprintf(
'%s%s/%s',
THELIA_TEMPLATE_DIR,
$templateDefinition->getPath(),
$templateName
);
if (file_exists($templateFilePath)) {
return $templateFilePath;
}
}
throw new TemplateException("Template file not found: $templateName");
} | php | public function getTemplateFilePath($templateName)
{
$templateList = array_merge(
[ $this ],
$this->getParentList()
);
/** @var TemplateDefinition $templateDefinition */
foreach ($templateList as $templateDefinition) {
$templateFilePath = sprintf(
'%s%s/%s',
THELIA_TEMPLATE_DIR,
$templateDefinition->getPath(),
$templateName
);
if (file_exists($templateFilePath)) {
return $templateFilePath;
}
}
throw new TemplateException("Template file not found: $templateName");
} | [
"public",
"function",
"getTemplateFilePath",
"(",
"$",
"templateName",
")",
"{",
"$",
"templateList",
"=",
"array_merge",
"(",
"[",
"$",
"this",
"]",
",",
"$",
"this",
"->",
"getParentList",
"(",
")",
")",
";",
"/** @var TemplateDefinition $templateDefinition */",... | Find a template file path, considering the template parents, if any.
@param string $templateName the template name, with path
@return string
@throws TemplateException | [
"Find",
"a",
"template",
"file",
"path",
"considering",
"the",
"template",
"parents",
"if",
"any",
"."
] | 38fbe7d5046bad6c0af9ea7c686b4655e8d84e67 | https://github.com/thelia/core/blob/38fbe7d5046bad6c0af9ea7c686b4655e8d84e67/lib/Thelia/Core/Template/TemplateDefinition.php#L204-L226 | train |
thelia/core | lib/Thelia/Action/Currency.php | Currency.create | public function create(CurrencyCreateEvent $event, $eventName, EventDispatcherInterface $dispatcher)
{
$currency = new CurrencyModel();
$isDefault = CurrencyQuery::create()->count() === 0;
$currency
->setDispatcher($dispatcher)
->setLocale($event->getLocale())
->setName($event->getCurrencyName())
->setSymbol($event->getSymbol())
->setFormat($event->getFormat())
->setRate($event->getRate())
->setCode(strtoupper($event->getCode()))
->setByDefault($isDefault)
->save()
;
$event->setCurrency($currency);
} | php | public function create(CurrencyCreateEvent $event, $eventName, EventDispatcherInterface $dispatcher)
{
$currency = new CurrencyModel();
$isDefault = CurrencyQuery::create()->count() === 0;
$currency
->setDispatcher($dispatcher)
->setLocale($event->getLocale())
->setName($event->getCurrencyName())
->setSymbol($event->getSymbol())
->setFormat($event->getFormat())
->setRate($event->getRate())
->setCode(strtoupper($event->getCode()))
->setByDefault($isDefault)
->save()
;
$event->setCurrency($currency);
} | [
"public",
"function",
"create",
"(",
"CurrencyCreateEvent",
"$",
"event",
",",
"$",
"eventName",
",",
"EventDispatcherInterface",
"$",
"dispatcher",
")",
"{",
"$",
"currency",
"=",
"new",
"CurrencyModel",
"(",
")",
";",
"$",
"isDefault",
"=",
"CurrencyQuery",
... | Create a new currencyuration entry
@param \Thelia\Core\Event\Currency\CurrencyCreateEvent $event
@param $eventName
@param EventDispatcherInterface $dispatcher | [
"Create",
"a",
"new",
"currencyuration",
"entry"
] | 38fbe7d5046bad6c0af9ea7c686b4655e8d84e67 | https://github.com/thelia/core/blob/38fbe7d5046bad6c0af9ea7c686b4655e8d84e67/lib/Thelia/Action/Currency.php#L48-L67 | train |
thelia/core | lib/Thelia/Action/Currency.php | Currency.update | public function update(CurrencyUpdateEvent $event, $eventName, EventDispatcherInterface $dispatcher)
{
if (null !== $currency = CurrencyQuery::create()->findPk($event->getCurrencyId())) {
$currency
->setDispatcher($dispatcher)
->setLocale($event->getLocale())
->setName($event->getCurrencyName())
->setSymbol($event->getSymbol())
->setFormat($event->getFormat())
->setRate($event->getRate())
->setCode(strtoupper($event->getCode()))
->save();
$event->setCurrency($currency);
}
} | php | public function update(CurrencyUpdateEvent $event, $eventName, EventDispatcherInterface $dispatcher)
{
if (null !== $currency = CurrencyQuery::create()->findPk($event->getCurrencyId())) {
$currency
->setDispatcher($dispatcher)
->setLocale($event->getLocale())
->setName($event->getCurrencyName())
->setSymbol($event->getSymbol())
->setFormat($event->getFormat())
->setRate($event->getRate())
->setCode(strtoupper($event->getCode()))
->save();
$event->setCurrency($currency);
}
} | [
"public",
"function",
"update",
"(",
"CurrencyUpdateEvent",
"$",
"event",
",",
"$",
"eventName",
",",
"EventDispatcherInterface",
"$",
"dispatcher",
")",
"{",
"if",
"(",
"null",
"!==",
"$",
"currency",
"=",
"CurrencyQuery",
"::",
"create",
"(",
")",
"->",
"f... | Change a currency
@param \Thelia\Core\Event\Currency\CurrencyUpdateEvent $event
@param $eventName
@param EventDispatcherInterface $dispatcher | [
"Change",
"a",
"currency"
] | 38fbe7d5046bad6c0af9ea7c686b4655e8d84e67 | https://github.com/thelia/core/blob/38fbe7d5046bad6c0af9ea7c686b4655e8d84e67/lib/Thelia/Action/Currency.php#L76-L93 | train |
thelia/core | lib/Thelia/Action/Currency.php | Currency.setDefault | public function setDefault(CurrencyUpdateEvent $event, $eventName, EventDispatcherInterface $dispatcher)
{
if (null !== $currency = CurrencyQuery::create()->findPk($event->getCurrencyId())) {
// Reset default status
CurrencyQuery::create()->filterByByDefault(true)->update(array('ByDefault' => false));
$currency
->setDispatcher($dispatcher)
->setVisible($event->getVisible())
->setByDefault($event->getIsDefault())
->save()
;
// Update rates when setting a new default currency
if ($event->getIsDefault()) {
$updateRateEvent = new CurrencyUpdateRateEvent();
$dispatcher->dispatch(TheliaEvents::CURRENCY_UPDATE_RATES, $updateRateEvent);
}
$event->setCurrency($currency);
}
} | php | public function setDefault(CurrencyUpdateEvent $event, $eventName, EventDispatcherInterface $dispatcher)
{
if (null !== $currency = CurrencyQuery::create()->findPk($event->getCurrencyId())) {
// Reset default status
CurrencyQuery::create()->filterByByDefault(true)->update(array('ByDefault' => false));
$currency
->setDispatcher($dispatcher)
->setVisible($event->getVisible())
->setByDefault($event->getIsDefault())
->save()
;
// Update rates when setting a new default currency
if ($event->getIsDefault()) {
$updateRateEvent = new CurrencyUpdateRateEvent();
$dispatcher->dispatch(TheliaEvents::CURRENCY_UPDATE_RATES, $updateRateEvent);
}
$event->setCurrency($currency);
}
} | [
"public",
"function",
"setDefault",
"(",
"CurrencyUpdateEvent",
"$",
"event",
",",
"$",
"eventName",
",",
"EventDispatcherInterface",
"$",
"dispatcher",
")",
"{",
"if",
"(",
"null",
"!==",
"$",
"currency",
"=",
"CurrencyQuery",
"::",
"create",
"(",
")",
"->",
... | Set the default currency
@param CurrencyUpdateEvent $event
@param $eventName
@param EventDispatcherInterface $dispatcher | [
"Set",
"the",
"default",
"currency"
] | 38fbe7d5046bad6c0af9ea7c686b4655e8d84e67 | https://github.com/thelia/core/blob/38fbe7d5046bad6c0af9ea7c686b4655e8d84e67/lib/Thelia/Action/Currency.php#L102-L124 | train |
thelia/core | lib/Thelia/Action/Currency.php | Currency.delete | public function delete(CurrencyDeleteEvent $event, $eventName, EventDispatcherInterface $dispatcher)
{
if (null !== ($currency = CurrencyQuery::create()->findPk($event->getCurrencyId()))) {
if ($currency->getByDefault()) {
throw new \RuntimeException(
Translator::getInstance()->trans('It is not allowed to delete the default currency')
);
}
$currency
->setDispatcher($dispatcher)
->delete()
;
$event->setCurrency($currency);
}
} | php | public function delete(CurrencyDeleteEvent $event, $eventName, EventDispatcherInterface $dispatcher)
{
if (null !== ($currency = CurrencyQuery::create()->findPk($event->getCurrencyId()))) {
if ($currency->getByDefault()) {
throw new \RuntimeException(
Translator::getInstance()->trans('It is not allowed to delete the default currency')
);
}
$currency
->setDispatcher($dispatcher)
->delete()
;
$event->setCurrency($currency);
}
} | [
"public",
"function",
"delete",
"(",
"CurrencyDeleteEvent",
"$",
"event",
",",
"$",
"eventName",
",",
"EventDispatcherInterface",
"$",
"dispatcher",
")",
"{",
"if",
"(",
"null",
"!==",
"(",
"$",
"currency",
"=",
"CurrencyQuery",
"::",
"create",
"(",
")",
"->... | Delete a currencyuration entry
@param \Thelia\Core\Event\Currency\CurrencyDeleteEvent $event
@param $eventName
@param EventDispatcherInterface $dispatcher | [
"Delete",
"a",
"currencyuration",
"entry"
] | 38fbe7d5046bad6c0af9ea7c686b4655e8d84e67 | https://github.com/thelia/core/blob/38fbe7d5046bad6c0af9ea7c686b4655e8d84e67/lib/Thelia/Action/Currency.php#L145-L161 | train |
BoldGrid/library | src/Library/Activity.php | Activity.getActivityConfigs | public function getActivityConfigs( $activity, $config_path ) {
$configs = array();
if ( file_exists( $config_path ) ) {
$configs = require $config_path;
}
return isset( $configs[ $activity ] ) ? $configs[ $activity ] : array();
} | php | public function getActivityConfigs( $activity, $config_path ) {
$configs = array();
if ( file_exists( $config_path ) ) {
$configs = require $config_path;
}
return isset( $configs[ $activity ] ) ? $configs[ $activity ] : array();
} | [
"public",
"function",
"getActivityConfigs",
"(",
"$",
"activity",
",",
"$",
"config_path",
")",
"{",
"$",
"configs",
"=",
"array",
"(",
")",
";",
"if",
"(",
"file_exists",
"(",
"$",
"config_path",
")",
")",
"{",
"$",
"configs",
"=",
"require",
"$",
"co... | Get the configs for a particular activity.
@since 2.7.7
@var string $activity The name of the activity.
@var string $config_path The full path to the config file.
@return array An array of configs. | [
"Get",
"the",
"configs",
"for",
"a",
"particular",
"activity",
"."
] | 51afe070e211cff9cf78454ff97912a0d943805c | https://github.com/BoldGrid/library/blob/51afe070e211cff9cf78454ff97912a0d943805c/src/Library/Activity.php#L116-L124 | train |
BoldGrid/library | src/Library/Activity.php | Activity.getActivityCount | public function getActivityCount( $activity ) {
$plugin_activities = $this->getPluginActivities();
return empty( $plugin_activities[ $activity ] ) ? 0 : $plugin_activities[ $activity ];
} | php | public function getActivityCount( $activity ) {
$plugin_activities = $this->getPluginActivities();
return empty( $plugin_activities[ $activity ] ) ? 0 : $plugin_activities[ $activity ];
} | [
"public",
"function",
"getActivityCount",
"(",
"$",
"activity",
")",
"{",
"$",
"plugin_activities",
"=",
"$",
"this",
"->",
"getPluginActivities",
"(",
")",
";",
"return",
"empty",
"(",
"$",
"plugin_activities",
"[",
"$",
"activity",
"]",
")",
"?",
"0",
":... | Get the count for an activity.
@since 2.7.7
@param string $activity The name of the activity.
@return int The activity's count. | [
"Get",
"the",
"count",
"for",
"an",
"activity",
"."
] | 51afe070e211cff9cf78454ff97912a0d943805c | https://github.com/BoldGrid/library/blob/51afe070e211cff9cf78454ff97912a0d943805c/src/Library/Activity.php#L134-L138 | train |
BoldGrid/library | src/Library/Activity.php | Activity.getPluginActivities | public function getPluginActivities() {
$activities = $this->getActivities();
if ( ! isset( $activities[ $this->plugin ] ) ) {
$activities[ $this->plugin ] = array();
}
return $activities[ $this->plugin ];
} | php | public function getPluginActivities() {
$activities = $this->getActivities();
if ( ! isset( $activities[ $this->plugin ] ) ) {
$activities[ $this->plugin ] = array();
}
return $activities[ $this->plugin ];
} | [
"public",
"function",
"getPluginActivities",
"(",
")",
"{",
"$",
"activities",
"=",
"$",
"this",
"->",
"getActivities",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"activities",
"[",
"$",
"this",
"->",
"plugin",
"]",
")",
")",
"{",
"$",
"activi... | Get all activities for a plugin.
@since 2.7.7
@return array | [
"Get",
"all",
"activities",
"for",
"a",
"plugin",
"."
] | 51afe070e211cff9cf78454ff97912a0d943805c | https://github.com/BoldGrid/library/blob/51afe070e211cff9cf78454ff97912a0d943805c/src/Library/Activity.php#L147-L155 | train |
BoldGrid/library | src/Library/Activity.php | Activity.maybeAddRatingPrompt | public function maybeAddRatingPrompt( $activity, $config_path ) {
$added = false;
$configs = $this->getActivityConfigs( $activity, $config_path );
if ( isset( $configs['threshold'] ) && $this->getActivityCount( $activity ) >= $configs['threshold'] ) {
$rating_prompt = new \Boldgrid\Library\Library\RatingPrompt();
$added = $rating_prompt->addPrompt( $configs['prompt'] );
}
return $added;
} | php | public function maybeAddRatingPrompt( $activity, $config_path ) {
$added = false;
$configs = $this->getActivityConfigs( $activity, $config_path );
if ( isset( $configs['threshold'] ) && $this->getActivityCount( $activity ) >= $configs['threshold'] ) {
$rating_prompt = new \Boldgrid\Library\Library\RatingPrompt();
$added = $rating_prompt->addPrompt( $configs['prompt'] );
}
return $added;
} | [
"public",
"function",
"maybeAddRatingPrompt",
"(",
"$",
"activity",
",",
"$",
"config_path",
")",
"{",
"$",
"added",
"=",
"false",
";",
"$",
"configs",
"=",
"$",
"this",
"->",
"getActivityConfigs",
"(",
"$",
"activity",
",",
"$",
"config_path",
")",
";",
... | Maybe add a rating prompt for an activity.
@since 2.7.7
@param string $activity The name of an activity
@param string $config_path The path to our plugin's rating prompt configs.
@return bool Whether or not we added a rating prompt. | [
"Maybe",
"add",
"a",
"rating",
"prompt",
"for",
"an",
"activity",
"."
] | 51afe070e211cff9cf78454ff97912a0d943805c | https://github.com/BoldGrid/library/blob/51afe070e211cff9cf78454ff97912a0d943805c/src/Library/Activity.php#L166-L177 | train |
BoldGrid/library | src/Library/Activity.php | Activity.savePluginActivities | public function savePluginActivities( $plugin_activities ) {
$activities = $this->getActivities();
$activities[ $this->plugin ] = $plugin_activities;
return $this->saveActivities( $activities );
} | php | public function savePluginActivities( $plugin_activities ) {
$activities = $this->getActivities();
$activities[ $this->plugin ] = $plugin_activities;
return $this->saveActivities( $activities );
} | [
"public",
"function",
"savePluginActivities",
"(",
"$",
"plugin_activities",
")",
"{",
"$",
"activities",
"=",
"$",
"this",
"->",
"getActivities",
"(",
")",
";",
"$",
"activities",
"[",
"$",
"this",
"->",
"plugin",
"]",
"=",
"$",
"plugin_activities",
";",
... | Save all activities for this plugin.
@since 2.7.7
@param array $plugin_activities An array of activities.
@return bool Whether or not the activities were updated successfully. | [
"Save",
"all",
"activities",
"for",
"this",
"plugin",
"."
] | 51afe070e211cff9cf78454ff97912a0d943805c | https://github.com/BoldGrid/library/blob/51afe070e211cff9cf78454ff97912a0d943805c/src/Library/Activity.php#L201-L207 | train |
thelia/core | lib/Thelia/Core/Template/ParserContext.php | ParserContext.cleanFormData | protected function cleanFormData(array $data)
{
foreach ($data as $key => $value) {
if (\is_array($value)) {
$data[$key] = $this->cleanFormData($value);
} elseif (\is_object($value)) {
unset($data[$key]);
}
}
return $data;
} | php | protected function cleanFormData(array $data)
{
foreach ($data as $key => $value) {
if (\is_array($value)) {
$data[$key] = $this->cleanFormData($value);
} elseif (\is_object($value)) {
unset($data[$key]);
}
}
return $data;
} | [
"protected",
"function",
"cleanFormData",
"(",
"array",
"$",
"data",
")",
"{",
"foreach",
"(",
"$",
"data",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"\\",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"data",
"[",
"$",
"key... | Remove all objects in data, because they are probably not serializable
@param array $data
@return array | [
"Remove",
"all",
"objects",
"in",
"data",
"because",
"they",
"are",
"probably",
"not",
"serializable"
] | 38fbe7d5046bad6c0af9ea7c686b4655e8d84e67 | https://github.com/thelia/core/blob/38fbe7d5046bad6c0af9ea7c686b4655e8d84e67/lib/Thelia/Core/Template/ParserContext.php#L115-L126 | train |
thelia/core | lib/Thelia/Core/Template/ParserContext.php | ParserContext.addForm | public function addForm(BaseForm $form)
{
$formErrorInformation = $this->getSession()->getFormErrorInformation();
// Get form field error details
$formFieldErrors = [];
/** @var Form $field */
foreach ($form->getForm()->getIterator() as $field) {
$errors = $field->getErrors();
if (\count($errors) > 0) {
$formFieldErrors[$field->getName()] = [];
/** @var FormError $error */
foreach ($errors as $error) {
$formFieldErrors[$field->getName()][] = [
'message' => $error->getMessage(),
'template' => $error->getMessageTemplate(),
'parameters' => $error->getMessageParameters(),
'pluralization' => $error->getMessagePluralization()
];
}
}
}
$this->set(\get_class($form) . ":" . $form->getType(), $form);
// Set form error information
$formErrorInformation[\get_class($form) . ":" . $form->getType()] = [
'data' => $this->cleanFormData($form->getForm()->getData()),
'hasError' => $form->hasError(),
'errorMessage' => $form->getErrorMessage(),
'method' => $this->requestStack->getCurrentRequest()->getMethod(),
'timestamp' => time(),
'validation_groups' => $form->getForm()->getConfig()->getOption('validation_groups'),
'field_errors' => $formFieldErrors
];
$this->getSession()->setFormErrorInformation($formErrorInformation);
return $this;
} | php | public function addForm(BaseForm $form)
{
$formErrorInformation = $this->getSession()->getFormErrorInformation();
// Get form field error details
$formFieldErrors = [];
/** @var Form $field */
foreach ($form->getForm()->getIterator() as $field) {
$errors = $field->getErrors();
if (\count($errors) > 0) {
$formFieldErrors[$field->getName()] = [];
/** @var FormError $error */
foreach ($errors as $error) {
$formFieldErrors[$field->getName()][] = [
'message' => $error->getMessage(),
'template' => $error->getMessageTemplate(),
'parameters' => $error->getMessageParameters(),
'pluralization' => $error->getMessagePluralization()
];
}
}
}
$this->set(\get_class($form) . ":" . $form->getType(), $form);
// Set form error information
$formErrorInformation[\get_class($form) . ":" . $form->getType()] = [
'data' => $this->cleanFormData($form->getForm()->getData()),
'hasError' => $form->hasError(),
'errorMessage' => $form->getErrorMessage(),
'method' => $this->requestStack->getCurrentRequest()->getMethod(),
'timestamp' => time(),
'validation_groups' => $form->getForm()->getConfig()->getOption('validation_groups'),
'field_errors' => $formFieldErrors
];
$this->getSession()->setFormErrorInformation($formErrorInformation);
return $this;
} | [
"public",
"function",
"addForm",
"(",
"BaseForm",
"$",
"form",
")",
"{",
"$",
"formErrorInformation",
"=",
"$",
"this",
"->",
"getSession",
"(",
")",
"->",
"getFormErrorInformation",
"(",
")",
";",
"// Get form field error details",
"$",
"formFieldErrors",
"=",
... | Add a new form to the error form context
@param BaseForm $form the errored form
@return $this | [
"Add",
"a",
"new",
"form",
"to",
"the",
"error",
"form",
"context"
] | 38fbe7d5046bad6c0af9ea7c686b4655e8d84e67 | https://github.com/thelia/core/blob/38fbe7d5046bad6c0af9ea7c686b4655e8d84e67/lib/Thelia/Core/Template/ParserContext.php#L134-L176 | train |
thelia/core | lib/Thelia/Core/Template/ParserContext.php | ParserContext.getForm | public function getForm($formId, $formClass, $formType)
{
if (isset($this->store[$formClass . ":" . $formType]) && $this->store[$formClass . ":" . $formType] instanceof BaseForm) {
return $this->store[$formClass . ":" . $formType];
}
$formErrorInformation = $this->getSession()->getFormErrorInformation();
if (isset($formErrorInformation[$formClass.":".$formType])) {
$formInfo = $formErrorInformation[$formClass.":".$formType];
if (\is_array($formInfo['data'])) {
$form = $this->formFactory->createForm(
$formId,
$formType,
$formInfo['data'],
[
'validation_groups' => $formInfo['validation_groups']
]
);
// If the form has errors, perform a validation, to restore the internal error context
// A controller (as the NewsletterController) may use the parserContext to redisplay a
// validated (not errored) form. In such cases, another validation may cause unexpected
// results.
if (true === $formInfo['hasError']) {
try {
$this->formValidator->validateForm($form, $formInfo['method']);
} catch (\Exception $ex) {
// Ignore the exception.
}
// Manually set the form fields error information, if validateForm() did not the job,
// which is the case when the user has been redirected.
foreach ($formInfo['field_errors'] as $fieldName => $errors) {
/** @var Form $field */
$field = $form->getForm()->get($fieldName);
if (null !== $field && \count($field->getErrors()) == 0) {
foreach ($errors as $errorData) {
$error = new FormError(
$errorData['message'],
$errorData['template'],
$errorData['parameters'],
$errorData['pluralization']
);
$field->addError($error);
}
}
}
}
$form->setError($formInfo['hasError']);
// Check if error message is empty, as BaseForm::setErrorMessage() always set form error flag to true.
if (! empty($formInfo['errorMessage'])) {
$form->setErrorMessage($formInfo['errorMessage']);
}
return $form;
}
}
return null;
} | php | public function getForm($formId, $formClass, $formType)
{
if (isset($this->store[$formClass . ":" . $formType]) && $this->store[$formClass . ":" . $formType] instanceof BaseForm) {
return $this->store[$formClass . ":" . $formType];
}
$formErrorInformation = $this->getSession()->getFormErrorInformation();
if (isset($formErrorInformation[$formClass.":".$formType])) {
$formInfo = $formErrorInformation[$formClass.":".$formType];
if (\is_array($formInfo['data'])) {
$form = $this->formFactory->createForm(
$formId,
$formType,
$formInfo['data'],
[
'validation_groups' => $formInfo['validation_groups']
]
);
// If the form has errors, perform a validation, to restore the internal error context
// A controller (as the NewsletterController) may use the parserContext to redisplay a
// validated (not errored) form. In such cases, another validation may cause unexpected
// results.
if (true === $formInfo['hasError']) {
try {
$this->formValidator->validateForm($form, $formInfo['method']);
} catch (\Exception $ex) {
// Ignore the exception.
}
// Manually set the form fields error information, if validateForm() did not the job,
// which is the case when the user has been redirected.
foreach ($formInfo['field_errors'] as $fieldName => $errors) {
/** @var Form $field */
$field = $form->getForm()->get($fieldName);
if (null !== $field && \count($field->getErrors()) == 0) {
foreach ($errors as $errorData) {
$error = new FormError(
$errorData['message'],
$errorData['template'],
$errorData['parameters'],
$errorData['pluralization']
);
$field->addError($error);
}
}
}
}
$form->setError($formInfo['hasError']);
// Check if error message is empty, as BaseForm::setErrorMessage() always set form error flag to true.
if (! empty($formInfo['errorMessage'])) {
$form->setErrorMessage($formInfo['errorMessage']);
}
return $form;
}
}
return null;
} | [
"public",
"function",
"getForm",
"(",
"$",
"formId",
",",
"$",
"formClass",
",",
"$",
"formType",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"store",
"[",
"$",
"formClass",
".",
"\":\"",
".",
"$",
"formType",
"]",
")",
"&&",
"$",
"this",... | Check if the specified form has errors, and return an instance of this form if it's the case.
@param string $formId the form ID, as defined in the container
@param string $formClass the form full qualified class name
@param string $formType the form type, something like 'form'
@return null|BaseForm null if no error information is available | [
"Check",
"if",
"the",
"specified",
"form",
"has",
"errors",
"and",
"return",
"an",
"instance",
"of",
"this",
"form",
"if",
"it",
"s",
"the",
"case",
"."
] | 38fbe7d5046bad6c0af9ea7c686b4655e8d84e67 | https://github.com/thelia/core/blob/38fbe7d5046bad6c0af9ea7c686b4655e8d84e67/lib/Thelia/Core/Template/ParserContext.php#L186-L251 | train |
thelia/core | lib/Thelia/Core/Template/ParserContext.php | ParserContext.clearForm | public function clearForm(BaseForm $form)
{
$formErrorInformation = $this->getSession()->getFormErrorInformation();
$formClass = \get_class($form) . ':' . $form->getType();
if (isset($formErrorInformation[$formClass])) {
unset($formErrorInformation[$formClass]);
$this->getSession()->setFormErrorInformation($formErrorInformation);
}
return $this;
} | php | public function clearForm(BaseForm $form)
{
$formErrorInformation = $this->getSession()->getFormErrorInformation();
$formClass = \get_class($form) . ':' . $form->getType();
if (isset($formErrorInformation[$formClass])) {
unset($formErrorInformation[$formClass]);
$this->getSession()->setFormErrorInformation($formErrorInformation);
}
return $this;
} | [
"public",
"function",
"clearForm",
"(",
"BaseForm",
"$",
"form",
")",
"{",
"$",
"formErrorInformation",
"=",
"$",
"this",
"->",
"getSession",
"(",
")",
"->",
"getFormErrorInformation",
"(",
")",
";",
"$",
"formClass",
"=",
"\\",
"get_class",
"(",
"$",
"for... | Remove form from the saved form error information.
@param BaseForm $form
@return $this | [
"Remove",
"form",
"from",
"the",
"saved",
"form",
"error",
"information",
"."
] | 38fbe7d5046bad6c0af9ea7c686b4655e8d84e67 | https://github.com/thelia/core/blob/38fbe7d5046bad6c0af9ea7c686b4655e8d84e67/lib/Thelia/Core/Template/ParserContext.php#L259-L271 | train |
thelia/core | lib/Thelia/Core/Template/ParserContext.php | ParserContext.cleanOutdatedFormErrorInformation | protected function cleanOutdatedFormErrorInformation()
{
$formErrorInformation = $this->getSession()->getFormErrorInformation();
if (! empty($formErrorInformation)) {
$now = time();
// Cleanup obsolete form information, and try to find the form data
foreach ($formErrorInformation as $name => $formData) {
if ($now - $formData['timestamp'] > self::FORM_ERROR_LIFETIME_SECONDS) {
unset($formErrorInformation[$name]);
}
}
$this->getSession()->setFormErrorInformation($formErrorInformation);
}
return $this;
} | php | protected function cleanOutdatedFormErrorInformation()
{
$formErrorInformation = $this->getSession()->getFormErrorInformation();
if (! empty($formErrorInformation)) {
$now = time();
// Cleanup obsolete form information, and try to find the form data
foreach ($formErrorInformation as $name => $formData) {
if ($now - $formData['timestamp'] > self::FORM_ERROR_LIFETIME_SECONDS) {
unset($formErrorInformation[$name]);
}
}
$this->getSession()->setFormErrorInformation($formErrorInformation);
}
return $this;
} | [
"protected",
"function",
"cleanOutdatedFormErrorInformation",
"(",
")",
"{",
"$",
"formErrorInformation",
"=",
"$",
"this",
"->",
"getSession",
"(",
")",
"->",
"getFormErrorInformation",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"formErrorInformation",
"... | Remove obsolete form error information. | [
"Remove",
"obsolete",
"form",
"error",
"information",
"."
] | 38fbe7d5046bad6c0af9ea7c686b4655e8d84e67 | https://github.com/thelia/core/blob/38fbe7d5046bad6c0af9ea7c686b4655e8d84e67/lib/Thelia/Core/Template/ParserContext.php#L276-L294 | train |
thelia/core | lib/Thelia/Mailer/MailerFactory.php | MailerFactory.sendEmailToShopManagers | public function sendEmailToShopManagers($messageCode, $messageParameters = [], $replyTo = [])
{
$storeName = ConfigQuery::getStoreName();
// Build the list of email recipients
$recipients = ConfigQuery::getNotificationEmailsList();
$to = [];
foreach ($recipients as $recipient) {
$to[$recipient] = $storeName;
}
$this->sendEmailMessage(
$messageCode,
[ConfigQuery::getStoreEmail() => $storeName],
$to,
$messageParameters,
null,
[],
[],
$replyTo
);
} | php | public function sendEmailToShopManagers($messageCode, $messageParameters = [], $replyTo = [])
{
$storeName = ConfigQuery::getStoreName();
// Build the list of email recipients
$recipients = ConfigQuery::getNotificationEmailsList();
$to = [];
foreach ($recipients as $recipient) {
$to[$recipient] = $storeName;
}
$this->sendEmailMessage(
$messageCode,
[ConfigQuery::getStoreEmail() => $storeName],
$to,
$messageParameters,
null,
[],
[],
$replyTo
);
} | [
"public",
"function",
"sendEmailToShopManagers",
"(",
"$",
"messageCode",
",",
"$",
"messageParameters",
"=",
"[",
"]",
",",
"$",
"replyTo",
"=",
"[",
"]",
")",
"{",
"$",
"storeName",
"=",
"ConfigQuery",
"::",
"getStoreName",
"(",
")",
";",
"// Build the lis... | Send a message to the shop managers.
@param string $messageCode
@param array $messageParameters an array of (name => value) parameters that will be available in the message.
@param array $replyTo Reply to addresses. An array of (email-address => name) [optional] | [
"Send",
"a",
"message",
"to",
"the",
"shop",
"managers",
"."
] | 38fbe7d5046bad6c0af9ea7c686b4655e8d84e67 | https://github.com/thelia/core/blob/38fbe7d5046bad6c0af9ea7c686b4655e8d84e67/lib/Thelia/Mailer/MailerFactory.php#L145-L168 | train |
thelia/core | lib/Thelia/Mailer/MailerFactory.php | MailerFactory.createEmailMessage | public function createEmailMessage($messageCode, $from, $to, $messageParameters = [], $locale = null, $cc = [], $bcc = [], $replyTo = [])
{
if (null !== $message = MessageQuery::getFromName($messageCode)) {
if ($locale === null) {
$locale = Lang::getDefaultLanguage()->getLocale();
}
$message->setLocale($locale);
// Assign parameters
foreach ($messageParameters as $name => $value) {
$this->parser->assign($name, $value);
}
$this->parser->assign('locale', $locale);
$instance = $this->getMessageInstance();
$this->setupMessageHeaders($instance, $from, $to, $cc, $bcc, $replyTo);
$message->buildMessage($this->parser, $instance);
return $instance;
}
throw new \RuntimeException(
Translator::getInstance()->trans(
"Failed to load message with code '%code%', propably because it does'nt exists.",
[ '%code%' => $messageCode ]
)
);
} | php | public function createEmailMessage($messageCode, $from, $to, $messageParameters = [], $locale = null, $cc = [], $bcc = [], $replyTo = [])
{
if (null !== $message = MessageQuery::getFromName($messageCode)) {
if ($locale === null) {
$locale = Lang::getDefaultLanguage()->getLocale();
}
$message->setLocale($locale);
// Assign parameters
foreach ($messageParameters as $name => $value) {
$this->parser->assign($name, $value);
}
$this->parser->assign('locale', $locale);
$instance = $this->getMessageInstance();
$this->setupMessageHeaders($instance, $from, $to, $cc, $bcc, $replyTo);
$message->buildMessage($this->parser, $instance);
return $instance;
}
throw new \RuntimeException(
Translator::getInstance()->trans(
"Failed to load message with code '%code%', propably because it does'nt exists.",
[ '%code%' => $messageCode ]
)
);
} | [
"public",
"function",
"createEmailMessage",
"(",
"$",
"messageCode",
",",
"$",
"from",
",",
"$",
"to",
",",
"$",
"messageParameters",
"=",
"[",
"]",
",",
"$",
"locale",
"=",
"null",
",",
"$",
"cc",
"=",
"[",
"]",
",",
"$",
"bcc",
"=",
"[",
"]",
"... | Create a SwiftMessage instance from a given message code.
@param string $messageCode
@param array $from From addresses. An array of (email-address => name)
@param array $to To addresses. An array of (email-address => name)
@param array $messageParameters an array of (name => value) parameters that will be available in the message.
@param string $locale If null, the default store locale is used.
@param array $cc Cc addresses. An array of (email-address => name) [optional]
@param array $bcc Bcc addresses. An array of (email-address => name) [optional]
@param array $replyTo Reply to addresses. An array of (email-address => name) [optional]
@return \Swift_Message the generated and built message.
@throws \SmartyException | [
"Create",
"a",
"SwiftMessage",
"instance",
"from",
"a",
"given",
"message",
"code",
"."
] | 38fbe7d5046bad6c0af9ea7c686b4655e8d84e67 | https://github.com/thelia/core/blob/38fbe7d5046bad6c0af9ea7c686b4655e8d84e67/lib/Thelia/Mailer/MailerFactory.php#L235-L266 | train |
thelia/core | lib/Thelia/Mailer/MailerFactory.php | MailerFactory.createSimpleEmailMessage | public function createSimpleEmailMessage($from, $to, $subject, $htmlBody, $textBody, $cc = [], $bcc = [], $replyTo = [])
{
$instance = $this->getMessageInstance();
$this->setupMessageHeaders($instance, $from, $to, $cc, $bcc, $replyTo);
$instance->setSubject($subject);
// If we do not have an HTML message
if (empty($htmlMessage)) {
// Message body is the text message
$instance->setBody($textBody, 'text/plain');
} else {
// The main body is the HTML messahe
$instance->setBody($htmlBody, 'text/html');
// Use the text as a message part, if we have one.
if (! empty($textMessage)) {
$instance->addPart($textBody, 'text/plain');
}
}
return $instance;
} | php | public function createSimpleEmailMessage($from, $to, $subject, $htmlBody, $textBody, $cc = [], $bcc = [], $replyTo = [])
{
$instance = $this->getMessageInstance();
$this->setupMessageHeaders($instance, $from, $to, $cc, $bcc, $replyTo);
$instance->setSubject($subject);
// If we do not have an HTML message
if (empty($htmlMessage)) {
// Message body is the text message
$instance->setBody($textBody, 'text/plain');
} else {
// The main body is the HTML messahe
$instance->setBody($htmlBody, 'text/html');
// Use the text as a message part, if we have one.
if (! empty($textMessage)) {
$instance->addPart($textBody, 'text/plain');
}
}
return $instance;
} | [
"public",
"function",
"createSimpleEmailMessage",
"(",
"$",
"from",
",",
"$",
"to",
",",
"$",
"subject",
",",
"$",
"htmlBody",
",",
"$",
"textBody",
",",
"$",
"cc",
"=",
"[",
"]",
",",
"$",
"bcc",
"=",
"[",
"]",
",",
"$",
"replyTo",
"=",
"[",
"]"... | Create a SwiftMessage instance from text
@param array $from From addresses. An array of (email-address => name)
@param array $to To addresses. An array of (email-address => name)
@param string $subject the message subject
@param string $htmlBody the HTML message body, or null
@param string $textBody the text message body, or null
@param array $cc Cc addresses. An array of (email-address => name) [optional]
@param array $bcc Bcc addresses. An array of (email-address => name) [optional]
@param array $replyTo Reply to addresses. An array of (email-address => name) [optional]
@return \Swift_Message the generated and built message. | [
"Create",
"a",
"SwiftMessage",
"instance",
"from",
"text"
] | 38fbe7d5046bad6c0af9ea7c686b4655e8d84e67 | https://github.com/thelia/core/blob/38fbe7d5046bad6c0af9ea7c686b4655e8d84e67/lib/Thelia/Mailer/MailerFactory.php#L282-L305 | train |
thelia/core | lib/Thelia/Action/Template.php | Template.create | public function create(TemplateCreateEvent $event, $eventName, EventDispatcherInterface $dispatcher)
{
$template = new TemplateModel();
$template
->setDispatcher($dispatcher)
->setLocale($event->getLocale())
->setName($event->getTemplateName())
->save()
;
$event->setTemplate($template);
} | php | public function create(TemplateCreateEvent $event, $eventName, EventDispatcherInterface $dispatcher)
{
$template = new TemplateModel();
$template
->setDispatcher($dispatcher)
->setLocale($event->getLocale())
->setName($event->getTemplateName())
->save()
;
$event->setTemplate($template);
} | [
"public",
"function",
"create",
"(",
"TemplateCreateEvent",
"$",
"event",
",",
"$",
"eventName",
",",
"EventDispatcherInterface",
"$",
"dispatcher",
")",
"{",
"$",
"template",
"=",
"new",
"TemplateModel",
"(",
")",
";",
"$",
"template",
"->",
"setDispatcher",
... | Create a new template entry
@param \Thelia\Core\Event\Template\TemplateCreateEvent $event
@param $eventName
@param EventDispatcherInterface $dispatcher | [
"Create",
"a",
"new",
"template",
"entry"
] | 38fbe7d5046bad6c0af9ea7c686b4655e8d84e67 | https://github.com/thelia/core/blob/38fbe7d5046bad6c0af9ea7c686b4655e8d84e67/lib/Thelia/Action/Template.php#L48-L62 | train |
thelia/core | lib/Thelia/Action/Template.php | Template.duplicate | public function duplicate(TemplateDuplicateEvent $event, $eventName, EventDispatcherInterface $dispatcher)
{
if (null !== $source = TemplateQuery::create()->findPk($event->getSourceTemplateId())) {
$source->setLocale($event->getLocale());
$createEvent = new TemplateCreateEvent();
$createEvent
->setLocale($event->getLocale())
->setTemplateName(
Translator::getInstance()->trans("Copy of %tpl", ["%tpl" => $source->getName() ])
);
$dispatcher->dispatch(TheliaEvents::TEMPLATE_CREATE, $createEvent);
$clone = $createEvent->getTemplate();
$attrList = AttributeTemplateQuery::create()->findByTemplateId($source->getId());
/** @var $feat AttributeTemplate */
foreach ($attrList as $feat) {
$dispatcher->dispatch(
TheliaEvents::TEMPLATE_ADD_ATTRIBUTE,
new TemplateAddAttributeEvent($clone, $feat->getAttributeId())
);
}
$featList = FeatureTemplateQuery::create()->findByTemplateId($source->getId());
/** @var $feat FeatureTemplate */
foreach ($featList as $feat) {
$dispatcher->dispatch(
TheliaEvents::TEMPLATE_ADD_FEATURE,
new TemplateAddFeatureEvent($clone, $feat->getFeatureId())
);
}
$event->setTemplate($clone);
}
} | php | public function duplicate(TemplateDuplicateEvent $event, $eventName, EventDispatcherInterface $dispatcher)
{
if (null !== $source = TemplateQuery::create()->findPk($event->getSourceTemplateId())) {
$source->setLocale($event->getLocale());
$createEvent = new TemplateCreateEvent();
$createEvent
->setLocale($event->getLocale())
->setTemplateName(
Translator::getInstance()->trans("Copy of %tpl", ["%tpl" => $source->getName() ])
);
$dispatcher->dispatch(TheliaEvents::TEMPLATE_CREATE, $createEvent);
$clone = $createEvent->getTemplate();
$attrList = AttributeTemplateQuery::create()->findByTemplateId($source->getId());
/** @var $feat AttributeTemplate */
foreach ($attrList as $feat) {
$dispatcher->dispatch(
TheliaEvents::TEMPLATE_ADD_ATTRIBUTE,
new TemplateAddAttributeEvent($clone, $feat->getAttributeId())
);
}
$featList = FeatureTemplateQuery::create()->findByTemplateId($source->getId());
/** @var $feat FeatureTemplate */
foreach ($featList as $feat) {
$dispatcher->dispatch(
TheliaEvents::TEMPLATE_ADD_FEATURE,
new TemplateAddFeatureEvent($clone, $feat->getFeatureId())
);
}
$event->setTemplate($clone);
}
} | [
"public",
"function",
"duplicate",
"(",
"TemplateDuplicateEvent",
"$",
"event",
",",
"$",
"eventName",
",",
"EventDispatcherInterface",
"$",
"dispatcher",
")",
"{",
"if",
"(",
"null",
"!==",
"$",
"source",
"=",
"TemplateQuery",
"::",
"create",
"(",
")",
"->",
... | Dupliucate an existing template entry
@param \Thelia\Core\Event\Template\TemplateCreateEvent $event
@param $eventName
@param EventDispatcherInterface $dispatcher | [
"Dupliucate",
"an",
"existing",
"template",
"entry"
] | 38fbe7d5046bad6c0af9ea7c686b4655e8d84e67 | https://github.com/thelia/core/blob/38fbe7d5046bad6c0af9ea7c686b4655e8d84e67/lib/Thelia/Action/Template.php#L71-L109 | train |
thelia/core | lib/Thelia/Action/Template.php | Template.update | public function update(TemplateUpdateEvent $event, $eventName, EventDispatcherInterface $dispatcher)
{
if (null !== $template = TemplateQuery::create()->findPk($event->getTemplateId())) {
$template
->setDispatcher($dispatcher)
->setLocale($event->getLocale())
->setName($event->getTemplateName())
->save();
$event->setTemplate($template);
}
} | php | public function update(TemplateUpdateEvent $event, $eventName, EventDispatcherInterface $dispatcher)
{
if (null !== $template = TemplateQuery::create()->findPk($event->getTemplateId())) {
$template
->setDispatcher($dispatcher)
->setLocale($event->getLocale())
->setName($event->getTemplateName())
->save();
$event->setTemplate($template);
}
} | [
"public",
"function",
"update",
"(",
"TemplateUpdateEvent",
"$",
"event",
",",
"$",
"eventName",
",",
"EventDispatcherInterface",
"$",
"dispatcher",
")",
"{",
"if",
"(",
"null",
"!==",
"$",
"template",
"=",
"TemplateQuery",
"::",
"create",
"(",
")",
"->",
"f... | Change a product template
@param \Thelia\Core\Event\Template\TemplateUpdateEvent $event
@param $eventName
@param EventDispatcherInterface $dispatcher | [
"Change",
"a",
"product",
"template"
] | 38fbe7d5046bad6c0af9ea7c686b4655e8d84e67 | https://github.com/thelia/core/blob/38fbe7d5046bad6c0af9ea7c686b4655e8d84e67/lib/Thelia/Action/Template.php#L118-L130 | train |
thelia/core | lib/Thelia/Action/Template.php | Template.delete | public function delete(TemplateDeleteEvent $event, $eventName, EventDispatcherInterface $dispatcher)
{
if (null !== ($template = TemplateQuery::create()->findPk($event->getTemplateId()))) {
// Check if template is used by a product
$productCount = ProductQuery::create()->findByTemplateId($template->getId())->count();
if ($productCount <= 0) {
$con = Propel::getWriteConnection(TemplateTableMap::DATABASE_NAME);
$con->beginTransaction();
try {
$template
->setDispatcher($dispatcher)
->delete($con);
// We have to also delete any reference of this template in category tables
// We can't use a FK here, as the DefaultTemplateId column may be NULL
// so let's take care of this.
CategoryQuery::create()
->filterByDefaultTemplateId($event->getTemplateId())
->update([ 'DefaultTemplateId' => null], $con);
$con->commit();
} catch (\Exception $ex) {
$con->rollback();
throw $ex;
}
}
$event->setTemplate($template);
$event->setProductCount($productCount);
}
} | php | public function delete(TemplateDeleteEvent $event, $eventName, EventDispatcherInterface $dispatcher)
{
if (null !== ($template = TemplateQuery::create()->findPk($event->getTemplateId()))) {
// Check if template is used by a product
$productCount = ProductQuery::create()->findByTemplateId($template->getId())->count();
if ($productCount <= 0) {
$con = Propel::getWriteConnection(TemplateTableMap::DATABASE_NAME);
$con->beginTransaction();
try {
$template
->setDispatcher($dispatcher)
->delete($con);
// We have to also delete any reference of this template in category tables
// We can't use a FK here, as the DefaultTemplateId column may be NULL
// so let's take care of this.
CategoryQuery::create()
->filterByDefaultTemplateId($event->getTemplateId())
->update([ 'DefaultTemplateId' => null], $con);
$con->commit();
} catch (\Exception $ex) {
$con->rollback();
throw $ex;
}
}
$event->setTemplate($template);
$event->setProductCount($productCount);
}
} | [
"public",
"function",
"delete",
"(",
"TemplateDeleteEvent",
"$",
"event",
",",
"$",
"eventName",
",",
"EventDispatcherInterface",
"$",
"dispatcher",
")",
"{",
"if",
"(",
"null",
"!==",
"(",
"$",
"template",
"=",
"TemplateQuery",
"::",
"create",
"(",
")",
"->... | Delete a product template entry
@param \Thelia\Core\Event\Template\TemplateDeleteEvent $event
@param $eventName
@param EventDispatcherInterface $dispatcher
@throws \Exception | [
"Delete",
"a",
"product",
"template",
"entry"
] | 38fbe7d5046bad6c0af9ea7c686b4655e8d84e67 | https://github.com/thelia/core/blob/38fbe7d5046bad6c0af9ea7c686b4655e8d84e67/lib/Thelia/Action/Template.php#L140-L174 | train |
Symplify/Autodiscovery | src/Doctrine/DoctrineEntityMappingAutodiscoverer.php | DoctrineEntityMappingAutodiscoverer.autodiscover | public function autodiscover(): void
{
$entityMappings = [];
foreach ($this->fileSystem->getEntityDirectories() as $entityDirectory) {
$namespace = $this->namespaceDetector->detectFromDirectory($entityDirectory);
if (! $namespace) {
continue;
}
$entityMappings[] = [
'name' => $namespace, // required name
'prefix' => $namespace,
'type' => 'annotation',
'dir' => $entityDirectory->getRealPath(),
'is_bundle' => false, // performance
];
}
$xmlNamespaces = [];
$directoryByNamespace = $this->resolveDirectoryByNamespace($this->fileSystem->getEntityXmlFiles());
foreach ($directoryByNamespace as $namespace => $directory) {
if (in_array($namespace, $xmlNamespaces, true)) {
continue;
}
$xmlNamespaces[] = $namespace;
$entityMappings[] = [
'name' => $namespace, // required name
'prefix' => $namespace,
'type' => 'xml',
'dir' => $directory,
'is_bundle' => false,
];
}
if (! count($entityMappings)) {
return;
}
// @see https://symfony.com/doc/current/reference/configuration/doctrine.html#mapping-entities-outside-of-a-bundle
$this->containerBuilder->prependExtensionConfig('doctrine', [
'orm' => ['mappings' => $entityMappings],
]);
} | php | public function autodiscover(): void
{
$entityMappings = [];
foreach ($this->fileSystem->getEntityDirectories() as $entityDirectory) {
$namespace = $this->namespaceDetector->detectFromDirectory($entityDirectory);
if (! $namespace) {
continue;
}
$entityMappings[] = [
'name' => $namespace, // required name
'prefix' => $namespace,
'type' => 'annotation',
'dir' => $entityDirectory->getRealPath(),
'is_bundle' => false, // performance
];
}
$xmlNamespaces = [];
$directoryByNamespace = $this->resolveDirectoryByNamespace($this->fileSystem->getEntityXmlFiles());
foreach ($directoryByNamespace as $namespace => $directory) {
if (in_array($namespace, $xmlNamespaces, true)) {
continue;
}
$xmlNamespaces[] = $namespace;
$entityMappings[] = [
'name' => $namespace, // required name
'prefix' => $namespace,
'type' => 'xml',
'dir' => $directory,
'is_bundle' => false,
];
}
if (! count($entityMappings)) {
return;
}
// @see https://symfony.com/doc/current/reference/configuration/doctrine.html#mapping-entities-outside-of-a-bundle
$this->containerBuilder->prependExtensionConfig('doctrine', [
'orm' => ['mappings' => $entityMappings],
]);
} | [
"public",
"function",
"autodiscover",
"(",
")",
":",
"void",
"{",
"$",
"entityMappings",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"fileSystem",
"->",
"getEntityDirectories",
"(",
")",
"as",
"$",
"entityDirectory",
")",
"{",
"$",
"namespace",
... | Needs to run before @see \Symfony\Bridge\Doctrine\DependencyInjection\CompilerPass\RegisterMappingsPass | [
"Needs",
"to",
"run",
"before"
] | dfe7536c4c6e9509d5c0358540272737d0e7954f | https://github.com/Symplify/Autodiscovery/blob/dfe7536c4c6e9509d5c0358540272737d0e7954f/src/Doctrine/DoctrineEntityMappingAutodiscoverer.php#L39-L84 | train |
thelia/core | lib/Thelia/Controller/Admin/AddressController.php | AddressController.createFormDataArray | protected function createFormDataArray($object)
{
return array(
"label" => $object->getLabel(),
"title" => $object->getTitleId(),
"firstname" => $object->getFirstname(),
"lastname" => $object->getLastname(),
"address1" => $object->getAddress1(),
"address2" => $object->getAddress2(),
"address3" => $object->getAddress3(),
"zipcode" => $object->getZipcode(),
"city" => $object->getCity(),
"country" => $object->getCountryId(),
"state" => $object->getStateId(),
"cellphone" => $object->getCellphone(),
"phone" => $object->getPhone(),
"company" => $object->getCompany()
);
} | php | protected function createFormDataArray($object)
{
return array(
"label" => $object->getLabel(),
"title" => $object->getTitleId(),
"firstname" => $object->getFirstname(),
"lastname" => $object->getLastname(),
"address1" => $object->getAddress1(),
"address2" => $object->getAddress2(),
"address3" => $object->getAddress3(),
"zipcode" => $object->getZipcode(),
"city" => $object->getCity(),
"country" => $object->getCountryId(),
"state" => $object->getStateId(),
"cellphone" => $object->getCellphone(),
"phone" => $object->getPhone(),
"company" => $object->getCompany()
);
} | [
"protected",
"function",
"createFormDataArray",
"(",
"$",
"object",
")",
"{",
"return",
"array",
"(",
"\"label\"",
"=>",
"$",
"object",
"->",
"getLabel",
"(",
")",
",",
"\"title\"",
"=>",
"$",
"object",
"->",
"getTitleId",
"(",
")",
",",
"\"firstname\"",
"... | Fills in the form data array
@param unknown $object
@return array | [
"Fills",
"in",
"the",
"form",
"data",
"array"
] | 38fbe7d5046bad6c0af9ea7c686b4655e8d84e67 | https://github.com/thelia/core/blob/38fbe7d5046bad6c0af9ea7c686b4655e8d84e67/lib/Thelia/Controller/Admin/AddressController.php#L102-L120 | train |
thelia/core | lib/Thelia/Controller/Admin/AddressController.php | AddressController.renderEditionTemplate | protected function renderEditionTemplate()
{
return $this->render('customer-edit', array(
"address_id" => $this->getRequest()->get('address_id'),
"page" => $this->getRequest()->get('page'),
"customer_id" => $this->getCustomerId()
));
} | php | protected function renderEditionTemplate()
{
return $this->render('customer-edit', array(
"address_id" => $this->getRequest()->get('address_id'),
"page" => $this->getRequest()->get('page'),
"customer_id" => $this->getCustomerId()
));
} | [
"protected",
"function",
"renderEditionTemplate",
"(",
")",
"{",
"return",
"$",
"this",
"->",
"render",
"(",
"'customer-edit'",
",",
"array",
"(",
"\"address_id\"",
"=>",
"$",
"this",
"->",
"getRequest",
"(",
")",
"->",
"get",
"(",
"'address_id'",
")",
",",
... | Render the edition template | [
"Render",
"the",
"edition",
"template"
] | 38fbe7d5046bad6c0af9ea7c686b4655e8d84e67 | https://github.com/thelia/core/blob/38fbe7d5046bad6c0af9ea7c686b4655e8d84e67/lib/Thelia/Controller/Admin/AddressController.php#L255-L262 | train |
melisplatform/melis-cms | src/Controller/ToolTemplateController.php | ToolTemplateController.renderToolTemplateHeaderRefreshAction | public function renderToolTemplateHeaderRefreshAction()
{
$melisKey = $this->params()->fromRoute('melisKey', '');
$view = new ViewModel();
$view->melisKey = $melisKey;
return $view;
} | php | public function renderToolTemplateHeaderRefreshAction()
{
$melisKey = $this->params()->fromRoute('melisKey', '');
$view = new ViewModel();
$view->melisKey = $melisKey;
return $view;
} | [
"public",
"function",
"renderToolTemplateHeaderRefreshAction",
"(",
")",
"{",
"$",
"melisKey",
"=",
"$",
"this",
"->",
"params",
"(",
")",
"->",
"fromRoute",
"(",
"'melisKey'",
",",
"''",
")",
";",
"$",
"view",
"=",
"new",
"ViewModel",
"(",
")",
";",
"$"... | Renders the refresh button into the Header section of the Tool
@return \Zend\View\Model\ViewModel | [
"Renders",
"the",
"refresh",
"button",
"into",
"the",
"Header",
"section",
"of",
"the",
"Tool"
] | ed470338f4c7653fd93e530013ab934eb7a52b6f | https://github.com/melisplatform/melis-cms/blob/ed470338f4c7653fd93e530013ab934eb7a52b6f/src/Controller/ToolTemplateController.php#L104-L112 | train |
melisplatform/melis-cms | src/Controller/ToolTemplateController.php | ToolTemplateController.renderToolTemplateContentFiltersSitesAction | public function renderToolTemplateContentFiltersSitesAction()
{
$translator = $this->getServiceLocator()->get('translator');
$siteTable = $this->getServiceLocator()->get('MelisEngineTableSite');
$sites = array();
$sites[] = '<option value="">'. $translator->translate('tr_meliscms_tool_templates_tpl_label_choose') .'</option>';
foreach($siteTable->fetchAll() as $site){
$siteName = !empty($site->site_label) ? $site->site_label : $site->site_name;
$sites[] = '<option value="'.$site->site_id.'">'. $siteName .'</option>';
}
$view = new ViewModel();
$view->sites = $sites;
return $view;
} | php | public function renderToolTemplateContentFiltersSitesAction()
{
$translator = $this->getServiceLocator()->get('translator');
$siteTable = $this->getServiceLocator()->get('MelisEngineTableSite');
$sites = array();
$sites[] = '<option value="">'. $translator->translate('tr_meliscms_tool_templates_tpl_label_choose') .'</option>';
foreach($siteTable->fetchAll() as $site){
$siteName = !empty($site->site_label) ? $site->site_label : $site->site_name;
$sites[] = '<option value="'.$site->site_id.'">'. $siteName .'</option>';
}
$view = new ViewModel();
$view->sites = $sites;
return $view;
} | [
"public",
"function",
"renderToolTemplateContentFiltersSitesAction",
"(",
")",
"{",
"$",
"translator",
"=",
"$",
"this",
"->",
"getServiceLocator",
"(",
")",
"->",
"get",
"(",
"'translator'",
")",
";",
"$",
"siteTable",
"=",
"$",
"this",
"->",
"getServiceLocator... | Renders to the site filter selection in the filter bar in the datatable
@return \Zend\View\Model\ViewModel | [
"Renders",
"to",
"the",
"site",
"filter",
"selection",
"in",
"the",
"filter",
"bar",
"in",
"the",
"datatable"
] | ed470338f4c7653fd93e530013ab934eb7a52b6f | https://github.com/melisplatform/melis-cms/blob/ed470338f4c7653fd93e530013ab934eb7a52b6f/src/Controller/ToolTemplateController.php#L127-L143 | train |
melisplatform/melis-cms | src/Controller/ToolTemplateController.php | ToolTemplateController.renderToolTemplatesModalAddHandlerAction | public function renderToolTemplatesModalAddHandlerAction()
{
$melisKey = $this->params()->fromRoute('melisKey', '');
// declare the Tool service that we will be using to completely create our tool.
$melisTool = $this->getServiceLocator()->get('MelisCoreTool');
// tell the Tool what configuration in the app.tool.php that will be used.
$melisTool->setMelisToolKey('meliscms', 'meliscms_tool_templates');
$view = new ViewModel();
$view->addModalHandler = $melisTool->getModal('meliscms_tool_template_add_modal');
$view->melisKey = $melisKey;
return $view;
} | php | public function renderToolTemplatesModalAddHandlerAction()
{
$melisKey = $this->params()->fromRoute('melisKey', '');
// declare the Tool service that we will be using to completely create our tool.
$melisTool = $this->getServiceLocator()->get('MelisCoreTool');
// tell the Tool what configuration in the app.tool.php that will be used.
$melisTool->setMelisToolKey('meliscms', 'meliscms_tool_templates');
$view = new ViewModel();
$view->addModalHandler = $melisTool->getModal('meliscms_tool_template_add_modal');
$view->melisKey = $melisKey;
return $view;
} | [
"public",
"function",
"renderToolTemplatesModalAddHandlerAction",
"(",
")",
"{",
"$",
"melisKey",
"=",
"$",
"this",
"->",
"params",
"(",
")",
"->",
"fromRoute",
"(",
"'melisKey'",
",",
"''",
")",
";",
"// declare the Tool service that we will be using to completely crea... | Renders the Add Tab and Content for the modal
@return \MelisCms\Controller\ViewModel | [
"Renders",
"the",
"Add",
"Tab",
"and",
"Content",
"for",
"the",
"modal"
] | ed470338f4c7653fd93e530013ab934eb7a52b6f | https://github.com/melisplatform/melis-cms/blob/ed470338f4c7653fd93e530013ab934eb7a52b6f/src/Controller/ToolTemplateController.php#L255-L270 | train |
melisplatform/melis-cms | src/Controller/ToolTemplateController.php | ToolTemplateController.renderToolTemplatesModalEditHandlerAction | public function renderToolTemplatesModalEditHandlerAction()
{
$melisKey = $this->params()->fromRoute('melisKey', '');
// declare the Tool service that we will be using to completely create our tool.
$melisTool = $this->getServiceLocator()->get('MelisCoreTool');
// tell the Tool what configuration in the app.tool.php that will be used.
$melisTool->setMelisToolKey('meliscms', 'meliscms_tool_templates');
$view = new ViewModel();
$view->editModalHandler = $melisTool->getModal('meliscms_tool_template_edit_modal');
$view->melisKey = $melisKey;
return $view;
} | php | public function renderToolTemplatesModalEditHandlerAction()
{
$melisKey = $this->params()->fromRoute('melisKey', '');
// declare the Tool service that we will be using to completely create our tool.
$melisTool = $this->getServiceLocator()->get('MelisCoreTool');
// tell the Tool what configuration in the app.tool.php that will be used.
$melisTool->setMelisToolKey('meliscms', 'meliscms_tool_templates');
$view = new ViewModel();
$view->editModalHandler = $melisTool->getModal('meliscms_tool_template_edit_modal');
$view->melisKey = $melisKey;
return $view;
} | [
"public",
"function",
"renderToolTemplatesModalEditHandlerAction",
"(",
")",
"{",
"$",
"melisKey",
"=",
"$",
"this",
"->",
"params",
"(",
")",
"->",
"fromRoute",
"(",
"'melisKey'",
",",
"''",
")",
";",
"// declare the Tool service that we will be using to completely cre... | Renders the Update Tab and Content for the modal
@return \MelisCms\Controller\ViewModel | [
"Renders",
"the",
"Update",
"Tab",
"and",
"Content",
"for",
"the",
"modal"
] | ed470338f4c7653fd93e530013ab934eb7a52b6f | https://github.com/melisplatform/melis-cms/blob/ed470338f4c7653fd93e530013ab934eb7a52b6f/src/Controller/ToolTemplateController.php#L276-L291 | train |
melisplatform/melis-cms | src/Controller/ToolTemplateController.php | ToolTemplateController.renderToolTemplatesModalEmptyHandlerAction | public function renderToolTemplatesModalEmptyHandlerAction()
{
$melisKey = $this->params()->fromRoute('melisKey', '');
$view = new ViewModel();
$view->melisKey = $melisKey;
return $view;
} | php | public function renderToolTemplatesModalEmptyHandlerAction()
{
$melisKey = $this->params()->fromRoute('melisKey', '');
$view = new ViewModel();
$view->melisKey = $melisKey;
return $view;
} | [
"public",
"function",
"renderToolTemplatesModalEmptyHandlerAction",
"(",
")",
"{",
"$",
"melisKey",
"=",
"$",
"this",
"->",
"params",
"(",
")",
"->",
"fromRoute",
"(",
"'melisKey'",
",",
"''",
")",
";",
"$",
"view",
"=",
"new",
"ViewModel",
"(",
")",
";",
... | Handles the empty modal if there's no available modal form for the user.
@return \MelisCms\Controller\ViewModel | [
"Handles",
"the",
"empty",
"modal",
"if",
"there",
"s",
"no",
"available",
"modal",
"form",
"for",
"the",
"user",
"."
] | ed470338f4c7653fd93e530013ab934eb7a52b6f | https://github.com/melisplatform/melis-cms/blob/ed470338f4c7653fd93e530013ab934eb7a52b6f/src/Controller/ToolTemplateController.php#L297-L305 | train |
melisplatform/melis-cms | src/Controller/ToolTemplateController.php | ToolTemplateController.modalTabToolTemplateAddAction | public function modalTabToolTemplateAddAction()
{
// declare the Tool service that we will be using to completely create our tool.
$melisTool = $this->getServiceLocator()->get('MelisCoreTool');
// tell the Tool what configuration in the app.tool.php that will be used.
$melisTool->setMelisToolKey('meliscms', 'meliscms_tool_templates');
$view = new ViewModel();
$view->setVariable('meliscms_tool_template_add', $melisTool->getForm('meliscms_tool_template_generic_form'));
return $view;
} | php | public function modalTabToolTemplateAddAction()
{
// declare the Tool service that we will be using to completely create our tool.
$melisTool = $this->getServiceLocator()->get('MelisCoreTool');
// tell the Tool what configuration in the app.tool.php that will be used.
$melisTool->setMelisToolKey('meliscms', 'meliscms_tool_templates');
$view = new ViewModel();
$view->setVariable('meliscms_tool_template_add', $melisTool->getForm('meliscms_tool_template_generic_form'));
return $view;
} | [
"public",
"function",
"modalTabToolTemplateAddAction",
"(",
")",
"{",
"// declare the Tool service that we will be using to completely create our tool.",
"$",
"melisTool",
"=",
"$",
"this",
"->",
"getServiceLocator",
"(",
")",
"->",
"get",
"(",
"'MelisCoreTool'",
")",
";",
... | This will be used to render the add form in the modal tab | [
"This",
"will",
"be",
"used",
"to",
"render",
"the",
"add",
"form",
"in",
"the",
"modal",
"tab"
] | ed470338f4c7653fd93e530013ab934eb7a52b6f | https://github.com/melisplatform/melis-cms/blob/ed470338f4c7653fd93e530013ab934eb7a52b6f/src/Controller/ToolTemplateController.php#L310-L323 | train |
melisplatform/melis-cms | src/Controller/ToolTemplateController.php | ToolTemplateController.getTemplateByPageIdAction | public function getTemplateByPageIdAction()
{
$success = 0;
$request = $this->getRequest();
$data = array();
if($request->isPost())
{
$template = $this->getServiceLocator()->get("MelisPageTemplate");
$success = 2;
$data = $template->getTemplate($pageId);
}
return $data;
} | php | public function getTemplateByPageIdAction()
{
$success = 0;
$request = $this->getRequest();
$data = array();
if($request->isPost())
{
$template = $this->getServiceLocator()->get("MelisPageTemplate");
$success = 2;
$data = $template->getTemplate($pageId);
}
return $data;
} | [
"public",
"function",
"getTemplateByPageIdAction",
"(",
")",
"{",
"$",
"success",
"=",
"0",
";",
"$",
"request",
"=",
"$",
"this",
"->",
"getRequest",
"(",
")",
";",
"$",
"data",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"request",
"->",
"isPost",... | Return template of a page
return array | [
"Return",
"template",
"of",
"a",
"page"
] | ed470338f4c7653fd93e530013ab934eb7a52b6f | https://github.com/melisplatform/melis-cms/blob/ed470338f4c7653fd93e530013ab934eb7a52b6f/src/Controller/ToolTemplateController.php#L348-L363 | train |
melisplatform/melis-cms | src/Controller/ToolTemplateController.php | ToolTemplateController.getControllers | protected function getControllers(string $controllersPath) : array
{
$controllers = [];
// List all controller files inside the ..src/controller folder
if (is_dir($controllersPath)) {
foreach (scandir($controllersPath) as $controller) {
// Skip directory pointers
if ($controller == '.' || $controller == '..' || is_dir($controllersPath . '/' . $controller)) {
continue;
}
// Check if file's extension is ".php"
$filePath = $controllersPath . '/' . $controller;
$fileExt = pathinfo($filePath)['extension'];
if ($fileExt == 'php' && is_file($filePath)) {
$controllers[] = $controller;
}
}
}
return $controllers;
} | php | protected function getControllers(string $controllersPath) : array
{
$controllers = [];
// List all controller files inside the ..src/controller folder
if (is_dir($controllersPath)) {
foreach (scandir($controllersPath) as $controller) {
// Skip directory pointers
if ($controller == '.' || $controller == '..' || is_dir($controllersPath . '/' . $controller)) {
continue;
}
// Check if file's extension is ".php"
$filePath = $controllersPath . '/' . $controller;
$fileExt = pathinfo($filePath)['extension'];
if ($fileExt == 'php' && is_file($filePath)) {
$controllers[] = $controller;
}
}
}
return $controllers;
} | [
"protected",
"function",
"getControllers",
"(",
"string",
"$",
"controllersPath",
")",
":",
"array",
"{",
"$",
"controllers",
"=",
"[",
"]",
";",
"// List all controller files inside the ..src/controller folder",
"if",
"(",
"is_dir",
"(",
"$",
"controllersPath",
")",
... | Returns a module's controllers
@return array | [
"Returns",
"a",
"module",
"s",
"controllers"
] | ed470338f4c7653fd93e530013ab934eb7a52b6f | https://github.com/melisplatform/melis-cms/blob/ed470338f4c7653fd93e530013ab934eb7a52b6f/src/Controller/ToolTemplateController.php#L778-L800 | train |
melisplatform/melis-cms | src/Controller/ToolTemplateController.php | ToolTemplateController.getTemplateDataByIdAction | public function getTemplateDataByIdAction()
{
$request = $this->getRequest();
$data = array();
if($request->isPost())
{
$templatesModel = $this->getServiceLocator()->get('MelisEngineTableTemplate');
$templateId = $request->getPost('templateId');
if(is_numeric($templateId))
$data = $templatesModel->getEntryById($templateId);
}
return new JsonModel($data);
} | php | public function getTemplateDataByIdAction()
{
$request = $this->getRequest();
$data = array();
if($request->isPost())
{
$templatesModel = $this->getServiceLocator()->get('MelisEngineTableTemplate');
$templateId = $request->getPost('templateId');
if(is_numeric($templateId))
$data = $templatesModel->getEntryById($templateId);
}
return new JsonModel($data);
} | [
"public",
"function",
"getTemplateDataByIdAction",
"(",
")",
"{",
"$",
"request",
"=",
"$",
"this",
"->",
"getRequest",
"(",
")",
";",
"$",
"data",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"request",
"->",
"isPost",
"(",
")",
")",
"{",
"$",
"te... | Returns all information of the specific template data | [
"Returns",
"all",
"information",
"of",
"the",
"specific",
"template",
"data"
] | ed470338f4c7653fd93e530013ab934eb7a52b6f | https://github.com/melisplatform/melis-cms/blob/ed470338f4c7653fd93e530013ab934eb7a52b6f/src/Controller/ToolTemplateController.php#L1059-L1074 | train |
BoldGrid/library | src/Library/License.php | License.ajaxClear | public function ajaxClear() {
$plugin = ! empty( $_POST['plugin'] ) ? sanitize_text_field( $_POST['plugin'] ) : null;
if ( empty( $plugin ) ) {
wp_send_json_error( __( 'Unknown plugin.', 'boldgrid-library' ) );
}
if ( ! current_user_can( 'manage_options' ) ) {
wp_send_json_error( __( 'Access denied.', 'boldgrid-library' ) );
}
$success = $this->clearTransient();
if ( ! $success ) {
wp_send_json_error( array(
'string' => sprintf(
// translators: 1 The name of a transient that we were unable to delete.
__( 'Failed to clear license data. Unable to delete site transient "%1$s".', 'boldgrid-library' ),
$this->getKey()
),
));
}
$this->initLicense();
$return = array(
'isPremium' => $this->isPremium( $plugin ),
'string' => $this->licenseString,
);
wp_send_json_success( $return );
} | php | public function ajaxClear() {
$plugin = ! empty( $_POST['plugin'] ) ? sanitize_text_field( $_POST['plugin'] ) : null;
if ( empty( $plugin ) ) {
wp_send_json_error( __( 'Unknown plugin.', 'boldgrid-library' ) );
}
if ( ! current_user_can( 'manage_options' ) ) {
wp_send_json_error( __( 'Access denied.', 'boldgrid-library' ) );
}
$success = $this->clearTransient();
if ( ! $success ) {
wp_send_json_error( array(
'string' => sprintf(
// translators: 1 The name of a transient that we were unable to delete.
__( 'Failed to clear license data. Unable to delete site transient "%1$s".', 'boldgrid-library' ),
$this->getKey()
),
));
}
$this->initLicense();
$return = array(
'isPremium' => $this->isPremium( $plugin ),
'string' => $this->licenseString,
);
wp_send_json_success( $return );
} | [
"public",
"function",
"ajaxClear",
"(",
")",
"{",
"$",
"plugin",
"=",
"!",
"empty",
"(",
"$",
"_POST",
"[",
"'plugin'",
"]",
")",
"?",
"sanitize_text_field",
"(",
"$",
"_POST",
"[",
"'plugin'",
"]",
")",
":",
"null",
";",
"if",
"(",
"empty",
"(",
"... | Handle ajax request to clear license data.
@since 2.2.0
@hook: wp_ajax_bg_clear_license | [
"Handle",
"ajax",
"request",
"to",
"clear",
"license",
"data",
"."
] | 51afe070e211cff9cf78454ff97912a0d943805c | https://github.com/BoldGrid/library/blob/51afe070e211cff9cf78454ff97912a0d943805c/src/Library/License.php#L71-L101 | train |
BoldGrid/library | src/Library/License.php | License.registerScripts | public function registerScripts() {
$handle = 'bglib-license';
wp_register_script(
$handle,
Library\Configs::get( 'libraryUrl' ) . 'src/assets/js/license.js',
'jQuery'
);
$translations = array(
'unknownError' => __( 'Unknown error', 'boldgrid-library' ),
);
wp_localize_script( $handle, 'bglibLicense', $translations );
} | php | public function registerScripts() {
$handle = 'bglib-license';
wp_register_script(
$handle,
Library\Configs::get( 'libraryUrl' ) . 'src/assets/js/license.js',
'jQuery'
);
$translations = array(
'unknownError' => __( 'Unknown error', 'boldgrid-library' ),
);
wp_localize_script( $handle, 'bglibLicense', $translations );
} | [
"public",
"function",
"registerScripts",
"(",
")",
"{",
"$",
"handle",
"=",
"'bglib-license'",
";",
"wp_register_script",
"(",
"$",
"handle",
",",
"Library",
"\\",
"Configs",
"::",
"get",
"(",
"'libraryUrl'",
")",
".",
"'src/assets/js/license.js'",
",",
"'jQuery... | Register scripts.
@since 2.2.0
@hook: admin_enqueue_scripts | [
"Register",
"scripts",
"."
] | 51afe070e211cff9cf78454ff97912a0d943805c | https://github.com/BoldGrid/library/blob/51afe070e211cff9cf78454ff97912a0d943805c/src/Library/License.php#L110-L124 | train |
BoldGrid/library | src/Library/License.php | License.setLicense | private function setLicense() {
if ( ! $this->getApiKey() ) {
$license = 'Missing Connect Key';
} else if ( ! ( $license = $this->getTransient() ) || ! $this->isVersionValid( $license ) ) {
delete_site_transient( $this->getKey() );
$license = $this->getRemoteLicense();
}
return $this->license = $license;
} | php | private function setLicense() {
if ( ! $this->getApiKey() ) {
$license = 'Missing Connect Key';
} else if ( ! ( $license = $this->getTransient() ) || ! $this->isVersionValid( $license ) ) {
delete_site_transient( $this->getKey() );
$license = $this->getRemoteLicense();
}
return $this->license = $license;
} | [
"private",
"function",
"setLicense",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"getApiKey",
"(",
")",
")",
"{",
"$",
"license",
"=",
"'Missing Connect Key'",
";",
"}",
"else",
"if",
"(",
"!",
"(",
"$",
"license",
"=",
"$",
"this",
"->",
"ge... | Set the license class property.
@since 1.0.0
@return mixed $license The response object or error string of call. | [
"Set",
"the",
"license",
"class",
"property",
"."
] | 51afe070e211cff9cf78454ff97912a0d943805c | https://github.com/BoldGrid/library/blob/51afe070e211cff9cf78454ff97912a0d943805c/src/Library/License.php#L146-L155 | train |
BoldGrid/library | src/Library/License.php | License.setTransient | private function setTransient() {
return ! $this->getTransient() && set_site_transient( $this->getKey(), $this->getLicense(), $this->getExpiration( $this->getData() ) );
} | php | private function setTransient() {
return ! $this->getTransient() && set_site_transient( $this->getKey(), $this->getLicense(), $this->getExpiration( $this->getData() ) );
} | [
"private",
"function",
"setTransient",
"(",
")",
"{",
"return",
"!",
"$",
"this",
"->",
"getTransient",
"(",
")",
"&&",
"set_site_transient",
"(",
"$",
"this",
"->",
"getKey",
"(",
")",
",",
"$",
"this",
"->",
"getLicense",
"(",
")",
",",
"$",
"this",
... | Sets the transient for the license data.
@since 1.0.0
@return bool Was the transient successfully set? | [
"Sets",
"the",
"transient",
"for",
"the",
"license",
"data",
"."
] | 51afe070e211cff9cf78454ff97912a0d943805c | https://github.com/BoldGrid/library/blob/51afe070e211cff9cf78454ff97912a0d943805c/src/Library/License.php#L164-L166 | train |
BoldGrid/library | src/Library/License.php | License.isValid | private function isValid() {
$data = $this->getTransient();
$valid = array( 'key', 'cipher', 'iv', 'data' );
if ( is_object( $data ) ) {
$props = array_keys( get_object_vars( $data ) );
$valid = array_diff( $valid, $props );
}
return empty( $valid );
} | php | private function isValid() {
$data = $this->getTransient();
$valid = array( 'key', 'cipher', 'iv', 'data' );
if ( is_object( $data ) ) {
$props = array_keys( get_object_vars( $data ) );
$valid = array_diff( $valid, $props );
}
return empty( $valid );
} | [
"private",
"function",
"isValid",
"(",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"getTransient",
"(",
")",
";",
"$",
"valid",
"=",
"array",
"(",
"'key'",
",",
"'cipher'",
",",
"'iv'",
",",
"'data'",
")",
";",
"if",
"(",
"is_object",
"(",
"$",
... | Check if the current license is valid.
Is valid if the refresh-by timestamp is not more than 1 day past due.
@since 1.0.0
@return mixed Checks if the license data is available. | [
"Check",
"if",
"the",
"current",
"license",
"is",
"valid",
"."
] | 51afe070e211cff9cf78454ff97912a0d943805c | https://github.com/BoldGrid/library/blob/51afe070e211cff9cf78454ff97912a0d943805c/src/Library/License.php#L177-L186 | train |
BoldGrid/library | src/Library/License.php | License.setData | private function setData() {
if ( $license = $this->getLicense() ) {
$data = json_decode(
openssl_decrypt(
$license->data,
$license->cipher,
$license->key,
0,
urldecode( $license->iv )
)
);
}
return $this->data = $data;
} | php | private function setData() {
if ( $license = $this->getLicense() ) {
$data = json_decode(
openssl_decrypt(
$license->data,
$license->cipher,
$license->key,
0,
urldecode( $license->iv )
)
);
}
return $this->data = $data;
} | [
"private",
"function",
"setData",
"(",
")",
"{",
"if",
"(",
"$",
"license",
"=",
"$",
"this",
"->",
"getLicense",
"(",
")",
")",
"{",
"$",
"data",
"=",
"json_decode",
"(",
"openssl_decrypt",
"(",
"$",
"license",
"->",
"data",
",",
"$",
"license",
"->... | Set the data class property.
@since 1.0.0
@return object $data The license data class property. | [
"Set",
"the",
"data",
"class",
"property",
"."
] | 51afe070e211cff9cf78454ff97912a0d943805c | https://github.com/BoldGrid/library/blob/51afe070e211cff9cf78454ff97912a0d943805c/src/Library/License.php#L195-L209 | train |
BoldGrid/library | src/Library/License.php | License.deactivate | public function deactivate() {
if ( ! $this->isValid() && Configs::get( 'licenseActivate' ) ) {
delete_site_transient( $this->getKey() );
deactivate_plugins( Configs::get( 'file' ) );
}
} | php | public function deactivate() {
if ( ! $this->isValid() && Configs::get( 'licenseActivate' ) ) {
delete_site_transient( $this->getKey() );
deactivate_plugins( Configs::get( 'file' ) );
}
} | [
"public",
"function",
"deactivate",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isValid",
"(",
")",
"&&",
"Configs",
"::",
"get",
"(",
"'licenseActivate'",
")",
")",
"{",
"delete_site_transient",
"(",
"$",
"this",
"->",
"getKey",
"(",
")",
")",
... | Runs plugin deactivation when deactivate_plugins is available.
@since 1.0.0
@hook: admin_init | [
"Runs",
"plugin",
"deactivation",
"when",
"deactivate_plugins",
"is",
"available",
"."
] | 51afe070e211cff9cf78454ff97912a0d943805c | https://github.com/BoldGrid/library/blob/51afe070e211cff9cf78454ff97912a0d943805c/src/Library/License.php#L233-L238 | train |
BoldGrid/library | src/Library/License.php | License.getRemoteLicense | private function getRemoteLicense() {
$call = new Api\Call( Configs::get( 'api' ) . '/api/plugin/getLicense?v=' .
$this->apiVersion );
if ( ! $response = $call->getError() ) {
$response = $call->getResponse()->result->data;
}
return $response;
} | php | private function getRemoteLicense() {
$call = new Api\Call( Configs::get( 'api' ) . '/api/plugin/getLicense?v=' .
$this->apiVersion );
if ( ! $response = $call->getError() ) {
$response = $call->getResponse()->result->data;
}
return $response;
} | [
"private",
"function",
"getRemoteLicense",
"(",
")",
"{",
"$",
"call",
"=",
"new",
"Api",
"\\",
"Call",
"(",
"Configs",
"::",
"get",
"(",
"'api'",
")",
".",
"'/api/plugin/getLicense?v='",
".",
"$",
"this",
"->",
"apiVersion",
")",
";",
"if",
"(",
"!",
... | Get the latest license data from the API server.
The current API version is 2.
@since 1.0.0
@return mixed $response The remote license data object or error string. | [
"Get",
"the",
"latest",
"license",
"data",
"from",
"the",
"API",
"server",
"."
] | 51afe070e211cff9cf78454ff97912a0d943805c | https://github.com/BoldGrid/library/blob/51afe070e211cff9cf78454ff97912a0d943805c/src/Library/License.php#L262-L271 | train |
BoldGrid/library | src/Library/License.php | License.initLicense | public function initLicense() {
$this->license = $this->setLicense();
if ( is_object( $this->getLicense() ) ) {
$this->data = $this->setData();
$this->setTransient( $this->getData() );
$licenseData = array( 'licenseData' => $this->getData() );
Configs::set( $licenseData, Configs::get() );
}
} | php | public function initLicense() {
$this->license = $this->setLicense();
if ( is_object( $this->getLicense() ) ) {
$this->data = $this->setData();
$this->setTransient( $this->getData() );
$licenseData = array( 'licenseData' => $this->getData() );
Configs::set( $licenseData, Configs::get() );
}
} | [
"public",
"function",
"initLicense",
"(",
")",
"{",
"$",
"this",
"->",
"license",
"=",
"$",
"this",
"->",
"setLicense",
"(",
")",
";",
"if",
"(",
"is_object",
"(",
"$",
"this",
"->",
"getLicense",
"(",
")",
")",
")",
"{",
"$",
"this",
"->",
"data",... | Init the license.
This method was originally contained within the constructor, however it
was pulled out as it was needed in additional places. For example, in cases
we instantiate this class and then clear the license data, we may need to
get fresh license data at that time by initializing the license again.
@since 2.2.0 | [
"Init",
"the",
"license",
"."
] | 51afe070e211cff9cf78454ff97912a0d943805c | https://github.com/BoldGrid/library/blob/51afe070e211cff9cf78454ff97912a0d943805c/src/Library/License.php#L375-L384 | train |
BoldGrid/library | src/Library/License.php | License.isPremium | public function isPremium( $product ) {
$isPremium = isset( $this->getData()->$product );
$this->licenseString = $isPremium ?
__( 'Premium', 'boldgrid-connect' ) : __( 'Free', 'boldgrid-library' );
return $isPremium;
} | php | public function isPremium( $product ) {
$isPremium = isset( $this->getData()->$product );
$this->licenseString = $isPremium ?
__( 'Premium', 'boldgrid-connect' ) : __( 'Free', 'boldgrid-library' );
return $isPremium;
} | [
"public",
"function",
"isPremium",
"(",
"$",
"product",
")",
"{",
"$",
"isPremium",
"=",
"isset",
"(",
"$",
"this",
"->",
"getData",
"(",
")",
"->",
"$",
"product",
")",
";",
"$",
"this",
"->",
"licenseString",
"=",
"$",
"isPremium",
"?",
"__",
"(",
... | Checks if product is premium or free.
@since 1.1.4
@hook Boldgrid\Library\License\isPremium
@return bool | [
"Checks",
"if",
"product",
"is",
"premium",
"or",
"free",
"."
] | 51afe070e211cff9cf78454ff97912a0d943805c | https://github.com/BoldGrid/library/blob/51afe070e211cff9cf78454ff97912a0d943805c/src/Library/License.php#L395-L402 | train |
BoldGrid/library | src/Library/License.php | License.isVersionValid | public function isVersionValid( $license ) {
return ( ! empty( $license->version ) && ! empty( $license->iv ) &&
16 === strlen( urldecode( $license->iv ) ) &&
$this->apiVersion === $license->version );
} | php | public function isVersionValid( $license ) {
return ( ! empty( $license->version ) && ! empty( $license->iv ) &&
16 === strlen( urldecode( $license->iv ) ) &&
$this->apiVersion === $license->version );
} | [
"public",
"function",
"isVersionValid",
"(",
"$",
"license",
")",
"{",
"return",
"(",
"!",
"empty",
"(",
"$",
"license",
"->",
"version",
")",
"&&",
"!",
"empty",
"(",
"$",
"license",
"->",
"iv",
")",
"&&",
"16",
"===",
"strlen",
"(",
"urldecode",
"(... | Check if the license version and encoding is correct.
The license data is valid (for the API version) if the "version" and "iv" properties are set,
the decoded initialization vector (iv) is 16 characters in length, and the "version" is
$this->apiVersion.
@since 2.4.0
@param Object $license Current license data.
@return bool | [
"Check",
"if",
"the",
"license",
"version",
"and",
"encoding",
"is",
"correct",
"."
] | 51afe070e211cff9cf78454ff97912a0d943805c | https://github.com/BoldGrid/library/blob/51afe070e211cff9cf78454ff97912a0d943805c/src/Library/License.php#L417-L421 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.