id
int32 0
241k
| repo
stringlengths 6
63
| path
stringlengths 5
140
| func_name
stringlengths 3
151
| original_string
stringlengths 84
13k
| language
stringclasses 1
value | code
stringlengths 84
13k
| code_tokens
list | docstring
stringlengths 3
47.2k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 91
247
|
|---|---|---|---|---|---|---|---|---|---|---|---|
26,700
|
iherwig/wcmf
|
src/wcmf/lib/io/impl/FileCache.php
|
FileCache.initializeCache
|
private function initializeCache($section) {
if (!isset($this->cache[$section])) {
$file = $this->getCacheFile($section);
if (file_exists($file)) {
$this->cache[$section] = unserialize(file_get_contents($file));
}
else {
$this->cache[$section] = [];
}
}
}
|
php
|
private function initializeCache($section) {
if (!isset($this->cache[$section])) {
$file = $this->getCacheFile($section);
if (file_exists($file)) {
$this->cache[$section] = unserialize(file_get_contents($file));
}
else {
$this->cache[$section] = [];
}
}
}
|
[
"private",
"function",
"initializeCache",
"(",
"$",
"section",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"cache",
"[",
"$",
"section",
"]",
")",
")",
"{",
"$",
"file",
"=",
"$",
"this",
"->",
"getCacheFile",
"(",
"$",
"section",
")",
";",
"if",
"(",
"file_exists",
"(",
"$",
"file",
")",
")",
"{",
"$",
"this",
"->",
"cache",
"[",
"$",
"section",
"]",
"=",
"unserialize",
"(",
"file_get_contents",
"(",
"$",
"file",
")",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"cache",
"[",
"$",
"section",
"]",
"=",
"[",
"]",
";",
"}",
"}",
"}"
] |
Initialize the cache
@param $section The caching section
|
[
"Initialize",
"the",
"cache"
] |
2542b8d4139464d39a9a8ce8a954dfecf700c41b
|
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/lib/io/impl/FileCache.php#L134-L144
|
26,701
|
iherwig/wcmf
|
src/wcmf/lib/io/impl/FileCache.php
|
FileCache.isExpired
|
private function isExpired($createTs, $lifetime) {
if ($lifetime === null) {
return false;
}
$expireDate = (new \DateTime())->setTimeStamp($createTs);
if (intval($lifetime)) {
$expireDate = $expireDate->modify('+'.$lifetime.' seconds');
}
return $expireDate < new \DateTime();
}
|
php
|
private function isExpired($createTs, $lifetime) {
if ($lifetime === null) {
return false;
}
$expireDate = (new \DateTime())->setTimeStamp($createTs);
if (intval($lifetime)) {
$expireDate = $expireDate->modify('+'.$lifetime.' seconds');
}
return $expireDate < new \DateTime();
}
|
[
"private",
"function",
"isExpired",
"(",
"$",
"createTs",
",",
"$",
"lifetime",
")",
"{",
"if",
"(",
"$",
"lifetime",
"===",
"null",
")",
"{",
"return",
"false",
";",
"}",
"$",
"expireDate",
"=",
"(",
"new",
"\\",
"DateTime",
"(",
")",
")",
"->",
"setTimeStamp",
"(",
"$",
"createTs",
")",
";",
"if",
"(",
"intval",
"(",
"$",
"lifetime",
")",
")",
"{",
"$",
"expireDate",
"=",
"$",
"expireDate",
"->",
"modify",
"(",
"'+'",
".",
"$",
"lifetime",
".",
"' seconds'",
")",
";",
"}",
"return",
"$",
"expireDate",
"<",
"new",
"\\",
"DateTime",
"(",
")",
";",
"}"
] |
Check if an entry with the given creation timestamp and lifetime is expired
@param $createTs The creation timestamp
@param $lifetime The lifetime in seconds
@return Boolean
|
[
"Check",
"if",
"an",
"entry",
"with",
"the",
"given",
"creation",
"timestamp",
"and",
"lifetime",
"is",
"expired"
] |
2542b8d4139464d39a9a8ce8a954dfecf700c41b
|
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/lib/io/impl/FileCache.php#L152-L161
|
26,702
|
iherwig/wcmf
|
src/wcmf/lib/io/impl/FileCache.php
|
FileCache.saveCache
|
private function saveCache($section) {
$content = serialize($this->cache[$section]);
$file = $this->getCacheFile($section);
$this->fileUtil->mkdirRec(dirname($file));
$fh = fopen($file, "w");
if ($fh !== false) {
fwrite($fh, $content);
fclose($fh);
}
else {
throw new ConfigurationException("The cache path is not writable: ".$file);
}
}
|
php
|
private function saveCache($section) {
$content = serialize($this->cache[$section]);
$file = $this->getCacheFile($section);
$this->fileUtil->mkdirRec(dirname($file));
$fh = fopen($file, "w");
if ($fh !== false) {
fwrite($fh, $content);
fclose($fh);
}
else {
throw new ConfigurationException("The cache path is not writable: ".$file);
}
}
|
[
"private",
"function",
"saveCache",
"(",
"$",
"section",
")",
"{",
"$",
"content",
"=",
"serialize",
"(",
"$",
"this",
"->",
"cache",
"[",
"$",
"section",
"]",
")",
";",
"$",
"file",
"=",
"$",
"this",
"->",
"getCacheFile",
"(",
"$",
"section",
")",
";",
"$",
"this",
"->",
"fileUtil",
"->",
"mkdirRec",
"(",
"dirname",
"(",
"$",
"file",
")",
")",
";",
"$",
"fh",
"=",
"fopen",
"(",
"$",
"file",
",",
"\"w\"",
")",
";",
"if",
"(",
"$",
"fh",
"!==",
"false",
")",
"{",
"fwrite",
"(",
"$",
"fh",
",",
"$",
"content",
")",
";",
"fclose",
"(",
"$",
"fh",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"ConfigurationException",
"(",
"\"The cache path is not writable: \"",
".",
"$",
"file",
")",
";",
"}",
"}"
] |
Save the cache
@param $section The caching section
|
[
"Save",
"the",
"cache"
] |
2542b8d4139464d39a9a8ce8a954dfecf700c41b
|
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/lib/io/impl/FileCache.php#L167-L179
|
26,703
|
iherwig/wcmf
|
src/wcmf/lib/persistence/Criteria.php
|
Criteria.getId
|
public function getId() {
$str = "[".$this->combineOperator."] ".$this->type.".".$this->attribute.
" ".$this->operator.(is_array($this->value) ? sizeof($this->value) : "");
return $str;
}
|
php
|
public function getId() {
$str = "[".$this->combineOperator."] ".$this->type.".".$this->attribute.
" ".$this->operator.(is_array($this->value) ? sizeof($this->value) : "");
return $str;
}
|
[
"public",
"function",
"getId",
"(",
")",
"{",
"$",
"str",
"=",
"\"[\"",
".",
"$",
"this",
"->",
"combineOperator",
".",
"\"] \"",
".",
"$",
"this",
"->",
"type",
".",
"\".\"",
".",
"$",
"this",
"->",
"attribute",
".",
"\" \"",
".",
"$",
"this",
"->",
"operator",
".",
"(",
"is_array",
"(",
"$",
"this",
"->",
"value",
")",
"?",
"sizeof",
"(",
"$",
"this",
"->",
"value",
")",
":",
"\"\"",
")",
";",
"return",
"$",
"str",
";",
"}"
] |
Get an identifier for the instance
@return String
|
[
"Get",
"an",
"identifier",
"for",
"the",
"instance"
] |
2542b8d4139464d39a9a8ce8a954dfecf700c41b
|
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/lib/persistence/Criteria.php#L148-L152
|
26,704
|
iherwig/wcmf
|
src/wcmf/application/controller/SortController.php
|
SortController.doMoveBefore
|
protected function doMoveBefore() {
$request = $this->getRequest();
$persistenceFacade = $this->getPersistenceFacade();
$isOrderBottom = $this->isOrderBotton($request);
// load the moved object and the reference object
$insertOid = ObjectId::parse($request->getValue('insertOid'));
$referenceOid = ObjectId::parse($request->getValue('referenceOid'));
$insertObject = $persistenceFacade->load($insertOid);
$referenceObject = $isOrderBottom ? new NullNode() : $persistenceFacade->load($referenceOid);
// check object existence
$objectMap = ['insertOid' => $insertObject,
'referenceOid' => $referenceObject];
if ($this->checkObjects($objectMap)) {
// determine the sort key
$mapper = $insertObject->getMapper();
$type = $insertObject->getType();
$sortkeyDef = $mapper->getSortkey();
$sortkey = $sortkeyDef['sortFieldName'];
$sortdir = strtoupper($sortkeyDef['sortDirection']);
// get the sortkey values of the objects before and after the insert position
if ($isOrderBottom) {
$lastObject = $this->loadLastObject($type, $sortkey, $sortdir);
$prevValue = $lastObject != null ? $this->getSortkeyValue($lastObject, $sortkey) : 1;
$nextValue = ceil($sortdir == 'ASC' ? $prevValue+1 : $prevValue-1);
}
else {
$nextValue = $this->getSortkeyValue($referenceObject, $sortkey);
$prevObject = $this->loadPreviousObject($type, $sortkey, $nextValue, $sortdir);
$prevValue = $prevObject != null ? $this->getSortkeyValue($prevObject, $sortkey) :
ceil($sortdir == 'ASC' ? $nextValue-1 : $nextValue+1);
}
// set the sortkey value to the average
$insertObject->setValue($sortkey, ($nextValue+$prevValue)/2);
}
}
|
php
|
protected function doMoveBefore() {
$request = $this->getRequest();
$persistenceFacade = $this->getPersistenceFacade();
$isOrderBottom = $this->isOrderBotton($request);
// load the moved object and the reference object
$insertOid = ObjectId::parse($request->getValue('insertOid'));
$referenceOid = ObjectId::parse($request->getValue('referenceOid'));
$insertObject = $persistenceFacade->load($insertOid);
$referenceObject = $isOrderBottom ? new NullNode() : $persistenceFacade->load($referenceOid);
// check object existence
$objectMap = ['insertOid' => $insertObject,
'referenceOid' => $referenceObject];
if ($this->checkObjects($objectMap)) {
// determine the sort key
$mapper = $insertObject->getMapper();
$type = $insertObject->getType();
$sortkeyDef = $mapper->getSortkey();
$sortkey = $sortkeyDef['sortFieldName'];
$sortdir = strtoupper($sortkeyDef['sortDirection']);
// get the sortkey values of the objects before and after the insert position
if ($isOrderBottom) {
$lastObject = $this->loadLastObject($type, $sortkey, $sortdir);
$prevValue = $lastObject != null ? $this->getSortkeyValue($lastObject, $sortkey) : 1;
$nextValue = ceil($sortdir == 'ASC' ? $prevValue+1 : $prevValue-1);
}
else {
$nextValue = $this->getSortkeyValue($referenceObject, $sortkey);
$prevObject = $this->loadPreviousObject($type, $sortkey, $nextValue, $sortdir);
$prevValue = $prevObject != null ? $this->getSortkeyValue($prevObject, $sortkey) :
ceil($sortdir == 'ASC' ? $nextValue-1 : $nextValue+1);
}
// set the sortkey value to the average
$insertObject->setValue($sortkey, ($nextValue+$prevValue)/2);
}
}
|
[
"protected",
"function",
"doMoveBefore",
"(",
")",
"{",
"$",
"request",
"=",
"$",
"this",
"->",
"getRequest",
"(",
")",
";",
"$",
"persistenceFacade",
"=",
"$",
"this",
"->",
"getPersistenceFacade",
"(",
")",
";",
"$",
"isOrderBottom",
"=",
"$",
"this",
"->",
"isOrderBotton",
"(",
"$",
"request",
")",
";",
"// load the moved object and the reference object",
"$",
"insertOid",
"=",
"ObjectId",
"::",
"parse",
"(",
"$",
"request",
"->",
"getValue",
"(",
"'insertOid'",
")",
")",
";",
"$",
"referenceOid",
"=",
"ObjectId",
"::",
"parse",
"(",
"$",
"request",
"->",
"getValue",
"(",
"'referenceOid'",
")",
")",
";",
"$",
"insertObject",
"=",
"$",
"persistenceFacade",
"->",
"load",
"(",
"$",
"insertOid",
")",
";",
"$",
"referenceObject",
"=",
"$",
"isOrderBottom",
"?",
"new",
"NullNode",
"(",
")",
":",
"$",
"persistenceFacade",
"->",
"load",
"(",
"$",
"referenceOid",
")",
";",
"// check object existence",
"$",
"objectMap",
"=",
"[",
"'insertOid'",
"=>",
"$",
"insertObject",
",",
"'referenceOid'",
"=>",
"$",
"referenceObject",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"checkObjects",
"(",
"$",
"objectMap",
")",
")",
"{",
"// determine the sort key",
"$",
"mapper",
"=",
"$",
"insertObject",
"->",
"getMapper",
"(",
")",
";",
"$",
"type",
"=",
"$",
"insertObject",
"->",
"getType",
"(",
")",
";",
"$",
"sortkeyDef",
"=",
"$",
"mapper",
"->",
"getSortkey",
"(",
")",
";",
"$",
"sortkey",
"=",
"$",
"sortkeyDef",
"[",
"'sortFieldName'",
"]",
";",
"$",
"sortdir",
"=",
"strtoupper",
"(",
"$",
"sortkeyDef",
"[",
"'sortDirection'",
"]",
")",
";",
"// get the sortkey values of the objects before and after the insert position",
"if",
"(",
"$",
"isOrderBottom",
")",
"{",
"$",
"lastObject",
"=",
"$",
"this",
"->",
"loadLastObject",
"(",
"$",
"type",
",",
"$",
"sortkey",
",",
"$",
"sortdir",
")",
";",
"$",
"prevValue",
"=",
"$",
"lastObject",
"!=",
"null",
"?",
"$",
"this",
"->",
"getSortkeyValue",
"(",
"$",
"lastObject",
",",
"$",
"sortkey",
")",
":",
"1",
";",
"$",
"nextValue",
"=",
"ceil",
"(",
"$",
"sortdir",
"==",
"'ASC'",
"?",
"$",
"prevValue",
"+",
"1",
":",
"$",
"prevValue",
"-",
"1",
")",
";",
"}",
"else",
"{",
"$",
"nextValue",
"=",
"$",
"this",
"->",
"getSortkeyValue",
"(",
"$",
"referenceObject",
",",
"$",
"sortkey",
")",
";",
"$",
"prevObject",
"=",
"$",
"this",
"->",
"loadPreviousObject",
"(",
"$",
"type",
",",
"$",
"sortkey",
",",
"$",
"nextValue",
",",
"$",
"sortdir",
")",
";",
"$",
"prevValue",
"=",
"$",
"prevObject",
"!=",
"null",
"?",
"$",
"this",
"->",
"getSortkeyValue",
"(",
"$",
"prevObject",
",",
"$",
"sortkey",
")",
":",
"ceil",
"(",
"$",
"sortdir",
"==",
"'ASC'",
"?",
"$",
"nextValue",
"-",
"1",
":",
"$",
"nextValue",
"+",
"1",
")",
";",
"}",
"// set the sortkey value to the average",
"$",
"insertObject",
"->",
"setValue",
"(",
"$",
"sortkey",
",",
"(",
"$",
"nextValue",
"+",
"$",
"prevValue",
")",
"/",
"2",
")",
";",
"}",
"}"
] |
Execute the moveBefore action
|
[
"Execute",
"the",
"moveBefore",
"action"
] |
2542b8d4139464d39a9a8ce8a954dfecf700c41b
|
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/application/controller/SortController.php#L154-L192
|
26,705
|
iherwig/wcmf
|
src/wcmf/application/controller/SortController.php
|
SortController.doInsertBefore
|
protected function doInsertBefore() {
$request = $this->getRequest();
$persistenceFacade = $this->getPersistenceFacade();
$isOrderBottom = $this->isOrderBotton($request);
// load the moved object, the reference object and the conainer object
$insertOid = ObjectId::parse($request->getValue('insertOid'));
$referenceOid = ObjectId::parse($request->getValue('referenceOid'));
$containerOid = ObjectId::parse($request->getValue('containerOid'));
$insertObject = $persistenceFacade->load($insertOid);
$referenceObject = $isOrderBottom ? new NullNode() : $persistenceFacade->load($referenceOid);
$containerObject = $persistenceFacade->load($containerOid);
// check object existence
$objectMap = ['insertOid' => $insertObject,
'referenceOid' => $referenceObject,
'containerOid' => $containerObject];
if ($this->checkObjects($objectMap)) {
$role = $request->getValue('role');
$originalChildren = $containerObject->getValue($role);
// add the new node to the container, if it is not yet
$nodeExists = sizeof(Node::filter($originalChildren, $insertOid)) == 1;
if (!$nodeExists) {
$containerObject->addNode($insertObject, $role);
}
// reorder the children list
$orderedChildren = [];
foreach ($originalChildren as $curChild) {
$oid = $curChild->getOID();
if ($oid == $referenceOid) {
$orderedChildren[] = $insertObject;
}
if ($oid != $insertOid) {
$orderedChildren[] = $curChild;
}
}
// get the sortkey values of the objects before and after the insert position
if ($isOrderBottom) {
$orderedChildren[] = $insertObject;
}
$containerObject->setNodeOrder($orderedChildren, [$insertObject], $role);
}
}
|
php
|
protected function doInsertBefore() {
$request = $this->getRequest();
$persistenceFacade = $this->getPersistenceFacade();
$isOrderBottom = $this->isOrderBotton($request);
// load the moved object, the reference object and the conainer object
$insertOid = ObjectId::parse($request->getValue('insertOid'));
$referenceOid = ObjectId::parse($request->getValue('referenceOid'));
$containerOid = ObjectId::parse($request->getValue('containerOid'));
$insertObject = $persistenceFacade->load($insertOid);
$referenceObject = $isOrderBottom ? new NullNode() : $persistenceFacade->load($referenceOid);
$containerObject = $persistenceFacade->load($containerOid);
// check object existence
$objectMap = ['insertOid' => $insertObject,
'referenceOid' => $referenceObject,
'containerOid' => $containerObject];
if ($this->checkObjects($objectMap)) {
$role = $request->getValue('role');
$originalChildren = $containerObject->getValue($role);
// add the new node to the container, if it is not yet
$nodeExists = sizeof(Node::filter($originalChildren, $insertOid)) == 1;
if (!$nodeExists) {
$containerObject->addNode($insertObject, $role);
}
// reorder the children list
$orderedChildren = [];
foreach ($originalChildren as $curChild) {
$oid = $curChild->getOID();
if ($oid == $referenceOid) {
$orderedChildren[] = $insertObject;
}
if ($oid != $insertOid) {
$orderedChildren[] = $curChild;
}
}
// get the sortkey values of the objects before and after the insert position
if ($isOrderBottom) {
$orderedChildren[] = $insertObject;
}
$containerObject->setNodeOrder($orderedChildren, [$insertObject], $role);
}
}
|
[
"protected",
"function",
"doInsertBefore",
"(",
")",
"{",
"$",
"request",
"=",
"$",
"this",
"->",
"getRequest",
"(",
")",
";",
"$",
"persistenceFacade",
"=",
"$",
"this",
"->",
"getPersistenceFacade",
"(",
")",
";",
"$",
"isOrderBottom",
"=",
"$",
"this",
"->",
"isOrderBotton",
"(",
"$",
"request",
")",
";",
"// load the moved object, the reference object and the conainer object",
"$",
"insertOid",
"=",
"ObjectId",
"::",
"parse",
"(",
"$",
"request",
"->",
"getValue",
"(",
"'insertOid'",
")",
")",
";",
"$",
"referenceOid",
"=",
"ObjectId",
"::",
"parse",
"(",
"$",
"request",
"->",
"getValue",
"(",
"'referenceOid'",
")",
")",
";",
"$",
"containerOid",
"=",
"ObjectId",
"::",
"parse",
"(",
"$",
"request",
"->",
"getValue",
"(",
"'containerOid'",
")",
")",
";",
"$",
"insertObject",
"=",
"$",
"persistenceFacade",
"->",
"load",
"(",
"$",
"insertOid",
")",
";",
"$",
"referenceObject",
"=",
"$",
"isOrderBottom",
"?",
"new",
"NullNode",
"(",
")",
":",
"$",
"persistenceFacade",
"->",
"load",
"(",
"$",
"referenceOid",
")",
";",
"$",
"containerObject",
"=",
"$",
"persistenceFacade",
"->",
"load",
"(",
"$",
"containerOid",
")",
";",
"// check object existence",
"$",
"objectMap",
"=",
"[",
"'insertOid'",
"=>",
"$",
"insertObject",
",",
"'referenceOid'",
"=>",
"$",
"referenceObject",
",",
"'containerOid'",
"=>",
"$",
"containerObject",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"checkObjects",
"(",
"$",
"objectMap",
")",
")",
"{",
"$",
"role",
"=",
"$",
"request",
"->",
"getValue",
"(",
"'role'",
")",
";",
"$",
"originalChildren",
"=",
"$",
"containerObject",
"->",
"getValue",
"(",
"$",
"role",
")",
";",
"// add the new node to the container, if it is not yet",
"$",
"nodeExists",
"=",
"sizeof",
"(",
"Node",
"::",
"filter",
"(",
"$",
"originalChildren",
",",
"$",
"insertOid",
")",
")",
"==",
"1",
";",
"if",
"(",
"!",
"$",
"nodeExists",
")",
"{",
"$",
"containerObject",
"->",
"addNode",
"(",
"$",
"insertObject",
",",
"$",
"role",
")",
";",
"}",
"// reorder the children list",
"$",
"orderedChildren",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"originalChildren",
"as",
"$",
"curChild",
")",
"{",
"$",
"oid",
"=",
"$",
"curChild",
"->",
"getOID",
"(",
")",
";",
"if",
"(",
"$",
"oid",
"==",
"$",
"referenceOid",
")",
"{",
"$",
"orderedChildren",
"[",
"]",
"=",
"$",
"insertObject",
";",
"}",
"if",
"(",
"$",
"oid",
"!=",
"$",
"insertOid",
")",
"{",
"$",
"orderedChildren",
"[",
"]",
"=",
"$",
"curChild",
";",
"}",
"}",
"// get the sortkey values of the objects before and after the insert position",
"if",
"(",
"$",
"isOrderBottom",
")",
"{",
"$",
"orderedChildren",
"[",
"]",
"=",
"$",
"insertObject",
";",
"}",
"$",
"containerObject",
"->",
"setNodeOrder",
"(",
"$",
"orderedChildren",
",",
"[",
"$",
"insertObject",
"]",
",",
"$",
"role",
")",
";",
"}",
"}"
] |
Execute the insertBefore action
|
[
"Execute",
"the",
"insertBefore",
"action"
] |
2542b8d4139464d39a9a8ce8a954dfecf700c41b
|
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/application/controller/SortController.php#L197-L240
|
26,706
|
iherwig/wcmf
|
src/wcmf/application/controller/SortController.php
|
SortController.loadPreviousObject
|
protected function loadPreviousObject($type, $sortkeyName, $sortkeyValue, $sortDirection) {
$query = new ObjectQuery($type);
$tpl = $query->getObjectTemplate($type);
$tpl->setValue($sortkeyName, Criteria::asValue($sortDirection == 'ASC' ? '<' : '>', $sortkeyValue), true);
$pagingInfo = new PagingInfo(1, true);
$objects = $query->execute(BuildDepth::SINGLE, [$sortkeyName." ".($sortDirection == 'ASC' ? 'DESC' : 'ASC')], $pagingInfo);
return sizeof($objects) > 0 ? $objects[0] : null;
}
|
php
|
protected function loadPreviousObject($type, $sortkeyName, $sortkeyValue, $sortDirection) {
$query = new ObjectQuery($type);
$tpl = $query->getObjectTemplate($type);
$tpl->setValue($sortkeyName, Criteria::asValue($sortDirection == 'ASC' ? '<' : '>', $sortkeyValue), true);
$pagingInfo = new PagingInfo(1, true);
$objects = $query->execute(BuildDepth::SINGLE, [$sortkeyName." ".($sortDirection == 'ASC' ? 'DESC' : 'ASC')], $pagingInfo);
return sizeof($objects) > 0 ? $objects[0] : null;
}
|
[
"protected",
"function",
"loadPreviousObject",
"(",
"$",
"type",
",",
"$",
"sortkeyName",
",",
"$",
"sortkeyValue",
",",
"$",
"sortDirection",
")",
"{",
"$",
"query",
"=",
"new",
"ObjectQuery",
"(",
"$",
"type",
")",
";",
"$",
"tpl",
"=",
"$",
"query",
"->",
"getObjectTemplate",
"(",
"$",
"type",
")",
";",
"$",
"tpl",
"->",
"setValue",
"(",
"$",
"sortkeyName",
",",
"Criteria",
"::",
"asValue",
"(",
"$",
"sortDirection",
"==",
"'ASC'",
"?",
"'<'",
":",
"'>'",
",",
"$",
"sortkeyValue",
")",
",",
"true",
")",
";",
"$",
"pagingInfo",
"=",
"new",
"PagingInfo",
"(",
"1",
",",
"true",
")",
";",
"$",
"objects",
"=",
"$",
"query",
"->",
"execute",
"(",
"BuildDepth",
"::",
"SINGLE",
",",
"[",
"$",
"sortkeyName",
".",
"\" \"",
".",
"(",
"$",
"sortDirection",
"==",
"'ASC'",
"?",
"'DESC'",
":",
"'ASC'",
")",
"]",
",",
"$",
"pagingInfo",
")",
";",
"return",
"sizeof",
"(",
"$",
"objects",
")",
">",
"0",
"?",
"$",
"objects",
"[",
"0",
"]",
":",
"null",
";",
"}"
] |
Load the object which order position is before the given sort value
@param $type The type of objects
@param $sortkeyName The name of the sortkey attribute
@param $sortkeyValue The reference sortkey value
@param $sortDirection The sort direction used with the sort key
|
[
"Load",
"the",
"object",
"which",
"order",
"position",
"is",
"before",
"the",
"given",
"sort",
"value"
] |
2542b8d4139464d39a9a8ce8a954dfecf700c41b
|
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/application/controller/SortController.php#L249-L256
|
26,707
|
iherwig/wcmf
|
src/wcmf/application/controller/SortController.php
|
SortController.loadLastObject
|
protected function loadLastObject($type, $sortkeyName, $sortDirection) {
$query = new ObjectQuery($type);
$pagingInfo = new PagingInfo(1, true);
$invSortDir = $sortDirection == 'ASC' ? 'DESC' : 'ASC';
$objects = $query->execute(BuildDepth::SINGLE, [$sortkeyName." ".$invSortDir], $pagingInfo);
return sizeof($objects) > 0 ? $objects[0] : null;
}
|
php
|
protected function loadLastObject($type, $sortkeyName, $sortDirection) {
$query = new ObjectQuery($type);
$pagingInfo = new PagingInfo(1, true);
$invSortDir = $sortDirection == 'ASC' ? 'DESC' : 'ASC';
$objects = $query->execute(BuildDepth::SINGLE, [$sortkeyName." ".$invSortDir], $pagingInfo);
return sizeof($objects) > 0 ? $objects[0] : null;
}
|
[
"protected",
"function",
"loadLastObject",
"(",
"$",
"type",
",",
"$",
"sortkeyName",
",",
"$",
"sortDirection",
")",
"{",
"$",
"query",
"=",
"new",
"ObjectQuery",
"(",
"$",
"type",
")",
";",
"$",
"pagingInfo",
"=",
"new",
"PagingInfo",
"(",
"1",
",",
"true",
")",
";",
"$",
"invSortDir",
"=",
"$",
"sortDirection",
"==",
"'ASC'",
"?",
"'DESC'",
":",
"'ASC'",
";",
"$",
"objects",
"=",
"$",
"query",
"->",
"execute",
"(",
"BuildDepth",
"::",
"SINGLE",
",",
"[",
"$",
"sortkeyName",
".",
"\" \"",
".",
"$",
"invSortDir",
"]",
",",
"$",
"pagingInfo",
")",
";",
"return",
"sizeof",
"(",
"$",
"objects",
")",
">",
"0",
"?",
"$",
"objects",
"[",
"0",
"]",
":",
"null",
";",
"}"
] |
Load the last object regarding the given sort key
@param $type The type of objects
@param $sortkeyName The name of the sortkey attribute
@param $sortDirection The sort direction used with the sort key
|
[
"Load",
"the",
"last",
"object",
"regarding",
"the",
"given",
"sort",
"key"
] |
2542b8d4139464d39a9a8ce8a954dfecf700c41b
|
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/application/controller/SortController.php#L264-L270
|
26,708
|
iherwig/wcmf
|
src/wcmf/application/controller/SortController.php
|
SortController.checkObjects
|
protected function checkObjects($objectMap) {
$response = $this->getResponse();
$invalidOids = [];
foreach ($objectMap as $parameterName => $object) {
if ($object == null) {
$invalidOids[] = $parameterName;
}
}
if (sizeof($invalidOids) > 0) {
$response->addError(ApplicationError::get('OID_INVALID',
['invalidOids' => $invalidOids]));
return false;
}
return true;
}
|
php
|
protected function checkObjects($objectMap) {
$response = $this->getResponse();
$invalidOids = [];
foreach ($objectMap as $parameterName => $object) {
if ($object == null) {
$invalidOids[] = $parameterName;
}
}
if (sizeof($invalidOids) > 0) {
$response->addError(ApplicationError::get('OID_INVALID',
['invalidOids' => $invalidOids]));
return false;
}
return true;
}
|
[
"protected",
"function",
"checkObjects",
"(",
"$",
"objectMap",
")",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"getResponse",
"(",
")",
";",
"$",
"invalidOids",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"objectMap",
"as",
"$",
"parameterName",
"=>",
"$",
"object",
")",
"{",
"if",
"(",
"$",
"object",
"==",
"null",
")",
"{",
"$",
"invalidOids",
"[",
"]",
"=",
"$",
"parameterName",
";",
"}",
"}",
"if",
"(",
"sizeof",
"(",
"$",
"invalidOids",
")",
">",
"0",
")",
"{",
"$",
"response",
"->",
"addError",
"(",
"ApplicationError",
"::",
"get",
"(",
"'OID_INVALID'",
",",
"[",
"'invalidOids'",
"=>",
"$",
"invalidOids",
"]",
")",
")",
";",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] |
Check if all objects in the given array are not null and add
an OID_INVALID error to the response, if at least one is
@param $objectMap An associative array with the controller parameter names
as keys and the objects to check as values
@return Boolean
|
[
"Check",
"if",
"all",
"objects",
"in",
"the",
"given",
"array",
"are",
"not",
"null",
"and",
"add",
"an",
"OID_INVALID",
"error",
"to",
"the",
"response",
"if",
"at",
"least",
"one",
"is"
] |
2542b8d4139464d39a9a8ce8a954dfecf700c41b
|
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/application/controller/SortController.php#L279-L293
|
26,709
|
iherwig/wcmf
|
src/wcmf/application/controller/SortController.php
|
SortController.getSortkeyValue
|
protected function getSortkeyValue($object, $valueName) {
$value = $object->getValue($valueName);
if ($value == null) {
$value = $object->getOID()->getFirstId();
}
return $value;
}
|
php
|
protected function getSortkeyValue($object, $valueName) {
$value = $object->getValue($valueName);
if ($value == null) {
$value = $object->getOID()->getFirstId();
}
return $value;
}
|
[
"protected",
"function",
"getSortkeyValue",
"(",
"$",
"object",
",",
"$",
"valueName",
")",
"{",
"$",
"value",
"=",
"$",
"object",
"->",
"getValue",
"(",
"$",
"valueName",
")",
";",
"if",
"(",
"$",
"value",
"==",
"null",
")",
"{",
"$",
"value",
"=",
"$",
"object",
"->",
"getOID",
"(",
")",
"->",
"getFirstId",
"(",
")",
";",
"}",
"return",
"$",
"value",
";",
"}"
] |
Get the sortkey value of an object. Defaults to the object's id, if
the value is null
@param $object The object
@param $valueName The name of the sortkey attribute
@return String
|
[
"Get",
"the",
"sortkey",
"value",
"of",
"an",
"object",
".",
"Defaults",
"to",
"the",
"object",
"s",
"id",
"if",
"the",
"value",
"is",
"null"
] |
2542b8d4139464d39a9a8ce8a954dfecf700c41b
|
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/application/controller/SortController.php#L311-L317
|
26,710
|
iherwig/wcmf
|
src/wcmf/lib/persistence/ObjectComparator.php
|
ObjectComparator.compare
|
public function compare(PersistentObject $a, PersistentObject $b) {
// we compare for each criteria and sum the results for $a, $b
// afterwards we compare the sums and return -1,0,1 appropriate
$sumA = 0;
$sumB = 0;
$maxWeight = sizeOf($this->sortCriteria);
$i = 0;
foreach ($this->sortCriteria as $criteria => $sortType) {
$weightedValue = ($maxWeight-$i)*($maxWeight-$i);
$aGreaterB = 0;
// sort by id
if ($criteria == self::ATTRIB_OID) {
if ($a->getOID() != $b->getOID()) {
($a->getOID() > $b->getOID()) ? $aGreaterB = 1 : $aGreaterB = -1;
}
}
// sort by type
else if ($criteria == self::ATTRIB_TYPE) {
if ($a->getType() != $b->getType()) {
($a->getType() > $b->getType()) ? $aGreaterB = 1 : $aGreaterB = -1;
}
}
// sort by value
else if($a->getValue($criteria) != null || $b->getValue($criteria) != null) {
$aValue = strToLower($a->getValue($criteria));
$bValue = strToLower($b->getValue($criteria));
if ($aValue != $bValue) {
($aValue > $bValue) ? $aGreaterB = 1 : $aGreaterB = -1;
}
}
// sort by property
else if($a->getProperty($criteria) != null || $b->getProperty($criteria) != null) {
$aProperty = strToLower($a->getProperty($criteria));
$bProperty = strToLower($b->getProperty($criteria));
if ($aProperty != $bProperty) {
($aProperty > $bProperty) ? $aGreaterB = 1 : $aGreaterB = -1;
}
}
// calculate result of current criteria depending on current sorttype
if ($sortType == self::SORTTYPE_ASC) {
if ($aGreaterB == 1) { $sumA += $weightedValue; }
else if ($aGreaterB == -1) { $sumB += $weightedValue; }
}
else if ($sortType == self::SORTTYPE_DESC) {
if ($aGreaterB == 1) { $sumB += $weightedValue; }
else if ($aGreaterB == -1) { $sumA += $weightedValue; }
}
else {
throw new IllegalArgumentException("Unknown SORTTYPE.");
}
$i++;
}
if ($sumA == $sumB) { return 0; }
return ($sumA > $sumB) ? 1 : -1;
}
|
php
|
public function compare(PersistentObject $a, PersistentObject $b) {
// we compare for each criteria and sum the results for $a, $b
// afterwards we compare the sums and return -1,0,1 appropriate
$sumA = 0;
$sumB = 0;
$maxWeight = sizeOf($this->sortCriteria);
$i = 0;
foreach ($this->sortCriteria as $criteria => $sortType) {
$weightedValue = ($maxWeight-$i)*($maxWeight-$i);
$aGreaterB = 0;
// sort by id
if ($criteria == self::ATTRIB_OID) {
if ($a->getOID() != $b->getOID()) {
($a->getOID() > $b->getOID()) ? $aGreaterB = 1 : $aGreaterB = -1;
}
}
// sort by type
else if ($criteria == self::ATTRIB_TYPE) {
if ($a->getType() != $b->getType()) {
($a->getType() > $b->getType()) ? $aGreaterB = 1 : $aGreaterB = -1;
}
}
// sort by value
else if($a->getValue($criteria) != null || $b->getValue($criteria) != null) {
$aValue = strToLower($a->getValue($criteria));
$bValue = strToLower($b->getValue($criteria));
if ($aValue != $bValue) {
($aValue > $bValue) ? $aGreaterB = 1 : $aGreaterB = -1;
}
}
// sort by property
else if($a->getProperty($criteria) != null || $b->getProperty($criteria) != null) {
$aProperty = strToLower($a->getProperty($criteria));
$bProperty = strToLower($b->getProperty($criteria));
if ($aProperty != $bProperty) {
($aProperty > $bProperty) ? $aGreaterB = 1 : $aGreaterB = -1;
}
}
// calculate result of current criteria depending on current sorttype
if ($sortType == self::SORTTYPE_ASC) {
if ($aGreaterB == 1) { $sumA += $weightedValue; }
else if ($aGreaterB == -1) { $sumB += $weightedValue; }
}
else if ($sortType == self::SORTTYPE_DESC) {
if ($aGreaterB == 1) { $sumB += $weightedValue; }
else if ($aGreaterB == -1) { $sumA += $weightedValue; }
}
else {
throw new IllegalArgumentException("Unknown SORTTYPE.");
}
$i++;
}
if ($sumA == $sumB) { return 0; }
return ($sumA > $sumB) ? 1 : -1;
}
|
[
"public",
"function",
"compare",
"(",
"PersistentObject",
"$",
"a",
",",
"PersistentObject",
"$",
"b",
")",
"{",
"// we compare for each criteria and sum the results for $a, $b",
"// afterwards we compare the sums and return -1,0,1 appropriate",
"$",
"sumA",
"=",
"0",
";",
"$",
"sumB",
"=",
"0",
";",
"$",
"maxWeight",
"=",
"sizeOf",
"(",
"$",
"this",
"->",
"sortCriteria",
")",
";",
"$",
"i",
"=",
"0",
";",
"foreach",
"(",
"$",
"this",
"->",
"sortCriteria",
"as",
"$",
"criteria",
"=>",
"$",
"sortType",
")",
"{",
"$",
"weightedValue",
"=",
"(",
"$",
"maxWeight",
"-",
"$",
"i",
")",
"*",
"(",
"$",
"maxWeight",
"-",
"$",
"i",
")",
";",
"$",
"aGreaterB",
"=",
"0",
";",
"// sort by id",
"if",
"(",
"$",
"criteria",
"==",
"self",
"::",
"ATTRIB_OID",
")",
"{",
"if",
"(",
"$",
"a",
"->",
"getOID",
"(",
")",
"!=",
"$",
"b",
"->",
"getOID",
"(",
")",
")",
"{",
"(",
"$",
"a",
"->",
"getOID",
"(",
")",
">",
"$",
"b",
"->",
"getOID",
"(",
")",
")",
"?",
"$",
"aGreaterB",
"=",
"1",
":",
"$",
"aGreaterB",
"=",
"-",
"1",
";",
"}",
"}",
"// sort by type",
"else",
"if",
"(",
"$",
"criteria",
"==",
"self",
"::",
"ATTRIB_TYPE",
")",
"{",
"if",
"(",
"$",
"a",
"->",
"getType",
"(",
")",
"!=",
"$",
"b",
"->",
"getType",
"(",
")",
")",
"{",
"(",
"$",
"a",
"->",
"getType",
"(",
")",
">",
"$",
"b",
"->",
"getType",
"(",
")",
")",
"?",
"$",
"aGreaterB",
"=",
"1",
":",
"$",
"aGreaterB",
"=",
"-",
"1",
";",
"}",
"}",
"// sort by value",
"else",
"if",
"(",
"$",
"a",
"->",
"getValue",
"(",
"$",
"criteria",
")",
"!=",
"null",
"||",
"$",
"b",
"->",
"getValue",
"(",
"$",
"criteria",
")",
"!=",
"null",
")",
"{",
"$",
"aValue",
"=",
"strToLower",
"(",
"$",
"a",
"->",
"getValue",
"(",
"$",
"criteria",
")",
")",
";",
"$",
"bValue",
"=",
"strToLower",
"(",
"$",
"b",
"->",
"getValue",
"(",
"$",
"criteria",
")",
")",
";",
"if",
"(",
"$",
"aValue",
"!=",
"$",
"bValue",
")",
"{",
"(",
"$",
"aValue",
">",
"$",
"bValue",
")",
"?",
"$",
"aGreaterB",
"=",
"1",
":",
"$",
"aGreaterB",
"=",
"-",
"1",
";",
"}",
"}",
"// sort by property",
"else",
"if",
"(",
"$",
"a",
"->",
"getProperty",
"(",
"$",
"criteria",
")",
"!=",
"null",
"||",
"$",
"b",
"->",
"getProperty",
"(",
"$",
"criteria",
")",
"!=",
"null",
")",
"{",
"$",
"aProperty",
"=",
"strToLower",
"(",
"$",
"a",
"->",
"getProperty",
"(",
"$",
"criteria",
")",
")",
";",
"$",
"bProperty",
"=",
"strToLower",
"(",
"$",
"b",
"->",
"getProperty",
"(",
"$",
"criteria",
")",
")",
";",
"if",
"(",
"$",
"aProperty",
"!=",
"$",
"bProperty",
")",
"{",
"(",
"$",
"aProperty",
">",
"$",
"bProperty",
")",
"?",
"$",
"aGreaterB",
"=",
"1",
":",
"$",
"aGreaterB",
"=",
"-",
"1",
";",
"}",
"}",
"// calculate result of current criteria depending on current sorttype",
"if",
"(",
"$",
"sortType",
"==",
"self",
"::",
"SORTTYPE_ASC",
")",
"{",
"if",
"(",
"$",
"aGreaterB",
"==",
"1",
")",
"{",
"$",
"sumA",
"+=",
"$",
"weightedValue",
";",
"}",
"else",
"if",
"(",
"$",
"aGreaterB",
"==",
"-",
"1",
")",
"{",
"$",
"sumB",
"+=",
"$",
"weightedValue",
";",
"}",
"}",
"else",
"if",
"(",
"$",
"sortType",
"==",
"self",
"::",
"SORTTYPE_DESC",
")",
"{",
"if",
"(",
"$",
"aGreaterB",
"==",
"1",
")",
"{",
"$",
"sumB",
"+=",
"$",
"weightedValue",
";",
"}",
"else",
"if",
"(",
"$",
"aGreaterB",
"==",
"-",
"1",
")",
"{",
"$",
"sumA",
"+=",
"$",
"weightedValue",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Unknown SORTTYPE.\"",
")",
";",
"}",
"$",
"i",
"++",
";",
"}",
"if",
"(",
"$",
"sumA",
"==",
"$",
"sumB",
")",
"{",
"return",
"0",
";",
"}",
"return",
"(",
"$",
"sumA",
">",
"$",
"sumB",
")",
"?",
"1",
":",
"-",
"1",
";",
"}"
] |
Compare function for sorting PersitentObject instances by the list of criterias
@param $a First PersitentObject instance
@param $b First PersitentObject instance
@return -1, 0 or 1 whether a is less, equal or greater than b
in respect of the criteria
|
[
"Compare",
"function",
"for",
"sorting",
"PersitentObject",
"instances",
"by",
"the",
"list",
"of",
"criterias"
] |
2542b8d4139464d39a9a8ce8a954dfecf700c41b
|
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/lib/persistence/ObjectComparator.php#L85-L139
|
26,711
|
iherwig/wcmf
|
src/wcmf/lib/model/visitor/LayoutVisitor.php
|
LayoutVisitor.calculatePosition
|
private function calculatePosition($obj) {
$parent = & $obj->getParent();
if (!$parent) {
// start here
$position = new Position(0, 0, 0);
}
else {
$position = new Position(0, 0, 0);
$parentPos = $this->map[$parent->getOID()];
$position->y = $parentPos->y + 1;
$position->z = $parentPos->z + 1;
$siblings = $parent->getChildren();
if ($siblings[0]->getOID() == $obj->getOID()) {
$position->x = $parentPos->x;
}
else {
// find leftmost sibling of object
for ($i=0; $i<sizeOf($siblings); $i++) {
if ($siblings[$i]->getOID() == $obj->getOID()) {
$leftSibling = & $siblings[$i-1];
}
}
// find x-coordinate of rightmost descendant of leftmost sibling
$maxX = 0;
$nIter = new NodeIterator($leftSibling);
foreach($nIter as $oid => $curObject) {
$curPosition = $this->map[$curObject->getOID()];
if ($curPosition->x >= $maxX) {
$maxX = $curPosition->x;
}
}
$position->x = $maxX+2;
// reposition parents
while ($parent != null) {
$this->map[$parent->getOID()]->x += 1;
$parent = $parent->getParent();
}
}
}
return $position;
}
|
php
|
private function calculatePosition($obj) {
$parent = & $obj->getParent();
if (!$parent) {
// start here
$position = new Position(0, 0, 0);
}
else {
$position = new Position(0, 0, 0);
$parentPos = $this->map[$parent->getOID()];
$position->y = $parentPos->y + 1;
$position->z = $parentPos->z + 1;
$siblings = $parent->getChildren();
if ($siblings[0]->getOID() == $obj->getOID()) {
$position->x = $parentPos->x;
}
else {
// find leftmost sibling of object
for ($i=0; $i<sizeOf($siblings); $i++) {
if ($siblings[$i]->getOID() == $obj->getOID()) {
$leftSibling = & $siblings[$i-1];
}
}
// find x-coordinate of rightmost descendant of leftmost sibling
$maxX = 0;
$nIter = new NodeIterator($leftSibling);
foreach($nIter as $oid => $curObject) {
$curPosition = $this->map[$curObject->getOID()];
if ($curPosition->x >= $maxX) {
$maxX = $curPosition->x;
}
}
$position->x = $maxX+2;
// reposition parents
while ($parent != null) {
$this->map[$parent->getOID()]->x += 1;
$parent = $parent->getParent();
}
}
}
return $position;
}
|
[
"private",
"function",
"calculatePosition",
"(",
"$",
"obj",
")",
"{",
"$",
"parent",
"=",
"&",
"$",
"obj",
"->",
"getParent",
"(",
")",
";",
"if",
"(",
"!",
"$",
"parent",
")",
"{",
"// start here",
"$",
"position",
"=",
"new",
"Position",
"(",
"0",
",",
"0",
",",
"0",
")",
";",
"}",
"else",
"{",
"$",
"position",
"=",
"new",
"Position",
"(",
"0",
",",
"0",
",",
"0",
")",
";",
"$",
"parentPos",
"=",
"$",
"this",
"->",
"map",
"[",
"$",
"parent",
"->",
"getOID",
"(",
")",
"]",
";",
"$",
"position",
"->",
"y",
"=",
"$",
"parentPos",
"->",
"y",
"+",
"1",
";",
"$",
"position",
"->",
"z",
"=",
"$",
"parentPos",
"->",
"z",
"+",
"1",
";",
"$",
"siblings",
"=",
"$",
"parent",
"->",
"getChildren",
"(",
")",
";",
"if",
"(",
"$",
"siblings",
"[",
"0",
"]",
"->",
"getOID",
"(",
")",
"==",
"$",
"obj",
"->",
"getOID",
"(",
")",
")",
"{",
"$",
"position",
"->",
"x",
"=",
"$",
"parentPos",
"->",
"x",
";",
"}",
"else",
"{",
"// find leftmost sibling of object",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"sizeOf",
"(",
"$",
"siblings",
")",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"$",
"siblings",
"[",
"$",
"i",
"]",
"->",
"getOID",
"(",
")",
"==",
"$",
"obj",
"->",
"getOID",
"(",
")",
")",
"{",
"$",
"leftSibling",
"=",
"&",
"$",
"siblings",
"[",
"$",
"i",
"-",
"1",
"]",
";",
"}",
"}",
"// find x-coordinate of rightmost descendant of leftmost sibling",
"$",
"maxX",
"=",
"0",
";",
"$",
"nIter",
"=",
"new",
"NodeIterator",
"(",
"$",
"leftSibling",
")",
";",
"foreach",
"(",
"$",
"nIter",
"as",
"$",
"oid",
"=>",
"$",
"curObject",
")",
"{",
"$",
"curPosition",
"=",
"$",
"this",
"->",
"map",
"[",
"$",
"curObject",
"->",
"getOID",
"(",
")",
"]",
";",
"if",
"(",
"$",
"curPosition",
"->",
"x",
">=",
"$",
"maxX",
")",
"{",
"$",
"maxX",
"=",
"$",
"curPosition",
"->",
"x",
";",
"}",
"}",
"$",
"position",
"->",
"x",
"=",
"$",
"maxX",
"+",
"2",
";",
"// reposition parents",
"while",
"(",
"$",
"parent",
"!=",
"null",
")",
"{",
"$",
"this",
"->",
"map",
"[",
"$",
"parent",
"->",
"getOID",
"(",
")",
"]",
"->",
"x",
"+=",
"1",
";",
"$",
"parent",
"=",
"$",
"parent",
"->",
"getParent",
"(",
")",
";",
"}",
"}",
"}",
"return",
"$",
"position",
";",
"}"
] |
Calculate the object's position using the described algorithm.
@param $obj PersistentObject instance
|
[
"Calculate",
"the",
"object",
"s",
"position",
"using",
"the",
"described",
"algorithm",
"."
] |
2542b8d4139464d39a9a8ce8a954dfecf700c41b
|
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/lib/model/visitor/LayoutVisitor.php#L75-L116
|
26,712
|
iherwig/wcmf
|
src/wcmf/lib/util/DBUtil.php
|
DBUtil.executeScript
|
public static function executeScript($file, $initSection) {
$logger = LogManager::getLogger(__CLASS__);
if (file_exists($file)) {
$logger->info('Executing SQL script '.$file.' ...');
// find init params
$config = ObjectFactory::getInstance('configuration');
if (($connectionParams = $config->getSection($initSection)) === false) {
throw new ConfigurationException("No '".$initSection."' section given in configfile.");
}
// connect to the database
$conn = self::createConnection($connectionParams);
$logger->debug('Starting transaction ...');
$conn->beginTransaction();
$exception = null;
$fh = fopen($file, 'r');
if ($fh) {
while (!feof($fh)) {
$command = fgets($fh, 8192);
if (strlen(trim($command)) > 0) {
$logger->debug('Executing command: '.preg_replace('/[\n]+$/', '', $command));
try {
$conn->query($command);
}
catch(\Exception $ex) {
$exception = $ex;
break;
}
}
}
fclose($fh);
}
if ($exception == null) {
$logger->debug('Execution succeeded, committing ...');
$conn->commit();
}
else {
$logger->error('Execution failed. Reason'.$exception->getMessage());
$logger->debug('Rolling back ...');
$conn->rollBack();
}
$logger->debug('Finished SQL script '.$file.'.');
}
else {
$logger->error('SQL script '.$file.' not found.');
}
}
|
php
|
public static function executeScript($file, $initSection) {
$logger = LogManager::getLogger(__CLASS__);
if (file_exists($file)) {
$logger->info('Executing SQL script '.$file.' ...');
// find init params
$config = ObjectFactory::getInstance('configuration');
if (($connectionParams = $config->getSection($initSection)) === false) {
throw new ConfigurationException("No '".$initSection."' section given in configfile.");
}
// connect to the database
$conn = self::createConnection($connectionParams);
$logger->debug('Starting transaction ...');
$conn->beginTransaction();
$exception = null;
$fh = fopen($file, 'r');
if ($fh) {
while (!feof($fh)) {
$command = fgets($fh, 8192);
if (strlen(trim($command)) > 0) {
$logger->debug('Executing command: '.preg_replace('/[\n]+$/', '', $command));
try {
$conn->query($command);
}
catch(\Exception $ex) {
$exception = $ex;
break;
}
}
}
fclose($fh);
}
if ($exception == null) {
$logger->debug('Execution succeeded, committing ...');
$conn->commit();
}
else {
$logger->error('Execution failed. Reason'.$exception->getMessage());
$logger->debug('Rolling back ...');
$conn->rollBack();
}
$logger->debug('Finished SQL script '.$file.'.');
}
else {
$logger->error('SQL script '.$file.' not found.');
}
}
|
[
"public",
"static",
"function",
"executeScript",
"(",
"$",
"file",
",",
"$",
"initSection",
")",
"{",
"$",
"logger",
"=",
"LogManager",
"::",
"getLogger",
"(",
"__CLASS__",
")",
";",
"if",
"(",
"file_exists",
"(",
"$",
"file",
")",
")",
"{",
"$",
"logger",
"->",
"info",
"(",
"'Executing SQL script '",
".",
"$",
"file",
".",
"' ...'",
")",
";",
"// find init params",
"$",
"config",
"=",
"ObjectFactory",
"::",
"getInstance",
"(",
"'configuration'",
")",
";",
"if",
"(",
"(",
"$",
"connectionParams",
"=",
"$",
"config",
"->",
"getSection",
"(",
"$",
"initSection",
")",
")",
"===",
"false",
")",
"{",
"throw",
"new",
"ConfigurationException",
"(",
"\"No '\"",
".",
"$",
"initSection",
".",
"\"' section given in configfile.\"",
")",
";",
"}",
"// connect to the database",
"$",
"conn",
"=",
"self",
"::",
"createConnection",
"(",
"$",
"connectionParams",
")",
";",
"$",
"logger",
"->",
"debug",
"(",
"'Starting transaction ...'",
")",
";",
"$",
"conn",
"->",
"beginTransaction",
"(",
")",
";",
"$",
"exception",
"=",
"null",
";",
"$",
"fh",
"=",
"fopen",
"(",
"$",
"file",
",",
"'r'",
")",
";",
"if",
"(",
"$",
"fh",
")",
"{",
"while",
"(",
"!",
"feof",
"(",
"$",
"fh",
")",
")",
"{",
"$",
"command",
"=",
"fgets",
"(",
"$",
"fh",
",",
"8192",
")",
";",
"if",
"(",
"strlen",
"(",
"trim",
"(",
"$",
"command",
")",
")",
">",
"0",
")",
"{",
"$",
"logger",
"->",
"debug",
"(",
"'Executing command: '",
".",
"preg_replace",
"(",
"'/[\\n]+$/'",
",",
"''",
",",
"$",
"command",
")",
")",
";",
"try",
"{",
"$",
"conn",
"->",
"query",
"(",
"$",
"command",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"ex",
")",
"{",
"$",
"exception",
"=",
"$",
"ex",
";",
"break",
";",
"}",
"}",
"}",
"fclose",
"(",
"$",
"fh",
")",
";",
"}",
"if",
"(",
"$",
"exception",
"==",
"null",
")",
"{",
"$",
"logger",
"->",
"debug",
"(",
"'Execution succeeded, committing ...'",
")",
";",
"$",
"conn",
"->",
"commit",
"(",
")",
";",
"}",
"else",
"{",
"$",
"logger",
"->",
"error",
"(",
"'Execution failed. Reason'",
".",
"$",
"exception",
"->",
"getMessage",
"(",
")",
")",
";",
"$",
"logger",
"->",
"debug",
"(",
"'Rolling back ...'",
")",
";",
"$",
"conn",
"->",
"rollBack",
"(",
")",
";",
"}",
"$",
"logger",
"->",
"debug",
"(",
"'Finished SQL script '",
".",
"$",
"file",
".",
"'.'",
")",
";",
"}",
"else",
"{",
"$",
"logger",
"->",
"error",
"(",
"'SQL script '",
".",
"$",
"file",
".",
"' not found.'",
")",
";",
"}",
"}"
] |
Execute a sql script. Execution is done inside a transaction, which is rolled back in case of failure.
@param $file The filename of the sql script
@param $initSection The name of the configuration section that defines the database connection
@return Boolean whether execution succeeded or not.
|
[
"Execute",
"a",
"sql",
"script",
".",
"Execution",
"is",
"done",
"inside",
"a",
"transaction",
"which",
"is",
"rolled",
"back",
"in",
"case",
"of",
"failure",
"."
] |
2542b8d4139464d39a9a8ce8a954dfecf700c41b
|
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/lib/util/DBUtil.php#L88-L136
|
26,713
|
iherwig/wcmf
|
src/wcmf/lib/util/DBUtil.php
|
DBUtil.createDatabase
|
public static function createDatabase($name, $server, $user, $password) {
$created = false;
if($name && $server && $user) {
// setup connection
$conn =null;
try {
$conn = new PDO("mysql:host=$server", $user, $password);
}
catch(\Exception $ex) {
throw new PersistenceException("Couldn't connect to MySql: ".$ex->getMessage());
}
// create database
$sqlStmt = "CREATE DATABASE IF NOT EXISTS ".$name;
$result = $conn->query($sqlStmt);
if ($result) {
$created = true;
}
if (!$created) {
throw new PersistenceException("Couldn't create database: ".$conn->errorInfo());
}
}
}
|
php
|
public static function createDatabase($name, $server, $user, $password) {
$created = false;
if($name && $server && $user) {
// setup connection
$conn =null;
try {
$conn = new PDO("mysql:host=$server", $user, $password);
}
catch(\Exception $ex) {
throw new PersistenceException("Couldn't connect to MySql: ".$ex->getMessage());
}
// create database
$sqlStmt = "CREATE DATABASE IF NOT EXISTS ".$name;
$result = $conn->query($sqlStmt);
if ($result) {
$created = true;
}
if (!$created) {
throw new PersistenceException("Couldn't create database: ".$conn->errorInfo());
}
}
}
|
[
"public",
"static",
"function",
"createDatabase",
"(",
"$",
"name",
",",
"$",
"server",
",",
"$",
"user",
",",
"$",
"password",
")",
"{",
"$",
"created",
"=",
"false",
";",
"if",
"(",
"$",
"name",
"&&",
"$",
"server",
"&&",
"$",
"user",
")",
"{",
"// setup connection",
"$",
"conn",
"=",
"null",
";",
"try",
"{",
"$",
"conn",
"=",
"new",
"PDO",
"(",
"\"mysql:host=$server\"",
",",
"$",
"user",
",",
"$",
"password",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"ex",
")",
"{",
"throw",
"new",
"PersistenceException",
"(",
"\"Couldn't connect to MySql: \"",
".",
"$",
"ex",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"// create database",
"$",
"sqlStmt",
"=",
"\"CREATE DATABASE IF NOT EXISTS \"",
".",
"$",
"name",
";",
"$",
"result",
"=",
"$",
"conn",
"->",
"query",
"(",
"$",
"sqlStmt",
")",
";",
"if",
"(",
"$",
"result",
")",
"{",
"$",
"created",
"=",
"true",
";",
"}",
"if",
"(",
"!",
"$",
"created",
")",
"{",
"throw",
"new",
"PersistenceException",
"(",
"\"Couldn't create database: \"",
".",
"$",
"conn",
"->",
"errorInfo",
"(",
")",
")",
";",
"}",
"}",
"}"
] |
Crate a database on the server. This works only for MySQL databases.
@param $name The name of the source database
@param $server The name of the database server
@param $user The user name
@param $password The password
|
[
"Crate",
"a",
"database",
"on",
"the",
"server",
".",
"This",
"works",
"only",
"for",
"MySQL",
"databases",
"."
] |
2542b8d4139464d39a9a8ce8a954dfecf700c41b
|
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/lib/util/DBUtil.php#L194-L215
|
26,714
|
GW2Treasures/gw2api
|
src/V2/Pagination/PaginatedEndpoint.php
|
PaginatedEndpoint.all
|
public function all() {
$size = $this->maxPageSize();
$firstPageResponse = $this->request( $this->createPaginatedRequestQuery( 0, $size ) );
$header_values = $firstPageResponse->getResponse()->getHeader('X-Result-Total');
$total = array_shift($header_values);
$result = $firstPageResponse->json();
if( $total <= $size ) {
return $result;
}
$requests = [];
for( $page = 1; $page < ceil( $total / $size ); $page++ ) {
$requests[] = $this->createPaginatedRequestQuery( $page, $size );
}
$responses = $this->requestMany( $requests );
foreach( $responses as $response ) {
$result = array_merge( $result, $response->json() );
}
return $result;
}
|
php
|
public function all() {
$size = $this->maxPageSize();
$firstPageResponse = $this->request( $this->createPaginatedRequestQuery( 0, $size ) );
$header_values = $firstPageResponse->getResponse()->getHeader('X-Result-Total');
$total = array_shift($header_values);
$result = $firstPageResponse->json();
if( $total <= $size ) {
return $result;
}
$requests = [];
for( $page = 1; $page < ceil( $total / $size ); $page++ ) {
$requests[] = $this->createPaginatedRequestQuery( $page, $size );
}
$responses = $this->requestMany( $requests );
foreach( $responses as $response ) {
$result = array_merge( $result, $response->json() );
}
return $result;
}
|
[
"public",
"function",
"all",
"(",
")",
"{",
"$",
"size",
"=",
"$",
"this",
"->",
"maxPageSize",
"(",
")",
";",
"$",
"firstPageResponse",
"=",
"$",
"this",
"->",
"request",
"(",
"$",
"this",
"->",
"createPaginatedRequestQuery",
"(",
"0",
",",
"$",
"size",
")",
")",
";",
"$",
"header_values",
"=",
"$",
"firstPageResponse",
"->",
"getResponse",
"(",
")",
"->",
"getHeader",
"(",
"'X-Result-Total'",
")",
";",
"$",
"total",
"=",
"array_shift",
"(",
"$",
"header_values",
")",
";",
"$",
"result",
"=",
"$",
"firstPageResponse",
"->",
"json",
"(",
")",
";",
"if",
"(",
"$",
"total",
"<=",
"$",
"size",
")",
"{",
"return",
"$",
"result",
";",
"}",
"$",
"requests",
"=",
"[",
"]",
";",
"for",
"(",
"$",
"page",
"=",
"1",
";",
"$",
"page",
"<",
"ceil",
"(",
"$",
"total",
"/",
"$",
"size",
")",
";",
"$",
"page",
"++",
")",
"{",
"$",
"requests",
"[",
"]",
"=",
"$",
"this",
"->",
"createPaginatedRequestQuery",
"(",
"$",
"page",
",",
"$",
"size",
")",
";",
"}",
"$",
"responses",
"=",
"$",
"this",
"->",
"requestMany",
"(",
"$",
"requests",
")",
";",
"foreach",
"(",
"$",
"responses",
"as",
"$",
"response",
")",
"{",
"$",
"result",
"=",
"array_merge",
"(",
"$",
"result",
",",
"$",
"response",
"->",
"json",
"(",
")",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] |
All entries.
@return array
|
[
"All",
"entries",
"."
] |
c8795af0c1d0a434b9e530f779d5a95786db2176
|
https://github.com/GW2Treasures/gw2api/blob/c8795af0c1d0a434b9e530f779d5a95786db2176/src/V2/Pagination/PaginatedEndpoint.php#L27-L52
|
26,715
|
GW2Treasures/gw2api
|
src/V2/Pagination/PaginatedEndpoint.php
|
PaginatedEndpoint.page
|
public function page( $page, $size = null ) {
if( is_null( $size )) {
$size = $this->maxPageSize();
}
if( $size > $this->maxPageSize() || $size <= 0 ) {
throw new OutOfRangeException('$size has to be between 0 and ' . $this->maxPageSize() . ', was ' . $size );
}
if( $page < 0 ) {
throw new OutOfRangeException('$page has to be 0 or greater');
}
return $this->request( $this->createPaginatedRequestQuery( $page, $size ) )->json();
}
|
php
|
public function page( $page, $size = null ) {
if( is_null( $size )) {
$size = $this->maxPageSize();
}
if( $size > $this->maxPageSize() || $size <= 0 ) {
throw new OutOfRangeException('$size has to be between 0 and ' . $this->maxPageSize() . ', was ' . $size );
}
if( $page < 0 ) {
throw new OutOfRangeException('$page has to be 0 or greater');
}
return $this->request( $this->createPaginatedRequestQuery( $page, $size ) )->json();
}
|
[
"public",
"function",
"page",
"(",
"$",
"page",
",",
"$",
"size",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"size",
")",
")",
"{",
"$",
"size",
"=",
"$",
"this",
"->",
"maxPageSize",
"(",
")",
";",
"}",
"if",
"(",
"$",
"size",
">",
"$",
"this",
"->",
"maxPageSize",
"(",
")",
"||",
"$",
"size",
"<=",
"0",
")",
"{",
"throw",
"new",
"OutOfRangeException",
"(",
"'$size has to be between 0 and '",
".",
"$",
"this",
"->",
"maxPageSize",
"(",
")",
".",
"', was '",
".",
"$",
"size",
")",
";",
"}",
"if",
"(",
"$",
"page",
"<",
"0",
")",
"{",
"throw",
"new",
"OutOfRangeException",
"(",
"'$page has to be 0 or greater'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"request",
"(",
"$",
"this",
"->",
"createPaginatedRequestQuery",
"(",
"$",
"page",
",",
"$",
"size",
")",
")",
"->",
"json",
"(",
")",
";",
"}"
] |
Get a single page.
@param int $page
@param int $size
@return mixed
|
[
"Get",
"a",
"single",
"page",
"."
] |
c8795af0c1d0a434b9e530f779d5a95786db2176
|
https://github.com/GW2Treasures/gw2api/blob/c8795af0c1d0a434b9e530f779d5a95786db2176/src/V2/Pagination/PaginatedEndpoint.php#L61-L75
|
26,716
|
GW2Treasures/gw2api
|
src/V2/Pagination/PaginatedEndpoint.php
|
PaginatedEndpoint.batch
|
public function batch( $parallelRequests = null, callable $callback = null ) {
/** @noinspection PhpParamsInspection */
if( !isset( $callback ) && is_callable( $parallelRequests )) {
$callback = $parallelRequests;
$parallelRequests = null;
}
if( is_null( $parallelRequests )) {
$parallelRequests = 6;
}
$size = $this->maxPageSize();
$firstPageResponse = $this->request( $this->createPaginatedRequestQuery( 0, $size ) );
$header_values = $firstPageResponse->getResponse()->getHeader('X-Result-Total');
$total = array_shift($header_values);
call_user_func( $callback, $firstPageResponse->json() );
unset( $firstPageResponse );
$lastPage = ceil( $total / $size );
for( $page = 1; $page < $lastPage; ) {
$batchRequests = [];
for( $batchPage = 0; $batchPage < $parallelRequests && $page + $batchPage < $lastPage; $batchPage++ ) {
$batchRequests[] = $this->createPaginatedRequestQuery( $page + $batchPage, $size );
}
$responses = $this->requestMany( $batchRequests );
foreach( $responses as $response ) {
call_user_func( $callback, $response->json() );
}
unset( $responses );
$page += $parallelRequests;
}
}
|
php
|
public function batch( $parallelRequests = null, callable $callback = null ) {
/** @noinspection PhpParamsInspection */
if( !isset( $callback ) && is_callable( $parallelRequests )) {
$callback = $parallelRequests;
$parallelRequests = null;
}
if( is_null( $parallelRequests )) {
$parallelRequests = 6;
}
$size = $this->maxPageSize();
$firstPageResponse = $this->request( $this->createPaginatedRequestQuery( 0, $size ) );
$header_values = $firstPageResponse->getResponse()->getHeader('X-Result-Total');
$total = array_shift($header_values);
call_user_func( $callback, $firstPageResponse->json() );
unset( $firstPageResponse );
$lastPage = ceil( $total / $size );
for( $page = 1; $page < $lastPage; ) {
$batchRequests = [];
for( $batchPage = 0; $batchPage < $parallelRequests && $page + $batchPage < $lastPage; $batchPage++ ) {
$batchRequests[] = $this->createPaginatedRequestQuery( $page + $batchPage, $size );
}
$responses = $this->requestMany( $batchRequests );
foreach( $responses as $response ) {
call_user_func( $callback, $response->json() );
}
unset( $responses );
$page += $parallelRequests;
}
}
|
[
"public",
"function",
"batch",
"(",
"$",
"parallelRequests",
"=",
"null",
",",
"callable",
"$",
"callback",
"=",
"null",
")",
"{",
"/** @noinspection PhpParamsInspection */",
"if",
"(",
"!",
"isset",
"(",
"$",
"callback",
")",
"&&",
"is_callable",
"(",
"$",
"parallelRequests",
")",
")",
"{",
"$",
"callback",
"=",
"$",
"parallelRequests",
";",
"$",
"parallelRequests",
"=",
"null",
";",
"}",
"if",
"(",
"is_null",
"(",
"$",
"parallelRequests",
")",
")",
"{",
"$",
"parallelRequests",
"=",
"6",
";",
"}",
"$",
"size",
"=",
"$",
"this",
"->",
"maxPageSize",
"(",
")",
";",
"$",
"firstPageResponse",
"=",
"$",
"this",
"->",
"request",
"(",
"$",
"this",
"->",
"createPaginatedRequestQuery",
"(",
"0",
",",
"$",
"size",
")",
")",
";",
"$",
"header_values",
"=",
"$",
"firstPageResponse",
"->",
"getResponse",
"(",
")",
"->",
"getHeader",
"(",
"'X-Result-Total'",
")",
";",
"$",
"total",
"=",
"array_shift",
"(",
"$",
"header_values",
")",
";",
"call_user_func",
"(",
"$",
"callback",
",",
"$",
"firstPageResponse",
"->",
"json",
"(",
")",
")",
";",
"unset",
"(",
"$",
"firstPageResponse",
")",
";",
"$",
"lastPage",
"=",
"ceil",
"(",
"$",
"total",
"/",
"$",
"size",
")",
";",
"for",
"(",
"$",
"page",
"=",
"1",
";",
"$",
"page",
"<",
"$",
"lastPage",
";",
")",
"{",
"$",
"batchRequests",
"=",
"[",
"]",
";",
"for",
"(",
"$",
"batchPage",
"=",
"0",
";",
"$",
"batchPage",
"<",
"$",
"parallelRequests",
"&&",
"$",
"page",
"+",
"$",
"batchPage",
"<",
"$",
"lastPage",
";",
"$",
"batchPage",
"++",
")",
"{",
"$",
"batchRequests",
"[",
"]",
"=",
"$",
"this",
"->",
"createPaginatedRequestQuery",
"(",
"$",
"page",
"+",
"$",
"batchPage",
",",
"$",
"size",
")",
";",
"}",
"$",
"responses",
"=",
"$",
"this",
"->",
"requestMany",
"(",
"$",
"batchRequests",
")",
";",
"foreach",
"(",
"$",
"responses",
"as",
"$",
"response",
")",
"{",
"call_user_func",
"(",
"$",
"callback",
",",
"$",
"response",
"->",
"json",
"(",
")",
")",
";",
"}",
"unset",
"(",
"$",
"responses",
")",
";",
"$",
"page",
"+=",
"$",
"parallelRequests",
";",
"}",
"}"
] |
Get all entries in multiple small batches.
@param int|null $parallelRequests [optional]
@param callable $callback
@return void
|
[
"Get",
"all",
"entries",
"in",
"multiple",
"small",
"batches",
"."
] |
c8795af0c1d0a434b9e530f779d5a95786db2176
|
https://github.com/GW2Treasures/gw2api/blob/c8795af0c1d0a434b9e530f779d5a95786db2176/src/V2/Pagination/PaginatedEndpoint.php#L84-L123
|
26,717
|
iherwig/wcmf
|
src/wcmf/lib/presentation/format/impl/HtmlFormat.php
|
HtmlFormat.getValueDefFromInputControlName
|
protected static function getValueDefFromInputControlName($name) {
if (strpos($name, 'value') !== 0) {
return null;
}
$def = [];
$fieldDelimiter = StringUtil::escapeForRegex(self::$inputFieldNameDelimiter);
$pieces = preg_split('/'.$fieldDelimiter.'/', $name);
if (sizeof($pieces) != 4) {
return null;
}
array_shift($pieces);
$def['language'] = array_shift($pieces);
$def['name'] = array_shift($pieces);
$def['oid'] = array_shift($pieces);
return $def;
}
|
php
|
protected static function getValueDefFromInputControlName($name) {
if (strpos($name, 'value') !== 0) {
return null;
}
$def = [];
$fieldDelimiter = StringUtil::escapeForRegex(self::$inputFieldNameDelimiter);
$pieces = preg_split('/'.$fieldDelimiter.'/', $name);
if (sizeof($pieces) != 4) {
return null;
}
array_shift($pieces);
$def['language'] = array_shift($pieces);
$def['name'] = array_shift($pieces);
$def['oid'] = array_shift($pieces);
return $def;
}
|
[
"protected",
"static",
"function",
"getValueDefFromInputControlName",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"name",
",",
"'value'",
")",
"!==",
"0",
")",
"{",
"return",
"null",
";",
"}",
"$",
"def",
"=",
"[",
"]",
";",
"$",
"fieldDelimiter",
"=",
"StringUtil",
"::",
"escapeForRegex",
"(",
"self",
"::",
"$",
"inputFieldNameDelimiter",
")",
";",
"$",
"pieces",
"=",
"preg_split",
"(",
"'/'",
".",
"$",
"fieldDelimiter",
".",
"'/'",
",",
"$",
"name",
")",
";",
"if",
"(",
"sizeof",
"(",
"$",
"pieces",
")",
"!=",
"4",
")",
"{",
"return",
"null",
";",
"}",
"array_shift",
"(",
"$",
"pieces",
")",
";",
"$",
"def",
"[",
"'language'",
"]",
"=",
"array_shift",
"(",
"$",
"pieces",
")",
";",
"$",
"def",
"[",
"'name'",
"]",
"=",
"array_shift",
"(",
"$",
"pieces",
")",
";",
"$",
"def",
"[",
"'oid'",
"]",
"=",
"array_shift",
"(",
"$",
"pieces",
")",
";",
"return",
"$",
"def",
";",
"}"
] |
Get the object value definition from a HTML input field name.
@param $name The name of input field in the format value-`language`-`name`-`oid`, where name is the name
of the attribute belonging to the node defined by oid
@return An associative array with keys 'oid', 'language', 'name' or null if the name is not valid
|
[
"Get",
"the",
"object",
"value",
"definition",
"from",
"a",
"HTML",
"input",
"field",
"name",
"."
] |
2542b8d4139464d39a9a8ce8a954dfecf700c41b
|
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/lib/presentation/format/impl/HtmlFormat.php#L130-L146
|
26,718
|
iherwig/wcmf
|
src/wcmf/lib/presentation/format/impl/HtmlFormat.php
|
HtmlFormat.getTemplateFile
|
protected function getTemplateFile(Response $response) {
if (self::$sharedView == null) {
self::$sharedView = ObjectFactory::getInstance('view');
}
// check if a view template is defined
$viewTpl = self::$sharedView->getTemplate($response->getSender(),
$response->getContext(), $response->getAction());
if (!$viewTpl) {
throw new ConfigurationException("View definition missing for ".
"response: ".$response->__toString());
}
// check for html_format property in response
// and add the suffix if existing
$viewTplFile = WCMF_BASE.$viewTpl;
$format = $response->getProperty('html_tpl_format');
if (isset($format)) {
$ext = pathinfo($viewTplFile, PATHINFO_EXTENSION);
$formatViewTplFile = dirname($viewTplFile).'/'.basename($viewTplFile, ".$ext").'-'.$format.'.'.$ext;
}
// give precedence to format specific file
$finalTplFile = isset($formatViewTplFile) && file_exists($formatViewTplFile) ?
$formatViewTplFile : $viewTplFile;
return $finalTplFile;
}
|
php
|
protected function getTemplateFile(Response $response) {
if (self::$sharedView == null) {
self::$sharedView = ObjectFactory::getInstance('view');
}
// check if a view template is defined
$viewTpl = self::$sharedView->getTemplate($response->getSender(),
$response->getContext(), $response->getAction());
if (!$viewTpl) {
throw new ConfigurationException("View definition missing for ".
"response: ".$response->__toString());
}
// check for html_format property in response
// and add the suffix if existing
$viewTplFile = WCMF_BASE.$viewTpl;
$format = $response->getProperty('html_tpl_format');
if (isset($format)) {
$ext = pathinfo($viewTplFile, PATHINFO_EXTENSION);
$formatViewTplFile = dirname($viewTplFile).'/'.basename($viewTplFile, ".$ext").'-'.$format.'.'.$ext;
}
// give precedence to format specific file
$finalTplFile = isset($formatViewTplFile) && file_exists($formatViewTplFile) ?
$formatViewTplFile : $viewTplFile;
return $finalTplFile;
}
|
[
"protected",
"function",
"getTemplateFile",
"(",
"Response",
"$",
"response",
")",
"{",
"if",
"(",
"self",
"::",
"$",
"sharedView",
"==",
"null",
")",
"{",
"self",
"::",
"$",
"sharedView",
"=",
"ObjectFactory",
"::",
"getInstance",
"(",
"'view'",
")",
";",
"}",
"// check if a view template is defined",
"$",
"viewTpl",
"=",
"self",
"::",
"$",
"sharedView",
"->",
"getTemplate",
"(",
"$",
"response",
"->",
"getSender",
"(",
")",
",",
"$",
"response",
"->",
"getContext",
"(",
")",
",",
"$",
"response",
"->",
"getAction",
"(",
")",
")",
";",
"if",
"(",
"!",
"$",
"viewTpl",
")",
"{",
"throw",
"new",
"ConfigurationException",
"(",
"\"View definition missing for \"",
".",
"\"response: \"",
".",
"$",
"response",
"->",
"__toString",
"(",
")",
")",
";",
"}",
"// check for html_format property in response",
"// and add the suffix if existing",
"$",
"viewTplFile",
"=",
"WCMF_BASE",
".",
"$",
"viewTpl",
";",
"$",
"format",
"=",
"$",
"response",
"->",
"getProperty",
"(",
"'html_tpl_format'",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"format",
")",
")",
"{",
"$",
"ext",
"=",
"pathinfo",
"(",
"$",
"viewTplFile",
",",
"PATHINFO_EXTENSION",
")",
";",
"$",
"formatViewTplFile",
"=",
"dirname",
"(",
"$",
"viewTplFile",
")",
".",
"'/'",
".",
"basename",
"(",
"$",
"viewTplFile",
",",
"\".$ext\"",
")",
".",
"'-'",
".",
"$",
"format",
".",
"'.'",
".",
"$",
"ext",
";",
"}",
"// give precedence to format specific file",
"$",
"finalTplFile",
"=",
"isset",
"(",
"$",
"formatViewTplFile",
")",
"&&",
"file_exists",
"(",
"$",
"formatViewTplFile",
")",
"?",
"$",
"formatViewTplFile",
":",
"$",
"viewTplFile",
";",
"return",
"$",
"finalTplFile",
";",
"}"
] |
Get the template file for the given response
@param $response
|
[
"Get",
"the",
"template",
"file",
"for",
"the",
"given",
"response"
] |
2542b8d4139464d39a9a8ce8a954dfecf700c41b
|
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/lib/presentation/format/impl/HtmlFormat.php#L152-L177
|
26,719
|
iherwig/wcmf
|
src/wcmf/lib/persistence/ObjectId.php
|
ObjectId.parse
|
public static function parse($oid) {
// fast checks first
if ($oid instanceof ObjectId) {
return $oid;
}
$oidParts = self::parseOidString($oid);
$type = $oidParts['type'];
$ids = $oidParts['id'];
$prefix = $oidParts['prefix'];
// check the type
if (!ObjectFactory::getInstance('persistenceFacade')->isKnownType($type)) {
return null;
}
// check if number of ids match the type
$numPks = self::getNumberOfPKs($type);
if ($numPks == null || $numPks != sizeof($ids)) {
return null;
}
return new ObjectID($type, $ids, $prefix);
}
|
php
|
public static function parse($oid) {
// fast checks first
if ($oid instanceof ObjectId) {
return $oid;
}
$oidParts = self::parseOidString($oid);
$type = $oidParts['type'];
$ids = $oidParts['id'];
$prefix = $oidParts['prefix'];
// check the type
if (!ObjectFactory::getInstance('persistenceFacade')->isKnownType($type)) {
return null;
}
// check if number of ids match the type
$numPks = self::getNumberOfPKs($type);
if ($numPks == null || $numPks != sizeof($ids)) {
return null;
}
return new ObjectID($type, $ids, $prefix);
}
|
[
"public",
"static",
"function",
"parse",
"(",
"$",
"oid",
")",
"{",
"// fast checks first",
"if",
"(",
"$",
"oid",
"instanceof",
"ObjectId",
")",
"{",
"return",
"$",
"oid",
";",
"}",
"$",
"oidParts",
"=",
"self",
"::",
"parseOidString",
"(",
"$",
"oid",
")",
";",
"$",
"type",
"=",
"$",
"oidParts",
"[",
"'type'",
"]",
";",
"$",
"ids",
"=",
"$",
"oidParts",
"[",
"'id'",
"]",
";",
"$",
"prefix",
"=",
"$",
"oidParts",
"[",
"'prefix'",
"]",
";",
"// check the type",
"if",
"(",
"!",
"ObjectFactory",
"::",
"getInstance",
"(",
"'persistenceFacade'",
")",
"->",
"isKnownType",
"(",
"$",
"type",
")",
")",
"{",
"return",
"null",
";",
"}",
"// check if number of ids match the type",
"$",
"numPks",
"=",
"self",
"::",
"getNumberOfPKs",
"(",
"$",
"type",
")",
";",
"if",
"(",
"$",
"numPks",
"==",
"null",
"||",
"$",
"numPks",
"!=",
"sizeof",
"(",
"$",
"ids",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"new",
"ObjectID",
"(",
"$",
"type",
",",
"$",
"ids",
",",
"$",
"prefix",
")",
";",
"}"
] |
Parse a serialized object id string into an ObjectId instance.
@param $oid The string
@return ObjectId or null, if the id cannot be parsed
|
[
"Parse",
"a",
"serialized",
"object",
"id",
"string",
"into",
"an",
"ObjectId",
"instance",
"."
] |
2542b8d4139464d39a9a8ce8a954dfecf700c41b
|
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/lib/persistence/ObjectId.php#L134-L157
|
26,720
|
iherwig/wcmf
|
src/wcmf/lib/persistence/ObjectId.php
|
ObjectId.parseOidString
|
private static function parseOidString($oid) {
if (strlen($oid) == 0) {
return null;
}
$oidParts = preg_split(self::getDelimiterPattern(), $oid);
if (sizeof($oidParts) < 2) {
return null;
}
if (self::$idPattern == null) {
self::$idPattern = '/^[0-9]*$|^'.self::$dummyIdPattern.'$/';
}
// get the ids from the oid
$ids = [];
$nextPart = array_pop($oidParts);
while($nextPart !== null && preg_match(self::$idPattern, $nextPart) == 1) {
$intNextPart = (int)$nextPart;
if ($nextPart == (string)$intNextPart) {
$ids[] = $intNextPart;
}
else {
$ids[] = $nextPart;
}
$nextPart = array_pop($oidParts);
}
$ids = array_reverse($ids);
// get the type
$type = $nextPart;
// get the prefix
$prefix = join(self::DELIMITER, $oidParts);
return [
'type' => $type,
'id' => $ids,
'prefix' => $prefix
];
}
|
php
|
private static function parseOidString($oid) {
if (strlen($oid) == 0) {
return null;
}
$oidParts = preg_split(self::getDelimiterPattern(), $oid);
if (sizeof($oidParts) < 2) {
return null;
}
if (self::$idPattern == null) {
self::$idPattern = '/^[0-9]*$|^'.self::$dummyIdPattern.'$/';
}
// get the ids from the oid
$ids = [];
$nextPart = array_pop($oidParts);
while($nextPart !== null && preg_match(self::$idPattern, $nextPart) == 1) {
$intNextPart = (int)$nextPart;
if ($nextPart == (string)$intNextPart) {
$ids[] = $intNextPart;
}
else {
$ids[] = $nextPart;
}
$nextPart = array_pop($oidParts);
}
$ids = array_reverse($ids);
// get the type
$type = $nextPart;
// get the prefix
$prefix = join(self::DELIMITER, $oidParts);
return [
'type' => $type,
'id' => $ids,
'prefix' => $prefix
];
}
|
[
"private",
"static",
"function",
"parseOidString",
"(",
"$",
"oid",
")",
"{",
"if",
"(",
"strlen",
"(",
"$",
"oid",
")",
"==",
"0",
")",
"{",
"return",
"null",
";",
"}",
"$",
"oidParts",
"=",
"preg_split",
"(",
"self",
"::",
"getDelimiterPattern",
"(",
")",
",",
"$",
"oid",
")",
";",
"if",
"(",
"sizeof",
"(",
"$",
"oidParts",
")",
"<",
"2",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"self",
"::",
"$",
"idPattern",
"==",
"null",
")",
"{",
"self",
"::",
"$",
"idPattern",
"=",
"'/^[0-9]*$|^'",
".",
"self",
"::",
"$",
"dummyIdPattern",
".",
"'$/'",
";",
"}",
"// get the ids from the oid",
"$",
"ids",
"=",
"[",
"]",
";",
"$",
"nextPart",
"=",
"array_pop",
"(",
"$",
"oidParts",
")",
";",
"while",
"(",
"$",
"nextPart",
"!==",
"null",
"&&",
"preg_match",
"(",
"self",
"::",
"$",
"idPattern",
",",
"$",
"nextPart",
")",
"==",
"1",
")",
"{",
"$",
"intNextPart",
"=",
"(",
"int",
")",
"$",
"nextPart",
";",
"if",
"(",
"$",
"nextPart",
"==",
"(",
"string",
")",
"$",
"intNextPart",
")",
"{",
"$",
"ids",
"[",
"]",
"=",
"$",
"intNextPart",
";",
"}",
"else",
"{",
"$",
"ids",
"[",
"]",
"=",
"$",
"nextPart",
";",
"}",
"$",
"nextPart",
"=",
"array_pop",
"(",
"$",
"oidParts",
")",
";",
"}",
"$",
"ids",
"=",
"array_reverse",
"(",
"$",
"ids",
")",
";",
"// get the type",
"$",
"type",
"=",
"$",
"nextPart",
";",
"// get the prefix",
"$",
"prefix",
"=",
"join",
"(",
"self",
"::",
"DELIMITER",
",",
"$",
"oidParts",
")",
";",
"return",
"[",
"'type'",
"=>",
"$",
"type",
",",
"'id'",
"=>",
"$",
"ids",
",",
"'prefix'",
"=>",
"$",
"prefix",
"]",
";",
"}"
] |
Parse the given object id string into it's parts
@param $oid The string
@return Associative array with keys 'type', 'id', 'prefix'
|
[
"Parse",
"the",
"given",
"object",
"id",
"string",
"into",
"it",
"s",
"parts"
] |
2542b8d4139464d39a9a8ce8a954dfecf700c41b
|
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/lib/persistence/ObjectId.php#L164-L204
|
26,721
|
iherwig/wcmf
|
src/wcmf/lib/persistence/ObjectId.php
|
ObjectId.containsDummyIds
|
public function containsDummyIds() {
foreach ($this->getId() as $id) {
if (self::isDummyId($id)) {
return true;
}
}
return false;
}
|
php
|
public function containsDummyIds() {
foreach ($this->getId() as $id) {
if (self::isDummyId($id)) {
return true;
}
}
return false;
}
|
[
"public",
"function",
"containsDummyIds",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"getId",
"(",
")",
"as",
"$",
"id",
")",
"{",
"if",
"(",
"self",
"::",
"isDummyId",
"(",
"$",
"id",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] |
Check if this object id contains a dummy id.
@return Boolean
|
[
"Check",
"if",
"this",
"object",
"id",
"contains",
"a",
"dummy",
"id",
"."
] |
2542b8d4139464d39a9a8ce8a954dfecf700c41b
|
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/lib/persistence/ObjectId.php#L242-L249
|
26,722
|
iherwig/wcmf
|
src/wcmf/lib/persistence/ObjectId.php
|
ObjectId.getNumberOfPKs
|
private static function getNumberOfPKs($type) {
if (!isset(self::$numPkKeys[$type])) {
$numPKs = 1;
$persistenceFacade = ObjectFactory::getInstance('persistenceFacade');
if ($persistenceFacade->isKnownType($type)) {
$mapper = $persistenceFacade->getMapper($type);
$numPKs = sizeof($mapper->getPKNames());
}
self::$numPkKeys[$type] = $numPKs;
}
return self::$numPkKeys[$type];
}
|
php
|
private static function getNumberOfPKs($type) {
if (!isset(self::$numPkKeys[$type])) {
$numPKs = 1;
$persistenceFacade = ObjectFactory::getInstance('persistenceFacade');
if ($persistenceFacade->isKnownType($type)) {
$mapper = $persistenceFacade->getMapper($type);
$numPKs = sizeof($mapper->getPKNames());
}
self::$numPkKeys[$type] = $numPKs;
}
return self::$numPkKeys[$type];
}
|
[
"private",
"static",
"function",
"getNumberOfPKs",
"(",
"$",
"type",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"numPkKeys",
"[",
"$",
"type",
"]",
")",
")",
"{",
"$",
"numPKs",
"=",
"1",
";",
"$",
"persistenceFacade",
"=",
"ObjectFactory",
"::",
"getInstance",
"(",
"'persistenceFacade'",
")",
";",
"if",
"(",
"$",
"persistenceFacade",
"->",
"isKnownType",
"(",
"$",
"type",
")",
")",
"{",
"$",
"mapper",
"=",
"$",
"persistenceFacade",
"->",
"getMapper",
"(",
"$",
"type",
")",
";",
"$",
"numPKs",
"=",
"sizeof",
"(",
"$",
"mapper",
"->",
"getPKNames",
"(",
")",
")",
";",
"}",
"self",
"::",
"$",
"numPkKeys",
"[",
"$",
"type",
"]",
"=",
"$",
"numPKs",
";",
"}",
"return",
"self",
"::",
"$",
"numPkKeys",
"[",
"$",
"type",
"]",
";",
"}"
] |
Get the number of primary keys a type has.
@param $type The type
@return Integer (1 if the type is unknown)
|
[
"Get",
"the",
"number",
"of",
"primary",
"keys",
"a",
"type",
"has",
"."
] |
2542b8d4139464d39a9a8ce8a954dfecf700c41b
|
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/lib/persistence/ObjectId.php#L256-L267
|
26,723
|
skie/plum_search
|
src/View/Helper/SearchHelper.php
|
SearchHelper.input
|
public function input(BaseParameter $param, $options = [])
{
$input = $this->_defaultInput($param);
$this->_setValue($input, $param);
$this->_setOptions($input, $param);
$this->_applyAutocompleteOptions($input, $param);
$input = Hash::merge($input, $options);
return $input;
}
|
php
|
public function input(BaseParameter $param, $options = [])
{
$input = $this->_defaultInput($param);
$this->_setValue($input, $param);
$this->_setOptions($input, $param);
$this->_applyAutocompleteOptions($input, $param);
$input = Hash::merge($input, $options);
return $input;
}
|
[
"public",
"function",
"input",
"(",
"BaseParameter",
"$",
"param",
",",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"input",
"=",
"$",
"this",
"->",
"_defaultInput",
"(",
"$",
"param",
")",
";",
"$",
"this",
"->",
"_setValue",
"(",
"$",
"input",
",",
"$",
"param",
")",
";",
"$",
"this",
"->",
"_setOptions",
"(",
"$",
"input",
",",
"$",
"param",
")",
";",
"$",
"this",
"->",
"_applyAutocompleteOptions",
"(",
"$",
"input",
",",
"$",
"param",
")",
";",
"$",
"input",
"=",
"Hash",
"::",
"merge",
"(",
"$",
"input",
",",
"$",
"options",
")",
";",
"return",
"$",
"input",
";",
"}"
] |
Generates input for parameter
@param BaseParameter $param Form parameter.
@param array $options Additional input options.
@return array
|
[
"Generates",
"input",
"for",
"parameter"
] |
24d981e240bff7c15731981d6f9b3056abdaf80e
|
https://github.com/skie/plum_search/blob/24d981e240bff7c15731981d6f9b3056abdaf80e/src/View/Helper/SearchHelper.php#L64-L73
|
26,724
|
skie/plum_search
|
src/View/Helper/SearchHelper.php
|
SearchHelper._defaultInput
|
protected function _defaultInput($param)
{
$input = $param->formInputConfig();
$name = $param->config('name');
$input += [
'type' => 'text',
'required' => false,
'label' => Inflector::humanize(preg_replace('/_id$/', '', $name)),
];
if (!$param->visible()) {
$input['type'] = 'hidden';
}
return $input;
}
|
php
|
protected function _defaultInput($param)
{
$input = $param->formInputConfig();
$name = $param->config('name');
$input += [
'type' => 'text',
'required' => false,
'label' => Inflector::humanize(preg_replace('/_id$/', '', $name)),
];
if (!$param->visible()) {
$input['type'] = 'hidden';
}
return $input;
}
|
[
"protected",
"function",
"_defaultInput",
"(",
"$",
"param",
")",
"{",
"$",
"input",
"=",
"$",
"param",
"->",
"formInputConfig",
"(",
")",
";",
"$",
"name",
"=",
"$",
"param",
"->",
"config",
"(",
"'name'",
")",
";",
"$",
"input",
"+=",
"[",
"'type'",
"=>",
"'text'",
",",
"'required'",
"=>",
"false",
",",
"'label'",
"=>",
"Inflector",
"::",
"humanize",
"(",
"preg_replace",
"(",
"'/_id$/'",
",",
"''",
",",
"$",
"name",
")",
")",
",",
"]",
";",
"if",
"(",
"!",
"$",
"param",
"->",
"visible",
"(",
")",
")",
"{",
"$",
"input",
"[",
"'type'",
"]",
"=",
"'hidden'",
";",
"}",
"return",
"$",
"input",
";",
"}"
] |
Generates default input for parameter
@param BaseParameter $param Form parameter.
@return array
|
[
"Generates",
"default",
"input",
"for",
"parameter"
] |
24d981e240bff7c15731981d6f9b3056abdaf80e
|
https://github.com/skie/plum_search/blob/24d981e240bff7c15731981d6f9b3056abdaf80e/src/View/Helper/SearchHelper.php#L81-L95
|
26,725
|
skie/plum_search
|
src/View/Helper/SearchHelper.php
|
SearchHelper._setValue
|
protected function _setValue(&$input, $param)
{
$value = $param->value();
if (!$param->isEmpty()) {
$input['value'] = $value;
} else {
$input['value'] = '';
}
return $input;
}
|
php
|
protected function _setValue(&$input, $param)
{
$value = $param->value();
if (!$param->isEmpty()) {
$input['value'] = $value;
} else {
$input['value'] = '';
}
return $input;
}
|
[
"protected",
"function",
"_setValue",
"(",
"&",
"$",
"input",
",",
"$",
"param",
")",
"{",
"$",
"value",
"=",
"$",
"param",
"->",
"value",
"(",
")",
";",
"if",
"(",
"!",
"$",
"param",
"->",
"isEmpty",
"(",
")",
")",
"{",
"$",
"input",
"[",
"'value'",
"]",
"=",
"$",
"value",
";",
"}",
"else",
"{",
"$",
"input",
"[",
"'value'",
"]",
"=",
"''",
";",
"}",
"return",
"$",
"input",
";",
"}"
] |
Set value for field
@param array $input Field options.
@param BaseParameter $param Form parameter.
@return array
|
[
"Set",
"value",
"for",
"field"
] |
24d981e240bff7c15731981d6f9b3056abdaf80e
|
https://github.com/skie/plum_search/blob/24d981e240bff7c15731981d6f9b3056abdaf80e/src/View/Helper/SearchHelper.php#L104-L114
|
26,726
|
skie/plum_search
|
src/View/Helper/SearchHelper.php
|
SearchHelper._setOptions
|
protected function _setOptions(&$input, $param)
{
if ($param->hasOptions() && !isset($input['empty'])) {
$input['empty'] = true;
}
return $input;
}
|
php
|
protected function _setOptions(&$input, $param)
{
if ($param->hasOptions() && !isset($input['empty'])) {
$input['empty'] = true;
}
return $input;
}
|
[
"protected",
"function",
"_setOptions",
"(",
"&",
"$",
"input",
",",
"$",
"param",
")",
"{",
"if",
"(",
"$",
"param",
"->",
"hasOptions",
"(",
")",
"&&",
"!",
"isset",
"(",
"$",
"input",
"[",
"'empty'",
"]",
")",
")",
"{",
"$",
"input",
"[",
"'empty'",
"]",
"=",
"true",
";",
"}",
"return",
"$",
"input",
";",
"}"
] |
Set options for field
@param array $input Field options.
@param BaseParameter $param Form parameter.
@return array
|
[
"Set",
"options",
"for",
"field"
] |
24d981e240bff7c15731981d6f9b3056abdaf80e
|
https://github.com/skie/plum_search/blob/24d981e240bff7c15731981d6f9b3056abdaf80e/src/View/Helper/SearchHelper.php#L123-L130
|
26,727
|
skie/plum_search
|
src/View/Helper/SearchHelper.php
|
SearchHelper._applyAutocompleteOptions
|
protected function _applyAutocompleteOptions(&$input, $param)
{
if ($param instanceof AutocompleteParameter) {
$input['data-url'] = $param->autocompleteUrl();
$input['class'] = 'autocomplete';
$input['data-name'] = $param->config('name');
}
return $input;
}
|
php
|
protected function _applyAutocompleteOptions(&$input, $param)
{
if ($param instanceof AutocompleteParameter) {
$input['data-url'] = $param->autocompleteUrl();
$input['class'] = 'autocomplete';
$input['data-name'] = $param->config('name');
}
return $input;
}
|
[
"protected",
"function",
"_applyAutocompleteOptions",
"(",
"&",
"$",
"input",
",",
"$",
"param",
")",
"{",
"if",
"(",
"$",
"param",
"instanceof",
"AutocompleteParameter",
")",
"{",
"$",
"input",
"[",
"'data-url'",
"]",
"=",
"$",
"param",
"->",
"autocompleteUrl",
"(",
")",
";",
"$",
"input",
"[",
"'class'",
"]",
"=",
"'autocomplete'",
";",
"$",
"input",
"[",
"'data-name'",
"]",
"=",
"$",
"param",
"->",
"config",
"(",
"'name'",
")",
";",
"}",
"return",
"$",
"input",
";",
"}"
] |
Set autocomplete settings for field
@param array $input Field options.
@param BaseParameter $param Form parameter.
@return array
|
[
"Set",
"autocomplete",
"settings",
"for",
"field"
] |
24d981e240bff7c15731981d6f9b3056abdaf80e
|
https://github.com/skie/plum_search/blob/24d981e240bff7c15731981d6f9b3056abdaf80e/src/View/Helper/SearchHelper.php#L139-L148
|
26,728
|
iherwig/wcmf
|
src/wcmf/lib/i18n/impl/DefaultLocalization.php
|
DefaultLocalization.loadTranslationImpl
|
protected function loadTranslationImpl(PersistentObject $object, $lang, $useDefaults=true) {
if ($object == null) {
throw new IllegalArgumentException('Cannot load translation for null');
}
$oidStr = $object->getOID()->__toString();
$cacheKey = $oidStr.'.'.$lang.'.'.$useDefaults;
if (!isset($this->translatedObjects[$cacheKey])) {
$translatedObject = $object;
// load the translations and translate the object for any language
// different to the default language
// NOTE: the original object will be detached from the transaction
if ($lang != $this->getDefaultLanguage()) {
$transaction = $this->persistenceFacade->getTransaction();
$transaction->detach($translatedObject->getOID());
$translatedObject = clone $object;
$query = new ObjectQuery($this->translationType, __CLASS__.'load_save');
$tpl = $query->getObjectTemplate($this->translationType);
$tpl->setValue('objectid', Criteria::asValue('=', $oidStr));
$tpl->setValue('language', Criteria::asValue('=', $lang));
$translationInstances = $query->execute(BuildDepth::SINGLE);
// create map for faster access
$translations = [];
foreach ($translationInstances as $translationInstance) {
$translations[$translationInstance->getValue('attribute')] = $translationInstance->getValue('translation');
}
// set the translated values in the object
$iter = new NodeValueIterator($object, false);
for($iter->rewind(); $iter->valid(); $iter->next()) {
$valueName = $iter->key();
$translation = isset($translations[$valueName]) ? $translations[$valueName] : '';
$this->setTranslatedValue($translatedObject, $valueName, $translation, $useDefaults);
}
}
$this->translatedObjects[$cacheKey] = $translatedObject;
}
return $this->translatedObjects[$cacheKey];
}
|
php
|
protected function loadTranslationImpl(PersistentObject $object, $lang, $useDefaults=true) {
if ($object == null) {
throw new IllegalArgumentException('Cannot load translation for null');
}
$oidStr = $object->getOID()->__toString();
$cacheKey = $oidStr.'.'.$lang.'.'.$useDefaults;
if (!isset($this->translatedObjects[$cacheKey])) {
$translatedObject = $object;
// load the translations and translate the object for any language
// different to the default language
// NOTE: the original object will be detached from the transaction
if ($lang != $this->getDefaultLanguage()) {
$transaction = $this->persistenceFacade->getTransaction();
$transaction->detach($translatedObject->getOID());
$translatedObject = clone $object;
$query = new ObjectQuery($this->translationType, __CLASS__.'load_save');
$tpl = $query->getObjectTemplate($this->translationType);
$tpl->setValue('objectid', Criteria::asValue('=', $oidStr));
$tpl->setValue('language', Criteria::asValue('=', $lang));
$translationInstances = $query->execute(BuildDepth::SINGLE);
// create map for faster access
$translations = [];
foreach ($translationInstances as $translationInstance) {
$translations[$translationInstance->getValue('attribute')] = $translationInstance->getValue('translation');
}
// set the translated values in the object
$iter = new NodeValueIterator($object, false);
for($iter->rewind(); $iter->valid(); $iter->next()) {
$valueName = $iter->key();
$translation = isset($translations[$valueName]) ? $translations[$valueName] : '';
$this->setTranslatedValue($translatedObject, $valueName, $translation, $useDefaults);
}
}
$this->translatedObjects[$cacheKey] = $translatedObject;
}
return $this->translatedObjects[$cacheKey];
}
|
[
"protected",
"function",
"loadTranslationImpl",
"(",
"PersistentObject",
"$",
"object",
",",
"$",
"lang",
",",
"$",
"useDefaults",
"=",
"true",
")",
"{",
"if",
"(",
"$",
"object",
"==",
"null",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"'Cannot load translation for null'",
")",
";",
"}",
"$",
"oidStr",
"=",
"$",
"object",
"->",
"getOID",
"(",
")",
"->",
"__toString",
"(",
")",
";",
"$",
"cacheKey",
"=",
"$",
"oidStr",
".",
"'.'",
".",
"$",
"lang",
".",
"'.'",
".",
"$",
"useDefaults",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"translatedObjects",
"[",
"$",
"cacheKey",
"]",
")",
")",
"{",
"$",
"translatedObject",
"=",
"$",
"object",
";",
"// load the translations and translate the object for any language",
"// different to the default language",
"// NOTE: the original object will be detached from the transaction",
"if",
"(",
"$",
"lang",
"!=",
"$",
"this",
"->",
"getDefaultLanguage",
"(",
")",
")",
"{",
"$",
"transaction",
"=",
"$",
"this",
"->",
"persistenceFacade",
"->",
"getTransaction",
"(",
")",
";",
"$",
"transaction",
"->",
"detach",
"(",
"$",
"translatedObject",
"->",
"getOID",
"(",
")",
")",
";",
"$",
"translatedObject",
"=",
"clone",
"$",
"object",
";",
"$",
"query",
"=",
"new",
"ObjectQuery",
"(",
"$",
"this",
"->",
"translationType",
",",
"__CLASS__",
".",
"'load_save'",
")",
";",
"$",
"tpl",
"=",
"$",
"query",
"->",
"getObjectTemplate",
"(",
"$",
"this",
"->",
"translationType",
")",
";",
"$",
"tpl",
"->",
"setValue",
"(",
"'objectid'",
",",
"Criteria",
"::",
"asValue",
"(",
"'='",
",",
"$",
"oidStr",
")",
")",
";",
"$",
"tpl",
"->",
"setValue",
"(",
"'language'",
",",
"Criteria",
"::",
"asValue",
"(",
"'='",
",",
"$",
"lang",
")",
")",
";",
"$",
"translationInstances",
"=",
"$",
"query",
"->",
"execute",
"(",
"BuildDepth",
"::",
"SINGLE",
")",
";",
"// create map for faster access",
"$",
"translations",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"translationInstances",
"as",
"$",
"translationInstance",
")",
"{",
"$",
"translations",
"[",
"$",
"translationInstance",
"->",
"getValue",
"(",
"'attribute'",
")",
"]",
"=",
"$",
"translationInstance",
"->",
"getValue",
"(",
"'translation'",
")",
";",
"}",
"// set the translated values in the object",
"$",
"iter",
"=",
"new",
"NodeValueIterator",
"(",
"$",
"object",
",",
"false",
")",
";",
"for",
"(",
"$",
"iter",
"->",
"rewind",
"(",
")",
";",
"$",
"iter",
"->",
"valid",
"(",
")",
";",
"$",
"iter",
"->",
"next",
"(",
")",
")",
"{",
"$",
"valueName",
"=",
"$",
"iter",
"->",
"key",
"(",
")",
";",
"$",
"translation",
"=",
"isset",
"(",
"$",
"translations",
"[",
"$",
"valueName",
"]",
")",
"?",
"$",
"translations",
"[",
"$",
"valueName",
"]",
":",
"''",
";",
"$",
"this",
"->",
"setTranslatedValue",
"(",
"$",
"translatedObject",
",",
"$",
"valueName",
",",
"$",
"translation",
",",
"$",
"useDefaults",
")",
";",
"}",
"}",
"$",
"this",
"->",
"translatedObjects",
"[",
"$",
"cacheKey",
"]",
"=",
"$",
"translatedObject",
";",
"}",
"return",
"$",
"this",
"->",
"translatedObjects",
"[",
"$",
"cacheKey",
"]",
";",
"}"
] |
Load a translation of a single entity for a specific language.
@param $object PersistentObject instance to load the translation into. The object
is supposed to have it's values in the default language.
@param $lang The language of the translation to load.
@param $useDefaults Boolean whether to use the default language values
for untranslated/empty values or not. Optional, default is true.
@return PersistentObject instance
@throws IllegalArgumentException
|
[
"Load",
"a",
"translation",
"of",
"a",
"single",
"entity",
"for",
"a",
"specific",
"language",
"."
] |
2542b8d4139464d39a9a8ce8a954dfecf700c41b
|
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/lib/i18n/impl/DefaultLocalization.php#L220-L262
|
26,729
|
iherwig/wcmf
|
src/wcmf/lib/i18n/impl/DefaultLocalization.php
|
DefaultLocalization.saveTranslationImpl
|
protected function saveTranslationImpl(PersistentObject $object, $lang) {
// if the requested language is the default language, do nothing
if ($lang == $this->getDefaultLanguage()) {
// nothing to do
}
// save the translations for any other language
else {
$object->beforeUpdate();
// get the existing translations for the requested language
$query = new ObjectQuery($this->translationType, __CLASS__.'load_save');
$tpl = $query->getObjectTemplate($this->translationType);
$tpl->setValue('objectid', Criteria::asValue('=', $object->getOID()->__toString()));
$tpl->setValue('language', Criteria::asValue('=', $lang));
$translationInstances = $query->execute(BuildDepth::SINGLE);
// create map for faster access
$translations = [];
foreach ($translationInstances as $translationInstance) {
$translations[$translationInstance->getValue('attribute')] = $translationInstance;
}
// save the translations, ignore pk values
$pkNames = $object->getMapper()->getPkNames();
$iter = new NodeValueIterator($object, false);
for($iter->rewind(); $iter->valid(); $iter->next()) {
$valueName = $iter->key();
if (!in_array($valueName, $pkNames)) {
$curIterNode = $iter->currentNode();
$translation = isset($translations[$valueName]) ? $translations[$valueName] : null;
$this->saveTranslatedValue($curIterNode, $valueName, $translation, $lang);
}
}
}
}
|
php
|
protected function saveTranslationImpl(PersistentObject $object, $lang) {
// if the requested language is the default language, do nothing
if ($lang == $this->getDefaultLanguage()) {
// nothing to do
}
// save the translations for any other language
else {
$object->beforeUpdate();
// get the existing translations for the requested language
$query = new ObjectQuery($this->translationType, __CLASS__.'load_save');
$tpl = $query->getObjectTemplate($this->translationType);
$tpl->setValue('objectid', Criteria::asValue('=', $object->getOID()->__toString()));
$tpl->setValue('language', Criteria::asValue('=', $lang));
$translationInstances = $query->execute(BuildDepth::SINGLE);
// create map for faster access
$translations = [];
foreach ($translationInstances as $translationInstance) {
$translations[$translationInstance->getValue('attribute')] = $translationInstance;
}
// save the translations, ignore pk values
$pkNames = $object->getMapper()->getPkNames();
$iter = new NodeValueIterator($object, false);
for($iter->rewind(); $iter->valid(); $iter->next()) {
$valueName = $iter->key();
if (!in_array($valueName, $pkNames)) {
$curIterNode = $iter->currentNode();
$translation = isset($translations[$valueName]) ? $translations[$valueName] : null;
$this->saveTranslatedValue($curIterNode, $valueName, $translation, $lang);
}
}
}
}
|
[
"protected",
"function",
"saveTranslationImpl",
"(",
"PersistentObject",
"$",
"object",
",",
"$",
"lang",
")",
"{",
"// if the requested language is the default language, do nothing",
"if",
"(",
"$",
"lang",
"==",
"$",
"this",
"->",
"getDefaultLanguage",
"(",
")",
")",
"{",
"// nothing to do",
"}",
"// save the translations for any other language",
"else",
"{",
"$",
"object",
"->",
"beforeUpdate",
"(",
")",
";",
"// get the existing translations for the requested language",
"$",
"query",
"=",
"new",
"ObjectQuery",
"(",
"$",
"this",
"->",
"translationType",
",",
"__CLASS__",
".",
"'load_save'",
")",
";",
"$",
"tpl",
"=",
"$",
"query",
"->",
"getObjectTemplate",
"(",
"$",
"this",
"->",
"translationType",
")",
";",
"$",
"tpl",
"->",
"setValue",
"(",
"'objectid'",
",",
"Criteria",
"::",
"asValue",
"(",
"'='",
",",
"$",
"object",
"->",
"getOID",
"(",
")",
"->",
"__toString",
"(",
")",
")",
")",
";",
"$",
"tpl",
"->",
"setValue",
"(",
"'language'",
",",
"Criteria",
"::",
"asValue",
"(",
"'='",
",",
"$",
"lang",
")",
")",
";",
"$",
"translationInstances",
"=",
"$",
"query",
"->",
"execute",
"(",
"BuildDepth",
"::",
"SINGLE",
")",
";",
"// create map for faster access",
"$",
"translations",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"translationInstances",
"as",
"$",
"translationInstance",
")",
"{",
"$",
"translations",
"[",
"$",
"translationInstance",
"->",
"getValue",
"(",
"'attribute'",
")",
"]",
"=",
"$",
"translationInstance",
";",
"}",
"// save the translations, ignore pk values",
"$",
"pkNames",
"=",
"$",
"object",
"->",
"getMapper",
"(",
")",
"->",
"getPkNames",
"(",
")",
";",
"$",
"iter",
"=",
"new",
"NodeValueIterator",
"(",
"$",
"object",
",",
"false",
")",
";",
"for",
"(",
"$",
"iter",
"->",
"rewind",
"(",
")",
";",
"$",
"iter",
"->",
"valid",
"(",
")",
";",
"$",
"iter",
"->",
"next",
"(",
")",
")",
"{",
"$",
"valueName",
"=",
"$",
"iter",
"->",
"key",
"(",
")",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"valueName",
",",
"$",
"pkNames",
")",
")",
"{",
"$",
"curIterNode",
"=",
"$",
"iter",
"->",
"currentNode",
"(",
")",
";",
"$",
"translation",
"=",
"isset",
"(",
"$",
"translations",
"[",
"$",
"valueName",
"]",
")",
"?",
"$",
"translations",
"[",
"$",
"valueName",
"]",
":",
"null",
";",
"$",
"this",
"->",
"saveTranslatedValue",
"(",
"$",
"curIterNode",
",",
"$",
"valueName",
",",
"$",
"translation",
",",
"$",
"lang",
")",
";",
"}",
"}",
"}",
"}"
] |
Save a translation of a single entity for a specific language. Only the
values that have a non-empty value are considered as translations and stored.
@param $object An instance of the entity type that holds the translations as values.
@param $lang The language of the translation.
|
[
"Save",
"a",
"translation",
"of",
"a",
"single",
"entity",
"for",
"a",
"specific",
"language",
".",
"Only",
"the",
"values",
"that",
"have",
"a",
"non",
"-",
"empty",
"value",
"are",
"considered",
"as",
"translations",
"and",
"stored",
"."
] |
2542b8d4139464d39a9a8ce8a954dfecf700c41b
|
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/lib/i18n/impl/DefaultLocalization.php#L291-L325
|
26,730
|
iherwig/wcmf
|
src/wcmf/lib/i18n/impl/DefaultLocalization.php
|
DefaultLocalization.setTranslatedValue
|
private function setTranslatedValue(PersistentObject $object, $valueName, $translation, $useDefaults) {
$mapper = $object->getMapper();
$isTranslatable = $mapper != null && $mapper->hasAttribute($valueName) ? $mapper->getAttribute($valueName)->hasTag('TRANSLATABLE') : false;
if ($isTranslatable) {
// empty the value, if the default language values should not be used
if (!$useDefaults) {
$object->setValue($valueName, null, true);
}
// translate the value
if (!($useDefaults && strlen($translation) == 0)) {
$object->setValue($valueName, $translation, true);
}
}
}
|
php
|
private function setTranslatedValue(PersistentObject $object, $valueName, $translation, $useDefaults) {
$mapper = $object->getMapper();
$isTranslatable = $mapper != null && $mapper->hasAttribute($valueName) ? $mapper->getAttribute($valueName)->hasTag('TRANSLATABLE') : false;
if ($isTranslatable) {
// empty the value, if the default language values should not be used
if (!$useDefaults) {
$object->setValue($valueName, null, true);
}
// translate the value
if (!($useDefaults && strlen($translation) == 0)) {
$object->setValue($valueName, $translation, true);
}
}
}
|
[
"private",
"function",
"setTranslatedValue",
"(",
"PersistentObject",
"$",
"object",
",",
"$",
"valueName",
",",
"$",
"translation",
",",
"$",
"useDefaults",
")",
"{",
"$",
"mapper",
"=",
"$",
"object",
"->",
"getMapper",
"(",
")",
";",
"$",
"isTranslatable",
"=",
"$",
"mapper",
"!=",
"null",
"&&",
"$",
"mapper",
"->",
"hasAttribute",
"(",
"$",
"valueName",
")",
"?",
"$",
"mapper",
"->",
"getAttribute",
"(",
"$",
"valueName",
")",
"->",
"hasTag",
"(",
"'TRANSLATABLE'",
")",
":",
"false",
";",
"if",
"(",
"$",
"isTranslatable",
")",
"{",
"// empty the value, if the default language values should not be used",
"if",
"(",
"!",
"$",
"useDefaults",
")",
"{",
"$",
"object",
"->",
"setValue",
"(",
"$",
"valueName",
",",
"null",
",",
"true",
")",
";",
"}",
"// translate the value",
"if",
"(",
"!",
"(",
"$",
"useDefaults",
"&&",
"strlen",
"(",
"$",
"translation",
")",
"==",
"0",
")",
")",
"{",
"$",
"object",
"->",
"setValue",
"(",
"$",
"valueName",
",",
"$",
"translation",
",",
"true",
")",
";",
"}",
"}",
"}"
] |
Set a translated value in the given PersistentObject instance.
@param $object The object to set the value on. The object
is supposed to have it's values in the default language.
@param $valueName The name of the value to translate
@param $translation Translation for the value.
@param $useDefaults Boolean whether to use the default language if no
translation is found or not.
|
[
"Set",
"a",
"translated",
"value",
"in",
"the",
"given",
"PersistentObject",
"instance",
"."
] |
2542b8d4139464d39a9a8ce8a954dfecf700c41b
|
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/lib/i18n/impl/DefaultLocalization.php#L385-L398
|
26,731
|
iherwig/wcmf
|
src/wcmf/lib/i18n/impl/DefaultLocalization.php
|
DefaultLocalization.saveTranslatedValue
|
private function saveTranslatedValue(PersistentObject $object, $valueName, $existingTranslation, $lang) {
$mapper = $object->getMapper();
$isTranslatable = $mapper != null && $mapper->hasAttribute($valueName) ? $mapper->getAttribute($valueName)->hasTag('TRANSLATABLE') : false;
if ($isTranslatable) {
$value = $object->getValue($valueName);
$translation = $existingTranslation;
$valueIsEmpty = $value === null || $value === '';
// if no translation exists and the value is not empty, create a new translation
if ($translation == null && !$valueIsEmpty) {
$translation = $this->persistenceFacade->create($this->translationType);
}
// if a translation exists and the value is empty, remove the existing translation
if ($translation != null && $valueIsEmpty) {
$translation->delete();
$translation = null;
}
if ($translation) {
// set all required properties
$oid = $object->getOID()->__toString();
$translation->setValue('objectid', $oid);
$translation->setValue('attribute', $valueName);
$translation->setValue('translation', $value);
$translation->setValue('language', $lang);
// store translation for oid update if necessary (see afterCreate())
if (!isset($this->createdTranslations[$oid])) {
$this->createdTranslations[$oid] = [];
}
$this->createdTranslations[$oid][] = $translation;
}
}
}
|
php
|
private function saveTranslatedValue(PersistentObject $object, $valueName, $existingTranslation, $lang) {
$mapper = $object->getMapper();
$isTranslatable = $mapper != null && $mapper->hasAttribute($valueName) ? $mapper->getAttribute($valueName)->hasTag('TRANSLATABLE') : false;
if ($isTranslatable) {
$value = $object->getValue($valueName);
$translation = $existingTranslation;
$valueIsEmpty = $value === null || $value === '';
// if no translation exists and the value is not empty, create a new translation
if ($translation == null && !$valueIsEmpty) {
$translation = $this->persistenceFacade->create($this->translationType);
}
// if a translation exists and the value is empty, remove the existing translation
if ($translation != null && $valueIsEmpty) {
$translation->delete();
$translation = null;
}
if ($translation) {
// set all required properties
$oid = $object->getOID()->__toString();
$translation->setValue('objectid', $oid);
$translation->setValue('attribute', $valueName);
$translation->setValue('translation', $value);
$translation->setValue('language', $lang);
// store translation for oid update if necessary (see afterCreate())
if (!isset($this->createdTranslations[$oid])) {
$this->createdTranslations[$oid] = [];
}
$this->createdTranslations[$oid][] = $translation;
}
}
}
|
[
"private",
"function",
"saveTranslatedValue",
"(",
"PersistentObject",
"$",
"object",
",",
"$",
"valueName",
",",
"$",
"existingTranslation",
",",
"$",
"lang",
")",
"{",
"$",
"mapper",
"=",
"$",
"object",
"->",
"getMapper",
"(",
")",
";",
"$",
"isTranslatable",
"=",
"$",
"mapper",
"!=",
"null",
"&&",
"$",
"mapper",
"->",
"hasAttribute",
"(",
"$",
"valueName",
")",
"?",
"$",
"mapper",
"->",
"getAttribute",
"(",
"$",
"valueName",
")",
"->",
"hasTag",
"(",
"'TRANSLATABLE'",
")",
":",
"false",
";",
"if",
"(",
"$",
"isTranslatable",
")",
"{",
"$",
"value",
"=",
"$",
"object",
"->",
"getValue",
"(",
"$",
"valueName",
")",
";",
"$",
"translation",
"=",
"$",
"existingTranslation",
";",
"$",
"valueIsEmpty",
"=",
"$",
"value",
"===",
"null",
"||",
"$",
"value",
"===",
"''",
";",
"// if no translation exists and the value is not empty, create a new translation",
"if",
"(",
"$",
"translation",
"==",
"null",
"&&",
"!",
"$",
"valueIsEmpty",
")",
"{",
"$",
"translation",
"=",
"$",
"this",
"->",
"persistenceFacade",
"->",
"create",
"(",
"$",
"this",
"->",
"translationType",
")",
";",
"}",
"// if a translation exists and the value is empty, remove the existing translation",
"if",
"(",
"$",
"translation",
"!=",
"null",
"&&",
"$",
"valueIsEmpty",
")",
"{",
"$",
"translation",
"->",
"delete",
"(",
")",
";",
"$",
"translation",
"=",
"null",
";",
"}",
"if",
"(",
"$",
"translation",
")",
"{",
"// set all required properties",
"$",
"oid",
"=",
"$",
"object",
"->",
"getOID",
"(",
")",
"->",
"__toString",
"(",
")",
";",
"$",
"translation",
"->",
"setValue",
"(",
"'objectid'",
",",
"$",
"oid",
")",
";",
"$",
"translation",
"->",
"setValue",
"(",
"'attribute'",
",",
"$",
"valueName",
")",
";",
"$",
"translation",
"->",
"setValue",
"(",
"'translation'",
",",
"$",
"value",
")",
";",
"$",
"translation",
"->",
"setValue",
"(",
"'language'",
",",
"$",
"lang",
")",
";",
"// store translation for oid update if necessary (see afterCreate())",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"createdTranslations",
"[",
"$",
"oid",
"]",
")",
")",
"{",
"$",
"this",
"->",
"createdTranslations",
"[",
"$",
"oid",
"]",
"=",
"[",
"]",
";",
"}",
"$",
"this",
"->",
"createdTranslations",
"[",
"$",
"oid",
"]",
"[",
"]",
"=",
"$",
"translation",
";",
"}",
"}",
"}"
] |
Save translated values for the given object
@param $object The object to save the translations on
@param $valueName The name of the value to translate
@param $existingTranslation Existing translation instance for the value (might be null).
@param $lang The language of the translations.
|
[
"Save",
"translated",
"values",
"for",
"the",
"given",
"object"
] |
2542b8d4139464d39a9a8ce8a954dfecf700c41b
|
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/lib/i18n/impl/DefaultLocalization.php#L407-L441
|
26,732
|
iherwig/wcmf
|
src/wcmf/lib/i18n/impl/DefaultLocalization.php
|
DefaultLocalization.afterCreate
|
public function afterCreate(PersistenceEvent $event) {
if ($event->getAction() == PersistenceAction::CREATE) {
$oldOid = $event->getOldOid();
$oldOidStr = $oldOid != null ? $oldOid->__toString() : null;
if ($oldOidStr != null && isset($this->createdTranslations[$oldOidStr])) {
foreach ($this->createdTranslations[$oldOidStr] as $translation) {
$translation->setValue('objectid', $event->getObject()->getOID()->__toString());
}
}
}
}
|
php
|
public function afterCreate(PersistenceEvent $event) {
if ($event->getAction() == PersistenceAction::CREATE) {
$oldOid = $event->getOldOid();
$oldOidStr = $oldOid != null ? $oldOid->__toString() : null;
if ($oldOidStr != null && isset($this->createdTranslations[$oldOidStr])) {
foreach ($this->createdTranslations[$oldOidStr] as $translation) {
$translation->setValue('objectid', $event->getObject()->getOID()->__toString());
}
}
}
}
|
[
"public",
"function",
"afterCreate",
"(",
"PersistenceEvent",
"$",
"event",
")",
"{",
"if",
"(",
"$",
"event",
"->",
"getAction",
"(",
")",
"==",
"PersistenceAction",
"::",
"CREATE",
")",
"{",
"$",
"oldOid",
"=",
"$",
"event",
"->",
"getOldOid",
"(",
")",
";",
"$",
"oldOidStr",
"=",
"$",
"oldOid",
"!=",
"null",
"?",
"$",
"oldOid",
"->",
"__toString",
"(",
")",
":",
"null",
";",
"if",
"(",
"$",
"oldOidStr",
"!=",
"null",
"&&",
"isset",
"(",
"$",
"this",
"->",
"createdTranslations",
"[",
"$",
"oldOidStr",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"createdTranslations",
"[",
"$",
"oldOidStr",
"]",
"as",
"$",
"translation",
")",
"{",
"$",
"translation",
"->",
"setValue",
"(",
"'objectid'",
",",
"$",
"event",
"->",
"getObject",
"(",
")",
"->",
"getOID",
"(",
")",
"->",
"__toString",
"(",
")",
")",
";",
"}",
"}",
"}",
"}"
] |
Update oids after create
@param $event
|
[
"Update",
"oids",
"after",
"create"
] |
2542b8d4139464d39a9a8ce8a954dfecf700c41b
|
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/lib/i18n/impl/DefaultLocalization.php#L447-L457
|
26,733
|
iherwig/wcmf
|
src/wcmf/lib/security/impl/DefaultPermissionManager.php
|
DefaultPermissionManager.setPermissionType
|
public function setPermissionType($permissionType) {
$this->permissionType = $permissionType;
$this->actionKeyProvider->setEntityType($this->permissionType);
}
|
php
|
public function setPermissionType($permissionType) {
$this->permissionType = $permissionType;
$this->actionKeyProvider->setEntityType($this->permissionType);
}
|
[
"public",
"function",
"setPermissionType",
"(",
"$",
"permissionType",
")",
"{",
"$",
"this",
"->",
"permissionType",
"=",
"$",
"permissionType",
";",
"$",
"this",
"->",
"actionKeyProvider",
"->",
"setEntityType",
"(",
"$",
"this",
"->",
"permissionType",
")",
";",
"}"
] |
Set the entity type name of Permission instances.
@param $permissionType String
|
[
"Set",
"the",
"entity",
"type",
"name",
"of",
"Permission",
"instances",
"."
] |
2542b8d4139464d39a9a8ce8a954dfecf700c41b
|
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/lib/security/impl/DefaultPermissionManager.php#L63-L66
|
26,734
|
iherwig/wcmf
|
src/wcmf/lib/security/impl/DefaultPermissionManager.php
|
DefaultPermissionManager.getPermissionInstance
|
protected function getPermissionInstance($resource, $context, $action) {
$query = new ObjectQuery($this->permissionType, __CLASS__.__METHOD__);
$tpl = $query->getObjectTemplate($this->permissionType);
$tpl->setValue('resource', Criteria::asValue('=', $resource));
$tpl->setValue('context', Criteria::asValue('=', $context));
$tpl->setValue('action', Criteria::asValue('=', $action));
$permissions = $query->execute(BuildDepth::SINGLE);
return (sizeof($permissions) > 0) ? $permissions[0] : null;
}
|
php
|
protected function getPermissionInstance($resource, $context, $action) {
$query = new ObjectQuery($this->permissionType, __CLASS__.__METHOD__);
$tpl = $query->getObjectTemplate($this->permissionType);
$tpl->setValue('resource', Criteria::asValue('=', $resource));
$tpl->setValue('context', Criteria::asValue('=', $context));
$tpl->setValue('action', Criteria::asValue('=', $action));
$permissions = $query->execute(BuildDepth::SINGLE);
return (sizeof($permissions) > 0) ? $permissions[0] : null;
}
|
[
"protected",
"function",
"getPermissionInstance",
"(",
"$",
"resource",
",",
"$",
"context",
",",
"$",
"action",
")",
"{",
"$",
"query",
"=",
"new",
"ObjectQuery",
"(",
"$",
"this",
"->",
"permissionType",
",",
"__CLASS__",
".",
"__METHOD__",
")",
";",
"$",
"tpl",
"=",
"$",
"query",
"->",
"getObjectTemplate",
"(",
"$",
"this",
"->",
"permissionType",
")",
";",
"$",
"tpl",
"->",
"setValue",
"(",
"'resource'",
",",
"Criteria",
"::",
"asValue",
"(",
"'='",
",",
"$",
"resource",
")",
")",
";",
"$",
"tpl",
"->",
"setValue",
"(",
"'context'",
",",
"Criteria",
"::",
"asValue",
"(",
"'='",
",",
"$",
"context",
")",
")",
";",
"$",
"tpl",
"->",
"setValue",
"(",
"'action'",
",",
"Criteria",
"::",
"asValue",
"(",
"'='",
",",
"$",
"action",
")",
")",
";",
"$",
"permissions",
"=",
"$",
"query",
"->",
"execute",
"(",
"BuildDepth",
"::",
"SINGLE",
")",
";",
"return",
"(",
"sizeof",
"(",
"$",
"permissions",
")",
">",
"0",
")",
"?",
"$",
"permissions",
"[",
"0",
"]",
":",
"null",
";",
"}"
] |
Get the permission object that matches the given parameters
@param $resource Resource
@param $context Context
@param $action Action
@return Instance of _permissionType or null
|
[
"Get",
"the",
"permission",
"object",
"that",
"matches",
"the",
"given",
"parameters"
] |
2542b8d4139464d39a9a8ce8a954dfecf700c41b
|
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/lib/security/impl/DefaultPermissionManager.php#L168-L176
|
26,735
|
iherwig/wcmf
|
src/wcmf/lib/security/impl/DefaultPermissionManager.php
|
DefaultPermissionManager.createPermissionObject
|
protected function createPermissionObject($resource, $context, $action, $roles) {
$permission = $this->persistenceFacade->create($this->permissionType);
$permission->setValue('resource', $resource);
$permission->setValue('context', $context);
$permission->setValue('action', $action);
$permission->setValue('roles', $roles);
return $permission;
}
|
php
|
protected function createPermissionObject($resource, $context, $action, $roles) {
$permission = $this->persistenceFacade->create($this->permissionType);
$permission->setValue('resource', $resource);
$permission->setValue('context', $context);
$permission->setValue('action', $action);
$permission->setValue('roles', $roles);
return $permission;
}
|
[
"protected",
"function",
"createPermissionObject",
"(",
"$",
"resource",
",",
"$",
"context",
",",
"$",
"action",
",",
"$",
"roles",
")",
"{",
"$",
"permission",
"=",
"$",
"this",
"->",
"persistenceFacade",
"->",
"create",
"(",
"$",
"this",
"->",
"permissionType",
")",
";",
"$",
"permission",
"->",
"setValue",
"(",
"'resource'",
",",
"$",
"resource",
")",
";",
"$",
"permission",
"->",
"setValue",
"(",
"'context'",
",",
"$",
"context",
")",
";",
"$",
"permission",
"->",
"setValue",
"(",
"'action'",
",",
"$",
"action",
")",
";",
"$",
"permission",
"->",
"setValue",
"(",
"'roles'",
",",
"$",
"roles",
")",
";",
"return",
"$",
"permission",
";",
"}"
] |
Create a permission object with the given parameters
@param $resource Resource
@param $context Context
@param $action Action
@param $roles String representing the permissions as returned from serializePermissions()
@return Instance of _permissionType
|
[
"Create",
"a",
"permission",
"object",
"with",
"the",
"given",
"parameters"
] |
2542b8d4139464d39a9a8ce8a954dfecf700c41b
|
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/lib/security/impl/DefaultPermissionManager.php#L186-L193
|
26,736
|
iherwig/wcmf
|
src/wcmf/lib/util/StringUtil.php
|
StringUtil.getUrls
|
public static function getUrls($string) {
preg_match_all("/<a[^>]+href=\"([^\">]+)/i", $string, $links);
// find urls in javascript popup links
for ($i=0; $i<sizeof($links[1]); $i++) {
if (preg_match_all("/javascript:.*window.open[\(]*'([^']+)/i", $links[1][$i], $popups)) {
$links[1][$i] = $popups[1][0];
}
}
// remove mailto links
for ($i=0; $i<sizeof($links[1]); $i++) {
if (preg_match("/^mailto:/i", $links[1][$i])) {
unset($links[1][$i]);
}
}
preg_match_all("/<img[^>]+src=\"([^\">]+)/i", $string, $images);
preg_match_all("/<video[^>]+src=\"([^\">]+)/i", $string, $videos);
preg_match_all("/<audios[^>]+src=\"([^\">]+)/i", $string, $audios);
preg_match_all("/<input[^>]+src=\"([^\">]+)/i", $string, $buttons);
preg_match_all("/<form[^>]+action=\"([^\">]+)/i", $string, $actions);
preg_match_all("/<link[^>]+href=\"([^\">]+)/i", $string, $css);
preg_match_all("/<script[^>]+src=\"([^\">]+)/i", $string, $scripts);
return array_merge($links[1], $images[1], $videos[1], $audios[1], $buttons[1], $actions[1], $css[1], $scripts[1]);
}
|
php
|
public static function getUrls($string) {
preg_match_all("/<a[^>]+href=\"([^\">]+)/i", $string, $links);
// find urls in javascript popup links
for ($i=0; $i<sizeof($links[1]); $i++) {
if (preg_match_all("/javascript:.*window.open[\(]*'([^']+)/i", $links[1][$i], $popups)) {
$links[1][$i] = $popups[1][0];
}
}
// remove mailto links
for ($i=0; $i<sizeof($links[1]); $i++) {
if (preg_match("/^mailto:/i", $links[1][$i])) {
unset($links[1][$i]);
}
}
preg_match_all("/<img[^>]+src=\"([^\">]+)/i", $string, $images);
preg_match_all("/<video[^>]+src=\"([^\">]+)/i", $string, $videos);
preg_match_all("/<audios[^>]+src=\"([^\">]+)/i", $string, $audios);
preg_match_all("/<input[^>]+src=\"([^\">]+)/i", $string, $buttons);
preg_match_all("/<form[^>]+action=\"([^\">]+)/i", $string, $actions);
preg_match_all("/<link[^>]+href=\"([^\">]+)/i", $string, $css);
preg_match_all("/<script[^>]+src=\"([^\">]+)/i", $string, $scripts);
return array_merge($links[1], $images[1], $videos[1], $audios[1], $buttons[1], $actions[1], $css[1], $scripts[1]);
}
|
[
"public",
"static",
"function",
"getUrls",
"(",
"$",
"string",
")",
"{",
"preg_match_all",
"(",
"\"/<a[^>]+href=\\\"([^\\\">]+)/i\"",
",",
"$",
"string",
",",
"$",
"links",
")",
";",
"// find urls in javascript popup links",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"sizeof",
"(",
"$",
"links",
"[",
"1",
"]",
")",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"preg_match_all",
"(",
"\"/javascript:.*window.open[\\(]*'([^']+)/i\"",
",",
"$",
"links",
"[",
"1",
"]",
"[",
"$",
"i",
"]",
",",
"$",
"popups",
")",
")",
"{",
"$",
"links",
"[",
"1",
"]",
"[",
"$",
"i",
"]",
"=",
"$",
"popups",
"[",
"1",
"]",
"[",
"0",
"]",
";",
"}",
"}",
"// remove mailto links",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"sizeof",
"(",
"$",
"links",
"[",
"1",
"]",
")",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"preg_match",
"(",
"\"/^mailto:/i\"",
",",
"$",
"links",
"[",
"1",
"]",
"[",
"$",
"i",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"links",
"[",
"1",
"]",
"[",
"$",
"i",
"]",
")",
";",
"}",
"}",
"preg_match_all",
"(",
"\"/<img[^>]+src=\\\"([^\\\">]+)/i\"",
",",
"$",
"string",
",",
"$",
"images",
")",
";",
"preg_match_all",
"(",
"\"/<video[^>]+src=\\\"([^\\\">]+)/i\"",
",",
"$",
"string",
",",
"$",
"videos",
")",
";",
"preg_match_all",
"(",
"\"/<audios[^>]+src=\\\"([^\\\">]+)/i\"",
",",
"$",
"string",
",",
"$",
"audios",
")",
";",
"preg_match_all",
"(",
"\"/<input[^>]+src=\\\"([^\\\">]+)/i\"",
",",
"$",
"string",
",",
"$",
"buttons",
")",
";",
"preg_match_all",
"(",
"\"/<form[^>]+action=\\\"([^\\\">]+)/i\"",
",",
"$",
"string",
",",
"$",
"actions",
")",
";",
"preg_match_all",
"(",
"\"/<link[^>]+href=\\\"([^\\\">]+)/i\"",
",",
"$",
"string",
",",
"$",
"css",
")",
";",
"preg_match_all",
"(",
"\"/<script[^>]+src=\\\"([^\\\">]+)/i\"",
",",
"$",
"string",
",",
"$",
"scripts",
")",
";",
"return",
"array_merge",
"(",
"$",
"links",
"[",
"1",
"]",
",",
"$",
"images",
"[",
"1",
"]",
",",
"$",
"videos",
"[",
"1",
"]",
",",
"$",
"audios",
"[",
"1",
"]",
",",
"$",
"buttons",
"[",
"1",
"]",
",",
"$",
"actions",
"[",
"1",
"]",
",",
"$",
"css",
"[",
"1",
"]",
",",
"$",
"scripts",
"[",
"1",
"]",
")",
";",
"}"
] |
Extraxt urls from a string.
@param $string The string to search in
@return An array with urls
@note This method searches for occurences of <a..href="xxx"..>, <img..src="xxx"..>, <video..src="xxx"..>,
<audio..src="xxx"..>, <input..src="xxx"..>, <form..action="xxx"..>, <link..href="xxx"..>, <script..src="xxx"..>
and extracts xxx.
|
[
"Extraxt",
"urls",
"from",
"a",
"string",
"."
] |
2542b8d4139464d39a9a8ce8a954dfecf700c41b
|
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/lib/util/StringUtil.php#L231-L254
|
26,737
|
iherwig/wcmf
|
src/wcmf/lib/util/StringUtil.php
|
StringUtil.getBoolean
|
public static function getBoolean($string) {
$val = filter_var($string, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);
if ($val === null) {
return $string;
}
return $val;
}
|
php
|
public static function getBoolean($string) {
$val = filter_var($string, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);
if ($val === null) {
return $string;
}
return $val;
}
|
[
"public",
"static",
"function",
"getBoolean",
"(",
"$",
"string",
")",
"{",
"$",
"val",
"=",
"filter_var",
"(",
"$",
"string",
",",
"FILTER_VALIDATE_BOOLEAN",
",",
"FILTER_NULL_ON_FAILURE",
")",
";",
"if",
"(",
"$",
"val",
"===",
"null",
")",
"{",
"return",
"$",
"string",
";",
"}",
"return",
"$",
"val",
";",
"}"
] |
Get the boolean value of a string
@param $string
@return Boolean or the string, if it does not represent a boolean.
|
[
"Get",
"the",
"boolean",
"value",
"of",
"a",
"string"
] |
2542b8d4139464d39a9a8ce8a954dfecf700c41b
|
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/lib/util/StringUtil.php#L401-L407
|
26,738
|
GW2Treasures/gw2api
|
src/V2/Localization/LocalizationHandler.php
|
LocalizationHandler.onRequest
|
public function onRequest( RequestInterface $request ) {
$localizedUri = Uri::withQueryValue( $request->getUri(), 'lang', $this->getEndpoint()->getLang() );
return $request->withUri($localizedUri);
}
|
php
|
public function onRequest( RequestInterface $request ) {
$localizedUri = Uri::withQueryValue( $request->getUri(), 'lang', $this->getEndpoint()->getLang() );
return $request->withUri($localizedUri);
}
|
[
"public",
"function",
"onRequest",
"(",
"RequestInterface",
"$",
"request",
")",
"{",
"$",
"localizedUri",
"=",
"Uri",
"::",
"withQueryValue",
"(",
"$",
"request",
"->",
"getUri",
"(",
")",
",",
"'lang'",
",",
"$",
"this",
"->",
"getEndpoint",
"(",
")",
"->",
"getLang",
"(",
")",
")",
";",
"return",
"$",
"request",
"->",
"withUri",
"(",
"$",
"localizedUri",
")",
";",
"}"
] |
Adds the `lang` query parameter to the request for localized endpoints.
@param RequestInterface $request
@return \Psr\Http\Message\RequestInterface
|
[
"Adds",
"the",
"lang",
"query",
"parameter",
"to",
"the",
"request",
"for",
"localized",
"endpoints",
"."
] |
c8795af0c1d0a434b9e530f779d5a95786db2176
|
https://github.com/GW2Treasures/gw2api/blob/c8795af0c1d0a434b9e530f779d5a95786db2176/src/V2/Localization/LocalizationHandler.php#L26-L29
|
26,739
|
iherwig/wcmf
|
src/wcmf/lib/model/output/ImageOutputStrategy.php
|
ImageOutputStrategy.drawConnectionLine
|
protected function drawConnectionLine($poid, $oid) {
list($start, $end) = $this->calculateEndPoints($poid, $oid);
if($this->lineType == self::LINETYPE_DIRECT) {
$this->drawDirectLine($start, $end);
}
else if($this->lineType == self::LINETYPE_ROUTED) {
$this->drawRoutedLine($start, $end);
}
}
|
php
|
protected function drawConnectionLine($poid, $oid) {
list($start, $end) = $this->calculateEndPoints($poid, $oid);
if($this->lineType == self::LINETYPE_DIRECT) {
$this->drawDirectLine($start, $end);
}
else if($this->lineType == self::LINETYPE_ROUTED) {
$this->drawRoutedLine($start, $end);
}
}
|
[
"protected",
"function",
"drawConnectionLine",
"(",
"$",
"poid",
",",
"$",
"oid",
")",
"{",
"list",
"(",
"$",
"start",
",",
"$",
"end",
")",
"=",
"$",
"this",
"->",
"calculateEndPoints",
"(",
"$",
"poid",
",",
"$",
"oid",
")",
";",
"if",
"(",
"$",
"this",
"->",
"lineType",
"==",
"self",
"::",
"LINETYPE_DIRECT",
")",
"{",
"$",
"this",
"->",
"drawDirectLine",
"(",
"$",
"start",
",",
"$",
"end",
")",
";",
"}",
"else",
"if",
"(",
"$",
"this",
"->",
"lineType",
"==",
"self",
"::",
"LINETYPE_ROUTED",
")",
"{",
"$",
"this",
"->",
"drawRoutedLine",
"(",
"$",
"start",
",",
"$",
"end",
")",
";",
"}",
"}"
] |
Draw connection line.
@param $poid The parent object's object id.
@param $oid The object's object id.
|
[
"Draw",
"connection",
"line",
"."
] |
2542b8d4139464d39a9a8ce8a954dfecf700c41b
|
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/lib/model/output/ImageOutputStrategy.php#L196-L204
|
26,740
|
iherwig/wcmf
|
src/wcmf/lib/model/output/ImageOutputStrategy.php
|
ImageOutputStrategy.drawDirectLine
|
protected function drawDirectLine($start, $end) {
ImageLine($this->img,
$start->x,
$start->y,
$end->x,
$end->y,
$this->lineColor);
}
|
php
|
protected function drawDirectLine($start, $end) {
ImageLine($this->img,
$start->x,
$start->y,
$end->x,
$end->y,
$this->lineColor);
}
|
[
"protected",
"function",
"drawDirectLine",
"(",
"$",
"start",
",",
"$",
"end",
")",
"{",
"ImageLine",
"(",
"$",
"this",
"->",
"img",
",",
"$",
"start",
"->",
"x",
",",
"$",
"start",
"->",
"y",
",",
"$",
"end",
"->",
"x",
",",
"$",
"end",
"->",
"y",
",",
"$",
"this",
"->",
"lineColor",
")",
";",
"}"
] |
Draw direct line.
@param $start The start point (Position).
@param $end The end point (Position).
|
[
"Draw",
"direct",
"line",
"."
] |
2542b8d4139464d39a9a8ce8a954dfecf700c41b
|
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/lib/model/output/ImageOutputStrategy.php#L211-L218
|
26,741
|
iherwig/wcmf
|
src/wcmf/lib/model/output/ImageOutputStrategy.php
|
ImageOutputStrategy.drawRoutedLine
|
protected function drawRoutedLine($start, $end) {
if ($this->map["type"] == MAPTYPE_HORIZONTAL) {
ImageLine($this->img,
$start->x,
$start->y,
$start->x,
$start->y-($start->y-$end->y)/2,
$this->lineColor);
ImageLine($this->img,
$start->x,
$start->y-($start->y-$end->y)/2,
$end->x,
$start->y-($start->y-$end->y)/2,
$this->lineColor);
ImageLine($this->img,
$end->x,
$start->y-($start->y-$end->y)/2,
$end->x,
$end->y,
$this->lineColor);
}
else {
ImageLine($this->img,
$start->x,
$start->y,
$start->x+($end->x-$start->x)/2,
$start->y,
$this->lineColor);
ImageLine($this->img,
$start->x+($end->x-$start->x)/2,
$start->y,
$start->x+($end->x-$start->x)/2,
$end->y,
$this->lineColor);
ImageLine($this->img,
$start->x+($end->x-$start->x)/2,
$end->y,
$end->x,
$end->y,
$this->lineColor);
}
}
|
php
|
protected function drawRoutedLine($start, $end) {
if ($this->map["type"] == MAPTYPE_HORIZONTAL) {
ImageLine($this->img,
$start->x,
$start->y,
$start->x,
$start->y-($start->y-$end->y)/2,
$this->lineColor);
ImageLine($this->img,
$start->x,
$start->y-($start->y-$end->y)/2,
$end->x,
$start->y-($start->y-$end->y)/2,
$this->lineColor);
ImageLine($this->img,
$end->x,
$start->y-($start->y-$end->y)/2,
$end->x,
$end->y,
$this->lineColor);
}
else {
ImageLine($this->img,
$start->x,
$start->y,
$start->x+($end->x-$start->x)/2,
$start->y,
$this->lineColor);
ImageLine($this->img,
$start->x+($end->x-$start->x)/2,
$start->y,
$start->x+($end->x-$start->x)/2,
$end->y,
$this->lineColor);
ImageLine($this->img,
$start->x+($end->x-$start->x)/2,
$end->y,
$end->x,
$end->y,
$this->lineColor);
}
}
|
[
"protected",
"function",
"drawRoutedLine",
"(",
"$",
"start",
",",
"$",
"end",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"map",
"[",
"\"type\"",
"]",
"==",
"MAPTYPE_HORIZONTAL",
")",
"{",
"ImageLine",
"(",
"$",
"this",
"->",
"img",
",",
"$",
"start",
"->",
"x",
",",
"$",
"start",
"->",
"y",
",",
"$",
"start",
"->",
"x",
",",
"$",
"start",
"->",
"y",
"-",
"(",
"$",
"start",
"->",
"y",
"-",
"$",
"end",
"->",
"y",
")",
"/",
"2",
",",
"$",
"this",
"->",
"lineColor",
")",
";",
"ImageLine",
"(",
"$",
"this",
"->",
"img",
",",
"$",
"start",
"->",
"x",
",",
"$",
"start",
"->",
"y",
"-",
"(",
"$",
"start",
"->",
"y",
"-",
"$",
"end",
"->",
"y",
")",
"/",
"2",
",",
"$",
"end",
"->",
"x",
",",
"$",
"start",
"->",
"y",
"-",
"(",
"$",
"start",
"->",
"y",
"-",
"$",
"end",
"->",
"y",
")",
"/",
"2",
",",
"$",
"this",
"->",
"lineColor",
")",
";",
"ImageLine",
"(",
"$",
"this",
"->",
"img",
",",
"$",
"end",
"->",
"x",
",",
"$",
"start",
"->",
"y",
"-",
"(",
"$",
"start",
"->",
"y",
"-",
"$",
"end",
"->",
"y",
")",
"/",
"2",
",",
"$",
"end",
"->",
"x",
",",
"$",
"end",
"->",
"y",
",",
"$",
"this",
"->",
"lineColor",
")",
";",
"}",
"else",
"{",
"ImageLine",
"(",
"$",
"this",
"->",
"img",
",",
"$",
"start",
"->",
"x",
",",
"$",
"start",
"->",
"y",
",",
"$",
"start",
"->",
"x",
"+",
"(",
"$",
"end",
"->",
"x",
"-",
"$",
"start",
"->",
"x",
")",
"/",
"2",
",",
"$",
"start",
"->",
"y",
",",
"$",
"this",
"->",
"lineColor",
")",
";",
"ImageLine",
"(",
"$",
"this",
"->",
"img",
",",
"$",
"start",
"->",
"x",
"+",
"(",
"$",
"end",
"->",
"x",
"-",
"$",
"start",
"->",
"x",
")",
"/",
"2",
",",
"$",
"start",
"->",
"y",
",",
"$",
"start",
"->",
"x",
"+",
"(",
"$",
"end",
"->",
"x",
"-",
"$",
"start",
"->",
"x",
")",
"/",
"2",
",",
"$",
"end",
"->",
"y",
",",
"$",
"this",
"->",
"lineColor",
")",
";",
"ImageLine",
"(",
"$",
"this",
"->",
"img",
",",
"$",
"start",
"->",
"x",
"+",
"(",
"$",
"end",
"->",
"x",
"-",
"$",
"start",
"->",
"x",
")",
"/",
"2",
",",
"$",
"end",
"->",
"y",
",",
"$",
"end",
"->",
"x",
",",
"$",
"end",
"->",
"y",
",",
"$",
"this",
"->",
"lineColor",
")",
";",
"}",
"}"
] |
Draw routed line.
@param $start The start point (Position).
@param $end The end point (Position).
|
[
"Draw",
"routed",
"line",
"."
] |
2542b8d4139464d39a9a8ce8a954dfecf700c41b
|
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/lib/model/output/ImageOutputStrategy.php#L225-L266
|
26,742
|
iherwig/wcmf
|
src/wcmf/lib/model/output/ImageOutputStrategy.php
|
ImageOutputStrategy.calculateEndPoints
|
private function calculateEndPoints($poid, $oid) {
// from child...
if ($this->map["type"] == MAPTYPE_HORIZONTAL) {
// connect from mid top...
$x1 = $this->map[$oid]->x * $this->scale['x'] + ($this->labelDim['right'] - $this->labelDim['left'])/2 + $this->border;
$y1 = $this->map[$oid]->y * $this->scale['y'] + $this->border - 1;
}
else {
// connect from mid left...
$x1 = $this->map[$oid]->x * $this->scale['x'] + $this->border - 1;
$y1 = $this->map[$oid]->y * $this->scale['y'] + ($this->labelDim['bottom'] - $this->labelDim['top'])/2 + $this->border;
}
// ...to parent
if ($this->map["type"] == MAPTYPE_HORIZONTAL) {
// ...to mid bottom
$x2 = $this->map[$poid]->x * $this->scale['x'] + ($this->labelDim['right'] - $this->labelDim['left'])/2 + $this->border;
$y2 = $this->map[$poid]->y * $this->scale['y'] + ($this->labelDim['bottom'] - $this->labelDim['top']) + $this->border + 1;
}
else {
// ...to mid right
$x2 = $this->map[$poid]->x * $this->scale['x'] + $this->labelDim['right'] - $this->labelDim['left'] + $this->border + 1;
$y2 = $this->map[$poid]->y * $this->scale['y'] + ($this->labelDim['bottom'] - $this->labelDim['top'])/2 + $this->border;
}
return [new Position($x1, $y1, 0), new Position($x2, $y2, 0)];
}
|
php
|
private function calculateEndPoints($poid, $oid) {
// from child...
if ($this->map["type"] == MAPTYPE_HORIZONTAL) {
// connect from mid top...
$x1 = $this->map[$oid]->x * $this->scale['x'] + ($this->labelDim['right'] - $this->labelDim['left'])/2 + $this->border;
$y1 = $this->map[$oid]->y * $this->scale['y'] + $this->border - 1;
}
else {
// connect from mid left...
$x1 = $this->map[$oid]->x * $this->scale['x'] + $this->border - 1;
$y1 = $this->map[$oid]->y * $this->scale['y'] + ($this->labelDim['bottom'] - $this->labelDim['top'])/2 + $this->border;
}
// ...to parent
if ($this->map["type"] == MAPTYPE_HORIZONTAL) {
// ...to mid bottom
$x2 = $this->map[$poid]->x * $this->scale['x'] + ($this->labelDim['right'] - $this->labelDim['left'])/2 + $this->border;
$y2 = $this->map[$poid]->y * $this->scale['y'] + ($this->labelDim['bottom'] - $this->labelDim['top']) + $this->border + 1;
}
else {
// ...to mid right
$x2 = $this->map[$poid]->x * $this->scale['x'] + $this->labelDim['right'] - $this->labelDim['left'] + $this->border + 1;
$y2 = $this->map[$poid]->y * $this->scale['y'] + ($this->labelDim['bottom'] - $this->labelDim['top'])/2 + $this->border;
}
return [new Position($x1, $y1, 0), new Position($x2, $y2, 0)];
}
|
[
"private",
"function",
"calculateEndPoints",
"(",
"$",
"poid",
",",
"$",
"oid",
")",
"{",
"// from child...",
"if",
"(",
"$",
"this",
"->",
"map",
"[",
"\"type\"",
"]",
"==",
"MAPTYPE_HORIZONTAL",
")",
"{",
"// connect from mid top...",
"$",
"x1",
"=",
"$",
"this",
"->",
"map",
"[",
"$",
"oid",
"]",
"->",
"x",
"*",
"$",
"this",
"->",
"scale",
"[",
"'x'",
"]",
"+",
"(",
"$",
"this",
"->",
"labelDim",
"[",
"'right'",
"]",
"-",
"$",
"this",
"->",
"labelDim",
"[",
"'left'",
"]",
")",
"/",
"2",
"+",
"$",
"this",
"->",
"border",
";",
"$",
"y1",
"=",
"$",
"this",
"->",
"map",
"[",
"$",
"oid",
"]",
"->",
"y",
"*",
"$",
"this",
"->",
"scale",
"[",
"'y'",
"]",
"+",
"$",
"this",
"->",
"border",
"-",
"1",
";",
"}",
"else",
"{",
"// connect from mid left...",
"$",
"x1",
"=",
"$",
"this",
"->",
"map",
"[",
"$",
"oid",
"]",
"->",
"x",
"*",
"$",
"this",
"->",
"scale",
"[",
"'x'",
"]",
"+",
"$",
"this",
"->",
"border",
"-",
"1",
";",
"$",
"y1",
"=",
"$",
"this",
"->",
"map",
"[",
"$",
"oid",
"]",
"->",
"y",
"*",
"$",
"this",
"->",
"scale",
"[",
"'y'",
"]",
"+",
"(",
"$",
"this",
"->",
"labelDim",
"[",
"'bottom'",
"]",
"-",
"$",
"this",
"->",
"labelDim",
"[",
"'top'",
"]",
")",
"/",
"2",
"+",
"$",
"this",
"->",
"border",
";",
"}",
"// ...to parent",
"if",
"(",
"$",
"this",
"->",
"map",
"[",
"\"type\"",
"]",
"==",
"MAPTYPE_HORIZONTAL",
")",
"{",
"// ...to mid bottom",
"$",
"x2",
"=",
"$",
"this",
"->",
"map",
"[",
"$",
"poid",
"]",
"->",
"x",
"*",
"$",
"this",
"->",
"scale",
"[",
"'x'",
"]",
"+",
"(",
"$",
"this",
"->",
"labelDim",
"[",
"'right'",
"]",
"-",
"$",
"this",
"->",
"labelDim",
"[",
"'left'",
"]",
")",
"/",
"2",
"+",
"$",
"this",
"->",
"border",
";",
"$",
"y2",
"=",
"$",
"this",
"->",
"map",
"[",
"$",
"poid",
"]",
"->",
"y",
"*",
"$",
"this",
"->",
"scale",
"[",
"'y'",
"]",
"+",
"(",
"$",
"this",
"->",
"labelDim",
"[",
"'bottom'",
"]",
"-",
"$",
"this",
"->",
"labelDim",
"[",
"'top'",
"]",
")",
"+",
"$",
"this",
"->",
"border",
"+",
"1",
";",
"}",
"else",
"{",
"// ...to mid right",
"$",
"x2",
"=",
"$",
"this",
"->",
"map",
"[",
"$",
"poid",
"]",
"->",
"x",
"*",
"$",
"this",
"->",
"scale",
"[",
"'x'",
"]",
"+",
"$",
"this",
"->",
"labelDim",
"[",
"'right'",
"]",
"-",
"$",
"this",
"->",
"labelDim",
"[",
"'left'",
"]",
"+",
"$",
"this",
"->",
"border",
"+",
"1",
";",
"$",
"y2",
"=",
"$",
"this",
"->",
"map",
"[",
"$",
"poid",
"]",
"->",
"y",
"*",
"$",
"this",
"->",
"scale",
"[",
"'y'",
"]",
"+",
"(",
"$",
"this",
"->",
"labelDim",
"[",
"'bottom'",
"]",
"-",
"$",
"this",
"->",
"labelDim",
"[",
"'top'",
"]",
")",
"/",
"2",
"+",
"$",
"this",
"->",
"border",
";",
"}",
"return",
"[",
"new",
"Position",
"(",
"$",
"x1",
",",
"$",
"y1",
",",
"0",
")",
",",
"new",
"Position",
"(",
"$",
"x2",
",",
"$",
"y2",
",",
"0",
")",
"]",
";",
"}"
] |
Calculate line end points.
@param $poid The parent object's object id.
@param $oid The object's object id.
@return Array containing start and end position
|
[
"Calculate",
"line",
"end",
"points",
"."
] |
2542b8d4139464d39a9a8ce8a954dfecf700c41b
|
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/lib/model/output/ImageOutputStrategy.php#L274-L298
|
26,743
|
iherwig/wcmf
|
src/wcmf/lib/core/ClassLoader.php
|
ClassLoader.load
|
public function load($className) {
// search under baseDir assuming that namespaces match directories
$filename = $this->baseDir.str_replace("\\", "/", $className).'.php';
if (file_exists($filename)) {
include($filename);
}
}
|
php
|
public function load($className) {
// search under baseDir assuming that namespaces match directories
$filename = $this->baseDir.str_replace("\\", "/", $className).'.php';
if (file_exists($filename)) {
include($filename);
}
}
|
[
"public",
"function",
"load",
"(",
"$",
"className",
")",
"{",
"// search under baseDir assuming that namespaces match directories",
"$",
"filename",
"=",
"$",
"this",
"->",
"baseDir",
".",
"str_replace",
"(",
"\"\\\\\"",
",",
"\"/\"",
",",
"$",
"className",
")",
".",
"'.php'",
";",
"if",
"(",
"file_exists",
"(",
"$",
"filename",
")",
")",
"{",
"include",
"(",
"$",
"filename",
")",
";",
"}",
"}"
] |
Load the given class definition
@param $className The class name
|
[
"Load",
"the",
"given",
"class",
"definition"
] |
2542b8d4139464d39a9a8ce8a954dfecf700c41b
|
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/lib/core/ClassLoader.php#L40-L46
|
26,744
|
iherwig/wcmf
|
src/wcmf/lib/presentation/Application.php
|
Application.initialize
|
public function initialize($defaultController='', $defaultContext='', $defaultAction='login') {
$config = ObjectFactory::getInstance('configuration');
$this->debug = $config->getBooleanValue('debug', 'Application');
// configure php
if ($config->hasSection('phpconfig')) {
$phpSettings = $config->getSection('phpconfig');
foreach ($phpSettings as $option => $value) {
ini_set($option, $value);
}
}
// create the Request and Response instances
$this->request = ObjectFactory::getInstance('request');
$this->response = ObjectFactory::getInstance('response');
$this->request->setResponse($this->response);
$this->request->initialize($defaultController, $defaultContext, $defaultAction);
// initialize session
$session = ObjectFactory::getInstance('session');
// load user configuration
$principalFactory = ObjectFactory::getInstance('principalFactory');
$authUser = $principalFactory->getUser($session->getAuthUser(), true);
if ($authUser && strlen($authUser->getConfig()) > 0) {
$config->addConfiguration($authUser->getConfig(), true);
}
// load event listeners
$listeners = $config->getValue('listeners', 'application');
foreach ($listeners as $key) {
ObjectFactory::getInstance($key);
}
// set timezone
date_default_timezone_set($config->getValue('timezone', 'application'));
// return the request
return $this->request;
}
|
php
|
public function initialize($defaultController='', $defaultContext='', $defaultAction='login') {
$config = ObjectFactory::getInstance('configuration');
$this->debug = $config->getBooleanValue('debug', 'Application');
// configure php
if ($config->hasSection('phpconfig')) {
$phpSettings = $config->getSection('phpconfig');
foreach ($phpSettings as $option => $value) {
ini_set($option, $value);
}
}
// create the Request and Response instances
$this->request = ObjectFactory::getInstance('request');
$this->response = ObjectFactory::getInstance('response');
$this->request->setResponse($this->response);
$this->request->initialize($defaultController, $defaultContext, $defaultAction);
// initialize session
$session = ObjectFactory::getInstance('session');
// load user configuration
$principalFactory = ObjectFactory::getInstance('principalFactory');
$authUser = $principalFactory->getUser($session->getAuthUser(), true);
if ($authUser && strlen($authUser->getConfig()) > 0) {
$config->addConfiguration($authUser->getConfig(), true);
}
// load event listeners
$listeners = $config->getValue('listeners', 'application');
foreach ($listeners as $key) {
ObjectFactory::getInstance($key);
}
// set timezone
date_default_timezone_set($config->getValue('timezone', 'application'));
// return the request
return $this->request;
}
|
[
"public",
"function",
"initialize",
"(",
"$",
"defaultController",
"=",
"''",
",",
"$",
"defaultContext",
"=",
"''",
",",
"$",
"defaultAction",
"=",
"'login'",
")",
"{",
"$",
"config",
"=",
"ObjectFactory",
"::",
"getInstance",
"(",
"'configuration'",
")",
";",
"$",
"this",
"->",
"debug",
"=",
"$",
"config",
"->",
"getBooleanValue",
"(",
"'debug'",
",",
"'Application'",
")",
";",
"// configure php",
"if",
"(",
"$",
"config",
"->",
"hasSection",
"(",
"'phpconfig'",
")",
")",
"{",
"$",
"phpSettings",
"=",
"$",
"config",
"->",
"getSection",
"(",
"'phpconfig'",
")",
";",
"foreach",
"(",
"$",
"phpSettings",
"as",
"$",
"option",
"=>",
"$",
"value",
")",
"{",
"ini_set",
"(",
"$",
"option",
",",
"$",
"value",
")",
";",
"}",
"}",
"// create the Request and Response instances",
"$",
"this",
"->",
"request",
"=",
"ObjectFactory",
"::",
"getInstance",
"(",
"'request'",
")",
";",
"$",
"this",
"->",
"response",
"=",
"ObjectFactory",
"::",
"getInstance",
"(",
"'response'",
")",
";",
"$",
"this",
"->",
"request",
"->",
"setResponse",
"(",
"$",
"this",
"->",
"response",
")",
";",
"$",
"this",
"->",
"request",
"->",
"initialize",
"(",
"$",
"defaultController",
",",
"$",
"defaultContext",
",",
"$",
"defaultAction",
")",
";",
"// initialize session",
"$",
"session",
"=",
"ObjectFactory",
"::",
"getInstance",
"(",
"'session'",
")",
";",
"// load user configuration",
"$",
"principalFactory",
"=",
"ObjectFactory",
"::",
"getInstance",
"(",
"'principalFactory'",
")",
";",
"$",
"authUser",
"=",
"$",
"principalFactory",
"->",
"getUser",
"(",
"$",
"session",
"->",
"getAuthUser",
"(",
")",
",",
"true",
")",
";",
"if",
"(",
"$",
"authUser",
"&&",
"strlen",
"(",
"$",
"authUser",
"->",
"getConfig",
"(",
")",
")",
">",
"0",
")",
"{",
"$",
"config",
"->",
"addConfiguration",
"(",
"$",
"authUser",
"->",
"getConfig",
"(",
")",
",",
"true",
")",
";",
"}",
"// load event listeners",
"$",
"listeners",
"=",
"$",
"config",
"->",
"getValue",
"(",
"'listeners'",
",",
"'application'",
")",
";",
"foreach",
"(",
"$",
"listeners",
"as",
"$",
"key",
")",
"{",
"ObjectFactory",
"::",
"getInstance",
"(",
"$",
"key",
")",
";",
"}",
"// set timezone",
"date_default_timezone_set",
"(",
"$",
"config",
"->",
"getValue",
"(",
"'timezone'",
",",
"'application'",
")",
")",
";",
"// return the request",
"return",
"$",
"this",
"->",
"request",
";",
"}"
] |
Initialize the request.
@param $defaultController The controller to call if none is given in request parameters (optional, default: '')
@param $defaultContext The context to set if none is given in request parameters (optional, default: '')
@param $defaultAction The action to perform if none is given in request parameters (optional, default: 'login')
@return Request instance representing the current HTTP request
|
[
"Initialize",
"the",
"request",
"."
] |
2542b8d4139464d39a9a8ce8a954dfecf700c41b
|
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/lib/presentation/Application.php#L71-L111
|
26,745
|
iherwig/wcmf
|
src/wcmf/lib/presentation/Application.php
|
Application.run
|
public function run(Request $request) {
// process the requested action
ObjectFactory::getInstance('actionMapper')->processAction($request, $this->response);
return $this->response;
}
|
php
|
public function run(Request $request) {
// process the requested action
ObjectFactory::getInstance('actionMapper')->processAction($request, $this->response);
return $this->response;
}
|
[
"public",
"function",
"run",
"(",
"Request",
"$",
"request",
")",
"{",
"// process the requested action",
"ObjectFactory",
"::",
"getInstance",
"(",
"'actionMapper'",
")",
"->",
"processAction",
"(",
"$",
"request",
",",
"$",
"this",
"->",
"response",
")",
";",
"return",
"$",
"this",
"->",
"response",
";",
"}"
] |
Run the application with the given request
@param $request
@return Response instance
|
[
"Run",
"the",
"application",
"with",
"the",
"given",
"request"
] |
2542b8d4139464d39a9a8ce8a954dfecf700c41b
|
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/lib/presentation/Application.php#L118-L122
|
26,746
|
iherwig/wcmf
|
src/wcmf/lib/presentation/Application.php
|
Application.handleException
|
public function handleException(\Exception $exception) {
// get error level
$logFunction = 'error';
if ($exception instanceof ApplicationException) {
$logFunction = $exception->getError()->getLevel() == ApplicationError::LEVEL_WARNING ?
'warn' : 'error';
}
self::$logger->$logFunction($exception);
try {
if (ObjectFactory::getInstance('configuration') != null) {
// rollback current transaction
$persistenceFacade = ObjectFactory::getInstance('persistenceFacade');
$persistenceFacade->getTransaction()->rollback();
// redirect to failure action
if ($this->request) {
$error = ApplicationError::fromException($exception);
$this->request->addError($error);
$this->response->addError($error);
$this->request->setAction('failure');
$this->response->setAction('failure');
$this->response->setStatus($error->getStatusCode());
ObjectFactory::getInstance('actionMapper')->processAction($this->request, $this->response);
return;
}
}
throw $exception;
}
catch (\Exception $ex) {
self::$logger->error($ex->getMessage()."\n".$ex->getTraceAsString());
}
}
|
php
|
public function handleException(\Exception $exception) {
// get error level
$logFunction = 'error';
if ($exception instanceof ApplicationException) {
$logFunction = $exception->getError()->getLevel() == ApplicationError::LEVEL_WARNING ?
'warn' : 'error';
}
self::$logger->$logFunction($exception);
try {
if (ObjectFactory::getInstance('configuration') != null) {
// rollback current transaction
$persistenceFacade = ObjectFactory::getInstance('persistenceFacade');
$persistenceFacade->getTransaction()->rollback();
// redirect to failure action
if ($this->request) {
$error = ApplicationError::fromException($exception);
$this->request->addError($error);
$this->response->addError($error);
$this->request->setAction('failure');
$this->response->setAction('failure');
$this->response->setStatus($error->getStatusCode());
ObjectFactory::getInstance('actionMapper')->processAction($this->request, $this->response);
return;
}
}
throw $exception;
}
catch (\Exception $ex) {
self::$logger->error($ex->getMessage()."\n".$ex->getTraceAsString());
}
}
|
[
"public",
"function",
"handleException",
"(",
"\\",
"Exception",
"$",
"exception",
")",
"{",
"// get error level",
"$",
"logFunction",
"=",
"'error'",
";",
"if",
"(",
"$",
"exception",
"instanceof",
"ApplicationException",
")",
"{",
"$",
"logFunction",
"=",
"$",
"exception",
"->",
"getError",
"(",
")",
"->",
"getLevel",
"(",
")",
"==",
"ApplicationError",
"::",
"LEVEL_WARNING",
"?",
"'warn'",
":",
"'error'",
";",
"}",
"self",
"::",
"$",
"logger",
"->",
"$",
"logFunction",
"(",
"$",
"exception",
")",
";",
"try",
"{",
"if",
"(",
"ObjectFactory",
"::",
"getInstance",
"(",
"'configuration'",
")",
"!=",
"null",
")",
"{",
"// rollback current transaction",
"$",
"persistenceFacade",
"=",
"ObjectFactory",
"::",
"getInstance",
"(",
"'persistenceFacade'",
")",
";",
"$",
"persistenceFacade",
"->",
"getTransaction",
"(",
")",
"->",
"rollback",
"(",
")",
";",
"// redirect to failure action",
"if",
"(",
"$",
"this",
"->",
"request",
")",
"{",
"$",
"error",
"=",
"ApplicationError",
"::",
"fromException",
"(",
"$",
"exception",
")",
";",
"$",
"this",
"->",
"request",
"->",
"addError",
"(",
"$",
"error",
")",
";",
"$",
"this",
"->",
"response",
"->",
"addError",
"(",
"$",
"error",
")",
";",
"$",
"this",
"->",
"request",
"->",
"setAction",
"(",
"'failure'",
")",
";",
"$",
"this",
"->",
"response",
"->",
"setAction",
"(",
"'failure'",
")",
";",
"$",
"this",
"->",
"response",
"->",
"setStatus",
"(",
"$",
"error",
"->",
"getStatusCode",
"(",
")",
")",
";",
"ObjectFactory",
"::",
"getInstance",
"(",
"'actionMapper'",
")",
"->",
"processAction",
"(",
"$",
"this",
"->",
"request",
",",
"$",
"this",
"->",
"response",
")",
";",
"return",
";",
"}",
"}",
"throw",
"$",
"exception",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"ex",
")",
"{",
"self",
"::",
"$",
"logger",
"->",
"error",
"(",
"$",
"ex",
"->",
"getMessage",
"(",
")",
".",
"\"\\n\"",
".",
"$",
"ex",
"->",
"getTraceAsString",
"(",
")",
")",
";",
"}",
"}"
] |
Default exception handling method. Rolls back the transaction and
executes 'failure' action.
@param $exception The Exception instance
|
[
"Default",
"exception",
"handling",
"method",
".",
"Rolls",
"back",
"the",
"transaction",
"and",
"executes",
"failure",
"action",
"."
] |
2542b8d4139464d39a9a8ce8a954dfecf700c41b
|
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/lib/presentation/Application.php#L129-L161
|
26,747
|
iherwig/wcmf
|
src/wcmf/lib/presentation/Application.php
|
Application.outputHandler
|
public function outputHandler($buffer) {
// log last error, if it's level is enabled
$error = error_get_last();
if ($error !== null && (in_array($error['type'], [E_ERROR, E_PARSE, E_COMPILE_ERROR]))) {
$errorStr = $error['file']."::".$error['line'].": ".$error['type'].": ".$error['message'];
self::$logger->error($errorStr);
// suppress error message in browser
if (!$this->debug) {
header('HTTP/1.1 500 Internal Server Error');
$buffer = '';
}
else {
$buffer = "<pre>\n".$errorStr."\n</pre>";
}
}
return trim($buffer);
}
|
php
|
public function outputHandler($buffer) {
// log last error, if it's level is enabled
$error = error_get_last();
if ($error !== null && (in_array($error['type'], [E_ERROR, E_PARSE, E_COMPILE_ERROR]))) {
$errorStr = $error['file']."::".$error['line'].": ".$error['type'].": ".$error['message'];
self::$logger->error($errorStr);
// suppress error message in browser
if (!$this->debug) {
header('HTTP/1.1 500 Internal Server Error');
$buffer = '';
}
else {
$buffer = "<pre>\n".$errorStr."\n</pre>";
}
}
return trim($buffer);
}
|
[
"public",
"function",
"outputHandler",
"(",
"$",
"buffer",
")",
"{",
"// log last error, if it's level is enabled",
"$",
"error",
"=",
"error_get_last",
"(",
")",
";",
"if",
"(",
"$",
"error",
"!==",
"null",
"&&",
"(",
"in_array",
"(",
"$",
"error",
"[",
"'type'",
"]",
",",
"[",
"E_ERROR",
",",
"E_PARSE",
",",
"E_COMPILE_ERROR",
"]",
")",
")",
")",
"{",
"$",
"errorStr",
"=",
"$",
"error",
"[",
"'file'",
"]",
".",
"\"::\"",
".",
"$",
"error",
"[",
"'line'",
"]",
".",
"\": \"",
".",
"$",
"error",
"[",
"'type'",
"]",
".",
"\": \"",
".",
"$",
"error",
"[",
"'message'",
"]",
";",
"self",
"::",
"$",
"logger",
"->",
"error",
"(",
"$",
"errorStr",
")",
";",
"// suppress error message in browser",
"if",
"(",
"!",
"$",
"this",
"->",
"debug",
")",
"{",
"header",
"(",
"'HTTP/1.1 500 Internal Server Error'",
")",
";",
"$",
"buffer",
"=",
"''",
";",
"}",
"else",
"{",
"$",
"buffer",
"=",
"\"<pre>\\n\"",
".",
"$",
"errorStr",
".",
"\"\\n</pre>\"",
";",
"}",
"}",
"return",
"trim",
"(",
"$",
"buffer",
")",
";",
"}"
] |
This method is run as ob_start callback
@note must be public
@param $buffer The content to be returned to the client
@return String
|
[
"This",
"method",
"is",
"run",
"as",
"ob_start",
"callback"
] |
2542b8d4139464d39a9a8ce8a954dfecf700c41b
|
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/lib/presentation/Application.php#L169-L185
|
26,748
|
skie/plum_search
|
src/Controller/Component/FilterComponent.php
|
FilterComponent.parameters
|
public function parameters($reset = false)
{
if ($reset || is_null($this->_searchParameters)) {
$this->_searchParameters = new ParameterRegistry($this->_controller, []);
$parameters = (array)$this->config('parameters');
foreach ($parameters as $parameter) {
if (!empty($parameter['name'])) {
$this->addParam($parameter['name'], $parameter);
}
}
}
return $this->_searchParameters;
}
|
php
|
public function parameters($reset = false)
{
if ($reset || is_null($this->_searchParameters)) {
$this->_searchParameters = new ParameterRegistry($this->_controller, []);
$parameters = (array)$this->config('parameters');
foreach ($parameters as $parameter) {
if (!empty($parameter['name'])) {
$this->addParam($parameter['name'], $parameter);
}
}
}
return $this->_searchParameters;
}
|
[
"public",
"function",
"parameters",
"(",
"$",
"reset",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"reset",
"||",
"is_null",
"(",
"$",
"this",
"->",
"_searchParameters",
")",
")",
"{",
"$",
"this",
"->",
"_searchParameters",
"=",
"new",
"ParameterRegistry",
"(",
"$",
"this",
"->",
"_controller",
",",
"[",
"]",
")",
";",
"$",
"parameters",
"=",
"(",
"array",
")",
"$",
"this",
"->",
"config",
"(",
"'parameters'",
")",
";",
"foreach",
"(",
"$",
"parameters",
"as",
"$",
"parameter",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"parameter",
"[",
"'name'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"addParam",
"(",
"$",
"parameter",
"[",
"'name'",
"]",
",",
"$",
"parameter",
")",
";",
"}",
"}",
"}",
"return",
"$",
"this",
"->",
"_searchParameters",
";",
"}"
] |
Returns parameters registry instance
@param bool $reset Reset flag.
@return \PlumSearch\FormParameter\ParameterRegistry
|
[
"Returns",
"parameters",
"registry",
"instance"
] |
24d981e240bff7c15731981d6f9b3056abdaf80e
|
https://github.com/skie/plum_search/blob/24d981e240bff7c15731981d6f9b3056abdaf80e/src/Controller/Component/FilterComponent.php#L71-L84
|
26,749
|
skie/plum_search
|
src/Controller/Component/FilterComponent.php
|
FilterComponent.prg
|
public function prg($table, $options = [])
{
$this->config($options);
$formName = $this->_initParam('formName', $this->config('formName'));
$action = $this->_initParam('action', $this->controller()->request->params['action']);
$this->parameters()->config([
'formName' => $formName,
]);
if ($this->_controller->request->is(['post', 'put'])) {
$this->_redirect($action);
} elseif ($this->_controller->request->is('get')) {
$this->_setViewData($formName);
return $table->find('filters', $this->values());
}
return $table;
}
|
php
|
public function prg($table, $options = [])
{
$this->config($options);
$formName = $this->_initParam('formName', $this->config('formName'));
$action = $this->_initParam('action', $this->controller()->request->params['action']);
$this->parameters()->config([
'formName' => $formName,
]);
if ($this->_controller->request->is(['post', 'put'])) {
$this->_redirect($action);
} elseif ($this->_controller->request->is('get')) {
$this->_setViewData($formName);
return $table->find('filters', $this->values());
}
return $table;
}
|
[
"public",
"function",
"prg",
"(",
"$",
"table",
",",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"config",
"(",
"$",
"options",
")",
";",
"$",
"formName",
"=",
"$",
"this",
"->",
"_initParam",
"(",
"'formName'",
",",
"$",
"this",
"->",
"config",
"(",
"'formName'",
")",
")",
";",
"$",
"action",
"=",
"$",
"this",
"->",
"_initParam",
"(",
"'action'",
",",
"$",
"this",
"->",
"controller",
"(",
")",
"->",
"request",
"->",
"params",
"[",
"'action'",
"]",
")",
";",
"$",
"this",
"->",
"parameters",
"(",
")",
"->",
"config",
"(",
"[",
"'formName'",
"=>",
"$",
"formName",
",",
"]",
")",
";",
"if",
"(",
"$",
"this",
"->",
"_controller",
"->",
"request",
"->",
"is",
"(",
"[",
"'post'",
",",
"'put'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"_redirect",
"(",
"$",
"action",
")",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"_controller",
"->",
"request",
"->",
"is",
"(",
"'get'",
")",
")",
"{",
"$",
"this",
"->",
"_setViewData",
"(",
"$",
"formName",
")",
";",
"return",
"$",
"table",
"->",
"find",
"(",
"'filters'",
",",
"$",
"this",
"->",
"values",
"(",
")",
")",
";",
"}",
"return",
"$",
"table",
";",
"}"
] |
Implements Post Redirect Get flow method.
For POST requests builds redirection url and perform redirect to get action.
For GET requests add filters finder to passed into the method query and returns it.
@param Table $table Table instance.
@param array $options Search parameters.
@return mixed
|
[
"Implements",
"Post",
"Redirect",
"Get",
"flow",
"method",
".",
"For",
"POST",
"requests",
"builds",
"redirection",
"url",
"and",
"perform",
"redirect",
"to",
"get",
"action",
".",
"For",
"GET",
"requests",
"add",
"filters",
"finder",
"to",
"passed",
"into",
"the",
"method",
"query",
"and",
"returns",
"it",
"."
] |
24d981e240bff7c15731981d6f9b3056abdaf80e
|
https://github.com/skie/plum_search/blob/24d981e240bff7c15731981d6f9b3056abdaf80e/src/Controller/Component/FilterComponent.php#L138-L157
|
26,750
|
skie/plum_search
|
src/Controller/Component/FilterComponent.php
|
FilterComponent._redirect
|
protected function _redirect($action)
{
$params = $this->controller()->request->params['pass'];
$searchParams = array_diff_key(
array_merge(
$this->controller()->request->query,
$this->values()
),
array_flip(
(array)$this->config('prohibitedParams')
)
);
if ($this->config('filterEmptyParams')) {
$searchParams = array_filter($searchParams);
}
$params['?'] = $searchParams;
$params = array_merge($params, $searchParams);
$params['action'] = $action;
$this->controller()->redirect($params);
$this->controller()->response->send();
$this->controller()->response->stop();
}
|
php
|
protected function _redirect($action)
{
$params = $this->controller()->request->params['pass'];
$searchParams = array_diff_key(
array_merge(
$this->controller()->request->query,
$this->values()
),
array_flip(
(array)$this->config('prohibitedParams')
)
);
if ($this->config('filterEmptyParams')) {
$searchParams = array_filter($searchParams);
}
$params['?'] = $searchParams;
$params = array_merge($params, $searchParams);
$params['action'] = $action;
$this->controller()->redirect($params);
$this->controller()->response->send();
$this->controller()->response->stop();
}
|
[
"protected",
"function",
"_redirect",
"(",
"$",
"action",
")",
"{",
"$",
"params",
"=",
"$",
"this",
"->",
"controller",
"(",
")",
"->",
"request",
"->",
"params",
"[",
"'pass'",
"]",
";",
"$",
"searchParams",
"=",
"array_diff_key",
"(",
"array_merge",
"(",
"$",
"this",
"->",
"controller",
"(",
")",
"->",
"request",
"->",
"query",
",",
"$",
"this",
"->",
"values",
"(",
")",
")",
",",
"array_flip",
"(",
"(",
"array",
")",
"$",
"this",
"->",
"config",
"(",
"'prohibitedParams'",
")",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"config",
"(",
"'filterEmptyParams'",
")",
")",
"{",
"$",
"searchParams",
"=",
"array_filter",
"(",
"$",
"searchParams",
")",
";",
"}",
"$",
"params",
"[",
"'?'",
"]",
"=",
"$",
"searchParams",
";",
"$",
"params",
"=",
"array_merge",
"(",
"$",
"params",
",",
"$",
"searchParams",
")",
";",
"$",
"params",
"[",
"'action'",
"]",
"=",
"$",
"action",
";",
"$",
"this",
"->",
"controller",
"(",
")",
"->",
"redirect",
"(",
"$",
"params",
")",
";",
"$",
"this",
"->",
"controller",
"(",
")",
"->",
"response",
"->",
"send",
"(",
")",
";",
"$",
"this",
"->",
"controller",
"(",
")",
"->",
"response",
"->",
"stop",
"(",
")",
";",
"}"
] |
Redirect action method
@param string $action Action name.
@return void
|
[
"Redirect",
"action",
"method"
] |
24d981e240bff7c15731981d6f9b3056abdaf80e
|
https://github.com/skie/plum_search/blob/24d981e240bff7c15731981d6f9b3056abdaf80e/src/Controller/Component/FilterComponent.php#L202-L225
|
26,751
|
skie/plum_search
|
src/Controller/Component/FilterComponent.php
|
FilterComponent._setViewData
|
protected function _setViewData($formName)
{
$this->controller()->request->data($formName, $this->parameters()->viewValues());
$this->controller()->set('searchParameters', $this->parameters());
}
|
php
|
protected function _setViewData($formName)
{
$this->controller()->request->data($formName, $this->parameters()->viewValues());
$this->controller()->set('searchParameters', $this->parameters());
}
|
[
"protected",
"function",
"_setViewData",
"(",
"$",
"formName",
")",
"{",
"$",
"this",
"->",
"controller",
"(",
")",
"->",
"request",
"->",
"data",
"(",
"$",
"formName",
",",
"$",
"this",
"->",
"parameters",
"(",
")",
"->",
"viewValues",
"(",
")",
")",
";",
"$",
"this",
"->",
"controller",
"(",
")",
"->",
"set",
"(",
"'searchParameters'",
",",
"$",
"this",
"->",
"parameters",
"(",
")",
")",
";",
"}"
] |
Set up view data
@param string $formName Form name.
@return void
|
[
"Set",
"up",
"view",
"data"
] |
24d981e240bff7c15731981d6f9b3056abdaf80e
|
https://github.com/skie/plum_search/blob/24d981e240bff7c15731981d6f9b3056abdaf80e/src/Controller/Component/FilterComponent.php#L233-L237
|
26,752
|
skie/plum_search
|
src/Model/Behavior/FilterableBehavior.php
|
FilterableBehavior.filters
|
public function filters($reset = false)
{
if ($reset || is_null($this->_searchFilters)) {
$this->_searchFilters = new FilterRegistry($this->_table);
}
return $this->_searchFilters;
}
|
php
|
public function filters($reset = false)
{
if ($reset || is_null($this->_searchFilters)) {
$this->_searchFilters = new FilterRegistry($this->_table);
}
return $this->_searchFilters;
}
|
[
"public",
"function",
"filters",
"(",
"$",
"reset",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"reset",
"||",
"is_null",
"(",
"$",
"this",
"->",
"_searchFilters",
")",
")",
"{",
"$",
"this",
"->",
"_searchFilters",
"=",
"new",
"FilterRegistry",
"(",
"$",
"this",
"->",
"_table",
")",
";",
"}",
"return",
"$",
"this",
"->",
"_searchFilters",
";",
"}"
] |
Returns filter registry instance
@param bool $reset Reset flag.
@return \PlumSearch\Model\FilterRegistry
|
[
"Returns",
"filter",
"registry",
"instance"
] |
24d981e240bff7c15731981d6f9b3056abdaf80e
|
https://github.com/skie/plum_search/blob/24d981e240bff7c15731981d6f9b3056abdaf80e/src/Model/Behavior/FilterableBehavior.php#L77-L84
|
26,753
|
skie/plum_search
|
src/Model/Behavior/FilterableBehavior.php
|
FilterableBehavior.findFilter
|
public function findFilter(Query $query, array $options)
{
foreach ($this->filters()->collection() as $name => $filter) {
$filter->apply($query, $options);
}
return $query;
}
|
php
|
public function findFilter(Query $query, array $options)
{
foreach ($this->filters()->collection() as $name => $filter) {
$filter->apply($query, $options);
}
return $query;
}
|
[
"public",
"function",
"findFilter",
"(",
"Query",
"$",
"query",
",",
"array",
"$",
"options",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"filters",
"(",
")",
"->",
"collection",
"(",
")",
"as",
"$",
"name",
"=>",
"$",
"filter",
")",
"{",
"$",
"filter",
"->",
"apply",
"(",
"$",
"query",
",",
"$",
"options",
")",
";",
"}",
"return",
"$",
"query",
";",
"}"
] |
Results for this finder will be query filtered by search parameters
@param \Cake\ORM\Query $query Query.
@param array $options Array of options as described above.
@return \Cake\ORM\Query
|
[
"Results",
"for",
"this",
"finder",
"will",
"be",
"query",
"filtered",
"by",
"search",
"parameters"
] |
24d981e240bff7c15731981d6f9b3056abdaf80e
|
https://github.com/skie/plum_search/blob/24d981e240bff7c15731981d6f9b3056abdaf80e/src/Model/Behavior/FilterableBehavior.php#L141-L148
|
26,754
|
vufind-org/vufindharvest
|
src/RecordWriterStrategy/RecordWriterStrategyFactory.php
|
RecordWriterStrategyFactory.getStrategy
|
public function getStrategy($basePath, $settings = [])
{
if (isset($settings['combineRecords']) && $settings['combineRecords']) {
$combineTag = $settings['combineRecordsTag'] ?? null;
return new CombinedRecordWriterStrategy($basePath, $combineTag);
}
return new IndividualRecordWriterStrategy($basePath);
}
|
php
|
public function getStrategy($basePath, $settings = [])
{
if (isset($settings['combineRecords']) && $settings['combineRecords']) {
$combineTag = $settings['combineRecordsTag'] ?? null;
return new CombinedRecordWriterStrategy($basePath, $combineTag);
}
return new IndividualRecordWriterStrategy($basePath);
}
|
[
"public",
"function",
"getStrategy",
"(",
"$",
"basePath",
",",
"$",
"settings",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"settings",
"[",
"'combineRecords'",
"]",
")",
"&&",
"$",
"settings",
"[",
"'combineRecords'",
"]",
")",
"{",
"$",
"combineTag",
"=",
"$",
"settings",
"[",
"'combineRecordsTag'",
"]",
"??",
"null",
";",
"return",
"new",
"CombinedRecordWriterStrategy",
"(",
"$",
"basePath",
",",
"$",
"combineTag",
")",
";",
"}",
"return",
"new",
"IndividualRecordWriterStrategy",
"(",
"$",
"basePath",
")",
";",
"}"
] |
Build writer strategy object.
@param string $basePath Base path for harvest
@param array $settings Configuration settings
@return RecordWriterStrategyInterface
|
[
"Build",
"writer",
"strategy",
"object",
"."
] |
43a42d1e2292fbba8974a26ace3d522551a1a88f
|
https://github.com/vufind-org/vufindharvest/blob/43a42d1e2292fbba8974a26ace3d522551a1a88f/src/RecordWriterStrategy/RecordWriterStrategyFactory.php#L49-L56
|
26,755
|
skie/plum_search
|
src/Model/FilterRegistry.php
|
FilterRegistry._create
|
protected function _create($class, $alias, $config)
{
if (empty($config['name'])) {
$config['name'] = $alias;
}
$instance = new $class($this, $config);
return $instance;
}
|
php
|
protected function _create($class, $alias, $config)
{
if (empty($config['name'])) {
$config['name'] = $alias;
}
$instance = new $class($this, $config);
return $instance;
}
|
[
"protected",
"function",
"_create",
"(",
"$",
"class",
",",
"$",
"alias",
",",
"$",
"config",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"config",
"[",
"'name'",
"]",
")",
")",
"{",
"$",
"config",
"[",
"'name'",
"]",
"=",
"$",
"alias",
";",
"}",
"$",
"instance",
"=",
"new",
"$",
"class",
"(",
"$",
"this",
",",
"$",
"config",
")",
";",
"return",
"$",
"instance",
";",
"}"
] |
Create the filter instance.
Part of the template method for Cake\Core\ObjectRegistry::load()
Enabled filters will be registered with the event manager.
@param string $class The class name to create.
@param string $alias The alias of the filter.
@param array $config An array of config to use for the filter.
@return \PlumSearch\Model\Filter\AbstractFilter The constructed filter class.
|
[
"Create",
"the",
"filter",
"instance",
"."
] |
24d981e240bff7c15731981d6f9b3056abdaf80e
|
https://github.com/skie/plum_search/blob/24d981e240bff7c15731981d6f9b3056abdaf80e/src/Model/FilterRegistry.php#L92-L100
|
26,756
|
iherwig/wcmf
|
src/wcmf/application/controller/TreeController.php
|
TreeController.getChildren
|
protected function getChildren($oid) {
$permissionManager = $this->getPermissionManager();
$persistenceFacade = $this->getPersistenceFacade();
// check read permission on type
$type = $oid->getType();
if (!$permissionManager->authorize($type, '', PersistenceAction::READ)) {
return [];
}
$objectsTmp = [];
if ($this->isRootTypeNode($oid)) {
// load instances of type
$objectsTmp = $persistenceFacade->loadObjects($type, BuildDepth::SINGLE);
}
else {
// load children of node
if ($permissionManager->authorize($oid, '', PersistenceAction::READ)) {
$node = $persistenceFacade->load($oid, 1);
if ($node) {
$objectsTmp = $node->getChildren();
}
}
}
// check read permission on instances
$objects = [];
foreach ($objectsTmp as $object) {
if ($permissionManager->authorize($object->getOID(), '', PersistenceAction::READ)) {
$objects[] = $object;
}
}
return $objects;
}
|
php
|
protected function getChildren($oid) {
$permissionManager = $this->getPermissionManager();
$persistenceFacade = $this->getPersistenceFacade();
// check read permission on type
$type = $oid->getType();
if (!$permissionManager->authorize($type, '', PersistenceAction::READ)) {
return [];
}
$objectsTmp = [];
if ($this->isRootTypeNode($oid)) {
// load instances of type
$objectsTmp = $persistenceFacade->loadObjects($type, BuildDepth::SINGLE);
}
else {
// load children of node
if ($permissionManager->authorize($oid, '', PersistenceAction::READ)) {
$node = $persistenceFacade->load($oid, 1);
if ($node) {
$objectsTmp = $node->getChildren();
}
}
}
// check read permission on instances
$objects = [];
foreach ($objectsTmp as $object) {
if ($permissionManager->authorize($object->getOID(), '', PersistenceAction::READ)) {
$objects[] = $object;
}
}
return $objects;
}
|
[
"protected",
"function",
"getChildren",
"(",
"$",
"oid",
")",
"{",
"$",
"permissionManager",
"=",
"$",
"this",
"->",
"getPermissionManager",
"(",
")",
";",
"$",
"persistenceFacade",
"=",
"$",
"this",
"->",
"getPersistenceFacade",
"(",
")",
";",
"// check read permission on type",
"$",
"type",
"=",
"$",
"oid",
"->",
"getType",
"(",
")",
";",
"if",
"(",
"!",
"$",
"permissionManager",
"->",
"authorize",
"(",
"$",
"type",
",",
"''",
",",
"PersistenceAction",
"::",
"READ",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"objectsTmp",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"isRootTypeNode",
"(",
"$",
"oid",
")",
")",
"{",
"// load instances of type",
"$",
"objectsTmp",
"=",
"$",
"persistenceFacade",
"->",
"loadObjects",
"(",
"$",
"type",
",",
"BuildDepth",
"::",
"SINGLE",
")",
";",
"}",
"else",
"{",
"// load children of node",
"if",
"(",
"$",
"permissionManager",
"->",
"authorize",
"(",
"$",
"oid",
",",
"''",
",",
"PersistenceAction",
"::",
"READ",
")",
")",
"{",
"$",
"node",
"=",
"$",
"persistenceFacade",
"->",
"load",
"(",
"$",
"oid",
",",
"1",
")",
";",
"if",
"(",
"$",
"node",
")",
"{",
"$",
"objectsTmp",
"=",
"$",
"node",
"->",
"getChildren",
"(",
")",
";",
"}",
"}",
"}",
"// check read permission on instances",
"$",
"objects",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"objectsTmp",
"as",
"$",
"object",
")",
"{",
"if",
"(",
"$",
"permissionManager",
"->",
"authorize",
"(",
"$",
"object",
"->",
"getOID",
"(",
")",
",",
"''",
",",
"PersistenceAction",
"::",
"READ",
")",
")",
"{",
"$",
"objects",
"[",
"]",
"=",
"$",
"object",
";",
"}",
"}",
"return",
"$",
"objects",
";",
"}"
] |
Get the children for a given oid.
@param $oid The object id
@return Array of Node instances.
|
[
"Get",
"the",
"children",
"for",
"a",
"given",
"oid",
"."
] |
2542b8d4139464d39a9a8ce8a954dfecf700c41b
|
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/application/controller/TreeController.php#L88-L122
|
26,757
|
iherwig/wcmf
|
src/wcmf/application/controller/TreeController.php
|
TreeController.getViewNode
|
protected function getViewNode(Node $node, $displayText='') {
if (strlen($displayText) == 0) {
$displayText = trim($this->getDisplayText($node));
}
if (strlen($displayText) == 0) {
$displayText = '-';
}
$oid = $node->getOID();
$isFolder = $oid->containsDummyIds();
$hasChildren = $this->isRootTypeNode($oid) || sizeof($node->getNumChildren()) > 0;
return [
'oid' => $node->getOID()->__toString(),
'displayText' => $displayText,
'isFolder' => $isFolder,
'hasChildren' => $hasChildren
];
}
|
php
|
protected function getViewNode(Node $node, $displayText='') {
if (strlen($displayText) == 0) {
$displayText = trim($this->getDisplayText($node));
}
if (strlen($displayText) == 0) {
$displayText = '-';
}
$oid = $node->getOID();
$isFolder = $oid->containsDummyIds();
$hasChildren = $this->isRootTypeNode($oid) || sizeof($node->getNumChildren()) > 0;
return [
'oid' => $node->getOID()->__toString(),
'displayText' => $displayText,
'isFolder' => $isFolder,
'hasChildren' => $hasChildren
];
}
|
[
"protected",
"function",
"getViewNode",
"(",
"Node",
"$",
"node",
",",
"$",
"displayText",
"=",
"''",
")",
"{",
"if",
"(",
"strlen",
"(",
"$",
"displayText",
")",
"==",
"0",
")",
"{",
"$",
"displayText",
"=",
"trim",
"(",
"$",
"this",
"->",
"getDisplayText",
"(",
"$",
"node",
")",
")",
";",
"}",
"if",
"(",
"strlen",
"(",
"$",
"displayText",
")",
"==",
"0",
")",
"{",
"$",
"displayText",
"=",
"'-'",
";",
"}",
"$",
"oid",
"=",
"$",
"node",
"->",
"getOID",
"(",
")",
";",
"$",
"isFolder",
"=",
"$",
"oid",
"->",
"containsDummyIds",
"(",
")",
";",
"$",
"hasChildren",
"=",
"$",
"this",
"->",
"isRootTypeNode",
"(",
"$",
"oid",
")",
"||",
"sizeof",
"(",
"$",
"node",
"->",
"getNumChildren",
"(",
")",
")",
">",
"0",
";",
"return",
"[",
"'oid'",
"=>",
"$",
"node",
"->",
"getOID",
"(",
")",
"->",
"__toString",
"(",
")",
",",
"'displayText'",
"=>",
"$",
"displayText",
",",
"'isFolder'",
"=>",
"$",
"isFolder",
",",
"'hasChildren'",
"=>",
"$",
"hasChildren",
"]",
";",
"}"
] |
Get the view of a Node
@param $node The Node to create the view for
@param $displayText The text to display (will be taken from TreeController::getDisplayText() if not specified) (default: '')
@return An associative array whose keys correspond to Ext.tree.TreeNode config parameters
|
[
"Get",
"the",
"view",
"of",
"a",
"Node"
] |
2542b8d4139464d39a9a8ce8a954dfecf700c41b
|
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/application/controller/TreeController.php#L139-L155
|
26,758
|
iherwig/wcmf
|
src/wcmf/application/controller/TreeController.php
|
TreeController.getDisplayText
|
protected function getDisplayText(Node $node) {
if ($this->isRootTypeNode($node->getOID())) {
$mapper = $node->getMapper();
return $mapper->getTypeDisplayName($this->getMessage());
}
else {
return strip_tags(preg_replace("/[\r\n']/", " ", NodeUtil::getDisplayValue($node)));
}
}
|
php
|
protected function getDisplayText(Node $node) {
if ($this->isRootTypeNode($node->getOID())) {
$mapper = $node->getMapper();
return $mapper->getTypeDisplayName($this->getMessage());
}
else {
return strip_tags(preg_replace("/[\r\n']/", " ", NodeUtil::getDisplayValue($node)));
}
}
|
[
"protected",
"function",
"getDisplayText",
"(",
"Node",
"$",
"node",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isRootTypeNode",
"(",
"$",
"node",
"->",
"getOID",
"(",
")",
")",
")",
"{",
"$",
"mapper",
"=",
"$",
"node",
"->",
"getMapper",
"(",
")",
";",
"return",
"$",
"mapper",
"->",
"getTypeDisplayName",
"(",
"$",
"this",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"else",
"{",
"return",
"strip_tags",
"(",
"preg_replace",
"(",
"\"/[\\r\\n']/\"",
",",
"\" \"",
",",
"NodeUtil",
"::",
"getDisplayValue",
"(",
"$",
"node",
")",
")",
")",
";",
"}",
"}"
] |
Get the display text for a Node
@param $node Node to display
@return The display text.
|
[
"Get",
"the",
"display",
"text",
"for",
"a",
"Node"
] |
2542b8d4139464d39a9a8ce8a954dfecf700c41b
|
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/application/controller/TreeController.php#L171-L179
|
26,759
|
iherwig/wcmf
|
src/wcmf/application/controller/TreeController.php
|
TreeController.getRootTypes
|
protected function getRootTypes() {
$types = null;
$config = $this->getConfiguration();
// get root types from configuration
// try request value first
$request = $this->getRequest();
$rootTypeVar = $request->getValue('rootTypes');
if ($config->hasValue($rootTypeVar, 'application')) {
$types = $config->getValue($rootTypeVar, 'application');
if (!is_array($types)) {
$types = null;
}
}
if ($types == null) {
// fall back to root types
$types = $config->hasValue('rootTypes', 'application');
}
// filter types by read permission
$permissionManager = $this->getPermissionManager();
$persistenceFacade = $this->getPersistenceFacade();
$nodes = [];
foreach($types as $type) {
if ($permissionManager->authorize($type, '', PersistenceAction::READ)) {
$node = $persistenceFacade->create($type, BuildDepth::SINGLE);
$nodes[] = $node;
}
}
return $nodes;
}
|
php
|
protected function getRootTypes() {
$types = null;
$config = $this->getConfiguration();
// get root types from configuration
// try request value first
$request = $this->getRequest();
$rootTypeVar = $request->getValue('rootTypes');
if ($config->hasValue($rootTypeVar, 'application')) {
$types = $config->getValue($rootTypeVar, 'application');
if (!is_array($types)) {
$types = null;
}
}
if ($types == null) {
// fall back to root types
$types = $config->hasValue('rootTypes', 'application');
}
// filter types by read permission
$permissionManager = $this->getPermissionManager();
$persistenceFacade = $this->getPersistenceFacade();
$nodes = [];
foreach($types as $type) {
if ($permissionManager->authorize($type, '', PersistenceAction::READ)) {
$node = $persistenceFacade->create($type, BuildDepth::SINGLE);
$nodes[] = $node;
}
}
return $nodes;
}
|
[
"protected",
"function",
"getRootTypes",
"(",
")",
"{",
"$",
"types",
"=",
"null",
";",
"$",
"config",
"=",
"$",
"this",
"->",
"getConfiguration",
"(",
")",
";",
"// get root types from configuration",
"// try request value first",
"$",
"request",
"=",
"$",
"this",
"->",
"getRequest",
"(",
")",
";",
"$",
"rootTypeVar",
"=",
"$",
"request",
"->",
"getValue",
"(",
"'rootTypes'",
")",
";",
"if",
"(",
"$",
"config",
"->",
"hasValue",
"(",
"$",
"rootTypeVar",
",",
"'application'",
")",
")",
"{",
"$",
"types",
"=",
"$",
"config",
"->",
"getValue",
"(",
"$",
"rootTypeVar",
",",
"'application'",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"types",
")",
")",
"{",
"$",
"types",
"=",
"null",
";",
"}",
"}",
"if",
"(",
"$",
"types",
"==",
"null",
")",
"{",
"// fall back to root types",
"$",
"types",
"=",
"$",
"config",
"->",
"hasValue",
"(",
"'rootTypes'",
",",
"'application'",
")",
";",
"}",
"// filter types by read permission",
"$",
"permissionManager",
"=",
"$",
"this",
"->",
"getPermissionManager",
"(",
")",
";",
"$",
"persistenceFacade",
"=",
"$",
"this",
"->",
"getPersistenceFacade",
"(",
")",
";",
"$",
"nodes",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"types",
"as",
"$",
"type",
")",
"{",
"if",
"(",
"$",
"permissionManager",
"->",
"authorize",
"(",
"$",
"type",
",",
"''",
",",
"PersistenceAction",
"::",
"READ",
")",
")",
"{",
"$",
"node",
"=",
"$",
"persistenceFacade",
"->",
"create",
"(",
"$",
"type",
",",
"BuildDepth",
"::",
"SINGLE",
")",
";",
"$",
"nodes",
"[",
"]",
"=",
"$",
"node",
";",
"}",
"}",
"return",
"$",
"nodes",
";",
"}"
] |
Get all root types
@return Array of Node instances
|
[
"Get",
"all",
"root",
"types"
] |
2542b8d4139464d39a9a8ce8a954dfecf700c41b
|
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/application/controller/TreeController.php#L185-L215
|
26,760
|
iherwig/wcmf
|
src/wcmf/application/controller/TreeController.php
|
TreeController.isRootTypeNode
|
protected function isRootTypeNode(ObjectId $oid) {
if ($oid->containsDummyIds()) {
$type = $oid->getType();
$rootTypes = $this->getRootTypes();
foreach ($rootTypes as $rootType) {
if ($rootType->getType() == $type) {
return true;
}
}
}
return false;
}
|
php
|
protected function isRootTypeNode(ObjectId $oid) {
if ($oid->containsDummyIds()) {
$type = $oid->getType();
$rootTypes = $this->getRootTypes();
foreach ($rootTypes as $rootType) {
if ($rootType->getType() == $type) {
return true;
}
}
}
return false;
}
|
[
"protected",
"function",
"isRootTypeNode",
"(",
"ObjectId",
"$",
"oid",
")",
"{",
"if",
"(",
"$",
"oid",
"->",
"containsDummyIds",
"(",
")",
")",
"{",
"$",
"type",
"=",
"$",
"oid",
"->",
"getType",
"(",
")",
";",
"$",
"rootTypes",
"=",
"$",
"this",
"->",
"getRootTypes",
"(",
")",
";",
"foreach",
"(",
"$",
"rootTypes",
"as",
"$",
"rootType",
")",
"{",
"if",
"(",
"$",
"rootType",
"->",
"getType",
"(",
")",
"==",
"$",
"type",
")",
"{",
"return",
"true",
";",
"}",
"}",
"}",
"return",
"false",
";",
"}"
] |
Check if the given oid belongs to a root type node
@param $oid The object id
@return Boolean
|
[
"Check",
"if",
"the",
"given",
"oid",
"belongs",
"to",
"a",
"root",
"type",
"node"
] |
2542b8d4139464d39a9a8ce8a954dfecf700c41b
|
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/application/controller/TreeController.php#L222-L233
|
26,761
|
iherwig/wcmf
|
src/wcmf/lib/security/principal/impl/AbstractUser.php
|
AbstractUser.ensureHashedPassword
|
protected function ensureHashedPassword() {
// the password is expected to be stored in the 'password' value
$password = $this->getValue('password');
if (strlen($password) > 0 && !PasswordService::isHashed($password)) {
$this->setValue('password', PasswordService::hash($password));
}
}
|
php
|
protected function ensureHashedPassword() {
// the password is expected to be stored in the 'password' value
$password = $this->getValue('password');
if (strlen($password) > 0 && !PasswordService::isHashed($password)) {
$this->setValue('password', PasswordService::hash($password));
}
}
|
[
"protected",
"function",
"ensureHashedPassword",
"(",
")",
"{",
"// the password is expected to be stored in the 'password' value",
"$",
"password",
"=",
"$",
"this",
"->",
"getValue",
"(",
"'password'",
")",
";",
"if",
"(",
"strlen",
"(",
"$",
"password",
")",
">",
"0",
"&&",
"!",
"PasswordService",
"::",
"isHashed",
"(",
"$",
"password",
")",
")",
"{",
"$",
"this",
"->",
"setValue",
"(",
"'password'",
",",
"PasswordService",
"::",
"hash",
"(",
"$",
"password",
")",
")",
";",
"}",
"}"
] |
Hash password property if not done already.
|
[
"Hash",
"password",
"property",
"if",
"not",
"done",
"already",
"."
] |
2542b8d4139464d39a9a8ce8a954dfecf700c41b
|
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/lib/security/principal/impl/AbstractUser.php#L160-L166
|
26,762
|
iherwig/wcmf
|
src/wcmf/lib/security/principal/impl/AbstractUser.php
|
AbstractUser.setRoleConfig
|
protected function setRoleConfig() {
if (strlen($this->getConfig()) == 0) {
// check added nodes for Role instances
foreach ($this->getAddedNodes() as $relationName => $nodes) {
foreach ($nodes as $node) {
if ($node instanceof Role) {
$roleName = $node->getName();
$roleConfigs = self::getRoleConfigs();
if (isset($roleConfigs[$roleName])) {
$this->setConfig($roleConfigs[$roleName]);
break;
}
}
}
}
}
}
|
php
|
protected function setRoleConfig() {
if (strlen($this->getConfig()) == 0) {
// check added nodes for Role instances
foreach ($this->getAddedNodes() as $relationName => $nodes) {
foreach ($nodes as $node) {
if ($node instanceof Role) {
$roleName = $node->getName();
$roleConfigs = self::getRoleConfigs();
if (isset($roleConfigs[$roleName])) {
$this->setConfig($roleConfigs[$roleName]);
break;
}
}
}
}
}
}
|
[
"protected",
"function",
"setRoleConfig",
"(",
")",
"{",
"if",
"(",
"strlen",
"(",
"$",
"this",
"->",
"getConfig",
"(",
")",
")",
"==",
"0",
")",
"{",
"// check added nodes for Role instances",
"foreach",
"(",
"$",
"this",
"->",
"getAddedNodes",
"(",
")",
"as",
"$",
"relationName",
"=>",
"$",
"nodes",
")",
"{",
"foreach",
"(",
"$",
"nodes",
"as",
"$",
"node",
")",
"{",
"if",
"(",
"$",
"node",
"instanceof",
"Role",
")",
"{",
"$",
"roleName",
"=",
"$",
"node",
"->",
"getName",
"(",
")",
";",
"$",
"roleConfigs",
"=",
"self",
"::",
"getRoleConfigs",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"roleConfigs",
"[",
"$",
"roleName",
"]",
")",
")",
"{",
"$",
"this",
"->",
"setConfig",
"(",
"$",
"roleConfigs",
"[",
"$",
"roleName",
"]",
")",
";",
"break",
";",
"}",
"}",
"}",
"}",
"}",
"}"
] |
Set the configuration of the currently associated role, if no
configuration is set already.
|
[
"Set",
"the",
"configuration",
"of",
"the",
"currently",
"associated",
"role",
"if",
"no",
"configuration",
"is",
"set",
"already",
"."
] |
2542b8d4139464d39a9a8ce8a954dfecf700c41b
|
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/lib/security/principal/impl/AbstractUser.php#L172-L188
|
26,763
|
iherwig/wcmf
|
src/wcmf/lib/security/principal/impl/AbstractUser.php
|
AbstractUser.getRoleConfigs
|
protected static function getRoleConfigs() {
if (self::$roleConfig == null) {
// load role config if existing
$config = ObjectFactory::getInstance('configuration');
if (($roleConfig = $config->getSection('roleconfig')) !== false) {
self::$roleConfig = $roleConfig;
}
}
return self::$roleConfig;
}
|
php
|
protected static function getRoleConfigs() {
if (self::$roleConfig == null) {
// load role config if existing
$config = ObjectFactory::getInstance('configuration');
if (($roleConfig = $config->getSection('roleconfig')) !== false) {
self::$roleConfig = $roleConfig;
}
}
return self::$roleConfig;
}
|
[
"protected",
"static",
"function",
"getRoleConfigs",
"(",
")",
"{",
"if",
"(",
"self",
"::",
"$",
"roleConfig",
"==",
"null",
")",
"{",
"// load role config if existing",
"$",
"config",
"=",
"ObjectFactory",
"::",
"getInstance",
"(",
"'configuration'",
")",
";",
"if",
"(",
"(",
"$",
"roleConfig",
"=",
"$",
"config",
"->",
"getSection",
"(",
"'roleconfig'",
")",
")",
"!==",
"false",
")",
"{",
"self",
"::",
"$",
"roleConfig",
"=",
"$",
"roleConfig",
";",
"}",
"}",
"return",
"self",
"::",
"$",
"roleConfig",
";",
"}"
] |
Get the role configurations from the application configuration
@return Array with role names as keys and config file names as values
|
[
"Get",
"the",
"role",
"configurations",
"from",
"the",
"application",
"configuration"
] |
2542b8d4139464d39a9a8ce8a954dfecf700c41b
|
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/lib/security/principal/impl/AbstractUser.php#L236-L245
|
26,764
|
iherwig/wcmf
|
src/wcmf/lib/security/principal/impl/AbstractUser.php
|
AbstractUser.getAuthUser
|
protected function getAuthUser() {
$principalFactory = ObjectFactory::getInstance('principalFactory');
$session = ObjectFactory::getInstance('session');
return $principalFactory->getUser($session->getAuthUser());
}
|
php
|
protected function getAuthUser() {
$principalFactory = ObjectFactory::getInstance('principalFactory');
$session = ObjectFactory::getInstance('session');
return $principalFactory->getUser($session->getAuthUser());
}
|
[
"protected",
"function",
"getAuthUser",
"(",
")",
"{",
"$",
"principalFactory",
"=",
"ObjectFactory",
"::",
"getInstance",
"(",
"'principalFactory'",
")",
";",
"$",
"session",
"=",
"ObjectFactory",
"::",
"getInstance",
"(",
"'session'",
")",
";",
"return",
"$",
"principalFactory",
"->",
"getUser",
"(",
"$",
"session",
"->",
"getAuthUser",
"(",
")",
")",
";",
"}"
] |
Get the currently authenticated user
@return User
|
[
"Get",
"the",
"currently",
"authenticated",
"user"
] |
2542b8d4139464d39a9a8ce8a954dfecf700c41b
|
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/lib/security/principal/impl/AbstractUser.php#L251-L255
|
26,765
|
iherwig/wcmf
|
src/wcmf/lib/persistence/impl/AbstractMapper.php
|
AbstractMapper.authorizationFailedError
|
protected function authorizationFailedError($resource, $action) {
// when reading only log the error to avoid errors on the display
$msg = ObjectFactory::getInstance('message')->
getText("Authorization failed for action '%0%' on '%1%'.", [$action, $resource]);
if ($action == PersistenceAction::READ) {
self::$logger->error($msg."\n".ErrorHandler::getStackTrace());
}
else {
throw new AuthorizationException($msg);
}
}
|
php
|
protected function authorizationFailedError($resource, $action) {
// when reading only log the error to avoid errors on the display
$msg = ObjectFactory::getInstance('message')->
getText("Authorization failed for action '%0%' on '%1%'.", [$action, $resource]);
if ($action == PersistenceAction::READ) {
self::$logger->error($msg."\n".ErrorHandler::getStackTrace());
}
else {
throw new AuthorizationException($msg);
}
}
|
[
"protected",
"function",
"authorizationFailedError",
"(",
"$",
"resource",
",",
"$",
"action",
")",
"{",
"// when reading only log the error to avoid errors on the display",
"$",
"msg",
"=",
"ObjectFactory",
"::",
"getInstance",
"(",
"'message'",
")",
"->",
"getText",
"(",
"\"Authorization failed for action '%0%' on '%1%'.\"",
",",
"[",
"$",
"action",
",",
"$",
"resource",
"]",
")",
";",
"if",
"(",
"$",
"action",
"==",
"PersistenceAction",
"::",
"READ",
")",
"{",
"self",
"::",
"$",
"logger",
"->",
"error",
"(",
"$",
"msg",
".",
"\"\\n\"",
".",
"ErrorHandler",
"::",
"getStackTrace",
"(",
")",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"AuthorizationException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] |
Handle an authorization error.
@param $resource
@param $action
@throws AuthorizationException
|
[
"Handle",
"an",
"authorization",
"error",
"."
] |
2542b8d4139464d39a9a8ce8a954dfecf700c41b
|
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/lib/persistence/impl/AbstractMapper.php#L403-L413
|
26,766
|
iherwig/wcmf
|
src/wcmf/lib/persistence/impl/AbstractMapper.php
|
AbstractMapper.initRelations
|
private function initRelations() {
if ($this->relations == null) {
$this->relations = [];
$this->relations['byrole'] = [];
$this->relations['bytype'] = [];
$relations = $this->getRelations();
foreach ($relations as $relation) {
$this->relations['byrole'][$relation->getOtherRole()] = $relation;
$otherType = $relation->getOtherType();
if (!isset($this->relations['bytype'][$otherType])) {
$this->relations['bytype'][$otherType] = [];
}
$this->relations['bytype'][$otherType][] = $relation;
$this->relations['bytype'][$this->persistenceFacade->getSimpleType($otherType)][] = $relation;
}
}
}
|
php
|
private function initRelations() {
if ($this->relations == null) {
$this->relations = [];
$this->relations['byrole'] = [];
$this->relations['bytype'] = [];
$relations = $this->getRelations();
foreach ($relations as $relation) {
$this->relations['byrole'][$relation->getOtherRole()] = $relation;
$otherType = $relation->getOtherType();
if (!isset($this->relations['bytype'][$otherType])) {
$this->relations['bytype'][$otherType] = [];
}
$this->relations['bytype'][$otherType][] = $relation;
$this->relations['bytype'][$this->persistenceFacade->getSimpleType($otherType)][] = $relation;
}
}
}
|
[
"private",
"function",
"initRelations",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"relations",
"==",
"null",
")",
"{",
"$",
"this",
"->",
"relations",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"relations",
"[",
"'byrole'",
"]",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"relations",
"[",
"'bytype'",
"]",
"=",
"[",
"]",
";",
"$",
"relations",
"=",
"$",
"this",
"->",
"getRelations",
"(",
")",
";",
"foreach",
"(",
"$",
"relations",
"as",
"$",
"relation",
")",
"{",
"$",
"this",
"->",
"relations",
"[",
"'byrole'",
"]",
"[",
"$",
"relation",
"->",
"getOtherRole",
"(",
")",
"]",
"=",
"$",
"relation",
";",
"$",
"otherType",
"=",
"$",
"relation",
"->",
"getOtherType",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"relations",
"[",
"'bytype'",
"]",
"[",
"$",
"otherType",
"]",
")",
")",
"{",
"$",
"this",
"->",
"relations",
"[",
"'bytype'",
"]",
"[",
"$",
"otherType",
"]",
"=",
"[",
"]",
";",
"}",
"$",
"this",
"->",
"relations",
"[",
"'bytype'",
"]",
"[",
"$",
"otherType",
"]",
"[",
"]",
"=",
"$",
"relation",
";",
"$",
"this",
"->",
"relations",
"[",
"'bytype'",
"]",
"[",
"$",
"this",
"->",
"persistenceFacade",
"->",
"getSimpleType",
"(",
"$",
"otherType",
")",
"]",
"[",
"]",
"=",
"$",
"relation",
";",
"}",
"}",
"}"
] |
Initialize relations.
|
[
"Initialize",
"relations",
"."
] |
2542b8d4139464d39a9a8ce8a954dfecf700c41b
|
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/lib/persistence/impl/AbstractMapper.php#L418-L435
|
26,767
|
Aerendir/PHPValueObjects
|
src/CurrencyExchangeRate/CurrencyExchangeRate.php
|
CurrencyExchangeRate.setExchangeRate
|
protected function setExchangeRate(float $exchangeRate): void
{
if ( ! is_float($exchangeRate)) {
throw new \InvalidArgumentException(sprintf('ExchangeRate has to be a float. %s given.', gettype($exchangeRate)));
}
$this->exchangeRate = $exchangeRate;
}
|
php
|
protected function setExchangeRate(float $exchangeRate): void
{
if ( ! is_float($exchangeRate)) {
throw new \InvalidArgumentException(sprintf('ExchangeRate has to be a float. %s given.', gettype($exchangeRate)));
}
$this->exchangeRate = $exchangeRate;
}
|
[
"protected",
"function",
"setExchangeRate",
"(",
"float",
"$",
"exchangeRate",
")",
":",
"void",
"{",
"if",
"(",
"!",
"is_float",
"(",
"$",
"exchangeRate",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'ExchangeRate has to be a float. %s given.'",
",",
"gettype",
"(",
"$",
"exchangeRate",
")",
")",
")",
";",
"}",
"$",
"this",
"->",
"exchangeRate",
"=",
"$",
"exchangeRate",
";",
"}"
] |
Set the conversion rate of the currency.
@param float $exchangeRate
|
[
"Set",
"the",
"conversion",
"rate",
"of",
"the",
"currency",
"."
] |
5ef646e593e411bf1b678755ff552a00a245d4c9
|
https://github.com/Aerendir/PHPValueObjects/blob/5ef646e593e411bf1b678755ff552a00a245d4c9/src/CurrencyExchangeRate/CurrencyExchangeRate.php#L95-L102
|
26,768
|
iherwig/wcmf
|
src/wcmf/lib/model/ObjectQueryUnionQueryProvider.php
|
ObjectQueryUnionQueryProvider.getLastQueryStrings
|
public function getLastQueryStrings() {
$result = [];
foreach ($this->queries as $query) {
$result[] = $query->getLastQueryString();
}
return $result;
}
|
php
|
public function getLastQueryStrings() {
$result = [];
foreach ($this->queries as $query) {
$result[] = $query->getLastQueryString();
}
return $result;
}
|
[
"public",
"function",
"getLastQueryStrings",
"(",
")",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"queries",
"as",
"$",
"query",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"$",
"query",
"->",
"getLastQueryString",
"(",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] |
Get the last query strings
@return Array of string
|
[
"Get",
"the",
"last",
"query",
"strings"
] |
2542b8d4139464d39a9a8ce8a954dfecf700c41b
|
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/lib/model/ObjectQueryUnionQueryProvider.php#L62-L68
|
26,769
|
iherwig/wcmf
|
src/wcmf/lib/model/NodeIterator.php
|
NodeIterator.addToQueue
|
protected function addToQueue($nodeList) {
for ($i=sizeof($nodeList)-1; $i>=0; $i--) {
if ($nodeList[$i] instanceof Node) {
$this->nodeList[] = $nodeList[$i];
}
}
}
|
php
|
protected function addToQueue($nodeList) {
for ($i=sizeof($nodeList)-1; $i>=0; $i--) {
if ($nodeList[$i] instanceof Node) {
$this->nodeList[] = $nodeList[$i];
}
}
}
|
[
"protected",
"function",
"addToQueue",
"(",
"$",
"nodeList",
")",
"{",
"for",
"(",
"$",
"i",
"=",
"sizeof",
"(",
"$",
"nodeList",
")",
"-",
"1",
";",
"$",
"i",
">=",
"0",
";",
"$",
"i",
"--",
")",
"{",
"if",
"(",
"$",
"nodeList",
"[",
"$",
"i",
"]",
"instanceof",
"Node",
")",
"{",
"$",
"this",
"->",
"nodeList",
"[",
"]",
"=",
"$",
"nodeList",
"[",
"$",
"i",
"]",
";",
"}",
"}",
"}"
] |
Add nodes to the processing queue.
@param $nodeList An array of nodes.
|
[
"Add",
"nodes",
"to",
"the",
"processing",
"queue",
"."
] |
2542b8d4139464d39a9a8ce8a954dfecf700c41b
|
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/lib/model/NodeIterator.php#L144-L150
|
26,770
|
GW2Treasures/gw2api
|
src/V2/Endpoint/Guild/RestrictedGuildHandler.php
|
RestrictedGuildHandler.onError
|
public function onError(ResponseInterface $response, RequestInterface $request) {
$json = $this->getResponseAsJson( $response );
if( !is_null( $json ) && isset( $json->text )) {
if( $json->text === 'access restricted to guild leaders' ) {
throw new GuildLeaderRequiredException( $json->text, $response );
} elseif( $json->text === 'membership required' ) {
throw new MembershipRequiredException( $json->text, $response );
}
}
}
|
php
|
public function onError(ResponseInterface $response, RequestInterface $request) {
$json = $this->getResponseAsJson( $response );
if( !is_null( $json ) && isset( $json->text )) {
if( $json->text === 'access restricted to guild leaders' ) {
throw new GuildLeaderRequiredException( $json->text, $response );
} elseif( $json->text === 'membership required' ) {
throw new MembershipRequiredException( $json->text, $response );
}
}
}
|
[
"public",
"function",
"onError",
"(",
"ResponseInterface",
"$",
"response",
",",
"RequestInterface",
"$",
"request",
")",
"{",
"$",
"json",
"=",
"$",
"this",
"->",
"getResponseAsJson",
"(",
"$",
"response",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"json",
")",
"&&",
"isset",
"(",
"$",
"json",
"->",
"text",
")",
")",
"{",
"if",
"(",
"$",
"json",
"->",
"text",
"===",
"'access restricted to guild leaders'",
")",
"{",
"throw",
"new",
"GuildLeaderRequiredException",
"(",
"$",
"json",
"->",
"text",
",",
"$",
"response",
")",
";",
"}",
"elseif",
"(",
"$",
"json",
"->",
"text",
"===",
"'membership required'",
")",
"{",
"throw",
"new",
"MembershipRequiredException",
"(",
"$",
"json",
"->",
"text",
",",
"$",
"response",
")",
";",
"}",
"}",
"}"
] |
Handle errors by the api.
@param ResponseInterface $response
@param RequestInterface $request
@throws GuildLeaderRequiredException
@throws MembershipRequiredException
|
[
"Handle",
"errors",
"by",
"the",
"api",
"."
] |
c8795af0c1d0a434b9e530f779d5a95786db2176
|
https://github.com/GW2Treasures/gw2api/blob/c8795af0c1d0a434b9e530f779d5a95786db2176/src/V2/Endpoint/Guild/RestrictedGuildHandler.php#L28-L37
|
26,771
|
iherwig/wcmf
|
src/wcmf/lib/io/FileUtil.php
|
FileUtil.getMimeType
|
public static function getMimeType($file) {
$defaultType = 'application/octet-stream';
if (class_exists('\FileInfo')) {
// use extension
$fileInfo = new finfo(FILEINFO_MIME);
$fileType = $fileInfo->file(file_get_contents($file));
}
else {
// try detect image mime type
$imageInfo = @getimagesize($file);
$fileType = isset($imageInfo['mime']) ? $imageInfo['mime'] : '';
}
return (is_string($fileType) && !empty($fileType)) ? $fileType : $defaultType;
}
|
php
|
public static function getMimeType($file) {
$defaultType = 'application/octet-stream';
if (class_exists('\FileInfo')) {
// use extension
$fileInfo = new finfo(FILEINFO_MIME);
$fileType = $fileInfo->file(file_get_contents($file));
}
else {
// try detect image mime type
$imageInfo = @getimagesize($file);
$fileType = isset($imageInfo['mime']) ? $imageInfo['mime'] : '';
}
return (is_string($fileType) && !empty($fileType)) ? $fileType : $defaultType;
}
|
[
"public",
"static",
"function",
"getMimeType",
"(",
"$",
"file",
")",
"{",
"$",
"defaultType",
"=",
"'application/octet-stream'",
";",
"if",
"(",
"class_exists",
"(",
"'\\FileInfo'",
")",
")",
"{",
"// use extension",
"$",
"fileInfo",
"=",
"new",
"finfo",
"(",
"FILEINFO_MIME",
")",
";",
"$",
"fileType",
"=",
"$",
"fileInfo",
"->",
"file",
"(",
"file_get_contents",
"(",
"$",
"file",
")",
")",
";",
"}",
"else",
"{",
"// try detect image mime type",
"$",
"imageInfo",
"=",
"@",
"getimagesize",
"(",
"$",
"file",
")",
";",
"$",
"fileType",
"=",
"isset",
"(",
"$",
"imageInfo",
"[",
"'mime'",
"]",
")",
"?",
"$",
"imageInfo",
"[",
"'mime'",
"]",
":",
"''",
";",
"}",
"return",
"(",
"is_string",
"(",
"$",
"fileType",
")",
"&&",
"!",
"empty",
"(",
"$",
"fileType",
")",
")",
"?",
"$",
"fileType",
":",
"$",
"defaultType",
";",
"}"
] |
Get the mime type of the given file
@param $file The file
@return String
|
[
"Get",
"the",
"mime",
"type",
"of",
"the",
"given",
"file"
] |
2542b8d4139464d39a9a8ce8a954dfecf700c41b
|
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/lib/io/FileUtil.php#L66-L79
|
26,772
|
iherwig/wcmf
|
src/wcmf/lib/io/FileUtil.php
|
FileUtil.copyRecDir
|
public static function copyRecDir($source, $dest) {
if (!is_dir($dest)) {
self::mkdirRec($dest);
}
$dir = opendir($source);
while ($file = readdir($dir)) {
if ($file == "." || $file == "..") {
continue;
}
self::copyRec("$source/$file", "$dest/$file");
}
closedir($dir);
}
|
php
|
public static function copyRecDir($source, $dest) {
if (!is_dir($dest)) {
self::mkdirRec($dest);
}
$dir = opendir($source);
while ($file = readdir($dir)) {
if ($file == "." || $file == "..") {
continue;
}
self::copyRec("$source/$file", "$dest/$file");
}
closedir($dir);
}
|
[
"public",
"static",
"function",
"copyRecDir",
"(",
"$",
"source",
",",
"$",
"dest",
")",
"{",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"dest",
")",
")",
"{",
"self",
"::",
"mkdirRec",
"(",
"$",
"dest",
")",
";",
"}",
"$",
"dir",
"=",
"opendir",
"(",
"$",
"source",
")",
";",
"while",
"(",
"$",
"file",
"=",
"readdir",
"(",
"$",
"dir",
")",
")",
"{",
"if",
"(",
"$",
"file",
"==",
"\".\"",
"||",
"$",
"file",
"==",
"\"..\"",
")",
"{",
"continue",
";",
"}",
"self",
"::",
"copyRec",
"(",
"\"$source/$file\"",
",",
"\"$dest/$file\"",
")",
";",
"}",
"closedir",
"(",
"$",
"dir",
")",
";",
"}"
] |
Recursive copy for directories.
@param $source The name of the source directory
@param $dest The name of the destination directory
|
[
"Recursive",
"copy",
"for",
"directories",
"."
] |
2542b8d4139464d39a9a8ce8a954dfecf700c41b
|
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/lib/io/FileUtil.php#L196-L208
|
26,773
|
iherwig/wcmf
|
src/wcmf/lib/io/FileUtil.php
|
FileUtil.fixFilename
|
public static function fixFilename($file) {
if (file_exists($file)) {
return $file;
}
else {
$file = iconv('utf-8', 'cp1252', $file);
if (file_exists($file)) {
return $file;
}
}
return null;
}
|
php
|
public static function fixFilename($file) {
if (file_exists($file)) {
return $file;
}
else {
$file = iconv('utf-8', 'cp1252', $file);
if (file_exists($file)) {
return $file;
}
}
return null;
}
|
[
"public",
"static",
"function",
"fixFilename",
"(",
"$",
"file",
")",
"{",
"if",
"(",
"file_exists",
"(",
"$",
"file",
")",
")",
"{",
"return",
"$",
"file",
";",
"}",
"else",
"{",
"$",
"file",
"=",
"iconv",
"(",
"'utf-8'",
",",
"'cp1252'",
",",
"$",
"file",
")",
";",
"if",
"(",
"file_exists",
"(",
"$",
"file",
")",
")",
"{",
"return",
"$",
"file",
";",
"}",
"}",
"return",
"null",
";",
"}"
] |
Fix the name of an existing file to be used with php file functions
@param $file
@return String or null, if the file does not exist
|
[
"Fix",
"the",
"name",
"of",
"an",
"existing",
"file",
"to",
"be",
"used",
"with",
"php",
"file",
"functions"
] |
2542b8d4139464d39a9a8ce8a954dfecf700c41b
|
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/lib/io/FileUtil.php#L286-L297
|
26,774
|
iherwig/wcmf
|
src/wcmf/lib/io/FileUtil.php
|
FileUtil.urlencodeFilename
|
public static function urlencodeFilename($file) {
$parts = explode('/', $file);
$result = [];
foreach ($parts as $part) {
$result[] = rawurlencode($part);
}
return join('/', $result);
}
|
php
|
public static function urlencodeFilename($file) {
$parts = explode('/', $file);
$result = [];
foreach ($parts as $part) {
$result[] = rawurlencode($part);
}
return join('/', $result);
}
|
[
"public",
"static",
"function",
"urlencodeFilename",
"(",
"$",
"file",
")",
"{",
"$",
"parts",
"=",
"explode",
"(",
"'/'",
",",
"$",
"file",
")",
";",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"parts",
"as",
"$",
"part",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"rawurlencode",
"(",
"$",
"part",
")",
";",
"}",
"return",
"join",
"(",
"'/'",
",",
"$",
"result",
")",
";",
"}"
] |
Url encode a file path
@param $file
@return String
|
[
"Url",
"encode",
"a",
"file",
"path"
] |
2542b8d4139464d39a9a8ce8a954dfecf700c41b
|
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/lib/io/FileUtil.php#L304-L311
|
26,775
|
iherwig/wcmf
|
src/wcmf/lib/model/ObjectQuery.php
|
ObjectQuery.getObjectTemplate
|
public function getObjectTemplate($type, $alias=null, $combineOperator=Criteria::OPERATOR_AND) {
$template = null;
// use the typeNode, the first time a node template of the query type is requested
$persistenceFacade = ObjectFactory::getInstance('persistenceFacade');
$fqType = $persistenceFacade->getFullyQualifiedType($type);
if ($fqType == $this->typeNode->getType() && !$this->isTypeNodeInQuery) {
$template = $this->typeNode;
$this->isTypeNodeInQuery = true;
// the typeNode is contained already in the rootNodes array
}
else {
// don't use PersistenceFacade::create, because template instances must be transient
$mapper = self::getMapper($fqType);
$template = $mapper->create($fqType, BuildDepth::SINGLE);
$this->rootNodes[] = $template;
}
$template->setProperty(self::PROPERTY_COMBINE_OPERATOR, $combineOperator);
if ($alias != null) {
$template->setProperty(self::PROPERTY_TABLE_NAME, $alias);
}
$initialOid = $template->getOID()->__toString();
$template->setProperty(self::PROPERTY_INITIAL_OID, $initialOid);
$this->observedObjects[$initialOid] = $template;
return $template;
}
|
php
|
public function getObjectTemplate($type, $alias=null, $combineOperator=Criteria::OPERATOR_AND) {
$template = null;
// use the typeNode, the first time a node template of the query type is requested
$persistenceFacade = ObjectFactory::getInstance('persistenceFacade');
$fqType = $persistenceFacade->getFullyQualifiedType($type);
if ($fqType == $this->typeNode->getType() && !$this->isTypeNodeInQuery) {
$template = $this->typeNode;
$this->isTypeNodeInQuery = true;
// the typeNode is contained already in the rootNodes array
}
else {
// don't use PersistenceFacade::create, because template instances must be transient
$mapper = self::getMapper($fqType);
$template = $mapper->create($fqType, BuildDepth::SINGLE);
$this->rootNodes[] = $template;
}
$template->setProperty(self::PROPERTY_COMBINE_OPERATOR, $combineOperator);
if ($alias != null) {
$template->setProperty(self::PROPERTY_TABLE_NAME, $alias);
}
$initialOid = $template->getOID()->__toString();
$template->setProperty(self::PROPERTY_INITIAL_OID, $initialOid);
$this->observedObjects[$initialOid] = $template;
return $template;
}
|
[
"public",
"function",
"getObjectTemplate",
"(",
"$",
"type",
",",
"$",
"alias",
"=",
"null",
",",
"$",
"combineOperator",
"=",
"Criteria",
"::",
"OPERATOR_AND",
")",
"{",
"$",
"template",
"=",
"null",
";",
"// use the typeNode, the first time a node template of the query type is requested",
"$",
"persistenceFacade",
"=",
"ObjectFactory",
"::",
"getInstance",
"(",
"'persistenceFacade'",
")",
";",
"$",
"fqType",
"=",
"$",
"persistenceFacade",
"->",
"getFullyQualifiedType",
"(",
"$",
"type",
")",
";",
"if",
"(",
"$",
"fqType",
"==",
"$",
"this",
"->",
"typeNode",
"->",
"getType",
"(",
")",
"&&",
"!",
"$",
"this",
"->",
"isTypeNodeInQuery",
")",
"{",
"$",
"template",
"=",
"$",
"this",
"->",
"typeNode",
";",
"$",
"this",
"->",
"isTypeNodeInQuery",
"=",
"true",
";",
"// the typeNode is contained already in the rootNodes array",
"}",
"else",
"{",
"// don't use PersistenceFacade::create, because template instances must be transient",
"$",
"mapper",
"=",
"self",
"::",
"getMapper",
"(",
"$",
"fqType",
")",
";",
"$",
"template",
"=",
"$",
"mapper",
"->",
"create",
"(",
"$",
"fqType",
",",
"BuildDepth",
"::",
"SINGLE",
")",
";",
"$",
"this",
"->",
"rootNodes",
"[",
"]",
"=",
"$",
"template",
";",
"}",
"$",
"template",
"->",
"setProperty",
"(",
"self",
"::",
"PROPERTY_COMBINE_OPERATOR",
",",
"$",
"combineOperator",
")",
";",
"if",
"(",
"$",
"alias",
"!=",
"null",
")",
"{",
"$",
"template",
"->",
"setProperty",
"(",
"self",
"::",
"PROPERTY_TABLE_NAME",
",",
"$",
"alias",
")",
";",
"}",
"$",
"initialOid",
"=",
"$",
"template",
"->",
"getOID",
"(",
")",
"->",
"__toString",
"(",
")",
";",
"$",
"template",
"->",
"setProperty",
"(",
"self",
"::",
"PROPERTY_INITIAL_OID",
",",
"$",
"initialOid",
")",
";",
"$",
"this",
"->",
"observedObjects",
"[",
"$",
"initialOid",
"]",
"=",
"$",
"template",
";",
"return",
"$",
"template",
";",
"}"
] |
Get an object template for a given type.
@param $type The type to query for
@param $alias An alias name to be used in the query. if null, use the default name (default: _null_)
@param $combineOperator One of the Criteria::OPERATOR constants that precedes
the conditions described in the template (default: _Criteria::OPERATOR_AND_)
@return Node
|
[
"Get",
"an",
"object",
"template",
"for",
"a",
"given",
"type",
"."
] |
2542b8d4139464d39a9a8ce8a954dfecf700c41b
|
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/lib/model/ObjectQuery.php#L169-L194
|
26,776
|
iherwig/wcmf
|
src/wcmf/lib/model/ObjectQuery.php
|
ObjectQuery.registerObjectTemplate
|
public function registerObjectTemplate(Node $template, $alias=null, $combineOperator=Criteria::OPERATOR_AND) {
if ($template != null) {
$initialOid = $template->getOID();
$initialOidStr = $initialOid->__toString();
$template->setProperty(self::PROPERTY_INITIAL_OID, $initialOidStr);
$this->observedObjects[$initialOidStr] = $template;
// call the setters for all attributes in order to register them in the query
$includePKs = !ObjectId::isDummyId($initialOid->getFirstId());
$template->copyValues($template, $includePKs);
$template->setProperty(self::PROPERTY_COMBINE_OPERATOR, $combineOperator);
if ($alias != null) {
$template->setProperty(self::PROPERTY_TABLE_NAME, $alias);
}
// replace the typeNode, the first time a node template of the query type is registered
if ($template->getType() == $this->typeNode->getType() && !$this->isTypeNodeInQuery) {
$newRootNodes = [$template];
foreach($this->rootNodes as $node) {
if ($node != $this->typeNode) {
$newRootNodes[] = $node;
}
}
$this->rootNodes = $newRootNodes;
$this->isTypeNodeInQuery = true;
}
else {
$this->rootNodes[] = $template;
}
}
}
|
php
|
public function registerObjectTemplate(Node $template, $alias=null, $combineOperator=Criteria::OPERATOR_AND) {
if ($template != null) {
$initialOid = $template->getOID();
$initialOidStr = $initialOid->__toString();
$template->setProperty(self::PROPERTY_INITIAL_OID, $initialOidStr);
$this->observedObjects[$initialOidStr] = $template;
// call the setters for all attributes in order to register them in the query
$includePKs = !ObjectId::isDummyId($initialOid->getFirstId());
$template->copyValues($template, $includePKs);
$template->setProperty(self::PROPERTY_COMBINE_OPERATOR, $combineOperator);
if ($alias != null) {
$template->setProperty(self::PROPERTY_TABLE_NAME, $alias);
}
// replace the typeNode, the first time a node template of the query type is registered
if ($template->getType() == $this->typeNode->getType() && !$this->isTypeNodeInQuery) {
$newRootNodes = [$template];
foreach($this->rootNodes as $node) {
if ($node != $this->typeNode) {
$newRootNodes[] = $node;
}
}
$this->rootNodes = $newRootNodes;
$this->isTypeNodeInQuery = true;
}
else {
$this->rootNodes[] = $template;
}
}
}
|
[
"public",
"function",
"registerObjectTemplate",
"(",
"Node",
"$",
"template",
",",
"$",
"alias",
"=",
"null",
",",
"$",
"combineOperator",
"=",
"Criteria",
"::",
"OPERATOR_AND",
")",
"{",
"if",
"(",
"$",
"template",
"!=",
"null",
")",
"{",
"$",
"initialOid",
"=",
"$",
"template",
"->",
"getOID",
"(",
")",
";",
"$",
"initialOidStr",
"=",
"$",
"initialOid",
"->",
"__toString",
"(",
")",
";",
"$",
"template",
"->",
"setProperty",
"(",
"self",
"::",
"PROPERTY_INITIAL_OID",
",",
"$",
"initialOidStr",
")",
";",
"$",
"this",
"->",
"observedObjects",
"[",
"$",
"initialOidStr",
"]",
"=",
"$",
"template",
";",
"// call the setters for all attributes in order to register them in the query",
"$",
"includePKs",
"=",
"!",
"ObjectId",
"::",
"isDummyId",
"(",
"$",
"initialOid",
"->",
"getFirstId",
"(",
")",
")",
";",
"$",
"template",
"->",
"copyValues",
"(",
"$",
"template",
",",
"$",
"includePKs",
")",
";",
"$",
"template",
"->",
"setProperty",
"(",
"self",
"::",
"PROPERTY_COMBINE_OPERATOR",
",",
"$",
"combineOperator",
")",
";",
"if",
"(",
"$",
"alias",
"!=",
"null",
")",
"{",
"$",
"template",
"->",
"setProperty",
"(",
"self",
"::",
"PROPERTY_TABLE_NAME",
",",
"$",
"alias",
")",
";",
"}",
"// replace the typeNode, the first time a node template of the query type is registered",
"if",
"(",
"$",
"template",
"->",
"getType",
"(",
")",
"==",
"$",
"this",
"->",
"typeNode",
"->",
"getType",
"(",
")",
"&&",
"!",
"$",
"this",
"->",
"isTypeNodeInQuery",
")",
"{",
"$",
"newRootNodes",
"=",
"[",
"$",
"template",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"rootNodes",
"as",
"$",
"node",
")",
"{",
"if",
"(",
"$",
"node",
"!=",
"$",
"this",
"->",
"typeNode",
")",
"{",
"$",
"newRootNodes",
"[",
"]",
"=",
"$",
"node",
";",
"}",
"}",
"$",
"this",
"->",
"rootNodes",
"=",
"$",
"newRootNodes",
";",
"$",
"this",
"->",
"isTypeNodeInQuery",
"=",
"true",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"rootNodes",
"[",
"]",
"=",
"$",
"template",
";",
"}",
"}",
"}"
] |
Register an object template at the query.
@param $template Node instance to register as template
@param $alias An alias name to be used in the query. if null, use the default name (default: _null_)
@param $combineOperator One of the Criteria::OPERATOR constants that precedes
the conditions described in the template (default: Criteria::OPERATOR_AND)
|
[
"Register",
"an",
"object",
"template",
"at",
"the",
"query",
"."
] |
2542b8d4139464d39a9a8ce8a954dfecf700c41b
|
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/lib/model/ObjectQuery.php#L203-L234
|
26,777
|
iherwig/wcmf
|
src/wcmf/lib/model/ObjectQuery.php
|
ObjectQuery.makeGroup
|
public function makeGroup($templates, $combineOperator=Criteria::OPERATOR_AND) {
$this->groups[] = ['tpls' => $templates, self::PROPERTY_COMBINE_OPERATOR => $combineOperator];
// store grouped nodes in an extra array to separate them from the others
for ($i=0; $i<sizeof($templates); $i++) {
if ($templates[$i] != null) {
$this->groupedOIDs[] = $templates[$i]->getOID();
}
else {
throw new IllegalArgumentException("Null value found in group");
}
}
}
|
php
|
public function makeGroup($templates, $combineOperator=Criteria::OPERATOR_AND) {
$this->groups[] = ['tpls' => $templates, self::PROPERTY_COMBINE_OPERATOR => $combineOperator];
// store grouped nodes in an extra array to separate them from the others
for ($i=0; $i<sizeof($templates); $i++) {
if ($templates[$i] != null) {
$this->groupedOIDs[] = $templates[$i]->getOID();
}
else {
throw new IllegalArgumentException("Null value found in group");
}
}
}
|
[
"public",
"function",
"makeGroup",
"(",
"$",
"templates",
",",
"$",
"combineOperator",
"=",
"Criteria",
"::",
"OPERATOR_AND",
")",
"{",
"$",
"this",
"->",
"groups",
"[",
"]",
"=",
"[",
"'tpls'",
"=>",
"$",
"templates",
",",
"self",
"::",
"PROPERTY_COMBINE_OPERATOR",
"=>",
"$",
"combineOperator",
"]",
";",
"// store grouped nodes in an extra array to separate them from the others",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"sizeof",
"(",
"$",
"templates",
")",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"$",
"templates",
"[",
"$",
"i",
"]",
"!=",
"null",
")",
"{",
"$",
"this",
"->",
"groupedOIDs",
"[",
"]",
"=",
"$",
"templates",
"[",
"$",
"i",
"]",
"->",
"getOID",
"(",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Null value found in group\"",
")",
";",
"}",
"}",
"}"
] |
Group different templates together to realize brackets in the query.
@note Grouped templates will be ignored, when iterating over the object tree and appended at the end.
@param $templates An array of references to the templates contained in the group
@param $combineOperator One of the Criteria::OPERATOR constants that precedes the group (default: _Criteria::OPERATOR_AND_)
|
[
"Group",
"different",
"templates",
"together",
"to",
"realize",
"brackets",
"in",
"the",
"query",
"."
] |
2542b8d4139464d39a9a8ce8a954dfecf700c41b
|
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/lib/model/ObjectQuery.php#L242-L253
|
26,778
|
iherwig/wcmf
|
src/wcmf/lib/model/ObjectQuery.php
|
ObjectQuery.getQueryCondition
|
public function getQueryCondition() {
$query = $this->getQueryString();
$tmp = preg_split("/ WHERE /i", $query);
if (sizeof($tmp) > 1) {
$tmp = preg_split("/ ORDER /i", $tmp[1]);
return $tmp[0];
}
return '';
}
|
php
|
public function getQueryCondition() {
$query = $this->getQueryString();
$tmp = preg_split("/ WHERE /i", $query);
if (sizeof($tmp) > 1) {
$tmp = preg_split("/ ORDER /i", $tmp[1]);
return $tmp[0];
}
return '';
}
|
[
"public",
"function",
"getQueryCondition",
"(",
")",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"getQueryString",
"(",
")",
";",
"$",
"tmp",
"=",
"preg_split",
"(",
"\"/ WHERE /i\"",
",",
"$",
"query",
")",
";",
"if",
"(",
"sizeof",
"(",
"$",
"tmp",
")",
">",
"1",
")",
"{",
"$",
"tmp",
"=",
"preg_split",
"(",
"\"/ ORDER /i\"",
",",
"$",
"tmp",
"[",
"1",
"]",
")",
";",
"return",
"$",
"tmp",
"[",
"0",
"]",
";",
"}",
"return",
"''",
";",
"}"
] |
Get the condition part of the query. This is especially useful to
build a StringQuery from the query objects.
@return String
|
[
"Get",
"the",
"condition",
"part",
"of",
"the",
"query",
".",
"This",
"is",
"especially",
"useful",
"to",
"build",
"a",
"StringQuery",
"from",
"the",
"query",
"objects",
"."
] |
2542b8d4139464d39a9a8ce8a954dfecf700c41b
|
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/lib/model/ObjectQuery.php#L260-L268
|
26,779
|
iherwig/wcmf
|
src/wcmf/lib/model/ObjectQuery.php
|
ObjectQuery.getParameters
|
protected function getParameters($criteria, array $parameters) {
$result = [];
// flatten conditions
$criteriaFlat = [];
foreach ($criteria as $key => $curCriteria) {
foreach ($curCriteria as $criterion) {
if ($criterion instanceof Criteria) {
$mapper = self::getMapper($criterion->getType());
$valueName = $criterion->getAttribute();
$attributeDesc = $mapper->getAttribute($valueName);
if ($attributeDesc) {
$criteriaFlat[] = $criterion;
}
}
}
}
// get parameters in order
$criteriaValuePosition = [];
foreach ($parameters as $placeholder => $index) {
$value = $criteriaFlat[$index]->getValue();
if (is_array($value)) {
// criteria has array value
// initialize position counting for this criteria (defined by index)
if (!isset($criteriaValuePosition[$index])) {
$criteriaValuePosition[$index] = 0;
}
// set the value from the array
$result[$placeholder] = $value[$criteriaValuePosition[$index]];
$criteriaValuePosition[$index]++;
}
else {
// criteria has single value
$result[$placeholder] = $value;
}
}
return $result;
}
|
php
|
protected function getParameters($criteria, array $parameters) {
$result = [];
// flatten conditions
$criteriaFlat = [];
foreach ($criteria as $key => $curCriteria) {
foreach ($curCriteria as $criterion) {
if ($criterion instanceof Criteria) {
$mapper = self::getMapper($criterion->getType());
$valueName = $criterion->getAttribute();
$attributeDesc = $mapper->getAttribute($valueName);
if ($attributeDesc) {
$criteriaFlat[] = $criterion;
}
}
}
}
// get parameters in order
$criteriaValuePosition = [];
foreach ($parameters as $placeholder => $index) {
$value = $criteriaFlat[$index]->getValue();
if (is_array($value)) {
// criteria has array value
// initialize position counting for this criteria (defined by index)
if (!isset($criteriaValuePosition[$index])) {
$criteriaValuePosition[$index] = 0;
}
// set the value from the array
$result[$placeholder] = $value[$criteriaValuePosition[$index]];
$criteriaValuePosition[$index]++;
}
else {
// criteria has single value
$result[$placeholder] = $value;
}
}
return $result;
}
|
[
"protected",
"function",
"getParameters",
"(",
"$",
"criteria",
",",
"array",
"$",
"parameters",
")",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"// flatten conditions",
"$",
"criteriaFlat",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"criteria",
"as",
"$",
"key",
"=>",
"$",
"curCriteria",
")",
"{",
"foreach",
"(",
"$",
"curCriteria",
"as",
"$",
"criterion",
")",
"{",
"if",
"(",
"$",
"criterion",
"instanceof",
"Criteria",
")",
"{",
"$",
"mapper",
"=",
"self",
"::",
"getMapper",
"(",
"$",
"criterion",
"->",
"getType",
"(",
")",
")",
";",
"$",
"valueName",
"=",
"$",
"criterion",
"->",
"getAttribute",
"(",
")",
";",
"$",
"attributeDesc",
"=",
"$",
"mapper",
"->",
"getAttribute",
"(",
"$",
"valueName",
")",
";",
"if",
"(",
"$",
"attributeDesc",
")",
"{",
"$",
"criteriaFlat",
"[",
"]",
"=",
"$",
"criterion",
";",
"}",
"}",
"}",
"}",
"// get parameters in order",
"$",
"criteriaValuePosition",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"parameters",
"as",
"$",
"placeholder",
"=>",
"$",
"index",
")",
"{",
"$",
"value",
"=",
"$",
"criteriaFlat",
"[",
"$",
"index",
"]",
"->",
"getValue",
"(",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"// criteria has array value",
"// initialize position counting for this criteria (defined by index)",
"if",
"(",
"!",
"isset",
"(",
"$",
"criteriaValuePosition",
"[",
"$",
"index",
"]",
")",
")",
"{",
"$",
"criteriaValuePosition",
"[",
"$",
"index",
"]",
"=",
"0",
";",
"}",
"// set the value from the array",
"$",
"result",
"[",
"$",
"placeholder",
"]",
"=",
"$",
"value",
"[",
"$",
"criteriaValuePosition",
"[",
"$",
"index",
"]",
"]",
";",
"$",
"criteriaValuePosition",
"[",
"$",
"index",
"]",
"++",
";",
"}",
"else",
"{",
"// criteria has single value",
"$",
"result",
"[",
"$",
"placeholder",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] |
Get an array of parameter values for the given criteria
@param $criteria An array of Criteria instances that define conditions on the object's attributes (maybe null)
@param $parameters Array defining the parameter order
@return Array
|
[
"Get",
"an",
"array",
"of",
"parameter",
"values",
"for",
"the",
"given",
"criteria"
] |
2542b8d4139464d39a9a8ce8a954dfecf700c41b
|
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/lib/model/ObjectQuery.php#L561-L597
|
26,780
|
iherwig/wcmf
|
src/wcmf/lib/model/ObjectQuery.php
|
ObjectQuery.processTableName
|
protected function processTableName(Node $tpl) {
$mapper = self::getMapper($tpl->getType());
$mapperTableName = $mapper->getRealTableName();
$tableName = $tpl->getProperty(self::PROPERTY_TABLE_NAME);
if ($tableName == null) {
$tableName = $mapperTableName;
// if the template is the child of another node of the same type,
// we must use a table alias
$parents = $tpl->getParentsEx(null, null, $tpl->getType());
foreach ($parents as $curParent) {
$curParentTableName = $curParent->getProperty(self::PROPERTY_TABLE_NAME);
if ($curParentTableName == $tableName) {
$tableName .= '_'.($this->aliasCounter++);
}
}
// set the table name for later reference
$tpl->setProperty(self::PROPERTY_TABLE_NAME, $tableName);
}
return ['name' => $mapperTableName, 'alias' => $tableName];
}
|
php
|
protected function processTableName(Node $tpl) {
$mapper = self::getMapper($tpl->getType());
$mapperTableName = $mapper->getRealTableName();
$tableName = $tpl->getProperty(self::PROPERTY_TABLE_NAME);
if ($tableName == null) {
$tableName = $mapperTableName;
// if the template is the child of another node of the same type,
// we must use a table alias
$parents = $tpl->getParentsEx(null, null, $tpl->getType());
foreach ($parents as $curParent) {
$curParentTableName = $curParent->getProperty(self::PROPERTY_TABLE_NAME);
if ($curParentTableName == $tableName) {
$tableName .= '_'.($this->aliasCounter++);
}
}
// set the table name for later reference
$tpl->setProperty(self::PROPERTY_TABLE_NAME, $tableName);
}
return ['name' => $mapperTableName, 'alias' => $tableName];
}
|
[
"protected",
"function",
"processTableName",
"(",
"Node",
"$",
"tpl",
")",
"{",
"$",
"mapper",
"=",
"self",
"::",
"getMapper",
"(",
"$",
"tpl",
"->",
"getType",
"(",
")",
")",
";",
"$",
"mapperTableName",
"=",
"$",
"mapper",
"->",
"getRealTableName",
"(",
")",
";",
"$",
"tableName",
"=",
"$",
"tpl",
"->",
"getProperty",
"(",
"self",
"::",
"PROPERTY_TABLE_NAME",
")",
";",
"if",
"(",
"$",
"tableName",
"==",
"null",
")",
"{",
"$",
"tableName",
"=",
"$",
"mapperTableName",
";",
"// if the template is the child of another node of the same type,",
"// we must use a table alias",
"$",
"parents",
"=",
"$",
"tpl",
"->",
"getParentsEx",
"(",
"null",
",",
"null",
",",
"$",
"tpl",
"->",
"getType",
"(",
")",
")",
";",
"foreach",
"(",
"$",
"parents",
"as",
"$",
"curParent",
")",
"{",
"$",
"curParentTableName",
"=",
"$",
"curParent",
"->",
"getProperty",
"(",
"self",
"::",
"PROPERTY_TABLE_NAME",
")",
";",
"if",
"(",
"$",
"curParentTableName",
"==",
"$",
"tableName",
")",
"{",
"$",
"tableName",
".=",
"'_'",
".",
"(",
"$",
"this",
"->",
"aliasCounter",
"++",
")",
";",
"}",
"}",
"// set the table name for later reference",
"$",
"tpl",
"->",
"setProperty",
"(",
"self",
"::",
"PROPERTY_TABLE_NAME",
",",
"$",
"tableName",
")",
";",
"}",
"return",
"[",
"'name'",
"=>",
"$",
"mapperTableName",
",",
"'alias'",
"=>",
"$",
"tableName",
"]",
";",
"}"
] |
Get the table name for the template and calculate an alias if
necessary.
@param $tpl The object template
@return Associative array with keys 'name', 'alias'
|
[
"Get",
"the",
"table",
"name",
"for",
"the",
"template",
"and",
"calculate",
"an",
"alias",
"if",
"necessary",
"."
] |
2542b8d4139464d39a9a8ce8a954dfecf700c41b
|
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/lib/model/ObjectQuery.php#L629-L651
|
26,781
|
iherwig/wcmf
|
src/wcmf/lib/model/ObjectQuery.php
|
ObjectQuery.valueChanged
|
public function valueChanged(ValueChangeEvent $event) {
$object = $event->getObject();
$name = $event->getValueName();
$initialOid = $object->getProperty(self::PROPERTY_INITIAL_OID);
if (isset($this->observedObjects[$initialOid])) {
$newValue = $event->getNewValue();
// make a criteria from newValue and make sure that all properties are set
if (!($newValue instanceof Criteria)) {
// LIKE fallback, if the value is not a Criteria instance
$mapper = self::getMapper($object->getType());
$pkNames = $mapper->getPkNames();
if (!in_array($name, $pkNames)) {
// use like condition on any attribute, if it's a string
// other value changes will be ignored!
if (is_string($newValue)) {
$newValue = new Criteria($object->getType(), $name, 'LIKE', '%'.$newValue.'%');
}
}
else {
// don't search for pk names with LIKE
$newValue = new Criteria($object->getType(), $name, '=', $newValue);
}
}
else {
// make sure that type and name are set even if the Criteria is constructed
// via Criteria::forValue()
$newValue->setType($object->getType());
$newValue->setAttribute($name);
}
$oid = $object->getOID()->__toString();
// store change in internal array to have it when constructing the query
if (!isset($this->conditions[$oid])) {
$this->conditions[$oid] = [];
}
$this->conditions[$oid][$name] = $newValue;
}
}
|
php
|
public function valueChanged(ValueChangeEvent $event) {
$object = $event->getObject();
$name = $event->getValueName();
$initialOid = $object->getProperty(self::PROPERTY_INITIAL_OID);
if (isset($this->observedObjects[$initialOid])) {
$newValue = $event->getNewValue();
// make a criteria from newValue and make sure that all properties are set
if (!($newValue instanceof Criteria)) {
// LIKE fallback, if the value is not a Criteria instance
$mapper = self::getMapper($object->getType());
$pkNames = $mapper->getPkNames();
if (!in_array($name, $pkNames)) {
// use like condition on any attribute, if it's a string
// other value changes will be ignored!
if (is_string($newValue)) {
$newValue = new Criteria($object->getType(), $name, 'LIKE', '%'.$newValue.'%');
}
}
else {
// don't search for pk names with LIKE
$newValue = new Criteria($object->getType(), $name, '=', $newValue);
}
}
else {
// make sure that type and name are set even if the Criteria is constructed
// via Criteria::forValue()
$newValue->setType($object->getType());
$newValue->setAttribute($name);
}
$oid = $object->getOID()->__toString();
// store change in internal array to have it when constructing the query
if (!isset($this->conditions[$oid])) {
$this->conditions[$oid] = [];
}
$this->conditions[$oid][$name] = $newValue;
}
}
|
[
"public",
"function",
"valueChanged",
"(",
"ValueChangeEvent",
"$",
"event",
")",
"{",
"$",
"object",
"=",
"$",
"event",
"->",
"getObject",
"(",
")",
";",
"$",
"name",
"=",
"$",
"event",
"->",
"getValueName",
"(",
")",
";",
"$",
"initialOid",
"=",
"$",
"object",
"->",
"getProperty",
"(",
"self",
"::",
"PROPERTY_INITIAL_OID",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"observedObjects",
"[",
"$",
"initialOid",
"]",
")",
")",
"{",
"$",
"newValue",
"=",
"$",
"event",
"->",
"getNewValue",
"(",
")",
";",
"// make a criteria from newValue and make sure that all properties are set",
"if",
"(",
"!",
"(",
"$",
"newValue",
"instanceof",
"Criteria",
")",
")",
"{",
"// LIKE fallback, if the value is not a Criteria instance",
"$",
"mapper",
"=",
"self",
"::",
"getMapper",
"(",
"$",
"object",
"->",
"getType",
"(",
")",
")",
";",
"$",
"pkNames",
"=",
"$",
"mapper",
"->",
"getPkNames",
"(",
")",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"name",
",",
"$",
"pkNames",
")",
")",
"{",
"// use like condition on any attribute, if it's a string",
"// other value changes will be ignored!",
"if",
"(",
"is_string",
"(",
"$",
"newValue",
")",
")",
"{",
"$",
"newValue",
"=",
"new",
"Criteria",
"(",
"$",
"object",
"->",
"getType",
"(",
")",
",",
"$",
"name",
",",
"'LIKE'",
",",
"'%'",
".",
"$",
"newValue",
".",
"'%'",
")",
";",
"}",
"}",
"else",
"{",
"// don't search for pk names with LIKE",
"$",
"newValue",
"=",
"new",
"Criteria",
"(",
"$",
"object",
"->",
"getType",
"(",
")",
",",
"$",
"name",
",",
"'='",
",",
"$",
"newValue",
")",
";",
"}",
"}",
"else",
"{",
"// make sure that type and name are set even if the Criteria is constructed",
"// via Criteria::forValue()",
"$",
"newValue",
"->",
"setType",
"(",
"$",
"object",
"->",
"getType",
"(",
")",
")",
";",
"$",
"newValue",
"->",
"setAttribute",
"(",
"$",
"name",
")",
";",
"}",
"$",
"oid",
"=",
"$",
"object",
"->",
"getOID",
"(",
")",
"->",
"__toString",
"(",
")",
";",
"// store change in internal array to have it when constructing the query",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"conditions",
"[",
"$",
"oid",
"]",
")",
")",
"{",
"$",
"this",
"->",
"conditions",
"[",
"$",
"oid",
"]",
"=",
"[",
"]",
";",
"}",
"$",
"this",
"->",
"conditions",
"[",
"$",
"oid",
"]",
"[",
"$",
"name",
"]",
"=",
"$",
"newValue",
";",
"}",
"}"
] |
Listen to ValueChangeEvents
@param $event ValueChangeEvent instance
|
[
"Listen",
"to",
"ValueChangeEvents"
] |
2542b8d4139464d39a9a8ce8a954dfecf700c41b
|
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/lib/model/ObjectQuery.php#L657-L694
|
26,782
|
skie/plum_search
|
src/FormParameter/ParameterRegistry.php
|
ParameterRegistry._resolveClassName
|
protected function _resolveClassName($class)
{
$result = App::className($class, 'FormParameter', 'Parameter');
if ($result || strpos($class, '.') !== false) {
return $result;
}
return App::className('PlumSearch.' . $class, 'FormParameter', 'Parameter');
}
|
php
|
protected function _resolveClassName($class)
{
$result = App::className($class, 'FormParameter', 'Parameter');
if ($result || strpos($class, '.') !== false) {
return $result;
}
return App::className('PlumSearch.' . $class, 'FormParameter', 'Parameter');
}
|
[
"protected",
"function",
"_resolveClassName",
"(",
"$",
"class",
")",
"{",
"$",
"result",
"=",
"App",
"::",
"className",
"(",
"$",
"class",
",",
"'FormParameter'",
",",
"'Parameter'",
")",
";",
"if",
"(",
"$",
"result",
"||",
"strpos",
"(",
"$",
"class",
",",
"'.'",
")",
"!==",
"false",
")",
"{",
"return",
"$",
"result",
";",
"}",
"return",
"App",
"::",
"className",
"(",
"'PlumSearch.'",
".",
"$",
"class",
",",
"'FormParameter'",
",",
"'Parameter'",
")",
";",
"}"
] |
Resolve a param class name.
Part of the template method for Cake\Core\ObjectRegistry::load()
@param string $class Partial class name to resolve.
@return string|false Either the correct class name or false.
|
[
"Resolve",
"a",
"param",
"class",
"name",
"."
] |
24d981e240bff7c15731981d6f9b3056abdaf80e
|
https://github.com/skie/plum_search/blob/24d981e240bff7c15731981d6f9b3056abdaf80e/src/FormParameter/ParameterRegistry.php#L62-L70
|
26,783
|
skie/plum_search
|
src/FormParameter/ParameterRegistry.php
|
ParameterRegistry.collection
|
public function collection($collectionMethod = null)
{
$collection = collection($this->_loaded);
if (is_callable($collectionMethod)) {
return $collectionMethod($collection);
}
return $collection;
}
|
php
|
public function collection($collectionMethod = null)
{
$collection = collection($this->_loaded);
if (is_callable($collectionMethod)) {
return $collectionMethod($collection);
}
return $collection;
}
|
[
"public",
"function",
"collection",
"(",
"$",
"collectionMethod",
"=",
"null",
")",
"{",
"$",
"collection",
"=",
"collection",
"(",
"$",
"this",
"->",
"_loaded",
")",
";",
"if",
"(",
"is_callable",
"(",
"$",
"collectionMethod",
")",
")",
"{",
"return",
"$",
"collectionMethod",
"(",
"$",
"collection",
")",
";",
"}",
"return",
"$",
"collection",
";",
"}"
] |
Return collection of loaded parameters
@return \Cake\Collection\Collection
|
[
"Return",
"collection",
"of",
"loaded",
"parameters"
] |
24d981e240bff7c15731981d6f9b3056abdaf80e
|
https://github.com/skie/plum_search/blob/24d981e240bff7c15731981d6f9b3056abdaf80e/src/FormParameter/ParameterRegistry.php#L115-L123
|
26,784
|
skie/plum_search
|
src/FormParameter/ParameterRegistry.php
|
ParameterRegistry.data
|
public function data($name = null)
{
if ($this->_Controller->request->is('get')) {
if (empty($name)) {
return $this->_Controller->request->query;
} else {
return $this->_Controller->request->query($name);
}
} elseif ($this->_Controller->request->is(['post', 'put'])) {
if (empty($name)) {
return $this->_Controller->request->data[$this->formName];
} else {
return $this->_Controller->request->data($this->fieldName($name));
}
}
return null;
}
|
php
|
public function data($name = null)
{
if ($this->_Controller->request->is('get')) {
if (empty($name)) {
return $this->_Controller->request->query;
} else {
return $this->_Controller->request->query($name);
}
} elseif ($this->_Controller->request->is(['post', 'put'])) {
if (empty($name)) {
return $this->_Controller->request->data[$this->formName];
} else {
return $this->_Controller->request->data($this->fieldName($name));
}
}
return null;
}
|
[
"public",
"function",
"data",
"(",
"$",
"name",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_Controller",
"->",
"request",
"->",
"is",
"(",
"'get'",
")",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"name",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_Controller",
"->",
"request",
"->",
"query",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"_Controller",
"->",
"request",
"->",
"query",
"(",
"$",
"name",
")",
";",
"}",
"}",
"elseif",
"(",
"$",
"this",
"->",
"_Controller",
"->",
"request",
"->",
"is",
"(",
"[",
"'post'",
",",
"'put'",
"]",
")",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"name",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_Controller",
"->",
"request",
"->",
"data",
"[",
"$",
"this",
"->",
"formName",
"]",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"_Controller",
"->",
"request",
"->",
"data",
"(",
"$",
"this",
"->",
"fieldName",
"(",
"$",
"name",
")",
")",
";",
"}",
"}",
"return",
"null",
";",
"}"
] |
Returns parameter value based by it's name
@param string $name Parameter name.
@return mixed
|
[
"Returns",
"parameter",
"value",
"based",
"by",
"it",
"s",
"name"
] |
24d981e240bff7c15731981d6f9b3056abdaf80e
|
https://github.com/skie/plum_search/blob/24d981e240bff7c15731981d6f9b3056abdaf80e/src/FormParameter/ParameterRegistry.php#L131-L148
|
26,785
|
iherwig/wcmf
|
src/wcmf/application/controller/RESTController.php
|
RESTController.readInRelation
|
public function readInRelation() {
$request = $this->getRequest();
// rewrite query if querying for a relation
$relationName = $request->getValue('relation');
// set the query
$sourceOid = ObjectId::parse($request->getValue('sourceOid'));
$persistenceFacade = $this->getPersistenceFacade();
$sourceNode = $persistenceFacade->load($sourceOid);
if ($sourceNode) {
$relationQuery = NodeUtil::getRelationQueryCondition($sourceNode, $relationName);
$query = ($request->hasValue('query') ? $request->getValue('query').'&' : '').$relationQuery;
$request->setValue('query', $query);
// set the class name
$mapper = $sourceNode->getMapper();
$relation = $mapper->getRelation($relationName);
$otherType = $relation->getOtherType();
$request->setValue('className', $otherType);
// set default order
if (!$request->hasValue('sortFieldName')) {
$otherMapper = $persistenceFacade->getMapper($otherType);
$sortkeyDef = $otherMapper->getSortkey($relation->getThisRole());
if ($sortkeyDef != null) {
$request->setValue('sortFieldName', $sortkeyDef['sortFieldName']);
$request->setValue('sortDirection', $sortkeyDef['sortDirection']);
}
}
}
// delegate to ListController
$subResponse = $this->executeSubAction('list');
$this->handleSubResponse($subResponse);
}
|
php
|
public function readInRelation() {
$request = $this->getRequest();
// rewrite query if querying for a relation
$relationName = $request->getValue('relation');
// set the query
$sourceOid = ObjectId::parse($request->getValue('sourceOid'));
$persistenceFacade = $this->getPersistenceFacade();
$sourceNode = $persistenceFacade->load($sourceOid);
if ($sourceNode) {
$relationQuery = NodeUtil::getRelationQueryCondition($sourceNode, $relationName);
$query = ($request->hasValue('query') ? $request->getValue('query').'&' : '').$relationQuery;
$request->setValue('query', $query);
// set the class name
$mapper = $sourceNode->getMapper();
$relation = $mapper->getRelation($relationName);
$otherType = $relation->getOtherType();
$request->setValue('className', $otherType);
// set default order
if (!$request->hasValue('sortFieldName')) {
$otherMapper = $persistenceFacade->getMapper($otherType);
$sortkeyDef = $otherMapper->getSortkey($relation->getThisRole());
if ($sortkeyDef != null) {
$request->setValue('sortFieldName', $sortkeyDef['sortFieldName']);
$request->setValue('sortDirection', $sortkeyDef['sortDirection']);
}
}
}
// delegate to ListController
$subResponse = $this->executeSubAction('list');
$this->handleSubResponse($subResponse);
}
|
[
"public",
"function",
"readInRelation",
"(",
")",
"{",
"$",
"request",
"=",
"$",
"this",
"->",
"getRequest",
"(",
")",
";",
"// rewrite query if querying for a relation",
"$",
"relationName",
"=",
"$",
"request",
"->",
"getValue",
"(",
"'relation'",
")",
";",
"// set the query",
"$",
"sourceOid",
"=",
"ObjectId",
"::",
"parse",
"(",
"$",
"request",
"->",
"getValue",
"(",
"'sourceOid'",
")",
")",
";",
"$",
"persistenceFacade",
"=",
"$",
"this",
"->",
"getPersistenceFacade",
"(",
")",
";",
"$",
"sourceNode",
"=",
"$",
"persistenceFacade",
"->",
"load",
"(",
"$",
"sourceOid",
")",
";",
"if",
"(",
"$",
"sourceNode",
")",
"{",
"$",
"relationQuery",
"=",
"NodeUtil",
"::",
"getRelationQueryCondition",
"(",
"$",
"sourceNode",
",",
"$",
"relationName",
")",
";",
"$",
"query",
"=",
"(",
"$",
"request",
"->",
"hasValue",
"(",
"'query'",
")",
"?",
"$",
"request",
"->",
"getValue",
"(",
"'query'",
")",
".",
"'&'",
":",
"''",
")",
".",
"$",
"relationQuery",
";",
"$",
"request",
"->",
"setValue",
"(",
"'query'",
",",
"$",
"query",
")",
";",
"// set the class name",
"$",
"mapper",
"=",
"$",
"sourceNode",
"->",
"getMapper",
"(",
")",
";",
"$",
"relation",
"=",
"$",
"mapper",
"->",
"getRelation",
"(",
"$",
"relationName",
")",
";",
"$",
"otherType",
"=",
"$",
"relation",
"->",
"getOtherType",
"(",
")",
";",
"$",
"request",
"->",
"setValue",
"(",
"'className'",
",",
"$",
"otherType",
")",
";",
"// set default order",
"if",
"(",
"!",
"$",
"request",
"->",
"hasValue",
"(",
"'sortFieldName'",
")",
")",
"{",
"$",
"otherMapper",
"=",
"$",
"persistenceFacade",
"->",
"getMapper",
"(",
"$",
"otherType",
")",
";",
"$",
"sortkeyDef",
"=",
"$",
"otherMapper",
"->",
"getSortkey",
"(",
"$",
"relation",
"->",
"getThisRole",
"(",
")",
")",
";",
"if",
"(",
"$",
"sortkeyDef",
"!=",
"null",
")",
"{",
"$",
"request",
"->",
"setValue",
"(",
"'sortFieldName'",
",",
"$",
"sortkeyDef",
"[",
"'sortFieldName'",
"]",
")",
";",
"$",
"request",
"->",
"setValue",
"(",
"'sortDirection'",
",",
"$",
"sortkeyDef",
"[",
"'sortDirection'",
"]",
")",
";",
"}",
"}",
"}",
"// delegate to ListController",
"$",
"subResponse",
"=",
"$",
"this",
"->",
"executeSubAction",
"(",
"'list'",
")",
";",
"$",
"this",
"->",
"handleSubResponse",
"(",
"$",
"subResponse",
")",
";",
"}"
] |
Read objects that are related to another object
| Parameter | Description
|------------------|-------------------------
| _in_ `language` | The language of the returned objects
| _in_ `sourceId` | Id of the object to which the returned objects are related (determines the object id together with _className_)
| _in_ `className` | The type of the object defined by _sourceId_
| _in_ `relation` | Name of the relation to the object defined by _sourceId_ (determines the type of the returned objects)
| _in_ `sortBy` | <em>?sortBy=+foo</em> for sorting the list by foo ascending or
| _in_ `sort` | <em>?sort(+foo)</em> for sorting the list by foo ascending
| _in_ `limit` | <em>?limit(10,25)</em> for loading 10 objects starting from position 25
| _in_ `query` | A query condition encoded in RQL to be used with StringQuery::setRQLConditionString()
| _out_ | List of objects
|
[
"Read",
"objects",
"that",
"are",
"related",
"to",
"another",
"object"
] |
2542b8d4139464d39a9a8ce8a954dfecf700c41b
|
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/application/controller/RESTController.php#L190-L225
|
26,786
|
iherwig/wcmf
|
src/wcmf/application/controller/RESTController.php
|
RESTController.create
|
public function create() {
$this->requireTransaction();
// delegate to SaveController
$subResponse = $this->executeSubAction('create');
// return object only
$oidStr = $subResponse->hasValue('oid') ? $subResponse->getValue('oid')->__toString() : null;
$this->handleSubResponse($subResponse, $oidStr);
// prevent commit
if ($subResponse->hasErrors()) {
$this->endTransaction(false);
}
}
|
php
|
public function create() {
$this->requireTransaction();
// delegate to SaveController
$subResponse = $this->executeSubAction('create');
// return object only
$oidStr = $subResponse->hasValue('oid') ? $subResponse->getValue('oid')->__toString() : null;
$this->handleSubResponse($subResponse, $oidStr);
// prevent commit
if ($subResponse->hasErrors()) {
$this->endTransaction(false);
}
}
|
[
"public",
"function",
"create",
"(",
")",
"{",
"$",
"this",
"->",
"requireTransaction",
"(",
")",
";",
"// delegate to SaveController",
"$",
"subResponse",
"=",
"$",
"this",
"->",
"executeSubAction",
"(",
"'create'",
")",
";",
"// return object only",
"$",
"oidStr",
"=",
"$",
"subResponse",
"->",
"hasValue",
"(",
"'oid'",
")",
"?",
"$",
"subResponse",
"->",
"getValue",
"(",
"'oid'",
")",
"->",
"__toString",
"(",
")",
":",
"null",
";",
"$",
"this",
"->",
"handleSubResponse",
"(",
"$",
"subResponse",
",",
"$",
"oidStr",
")",
";",
"// prevent commit",
"if",
"(",
"$",
"subResponse",
"->",
"hasErrors",
"(",
")",
")",
"{",
"$",
"this",
"->",
"endTransaction",
"(",
"false",
")",
";",
"}",
"}"
] |
Create an object of a given type
| Parameter | Description
|------------------|-------------------------
| _in_ `language` | The language of the object
| _in_ `className` | Type of object to create
| _out_ | Created object data
The object data is contained in POST content.
|
[
"Create",
"an",
"object",
"of",
"a",
"given",
"type"
] |
2542b8d4139464d39a9a8ce8a954dfecf700c41b
|
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/application/controller/RESTController.php#L238-L251
|
26,787
|
iherwig/wcmf
|
src/wcmf/application/controller/RESTController.php
|
RESTController.createInRelation
|
public function createInRelation() {
$this->requireTransaction();
$request = $this->getRequest();
// create new object
$oidStr = null;
$sourceOid = ObjectId::parse($request->getValue('sourceOid'));
$relatedType = $this->getRelatedType($sourceOid, $request->getValue('relation'));
$request->setValue('className', $relatedType);
$subResponse = $this->executeSubAction('create');
if (!$subResponse->hasErrors()) {
$createStatus = $subResponse->getStatus();
$targetOid = $subResponse->getValue('oid');
$targetOidStr = $targetOid->__toString();
// add new object to relation
$request->setValue('targetOid', $targetOidStr);
$request->setValue('role', $request->getValue('relation'));
$subResponse = $this->executeSubAction('associate');
if (!$subResponse->hasErrors()) {
// add related object to subresponse similar to default update action
$persistenceFacade = $this->getPersistenceFacade();
$targetObj = $persistenceFacade->load($targetOid);
$subResponse->setValue('oid', $targetOid);
$subResponse->setValue($targetOidStr, $targetObj);
$subResponse->setStatus($createStatus);
// in case of success, return object only
$oidStr = $subResponse->hasValue('oid') ? $subResponse->getValue('oid')->__toString() : '';
}
}
// prevent commit
if ($subResponse->hasErrors()) {
$this->endTransaction(false);
}
$this->handleSubResponse($subResponse, $oidStr);
}
|
php
|
public function createInRelation() {
$this->requireTransaction();
$request = $this->getRequest();
// create new object
$oidStr = null;
$sourceOid = ObjectId::parse($request->getValue('sourceOid'));
$relatedType = $this->getRelatedType($sourceOid, $request->getValue('relation'));
$request->setValue('className', $relatedType);
$subResponse = $this->executeSubAction('create');
if (!$subResponse->hasErrors()) {
$createStatus = $subResponse->getStatus();
$targetOid = $subResponse->getValue('oid');
$targetOidStr = $targetOid->__toString();
// add new object to relation
$request->setValue('targetOid', $targetOidStr);
$request->setValue('role', $request->getValue('relation'));
$subResponse = $this->executeSubAction('associate');
if (!$subResponse->hasErrors()) {
// add related object to subresponse similar to default update action
$persistenceFacade = $this->getPersistenceFacade();
$targetObj = $persistenceFacade->load($targetOid);
$subResponse->setValue('oid', $targetOid);
$subResponse->setValue($targetOidStr, $targetObj);
$subResponse->setStatus($createStatus);
// in case of success, return object only
$oidStr = $subResponse->hasValue('oid') ? $subResponse->getValue('oid')->__toString() : '';
}
}
// prevent commit
if ($subResponse->hasErrors()) {
$this->endTransaction(false);
}
$this->handleSubResponse($subResponse, $oidStr);
}
|
[
"public",
"function",
"createInRelation",
"(",
")",
"{",
"$",
"this",
"->",
"requireTransaction",
"(",
")",
";",
"$",
"request",
"=",
"$",
"this",
"->",
"getRequest",
"(",
")",
";",
"// create new object",
"$",
"oidStr",
"=",
"null",
";",
"$",
"sourceOid",
"=",
"ObjectId",
"::",
"parse",
"(",
"$",
"request",
"->",
"getValue",
"(",
"'sourceOid'",
")",
")",
";",
"$",
"relatedType",
"=",
"$",
"this",
"->",
"getRelatedType",
"(",
"$",
"sourceOid",
",",
"$",
"request",
"->",
"getValue",
"(",
"'relation'",
")",
")",
";",
"$",
"request",
"->",
"setValue",
"(",
"'className'",
",",
"$",
"relatedType",
")",
";",
"$",
"subResponse",
"=",
"$",
"this",
"->",
"executeSubAction",
"(",
"'create'",
")",
";",
"if",
"(",
"!",
"$",
"subResponse",
"->",
"hasErrors",
"(",
")",
")",
"{",
"$",
"createStatus",
"=",
"$",
"subResponse",
"->",
"getStatus",
"(",
")",
";",
"$",
"targetOid",
"=",
"$",
"subResponse",
"->",
"getValue",
"(",
"'oid'",
")",
";",
"$",
"targetOidStr",
"=",
"$",
"targetOid",
"->",
"__toString",
"(",
")",
";",
"// add new object to relation",
"$",
"request",
"->",
"setValue",
"(",
"'targetOid'",
",",
"$",
"targetOidStr",
")",
";",
"$",
"request",
"->",
"setValue",
"(",
"'role'",
",",
"$",
"request",
"->",
"getValue",
"(",
"'relation'",
")",
")",
";",
"$",
"subResponse",
"=",
"$",
"this",
"->",
"executeSubAction",
"(",
"'associate'",
")",
";",
"if",
"(",
"!",
"$",
"subResponse",
"->",
"hasErrors",
"(",
")",
")",
"{",
"// add related object to subresponse similar to default update action",
"$",
"persistenceFacade",
"=",
"$",
"this",
"->",
"getPersistenceFacade",
"(",
")",
";",
"$",
"targetObj",
"=",
"$",
"persistenceFacade",
"->",
"load",
"(",
"$",
"targetOid",
")",
";",
"$",
"subResponse",
"->",
"setValue",
"(",
"'oid'",
",",
"$",
"targetOid",
")",
";",
"$",
"subResponse",
"->",
"setValue",
"(",
"$",
"targetOidStr",
",",
"$",
"targetObj",
")",
";",
"$",
"subResponse",
"->",
"setStatus",
"(",
"$",
"createStatus",
")",
";",
"// in case of success, return object only",
"$",
"oidStr",
"=",
"$",
"subResponse",
"->",
"hasValue",
"(",
"'oid'",
")",
"?",
"$",
"subResponse",
"->",
"getValue",
"(",
"'oid'",
")",
"->",
"__toString",
"(",
")",
":",
"''",
";",
"}",
"}",
"// prevent commit",
"if",
"(",
"$",
"subResponse",
"->",
"hasErrors",
"(",
")",
")",
"{",
"$",
"this",
"->",
"endTransaction",
"(",
"false",
")",
";",
"}",
"$",
"this",
"->",
"handleSubResponse",
"(",
"$",
"subResponse",
",",
"$",
"oidStr",
")",
";",
"}"
] |
Create an object of a given type in the given relation
| Parameter | Description
|------------------|-------------------------
| _in_ `language` | The language of the object
| _in_ `className` | Type of object to create
| _in_ `sourceId` | Id of the object to which the created objects are added (determines the object id together with _className_)
| _in_ `relation` | Name of the relation to the object defined by _sourceId_ (determines the type of the created/added object)
| _out_ | Created object data
The object data is contained in POST content. If an existing object
should be added, an `oid` parameter in the object data is sufficient.
|
[
"Create",
"an",
"object",
"of",
"a",
"given",
"type",
"in",
"the",
"given",
"relation"
] |
2542b8d4139464d39a9a8ce8a954dfecf700c41b
|
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/application/controller/RESTController.php#L267-L304
|
26,788
|
iherwig/wcmf
|
src/wcmf/application/controller/RESTController.php
|
RESTController.update
|
public function update() {
$this->requireTransaction();
$request = $this->getRequest();
$oidStr = $this->getFirstRequestOid();
$isOrderRequest = $request->hasValue('referenceOid');
if ($isOrderRequest) {
// change order in all objects of the same type
$request->setValue('insertOid', $this->getFirstRequestOid());
// delegate to SortController
$subResponse = $this->executeSubAction('moveBefore');
// add sorted object to subresponse similar to default update action
if (!$subResponse->hasErrors()) {
$oid = ObjectId::parse($oidStr);
$persistenceFacade = $this->getPersistenceFacade();
$object = $persistenceFacade->load($oid);
$subResponse->setValue('oid', $oid);
$subResponse->setValue($oidStr, $object);
}
}
else {
// delegate to SaveController
$subResponse = $this->executeSubAction('update');
}
// prevent commit
if ($subResponse->hasErrors()) {
$this->endTransaction(false);
}
$this->handleSubResponse($subResponse, $oidStr);
}
|
php
|
public function update() {
$this->requireTransaction();
$request = $this->getRequest();
$oidStr = $this->getFirstRequestOid();
$isOrderRequest = $request->hasValue('referenceOid');
if ($isOrderRequest) {
// change order in all objects of the same type
$request->setValue('insertOid', $this->getFirstRequestOid());
// delegate to SortController
$subResponse = $this->executeSubAction('moveBefore');
// add sorted object to subresponse similar to default update action
if (!$subResponse->hasErrors()) {
$oid = ObjectId::parse($oidStr);
$persistenceFacade = $this->getPersistenceFacade();
$object = $persistenceFacade->load($oid);
$subResponse->setValue('oid', $oid);
$subResponse->setValue($oidStr, $object);
}
}
else {
// delegate to SaveController
$subResponse = $this->executeSubAction('update');
}
// prevent commit
if ($subResponse->hasErrors()) {
$this->endTransaction(false);
}
$this->handleSubResponse($subResponse, $oidStr);
}
|
[
"public",
"function",
"update",
"(",
")",
"{",
"$",
"this",
"->",
"requireTransaction",
"(",
")",
";",
"$",
"request",
"=",
"$",
"this",
"->",
"getRequest",
"(",
")",
";",
"$",
"oidStr",
"=",
"$",
"this",
"->",
"getFirstRequestOid",
"(",
")",
";",
"$",
"isOrderRequest",
"=",
"$",
"request",
"->",
"hasValue",
"(",
"'referenceOid'",
")",
";",
"if",
"(",
"$",
"isOrderRequest",
")",
"{",
"// change order in all objects of the same type",
"$",
"request",
"->",
"setValue",
"(",
"'insertOid'",
",",
"$",
"this",
"->",
"getFirstRequestOid",
"(",
")",
")",
";",
"// delegate to SortController",
"$",
"subResponse",
"=",
"$",
"this",
"->",
"executeSubAction",
"(",
"'moveBefore'",
")",
";",
"// add sorted object to subresponse similar to default update action",
"if",
"(",
"!",
"$",
"subResponse",
"->",
"hasErrors",
"(",
")",
")",
"{",
"$",
"oid",
"=",
"ObjectId",
"::",
"parse",
"(",
"$",
"oidStr",
")",
";",
"$",
"persistenceFacade",
"=",
"$",
"this",
"->",
"getPersistenceFacade",
"(",
")",
";",
"$",
"object",
"=",
"$",
"persistenceFacade",
"->",
"load",
"(",
"$",
"oid",
")",
";",
"$",
"subResponse",
"->",
"setValue",
"(",
"'oid'",
",",
"$",
"oid",
")",
";",
"$",
"subResponse",
"->",
"setValue",
"(",
"$",
"oidStr",
",",
"$",
"object",
")",
";",
"}",
"}",
"else",
"{",
"// delegate to SaveController",
"$",
"subResponse",
"=",
"$",
"this",
"->",
"executeSubAction",
"(",
"'update'",
")",
";",
"}",
"// prevent commit",
"if",
"(",
"$",
"subResponse",
"->",
"hasErrors",
"(",
")",
")",
"{",
"$",
"this",
"->",
"endTransaction",
"(",
"false",
")",
";",
"}",
"$",
"this",
"->",
"handleSubResponse",
"(",
"$",
"subResponse",
",",
"$",
"oidStr",
")",
";",
"}"
] |
Update an object or change the order
| Parameter | Description
|------------------|-------------------------
| _in_ `language` | The language of the object
| _in_ `className` | Type of object to update
| _in_ `id` | Id of object to update
| _out_ | Updated object data
The object data is contained in POST content.
|
[
"Update",
"an",
"object",
"or",
"change",
"the",
"order"
] |
2542b8d4139464d39a9a8ce8a954dfecf700c41b
|
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/application/controller/RESTController.php#L318-L350
|
26,789
|
iherwig/wcmf
|
src/wcmf/application/controller/RESTController.php
|
RESTController.updateInRelation
|
public function updateInRelation() {
$this->requireTransaction();
$request = $this->getRequest();
$isOrderRequest = $request->hasValue('referenceOid');
$request->setValue('role', $request->getValue('relation'));
if ($isOrderRequest) {
// change order in a relation
$request->setValue('containerOid', $request->getValue('sourceOid'));
$request->setValue('insertOid', $request->getValue('targetOid'));
// delegate to SortController
$subResponse = $this->executeSubAction('insertBefore');
}
else {
// update existing object
// delegate to SaveController
// NOTE: we need to update first, otherwise the update action might override
// the foreign keys changes from the associate action
$subResponse = $this->executeSubAction('update');
if (!$subResponse->hasErrors()) {
// and add object to relation
// delegate to AssociateController
$subResponse = $this->executeSubAction('associate');
}
}
// add related object to subresponse similar to default update action
if (!$subResponse->hasErrors()) {
$targetOidStr = $request->getValue('targetOid');
$targetOid = ObjectId::parse($targetOidStr);
$persistenceFacade = $this->getPersistenceFacade();
$targetObj = $persistenceFacade->load($targetOid);
$subResponse->setValue('oid', $targetOid);
$subResponse->setValue($targetOidStr, $targetObj);
}
// prevent commit
if ($subResponse->hasErrors()) {
$this->endTransaction(false);
}
$this->handleSubResponse($subResponse, $targetOidStr);
}
|
php
|
public function updateInRelation() {
$this->requireTransaction();
$request = $this->getRequest();
$isOrderRequest = $request->hasValue('referenceOid');
$request->setValue('role', $request->getValue('relation'));
if ($isOrderRequest) {
// change order in a relation
$request->setValue('containerOid', $request->getValue('sourceOid'));
$request->setValue('insertOid', $request->getValue('targetOid'));
// delegate to SortController
$subResponse = $this->executeSubAction('insertBefore');
}
else {
// update existing object
// delegate to SaveController
// NOTE: we need to update first, otherwise the update action might override
// the foreign keys changes from the associate action
$subResponse = $this->executeSubAction('update');
if (!$subResponse->hasErrors()) {
// and add object to relation
// delegate to AssociateController
$subResponse = $this->executeSubAction('associate');
}
}
// add related object to subresponse similar to default update action
if (!$subResponse->hasErrors()) {
$targetOidStr = $request->getValue('targetOid');
$targetOid = ObjectId::parse($targetOidStr);
$persistenceFacade = $this->getPersistenceFacade();
$targetObj = $persistenceFacade->load($targetOid);
$subResponse->setValue('oid', $targetOid);
$subResponse->setValue($targetOidStr, $targetObj);
}
// prevent commit
if ($subResponse->hasErrors()) {
$this->endTransaction(false);
}
$this->handleSubResponse($subResponse, $targetOidStr);
}
|
[
"public",
"function",
"updateInRelation",
"(",
")",
"{",
"$",
"this",
"->",
"requireTransaction",
"(",
")",
";",
"$",
"request",
"=",
"$",
"this",
"->",
"getRequest",
"(",
")",
";",
"$",
"isOrderRequest",
"=",
"$",
"request",
"->",
"hasValue",
"(",
"'referenceOid'",
")",
";",
"$",
"request",
"->",
"setValue",
"(",
"'role'",
",",
"$",
"request",
"->",
"getValue",
"(",
"'relation'",
")",
")",
";",
"if",
"(",
"$",
"isOrderRequest",
")",
"{",
"// change order in a relation",
"$",
"request",
"->",
"setValue",
"(",
"'containerOid'",
",",
"$",
"request",
"->",
"getValue",
"(",
"'sourceOid'",
")",
")",
";",
"$",
"request",
"->",
"setValue",
"(",
"'insertOid'",
",",
"$",
"request",
"->",
"getValue",
"(",
"'targetOid'",
")",
")",
";",
"// delegate to SortController",
"$",
"subResponse",
"=",
"$",
"this",
"->",
"executeSubAction",
"(",
"'insertBefore'",
")",
";",
"}",
"else",
"{",
"// update existing object",
"// delegate to SaveController",
"// NOTE: we need to update first, otherwise the update action might override",
"// the foreign keys changes from the associate action",
"$",
"subResponse",
"=",
"$",
"this",
"->",
"executeSubAction",
"(",
"'update'",
")",
";",
"if",
"(",
"!",
"$",
"subResponse",
"->",
"hasErrors",
"(",
")",
")",
"{",
"// and add object to relation",
"// delegate to AssociateController",
"$",
"subResponse",
"=",
"$",
"this",
"->",
"executeSubAction",
"(",
"'associate'",
")",
";",
"}",
"}",
"// add related object to subresponse similar to default update action",
"if",
"(",
"!",
"$",
"subResponse",
"->",
"hasErrors",
"(",
")",
")",
"{",
"$",
"targetOidStr",
"=",
"$",
"request",
"->",
"getValue",
"(",
"'targetOid'",
")",
";",
"$",
"targetOid",
"=",
"ObjectId",
"::",
"parse",
"(",
"$",
"targetOidStr",
")",
";",
"$",
"persistenceFacade",
"=",
"$",
"this",
"->",
"getPersistenceFacade",
"(",
")",
";",
"$",
"targetObj",
"=",
"$",
"persistenceFacade",
"->",
"load",
"(",
"$",
"targetOid",
")",
";",
"$",
"subResponse",
"->",
"setValue",
"(",
"'oid'",
",",
"$",
"targetOid",
")",
";",
"$",
"subResponse",
"->",
"setValue",
"(",
"$",
"targetOidStr",
",",
"$",
"targetObj",
")",
";",
"}",
"// prevent commit",
"if",
"(",
"$",
"subResponse",
"->",
"hasErrors",
"(",
")",
")",
"{",
"$",
"this",
"->",
"endTransaction",
"(",
"false",
")",
";",
"}",
"$",
"this",
"->",
"handleSubResponse",
"(",
"$",
"subResponse",
",",
"$",
"targetOidStr",
")",
";",
"}"
] |
Update an object in a relation or change the order
| Parameter | Description
|------------------|-------------------------
| _in_ `language` | The language of the object
| _in_ `className` | Type of object to update
| _in_ `id` | Id of object to update
| _in_ `relation` | Relation name if an existing object should be added to a relation (determines the type of the added object)
| _in_ `sourceId` | Id of the object to which the added object is related (determines the object id together with _className_)
| _in_ `targetId` | Id of the object to be added to the relation (determines the object id together with _relation_)
| _out_ | Updated object data
The object data is contained in POST content.
|
[
"Update",
"an",
"object",
"in",
"a",
"relation",
"or",
"change",
"the",
"order"
] |
2542b8d4139464d39a9a8ce8a954dfecf700c41b
|
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/application/controller/RESTController.php#L367-L409
|
26,790
|
iherwig/wcmf
|
src/wcmf/application/controller/RESTController.php
|
RESTController.deleteInRelation
|
public function deleteInRelation() {
$this->requireTransaction();
$request = $this->getRequest();
// remove existing object from relation
$request->setValue('role', $request->getValue('relation'));
// delegate to AssociateController
$subResponse = $this->executeSubAction('disassociate');
// prevent commit
if ($subResponse->hasErrors()) {
$this->endTransaction(false);
}
$this->handleSubResponse($subResponse);
}
|
php
|
public function deleteInRelation() {
$this->requireTransaction();
$request = $this->getRequest();
// remove existing object from relation
$request->setValue('role', $request->getValue('relation'));
// delegate to AssociateController
$subResponse = $this->executeSubAction('disassociate');
// prevent commit
if ($subResponse->hasErrors()) {
$this->endTransaction(false);
}
$this->handleSubResponse($subResponse);
}
|
[
"public",
"function",
"deleteInRelation",
"(",
")",
"{",
"$",
"this",
"->",
"requireTransaction",
"(",
")",
";",
"$",
"request",
"=",
"$",
"this",
"->",
"getRequest",
"(",
")",
";",
"// remove existing object from relation",
"$",
"request",
"->",
"setValue",
"(",
"'role'",
",",
"$",
"request",
"->",
"getValue",
"(",
"'relation'",
")",
")",
";",
"// delegate to AssociateController",
"$",
"subResponse",
"=",
"$",
"this",
"->",
"executeSubAction",
"(",
"'disassociate'",
")",
";",
"// prevent commit",
"if",
"(",
"$",
"subResponse",
"->",
"hasErrors",
"(",
")",
")",
"{",
"$",
"this",
"->",
"endTransaction",
"(",
"false",
")",
";",
"}",
"$",
"this",
"->",
"handleSubResponse",
"(",
"$",
"subResponse",
")",
";",
"}"
] |
Remove an object from a relation
| Parameter | Description
|------------------|-------------------------
| _in_ `language` | The language of the object
| _in_ `className` | Type of object to delete
| _in_ `id` | Id of object to delete
| _in_ `relation` | Name of the relation to the object defined by _sourceId_ (determines the type of the deleted object)
| _in_ `sourceId` | Id of the object to which the deleted object is related (determines the object id together with _className_)
| _in_ `targetId` | Id of the object to be deleted from the relation (determines the object id together with _relation_)
|
[
"Remove",
"an",
"object",
"from",
"a",
"relation"
] |
2542b8d4139464d39a9a8ce8a954dfecf700c41b
|
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/application/controller/RESTController.php#L444-L459
|
26,791
|
iherwig/wcmf
|
src/wcmf/application/controller/RESTController.php
|
RESTController.handleSubResponse
|
protected function handleSubResponse(Response $subResponse, $oidStr=null) {
$response = $this->getResponse();
if (!$subResponse->hasErrors()) {
$response->clearValues();
$response->setHeaders($subResponse->getHeaders());
$response->setStatus($subResponse->getStatus());
if ($subResponse->hasValue('object')) {
$object = $subResponse->getValue('object');
if ($object != null) {
$response->setValue($object->getOID()->__toString(), $object);
}
}
if ($subResponse->hasValue('list')) {
$objects = $subResponse->getValue('list');
$response->setValues($objects);
}
if ($oidStr != null && $subResponse->hasValue($oidStr)) {
$object = $subResponse->getValue($oidStr);
$response->setValue($oidStr, $object);
if ($subResponse->getStatus() == 201) {
$this->setLocationHeaderFromOid($oidStr);
}
}
return true;
}
// in case of error, return default response
$response->setErrors($subResponse->getErrors());
$response->setStatus(400);
return false;
}
|
php
|
protected function handleSubResponse(Response $subResponse, $oidStr=null) {
$response = $this->getResponse();
if (!$subResponse->hasErrors()) {
$response->clearValues();
$response->setHeaders($subResponse->getHeaders());
$response->setStatus($subResponse->getStatus());
if ($subResponse->hasValue('object')) {
$object = $subResponse->getValue('object');
if ($object != null) {
$response->setValue($object->getOID()->__toString(), $object);
}
}
if ($subResponse->hasValue('list')) {
$objects = $subResponse->getValue('list');
$response->setValues($objects);
}
if ($oidStr != null && $subResponse->hasValue($oidStr)) {
$object = $subResponse->getValue($oidStr);
$response->setValue($oidStr, $object);
if ($subResponse->getStatus() == 201) {
$this->setLocationHeaderFromOid($oidStr);
}
}
return true;
}
// in case of error, return default response
$response->setErrors($subResponse->getErrors());
$response->setStatus(400);
return false;
}
|
[
"protected",
"function",
"handleSubResponse",
"(",
"Response",
"$",
"subResponse",
",",
"$",
"oidStr",
"=",
"null",
")",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"getResponse",
"(",
")",
";",
"if",
"(",
"!",
"$",
"subResponse",
"->",
"hasErrors",
"(",
")",
")",
"{",
"$",
"response",
"->",
"clearValues",
"(",
")",
";",
"$",
"response",
"->",
"setHeaders",
"(",
"$",
"subResponse",
"->",
"getHeaders",
"(",
")",
")",
";",
"$",
"response",
"->",
"setStatus",
"(",
"$",
"subResponse",
"->",
"getStatus",
"(",
")",
")",
";",
"if",
"(",
"$",
"subResponse",
"->",
"hasValue",
"(",
"'object'",
")",
")",
"{",
"$",
"object",
"=",
"$",
"subResponse",
"->",
"getValue",
"(",
"'object'",
")",
";",
"if",
"(",
"$",
"object",
"!=",
"null",
")",
"{",
"$",
"response",
"->",
"setValue",
"(",
"$",
"object",
"->",
"getOID",
"(",
")",
"->",
"__toString",
"(",
")",
",",
"$",
"object",
")",
";",
"}",
"}",
"if",
"(",
"$",
"subResponse",
"->",
"hasValue",
"(",
"'list'",
")",
")",
"{",
"$",
"objects",
"=",
"$",
"subResponse",
"->",
"getValue",
"(",
"'list'",
")",
";",
"$",
"response",
"->",
"setValues",
"(",
"$",
"objects",
")",
";",
"}",
"if",
"(",
"$",
"oidStr",
"!=",
"null",
"&&",
"$",
"subResponse",
"->",
"hasValue",
"(",
"$",
"oidStr",
")",
")",
"{",
"$",
"object",
"=",
"$",
"subResponse",
"->",
"getValue",
"(",
"$",
"oidStr",
")",
";",
"$",
"response",
"->",
"setValue",
"(",
"$",
"oidStr",
",",
"$",
"object",
")",
";",
"if",
"(",
"$",
"subResponse",
"->",
"getStatus",
"(",
")",
"==",
"201",
")",
"{",
"$",
"this",
"->",
"setLocationHeaderFromOid",
"(",
"$",
"oidStr",
")",
";",
"}",
"}",
"return",
"true",
";",
"}",
"// in case of error, return default response",
"$",
"response",
"->",
"setErrors",
"(",
"$",
"subResponse",
"->",
"getErrors",
"(",
")",
")",
";",
"$",
"response",
"->",
"setStatus",
"(",
"400",
")",
";",
"return",
"false",
";",
"}"
] |
Create the actual response from the response resulting from delegating to
another controller
@param $subResponse The response returned from the other controller
@param $oidStr Serialized object id of the object to return (optional)
@return Boolean whether an error occured or not
|
[
"Create",
"the",
"actual",
"response",
"from",
"the",
"response",
"resulting",
"from",
"delegating",
"to",
"another",
"controller"
] |
2542b8d4139464d39a9a8ce8a954dfecf700c41b
|
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/application/controller/RESTController.php#L468-L498
|
26,792
|
iherwig/wcmf
|
src/wcmf/application/controller/RESTController.php
|
RESTController.setLocationHeaderFromOid
|
protected function setLocationHeaderFromOid($oidStr) {
$oid = ObjectId::parse($oidStr);
if ($oid) {
$response = $this->getResponse();
$response->setHeader('Location', $oidStr);
}
}
|
php
|
protected function setLocationHeaderFromOid($oidStr) {
$oid = ObjectId::parse($oidStr);
if ($oid) {
$response = $this->getResponse();
$response->setHeader('Location', $oidStr);
}
}
|
[
"protected",
"function",
"setLocationHeaderFromOid",
"(",
"$",
"oidStr",
")",
"{",
"$",
"oid",
"=",
"ObjectId",
"::",
"parse",
"(",
"$",
"oidStr",
")",
";",
"if",
"(",
"$",
"oid",
")",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"getResponse",
"(",
")",
";",
"$",
"response",
"->",
"setHeader",
"(",
"'Location'",
",",
"$",
"oidStr",
")",
";",
"}",
"}"
] |
Set the location response header according to the given object id
@param $oidStr The serialized object id
|
[
"Set",
"the",
"location",
"response",
"header",
"according",
"to",
"the",
"given",
"object",
"id"
] |
2542b8d4139464d39a9a8ce8a954dfecf700c41b
|
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/application/controller/RESTController.php#L528-L534
|
26,793
|
iherwig/wcmf
|
src/wcmf/application/controller/RESTController.php
|
RESTController.getFirstRequestOid
|
protected function getFirstRequestOid() {
$request = $this->getRequest();
foreach ($request->getValues() as $key => $value) {
if (ObjectId::isValid($key)) {
return $key;
}
}
return '';
}
|
php
|
protected function getFirstRequestOid() {
$request = $this->getRequest();
foreach ($request->getValues() as $key => $value) {
if (ObjectId::isValid($key)) {
return $key;
}
}
return '';
}
|
[
"protected",
"function",
"getFirstRequestOid",
"(",
")",
"{",
"$",
"request",
"=",
"$",
"this",
"->",
"getRequest",
"(",
")",
";",
"foreach",
"(",
"$",
"request",
"->",
"getValues",
"(",
")",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"ObjectId",
"::",
"isValid",
"(",
"$",
"key",
")",
")",
"{",
"return",
"$",
"key",
";",
"}",
"}",
"return",
"''",
";",
"}"
] |
Get the first oid from the request
@return String
|
[
"Get",
"the",
"first",
"oid",
"from",
"the",
"request"
] |
2542b8d4139464d39a9a8ce8a954dfecf700c41b
|
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/application/controller/RESTController.php#L540-L548
|
26,794
|
iherwig/wcmf
|
src/wcmf/application/controller/RESTController.php
|
RESTController.getRelatedType
|
protected function getRelatedType(ObjectId $sourceOid, $role) {
$persistenceFacade = $this->getPersistenceFacade();
$sourceMapper = $persistenceFacade->getMapper($sourceOid->getType());
$relation = $sourceMapper->getRelation($role);
return $relation->getOtherType();
}
|
php
|
protected function getRelatedType(ObjectId $sourceOid, $role) {
$persistenceFacade = $this->getPersistenceFacade();
$sourceMapper = $persistenceFacade->getMapper($sourceOid->getType());
$relation = $sourceMapper->getRelation($role);
return $relation->getOtherType();
}
|
[
"protected",
"function",
"getRelatedType",
"(",
"ObjectId",
"$",
"sourceOid",
",",
"$",
"role",
")",
"{",
"$",
"persistenceFacade",
"=",
"$",
"this",
"->",
"getPersistenceFacade",
"(",
")",
";",
"$",
"sourceMapper",
"=",
"$",
"persistenceFacade",
"->",
"getMapper",
"(",
"$",
"sourceOid",
"->",
"getType",
"(",
")",
")",
";",
"$",
"relation",
"=",
"$",
"sourceMapper",
"->",
"getRelation",
"(",
"$",
"role",
")",
";",
"return",
"$",
"relation",
"->",
"getOtherType",
"(",
")",
";",
"}"
] |
Get the type that is used in the given role related to the
given source object.
@param $sourceOid ObjectId of the source object
@param $role The role name
@return String
|
[
"Get",
"the",
"type",
"that",
"is",
"used",
"in",
"the",
"given",
"role",
"related",
"to",
"the",
"given",
"source",
"object",
"."
] |
2542b8d4139464d39a9a8ce8a954dfecf700c41b
|
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/application/controller/RESTController.php#L557-L562
|
26,795
|
heyday/silverstripe-versioneddataobjects
|
code/VersionedReadingMode.php
|
VersionedReadingMode.restoreOriginalReadingMode
|
public static function restoreOriginalReadingMode()
{
if (
isset(self::$originalReadingMode) &&
in_array(self::$originalReadingMode, array('Stage', 'Live'))
) {
Versioned::reading_stage(self::$originalReadingMode);
}
}
|
php
|
public static function restoreOriginalReadingMode()
{
if (
isset(self::$originalReadingMode) &&
in_array(self::$originalReadingMode, array('Stage', 'Live'))
) {
Versioned::reading_stage(self::$originalReadingMode);
}
}
|
[
"public",
"static",
"function",
"restoreOriginalReadingMode",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"self",
"::",
"$",
"originalReadingMode",
")",
"&&",
"in_array",
"(",
"self",
"::",
"$",
"originalReadingMode",
",",
"array",
"(",
"'Stage'",
",",
"'Live'",
")",
")",
")",
"{",
"Versioned",
"::",
"reading_stage",
"(",
"self",
"::",
"$",
"originalReadingMode",
")",
";",
"}",
"}"
] |
Restore the reading mode to what's been set originally in the CMS
|
[
"Restore",
"the",
"reading",
"mode",
"to",
"what",
"s",
"been",
"set",
"originally",
"in",
"the",
"CMS"
] |
30a07d976abd17baba9d9194ca176c82d72323ac
|
https://github.com/heyday/silverstripe-versioneddataobjects/blob/30a07d976abd17baba9d9194ca176c82d72323ac/code/VersionedReadingMode.php#L39-L47
|
26,796
|
iherwig/wcmf
|
src/wcmf/lib/model/output/DotOutputStrategy.php
|
DotOutputStrategy.isWritten
|
private function isWritten($node) {
$oidStr = $node->getOID()->__toString();
return (isset($this->writtenNodes[$oidStr]));
}
|
php
|
private function isWritten($node) {
$oidStr = $node->getOID()->__toString();
return (isset($this->writtenNodes[$oidStr]));
}
|
[
"private",
"function",
"isWritten",
"(",
"$",
"node",
")",
"{",
"$",
"oidStr",
"=",
"$",
"node",
"->",
"getOID",
"(",
")",
"->",
"__toString",
"(",
")",
";",
"return",
"(",
"isset",
"(",
"$",
"this",
"->",
"writtenNodes",
"[",
"$",
"oidStr",
"]",
")",
")",
";",
"}"
] |
Check if a node is written.
@param $node The node to check
@return Boolean
|
[
"Check",
"if",
"a",
"node",
"is",
"written",
"."
] |
2542b8d4139464d39a9a8ce8a954dfecf700c41b
|
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/lib/model/output/DotOutputStrategy.php#L130-L133
|
26,797
|
iherwig/wcmf
|
src/wcmf/lib/model/output/DotOutputStrategy.php
|
DotOutputStrategy.getIndex
|
private function getIndex($node) {
$oidStr = $node->getOID()->__toString();
if (!isset($this->nodeIndexMap[$oidStr])) {
$this->nodeIndexMap[$oidStr] = $this->getNextIndex();
}
return $this->nodeIndexMap[$oidStr];
}
|
php
|
private function getIndex($node) {
$oidStr = $node->getOID()->__toString();
if (!isset($this->nodeIndexMap[$oidStr])) {
$this->nodeIndexMap[$oidStr] = $this->getNextIndex();
}
return $this->nodeIndexMap[$oidStr];
}
|
[
"private",
"function",
"getIndex",
"(",
"$",
"node",
")",
"{",
"$",
"oidStr",
"=",
"$",
"node",
"->",
"getOID",
"(",
")",
"->",
"__toString",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"nodeIndexMap",
"[",
"$",
"oidStr",
"]",
")",
")",
"{",
"$",
"this",
"->",
"nodeIndexMap",
"[",
"$",
"oidStr",
"]",
"=",
"$",
"this",
"->",
"getNextIndex",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"nodeIndexMap",
"[",
"$",
"oidStr",
"]",
";",
"}"
] |
Get the node index.
@param $node The node to get the index of
@return Number
|
[
"Get",
"the",
"node",
"index",
"."
] |
2542b8d4139464d39a9a8ce8a954dfecf700c41b
|
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/lib/model/output/DotOutputStrategy.php#L140-L146
|
26,798
|
iherwig/wcmf
|
src/wcmf/lib/model/NodeSortkeyComparator.php
|
NodeSortkeyComparator.compare
|
public function compare(Node $a, Node $b) {
$valA = $this->getSortkeyValue($a);
$valB = $this->getSortkeyValue($b);
if ($valA == $valB) { return 0; }
return ($valA > $valB) ? 1 : -1;
}
|
php
|
public function compare(Node $a, Node $b) {
$valA = $this->getSortkeyValue($a);
$valB = $this->getSortkeyValue($b);
if ($valA == $valB) { return 0; }
return ($valA > $valB) ? 1 : -1;
}
|
[
"public",
"function",
"compare",
"(",
"Node",
"$",
"a",
",",
"Node",
"$",
"b",
")",
"{",
"$",
"valA",
"=",
"$",
"this",
"->",
"getSortkeyValue",
"(",
"$",
"a",
")",
";",
"$",
"valB",
"=",
"$",
"this",
"->",
"getSortkeyValue",
"(",
"$",
"b",
")",
";",
"if",
"(",
"$",
"valA",
"==",
"$",
"valB",
")",
"{",
"return",
"0",
";",
"}",
"return",
"(",
"$",
"valA",
">",
"$",
"valB",
")",
"?",
"1",
":",
"-",
"1",
";",
"}"
] |
Compare function for sorting Nodes in the given relation
@param $a First Node instance
@param $b First Node instance
@return -1, 0 or 1 whether a is less, equal or greater than b
in respect of the criteria
|
[
"Compare",
"function",
"for",
"sorting",
"Nodes",
"in",
"the",
"given",
"relation"
] |
2542b8d4139464d39a9a8ce8a954dfecf700c41b
|
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/lib/model/NodeSortkeyComparator.php#L63-L68
|
26,799
|
iherwig/wcmf
|
src/wcmf/lib/model/NodeSortkeyComparator.php
|
NodeSortkeyComparator.getSortkeyValue
|
protected function getSortkeyValue(Node $node) {
// if no role is defined for a or b, the sortkey is
// determined from the type of the reference node
$defaultRole = $this->referenceNode->getType();
$referenceMapper = $this->referenceNode->getMapper();
$mapper = $node->getMapper();
if ($referenceMapper && $mapper) {
$referenceRole = $defaultRole;
// get the sortkey of the node for the relation to the reference node,
// if a role is defined
$oidStr = $node->getOID()->__toString();
if (isset($this->oidRoleMap[$oidStr])) {
$nodeRole = $this->oidRoleMap[$oidStr];
$relationDesc = $referenceMapper->getRelation($nodeRole);
$referenceRole = $relationDesc->getThisRole();
}
$sortkeyDef = $mapper->getSortkey($referenceRole);
return $node->getValue($sortkeyDef['sortFieldName']);
}
return 0;
}
|
php
|
protected function getSortkeyValue(Node $node) {
// if no role is defined for a or b, the sortkey is
// determined from the type of the reference node
$defaultRole = $this->referenceNode->getType();
$referenceMapper = $this->referenceNode->getMapper();
$mapper = $node->getMapper();
if ($referenceMapper && $mapper) {
$referenceRole = $defaultRole;
// get the sortkey of the node for the relation to the reference node,
// if a role is defined
$oidStr = $node->getOID()->__toString();
if (isset($this->oidRoleMap[$oidStr])) {
$nodeRole = $this->oidRoleMap[$oidStr];
$relationDesc = $referenceMapper->getRelation($nodeRole);
$referenceRole = $relationDesc->getThisRole();
}
$sortkeyDef = $mapper->getSortkey($referenceRole);
return $node->getValue($sortkeyDef['sortFieldName']);
}
return 0;
}
|
[
"protected",
"function",
"getSortkeyValue",
"(",
"Node",
"$",
"node",
")",
"{",
"// if no role is defined for a or b, the sortkey is",
"// determined from the type of the reference node",
"$",
"defaultRole",
"=",
"$",
"this",
"->",
"referenceNode",
"->",
"getType",
"(",
")",
";",
"$",
"referenceMapper",
"=",
"$",
"this",
"->",
"referenceNode",
"->",
"getMapper",
"(",
")",
";",
"$",
"mapper",
"=",
"$",
"node",
"->",
"getMapper",
"(",
")",
";",
"if",
"(",
"$",
"referenceMapper",
"&&",
"$",
"mapper",
")",
"{",
"$",
"referenceRole",
"=",
"$",
"defaultRole",
";",
"// get the sortkey of the node for the relation to the reference node,",
"// if a role is defined",
"$",
"oidStr",
"=",
"$",
"node",
"->",
"getOID",
"(",
")",
"->",
"__toString",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"oidRoleMap",
"[",
"$",
"oidStr",
"]",
")",
")",
"{",
"$",
"nodeRole",
"=",
"$",
"this",
"->",
"oidRoleMap",
"[",
"$",
"oidStr",
"]",
";",
"$",
"relationDesc",
"=",
"$",
"referenceMapper",
"->",
"getRelation",
"(",
"$",
"nodeRole",
")",
";",
"$",
"referenceRole",
"=",
"$",
"relationDesc",
"->",
"getThisRole",
"(",
")",
";",
"}",
"$",
"sortkeyDef",
"=",
"$",
"mapper",
"->",
"getSortkey",
"(",
"$",
"referenceRole",
")",
";",
"return",
"$",
"node",
"->",
"getValue",
"(",
"$",
"sortkeyDef",
"[",
"'sortFieldName'",
"]",
")",
";",
"}",
"return",
"0",
";",
"}"
] |
Get the sortkey value of a node in the given relation
@param $node Node
@return Number
|
[
"Get",
"the",
"sortkey",
"value",
"of",
"a",
"node",
"in",
"the",
"given",
"relation"
] |
2542b8d4139464d39a9a8ce8a954dfecf700c41b
|
https://github.com/iherwig/wcmf/blob/2542b8d4139464d39a9a8ce8a954dfecf700c41b/src/wcmf/lib/model/NodeSortkeyComparator.php#L75-L97
|
Subsets and Splits
Yii Code Samples
Gathers all records from test, train, and validation sets that contain the word 'yii', providing a basic filtered view of the dataset relevant to Yii-related content.