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 |
---|---|---|---|---|---|---|---|---|---|---|---|
contao-community-alliance/dc-general | src/DataDefinition/Palette/Builder/PaletteBuilder.php | PaletteBuilder.createProperty | public function createProperty($propertyName, $_ = null)
{
if ($this->property) {
$this->finishProperty();
}
$propertyNames = \func_get_args();
$this->property = [];
foreach ($propertyNames as $propertyName) {
$property = $this->propertyClass->newInstance($propertyName);
$event = new CreatePropertyEvent($property, $this);
$this->dispatchEvent($event);
$property = $event->getProperty();
$this->property[] = $property;
}
if (1 === \count($this->property)) {
$this->property = \array_shift($this->property);
}
return $this;
} | php | public function createProperty($propertyName, $_ = null)
{
if ($this->property) {
$this->finishProperty();
}
$propertyNames = \func_get_args();
$this->property = [];
foreach ($propertyNames as $propertyName) {
$property = $this->propertyClass->newInstance($propertyName);
$event = new CreatePropertyEvent($property, $this);
$this->dispatchEvent($event);
$property = $event->getProperty();
$this->property[] = $property;
}
if (1 === \count($this->property)) {
$this->property = \array_shift($this->property);
}
return $this;
} | [
"public",
"function",
"createProperty",
"(",
"$",
"propertyName",
",",
"$",
"_",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"property",
")",
"{",
"$",
"this",
"->",
"finishProperty",
"(",
")",
";",
"}",
"$",
"propertyNames",
"=",
"\\",
"func_get_args",
"(",
")",
";",
"$",
"this",
"->",
"property",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"propertyNames",
"as",
"$",
"propertyName",
")",
"{",
"$",
"property",
"=",
"$",
"this",
"->",
"propertyClass",
"->",
"newInstance",
"(",
"$",
"propertyName",
")",
";",
"$",
"event",
"=",
"new",
"CreatePropertyEvent",
"(",
"$",
"property",
",",
"$",
"this",
")",
";",
"$",
"this",
"->",
"dispatchEvent",
"(",
"$",
"event",
")",
";",
"$",
"property",
"=",
"$",
"event",
"->",
"getProperty",
"(",
")",
";",
"$",
"this",
"->",
"property",
"[",
"]",
"=",
"$",
"property",
";",
"}",
"if",
"(",
"1",
"===",
"\\",
"count",
"(",
"$",
"this",
"->",
"property",
")",
")",
"{",
"$",
"this",
"->",
"property",
"=",
"\\",
"array_shift",
"(",
"$",
"this",
"->",
"property",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Start a new single property or set of properties.
@param string $propertyName The name of the property.
@param PropertyInterface $_ Any more subsequent property names to be used.
@return PaletteBuilder
@SuppressWarnings(PHPMD.UnusedFormalParameter)
@SuppressWarnings(PHPMD.ShortVariable)
@SuppressWarnings(PHPMD.CamelCaseParameterName) | [
"Start",
"a",
"new",
"single",
"property",
"or",
"set",
"of",
"properties",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/DataDefinition/Palette/Builder/PaletteBuilder.php#L886-L910 | train |
contao-community-alliance/dc-general | src/DataDefinition/Palette/Builder/PaletteBuilder.php | PaletteBuilder.finishProperty | public function finishProperty(&$property = null)
{
if (!$this->property) {
throw new DcGeneralRuntimeException('Property is missing, please create a property first');
}
if ($this->condition) {
$this->finishCondition();
}
$properties = \is_object($this->property) ? [$this->property] : $this->property;
foreach ($properties as $index => $tempProperty) {
$event = new FinishPropertyEvent($tempProperty, $this);
$this->dispatchEvent($event);
$properties[$index] = $event->getProperty();
}
if ($this->legend) {
$this->legend->addProperties($properties);
}
$property = $properties;
$this->property = null;
return $this;
} | php | public function finishProperty(&$property = null)
{
if (!$this->property) {
throw new DcGeneralRuntimeException('Property is missing, please create a property first');
}
if ($this->condition) {
$this->finishCondition();
}
$properties = \is_object($this->property) ? [$this->property] : $this->property;
foreach ($properties as $index => $tempProperty) {
$event = new FinishPropertyEvent($tempProperty, $this);
$this->dispatchEvent($event);
$properties[$index] = $event->getProperty();
}
if ($this->legend) {
$this->legend->addProperties($properties);
}
$property = $properties;
$this->property = null;
return $this;
} | [
"public",
"function",
"finishProperty",
"(",
"&",
"$",
"property",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"property",
")",
"{",
"throw",
"new",
"DcGeneralRuntimeException",
"(",
"'Property is missing, please create a property first'",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"condition",
")",
"{",
"$",
"this",
"->",
"finishCondition",
"(",
")",
";",
"}",
"$",
"properties",
"=",
"\\",
"is_object",
"(",
"$",
"this",
"->",
"property",
")",
"?",
"[",
"$",
"this",
"->",
"property",
"]",
":",
"$",
"this",
"->",
"property",
";",
"foreach",
"(",
"$",
"properties",
"as",
"$",
"index",
"=>",
"$",
"tempProperty",
")",
"{",
"$",
"event",
"=",
"new",
"FinishPropertyEvent",
"(",
"$",
"tempProperty",
",",
"$",
"this",
")",
";",
"$",
"this",
"->",
"dispatchEvent",
"(",
"$",
"event",
")",
";",
"$",
"properties",
"[",
"$",
"index",
"]",
"=",
"$",
"event",
"->",
"getProperty",
"(",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"legend",
")",
"{",
"$",
"this",
"->",
"legend",
"->",
"addProperties",
"(",
"$",
"properties",
")",
";",
"}",
"$",
"property",
"=",
"$",
"properties",
";",
"$",
"this",
"->",
"property",
"=",
"null",
";",
"return",
"$",
"this",
";",
"}"
]
| Finish the current property or set of properties.
@param PropertyInterface|PropertyInterface[] $property Return the final property or set of properties.
@return PaletteBuilder
@throws DcGeneralRuntimeException When no property is stored in the builder. | [
"Finish",
"the",
"current",
"property",
"or",
"set",
"of",
"properties",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/DataDefinition/Palette/Builder/PaletteBuilder.php#L921-L948 | train |
contao-community-alliance/dc-general | src/DataDefinition/Palette/Builder/PaletteBuilder.php | PaletteBuilder.createDefaultPaletteCondition | public function createDefaultPaletteCondition()
{
if ($this->condition) {
$this->finishCondition();
}
if (!$this->palette) {
throw new DcGeneralRuntimeException(
'Does not know where to create the property-value condition, please create a palette or property first'
);
}
$condition = $this->defaultPaletteConditionClass->newInstance();
$event = new CreateDefaultPaletteConditionEvent($condition, $this);
$this->dispatchEvent($event);
$condition = $event->getDefaultPaletteCondition();
$event = new CreateConditionEvent($condition, $this);
$this->dispatchEvent($event);
$this->condition = $event->getCondition();
return $this;
} | php | public function createDefaultPaletteCondition()
{
if ($this->condition) {
$this->finishCondition();
}
if (!$this->palette) {
throw new DcGeneralRuntimeException(
'Does not know where to create the property-value condition, please create a palette or property first'
);
}
$condition = $this->defaultPaletteConditionClass->newInstance();
$event = new CreateDefaultPaletteConditionEvent($condition, $this);
$this->dispatchEvent($event);
$condition = $event->getDefaultPaletteCondition();
$event = new CreateConditionEvent($condition, $this);
$this->dispatchEvent($event);
$this->condition = $event->getCondition();
return $this;
} | [
"public",
"function",
"createDefaultPaletteCondition",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"condition",
")",
"{",
"$",
"this",
"->",
"finishCondition",
"(",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"palette",
")",
"{",
"throw",
"new",
"DcGeneralRuntimeException",
"(",
"'Does not know where to create the property-value condition, please create a palette or property first'",
")",
";",
"}",
"$",
"condition",
"=",
"$",
"this",
"->",
"defaultPaletteConditionClass",
"->",
"newInstance",
"(",
")",
";",
"$",
"event",
"=",
"new",
"CreateDefaultPaletteConditionEvent",
"(",
"$",
"condition",
",",
"$",
"this",
")",
";",
"$",
"this",
"->",
"dispatchEvent",
"(",
"$",
"event",
")",
";",
"$",
"condition",
"=",
"$",
"event",
"->",
"getDefaultPaletteCondition",
"(",
")",
";",
"$",
"event",
"=",
"new",
"CreateConditionEvent",
"(",
"$",
"condition",
",",
"$",
"this",
")",
";",
"$",
"this",
"->",
"dispatchEvent",
"(",
"$",
"event",
")",
";",
"$",
"this",
"->",
"condition",
"=",
"$",
"event",
"->",
"getCondition",
"(",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Start a new default-palette condition.
@return PaletteBuilder
@throws DcGeneralRuntimeException When no palette or property has been stored. | [
"Start",
"a",
"new",
"default",
"-",
"palette",
"condition",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/DataDefinition/Palette/Builder/PaletteBuilder.php#L1015-L1037 | train |
contao-community-alliance/dc-general | src/DataDefinition/Palette/Builder/PaletteBuilder.php | PaletteBuilder.chainDefaultPaletteCondition | public function chainDefaultPaletteCondition()
{
if (!$this->palette) {
throw new DcGeneralRuntimeException(
'Does not know where to create the property-value condition, please create a palette or property first'
);
}
$this->createPaletteConditionChain();
$condition = $this->defaultPaletteConditionClass->newInstance();
$event = new CreateDefaultPaletteConditionEvent($condition, $this);
$this->dispatchEvent($event);
$condition = $event->getDefaultPaletteCondition();
$event = new CreateConditionEvent($condition, $this);
$this->dispatchEvent($event);
$condition = $event->getCondition();
$this->condition->addCondition($condition);
return $this;
} | php | public function chainDefaultPaletteCondition()
{
if (!$this->palette) {
throw new DcGeneralRuntimeException(
'Does not know where to create the property-value condition, please create a palette or property first'
);
}
$this->createPaletteConditionChain();
$condition = $this->defaultPaletteConditionClass->newInstance();
$event = new CreateDefaultPaletteConditionEvent($condition, $this);
$this->dispatchEvent($event);
$condition = $event->getDefaultPaletteCondition();
$event = new CreateConditionEvent($condition, $this);
$this->dispatchEvent($event);
$condition = $event->getCondition();
$this->condition->addCondition($condition);
return $this;
} | [
"public",
"function",
"chainDefaultPaletteCondition",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"palette",
")",
"{",
"throw",
"new",
"DcGeneralRuntimeException",
"(",
"'Does not know where to create the property-value condition, please create a palette or property first'",
")",
";",
"}",
"$",
"this",
"->",
"createPaletteConditionChain",
"(",
")",
";",
"$",
"condition",
"=",
"$",
"this",
"->",
"defaultPaletteConditionClass",
"->",
"newInstance",
"(",
")",
";",
"$",
"event",
"=",
"new",
"CreateDefaultPaletteConditionEvent",
"(",
"$",
"condition",
",",
"$",
"this",
")",
";",
"$",
"this",
"->",
"dispatchEvent",
"(",
"$",
"event",
")",
";",
"$",
"condition",
"=",
"$",
"event",
"->",
"getDefaultPaletteCondition",
"(",
")",
";",
"$",
"event",
"=",
"new",
"CreateConditionEvent",
"(",
"$",
"condition",
",",
"$",
"this",
")",
";",
"$",
"this",
"->",
"dispatchEvent",
"(",
"$",
"event",
")",
";",
"$",
"condition",
"=",
"$",
"event",
"->",
"getCondition",
"(",
")",
";",
"$",
"this",
"->",
"condition",
"->",
"addCondition",
"(",
"$",
"condition",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Start a new default-palette condition and chain with previous condition.
@return PaletteBuilder
@throws DcGeneralRuntimeException When no palette or property has been stored. | [
"Start",
"a",
"new",
"default",
"-",
"palette",
"condition",
"and",
"chain",
"with",
"previous",
"condition",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/DataDefinition/Palette/Builder/PaletteBuilder.php#L1046-L1068 | train |
contao-community-alliance/dc-general | src/DataDefinition/Palette/Builder/PaletteBuilder.php | PaletteBuilder.createPropertyValueCondition | public function createPropertyValueCondition($propertyName, $propertyValue, $strict = false)
{
if ($this->condition) {
$this->finishCondition();
}
if ($this->property) {
$condition = $this->propertyValueConditionClass->newInstance();
} elseif ($this->palette) {
$condition = $this->palettePropertyValueConditionClass->newInstance();
} else {
throw new DcGeneralRuntimeException(
'Does not know where to create the property-value condition, please create a palette or property first'
);
}
$condition->setPropertyName($propertyName);
$condition->setPropertyValue($propertyValue);
$condition->setStrict($strict);
$event = new CreatePropertyValueConditionEvent($condition, $this);
$this->dispatchEvent($event);
$condition = $event->getPropertyValueCondition();
$event = new CreateConditionEvent($condition, $this);
$this->dispatchEvent($event);
$condition = $event->getCondition();
$this->condition = $condition;
return $this;
} | php | public function createPropertyValueCondition($propertyName, $propertyValue, $strict = false)
{
if ($this->condition) {
$this->finishCondition();
}
if ($this->property) {
$condition = $this->propertyValueConditionClass->newInstance();
} elseif ($this->palette) {
$condition = $this->palettePropertyValueConditionClass->newInstance();
} else {
throw new DcGeneralRuntimeException(
'Does not know where to create the property-value condition, please create a palette or property first'
);
}
$condition->setPropertyName($propertyName);
$condition->setPropertyValue($propertyValue);
$condition->setStrict($strict);
$event = new CreatePropertyValueConditionEvent($condition, $this);
$this->dispatchEvent($event);
$condition = $event->getPropertyValueCondition();
$event = new CreateConditionEvent($condition, $this);
$this->dispatchEvent($event);
$condition = $event->getCondition();
$this->condition = $condition;
return $this;
} | [
"public",
"function",
"createPropertyValueCondition",
"(",
"$",
"propertyName",
",",
"$",
"propertyValue",
",",
"$",
"strict",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"condition",
")",
"{",
"$",
"this",
"->",
"finishCondition",
"(",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"property",
")",
"{",
"$",
"condition",
"=",
"$",
"this",
"->",
"propertyValueConditionClass",
"->",
"newInstance",
"(",
")",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"palette",
")",
"{",
"$",
"condition",
"=",
"$",
"this",
"->",
"palettePropertyValueConditionClass",
"->",
"newInstance",
"(",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"DcGeneralRuntimeException",
"(",
"'Does not know where to create the property-value condition, please create a palette or property first'",
")",
";",
"}",
"$",
"condition",
"->",
"setPropertyName",
"(",
"$",
"propertyName",
")",
";",
"$",
"condition",
"->",
"setPropertyValue",
"(",
"$",
"propertyValue",
")",
";",
"$",
"condition",
"->",
"setStrict",
"(",
"$",
"strict",
")",
";",
"$",
"event",
"=",
"new",
"CreatePropertyValueConditionEvent",
"(",
"$",
"condition",
",",
"$",
"this",
")",
";",
"$",
"this",
"->",
"dispatchEvent",
"(",
"$",
"event",
")",
";",
"$",
"condition",
"=",
"$",
"event",
"->",
"getPropertyValueCondition",
"(",
")",
";",
"$",
"event",
"=",
"new",
"CreateConditionEvent",
"(",
"$",
"condition",
",",
"$",
"this",
")",
";",
"$",
"this",
"->",
"dispatchEvent",
"(",
"$",
"event",
")",
";",
"$",
"condition",
"=",
"$",
"event",
"->",
"getCondition",
"(",
")",
";",
"$",
"this",
"->",
"condition",
"=",
"$",
"condition",
";",
"return",
"$",
"this",
";",
"}"
]
| Start a new property-value condition.
@param string $propertyName The name of the property.
@param mixed $propertyValue The value of the property.
@param bool $strict Flag if the comparison shall be strict (type safe).
@return PaletteBuilder
@throws DcGeneralRuntimeException If neither a palette nor a property is stored in the builder. | [
"Start",
"a",
"new",
"property",
"-",
"value",
"condition",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/DataDefinition/Palette/Builder/PaletteBuilder.php#L1081-L1112 | train |
contao-community-alliance/dc-general | src/DataDefinition/Palette/Builder/PaletteBuilder.php | PaletteBuilder.chainPropertyValueCondition | public function chainPropertyValueCondition(
$propertyName,
$propertyValue,
$strict = false,
$conjunction = PropertyConditionChain::AND_CONJUNCTION
) {
if ($this->property) {
$this->createPropertyConditionChain($conjunction);
$condition = $this->propertyValueConditionClass->newInstance();
} elseif ($this->palette) {
$this->createPaletteConditionChain();
$condition = $this->palettePropertyValueConditionClass->newInstance();
} else {
throw new DcGeneralRuntimeException(
'Does not know where to create the property-value condition, please create a palette or property first'
);
}
$condition->setPropertyName($propertyName);
$condition->setPropertyValue($propertyValue);
$condition->setStrict($strict);
$event = new CreatePropertyValueConditionEvent($condition, $this);
$this->dispatchEvent($event);
$condition = $event->getPropertyValueCondition();
$event = new CreateConditionEvent($condition, $this);
$this->dispatchEvent($event);
$condition = $event->getCondition();
$this->condition->addCondition($condition);
return $this;
} | php | public function chainPropertyValueCondition(
$propertyName,
$propertyValue,
$strict = false,
$conjunction = PropertyConditionChain::AND_CONJUNCTION
) {
if ($this->property) {
$this->createPropertyConditionChain($conjunction);
$condition = $this->propertyValueConditionClass->newInstance();
} elseif ($this->palette) {
$this->createPaletteConditionChain();
$condition = $this->palettePropertyValueConditionClass->newInstance();
} else {
throw new DcGeneralRuntimeException(
'Does not know where to create the property-value condition, please create a palette or property first'
);
}
$condition->setPropertyName($propertyName);
$condition->setPropertyValue($propertyValue);
$condition->setStrict($strict);
$event = new CreatePropertyValueConditionEvent($condition, $this);
$this->dispatchEvent($event);
$condition = $event->getPropertyValueCondition();
$event = new CreateConditionEvent($condition, $this);
$this->dispatchEvent($event);
$condition = $event->getCondition();
$this->condition->addCondition($condition);
return $this;
} | [
"public",
"function",
"chainPropertyValueCondition",
"(",
"$",
"propertyName",
",",
"$",
"propertyValue",
",",
"$",
"strict",
"=",
"false",
",",
"$",
"conjunction",
"=",
"PropertyConditionChain",
"::",
"AND_CONJUNCTION",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"property",
")",
"{",
"$",
"this",
"->",
"createPropertyConditionChain",
"(",
"$",
"conjunction",
")",
";",
"$",
"condition",
"=",
"$",
"this",
"->",
"propertyValueConditionClass",
"->",
"newInstance",
"(",
")",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"palette",
")",
"{",
"$",
"this",
"->",
"createPaletteConditionChain",
"(",
")",
";",
"$",
"condition",
"=",
"$",
"this",
"->",
"palettePropertyValueConditionClass",
"->",
"newInstance",
"(",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"DcGeneralRuntimeException",
"(",
"'Does not know where to create the property-value condition, please create a palette or property first'",
")",
";",
"}",
"$",
"condition",
"->",
"setPropertyName",
"(",
"$",
"propertyName",
")",
";",
"$",
"condition",
"->",
"setPropertyValue",
"(",
"$",
"propertyValue",
")",
";",
"$",
"condition",
"->",
"setStrict",
"(",
"$",
"strict",
")",
";",
"$",
"event",
"=",
"new",
"CreatePropertyValueConditionEvent",
"(",
"$",
"condition",
",",
"$",
"this",
")",
";",
"$",
"this",
"->",
"dispatchEvent",
"(",
"$",
"event",
")",
";",
"$",
"condition",
"=",
"$",
"event",
"->",
"getPropertyValueCondition",
"(",
")",
";",
"$",
"event",
"=",
"new",
"CreateConditionEvent",
"(",
"$",
"condition",
",",
"$",
"this",
")",
";",
"$",
"this",
"->",
"dispatchEvent",
"(",
"$",
"event",
")",
";",
"$",
"condition",
"=",
"$",
"event",
"->",
"getCondition",
"(",
")",
";",
"$",
"this",
"->",
"condition",
"->",
"addCondition",
"(",
"$",
"condition",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Start a new property-value condition and chain with previous condition.
@param string $propertyName The name of the property.
@param mixed $propertyValue The value of the property.
@param bool $strict Flag if the comparison shall be strict (type safe).
@param string $conjunction The conjunction.
@return PaletteBuilder
@throws DcGeneralRuntimeException If neither a palette nor a property is stored in the builder. | [
"Start",
"a",
"new",
"property",
"-",
"value",
"condition",
"and",
"chain",
"with",
"previous",
"condition",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/DataDefinition/Palette/Builder/PaletteBuilder.php#L1126-L1159 | train |
contao-community-alliance/dc-general | src/DataDefinition/Palette/Builder/PaletteBuilder.php | PaletteBuilder.finishCondition | public function finishCondition(&$condition = null)
{
if (!$this->condition) {
throw new DcGeneralRuntimeException('Condition is missing, please create a condition first');
}
$event = new FinishConditionEvent($this->condition, $this);
$this->dispatchEvent($event);
$condition = $event->getCondition();
$this->addCondition($condition);
$this->condition = null;
return $this;
} | php | public function finishCondition(&$condition = null)
{
if (!$this->condition) {
throw new DcGeneralRuntimeException('Condition is missing, please create a condition first');
}
$event = new FinishConditionEvent($this->condition, $this);
$this->dispatchEvent($event);
$condition = $event->getCondition();
$this->addCondition($condition);
$this->condition = null;
return $this;
} | [
"public",
"function",
"finishCondition",
"(",
"&",
"$",
"condition",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"condition",
")",
"{",
"throw",
"new",
"DcGeneralRuntimeException",
"(",
"'Condition is missing, please create a condition first'",
")",
";",
"}",
"$",
"event",
"=",
"new",
"FinishConditionEvent",
"(",
"$",
"this",
"->",
"condition",
",",
"$",
"this",
")",
";",
"$",
"this",
"->",
"dispatchEvent",
"(",
"$",
"event",
")",
";",
"$",
"condition",
"=",
"$",
"event",
"->",
"getCondition",
"(",
")",
";",
"$",
"this",
"->",
"addCondition",
"(",
"$",
"condition",
")",
";",
"$",
"this",
"->",
"condition",
"=",
"null",
";",
"return",
"$",
"this",
";",
"}"
]
| Finish the current condition.
@param PropertyConditionInterface|PaletteConditionInterface $condition Return the final condition.
@return PaletteBuilder
@throws DcGeneralRuntimeException If no condition is stored in the builder. | [
"Finish",
"the",
"current",
"condition",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/DataDefinition/Palette/Builder/PaletteBuilder.php#L1170-L1184 | train |
contao-community-alliance/dc-general | src/DataDefinition/Palette/Builder/PaletteBuilder.php | PaletteBuilder.addPaletteCondition | protected function addPaletteCondition(PaletteConditionInterface $condition)
{
if (!$this->palette) {
throw new DcGeneralRuntimeException('Palette is missing, please create a palette first');
}
$event = new AddConditionEvent($condition, $this->palette, $this);
$this->dispatchEvent($event);
$condition = $event->getCondition();
$previousCondition = $this->palette->getCondition();
if (!$previousCondition) {
$this->palette->setCondition($condition);
} elseif ($previousCondition instanceof PropertyConditionChain) {
$previousCondition->addCondition($condition);
} else {
$chain = $this->paletteConditionChainClass->newInstance();
$chain->addCondition($previousCondition);
$chain->addCondition($condition);
$this->palette->setCondition($chain);
}
} | php | protected function addPaletteCondition(PaletteConditionInterface $condition)
{
if (!$this->palette) {
throw new DcGeneralRuntimeException('Palette is missing, please create a palette first');
}
$event = new AddConditionEvent($condition, $this->palette, $this);
$this->dispatchEvent($event);
$condition = $event->getCondition();
$previousCondition = $this->palette->getCondition();
if (!$previousCondition) {
$this->palette->setCondition($condition);
} elseif ($previousCondition instanceof PropertyConditionChain) {
$previousCondition->addCondition($condition);
} else {
$chain = $this->paletteConditionChainClass->newInstance();
$chain->addCondition($previousCondition);
$chain->addCondition($condition);
$this->palette->setCondition($chain);
}
} | [
"protected",
"function",
"addPaletteCondition",
"(",
"PaletteConditionInterface",
"$",
"condition",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"palette",
")",
"{",
"throw",
"new",
"DcGeneralRuntimeException",
"(",
"'Palette is missing, please create a palette first'",
")",
";",
"}",
"$",
"event",
"=",
"new",
"AddConditionEvent",
"(",
"$",
"condition",
",",
"$",
"this",
"->",
"palette",
",",
"$",
"this",
")",
";",
"$",
"this",
"->",
"dispatchEvent",
"(",
"$",
"event",
")",
";",
"$",
"condition",
"=",
"$",
"event",
"->",
"getCondition",
"(",
")",
";",
"$",
"previousCondition",
"=",
"$",
"this",
"->",
"palette",
"->",
"getCondition",
"(",
")",
";",
"if",
"(",
"!",
"$",
"previousCondition",
")",
"{",
"$",
"this",
"->",
"palette",
"->",
"setCondition",
"(",
"$",
"condition",
")",
";",
"}",
"elseif",
"(",
"$",
"previousCondition",
"instanceof",
"PropertyConditionChain",
")",
"{",
"$",
"previousCondition",
"->",
"addCondition",
"(",
"$",
"condition",
")",
";",
"}",
"else",
"{",
"$",
"chain",
"=",
"$",
"this",
"->",
"paletteConditionChainClass",
"->",
"newInstance",
"(",
")",
";",
"$",
"chain",
"->",
"addCondition",
"(",
"$",
"previousCondition",
")",
";",
"$",
"chain",
"->",
"addCondition",
"(",
"$",
"condition",
")",
";",
"$",
"this",
"->",
"palette",
"->",
"setCondition",
"(",
"$",
"chain",
")",
";",
"}",
"}"
]
| Add a custom condition to last created palette.
@param PaletteConditionInterface $condition The condition to add.
@return void
@throws DcGeneralRuntimeException If the palette is missing. | [
"Add",
"a",
"custom",
"condition",
"to",
"last",
"created",
"palette",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/DataDefinition/Palette/Builder/PaletteBuilder.php#L1195-L1217 | train |
contao-community-alliance/dc-general | src/DataDefinition/Palette/Builder/PaletteBuilder.php | PaletteBuilder.addPropertyCondition | protected function addPropertyCondition(PropertyConditionInterface $condition, $scope = self::VISIBLE)
{
if (!$this->property) {
throw new DcGeneralRuntimeException('Property is missing, please create a property first');
}
$properties = \is_object($this->property) ? [$this->property] : $this->property;
foreach ($properties as $property) {
/** @var PropertyInterface $property */
$event = new AddConditionEvent($condition, $property, $this);
$this->dispatchEvent($event);
$condition = $event->getCondition();
$previousCondition = self::EDITABLE === $scope
? $property->getEditableCondition()
: $property->getVisibleCondition();
if (!$previousCondition) {
if (self::EDITABLE === $scope) {
$property->setEditableCondition($condition);
} else {
$property->setVisibleCondition($condition);
}
} elseif ($previousCondition instanceof PropertyConditionChain) {
$previousCondition->addCondition($condition);
} else {
$chain = $this->propertyConditionChainClass->newInstance();
$chain->addCondition($previousCondition);
$chain->addCondition($condition);
if (self::EDITABLE === $scope) {
$property->setEditableCondition($chain);
} else {
$property->setVisibleCondition($chain);
}
}
}
} | php | protected function addPropertyCondition(PropertyConditionInterface $condition, $scope = self::VISIBLE)
{
if (!$this->property) {
throw new DcGeneralRuntimeException('Property is missing, please create a property first');
}
$properties = \is_object($this->property) ? [$this->property] : $this->property;
foreach ($properties as $property) {
/** @var PropertyInterface $property */
$event = new AddConditionEvent($condition, $property, $this);
$this->dispatchEvent($event);
$condition = $event->getCondition();
$previousCondition = self::EDITABLE === $scope
? $property->getEditableCondition()
: $property->getVisibleCondition();
if (!$previousCondition) {
if (self::EDITABLE === $scope) {
$property->setEditableCondition($condition);
} else {
$property->setVisibleCondition($condition);
}
} elseif ($previousCondition instanceof PropertyConditionChain) {
$previousCondition->addCondition($condition);
} else {
$chain = $this->propertyConditionChainClass->newInstance();
$chain->addCondition($previousCondition);
$chain->addCondition($condition);
if (self::EDITABLE === $scope) {
$property->setEditableCondition($chain);
} else {
$property->setVisibleCondition($chain);
}
}
}
} | [
"protected",
"function",
"addPropertyCondition",
"(",
"PropertyConditionInterface",
"$",
"condition",
",",
"$",
"scope",
"=",
"self",
"::",
"VISIBLE",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"property",
")",
"{",
"throw",
"new",
"DcGeneralRuntimeException",
"(",
"'Property is missing, please create a property first'",
")",
";",
"}",
"$",
"properties",
"=",
"\\",
"is_object",
"(",
"$",
"this",
"->",
"property",
")",
"?",
"[",
"$",
"this",
"->",
"property",
"]",
":",
"$",
"this",
"->",
"property",
";",
"foreach",
"(",
"$",
"properties",
"as",
"$",
"property",
")",
"{",
"/** @var PropertyInterface $property */",
"$",
"event",
"=",
"new",
"AddConditionEvent",
"(",
"$",
"condition",
",",
"$",
"property",
",",
"$",
"this",
")",
";",
"$",
"this",
"->",
"dispatchEvent",
"(",
"$",
"event",
")",
";",
"$",
"condition",
"=",
"$",
"event",
"->",
"getCondition",
"(",
")",
";",
"$",
"previousCondition",
"=",
"self",
"::",
"EDITABLE",
"===",
"$",
"scope",
"?",
"$",
"property",
"->",
"getEditableCondition",
"(",
")",
":",
"$",
"property",
"->",
"getVisibleCondition",
"(",
")",
";",
"if",
"(",
"!",
"$",
"previousCondition",
")",
"{",
"if",
"(",
"self",
"::",
"EDITABLE",
"===",
"$",
"scope",
")",
"{",
"$",
"property",
"->",
"setEditableCondition",
"(",
"$",
"condition",
")",
";",
"}",
"else",
"{",
"$",
"property",
"->",
"setVisibleCondition",
"(",
"$",
"condition",
")",
";",
"}",
"}",
"elseif",
"(",
"$",
"previousCondition",
"instanceof",
"PropertyConditionChain",
")",
"{",
"$",
"previousCondition",
"->",
"addCondition",
"(",
"$",
"condition",
")",
";",
"}",
"else",
"{",
"$",
"chain",
"=",
"$",
"this",
"->",
"propertyConditionChainClass",
"->",
"newInstance",
"(",
")",
";",
"$",
"chain",
"->",
"addCondition",
"(",
"$",
"previousCondition",
")",
";",
"$",
"chain",
"->",
"addCondition",
"(",
"$",
"condition",
")",
";",
"if",
"(",
"self",
"::",
"EDITABLE",
"===",
"$",
"scope",
")",
"{",
"$",
"property",
"->",
"setEditableCondition",
"(",
"$",
"chain",
")",
";",
"}",
"else",
"{",
"$",
"property",
"->",
"setVisibleCondition",
"(",
"$",
"chain",
")",
";",
"}",
"}",
"}",
"}"
]
| Add a custom condition to last created property.
@param PropertyConditionInterface $condition The condition to add.
@param string $scope The scope.
@return void
@throws DcGeneralRuntimeException If the the property is missing. | [
"Add",
"a",
"custom",
"condition",
"to",
"last",
"created",
"property",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/DataDefinition/Palette/Builder/PaletteBuilder.php#L1229-L1267 | train |
contao-community-alliance/dc-general | src/DataDefinition/Palette/Builder/PaletteBuilder.php | PaletteBuilder.addCondition | public function addCondition($condition, $scope = self::VISIBLE)
{
if ($condition instanceof PaletteConditionInterface) {
$this->addPaletteCondition($condition);
return $this;
}
if ($condition instanceof PropertyConditionInterface) {
$this->addPropertyCondition($condition, $scope);
return $this;
}
$type = \is_object($condition) ? \get_class($condition) : \gettype($condition);
throw new DcGeneralInvalidArgumentException('Cannot handle condition of type [' . $type . ']');
} | php | public function addCondition($condition, $scope = self::VISIBLE)
{
if ($condition instanceof PaletteConditionInterface) {
$this->addPaletteCondition($condition);
return $this;
}
if ($condition instanceof PropertyConditionInterface) {
$this->addPropertyCondition($condition, $scope);
return $this;
}
$type = \is_object($condition) ? \get_class($condition) : \gettype($condition);
throw new DcGeneralInvalidArgumentException('Cannot handle condition of type [' . $type . ']');
} | [
"public",
"function",
"addCondition",
"(",
"$",
"condition",
",",
"$",
"scope",
"=",
"self",
"::",
"VISIBLE",
")",
"{",
"if",
"(",
"$",
"condition",
"instanceof",
"PaletteConditionInterface",
")",
"{",
"$",
"this",
"->",
"addPaletteCondition",
"(",
"$",
"condition",
")",
";",
"return",
"$",
"this",
";",
"}",
"if",
"(",
"$",
"condition",
"instanceof",
"PropertyConditionInterface",
")",
"{",
"$",
"this",
"->",
"addPropertyCondition",
"(",
"$",
"condition",
",",
"$",
"scope",
")",
";",
"return",
"$",
"this",
";",
"}",
"$",
"type",
"=",
"\\",
"is_object",
"(",
"$",
"condition",
")",
"?",
"\\",
"get_class",
"(",
"$",
"condition",
")",
":",
"\\",
"gettype",
"(",
"$",
"condition",
")",
";",
"throw",
"new",
"DcGeneralInvalidArgumentException",
"(",
"'Cannot handle condition of type ['",
".",
"$",
"type",
".",
"']'",
")",
";",
"}"
]
| Add a custom condition to last created property or palette.
@param PaletteConditionInterface|PropertyConditionInterface $condition The condition to add.
@param string $scope The scope.
@return PaletteBuilder
@throws DcGeneralInvalidArgumentException When an unknown condition type is passed. | [
"Add",
"a",
"custom",
"condition",
"to",
"last",
"created",
"property",
"or",
"palette",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/DataDefinition/Palette/Builder/PaletteBuilder.php#L1279-L1293 | train |
contao-community-alliance/dc-general | src/DataDefinition/Palette/Builder/PaletteBuilder.php | PaletteBuilder.dispatchEvent | protected function dispatchEvent(BuilderEvent $event)
{
/** @var \Symfony\Component\EventDispatcher\EventDispatcher $dispatcher */
$dispatcher = $GLOBALS['container']['event-dispatcher'];
$dispatcher->dispatch($event::NAME, $event);
} | php | protected function dispatchEvent(BuilderEvent $event)
{
/** @var \Symfony\Component\EventDispatcher\EventDispatcher $dispatcher */
$dispatcher = $GLOBALS['container']['event-dispatcher'];
$dispatcher->dispatch($event::NAME, $event);
} | [
"protected",
"function",
"dispatchEvent",
"(",
"BuilderEvent",
"$",
"event",
")",
"{",
"/** @var \\Symfony\\Component\\EventDispatcher\\EventDispatcher $dispatcher */",
"$",
"dispatcher",
"=",
"$",
"GLOBALS",
"[",
"'container'",
"]",
"[",
"'event-dispatcher'",
"]",
";",
"$",
"dispatcher",
"->",
"dispatch",
"(",
"$",
"event",
"::",
"NAME",
",",
"$",
"event",
")",
";",
"}"
]
| Dispatch an event over the global event dispatcher.
@param BuilderEvent $event The event to dispatch.
@return void
@internal
@SuppressWarnings(PHPMD.Superglobals)
@SuppressWarnings(PHPMD.CamelCaseVariableName) | [
"Dispatch",
"an",
"event",
"over",
"the",
"global",
"event",
"dispatcher",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/DataDefinition/Palette/Builder/PaletteBuilder.php#L1307-L1312 | train |
contao-community-alliance/dc-general | src/Contao/View/Contao2BackendView/ActionHandler/DeleteHandler.php | DeleteHandler.guardIsDeletable | protected function guardIsDeletable(EnvironmentInterface $environment, ModelIdInterface $modelId, $redirect = false)
{
$dataDefinition = $environment->getDataDefinition();
if ($dataDefinition->getBasicDefinition()->isDeletable()) {
return;
}
if (false === $redirect) {
throw new NotDeletableException($modelId->getDataProviderName());
}
$eventDispatcher = $environment->getEventDispatcher();
$eventDispatcher->dispatch(
ContaoEvents::SYSTEM_LOG,
new LogEvent(
\sprintf(
'Table "%s" is not deletable DC_General - DefaultController - delete()',
$dataDefinition->getName()
),
__CLASS__ . '::delete()',
TL_ERROR
)
);
$eventDispatcher->dispatch(
ContaoEvents::CONTROLLER_REDIRECT,
new RedirectEvent('contao?act=error')
);
} | php | protected function guardIsDeletable(EnvironmentInterface $environment, ModelIdInterface $modelId, $redirect = false)
{
$dataDefinition = $environment->getDataDefinition();
if ($dataDefinition->getBasicDefinition()->isDeletable()) {
return;
}
if (false === $redirect) {
throw new NotDeletableException($modelId->getDataProviderName());
}
$eventDispatcher = $environment->getEventDispatcher();
$eventDispatcher->dispatch(
ContaoEvents::SYSTEM_LOG,
new LogEvent(
\sprintf(
'Table "%s" is not deletable DC_General - DefaultController - delete()',
$dataDefinition->getName()
),
__CLASS__ . '::delete()',
TL_ERROR
)
);
$eventDispatcher->dispatch(
ContaoEvents::CONTROLLER_REDIRECT,
new RedirectEvent('contao?act=error')
);
} | [
"protected",
"function",
"guardIsDeletable",
"(",
"EnvironmentInterface",
"$",
"environment",
",",
"ModelIdInterface",
"$",
"modelId",
",",
"$",
"redirect",
"=",
"false",
")",
"{",
"$",
"dataDefinition",
"=",
"$",
"environment",
"->",
"getDataDefinition",
"(",
")",
";",
"if",
"(",
"$",
"dataDefinition",
"->",
"getBasicDefinition",
"(",
")",
"->",
"isDeletable",
"(",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"false",
"===",
"$",
"redirect",
")",
"{",
"throw",
"new",
"NotDeletableException",
"(",
"$",
"modelId",
"->",
"getDataProviderName",
"(",
")",
")",
";",
"}",
"$",
"eventDispatcher",
"=",
"$",
"environment",
"->",
"getEventDispatcher",
"(",
")",
";",
"$",
"eventDispatcher",
"->",
"dispatch",
"(",
"ContaoEvents",
"::",
"SYSTEM_LOG",
",",
"new",
"LogEvent",
"(",
"\\",
"sprintf",
"(",
"'Table \"%s\" is not deletable DC_General - DefaultController - delete()'",
",",
"$",
"dataDefinition",
"->",
"getName",
"(",
")",
")",
",",
"__CLASS__",
".",
"'::delete()'",
",",
"TL_ERROR",
")",
")",
";",
"$",
"eventDispatcher",
"->",
"dispatch",
"(",
"ContaoEvents",
"::",
"CONTROLLER_REDIRECT",
",",
"new",
"RedirectEvent",
"(",
"'contao?act=error'",
")",
")",
";",
"}"
]
| Check if is it allowed to delete a record.
@param EnvironmentInterface $environment The environment.
@param ModelIdInterface $modelId The model id.
@param bool $redirect If true it redirects to error page instead of throwing an exception.
@return void
@throws NotDeletableException If table can´t delete. | [
"Check",
"if",
"is",
"it",
"allowed",
"to",
"delete",
"a",
"record",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/View/Contao2BackendView/ActionHandler/DeleteHandler.php#L105-L134 | train |
contao-community-alliance/dc-general | src/Contao/View/Contao2BackendView/ActionHandler/DeleteHandler.php | DeleteHandler.fetchModel | protected function fetchModel(EnvironmentInterface $environment, ModelIdInterface $modelId)
{
$dataProvider = $environment->getDataProvider($modelId->getDataProviderName());
$model = $dataProvider->fetch($dataProvider->getEmptyConfig()->setId($modelId->getId()));
if (!$model || !$model->getId()) {
throw new DcGeneralRuntimeException(
'Could not load model with id ' . $modelId->getSerialized()
);
}
return $model;
} | php | protected function fetchModel(EnvironmentInterface $environment, ModelIdInterface $modelId)
{
$dataProvider = $environment->getDataProvider($modelId->getDataProviderName());
$model = $dataProvider->fetch($dataProvider->getEmptyConfig()->setId($modelId->getId()));
if (!$model || !$model->getId()) {
throw new DcGeneralRuntimeException(
'Could not load model with id ' . $modelId->getSerialized()
);
}
return $model;
} | [
"protected",
"function",
"fetchModel",
"(",
"EnvironmentInterface",
"$",
"environment",
",",
"ModelIdInterface",
"$",
"modelId",
")",
"{",
"$",
"dataProvider",
"=",
"$",
"environment",
"->",
"getDataProvider",
"(",
"$",
"modelId",
"->",
"getDataProviderName",
"(",
")",
")",
";",
"$",
"model",
"=",
"$",
"dataProvider",
"->",
"fetch",
"(",
"$",
"dataProvider",
"->",
"getEmptyConfig",
"(",
")",
"->",
"setId",
"(",
"$",
"modelId",
"->",
"getId",
"(",
")",
")",
")",
";",
"if",
"(",
"!",
"$",
"model",
"||",
"!",
"$",
"model",
"->",
"getId",
"(",
")",
")",
"{",
"throw",
"new",
"DcGeneralRuntimeException",
"(",
"'Could not load model with id '",
".",
"$",
"modelId",
"->",
"getSerialized",
"(",
")",
")",
";",
"}",
"return",
"$",
"model",
";",
"}"
]
| Fetch the model.
@param EnvironmentInterface $environment The environment.
@param ModelIdInterface $modelId The model id.
@return ModelInterface
@throws DcGeneralRuntimeException If model is not found. | [
"Fetch",
"the",
"model",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/View/Contao2BackendView/ActionHandler/DeleteHandler.php#L146-L158 | train |
contao-community-alliance/dc-general | src/Contao/View/Contao2BackendView/ActionHandler/DeleteHandler.php | DeleteHandler.delete | public function delete(EnvironmentInterface $environment, ModelIdInterface $modelId)
{
$this->guardNotEditOnly($environment->getDataDefinition(), $modelId);
$this->guardIsDeletable($environment, $modelId);
$model = $this->fetchModel($environment, $modelId);
// Trigger event before the model will be deleted.
$preDeleteEvent = new PreDeleteModelEvent($environment, $model);
$environment->getEventDispatcher()->dispatch($preDeleteEvent::NAME, $preDeleteEvent);
$dataProvider = $environment->getDataProvider($modelId->getDataProviderName());
$dataProvider->delete($model);
// Trigger event after the model is deleted.
$postDeleteEvent = new PostDeleteModelEvent($environment, $model);
$environment->getEventDispatcher()->dispatch($postDeleteEvent::NAME, $postDeleteEvent);
} | php | public function delete(EnvironmentInterface $environment, ModelIdInterface $modelId)
{
$this->guardNotEditOnly($environment->getDataDefinition(), $modelId);
$this->guardIsDeletable($environment, $modelId);
$model = $this->fetchModel($environment, $modelId);
// Trigger event before the model will be deleted.
$preDeleteEvent = new PreDeleteModelEvent($environment, $model);
$environment->getEventDispatcher()->dispatch($preDeleteEvent::NAME, $preDeleteEvent);
$dataProvider = $environment->getDataProvider($modelId->getDataProviderName());
$dataProvider->delete($model);
// Trigger event after the model is deleted.
$postDeleteEvent = new PostDeleteModelEvent($environment, $model);
$environment->getEventDispatcher()->dispatch($postDeleteEvent::NAME, $postDeleteEvent);
} | [
"public",
"function",
"delete",
"(",
"EnvironmentInterface",
"$",
"environment",
",",
"ModelIdInterface",
"$",
"modelId",
")",
"{",
"$",
"this",
"->",
"guardNotEditOnly",
"(",
"$",
"environment",
"->",
"getDataDefinition",
"(",
")",
",",
"$",
"modelId",
")",
";",
"$",
"this",
"->",
"guardIsDeletable",
"(",
"$",
"environment",
",",
"$",
"modelId",
")",
";",
"$",
"model",
"=",
"$",
"this",
"->",
"fetchModel",
"(",
"$",
"environment",
",",
"$",
"modelId",
")",
";",
"// Trigger event before the model will be deleted.",
"$",
"preDeleteEvent",
"=",
"new",
"PreDeleteModelEvent",
"(",
"$",
"environment",
",",
"$",
"model",
")",
";",
"$",
"environment",
"->",
"getEventDispatcher",
"(",
")",
"->",
"dispatch",
"(",
"$",
"preDeleteEvent",
"::",
"NAME",
",",
"$",
"preDeleteEvent",
")",
";",
"$",
"dataProvider",
"=",
"$",
"environment",
"->",
"getDataProvider",
"(",
"$",
"modelId",
"->",
"getDataProviderName",
"(",
")",
")",
";",
"$",
"dataProvider",
"->",
"delete",
"(",
"$",
"model",
")",
";",
"// Trigger event after the model is deleted.",
"$",
"postDeleteEvent",
"=",
"new",
"PostDeleteModelEvent",
"(",
"$",
"environment",
",",
"$",
"model",
")",
";",
"$",
"environment",
"->",
"getEventDispatcher",
"(",
")",
"->",
"dispatch",
"(",
"$",
"postDeleteEvent",
"::",
"NAME",
",",
"$",
"postDeleteEvent",
")",
";",
"}"
]
| Delete an model.
@param EnvironmentInterface $environment Environment.
@param ModelIdInterface $modelId The model id.
@return void
@throws EditOnlyModeException If the data definition is in edit only mode.
@throws NotDeletableException If the data definition does not allow delete actions.
@throws DcGeneralRuntimeException If the model is not found. | [
"Delete",
"an",
"model",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/View/Contao2BackendView/ActionHandler/DeleteHandler.php#L172-L189 | train |
contao-community-alliance/dc-general | src/Contao/View/Contao2BackendView/ActionHandler/DeleteHandler.php | DeleteHandler.checkPermission | private function checkPermission(EnvironmentInterface $environment)
{
if (true === $environment->getDataDefinition()->getBasicDefinition()->isDeletable()) {
return true;
}
return \sprintf(
'<div style="text-align:center; font-weight:bold; padding:40px;">
You have no permission for delete model %s.
</div>',
ModelId::fromSerialized($environment->getInputProvider()->getParameter('id'))->getSerialized()
);
} | php | private function checkPermission(EnvironmentInterface $environment)
{
if (true === $environment->getDataDefinition()->getBasicDefinition()->isDeletable()) {
return true;
}
return \sprintf(
'<div style="text-align:center; font-weight:bold; padding:40px;">
You have no permission for delete model %s.
</div>',
ModelId::fromSerialized($environment->getInputProvider()->getParameter('id'))->getSerialized()
);
} | [
"private",
"function",
"checkPermission",
"(",
"EnvironmentInterface",
"$",
"environment",
")",
"{",
"if",
"(",
"true",
"===",
"$",
"environment",
"->",
"getDataDefinition",
"(",
")",
"->",
"getBasicDefinition",
"(",
")",
"->",
"isDeletable",
"(",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"\\",
"sprintf",
"(",
"'<div style=\"text-align:center; font-weight:bold; padding:40px;\">\n You have no permission for delete model %s.\n </div>'",
",",
"ModelId",
"::",
"fromSerialized",
"(",
"$",
"environment",
"->",
"getInputProvider",
"(",
")",
"->",
"getParameter",
"(",
"'id'",
")",
")",
"->",
"getSerialized",
"(",
")",
")",
";",
"}"
]
| Check permission for delete a model.
@param EnvironmentInterface $environment The environment.
@return string|bool | [
"Check",
"permission",
"for",
"delete",
"a",
"model",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/View/Contao2BackendView/ActionHandler/DeleteHandler.php#L235-L247 | train |
contao-community-alliance/dc-general | src/Contao/View/Contao2BackendView/ActionHandler/DeleteHandler.php | DeleteHandler.deepDelete | protected function deepDelete(EnvironmentInterface $environment, ModelIdInterface $modelId)
{
/** @var DefaultModelRelationshipDefinition $relationships */
$relationships = $environment->getDataDefinition()->getDefinition('model-relationships');
$childConditions = $relationships->getChildConditions($modelId->getDataProviderName());
// delete child element before delete parent element
/** @var ParentChildConditionInterface $childCondition */
foreach ($childConditions as $childCondition) {
$destinationChildConditions = $relationships->getChildConditions($childCondition->getDestinationName());
if (empty($destinationChildConditions)) {
continue;
}
$dataProvider = $environment->getDataProvider($modelId->getDataProviderName());
$model = $dataProvider->fetch(
$dataProvider->getEmptyConfig()->setId($modelId->getId())
);
$destinationChildDataProvider = $environment->getDataProvider($childCondition->getDestinationName());
/** @var DefaultCollection $destinationChildModels */
$destinationChildModels = $destinationChildDataProvider->fetchAll(
$dataProvider->getEmptyConfig()->setFilter($childCondition->getFilter($model))
);
if ($destinationChildModels->count() < 1) {
continue;
}
foreach ($destinationChildModels as $destinationChildModel) {
$this->deepDelete($environment, ModelId::fromModel($destinationChildModel));
}
}
foreach ($childConditions as $childCondition) {
$dataProvider = $environment->getDataProvider($modelId->getDataProviderName());
$model = $dataProvider->fetch($dataProvider->getEmptyConfig()->setId($modelId->getId()));
$childDataProvider = $environment->getDataProvider($childCondition->getDestinationName());
$filters = $childCondition->getFilter($model);
/** @var DefaultCollection $childModels */
$childModels = $childDataProvider->fetchAll($dataProvider->getEmptyConfig()->setFilter($filters));
if ($childModels->count() < 1) {
continue;
}
foreach ($childModels as $childModel) {
// Trigger event before the model will be deleted.
$preDeleteEvent = new PreDeleteModelEvent($environment, $childModel);
$environment->getEventDispatcher()->dispatch($preDeleteEvent::NAME, $preDeleteEvent);
$childDataProvider->delete($childModel);
// Trigger event after the model is deleted.
$postDeleteEvent = new PostDeleteModelEvent($environment, $childModel);
$environment->getEventDispatcher()->dispatch($postDeleteEvent::NAME, $postDeleteEvent);
}
}
} | php | protected function deepDelete(EnvironmentInterface $environment, ModelIdInterface $modelId)
{
/** @var DefaultModelRelationshipDefinition $relationships */
$relationships = $environment->getDataDefinition()->getDefinition('model-relationships');
$childConditions = $relationships->getChildConditions($modelId->getDataProviderName());
// delete child element before delete parent element
/** @var ParentChildConditionInterface $childCondition */
foreach ($childConditions as $childCondition) {
$destinationChildConditions = $relationships->getChildConditions($childCondition->getDestinationName());
if (empty($destinationChildConditions)) {
continue;
}
$dataProvider = $environment->getDataProvider($modelId->getDataProviderName());
$model = $dataProvider->fetch(
$dataProvider->getEmptyConfig()->setId($modelId->getId())
);
$destinationChildDataProvider = $environment->getDataProvider($childCondition->getDestinationName());
/** @var DefaultCollection $destinationChildModels */
$destinationChildModels = $destinationChildDataProvider->fetchAll(
$dataProvider->getEmptyConfig()->setFilter($childCondition->getFilter($model))
);
if ($destinationChildModels->count() < 1) {
continue;
}
foreach ($destinationChildModels as $destinationChildModel) {
$this->deepDelete($environment, ModelId::fromModel($destinationChildModel));
}
}
foreach ($childConditions as $childCondition) {
$dataProvider = $environment->getDataProvider($modelId->getDataProviderName());
$model = $dataProvider->fetch($dataProvider->getEmptyConfig()->setId($modelId->getId()));
$childDataProvider = $environment->getDataProvider($childCondition->getDestinationName());
$filters = $childCondition->getFilter($model);
/** @var DefaultCollection $childModels */
$childModels = $childDataProvider->fetchAll($dataProvider->getEmptyConfig()->setFilter($filters));
if ($childModels->count() < 1) {
continue;
}
foreach ($childModels as $childModel) {
// Trigger event before the model will be deleted.
$preDeleteEvent = new PreDeleteModelEvent($environment, $childModel);
$environment->getEventDispatcher()->dispatch($preDeleteEvent::NAME, $preDeleteEvent);
$childDataProvider->delete($childModel);
// Trigger event after the model is deleted.
$postDeleteEvent = new PostDeleteModelEvent($environment, $childModel);
$environment->getEventDispatcher()->dispatch($postDeleteEvent::NAME, $postDeleteEvent);
}
}
} | [
"protected",
"function",
"deepDelete",
"(",
"EnvironmentInterface",
"$",
"environment",
",",
"ModelIdInterface",
"$",
"modelId",
")",
"{",
"/** @var DefaultModelRelationshipDefinition $relationships */",
"$",
"relationships",
"=",
"$",
"environment",
"->",
"getDataDefinition",
"(",
")",
"->",
"getDefinition",
"(",
"'model-relationships'",
")",
";",
"$",
"childConditions",
"=",
"$",
"relationships",
"->",
"getChildConditions",
"(",
"$",
"modelId",
"->",
"getDataProviderName",
"(",
")",
")",
";",
"// delete child element before delete parent element",
"/** @var ParentChildConditionInterface $childCondition */",
"foreach",
"(",
"$",
"childConditions",
"as",
"$",
"childCondition",
")",
"{",
"$",
"destinationChildConditions",
"=",
"$",
"relationships",
"->",
"getChildConditions",
"(",
"$",
"childCondition",
"->",
"getDestinationName",
"(",
")",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"destinationChildConditions",
")",
")",
"{",
"continue",
";",
"}",
"$",
"dataProvider",
"=",
"$",
"environment",
"->",
"getDataProvider",
"(",
"$",
"modelId",
"->",
"getDataProviderName",
"(",
")",
")",
";",
"$",
"model",
"=",
"$",
"dataProvider",
"->",
"fetch",
"(",
"$",
"dataProvider",
"->",
"getEmptyConfig",
"(",
")",
"->",
"setId",
"(",
"$",
"modelId",
"->",
"getId",
"(",
")",
")",
")",
";",
"$",
"destinationChildDataProvider",
"=",
"$",
"environment",
"->",
"getDataProvider",
"(",
"$",
"childCondition",
"->",
"getDestinationName",
"(",
")",
")",
";",
"/** @var DefaultCollection $destinationChildModels */",
"$",
"destinationChildModels",
"=",
"$",
"destinationChildDataProvider",
"->",
"fetchAll",
"(",
"$",
"dataProvider",
"->",
"getEmptyConfig",
"(",
")",
"->",
"setFilter",
"(",
"$",
"childCondition",
"->",
"getFilter",
"(",
"$",
"model",
")",
")",
")",
";",
"if",
"(",
"$",
"destinationChildModels",
"->",
"count",
"(",
")",
"<",
"1",
")",
"{",
"continue",
";",
"}",
"foreach",
"(",
"$",
"destinationChildModels",
"as",
"$",
"destinationChildModel",
")",
"{",
"$",
"this",
"->",
"deepDelete",
"(",
"$",
"environment",
",",
"ModelId",
"::",
"fromModel",
"(",
"$",
"destinationChildModel",
")",
")",
";",
"}",
"}",
"foreach",
"(",
"$",
"childConditions",
"as",
"$",
"childCondition",
")",
"{",
"$",
"dataProvider",
"=",
"$",
"environment",
"->",
"getDataProvider",
"(",
"$",
"modelId",
"->",
"getDataProviderName",
"(",
")",
")",
";",
"$",
"model",
"=",
"$",
"dataProvider",
"->",
"fetch",
"(",
"$",
"dataProvider",
"->",
"getEmptyConfig",
"(",
")",
"->",
"setId",
"(",
"$",
"modelId",
"->",
"getId",
"(",
")",
")",
")",
";",
"$",
"childDataProvider",
"=",
"$",
"environment",
"->",
"getDataProvider",
"(",
"$",
"childCondition",
"->",
"getDestinationName",
"(",
")",
")",
";",
"$",
"filters",
"=",
"$",
"childCondition",
"->",
"getFilter",
"(",
"$",
"model",
")",
";",
"/** @var DefaultCollection $childModels */",
"$",
"childModels",
"=",
"$",
"childDataProvider",
"->",
"fetchAll",
"(",
"$",
"dataProvider",
"->",
"getEmptyConfig",
"(",
")",
"->",
"setFilter",
"(",
"$",
"filters",
")",
")",
";",
"if",
"(",
"$",
"childModels",
"->",
"count",
"(",
")",
"<",
"1",
")",
"{",
"continue",
";",
"}",
"foreach",
"(",
"$",
"childModels",
"as",
"$",
"childModel",
")",
"{",
"// Trigger event before the model will be deleted.",
"$",
"preDeleteEvent",
"=",
"new",
"PreDeleteModelEvent",
"(",
"$",
"environment",
",",
"$",
"childModel",
")",
";",
"$",
"environment",
"->",
"getEventDispatcher",
"(",
")",
"->",
"dispatch",
"(",
"$",
"preDeleteEvent",
"::",
"NAME",
",",
"$",
"preDeleteEvent",
")",
";",
"$",
"childDataProvider",
"->",
"delete",
"(",
"$",
"childModel",
")",
";",
"// Trigger event after the model is deleted.",
"$",
"postDeleteEvent",
"=",
"new",
"PostDeleteModelEvent",
"(",
"$",
"environment",
",",
"$",
"childModel",
")",
";",
"$",
"environment",
"->",
"getEventDispatcher",
"(",
")",
"->",
"dispatch",
"(",
"$",
"postDeleteEvent",
"::",
"NAME",
",",
"$",
"postDeleteEvent",
")",
";",
"}",
"}",
"}"
]
| Delete all deep models.
@param EnvironmentInterface $environment Environment.
@param ModelIdInterface $modelId The Model Id.
@return void
@SuppressWarnings(PHPMD.LongVariableName) | [
"Delete",
"all",
"deep",
"models",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/View/Contao2BackendView/ActionHandler/DeleteHandler.php#L259-L317 | train |
contao-community-alliance/dc-general | src/Contao/View/Contao2BackendView/PanelBuilder.php | PanelBuilder.build | public function build()
{
$panel = new DefaultPanelContainer();
$panel->setEnvironment($this->environment);
/** @var Contao2BackendViewDefinitionInterface $viewDefinition */
$viewDefinition = $this
->environment
->getDataDefinition()
->getDefinition(Contao2BackendViewDefinitionInterface::NAME);
foreach ($viewDefinition->getPanelLayout()->getRows() as $panelKey => $row) {
$panelRow = new DefaultPanel();
$panel->addPanel($panelKey, $panelRow);
foreach ($row as $element) {
/** @var ElementInformationInterface $element */
if (null !== $instance = $this->createElement($element)) {
$panelRow->addElement($element->getName(), $instance);
}
}
}
return $panel;
} | php | public function build()
{
$panel = new DefaultPanelContainer();
$panel->setEnvironment($this->environment);
/** @var Contao2BackendViewDefinitionInterface $viewDefinition */
$viewDefinition = $this
->environment
->getDataDefinition()
->getDefinition(Contao2BackendViewDefinitionInterface::NAME);
foreach ($viewDefinition->getPanelLayout()->getRows() as $panelKey => $row) {
$panelRow = new DefaultPanel();
$panel->addPanel($panelKey, $panelRow);
foreach ($row as $element) {
/** @var ElementInformationInterface $element */
if (null !== $instance = $this->createElement($element)) {
$panelRow->addElement($element->getName(), $instance);
}
}
}
return $panel;
} | [
"public",
"function",
"build",
"(",
")",
"{",
"$",
"panel",
"=",
"new",
"DefaultPanelContainer",
"(",
")",
";",
"$",
"panel",
"->",
"setEnvironment",
"(",
"$",
"this",
"->",
"environment",
")",
";",
"/** @var Contao2BackendViewDefinitionInterface $viewDefinition */",
"$",
"viewDefinition",
"=",
"$",
"this",
"->",
"environment",
"->",
"getDataDefinition",
"(",
")",
"->",
"getDefinition",
"(",
"Contao2BackendViewDefinitionInterface",
"::",
"NAME",
")",
";",
"foreach",
"(",
"$",
"viewDefinition",
"->",
"getPanelLayout",
"(",
")",
"->",
"getRows",
"(",
")",
"as",
"$",
"panelKey",
"=>",
"$",
"row",
")",
"{",
"$",
"panelRow",
"=",
"new",
"DefaultPanel",
"(",
")",
";",
"$",
"panel",
"->",
"addPanel",
"(",
"$",
"panelKey",
",",
"$",
"panelRow",
")",
";",
"foreach",
"(",
"$",
"row",
"as",
"$",
"element",
")",
"{",
"/** @var ElementInformationInterface $element */",
"if",
"(",
"null",
"!==",
"$",
"instance",
"=",
"$",
"this",
"->",
"createElement",
"(",
"$",
"element",
")",
")",
"{",
"$",
"panelRow",
"->",
"addElement",
"(",
"$",
"element",
"->",
"getName",
"(",
")",
",",
"$",
"instance",
")",
";",
"}",
"}",
"}",
"return",
"$",
"panel",
";",
"}"
]
| Build the panel.
@return DefaultPanelContainer | [
"Build",
"the",
"panel",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/View/Contao2BackendView/PanelBuilder.php#L67-L90 | train |
contao-community-alliance/dc-general | src/Contao/View/Contao2BackendView/PanelBuilder.php | PanelBuilder.createElement | private function createElement($element)
{
if ($element instanceof FilterElementInformationInterface) {
$panelElement = new DefaultFilterElement();
return $panelElement->setPropertyName($element->getPropertyName());
}
if ($element instanceof LimitElementInformationInterface) {
return new DefaultLimitElement();
}
if ($element instanceof SearchElementInformationInterface) {
return $this->buildSearchElement($element);
}
if ($element instanceof SortElementInformationInterface) {
return new DefaultSortElement();
}
if ($element instanceof SubmitElementInformationInterface) {
return new DefaultSubmitElement();
}
return null;
} | php | private function createElement($element)
{
if ($element instanceof FilterElementInformationInterface) {
$panelElement = new DefaultFilterElement();
return $panelElement->setPropertyName($element->getPropertyName());
}
if ($element instanceof LimitElementInformationInterface) {
return new DefaultLimitElement();
}
if ($element instanceof SearchElementInformationInterface) {
return $this->buildSearchElement($element);
}
if ($element instanceof SortElementInformationInterface) {
return new DefaultSortElement();
}
if ($element instanceof SubmitElementInformationInterface) {
return new DefaultSubmitElement();
}
return null;
} | [
"private",
"function",
"createElement",
"(",
"$",
"element",
")",
"{",
"if",
"(",
"$",
"element",
"instanceof",
"FilterElementInformationInterface",
")",
"{",
"$",
"panelElement",
"=",
"new",
"DefaultFilterElement",
"(",
")",
";",
"return",
"$",
"panelElement",
"->",
"setPropertyName",
"(",
"$",
"element",
"->",
"getPropertyName",
"(",
")",
")",
";",
"}",
"if",
"(",
"$",
"element",
"instanceof",
"LimitElementInformationInterface",
")",
"{",
"return",
"new",
"DefaultLimitElement",
"(",
")",
";",
"}",
"if",
"(",
"$",
"element",
"instanceof",
"SearchElementInformationInterface",
")",
"{",
"return",
"$",
"this",
"->",
"buildSearchElement",
"(",
"$",
"element",
")",
";",
"}",
"if",
"(",
"$",
"element",
"instanceof",
"SortElementInformationInterface",
")",
"{",
"return",
"new",
"DefaultSortElement",
"(",
")",
";",
"}",
"if",
"(",
"$",
"element",
"instanceof",
"SubmitElementInformationInterface",
")",
"{",
"return",
"new",
"DefaultSubmitElement",
"(",
")",
";",
"}",
"return",
"null",
";",
"}"
]
| Create the panel element.
@param ElementInformationInterface $element The element being created.
@return PanelElementInterface|null | [
"Create",
"the",
"panel",
"element",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/View/Contao2BackendView/PanelBuilder.php#L99-L119 | train |
contao-community-alliance/dc-general | src/Contao/View/Contao2BackendView/PanelBuilder.php | PanelBuilder.buildSearchElement | private function buildSearchElement($element)
{
$panelElement = new DefaultSearchElement();
foreach ($element->getPropertyNames() as $propName) {
$panelElement->addProperty($propName);
}
return $panelElement;
} | php | private function buildSearchElement($element)
{
$panelElement = new DefaultSearchElement();
foreach ($element->getPropertyNames() as $propName) {
$panelElement->addProperty($propName);
}
return $panelElement;
} | [
"private",
"function",
"buildSearchElement",
"(",
"$",
"element",
")",
"{",
"$",
"panelElement",
"=",
"new",
"DefaultSearchElement",
"(",
")",
";",
"foreach",
"(",
"$",
"element",
"->",
"getPropertyNames",
"(",
")",
"as",
"$",
"propName",
")",
"{",
"$",
"panelElement",
"->",
"addProperty",
"(",
"$",
"propName",
")",
";",
"}",
"return",
"$",
"panelElement",
";",
"}"
]
| Build a search element.
@param SearchElementInformationInterface $element The element definition.
@return DefaultSearchElement | [
"Build",
"a",
"search",
"element",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/View/Contao2BackendView/PanelBuilder.php#L128-L136 | train |
contao-community-alliance/dc-general | src/Controller/RelationshipManager.php | RelationshipManager.isRoot | public function isRoot(ModelInterface $model)
{
if (BasicDefinitionInterface::MODE_HIERARCHICAL !== $this->mode) {
return false;
}
$condition = $this->relationships->getRootCondition();
if (!$condition instanceof RootConditionInterface) {
throw new DcGeneralRuntimeException('No root condition defined');
}
return $condition->matches($model);
} | php | public function isRoot(ModelInterface $model)
{
if (BasicDefinitionInterface::MODE_HIERARCHICAL !== $this->mode) {
return false;
}
$condition = $this->relationships->getRootCondition();
if (!$condition instanceof RootConditionInterface) {
throw new DcGeneralRuntimeException('No root condition defined');
}
return $condition->matches($model);
} | [
"public",
"function",
"isRoot",
"(",
"ModelInterface",
"$",
"model",
")",
"{",
"if",
"(",
"BasicDefinitionInterface",
"::",
"MODE_HIERARCHICAL",
"!==",
"$",
"this",
"->",
"mode",
")",
"{",
"return",
"false",
";",
"}",
"$",
"condition",
"=",
"$",
"this",
"->",
"relationships",
"->",
"getRootCondition",
"(",
")",
";",
"if",
"(",
"!",
"$",
"condition",
"instanceof",
"RootConditionInterface",
")",
"{",
"throw",
"new",
"DcGeneralRuntimeException",
"(",
"'No root condition defined'",
")",
";",
"}",
"return",
"$",
"condition",
"->",
"matches",
"(",
"$",
"model",
")",
";",
"}"
]
| Check if the given model is a root model for the current data definition.
@param ModelInterface $model The model to check.
@return bool
@throws DcGeneralRuntimeException When no root condition is defined. | [
"Check",
"if",
"the",
"given",
"model",
"is",
"a",
"root",
"model",
"for",
"the",
"current",
"data",
"definition",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Controller/RelationshipManager.php#L73-L85 | train |
contao-community-alliance/dc-general | src/Controller/RelationshipManager.php | RelationshipManager.setRoot | public function setRoot(ModelInterface $model)
{
if (BasicDefinitionInterface::MODE_HIERARCHICAL !== $this->mode) {
return;
}
$condition = $this->relationships->getRootCondition();
if (!$condition instanceof RootConditionInterface) {
throw new DcGeneralRuntimeException('No root condition defined');
}
$condition->applyTo($model);
} | php | public function setRoot(ModelInterface $model)
{
if (BasicDefinitionInterface::MODE_HIERARCHICAL !== $this->mode) {
return;
}
$condition = $this->relationships->getRootCondition();
if (!$condition instanceof RootConditionInterface) {
throw new DcGeneralRuntimeException('No root condition defined');
}
$condition->applyTo($model);
} | [
"public",
"function",
"setRoot",
"(",
"ModelInterface",
"$",
"model",
")",
"{",
"if",
"(",
"BasicDefinitionInterface",
"::",
"MODE_HIERARCHICAL",
"!==",
"$",
"this",
"->",
"mode",
")",
"{",
"return",
";",
"}",
"$",
"condition",
"=",
"$",
"this",
"->",
"relationships",
"->",
"getRootCondition",
"(",
")",
";",
"if",
"(",
"!",
"$",
"condition",
"instanceof",
"RootConditionInterface",
")",
"{",
"throw",
"new",
"DcGeneralRuntimeException",
"(",
"'No root condition defined'",
")",
";",
"}",
"$",
"condition",
"->",
"applyTo",
"(",
"$",
"model",
")",
";",
"}"
]
| Apply the root condition of the current data definition to the given model.
@param ModelInterface $model The model to be used as root.
@return void
@throws DcGeneralRuntimeException When no root condition is defined. | [
"Apply",
"the",
"root",
"condition",
"of",
"the",
"current",
"data",
"definition",
"to",
"the",
"given",
"model",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Controller/RelationshipManager.php#L96-L108 | train |
contao-community-alliance/dc-general | src/Controller/RelationshipManager.php | RelationshipManager.setParent | public function setParent(ModelInterface $childModel, ModelInterface $parentModel)
{
$condition = $this->relationships->getChildCondition(
$parentModel->getProviderName(),
$childModel->getProviderName()
);
if (!$condition instanceof ParentChildConditionInterface) {
throw new DcGeneralRuntimeException(
'No condition defined from ' . $parentModel->getProviderName() . ' to ' . $childModel->getProviderName()
);
}
$condition->applyTo($parentModel, $childModel);
} | php | public function setParent(ModelInterface $childModel, ModelInterface $parentModel)
{
$condition = $this->relationships->getChildCondition(
$parentModel->getProviderName(),
$childModel->getProviderName()
);
if (!$condition instanceof ParentChildConditionInterface) {
throw new DcGeneralRuntimeException(
'No condition defined from ' . $parentModel->getProviderName() . ' to ' . $childModel->getProviderName()
);
}
$condition->applyTo($parentModel, $childModel);
} | [
"public",
"function",
"setParent",
"(",
"ModelInterface",
"$",
"childModel",
",",
"ModelInterface",
"$",
"parentModel",
")",
"{",
"$",
"condition",
"=",
"$",
"this",
"->",
"relationships",
"->",
"getChildCondition",
"(",
"$",
"parentModel",
"->",
"getProviderName",
"(",
")",
",",
"$",
"childModel",
"->",
"getProviderName",
"(",
")",
")",
";",
"if",
"(",
"!",
"$",
"condition",
"instanceof",
"ParentChildConditionInterface",
")",
"{",
"throw",
"new",
"DcGeneralRuntimeException",
"(",
"'No condition defined from '",
".",
"$",
"parentModel",
"->",
"getProviderName",
"(",
")",
".",
"' to '",
".",
"$",
"childModel",
"->",
"getProviderName",
"(",
")",
")",
";",
"}",
"$",
"condition",
"->",
"applyTo",
"(",
"$",
"parentModel",
",",
"$",
"childModel",
")",
";",
"}"
]
| Set a model as the parent of another model.
@param ModelInterface $childModel The model to become the child.
@param ModelInterface $parentModel The model to use as parent.
@return void
@throws DcGeneralRuntimeException When no condition is defined. | [
"Set",
"a",
"model",
"as",
"the",
"parent",
"of",
"another",
"model",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Controller/RelationshipManager.php#L134-L147 | train |
contao-community-alliance/dc-general | src/Controller/RelationshipManager.php | RelationshipManager.setParentForAll | public function setParentForAll(CollectionInterface $models, ModelInterface $parentModel)
{
foreach ($models as $model) {
$this->setParent($model, $parentModel);
}
} | php | public function setParentForAll(CollectionInterface $models, ModelInterface $parentModel)
{
foreach ($models as $model) {
$this->setParent($model, $parentModel);
}
} | [
"public",
"function",
"setParentForAll",
"(",
"CollectionInterface",
"$",
"models",
",",
"ModelInterface",
"$",
"parentModel",
")",
"{",
"foreach",
"(",
"$",
"models",
"as",
"$",
"model",
")",
"{",
"$",
"this",
"->",
"setParent",
"(",
"$",
"model",
",",
"$",
"parentModel",
")",
";",
"}",
"}"
]
| Sets the parent for all models.
@param CollectionInterface $models The collection of models to apply the parent to.
@param ModelInterface $parentModel The new parent model.
@return void | [
"Sets",
"the",
"parent",
"for",
"all",
"models",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Controller/RelationshipManager.php#L157-L162 | train |
contao-community-alliance/dc-general | src/Controller/RelationshipManager.php | RelationshipManager.setSameParent | public function setSameParent(ModelInterface $receivingModel, ModelInterface $sourceModel, $parentTable)
{
$condition = $this->relationships->getChildCondition($parentTable, $receivingModel->getProviderName());
if (!$condition instanceof ParentChildConditionInterface) {
throw new DcGeneralRuntimeException(
'No condition defined from ' . $parentTable . ' to ' . $receivingModel->getProviderName()
);
}
$condition->copyFrom($sourceModel, $receivingModel);
} | php | public function setSameParent(ModelInterface $receivingModel, ModelInterface $sourceModel, $parentTable)
{
$condition = $this->relationships->getChildCondition($parentTable, $receivingModel->getProviderName());
if (!$condition instanceof ParentChildConditionInterface) {
throw new DcGeneralRuntimeException(
'No condition defined from ' . $parentTable . ' to ' . $receivingModel->getProviderName()
);
}
$condition->copyFrom($sourceModel, $receivingModel);
} | [
"public",
"function",
"setSameParent",
"(",
"ModelInterface",
"$",
"receivingModel",
",",
"ModelInterface",
"$",
"sourceModel",
",",
"$",
"parentTable",
")",
"{",
"$",
"condition",
"=",
"$",
"this",
"->",
"relationships",
"->",
"getChildCondition",
"(",
"$",
"parentTable",
",",
"$",
"receivingModel",
"->",
"getProviderName",
"(",
")",
")",
";",
"if",
"(",
"!",
"$",
"condition",
"instanceof",
"ParentChildConditionInterface",
")",
"{",
"throw",
"new",
"DcGeneralRuntimeException",
"(",
"'No condition defined from '",
".",
"$",
"parentTable",
".",
"' to '",
".",
"$",
"receivingModel",
"->",
"getProviderName",
"(",
")",
")",
";",
"}",
"$",
"condition",
"->",
"copyFrom",
"(",
"$",
"sourceModel",
",",
"$",
"receivingModel",
")",
";",
"}"
]
| Sets all parent condition fields in the destination to the values from the source model.
Useful when moving an element after another in a different parent.
@param ModelInterface $receivingModel The model that shall get updated.
@param ModelInterface $sourceModel The model that the values shall get retrieved from.
@param string $parentTable The name of the parent table for the models.
@return void
@throws DcGeneralRuntimeException When no condition is defined. | [
"Sets",
"all",
"parent",
"condition",
"fields",
"in",
"the",
"destination",
"to",
"the",
"values",
"from",
"the",
"source",
"model",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Controller/RelationshipManager.php#L177-L187 | train |
contao-community-alliance/dc-general | src/Controller/RelationshipManager.php | RelationshipManager.setSameParentForAll | public function setSameParentForAll(CollectionInterface $models, ModelInterface $sourceModel, $parentTable)
{
foreach ($models as $model) {
$this->setSameParent($model, $sourceModel, $parentTable);
}
} | php | public function setSameParentForAll(CollectionInterface $models, ModelInterface $sourceModel, $parentTable)
{
foreach ($models as $model) {
$this->setSameParent($model, $sourceModel, $parentTable);
}
} | [
"public",
"function",
"setSameParentForAll",
"(",
"CollectionInterface",
"$",
"models",
",",
"ModelInterface",
"$",
"sourceModel",
",",
"$",
"parentTable",
")",
"{",
"foreach",
"(",
"$",
"models",
"as",
"$",
"model",
")",
"{",
"$",
"this",
"->",
"setSameParent",
"(",
"$",
"model",
",",
"$",
"sourceModel",
",",
"$",
"parentTable",
")",
";",
"}",
"}"
]
| Sets the same parent for all models.
@param CollectionInterface $models The collection of models to apply the parent to.
@param ModelInterface $sourceModel The model that the values shall get retrieved from.
@param string $parentTable The name of the parent table for the models.
@return void | [
"Sets",
"the",
"same",
"parent",
"for",
"all",
"models",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Controller/RelationshipManager.php#L198-L203 | train |
contao-community-alliance/dc-general | src/Contao/Subscriber/DynamicParentTableSubscriber.php | DynamicParentTableSubscriber.handlePrePersistModelEvent | public function handlePrePersistModelEvent(PrePersistModelEvent $event)
{
$enviroment = $event->getEnvironment();
$dataDefinition = $enviroment->getDataDefinition();
if (null === ($parentDataDefinition = $enviroment->getParentDataDefinition())
|| (false === $dataDefinition->getPropertiesDefinition()->hasProperty('ptable'))
|| (false === $dataDefinition->getBasicDefinition()->isDynamicParentTable())
) {
return;
}
$model = $event->getModel();
$model->setProperty('ptable', $parentDataDefinition->getName());
} | php | public function handlePrePersistModelEvent(PrePersistModelEvent $event)
{
$enviroment = $event->getEnvironment();
$dataDefinition = $enviroment->getDataDefinition();
if (null === ($parentDataDefinition = $enviroment->getParentDataDefinition())
|| (false === $dataDefinition->getPropertiesDefinition()->hasProperty('ptable'))
|| (false === $dataDefinition->getBasicDefinition()->isDynamicParentTable())
) {
return;
}
$model = $event->getModel();
$model->setProperty('ptable', $parentDataDefinition->getName());
} | [
"public",
"function",
"handlePrePersistModelEvent",
"(",
"PrePersistModelEvent",
"$",
"event",
")",
"{",
"$",
"enviroment",
"=",
"$",
"event",
"->",
"getEnvironment",
"(",
")",
";",
"$",
"dataDefinition",
"=",
"$",
"enviroment",
"->",
"getDataDefinition",
"(",
")",
";",
"if",
"(",
"null",
"===",
"(",
"$",
"parentDataDefinition",
"=",
"$",
"enviroment",
"->",
"getParentDataDefinition",
"(",
")",
")",
"||",
"(",
"false",
"===",
"$",
"dataDefinition",
"->",
"getPropertiesDefinition",
"(",
")",
"->",
"hasProperty",
"(",
"'ptable'",
")",
")",
"||",
"(",
"false",
"===",
"$",
"dataDefinition",
"->",
"getBasicDefinition",
"(",
")",
"->",
"isDynamicParentTable",
"(",
")",
")",
")",
"{",
"return",
";",
"}",
"$",
"model",
"=",
"$",
"event",
"->",
"getModel",
"(",
")",
";",
"$",
"model",
"->",
"setProperty",
"(",
"'ptable'",
",",
"$",
"parentDataDefinition",
"->",
"getName",
"(",
")",
")",
";",
"}"
]
| Handle the pre persist model event.
@param PrePersistModelEvent $event The event to handle.
@return void | [
"Handle",
"the",
"pre",
"persist",
"model",
"event",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/Subscriber/DynamicParentTableSubscriber.php#L63-L78 | train |
contao-community-alliance/dc-general | src/Contao/View/Contao2BackendView/Widget/FileTreeOrder.php | FileTreeOrder.getSerializedValue | protected function getSerializedValue()
{
if (null === $this->varValue) {
$this->varValue = [];
}
return \implode(',', \array_map('\Contao\StringUtil::binToUuid', $this->varValue));
} | php | protected function getSerializedValue()
{
if (null === $this->varValue) {
$this->varValue = [];
}
return \implode(',', \array_map('\Contao\StringUtil::binToUuid', $this->varValue));
} | [
"protected",
"function",
"getSerializedValue",
"(",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"varValue",
")",
"{",
"$",
"this",
"->",
"varValue",
"=",
"[",
"]",
";",
"}",
"return",
"\\",
"implode",
"(",
"','",
",",
"\\",
"array_map",
"(",
"'\\Contao\\StringUtil::binToUuid'",
",",
"$",
"this",
"->",
"varValue",
")",
")",
";",
"}"
]
| Get the value serialized as string.
@return string | [
"Get",
"the",
"value",
"serialized",
"as",
"string",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/View/Contao2BackendView/Widget/FileTreeOrder.php#L65-L72 | train |
contao-community-alliance/dc-general | src/Contao/View/Contao2BackendView/ActionHandler/CreateHandler.php | CreateHandler.checkPermission | private function checkPermission(EnvironmentInterface $environment)
{
$dataDefinition = $environment->getDataDefinition();
if (true === $dataDefinition->getBasicDefinition()->isCreatable()) {
return true;
}
return \sprintf(
'<div style="text-align:center; font-weight:bold; padding:40px;">
You have no permission for create model in %s.
</div>',
$dataDefinition->getName()
);
} | php | private function checkPermission(EnvironmentInterface $environment)
{
$dataDefinition = $environment->getDataDefinition();
if (true === $dataDefinition->getBasicDefinition()->isCreatable()) {
return true;
}
return \sprintf(
'<div style="text-align:center; font-weight:bold; padding:40px;">
You have no permission for create model in %s.
</div>',
$dataDefinition->getName()
);
} | [
"private",
"function",
"checkPermission",
"(",
"EnvironmentInterface",
"$",
"environment",
")",
"{",
"$",
"dataDefinition",
"=",
"$",
"environment",
"->",
"getDataDefinition",
"(",
")",
";",
"if",
"(",
"true",
"===",
"$",
"dataDefinition",
"->",
"getBasicDefinition",
"(",
")",
"->",
"isCreatable",
"(",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"\\",
"sprintf",
"(",
"'<div style=\"text-align:center; font-weight:bold; padding:40px;\">\n You have no permission for create model in %s.\n </div>'",
",",
"$",
"dataDefinition",
"->",
"getName",
"(",
")",
")",
";",
"}"
]
| Check permission for create a model.
@param EnvironmentInterface $environment The environment.
@return string|bool | [
"Check",
"permission",
"for",
"create",
"a",
"model",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/View/Contao2BackendView/ActionHandler/CreateHandler.php#L136-L150 | train |
contao-community-alliance/dc-general | src/Contao/View/Contao2BackendView/ActionHandler/CreateHandler.php | CreateHandler.handleGlobalCommands | protected function handleGlobalCommands(EnvironmentInterface $environment)
{
$dataDefinition = $environment->getDataDefinition();
$backendView = $dataDefinition->getDefinition(Contao2BackendViewDefinitionInterface::NAME);
$globalCommands = $backendView->getGlobalCommands();
$globalCommands->clearCommands();
$backCommand = new BackCommand();
$backCommand->setDisabled(false);
$globalCommands->addCommand($backCommand);
} | php | protected function handleGlobalCommands(EnvironmentInterface $environment)
{
$dataDefinition = $environment->getDataDefinition();
$backendView = $dataDefinition->getDefinition(Contao2BackendViewDefinitionInterface::NAME);
$globalCommands = $backendView->getGlobalCommands();
$globalCommands->clearCommands();
$backCommand = new BackCommand();
$backCommand->setDisabled(false);
$globalCommands->addCommand($backCommand);
} | [
"protected",
"function",
"handleGlobalCommands",
"(",
"EnvironmentInterface",
"$",
"environment",
")",
"{",
"$",
"dataDefinition",
"=",
"$",
"environment",
"->",
"getDataDefinition",
"(",
")",
";",
"$",
"backendView",
"=",
"$",
"dataDefinition",
"->",
"getDefinition",
"(",
"Contao2BackendViewDefinitionInterface",
"::",
"NAME",
")",
";",
"$",
"globalCommands",
"=",
"$",
"backendView",
"->",
"getGlobalCommands",
"(",
")",
";",
"$",
"globalCommands",
"->",
"clearCommands",
"(",
")",
";",
"$",
"backCommand",
"=",
"new",
"BackCommand",
"(",
")",
";",
"$",
"backCommand",
"->",
"setDisabled",
"(",
"false",
")",
";",
"$",
"globalCommands",
"->",
"addCommand",
"(",
"$",
"backCommand",
")",
";",
"}"
]
| Handle the globals commands
@param EnvironmentInterface $environment The environment.
@return void | [
"Handle",
"the",
"globals",
"commands"
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/View/Contao2BackendView/ActionHandler/CreateHandler.php#L159-L170 | train |
contao-community-alliance/dc-general | src/Contao/View/Contao2BackendView/ActionHandler/AbstractListShowAllHandler.php | AbstractListShowAllHandler.renderModel | protected function renderModel(ModelInterface $model, EnvironmentInterface $environment)
{
$event = new FormatModelLabelEvent($environment, $model);
$environment->getEventDispatcher()->dispatch(
DcGeneralEvents::FORMAT_MODEL_LABEL,
$event
);
$model->setMeta($model::LABEL_VALUE, $event->getLabel());
} | php | protected function renderModel(ModelInterface $model, EnvironmentInterface $environment)
{
$event = new FormatModelLabelEvent($environment, $model);
$environment->getEventDispatcher()->dispatch(
DcGeneralEvents::FORMAT_MODEL_LABEL,
$event
);
$model->setMeta($model::LABEL_VALUE, $event->getLabel());
} | [
"protected",
"function",
"renderModel",
"(",
"ModelInterface",
"$",
"model",
",",
"EnvironmentInterface",
"$",
"environment",
")",
"{",
"$",
"event",
"=",
"new",
"FormatModelLabelEvent",
"(",
"$",
"environment",
",",
"$",
"model",
")",
";",
"$",
"environment",
"->",
"getEventDispatcher",
"(",
")",
"->",
"dispatch",
"(",
"DcGeneralEvents",
"::",
"FORMAT_MODEL_LABEL",
",",
"$",
"event",
")",
";",
"$",
"model",
"->",
"setMeta",
"(",
"$",
"model",
"::",
"LABEL_VALUE",
",",
"$",
"event",
"->",
"getLabel",
"(",
")",
")",
";",
"}"
]
| Render a model.
@param ModelInterface $model The model to render.
@param EnvironmentInterface $environment Current environment.
@return void | [
"Render",
"a",
"model",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/View/Contao2BackendView/ActionHandler/AbstractListShowAllHandler.php#L263-L272 | train |
contao-community-alliance/dc-general | src/Contao/View/Contao2BackendView/ActionHandler/AbstractListShowAllHandler.php | AbstractListShowAllHandler.renderCollection | private function renderCollection(EnvironmentInterface $environment, CollectionInterface $collection, $grouping)
{
$listing = $this->getViewSection($environment->getDataDefinition())->getListingConfig();
$remoteCur = null;
$groupClass = 'tl_folder_tlist';
$eoCount = -1;
// Generate buttons - only if not in select mode!
if ('select' !== $environment->getInputProvider()->getParameter('act')) {
$buttonRenderer = new ButtonRenderer($environment);
$buttonRenderer->renderButtonsForCollection($collection);
}
// Run each model.
foreach ($collection as $model) {
/** @var ModelInterface $model */
$this->addGroupHeader($environment, (array) $grouping, $model, $groupClass, $eoCount, $remoteCur);
if ($listing->getItemCssClass()) {
$model->setMeta($model::CSS_CLASS, $listing->getItemCssClass());
}
$cssClasses = [(0 === (++$eoCount) % 2) ? 'even' : 'odd'];
(null !== $model->getMeta($model::CSS_ROW_CLASS)) ?
$cssClasses[] = $model->getMeta($model::CSS_ROW_CLASS) : null;
$modelId = ModelId::fromModel($model);
if ($environment->getClipboard()->hasId($modelId)) {
$cssClasses[] = 'tl_folder_clipped';
}
$model->setMeta($model::CSS_ROW_CLASS, \implode(' ', $cssClasses));
$this->renderModel($model, $environment);
}
} | php | private function renderCollection(EnvironmentInterface $environment, CollectionInterface $collection, $grouping)
{
$listing = $this->getViewSection($environment->getDataDefinition())->getListingConfig();
$remoteCur = null;
$groupClass = 'tl_folder_tlist';
$eoCount = -1;
// Generate buttons - only if not in select mode!
if ('select' !== $environment->getInputProvider()->getParameter('act')) {
$buttonRenderer = new ButtonRenderer($environment);
$buttonRenderer->renderButtonsForCollection($collection);
}
// Run each model.
foreach ($collection as $model) {
/** @var ModelInterface $model */
$this->addGroupHeader($environment, (array) $grouping, $model, $groupClass, $eoCount, $remoteCur);
if ($listing->getItemCssClass()) {
$model->setMeta($model::CSS_CLASS, $listing->getItemCssClass());
}
$cssClasses = [(0 === (++$eoCount) % 2) ? 'even' : 'odd'];
(null !== $model->getMeta($model::CSS_ROW_CLASS)) ?
$cssClasses[] = $model->getMeta($model::CSS_ROW_CLASS) : null;
$modelId = ModelId::fromModel($model);
if ($environment->getClipboard()->hasId($modelId)) {
$cssClasses[] = 'tl_folder_clipped';
}
$model->setMeta($model::CSS_ROW_CLASS, \implode(' ', $cssClasses));
$this->renderModel($model, $environment);
}
} | [
"private",
"function",
"renderCollection",
"(",
"EnvironmentInterface",
"$",
"environment",
",",
"CollectionInterface",
"$",
"collection",
",",
"$",
"grouping",
")",
"{",
"$",
"listing",
"=",
"$",
"this",
"->",
"getViewSection",
"(",
"$",
"environment",
"->",
"getDataDefinition",
"(",
")",
")",
"->",
"getListingConfig",
"(",
")",
";",
"$",
"remoteCur",
"=",
"null",
";",
"$",
"groupClass",
"=",
"'tl_folder_tlist'",
";",
"$",
"eoCount",
"=",
"-",
"1",
";",
"// Generate buttons - only if not in select mode!",
"if",
"(",
"'select'",
"!==",
"$",
"environment",
"->",
"getInputProvider",
"(",
")",
"->",
"getParameter",
"(",
"'act'",
")",
")",
"{",
"$",
"buttonRenderer",
"=",
"new",
"ButtonRenderer",
"(",
"$",
"environment",
")",
";",
"$",
"buttonRenderer",
"->",
"renderButtonsForCollection",
"(",
"$",
"collection",
")",
";",
"}",
"// Run each model.",
"foreach",
"(",
"$",
"collection",
"as",
"$",
"model",
")",
"{",
"/** @var ModelInterface $model */",
"$",
"this",
"->",
"addGroupHeader",
"(",
"$",
"environment",
",",
"(",
"array",
")",
"$",
"grouping",
",",
"$",
"model",
",",
"$",
"groupClass",
",",
"$",
"eoCount",
",",
"$",
"remoteCur",
")",
";",
"if",
"(",
"$",
"listing",
"->",
"getItemCssClass",
"(",
")",
")",
"{",
"$",
"model",
"->",
"setMeta",
"(",
"$",
"model",
"::",
"CSS_CLASS",
",",
"$",
"listing",
"->",
"getItemCssClass",
"(",
")",
")",
";",
"}",
"$",
"cssClasses",
"=",
"[",
"(",
"0",
"===",
"(",
"++",
"$",
"eoCount",
")",
"%",
"2",
")",
"?",
"'even'",
":",
"'odd'",
"]",
";",
"(",
"null",
"!==",
"$",
"model",
"->",
"getMeta",
"(",
"$",
"model",
"::",
"CSS_ROW_CLASS",
")",
")",
"?",
"$",
"cssClasses",
"[",
"]",
"=",
"$",
"model",
"->",
"getMeta",
"(",
"$",
"model",
"::",
"CSS_ROW_CLASS",
")",
":",
"null",
";",
"$",
"modelId",
"=",
"ModelId",
"::",
"fromModel",
"(",
"$",
"model",
")",
";",
"if",
"(",
"$",
"environment",
"->",
"getClipboard",
"(",
")",
"->",
"hasId",
"(",
"$",
"modelId",
")",
")",
"{",
"$",
"cssClasses",
"[",
"]",
"=",
"'tl_folder_clipped'",
";",
"}",
"$",
"model",
"->",
"setMeta",
"(",
"$",
"model",
"::",
"CSS_ROW_CLASS",
",",
"\\",
"implode",
"(",
"' '",
",",
"$",
"cssClasses",
")",
")",
";",
"$",
"this",
"->",
"renderModel",
"(",
"$",
"model",
",",
"$",
"environment",
")",
";",
"}",
"}"
]
| Render the collection.
@param EnvironmentInterface $environment The environment.
@param CollectionInterface $collection The collection to render.
@param array $grouping The grouping information.
@return void | [
"Render",
"the",
"collection",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/View/Contao2BackendView/ActionHandler/AbstractListShowAllHandler.php#L372-L407 | train |
contao-community-alliance/dc-general | src/Contao/View/Contao2BackendView/ActionHandler/AbstractListShowAllHandler.php | AbstractListShowAllHandler.addGroupHeader | private function addGroupHeader(
EnvironmentInterface $environment,
array $grouping,
ModelInterface $model,
&$groupClass,
&$eoCount,
&$remoteCur = null
) {
if ($grouping && GroupAndSortingInformationInterface::GROUP_NONE !== $grouping['mode']) {
$remoteNew = $this->renderGroupHeader(
$grouping['property'],
$model,
$grouping['mode'],
$grouping['length'],
$environment
);
$model->setMeta(
$model::GROUP_VALUE,
[
'class' => $groupClass,
'value' => $remoteNew
]
);
// Add the group header if it differs from the last header.
if (($remoteCur !== $remoteNew) || (null === $remoteCur)) {
$eoCount = -1;
$groupClass = 'tl_folder_list';
$remoteCur = $remoteNew;
}
}
} | php | private function addGroupHeader(
EnvironmentInterface $environment,
array $grouping,
ModelInterface $model,
&$groupClass,
&$eoCount,
&$remoteCur = null
) {
if ($grouping && GroupAndSortingInformationInterface::GROUP_NONE !== $grouping['mode']) {
$remoteNew = $this->renderGroupHeader(
$grouping['property'],
$model,
$grouping['mode'],
$grouping['length'],
$environment
);
$model->setMeta(
$model::GROUP_VALUE,
[
'class' => $groupClass,
'value' => $remoteNew
]
);
// Add the group header if it differs from the last header.
if (($remoteCur !== $remoteNew) || (null === $remoteCur)) {
$eoCount = -1;
$groupClass = 'tl_folder_list';
$remoteCur = $remoteNew;
}
}
} | [
"private",
"function",
"addGroupHeader",
"(",
"EnvironmentInterface",
"$",
"environment",
",",
"array",
"$",
"grouping",
",",
"ModelInterface",
"$",
"model",
",",
"&",
"$",
"groupClass",
",",
"&",
"$",
"eoCount",
",",
"&",
"$",
"remoteCur",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"grouping",
"&&",
"GroupAndSortingInformationInterface",
"::",
"GROUP_NONE",
"!==",
"$",
"grouping",
"[",
"'mode'",
"]",
")",
"{",
"$",
"remoteNew",
"=",
"$",
"this",
"->",
"renderGroupHeader",
"(",
"$",
"grouping",
"[",
"'property'",
"]",
",",
"$",
"model",
",",
"$",
"grouping",
"[",
"'mode'",
"]",
",",
"$",
"grouping",
"[",
"'length'",
"]",
",",
"$",
"environment",
")",
";",
"$",
"model",
"->",
"setMeta",
"(",
"$",
"model",
"::",
"GROUP_VALUE",
",",
"[",
"'class'",
"=>",
"$",
"groupClass",
",",
"'value'",
"=>",
"$",
"remoteNew",
"]",
")",
";",
"// Add the group header if it differs from the last header.",
"if",
"(",
"(",
"$",
"remoteCur",
"!==",
"$",
"remoteNew",
")",
"||",
"(",
"null",
"===",
"$",
"remoteCur",
")",
")",
"{",
"$",
"eoCount",
"=",
"-",
"1",
";",
"$",
"groupClass",
"=",
"'tl_folder_list'",
";",
"$",
"remoteCur",
"=",
"$",
"remoteNew",
";",
"}",
"}",
"}"
]
| Add the group header information to the model.
@param EnvironmentInterface $environment The environment.
@param array $grouping The grouping information.
@param ModelInterface $model The model.
@param string $groupClass The group class.
@param integer $eoCount The row even odd counter.
@param mixed $remoteCur The current remote.
@return void | [
"Add",
"the",
"group",
"header",
"information",
"to",
"the",
"model",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/View/Contao2BackendView/ActionHandler/AbstractListShowAllHandler.php#L421-L452 | train |
contao-community-alliance/dc-general | src/Contao/View/Contao2BackendView/ActionHandler/AbstractListShowAllHandler.php | AbstractListShowAllHandler.getTableHead | private function getTableHead(EnvironmentInterface $environment)
{
$tableHead = [];
$definition = $environment->getDataDefinition();
$properties = $definition->getPropertiesDefinition();
$formatter = $this->getViewSection($definition)->getListingConfig()->getLabelFormatter($definition->getName());
$sorting = ViewHelpers::getCurrentSorting($environment);
$columns = $this->getSortingColumns($sorting);
foreach ($formatter->getPropertyNames() as $field) {
// Skip unknown properties. This may happen if the property is not defined for editing but only listing.
if (!$properties->hasProperty($field)) {
continue;
}
$tableHead[] = [
'class' => 'tl_folder_tlist col_' . $field . (\in_array($field, $columns) ? ' ordered_by' : ''),
'content' => $properties->getProperty($field)->getLabel()
];
}
$tableHead[] = [
'class' => 'tl_folder_tlist tl_right_nowrap',
'content' => $this->renderPasteTopButton($environment, $sorting) ?: ' '
];
return $tableHead;
} | php | private function getTableHead(EnvironmentInterface $environment)
{
$tableHead = [];
$definition = $environment->getDataDefinition();
$properties = $definition->getPropertiesDefinition();
$formatter = $this->getViewSection($definition)->getListingConfig()->getLabelFormatter($definition->getName());
$sorting = ViewHelpers::getCurrentSorting($environment);
$columns = $this->getSortingColumns($sorting);
foreach ($formatter->getPropertyNames() as $field) {
// Skip unknown properties. This may happen if the property is not defined for editing but only listing.
if (!$properties->hasProperty($field)) {
continue;
}
$tableHead[] = [
'class' => 'tl_folder_tlist col_' . $field . (\in_array($field, $columns) ? ' ordered_by' : ''),
'content' => $properties->getProperty($field)->getLabel()
];
}
$tableHead[] = [
'class' => 'tl_folder_tlist tl_right_nowrap',
'content' => $this->renderPasteTopButton($environment, $sorting) ?: ' '
];
return $tableHead;
} | [
"private",
"function",
"getTableHead",
"(",
"EnvironmentInterface",
"$",
"environment",
")",
"{",
"$",
"tableHead",
"=",
"[",
"]",
";",
"$",
"definition",
"=",
"$",
"environment",
"->",
"getDataDefinition",
"(",
")",
";",
"$",
"properties",
"=",
"$",
"definition",
"->",
"getPropertiesDefinition",
"(",
")",
";",
"$",
"formatter",
"=",
"$",
"this",
"->",
"getViewSection",
"(",
"$",
"definition",
")",
"->",
"getListingConfig",
"(",
")",
"->",
"getLabelFormatter",
"(",
"$",
"definition",
"->",
"getName",
"(",
")",
")",
";",
"$",
"sorting",
"=",
"ViewHelpers",
"::",
"getCurrentSorting",
"(",
"$",
"environment",
")",
";",
"$",
"columns",
"=",
"$",
"this",
"->",
"getSortingColumns",
"(",
"$",
"sorting",
")",
";",
"foreach",
"(",
"$",
"formatter",
"->",
"getPropertyNames",
"(",
")",
"as",
"$",
"field",
")",
"{",
"// Skip unknown properties. This may happen if the property is not defined for editing but only listing.",
"if",
"(",
"!",
"$",
"properties",
"->",
"hasProperty",
"(",
"$",
"field",
")",
")",
"{",
"continue",
";",
"}",
"$",
"tableHead",
"[",
"]",
"=",
"[",
"'class'",
"=>",
"'tl_folder_tlist col_'",
".",
"$",
"field",
".",
"(",
"\\",
"in_array",
"(",
"$",
"field",
",",
"$",
"columns",
")",
"?",
"' ordered_by'",
":",
"''",
")",
",",
"'content'",
"=>",
"$",
"properties",
"->",
"getProperty",
"(",
"$",
"field",
")",
"->",
"getLabel",
"(",
")",
"]",
";",
"}",
"$",
"tableHead",
"[",
"]",
"=",
"[",
"'class'",
"=>",
"'tl_folder_tlist tl_right_nowrap'",
",",
"'content'",
"=>",
"$",
"this",
"->",
"renderPasteTopButton",
"(",
"$",
"environment",
",",
"$",
"sorting",
")",
"?",
":",
"' '",
"]",
";",
"return",
"$",
"tableHead",
";",
"}"
]
| Get the table headings.
@param EnvironmentInterface $environment The environment.
@return array | [
"Get",
"the",
"table",
"headings",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/View/Contao2BackendView/ActionHandler/AbstractListShowAllHandler.php#L474-L500 | train |
contao-community-alliance/dc-general | src/Contao/View/Contao2BackendView/ActionHandler/AbstractListShowAllHandler.php | AbstractListShowAllHandler.isSortable | private function isSortable(EnvironmentInterface $environment)
{
return ((true === (bool) ViewHelpers::getManualSortingProperty($environment))
&& (true === $environment->getDataDefinition()->getBasicDefinition()->isEditable()));
} | php | private function isSortable(EnvironmentInterface $environment)
{
return ((true === (bool) ViewHelpers::getManualSortingProperty($environment))
&& (true === $environment->getDataDefinition()->getBasicDefinition()->isEditable()));
} | [
"private",
"function",
"isSortable",
"(",
"EnvironmentInterface",
"$",
"environment",
")",
"{",
"return",
"(",
"(",
"true",
"===",
"(",
"bool",
")",
"ViewHelpers",
"::",
"getManualSortingProperty",
"(",
"$",
"environment",
")",
")",
"&&",
"(",
"true",
"===",
"$",
"environment",
"->",
"getDataDefinition",
"(",
")",
"->",
"getBasicDefinition",
"(",
")",
"->",
"isEditable",
"(",
")",
")",
")",
";",
"}"
]
| Check if the models are sortable.
@param EnvironmentInterface $environment The environment.
@return bool | [
"Check",
"if",
"the",
"models",
"are",
"sortable",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/View/Contao2BackendView/ActionHandler/AbstractListShowAllHandler.php#L557-L561 | train |
contao-community-alliance/dc-general | src/Contao/View/Contao2BackendView/ActionHandler/AbstractListShowAllHandler.php | AbstractListShowAllHandler.renderPasteTopButton | protected function renderPasteTopButton(EnvironmentInterface $environment, $sorting)
{
$definition = $environment->getDataDefinition();
$dispatcher = $environment->getEventDispatcher();
$languageDomain = 'contao_' . $definition->getName();
$filter = new Filter();
$filter->andModelIsFromProvider($definition->getBasicDefinition()->getDataProvider());
if (!$sorting || $environment->getClipboard()->isEmpty($filter)) {
return null;
}
if (!ViewHelpers::getManualSortingProperty($environment)) {
return null;
}
/** @var AddToUrlEvent $urlEvent */
$urlEvent = $dispatcher->dispatch(
ContaoEvents::BACKEND_ADD_TO_URL,
new AddToUrlEvent(
'act=paste&after=' . ModelId::fromValues($definition->getName(), '0')->getSerialized()
)
);
/** @var GenerateHtmlEvent $imageEvent */
$imageEvent = $dispatcher->dispatch(
ContaoEvents::IMAGE_GET_HTML,
new GenerateHtmlEvent(
'pasteafter.svg',
$this->translate('pasteafter.0', $languageDomain),
'class="blink"'
)
);
return \sprintf(
'<a href="%s" title="%s" onclick="Backend.getScrollOffset()">%s</a>',
$urlEvent->getUrl(),
StringUtil::specialchars($this->translate('pasteafter.0', $languageDomain)),
$imageEvent->getHtml()
);
} | php | protected function renderPasteTopButton(EnvironmentInterface $environment, $sorting)
{
$definition = $environment->getDataDefinition();
$dispatcher = $environment->getEventDispatcher();
$languageDomain = 'contao_' . $definition->getName();
$filter = new Filter();
$filter->andModelIsFromProvider($definition->getBasicDefinition()->getDataProvider());
if (!$sorting || $environment->getClipboard()->isEmpty($filter)) {
return null;
}
if (!ViewHelpers::getManualSortingProperty($environment)) {
return null;
}
/** @var AddToUrlEvent $urlEvent */
$urlEvent = $dispatcher->dispatch(
ContaoEvents::BACKEND_ADD_TO_URL,
new AddToUrlEvent(
'act=paste&after=' . ModelId::fromValues($definition->getName(), '0')->getSerialized()
)
);
/** @var GenerateHtmlEvent $imageEvent */
$imageEvent = $dispatcher->dispatch(
ContaoEvents::IMAGE_GET_HTML,
new GenerateHtmlEvent(
'pasteafter.svg',
$this->translate('pasteafter.0', $languageDomain),
'class="blink"'
)
);
return \sprintf(
'<a href="%s" title="%s" onclick="Backend.getScrollOffset()">%s</a>',
$urlEvent->getUrl(),
StringUtil::specialchars($this->translate('pasteafter.0', $languageDomain)),
$imageEvent->getHtml()
);
} | [
"protected",
"function",
"renderPasteTopButton",
"(",
"EnvironmentInterface",
"$",
"environment",
",",
"$",
"sorting",
")",
"{",
"$",
"definition",
"=",
"$",
"environment",
"->",
"getDataDefinition",
"(",
")",
";",
"$",
"dispatcher",
"=",
"$",
"environment",
"->",
"getEventDispatcher",
"(",
")",
";",
"$",
"languageDomain",
"=",
"'contao_'",
".",
"$",
"definition",
"->",
"getName",
"(",
")",
";",
"$",
"filter",
"=",
"new",
"Filter",
"(",
")",
";",
"$",
"filter",
"->",
"andModelIsFromProvider",
"(",
"$",
"definition",
"->",
"getBasicDefinition",
"(",
")",
"->",
"getDataProvider",
"(",
")",
")",
";",
"if",
"(",
"!",
"$",
"sorting",
"||",
"$",
"environment",
"->",
"getClipboard",
"(",
")",
"->",
"isEmpty",
"(",
"$",
"filter",
")",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"!",
"ViewHelpers",
"::",
"getManualSortingProperty",
"(",
"$",
"environment",
")",
")",
"{",
"return",
"null",
";",
"}",
"/** @var AddToUrlEvent $urlEvent */",
"$",
"urlEvent",
"=",
"$",
"dispatcher",
"->",
"dispatch",
"(",
"ContaoEvents",
"::",
"BACKEND_ADD_TO_URL",
",",
"new",
"AddToUrlEvent",
"(",
"'act=paste&after='",
".",
"ModelId",
"::",
"fromValues",
"(",
"$",
"definition",
"->",
"getName",
"(",
")",
",",
"'0'",
")",
"->",
"getSerialized",
"(",
")",
")",
")",
";",
"/** @var GenerateHtmlEvent $imageEvent */",
"$",
"imageEvent",
"=",
"$",
"dispatcher",
"->",
"dispatch",
"(",
"ContaoEvents",
"::",
"IMAGE_GET_HTML",
",",
"new",
"GenerateHtmlEvent",
"(",
"'pasteafter.svg'",
",",
"$",
"this",
"->",
"translate",
"(",
"'pasteafter.0'",
",",
"$",
"languageDomain",
")",
",",
"'class=\"blink\"'",
")",
")",
";",
"return",
"\\",
"sprintf",
"(",
"'<a href=\"%s\" title=\"%s\" onclick=\"Backend.getScrollOffset()\">%s</a>'",
",",
"$",
"urlEvent",
"->",
"getUrl",
"(",
")",
",",
"StringUtil",
"::",
"specialchars",
"(",
"$",
"this",
"->",
"translate",
"(",
"'pasteafter.0'",
",",
"$",
"languageDomain",
")",
")",
",",
"$",
"imageEvent",
"->",
"getHtml",
"(",
")",
")",
";",
"}"
]
| Render paste top button. Returns null if no button should be rendered.
@param EnvironmentInterface $environment The environment.
@param GroupAndSortingDefinitionInterface|null $sorting The sorting mode.
@return string | [
"Render",
"paste",
"top",
"button",
".",
"Returns",
"null",
"if",
"no",
"button",
"should",
"be",
"rendered",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/View/Contao2BackendView/ActionHandler/AbstractListShowAllHandler.php#L571-L611 | train |
contao-community-alliance/dc-general | src/Contao/View/Contao2BackendView/ActionHandler/AbstractListShowAllHandler.php | AbstractListShowAllHandler.getSortingColumns | private function getSortingColumns($sortingDefinition)
{
if (null === $sortingDefinition) {
return [];
}
$sortingColumns = [];
/** @var GroupAndSortingDefinitionInterface $sortingDefinition */
foreach ($sortingDefinition as $information) {
/** @var GroupAndSortingInformationInterface $information */
if ($information->getProperty()) {
$sortingColumns[] = $information->getProperty();
}
}
return $sortingColumns;
} | php | private function getSortingColumns($sortingDefinition)
{
if (null === $sortingDefinition) {
return [];
}
$sortingColumns = [];
/** @var GroupAndSortingDefinitionInterface $sortingDefinition */
foreach ($sortingDefinition as $information) {
/** @var GroupAndSortingInformationInterface $information */
if ($information->getProperty()) {
$sortingColumns[] = $information->getProperty();
}
}
return $sortingColumns;
} | [
"private",
"function",
"getSortingColumns",
"(",
"$",
"sortingDefinition",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"sortingDefinition",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"sortingColumns",
"=",
"[",
"]",
";",
"/** @var GroupAndSortingDefinitionInterface $sortingDefinition */",
"foreach",
"(",
"$",
"sortingDefinition",
"as",
"$",
"information",
")",
"{",
"/** @var GroupAndSortingInformationInterface $information */",
"if",
"(",
"$",
"information",
"->",
"getProperty",
"(",
")",
")",
"{",
"$",
"sortingColumns",
"[",
"]",
"=",
"$",
"information",
"->",
"getProperty",
"(",
")",
";",
"}",
"}",
"return",
"$",
"sortingColumns",
";",
"}"
]
| Determine the current sorting columns.
@param GroupAndSortingDefinitionInterface|null $sortingDefinition The sorting definition.
@return array | [
"Determine",
"the",
"current",
"sorting",
"columns",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/View/Contao2BackendView/ActionHandler/AbstractListShowAllHandler.php#L647-L663 | train |
contao-community-alliance/dc-general | src/Contao/Event/Subscriber.php | Subscriber.getPanelElementTemplate | public function getPanelElementTemplate(GetPanelElementTemplateEvent $event)
{
if (!$this->scopeDeterminator->currentScopeIsBackend()) {
return;
}
if ($event->getTemplate()) {
return;
}
$element = $event->getElement();
if ($element instanceof FilterElementInterface) {
$event->setTemplate(new ContaoBackendViewTemplate('dcbe_general_panel_filter'));
} elseif ($element instanceof LimitElementInterface) {
$event->setTemplate(new ContaoBackendViewTemplate('dcbe_general_panel_limit'));
} elseif ($element instanceof SearchElementInterface) {
$event->setTemplate(new ContaoBackendViewTemplate('dcbe_general_panel_search'));
} elseif ($element instanceof SortElementInterface) {
$event->setTemplate(new ContaoBackendViewTemplate('dcbe_general_panel_sort'));
} elseif ($element instanceof SubmitElementInterface) {
$event->setTemplate(new ContaoBackendViewTemplate('dcbe_general_panel_submit'));
}
} | php | public function getPanelElementTemplate(GetPanelElementTemplateEvent $event)
{
if (!$this->scopeDeterminator->currentScopeIsBackend()) {
return;
}
if ($event->getTemplate()) {
return;
}
$element = $event->getElement();
if ($element instanceof FilterElementInterface) {
$event->setTemplate(new ContaoBackendViewTemplate('dcbe_general_panel_filter'));
} elseif ($element instanceof LimitElementInterface) {
$event->setTemplate(new ContaoBackendViewTemplate('dcbe_general_panel_limit'));
} elseif ($element instanceof SearchElementInterface) {
$event->setTemplate(new ContaoBackendViewTemplate('dcbe_general_panel_search'));
} elseif ($element instanceof SortElementInterface) {
$event->setTemplate(new ContaoBackendViewTemplate('dcbe_general_panel_sort'));
} elseif ($element instanceof SubmitElementInterface) {
$event->setTemplate(new ContaoBackendViewTemplate('dcbe_general_panel_submit'));
}
} | [
"public",
"function",
"getPanelElementTemplate",
"(",
"GetPanelElementTemplateEvent",
"$",
"event",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"scopeDeterminator",
"->",
"currentScopeIsBackend",
"(",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"$",
"event",
"->",
"getTemplate",
"(",
")",
")",
"{",
"return",
";",
"}",
"$",
"element",
"=",
"$",
"event",
"->",
"getElement",
"(",
")",
";",
"if",
"(",
"$",
"element",
"instanceof",
"FilterElementInterface",
")",
"{",
"$",
"event",
"->",
"setTemplate",
"(",
"new",
"ContaoBackendViewTemplate",
"(",
"'dcbe_general_panel_filter'",
")",
")",
";",
"}",
"elseif",
"(",
"$",
"element",
"instanceof",
"LimitElementInterface",
")",
"{",
"$",
"event",
"->",
"setTemplate",
"(",
"new",
"ContaoBackendViewTemplate",
"(",
"'dcbe_general_panel_limit'",
")",
")",
";",
"}",
"elseif",
"(",
"$",
"element",
"instanceof",
"SearchElementInterface",
")",
"{",
"$",
"event",
"->",
"setTemplate",
"(",
"new",
"ContaoBackendViewTemplate",
"(",
"'dcbe_general_panel_search'",
")",
")",
";",
"}",
"elseif",
"(",
"$",
"element",
"instanceof",
"SortElementInterface",
")",
"{",
"$",
"event",
"->",
"setTemplate",
"(",
"new",
"ContaoBackendViewTemplate",
"(",
"'dcbe_general_panel_sort'",
")",
")",
";",
"}",
"elseif",
"(",
"$",
"element",
"instanceof",
"SubmitElementInterface",
")",
"{",
"$",
"event",
"->",
"setTemplate",
"(",
"new",
"ContaoBackendViewTemplate",
"(",
"'dcbe_general_panel_submit'",
")",
")",
";",
"}",
"}"
]
| Create a template instance for the default panel elements if none has been created yet.
@param GetPanelElementTemplateEvent $event The event.
@return void | [
"Create",
"a",
"template",
"instance",
"for",
"the",
"default",
"panel",
"elements",
"if",
"none",
"has",
"been",
"created",
"yet",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/Event/Subscriber.php#L105-L128 | train |
contao-community-alliance/dc-general | src/Contao/Event/Subscriber.php | Subscriber.resolveWidgetErrorMessage | public function resolveWidgetErrorMessage(ResolveWidgetErrorMessageEvent $event)
{
if (!$this->scopeDeterminator->currentScopeIsBackend()) {
return;
}
$error = $event->getError();
if ($error instanceof \Exception) {
$event->setError($error->getMessage());
} elseif (\is_object($error)) {
if (\method_exists($error, '__toString')) {
$event->setError((string) $error);
} else {
$event->setError(\sprintf('[%s]', \get_class($error)));
}
} elseif (!\is_string($error)) {
$event->setError(\sprintf('[%s]', \gettype($error)));
}
} | php | public function resolveWidgetErrorMessage(ResolveWidgetErrorMessageEvent $event)
{
if (!$this->scopeDeterminator->currentScopeIsBackend()) {
return;
}
$error = $event->getError();
if ($error instanceof \Exception) {
$event->setError($error->getMessage());
} elseif (\is_object($error)) {
if (\method_exists($error, '__toString')) {
$event->setError((string) $error);
} else {
$event->setError(\sprintf('[%s]', \get_class($error)));
}
} elseif (!\is_string($error)) {
$event->setError(\sprintf('[%s]', \gettype($error)));
}
} | [
"public",
"function",
"resolveWidgetErrorMessage",
"(",
"ResolveWidgetErrorMessageEvent",
"$",
"event",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"scopeDeterminator",
"->",
"currentScopeIsBackend",
"(",
")",
")",
"{",
"return",
";",
"}",
"$",
"error",
"=",
"$",
"event",
"->",
"getError",
"(",
")",
";",
"if",
"(",
"$",
"error",
"instanceof",
"\\",
"Exception",
")",
"{",
"$",
"event",
"->",
"setError",
"(",
"$",
"error",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"elseif",
"(",
"\\",
"is_object",
"(",
"$",
"error",
")",
")",
"{",
"if",
"(",
"\\",
"method_exists",
"(",
"$",
"error",
",",
"'__toString'",
")",
")",
"{",
"$",
"event",
"->",
"setError",
"(",
"(",
"string",
")",
"$",
"error",
")",
";",
"}",
"else",
"{",
"$",
"event",
"->",
"setError",
"(",
"\\",
"sprintf",
"(",
"'[%s]'",
",",
"\\",
"get_class",
"(",
"$",
"error",
")",
")",
")",
";",
"}",
"}",
"elseif",
"(",
"!",
"\\",
"is_string",
"(",
"$",
"error",
")",
")",
"{",
"$",
"event",
"->",
"setError",
"(",
"\\",
"sprintf",
"(",
"'[%s]'",
",",
"\\",
"gettype",
"(",
"$",
"error",
")",
")",
")",
";",
"}",
"}"
]
| Resolve a widget error message.
@param ResolveWidgetErrorMessageEvent $event The event being processed.
@return void | [
"Resolve",
"a",
"widget",
"error",
"message",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/Event/Subscriber.php#L137-L156 | train |
contao-community-alliance/dc-general | src/Contao/Event/Subscriber.php | Subscriber.getOptions | protected static function getOptions($environment, $model, $property)
{
$event = new GetPropertyOptionsEvent($environment, $model);
$event->setPropertyName($property->getName());
$event->setOptions($property->getOptions());
$environment->getEventDispatcher()->dispatch($event::NAME, $event);
return $event->getOptions();
} | php | protected static function getOptions($environment, $model, $property)
{
$event = new GetPropertyOptionsEvent($environment, $model);
$event->setPropertyName($property->getName());
$event->setOptions($property->getOptions());
$environment->getEventDispatcher()->dispatch($event::NAME, $event);
return $event->getOptions();
} | [
"protected",
"static",
"function",
"getOptions",
"(",
"$",
"environment",
",",
"$",
"model",
",",
"$",
"property",
")",
"{",
"$",
"event",
"=",
"new",
"GetPropertyOptionsEvent",
"(",
"$",
"environment",
",",
"$",
"model",
")",
";",
"$",
"event",
"->",
"setPropertyName",
"(",
"$",
"property",
"->",
"getName",
"(",
")",
")",
";",
"$",
"event",
"->",
"setOptions",
"(",
"$",
"property",
"->",
"getOptions",
"(",
")",
")",
";",
"$",
"environment",
"->",
"getEventDispatcher",
"(",
")",
"->",
"dispatch",
"(",
"$",
"event",
"::",
"NAME",
",",
"$",
"event",
")",
";",
"return",
"$",
"event",
"->",
"getOptions",
"(",
")",
";",
"}"
]
| Fetch the options for a certain property.
@param EnvironmentInterface $environment The environment.
@param ModelInterface $model The model.
@param PropertyInterface $property The property.
@return array | [
"Fetch",
"the",
"options",
"for",
"a",
"certain",
"property",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/Event/Subscriber.php#L167-L176 | train |
contao-community-alliance/dc-general | src/Contao/Event/Subscriber.php | Subscriber.decodeValue | private static function decodeValue($environment, $model, $property, $value)
{
$event = new DecodePropertyValueForWidgetEvent($environment, $model);
$event
->setProperty($property)
->setValue($value);
$environment->getEventDispatcher()->dispatch(\sprintf('%s', $event::NAME), $event);
return $event->getValue();
} | php | private static function decodeValue($environment, $model, $property, $value)
{
$event = new DecodePropertyValueForWidgetEvent($environment, $model);
$event
->setProperty($property)
->setValue($value);
$environment->getEventDispatcher()->dispatch(\sprintf('%s', $event::NAME), $event);
return $event->getValue();
} | [
"private",
"static",
"function",
"decodeValue",
"(",
"$",
"environment",
",",
"$",
"model",
",",
"$",
"property",
",",
"$",
"value",
")",
"{",
"$",
"event",
"=",
"new",
"DecodePropertyValueForWidgetEvent",
"(",
"$",
"environment",
",",
"$",
"model",
")",
";",
"$",
"event",
"->",
"setProperty",
"(",
"$",
"property",
")",
"->",
"setValue",
"(",
"$",
"value",
")",
";",
"$",
"environment",
"->",
"getEventDispatcher",
"(",
")",
"->",
"dispatch",
"(",
"\\",
"sprintf",
"(",
"'%s'",
",",
"$",
"event",
"::",
"NAME",
")",
",",
"$",
"event",
")",
";",
"return",
"$",
"event",
"->",
"getValue",
"(",
")",
";",
"}"
]
| Decode a value from native data of the data provider to the widget via event.
@param EnvironmentInterface $environment The environment.
@param ModelInterface $model The model.
@param string $property The property.
@param mixed $value The value of the property.
@return mixed | [
"Decode",
"a",
"value",
"from",
"native",
"data",
"of",
"the",
"data",
"provider",
"to",
"the",
"widget",
"via",
"event",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/Event/Subscriber.php#L188-L198 | train |
contao-community-alliance/dc-general | src/Contao/Event/Subscriber.php | Subscriber.parseDateTime | private static function parseDateTime(EventDispatcherInterface $dispatcher, $dateFormat, $timeStamp)
{
$dateEvent = new ParseDateEvent($timeStamp, $dateFormat);
$dispatcher->dispatch(ContaoEvents::DATE_PARSE, $dateEvent);
return $dateEvent->getResult();
} | php | private static function parseDateTime(EventDispatcherInterface $dispatcher, $dateFormat, $timeStamp)
{
$dateEvent = new ParseDateEvent($timeStamp, $dateFormat);
$dispatcher->dispatch(ContaoEvents::DATE_PARSE, $dateEvent);
return $dateEvent->getResult();
} | [
"private",
"static",
"function",
"parseDateTime",
"(",
"EventDispatcherInterface",
"$",
"dispatcher",
",",
"$",
"dateFormat",
",",
"$",
"timeStamp",
")",
"{",
"$",
"dateEvent",
"=",
"new",
"ParseDateEvent",
"(",
"$",
"timeStamp",
",",
"$",
"dateFormat",
")",
";",
"$",
"dispatcher",
"->",
"dispatch",
"(",
"ContaoEvents",
"::",
"DATE_PARSE",
",",
"$",
"dateEvent",
")",
";",
"return",
"$",
"dateEvent",
"->",
"getResult",
"(",
")",
";",
"}"
]
| Render a timestamp using the given format.
@param EventDispatcherInterface $dispatcher The Event dispatcher.
@param string $dateFormat The date format to use.
@param int $timeStamp The timestamp.
@return string | [
"Render",
"a",
"timestamp",
"using",
"the",
"given",
"format",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/Event/Subscriber.php#L209-L215 | train |
contao-community-alliance/dc-general | src/Contao/Event/Subscriber.php | Subscriber.renderReadablePropertyValue | public function renderReadablePropertyValue(RenderReadablePropertyValueEvent $event)
{
if (!$this->scopeDeterminator->currentScopeIsBackend()) {
return;
}
if (null !== $event->getRendered()) {
return;
}
$property = $event->getProperty();
$value = self::decodeValue(
$event->getEnvironment(),
$event->getModel(),
$event->getProperty()->getName(),
$event->getValue()
);
$extra = $property->getExtra();
self::renderForeignKeyReadable($event, $extra, $value);
self::renderArrayReadable($event, $value);
self::renderTimestampReadable($event, $extra, $value);
self::renderDateTimePropertyIsTstamp($event, $property, $value);
self::renderSimpleCheckbox($event, $property, $extra, $value);
self::renderTextAreaReadable($event, $property, $extra, $value);
self::renderReferenceReadable($event, $extra, $value);
if (null !== $event->getRendered()) {
return;
}
self::renderDateTimeValueInstance($event, $value);
self::renderOptionValueReadable($event, $property, $value);
} | php | public function renderReadablePropertyValue(RenderReadablePropertyValueEvent $event)
{
if (!$this->scopeDeterminator->currentScopeIsBackend()) {
return;
}
if (null !== $event->getRendered()) {
return;
}
$property = $event->getProperty();
$value = self::decodeValue(
$event->getEnvironment(),
$event->getModel(),
$event->getProperty()->getName(),
$event->getValue()
);
$extra = $property->getExtra();
self::renderForeignKeyReadable($event, $extra, $value);
self::renderArrayReadable($event, $value);
self::renderTimestampReadable($event, $extra, $value);
self::renderDateTimePropertyIsTstamp($event, $property, $value);
self::renderSimpleCheckbox($event, $property, $extra, $value);
self::renderTextAreaReadable($event, $property, $extra, $value);
self::renderReferenceReadable($event, $extra, $value);
if (null !== $event->getRendered()) {
return;
}
self::renderDateTimeValueInstance($event, $value);
self::renderOptionValueReadable($event, $property, $value);
} | [
"public",
"function",
"renderReadablePropertyValue",
"(",
"RenderReadablePropertyValueEvent",
"$",
"event",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"scopeDeterminator",
"->",
"currentScopeIsBackend",
"(",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"null",
"!==",
"$",
"event",
"->",
"getRendered",
"(",
")",
")",
"{",
"return",
";",
"}",
"$",
"property",
"=",
"$",
"event",
"->",
"getProperty",
"(",
")",
";",
"$",
"value",
"=",
"self",
"::",
"decodeValue",
"(",
"$",
"event",
"->",
"getEnvironment",
"(",
")",
",",
"$",
"event",
"->",
"getModel",
"(",
")",
",",
"$",
"event",
"->",
"getProperty",
"(",
")",
"->",
"getName",
"(",
")",
",",
"$",
"event",
"->",
"getValue",
"(",
")",
")",
";",
"$",
"extra",
"=",
"$",
"property",
"->",
"getExtra",
"(",
")",
";",
"self",
"::",
"renderForeignKeyReadable",
"(",
"$",
"event",
",",
"$",
"extra",
",",
"$",
"value",
")",
";",
"self",
"::",
"renderArrayReadable",
"(",
"$",
"event",
",",
"$",
"value",
")",
";",
"self",
"::",
"renderTimestampReadable",
"(",
"$",
"event",
",",
"$",
"extra",
",",
"$",
"value",
")",
";",
"self",
"::",
"renderDateTimePropertyIsTstamp",
"(",
"$",
"event",
",",
"$",
"property",
",",
"$",
"value",
")",
";",
"self",
"::",
"renderSimpleCheckbox",
"(",
"$",
"event",
",",
"$",
"property",
",",
"$",
"extra",
",",
"$",
"value",
")",
";",
"self",
"::",
"renderTextAreaReadable",
"(",
"$",
"event",
",",
"$",
"property",
",",
"$",
"extra",
",",
"$",
"value",
")",
";",
"self",
"::",
"renderReferenceReadable",
"(",
"$",
"event",
",",
"$",
"extra",
",",
"$",
"value",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"event",
"->",
"getRendered",
"(",
")",
")",
"{",
"return",
";",
"}",
"self",
"::",
"renderDateTimeValueInstance",
"(",
"$",
"event",
",",
"$",
"value",
")",
";",
"self",
"::",
"renderOptionValueReadable",
"(",
"$",
"event",
",",
"$",
"property",
",",
"$",
"value",
")",
";",
"}"
]
| Render a property value to readable text.
@param RenderReadablePropertyValueEvent $event The event being processed.
@return void | [
"Render",
"a",
"property",
"value",
"to",
"readable",
"text",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/Event/Subscriber.php#L224-L258 | train |
contao-community-alliance/dc-general | src/Contao/Event/Subscriber.php | Subscriber.initTwig | public function initTwig(\ContaoTwigInitializeEvent $event)
{
if (!$this->scopeDeterminator->currentScopeIsBackend()) {
return;
}
$contaoTwig = $event->getContaoTwig();
$environment = $contaoTwig->getEnvironment();
$environment->addExtension(new DcGeneralExtension());
} | php | public function initTwig(\ContaoTwigInitializeEvent $event)
{
if (!$this->scopeDeterminator->currentScopeIsBackend()) {
return;
}
$contaoTwig = $event->getContaoTwig();
$environment = $contaoTwig->getEnvironment();
$environment->addExtension(new DcGeneralExtension());
} | [
"public",
"function",
"initTwig",
"(",
"\\",
"ContaoTwigInitializeEvent",
"$",
"event",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"scopeDeterminator",
"->",
"currentScopeIsBackend",
"(",
")",
")",
"{",
"return",
";",
"}",
"$",
"contaoTwig",
"=",
"$",
"event",
"->",
"getContaoTwig",
"(",
")",
";",
"$",
"environment",
"=",
"$",
"contaoTwig",
"->",
"getEnvironment",
"(",
")",
";",
"$",
"environment",
"->",
"addExtension",
"(",
"new",
"DcGeneralExtension",
"(",
")",
")",
";",
"}"
]
| Add custom twig extension.
@param \ContaoTwigInitializeEvent $event The event.
@return void | [
"Add",
"custom",
"twig",
"extension",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/Event/Subscriber.php#L267-L277 | train |
contao-community-alliance/dc-general | src/Contao/Event/Subscriber.php | Subscriber.initializePanels | public function initializePanels(ActionEvent $event)
{
if (!$this->scopeDeterminator->currentScopeIsBackend()) {
return;
}
if (!\in_array(
$event->getAction()->getName(),
['copy', 'create', 'paste', 'delete', 'move', 'undo', 'edit', 'toggle', 'showAll', 'show']
)
) {
return;
}
$environment = $event->getEnvironment();
$definition = $environment->getDataDefinition();
$view = $environment->getView();
if (!$view instanceof BaseView
|| !$view->getPanel()
|| !$definition->hasDefinition(Contao2BackendViewDefinitionInterface::NAME)
) {
return;
}
/** @var Contao2BackendViewDefinitionInterface $backendDefinition */
$backendDefinition = $definition->getDefinition(Contao2BackendViewDefinitionInterface::NAME);
$listingConfig = $backendDefinition->getListingConfig();
$dataConfig = $environment->getBaseConfigRegistry()->getBaseConfig();
$panel = $view->getPanel();
ViewHelpers::initializeSorting($panel, $dataConfig, $listingConfig);
} | php | public function initializePanels(ActionEvent $event)
{
if (!$this->scopeDeterminator->currentScopeIsBackend()) {
return;
}
if (!\in_array(
$event->getAction()->getName(),
['copy', 'create', 'paste', 'delete', 'move', 'undo', 'edit', 'toggle', 'showAll', 'show']
)
) {
return;
}
$environment = $event->getEnvironment();
$definition = $environment->getDataDefinition();
$view = $environment->getView();
if (!$view instanceof BaseView
|| !$view->getPanel()
|| !$definition->hasDefinition(Contao2BackendViewDefinitionInterface::NAME)
) {
return;
}
/** @var Contao2BackendViewDefinitionInterface $backendDefinition */
$backendDefinition = $definition->getDefinition(Contao2BackendViewDefinitionInterface::NAME);
$listingConfig = $backendDefinition->getListingConfig();
$dataConfig = $environment->getBaseConfigRegistry()->getBaseConfig();
$panel = $view->getPanel();
ViewHelpers::initializeSorting($panel, $dataConfig, $listingConfig);
} | [
"public",
"function",
"initializePanels",
"(",
"ActionEvent",
"$",
"event",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"scopeDeterminator",
"->",
"currentScopeIsBackend",
"(",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"\\",
"in_array",
"(",
"$",
"event",
"->",
"getAction",
"(",
")",
"->",
"getName",
"(",
")",
",",
"[",
"'copy'",
",",
"'create'",
",",
"'paste'",
",",
"'delete'",
",",
"'move'",
",",
"'undo'",
",",
"'edit'",
",",
"'toggle'",
",",
"'showAll'",
",",
"'show'",
"]",
")",
")",
"{",
"return",
";",
"}",
"$",
"environment",
"=",
"$",
"event",
"->",
"getEnvironment",
"(",
")",
";",
"$",
"definition",
"=",
"$",
"environment",
"->",
"getDataDefinition",
"(",
")",
";",
"$",
"view",
"=",
"$",
"environment",
"->",
"getView",
"(",
")",
";",
"if",
"(",
"!",
"$",
"view",
"instanceof",
"BaseView",
"||",
"!",
"$",
"view",
"->",
"getPanel",
"(",
")",
"||",
"!",
"$",
"definition",
"->",
"hasDefinition",
"(",
"Contao2BackendViewDefinitionInterface",
"::",
"NAME",
")",
")",
"{",
"return",
";",
"}",
"/** @var Contao2BackendViewDefinitionInterface $backendDefinition */",
"$",
"backendDefinition",
"=",
"$",
"definition",
"->",
"getDefinition",
"(",
"Contao2BackendViewDefinitionInterface",
"::",
"NAME",
")",
";",
"$",
"listingConfig",
"=",
"$",
"backendDefinition",
"->",
"getListingConfig",
"(",
")",
";",
"$",
"dataConfig",
"=",
"$",
"environment",
"->",
"getBaseConfigRegistry",
"(",
")",
"->",
"getBaseConfig",
"(",
")",
";",
"$",
"panel",
"=",
"$",
"view",
"->",
"getPanel",
"(",
")",
";",
"ViewHelpers",
"::",
"initializeSorting",
"(",
"$",
"panel",
",",
"$",
"dataConfig",
",",
"$",
"listingConfig",
")",
";",
"}"
]
| Initialize the panels for known actions so that they always know their state.
@param ActionEvent $event The event.
@return void | [
"Initialize",
"the",
"panels",
"for",
"known",
"actions",
"so",
"that",
"they",
"always",
"know",
"their",
"state",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/Event/Subscriber.php#L286-L319 | train |
contao-community-alliance/dc-general | src/Contao/Event/Subscriber.php | Subscriber.renderForeignKeyReadable | private static function renderForeignKeyReadable(RenderReadablePropertyValueEvent $event, $extra, $value)
{
if (!isset($extra['foreignKey']) || (null !== $event->getRendered())) {
return;
}
// Not yet impl.
} | php | private static function renderForeignKeyReadable(RenderReadablePropertyValueEvent $event, $extra, $value)
{
if (!isset($extra['foreignKey']) || (null !== $event->getRendered())) {
return;
}
// Not yet impl.
} | [
"private",
"static",
"function",
"renderForeignKeyReadable",
"(",
"RenderReadablePropertyValueEvent",
"$",
"event",
",",
"$",
"extra",
",",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"extra",
"[",
"'foreignKey'",
"]",
")",
"||",
"(",
"null",
"!==",
"$",
"event",
"->",
"getRendered",
"(",
")",
")",
")",
"{",
"return",
";",
"}",
"// Not yet impl.",
"}"
]
| Render a foreign key reference.
@param RenderReadablePropertyValueEvent $event The event to store the value to.
@param array $extra The extra data from the property.
@param mixed $value The value to format.
@return void
@SuppressWarnings(PHPMD.UnusedFormalParameter) | [
"Render",
"a",
"foreign",
"key",
"reference",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/Event/Subscriber.php#L358-L365 | train |
contao-community-alliance/dc-general | src/Contao/Event/Subscriber.php | Subscriber.renderArrayReadable | private static function renderArrayReadable(RenderReadablePropertyValueEvent $event, $value)
{
if (!\is_array($value) || (null !== $event->getRendered())) {
return;
}
foreach ($value as $kk => $vv) {
if (\is_array($vv)) {
$vals = \array_values($vv);
$value[$kk] = $vals[0] . ' (' . $vals[1] . ')';
}
}
$event->setRendered(\implode(', ', $value));
} | php | private static function renderArrayReadable(RenderReadablePropertyValueEvent $event, $value)
{
if (!\is_array($value) || (null !== $event->getRendered())) {
return;
}
foreach ($value as $kk => $vv) {
if (\is_array($vv)) {
$vals = \array_values($vv);
$value[$kk] = $vals[0] . ' (' . $vals[1] . ')';
}
}
$event->setRendered(\implode(', ', $value));
} | [
"private",
"static",
"function",
"renderArrayReadable",
"(",
"RenderReadablePropertyValueEvent",
"$",
"event",
",",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"\\",
"is_array",
"(",
"$",
"value",
")",
"||",
"(",
"null",
"!==",
"$",
"event",
"->",
"getRendered",
"(",
")",
")",
")",
"{",
"return",
";",
"}",
"foreach",
"(",
"$",
"value",
"as",
"$",
"kk",
"=>",
"$",
"vv",
")",
"{",
"if",
"(",
"\\",
"is_array",
"(",
"$",
"vv",
")",
")",
"{",
"$",
"vals",
"=",
"\\",
"array_values",
"(",
"$",
"vv",
")",
";",
"$",
"value",
"[",
"$",
"kk",
"]",
"=",
"$",
"vals",
"[",
"0",
"]",
".",
"' ('",
".",
"$",
"vals",
"[",
"1",
"]",
".",
"')'",
";",
"}",
"}",
"$",
"event",
"->",
"setRendered",
"(",
"\\",
"implode",
"(",
"', '",
",",
"$",
"value",
")",
")",
";",
"}"
]
| Render an array as readable property value.
@param RenderReadablePropertyValueEvent $event The event to store the value to.
@param array $value The array to render.
@return void | [
"Render",
"an",
"array",
"as",
"readable",
"property",
"value",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/Event/Subscriber.php#L375-L389 | train |
contao-community-alliance/dc-general | src/Contao/Event/Subscriber.php | Subscriber.renderTimestampReadable | private static function renderTimestampReadable(RenderReadablePropertyValueEvent $event, $extra, $value)
{
if (!isset($extra['rgxp'])
|| !(('date' === $extra['rgxp']) || ('time' === $extra['rgxp']) || ('datim' === $extra['rgxp']))
|| (null !== $event->getRendered())) {
return;
}
$dispatcher = $event->getEnvironment()->getEventDispatcher();
$event->setRendered(
self::parseDateTime($dispatcher, self::getConfig()->get($extra['rgxp'] . 'Format'), $value)
);
} | php | private static function renderTimestampReadable(RenderReadablePropertyValueEvent $event, $extra, $value)
{
if (!isset($extra['rgxp'])
|| !(('date' === $extra['rgxp']) || ('time' === $extra['rgxp']) || ('datim' === $extra['rgxp']))
|| (null !== $event->getRendered())) {
return;
}
$dispatcher = $event->getEnvironment()->getEventDispatcher();
$event->setRendered(
self::parseDateTime($dispatcher, self::getConfig()->get($extra['rgxp'] . 'Format'), $value)
);
} | [
"private",
"static",
"function",
"renderTimestampReadable",
"(",
"RenderReadablePropertyValueEvent",
"$",
"event",
",",
"$",
"extra",
",",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"extra",
"[",
"'rgxp'",
"]",
")",
"||",
"!",
"(",
"(",
"'date'",
"===",
"$",
"extra",
"[",
"'rgxp'",
"]",
")",
"||",
"(",
"'time'",
"===",
"$",
"extra",
"[",
"'rgxp'",
"]",
")",
"||",
"(",
"'datim'",
"===",
"$",
"extra",
"[",
"'rgxp'",
"]",
")",
")",
"||",
"(",
"null",
"!==",
"$",
"event",
"->",
"getRendered",
"(",
")",
")",
")",
"{",
"return",
";",
"}",
"$",
"dispatcher",
"=",
"$",
"event",
"->",
"getEnvironment",
"(",
")",
"->",
"getEventDispatcher",
"(",
")",
";",
"$",
"event",
"->",
"setRendered",
"(",
"self",
"::",
"parseDateTime",
"(",
"$",
"dispatcher",
",",
"self",
"::",
"getConfig",
"(",
")",
"->",
"get",
"(",
"$",
"extra",
"[",
"'rgxp'",
"]",
".",
"'Format'",
")",
",",
"$",
"value",
")",
")",
";",
"}"
]
| Render a timestamp.
@param RenderReadablePropertyValueEvent $event The event to store the value to.
@param array $extra The extra data from the property.
@param int $value The value to format.
@return void | [
"Render",
"a",
"timestamp",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/Event/Subscriber.php#L400-L413 | train |
contao-community-alliance/dc-general | src/Contao/Event/Subscriber.php | Subscriber.renderDateTimePropertyIsTstamp | private static function renderDateTimePropertyIsTstamp(RenderReadablePropertyValueEvent $event, $property, $value)
{
if ((null !== $event->getRendered()) || ('tstamp' !== $property->getName())) {
return;
}
$dispatcher = $event->getEnvironment()->getEventDispatcher();
// Date and time format.
$event->setRendered(self::parseDateTime($dispatcher, self::getConfig()->get('timeFormat'), $value));
} | php | private static function renderDateTimePropertyIsTstamp(RenderReadablePropertyValueEvent $event, $property, $value)
{
if ((null !== $event->getRendered()) || ('tstamp' !== $property->getName())) {
return;
}
$dispatcher = $event->getEnvironment()->getEventDispatcher();
// Date and time format.
$event->setRendered(self::parseDateTime($dispatcher, self::getConfig()->get('timeFormat'), $value));
} | [
"private",
"static",
"function",
"renderDateTimePropertyIsTstamp",
"(",
"RenderReadablePropertyValueEvent",
"$",
"event",
",",
"$",
"property",
",",
"$",
"value",
")",
"{",
"if",
"(",
"(",
"null",
"!==",
"$",
"event",
"->",
"getRendered",
"(",
")",
")",
"||",
"(",
"'tstamp'",
"!==",
"$",
"property",
"->",
"getName",
"(",
")",
")",
")",
"{",
"return",
";",
"}",
"$",
"dispatcher",
"=",
"$",
"event",
"->",
"getEnvironment",
"(",
")",
"->",
"getEventDispatcher",
"(",
")",
";",
"// Date and time format.",
"$",
"event",
"->",
"setRendered",
"(",
"self",
"::",
"parseDateTime",
"(",
"$",
"dispatcher",
",",
"self",
"::",
"getConfig",
"(",
")",
"->",
"get",
"(",
"'timeFormat'",
")",
",",
"$",
"value",
")",
")",
";",
"}"
]
| Render date time when property is tstamp.
@param RenderReadablePropertyValueEvent $event The event to store the value to.
@param PropertyInterface $property The property for render it.
@param int $value The value to format.
@return void | [
"Render",
"date",
"time",
"when",
"property",
"is",
"tstamp",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/Event/Subscriber.php#L424-L434 | train |
contao-community-alliance/dc-general | src/Contao/Event/Subscriber.php | Subscriber.renderSimpleCheckbox | private static function renderSimpleCheckbox(RenderReadablePropertyValueEvent $event, $property, $extra, $value)
{
if ((null !== $event->getRendered())
|| !(!$extra['multiple'] && ('checkbox' === $property->getWidgetType()))
) {
return;
}
$map = [false => 'no', true => 'yes'];
$event->setRendered($event->getEnvironment()->getTranslator()->translate('MSC.' . $map[(bool) $value]));
} | php | private static function renderSimpleCheckbox(RenderReadablePropertyValueEvent $event, $property, $extra, $value)
{
if ((null !== $event->getRendered())
|| !(!$extra['multiple'] && ('checkbox' === $property->getWidgetType()))
) {
return;
}
$map = [false => 'no', true => 'yes'];
$event->setRendered($event->getEnvironment()->getTranslator()->translate('MSC.' . $map[(bool) $value]));
} | [
"private",
"static",
"function",
"renderSimpleCheckbox",
"(",
"RenderReadablePropertyValueEvent",
"$",
"event",
",",
"$",
"property",
",",
"$",
"extra",
",",
"$",
"value",
")",
"{",
"if",
"(",
"(",
"null",
"!==",
"$",
"event",
"->",
"getRendered",
"(",
")",
")",
"||",
"!",
"(",
"!",
"$",
"extra",
"[",
"'multiple'",
"]",
"&&",
"(",
"'checkbox'",
"===",
"$",
"property",
"->",
"getWidgetType",
"(",
")",
")",
")",
")",
"{",
"return",
";",
"}",
"$",
"map",
"=",
"[",
"false",
"=>",
"'no'",
",",
"true",
"=>",
"'yes'",
"]",
";",
"$",
"event",
"->",
"setRendered",
"(",
"$",
"event",
"->",
"getEnvironment",
"(",
")",
"->",
"getTranslator",
"(",
")",
"->",
"translate",
"(",
"'MSC.'",
".",
"$",
"map",
"[",
"(",
"bool",
")",
"$",
"value",
"]",
")",
")",
";",
"}"
]
| Render for simple checkobx
@param RenderReadablePropertyValueEvent $event The event to store the value to.
@param PropertyInterface $property The property for render it.
@param array $extra The extra data from the property.
@param int $value The value to format.
@return void | [
"Render",
"for",
"simple",
"checkobx"
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/Event/Subscriber.php#L446-L457 | train |
contao-community-alliance/dc-general | src/Contao/Event/Subscriber.php | Subscriber.renderDateTimeValueInstance | private static function renderDateTimeValueInstance($event, $value)
{
if (!($value instanceof \DateTime)) {
return;
}
$dispatcher = $event->getEnvironment()->getEventDispatcher();
$event->setRendered(
self::parseDateTime($dispatcher, self::getConfig()->get('datimFormat'), $value->getTimestamp())
);
} | php | private static function renderDateTimeValueInstance($event, $value)
{
if (!($value instanceof \DateTime)) {
return;
}
$dispatcher = $event->getEnvironment()->getEventDispatcher();
$event->setRendered(
self::parseDateTime($dispatcher, self::getConfig()->get('datimFormat'), $value->getTimestamp())
);
} | [
"private",
"static",
"function",
"renderDateTimeValueInstance",
"(",
"$",
"event",
",",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"(",
"$",
"value",
"instanceof",
"\\",
"DateTime",
")",
")",
"{",
"return",
";",
"}",
"$",
"dispatcher",
"=",
"$",
"event",
"->",
"getEnvironment",
"(",
")",
"->",
"getEventDispatcher",
"(",
")",
";",
"$",
"event",
"->",
"setRendered",
"(",
"self",
"::",
"parseDateTime",
"(",
"$",
"dispatcher",
",",
"self",
"::",
"getConfig",
"(",
")",
"->",
"get",
"(",
"'datimFormat'",
")",
",",
"$",
"value",
"->",
"getTimestamp",
"(",
")",
")",
")",
";",
"}"
]
| Render datetime if the value is instance of datetime .
@param RenderReadablePropertyValueEvent $event The event to store the value to.
@param int $value The value to format.
@return void | [
"Render",
"datetime",
"if",
"the",
"value",
"is",
"instance",
"of",
"datetime",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/Event/Subscriber.php#L467-L478 | train |
contao-community-alliance/dc-general | src/Contao/Event/Subscriber.php | Subscriber.renderTextAreaReadable | private static function renderTextAreaReadable(RenderReadablePropertyValueEvent $event, $property, $extra, $value)
{
if ((empty($extra['allowHtml']) && empty($extra['preserveTags']))
|| (null !== $event->getRendered())
|| ('textarea' !== $property->getWidgetType())) {
return;
}
$event->setRendered(\nl2br_html5(StringUtil::specialchars($value)));
} | php | private static function renderTextAreaReadable(RenderReadablePropertyValueEvent $event, $property, $extra, $value)
{
if ((empty($extra['allowHtml']) && empty($extra['preserveTags']))
|| (null !== $event->getRendered())
|| ('textarea' !== $property->getWidgetType())) {
return;
}
$event->setRendered(\nl2br_html5(StringUtil::specialchars($value)));
} | [
"private",
"static",
"function",
"renderTextAreaReadable",
"(",
"RenderReadablePropertyValueEvent",
"$",
"event",
",",
"$",
"property",
",",
"$",
"extra",
",",
"$",
"value",
")",
"{",
"if",
"(",
"(",
"empty",
"(",
"$",
"extra",
"[",
"'allowHtml'",
"]",
")",
"&&",
"empty",
"(",
"$",
"extra",
"[",
"'preserveTags'",
"]",
")",
")",
"||",
"(",
"null",
"!==",
"$",
"event",
"->",
"getRendered",
"(",
")",
")",
"||",
"(",
"'textarea'",
"!==",
"$",
"property",
"->",
"getWidgetType",
"(",
")",
")",
")",
"{",
"return",
";",
"}",
"$",
"event",
"->",
"setRendered",
"(",
"\\",
"nl2br_html5",
"(",
"StringUtil",
"::",
"specialchars",
"(",
"$",
"value",
")",
")",
")",
";",
"}"
]
| Render a string if not allow html or preserve tags is given.
@param RenderReadablePropertyValueEvent $event The event to store the value to.
@param PropertyInterface $property The property for render it.
@param array $extra The extra data from the property.
@param string $value The value to format.
@return void | [
"Render",
"a",
"string",
"if",
"not",
"allow",
"html",
"or",
"preserve",
"tags",
"is",
"given",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/Event/Subscriber.php#L516-L525 | train |
contao-community-alliance/dc-general | src/Contao/Event/Subscriber.php | Subscriber.renderOptionValueReadable | private static function renderOptionValueReadable(RenderReadablePropertyValueEvent $event, $property, $value)
{
if (!($options = $property->getOptions())) {
$options = self::getOptions($event->getEnvironment(), $event->getModel(), $event->getProperty());
if ($options) {
$property->setOptions($options);
}
}
if (\array_is_assoc($options)) {
$event->setRendered($options[$value]);
}
} | php | private static function renderOptionValueReadable(RenderReadablePropertyValueEvent $event, $property, $value)
{
if (!($options = $property->getOptions())) {
$options = self::getOptions($event->getEnvironment(), $event->getModel(), $event->getProperty());
if ($options) {
$property->setOptions($options);
}
}
if (\array_is_assoc($options)) {
$event->setRendered($options[$value]);
}
} | [
"private",
"static",
"function",
"renderOptionValueReadable",
"(",
"RenderReadablePropertyValueEvent",
"$",
"event",
",",
"$",
"property",
",",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"(",
"$",
"options",
"=",
"$",
"property",
"->",
"getOptions",
"(",
")",
")",
")",
"{",
"$",
"options",
"=",
"self",
"::",
"getOptions",
"(",
"$",
"event",
"->",
"getEnvironment",
"(",
")",
",",
"$",
"event",
"->",
"getModel",
"(",
")",
",",
"$",
"event",
"->",
"getProperty",
"(",
")",
")",
";",
"if",
"(",
"$",
"options",
")",
"{",
"$",
"property",
"->",
"setOptions",
"(",
"$",
"options",
")",
";",
"}",
"}",
"if",
"(",
"\\",
"array_is_assoc",
"(",
"$",
"options",
")",
")",
"{",
"$",
"event",
"->",
"setRendered",
"(",
"$",
"options",
"[",
"$",
"value",
"]",
")",
";",
"}",
"}"
]
| Render a property option.
@param RenderReadablePropertyValueEvent $event The event to store the value to.
@param PropertyInterface $property The property holding the options.
@param mixed $value The value to format.
@return void | [
"Render",
"a",
"property",
"option",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/Event/Subscriber.php#L536-L548 | train |
contao-community-alliance/dc-general | src/Event/ActionEvent.php | ActionEvent.setResponse | public function setResponse($response)
{
$this->response = (null !== $response) ? (string) $response : null;
return $this;
} | php | public function setResponse($response)
{
$this->response = (null !== $response) ? (string) $response : null;
return $this;
} | [
"public",
"function",
"setResponse",
"(",
"$",
"response",
")",
"{",
"$",
"this",
"->",
"response",
"=",
"(",
"null",
"!==",
"$",
"response",
")",
"?",
"(",
"string",
")",
"$",
"response",
":",
"null",
";",
"return",
"$",
"this",
";",
"}"
]
| Set the action response.
@param string $response The response.
@return ActionEvent | [
"Set",
"the",
"action",
"response",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Event/ActionEvent.php#L43-L47 | train |
yiisoft/cache | src/FileCache.php | FileCache.setCachePath | public function setCachePath(string $cachePath)
{
$this->cachePath = $cachePath;
if (!is_dir($this->cachePath)) {
FileHelper::createDirectory($this->cachePath, $this->dirMode, true);
}
} | php | public function setCachePath(string $cachePath)
{
$this->cachePath = $cachePath;
if (!is_dir($this->cachePath)) {
FileHelper::createDirectory($this->cachePath, $this->dirMode, true);
}
} | [
"public",
"function",
"setCachePath",
"(",
"string",
"$",
"cachePath",
")",
"{",
"$",
"this",
"->",
"cachePath",
"=",
"$",
"cachePath",
";",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"this",
"->",
"cachePath",
")",
")",
"{",
"FileHelper",
"::",
"createDirectory",
"(",
"$",
"this",
"->",
"cachePath",
",",
"$",
"this",
"->",
"dirMode",
",",
"true",
")",
";",
"}",
"}"
]
| Sets cache path and ensures it exists.
@param string $cachePath | [
"Sets",
"cache",
"path",
"and",
"ensures",
"it",
"exists",
"."
]
| d3ffe8436270481e34842705817a5cf8025d947f | https://github.com/yiisoft/cache/blob/d3ffe8436270481e34842705817a5cf8025d947f/src/FileCache.php#L91-L97 | train |
contao-community-alliance/dc-general | src/Data/DefaultModel.php | DefaultModel.getProperty | public function getProperty($propertyName)
{
if ('id' === $propertyName) {
return $this->getID();
}
if (\array_key_exists($propertyName, $this->arrProperties)) {
return $this->arrProperties[$propertyName];
}
return null;
} | php | public function getProperty($propertyName)
{
if ('id' === $propertyName) {
return $this->getID();
}
if (\array_key_exists($propertyName, $this->arrProperties)) {
return $this->arrProperties[$propertyName];
}
return null;
} | [
"public",
"function",
"getProperty",
"(",
"$",
"propertyName",
")",
"{",
"if",
"(",
"'id'",
"===",
"$",
"propertyName",
")",
"{",
"return",
"$",
"this",
"->",
"getID",
"(",
")",
";",
"}",
"if",
"(",
"\\",
"array_key_exists",
"(",
"$",
"propertyName",
",",
"$",
"this",
"->",
"arrProperties",
")",
")",
"{",
"return",
"$",
"this",
"->",
"arrProperties",
"[",
"$",
"propertyName",
"]",
";",
"}",
"return",
"null",
";",
"}"
]
| Fetch the property with the given name from the model.
This method returns null if an unknown property is retrieved.
@param string $propertyName The property name to be retrieved.
@return mixed The value of the given property. | [
"Fetch",
"the",
"property",
"with",
"the",
"given",
"name",
"from",
"the",
"model",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Data/DefaultModel.php#L86-L97 | train |
contao-community-alliance/dc-general | src/Data/DefaultModel.php | DefaultModel.setID | public function setID($mixID)
{
if (null === $this->mixID) {
$this->setIdRaw($mixID);
$this->setMeta(static::IS_CHANGED, true);
}
} | php | public function setID($mixID)
{
if (null === $this->mixID) {
$this->setIdRaw($mixID);
$this->setMeta(static::IS_CHANGED, true);
}
} | [
"public",
"function",
"setID",
"(",
"$",
"mixID",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"mixID",
")",
"{",
"$",
"this",
"->",
"setIdRaw",
"(",
"$",
"mixID",
")",
";",
"$",
"this",
"->",
"setMeta",
"(",
"static",
"::",
"IS_CHANGED",
",",
"true",
")",
";",
"}",
"}"
]
| Set the id for this object.
NOTE: when the Id has been set once to a non null value, it can NOT be changed anymore.
Normally this should only be called from inside of the implementing provider.
@param mixed $mixID Could be a integer, string or anything else - depends on the provider implementation.
@return void | [
"Set",
"the",
"id",
"for",
"this",
"object",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Data/DefaultModel.php#L120-L126 | train |
contao-community-alliance/dc-general | src/Data/DefaultModel.php | DefaultModel.setProperty | public function setProperty($propertyName, $value)
{
if ($value !== $this->getProperty($propertyName)) {
$this->setMeta(static::IS_CHANGED, true);
$this->setPropertyRaw($propertyName, $value);
}
} | php | public function setProperty($propertyName, $value)
{
if ($value !== $this->getProperty($propertyName)) {
$this->setMeta(static::IS_CHANGED, true);
$this->setPropertyRaw($propertyName, $value);
}
} | [
"public",
"function",
"setProperty",
"(",
"$",
"propertyName",
",",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
"!==",
"$",
"this",
"->",
"getProperty",
"(",
"$",
"propertyName",
")",
")",
"{",
"$",
"this",
"->",
"setMeta",
"(",
"static",
"::",
"IS_CHANGED",
",",
"true",
")",
";",
"$",
"this",
"->",
"setPropertyRaw",
"(",
"$",
"propertyName",
",",
"$",
"value",
")",
";",
"}",
"}"
]
| Update the property value in the model.
@param string $propertyName The property name to be set.
@param mixed $value The value to be set.
@return void | [
"Update",
"the",
"property",
"value",
"in",
"the",
"model",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Data/DefaultModel.php#L165-L171 | train |
contao-community-alliance/dc-general | src/Data/DefaultModel.php | DefaultModel.setPropertiesAsArray | public function setPropertiesAsArray($properties)
{
if (\is_array($properties)) {
if (\array_key_exists('id', $properties)) {
unset($properties['id']);
}
foreach ($properties as $propertyName => $value) {
$this->setProperty($propertyName, $value);
}
}
} | php | public function setPropertiesAsArray($properties)
{
if (\is_array($properties)) {
if (\array_key_exists('id', $properties)) {
unset($properties['id']);
}
foreach ($properties as $propertyName => $value) {
$this->setProperty($propertyName, $value);
}
}
} | [
"public",
"function",
"setPropertiesAsArray",
"(",
"$",
"properties",
")",
"{",
"if",
"(",
"\\",
"is_array",
"(",
"$",
"properties",
")",
")",
"{",
"if",
"(",
"\\",
"array_key_exists",
"(",
"'id'",
",",
"$",
"properties",
")",
")",
"{",
"unset",
"(",
"$",
"properties",
"[",
"'id'",
"]",
")",
";",
"}",
"foreach",
"(",
"$",
"properties",
"as",
"$",
"propertyName",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"setProperty",
"(",
"$",
"propertyName",
",",
"$",
"value",
")",
";",
"}",
"}",
"}"
]
| Update all properties in the model.
@param array $properties The property values as name => value pairs.
@return void | [
"Update",
"all",
"properties",
"in",
"the",
"model",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Data/DefaultModel.php#L180-L191 | train |
contao-community-alliance/dc-general | src/Contao/View/Contao2BackendView/ActionHandler/ParentedListViewShowAllHandler.php | ParentedListViewShowAllHandler.renderHeaderFields | private function renderHeaderFields($parentModel, EnvironmentInterface $environment)
{
$definition = $environment->getDataDefinition();
$parentName = $definition->getBasicDefinition()->getParentDataProvider();
$add = [];
$properties = $environment->getParentDataDefinition()->getPropertiesDefinition();
foreach ($this->getViewSection($definition)->getListingConfig()->getHeaderPropertyNames() as $field) {
$value = StringUtil::deserialize($parentModel->getProperty($field));
if ('tstamp' === $field) {
$value = date(Config::get('datimFormat'), $value);
} else {
$value = $this->renderParentProperty($environment, $properties->getProperty($field), $value);
}
// Add the field.
if ('' !== $value) {
$add[$this->translateHeaderColumnName($field, $parentName)] = $value;
}
}
$event = new GetParentHeaderEvent($environment, $parentModel);
$event->setAdditional($add);
$environment->getEventDispatcher()->dispatch(GetParentHeaderEvent::NAME, $event);
if (null !== !$event->getAdditional()) {
$add = $event->getAdditional();
}
return \array_map(
function ($value) {
if (\is_array($value)) {
return $value[0];
}
return $value;
},
$add
);
} | php | private function renderHeaderFields($parentModel, EnvironmentInterface $environment)
{
$definition = $environment->getDataDefinition();
$parentName = $definition->getBasicDefinition()->getParentDataProvider();
$add = [];
$properties = $environment->getParentDataDefinition()->getPropertiesDefinition();
foreach ($this->getViewSection($definition)->getListingConfig()->getHeaderPropertyNames() as $field) {
$value = StringUtil::deserialize($parentModel->getProperty($field));
if ('tstamp' === $field) {
$value = date(Config::get('datimFormat'), $value);
} else {
$value = $this->renderParentProperty($environment, $properties->getProperty($field), $value);
}
// Add the field.
if ('' !== $value) {
$add[$this->translateHeaderColumnName($field, $parentName)] = $value;
}
}
$event = new GetParentHeaderEvent($environment, $parentModel);
$event->setAdditional($add);
$environment->getEventDispatcher()->dispatch(GetParentHeaderEvent::NAME, $event);
if (null !== !$event->getAdditional()) {
$add = $event->getAdditional();
}
return \array_map(
function ($value) {
if (\is_array($value)) {
return $value[0];
}
return $value;
},
$add
);
} | [
"private",
"function",
"renderHeaderFields",
"(",
"$",
"parentModel",
",",
"EnvironmentInterface",
"$",
"environment",
")",
"{",
"$",
"definition",
"=",
"$",
"environment",
"->",
"getDataDefinition",
"(",
")",
";",
"$",
"parentName",
"=",
"$",
"definition",
"->",
"getBasicDefinition",
"(",
")",
"->",
"getParentDataProvider",
"(",
")",
";",
"$",
"add",
"=",
"[",
"]",
";",
"$",
"properties",
"=",
"$",
"environment",
"->",
"getParentDataDefinition",
"(",
")",
"->",
"getPropertiesDefinition",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"getViewSection",
"(",
"$",
"definition",
")",
"->",
"getListingConfig",
"(",
")",
"->",
"getHeaderPropertyNames",
"(",
")",
"as",
"$",
"field",
")",
"{",
"$",
"value",
"=",
"StringUtil",
"::",
"deserialize",
"(",
"$",
"parentModel",
"->",
"getProperty",
"(",
"$",
"field",
")",
")",
";",
"if",
"(",
"'tstamp'",
"===",
"$",
"field",
")",
"{",
"$",
"value",
"=",
"date",
"(",
"Config",
"::",
"get",
"(",
"'datimFormat'",
")",
",",
"$",
"value",
")",
";",
"}",
"else",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"renderParentProperty",
"(",
"$",
"environment",
",",
"$",
"properties",
"->",
"getProperty",
"(",
"$",
"field",
")",
",",
"$",
"value",
")",
";",
"}",
"// Add the field.",
"if",
"(",
"''",
"!==",
"$",
"value",
")",
"{",
"$",
"add",
"[",
"$",
"this",
"->",
"translateHeaderColumnName",
"(",
"$",
"field",
",",
"$",
"parentName",
")",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"$",
"event",
"=",
"new",
"GetParentHeaderEvent",
"(",
"$",
"environment",
",",
"$",
"parentModel",
")",
";",
"$",
"event",
"->",
"setAdditional",
"(",
"$",
"add",
")",
";",
"$",
"environment",
"->",
"getEventDispatcher",
"(",
")",
"->",
"dispatch",
"(",
"GetParentHeaderEvent",
"::",
"NAME",
",",
"$",
"event",
")",
";",
"if",
"(",
"null",
"!==",
"!",
"$",
"event",
"->",
"getAdditional",
"(",
")",
")",
"{",
"$",
"add",
"=",
"$",
"event",
"->",
"getAdditional",
"(",
")",
";",
"}",
"return",
"\\",
"array_map",
"(",
"function",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"\\",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"return",
"$",
"value",
"[",
"0",
"]",
";",
"}",
"return",
"$",
"value",
";",
"}",
",",
"$",
"add",
")",
";",
"}"
]
| Render the header of the parent view with information from the parent table.
@param ModelInterface $parentModel The parent model.
@param EnvironmentInterface $environment The environment.
@return array | [
"Render",
"the",
"header",
"of",
"the",
"parent",
"view",
"with",
"information",
"from",
"the",
"parent",
"table",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/View/Contao2BackendView/ActionHandler/ParentedListViewShowAllHandler.php#L153-L192 | train |
contao-community-alliance/dc-general | src/Contao/View/Contao2BackendView/ActionHandler/ParentedListViewShowAllHandler.php | ParentedListViewShowAllHandler.translateHeaderColumnName | private function translateHeaderColumnName($field, $parentName)
{
return ('tstamp' === $field)
? $this->translate('MSC.tstamp', 'contao_default')
: $this->translate(\sprintf('%s.0', $field), $parentName);
} | php | private function translateHeaderColumnName($field, $parentName)
{
return ('tstamp' === $field)
? $this->translate('MSC.tstamp', 'contao_default')
: $this->translate(\sprintf('%s.0', $field), $parentName);
} | [
"private",
"function",
"translateHeaderColumnName",
"(",
"$",
"field",
",",
"$",
"parentName",
")",
"{",
"return",
"(",
"'tstamp'",
"===",
"$",
"field",
")",
"?",
"$",
"this",
"->",
"translate",
"(",
"'MSC.tstamp'",
",",
"'contao_default'",
")",
":",
"$",
"this",
"->",
"translate",
"(",
"\\",
"sprintf",
"(",
"'%s.0'",
",",
"$",
"field",
")",
",",
"$",
"parentName",
")",
";",
"}"
]
| Translate a column name for use in parent model display section.
@param string $field The field name.
@param string $parentName The parent definition name.
@return array|string | [
"Translate",
"a",
"column",
"name",
"for",
"use",
"in",
"parent",
"model",
"display",
"section",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/View/Contao2BackendView/ActionHandler/ParentedListViewShowAllHandler.php#L202-L207 | train |
contao-community-alliance/dc-general | src/Contao/View/Contao2BackendView/ActionHandler/ParentedListViewShowAllHandler.php | ParentedListViewShowAllHandler.renderParentProperty | private function renderParentProperty(EnvironmentInterface $environment, $property, $value)
{
$evaluation = $property->getExtra();
if (\is_array($value)) {
return \implode(', ', $value);
}
$isRendered = false;
$value = $this->renderForCheckbox($property, $value, $isRendered);
$value = $this->renderForDateTime($environment, $property, $value, $isRendered);
$value = $this->renderReference($value, $evaluation['reference'], $isRendered);
$options = $property->getOptions();
if ($evaluation['isAssociative'] || \array_is_assoc($options)) {
$value = $options[$value];
}
return $value;
} | php | private function renderParentProperty(EnvironmentInterface $environment, $property, $value)
{
$evaluation = $property->getExtra();
if (\is_array($value)) {
return \implode(', ', $value);
}
$isRendered = false;
$value = $this->renderForCheckbox($property, $value, $isRendered);
$value = $this->renderForDateTime($environment, $property, $value, $isRendered);
$value = $this->renderReference($value, $evaluation['reference'], $isRendered);
$options = $property->getOptions();
if ($evaluation['isAssociative'] || \array_is_assoc($options)) {
$value = $options[$value];
}
return $value;
} | [
"private",
"function",
"renderParentProperty",
"(",
"EnvironmentInterface",
"$",
"environment",
",",
"$",
"property",
",",
"$",
"value",
")",
"{",
"$",
"evaluation",
"=",
"$",
"property",
"->",
"getExtra",
"(",
")",
";",
"if",
"(",
"\\",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"return",
"\\",
"implode",
"(",
"', '",
",",
"$",
"value",
")",
";",
"}",
"$",
"isRendered",
"=",
"false",
";",
"$",
"value",
"=",
"$",
"this",
"->",
"renderForCheckbox",
"(",
"$",
"property",
",",
"$",
"value",
",",
"$",
"isRendered",
")",
";",
"$",
"value",
"=",
"$",
"this",
"->",
"renderForDateTime",
"(",
"$",
"environment",
",",
"$",
"property",
",",
"$",
"value",
",",
"$",
"isRendered",
")",
";",
"$",
"value",
"=",
"$",
"this",
"->",
"renderReference",
"(",
"$",
"value",
",",
"$",
"evaluation",
"[",
"'reference'",
"]",
",",
"$",
"isRendered",
")",
";",
"$",
"options",
"=",
"$",
"property",
"->",
"getOptions",
"(",
")",
";",
"if",
"(",
"$",
"evaluation",
"[",
"'isAssociative'",
"]",
"||",
"\\",
"array_is_assoc",
"(",
"$",
"options",
")",
")",
"{",
"$",
"value",
"=",
"$",
"options",
"[",
"$",
"value",
"]",
";",
"}",
"return",
"$",
"value",
";",
"}"
]
| Render a property of the parent model.
@param EnvironmentInterface $environment The environment.
@param PropertyInterface $property The property.
@param mixed $value The value to format.
@return string | [
"Render",
"a",
"property",
"of",
"the",
"parent",
"model",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/View/Contao2BackendView/ActionHandler/ParentedListViewShowAllHandler.php#L218-L238 | train |
contao-community-alliance/dc-general | src/Contao/View/Contao2BackendView/ActionHandler/ParentedListViewShowAllHandler.php | ParentedListViewShowAllHandler.renderForCheckbox | private function renderForCheckbox(PropertyInterface $property, $value, &$isRendered)
{
$evaluation = $property->getExtra();
if ((true === $isRendered) || $evaluation['multiple'] || !('checkbox' === $property->getWidgetType())) {
return $value;
}
$isRendered = true;
return !empty($value)
? $this->translate('MSC.yes', 'contao_default')
: $this->translate('MSC.no', 'contao_default');
} | php | private function renderForCheckbox(PropertyInterface $property, $value, &$isRendered)
{
$evaluation = $property->getExtra();
if ((true === $isRendered) || $evaluation['multiple'] || !('checkbox' === $property->getWidgetType())) {
return $value;
}
$isRendered = true;
return !empty($value)
? $this->translate('MSC.yes', 'contao_default')
: $this->translate('MSC.no', 'contao_default');
} | [
"private",
"function",
"renderForCheckbox",
"(",
"PropertyInterface",
"$",
"property",
",",
"$",
"value",
",",
"&",
"$",
"isRendered",
")",
"{",
"$",
"evaluation",
"=",
"$",
"property",
"->",
"getExtra",
"(",
")",
";",
"if",
"(",
"(",
"true",
"===",
"$",
"isRendered",
")",
"||",
"$",
"evaluation",
"[",
"'multiple'",
"]",
"||",
"!",
"(",
"'checkbox'",
"===",
"$",
"property",
"->",
"getWidgetType",
"(",
")",
")",
")",
"{",
"return",
"$",
"value",
";",
"}",
"$",
"isRendered",
"=",
"true",
";",
"return",
"!",
"empty",
"(",
"$",
"value",
")",
"?",
"$",
"this",
"->",
"translate",
"(",
"'MSC.yes'",
",",
"'contao_default'",
")",
":",
"$",
"this",
"->",
"translate",
"(",
"'MSC.no'",
",",
"'contao_default'",
")",
";",
"}"
]
| Render for checkbox.
@param PropertyInterface $property The property.
@param mixed $value The value.
@param boolean $isRendered Determine if is rendered.
@return mixed | [
"Render",
"for",
"checkbox",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/View/Contao2BackendView/ActionHandler/ParentedListViewShowAllHandler.php#L249-L262 | train |
contao-community-alliance/dc-general | src/Contao/View/Contao2BackendView/ActionHandler/ParentedListViewShowAllHandler.php | ParentedListViewShowAllHandler.renderForDateTime | private function renderForDateTime(
EnvironmentInterface $environment,
PropertyInterface $property,
$value,
&$isRendered
) {
$evaluation = $property->getExtra();
if ((true === $isRendered) || !$value || !\in_array($evaluation['rgxp'], ['date', 'time', 'datim'])) {
return $value;
}
$isRendered = true;
$event = new ParseDateEvent($value, Config::get($evaluation['rgxp'] . 'Format'));
$environment->getEventDispatcher()->dispatch(ContaoEvents::DATE_PARSE, $event);
return $event->getResult();
} | php | private function renderForDateTime(
EnvironmentInterface $environment,
PropertyInterface $property,
$value,
&$isRendered
) {
$evaluation = $property->getExtra();
if ((true === $isRendered) || !$value || !\in_array($evaluation['rgxp'], ['date', 'time', 'datim'])) {
return $value;
}
$isRendered = true;
$event = new ParseDateEvent($value, Config::get($evaluation['rgxp'] . 'Format'));
$environment->getEventDispatcher()->dispatch(ContaoEvents::DATE_PARSE, $event);
return $event->getResult();
} | [
"private",
"function",
"renderForDateTime",
"(",
"EnvironmentInterface",
"$",
"environment",
",",
"PropertyInterface",
"$",
"property",
",",
"$",
"value",
",",
"&",
"$",
"isRendered",
")",
"{",
"$",
"evaluation",
"=",
"$",
"property",
"->",
"getExtra",
"(",
")",
";",
"if",
"(",
"(",
"true",
"===",
"$",
"isRendered",
")",
"||",
"!",
"$",
"value",
"||",
"!",
"\\",
"in_array",
"(",
"$",
"evaluation",
"[",
"'rgxp'",
"]",
",",
"[",
"'date'",
",",
"'time'",
",",
"'datim'",
"]",
")",
")",
"{",
"return",
"$",
"value",
";",
"}",
"$",
"isRendered",
"=",
"true",
";",
"$",
"event",
"=",
"new",
"ParseDateEvent",
"(",
"$",
"value",
",",
"Config",
"::",
"get",
"(",
"$",
"evaluation",
"[",
"'rgxp'",
"]",
".",
"'Format'",
")",
")",
";",
"$",
"environment",
"->",
"getEventDispatcher",
"(",
")",
"->",
"dispatch",
"(",
"ContaoEvents",
"::",
"DATE_PARSE",
",",
"$",
"event",
")",
";",
"return",
"$",
"event",
"->",
"getResult",
"(",
")",
";",
"}"
]
| Render for date time.
@param EnvironmentInterface $environment The environment.
@param PropertyInterface $property The property.
@param mixed $value The value.
@param boolean $isRendered Determine if is rendered.
@return mixed | [
"Render",
"for",
"date",
"time",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/View/Contao2BackendView/ActionHandler/ParentedListViewShowAllHandler.php#L274-L291 | train |
contao-community-alliance/dc-general | src/View/ActionHandler/AbstractPropertyOverrideEditAllHandler.php | AbstractPropertyOverrideEditAllHandler.handleSubmit | protected function handleSubmit(Action $action, EnvironmentInterface $environment)
{
$inputProvider = $environment->getInputProvider();
$sessionStorage = $environment->getSessionStorage();
$eventDispatcher = $environment->getEventDispatcher();
if (('auto' === $inputProvider->getValue('SUBMIT_TYPE'))
|| !$inputProvider->hasValue($this->getMode($action) . '_saveNback')) {
return;
}
$sessionStorage->remove($environment->getDataDefinition()->getName() . '.' . $this->getMode($action));
$urlEvent = new GetReferrerEvent(false, $environment->getDataDefinition()->getName());
$eventDispatcher->dispatch(ContaoEvents::SYSTEM_GET_REFERRER, $urlEvent);
$eventDispatcher->dispatch(ContaoEvents::CONTROLLER_REDIRECT, new RedirectEvent($urlEvent->getReferrerUrl()));
} | php | protected function handleSubmit(Action $action, EnvironmentInterface $environment)
{
$inputProvider = $environment->getInputProvider();
$sessionStorage = $environment->getSessionStorage();
$eventDispatcher = $environment->getEventDispatcher();
if (('auto' === $inputProvider->getValue('SUBMIT_TYPE'))
|| !$inputProvider->hasValue($this->getMode($action) . '_saveNback')) {
return;
}
$sessionStorage->remove($environment->getDataDefinition()->getName() . '.' . $this->getMode($action));
$urlEvent = new GetReferrerEvent(false, $environment->getDataDefinition()->getName());
$eventDispatcher->dispatch(ContaoEvents::SYSTEM_GET_REFERRER, $urlEvent);
$eventDispatcher->dispatch(ContaoEvents::CONTROLLER_REDIRECT, new RedirectEvent($urlEvent->getReferrerUrl()));
} | [
"protected",
"function",
"handleSubmit",
"(",
"Action",
"$",
"action",
",",
"EnvironmentInterface",
"$",
"environment",
")",
"{",
"$",
"inputProvider",
"=",
"$",
"environment",
"->",
"getInputProvider",
"(",
")",
";",
"$",
"sessionStorage",
"=",
"$",
"environment",
"->",
"getSessionStorage",
"(",
")",
";",
"$",
"eventDispatcher",
"=",
"$",
"environment",
"->",
"getEventDispatcher",
"(",
")",
";",
"if",
"(",
"(",
"'auto'",
"===",
"$",
"inputProvider",
"->",
"getValue",
"(",
"'SUBMIT_TYPE'",
")",
")",
"||",
"!",
"$",
"inputProvider",
"->",
"hasValue",
"(",
"$",
"this",
"->",
"getMode",
"(",
"$",
"action",
")",
".",
"'_saveNback'",
")",
")",
"{",
"return",
";",
"}",
"$",
"sessionStorage",
"->",
"remove",
"(",
"$",
"environment",
"->",
"getDataDefinition",
"(",
")",
"->",
"getName",
"(",
")",
".",
"'.'",
".",
"$",
"this",
"->",
"getMode",
"(",
"$",
"action",
")",
")",
";",
"$",
"urlEvent",
"=",
"new",
"GetReferrerEvent",
"(",
"false",
",",
"$",
"environment",
"->",
"getDataDefinition",
"(",
")",
"->",
"getName",
"(",
")",
")",
";",
"$",
"eventDispatcher",
"->",
"dispatch",
"(",
"ContaoEvents",
"::",
"SYSTEM_GET_REFERRER",
",",
"$",
"urlEvent",
")",
";",
"$",
"eventDispatcher",
"->",
"dispatch",
"(",
"ContaoEvents",
"::",
"CONTROLLER_REDIRECT",
",",
"new",
"RedirectEvent",
"(",
"$",
"urlEvent",
"->",
"getReferrerUrl",
"(",
")",
")",
")",
";",
"}"
]
| Handle submit triggered button.
If the button save and back triggered.
Clear the data from session and redirect to list view.
@param Action $action The action.
@param EnvironmentInterface $environment The environment.
@return void | [
"Handle",
"submit",
"triggered",
"button",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/View/ActionHandler/AbstractPropertyOverrideEditAllHandler.php#L57-L74 | train |
contao-community-alliance/dc-general | src/View/ActionHandler/AbstractPropertyOverrideEditAllHandler.php | AbstractPropertyOverrideEditAllHandler.editCollection | protected function editCollection(
Action $action,
CollectionInterface $collection,
PropertyValueBagInterface $propertyValueBag,
\ArrayObject $renderInformation,
EnvironmentInterface $environment
) {
while ($collection->count() > 0) {
$model = $collection->shift();
$persistPropertyValueBag =
$this->cloneCleanPropertyValueBag($action, $propertyValueBag, $model, $environment);
$this->resetPropertyValueErrors($persistPropertyValueBag);
$this->handleEditHandler($action, $model, $persistPropertyValueBag, $environment);
$this->markPropertyInvalidErrorsByModel($propertyValueBag, $model, $renderInformation, $environment);
$this->updatePropertyValueBag($action, $model, $persistPropertyValueBag, $propertyValueBag, $environment);
}
} | php | protected function editCollection(
Action $action,
CollectionInterface $collection,
PropertyValueBagInterface $propertyValueBag,
\ArrayObject $renderInformation,
EnvironmentInterface $environment
) {
while ($collection->count() > 0) {
$model = $collection->shift();
$persistPropertyValueBag =
$this->cloneCleanPropertyValueBag($action, $propertyValueBag, $model, $environment);
$this->resetPropertyValueErrors($persistPropertyValueBag);
$this->handleEditHandler($action, $model, $persistPropertyValueBag, $environment);
$this->markPropertyInvalidErrorsByModel($propertyValueBag, $model, $renderInformation, $environment);
$this->updatePropertyValueBag($action, $model, $persistPropertyValueBag, $propertyValueBag, $environment);
}
} | [
"protected",
"function",
"editCollection",
"(",
"Action",
"$",
"action",
",",
"CollectionInterface",
"$",
"collection",
",",
"PropertyValueBagInterface",
"$",
"propertyValueBag",
",",
"\\",
"ArrayObject",
"$",
"renderInformation",
",",
"EnvironmentInterface",
"$",
"environment",
")",
"{",
"while",
"(",
"$",
"collection",
"->",
"count",
"(",
")",
">",
"0",
")",
"{",
"$",
"model",
"=",
"$",
"collection",
"->",
"shift",
"(",
")",
";",
"$",
"persistPropertyValueBag",
"=",
"$",
"this",
"->",
"cloneCleanPropertyValueBag",
"(",
"$",
"action",
",",
"$",
"propertyValueBag",
",",
"$",
"model",
",",
"$",
"environment",
")",
";",
"$",
"this",
"->",
"resetPropertyValueErrors",
"(",
"$",
"persistPropertyValueBag",
")",
";",
"$",
"this",
"->",
"handleEditHandler",
"(",
"$",
"action",
",",
"$",
"model",
",",
"$",
"persistPropertyValueBag",
",",
"$",
"environment",
")",
";",
"$",
"this",
"->",
"markPropertyInvalidErrorsByModel",
"(",
"$",
"propertyValueBag",
",",
"$",
"model",
",",
"$",
"renderInformation",
",",
"$",
"environment",
")",
";",
"$",
"this",
"->",
"updatePropertyValueBag",
"(",
"$",
"action",
",",
"$",
"model",
",",
"$",
"persistPropertyValueBag",
",",
"$",
"propertyValueBag",
",",
"$",
"environment",
")",
";",
"}",
"}"
]
| Edit collection of models.
If model property isn´t visible revoke this.
@param Action $action The action.
@param CollectionInterface $collection The model collection.
@param PropertyValueBagInterface $propertyValueBag The properties and values for model collection.
@param \ArrayObject $renderInformation The render information.
@param EnvironmentInterface $environment The environment.
@return void | [
"Edit",
"collection",
"of",
"models",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/View/ActionHandler/AbstractPropertyOverrideEditAllHandler.php#L89-L107 | train |
contao-community-alliance/dc-general | src/View/ActionHandler/AbstractPropertyOverrideEditAllHandler.php | AbstractPropertyOverrideEditAllHandler.updateErrorInformation | protected function updateErrorInformation(
\ArrayObject $renderInformation
) {
$modelError = $renderInformation->offsetGet('modelError');
if (null === $modelError) {
return;
}
$error = [];
foreach (\array_keys($modelError) as $modelId) {
$error[] = \sprintf(
'<strong><a href="%s#pal_%s">%s</a></strong>',
Environment::get('request'),
\str_replace('::', '____', $modelId),
$modelId
);
foreach ($modelError[$modelId] as $modelIdErrors) {
foreach ($modelIdErrors as $modelIdError) {
$error[] = $modelIdError;
}
}
if (\count($modelError) > 1) {
$error[] = '';
}
}
$renderInformation->offsetSet('error', \array_merge($renderInformation->offsetGet('error'), $error));
} | php | protected function updateErrorInformation(
\ArrayObject $renderInformation
) {
$modelError = $renderInformation->offsetGet('modelError');
if (null === $modelError) {
return;
}
$error = [];
foreach (\array_keys($modelError) as $modelId) {
$error[] = \sprintf(
'<strong><a href="%s#pal_%s">%s</a></strong>',
Environment::get('request'),
\str_replace('::', '____', $modelId),
$modelId
);
foreach ($modelError[$modelId] as $modelIdErrors) {
foreach ($modelIdErrors as $modelIdError) {
$error[] = $modelIdError;
}
}
if (\count($modelError) > 1) {
$error[] = '';
}
}
$renderInformation->offsetSet('error', \array_merge($renderInformation->offsetGet('error'), $error));
} | [
"protected",
"function",
"updateErrorInformation",
"(",
"\\",
"ArrayObject",
"$",
"renderInformation",
")",
"{",
"$",
"modelError",
"=",
"$",
"renderInformation",
"->",
"offsetGet",
"(",
"'modelError'",
")",
";",
"if",
"(",
"null",
"===",
"$",
"modelError",
")",
"{",
"return",
";",
"}",
"$",
"error",
"=",
"[",
"]",
";",
"foreach",
"(",
"\\",
"array_keys",
"(",
"$",
"modelError",
")",
"as",
"$",
"modelId",
")",
"{",
"$",
"error",
"[",
"]",
"=",
"\\",
"sprintf",
"(",
"'<strong><a href=\"%s#pal_%s\">%s</a></strong>'",
",",
"Environment",
"::",
"get",
"(",
"'request'",
")",
",",
"\\",
"str_replace",
"(",
"'::'",
",",
"'____'",
",",
"$",
"modelId",
")",
",",
"$",
"modelId",
")",
";",
"foreach",
"(",
"$",
"modelError",
"[",
"$",
"modelId",
"]",
"as",
"$",
"modelIdErrors",
")",
"{",
"foreach",
"(",
"$",
"modelIdErrors",
"as",
"$",
"modelIdError",
")",
"{",
"$",
"error",
"[",
"]",
"=",
"$",
"modelIdError",
";",
"}",
"}",
"if",
"(",
"\\",
"count",
"(",
"$",
"modelError",
")",
">",
"1",
")",
"{",
"$",
"error",
"[",
"]",
"=",
"''",
";",
"}",
"}",
"$",
"renderInformation",
"->",
"offsetSet",
"(",
"'error'",
",",
"\\",
"array_merge",
"(",
"$",
"renderInformation",
"->",
"offsetGet",
"(",
"'error'",
")",
",",
"$",
"error",
")",
")",
";",
"}"
]
| Update the error information.
@param \ArrayObject $renderInformation The render information.
@return void | [
"Update",
"the",
"error",
"information",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/View/ActionHandler/AbstractPropertyOverrideEditAllHandler.php#L116-L146 | train |
contao-community-alliance/dc-general | src/View/ActionHandler/AbstractPropertyOverrideEditAllHandler.php | AbstractPropertyOverrideEditAllHandler.cloneCleanPropertyValueBag | private function cloneCleanPropertyValueBag(
Action $action,
PropertyValueBagInterface $propertyValueBag,
ModelInterface $model,
EnvironmentInterface $environment
) {
$sessionProperties = $this->getPropertiesFromSession($action, $environment);
$clonePropertyValueBag = clone $propertyValueBag;
foreach (\array_keys($propertyValueBag->getArrayCopy()) as $propertyName) {
$clonePropertyValueBag->resetPropertyValueErrors($propertyName);
if ($this->ensurePropertyVisibleInModel($action, $propertyName, $model, $environment)) {
if (!\array_key_exists($propertyName, $sessionProperties)
) {
$clonePropertyValueBag->setPropertyValue($propertyName, $model->getProperty($propertyName));
}
continue;
}
$clonePropertyValueBag->removePropertyValue($propertyName);
}
return $clonePropertyValueBag;
} | php | private function cloneCleanPropertyValueBag(
Action $action,
PropertyValueBagInterface $propertyValueBag,
ModelInterface $model,
EnvironmentInterface $environment
) {
$sessionProperties = $this->getPropertiesFromSession($action, $environment);
$clonePropertyValueBag = clone $propertyValueBag;
foreach (\array_keys($propertyValueBag->getArrayCopy()) as $propertyName) {
$clonePropertyValueBag->resetPropertyValueErrors($propertyName);
if ($this->ensurePropertyVisibleInModel($action, $propertyName, $model, $environment)) {
if (!\array_key_exists($propertyName, $sessionProperties)
) {
$clonePropertyValueBag->setPropertyValue($propertyName, $model->getProperty($propertyName));
}
continue;
}
$clonePropertyValueBag->removePropertyValue($propertyName);
}
return $clonePropertyValueBag;
} | [
"private",
"function",
"cloneCleanPropertyValueBag",
"(",
"Action",
"$",
"action",
",",
"PropertyValueBagInterface",
"$",
"propertyValueBag",
",",
"ModelInterface",
"$",
"model",
",",
"EnvironmentInterface",
"$",
"environment",
")",
"{",
"$",
"sessionProperties",
"=",
"$",
"this",
"->",
"getPropertiesFromSession",
"(",
"$",
"action",
",",
"$",
"environment",
")",
";",
"$",
"clonePropertyValueBag",
"=",
"clone",
"$",
"propertyValueBag",
";",
"foreach",
"(",
"\\",
"array_keys",
"(",
"$",
"propertyValueBag",
"->",
"getArrayCopy",
"(",
")",
")",
"as",
"$",
"propertyName",
")",
"{",
"$",
"clonePropertyValueBag",
"->",
"resetPropertyValueErrors",
"(",
"$",
"propertyName",
")",
";",
"if",
"(",
"$",
"this",
"->",
"ensurePropertyVisibleInModel",
"(",
"$",
"action",
",",
"$",
"propertyName",
",",
"$",
"model",
",",
"$",
"environment",
")",
")",
"{",
"if",
"(",
"!",
"\\",
"array_key_exists",
"(",
"$",
"propertyName",
",",
"$",
"sessionProperties",
")",
")",
"{",
"$",
"clonePropertyValueBag",
"->",
"setPropertyValue",
"(",
"$",
"propertyName",
",",
"$",
"model",
"->",
"getProperty",
"(",
"$",
"propertyName",
")",
")",
";",
"}",
"continue",
";",
"}",
"$",
"clonePropertyValueBag",
"->",
"removePropertyValue",
"(",
"$",
"propertyName",
")",
";",
"}",
"return",
"$",
"clonePropertyValueBag",
";",
"}"
]
| Clone and clean property value bag.
@param Action $action The action.
@param PropertyValueBagInterface $propertyValueBag The property value bag.
@param ModelInterface $model The model.
@param EnvironmentInterface $environment The environment.
@return PropertyValueBagInterface | [
"Clone",
"and",
"clean",
"property",
"value",
"bag",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/View/ActionHandler/AbstractPropertyOverrideEditAllHandler.php#L158-L183 | train |
contao-community-alliance/dc-general | src/View/ActionHandler/AbstractPropertyOverrideEditAllHandler.php | AbstractPropertyOverrideEditAllHandler.resetPropertyValueErrors | private function resetPropertyValueErrors(PropertyValueBagInterface $propertyValueBag)
{
foreach (\array_keys($propertyValueBag->getInvalidPropertyErrors()) as $errorProperty) {
$propertyValueBag->resetPropertyValueErrors($errorProperty);
}
} | php | private function resetPropertyValueErrors(PropertyValueBagInterface $propertyValueBag)
{
foreach (\array_keys($propertyValueBag->getInvalidPropertyErrors()) as $errorProperty) {
$propertyValueBag->resetPropertyValueErrors($errorProperty);
}
} | [
"private",
"function",
"resetPropertyValueErrors",
"(",
"PropertyValueBagInterface",
"$",
"propertyValueBag",
")",
"{",
"foreach",
"(",
"\\",
"array_keys",
"(",
"$",
"propertyValueBag",
"->",
"getInvalidPropertyErrors",
"(",
")",
")",
"as",
"$",
"errorProperty",
")",
"{",
"$",
"propertyValueBag",
"->",
"resetPropertyValueErrors",
"(",
"$",
"errorProperty",
")",
";",
"}",
"}"
]
| Reset property value errors.
@param PropertyValueBagInterface $propertyValueBag The property value bag.
@return void | [
"Reset",
"property",
"value",
"errors",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/View/ActionHandler/AbstractPropertyOverrideEditAllHandler.php#L192-L197 | train |
contao-community-alliance/dc-general | src/View/ActionHandler/AbstractPropertyOverrideEditAllHandler.php | AbstractPropertyOverrideEditAllHandler.markPropertyInvalidErrorsByModel | private function markPropertyInvalidErrorsByModel(
PropertyValueBagInterface $propertyValueBag,
ModelInterface $model,
\ArrayObject $renderInformation,
EnvironmentInterface $environment
) {
$editInformation = $GLOBALS['container']['dc-general.edit-information'];
$errorInformation = $editInformation->getModelError($model);
if (null === $errorInformation) {
return;
}
foreach (\array_keys($errorInformation) as $errorPropertyName) {
\array_map(
function ($error) use (
$errorPropertyName,
$model,
$propertyValueBag,
$renderInformation,
$editInformation,
$environment
) {
$modelError = (array) $renderInformation->offsetGet('modelError');
$inputField = \sprintf(
'ctrl_%s_%s',
\str_replace('::', '____', ModelId::fromModel($model)->getSerialized()),
$errorPropertyName
);
$modelError[ModelId::fromModel($model)->getSerialized()][$errorPropertyName][] = \sprintf(
'<a href="%s#%s">No saved model[%s]. %s</a>',
Environment::get('request'),
$inputField,
$model->getId(),
$error
);
$renderInformation->offsetSet('modelError', $modelError);
$modelEditError = $editInformation->getModelError($model);
if ($modelEditError && isset($modelEditError[$errorPropertyName])) {
$propertyValueBag->setPropertyValue(
$errorPropertyName,
$environment->getInputProvider()->getValue($errorPropertyName)
);
$propertyValueBag->markPropertyValueAsInvalid(
$errorPropertyName,
$modelEditError[$errorPropertyName]
);
}
},
$errorInformation[$errorPropertyName]
);
}
} | php | private function markPropertyInvalidErrorsByModel(
PropertyValueBagInterface $propertyValueBag,
ModelInterface $model,
\ArrayObject $renderInformation,
EnvironmentInterface $environment
) {
$editInformation = $GLOBALS['container']['dc-general.edit-information'];
$errorInformation = $editInformation->getModelError($model);
if (null === $errorInformation) {
return;
}
foreach (\array_keys($errorInformation) as $errorPropertyName) {
\array_map(
function ($error) use (
$errorPropertyName,
$model,
$propertyValueBag,
$renderInformation,
$editInformation,
$environment
) {
$modelError = (array) $renderInformation->offsetGet('modelError');
$inputField = \sprintf(
'ctrl_%s_%s',
\str_replace('::', '____', ModelId::fromModel($model)->getSerialized()),
$errorPropertyName
);
$modelError[ModelId::fromModel($model)->getSerialized()][$errorPropertyName][] = \sprintf(
'<a href="%s#%s">No saved model[%s]. %s</a>',
Environment::get('request'),
$inputField,
$model->getId(),
$error
);
$renderInformation->offsetSet('modelError', $modelError);
$modelEditError = $editInformation->getModelError($model);
if ($modelEditError && isset($modelEditError[$errorPropertyName])) {
$propertyValueBag->setPropertyValue(
$errorPropertyName,
$environment->getInputProvider()->getValue($errorPropertyName)
);
$propertyValueBag->markPropertyValueAsInvalid(
$errorPropertyName,
$modelEditError[$errorPropertyName]
);
}
},
$errorInformation[$errorPropertyName]
);
}
} | [
"private",
"function",
"markPropertyInvalidErrorsByModel",
"(",
"PropertyValueBagInterface",
"$",
"propertyValueBag",
",",
"ModelInterface",
"$",
"model",
",",
"\\",
"ArrayObject",
"$",
"renderInformation",
",",
"EnvironmentInterface",
"$",
"environment",
")",
"{",
"$",
"editInformation",
"=",
"$",
"GLOBALS",
"[",
"'container'",
"]",
"[",
"'dc-general.edit-information'",
"]",
";",
"$",
"errorInformation",
"=",
"$",
"editInformation",
"->",
"getModelError",
"(",
"$",
"model",
")",
";",
"if",
"(",
"null",
"===",
"$",
"errorInformation",
")",
"{",
"return",
";",
"}",
"foreach",
"(",
"\\",
"array_keys",
"(",
"$",
"errorInformation",
")",
"as",
"$",
"errorPropertyName",
")",
"{",
"\\",
"array_map",
"(",
"function",
"(",
"$",
"error",
")",
"use",
"(",
"$",
"errorPropertyName",
",",
"$",
"model",
",",
"$",
"propertyValueBag",
",",
"$",
"renderInformation",
",",
"$",
"editInformation",
",",
"$",
"environment",
")",
"{",
"$",
"modelError",
"=",
"(",
"array",
")",
"$",
"renderInformation",
"->",
"offsetGet",
"(",
"'modelError'",
")",
";",
"$",
"inputField",
"=",
"\\",
"sprintf",
"(",
"'ctrl_%s_%s'",
",",
"\\",
"str_replace",
"(",
"'::'",
",",
"'____'",
",",
"ModelId",
"::",
"fromModel",
"(",
"$",
"model",
")",
"->",
"getSerialized",
"(",
")",
")",
",",
"$",
"errorPropertyName",
")",
";",
"$",
"modelError",
"[",
"ModelId",
"::",
"fromModel",
"(",
"$",
"model",
")",
"->",
"getSerialized",
"(",
")",
"]",
"[",
"$",
"errorPropertyName",
"]",
"[",
"]",
"=",
"\\",
"sprintf",
"(",
"'<a href=\"%s#%s\">No saved model[%s]. %s</a>'",
",",
"Environment",
"::",
"get",
"(",
"'request'",
")",
",",
"$",
"inputField",
",",
"$",
"model",
"->",
"getId",
"(",
")",
",",
"$",
"error",
")",
";",
"$",
"renderInformation",
"->",
"offsetSet",
"(",
"'modelError'",
",",
"$",
"modelError",
")",
";",
"$",
"modelEditError",
"=",
"$",
"editInformation",
"->",
"getModelError",
"(",
"$",
"model",
")",
";",
"if",
"(",
"$",
"modelEditError",
"&&",
"isset",
"(",
"$",
"modelEditError",
"[",
"$",
"errorPropertyName",
"]",
")",
")",
"{",
"$",
"propertyValueBag",
"->",
"setPropertyValue",
"(",
"$",
"errorPropertyName",
",",
"$",
"environment",
"->",
"getInputProvider",
"(",
")",
"->",
"getValue",
"(",
"$",
"errorPropertyName",
")",
")",
";",
"$",
"propertyValueBag",
"->",
"markPropertyValueAsInvalid",
"(",
"$",
"errorPropertyName",
",",
"$",
"modelEditError",
"[",
"$",
"errorPropertyName",
"]",
")",
";",
"}",
"}",
",",
"$",
"errorInformation",
"[",
"$",
"errorPropertyName",
"]",
")",
";",
"}",
"}"
]
| Mark property in invalid errors by model.
@param PropertyValueBagInterface $propertyValueBag The property values.
@param ModelInterface $model The Model.
@param \ArrayObject $renderInformation The render information.
@param EnvironmentInterface $environment The environment.
@return void
@SuppressWarnings(PHPMD.Superglobals) | [
"Mark",
"property",
"in",
"invalid",
"errors",
"by",
"model",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/View/ActionHandler/AbstractPropertyOverrideEditAllHandler.php#L211-L267 | train |
contao-community-alliance/dc-general | src/View/ActionHandler/AbstractPropertyOverrideEditAllHandler.php | AbstractPropertyOverrideEditAllHandler.updatePropertyValueBag | private function updatePropertyValueBag(
Action $action,
ModelInterface $model,
PropertyValueBagInterface $sourcePropertyValueBag,
PropertyValueBagInterface $updatePropertyValueBag,
EnvironmentInterface $environment
) {
$dataProvider = $environment->getDataProvider();
$sessionProperties = $this->getPropertiesFromSession($action, $environment);
foreach (\array_keys($sessionProperties) as $sessionPropertyName) {
if (!$sourcePropertyValueBag->hasPropertyValue($sessionPropertyName)) {
continue;
}
if (!$updatePropertyValueBag->isPropertyValueInvalid($sessionPropertyName)) {
$editModel = $dataProvider->fetch($dataProvider->getEmptyConfig()->setId($model->getId()));
$updatePropertyValueBag->setPropertyValue(
$sessionPropertyName,
$editModel->getProperty($sessionPropertyName)
);
}
if ($updatePropertyValueBag->isPropertyValueInvalid($sessionPropertyName)) {
continue;
}
$updatePropertyValueBag->markPropertyValueAsInvalid(
$sessionPropertyName,
$sourcePropertyValueBag->getPropertyValueErrors(
$sessionPropertyName
)
);
}
} | php | private function updatePropertyValueBag(
Action $action,
ModelInterface $model,
PropertyValueBagInterface $sourcePropertyValueBag,
PropertyValueBagInterface $updatePropertyValueBag,
EnvironmentInterface $environment
) {
$dataProvider = $environment->getDataProvider();
$sessionProperties = $this->getPropertiesFromSession($action, $environment);
foreach (\array_keys($sessionProperties) as $sessionPropertyName) {
if (!$sourcePropertyValueBag->hasPropertyValue($sessionPropertyName)) {
continue;
}
if (!$updatePropertyValueBag->isPropertyValueInvalid($sessionPropertyName)) {
$editModel = $dataProvider->fetch($dataProvider->getEmptyConfig()->setId($model->getId()));
$updatePropertyValueBag->setPropertyValue(
$sessionPropertyName,
$editModel->getProperty($sessionPropertyName)
);
}
if ($updatePropertyValueBag->isPropertyValueInvalid($sessionPropertyName)) {
continue;
}
$updatePropertyValueBag->markPropertyValueAsInvalid(
$sessionPropertyName,
$sourcePropertyValueBag->getPropertyValueErrors(
$sessionPropertyName
)
);
}
} | [
"private",
"function",
"updatePropertyValueBag",
"(",
"Action",
"$",
"action",
",",
"ModelInterface",
"$",
"model",
",",
"PropertyValueBagInterface",
"$",
"sourcePropertyValueBag",
",",
"PropertyValueBagInterface",
"$",
"updatePropertyValueBag",
",",
"EnvironmentInterface",
"$",
"environment",
")",
"{",
"$",
"dataProvider",
"=",
"$",
"environment",
"->",
"getDataProvider",
"(",
")",
";",
"$",
"sessionProperties",
"=",
"$",
"this",
"->",
"getPropertiesFromSession",
"(",
"$",
"action",
",",
"$",
"environment",
")",
";",
"foreach",
"(",
"\\",
"array_keys",
"(",
"$",
"sessionProperties",
")",
"as",
"$",
"sessionPropertyName",
")",
"{",
"if",
"(",
"!",
"$",
"sourcePropertyValueBag",
"->",
"hasPropertyValue",
"(",
"$",
"sessionPropertyName",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"!",
"$",
"updatePropertyValueBag",
"->",
"isPropertyValueInvalid",
"(",
"$",
"sessionPropertyName",
")",
")",
"{",
"$",
"editModel",
"=",
"$",
"dataProvider",
"->",
"fetch",
"(",
"$",
"dataProvider",
"->",
"getEmptyConfig",
"(",
")",
"->",
"setId",
"(",
"$",
"model",
"->",
"getId",
"(",
")",
")",
")",
";",
"$",
"updatePropertyValueBag",
"->",
"setPropertyValue",
"(",
"$",
"sessionPropertyName",
",",
"$",
"editModel",
"->",
"getProperty",
"(",
"$",
"sessionPropertyName",
")",
")",
";",
"}",
"if",
"(",
"$",
"updatePropertyValueBag",
"->",
"isPropertyValueInvalid",
"(",
"$",
"sessionPropertyName",
")",
")",
"{",
"continue",
";",
"}",
"$",
"updatePropertyValueBag",
"->",
"markPropertyValueAsInvalid",
"(",
"$",
"sessionPropertyName",
",",
"$",
"sourcePropertyValueBag",
"->",
"getPropertyValueErrors",
"(",
"$",
"sessionPropertyName",
")",
")",
";",
"}",
"}"
]
| Update property value bag.
@param Action $action The action.
@param ModelInterface $model The model.
@param PropertyValueBagInterface $sourcePropertyValueBag The source property value bag.
@param PropertyValueBagInterface $updatePropertyValueBag The update property value bag.
@param EnvironmentInterface $environment The environment.
@return void | [
"Update",
"property",
"value",
"bag",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/View/ActionHandler/AbstractPropertyOverrideEditAllHandler.php#L280-L314 | train |
contao-community-alliance/dc-general | src/View/ActionHandler/AbstractPropertyOverrideEditAllHandler.php | AbstractPropertyOverrideEditAllHandler.handleEditHandler | private function handleEditHandler(
Action $action,
ModelInterface $model,
PropertyValueBagInterface $propertyValueBag,
EnvironmentInterface $environment
) {
$inputProvider = $environment->getInputProvider();
$editInformation = $GLOBALS['container']['dc-general.edit-information'];
$inputValues = $this->handleInputValues($action, $model, $environment);
$view = $environment->getView();
if (!$view instanceof BaseView) {
return;
}
$clone = clone $model;
$clone->setId($model->getId());
$inputProvider->setParameter('id', ModelId::fromModel($model)->getSerialized());
$this->callAction($environment, 'edit');
$inputProvider->unsetParameter('id');
$this->restoreInputValues($action, $model, $propertyValueBag, $inputValues, $environment);
$errorInformation = $editInformation->getModelError($model);
if (null !== $errorInformation) {
foreach (\array_keys($errorInformation) as $errorPropertyName) {
if (false === $propertyValueBag->hasPropertyValue($errorPropertyName)) {
continue;
}
if ($propertyValueBag->isPropertyValueInvalid($errorPropertyName)) {
continue;
}
foreach ($errorInformation[$errorPropertyName] as $error) {
$propertyValueBag->markPropertyValueAsInvalid($errorPropertyName, $error);
}
}
}
} | php | private function handleEditHandler(
Action $action,
ModelInterface $model,
PropertyValueBagInterface $propertyValueBag,
EnvironmentInterface $environment
) {
$inputProvider = $environment->getInputProvider();
$editInformation = $GLOBALS['container']['dc-general.edit-information'];
$inputValues = $this->handleInputValues($action, $model, $environment);
$view = $environment->getView();
if (!$view instanceof BaseView) {
return;
}
$clone = clone $model;
$clone->setId($model->getId());
$inputProvider->setParameter('id', ModelId::fromModel($model)->getSerialized());
$this->callAction($environment, 'edit');
$inputProvider->unsetParameter('id');
$this->restoreInputValues($action, $model, $propertyValueBag, $inputValues, $environment);
$errorInformation = $editInformation->getModelError($model);
if (null !== $errorInformation) {
foreach (\array_keys($errorInformation) as $errorPropertyName) {
if (false === $propertyValueBag->hasPropertyValue($errorPropertyName)) {
continue;
}
if ($propertyValueBag->isPropertyValueInvalid($errorPropertyName)) {
continue;
}
foreach ($errorInformation[$errorPropertyName] as $error) {
$propertyValueBag->markPropertyValueAsInvalid($errorPropertyName, $error);
}
}
}
} | [
"private",
"function",
"handleEditHandler",
"(",
"Action",
"$",
"action",
",",
"ModelInterface",
"$",
"model",
",",
"PropertyValueBagInterface",
"$",
"propertyValueBag",
",",
"EnvironmentInterface",
"$",
"environment",
")",
"{",
"$",
"inputProvider",
"=",
"$",
"environment",
"->",
"getInputProvider",
"(",
")",
";",
"$",
"editInformation",
"=",
"$",
"GLOBALS",
"[",
"'container'",
"]",
"[",
"'dc-general.edit-information'",
"]",
";",
"$",
"inputValues",
"=",
"$",
"this",
"->",
"handleInputValues",
"(",
"$",
"action",
",",
"$",
"model",
",",
"$",
"environment",
")",
";",
"$",
"view",
"=",
"$",
"environment",
"->",
"getView",
"(",
")",
";",
"if",
"(",
"!",
"$",
"view",
"instanceof",
"BaseView",
")",
"{",
"return",
";",
"}",
"$",
"clone",
"=",
"clone",
"$",
"model",
";",
"$",
"clone",
"->",
"setId",
"(",
"$",
"model",
"->",
"getId",
"(",
")",
")",
";",
"$",
"inputProvider",
"->",
"setParameter",
"(",
"'id'",
",",
"ModelId",
"::",
"fromModel",
"(",
"$",
"model",
")",
"->",
"getSerialized",
"(",
")",
")",
";",
"$",
"this",
"->",
"callAction",
"(",
"$",
"environment",
",",
"'edit'",
")",
";",
"$",
"inputProvider",
"->",
"unsetParameter",
"(",
"'id'",
")",
";",
"$",
"this",
"->",
"restoreInputValues",
"(",
"$",
"action",
",",
"$",
"model",
",",
"$",
"propertyValueBag",
",",
"$",
"inputValues",
",",
"$",
"environment",
")",
";",
"$",
"errorInformation",
"=",
"$",
"editInformation",
"->",
"getModelError",
"(",
"$",
"model",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"errorInformation",
")",
"{",
"foreach",
"(",
"\\",
"array_keys",
"(",
"$",
"errorInformation",
")",
"as",
"$",
"errorPropertyName",
")",
"{",
"if",
"(",
"false",
"===",
"$",
"propertyValueBag",
"->",
"hasPropertyValue",
"(",
"$",
"errorPropertyName",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"$",
"propertyValueBag",
"->",
"isPropertyValueInvalid",
"(",
"$",
"errorPropertyName",
")",
")",
"{",
"continue",
";",
"}",
"foreach",
"(",
"$",
"errorInformation",
"[",
"$",
"errorPropertyName",
"]",
"as",
"$",
"error",
")",
"{",
"$",
"propertyValueBag",
"->",
"markPropertyValueAsInvalid",
"(",
"$",
"errorPropertyName",
",",
"$",
"error",
")",
";",
"}",
"}",
"}",
"}"
]
| Handle the edit handler.
@param Action $action The action.
@param ModelInterface $model The model.
@param PropertyValueBagInterface $propertyValueBag The property value.
@param EnvironmentInterface $environment The environment.
@return void
@SuppressWarnings(PHPMD.Superglobals) | [
"Handle",
"the",
"edit",
"handler",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/View/ActionHandler/AbstractPropertyOverrideEditAllHandler.php#L328-L371 | train |
contao-community-alliance/dc-general | src/View/ActionHandler/AbstractPropertyOverrideEditAllHandler.php | AbstractPropertyOverrideEditAllHandler.handleInputValues | private function handleInputValues(Action $action, ModelInterface $model, EnvironmentInterface $environment)
{
$editProperties = $this->getEditPropertiesByModelId($action, ModelId::fromModel($model), $environment);
if (!$editProperties) {
return [];
}
$inputProvider = $environment->getInputProvider();
$inputValues = [];
foreach (\array_keys($_POST) as $valueName) {
$inputValues[$valueName] = $inputProvider->getValue($valueName, true);
$inputProvider->unsetValue($valueName);
switch ($valueName) {
case 'FORM_SUBMIT':
case 'REQUEST_TOKEN':
$inputProvider->setValue($valueName, $inputValues[$valueName]);
break;
case 'FORM_INPUTS':
$inputProvider->setValue($valueName, \array_keys($editProperties));
foreach (\array_keys($editProperties) as $editPropertyName) {
$inputProvider->setValue($editPropertyName, $editProperties[$editPropertyName]);
}
break;
default:
}
}
return $inputValues;
} | php | private function handleInputValues(Action $action, ModelInterface $model, EnvironmentInterface $environment)
{
$editProperties = $this->getEditPropertiesByModelId($action, ModelId::fromModel($model), $environment);
if (!$editProperties) {
return [];
}
$inputProvider = $environment->getInputProvider();
$inputValues = [];
foreach (\array_keys($_POST) as $valueName) {
$inputValues[$valueName] = $inputProvider->getValue($valueName, true);
$inputProvider->unsetValue($valueName);
switch ($valueName) {
case 'FORM_SUBMIT':
case 'REQUEST_TOKEN':
$inputProvider->setValue($valueName, $inputValues[$valueName]);
break;
case 'FORM_INPUTS':
$inputProvider->setValue($valueName, \array_keys($editProperties));
foreach (\array_keys($editProperties) as $editPropertyName) {
$inputProvider->setValue($editPropertyName, $editProperties[$editPropertyName]);
}
break;
default:
}
}
return $inputValues;
} | [
"private",
"function",
"handleInputValues",
"(",
"Action",
"$",
"action",
",",
"ModelInterface",
"$",
"model",
",",
"EnvironmentInterface",
"$",
"environment",
")",
"{",
"$",
"editProperties",
"=",
"$",
"this",
"->",
"getEditPropertiesByModelId",
"(",
"$",
"action",
",",
"ModelId",
"::",
"fromModel",
"(",
"$",
"model",
")",
",",
"$",
"environment",
")",
";",
"if",
"(",
"!",
"$",
"editProperties",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"inputProvider",
"=",
"$",
"environment",
"->",
"getInputProvider",
"(",
")",
";",
"$",
"inputValues",
"=",
"[",
"]",
";",
"foreach",
"(",
"\\",
"array_keys",
"(",
"$",
"_POST",
")",
"as",
"$",
"valueName",
")",
"{",
"$",
"inputValues",
"[",
"$",
"valueName",
"]",
"=",
"$",
"inputProvider",
"->",
"getValue",
"(",
"$",
"valueName",
",",
"true",
")",
";",
"$",
"inputProvider",
"->",
"unsetValue",
"(",
"$",
"valueName",
")",
";",
"switch",
"(",
"$",
"valueName",
")",
"{",
"case",
"'FORM_SUBMIT'",
":",
"case",
"'REQUEST_TOKEN'",
":",
"$",
"inputProvider",
"->",
"setValue",
"(",
"$",
"valueName",
",",
"$",
"inputValues",
"[",
"$",
"valueName",
"]",
")",
";",
"break",
";",
"case",
"'FORM_INPUTS'",
":",
"$",
"inputProvider",
"->",
"setValue",
"(",
"$",
"valueName",
",",
"\\",
"array_keys",
"(",
"$",
"editProperties",
")",
")",
";",
"foreach",
"(",
"\\",
"array_keys",
"(",
"$",
"editProperties",
")",
"as",
"$",
"editPropertyName",
")",
"{",
"$",
"inputProvider",
"->",
"setValue",
"(",
"$",
"editPropertyName",
",",
"$",
"editProperties",
"[",
"$",
"editPropertyName",
"]",
")",
";",
"}",
"break",
";",
"default",
":",
"}",
"}",
"return",
"$",
"inputValues",
";",
"}"
]
| Handle input values and return it.
@param Action $action The action.
@param ModelInterface $model The model.
@param EnvironmentInterface $environment The environment.
@return array
@SuppressWarnings(PHPMD.Superglobals) | [
"Handle",
"input",
"values",
"and",
"return",
"it",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/View/ActionHandler/AbstractPropertyOverrideEditAllHandler.php#L384-L420 | train |
contao-community-alliance/dc-general | src/View/ActionHandler/AbstractPropertyOverrideEditAllHandler.php | AbstractPropertyOverrideEditAllHandler.restoreInputValues | protected function restoreInputValues(
Action $action,
ModelInterface $model,
PropertyValueBagInterface $propertyValueBag,
array $inputValues,
EnvironmentInterface $environment
) {
$editProperties = $this->getEditPropertiesByModelId($action, ModelId::fromModel($model), $environment);
if (!$editProperties) {
return;
}
$inputProvider = $environment->getInputProvider();
unset($_POST);
foreach (\array_keys($inputValues) as $postName) {
$inputProvider->setValue($postName, $inputValues[$postName]);
}
foreach (\array_keys($editProperties) as $editedPropertyName) {
$propertyValueBag->setPropertyValue($editedPropertyName, $model->getProperty($editedPropertyName));
}
} | php | protected function restoreInputValues(
Action $action,
ModelInterface $model,
PropertyValueBagInterface $propertyValueBag,
array $inputValues,
EnvironmentInterface $environment
) {
$editProperties = $this->getEditPropertiesByModelId($action, ModelId::fromModel($model), $environment);
if (!$editProperties) {
return;
}
$inputProvider = $environment->getInputProvider();
unset($_POST);
foreach (\array_keys($inputValues) as $postName) {
$inputProvider->setValue($postName, $inputValues[$postName]);
}
foreach (\array_keys($editProperties) as $editedPropertyName) {
$propertyValueBag->setPropertyValue($editedPropertyName, $model->getProperty($editedPropertyName));
}
} | [
"protected",
"function",
"restoreInputValues",
"(",
"Action",
"$",
"action",
",",
"ModelInterface",
"$",
"model",
",",
"PropertyValueBagInterface",
"$",
"propertyValueBag",
",",
"array",
"$",
"inputValues",
",",
"EnvironmentInterface",
"$",
"environment",
")",
"{",
"$",
"editProperties",
"=",
"$",
"this",
"->",
"getEditPropertiesByModelId",
"(",
"$",
"action",
",",
"ModelId",
"::",
"fromModel",
"(",
"$",
"model",
")",
",",
"$",
"environment",
")",
";",
"if",
"(",
"!",
"$",
"editProperties",
")",
"{",
"return",
";",
"}",
"$",
"inputProvider",
"=",
"$",
"environment",
"->",
"getInputProvider",
"(",
")",
";",
"unset",
"(",
"$",
"_POST",
")",
";",
"foreach",
"(",
"\\",
"array_keys",
"(",
"$",
"inputValues",
")",
"as",
"$",
"postName",
")",
"{",
"$",
"inputProvider",
"->",
"setValue",
"(",
"$",
"postName",
",",
"$",
"inputValues",
"[",
"$",
"postName",
"]",
")",
";",
"}",
"foreach",
"(",
"\\",
"array_keys",
"(",
"$",
"editProperties",
")",
"as",
"$",
"editedPropertyName",
")",
"{",
"$",
"propertyValueBag",
"->",
"setPropertyValue",
"(",
"$",
"editedPropertyName",
",",
"$",
"model",
"->",
"getProperty",
"(",
"$",
"editedPropertyName",
")",
")",
";",
"}",
"}"
]
| Restore input values.
@param Action $action The action.
@param ModelInterface $model The model.
@param PropertyValueBagInterface $propertyValueBag The property value bag.
@param array $inputValues The input values.
@param EnvironmentInterface $environment The environment.
@return void
@SuppressWarnings(PHPMD.Superglobals) | [
"Restore",
"input",
"values",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/View/ActionHandler/AbstractPropertyOverrideEditAllHandler.php#L435-L457 | train |
contao-community-alliance/dc-general | src/View/ActionHandler/AbstractPropertyOverrideEditAllHandler.php | AbstractPropertyOverrideEditAllHandler.getEditButtons | protected function getEditButtons(Action $action, EnvironmentInterface $environment)
{
$translator = $environment->getTranslator();
$mode = $this->getMode($action);
$buttons = [];
$buttons['save'] = \sprintf(
'<input type="submit" name="%s_save" id="%s_save" class="tl_submit" accesskey="s" value="%s" />',
$mode,
$mode,
$translator->translate('MSC.save')
);
$buttons['save'] .= ' ';
$buttons['save'] .= \sprintf(
'<input type="submit" name="%s_saveNback" id="%s_saveNback" class="tl_submit" accesskey="c" value="%s" />',
$mode,
$mode,
$translator->translate('MSC.saveNback')
);
$submitButtonTemplate = new ContaoBackendViewTemplate('dc_general_submit_button');
$submitButtonTemplate->setData($buttons);
return \preg_replace('/(\s\s+|\t|\n)/', '', $submitButtonTemplate->parse());
} | php | protected function getEditButtons(Action $action, EnvironmentInterface $environment)
{
$translator = $environment->getTranslator();
$mode = $this->getMode($action);
$buttons = [];
$buttons['save'] = \sprintf(
'<input type="submit" name="%s_save" id="%s_save" class="tl_submit" accesskey="s" value="%s" />',
$mode,
$mode,
$translator->translate('MSC.save')
);
$buttons['save'] .= ' ';
$buttons['save'] .= \sprintf(
'<input type="submit" name="%s_saveNback" id="%s_saveNback" class="tl_submit" accesskey="c" value="%s" />',
$mode,
$mode,
$translator->translate('MSC.saveNback')
);
$submitButtonTemplate = new ContaoBackendViewTemplate('dc_general_submit_button');
$submitButtonTemplate->setData($buttons);
return \preg_replace('/(\s\s+|\t|\n)/', '', $submitButtonTemplate->parse());
} | [
"protected",
"function",
"getEditButtons",
"(",
"Action",
"$",
"action",
",",
"EnvironmentInterface",
"$",
"environment",
")",
"{",
"$",
"translator",
"=",
"$",
"environment",
"->",
"getTranslator",
"(",
")",
";",
"$",
"mode",
"=",
"$",
"this",
"->",
"getMode",
"(",
"$",
"action",
")",
";",
"$",
"buttons",
"=",
"[",
"]",
";",
"$",
"buttons",
"[",
"'save'",
"]",
"=",
"\\",
"sprintf",
"(",
"'<input type=\"submit\" name=\"%s_save\" id=\"%s_save\" class=\"tl_submit\" accesskey=\"s\" value=\"%s\" />'",
",",
"$",
"mode",
",",
"$",
"mode",
",",
"$",
"translator",
"->",
"translate",
"(",
"'MSC.save'",
")",
")",
";",
"$",
"buttons",
"[",
"'save'",
"]",
".=",
"' '",
";",
"$",
"buttons",
"[",
"'save'",
"]",
".=",
"\\",
"sprintf",
"(",
"'<input type=\"submit\" name=\"%s_saveNback\" id=\"%s_saveNback\" class=\"tl_submit\" accesskey=\"c\" value=\"%s\" />'",
",",
"$",
"mode",
",",
"$",
"mode",
",",
"$",
"translator",
"->",
"translate",
"(",
"'MSC.saveNback'",
")",
")",
";",
"$",
"submitButtonTemplate",
"=",
"new",
"ContaoBackendViewTemplate",
"(",
"'dc_general_submit_button'",
")",
";",
"$",
"submitButtonTemplate",
"->",
"setData",
"(",
"$",
"buttons",
")",
";",
"return",
"\\",
"preg_replace",
"(",
"'/(\\s\\s+|\\t|\\n)/'",
",",
"''",
",",
"$",
"submitButtonTemplate",
"->",
"parse",
"(",
")",
")",
";",
"}"
]
| Retrieve buttons to use in the bottom panel.
@param Action $action The action.
@param EnvironmentInterface $environment The environment.
@return array | [
"Retrieve",
"buttons",
"to",
"use",
"in",
"the",
"bottom",
"panel",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/View/ActionHandler/AbstractPropertyOverrideEditAllHandler.php#L467-L495 | train |
contao-community-alliance/dc-general | src/View/ActionHandler/AbstractPropertyOverrideEditAllHandler.php | AbstractPropertyOverrideEditAllHandler.renderTemplate | protected function renderTemplate(Action $action, array $config)
{
$template = new ContaoBackendViewTemplate('dcbe_general_edit');
$template->setData($config);
$template->set('mode', $this->getMode($action));
return $template->parse();
} | php | protected function renderTemplate(Action $action, array $config)
{
$template = new ContaoBackendViewTemplate('dcbe_general_edit');
$template->setData($config);
$template->set('mode', $this->getMode($action));
return $template->parse();
} | [
"protected",
"function",
"renderTemplate",
"(",
"Action",
"$",
"action",
",",
"array",
"$",
"config",
")",
"{",
"$",
"template",
"=",
"new",
"ContaoBackendViewTemplate",
"(",
"'dcbe_general_edit'",
")",
";",
"$",
"template",
"->",
"setData",
"(",
"$",
"config",
")",
";",
"$",
"template",
"->",
"set",
"(",
"'mode'",
",",
"$",
"this",
"->",
"getMode",
"(",
"$",
"action",
")",
")",
";",
"return",
"$",
"template",
"->",
"parse",
"(",
")",
";",
"}"
]
| Render the template for the edit mask.
@param Action $action The action.
@param array $config The template config data.
@return string | [
"Render",
"the",
"template",
"for",
"the",
"edit",
"mask",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/View/ActionHandler/AbstractPropertyOverrideEditAllHandler.php#L505-L513 | train |
contao-community-alliance/dc-general | src/View/ActionHandler/AbstractPropertyOverrideEditAllHandler.php | AbstractPropertyOverrideEditAllHandler.getPropertyValueBagFromModel | protected function getPropertyValueBagFromModel(
Action $action,
ModelInterface $model,
EnvironmentInterface $environment
) {
$propertiesDefinition = $environment->getDataDefinition()->getPropertiesDefinition();
$editInformation = $GLOBALS['container']['dc-general.edit-information'];
$propertyValueBag = new PropertyValueBag();
foreach ($model->getPropertiesAsArray() as $propertyName => $propertyValue) {
if (!$propertiesDefinition->hasProperty($propertyName)) {
continue;
}
$property = $propertiesDefinition->getProperty($propertyName);
if (!$property->getWidgetType()) {
continue;
}
$modelError = $editInformation->getModelError($model);
if ($modelError && isset($modelError[$propertyName])) {
$sessionValues = $this->getEditPropertiesByModelId($action, ModelId::fromModel($model), $environment);
$propertyValueBag->setPropertyValue($propertyName, $sessionValues[$propertyName]);
$propertyValueBag->markPropertyValueAsInvalid($propertyName, $modelError[$propertyName]);
continue;
}
$propertyValueBag->setPropertyValue($propertyName, $propertyValue);
}
return $propertyValueBag;
} | php | protected function getPropertyValueBagFromModel(
Action $action,
ModelInterface $model,
EnvironmentInterface $environment
) {
$propertiesDefinition = $environment->getDataDefinition()->getPropertiesDefinition();
$editInformation = $GLOBALS['container']['dc-general.edit-information'];
$propertyValueBag = new PropertyValueBag();
foreach ($model->getPropertiesAsArray() as $propertyName => $propertyValue) {
if (!$propertiesDefinition->hasProperty($propertyName)) {
continue;
}
$property = $propertiesDefinition->getProperty($propertyName);
if (!$property->getWidgetType()) {
continue;
}
$modelError = $editInformation->getModelError($model);
if ($modelError && isset($modelError[$propertyName])) {
$sessionValues = $this->getEditPropertiesByModelId($action, ModelId::fromModel($model), $environment);
$propertyValueBag->setPropertyValue($propertyName, $sessionValues[$propertyName]);
$propertyValueBag->markPropertyValueAsInvalid($propertyName, $modelError[$propertyName]);
continue;
}
$propertyValueBag->setPropertyValue($propertyName, $propertyValue);
}
return $propertyValueBag;
} | [
"protected",
"function",
"getPropertyValueBagFromModel",
"(",
"Action",
"$",
"action",
",",
"ModelInterface",
"$",
"model",
",",
"EnvironmentInterface",
"$",
"environment",
")",
"{",
"$",
"propertiesDefinition",
"=",
"$",
"environment",
"->",
"getDataDefinition",
"(",
")",
"->",
"getPropertiesDefinition",
"(",
")",
";",
"$",
"editInformation",
"=",
"$",
"GLOBALS",
"[",
"'container'",
"]",
"[",
"'dc-general.edit-information'",
"]",
";",
"$",
"propertyValueBag",
"=",
"new",
"PropertyValueBag",
"(",
")",
";",
"foreach",
"(",
"$",
"model",
"->",
"getPropertiesAsArray",
"(",
")",
"as",
"$",
"propertyName",
"=>",
"$",
"propertyValue",
")",
"{",
"if",
"(",
"!",
"$",
"propertiesDefinition",
"->",
"hasProperty",
"(",
"$",
"propertyName",
")",
")",
"{",
"continue",
";",
"}",
"$",
"property",
"=",
"$",
"propertiesDefinition",
"->",
"getProperty",
"(",
"$",
"propertyName",
")",
";",
"if",
"(",
"!",
"$",
"property",
"->",
"getWidgetType",
"(",
")",
")",
"{",
"continue",
";",
"}",
"$",
"modelError",
"=",
"$",
"editInformation",
"->",
"getModelError",
"(",
"$",
"model",
")",
";",
"if",
"(",
"$",
"modelError",
"&&",
"isset",
"(",
"$",
"modelError",
"[",
"$",
"propertyName",
"]",
")",
")",
"{",
"$",
"sessionValues",
"=",
"$",
"this",
"->",
"getEditPropertiesByModelId",
"(",
"$",
"action",
",",
"ModelId",
"::",
"fromModel",
"(",
"$",
"model",
")",
",",
"$",
"environment",
")",
";",
"$",
"propertyValueBag",
"->",
"setPropertyValue",
"(",
"$",
"propertyName",
",",
"$",
"sessionValues",
"[",
"$",
"propertyName",
"]",
")",
";",
"$",
"propertyValueBag",
"->",
"markPropertyValueAsInvalid",
"(",
"$",
"propertyName",
",",
"$",
"modelError",
"[",
"$",
"propertyName",
"]",
")",
";",
"continue",
";",
"}",
"$",
"propertyValueBag",
"->",
"setPropertyValue",
"(",
"$",
"propertyName",
",",
"$",
"propertyValue",
")",
";",
"}",
"return",
"$",
"propertyValueBag",
";",
"}"
]
| Get property value bag from the model.
@param Action $action The action.
@param ModelInterface $model The model.
@param EnvironmentInterface $environment The environment.
@return PropertyValueBag
@throws DcGeneralInvalidArgumentException If create property value bug, the construct argument isn´t right.
@SuppressWarnings(PHPMD.Superglobals) | [
"Get",
"property",
"value",
"bag",
"from",
"the",
"model",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/View/ActionHandler/AbstractPropertyOverrideEditAllHandler.php#L528-L562 | train |
contao-community-alliance/dc-general | src/View/ActionHandler/AbstractPropertyOverrideEditAllHandler.php | AbstractPropertyOverrideEditAllHandler.getCollectionFromSession | protected function getCollectionFromSession(Action $action, EnvironmentInterface $environment)
{
$inputProvider = $environment->getInputProvider();
$sessionStorage = $environment->getSessionStorage();
$dataDefinition = $environment->getDataDefinition();
$dataProvider = $environment->getDataProvider($dataDefinition->getName());
$addEditProperties =
$inputProvider->hasValue('FORM_INPUTS')
&& ($dataDefinition->getName() === $inputProvider->getValue('FORM_SUBMIT'));
$session = $this->getSession($action, $environment);
$editProperties = [];
$modelIds = [];
foreach ($session['models'] as $modelId) {
$modelIds[] = ModelId::fromSerialized($modelId)->getId();
if ($addEditProperties) {
$modelEditProperties = $inputProvider->getValue(\str_replace('::', '____', $modelId) . '_', true);
$inputProvider->unsetValue(\str_replace('::', '____', $modelId) . '_');
$editProperties[$modelId] = $modelEditProperties;
}
}
$idProperty = \method_exists($dataProvider, 'getIdProperty') ? $dataProvider->getIdProperty() : 'id';
$collection = $dataProvider->fetchAll(
$dataProvider->getEmptyConfig()->setFilter(
[['operation' => 'IN', 'property' => $idProperty, 'values' => $modelIds]]
)
);
$session['editProperties'] = $editProperties;
$sessionStorage->set($dataDefinition->getName() . '.' . $this->getMode($action), $session);
return $collection;
} | php | protected function getCollectionFromSession(Action $action, EnvironmentInterface $environment)
{
$inputProvider = $environment->getInputProvider();
$sessionStorage = $environment->getSessionStorage();
$dataDefinition = $environment->getDataDefinition();
$dataProvider = $environment->getDataProvider($dataDefinition->getName());
$addEditProperties =
$inputProvider->hasValue('FORM_INPUTS')
&& ($dataDefinition->getName() === $inputProvider->getValue('FORM_SUBMIT'));
$session = $this->getSession($action, $environment);
$editProperties = [];
$modelIds = [];
foreach ($session['models'] as $modelId) {
$modelIds[] = ModelId::fromSerialized($modelId)->getId();
if ($addEditProperties) {
$modelEditProperties = $inputProvider->getValue(\str_replace('::', '____', $modelId) . '_', true);
$inputProvider->unsetValue(\str_replace('::', '____', $modelId) . '_');
$editProperties[$modelId] = $modelEditProperties;
}
}
$idProperty = \method_exists($dataProvider, 'getIdProperty') ? $dataProvider->getIdProperty() : 'id';
$collection = $dataProvider->fetchAll(
$dataProvider->getEmptyConfig()->setFilter(
[['operation' => 'IN', 'property' => $idProperty, 'values' => $modelIds]]
)
);
$session['editProperties'] = $editProperties;
$sessionStorage->set($dataDefinition->getName() . '.' . $this->getMode($action), $session);
return $collection;
} | [
"protected",
"function",
"getCollectionFromSession",
"(",
"Action",
"$",
"action",
",",
"EnvironmentInterface",
"$",
"environment",
")",
"{",
"$",
"inputProvider",
"=",
"$",
"environment",
"->",
"getInputProvider",
"(",
")",
";",
"$",
"sessionStorage",
"=",
"$",
"environment",
"->",
"getSessionStorage",
"(",
")",
";",
"$",
"dataDefinition",
"=",
"$",
"environment",
"->",
"getDataDefinition",
"(",
")",
";",
"$",
"dataProvider",
"=",
"$",
"environment",
"->",
"getDataProvider",
"(",
"$",
"dataDefinition",
"->",
"getName",
"(",
")",
")",
";",
"$",
"addEditProperties",
"=",
"$",
"inputProvider",
"->",
"hasValue",
"(",
"'FORM_INPUTS'",
")",
"&&",
"(",
"$",
"dataDefinition",
"->",
"getName",
"(",
")",
"===",
"$",
"inputProvider",
"->",
"getValue",
"(",
"'FORM_SUBMIT'",
")",
")",
";",
"$",
"session",
"=",
"$",
"this",
"->",
"getSession",
"(",
"$",
"action",
",",
"$",
"environment",
")",
";",
"$",
"editProperties",
"=",
"[",
"]",
";",
"$",
"modelIds",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"session",
"[",
"'models'",
"]",
"as",
"$",
"modelId",
")",
"{",
"$",
"modelIds",
"[",
"]",
"=",
"ModelId",
"::",
"fromSerialized",
"(",
"$",
"modelId",
")",
"->",
"getId",
"(",
")",
";",
"if",
"(",
"$",
"addEditProperties",
")",
"{",
"$",
"modelEditProperties",
"=",
"$",
"inputProvider",
"->",
"getValue",
"(",
"\\",
"str_replace",
"(",
"'::'",
",",
"'____'",
",",
"$",
"modelId",
")",
".",
"'_'",
",",
"true",
")",
";",
"$",
"inputProvider",
"->",
"unsetValue",
"(",
"\\",
"str_replace",
"(",
"'::'",
",",
"'____'",
",",
"$",
"modelId",
")",
".",
"'_'",
")",
";",
"$",
"editProperties",
"[",
"$",
"modelId",
"]",
"=",
"$",
"modelEditProperties",
";",
"}",
"}",
"$",
"idProperty",
"=",
"\\",
"method_exists",
"(",
"$",
"dataProvider",
",",
"'getIdProperty'",
")",
"?",
"$",
"dataProvider",
"->",
"getIdProperty",
"(",
")",
":",
"'id'",
";",
"$",
"collection",
"=",
"$",
"dataProvider",
"->",
"fetchAll",
"(",
"$",
"dataProvider",
"->",
"getEmptyConfig",
"(",
")",
"->",
"setFilter",
"(",
"[",
"[",
"'operation'",
"=>",
"'IN'",
",",
"'property'",
"=>",
"$",
"idProperty",
",",
"'values'",
"=>",
"$",
"modelIds",
"]",
"]",
")",
")",
";",
"$",
"session",
"[",
"'editProperties'",
"]",
"=",
"$",
"editProperties",
";",
"$",
"sessionStorage",
"->",
"set",
"(",
"$",
"dataDefinition",
"->",
"getName",
"(",
")",
".",
"'.'",
".",
"$",
"this",
"->",
"getMode",
"(",
"$",
"action",
")",
",",
"$",
"session",
")",
";",
"return",
"$",
"collection",
";",
"}"
]
| Return select model collection from the session.
@param Action $action The action.
@param EnvironmentInterface $environment The environment.
@return CollectionInterface
@throws DcGeneralRuntimeException When the model id can´t parse. | [
"Return",
"select",
"model",
"collection",
"from",
"the",
"session",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/View/ActionHandler/AbstractPropertyOverrideEditAllHandler.php#L574-L613 | train |
contao-community-alliance/dc-general | src/View/ActionHandler/AbstractPropertyOverrideEditAllHandler.php | AbstractPropertyOverrideEditAllHandler.getEditPropertiesByModelId | protected function getEditPropertiesByModelId(
Action $action,
ModelIdInterface $modelId,
EnvironmentInterface $environment
) {
$session = $this->getSession($action, $environment);
return $session['editProperties'][$modelId->getSerialized()];
} | php | protected function getEditPropertiesByModelId(
Action $action,
ModelIdInterface $modelId,
EnvironmentInterface $environment
) {
$session = $this->getSession($action, $environment);
return $session['editProperties'][$modelId->getSerialized()];
} | [
"protected",
"function",
"getEditPropertiesByModelId",
"(",
"Action",
"$",
"action",
",",
"ModelIdInterface",
"$",
"modelId",
",",
"EnvironmentInterface",
"$",
"environment",
")",
"{",
"$",
"session",
"=",
"$",
"this",
"->",
"getSession",
"(",
"$",
"action",
",",
"$",
"environment",
")",
";",
"return",
"$",
"session",
"[",
"'editProperties'",
"]",
"[",
"$",
"modelId",
"->",
"getSerialized",
"(",
")",
"]",
";",
"}"
]
| Get the edit properties by model id.
@param Action $action The action.
@param ModelIdInterface $modelId The model id.
@param EnvironmentInterface $environment The environment.
@return array | [
"Get",
"the",
"edit",
"properties",
"by",
"model",
"id",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/View/ActionHandler/AbstractPropertyOverrideEditAllHandler.php#L624-L632 | train |
contao-community-alliance/dc-general | src/View/ActionHandler/AbstractPropertyOverrideEditAllHandler.php | AbstractPropertyOverrideEditAllHandler.revertValuesByErrors | protected function revertValuesByErrors(
Action $action,
CollectionInterface $collection,
EnvironmentInterface $environment
) {
$editInformation = $GLOBALS['container']['dc-general.edit-information'];
if (!$editInformation->hasAnyModelError()) {
return;
}
$dataProvider = $environment->getDataProvider();
$properties = $this->getPropertiesFromSession($action, $environment);
while ($collection->count() > 0) {
$model = $collection->shift();
$modelErrors = $editInformation->getModelError($model);
if (!$modelErrors && ('edit' === $this->getMode($action))) {
continue;
}
$revertModel = $dataProvider->fetch($dataProvider->getEmptyConfig()->setId($model->getId()));
$originalModel = clone $revertModel;
$revertModel->setId($revertModel->getId());
foreach ($properties as $property) {
if (('edit' === $this->getMode($action))
&& !\in_array($property->getName(), $modelErrors)) {
continue;
}
$revertModel->setProperty($property->getName(), $model->getProperty($property->getName()));
}
$dataProvider->save($revertModel);
$this->handlePostPersist($revertModel, $originalModel, $environment);
}
} | php | protected function revertValuesByErrors(
Action $action,
CollectionInterface $collection,
EnvironmentInterface $environment
) {
$editInformation = $GLOBALS['container']['dc-general.edit-information'];
if (!$editInformation->hasAnyModelError()) {
return;
}
$dataProvider = $environment->getDataProvider();
$properties = $this->getPropertiesFromSession($action, $environment);
while ($collection->count() > 0) {
$model = $collection->shift();
$modelErrors = $editInformation->getModelError($model);
if (!$modelErrors && ('edit' === $this->getMode($action))) {
continue;
}
$revertModel = $dataProvider->fetch($dataProvider->getEmptyConfig()->setId($model->getId()));
$originalModel = clone $revertModel;
$revertModel->setId($revertModel->getId());
foreach ($properties as $property) {
if (('edit' === $this->getMode($action))
&& !\in_array($property->getName(), $modelErrors)) {
continue;
}
$revertModel->setProperty($property->getName(), $model->getProperty($property->getName()));
}
$dataProvider->save($revertModel);
$this->handlePostPersist($revertModel, $originalModel, $environment);
}
} | [
"protected",
"function",
"revertValuesByErrors",
"(",
"Action",
"$",
"action",
",",
"CollectionInterface",
"$",
"collection",
",",
"EnvironmentInterface",
"$",
"environment",
")",
"{",
"$",
"editInformation",
"=",
"$",
"GLOBALS",
"[",
"'container'",
"]",
"[",
"'dc-general.edit-information'",
"]",
";",
"if",
"(",
"!",
"$",
"editInformation",
"->",
"hasAnyModelError",
"(",
")",
")",
"{",
"return",
";",
"}",
"$",
"dataProvider",
"=",
"$",
"environment",
"->",
"getDataProvider",
"(",
")",
";",
"$",
"properties",
"=",
"$",
"this",
"->",
"getPropertiesFromSession",
"(",
"$",
"action",
",",
"$",
"environment",
")",
";",
"while",
"(",
"$",
"collection",
"->",
"count",
"(",
")",
">",
"0",
")",
"{",
"$",
"model",
"=",
"$",
"collection",
"->",
"shift",
"(",
")",
";",
"$",
"modelErrors",
"=",
"$",
"editInformation",
"->",
"getModelError",
"(",
"$",
"model",
")",
";",
"if",
"(",
"!",
"$",
"modelErrors",
"&&",
"(",
"'edit'",
"===",
"$",
"this",
"->",
"getMode",
"(",
"$",
"action",
")",
")",
")",
"{",
"continue",
";",
"}",
"$",
"revertModel",
"=",
"$",
"dataProvider",
"->",
"fetch",
"(",
"$",
"dataProvider",
"->",
"getEmptyConfig",
"(",
")",
"->",
"setId",
"(",
"$",
"model",
"->",
"getId",
"(",
")",
")",
")",
";",
"$",
"originalModel",
"=",
"clone",
"$",
"revertModel",
";",
"$",
"revertModel",
"->",
"setId",
"(",
"$",
"revertModel",
"->",
"getId",
"(",
")",
")",
";",
"foreach",
"(",
"$",
"properties",
"as",
"$",
"property",
")",
"{",
"if",
"(",
"(",
"'edit'",
"===",
"$",
"this",
"->",
"getMode",
"(",
"$",
"action",
")",
")",
"&&",
"!",
"\\",
"in_array",
"(",
"$",
"property",
"->",
"getName",
"(",
")",
",",
"$",
"modelErrors",
")",
")",
"{",
"continue",
";",
"}",
"$",
"revertModel",
"->",
"setProperty",
"(",
"$",
"property",
"->",
"getName",
"(",
")",
",",
"$",
"model",
"->",
"getProperty",
"(",
"$",
"property",
"->",
"getName",
"(",
")",
")",
")",
";",
"}",
"$",
"dataProvider",
"->",
"save",
"(",
"$",
"revertModel",
")",
";",
"$",
"this",
"->",
"handlePostPersist",
"(",
"$",
"revertModel",
",",
"$",
"originalModel",
",",
"$",
"environment",
")",
";",
"}",
"}"
]
| Revert model values if their have errors.
@param Action $action The action.
@param CollectionInterface $collection The collection of Models.
@param EnvironmentInterface $environment The environment.
@return void
@SuppressWarnings(PHPMD.Superglobals) | [
"Revert",
"model",
"values",
"if",
"their",
"have",
"errors",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/View/ActionHandler/AbstractPropertyOverrideEditAllHandler.php#L672-L711 | train |
contao-community-alliance/dc-general | src/View/ActionHandler/AbstractPropertyOverrideEditAllHandler.php | AbstractPropertyOverrideEditAllHandler.handlePostPersist | private function handlePostPersist(
ModelInterface $model,
ModelInterface $originalModel,
EnvironmentInterface $environment
) {
$event = new PostPersistModelEvent($environment, $model, $originalModel);
$environment->getEventDispatcher()->dispatch($event::NAME, $event);
} | php | private function handlePostPersist(
ModelInterface $model,
ModelInterface $originalModel,
EnvironmentInterface $environment
) {
$event = new PostPersistModelEvent($environment, $model, $originalModel);
$environment->getEventDispatcher()->dispatch($event::NAME, $event);
} | [
"private",
"function",
"handlePostPersist",
"(",
"ModelInterface",
"$",
"model",
",",
"ModelInterface",
"$",
"originalModel",
",",
"EnvironmentInterface",
"$",
"environment",
")",
"{",
"$",
"event",
"=",
"new",
"PostPersistModelEvent",
"(",
"$",
"environment",
",",
"$",
"model",
",",
"$",
"originalModel",
")",
";",
"$",
"environment",
"->",
"getEventDispatcher",
"(",
")",
"->",
"dispatch",
"(",
"$",
"event",
"::",
"NAME",
",",
"$",
"event",
")",
";",
"}"
]
| Trigger the post persist event if available.
@param ModelInterface $model The edit model.
@param ModelInterface $originalModel The original model.
@param EnvironmentInterface $environment The environment.
@return void | [
"Trigger",
"the",
"post",
"persist",
"event",
"if",
"available",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/View/ActionHandler/AbstractPropertyOverrideEditAllHandler.php#L722-L729 | train |
contao-community-alliance/dc-general | src/DataDefinition/ModelRelationship/ParentChildCondition.php | ParentChildCondition.parseFilter | public function parseFilter($filter, $model)
{
$this->guardProviderNames(null, $model);
$applied = [
'operation' => $filter['operation'],
];
if (isset($filter['local'])) {
$applied['property'] = $filter['local'];
}
if (isset($filter['remote'])) {
$applied['value'] = $model->getProperty($filter['remote']);
}
if (isset($filter['remote_value'])) {
$applied['value'] = $filter['remote_value'];
}
if (isset($filter['value'])) {
$applied['value'] = $filter['value'];
}
if (isset($filter['children'])) {
foreach ($filter['children'] as $child) {
$applied['children'][] = $this->parseFilter($child, $model);
}
}
return $applied;
} | php | public function parseFilter($filter, $model)
{
$this->guardProviderNames(null, $model);
$applied = [
'operation' => $filter['operation'],
];
if (isset($filter['local'])) {
$applied['property'] = $filter['local'];
}
if (isset($filter['remote'])) {
$applied['value'] = $model->getProperty($filter['remote']);
}
if (isset($filter['remote_value'])) {
$applied['value'] = $filter['remote_value'];
}
if (isset($filter['value'])) {
$applied['value'] = $filter['value'];
}
if (isset($filter['children'])) {
foreach ($filter['children'] as $child) {
$applied['children'][] = $this->parseFilter($child, $model);
}
}
return $applied;
} | [
"public",
"function",
"parseFilter",
"(",
"$",
"filter",
",",
"$",
"model",
")",
"{",
"$",
"this",
"->",
"guardProviderNames",
"(",
"null",
",",
"$",
"model",
")",
";",
"$",
"applied",
"=",
"[",
"'operation'",
"=>",
"$",
"filter",
"[",
"'operation'",
"]",
",",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"filter",
"[",
"'local'",
"]",
")",
")",
"{",
"$",
"applied",
"[",
"'property'",
"]",
"=",
"$",
"filter",
"[",
"'local'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"filter",
"[",
"'remote'",
"]",
")",
")",
"{",
"$",
"applied",
"[",
"'value'",
"]",
"=",
"$",
"model",
"->",
"getProperty",
"(",
"$",
"filter",
"[",
"'remote'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"filter",
"[",
"'remote_value'",
"]",
")",
")",
"{",
"$",
"applied",
"[",
"'value'",
"]",
"=",
"$",
"filter",
"[",
"'remote_value'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"filter",
"[",
"'value'",
"]",
")",
")",
"{",
"$",
"applied",
"[",
"'value'",
"]",
"=",
"$",
"filter",
"[",
"'value'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"filter",
"[",
"'children'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"filter",
"[",
"'children'",
"]",
"as",
"$",
"child",
")",
"{",
"$",
"applied",
"[",
"'children'",
"]",
"[",
"]",
"=",
"$",
"this",
"->",
"parseFilter",
"(",
"$",
"child",
",",
"$",
"model",
")",
";",
"}",
"}",
"return",
"$",
"applied",
";",
"}"
]
| Apply the filter values for a given model to the given rule.
@param array $filter The filter rule to which the values shall get applied.
@param ModelInterface $model The model to fetch the values from.
@return array | [
"Apply",
"the",
"filter",
"values",
"for",
"a",
"given",
"model",
"to",
"the",
"given",
"rule",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/DataDefinition/ModelRelationship/ParentChildCondition.php#L175-L206 | train |
contao-community-alliance/dc-general | src/DataDefinition/ModelRelationship/ParentChildCondition.php | ParentChildCondition.isValidSetter | private function isValidSetter($setter)
{
return (\is_array($setter)
&& (2 === \count($setter))
&& isset($setter['to_field'])
&& (isset($setter['from_field']) || isset($setter['value'])));
} | php | private function isValidSetter($setter)
{
return (\is_array($setter)
&& (2 === \count($setter))
&& isset($setter['to_field'])
&& (isset($setter['from_field']) || isset($setter['value'])));
} | [
"private",
"function",
"isValidSetter",
"(",
"$",
"setter",
")",
"{",
"return",
"(",
"\\",
"is_array",
"(",
"$",
"setter",
")",
"&&",
"(",
"2",
"===",
"\\",
"count",
"(",
"$",
"setter",
")",
")",
"&&",
"isset",
"(",
"$",
"setter",
"[",
"'to_field'",
"]",
")",
"&&",
"(",
"isset",
"(",
"$",
"setter",
"[",
"'from_field'",
"]",
")",
"||",
"isset",
"(",
"$",
"setter",
"[",
"'value'",
"]",
")",
")",
")",
";",
"}"
]
| Check if the passed value is a valid setter.
@param array $setter The setter.
@return bool | [
"Check",
"if",
"the",
"passed",
"value",
"is",
"a",
"valid",
"setter",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/DataDefinition/ModelRelationship/ParentChildCondition.php#L234-L240 | train |
contao-community-alliance/dc-general | src/DataDefinition/ModelRelationship/ParentChildCondition.php | ParentChildCondition.extractNeededProperties | private function extractNeededProperties($rule)
{
if (\in_array($rule['operation'], ['AND', 'OR'])) {
$properties = [];
foreach ($rule['children'] as $childRule) {
$properties[] = $this->extractNeededProperties($childRule);
}
return $properties;
}
// Local is child property name.
if (isset($rule['local'])) {
return $rule['local'];
}
// Remote is parent property name.
if (isset($rule['property'])) {
return $rule['property'];
}
throw new \RuntimeException('Unexpected filter rule ' . \var_export($rule, true));
} | php | private function extractNeededProperties($rule)
{
if (\in_array($rule['operation'], ['AND', 'OR'])) {
$properties = [];
foreach ($rule['children'] as $childRule) {
$properties[] = $this->extractNeededProperties($childRule);
}
return $properties;
}
// Local is child property name.
if (isset($rule['local'])) {
return $rule['local'];
}
// Remote is parent property name.
if (isset($rule['property'])) {
return $rule['property'];
}
throw new \RuntimeException('Unexpected filter rule ' . \var_export($rule, true));
} | [
"private",
"function",
"extractNeededProperties",
"(",
"$",
"rule",
")",
"{",
"if",
"(",
"\\",
"in_array",
"(",
"$",
"rule",
"[",
"'operation'",
"]",
",",
"[",
"'AND'",
",",
"'OR'",
"]",
")",
")",
"{",
"$",
"properties",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"rule",
"[",
"'children'",
"]",
"as",
"$",
"childRule",
")",
"{",
"$",
"properties",
"[",
"]",
"=",
"$",
"this",
"->",
"extractNeededProperties",
"(",
"$",
"childRule",
")",
";",
"}",
"return",
"$",
"properties",
";",
"}",
"// Local is child property name.",
"if",
"(",
"isset",
"(",
"$",
"rule",
"[",
"'local'",
"]",
")",
")",
"{",
"return",
"$",
"rule",
"[",
"'local'",
"]",
";",
"}",
"// Remote is parent property name.",
"if",
"(",
"isset",
"(",
"$",
"rule",
"[",
"'property'",
"]",
")",
")",
"{",
"return",
"$",
"rule",
"[",
"'property'",
"]",
";",
"}",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'Unexpected filter rule '",
".",
"\\",
"var_export",
"(",
"$",
"rule",
",",
"true",
")",
")",
";",
"}"
]
| Return the names of the needed properties for filtering.
@param array $rule The filter rule from which the properties shall be extracted from.
@return array
@throws \RuntimeException When an unexpected filter rule is encountered. | [
"Return",
"the",
"names",
"of",
"the",
"needed",
"properties",
"for",
"filtering",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/DataDefinition/ModelRelationship/ParentChildCondition.php#L432-L453 | train |
contao-community-alliance/dc-general | src/DataDefinition/ModelRelationship/ParentChildCondition.php | ParentChildCondition.guardProviderNames | private function guardProviderNames($child, $parent = null)
{
if (null !== $child && $child->getProviderName() !== $this->destinationProvider) {
throw new \InvalidArgumentException(
\sprintf('provider name %s is not equal to %s', $child->getProviderName(), $this->destinationProvider)
);
}
if (null !== $parent && $parent->getProviderName() !== $this->sourceProvider) {
throw new \InvalidArgumentException(
\sprintf('provider name %s is not equal to %s', $parent->getProviderName(), $this->sourceProvider)
);
}
} | php | private function guardProviderNames($child, $parent = null)
{
if (null !== $child && $child->getProviderName() !== $this->destinationProvider) {
throw new \InvalidArgumentException(
\sprintf('provider name %s is not equal to %s', $child->getProviderName(), $this->destinationProvider)
);
}
if (null !== $parent && $parent->getProviderName() !== $this->sourceProvider) {
throw new \InvalidArgumentException(
\sprintf('provider name %s is not equal to %s', $parent->getProviderName(), $this->sourceProvider)
);
}
} | [
"private",
"function",
"guardProviderNames",
"(",
"$",
"child",
",",
"$",
"parent",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"!==",
"$",
"child",
"&&",
"$",
"child",
"->",
"getProviderName",
"(",
")",
"!==",
"$",
"this",
"->",
"destinationProvider",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\\",
"sprintf",
"(",
"'provider name %s is not equal to %s'",
",",
"$",
"child",
"->",
"getProviderName",
"(",
")",
",",
"$",
"this",
"->",
"destinationProvider",
")",
")",
";",
"}",
"if",
"(",
"null",
"!==",
"$",
"parent",
"&&",
"$",
"parent",
"->",
"getProviderName",
"(",
")",
"!==",
"$",
"this",
"->",
"sourceProvider",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\\",
"sprintf",
"(",
"'provider name %s is not equal to %s'",
",",
"$",
"parent",
"->",
"getProviderName",
"(",
")",
",",
"$",
"this",
"->",
"sourceProvider",
")",
")",
";",
"}",
"}"
]
| Guard that the data provider names match.
@param ModelInterface|null $child The child model.
@param ModelInterface|null $parent The parent model.
@return void
@throws \InvalidArgumentException When any provider name mismatches. | [
"Guard",
"that",
"the",
"data",
"provider",
"names",
"match",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/DataDefinition/ModelRelationship/ParentChildCondition.php#L482-L494 | train |
contao-community-alliance/dc-general | src/Data/DefaultCollection.php | DefaultCollection.get | public function get($index)
{
if (\array_key_exists($index, $this->arrCollection)) {
return $this->arrCollection[$index];
}
return null;
} | php | public function get($index)
{
if (\array_key_exists($index, $this->arrCollection)) {
return $this->arrCollection[$index];
}
return null;
} | [
"public",
"function",
"get",
"(",
"$",
"index",
")",
"{",
"if",
"(",
"\\",
"array_key_exists",
"(",
"$",
"index",
",",
"$",
"this",
"->",
"arrCollection",
")",
")",
"{",
"return",
"$",
"this",
"->",
"arrCollection",
"[",
"$",
"index",
"]",
";",
"}",
"return",
"null",
";",
"}"
]
| Get the model at a specific index.
@param int $index The index of the model to retrieve.
@return ModelInterface | [
"Get",
"the",
"model",
"at",
"a",
"specific",
"index",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Data/DefaultCollection.php#L104-L111 | train |
contao-community-alliance/dc-general | src/Data/DefaultCollection.php | DefaultCollection.insert | public function insert($index, ModelInterface $model)
{
if ($model->hasProperties()) {
\array_insert($this->arrCollection, $index, [$model]);
}
} | php | public function insert($index, ModelInterface $model)
{
if ($model->hasProperties()) {
\array_insert($this->arrCollection, $index, [$model]);
}
} | [
"public",
"function",
"insert",
"(",
"$",
"index",
",",
"ModelInterface",
"$",
"model",
")",
"{",
"if",
"(",
"$",
"model",
"->",
"hasProperties",
"(",
")",
")",
"{",
"\\",
"array_insert",
"(",
"$",
"this",
"->",
"arrCollection",
",",
"$",
"index",
",",
"[",
"$",
"model",
"]",
")",
";",
"}",
"}"
]
| Insert a record at the specific position.
Move all records at position >= $index one index up.
If $index is out of bounds, just add at the end (does not fill with empty records!).
@param int $index The index where the model shall be placed.
@param ModelInterface $model The model to insert.
@return void | [
"Insert",
"a",
"record",
"at",
"the",
"specific",
"position",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Data/DefaultCollection.php#L188-L193 | train |
contao-community-alliance/dc-general | src/Data/DefaultCollection.php | DefaultCollection.remove | public function remove($indexValue)
{
if (\is_object($indexValue)) {
foreach ($this->arrCollection as $collectionIndex => $model) {
if ($indexValue === $model) {
unset($this->arrCollection[$collectionIndex]);
}
}
} else {
unset($this->arrCollection[$indexValue]);
}
$this->arrCollection = \array_values($this->arrCollection);
} | php | public function remove($indexValue)
{
if (\is_object($indexValue)) {
foreach ($this->arrCollection as $collectionIndex => $model) {
if ($indexValue === $model) {
unset($this->arrCollection[$collectionIndex]);
}
}
} else {
unset($this->arrCollection[$indexValue]);
}
$this->arrCollection = \array_values($this->arrCollection);
} | [
"public",
"function",
"remove",
"(",
"$",
"indexValue",
")",
"{",
"if",
"(",
"\\",
"is_object",
"(",
"$",
"indexValue",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"arrCollection",
"as",
"$",
"collectionIndex",
"=>",
"$",
"model",
")",
"{",
"if",
"(",
"$",
"indexValue",
"===",
"$",
"model",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"arrCollection",
"[",
"$",
"collectionIndex",
"]",
")",
";",
"}",
"}",
"}",
"else",
"{",
"unset",
"(",
"$",
"this",
"->",
"arrCollection",
"[",
"$",
"indexValue",
"]",
")",
";",
"}",
"$",
"this",
"->",
"arrCollection",
"=",
"\\",
"array_values",
"(",
"$",
"this",
"->",
"arrCollection",
")",
";",
"}"
]
| Remove the given index or model from the collection and renew the index.
ATTENTION: Don't use key to unset in foreach because of the new index.
@param mixed $indexValue The index (integer) or InterfaceGeneralModel instance to remove.
@return void | [
"Remove",
"the",
"given",
"index",
"or",
"model",
"from",
"the",
"collection",
"and",
"renew",
"the",
"index",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Data/DefaultCollection.php#L204-L217 | train |
contao-community-alliance/dc-general | src/Data/DefaultCollection.php | DefaultCollection.removeById | public function removeById($modelId)
{
foreach ($this->arrCollection as $index => $model) {
if ($modelId === $model->getId()) {
unset($this->arrCollection[$index]);
}
}
} | php | public function removeById($modelId)
{
foreach ($this->arrCollection as $index => $model) {
if ($modelId === $model->getId()) {
unset($this->arrCollection[$index]);
}
}
} | [
"public",
"function",
"removeById",
"(",
"$",
"modelId",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"arrCollection",
"as",
"$",
"index",
"=>",
"$",
"model",
")",
"{",
"if",
"(",
"$",
"modelId",
"===",
"$",
"model",
"->",
"getId",
"(",
")",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"arrCollection",
"[",
"$",
"index",
"]",
")",
";",
"}",
"}",
"}"
]
| Remove the model with the given id from the collection.
@param mixed $modelId The id of the model to remove.
@return void | [
"Remove",
"the",
"model",
"with",
"the",
"given",
"id",
"from",
"the",
"collection",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Data/DefaultCollection.php#L242-L249 | train |
contao-community-alliance/dc-general | src/Data/DefaultCollection.php | DefaultCollection.containsById | public function containsById($modelId)
{
/** @var ModelInterface $localModel */
foreach ($this as $localModel) {
if ($modelId === $localModel->getId()) {
return true;
}
}
return false;
} | php | public function containsById($modelId)
{
/** @var ModelInterface $localModel */
foreach ($this as $localModel) {
if ($modelId === $localModel->getId()) {
return true;
}
}
return false;
} | [
"public",
"function",
"containsById",
"(",
"$",
"modelId",
")",
"{",
"/** @var ModelInterface $localModel */",
"foreach",
"(",
"$",
"this",
"as",
"$",
"localModel",
")",
"{",
"if",
"(",
"$",
"modelId",
"===",
"$",
"localModel",
"->",
"getId",
"(",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
]
| Check whether the given model is contained in the collection.
@param mixed $modelId The model id to search.
@return bool | [
"Check",
"whether",
"the",
"given",
"model",
"is",
"contained",
"in",
"the",
"collection",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Data/DefaultCollection.php#L277-L287 | train |
contao-community-alliance/dc-general | src/Data/DefaultCollection.php | DefaultCollection.intersect | public function intersect($collection)
{
$intersection = new DefaultCollection();
/** @var ModelInterface $localModel */
foreach ($this as $localModel) {
/** @var ModelInterface $otherModel */
foreach ($collection as $otherModel) {
if (($localModel->getProviderName() === $otherModel->getProviderName())
&& ($localModel->getId() === $otherModel->getId())
) {
$intersection->push($localModel);
}
}
}
return $intersection;
} | php | public function intersect($collection)
{
$intersection = new DefaultCollection();
/** @var ModelInterface $localModel */
foreach ($this as $localModel) {
/** @var ModelInterface $otherModel */
foreach ($collection as $otherModel) {
if (($localModel->getProviderName() === $otherModel->getProviderName())
&& ($localModel->getId() === $otherModel->getId())
) {
$intersection->push($localModel);
}
}
}
return $intersection;
} | [
"public",
"function",
"intersect",
"(",
"$",
"collection",
")",
"{",
"$",
"intersection",
"=",
"new",
"DefaultCollection",
"(",
")",
";",
"/** @var ModelInterface $localModel */",
"foreach",
"(",
"$",
"this",
"as",
"$",
"localModel",
")",
"{",
"/** @var ModelInterface $otherModel */",
"foreach",
"(",
"$",
"collection",
"as",
"$",
"otherModel",
")",
"{",
"if",
"(",
"(",
"$",
"localModel",
"->",
"getProviderName",
"(",
")",
"===",
"$",
"otherModel",
"->",
"getProviderName",
"(",
")",
")",
"&&",
"(",
"$",
"localModel",
"->",
"getId",
"(",
")",
"===",
"$",
"otherModel",
"->",
"getId",
"(",
")",
")",
")",
"{",
"$",
"intersection",
"->",
"push",
"(",
"$",
"localModel",
")",
";",
"}",
"}",
"}",
"return",
"$",
"intersection",
";",
"}"
]
| Intersect the given collection with this collection and return the result.
@param CollectionInterface $collection The collection to intersect.
@return CollectionInterface | [
"Intersect",
"the",
"given",
"collection",
"with",
"this",
"collection",
"and",
"return",
"the",
"result",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Data/DefaultCollection.php#L296-L312 | train |
contao-community-alliance/dc-general | src/Data/DefaultCollection.php | DefaultCollection.union | public function union($collection)
{
$union = clone $this;
/** @var ModelInterface $otherModel */
foreach ($collection->diff($this) as $otherModel) {
$union->push($otherModel);
}
return $union;
} | php | public function union($collection)
{
$union = clone $this;
/** @var ModelInterface $otherModel */
foreach ($collection->diff($this) as $otherModel) {
$union->push($otherModel);
}
return $union;
} | [
"public",
"function",
"union",
"(",
"$",
"collection",
")",
"{",
"$",
"union",
"=",
"clone",
"$",
"this",
";",
"/** @var ModelInterface $otherModel */",
"foreach",
"(",
"$",
"collection",
"->",
"diff",
"(",
"$",
"this",
")",
"as",
"$",
"otherModel",
")",
"{",
"$",
"union",
"->",
"push",
"(",
"$",
"otherModel",
")",
";",
"}",
"return",
"$",
"union",
";",
"}"
]
| Compute the union of this collection and the given collection.
@param CollectionInterface $collection The collection to intersect.
@return CollectionInterface | [
"Compute",
"the",
"union",
"of",
"this",
"collection",
"and",
"the",
"given",
"collection",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Data/DefaultCollection.php#L321-L331 | train |
contao-community-alliance/dc-general | src/Data/DefaultCollection.php | DefaultCollection.diff | public function diff($collection)
{
$diff = new DefaultCollection();
/** @var ModelInterface $localModel */
foreach ($this as $localModel) {
/** @var ModelInterface $otherModel */
foreach ($collection as $otherModel) {
if (($localModel->getProviderName() === $otherModel->getProviderName())
&& ($localModel->getId() === $otherModel->getId())
) {
continue;
}
$diff->push($localModel);
}
}
return $diff;
} | php | public function diff($collection)
{
$diff = new DefaultCollection();
/** @var ModelInterface $localModel */
foreach ($this as $localModel) {
/** @var ModelInterface $otherModel */
foreach ($collection as $otherModel) {
if (($localModel->getProviderName() === $otherModel->getProviderName())
&& ($localModel->getId() === $otherModel->getId())
) {
continue;
}
$diff->push($localModel);
}
}
return $diff;
} | [
"public",
"function",
"diff",
"(",
"$",
"collection",
")",
"{",
"$",
"diff",
"=",
"new",
"DefaultCollection",
"(",
")",
";",
"/** @var ModelInterface $localModel */",
"foreach",
"(",
"$",
"this",
"as",
"$",
"localModel",
")",
"{",
"/** @var ModelInterface $otherModel */",
"foreach",
"(",
"$",
"collection",
"as",
"$",
"otherModel",
")",
"{",
"if",
"(",
"(",
"$",
"localModel",
"->",
"getProviderName",
"(",
")",
"===",
"$",
"otherModel",
"->",
"getProviderName",
"(",
")",
")",
"&&",
"(",
"$",
"localModel",
"->",
"getId",
"(",
")",
"===",
"$",
"otherModel",
"->",
"getId",
"(",
")",
")",
")",
"{",
"continue",
";",
"}",
"$",
"diff",
"->",
"push",
"(",
"$",
"localModel",
")",
";",
"}",
"}",
"return",
"$",
"diff",
";",
"}"
]
| Computes the difference of the collection.
@param CollectionInterface $collection The collection to compute the difference for.
@return CollectionInterface The collection containing all the entries from this collection that are not present
in the given collection. | [
"Computes",
"the",
"difference",
"of",
"the",
"collection",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Data/DefaultCollection.php#L341-L358 | train |
contao-community-alliance/dc-general | src/Data/DefaultCollection.php | DefaultCollection.isSubsetOf | public function isSubsetOf($collection)
{
/** @var ModelInterface $localModel */
foreach ($this as $localModel) {
/** @var ModelInterface $otherModel */
foreach ($collection as $otherModel) {
if (($localModel->getProviderName() === $otherModel->getProviderName())
&& ($localModel->getId() === $otherModel->getId())
) {
continue;
}
return false;
}
}
return true;
} | php | public function isSubsetOf($collection)
{
/** @var ModelInterface $localModel */
foreach ($this as $localModel) {
/** @var ModelInterface $otherModel */
foreach ($collection as $otherModel) {
if (($localModel->getProviderName() === $otherModel->getProviderName())
&& ($localModel->getId() === $otherModel->getId())
) {
continue;
}
return false;
}
}
return true;
} | [
"public",
"function",
"isSubsetOf",
"(",
"$",
"collection",
")",
"{",
"/** @var ModelInterface $localModel */",
"foreach",
"(",
"$",
"this",
"as",
"$",
"localModel",
")",
"{",
"/** @var ModelInterface $otherModel */",
"foreach",
"(",
"$",
"collection",
"as",
"$",
"otherModel",
")",
"{",
"if",
"(",
"(",
"$",
"localModel",
"->",
"getProviderName",
"(",
")",
"===",
"$",
"otherModel",
"->",
"getProviderName",
"(",
")",
")",
"&&",
"(",
"$",
"localModel",
"->",
"getId",
"(",
")",
"===",
"$",
"otherModel",
"->",
"getId",
"(",
")",
")",
")",
"{",
"continue",
";",
"}",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
]
| Check if the given collection is an subset of the given collection.
@param CollectionInterface $collection The collection to check.
@return boolean | [
"Check",
"if",
"the",
"given",
"collection",
"is",
"an",
"subset",
"of",
"the",
"given",
"collection",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Data/DefaultCollection.php#L367-L382 | train |
contao-community-alliance/dc-general | src/Data/DefaultCollection.php | DefaultCollection.sort | public function sort($callback)
{
$newCollection = clone $this;
\uasort($newCollection->arrCollection, $callback);
$newCollection->arrCollection = \array_values($newCollection->arrCollection);
return $newCollection;
} | php | public function sort($callback)
{
$newCollection = clone $this;
\uasort($newCollection->arrCollection, $callback);
$newCollection->arrCollection = \array_values($newCollection->arrCollection);
return $newCollection;
} | [
"public",
"function",
"sort",
"(",
"$",
"callback",
")",
"{",
"$",
"newCollection",
"=",
"clone",
"$",
"this",
";",
"\\",
"uasort",
"(",
"$",
"newCollection",
"->",
"arrCollection",
",",
"$",
"callback",
")",
";",
"$",
"newCollection",
"->",
"arrCollection",
"=",
"\\",
"array_values",
"(",
"$",
"newCollection",
"->",
"arrCollection",
")",
";",
"return",
"$",
"newCollection",
";",
"}"
]
| Sort the records with the given callback and return the new sorted collection.
@param callback $callback The callback function to use.
@return CollectionInterface | [
"Sort",
"the",
"records",
"with",
"the",
"given",
"callback",
"and",
"return",
"the",
"new",
"sorted",
"collection",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Data/DefaultCollection.php#L405-L413 | train |
contao-community-alliance/dc-general | src/Contao/Dca/Populator/ParentDefinitionPopulator.php | ParentDefinitionPopulator.populateController | public function populateController(EnvironmentInterface $environment)
{
$definition = $environment->getDataDefinition();
if (!$definition->getBasicDefinition()->getParentDataProvider()) {
return;
}
$parentDefinition = (new DcGeneralFactory())
->setEventDispatcher($environment->getEventDispatcher())
->setTranslator($environment->getTranslator())
->setContainerName($definition->getBasicDefinition()->getParentDataProvider())
->createDcGeneral()
->getEnvironment()
->getDataDefinition();
$environment->setParentDataDefinition($parentDefinition);
} | php | public function populateController(EnvironmentInterface $environment)
{
$definition = $environment->getDataDefinition();
if (!$definition->getBasicDefinition()->getParentDataProvider()) {
return;
}
$parentDefinition = (new DcGeneralFactory())
->setEventDispatcher($environment->getEventDispatcher())
->setTranslator($environment->getTranslator())
->setContainerName($definition->getBasicDefinition()->getParentDataProvider())
->createDcGeneral()
->getEnvironment()
->getDataDefinition();
$environment->setParentDataDefinition($parentDefinition);
} | [
"public",
"function",
"populateController",
"(",
"EnvironmentInterface",
"$",
"environment",
")",
"{",
"$",
"definition",
"=",
"$",
"environment",
"->",
"getDataDefinition",
"(",
")",
";",
"if",
"(",
"!",
"$",
"definition",
"->",
"getBasicDefinition",
"(",
")",
"->",
"getParentDataProvider",
"(",
")",
")",
"{",
"return",
";",
"}",
"$",
"parentDefinition",
"=",
"(",
"new",
"DcGeneralFactory",
"(",
")",
")",
"->",
"setEventDispatcher",
"(",
"$",
"environment",
"->",
"getEventDispatcher",
"(",
")",
")",
"->",
"setTranslator",
"(",
"$",
"environment",
"->",
"getTranslator",
"(",
")",
")",
"->",
"setContainerName",
"(",
"$",
"definition",
"->",
"getBasicDefinition",
"(",
")",
"->",
"getParentDataProvider",
"(",
")",
")",
"->",
"createDcGeneral",
"(",
")",
"->",
"getEnvironment",
"(",
")",
"->",
"getDataDefinition",
"(",
")",
";",
"$",
"environment",
"->",
"setParentDataDefinition",
"(",
"$",
"parentDefinition",
")",
";",
"}"
]
| Create a parent data definition, if parent data provider defined.
@param EnvironmentInterface $environment The environment to populate.
@return void
@internal | [
"Create",
"a",
"parent",
"data",
"definition",
"if",
"parent",
"data",
"provider",
"defined",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/Dca/Populator/ParentDefinitionPopulator.php#L44-L61 | train |
contao-community-alliance/dc-general | src/DataDefinition/Palette/Builder/Event/CreatePropertyValueConditionEvent.php | CreatePropertyValueConditionEvent.setPropertyValueCondition | public function setPropertyValueCondition($condition)
{
if (!($condition instanceof PalettePropertyValueCondition)
&& (!$condition instanceof PropertyValueCondition)
) {
throw new DcGeneralInvalidArgumentException(
'The condition is invalid. ' .
' Only use PalettePropertyValueCondition or PropertyValueCondition.'
);
}
$this->condition = $condition;
return $this;
} | php | public function setPropertyValueCondition($condition)
{
if (!($condition instanceof PalettePropertyValueCondition)
&& (!$condition instanceof PropertyValueCondition)
) {
throw new DcGeneralInvalidArgumentException(
'The condition is invalid. ' .
' Only use PalettePropertyValueCondition or PropertyValueCondition.'
);
}
$this->condition = $condition;
return $this;
} | [
"public",
"function",
"setPropertyValueCondition",
"(",
"$",
"condition",
")",
"{",
"if",
"(",
"!",
"(",
"$",
"condition",
"instanceof",
"PalettePropertyValueCondition",
")",
"&&",
"(",
"!",
"$",
"condition",
"instanceof",
"PropertyValueCondition",
")",
")",
"{",
"throw",
"new",
"DcGeneralInvalidArgumentException",
"(",
"'The condition is invalid. '",
".",
"' Only use PalettePropertyValueCondition or PropertyValueCondition.'",
")",
";",
"}",
"$",
"this",
"->",
"condition",
"=",
"$",
"condition",
";",
"return",
"$",
"this",
";",
"}"
]
| Set the property value condition.
@param PalettePropertyValueCondition|PropertyValueCondition $condition The property value condition.
@return CreatePropertyValueConditionEvent
@throws DcGeneralInvalidArgumentException When an invalid condition has been passed. | [
"Set",
"the",
"property",
"value",
"condition",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/DataDefinition/Palette/Builder/Event/CreatePropertyValueConditionEvent.php#L66-L79 | train |
contao-community-alliance/dc-general | src/DataDefinition/ModelRelationship/FilterBuilder.php | FilterBuilder.getBuilderFromArray | public static function getBuilderFromArray($filter, $builder)
{
switch ($filter['operation']) {
case 'AND':
return AndFilterBuilder::fromArray($filter, $builder);
case 'OR':
return OrFilterBuilder::fromArray($filter, $builder);
case '=':
return PropertyEqualsFilterBuilder::fromArray($filter);
case '>':
return PropertyGreaterThanFilterBuilder::fromArray($filter);
case '<':
return PropertyLessThanFilterBuilder::fromArray($filter);
case 'IN':
return PropertyValueInFilterBuilder::fromArray($filter);
case 'LIKE':
return PropertyValueLikeFilterBuilder::fromArray($filter);
default:
}
throw new DcGeneralInvalidArgumentException(
'Invalid operation ' . $filter['operation'] . ' it must be one of: AND, OR, =, >, <, IN, LIKE'
);
} | php | public static function getBuilderFromArray($filter, $builder)
{
switch ($filter['operation']) {
case 'AND':
return AndFilterBuilder::fromArray($filter, $builder);
case 'OR':
return OrFilterBuilder::fromArray($filter, $builder);
case '=':
return PropertyEqualsFilterBuilder::fromArray($filter);
case '>':
return PropertyGreaterThanFilterBuilder::fromArray($filter);
case '<':
return PropertyLessThanFilterBuilder::fromArray($filter);
case 'IN':
return PropertyValueInFilterBuilder::fromArray($filter);
case 'LIKE':
return PropertyValueLikeFilterBuilder::fromArray($filter);
default:
}
throw new DcGeneralInvalidArgumentException(
'Invalid operation ' . $filter['operation'] . ' it must be one of: AND, OR, =, >, <, IN, LIKE'
);
} | [
"public",
"static",
"function",
"getBuilderFromArray",
"(",
"$",
"filter",
",",
"$",
"builder",
")",
"{",
"switch",
"(",
"$",
"filter",
"[",
"'operation'",
"]",
")",
"{",
"case",
"'AND'",
":",
"return",
"AndFilterBuilder",
"::",
"fromArray",
"(",
"$",
"filter",
",",
"$",
"builder",
")",
";",
"case",
"'OR'",
":",
"return",
"OrFilterBuilder",
"::",
"fromArray",
"(",
"$",
"filter",
",",
"$",
"builder",
")",
";",
"case",
"'='",
":",
"return",
"PropertyEqualsFilterBuilder",
"::",
"fromArray",
"(",
"$",
"filter",
")",
";",
"case",
"'>'",
":",
"return",
"PropertyGreaterThanFilterBuilder",
"::",
"fromArray",
"(",
"$",
"filter",
")",
";",
"case",
"'<'",
":",
"return",
"PropertyLessThanFilterBuilder",
"::",
"fromArray",
"(",
"$",
"filter",
")",
";",
"case",
"'IN'",
":",
"return",
"PropertyValueInFilterBuilder",
"::",
"fromArray",
"(",
"$",
"filter",
")",
";",
"case",
"'LIKE'",
":",
"return",
"PropertyValueLikeFilterBuilder",
"::",
"fromArray",
"(",
"$",
"filter",
")",
";",
"default",
":",
"}",
"throw",
"new",
"DcGeneralInvalidArgumentException",
"(",
"'Invalid operation '",
".",
"$",
"filter",
"[",
"'operation'",
"]",
".",
"' it must be one of: AND, OR, =, >, <, IN, LIKE'",
")",
";",
"}"
]
| Instantiate the correct builder class from a given filter array.
@param array $filter The filter.
@param FilterBuilder $builder The builder instance.
@return BaseFilterBuilder
@throws DcGeneralInvalidArgumentException When an invalid operation is encountered. | [
"Instantiate",
"the",
"correct",
"builder",
"class",
"from",
"a",
"given",
"filter",
"array",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/DataDefinition/ModelRelationship/FilterBuilder.php#L83-L106 | train |
contao-community-alliance/dc-general | src/DataDefinition/ModelRelationship/FilterBuilder.php | FilterBuilder.encapsulateOr | public function encapsulateOr()
{
$root = $this->filters;
$this->filters = new AndFilterBuilder();
$this->filters->setBuilder($this);
$orFilter = new OrFilterBuilder([$root]);
$this->filters->add($orFilter);
return $orFilter;
} | php | public function encapsulateOr()
{
$root = $this->filters;
$this->filters = new AndFilterBuilder();
$this->filters->setBuilder($this);
$orFilter = new OrFilterBuilder([$root]);
$this->filters->add($orFilter);
return $orFilter;
} | [
"public",
"function",
"encapsulateOr",
"(",
")",
"{",
"$",
"root",
"=",
"$",
"this",
"->",
"filters",
";",
"$",
"this",
"->",
"filters",
"=",
"new",
"AndFilterBuilder",
"(",
")",
";",
"$",
"this",
"->",
"filters",
"->",
"setBuilder",
"(",
"$",
"this",
")",
";",
"$",
"orFilter",
"=",
"new",
"OrFilterBuilder",
"(",
"[",
"$",
"root",
"]",
")",
";",
"$",
"this",
"->",
"filters",
"->",
"add",
"(",
"$",
"orFilter",
")",
";",
"return",
"$",
"orFilter",
";",
"}"
]
| Encapsulate the root with an Or condition and return the OR condition.
@return OrFilterBuilder | [
"Encapsulate",
"the",
"root",
"with",
"an",
"Or",
"condition",
"and",
"return",
"the",
"OR",
"condition",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/DataDefinition/ModelRelationship/FilterBuilder.php#L147-L158 | train |
contao-community-alliance/dc-general | src/DataDefinition/ModelRelationship/RootCondition.php | RootCondition.guardProviderName | private function guardProviderName($model)
{
if ($model->getProviderName() !== $this->sourceProvider) {
throw new \InvalidArgumentException(
\sprintf('provider name %s is not equal to %s', $model->getProviderName(), $this->getSourceName())
);
}
} | php | private function guardProviderName($model)
{
if ($model->getProviderName() !== $this->sourceProvider) {
throw new \InvalidArgumentException(
\sprintf('provider name %s is not equal to %s', $model->getProviderName(), $this->getSourceName())
);
}
} | [
"private",
"function",
"guardProviderName",
"(",
"$",
"model",
")",
"{",
"if",
"(",
"$",
"model",
"->",
"getProviderName",
"(",
")",
"!==",
"$",
"this",
"->",
"sourceProvider",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\\",
"sprintf",
"(",
"'provider name %s is not equal to %s'",
",",
"$",
"model",
"->",
"getProviderName",
"(",
")",
",",
"$",
"this",
"->",
"getSourceName",
"(",
")",
")",
")",
";",
"}",
"}"
]
| Guard that the data provider name matches.
@param ModelInterface $model The model.
@return void
@throws \InvalidArgumentException When any provider name mismatches. | [
"Guard",
"that",
"the",
"data",
"provider",
"name",
"matches",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/DataDefinition/ModelRelationship/RootCondition.php#L173-L180 | train |
contao-community-alliance/dc-general | src/Contao/View/Contao2BackendView/EventListener/BackButtonListener.php | BackButtonListener.getReferrerUrl | private function getReferrerUrl(EnvironmentInterface $environment)
{
$parent = $environment->getParentDataDefinition();
$event = new GetReferrerEvent(
true,
(null !== $parent)
? $parent->getName()
: $environment->getDataDefinition()->getName()
);
$environment->getEventDispatcher()->dispatch(ContaoEvents::SYSTEM_GET_REFERRER, $event);
return $event->getReferrerUrl();
} | php | private function getReferrerUrl(EnvironmentInterface $environment)
{
$parent = $environment->getParentDataDefinition();
$event = new GetReferrerEvent(
true,
(null !== $parent)
? $parent->getName()
: $environment->getDataDefinition()->getName()
);
$environment->getEventDispatcher()->dispatch(ContaoEvents::SYSTEM_GET_REFERRER, $event);
return $event->getReferrerUrl();
} | [
"private",
"function",
"getReferrerUrl",
"(",
"EnvironmentInterface",
"$",
"environment",
")",
"{",
"$",
"parent",
"=",
"$",
"environment",
"->",
"getParentDataDefinition",
"(",
")",
";",
"$",
"event",
"=",
"new",
"GetReferrerEvent",
"(",
"true",
",",
"(",
"null",
"!==",
"$",
"parent",
")",
"?",
"$",
"parent",
"->",
"getName",
"(",
")",
":",
"$",
"environment",
"->",
"getDataDefinition",
"(",
")",
"->",
"getName",
"(",
")",
")",
";",
"$",
"environment",
"->",
"getEventDispatcher",
"(",
")",
"->",
"dispatch",
"(",
"ContaoEvents",
"::",
"SYSTEM_GET_REFERRER",
",",
"$",
"event",
")",
";",
"return",
"$",
"event",
"->",
"getReferrerUrl",
"(",
")",
";",
"}"
]
| Determine the correct referrer URL.
@param EnvironmentInterface $environment The environment.
@return mixed | [
"Determine",
"the",
"correct",
"referrer",
"URL",
"."
]
| bf59fc2085cc848c564e40324dee14ef2897faa6 | https://github.com/contao-community-alliance/dc-general/blob/bf59fc2085cc848c564e40324dee14ef2897faa6/src/Contao/View/Contao2BackendView/EventListener/BackButtonListener.php#L80-L93 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.