repo
stringlengths 6
63
| path
stringlengths 5
140
| func_name
stringlengths 3
151
| original_string
stringlengths 84
13k
| language
stringclasses 1
value | code
stringlengths 84
13k
| code_tokens
list | docstring
stringlengths 3
47.2k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 91
247
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
rinvex/authy | src/Response.php | Response.isSuccess | protected function isSuccess($result): bool
{
return ! is_null($result) ? (is_string($result) && $result === 'true') || (is_bool($result) && $result) : false;
} | php | protected function isSuccess($result): bool
{
return ! is_null($result) ? (is_string($result) && $result === 'true') || (is_bool($result) && $result) : false;
} | [
"protected",
"function",
"isSuccess",
"(",
"$",
"result",
")",
":",
"bool",
"{",
"return",
"!",
"is_null",
"(",
"$",
"result",
")",
"?",
"(",
"is_string",
"(",
"$",
"result",
")",
"&&",
"$",
"result",
"===",
"'true'",
")",
"||",
"(",
"is_bool",
"(",
"$",
"result",
")",
"&&",
"$",
"result",
")",
":",
"false",
";",
"}"
]
| Determine if the given result is success.
@param mixed $result
@return bool | [
"Determine",
"if",
"the",
"given",
"result",
"is",
"success",
"."
]
| 36c748e018843fefa8cf588950573199c11c0c10 | https://github.com/rinvex/authy/blob/36c748e018843fefa8cf588950573199c11c0c10/src/Response.php#L107-L110 | train |
rinvex/authy | src/Token.php | Token.send | public function send($authyId, $method = 'sms', $force = false, $action = null, $actionMessage = null): Response
{
// Prepare required variables
$url = $this->api.$method."/{$authyId}";
$params = $this->params + ['query' => ['force' => $force ? 'true' : 'false', 'action' => $action, 'actionMessage' => $actionMessage]];
// Send Authy token, and return response
return new Response($this->http->get($url, $params));
} | php | public function send($authyId, $method = 'sms', $force = false, $action = null, $actionMessage = null): Response
{
// Prepare required variables
$url = $this->api.$method."/{$authyId}";
$params = $this->params + ['query' => ['force' => $force ? 'true' : 'false', 'action' => $action, 'actionMessage' => $actionMessage]];
// Send Authy token, and return response
return new Response($this->http->get($url, $params));
} | [
"public",
"function",
"send",
"(",
"$",
"authyId",
",",
"$",
"method",
"=",
"'sms'",
",",
"$",
"force",
"=",
"false",
",",
"$",
"action",
"=",
"null",
",",
"$",
"actionMessage",
"=",
"null",
")",
":",
"Response",
"{",
"// Prepare required variables",
"$",
"url",
"=",
"$",
"this",
"->",
"api",
".",
"$",
"method",
".",
"\"/{$authyId}\"",
";",
"$",
"params",
"=",
"$",
"this",
"->",
"params",
"+",
"[",
"'query'",
"=>",
"[",
"'force'",
"=>",
"$",
"force",
"?",
"'true'",
":",
"'false'",
",",
"'action'",
"=>",
"$",
"action",
",",
"'actionMessage'",
"=>",
"$",
"actionMessage",
"]",
"]",
";",
"// Send Authy token, and return response",
"return",
"new",
"Response",
"(",
"$",
"this",
"->",
"http",
"->",
"get",
"(",
"$",
"url",
",",
"$",
"params",
")",
")",
";",
"}"
]
| Send verification token to the given Authy user.
@param int $authyId
@param string $method
@param bool $force
@param string|null $action
@param string|null $actionMessage
@return \Rinvex\Authy\Response | [
"Send",
"verification",
"token",
"to",
"the",
"given",
"Authy",
"user",
"."
]
| 36c748e018843fefa8cf588950573199c11c0c10 | https://github.com/rinvex/authy/blob/36c748e018843fefa8cf588950573199c11c0c10/src/Token.php#L20-L28 | train |
rinvex/authy | src/Token.php | Token.verify | public function verify($token, $authyId, $force = false, $action = null): Response
{
// Prepare required variables
$url = $this->api."verify/{$token}/{$authyId}";
$params = $this->params + ['query' => ['force' => $force ? 'true' : 'false', 'action' => $action]];
// Verify Authy token
return new Response($this->http->get($url, $params));
} | php | public function verify($token, $authyId, $force = false, $action = null): Response
{
// Prepare required variables
$url = $this->api."verify/{$token}/{$authyId}";
$params = $this->params + ['query' => ['force' => $force ? 'true' : 'false', 'action' => $action]];
// Verify Authy token
return new Response($this->http->get($url, $params));
} | [
"public",
"function",
"verify",
"(",
"$",
"token",
",",
"$",
"authyId",
",",
"$",
"force",
"=",
"false",
",",
"$",
"action",
"=",
"null",
")",
":",
"Response",
"{",
"// Prepare required variables",
"$",
"url",
"=",
"$",
"this",
"->",
"api",
".",
"\"verify/{$token}/{$authyId}\"",
";",
"$",
"params",
"=",
"$",
"this",
"->",
"params",
"+",
"[",
"'query'",
"=>",
"[",
"'force'",
"=>",
"$",
"force",
"?",
"'true'",
":",
"'false'",
",",
"'action'",
"=>",
"$",
"action",
"]",
"]",
";",
"// Verify Authy token",
"return",
"new",
"Response",
"(",
"$",
"this",
"->",
"http",
"->",
"get",
"(",
"$",
"url",
",",
"$",
"params",
")",
")",
";",
"}"
]
| Verify the given token for the given Authy user.
@param int $token
@param int $authyId
@param bool $force
@param string|null $action
@return \Rinvex\Authy\Response | [
"Verify",
"the",
"given",
"token",
"for",
"the",
"given",
"Authy",
"user",
"."
]
| 36c748e018843fefa8cf588950573199c11c0c10 | https://github.com/rinvex/authy/blob/36c748e018843fefa8cf588950573199c11c0c10/src/Token.php#L40-L48 | train |
rinvex/authy | src/User.php | User.register | public function register($email, $cellphone, $countryCode, $sendInstallLink = true): Response
{
// Prepare required variables
$url = $this->api.'users/new';
$params = $this->params + [
'form_params' => [
'send_install_link_via_sms' => (bool) $sendInstallLink,
'user' => [
'email' => $email,
'cellphone' => preg_replace('/[^0-9]/', '', $cellphone),
'country_code' => $countryCode,
],
],
];
// Register Authy user, and return response
return new Response($this->http->post($url, $params));
} | php | public function register($email, $cellphone, $countryCode, $sendInstallLink = true): Response
{
// Prepare required variables
$url = $this->api.'users/new';
$params = $this->params + [
'form_params' => [
'send_install_link_via_sms' => (bool) $sendInstallLink,
'user' => [
'email' => $email,
'cellphone' => preg_replace('/[^0-9]/', '', $cellphone),
'country_code' => $countryCode,
],
],
];
// Register Authy user, and return response
return new Response($this->http->post($url, $params));
} | [
"public",
"function",
"register",
"(",
"$",
"email",
",",
"$",
"cellphone",
",",
"$",
"countryCode",
",",
"$",
"sendInstallLink",
"=",
"true",
")",
":",
"Response",
"{",
"// Prepare required variables",
"$",
"url",
"=",
"$",
"this",
"->",
"api",
".",
"'users/new'",
";",
"$",
"params",
"=",
"$",
"this",
"->",
"params",
"+",
"[",
"'form_params'",
"=>",
"[",
"'send_install_link_via_sms'",
"=>",
"(",
"bool",
")",
"$",
"sendInstallLink",
",",
"'user'",
"=>",
"[",
"'email'",
"=>",
"$",
"email",
",",
"'cellphone'",
"=>",
"preg_replace",
"(",
"'/[^0-9]/'",
",",
"''",
",",
"$",
"cellphone",
")",
",",
"'country_code'",
"=>",
"$",
"countryCode",
",",
"]",
",",
"]",
",",
"]",
";",
"// Register Authy user, and return response",
"return",
"new",
"Response",
"(",
"$",
"this",
"->",
"http",
"->",
"post",
"(",
"$",
"url",
",",
"$",
"params",
")",
")",
";",
"}"
]
| Register a new Authy user.
@param string $email
@param string $cellphone
@param string $countryCode
@param bool $sendInstallLink
@return \Rinvex\Authy\Response | [
"Register",
"a",
"new",
"Authy",
"user",
"."
]
| 36c748e018843fefa8cf588950573199c11c0c10 | https://github.com/rinvex/authy/blob/36c748e018843fefa8cf588950573199c11c0c10/src/User.php#L19-L36 | train |
rinvex/authy | src/User.php | User.registerActivity | public function registerActivity($authyId, $type, $data, $ip = null): Response
{
// Prepare required variables
$url = $this->api."users/{$authyId}/register_activity";
$params = $this->params + ['form_params' => ['type' => $type, 'data' => $data, 'user_ip' => $ip]];
// Register Authy user activity, and return response
return new Response($this->http->post($url, $params));
} | php | public function registerActivity($authyId, $type, $data, $ip = null): Response
{
// Prepare required variables
$url = $this->api."users/{$authyId}/register_activity";
$params = $this->params + ['form_params' => ['type' => $type, 'data' => $data, 'user_ip' => $ip]];
// Register Authy user activity, and return response
return new Response($this->http->post($url, $params));
} | [
"public",
"function",
"registerActivity",
"(",
"$",
"authyId",
",",
"$",
"type",
",",
"$",
"data",
",",
"$",
"ip",
"=",
"null",
")",
":",
"Response",
"{",
"// Prepare required variables",
"$",
"url",
"=",
"$",
"this",
"->",
"api",
".",
"\"users/{$authyId}/register_activity\"",
";",
"$",
"params",
"=",
"$",
"this",
"->",
"params",
"+",
"[",
"'form_params'",
"=>",
"[",
"'type'",
"=>",
"$",
"type",
",",
"'data'",
"=>",
"$",
"data",
",",
"'user_ip'",
"=>",
"$",
"ip",
"]",
"]",
";",
"// Register Authy user activity, and return response",
"return",
"new",
"Response",
"(",
"$",
"this",
"->",
"http",
"->",
"post",
"(",
"$",
"url",
",",
"$",
"params",
")",
")",
";",
"}"
]
| Register the given user activity.
@param int $authyId
@param string $type
@param string $data
@param string|null $ip
@return \Rinvex\Authy\Response | [
"Register",
"the",
"given",
"user",
"activity",
"."
]
| 36c748e018843fefa8cf588950573199c11c0c10 | https://github.com/rinvex/authy/blob/36c748e018843fefa8cf588950573199c11c0c10/src/User.php#L48-L56 | train |
rinvex/authy | src/User.php | User.status | public function status($authyId, $ip = null): Response
{
// Prepare required variables
$url = $this->api."users/{$authyId}/status";
$params = $this->params + ['query' => ['user_ip' => $ip]];
// Return Authy user status
return new Response($this->http->get($url, $params));
} | php | public function status($authyId, $ip = null): Response
{
// Prepare required variables
$url = $this->api."users/{$authyId}/status";
$params = $this->params + ['query' => ['user_ip' => $ip]];
// Return Authy user status
return new Response($this->http->get($url, $params));
} | [
"public",
"function",
"status",
"(",
"$",
"authyId",
",",
"$",
"ip",
"=",
"null",
")",
":",
"Response",
"{",
"// Prepare required variables",
"$",
"url",
"=",
"$",
"this",
"->",
"api",
".",
"\"users/{$authyId}/status\"",
";",
"$",
"params",
"=",
"$",
"this",
"->",
"params",
"+",
"[",
"'query'",
"=>",
"[",
"'user_ip'",
"=>",
"$",
"ip",
"]",
"]",
";",
"// Return Authy user status",
"return",
"new",
"Response",
"(",
"$",
"this",
"->",
"http",
"->",
"get",
"(",
"$",
"url",
",",
"$",
"params",
")",
")",
";",
"}"
]
| Get status of the given user.
@param int $authyId
@param string|null $ip
@return \Rinvex\Authy\Response | [
"Get",
"status",
"of",
"the",
"given",
"user",
"."
]
| 36c748e018843fefa8cf588950573199c11c0c10 | https://github.com/rinvex/authy/blob/36c748e018843fefa8cf588950573199c11c0c10/src/User.php#L66-L74 | train |
rinvex/authy | src/User.php | User.delete | public function delete($authyId, $ip = null): Response
{
// Prepare required variables
$url = $this->api."users/{$authyId}/delete";
$params = $this->params + ['form_params' => ['ip' => $ip]];
// Delete Authy user, and return response
return new Response($this->http->post($url, $params));
} | php | public function delete($authyId, $ip = null): Response
{
// Prepare required variables
$url = $this->api."users/{$authyId}/delete";
$params = $this->params + ['form_params' => ['ip' => $ip]];
// Delete Authy user, and return response
return new Response($this->http->post($url, $params));
} | [
"public",
"function",
"delete",
"(",
"$",
"authyId",
",",
"$",
"ip",
"=",
"null",
")",
":",
"Response",
"{",
"// Prepare required variables",
"$",
"url",
"=",
"$",
"this",
"->",
"api",
".",
"\"users/{$authyId}/delete\"",
";",
"$",
"params",
"=",
"$",
"this",
"->",
"params",
"+",
"[",
"'form_params'",
"=>",
"[",
"'ip'",
"=>",
"$",
"ip",
"]",
"]",
";",
"// Delete Authy user, and return response",
"return",
"new",
"Response",
"(",
"$",
"this",
"->",
"http",
"->",
"post",
"(",
"$",
"url",
",",
"$",
"params",
")",
")",
";",
"}"
]
| Delete the given Authy user.
@param int $authyId
@param string|null $ip
@return \Rinvex\Authy\Response | [
"Delete",
"the",
"given",
"Authy",
"user",
"."
]
| 36c748e018843fefa8cf588950573199c11c0c10 | https://github.com/rinvex/authy/blob/36c748e018843fefa8cf588950573199c11c0c10/src/User.php#L84-L92 | train |
silverstripe/silverstripe-documentconverter | src/ServiceConnector.php | ServiceConnector.getDetail | protected function getDetail($detail)
{
$fromDetails = $this->docvertDetails[$detail];
if ($fromDetails) {
return $fromDetails;
}
$fromConfig = $this->config()->get($detail);
if ($fromConfig) {
return $fromConfig;
}
$fromEnv = Environment::getEnv('DOCVERT_' . strtoupper($detail));
if ($fromEnv) {
return $fromEnv;
}
} | php | protected function getDetail($detail)
{
$fromDetails = $this->docvertDetails[$detail];
if ($fromDetails) {
return $fromDetails;
}
$fromConfig = $this->config()->get($detail);
if ($fromConfig) {
return $fromConfig;
}
$fromEnv = Environment::getEnv('DOCVERT_' . strtoupper($detail));
if ($fromEnv) {
return $fromEnv;
}
} | [
"protected",
"function",
"getDetail",
"(",
"$",
"detail",
")",
"{",
"$",
"fromDetails",
"=",
"$",
"this",
"->",
"docvertDetails",
"[",
"$",
"detail",
"]",
";",
"if",
"(",
"$",
"fromDetails",
")",
"{",
"return",
"$",
"fromDetails",
";",
"}",
"$",
"fromConfig",
"=",
"$",
"this",
"->",
"config",
"(",
")",
"->",
"get",
"(",
"$",
"detail",
")",
";",
"if",
"(",
"$",
"fromConfig",
")",
"{",
"return",
"$",
"fromConfig",
";",
"}",
"$",
"fromEnv",
"=",
"Environment",
"::",
"getEnv",
"(",
"'DOCVERT_'",
".",
"strtoupper",
"(",
"$",
"detail",
")",
")",
";",
"if",
"(",
"$",
"fromEnv",
")",
"{",
"return",
"$",
"fromEnv",
";",
"}",
"}"
]
| Retrieves detail in priority order from
1. local instance field
2. Config
3. Environment
@param string $detail key name for detail
@return string the value for that key | [
"Retrieves",
"detail",
"in",
"priority",
"order",
"from",
"1",
".",
"local",
"instance",
"field",
"2",
".",
"Config",
"3",
".",
"Environment"
]
| 8bf570e1450c891d9ae0df49bc97ab4273784c5c | https://github.com/silverstripe/silverstripe-documentconverter/blob/8bf570e1450c891d9ae0df49bc97ab4273784c5c/src/ServiceConnector.php#L79-L95 | train |
silverstripe/silverstripe-documentconverter | src/ImportField.php | ImportField.upload | public function upload(HTTPRequest $request)
{
if ($this->isDisabled() || $this->isReadonly()) {
return $this->httpError(403);
}
// Protect against CSRF on destructive action
$token = $this->getForm()->getSecurityToken();
if (!$token->checkRequest($request)) {
return $this->httpError(400);
}
$tmpfile = $request->postVar('Upload');
// Check if the file has been uploaded into the temporary storage.
if (!$tmpfile) {
$return = [
'error' => _t(
'SilverStripe\\AssetAdmin\\Forms\\UploadField.FIELDNOTSET',
'File information not found'
)
];
} else {
$return = [
'name' => $tmpfile['name'],
'size' => $tmpfile['size'],
'type' => $tmpfile['type'],
'error' => $tmpfile['error']
];
}
if (!$return['error']) {
// Get options for this import.
$splitHeader = (int)$request->postVar('SplitHeader');
$keepSource = (bool)$request->postVar('KeepSource');
$chosenFolderID = (int)$request->postVar('ChosenFolderID');
$publishPages = (bool)$request->postVar('PublishPages');
$includeTOC = (bool)$request->postVar('IncludeTOC');
// Process the document and write the page.
$preservedDocument = null;
if ($keepSource) {
$preservedDocument = $this->preserveSourceDocument($tmpfile, $chosenFolderID);
}
$importResult = $this->importFromPOST($tmpfile, $splitHeader, $publishPages, $chosenFolderID);
if (is_array($importResult) && isset($importResult['error'])) {
$return['error'] = $importResult['error'];
} elseif ($includeTOC) {
$this->writeTOC($publishPages, $keepSource ? $preservedDocument : null);
}
}
$response = HTTPResponse::create(Convert::raw2json([$return]));
$response->addHeader('Content-Type', 'application/json');
return $response;
} | php | public function upload(HTTPRequest $request)
{
if ($this->isDisabled() || $this->isReadonly()) {
return $this->httpError(403);
}
// Protect against CSRF on destructive action
$token = $this->getForm()->getSecurityToken();
if (!$token->checkRequest($request)) {
return $this->httpError(400);
}
$tmpfile = $request->postVar('Upload');
// Check if the file has been uploaded into the temporary storage.
if (!$tmpfile) {
$return = [
'error' => _t(
'SilverStripe\\AssetAdmin\\Forms\\UploadField.FIELDNOTSET',
'File information not found'
)
];
} else {
$return = [
'name' => $tmpfile['name'],
'size' => $tmpfile['size'],
'type' => $tmpfile['type'],
'error' => $tmpfile['error']
];
}
if (!$return['error']) {
// Get options for this import.
$splitHeader = (int)$request->postVar('SplitHeader');
$keepSource = (bool)$request->postVar('KeepSource');
$chosenFolderID = (int)$request->postVar('ChosenFolderID');
$publishPages = (bool)$request->postVar('PublishPages');
$includeTOC = (bool)$request->postVar('IncludeTOC');
// Process the document and write the page.
$preservedDocument = null;
if ($keepSource) {
$preservedDocument = $this->preserveSourceDocument($tmpfile, $chosenFolderID);
}
$importResult = $this->importFromPOST($tmpfile, $splitHeader, $publishPages, $chosenFolderID);
if (is_array($importResult) && isset($importResult['error'])) {
$return['error'] = $importResult['error'];
} elseif ($includeTOC) {
$this->writeTOC($publishPages, $keepSource ? $preservedDocument : null);
}
}
$response = HTTPResponse::create(Convert::raw2json([$return]));
$response->addHeader('Content-Type', 'application/json');
return $response;
} | [
"public",
"function",
"upload",
"(",
"HTTPRequest",
"$",
"request",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isDisabled",
"(",
")",
"||",
"$",
"this",
"->",
"isReadonly",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"httpError",
"(",
"403",
")",
";",
"}",
"// Protect against CSRF on destructive action",
"$",
"token",
"=",
"$",
"this",
"->",
"getForm",
"(",
")",
"->",
"getSecurityToken",
"(",
")",
";",
"if",
"(",
"!",
"$",
"token",
"->",
"checkRequest",
"(",
"$",
"request",
")",
")",
"{",
"return",
"$",
"this",
"->",
"httpError",
"(",
"400",
")",
";",
"}",
"$",
"tmpfile",
"=",
"$",
"request",
"->",
"postVar",
"(",
"'Upload'",
")",
";",
"// Check if the file has been uploaded into the temporary storage.",
"if",
"(",
"!",
"$",
"tmpfile",
")",
"{",
"$",
"return",
"=",
"[",
"'error'",
"=>",
"_t",
"(",
"'SilverStripe\\\\AssetAdmin\\\\Forms\\\\UploadField.FIELDNOTSET'",
",",
"'File information not found'",
")",
"]",
";",
"}",
"else",
"{",
"$",
"return",
"=",
"[",
"'name'",
"=>",
"$",
"tmpfile",
"[",
"'name'",
"]",
",",
"'size'",
"=>",
"$",
"tmpfile",
"[",
"'size'",
"]",
",",
"'type'",
"=>",
"$",
"tmpfile",
"[",
"'type'",
"]",
",",
"'error'",
"=>",
"$",
"tmpfile",
"[",
"'error'",
"]",
"]",
";",
"}",
"if",
"(",
"!",
"$",
"return",
"[",
"'error'",
"]",
")",
"{",
"// Get options for this import.",
"$",
"splitHeader",
"=",
"(",
"int",
")",
"$",
"request",
"->",
"postVar",
"(",
"'SplitHeader'",
")",
";",
"$",
"keepSource",
"=",
"(",
"bool",
")",
"$",
"request",
"->",
"postVar",
"(",
"'KeepSource'",
")",
";",
"$",
"chosenFolderID",
"=",
"(",
"int",
")",
"$",
"request",
"->",
"postVar",
"(",
"'ChosenFolderID'",
")",
";",
"$",
"publishPages",
"=",
"(",
"bool",
")",
"$",
"request",
"->",
"postVar",
"(",
"'PublishPages'",
")",
";",
"$",
"includeTOC",
"=",
"(",
"bool",
")",
"$",
"request",
"->",
"postVar",
"(",
"'IncludeTOC'",
")",
";",
"// Process the document and write the page.",
"$",
"preservedDocument",
"=",
"null",
";",
"if",
"(",
"$",
"keepSource",
")",
"{",
"$",
"preservedDocument",
"=",
"$",
"this",
"->",
"preserveSourceDocument",
"(",
"$",
"tmpfile",
",",
"$",
"chosenFolderID",
")",
";",
"}",
"$",
"importResult",
"=",
"$",
"this",
"->",
"importFromPOST",
"(",
"$",
"tmpfile",
",",
"$",
"splitHeader",
",",
"$",
"publishPages",
",",
"$",
"chosenFolderID",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"importResult",
")",
"&&",
"isset",
"(",
"$",
"importResult",
"[",
"'error'",
"]",
")",
")",
"{",
"$",
"return",
"[",
"'error'",
"]",
"=",
"$",
"importResult",
"[",
"'error'",
"]",
";",
"}",
"elseif",
"(",
"$",
"includeTOC",
")",
"{",
"$",
"this",
"->",
"writeTOC",
"(",
"$",
"publishPages",
",",
"$",
"keepSource",
"?",
"$",
"preservedDocument",
":",
"null",
")",
";",
"}",
"}",
"$",
"response",
"=",
"HTTPResponse",
"::",
"create",
"(",
"Convert",
"::",
"raw2json",
"(",
"[",
"$",
"return",
"]",
")",
")",
";",
"$",
"response",
"->",
"addHeader",
"(",
"'Content-Type'",
",",
"'application/json'",
")",
";",
"return",
"$",
"response",
";",
"}"
]
| Process the document immediately upon upload. | [
"Process",
"the",
"document",
"immediately",
"upon",
"upload",
"."
]
| 8bf570e1450c891d9ae0df49bc97ab4273784c5c | https://github.com/silverstripe/silverstripe-documentconverter/blob/8bf570e1450c891d9ae0df49bc97ab4273784c5c/src/ImportField.php#L64-L120 | train |
silverstripe/silverstripe-documentconverter | src/ImportField.php | ImportField.preserveSourceDocument | protected function preserveSourceDocument($tmpfile, $chosenFolderID = null)
{
$upload = Upload::create();
$file = File::create();
$upload->loadIntoFile($tmpfile, $file, $chosenFolderID);
$page = $this->form->getRecord();
$page->ImportedFromFileID = $file->ID;
$page->write();
return $file;
} | php | protected function preserveSourceDocument($tmpfile, $chosenFolderID = null)
{
$upload = Upload::create();
$file = File::create();
$upload->loadIntoFile($tmpfile, $file, $chosenFolderID);
$page = $this->form->getRecord();
$page->ImportedFromFileID = $file->ID;
$page->write();
return $file;
} | [
"protected",
"function",
"preserveSourceDocument",
"(",
"$",
"tmpfile",
",",
"$",
"chosenFolderID",
"=",
"null",
")",
"{",
"$",
"upload",
"=",
"Upload",
"::",
"create",
"(",
")",
";",
"$",
"file",
"=",
"File",
"::",
"create",
"(",
")",
";",
"$",
"upload",
"->",
"loadIntoFile",
"(",
"$",
"tmpfile",
",",
"$",
"file",
",",
"$",
"chosenFolderID",
")",
";",
"$",
"page",
"=",
"$",
"this",
"->",
"form",
"->",
"getRecord",
"(",
")",
";",
"$",
"page",
"->",
"ImportedFromFileID",
"=",
"$",
"file",
"->",
"ID",
";",
"$",
"page",
"->",
"write",
"(",
")",
";",
"return",
"$",
"file",
";",
"}"
]
| Preserves the source file by copying it to a specified folder.
@param $tmpfile Temporary file data structure.
@param int $chosenFolderID Target folder.
@return File Stored file. | [
"Preserves",
"the",
"source",
"file",
"by",
"copying",
"it",
"to",
"a",
"specified",
"folder",
"."
]
| 8bf570e1450c891d9ae0df49bc97ab4273784c5c | https://github.com/silverstripe/silverstripe-documentconverter/blob/8bf570e1450c891d9ae0df49bc97ab4273784c5c/src/ImportField.php#L129-L141 | train |
silverstripe/silverstripe-documentconverter | src/ImportField.php | ImportField.writeTOC | protected function writeTOC($publishPages = false, $preservedDocument = null)
{
$page = $this->form->getRecord();
$content = '<ul>';
if ($page) {
if ($page->Children()->Count() > 0) {
foreach ($page->Children() as $child) {
$content .= '<li><a href="' . $child->Link() . '">' . $child->Title . '</a></li>';
}
$page->Content = $content . '</ul>';
} else {
$doc = new DOMDocument();
$doc->loadHTML($page->Content);
$body = $doc->getElementsByTagName('body')->item(0);
$node = $body->firstChild;
$h1 = $h2 = 1;
while ($node) {
if ($node instanceof DOMElement && $node->tagName == 'h1') {
$content .= '<li><a href="#h1.' . $h1 . '">' .
trim(preg_replace('/\n|\r/', '', Convert::html2raw($node->textContent))) .
'</a></li>';
$node->setAttributeNode(new DOMAttr("id", "h1.".$h1));
$h1++;
} elseif ($node instanceof DOMElement && $node->tagName == 'h2') {
$content .= '<li class="menu-h2"><a href="#h2.' . $h2 . '">' .
trim(preg_replace('/\n|\r/', '', Convert::html2raw($node->textContent))) .
'</a></li>';
$node->setAttributeNode(new DOMAttr("id", "h2.".$h2));
$h2++;
}
$node = $node->nextSibling;
}
$page->Content = $content . '</ul>' . $doc->saveHTML();
}
// Add in the link to the original document, if provided.
if ($preservedDocument) {
$page->Content = '<a href="' .
$preservedDocument->Link() .
'" title="download original document">download original document (' .
$preservedDocument->getSize() .
')</a>' .
$page->Content;
}
// Store the result
$page->write();
if ($publishPages) {
$page->publishRecursive();
}
}
} | php | protected function writeTOC($publishPages = false, $preservedDocument = null)
{
$page = $this->form->getRecord();
$content = '<ul>';
if ($page) {
if ($page->Children()->Count() > 0) {
foreach ($page->Children() as $child) {
$content .= '<li><a href="' . $child->Link() . '">' . $child->Title . '</a></li>';
}
$page->Content = $content . '</ul>';
} else {
$doc = new DOMDocument();
$doc->loadHTML($page->Content);
$body = $doc->getElementsByTagName('body')->item(0);
$node = $body->firstChild;
$h1 = $h2 = 1;
while ($node) {
if ($node instanceof DOMElement && $node->tagName == 'h1') {
$content .= '<li><a href="#h1.' . $h1 . '">' .
trim(preg_replace('/\n|\r/', '', Convert::html2raw($node->textContent))) .
'</a></li>';
$node->setAttributeNode(new DOMAttr("id", "h1.".$h1));
$h1++;
} elseif ($node instanceof DOMElement && $node->tagName == 'h2') {
$content .= '<li class="menu-h2"><a href="#h2.' . $h2 . '">' .
trim(preg_replace('/\n|\r/', '', Convert::html2raw($node->textContent))) .
'</a></li>';
$node->setAttributeNode(new DOMAttr("id", "h2.".$h2));
$h2++;
}
$node = $node->nextSibling;
}
$page->Content = $content . '</ul>' . $doc->saveHTML();
}
// Add in the link to the original document, if provided.
if ($preservedDocument) {
$page->Content = '<a href="' .
$preservedDocument->Link() .
'" title="download original document">download original document (' .
$preservedDocument->getSize() .
')</a>' .
$page->Content;
}
// Store the result
$page->write();
if ($publishPages) {
$page->publishRecursive();
}
}
} | [
"protected",
"function",
"writeTOC",
"(",
"$",
"publishPages",
"=",
"false",
",",
"$",
"preservedDocument",
"=",
"null",
")",
"{",
"$",
"page",
"=",
"$",
"this",
"->",
"form",
"->",
"getRecord",
"(",
")",
";",
"$",
"content",
"=",
"'<ul>'",
";",
"if",
"(",
"$",
"page",
")",
"{",
"if",
"(",
"$",
"page",
"->",
"Children",
"(",
")",
"->",
"Count",
"(",
")",
">",
"0",
")",
"{",
"foreach",
"(",
"$",
"page",
"->",
"Children",
"(",
")",
"as",
"$",
"child",
")",
"{",
"$",
"content",
".=",
"'<li><a href=\"'",
".",
"$",
"child",
"->",
"Link",
"(",
")",
".",
"'\">'",
".",
"$",
"child",
"->",
"Title",
".",
"'</a></li>'",
";",
"}",
"$",
"page",
"->",
"Content",
"=",
"$",
"content",
".",
"'</ul>'",
";",
"}",
"else",
"{",
"$",
"doc",
"=",
"new",
"DOMDocument",
"(",
")",
";",
"$",
"doc",
"->",
"loadHTML",
"(",
"$",
"page",
"->",
"Content",
")",
";",
"$",
"body",
"=",
"$",
"doc",
"->",
"getElementsByTagName",
"(",
"'body'",
")",
"->",
"item",
"(",
"0",
")",
";",
"$",
"node",
"=",
"$",
"body",
"->",
"firstChild",
";",
"$",
"h1",
"=",
"$",
"h2",
"=",
"1",
";",
"while",
"(",
"$",
"node",
")",
"{",
"if",
"(",
"$",
"node",
"instanceof",
"DOMElement",
"&&",
"$",
"node",
"->",
"tagName",
"==",
"'h1'",
")",
"{",
"$",
"content",
".=",
"'<li><a href=\"#h1.'",
".",
"$",
"h1",
".",
"'\">'",
".",
"trim",
"(",
"preg_replace",
"(",
"'/\\n|\\r/'",
",",
"''",
",",
"Convert",
"::",
"html2raw",
"(",
"$",
"node",
"->",
"textContent",
")",
")",
")",
".",
"'</a></li>'",
";",
"$",
"node",
"->",
"setAttributeNode",
"(",
"new",
"DOMAttr",
"(",
"\"id\"",
",",
"\"h1.\"",
".",
"$",
"h1",
")",
")",
";",
"$",
"h1",
"++",
";",
"}",
"elseif",
"(",
"$",
"node",
"instanceof",
"DOMElement",
"&&",
"$",
"node",
"->",
"tagName",
"==",
"'h2'",
")",
"{",
"$",
"content",
".=",
"'<li class=\"menu-h2\"><a href=\"#h2.'",
".",
"$",
"h2",
".",
"'\">'",
".",
"trim",
"(",
"preg_replace",
"(",
"'/\\n|\\r/'",
",",
"''",
",",
"Convert",
"::",
"html2raw",
"(",
"$",
"node",
"->",
"textContent",
")",
")",
")",
".",
"'</a></li>'",
";",
"$",
"node",
"->",
"setAttributeNode",
"(",
"new",
"DOMAttr",
"(",
"\"id\"",
",",
"\"h2.\"",
".",
"$",
"h2",
")",
")",
";",
"$",
"h2",
"++",
";",
"}",
"$",
"node",
"=",
"$",
"node",
"->",
"nextSibling",
";",
"}",
"$",
"page",
"->",
"Content",
"=",
"$",
"content",
".",
"'</ul>'",
".",
"$",
"doc",
"->",
"saveHTML",
"(",
")",
";",
"}",
"// Add in the link to the original document, if provided.",
"if",
"(",
"$",
"preservedDocument",
")",
"{",
"$",
"page",
"->",
"Content",
"=",
"'<a href=\"'",
".",
"$",
"preservedDocument",
"->",
"Link",
"(",
")",
".",
"'\" title=\"download original document\">download original document ('",
".",
"$",
"preservedDocument",
"->",
"getSize",
"(",
")",
".",
"')</a>'",
".",
"$",
"page",
"->",
"Content",
";",
"}",
"// Store the result",
"$",
"page",
"->",
"write",
"(",
")",
";",
"if",
"(",
"$",
"publishPages",
")",
"{",
"$",
"page",
"->",
"publishRecursive",
"(",
")",
";",
"}",
"}",
"}"
]
| Builds and writes the table of contents for the document.
@param bool $publishPage Should the parent page be published.
@param File $preservedDocument Set if the link to the original document should be added. | [
"Builds",
"and",
"writes",
"the",
"table",
"of",
"contents",
"for",
"the",
"document",
"."
]
| 8bf570e1450c891d9ae0df49bc97ab4273784c5c | https://github.com/silverstripe/silverstripe-documentconverter/blob/8bf570e1450c891d9ae0df49bc97ab4273784c5c/src/ImportField.php#L149-L201 | train |
silverstripe/silverstripe-documentconverter | src/ImportField.php | ImportField.writeContent | protected function writeContent($subtitle, $subdoc, $subnode, $sort = null, $publishPages = false)
{
$record = $this->form->getRecord();
if ($subtitle) {
// Write the chapter page to a subpage.
$page = DataObject::get_one(
'Page',
sprintf('"Title" = \'%s\' AND "ParentID" = %d', $subtitle, $record->ID)
);
if (!$page) {
$page = Page::create();
$page->ParentID = $record->ID;
$page->Title = $subtitle;
}
unset($this->unusedChildren[$page->ID]);
file_put_contents(ASSETS_PATH . '/index-' . $sort . '.html', $this->getBodyText($subdoc, $subnode));
if ($sort) {
$page->Sort = $sort;
}
$page->Content = $this->getBodyText($subdoc, $subnode);
$page->write();
if ($publishPages) {
$page->publishRecursive();
}
} else {
// Write to the master page.
$record->Content = $this->getBodyText($subdoc, $subnode);
$record->write();
if ($publishPages) {
$record->publishRecursive();
}
}
} | php | protected function writeContent($subtitle, $subdoc, $subnode, $sort = null, $publishPages = false)
{
$record = $this->form->getRecord();
if ($subtitle) {
// Write the chapter page to a subpage.
$page = DataObject::get_one(
'Page',
sprintf('"Title" = \'%s\' AND "ParentID" = %d', $subtitle, $record->ID)
);
if (!$page) {
$page = Page::create();
$page->ParentID = $record->ID;
$page->Title = $subtitle;
}
unset($this->unusedChildren[$page->ID]);
file_put_contents(ASSETS_PATH . '/index-' . $sort . '.html', $this->getBodyText($subdoc, $subnode));
if ($sort) {
$page->Sort = $sort;
}
$page->Content = $this->getBodyText($subdoc, $subnode);
$page->write();
if ($publishPages) {
$page->publishRecursive();
}
} else {
// Write to the master page.
$record->Content = $this->getBodyText($subdoc, $subnode);
$record->write();
if ($publishPages) {
$record->publishRecursive();
}
}
} | [
"protected",
"function",
"writeContent",
"(",
"$",
"subtitle",
",",
"$",
"subdoc",
",",
"$",
"subnode",
",",
"$",
"sort",
"=",
"null",
",",
"$",
"publishPages",
"=",
"false",
")",
"{",
"$",
"record",
"=",
"$",
"this",
"->",
"form",
"->",
"getRecord",
"(",
")",
";",
"if",
"(",
"$",
"subtitle",
")",
"{",
"// Write the chapter page to a subpage.",
"$",
"page",
"=",
"DataObject",
"::",
"get_one",
"(",
"'Page'",
",",
"sprintf",
"(",
"'\"Title\" = \\'%s\\' AND \"ParentID\" = %d'",
",",
"$",
"subtitle",
",",
"$",
"record",
"->",
"ID",
")",
")",
";",
"if",
"(",
"!",
"$",
"page",
")",
"{",
"$",
"page",
"=",
"Page",
"::",
"create",
"(",
")",
";",
"$",
"page",
"->",
"ParentID",
"=",
"$",
"record",
"->",
"ID",
";",
"$",
"page",
"->",
"Title",
"=",
"$",
"subtitle",
";",
"}",
"unset",
"(",
"$",
"this",
"->",
"unusedChildren",
"[",
"$",
"page",
"->",
"ID",
"]",
")",
";",
"file_put_contents",
"(",
"ASSETS_PATH",
".",
"'/index-'",
".",
"$",
"sort",
".",
"'.html'",
",",
"$",
"this",
"->",
"getBodyText",
"(",
"$",
"subdoc",
",",
"$",
"subnode",
")",
")",
";",
"if",
"(",
"$",
"sort",
")",
"{",
"$",
"page",
"->",
"Sort",
"=",
"$",
"sort",
";",
"}",
"$",
"page",
"->",
"Content",
"=",
"$",
"this",
"->",
"getBodyText",
"(",
"$",
"subdoc",
",",
"$",
"subnode",
")",
";",
"$",
"page",
"->",
"write",
"(",
")",
";",
"if",
"(",
"$",
"publishPages",
")",
"{",
"$",
"page",
"->",
"publishRecursive",
"(",
")",
";",
"}",
"}",
"else",
"{",
"// Write to the master page.",
"$",
"record",
"->",
"Content",
"=",
"$",
"this",
"->",
"getBodyText",
"(",
"$",
"subdoc",
",",
"$",
"subnode",
")",
";",
"$",
"record",
"->",
"write",
"(",
")",
";",
"if",
"(",
"$",
"publishPages",
")",
"{",
"$",
"record",
"->",
"publishRecursive",
"(",
")",
";",
"}",
"}",
"}"
]
| Used only when writing the document that has been split by headers.
Can write both to the chapter pages as well as the master page.
@param string $subtitle Title of the chapter - if missing, it will write to the master page.
@param $subdoc
@param $subnode
@param int $sort Order of the chapter page.
@param $publishPages Whether to publish the resulting child/master pages. | [
"Used",
"only",
"when",
"writing",
"the",
"document",
"that",
"has",
"been",
"split",
"by",
"headers",
".",
"Can",
"write",
"both",
"to",
"the",
"chapter",
"pages",
"as",
"well",
"as",
"the",
"master",
"page",
"."
]
| 8bf570e1450c891d9ae0df49bc97ab4273784c5c | https://github.com/silverstripe/silverstripe-documentconverter/blob/8bf570e1450c891d9ae0df49bc97ab4273784c5c/src/ImportField.php#L231-L267 | train |
duncan3dc/sessions | src/SessionInstance.php | SessionInstance.regenerate | public function regenerate()
{
$this->init();
# Generate a new session
session_start();
session_regenerate_id();
# Get the newly generated ID
$this->id = session_id();
# Remove the lock from the session file
session_write_close();
return $this->id;
} | php | public function regenerate()
{
$this->init();
# Generate a new session
session_start();
session_regenerate_id();
# Get the newly generated ID
$this->id = session_id();
# Remove the lock from the session file
session_write_close();
return $this->id;
} | [
"public",
"function",
"regenerate",
"(",
")",
"{",
"$",
"this",
"->",
"init",
"(",
")",
";",
"# Generate a new session",
"session_start",
"(",
")",
";",
"session_regenerate_id",
"(",
")",
";",
"# Get the newly generated ID",
"$",
"this",
"->",
"id",
"=",
"session_id",
"(",
")",
";",
"# Remove the lock from the session file",
"session_write_close",
"(",
")",
";",
"return",
"$",
"this",
"->",
"id",
";",
"}"
]
| Update the current session id with a newly generated one.
@return string The new session ID | [
"Update",
"the",
"current",
"session",
"id",
"with",
"a",
"newly",
"generated",
"one",
"."
]
| 7ff0b18a5ed9df6aadc953416015cd447cebdc71 | https://github.com/duncan3dc/sessions/blob/7ff0b18a5ed9df6aadc953416015cd447cebdc71/src/SessionInstance.php#L135-L150 | train |
duncan3dc/sessions | src/SessionInstance.php | SessionInstance.destroy | public function destroy(): SessionInterface
{
$this->init();
# Start the session up, but ignore the error about headers already being sent
@session_start();
# Clear the session data from the server
session_destroy();
# Clear the cookie so the client knows the session is gone
setcookie($this->name, "", time() - 86400, $this->cookie->getPath(), $this->cookie->getDomain(), $this->cookie->isSecure(), $this->cookie->isHttpOnly());
# Reset the session data
$this->init = false;
$this->data = [];
return $this;
} | php | public function destroy(): SessionInterface
{
$this->init();
# Start the session up, but ignore the error about headers already being sent
@session_start();
# Clear the session data from the server
session_destroy();
# Clear the cookie so the client knows the session is gone
setcookie($this->name, "", time() - 86400, $this->cookie->getPath(), $this->cookie->getDomain(), $this->cookie->isSecure(), $this->cookie->isHttpOnly());
# Reset the session data
$this->init = false;
$this->data = [];
return $this;
} | [
"public",
"function",
"destroy",
"(",
")",
":",
"SessionInterface",
"{",
"$",
"this",
"->",
"init",
"(",
")",
";",
"# Start the session up, but ignore the error about headers already being sent",
"@",
"session_start",
"(",
")",
";",
"# Clear the session data from the server",
"session_destroy",
"(",
")",
";",
"# Clear the cookie so the client knows the session is gone",
"setcookie",
"(",
"$",
"this",
"->",
"name",
",",
"\"\"",
",",
"time",
"(",
")",
"-",
"86400",
",",
"$",
"this",
"->",
"cookie",
"->",
"getPath",
"(",
")",
",",
"$",
"this",
"->",
"cookie",
"->",
"getDomain",
"(",
")",
",",
"$",
"this",
"->",
"cookie",
"->",
"isSecure",
"(",
")",
",",
"$",
"this",
"->",
"cookie",
"->",
"isHttpOnly",
"(",
")",
")",
";",
"# Reset the session data",
"$",
"this",
"->",
"init",
"=",
"false",
";",
"$",
"this",
"->",
"data",
"=",
"[",
"]",
";",
"return",
"$",
"this",
";",
"}"
]
| Tear down the session and wipe all its data.
@return SessionInterface | [
"Tear",
"down",
"the",
"session",
"and",
"wipe",
"all",
"its",
"data",
"."
]
| 7ff0b18a5ed9df6aadc953416015cd447cebdc71 | https://github.com/duncan3dc/sessions/blob/7ff0b18a5ed9df6aadc953416015cd447cebdc71/src/SessionInstance.php#L258-L276 | train |
RobinDev/DataTablesPHP | src/Helper.php | Helper.formatOn | public static function formatOn($on, $r = '')
{
if (isset($on[0]) && is_array($on[0])) {
foreach ($on as $on2) {
$r = self::formatOn($on2, $r);
}
} else {
$on2 = array_keys($on);
$r .= (!empty($r) ? ' AND ' : '').'`'.key($on).'`.`'.current($on).'` = `'.next($on2).'`.`'.next($on).'`';
}
return $r;
} | php | public static function formatOn($on, $r = '')
{
if (isset($on[0]) && is_array($on[0])) {
foreach ($on as $on2) {
$r = self::formatOn($on2, $r);
}
} else {
$on2 = array_keys($on);
$r .= (!empty($r) ? ' AND ' : '').'`'.key($on).'`.`'.current($on).'` = `'.next($on2).'`.`'.next($on).'`';
}
return $r;
} | [
"public",
"static",
"function",
"formatOn",
"(",
"$",
"on",
",",
"$",
"r",
"=",
"''",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"on",
"[",
"0",
"]",
")",
"&&",
"is_array",
"(",
"$",
"on",
"[",
"0",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"on",
"as",
"$",
"on2",
")",
"{",
"$",
"r",
"=",
"self",
"::",
"formatOn",
"(",
"$",
"on2",
",",
"$",
"r",
")",
";",
"}",
"}",
"else",
"{",
"$",
"on2",
"=",
"array_keys",
"(",
"$",
"on",
")",
";",
"$",
"r",
".=",
"(",
"!",
"empty",
"(",
"$",
"r",
")",
"?",
"' AND '",
":",
"''",
")",
".",
"'`'",
".",
"key",
"(",
"$",
"on",
")",
".",
"'`.`'",
".",
"current",
"(",
"$",
"on",
")",
".",
"'` = `'",
".",
"next",
"(",
"$",
"on2",
")",
".",
"'`.`'",
".",
"next",
"(",
"$",
"on",
")",
".",
"'`'",
";",
"}",
"return",
"$",
"r",
";",
"}"
]
| SQL rendering for JOIN ON
@param array $on
@param string $r
@return string | [
"SQL",
"rendering",
"for",
"JOIN",
"ON"
]
| 41fc1e6d6fdcecd4870bb1683020f7b2de525685 | https://github.com/RobinDev/DataTablesPHP/blob/41fc1e6d6fdcecd4870bb1683020f7b2de525685/src/Helper.php#L62-L74 | train |
RobinDev/DataTablesPHP | src/Helper.php | Helper.arrayToCsv | public static function arrayToCsv($array, $header_row = true, $col_sep = ",", $row_sep = "\n", $qut = '"')
{
if (!is_array($array) || !isset($array[0]) || !is_array($array[0])) {
return false;
}
$output = '';
if ($header_row) {
foreach ($array[0] as $key => $val) {
$key = str_replace($qut, "$qut$qut", $key);
$output .= "$col_sep$qut$key$qut";
}
$output = substr($output, 1)."\n";
}
foreach ($array as $key => $val) {
$tmp = '';
foreach ($val as $cell_key => $cell_val) {
$cell_val = str_replace($qut, "$qut$qut", $cell_val);
$tmp .= "$col_sep$qut$cell_val$qut";
}
$output .= substr($tmp, 1).$row_sep;
}
return $output;
} | php | public static function arrayToCsv($array, $header_row = true, $col_sep = ",", $row_sep = "\n", $qut = '"')
{
if (!is_array($array) || !isset($array[0]) || !is_array($array[0])) {
return false;
}
$output = '';
if ($header_row) {
foreach ($array[0] as $key => $val) {
$key = str_replace($qut, "$qut$qut", $key);
$output .= "$col_sep$qut$key$qut";
}
$output = substr($output, 1)."\n";
}
foreach ($array as $key => $val) {
$tmp = '';
foreach ($val as $cell_key => $cell_val) {
$cell_val = str_replace($qut, "$qut$qut", $cell_val);
$tmp .= "$col_sep$qut$cell_val$qut";
}
$output .= substr($tmp, 1).$row_sep;
}
return $output;
} | [
"public",
"static",
"function",
"arrayToCsv",
"(",
"$",
"array",
",",
"$",
"header_row",
"=",
"true",
",",
"$",
"col_sep",
"=",
"\",\"",
",",
"$",
"row_sep",
"=",
"\"\\n\"",
",",
"$",
"qut",
"=",
"'\"'",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"array",
")",
"||",
"!",
"isset",
"(",
"$",
"array",
"[",
"0",
"]",
")",
"||",
"!",
"is_array",
"(",
"$",
"array",
"[",
"0",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"output",
"=",
"''",
";",
"if",
"(",
"$",
"header_row",
")",
"{",
"foreach",
"(",
"$",
"array",
"[",
"0",
"]",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"$",
"key",
"=",
"str_replace",
"(",
"$",
"qut",
",",
"\"$qut$qut\"",
",",
"$",
"key",
")",
";",
"$",
"output",
".=",
"\"$col_sep$qut$key$qut\"",
";",
"}",
"$",
"output",
"=",
"substr",
"(",
"$",
"output",
",",
"1",
")",
".",
"\"\\n\"",
";",
"}",
"foreach",
"(",
"$",
"array",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"$",
"tmp",
"=",
"''",
";",
"foreach",
"(",
"$",
"val",
"as",
"$",
"cell_key",
"=>",
"$",
"cell_val",
")",
"{",
"$",
"cell_val",
"=",
"str_replace",
"(",
"$",
"qut",
",",
"\"$qut$qut\"",
",",
"$",
"cell_val",
")",
";",
"$",
"tmp",
".=",
"\"$col_sep$qut$cell_val$qut\"",
";",
"}",
"$",
"output",
".=",
"substr",
"(",
"$",
"tmp",
",",
"1",
")",
".",
"$",
"row_sep",
";",
"}",
"return",
"$",
"output",
";",
"}"
]
| Convert an array in a string CSV
@param array $array
@param bool $header_row
@param string $col_sep
@param string $row_sep
@param string $qut
@return string | [
"Convert",
"an",
"array",
"in",
"a",
"string",
"CSV"
]
| 41fc1e6d6fdcecd4870bb1683020f7b2de525685 | https://github.com/RobinDev/DataTablesPHP/blob/41fc1e6d6fdcecd4870bb1683020f7b2de525685/src/Helper.php#L89-L112 | train |
localheinz/php-cs-fixer-config | src/Factory.php | Factory.fromRuleSet | public static function fromRuleSet(RuleSet $ruleSet, array $overrideRules = [])
{
if (\PHP_VERSION_ID < $ruleSet->targetPhpVersion()) {
throw new \RuntimeException(\sprintf(
'Current PHP version "%s is less than targeted PHP version "%s".',
\PHP_VERSION_ID,
$ruleSet->targetPhpVersion()
));
}
$config = new Config($ruleSet->name());
$config->setRiskyAllowed(true);
$config->setRules(\array_merge(
$ruleSet->rules(),
$overrideRules
));
return $config;
} | php | public static function fromRuleSet(RuleSet $ruleSet, array $overrideRules = [])
{
if (\PHP_VERSION_ID < $ruleSet->targetPhpVersion()) {
throw new \RuntimeException(\sprintf(
'Current PHP version "%s is less than targeted PHP version "%s".',
\PHP_VERSION_ID,
$ruleSet->targetPhpVersion()
));
}
$config = new Config($ruleSet->name());
$config->setRiskyAllowed(true);
$config->setRules(\array_merge(
$ruleSet->rules(),
$overrideRules
));
return $config;
} | [
"public",
"static",
"function",
"fromRuleSet",
"(",
"RuleSet",
"$",
"ruleSet",
",",
"array",
"$",
"overrideRules",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"\\",
"PHP_VERSION_ID",
"<",
"$",
"ruleSet",
"->",
"targetPhpVersion",
"(",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"\\",
"sprintf",
"(",
"'Current PHP version \"%s is less than targeted PHP version \"%s\".'",
",",
"\\",
"PHP_VERSION_ID",
",",
"$",
"ruleSet",
"->",
"targetPhpVersion",
"(",
")",
")",
")",
";",
"}",
"$",
"config",
"=",
"new",
"Config",
"(",
"$",
"ruleSet",
"->",
"name",
"(",
")",
")",
";",
"$",
"config",
"->",
"setRiskyAllowed",
"(",
"true",
")",
";",
"$",
"config",
"->",
"setRules",
"(",
"\\",
"array_merge",
"(",
"$",
"ruleSet",
"->",
"rules",
"(",
")",
",",
"$",
"overrideRules",
")",
")",
";",
"return",
"$",
"config",
";",
"}"
]
| Creates a configuration based on a rule set.
@param RuleSet $ruleSet
@param array $overrideRules
@throws \RuntimeException
@return Config | [
"Creates",
"a",
"configuration",
"based",
"on",
"a",
"rule",
"set",
"."
]
| 7fed155336625f766d880f8b53004703d21b9af1 | https://github.com/localheinz/php-cs-fixer-config/blob/7fed155336625f766d880f8b53004703d21b9af1/src/Factory.php#L28-L47 | train |
duncan3dc/sessions | src/Cookie.php | Cookie.createFromIni | public static function createFromIni(): CookieInterface
{
$params = session_get_cookie_params();
return (new static())
->withLifetime($params["lifetime"])
->withPath($params["path"])
->withDomain($params["domain"])
->withSecure($params["secure"])
->withHttpOnly($params["httponly"]);
} | php | public static function createFromIni(): CookieInterface
{
$params = session_get_cookie_params();
return (new static())
->withLifetime($params["lifetime"])
->withPath($params["path"])
->withDomain($params["domain"])
->withSecure($params["secure"])
->withHttpOnly($params["httponly"]);
} | [
"public",
"static",
"function",
"createFromIni",
"(",
")",
":",
"CookieInterface",
"{",
"$",
"params",
"=",
"session_get_cookie_params",
"(",
")",
";",
"return",
"(",
"new",
"static",
"(",
")",
")",
"->",
"withLifetime",
"(",
"$",
"params",
"[",
"\"lifetime\"",
"]",
")",
"->",
"withPath",
"(",
"$",
"params",
"[",
"\"path\"",
"]",
")",
"->",
"withDomain",
"(",
"$",
"params",
"[",
"\"domain\"",
"]",
")",
"->",
"withSecure",
"(",
"$",
"params",
"[",
"\"secure\"",
"]",
")",
"->",
"withHttpOnly",
"(",
"$",
"params",
"[",
"\"httponly\"",
"]",
")",
";",
"}"
]
| Create a new instance from the current environment settings.
@return CookieInterface | [
"Create",
"a",
"new",
"instance",
"from",
"the",
"current",
"environment",
"settings",
"."
]
| 7ff0b18a5ed9df6aadc953416015cd447cebdc71 | https://github.com/duncan3dc/sessions/blob/7ff0b18a5ed9df6aadc953416015cd447cebdc71/src/Cookie.php#L38-L48 | train |
duncan3dc/sessions | src/SessionTrait.php | SessionTrait.clear | public function clear(): SessionInterface
{
# Get all the current session data
$values = $this->getAll();
# Replace all the values with nulls
$values = array_map(function ($value) {
return null;
}, $values);
# Store all the null values (effectively unsetting the keys)
$this->set($values);
return $this;
} | php | public function clear(): SessionInterface
{
# Get all the current session data
$values = $this->getAll();
# Replace all the values with nulls
$values = array_map(function ($value) {
return null;
}, $values);
# Store all the null values (effectively unsetting the keys)
$this->set($values);
return $this;
} | [
"public",
"function",
"clear",
"(",
")",
":",
"SessionInterface",
"{",
"# Get all the current session data",
"$",
"values",
"=",
"$",
"this",
"->",
"getAll",
"(",
")",
";",
"# Replace all the values with nulls",
"$",
"values",
"=",
"array_map",
"(",
"function",
"(",
"$",
"value",
")",
"{",
"return",
"null",
";",
"}",
",",
"$",
"values",
")",
";",
"# Store all the null values (effectively unsetting the keys)",
"$",
"this",
"->",
"set",
"(",
"$",
"values",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Clear all previously set values.
@return SessionInterface | [
"Clear",
"all",
"previously",
"set",
"values",
"."
]
| 7ff0b18a5ed9df6aadc953416015cd447cebdc71 | https://github.com/duncan3dc/sessions/blob/7ff0b18a5ed9df6aadc953416015cd447cebdc71/src/SessionTrait.php#L87-L101 | train |
duncan3dc/sessions | src/SessionTrait.php | SessionTrait.getFlash | public function getFlash(string $key)
{
$key = $this->flashKey($key);
$value = $this->get($key);
$this->delete($key);
return $value;
} | php | public function getFlash(string $key)
{
$key = $this->flashKey($key);
$value = $this->get($key);
$this->delete($key);
return $value;
} | [
"public",
"function",
"getFlash",
"(",
"string",
"$",
"key",
")",
"{",
"$",
"key",
"=",
"$",
"this",
"->",
"flashKey",
"(",
"$",
"key",
")",
";",
"$",
"value",
"=",
"$",
"this",
"->",
"get",
"(",
"$",
"key",
")",
";",
"$",
"this",
"->",
"delete",
"(",
"$",
"key",
")",
";",
"return",
"$",
"value",
";",
"}"
]
| Retrieve a one-time value from the session data.
@param string $key The name of the flash value to retrieve
@return mixed | [
"Retrieve",
"a",
"one",
"-",
"time",
"value",
"from",
"the",
"session",
"data",
"."
]
| 7ff0b18a5ed9df6aadc953416015cd447cebdc71 | https://github.com/duncan3dc/sessions/blob/7ff0b18a5ed9df6aadc953416015cd447cebdc71/src/SessionTrait.php#L124-L133 | train |
duncan3dc/sessions | src/SessionTrait.php | SessionTrait.setFlash | public function setFlash(string $key, $value): SessionInterface
{
$key = $this->flashKey($key);
return $this->set($key, $value);
} | php | public function setFlash(string $key, $value): SessionInterface
{
$key = $this->flashKey($key);
return $this->set($key, $value);
} | [
"public",
"function",
"setFlash",
"(",
"string",
"$",
"key",
",",
"$",
"value",
")",
":",
"SessionInterface",
"{",
"$",
"key",
"=",
"$",
"this",
"->",
"flashKey",
"(",
"$",
"key",
")",
";",
"return",
"$",
"this",
"->",
"set",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"}"
]
| Set a one-time value within session data.
@param string $key The name of the flash value to update
@param mixed $value The value to store against the key
@return SessionInterface | [
"Set",
"a",
"one",
"-",
"time",
"value",
"within",
"session",
"data",
"."
]
| 7ff0b18a5ed9df6aadc953416015cd447cebdc71 | https://github.com/duncan3dc/sessions/blob/7ff0b18a5ed9df6aadc953416015cd447cebdc71/src/SessionTrait.php#L144-L149 | train |
duncan3dc/sessions | src/Storageless/RequestHandler.php | RequestHandler.handle | public function handle(ServerRequestInterface $request): ResponseInterface
{
$storageless = $request->getAttribute(SessionMiddleware::SESSION_ATTRIBUTE);
$session = new Session($storageless);
$request = $request->withAttribute(SessionInterface::class, $session);
return $this->handler->handle($request);
} | php | public function handle(ServerRequestInterface $request): ResponseInterface
{
$storageless = $request->getAttribute(SessionMiddleware::SESSION_ATTRIBUTE);
$session = new Session($storageless);
$request = $request->withAttribute(SessionInterface::class, $session);
return $this->handler->handle($request);
} | [
"public",
"function",
"handle",
"(",
"ServerRequestInterface",
"$",
"request",
")",
":",
"ResponseInterface",
"{",
"$",
"storageless",
"=",
"$",
"request",
"->",
"getAttribute",
"(",
"SessionMiddleware",
"::",
"SESSION_ATTRIBUTE",
")",
";",
"$",
"session",
"=",
"new",
"Session",
"(",
"$",
"storageless",
")",
";",
"$",
"request",
"=",
"$",
"request",
"->",
"withAttribute",
"(",
"SessionInterface",
"::",
"class",
",",
"$",
"session",
")",
";",
"return",
"$",
"this",
"->",
"handler",
"->",
"handle",
"(",
"$",
"request",
")",
";",
"}"
]
| Wrap the storageless session from the request in our session interface.
@param ServerRequestInterface $request The request to handle
@return ResponseInterface | [
"Wrap",
"the",
"storageless",
"session",
"from",
"the",
"request",
"in",
"our",
"session",
"interface",
"."
]
| 7ff0b18a5ed9df6aadc953416015cd447cebdc71 | https://github.com/duncan3dc/sessions/blob/7ff0b18a5ed9df6aadc953416015cd447cebdc71/src/Storageless/RequestHandler.php#L37-L46 | train |
RobinDev/DataTablesPHP | src/DataTable.php | DataTable.instance | public static function instance($id = 'datatable')
{
$cls = get_called_class();
if (!isset(self::$instance[$id])) {
self::$instance[$id] = new $cls($id);
}
return self::$instance[$id];
} | php | public static function instance($id = 'datatable')
{
$cls = get_called_class();
if (!isset(self::$instance[$id])) {
self::$instance[$id] = new $cls($id);
}
return self::$instance[$id];
} | [
"public",
"static",
"function",
"instance",
"(",
"$",
"id",
"=",
"'datatable'",
")",
"{",
"$",
"cls",
"=",
"get_called_class",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"instance",
"[",
"$",
"id",
"]",
")",
")",
"{",
"self",
"::",
"$",
"instance",
"[",
"$",
"id",
"]",
"=",
"new",
"$",
"cls",
"(",
"$",
"id",
")",
";",
"}",
"return",
"self",
"::",
"$",
"instance",
"[",
"$",
"id",
"]",
";",
"}"
]
| Get a table initialized if exist, else initialize one
@param string $id Id wich permit to identify the table
@return self | [
"Get",
"a",
"table",
"initialized",
"if",
"exist",
"else",
"initialize",
"one"
]
| 41fc1e6d6fdcecd4870bb1683020f7b2de525685 | https://github.com/RobinDev/DataTablesPHP/blob/41fc1e6d6fdcecd4870bb1683020f7b2de525685/src/DataTable.php#L128-L136 | train |
RobinDev/DataTablesPHP | src/DataTable.php | DataTable.setJsInitParams | public function setJsInitParams($params)
{
foreach ($params as $k => $v) {
$this->setJsInitParam($k, $v);
}
return $this;
} | php | public function setJsInitParams($params)
{
foreach ($params as $k => $v) {
$this->setJsInitParam($k, $v);
}
return $this;
} | [
"public",
"function",
"setJsInitParams",
"(",
"$",
"params",
")",
"{",
"foreach",
"(",
"$",
"params",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"$",
"this",
"->",
"setJsInitParam",
"(",
"$",
"k",
",",
"$",
"v",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Add dataTables.js Init Params
@param array $params Contain dataTables.js Init Params
@return self | [
"Add",
"dataTables",
".",
"js",
"Init",
"Params"
]
| 41fc1e6d6fdcecd4870bb1683020f7b2de525685 | https://github.com/RobinDev/DataTablesPHP/blob/41fc1e6d6fdcecd4870bb1683020f7b2de525685/src/DataTable.php#L170-L177 | train |
RobinDev/DataTablesPHP | src/DataTable.php | DataTable.setTHead | protected function setTHead(&$params)
{
$k = $this->getColumnIndex($params);
if (isset($params['parent'])) {
$this->theadChild[] = [
'title' => $params['title'],
'class' => isset($params['className']) ? $params['className'] : null,
'colspan' => 1,
];
$this->thead[$k]['colspan'] = !isset($this->thead[$k]['colspan']) ? 1 : ($this->thead[$k]['colspan']+1);
$this->thead[$k]['title'] = $params['parent'];
$this->header = true;
} else {
if (isset($params['title'])) {
$this->thead[$k]['title'] = $params['title'];
}
if (isset($params['className'])) {
$this->thead[$k]['class'] = $params['className'];
}
}
} | php | protected function setTHead(&$params)
{
$k = $this->getColumnIndex($params);
if (isset($params['parent'])) {
$this->theadChild[] = [
'title' => $params['title'],
'class' => isset($params['className']) ? $params['className'] : null,
'colspan' => 1,
];
$this->thead[$k]['colspan'] = !isset($this->thead[$k]['colspan']) ? 1 : ($this->thead[$k]['colspan']+1);
$this->thead[$k]['title'] = $params['parent'];
$this->header = true;
} else {
if (isset($params['title'])) {
$this->thead[$k]['title'] = $params['title'];
}
if (isset($params['className'])) {
$this->thead[$k]['class'] = $params['className'];
}
}
} | [
"protected",
"function",
"setTHead",
"(",
"&",
"$",
"params",
")",
"{",
"$",
"k",
"=",
"$",
"this",
"->",
"getColumnIndex",
"(",
"$",
"params",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"params",
"[",
"'parent'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"theadChild",
"[",
"]",
"=",
"[",
"'title'",
"=>",
"$",
"params",
"[",
"'title'",
"]",
",",
"'class'",
"=>",
"isset",
"(",
"$",
"params",
"[",
"'className'",
"]",
")",
"?",
"$",
"params",
"[",
"'className'",
"]",
":",
"null",
",",
"'colspan'",
"=>",
"1",
",",
"]",
";",
"$",
"this",
"->",
"thead",
"[",
"$",
"k",
"]",
"[",
"'colspan'",
"]",
"=",
"!",
"isset",
"(",
"$",
"this",
"->",
"thead",
"[",
"$",
"k",
"]",
"[",
"'colspan'",
"]",
")",
"?",
"1",
":",
"(",
"$",
"this",
"->",
"thead",
"[",
"$",
"k",
"]",
"[",
"'colspan'",
"]",
"+",
"1",
")",
";",
"$",
"this",
"->",
"thead",
"[",
"$",
"k",
"]",
"[",
"'title'",
"]",
"=",
"$",
"params",
"[",
"'parent'",
"]",
";",
"$",
"this",
"->",
"header",
"=",
"true",
";",
"}",
"else",
"{",
"if",
"(",
"isset",
"(",
"$",
"params",
"[",
"'title'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"thead",
"[",
"$",
"k",
"]",
"[",
"'title'",
"]",
"=",
"$",
"params",
"[",
"'title'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"params",
"[",
"'className'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"thead",
"[",
"$",
"k",
"]",
"[",
"'class'",
"]",
"=",
"$",
"params",
"[",
"'className'",
"]",
";",
"}",
"}",
"}"
]
| Add a new column header
@param array $params 's column | [
"Add",
"a",
"new",
"column",
"header"
]
| 41fc1e6d6fdcecd4870bb1683020f7b2de525685 | https://github.com/RobinDev/DataTablesPHP/blob/41fc1e6d6fdcecd4870bb1683020f7b2de525685/src/DataTable.php#L218-L239 | train |
RobinDev/DataTablesPHP | src/DataTable.php | DataTable.setTFoot | protected function setTFoot(&$params)
{
if (isset($params['sFilter'])) {
if (isset($params['sFilter']['type']) && in_array($params['sFilter']['type'], self::$columFilteringParams['type'])) {
$params['sFilter'] = array_merge(self::$columFilteringParams, $params['sFilter']);
$this->individualColumnFiltering = true;
$this->footer = true;
} else {
unset($params['sFilter']);
}
}
} | php | protected function setTFoot(&$params)
{
if (isset($params['sFilter'])) {
if (isset($params['sFilter']['type']) && in_array($params['sFilter']['type'], self::$columFilteringParams['type'])) {
$params['sFilter'] = array_merge(self::$columFilteringParams, $params['sFilter']);
$this->individualColumnFiltering = true;
$this->footer = true;
} else {
unset($params['sFilter']);
}
}
} | [
"protected",
"function",
"setTFoot",
"(",
"&",
"$",
"params",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"params",
"[",
"'sFilter'",
"]",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"params",
"[",
"'sFilter'",
"]",
"[",
"'type'",
"]",
")",
"&&",
"in_array",
"(",
"$",
"params",
"[",
"'sFilter'",
"]",
"[",
"'type'",
"]",
",",
"self",
"::",
"$",
"columFilteringParams",
"[",
"'type'",
"]",
")",
")",
"{",
"$",
"params",
"[",
"'sFilter'",
"]",
"=",
"array_merge",
"(",
"self",
"::",
"$",
"columFilteringParams",
",",
"$",
"params",
"[",
"'sFilter'",
"]",
")",
";",
"$",
"this",
"->",
"individualColumnFiltering",
"=",
"true",
";",
"$",
"this",
"->",
"footer",
"=",
"true",
";",
"}",
"else",
"{",
"unset",
"(",
"$",
"params",
"[",
"'sFilter'",
"]",
")",
";",
"}",
"}",
"}"
]
| Manage the column tfoot
Normalize sFilter params if exist
@param array $params | [
"Manage",
"the",
"column",
"tfoot",
"Normalize",
"sFilter",
"params",
"if",
"exist"
]
| 41fc1e6d6fdcecd4870bb1683020f7b2de525685 | https://github.com/RobinDev/DataTablesPHP/blob/41fc1e6d6fdcecd4870bb1683020f7b2de525685/src/DataTable.php#L247-L258 | train |
RobinDev/DataTablesPHP | src/DataTable.php | DataTable.setColumn | public function setColumn($params, $show = true)
{
if ($show) {
$this->setTHead($params);
$this->setTFoot($params);
$this->columns[] = $params;
} else {
$this->unsetColumns[] = $params;
}
return $this;
} | php | public function setColumn($params, $show = true)
{
if ($show) {
$this->setTHead($params);
$this->setTFoot($params);
$this->columns[] = $params;
} else {
$this->unsetColumns[] = $params;
}
return $this;
} | [
"public",
"function",
"setColumn",
"(",
"$",
"params",
",",
"$",
"show",
"=",
"true",
")",
"{",
"if",
"(",
"$",
"show",
")",
"{",
"$",
"this",
"->",
"setTHead",
"(",
"$",
"params",
")",
";",
"$",
"this",
"->",
"setTFoot",
"(",
"$",
"params",
")",
";",
"$",
"this",
"->",
"columns",
"[",
"]",
"=",
"$",
"params",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"unsetColumns",
"[",
"]",
"=",
"$",
"params",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Add a column to the table
@param array $params Can contain :
$params[$key] = mixed // Properties for Initialization Javascript (see self::$columnParams)
$params['parent'] = string // Permit to have a complex header with a colspan...
// Set the same string to put multiple column under the same th
$params['sFilter'] = array // Permit to add a filtering html input for the column
$params['sFilter']['type'] = string // see self::$columFilteringParams['type']
$params['sFilter']['regex'] = bool //
$params['sFilter']['sql_table'] = string
$params['sFilter']['sql_name'] = string
$params['sFilter']['sqlFilter'] = string // Initial SQL filter
@param bool $show Set false to Add a column to load in the result but wich will not be print
@return self | [
"Add",
"a",
"column",
"to",
"the",
"table"
]
| 41fc1e6d6fdcecd4870bb1683020f7b2de525685 | https://github.com/RobinDev/DataTablesPHP/blob/41fc1e6d6fdcecd4870bb1683020f7b2de525685/src/DataTable.php#L278-L290 | train |
RobinDev/DataTablesPHP | src/DataTable.php | DataTable.setColumns | public function setColumns($columns)
{
foreach ($columns as $c) {
$this->setColumn($c, isset($c['show']) ? $c['show'] : true);
}
return $this;
} | php | public function setColumns($columns)
{
foreach ($columns as $c) {
$this->setColumn($c, isset($c['show']) ? $c['show'] : true);
}
return $this;
} | [
"public",
"function",
"setColumns",
"(",
"$",
"columns",
")",
"{",
"foreach",
"(",
"$",
"columns",
"as",
"$",
"c",
")",
"{",
"$",
"this",
"->",
"setColumn",
"(",
"$",
"c",
",",
"isset",
"(",
"$",
"c",
"[",
"'show'",
"]",
")",
"?",
"$",
"c",
"[",
"'show'",
"]",
":",
"true",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Add columns to the table
@param array $columns
@return self | [
"Add",
"columns",
"to",
"the",
"table"
]
| 41fc1e6d6fdcecd4870bb1683020f7b2de525685 | https://github.com/RobinDev/DataTablesPHP/blob/41fc1e6d6fdcecd4870bb1683020f7b2de525685/src/DataTable.php#L299-L306 | train |
RobinDev/DataTablesPHP | src/DataTable.php | DataTable.getJavascript | public function getJavascript()
{
if (!empty($this->columns)) {
$this->setJsInitParam('columns', $this->getColumnsForJs());
}
$js = 'var '.$this->tableName.' = $("#'.$this->tableName.'").dataTable('."\n"
.(!empty($this->jsInitParameters) ? PHPToJS::render((object) $this->jsInitParameters) : '')."\n"
.');'."\n";
$js .= $this->getJavascriptSearchPart();
return $js;
} | php | public function getJavascript()
{
if (!empty($this->columns)) {
$this->setJsInitParam('columns', $this->getColumnsForJs());
}
$js = 'var '.$this->tableName.' = $("#'.$this->tableName.'").dataTable('."\n"
.(!empty($this->jsInitParameters) ? PHPToJS::render((object) $this->jsInitParameters) : '')."\n"
.');'."\n";
$js .= $this->getJavascriptSearchPart();
return $js;
} | [
"public",
"function",
"getJavascript",
"(",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"columns",
")",
")",
"{",
"$",
"this",
"->",
"setJsInitParam",
"(",
"'columns'",
",",
"$",
"this",
"->",
"getColumnsForJs",
"(",
")",
")",
";",
"}",
"$",
"js",
"=",
"'var '",
".",
"$",
"this",
"->",
"tableName",
".",
"' = $(\"#'",
".",
"$",
"this",
"->",
"tableName",
".",
"'\").dataTable('",
".",
"\"\\n\"",
".",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"jsInitParameters",
")",
"?",
"PHPToJS",
"::",
"render",
"(",
"(",
"object",
")",
"$",
"this",
"->",
"jsInitParameters",
")",
":",
"''",
")",
".",
"\"\\n\"",
".",
"');'",
".",
"\"\\n\"",
";",
"$",
"js",
".=",
"$",
"this",
"->",
"getJavascriptSearchPart",
"(",
")",
";",
"return",
"$",
"js",
";",
"}"
]
| Return javascript string to activate table
@return string | [
"Return",
"javascript",
"string",
"to",
"activate",
"table"
]
| 41fc1e6d6fdcecd4870bb1683020f7b2de525685 | https://github.com/RobinDev/DataTablesPHP/blob/41fc1e6d6fdcecd4870bb1683020f7b2de525685/src/DataTable.php#L476-L489 | train |
RobinDev/DataTablesPHP | src/DataTable.php | DataTable.getJavascriptSearchPart | protected function getJavascriptSearchPart()
{
if (!$this->individualColumnFiltering) {
return '';
}
$js = 'var '.$this->tableName.'Api = '.$this->tableName.'.api(true);'."\n"
.'$("#'.$this->tableName.' tfoot th").each( function(colI) {'."\n"
.'$(".sSearch", this).on("keyup change", function (e) {'."\n"
.($this->isServerSide() ? ' if ( e.keyCode == 13 ) {'."\n" : '')
.' '.$this->tableName.'Api.column( colI ).search('
.' '.($this->renderFilterOperators ? '( this.tagName != "INPUT" || this.value == \'\' ? \'\' : $(this).prev().find("select").val()) + this.value ' : ' this.value ')
.' ).draw();'."\n"
.($this->isServerSide() ? ' }'."\n" : '')
.'});'."\n"
.'});'."\n";
return $js;
} | php | protected function getJavascriptSearchPart()
{
if (!$this->individualColumnFiltering) {
return '';
}
$js = 'var '.$this->tableName.'Api = '.$this->tableName.'.api(true);'."\n"
.'$("#'.$this->tableName.' tfoot th").each( function(colI) {'."\n"
.'$(".sSearch", this).on("keyup change", function (e) {'."\n"
.($this->isServerSide() ? ' if ( e.keyCode == 13 ) {'."\n" : '')
.' '.$this->tableName.'Api.column( colI ).search('
.' '.($this->renderFilterOperators ? '( this.tagName != "INPUT" || this.value == \'\' ? \'\' : $(this).prev().find("select").val()) + this.value ' : ' this.value ')
.' ).draw();'."\n"
.($this->isServerSide() ? ' }'."\n" : '')
.'});'."\n"
.'});'."\n";
return $js;
} | [
"protected",
"function",
"getJavascriptSearchPart",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"individualColumnFiltering",
")",
"{",
"return",
"''",
";",
"}",
"$",
"js",
"=",
"'var '",
".",
"$",
"this",
"->",
"tableName",
".",
"'Api = '",
".",
"$",
"this",
"->",
"tableName",
".",
"'.api(true);'",
".",
"\"\\n\"",
".",
"'$(\"#'",
".",
"$",
"this",
"->",
"tableName",
".",
"' tfoot th\").each( function(colI) {'",
".",
"\"\\n\"",
".",
"'$(\".sSearch\", this).on(\"keyup change\", function (e) {'",
".",
"\"\\n\"",
".",
"(",
"$",
"this",
"->",
"isServerSide",
"(",
")",
"?",
"' if ( e.keyCode == 13 ) {'",
".",
"\"\\n\"",
":",
"''",
")",
".",
"' '",
".",
"$",
"this",
"->",
"tableName",
".",
"'Api.column( colI ).search('",
".",
"' '",
".",
"(",
"$",
"this",
"->",
"renderFilterOperators",
"?",
"'( this.tagName != \"INPUT\" || this.value == \\'\\' ? \\'\\' : $(this).prev().find(\"select\").val()) + this.value '",
":",
"' this.value '",
")",
".",
"' ).draw();'",
".",
"\"\\n\"",
".",
"(",
"$",
"this",
"->",
"isServerSide",
"(",
")",
"?",
"' }'",
".",
"\"\\n\"",
":",
"''",
")",
".",
"'});'",
".",
"\"\\n\"",
".",
"'});'",
".",
"\"\\n\"",
";",
"return",
"$",
"js",
";",
"}"
]
| Generate the javascript relative to the individual column filtering
@return string | [
"Generate",
"the",
"javascript",
"relative",
"to",
"the",
"individual",
"column",
"filtering"
]
| 41fc1e6d6fdcecd4870bb1683020f7b2de525685 | https://github.com/RobinDev/DataTablesPHP/blob/41fc1e6d6fdcecd4870bb1683020f7b2de525685/src/DataTable.php#L496-L513 | train |
RobinDev/DataTablesPHP | src/DataTable.php | DataTable.formatOption | protected function formatOption($name, $value, $label)
{
return '<option value="'.$value.'"'
.(isset($this->filters[$name]) && strpos($this->filters[$name], $value) === 0 ? ' selected' : '')
.'>'.(isset($label) ? $label : $value).'</option>';
} | php | protected function formatOption($name, $value, $label)
{
return '<option value="'.$value.'"'
.(isset($this->filters[$name]) && strpos($this->filters[$name], $value) === 0 ? ' selected' : '')
.'>'.(isset($label) ? $label : $value).'</option>';
} | [
"protected",
"function",
"formatOption",
"(",
"$",
"name",
",",
"$",
"value",
",",
"$",
"label",
")",
"{",
"return",
"'<option value=\"'",
".",
"$",
"value",
".",
"'\"'",
".",
"(",
"isset",
"(",
"$",
"this",
"->",
"filters",
"[",
"$",
"name",
"]",
")",
"&&",
"strpos",
"(",
"$",
"this",
"->",
"filters",
"[",
"$",
"name",
"]",
",",
"$",
"value",
")",
"===",
"0",
"?",
"' selected'",
":",
"''",
")",
".",
"'>'",
".",
"(",
"isset",
"(",
"$",
"label",
")",
"?",
"$",
"label",
":",
"$",
"value",
")",
".",
"'</option>'",
";",
"}"
]
| Render option for select
@param string $name
@param string $value
@param string $label
@return string | [
"Render",
"option",
"for",
"select"
]
| 41fc1e6d6fdcecd4870bb1683020f7b2de525685 | https://github.com/RobinDev/DataTablesPHP/blob/41fc1e6d6fdcecd4870bb1683020f7b2de525685/src/DataTable.php#L560-L565 | train |
RobinDev/DataTablesPHP | src/DataTable.php | DataTable.setFrom | public function setFrom($table, $alias = null)
{
$this->table = $table;
$this->aliasTable = $alias === null ? $table : $alias;
return $this;
} | php | public function setFrom($table, $alias = null)
{
$this->table = $table;
$this->aliasTable = $alias === null ? $table : $alias;
return $this;
} | [
"public",
"function",
"setFrom",
"(",
"$",
"table",
",",
"$",
"alias",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"table",
"=",
"$",
"table",
";",
"$",
"this",
"->",
"aliasTable",
"=",
"$",
"alias",
"===",
"null",
"?",
"$",
"table",
":",
"$",
"alias",
";",
"return",
"$",
"this",
";",
"}"
]
| Set the mysql table to request
@param string $table
@param string $alias
@return self | [
"Set",
"the",
"mysql",
"table",
"to",
"request"
]
| 41fc1e6d6fdcecd4870bb1683020f7b2de525685 | https://github.com/RobinDev/DataTablesPHP/blob/41fc1e6d6fdcecd4870bb1683020f7b2de525685/src/DataTable.php#L670-L676 | train |
RobinDev/DataTablesPHP | src/DataTable.php | DataTable.setJoin | public function setJoin($table, $on, $join = 'LEFT JOIN', $duplicate = false)
{
$this->join[] = $join.' '.$table.' ON '.Helper::formatOn($on);
if ($duplicate !== false) {
$this->patchDuplicateRow['pKey'] = $duplicate[0];
if (is_array($duplicate[1])) {
$this->patchDuplicateRow['columns'] = isset($this->patchDuplicateRow['columns']) ? array_merge($this->patchDuplicateRow['columns'], $duplicate[1]) : $duplicate[1];
} else {
$this->patchDuplicateRow['columns'][] = $duplicate[1];
}
}
return $this;
} | php | public function setJoin($table, $on, $join = 'LEFT JOIN', $duplicate = false)
{
$this->join[] = $join.' '.$table.' ON '.Helper::formatOn($on);
if ($duplicate !== false) {
$this->patchDuplicateRow['pKey'] = $duplicate[0];
if (is_array($duplicate[1])) {
$this->patchDuplicateRow['columns'] = isset($this->patchDuplicateRow['columns']) ? array_merge($this->patchDuplicateRow['columns'], $duplicate[1]) : $duplicate[1];
} else {
$this->patchDuplicateRow['columns'][] = $duplicate[1];
}
}
return $this;
} | [
"public",
"function",
"setJoin",
"(",
"$",
"table",
",",
"$",
"on",
",",
"$",
"join",
"=",
"'LEFT JOIN'",
",",
"$",
"duplicate",
"=",
"false",
")",
"{",
"$",
"this",
"->",
"join",
"[",
"]",
"=",
"$",
"join",
".",
"' '",
".",
"$",
"table",
".",
"' ON '",
".",
"Helper",
"::",
"formatOn",
"(",
"$",
"on",
")",
";",
"if",
"(",
"$",
"duplicate",
"!==",
"false",
")",
"{",
"$",
"this",
"->",
"patchDuplicateRow",
"[",
"'pKey'",
"]",
"=",
"$",
"duplicate",
"[",
"0",
"]",
";",
"if",
"(",
"is_array",
"(",
"$",
"duplicate",
"[",
"1",
"]",
")",
")",
"{",
"$",
"this",
"->",
"patchDuplicateRow",
"[",
"'columns'",
"]",
"=",
"isset",
"(",
"$",
"this",
"->",
"patchDuplicateRow",
"[",
"'columns'",
"]",
")",
"?",
"array_merge",
"(",
"$",
"this",
"->",
"patchDuplicateRow",
"[",
"'columns'",
"]",
",",
"$",
"duplicate",
"[",
"1",
"]",
")",
":",
"$",
"duplicate",
"[",
"1",
"]",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"patchDuplicateRow",
"[",
"'columns'",
"]",
"[",
"]",
"=",
"$",
"duplicate",
"[",
"1",
"]",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
]
| Join data from other tables
@param string $table .
@param array $on Must contains two elements like key:sql_table => value:sql_column
@param string $join .
@param array $duplicate 0 Contain a column id... Generally the same that on ON
1 Contain column or columns
@return self | [
"Join",
"data",
"from",
"other",
"tables"
]
| 41fc1e6d6fdcecd4870bb1683020f7b2de525685 | https://github.com/RobinDev/DataTablesPHP/blob/41fc1e6d6fdcecd4870bb1683020f7b2de525685/src/DataTable.php#L689-L702 | train |
RobinDev/DataTablesPHP | src/DataTable.php | DataTable.setGroupBy | public function setGroupBy($column)
{
$this->groupBy = (isset($this->groupBy) ? $this->groupBy.',' : '').$column;
return $this;
} | php | public function setGroupBy($column)
{
$this->groupBy = (isset($this->groupBy) ? $this->groupBy.',' : '').$column;
return $this;
} | [
"public",
"function",
"setGroupBy",
"(",
"$",
"column",
")",
"{",
"$",
"this",
"->",
"groupBy",
"=",
"(",
"isset",
"(",
"$",
"this",
"->",
"groupBy",
")",
"?",
"$",
"this",
"->",
"groupBy",
".",
"','",
":",
"''",
")",
".",
"$",
"column",
";",
"return",
"$",
"this",
";",
"}"
]
| Group by a SQL column
@param string $column
@return self | [
"Group",
"by",
"a",
"SQL",
"column"
]
| 41fc1e6d6fdcecd4870bb1683020f7b2de525685 | https://github.com/RobinDev/DataTablesPHP/blob/41fc1e6d6fdcecd4870bb1683020f7b2de525685/src/DataTable.php#L711-L716 | train |
RobinDev/DataTablesPHP | src/DataTable.php | DataTable.initFilters | protected function initFilters()
{
$initColumnSearch = $this->initColumnSearch;
foreach ($this->columns as $c) {
if (isset($c['sqlFilter'])) {
$where_condition = $this->generateSQLColumnFilter($this->toSQLColumn($c, 2), $c['sqlFilter']);
if (!$this->setHaving($where_condition, $c)) {
$initColumnSearch[] = $this->generateSQLColumnFilter($this->toSQLColumn($c, 2), $c['sqlFilter']);
}
}
}
return implode(' AND ', $initColumnSearch);
} | php | protected function initFilters()
{
$initColumnSearch = $this->initColumnSearch;
foreach ($this->columns as $c) {
if (isset($c['sqlFilter'])) {
$where_condition = $this->generateSQLColumnFilter($this->toSQLColumn($c, 2), $c['sqlFilter']);
if (!$this->setHaving($where_condition, $c)) {
$initColumnSearch[] = $this->generateSQLColumnFilter($this->toSQLColumn($c, 2), $c['sqlFilter']);
}
}
}
return implode(' AND ', $initColumnSearch);
} | [
"protected",
"function",
"initFilters",
"(",
")",
"{",
"$",
"initColumnSearch",
"=",
"$",
"this",
"->",
"initColumnSearch",
";",
"foreach",
"(",
"$",
"this",
"->",
"columns",
"as",
"$",
"c",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"c",
"[",
"'sqlFilter'",
"]",
")",
")",
"{",
"$",
"where_condition",
"=",
"$",
"this",
"->",
"generateSQLColumnFilter",
"(",
"$",
"this",
"->",
"toSQLColumn",
"(",
"$",
"c",
",",
"2",
")",
",",
"$",
"c",
"[",
"'sqlFilter'",
"]",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"setHaving",
"(",
"$",
"where_condition",
",",
"$",
"c",
")",
")",
"{",
"$",
"initColumnSearch",
"[",
"]",
"=",
"$",
"this",
"->",
"generateSQLColumnFilter",
"(",
"$",
"this",
"->",
"toSQLColumn",
"(",
"$",
"c",
",",
"2",
")",
",",
"$",
"c",
"[",
"'sqlFilter'",
"]",
")",
";",
"}",
"}",
"}",
"return",
"implode",
"(",
"' AND '",
",",
"$",
"initColumnSearch",
")",
";",
"}"
]
| SQL Rendering for the initial filters set
@return string SQL Part Query | [
"SQL",
"Rendering",
"for",
"the",
"initial",
"filters",
"set"
]
| 41fc1e6d6fdcecd4870bb1683020f7b2de525685 | https://github.com/RobinDev/DataTablesPHP/blob/41fc1e6d6fdcecd4870bb1683020f7b2de525685/src/DataTable.php#L936-L949 | train |
RobinDev/DataTablesPHP | src/DataTable.php | DataTable.globalFilter | public function globalFilter()
{
$globalSearch = [];
if (isset($this->request['search']) && !empty($this->request['search']['value'])) {
for ($i = 0, $ien = count($this->request['columns']); $i<$ien; $i++) {
if (self::isSearchable($this->columns[$i])) {
$where_condition = $this->toSQLColumn($this->columns[$i], 2).' LIKE '.$this->pdoLink->quote('%'.$this->request['search']['value'].'%');
if (!$this->setHaving($where_condition, $this->columns[$i])) {
$globalSearch[] = $where_condition;
}
}
}
}
return empty($globalSearch) ? '' : '('.implode(' OR ', $globalSearch).')';
} | php | public function globalFilter()
{
$globalSearch = [];
if (isset($this->request['search']) && !empty($this->request['search']['value'])) {
for ($i = 0, $ien = count($this->request['columns']); $i<$ien; $i++) {
if (self::isSearchable($this->columns[$i])) {
$where_condition = $this->toSQLColumn($this->columns[$i], 2).' LIKE '.$this->pdoLink->quote('%'.$this->request['search']['value'].'%');
if (!$this->setHaving($where_condition, $this->columns[$i])) {
$globalSearch[] = $where_condition;
}
}
}
}
return empty($globalSearch) ? '' : '('.implode(' OR ', $globalSearch).')';
} | [
"public",
"function",
"globalFilter",
"(",
")",
"{",
"$",
"globalSearch",
"=",
"[",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"request",
"[",
"'search'",
"]",
")",
"&&",
"!",
"empty",
"(",
"$",
"this",
"->",
"request",
"[",
"'search'",
"]",
"[",
"'value'",
"]",
")",
")",
"{",
"for",
"(",
"$",
"i",
"=",
"0",
",",
"$",
"ien",
"=",
"count",
"(",
"$",
"this",
"->",
"request",
"[",
"'columns'",
"]",
")",
";",
"$",
"i",
"<",
"$",
"ien",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"self",
"::",
"isSearchable",
"(",
"$",
"this",
"->",
"columns",
"[",
"$",
"i",
"]",
")",
")",
"{",
"$",
"where_condition",
"=",
"$",
"this",
"->",
"toSQLColumn",
"(",
"$",
"this",
"->",
"columns",
"[",
"$",
"i",
"]",
",",
"2",
")",
".",
"' LIKE '",
".",
"$",
"this",
"->",
"pdoLink",
"->",
"quote",
"(",
"'%'",
".",
"$",
"this",
"->",
"request",
"[",
"'search'",
"]",
"[",
"'value'",
"]",
".",
"'%'",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"setHaving",
"(",
"$",
"where_condition",
",",
"$",
"this",
"->",
"columns",
"[",
"$",
"i",
"]",
")",
")",
"{",
"$",
"globalSearch",
"[",
"]",
"=",
"$",
"where_condition",
";",
"}",
"}",
"}",
"}",
"return",
"empty",
"(",
"$",
"globalSearch",
")",
"?",
"''",
":",
"'('",
".",
"implode",
"(",
"' OR '",
",",
"$",
"globalSearch",
")",
".",
"')'",
";",
"}"
]
| SQL Rendering for the global search
@return string SQL Part Query | [
"SQL",
"Rendering",
"for",
"the",
"global",
"search"
]
| 41fc1e6d6fdcecd4870bb1683020f7b2de525685 | https://github.com/RobinDev/DataTablesPHP/blob/41fc1e6d6fdcecd4870bb1683020f7b2de525685/src/DataTable.php#L956-L971 | train |
RobinDev/DataTablesPHP | src/DataTable.php | DataTable.individualColumnFilters | protected function individualColumnFilters()
{
$columnSearch = [];
if (isset($this->individualColumnFiltering)) {
$this->sRangeSeparator = isset($this->sRangeSeparator) ? $this->sRangeSeparator : '~';
for ($i = 0, $ien = count($this->columns); $i<$ien; $i++) {
if (self::isSearchable($this->columns[$i]) && !empty($this->request['columns'][$i]['search']['value'])) {
$search_value = trim($this->request['columns'][$i]['search']['value']);
$key = $this->toSQLColumn($this->columns[$i], 2, true);
$where_condition = $this->generateSQLColumnFilter($key, $search_value);
if (!$this->setHaving($where_condition, $this->columns[$i])) {
$columnSearch[] = $where_condition;
}
}
}
}
return implode(' AND ', $columnSearch);
} | php | protected function individualColumnFilters()
{
$columnSearch = [];
if (isset($this->individualColumnFiltering)) {
$this->sRangeSeparator = isset($this->sRangeSeparator) ? $this->sRangeSeparator : '~';
for ($i = 0, $ien = count($this->columns); $i<$ien; $i++) {
if (self::isSearchable($this->columns[$i]) && !empty($this->request['columns'][$i]['search']['value'])) {
$search_value = trim($this->request['columns'][$i]['search']['value']);
$key = $this->toSQLColumn($this->columns[$i], 2, true);
$where_condition = $this->generateSQLColumnFilter($key, $search_value);
if (!$this->setHaving($where_condition, $this->columns[$i])) {
$columnSearch[] = $where_condition;
}
}
}
}
return implode(' AND ', $columnSearch);
} | [
"protected",
"function",
"individualColumnFilters",
"(",
")",
"{",
"$",
"columnSearch",
"=",
"[",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"individualColumnFiltering",
")",
")",
"{",
"$",
"this",
"->",
"sRangeSeparator",
"=",
"isset",
"(",
"$",
"this",
"->",
"sRangeSeparator",
")",
"?",
"$",
"this",
"->",
"sRangeSeparator",
":",
"'~'",
";",
"for",
"(",
"$",
"i",
"=",
"0",
",",
"$",
"ien",
"=",
"count",
"(",
"$",
"this",
"->",
"columns",
")",
";",
"$",
"i",
"<",
"$",
"ien",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"self",
"::",
"isSearchable",
"(",
"$",
"this",
"->",
"columns",
"[",
"$",
"i",
"]",
")",
"&&",
"!",
"empty",
"(",
"$",
"this",
"->",
"request",
"[",
"'columns'",
"]",
"[",
"$",
"i",
"]",
"[",
"'search'",
"]",
"[",
"'value'",
"]",
")",
")",
"{",
"$",
"search_value",
"=",
"trim",
"(",
"$",
"this",
"->",
"request",
"[",
"'columns'",
"]",
"[",
"$",
"i",
"]",
"[",
"'search'",
"]",
"[",
"'value'",
"]",
")",
";",
"$",
"key",
"=",
"$",
"this",
"->",
"toSQLColumn",
"(",
"$",
"this",
"->",
"columns",
"[",
"$",
"i",
"]",
",",
"2",
",",
"true",
")",
";",
"$",
"where_condition",
"=",
"$",
"this",
"->",
"generateSQLColumnFilter",
"(",
"$",
"key",
",",
"$",
"search_value",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"setHaving",
"(",
"$",
"where_condition",
",",
"$",
"this",
"->",
"columns",
"[",
"$",
"i",
"]",
")",
")",
"{",
"$",
"columnSearch",
"[",
"]",
"=",
"$",
"where_condition",
";",
"}",
"}",
"}",
"}",
"return",
"implode",
"(",
"' AND '",
",",
"$",
"columnSearch",
")",
";",
"}"
]
| SQL Rendering for the invidividual column filters
@return string | [
"SQL",
"Rendering",
"for",
"the",
"invidividual",
"column",
"filters"
]
| 41fc1e6d6fdcecd4870bb1683020f7b2de525685 | https://github.com/RobinDev/DataTablesPHP/blob/41fc1e6d6fdcecd4870bb1683020f7b2de525685/src/DataTable.php#L978-L996 | train |
RobinDev/DataTablesPHP | src/DataTable.php | DataTable.toSQLColumn | protected function toSQLColumn($column, $onlyAlias = 0, $filter = false)
{
if (!isset($column['sql_name']) && !isset($column['data'])) {
self::sendFatal('Houston, we have a problem with one of your column : can\'t draw it SQL name because it don\'t have data or sql_name define.'."\n".json_encode($column));
}
if ($filter && isset($column['sFilter']) && isset($column['sFilter']['sql_name'])) {
return $this->toSQLColumn($column['sFilter'], $onlyAlias, false);
}
$quote = !isset($column['protect_sql']) || $column['protect_sql'] ? '`' : '';
// Alias ne correspondrait pas à Name ?!!!!
$table = isset($column['sql_table']) ? $column['sql_table'] : $this->aliasTable;
return $onlyAlias === 1 && isset($column['alias']) ?
$column['alias'] :
$quote.$table.$quote.(empty($table) ? '' : '.')
.$quote.(isset($column['sql_name']) ? $column['sql_name'] : $column['data']).$quote
.($onlyAlias === 0 && isset($column['alias']) ? ' AS '.$column['alias'] : '');
} | php | protected function toSQLColumn($column, $onlyAlias = 0, $filter = false)
{
if (!isset($column['sql_name']) && !isset($column['data'])) {
self::sendFatal('Houston, we have a problem with one of your column : can\'t draw it SQL name because it don\'t have data or sql_name define.'."\n".json_encode($column));
}
if ($filter && isset($column['sFilter']) && isset($column['sFilter']['sql_name'])) {
return $this->toSQLColumn($column['sFilter'], $onlyAlias, false);
}
$quote = !isset($column['protect_sql']) || $column['protect_sql'] ? '`' : '';
// Alias ne correspondrait pas à Name ?!!!!
$table = isset($column['sql_table']) ? $column['sql_table'] : $this->aliasTable;
return $onlyAlias === 1 && isset($column['alias']) ?
$column['alias'] :
$quote.$table.$quote.(empty($table) ? '' : '.')
.$quote.(isset($column['sql_name']) ? $column['sql_name'] : $column['data']).$quote
.($onlyAlias === 0 && isset($column['alias']) ? ' AS '.$column['alias'] : '');
} | [
"protected",
"function",
"toSQLColumn",
"(",
"$",
"column",
",",
"$",
"onlyAlias",
"=",
"0",
",",
"$",
"filter",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"column",
"[",
"'sql_name'",
"]",
")",
"&&",
"!",
"isset",
"(",
"$",
"column",
"[",
"'data'",
"]",
")",
")",
"{",
"self",
"::",
"sendFatal",
"(",
"'Houston, we have a problem with one of your column : can\\'t draw it SQL name because it don\\'t have data or sql_name define.'",
".",
"\"\\n\"",
".",
"json_encode",
"(",
"$",
"column",
")",
")",
";",
"}",
"if",
"(",
"$",
"filter",
"&&",
"isset",
"(",
"$",
"column",
"[",
"'sFilter'",
"]",
")",
"&&",
"isset",
"(",
"$",
"column",
"[",
"'sFilter'",
"]",
"[",
"'sql_name'",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"toSQLColumn",
"(",
"$",
"column",
"[",
"'sFilter'",
"]",
",",
"$",
"onlyAlias",
",",
"false",
")",
";",
"}",
"$",
"quote",
"=",
"!",
"isset",
"(",
"$",
"column",
"[",
"'protect_sql'",
"]",
")",
"||",
"$",
"column",
"[",
"'protect_sql'",
"]",
"?",
"'`'",
":",
"''",
";",
"// Alias ne correspondrait pas à Name ?!!!!",
"$",
"table",
"=",
"isset",
"(",
"$",
"column",
"[",
"'sql_table'",
"]",
")",
"?",
"$",
"column",
"[",
"'sql_table'",
"]",
":",
"$",
"this",
"->",
"aliasTable",
";",
"return",
"$",
"onlyAlias",
"===",
"1",
"&&",
"isset",
"(",
"$",
"column",
"[",
"'alias'",
"]",
")",
"?",
"$",
"column",
"[",
"'alias'",
"]",
":",
"$",
"quote",
".",
"$",
"table",
".",
"$",
"quote",
".",
"(",
"empty",
"(",
"$",
"table",
")",
"?",
"''",
":",
"'.'",
")",
".",
"$",
"quote",
".",
"(",
"isset",
"(",
"$",
"column",
"[",
"'sql_name'",
"]",
")",
"?",
"$",
"column",
"[",
"'sql_name'",
"]",
":",
"$",
"column",
"[",
"'data'",
"]",
")",
".",
"$",
"quote",
".",
"(",
"$",
"onlyAlias",
"===",
"0",
"&&",
"isset",
"(",
"$",
"column",
"[",
"'alias'",
"]",
")",
"?",
"' AS '",
".",
"$",
"column",
"[",
"'alias'",
"]",
":",
"''",
")",
";",
"}"
]
| Give a column's sql name
@param array $column
@param int $onlyAlias 0: return sql_table.sql_name AS alias
1: return alias
2: return sql_table.sql_name
@param bool $filter
@return string | [
"Give",
"a",
"column",
"s",
"sql",
"name"
]
| 41fc1e6d6fdcecd4870bb1683020f7b2de525685 | https://github.com/RobinDev/DataTablesPHP/blob/41fc1e6d6fdcecd4870bb1683020f7b2de525685/src/DataTable.php#L1081-L1100 | train |
RobinDev/DataTablesPHP | src/DataTable.php | DataTable.patchDuplicateRow | protected function patchDuplicateRow($d, $pKey, array $columns)
{
$id = $d[$pKey];
if (isset($this->rData[$id])) {
foreach ($columns as $c => $separator) {
$this->rData[$id][$c] .= $separator.$d[$c];
}
} else {
$this->rData[$id] = $d;
}
} | php | protected function patchDuplicateRow($d, $pKey, array $columns)
{
$id = $d[$pKey];
if (isset($this->rData[$id])) {
foreach ($columns as $c => $separator) {
$this->rData[$id][$c] .= $separator.$d[$c];
}
} else {
$this->rData[$id] = $d;
}
} | [
"protected",
"function",
"patchDuplicateRow",
"(",
"$",
"d",
",",
"$",
"pKey",
",",
"array",
"$",
"columns",
")",
"{",
"$",
"id",
"=",
"$",
"d",
"[",
"$",
"pKey",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"rData",
"[",
"$",
"id",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"columns",
"as",
"$",
"c",
"=>",
"$",
"separator",
")",
"{",
"$",
"this",
"->",
"rData",
"[",
"$",
"id",
"]",
"[",
"$",
"c",
"]",
".=",
"$",
"separator",
".",
"$",
"d",
"[",
"$",
"c",
"]",
";",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"rData",
"[",
"$",
"id",
"]",
"=",
"$",
"d",
";",
"}",
"}"
]
| To avoid duplicate row when LEFT JOIN if GROUP BY is not set
@param array $d
@param string $pKey
@param array $columns | [
"To",
"avoid",
"duplicate",
"row",
"when",
"LEFT",
"JOIN",
"if",
"GROUP",
"BY",
"is",
"not",
"set"
]
| 41fc1e6d6fdcecd4870bb1683020f7b2de525685 | https://github.com/RobinDev/DataTablesPHP/blob/41fc1e6d6fdcecd4870bb1683020f7b2de525685/src/DataTable.php#L1121-L1131 | train |
RobinDev/DataTablesPHP | src/DataTable.php | DataTable.exec | public function exec(array $request, $csv = false)
{
if ($csv) {
$this->request['length'] = -1;
}
$queries = $this->generateSQLRequest($request);
$this->addToSend('sqlQuery', $queries['data']);
$pdo = $this->pdoLink;
try {
$q = $pdo->query($queries['data']);
$this->rData = [];
// PATCH : Annoying JOIN wich duplicate row if there is different tag
if (isset($this->patchDuplicateRow)) {
while ($d = $q->fetch()) {
$this->patchDuplicateRow($d, $this->patchDuplicateRow['pKey'], $this->patchDuplicateRow['columns']);
}
} else {
$this->rData = $q ? $q->fetchAll() : [];
}
} catch (Exception $Exception) {
$this->sendFatal($pdo->errorInfo()[0].' - '.$pdo->errorInfo()[2].chr(10).$queries['data'], $this->toSend);
}
if ($csv) {
return self::sendCsv($this->rData);
}
if ($this->counters) {
try {
$q = $pdo->query($queries['recordsFiltered']);
} catch (Exception $Exception) {
$this->sendFatal($pdo->errorInfo()[0].' - '.$pdo->errorInfo()[2].chr(10).$queries['recordsFiltered'], $this->toSend);
}
$recordsFiltered = $q ? $q->fetch()['count'] : 0;
try {
$q = $pdo->query($queries['recordsTotal']);
} catch (Exception $Exception) {
$this->sendFatal($pdo->errorInfo()[0].' - '.$pdo->errorInfo()[2].chr(10).$queries['recordsTotal'], $this->toSend);
}
$recordsTotal = $q->fetch()['count'];
} else {
$recordsFiltered = $recordsTotal = 0;
}
$this->sendData($this->rData, $recordsFiltered, $recordsTotal);
} | php | public function exec(array $request, $csv = false)
{
if ($csv) {
$this->request['length'] = -1;
}
$queries = $this->generateSQLRequest($request);
$this->addToSend('sqlQuery', $queries['data']);
$pdo = $this->pdoLink;
try {
$q = $pdo->query($queries['data']);
$this->rData = [];
// PATCH : Annoying JOIN wich duplicate row if there is different tag
if (isset($this->patchDuplicateRow)) {
while ($d = $q->fetch()) {
$this->patchDuplicateRow($d, $this->patchDuplicateRow['pKey'], $this->patchDuplicateRow['columns']);
}
} else {
$this->rData = $q ? $q->fetchAll() : [];
}
} catch (Exception $Exception) {
$this->sendFatal($pdo->errorInfo()[0].' - '.$pdo->errorInfo()[2].chr(10).$queries['data'], $this->toSend);
}
if ($csv) {
return self::sendCsv($this->rData);
}
if ($this->counters) {
try {
$q = $pdo->query($queries['recordsFiltered']);
} catch (Exception $Exception) {
$this->sendFatal($pdo->errorInfo()[0].' - '.$pdo->errorInfo()[2].chr(10).$queries['recordsFiltered'], $this->toSend);
}
$recordsFiltered = $q ? $q->fetch()['count'] : 0;
try {
$q = $pdo->query($queries['recordsTotal']);
} catch (Exception $Exception) {
$this->sendFatal($pdo->errorInfo()[0].' - '.$pdo->errorInfo()[2].chr(10).$queries['recordsTotal'], $this->toSend);
}
$recordsTotal = $q->fetch()['count'];
} else {
$recordsFiltered = $recordsTotal = 0;
}
$this->sendData($this->rData, $recordsFiltered, $recordsTotal);
} | [
"public",
"function",
"exec",
"(",
"array",
"$",
"request",
",",
"$",
"csv",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"csv",
")",
"{",
"$",
"this",
"->",
"request",
"[",
"'length'",
"]",
"=",
"-",
"1",
";",
"}",
"$",
"queries",
"=",
"$",
"this",
"->",
"generateSQLRequest",
"(",
"$",
"request",
")",
";",
"$",
"this",
"->",
"addToSend",
"(",
"'sqlQuery'",
",",
"$",
"queries",
"[",
"'data'",
"]",
")",
";",
"$",
"pdo",
"=",
"$",
"this",
"->",
"pdoLink",
";",
"try",
"{",
"$",
"q",
"=",
"$",
"pdo",
"->",
"query",
"(",
"$",
"queries",
"[",
"'data'",
"]",
")",
";",
"$",
"this",
"->",
"rData",
"=",
"[",
"]",
";",
"// PATCH : Annoying JOIN wich duplicate row if there is different tag",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"patchDuplicateRow",
")",
")",
"{",
"while",
"(",
"$",
"d",
"=",
"$",
"q",
"->",
"fetch",
"(",
")",
")",
"{",
"$",
"this",
"->",
"patchDuplicateRow",
"(",
"$",
"d",
",",
"$",
"this",
"->",
"patchDuplicateRow",
"[",
"'pKey'",
"]",
",",
"$",
"this",
"->",
"patchDuplicateRow",
"[",
"'columns'",
"]",
")",
";",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"rData",
"=",
"$",
"q",
"?",
"$",
"q",
"->",
"fetchAll",
"(",
")",
":",
"[",
"]",
";",
"}",
"}",
"catch",
"(",
"Exception",
"$",
"Exception",
")",
"{",
"$",
"this",
"->",
"sendFatal",
"(",
"$",
"pdo",
"->",
"errorInfo",
"(",
")",
"[",
"0",
"]",
".",
"' - '",
".",
"$",
"pdo",
"->",
"errorInfo",
"(",
")",
"[",
"2",
"]",
".",
"chr",
"(",
"10",
")",
".",
"$",
"queries",
"[",
"'data'",
"]",
",",
"$",
"this",
"->",
"toSend",
")",
";",
"}",
"if",
"(",
"$",
"csv",
")",
"{",
"return",
"self",
"::",
"sendCsv",
"(",
"$",
"this",
"->",
"rData",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"counters",
")",
"{",
"try",
"{",
"$",
"q",
"=",
"$",
"pdo",
"->",
"query",
"(",
"$",
"queries",
"[",
"'recordsFiltered'",
"]",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"Exception",
")",
"{",
"$",
"this",
"->",
"sendFatal",
"(",
"$",
"pdo",
"->",
"errorInfo",
"(",
")",
"[",
"0",
"]",
".",
"' - '",
".",
"$",
"pdo",
"->",
"errorInfo",
"(",
")",
"[",
"2",
"]",
".",
"chr",
"(",
"10",
")",
".",
"$",
"queries",
"[",
"'recordsFiltered'",
"]",
",",
"$",
"this",
"->",
"toSend",
")",
";",
"}",
"$",
"recordsFiltered",
"=",
"$",
"q",
"?",
"$",
"q",
"->",
"fetch",
"(",
")",
"[",
"'count'",
"]",
":",
"0",
";",
"try",
"{",
"$",
"q",
"=",
"$",
"pdo",
"->",
"query",
"(",
"$",
"queries",
"[",
"'recordsTotal'",
"]",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"Exception",
")",
"{",
"$",
"this",
"->",
"sendFatal",
"(",
"$",
"pdo",
"->",
"errorInfo",
"(",
")",
"[",
"0",
"]",
".",
"' - '",
".",
"$",
"pdo",
"->",
"errorInfo",
"(",
")",
"[",
"2",
"]",
".",
"chr",
"(",
"10",
")",
".",
"$",
"queries",
"[",
"'recordsTotal'",
"]",
",",
"$",
"this",
"->",
"toSend",
")",
";",
"}",
"$",
"recordsTotal",
"=",
"$",
"q",
"->",
"fetch",
"(",
")",
"[",
"'count'",
"]",
";",
"}",
"else",
"{",
"$",
"recordsFiltered",
"=",
"$",
"recordsTotal",
"=",
"0",
";",
"}",
"$",
"this",
"->",
"sendData",
"(",
"$",
"this",
"->",
"rData",
",",
"$",
"recordsFiltered",
",",
"$",
"recordsTotal",
")",
";",
"}"
]
| Execute the ajax request and send the result in json
@param array $request ($_GET, $_POST...)
@param bool $csv
@return string Exit with the json result for Datatables.js | [
"Execute",
"the",
"ajax",
"request",
"and",
"send",
"the",
"result",
"in",
"json"
]
| 41fc1e6d6fdcecd4870bb1683020f7b2de525685 | https://github.com/RobinDev/DataTablesPHP/blob/41fc1e6d6fdcecd4870bb1683020f7b2de525685/src/DataTable.php#L1141-L1190 | train |
RobinDev/DataTablesPHP | src/DataTable.php | DataTable.sendData | protected function sendData($data, $recordsFiltered, $recordsTotal)
{
$toJson = array(
'draw' => intval($this->request['draw']),
'recordsTotal' => intval($recordsTotal),
'recordsFiltered' => intval($recordsFiltered),
'data' => $this->dataOutput($data), );
if (isset($this->toSend)) {
$toJson = array_merge($this->toSend, $toJson);
}
exit(json_encode($toJson));
} | php | protected function sendData($data, $recordsFiltered, $recordsTotal)
{
$toJson = array(
'draw' => intval($this->request['draw']),
'recordsTotal' => intval($recordsTotal),
'recordsFiltered' => intval($recordsFiltered),
'data' => $this->dataOutput($data), );
if (isset($this->toSend)) {
$toJson = array_merge($this->toSend, $toJson);
}
exit(json_encode($toJson));
} | [
"protected",
"function",
"sendData",
"(",
"$",
"data",
",",
"$",
"recordsFiltered",
",",
"$",
"recordsTotal",
")",
"{",
"$",
"toJson",
"=",
"array",
"(",
"'draw'",
"=>",
"intval",
"(",
"$",
"this",
"->",
"request",
"[",
"'draw'",
"]",
")",
",",
"'recordsTotal'",
"=>",
"intval",
"(",
"$",
"recordsTotal",
")",
",",
"'recordsFiltered'",
"=>",
"intval",
"(",
"$",
"recordsFiltered",
")",
",",
"'data'",
"=>",
"$",
"this",
"->",
"dataOutput",
"(",
"$",
"data",
")",
",",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"toSend",
")",
")",
"{",
"$",
"toJson",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"toSend",
",",
"$",
"toJson",
")",
";",
"}",
"exit",
"(",
"json_encode",
"(",
"$",
"toJson",
")",
")",
";",
"}"
]
| Send the json encoded result for DataTables.js
@param array $data
@param int $recordsFiltered
@param int $recordsTotal
@return json output | [
"Send",
"the",
"json",
"encoded",
"result",
"for",
"DataTables",
".",
"js"
]
| 41fc1e6d6fdcecd4870bb1683020f7b2de525685 | https://github.com/RobinDev/DataTablesPHP/blob/41fc1e6d6fdcecd4870bb1683020f7b2de525685/src/DataTable.php#L1216-L1227 | train |
RobinDev/DataTablesPHP | src/DataTable.php | DataTable.sendCsv | protected static function sendCsv($data)
{
header("Content-Disposition: attachment; filename=".uniqid('dataExpl').'.csv');
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header("Content-Description: File Transfer");
exit(Helper::arrayToCsv($data));
} | php | protected static function sendCsv($data)
{
header("Content-Disposition: attachment; filename=".uniqid('dataExpl').'.csv');
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header("Content-Description: File Transfer");
exit(Helper::arrayToCsv($data));
} | [
"protected",
"static",
"function",
"sendCsv",
"(",
"$",
"data",
")",
"{",
"header",
"(",
"\"Content-Disposition: attachment; filename=\"",
".",
"uniqid",
"(",
"'dataExpl'",
")",
".",
"'.csv'",
")",
";",
"header",
"(",
"\"Content-Type: application/force-download\"",
")",
";",
"header",
"(",
"\"Content-Type: application/octet-stream\"",
")",
";",
"header",
"(",
"\"Content-Type: application/download\"",
")",
";",
"header",
"(",
"\"Content-Description: File Transfer\"",
")",
";",
"exit",
"(",
"Helper",
"::",
"arrayToCsv",
"(",
"$",
"data",
")",
")",
";",
"}"
]
| Return the csv
@param array $data | [
"Return",
"the",
"csv"
]
| 41fc1e6d6fdcecd4870bb1683020f7b2de525685 | https://github.com/RobinDev/DataTablesPHP/blob/41fc1e6d6fdcecd4870bb1683020f7b2de525685/src/DataTable.php#L1234-L1242 | train |
RobinDev/DataTablesPHP | src/DataTable.php | DataTable.sendFatal | public static function sendFatal($error, $toSend = null)
{
$toJson = ['error' => utf8_encode($error)];
if (isset($toSend)) {
$toJson = array_merge($toSend, $toJson);
}
exit(json_encode($toJson));
} | php | public static function sendFatal($error, $toSend = null)
{
$toJson = ['error' => utf8_encode($error)];
if (isset($toSend)) {
$toJson = array_merge($toSend, $toJson);
}
exit(json_encode($toJson));
} | [
"public",
"static",
"function",
"sendFatal",
"(",
"$",
"error",
",",
"$",
"toSend",
"=",
"null",
")",
"{",
"$",
"toJson",
"=",
"[",
"'error'",
"=>",
"utf8_encode",
"(",
"$",
"error",
")",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"toSend",
")",
")",
"{",
"$",
"toJson",
"=",
"array_merge",
"(",
"$",
"toSend",
",",
"$",
"toJson",
")",
";",
"}",
"exit",
"(",
"json_encode",
"(",
"$",
"toJson",
")",
")",
";",
"}"
]
| Throw a fatal error.
This writes out an error message in a JSON string which DataTables will
see and show to the user in the browser.
@param string $error Message to send to the client
@param array $toSend Others informations to transfer | [
"Throw",
"a",
"fatal",
"error",
".",
"This",
"writes",
"out",
"an",
"error",
"message",
"in",
"a",
"JSON",
"string",
"which",
"DataTables",
"will",
"see",
"and",
"show",
"to",
"the",
"user",
"in",
"the",
"browser",
"."
]
| 41fc1e6d6fdcecd4870bb1683020f7b2de525685 | https://github.com/RobinDev/DataTablesPHP/blob/41fc1e6d6fdcecd4870bb1683020f7b2de525685/src/DataTable.php#L1252-L1260 | train |
duncan3dc/sessions | src/Session.php | Session.getInstance | public static function getInstance(): SessionInterface
{
if (static::$session instanceof SessionInterface) {
return static::$session;
}
if (strlen(static::$name) < 1) {
throw new \Exception("Cannot start session, no name has been specified, you must call Session::name() before using this class");
}
static::$session = new SessionInstance(static::$name);
return static::$session;
} | php | public static function getInstance(): SessionInterface
{
if (static::$session instanceof SessionInterface) {
return static::$session;
}
if (strlen(static::$name) < 1) {
throw new \Exception("Cannot start session, no name has been specified, you must call Session::name() before using this class");
}
static::$session = new SessionInstance(static::$name);
return static::$session;
} | [
"public",
"static",
"function",
"getInstance",
"(",
")",
":",
"SessionInterface",
"{",
"if",
"(",
"static",
"::",
"$",
"session",
"instanceof",
"SessionInterface",
")",
"{",
"return",
"static",
"::",
"$",
"session",
";",
"}",
"if",
"(",
"strlen",
"(",
"static",
"::",
"$",
"name",
")",
"<",
"1",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Cannot start session, no name has been specified, you must call Session::name() before using this class\"",
")",
";",
"}",
"static",
"::",
"$",
"session",
"=",
"new",
"SessionInstance",
"(",
"static",
"::",
"$",
"name",
")",
";",
"return",
"static",
"::",
"$",
"session",
";",
"}"
]
| Ensure the session instance has been created.
@return SessionInterface | [
"Ensure",
"the",
"session",
"instance",
"has",
"been",
"created",
"."
]
| 7ff0b18a5ed9df6aadc953416015cd447cebdc71 | https://github.com/duncan3dc/sessions/blob/7ff0b18a5ed9df6aadc953416015cd447cebdc71/src/Session.php#L55-L68 | train |
duncan3dc/sessions | src/SessionNamespace.php | SessionNamespace.createNamespace | public function createNamespace(string $name): SessionInterface
{
$name = $this->getNamespacedKey($name);
return new SessionNamespace($name, $this->session);
} | php | public function createNamespace(string $name): SessionInterface
{
$name = $this->getNamespacedKey($name);
return new SessionNamespace($name, $this->session);
} | [
"public",
"function",
"createNamespace",
"(",
"string",
"$",
"name",
")",
":",
"SessionInterface",
"{",
"$",
"name",
"=",
"$",
"this",
"->",
"getNamespacedKey",
"(",
"$",
"name",
")",
";",
"return",
"new",
"SessionNamespace",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"session",
")",
";",
"}"
]
| Create a new namespaced section of this session to avoid clashes.
@param string $name The namespace of the session
@return SessionInterface | [
"Create",
"a",
"new",
"namespaced",
"section",
"of",
"this",
"session",
"to",
"avoid",
"clashes",
"."
]
| 7ff0b18a5ed9df6aadc953416015cd447cebdc71 | https://github.com/duncan3dc/sessions/blob/7ff0b18a5ed9df6aadc953416015cd447cebdc71/src/SessionNamespace.php#L67-L71 | train |
duncan3dc/sessions | src/SessionNamespace.php | SessionNamespace.getAll | public function getAll(): array
{
$namespace = $this->getNamespace();
$length = mb_strlen($namespace);
$values = [];
$data = $this->session->getAll();
foreach ($data as $key => $val) {
if (mb_substr($key, 0, $length) === $namespace) {
$key = mb_substr($key, $length);
$values[$key] = $val;
}
}
return $values;
} | php | public function getAll(): array
{
$namespace = $this->getNamespace();
$length = mb_strlen($namespace);
$values = [];
$data = $this->session->getAll();
foreach ($data as $key => $val) {
if (mb_substr($key, 0, $length) === $namespace) {
$key = mb_substr($key, $length);
$values[$key] = $val;
}
}
return $values;
} | [
"public",
"function",
"getAll",
"(",
")",
":",
"array",
"{",
"$",
"namespace",
"=",
"$",
"this",
"->",
"getNamespace",
"(",
")",
";",
"$",
"length",
"=",
"mb_strlen",
"(",
"$",
"namespace",
")",
";",
"$",
"values",
"=",
"[",
"]",
";",
"$",
"data",
"=",
"$",
"this",
"->",
"session",
"->",
"getAll",
"(",
")",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"if",
"(",
"mb_substr",
"(",
"$",
"key",
",",
"0",
",",
"$",
"length",
")",
"===",
"$",
"namespace",
")",
"{",
"$",
"key",
"=",
"mb_substr",
"(",
"$",
"key",
",",
"$",
"length",
")",
";",
"$",
"values",
"[",
"$",
"key",
"]",
"=",
"$",
"val",
";",
"}",
"}",
"return",
"$",
"values",
";",
"}"
]
| Get all the current session data.
@return array | [
"Get",
"all",
"the",
"current",
"session",
"data",
"."
]
| 7ff0b18a5ed9df6aadc953416015cd447cebdc71 | https://github.com/duncan3dc/sessions/blob/7ff0b18a5ed9df6aadc953416015cd447cebdc71/src/SessionNamespace.php#L94-L110 | train |
letrunghieu/active | src/Active.php | Active.updateInstances | public function updateInstances($route, $request)
{
$this->request = $request;
if ($request) {
$this->uri = urldecode($request->path());
}
$this->route = $route;
if ($route) {
$this->action = $route->getActionName();
$actionSegments = Str::parseCallback($this->action, null);
$this->controller = head($actionSegments);
$this->method = last($actionSegments);
}
} | php | public function updateInstances($route, $request)
{
$this->request = $request;
if ($request) {
$this->uri = urldecode($request->path());
}
$this->route = $route;
if ($route) {
$this->action = $route->getActionName();
$actionSegments = Str::parseCallback($this->action, null);
$this->controller = head($actionSegments);
$this->method = last($actionSegments);
}
} | [
"public",
"function",
"updateInstances",
"(",
"$",
"route",
",",
"$",
"request",
")",
"{",
"$",
"this",
"->",
"request",
"=",
"$",
"request",
";",
"if",
"(",
"$",
"request",
")",
"{",
"$",
"this",
"->",
"uri",
"=",
"urldecode",
"(",
"$",
"request",
"->",
"path",
"(",
")",
")",
";",
"}",
"$",
"this",
"->",
"route",
"=",
"$",
"route",
";",
"if",
"(",
"$",
"route",
")",
"{",
"$",
"this",
"->",
"action",
"=",
"$",
"route",
"->",
"getActionName",
"(",
")",
";",
"$",
"actionSegments",
"=",
"Str",
"::",
"parseCallback",
"(",
"$",
"this",
"->",
"action",
",",
"null",
")",
";",
"$",
"this",
"->",
"controller",
"=",
"head",
"(",
"$",
"actionSegments",
")",
";",
"$",
"this",
"->",
"method",
"=",
"last",
"(",
"$",
"actionSegments",
")",
";",
"}",
"}"
]
| Update the route and request instances
@param Route $route
@param Request $request | [
"Update",
"the",
"route",
"and",
"request",
"instances"
]
| 42d0f50be74b89d730bb4c0ee8c32447630506c6 | https://github.com/letrunghieu/active/blob/42d0f50be74b89d730bb4c0ee8c32447630506c6/src/Active.php#L87-L102 | train |
letrunghieu/active | src/Active.php | Active.checkUri | public function checkUri($uris)
{
if (!$this->request) {
return false;
}
foreach ((array)$uris as $uri) {
if ($this->uri == $uri) {
return true;
}
}
return false;
} | php | public function checkUri($uris)
{
if (!$this->request) {
return false;
}
foreach ((array)$uris as $uri) {
if ($this->uri == $uri) {
return true;
}
}
return false;
} | [
"public",
"function",
"checkUri",
"(",
"$",
"uris",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"request",
")",
"{",
"return",
"false",
";",
"}",
"foreach",
"(",
"(",
"array",
")",
"$",
"uris",
"as",
"$",
"uri",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"uri",
"==",
"$",
"uri",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
]
| Check if the URI of the current request matches one of the specific URIs
@param array|string $uris
@return bool | [
"Check",
"if",
"the",
"URI",
"of",
"the",
"current",
"request",
"matches",
"one",
"of",
"the",
"specific",
"URIs"
]
| 42d0f50be74b89d730bb4c0ee8c32447630506c6 | https://github.com/letrunghieu/active/blob/42d0f50be74b89d730bb4c0ee8c32447630506c6/src/Active.php#L125-L138 | train |
letrunghieu/active | src/Active.php | Active.checkRoute | public function checkRoute($routeNames)
{
if (!$this->route) {
return false;
}
$routeName = $this->route->getName();
if (in_array($routeName, (array)$routeNames)) {
return true;
}
return false;
} | php | public function checkRoute($routeNames)
{
if (!$this->route) {
return false;
}
$routeName = $this->route->getName();
if (in_array($routeName, (array)$routeNames)) {
return true;
}
return false;
} | [
"public",
"function",
"checkRoute",
"(",
"$",
"routeNames",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"route",
")",
"{",
"return",
"false",
";",
"}",
"$",
"routeName",
"=",
"$",
"this",
"->",
"route",
"->",
"getName",
"(",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"routeName",
",",
"(",
"array",
")",
"$",
"routeNames",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
]
| Check if the name of the current route matches one of specific values
@param array|string $routeNames
@return bool | [
"Check",
"if",
"the",
"name",
"of",
"the",
"current",
"route",
"matches",
"one",
"of",
"specific",
"values"
]
| 42d0f50be74b89d730bb4c0ee8c32447630506c6 | https://github.com/letrunghieu/active/blob/42d0f50be74b89d730bb4c0ee8c32447630506c6/src/Active.php#L201-L214 | train |
letrunghieu/active | src/Active.php | Active.checkRoutePattern | public function checkRoutePattern($patterns)
{
if (!$this->route) {
return false;
}
$routeName = $this->route->getName();
if ($routeName == null) {
return in_array(null, $patterns);
}
foreach ((array)$patterns as $p) {
if (str_is($p, $routeName)) {
return true;
}
}
return false;
} | php | public function checkRoutePattern($patterns)
{
if (!$this->route) {
return false;
}
$routeName = $this->route->getName();
if ($routeName == null) {
return in_array(null, $patterns);
}
foreach ((array)$patterns as $p) {
if (str_is($p, $routeName)) {
return true;
}
}
return false;
} | [
"public",
"function",
"checkRoutePattern",
"(",
"$",
"patterns",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"route",
")",
"{",
"return",
"false",
";",
"}",
"$",
"routeName",
"=",
"$",
"this",
"->",
"route",
"->",
"getName",
"(",
")",
";",
"if",
"(",
"$",
"routeName",
"==",
"null",
")",
"{",
"return",
"in_array",
"(",
"null",
",",
"$",
"patterns",
")",
";",
"}",
"foreach",
"(",
"(",
"array",
")",
"$",
"patterns",
"as",
"$",
"p",
")",
"{",
"if",
"(",
"str_is",
"(",
"$",
"p",
",",
"$",
"routeName",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
]
| Check the current route name with one or some patterns
@param array|string $patterns
@return bool | [
"Check",
"the",
"current",
"route",
"name",
"with",
"one",
"or",
"some",
"patterns"
]
| 42d0f50be74b89d730bb4c0ee8c32447630506c6 | https://github.com/letrunghieu/active/blob/42d0f50be74b89d730bb4c0ee8c32447630506c6/src/Active.php#L223-L242 | train |
letrunghieu/active | src/Active.php | Active.checkRouteParam | public function checkRouteParam($param, $value)
{
if (!$this->route) {
return false;
}
$paramValue = $this->route->parameter($param);
// If the parameter value is an instance of Model class, we compare $value with the value of
// its primary key.
if (is_a($paramValue, Model::class)) {
return $paramValue->{$paramValue->getKeyName()} == $value;
}
return $paramValue == $value;
} | php | public function checkRouteParam($param, $value)
{
if (!$this->route) {
return false;
}
$paramValue = $this->route->parameter($param);
// If the parameter value is an instance of Model class, we compare $value with the value of
// its primary key.
if (is_a($paramValue, Model::class)) {
return $paramValue->{$paramValue->getKeyName()} == $value;
}
return $paramValue == $value;
} | [
"public",
"function",
"checkRouteParam",
"(",
"$",
"param",
",",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"route",
")",
"{",
"return",
"false",
";",
"}",
"$",
"paramValue",
"=",
"$",
"this",
"->",
"route",
"->",
"parameter",
"(",
"$",
"param",
")",
";",
"// If the parameter value is an instance of Model class, we compare $value with the value of",
"// its primary key.",
"if",
"(",
"is_a",
"(",
"$",
"paramValue",
",",
"Model",
"::",
"class",
")",
")",
"{",
"return",
"$",
"paramValue",
"->",
"{",
"$",
"paramValue",
"->",
"getKeyName",
"(",
")",
"}",
"==",
"$",
"value",
";",
"}",
"return",
"$",
"paramValue",
"==",
"$",
"value",
";",
"}"
]
| Check if the parameter of the current route has the correct value
@param $param
@param $value
@return bool | [
"Check",
"if",
"the",
"parameter",
"of",
"the",
"current",
"route",
"has",
"the",
"correct",
"value"
]
| 42d0f50be74b89d730bb4c0ee8c32447630506c6 | https://github.com/letrunghieu/active/blob/42d0f50be74b89d730bb4c0ee8c32447630506c6/src/Active.php#L252-L267 | train |
letrunghieu/active | src/Active.php | Active.checkAction | public function checkAction($actions)
{
if (!$this->action) {
return false;
}
if (in_array($this->action, (array)$actions)) {
return true;
}
return false;
} | php | public function checkAction($actions)
{
if (!$this->action) {
return false;
}
if (in_array($this->action, (array)$actions)) {
return true;
}
return false;
} | [
"public",
"function",
"checkAction",
"(",
"$",
"actions",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"action",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"in_array",
"(",
"$",
"this",
"->",
"action",
",",
"(",
"array",
")",
"$",
"actions",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
]
| Return 'active' class if current route action match one of provided action names
@param array|string $actions
@return bool | [
"Return",
"active",
"class",
"if",
"current",
"route",
"action",
"match",
"one",
"of",
"provided",
"action",
"names"
]
| 42d0f50be74b89d730bb4c0ee8c32447630506c6 | https://github.com/letrunghieu/active/blob/42d0f50be74b89d730bb4c0ee8c32447630506c6/src/Active.php#L276-L287 | train |
letrunghieu/active | src/Active.php | Active.checkController | public function checkController($controllers)
{
if (!$this->controller) {
return false;
}
if (in_array($this->controller, (array)$controllers)) {
return true;
}
return false;
} | php | public function checkController($controllers)
{
if (!$this->controller) {
return false;
}
if (in_array($this->controller, (array)$controllers)) {
return true;
}
return false;
} | [
"public",
"function",
"checkController",
"(",
"$",
"controllers",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"controller",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"in_array",
"(",
"$",
"this",
"->",
"controller",
",",
"(",
"array",
")",
"$",
"controllers",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
]
| Check if the current controller class matches one of specific values
@param array|string $controllers
@return bool | [
"Check",
"if",
"the",
"current",
"controller",
"class",
"matches",
"one",
"of",
"specific",
"values"
]
| 42d0f50be74b89d730bb4c0ee8c32447630506c6 | https://github.com/letrunghieu/active/blob/42d0f50be74b89d730bb4c0ee8c32447630506c6/src/Active.php#L296-L307 | train |
ContaoDMS/dms | system/modules/DocumentManagementSystem/classes/pojos/Document.php | Document.getFileNameVersioned | public function getFileNameVersioned()
{
return static::buildFileNameVersioned($this->strFileName, static::getVersionForFileName($this->intVersionMajor, $this->intVersionMinor, $this->intVersionPatch), $this->strFileType);
} | php | public function getFileNameVersioned()
{
return static::buildFileNameVersioned($this->strFileName, static::getVersionForFileName($this->intVersionMajor, $this->intVersionMinor, $this->intVersionPatch), $this->strFileType);
} | [
"public",
"function",
"getFileNameVersioned",
"(",
")",
"{",
"return",
"static",
"::",
"buildFileNameVersioned",
"(",
"$",
"this",
"->",
"strFileName",
",",
"static",
"::",
"getVersionForFileName",
"(",
"$",
"this",
"->",
"intVersionMajor",
",",
"$",
"this",
"->",
"intVersionMinor",
",",
"$",
"this",
"->",
"intVersionPatch",
")",
",",
"$",
"this",
"->",
"strFileType",
")",
";",
"}"
]
| Return the complete versioned filename string for this document.
@return string The complete versioned filename string for this document. | [
"Return",
"the",
"complete",
"versioned",
"filename",
"string",
"for",
"this",
"document",
"."
]
| dd6856ac87fdc7fc93dc6274fad678e416712059 | https://github.com/ContaoDMS/dms/blob/dd6856ac87fdc7fc93dc6274fad678e416712059/system/modules/DocumentManagementSystem/classes/pojos/Document.php#L306-L309 | train |
ContaoDMS/dms | system/modules/DocumentManagementSystem/classes/pojos/Document.php | Document.getFileSize | public function getFileSize($strUnit, $blnFormatted = false)
{
$doubleFileSize = \Document::convertFileSize($this->intFileSize, self::FILE_SIZE_UNIT_BYTE, $strUnit);
if ($doubleFileSize < 0)
{
throw new \Exception(sprintf('Invalid file size [%s] or unit [%s] for document.', $this->intFileSize, $strKey));
}
if ($blnFormatted)
{
return \Document::formatFileSize($doubleFileSize, $strUnit);
}
return $doubleFileSize;
} | php | public function getFileSize($strUnit, $blnFormatted = false)
{
$doubleFileSize = \Document::convertFileSize($this->intFileSize, self::FILE_SIZE_UNIT_BYTE, $strUnit);
if ($doubleFileSize < 0)
{
throw new \Exception(sprintf('Invalid file size [%s] or unit [%s] for document.', $this->intFileSize, $strKey));
}
if ($blnFormatted)
{
return \Document::formatFileSize($doubleFileSize, $strUnit);
}
return $doubleFileSize;
} | [
"public",
"function",
"getFileSize",
"(",
"$",
"strUnit",
",",
"$",
"blnFormatted",
"=",
"false",
")",
"{",
"$",
"doubleFileSize",
"=",
"\\",
"Document",
"::",
"convertFileSize",
"(",
"$",
"this",
"->",
"intFileSize",
",",
"self",
"::",
"FILE_SIZE_UNIT_BYTE",
",",
"$",
"strUnit",
")",
";",
"if",
"(",
"$",
"doubleFileSize",
"<",
"0",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"sprintf",
"(",
"'Invalid file size [%s] or unit [%s] for document.'",
",",
"$",
"this",
"->",
"intFileSize",
",",
"$",
"strKey",
")",
")",
";",
"}",
"if",
"(",
"$",
"blnFormatted",
")",
"{",
"return",
"\\",
"Document",
"::",
"formatFileSize",
"(",
"$",
"doubleFileSize",
",",
"$",
"strUnit",
")",
";",
"}",
"return",
"$",
"doubleFileSize",
";",
"}"
]
| Return the file size for the given unit.
@param string $strUnit The file size unit.
@param bool $blnFormatted True if the file size should be returned as formatted string (with unit).
@return mixed The file size for the given unit (as int or formatted as string). | [
"Return",
"the",
"file",
"size",
"for",
"the",
"given",
"unit",
"."
]
| dd6856ac87fdc7fc93dc6274fad678e416712059 | https://github.com/ContaoDMS/dms/blob/dd6856ac87fdc7fc93dc6274fad678e416712059/system/modules/DocumentManagementSystem/classes/pojos/Document.php#L318-L332 | train |
ContaoDMS/dms | system/modules/DocumentManagementSystem/classes/pojos/Document.php | Document.convertFileSize | public static function convertFileSize($doubleFileSize, $strSourceUnit, $strTargetUnit)
{
if ($strSourceUnit == $strTargetUnit)
{
// no conversion needed
return $doubleFileSize;
}
if ($strSourceUnit == \Document::FILE_SIZE_UNIT_BYTE)
{
switch ($strTargetUnit)
{
case \Document::FILE_SIZE_UNIT_KB : return $doubleFileSize / 1024;
case \Document::FILE_SIZE_UNIT_MB : return $doubleFileSize / 1024 / 1024;
case \Document::FILE_SIZE_UNIT_GB : return $doubleFileSize / 1024 / 1024 / 1024;
}
}
else if ($strSourceUnit == \Document::FILE_SIZE_UNIT_KB)
{
switch ($strTargetUnit)
{
case \Document::FILE_SIZE_UNIT_BYTE : return $doubleFileSize * 1024;
case \Document::FILE_SIZE_UNIT_MB : return $doubleFileSize / 1024;
case \Document::FILE_SIZE_UNIT_GB : return $doubleFileSize / 1024 / 1024;
}
}
else if ($strSourceUnit == \Document::FILE_SIZE_UNIT_MB)
{
switch ($strTargetUnit)
{
case \Document::FILE_SIZE_UNIT_BYTE : return $doubleFileSize * 1024 * 1024;
case \Document::FILE_SIZE_UNIT_KB : return $doubleFileSize * 1024;
case \Document::FILE_SIZE_UNIT_GB : return $doubleFileSize / 1024;
}
}
else if ($strSourceUnit == \Document::FILE_SIZE_UNIT_GB)
{
switch ($strTargetUnit)
{
case \Document::FILE_SIZE_UNIT_BYTE : return $doubleFileSize * 1024 * 1024 * 1024;
case \Document::FILE_SIZE_UNIT_KB : return $doubleFileSize * 1024 * 1024;
case \Document::FILE_SIZE_UNIT_MB : return $doubleFileSize * 1024;
}
}
// no match
return -1;
} | php | public static function convertFileSize($doubleFileSize, $strSourceUnit, $strTargetUnit)
{
if ($strSourceUnit == $strTargetUnit)
{
// no conversion needed
return $doubleFileSize;
}
if ($strSourceUnit == \Document::FILE_SIZE_UNIT_BYTE)
{
switch ($strTargetUnit)
{
case \Document::FILE_SIZE_UNIT_KB : return $doubleFileSize / 1024;
case \Document::FILE_SIZE_UNIT_MB : return $doubleFileSize / 1024 / 1024;
case \Document::FILE_SIZE_UNIT_GB : return $doubleFileSize / 1024 / 1024 / 1024;
}
}
else if ($strSourceUnit == \Document::FILE_SIZE_UNIT_KB)
{
switch ($strTargetUnit)
{
case \Document::FILE_SIZE_UNIT_BYTE : return $doubleFileSize * 1024;
case \Document::FILE_SIZE_UNIT_MB : return $doubleFileSize / 1024;
case \Document::FILE_SIZE_UNIT_GB : return $doubleFileSize / 1024 / 1024;
}
}
else if ($strSourceUnit == \Document::FILE_SIZE_UNIT_MB)
{
switch ($strTargetUnit)
{
case \Document::FILE_SIZE_UNIT_BYTE : return $doubleFileSize * 1024 * 1024;
case \Document::FILE_SIZE_UNIT_KB : return $doubleFileSize * 1024;
case \Document::FILE_SIZE_UNIT_GB : return $doubleFileSize / 1024;
}
}
else if ($strSourceUnit == \Document::FILE_SIZE_UNIT_GB)
{
switch ($strTargetUnit)
{
case \Document::FILE_SIZE_UNIT_BYTE : return $doubleFileSize * 1024 * 1024 * 1024;
case \Document::FILE_SIZE_UNIT_KB : return $doubleFileSize * 1024 * 1024;
case \Document::FILE_SIZE_UNIT_MB : return $doubleFileSize * 1024;
}
}
// no match
return -1;
} | [
"public",
"static",
"function",
"convertFileSize",
"(",
"$",
"doubleFileSize",
",",
"$",
"strSourceUnit",
",",
"$",
"strTargetUnit",
")",
"{",
"if",
"(",
"$",
"strSourceUnit",
"==",
"$",
"strTargetUnit",
")",
"{",
"// no conversion needed",
"return",
"$",
"doubleFileSize",
";",
"}",
"if",
"(",
"$",
"strSourceUnit",
"==",
"\\",
"Document",
"::",
"FILE_SIZE_UNIT_BYTE",
")",
"{",
"switch",
"(",
"$",
"strTargetUnit",
")",
"{",
"case",
"\\",
"Document",
"::",
"FILE_SIZE_UNIT_KB",
":",
"return",
"$",
"doubleFileSize",
"/",
"1024",
";",
"case",
"\\",
"Document",
"::",
"FILE_SIZE_UNIT_MB",
":",
"return",
"$",
"doubleFileSize",
"/",
"1024",
"/",
"1024",
";",
"case",
"\\",
"Document",
"::",
"FILE_SIZE_UNIT_GB",
":",
"return",
"$",
"doubleFileSize",
"/",
"1024",
"/",
"1024",
"/",
"1024",
";",
"}",
"}",
"else",
"if",
"(",
"$",
"strSourceUnit",
"==",
"\\",
"Document",
"::",
"FILE_SIZE_UNIT_KB",
")",
"{",
"switch",
"(",
"$",
"strTargetUnit",
")",
"{",
"case",
"\\",
"Document",
"::",
"FILE_SIZE_UNIT_BYTE",
":",
"return",
"$",
"doubleFileSize",
"*",
"1024",
";",
"case",
"\\",
"Document",
"::",
"FILE_SIZE_UNIT_MB",
":",
"return",
"$",
"doubleFileSize",
"/",
"1024",
";",
"case",
"\\",
"Document",
"::",
"FILE_SIZE_UNIT_GB",
":",
"return",
"$",
"doubleFileSize",
"/",
"1024",
"/",
"1024",
";",
"}",
"}",
"else",
"if",
"(",
"$",
"strSourceUnit",
"==",
"\\",
"Document",
"::",
"FILE_SIZE_UNIT_MB",
")",
"{",
"switch",
"(",
"$",
"strTargetUnit",
")",
"{",
"case",
"\\",
"Document",
"::",
"FILE_SIZE_UNIT_BYTE",
":",
"return",
"$",
"doubleFileSize",
"*",
"1024",
"*",
"1024",
";",
"case",
"\\",
"Document",
"::",
"FILE_SIZE_UNIT_KB",
":",
"return",
"$",
"doubleFileSize",
"*",
"1024",
";",
"case",
"\\",
"Document",
"::",
"FILE_SIZE_UNIT_GB",
":",
"return",
"$",
"doubleFileSize",
"/",
"1024",
";",
"}",
"}",
"else",
"if",
"(",
"$",
"strSourceUnit",
"==",
"\\",
"Document",
"::",
"FILE_SIZE_UNIT_GB",
")",
"{",
"switch",
"(",
"$",
"strTargetUnit",
")",
"{",
"case",
"\\",
"Document",
"::",
"FILE_SIZE_UNIT_BYTE",
":",
"return",
"$",
"doubleFileSize",
"*",
"1024",
"*",
"1024",
"*",
"1024",
";",
"case",
"\\",
"Document",
"::",
"FILE_SIZE_UNIT_KB",
":",
"return",
"$",
"doubleFileSize",
"*",
"1024",
"*",
"1024",
";",
"case",
"\\",
"Document",
"::",
"FILE_SIZE_UNIT_MB",
":",
"return",
"$",
"doubleFileSize",
"*",
"1024",
";",
"}",
"}",
"// no match",
"return",
"-",
"1",
";",
"}"
]
| Utility function to convert file size from a source unit into a target unit.
@param double $doubleFileSize The file size value.
@param string $strSourceUnit The source unit of the file size.
@param string $strTargetUnit The target unit of the file size.
@return double The converted file size value. | [
"Utility",
"function",
"to",
"convert",
"file",
"size",
"from",
"a",
"source",
"unit",
"into",
"a",
"target",
"unit",
"."
]
| dd6856ac87fdc7fc93dc6274fad678e416712059 | https://github.com/ContaoDMS/dms/blob/dd6856ac87fdc7fc93dc6274fad678e416712059/system/modules/DocumentManagementSystem/classes/pojos/Document.php#L342-L388 | train |
ContaoDMS/dms | system/modules/DocumentManagementSystem/classes/pojos/Document.php | Document.formatFileSize | public static function formatFileSize($doubleFileSize, $strUnit)
{
$value = number_format($doubleFileSize, 2, $GLOBALS['TL_LANG']['DMS']['file_size_format']['dec_point'], $GLOBALS['TL_LANG']['DMS']['file_size_format']['$thousands_sep']);
if (substr($value, -3) == ($GLOBALS['TL_LANG']['DMS']['file_size_format']['dec_point'] . "00"))
{
$value = substr($value, 0, - 3);
}
return sprintf($GLOBALS['TL_LANG']['DMS']['file_size_format']['text'], $value, $GLOBALS['TL_LANG']['DMS']['file_size_unit'][$strUnit]);
} | php | public static function formatFileSize($doubleFileSize, $strUnit)
{
$value = number_format($doubleFileSize, 2, $GLOBALS['TL_LANG']['DMS']['file_size_format']['dec_point'], $GLOBALS['TL_LANG']['DMS']['file_size_format']['$thousands_sep']);
if (substr($value, -3) == ($GLOBALS['TL_LANG']['DMS']['file_size_format']['dec_point'] . "00"))
{
$value = substr($value, 0, - 3);
}
return sprintf($GLOBALS['TL_LANG']['DMS']['file_size_format']['text'], $value, $GLOBALS['TL_LANG']['DMS']['file_size_unit'][$strUnit]);
} | [
"public",
"static",
"function",
"formatFileSize",
"(",
"$",
"doubleFileSize",
",",
"$",
"strUnit",
")",
"{",
"$",
"value",
"=",
"number_format",
"(",
"$",
"doubleFileSize",
",",
"2",
",",
"$",
"GLOBALS",
"[",
"'TL_LANG'",
"]",
"[",
"'DMS'",
"]",
"[",
"'file_size_format'",
"]",
"[",
"'dec_point'",
"]",
",",
"$",
"GLOBALS",
"[",
"'TL_LANG'",
"]",
"[",
"'DMS'",
"]",
"[",
"'file_size_format'",
"]",
"[",
"'$thousands_sep'",
"]",
")",
";",
"if",
"(",
"substr",
"(",
"$",
"value",
",",
"-",
"3",
")",
"==",
"(",
"$",
"GLOBALS",
"[",
"'TL_LANG'",
"]",
"[",
"'DMS'",
"]",
"[",
"'file_size_format'",
"]",
"[",
"'dec_point'",
"]",
".",
"\"00\"",
")",
")",
"{",
"$",
"value",
"=",
"substr",
"(",
"$",
"value",
",",
"0",
",",
"-",
"3",
")",
";",
"}",
"return",
"sprintf",
"(",
"$",
"GLOBALS",
"[",
"'TL_LANG'",
"]",
"[",
"'DMS'",
"]",
"[",
"'file_size_format'",
"]",
"[",
"'text'",
"]",
",",
"$",
"value",
",",
"$",
"GLOBALS",
"[",
"'TL_LANG'",
"]",
"[",
"'DMS'",
"]",
"[",
"'file_size_unit'",
"]",
"[",
"$",
"strUnit",
"]",
")",
";",
"}"
]
| Utility function to format file size values
@param double $doubleFileSize The file size value.
@param string $strUnit The file size unit.
@return string The formatted file size value. | [
"Utility",
"function",
"to",
"format",
"file",
"size",
"values"
]
| dd6856ac87fdc7fc93dc6274fad678e416712059 | https://github.com/ContaoDMS/dms/blob/dd6856ac87fdc7fc93dc6274fad678e416712059/system/modules/DocumentManagementSystem/classes/pojos/Document.php#L397-L405 | train |
ContaoDMS/dms | system/modules/DocumentManagementSystem/modules/ModuleDmsListing.php | ModuleDmsListing.applyReadPermissionsToCategories | private function applyReadPermissionsToCategories(Array $arrCategories)
{
$arrSecureCategories = $arrCategories;
foreach ($arrSecureCategories as $category)
{
if (!$category->isPublished() || ($this->dmsHideEmptyCategories && !$category->hasPublishedDocuments()) || ($this->dmsHideLockedCategories && !$category->isReadableForCurrentMember()))
{
unset($arrSecureCategories[$category->id]);
}
else if ($category->hasSubCategories())
{
$arrSecureSubCategories = $this->applyReadPermissionsToCategories($category->subCategories);
$category->subCategories = $arrSecureSubCategories;
}
}
return $arrSecureCategories;
} | php | private function applyReadPermissionsToCategories(Array $arrCategories)
{
$arrSecureCategories = $arrCategories;
foreach ($arrSecureCategories as $category)
{
if (!$category->isPublished() || ($this->dmsHideEmptyCategories && !$category->hasPublishedDocuments()) || ($this->dmsHideLockedCategories && !$category->isReadableForCurrentMember()))
{
unset($arrSecureCategories[$category->id]);
}
else if ($category->hasSubCategories())
{
$arrSecureSubCategories = $this->applyReadPermissionsToCategories($category->subCategories);
$category->subCategories = $arrSecureSubCategories;
}
}
return $arrSecureCategories;
} | [
"private",
"function",
"applyReadPermissionsToCategories",
"(",
"Array",
"$",
"arrCategories",
")",
"{",
"$",
"arrSecureCategories",
"=",
"$",
"arrCategories",
";",
"foreach",
"(",
"$",
"arrSecureCategories",
"as",
"$",
"category",
")",
"{",
"if",
"(",
"!",
"$",
"category",
"->",
"isPublished",
"(",
")",
"||",
"(",
"$",
"this",
"->",
"dmsHideEmptyCategories",
"&&",
"!",
"$",
"category",
"->",
"hasPublishedDocuments",
"(",
")",
")",
"||",
"(",
"$",
"this",
"->",
"dmsHideLockedCategories",
"&&",
"!",
"$",
"category",
"->",
"isReadableForCurrentMember",
"(",
")",
")",
")",
"{",
"unset",
"(",
"$",
"arrSecureCategories",
"[",
"$",
"category",
"->",
"id",
"]",
")",
";",
"}",
"else",
"if",
"(",
"$",
"category",
"->",
"hasSubCategories",
"(",
")",
")",
"{",
"$",
"arrSecureSubCategories",
"=",
"$",
"this",
"->",
"applyReadPermissionsToCategories",
"(",
"$",
"category",
"->",
"subCategories",
")",
";",
"$",
"category",
"->",
"subCategories",
"=",
"$",
"arrSecureSubCategories",
";",
"}",
"}",
"return",
"$",
"arrSecureCategories",
";",
"}"
]
| Apply the read permissions to the categories.
@param arr $arrCategories The structured array of categories.
@return array Returns a reduced array of categories (depends on the read permissions). | [
"Apply",
"the",
"read",
"permissions",
"to",
"the",
"categories",
"."
]
| dd6856ac87fdc7fc93dc6274fad678e416712059 | https://github.com/ContaoDMS/dms/blob/dd6856ac87fdc7fc93dc6274fad678e416712059/system/modules/DocumentManagementSystem/modules/ModuleDmsListing.php#L189-L205 | train |
ContaoDMS/dms | system/modules/DocumentManagementSystem/classes/pojos/Category.php | Category.isPublished | public function isPublished()
{
$time = time();
$published = ($this->published && ($this->publicationStart == '' || $this->publicationStart < $time) && ($this->publicationStop == '' || $this->publicationStop > $time));
return $published;
} | php | public function isPublished()
{
$time = time();
$published = ($this->published && ($this->publicationStart == '' || $this->publicationStart < $time) && ($this->publicationStop == '' || $this->publicationStop > $time));
return $published;
} | [
"public",
"function",
"isPublished",
"(",
")",
"{",
"$",
"time",
"=",
"time",
"(",
")",
";",
"$",
"published",
"=",
"(",
"$",
"this",
"->",
"published",
"&&",
"(",
"$",
"this",
"->",
"publicationStart",
"==",
"''",
"||",
"$",
"this",
"->",
"publicationStart",
"<",
"$",
"time",
")",
"&&",
"(",
"$",
"this",
"->",
"publicationStop",
"==",
"''",
"||",
"$",
"this",
"->",
"publicationStop",
">",
"$",
"time",
")",
")",
";",
"return",
"$",
"published",
";",
"}"
]
| Return if this category is published.
@return bool True if this category is published. | [
"Return",
"if",
"this",
"category",
"is",
"published",
"."
]
| dd6856ac87fdc7fc93dc6274fad678e416712059 | https://github.com/ContaoDMS/dms/blob/dd6856ac87fdc7fc93dc6274fad678e416712059/system/modules/DocumentManagementSystem/classes/pojos/Category.php#L235-L240 | train |
ContaoDMS/dms | system/modules/DocumentManagementSystem/classes/pojos/Category.php | Category.shouldPublishDocumentsPerDefault | public function shouldPublishDocumentsPerDefault()
{
if ($this->strPublishDocumentsPerDefault == self::PUBLISH_DOCUMENTS_PER_DEFAULT_ENABLE)
{
return true;
}
else if ($this->strPublishDocumentsPerDefault == self::PUBLISH_DOCUMENTS_PER_DEFAULT_INHERIT && $this->hasParentCategory())
{
return $this->parentCategory->shouldPublishDocumentsPerDefault();
}
return false;
} | php | public function shouldPublishDocumentsPerDefault()
{
if ($this->strPublishDocumentsPerDefault == self::PUBLISH_DOCUMENTS_PER_DEFAULT_ENABLE)
{
return true;
}
else if ($this->strPublishDocumentsPerDefault == self::PUBLISH_DOCUMENTS_PER_DEFAULT_INHERIT && $this->hasParentCategory())
{
return $this->parentCategory->shouldPublishDocumentsPerDefault();
}
return false;
} | [
"public",
"function",
"shouldPublishDocumentsPerDefault",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"strPublishDocumentsPerDefault",
"==",
"self",
"::",
"PUBLISH_DOCUMENTS_PER_DEFAULT_ENABLE",
")",
"{",
"return",
"true",
";",
"}",
"else",
"if",
"(",
"$",
"this",
"->",
"strPublishDocumentsPerDefault",
"==",
"self",
"::",
"PUBLISH_DOCUMENTS_PER_DEFAULT_INHERIT",
"&&",
"$",
"this",
"->",
"hasParentCategory",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"parentCategory",
"->",
"shouldPublishDocumentsPerDefault",
"(",
")",
";",
"}",
"return",
"false",
";",
"}"
]
| Return if documents uploaded to this category should be published per default.
@return bool If documents uploaded to this category should be published per default or not. | [
"Return",
"if",
"documents",
"uploaded",
"to",
"this",
"category",
"should",
"be",
"published",
"per",
"default",
"."
]
| dd6856ac87fdc7fc93dc6274fad678e416712059 | https://github.com/ContaoDMS/dms/blob/dd6856ac87fdc7fc93dc6274fad678e416712059/system/modules/DocumentManagementSystem/classes/pojos/Category.php#L247-L258 | train |
ContaoDMS/dms | system/modules/DocumentManagementSystem/classes/pojos/Category.php | Category.hasDocumentsInSubCategories | public function hasDocumentsInSubCategories()
{
if ($this->hasSubCategories())
{
foreach ($this->arrSubCategories as $subCategory)
{
if ($subCategory->hasDocuments() || $subCategory->hasDocumentsInSubCategories())
{
return true;
}
}
}
return false;
} | php | public function hasDocumentsInSubCategories()
{
if ($this->hasSubCategories())
{
foreach ($this->arrSubCategories as $subCategory)
{
if ($subCategory->hasDocuments() || $subCategory->hasDocumentsInSubCategories())
{
return true;
}
}
}
return false;
} | [
"public",
"function",
"hasDocumentsInSubCategories",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hasSubCategories",
"(",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"arrSubCategories",
"as",
"$",
"subCategory",
")",
"{",
"if",
"(",
"$",
"subCategory",
"->",
"hasDocuments",
"(",
")",
"||",
"$",
"subCategory",
"->",
"hasDocumentsInSubCategories",
"(",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"}",
"return",
"false",
";",
"}"
]
| Return if this category has documents in any of its subcategories.
@return bool True if there are documents in any the subcategories. | [
"Return",
"if",
"this",
"category",
"has",
"documents",
"in",
"any",
"of",
"its",
"subcategories",
"."
]
| dd6856ac87fdc7fc93dc6274fad678e416712059 | https://github.com/ContaoDMS/dms/blob/dd6856ac87fdc7fc93dc6274fad678e416712059/system/modules/DocumentManagementSystem/classes/pojos/Category.php#L312-L325 | train |
ContaoDMS/dms | system/modules/DocumentManagementSystem/classes/pojos/Category.php | Category.getPublishedDocumentCount | public function getPublishedDocumentCount()
{
$count = 0;
foreach ($this->arrDocuments as $document)
{
if ($document->isPublished())
{
$count++;
}
}
return $count;
} | php | public function getPublishedDocumentCount()
{
$count = 0;
foreach ($this->arrDocuments as $document)
{
if ($document->isPublished())
{
$count++;
}
}
return $count;
} | [
"public",
"function",
"getPublishedDocumentCount",
"(",
")",
"{",
"$",
"count",
"=",
"0",
";",
"foreach",
"(",
"$",
"this",
"->",
"arrDocuments",
"as",
"$",
"document",
")",
"{",
"if",
"(",
"$",
"document",
"->",
"isPublished",
"(",
")",
")",
"{",
"$",
"count",
"++",
";",
"}",
"}",
"return",
"$",
"count",
";",
"}"
]
| Get the number of published documents.
@return int The number of published documents. | [
"Get",
"the",
"number",
"of",
"published",
"documents",
"."
]
| dd6856ac87fdc7fc93dc6274fad678e416712059 | https://github.com/ContaoDMS/dms/blob/dd6856ac87fdc7fc93dc6274fad678e416712059/system/modules/DocumentManagementSystem/classes/pojos/Category.php#L427-L438 | train |
ContaoDMS/dms | system/modules/DocumentManagementSystem/classes/pojos/Category.php | Category.isReadableForCurrentMember | public function isReadableForCurrentMember()
{
if ($this->generalReadPermission == self::GENERAL_READ_PERMISSION_ALL)
{
return true;
}
else if ($this->generalReadPermission == self::GENERAL_READ_PERMISSION_LOGGED_USER && FE_USER_LOGGED_IN)
{
return true;
}
else if ($this->generalReadPermission == self::GENERAL_READ_PERMISSION_CUSTOM && FE_USER_LOGGED_IN)
{
return $this->isAccessibleForCurrentMember(\AccessRight::READ);
}
else if ($this->generalReadPermission == self::GENERAL_READ_PERMISSION_INHERIT && $this->hasParentCategory())
{
return $this->parentCategory->isReadableForCurrentMember();
}
return false;
} | php | public function isReadableForCurrentMember()
{
if ($this->generalReadPermission == self::GENERAL_READ_PERMISSION_ALL)
{
return true;
}
else if ($this->generalReadPermission == self::GENERAL_READ_PERMISSION_LOGGED_USER && FE_USER_LOGGED_IN)
{
return true;
}
else if ($this->generalReadPermission == self::GENERAL_READ_PERMISSION_CUSTOM && FE_USER_LOGGED_IN)
{
return $this->isAccessibleForCurrentMember(\AccessRight::READ);
}
else if ($this->generalReadPermission == self::GENERAL_READ_PERMISSION_INHERIT && $this->hasParentCategory())
{
return $this->parentCategory->isReadableForCurrentMember();
}
return false;
} | [
"public",
"function",
"isReadableForCurrentMember",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"generalReadPermission",
"==",
"self",
"::",
"GENERAL_READ_PERMISSION_ALL",
")",
"{",
"return",
"true",
";",
"}",
"else",
"if",
"(",
"$",
"this",
"->",
"generalReadPermission",
"==",
"self",
"::",
"GENERAL_READ_PERMISSION_LOGGED_USER",
"&&",
"FE_USER_LOGGED_IN",
")",
"{",
"return",
"true",
";",
"}",
"else",
"if",
"(",
"$",
"this",
"->",
"generalReadPermission",
"==",
"self",
"::",
"GENERAL_READ_PERMISSION_CUSTOM",
"&&",
"FE_USER_LOGGED_IN",
")",
"{",
"return",
"$",
"this",
"->",
"isAccessibleForCurrentMember",
"(",
"\\",
"AccessRight",
"::",
"READ",
")",
";",
"}",
"else",
"if",
"(",
"$",
"this",
"->",
"generalReadPermission",
"==",
"self",
"::",
"GENERAL_READ_PERMISSION_INHERIT",
"&&",
"$",
"this",
"->",
"hasParentCategory",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"parentCategory",
"->",
"isReadableForCurrentMember",
"(",
")",
";",
"}",
"return",
"false",
";",
"}"
]
| Return if this category is readable for the current logged member.
@return bool True if this category is readable for the current logged member. | [
"Return",
"if",
"this",
"category",
"is",
"readable",
"for",
"the",
"current",
"logged",
"member",
"."
]
| dd6856ac87fdc7fc93dc6274fad678e416712059 | https://github.com/ContaoDMS/dms/blob/dd6856ac87fdc7fc93dc6274fad678e416712059/system/modules/DocumentManagementSystem/classes/pojos/Category.php#L476-L495 | train |
ContaoDMS/dms | system/modules/DocumentManagementSystem/classes/pojos/Category.php | Category.isAccessibleForCurrentMember | public function isAccessibleForCurrentMember($strAccessRight)
{
if ($this->generalManagePermission == self::GENERAL_MANAGE_PERMISSION_LOGGED_USER && FE_USER_LOGGED_IN)
{
return true;
}
else if ($this->generalManagePermission == self::GENERAL_MANAGE_PERMISSION_CUSTOM && FE_USER_LOGGED_IN)
{
$blnIsAccessible = false;
$arrMemberGroups = deserialize(\FrontendUser::getInstance()->groups);
if (!empty($arrMemberGroups))
{
foreach($this->arrAccessRights as $accessRight)
{
if ($accessRight->isActive() && in_array($accessRight->memberGroup, $arrMemberGroups))
{
$blnIsAccessible = $blnIsAccessible || $accessRight->$strAccessRight;
}
}
}
return $blnIsAccessible;
}
else if ($this->generalManagePermission == self::GENERAL_MANAGE_PERMISSION_INHERIT && $this->hasParentCategory())
{
return $this->parentCategory->isAccessibleForCurrentMember($strAccessRight);
}
return false;
} | php | public function isAccessibleForCurrentMember($strAccessRight)
{
if ($this->generalManagePermission == self::GENERAL_MANAGE_PERMISSION_LOGGED_USER && FE_USER_LOGGED_IN)
{
return true;
}
else if ($this->generalManagePermission == self::GENERAL_MANAGE_PERMISSION_CUSTOM && FE_USER_LOGGED_IN)
{
$blnIsAccessible = false;
$arrMemberGroups = deserialize(\FrontendUser::getInstance()->groups);
if (!empty($arrMemberGroups))
{
foreach($this->arrAccessRights as $accessRight)
{
if ($accessRight->isActive() && in_array($accessRight->memberGroup, $arrMemberGroups))
{
$blnIsAccessible = $blnIsAccessible || $accessRight->$strAccessRight;
}
}
}
return $blnIsAccessible;
}
else if ($this->generalManagePermission == self::GENERAL_MANAGE_PERMISSION_INHERIT && $this->hasParentCategory())
{
return $this->parentCategory->isAccessibleForCurrentMember($strAccessRight);
}
return false;
} | [
"public",
"function",
"isAccessibleForCurrentMember",
"(",
"$",
"strAccessRight",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"generalManagePermission",
"==",
"self",
"::",
"GENERAL_MANAGE_PERMISSION_LOGGED_USER",
"&&",
"FE_USER_LOGGED_IN",
")",
"{",
"return",
"true",
";",
"}",
"else",
"if",
"(",
"$",
"this",
"->",
"generalManagePermission",
"==",
"self",
"::",
"GENERAL_MANAGE_PERMISSION_CUSTOM",
"&&",
"FE_USER_LOGGED_IN",
")",
"{",
"$",
"blnIsAccessible",
"=",
"false",
";",
"$",
"arrMemberGroups",
"=",
"deserialize",
"(",
"\\",
"FrontendUser",
"::",
"getInstance",
"(",
")",
"->",
"groups",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"arrMemberGroups",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"arrAccessRights",
"as",
"$",
"accessRight",
")",
"{",
"if",
"(",
"$",
"accessRight",
"->",
"isActive",
"(",
")",
"&&",
"in_array",
"(",
"$",
"accessRight",
"->",
"memberGroup",
",",
"$",
"arrMemberGroups",
")",
")",
"{",
"$",
"blnIsAccessible",
"=",
"$",
"blnIsAccessible",
"||",
"$",
"accessRight",
"->",
"$",
"strAccessRight",
";",
"}",
"}",
"}",
"return",
"$",
"blnIsAccessible",
";",
"}",
"else",
"if",
"(",
"$",
"this",
"->",
"generalManagePermission",
"==",
"self",
"::",
"GENERAL_MANAGE_PERMISSION_INHERIT",
"&&",
"$",
"this",
"->",
"hasParentCategory",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"parentCategory",
"->",
"isAccessibleForCurrentMember",
"(",
"$",
"strAccessRight",
")",
";",
"}",
"return",
"false",
";",
"}"
]
| Return if the current logged member has access with the given right to this category.
@param string $strAccessRight The name of the right.
@return bool True if the current logged member has access with the given right to this category. | [
"Return",
"if",
"the",
"current",
"logged",
"member",
"has",
"access",
"with",
"the",
"given",
"right",
"to",
"this",
"category",
"."
]
| dd6856ac87fdc7fc93dc6274fad678e416712059 | https://github.com/ContaoDMS/dms/blob/dd6856ac87fdc7fc93dc6274fad678e416712059/system/modules/DocumentManagementSystem/classes/pojos/Category.php#L555-L582 | train |
ContaoDMS/dms | system/modules/DocumentManagementSystem/classes/pojos/Category.php | Category.getPath | public function getPath($blnSkipThis)
{
$arrPath = array();
if (!$this->isRootCategory() && $this->hasParentCategory())
{
$arrPath = $this->parentCategory->getPath(false);
}
if (!$blnSkipThis)
{
$arrPath[] = $this;
}
return $arrPath;
} | php | public function getPath($blnSkipThis)
{
$arrPath = array();
if (!$this->isRootCategory() && $this->hasParentCategory())
{
$arrPath = $this->parentCategory->getPath(false);
}
if (!$blnSkipThis)
{
$arrPath[] = $this;
}
return $arrPath;
} | [
"public",
"function",
"getPath",
"(",
"$",
"blnSkipThis",
")",
"{",
"$",
"arrPath",
"=",
"array",
"(",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"isRootCategory",
"(",
")",
"&&",
"$",
"this",
"->",
"hasParentCategory",
"(",
")",
")",
"{",
"$",
"arrPath",
"=",
"$",
"this",
"->",
"parentCategory",
"->",
"getPath",
"(",
"false",
")",
";",
"}",
"if",
"(",
"!",
"$",
"blnSkipThis",
")",
"{",
"$",
"arrPath",
"[",
"]",
"=",
"$",
"this",
";",
"}",
"return",
"$",
"arrPath",
";",
"}"
]
| Returns the path from the root node of this category to this category in context of the current structure of categories.
@param bool $blnSkipThis True if this category should be skipped.
@return arr All nodes in the path from the root node to this category. | [
"Returns",
"the",
"path",
"from",
"the",
"root",
"node",
"of",
"this",
"category",
"to",
"this",
"category",
"in",
"context",
"of",
"the",
"current",
"structure",
"of",
"categories",
"."
]
| dd6856ac87fdc7fc93dc6274fad678e416712059 | https://github.com/ContaoDMS/dms/blob/dd6856ac87fdc7fc93dc6274fad678e416712059/system/modules/DocumentManagementSystem/classes/pojos/Category.php#L626-L640 | train |
ContaoDMS/dms | system/modules/DocumentManagementSystem/classes/pojos/Category.php | Category.getPathNames | public function getPathNames($blnSkipThis)
{
$arrPath = array();
if (!$this->isRootCategory() && $this->hasParentCategory())
{
$arrPath = $this->parentCategory->getPathNames(false);
}
if (!$blnSkipThis)
{
$arrPath[] = $this->name;
}
return $arrPath;
} | php | public function getPathNames($blnSkipThis)
{
$arrPath = array();
if (!$this->isRootCategory() && $this->hasParentCategory())
{
$arrPath = $this->parentCategory->getPathNames(false);
}
if (!$blnSkipThis)
{
$arrPath[] = $this->name;
}
return $arrPath;
} | [
"public",
"function",
"getPathNames",
"(",
"$",
"blnSkipThis",
")",
"{",
"$",
"arrPath",
"=",
"array",
"(",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"isRootCategory",
"(",
")",
"&&",
"$",
"this",
"->",
"hasParentCategory",
"(",
")",
")",
"{",
"$",
"arrPath",
"=",
"$",
"this",
"->",
"parentCategory",
"->",
"getPathNames",
"(",
"false",
")",
";",
"}",
"if",
"(",
"!",
"$",
"blnSkipThis",
")",
"{",
"$",
"arrPath",
"[",
"]",
"=",
"$",
"this",
"->",
"name",
";",
"}",
"return",
"$",
"arrPath",
";",
"}"
]
| Returns the names in the path from the root node of this category to this category in context of the current structure of categories.
@param bool $blnSkipThis True if the name of this category should be skipped.
@return arr All nodes names in the path from the root node to this category. | [
"Returns",
"the",
"names",
"in",
"the",
"path",
"from",
"the",
"root",
"node",
"of",
"this",
"category",
"to",
"this",
"category",
"in",
"context",
"of",
"the",
"current",
"structure",
"of",
"categories",
"."
]
| dd6856ac87fdc7fc93dc6274fad678e416712059 | https://github.com/ContaoDMS/dms/blob/dd6856ac87fdc7fc93dc6274fad678e416712059/system/modules/DocumentManagementSystem/classes/pojos/Category.php#L648-L662 | train |
ContaoDMS/dms | system/modules/DocumentManagementSystem/classes/pojos/Category.php | Category.getAllowedFileTypes | public function getAllowedFileTypes()
{
$arrFileTypesOfParents = array();
if ($this->fileTypesInherit && !$this->isRootCategory() && $this->hasParentCategory())
{
$arrFileTypesOfParents = $this->parentCategory->getAllowedFileTypes();
}
$arrFileTypes = DmsUtils::getUniqueFileTypes($this->fileTypes, $arrFileTypesOfParents);
return $arrFileTypes;
} | php | public function getAllowedFileTypes()
{
$arrFileTypesOfParents = array();
if ($this->fileTypesInherit && !$this->isRootCategory() && $this->hasParentCategory())
{
$arrFileTypesOfParents = $this->parentCategory->getAllowedFileTypes();
}
$arrFileTypes = DmsUtils::getUniqueFileTypes($this->fileTypes, $arrFileTypesOfParents);
return $arrFileTypes;
} | [
"public",
"function",
"getAllowedFileTypes",
"(",
")",
"{",
"$",
"arrFileTypesOfParents",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"fileTypesInherit",
"&&",
"!",
"$",
"this",
"->",
"isRootCategory",
"(",
")",
"&&",
"$",
"this",
"->",
"hasParentCategory",
"(",
")",
")",
"{",
"$",
"arrFileTypesOfParents",
"=",
"$",
"this",
"->",
"parentCategory",
"->",
"getAllowedFileTypes",
"(",
")",
";",
"}",
"$",
"arrFileTypes",
"=",
"DmsUtils",
"::",
"getUniqueFileTypes",
"(",
"$",
"this",
"->",
"fileTypes",
",",
"$",
"arrFileTypesOfParents",
")",
";",
"return",
"$",
"arrFileTypes",
";",
"}"
]
| Returns an array of file types which are allowed to be uploaded into this category.
@return array The array of file types which are allowed. | [
"Returns",
"an",
"array",
"of",
"file",
"types",
"which",
"are",
"allowed",
"to",
"be",
"uploaded",
"into",
"this",
"category",
"."
]
| dd6856ac87fdc7fc93dc6274fad678e416712059 | https://github.com/ContaoDMS/dms/blob/dd6856ac87fdc7fc93dc6274fad678e416712059/system/modules/DocumentManagementSystem/classes/pojos/Category.php#L679-L691 | train |
ContaoDMS/dms | system/modules/DocumentManagementSystem/classes/pojos/Category.php | Category.isFileTypeAllowed | public function isFileTypeAllowed($strFileType, $blnCaseSensitive = false)
{
$arrAllowedFileTypes = $this->getAllowedFileTypes();
if (!$blnCaseSensitive)
{
$strFileType = strtolower($strFileType);
}
return in_array($strFileType, $arrAllowedFileTypes);
} | php | public function isFileTypeAllowed($strFileType, $blnCaseSensitive = false)
{
$arrAllowedFileTypes = $this->getAllowedFileTypes();
if (!$blnCaseSensitive)
{
$strFileType = strtolower($strFileType);
}
return in_array($strFileType, $arrAllowedFileTypes);
} | [
"public",
"function",
"isFileTypeAllowed",
"(",
"$",
"strFileType",
",",
"$",
"blnCaseSensitive",
"=",
"false",
")",
"{",
"$",
"arrAllowedFileTypes",
"=",
"$",
"this",
"->",
"getAllowedFileTypes",
"(",
")",
";",
"if",
"(",
"!",
"$",
"blnCaseSensitive",
")",
"{",
"$",
"strFileType",
"=",
"strtolower",
"(",
"$",
"strFileType",
")",
";",
"}",
"return",
"in_array",
"(",
"$",
"strFileType",
",",
"$",
"arrAllowedFileTypes",
")",
";",
"}"
]
| Returns if the given file type is allowed to be uploaded into this category.
@param string $strFileType The file type to be checked.
@param bool $blnCaseSensitive True if checking should be done case sensitive.
@return bool True if the given file type is allowed to be uploaded into this category. | [
"Returns",
"if",
"the",
"given",
"file",
"type",
"is",
"allowed",
"to",
"be",
"uploaded",
"into",
"this",
"category",
"."
]
| dd6856ac87fdc7fc93dc6274fad678e416712059 | https://github.com/ContaoDMS/dms/blob/dd6856ac87fdc7fc93dc6274fad678e416712059/system/modules/DocumentManagementSystem/classes/pojos/Category.php#L700-L709 | train |
FreeDSx/ASN1 | src/FreeDSx/Asn1/Encoder/CerDerTrait.php | CerDerTrait.encodeSetOf | protected function encodeSetOf(SetOfType $setOf)
{
if (\count($setOf->getChildren()) === 0) {
return '';
}
$children = [];
# Encode each child and record the length, we need it later
foreach ($setOf as $type) {
$child = ['original' => $this->encode($type)];
$child['length'] = \strlen($child['original']);
$children[] = $child;
}
# Sort the encoded types by length first to determine the padding needed.
\usort($children, function ($a, $b) {
/* @var AbstractType $a
* @var AbstractType $b */
return $a['length'] < $b['length'] ? -1 : 1;
});
# Get the last child (ie. the longest), and put the array back to normal.
$child = \end($children);
$padding = $child ['length'];
\reset($children);
# Sort by padding the items and comparing them.
\usort($children, function($a, $b) use ($padding) {
return \strcmp(
\str_pad($a['original'], $padding, "\x00"),
\str_pad($b['original'], $padding, "\x00")
);
});
# Reconstruct the byte string from the order obtained.
$bytes = '';
foreach ($children as $child) {
$bytes .= $child['original'];
}
return $bytes;
} | php | protected function encodeSetOf(SetOfType $setOf)
{
if (\count($setOf->getChildren()) === 0) {
return '';
}
$children = [];
# Encode each child and record the length, we need it later
foreach ($setOf as $type) {
$child = ['original' => $this->encode($type)];
$child['length'] = \strlen($child['original']);
$children[] = $child;
}
# Sort the encoded types by length first to determine the padding needed.
\usort($children, function ($a, $b) {
/* @var AbstractType $a
* @var AbstractType $b */
return $a['length'] < $b['length'] ? -1 : 1;
});
# Get the last child (ie. the longest), and put the array back to normal.
$child = \end($children);
$padding = $child ['length'];
\reset($children);
# Sort by padding the items and comparing them.
\usort($children, function($a, $b) use ($padding) {
return \strcmp(
\str_pad($a['original'], $padding, "\x00"),
\str_pad($b['original'], $padding, "\x00")
);
});
# Reconstruct the byte string from the order obtained.
$bytes = '';
foreach ($children as $child) {
$bytes .= $child['original'];
}
return $bytes;
} | [
"protected",
"function",
"encodeSetOf",
"(",
"SetOfType",
"$",
"setOf",
")",
"{",
"if",
"(",
"\\",
"count",
"(",
"$",
"setOf",
"->",
"getChildren",
"(",
")",
")",
"===",
"0",
")",
"{",
"return",
"''",
";",
"}",
"$",
"children",
"=",
"[",
"]",
";",
"# Encode each child and record the length, we need it later",
"foreach",
"(",
"$",
"setOf",
"as",
"$",
"type",
")",
"{",
"$",
"child",
"=",
"[",
"'original'",
"=>",
"$",
"this",
"->",
"encode",
"(",
"$",
"type",
")",
"]",
";",
"$",
"child",
"[",
"'length'",
"]",
"=",
"\\",
"strlen",
"(",
"$",
"child",
"[",
"'original'",
"]",
")",
";",
"$",
"children",
"[",
"]",
"=",
"$",
"child",
";",
"}",
"# Sort the encoded types by length first to determine the padding needed.",
"\\",
"usort",
"(",
"$",
"children",
",",
"function",
"(",
"$",
"a",
",",
"$",
"b",
")",
"{",
"/* @var AbstractType $a\n * @var AbstractType $b */",
"return",
"$",
"a",
"[",
"'length'",
"]",
"<",
"$",
"b",
"[",
"'length'",
"]",
"?",
"-",
"1",
":",
"1",
";",
"}",
")",
";",
"# Get the last child (ie. the longest), and put the array back to normal.",
"$",
"child",
"=",
"\\",
"end",
"(",
"$",
"children",
")",
";",
"$",
"padding",
"=",
"$",
"child",
"[",
"'length'",
"]",
";",
"\\",
"reset",
"(",
"$",
"children",
")",
";",
"# Sort by padding the items and comparing them.",
"\\",
"usort",
"(",
"$",
"children",
",",
"function",
"(",
"$",
"a",
",",
"$",
"b",
")",
"use",
"(",
"$",
"padding",
")",
"{",
"return",
"\\",
"strcmp",
"(",
"\\",
"str_pad",
"(",
"$",
"a",
"[",
"'original'",
"]",
",",
"$",
"padding",
",",
"\"\\x00\"",
")",
",",
"\\",
"str_pad",
"(",
"$",
"b",
"[",
"'original'",
"]",
",",
"$",
"padding",
",",
"\"\\x00\"",
")",
")",
";",
"}",
")",
";",
"# Reconstruct the byte string from the order obtained.",
"$",
"bytes",
"=",
"''",
";",
"foreach",
"(",
"$",
"children",
"as",
"$",
"child",
")",
"{",
"$",
"bytes",
".=",
"$",
"child",
"[",
"'original'",
"]",
";",
"}",
"return",
"$",
"bytes",
";",
"}"
]
| X.690 Section 11.6
The encodings of the component values of a set-of value shall appear in ascending order, the encodings being
compared as octet strings with the shorter components being padded at their trailing end with 0-octets.
NOTE – The padding octets are for comparison purposes only and do not appear in the encodings.
---------
It's very hard to find examples, but it's not clear to me from the wording if I have this correct. The example I
did find in "ASN.1 Complete" (John Larmouth) contains seemingly several encoding errors:
- Length is not encoded correctly for the SET OF element.
- The integer 10 is encoded incorrectly.
- The sort is in descending order of the encoded value (in opposition to X.690 11.6), though in ascending
order of the literal integer values.
So I'm hesitant to trust that. Perhaps there's an example elsewhere to be used? Tests around this are hard to
come by in ASN.1 libraries for some reason.
@todo Is this assumed ordering correct? Confirmation needed. This could probably be simplified too.
@param SetOfType $setOf
@return string | [
"X",
".",
"690",
"Section",
"11",
".",
"6"
]
| 0b0a35a2fd3a8fa0c945f91e9cdcf17eaa3789e5 | https://github.com/FreeDSx/ASN1/blob/0b0a35a2fd3a8fa0c945f91e9cdcf17eaa3789e5/src/FreeDSx/Asn1/Encoder/CerDerTrait.php#L127-L168 | train |
thampe/inky | src/Inky.php | Inky.addAlias | public function addAlias($alias, $tagName)
{
if($this->getComponentFactory($tagName)) {
$this->alias[(string) $alias] = (string) $tagName;
}
return $this;
} | php | public function addAlias($alias, $tagName)
{
if($this->getComponentFactory($tagName)) {
$this->alias[(string) $alias] = (string) $tagName;
}
return $this;
} | [
"public",
"function",
"addAlias",
"(",
"$",
"alias",
",",
"$",
"tagName",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"getComponentFactory",
"(",
"$",
"tagName",
")",
")",
"{",
"$",
"this",
"->",
"alias",
"[",
"(",
"string",
")",
"$",
"alias",
"]",
"=",
"(",
"string",
")",
"$",
"tagName",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Adds an alisa for a component
@param $alias
@param $tagName
@return $this | [
"Adds",
"an",
"alisa",
"for",
"a",
"component"
]
| 26c7a897e5e13e16ef8d6f2c50838d505cbd4d4f | https://github.com/thampe/inky/blob/26c7a897e5e13e16ef8d6f2c50838d505cbd4d4f/src/Inky.php#L99-L105 | train |
thampe/inky | src/Inky.php | Inky.getComponentFactory | public function getComponentFactory($tagName)
{
//check for alias first
if(isset($this->alias[$tagName])) {
$tagName = $this->alias[$tagName];
}
if(
isset($this->componentFactory[$tagName])
&& $this->componentFactory[$tagName] instanceof ComponentFactoryInterface
) {
return $this->componentFactory[$tagName];
}
return null;
} | php | public function getComponentFactory($tagName)
{
//check for alias first
if(isset($this->alias[$tagName])) {
$tagName = $this->alias[$tagName];
}
if(
isset($this->componentFactory[$tagName])
&& $this->componentFactory[$tagName] instanceof ComponentFactoryInterface
) {
return $this->componentFactory[$tagName];
}
return null;
} | [
"public",
"function",
"getComponentFactory",
"(",
"$",
"tagName",
")",
"{",
"//check for alias first",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"alias",
"[",
"$",
"tagName",
"]",
")",
")",
"{",
"$",
"tagName",
"=",
"$",
"this",
"->",
"alias",
"[",
"$",
"tagName",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"componentFactory",
"[",
"$",
"tagName",
"]",
")",
"&&",
"$",
"this",
"->",
"componentFactory",
"[",
"$",
"tagName",
"]",
"instanceof",
"ComponentFactoryInterface",
")",
"{",
"return",
"$",
"this",
"->",
"componentFactory",
"[",
"$",
"tagName",
"]",
";",
"}",
"return",
"null",
";",
"}"
]
| returns a Component Factory for a given tag or alias
@param $tagName
@return null|ComponentFactoryInterface | [
"returns",
"a",
"Component",
"Factory",
"for",
"a",
"given",
"tag",
"or",
"alias"
]
| 26c7a897e5e13e16ef8d6f2c50838d505cbd4d4f | https://github.com/thampe/inky/blob/26c7a897e5e13e16ef8d6f2c50838d505cbd4d4f/src/Inky.php#L136-L151 | train |
flarum/mentions | src/Listener/FilterVisiblePosts.php | FilterVisiblePosts.handle | public function handle(WillSerializeData $event)
{
// Firstly we gather a list of posts contained within the API document.
// This will vary according to the API endpoint that is being accessed.
if ($event->isController(Controller\ShowDiscussionController::class)) {
$posts = $event->data->posts;
} elseif ($event->isController(Controller\ShowPostController::class)
|| $event->isController(Controller\CreatePostController::class)
|| $event->isController(Controller\UpdatePostController::class)) {
$posts = [$event->data];
} elseif ($event->isController(Controller\ListPostsController::class)) {
$posts = $event->data;
}
if (isset($posts)) {
$posts = new Collection($posts);
$posts = $posts->filter(function ($post) {
return $post instanceof CommentPost;
});
// Load all of the users that these posts mention. This way the data
// will be ready to go when we need to sub in current usernames
// during the rendering process.
$posts->load(['mentionsUsers', 'mentionsPosts.user']);
// Construct a list of the IDs of all of the posts that these posts
// have been mentioned in. We can then filter this list of IDs to
// weed out all of the ones which the user is not meant to see.
$ids = [];
foreach ($posts as $post) {
$ids = array_merge($ids, $post->mentionedBy->pluck('id')->all());
}
$ids = $this->posts->filterVisibleIds($ids, $event->actor);
// Finally, go back through each of the posts and filter out any
// of the posts in the relationship data that we now know are
// invisible to the user.
foreach ($posts as $post) {
$post->setRelation('mentionedBy', $post->mentionedBy->filter(function ($post) use ($ids) {
return array_search($post->id, $ids) !== false;
}));
}
}
} | php | public function handle(WillSerializeData $event)
{
// Firstly we gather a list of posts contained within the API document.
// This will vary according to the API endpoint that is being accessed.
if ($event->isController(Controller\ShowDiscussionController::class)) {
$posts = $event->data->posts;
} elseif ($event->isController(Controller\ShowPostController::class)
|| $event->isController(Controller\CreatePostController::class)
|| $event->isController(Controller\UpdatePostController::class)) {
$posts = [$event->data];
} elseif ($event->isController(Controller\ListPostsController::class)) {
$posts = $event->data;
}
if (isset($posts)) {
$posts = new Collection($posts);
$posts = $posts->filter(function ($post) {
return $post instanceof CommentPost;
});
// Load all of the users that these posts mention. This way the data
// will be ready to go when we need to sub in current usernames
// during the rendering process.
$posts->load(['mentionsUsers', 'mentionsPosts.user']);
// Construct a list of the IDs of all of the posts that these posts
// have been mentioned in. We can then filter this list of IDs to
// weed out all of the ones which the user is not meant to see.
$ids = [];
foreach ($posts as $post) {
$ids = array_merge($ids, $post->mentionedBy->pluck('id')->all());
}
$ids = $this->posts->filterVisibleIds($ids, $event->actor);
// Finally, go back through each of the posts and filter out any
// of the posts in the relationship data that we now know are
// invisible to the user.
foreach ($posts as $post) {
$post->setRelation('mentionedBy', $post->mentionedBy->filter(function ($post) use ($ids) {
return array_search($post->id, $ids) !== false;
}));
}
}
} | [
"public",
"function",
"handle",
"(",
"WillSerializeData",
"$",
"event",
")",
"{",
"// Firstly we gather a list of posts contained within the API document.",
"// This will vary according to the API endpoint that is being accessed.",
"if",
"(",
"$",
"event",
"->",
"isController",
"(",
"Controller",
"\\",
"ShowDiscussionController",
"::",
"class",
")",
")",
"{",
"$",
"posts",
"=",
"$",
"event",
"->",
"data",
"->",
"posts",
";",
"}",
"elseif",
"(",
"$",
"event",
"->",
"isController",
"(",
"Controller",
"\\",
"ShowPostController",
"::",
"class",
")",
"||",
"$",
"event",
"->",
"isController",
"(",
"Controller",
"\\",
"CreatePostController",
"::",
"class",
")",
"||",
"$",
"event",
"->",
"isController",
"(",
"Controller",
"\\",
"UpdatePostController",
"::",
"class",
")",
")",
"{",
"$",
"posts",
"=",
"[",
"$",
"event",
"->",
"data",
"]",
";",
"}",
"elseif",
"(",
"$",
"event",
"->",
"isController",
"(",
"Controller",
"\\",
"ListPostsController",
"::",
"class",
")",
")",
"{",
"$",
"posts",
"=",
"$",
"event",
"->",
"data",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"posts",
")",
")",
"{",
"$",
"posts",
"=",
"new",
"Collection",
"(",
"$",
"posts",
")",
";",
"$",
"posts",
"=",
"$",
"posts",
"->",
"filter",
"(",
"function",
"(",
"$",
"post",
")",
"{",
"return",
"$",
"post",
"instanceof",
"CommentPost",
";",
"}",
")",
";",
"// Load all of the users that these posts mention. This way the data",
"// will be ready to go when we need to sub in current usernames",
"// during the rendering process.",
"$",
"posts",
"->",
"load",
"(",
"[",
"'mentionsUsers'",
",",
"'mentionsPosts.user'",
"]",
")",
";",
"// Construct a list of the IDs of all of the posts that these posts",
"// have been mentioned in. We can then filter this list of IDs to",
"// weed out all of the ones which the user is not meant to see.",
"$",
"ids",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"posts",
"as",
"$",
"post",
")",
"{",
"$",
"ids",
"=",
"array_merge",
"(",
"$",
"ids",
",",
"$",
"post",
"->",
"mentionedBy",
"->",
"pluck",
"(",
"'id'",
")",
"->",
"all",
"(",
")",
")",
";",
"}",
"$",
"ids",
"=",
"$",
"this",
"->",
"posts",
"->",
"filterVisibleIds",
"(",
"$",
"ids",
",",
"$",
"event",
"->",
"actor",
")",
";",
"// Finally, go back through each of the posts and filter out any",
"// of the posts in the relationship data that we now know are",
"// invisible to the user.",
"foreach",
"(",
"$",
"posts",
"as",
"$",
"post",
")",
"{",
"$",
"post",
"->",
"setRelation",
"(",
"'mentionedBy'",
",",
"$",
"post",
"->",
"mentionedBy",
"->",
"filter",
"(",
"function",
"(",
"$",
"post",
")",
"use",
"(",
"$",
"ids",
")",
"{",
"return",
"array_search",
"(",
"$",
"post",
"->",
"id",
",",
"$",
"ids",
")",
"!==",
"false",
";",
"}",
")",
")",
";",
"}",
"}",
"}"
]
| Apply visibility permissions to API data.
Each post in an API document has a relationship with posts that have
mentioned it (mentionedBy). This listener will manually filter these
additional posts so that the user can't see any posts which they don't
have access to.
@param WillSerializeData $event | [
"Apply",
"visibility",
"permissions",
"to",
"API",
"data",
"."
]
| acc0516a18d691095dc3657648f1bc16d0c5f51f | https://github.com/flarum/mentions/blob/acc0516a18d691095dc3657648f1bc16d0c5f51f/src/Listener/FilterVisiblePosts.php#L45-L91 | train |
ContaoDMS/dms | system/modules/DocumentManagementSystem/modules/ModuleDmsManagement.php | ModuleDmsManagement.uploadSelectFile | private function uploadSelectFile(&$params, &$dmsLoader, &$uploadCategory, &$arrMessages, &$blnShowStart)
{
$params->loadRootCategory = true; // get complete path to root, for checking inherited access rights
$params->loadAccessRights = true;
$params->loadDocuments = false;
$category = $dmsLoader->loadCategory($uploadCategory, $params);
if ($category->isUploadableForCurrentMember())
{
$this->Template = new \FrontendTemplate("mod_dms_mgmt_upload_select_file");
$this->Template->setData($this->arrData);
$this->Template->category = $category;
$this->Template->maxUploadFileSizeByte = \DmsConfig::getMaxUploadFileSize(\Document::FILE_SIZE_UNIT_BYTE, false);
$this->Template->maxUploadFileSizeByteFormatted = \DmsConfig::getMaxUploadFileSize(\Document::FILE_SIZE_UNIT_BYTE, true);
$this->Template->maxUploadFileSizeKbFormatted = \DmsConfig::getMaxUploadFileSize(\Document::FILE_SIZE_UNIT_KB, true);
$this->Template->maxUploadFileSizeMbFormatted = \DmsConfig::getMaxUploadFileSize(\Document::FILE_SIZE_UNIT_MB, true);
$this->Template->maxUploadFileSizeGbFormatted = \DmsConfig::getMaxUploadFileSize(\Document::FILE_SIZE_UNIT_GB, true);
$blnShowStart = false;
}
else
{
$arrMessages['errors'][] = $GLOBALS['TL_LANG']['DMS']['ERR']['upload_document_not_allowed'];
$blnShowStart = true;
}
} | php | private function uploadSelectFile(&$params, &$dmsLoader, &$uploadCategory, &$arrMessages, &$blnShowStart)
{
$params->loadRootCategory = true; // get complete path to root, for checking inherited access rights
$params->loadAccessRights = true;
$params->loadDocuments = false;
$category = $dmsLoader->loadCategory($uploadCategory, $params);
if ($category->isUploadableForCurrentMember())
{
$this->Template = new \FrontendTemplate("mod_dms_mgmt_upload_select_file");
$this->Template->setData($this->arrData);
$this->Template->category = $category;
$this->Template->maxUploadFileSizeByte = \DmsConfig::getMaxUploadFileSize(\Document::FILE_SIZE_UNIT_BYTE, false);
$this->Template->maxUploadFileSizeByteFormatted = \DmsConfig::getMaxUploadFileSize(\Document::FILE_SIZE_UNIT_BYTE, true);
$this->Template->maxUploadFileSizeKbFormatted = \DmsConfig::getMaxUploadFileSize(\Document::FILE_SIZE_UNIT_KB, true);
$this->Template->maxUploadFileSizeMbFormatted = \DmsConfig::getMaxUploadFileSize(\Document::FILE_SIZE_UNIT_MB, true);
$this->Template->maxUploadFileSizeGbFormatted = \DmsConfig::getMaxUploadFileSize(\Document::FILE_SIZE_UNIT_GB, true);
$blnShowStart = false;
}
else
{
$arrMessages['errors'][] = $GLOBALS['TL_LANG']['DMS']['ERR']['upload_document_not_allowed'];
$blnShowStart = true;
}
} | [
"private",
"function",
"uploadSelectFile",
"(",
"&",
"$",
"params",
",",
"&",
"$",
"dmsLoader",
",",
"&",
"$",
"uploadCategory",
",",
"&",
"$",
"arrMessages",
",",
"&",
"$",
"blnShowStart",
")",
"{",
"$",
"params",
"->",
"loadRootCategory",
"=",
"true",
";",
"// get complete path to root, for checking inherited access rights",
"$",
"params",
"->",
"loadAccessRights",
"=",
"true",
";",
"$",
"params",
"->",
"loadDocuments",
"=",
"false",
";",
"$",
"category",
"=",
"$",
"dmsLoader",
"->",
"loadCategory",
"(",
"$",
"uploadCategory",
",",
"$",
"params",
")",
";",
"if",
"(",
"$",
"category",
"->",
"isUploadableForCurrentMember",
"(",
")",
")",
"{",
"$",
"this",
"->",
"Template",
"=",
"new",
"\\",
"FrontendTemplate",
"(",
"\"mod_dms_mgmt_upload_select_file\"",
")",
";",
"$",
"this",
"->",
"Template",
"->",
"setData",
"(",
"$",
"this",
"->",
"arrData",
")",
";",
"$",
"this",
"->",
"Template",
"->",
"category",
"=",
"$",
"category",
";",
"$",
"this",
"->",
"Template",
"->",
"maxUploadFileSizeByte",
"=",
"\\",
"DmsConfig",
"::",
"getMaxUploadFileSize",
"(",
"\\",
"Document",
"::",
"FILE_SIZE_UNIT_BYTE",
",",
"false",
")",
";",
"$",
"this",
"->",
"Template",
"->",
"maxUploadFileSizeByteFormatted",
"=",
"\\",
"DmsConfig",
"::",
"getMaxUploadFileSize",
"(",
"\\",
"Document",
"::",
"FILE_SIZE_UNIT_BYTE",
",",
"true",
")",
";",
"$",
"this",
"->",
"Template",
"->",
"maxUploadFileSizeKbFormatted",
"=",
"\\",
"DmsConfig",
"::",
"getMaxUploadFileSize",
"(",
"\\",
"Document",
"::",
"FILE_SIZE_UNIT_KB",
",",
"true",
")",
";",
"$",
"this",
"->",
"Template",
"->",
"maxUploadFileSizeMbFormatted",
"=",
"\\",
"DmsConfig",
"::",
"getMaxUploadFileSize",
"(",
"\\",
"Document",
"::",
"FILE_SIZE_UNIT_MB",
",",
"true",
")",
";",
"$",
"this",
"->",
"Template",
"->",
"maxUploadFileSizeGbFormatted",
"=",
"\\",
"DmsConfig",
"::",
"getMaxUploadFileSize",
"(",
"\\",
"Document",
"::",
"FILE_SIZE_UNIT_GB",
",",
"true",
")",
";",
"$",
"blnShowStart",
"=",
"false",
";",
"}",
"else",
"{",
"$",
"arrMessages",
"[",
"'errors'",
"]",
"[",
"]",
"=",
"$",
"GLOBALS",
"[",
"'TL_LANG'",
"]",
"[",
"'DMS'",
"]",
"[",
"'ERR'",
"]",
"[",
"'upload_document_not_allowed'",
"]",
";",
"$",
"blnShowStart",
"=",
"true",
";",
"}",
"}"
]
| Display the file select screen for upload | [
"Display",
"the",
"file",
"select",
"screen",
"for",
"upload"
]
| dd6856ac87fdc7fc93dc6274fad678e416712059 | https://github.com/ContaoDMS/dms/blob/dd6856ac87fdc7fc93dc6274fad678e416712059/system/modules/DocumentManagementSystem/modules/ModuleDmsManagement.php#L250-L276 | train |
ContaoDMS/dms | system/modules/DocumentManagementSystem/modules/ModuleDmsManagement.php | ModuleDmsManagement.manageSelectDocument | private function manageSelectDocument(&$params, &$dmsLoader, &$manageCategory, &$arrMessages, &$blnShowStart)
{
$params->loadRootCategory = true; // get complete path to root, for checking inherited access rights
$params->loadAccessRights = true;
$params->loadDocuments = true;
$category = $dmsLoader->loadCategory($manageCategory, $params);
if (!$category->isManageableForCurrentMember())
{
$arrMessages['errors'][] = $GLOBALS['TL_LANG']['DMS']['ERR']['manage_document_not_allowed'];
$blnShowStart = true;
}
else if (!$category->hasDocuments())
{
$arrMessages['errors'][] = $GLOBALS['TL_LANG']['DMS']['ERR']['manage_document_category_empty'];
$blnShowStart = true;
}
else
{
$this->Template = new \FrontendTemplate("mod_dms_mgmt_manage_document_select");
$this->Template->setData($this->arrData);
$this->Template->category = $category;
$blnShowStart = false;
}
} | php | private function manageSelectDocument(&$params, &$dmsLoader, &$manageCategory, &$arrMessages, &$blnShowStart)
{
$params->loadRootCategory = true; // get complete path to root, for checking inherited access rights
$params->loadAccessRights = true;
$params->loadDocuments = true;
$category = $dmsLoader->loadCategory($manageCategory, $params);
if (!$category->isManageableForCurrentMember())
{
$arrMessages['errors'][] = $GLOBALS['TL_LANG']['DMS']['ERR']['manage_document_not_allowed'];
$blnShowStart = true;
}
else if (!$category->hasDocuments())
{
$arrMessages['errors'][] = $GLOBALS['TL_LANG']['DMS']['ERR']['manage_document_category_empty'];
$blnShowStart = true;
}
else
{
$this->Template = new \FrontendTemplate("mod_dms_mgmt_manage_document_select");
$this->Template->setData($this->arrData);
$this->Template->category = $category;
$blnShowStart = false;
}
} | [
"private",
"function",
"manageSelectDocument",
"(",
"&",
"$",
"params",
",",
"&",
"$",
"dmsLoader",
",",
"&",
"$",
"manageCategory",
",",
"&",
"$",
"arrMessages",
",",
"&",
"$",
"blnShowStart",
")",
"{",
"$",
"params",
"->",
"loadRootCategory",
"=",
"true",
";",
"// get complete path to root, for checking inherited access rights",
"$",
"params",
"->",
"loadAccessRights",
"=",
"true",
";",
"$",
"params",
"->",
"loadDocuments",
"=",
"true",
";",
"$",
"category",
"=",
"$",
"dmsLoader",
"->",
"loadCategory",
"(",
"$",
"manageCategory",
",",
"$",
"params",
")",
";",
"if",
"(",
"!",
"$",
"category",
"->",
"isManageableForCurrentMember",
"(",
")",
")",
"{",
"$",
"arrMessages",
"[",
"'errors'",
"]",
"[",
"]",
"=",
"$",
"GLOBALS",
"[",
"'TL_LANG'",
"]",
"[",
"'DMS'",
"]",
"[",
"'ERR'",
"]",
"[",
"'manage_document_not_allowed'",
"]",
";",
"$",
"blnShowStart",
"=",
"true",
";",
"}",
"else",
"if",
"(",
"!",
"$",
"category",
"->",
"hasDocuments",
"(",
")",
")",
"{",
"$",
"arrMessages",
"[",
"'errors'",
"]",
"[",
"]",
"=",
"$",
"GLOBALS",
"[",
"'TL_LANG'",
"]",
"[",
"'DMS'",
"]",
"[",
"'ERR'",
"]",
"[",
"'manage_document_category_empty'",
"]",
";",
"$",
"blnShowStart",
"=",
"true",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"Template",
"=",
"new",
"\\",
"FrontendTemplate",
"(",
"\"mod_dms_mgmt_manage_document_select\"",
")",
";",
"$",
"this",
"->",
"Template",
"->",
"setData",
"(",
"$",
"this",
"->",
"arrData",
")",
";",
"$",
"this",
"->",
"Template",
"->",
"category",
"=",
"$",
"category",
";",
"$",
"blnShowStart",
"=",
"false",
";",
"}",
"}"
]
| Display the document select screen for managing | [
"Display",
"the",
"document",
"select",
"screen",
"for",
"managing"
]
| dd6856ac87fdc7fc93dc6274fad678e416712059 | https://github.com/ContaoDMS/dms/blob/dd6856ac87fdc7fc93dc6274fad678e416712059/system/modules/DocumentManagementSystem/modules/ModuleDmsManagement.php#L585-L611 | train |
ContaoDMS/dms | system/modules/DocumentManagementSystem/modules/ModuleDmsManagement.php | ModuleDmsManagement.managePublishDocument | private function managePublishDocument(&$params, &$dmsLoader, &$manageCategory, &$arrMessages, &$blnShowStart, $documentId)
{
$params->loadRootCategory = true; // get complete path to root, for checking inherited access rights
$params->loadAccessRights = true;
$params->loadDocuments = false;
$category = $dmsLoader->loadCategory($manageCategory, $params);
if (!$category->isPublishableForCurrentMember())
{
$arrMessages['errors'][] = $GLOBALS['TL_LANG']['DMS']['ERR']['manage_document_not_allowed'];
$blnShowStart = true;
}
else
{
$document = $dmsLoader->loadDocument($documentId, $params);
if ($document != null)
{
if (!$document->isPublished())
{
$document->lasteditMemberId = $this->Member->id;
$document->lasteditDate = time();
$document->published = true;
$dmsWriter = \DmsWriter::getInstance();
$document = $dmsWriter->updateDocument($document);
$arrMessages['successes'][] = $GLOBALS['TL_LANG']['DMS']['SUCCESS']['document_successfully_published'];
}
else
{
$arrMessages['infos'][] = $GLOBALS['TL_LANG']['DMS']['INFO']['document_already_published'];
}
}
else
{
$arrMessages['errors'][] = $GLOBALS['TL_LANG']['DMS']['ERR']['manage_document_not_found'];
}
$this->manageSelectDocument($params, $dmsLoader, $manageCategory, $arrMessages, $blnShowStart);
}
} | php | private function managePublishDocument(&$params, &$dmsLoader, &$manageCategory, &$arrMessages, &$blnShowStart, $documentId)
{
$params->loadRootCategory = true; // get complete path to root, for checking inherited access rights
$params->loadAccessRights = true;
$params->loadDocuments = false;
$category = $dmsLoader->loadCategory($manageCategory, $params);
if (!$category->isPublishableForCurrentMember())
{
$arrMessages['errors'][] = $GLOBALS['TL_LANG']['DMS']['ERR']['manage_document_not_allowed'];
$blnShowStart = true;
}
else
{
$document = $dmsLoader->loadDocument($documentId, $params);
if ($document != null)
{
if (!$document->isPublished())
{
$document->lasteditMemberId = $this->Member->id;
$document->lasteditDate = time();
$document->published = true;
$dmsWriter = \DmsWriter::getInstance();
$document = $dmsWriter->updateDocument($document);
$arrMessages['successes'][] = $GLOBALS['TL_LANG']['DMS']['SUCCESS']['document_successfully_published'];
}
else
{
$arrMessages['infos'][] = $GLOBALS['TL_LANG']['DMS']['INFO']['document_already_published'];
}
}
else
{
$arrMessages['errors'][] = $GLOBALS['TL_LANG']['DMS']['ERR']['manage_document_not_found'];
}
$this->manageSelectDocument($params, $dmsLoader, $manageCategory, $arrMessages, $blnShowStart);
}
} | [
"private",
"function",
"managePublishDocument",
"(",
"&",
"$",
"params",
",",
"&",
"$",
"dmsLoader",
",",
"&",
"$",
"manageCategory",
",",
"&",
"$",
"arrMessages",
",",
"&",
"$",
"blnShowStart",
",",
"$",
"documentId",
")",
"{",
"$",
"params",
"->",
"loadRootCategory",
"=",
"true",
";",
"// get complete path to root, for checking inherited access rights",
"$",
"params",
"->",
"loadAccessRights",
"=",
"true",
";",
"$",
"params",
"->",
"loadDocuments",
"=",
"false",
";",
"$",
"category",
"=",
"$",
"dmsLoader",
"->",
"loadCategory",
"(",
"$",
"manageCategory",
",",
"$",
"params",
")",
";",
"if",
"(",
"!",
"$",
"category",
"->",
"isPublishableForCurrentMember",
"(",
")",
")",
"{",
"$",
"arrMessages",
"[",
"'errors'",
"]",
"[",
"]",
"=",
"$",
"GLOBALS",
"[",
"'TL_LANG'",
"]",
"[",
"'DMS'",
"]",
"[",
"'ERR'",
"]",
"[",
"'manage_document_not_allowed'",
"]",
";",
"$",
"blnShowStart",
"=",
"true",
";",
"}",
"else",
"{",
"$",
"document",
"=",
"$",
"dmsLoader",
"->",
"loadDocument",
"(",
"$",
"documentId",
",",
"$",
"params",
")",
";",
"if",
"(",
"$",
"document",
"!=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"document",
"->",
"isPublished",
"(",
")",
")",
"{",
"$",
"document",
"->",
"lasteditMemberId",
"=",
"$",
"this",
"->",
"Member",
"->",
"id",
";",
"$",
"document",
"->",
"lasteditDate",
"=",
"time",
"(",
")",
";",
"$",
"document",
"->",
"published",
"=",
"true",
";",
"$",
"dmsWriter",
"=",
"\\",
"DmsWriter",
"::",
"getInstance",
"(",
")",
";",
"$",
"document",
"=",
"$",
"dmsWriter",
"->",
"updateDocument",
"(",
"$",
"document",
")",
";",
"$",
"arrMessages",
"[",
"'successes'",
"]",
"[",
"]",
"=",
"$",
"GLOBALS",
"[",
"'TL_LANG'",
"]",
"[",
"'DMS'",
"]",
"[",
"'SUCCESS'",
"]",
"[",
"'document_successfully_published'",
"]",
";",
"}",
"else",
"{",
"$",
"arrMessages",
"[",
"'infos'",
"]",
"[",
"]",
"=",
"$",
"GLOBALS",
"[",
"'TL_LANG'",
"]",
"[",
"'DMS'",
"]",
"[",
"'INFO'",
"]",
"[",
"'document_already_published'",
"]",
";",
"}",
"}",
"else",
"{",
"$",
"arrMessages",
"[",
"'errors'",
"]",
"[",
"]",
"=",
"$",
"GLOBALS",
"[",
"'TL_LANG'",
"]",
"[",
"'DMS'",
"]",
"[",
"'ERR'",
"]",
"[",
"'manage_document_not_found'",
"]",
";",
"}",
"$",
"this",
"->",
"manageSelectDocument",
"(",
"$",
"params",
",",
"$",
"dmsLoader",
",",
"$",
"manageCategory",
",",
"$",
"arrMessages",
",",
"$",
"blnShowStart",
")",
";",
"}",
"}"
]
| Execute publishing documents | [
"Execute",
"publishing",
"documents"
]
| dd6856ac87fdc7fc93dc6274fad678e416712059 | https://github.com/ContaoDMS/dms/blob/dd6856ac87fdc7fc93dc6274fad678e416712059/system/modules/DocumentManagementSystem/modules/ModuleDmsManagement.php#L616-L655 | train |
ContaoDMS/dms | system/modules/DocumentManagementSystem/modules/ModuleDmsManagement.php | ModuleDmsManagement.manageDeleteDocument | private function manageDeleteDocument(&$params, &$dmsLoader, &$manageCategory, &$arrMessages, &$blnShowStart, $documentId)
{
$params->loadRootCategory = true; // get complete path to root, for checking inherited access rights
$params->loadAccessRights = true;
$params->loadDocuments = false;
$category = $dmsLoader->loadCategory($manageCategory, $params);
if (!$category->isDeletableForCurrentMember())
{
$arrMessages['errors'][] = $GLOBALS['TL_LANG']['DMS']['ERR']['manage_document_not_allowed'];
$blnShowStart = true;
}
else
{
$document = $dmsLoader->loadDocument($documentId, $params);
if ($document != null)
{
// delete the document in the database
$dmsWriter = \DmsWriter::getInstance();
if ($dmsWriter->deleteDocument($document))
{
$arrMessages['successes'][] = $GLOBALS['TL_LANG']['DMS']['SUCCESS']['document_successfully_deleted'];
// delete the file
$filePath = \DmsConfig::getDocumentFilePath($document->getFileNameVersioned());
if (file_exists(TL_ROOT . '/' . $filePath))
{
unlink($filePath);
\Dbafs::deleteResource($filePath);
$arrMessages['successes'][] = $GLOBALS['TL_LANG']['DMS']['SUCCESS']['document_file_successfully_deleted'];
}
else
{
$arrMessages['infos'][] = $GLOBALS['TL_LANG']['DMS']['INFO']['document_delete_file_not_exists'];
}
}
else
{
$arrMessages['errors'][] = $GLOBALS['TL_LANG']['DMS']['ERR']['delete_document_failed'];
}
}
else
{
$arrMessages['errors'][] = $GLOBALS['TL_LANG']['DMS']['ERR']['manage_document_not_found'];
}
$this->manageSelectDocument($params, $dmsLoader, $manageCategory, $arrMessages, $blnShowStart);
}
} | php | private function manageDeleteDocument(&$params, &$dmsLoader, &$manageCategory, &$arrMessages, &$blnShowStart, $documentId)
{
$params->loadRootCategory = true; // get complete path to root, for checking inherited access rights
$params->loadAccessRights = true;
$params->loadDocuments = false;
$category = $dmsLoader->loadCategory($manageCategory, $params);
if (!$category->isDeletableForCurrentMember())
{
$arrMessages['errors'][] = $GLOBALS['TL_LANG']['DMS']['ERR']['manage_document_not_allowed'];
$blnShowStart = true;
}
else
{
$document = $dmsLoader->loadDocument($documentId, $params);
if ($document != null)
{
// delete the document in the database
$dmsWriter = \DmsWriter::getInstance();
if ($dmsWriter->deleteDocument($document))
{
$arrMessages['successes'][] = $GLOBALS['TL_LANG']['DMS']['SUCCESS']['document_successfully_deleted'];
// delete the file
$filePath = \DmsConfig::getDocumentFilePath($document->getFileNameVersioned());
if (file_exists(TL_ROOT . '/' . $filePath))
{
unlink($filePath);
\Dbafs::deleteResource($filePath);
$arrMessages['successes'][] = $GLOBALS['TL_LANG']['DMS']['SUCCESS']['document_file_successfully_deleted'];
}
else
{
$arrMessages['infos'][] = $GLOBALS['TL_LANG']['DMS']['INFO']['document_delete_file_not_exists'];
}
}
else
{
$arrMessages['errors'][] = $GLOBALS['TL_LANG']['DMS']['ERR']['delete_document_failed'];
}
}
else
{
$arrMessages['errors'][] = $GLOBALS['TL_LANG']['DMS']['ERR']['manage_document_not_found'];
}
$this->manageSelectDocument($params, $dmsLoader, $manageCategory, $arrMessages, $blnShowStart);
}
} | [
"private",
"function",
"manageDeleteDocument",
"(",
"&",
"$",
"params",
",",
"&",
"$",
"dmsLoader",
",",
"&",
"$",
"manageCategory",
",",
"&",
"$",
"arrMessages",
",",
"&",
"$",
"blnShowStart",
",",
"$",
"documentId",
")",
"{",
"$",
"params",
"->",
"loadRootCategory",
"=",
"true",
";",
"// get complete path to root, for checking inherited access rights",
"$",
"params",
"->",
"loadAccessRights",
"=",
"true",
";",
"$",
"params",
"->",
"loadDocuments",
"=",
"false",
";",
"$",
"category",
"=",
"$",
"dmsLoader",
"->",
"loadCategory",
"(",
"$",
"manageCategory",
",",
"$",
"params",
")",
";",
"if",
"(",
"!",
"$",
"category",
"->",
"isDeletableForCurrentMember",
"(",
")",
")",
"{",
"$",
"arrMessages",
"[",
"'errors'",
"]",
"[",
"]",
"=",
"$",
"GLOBALS",
"[",
"'TL_LANG'",
"]",
"[",
"'DMS'",
"]",
"[",
"'ERR'",
"]",
"[",
"'manage_document_not_allowed'",
"]",
";",
"$",
"blnShowStart",
"=",
"true",
";",
"}",
"else",
"{",
"$",
"document",
"=",
"$",
"dmsLoader",
"->",
"loadDocument",
"(",
"$",
"documentId",
",",
"$",
"params",
")",
";",
"if",
"(",
"$",
"document",
"!=",
"null",
")",
"{",
"// delete the document in the database",
"$",
"dmsWriter",
"=",
"\\",
"DmsWriter",
"::",
"getInstance",
"(",
")",
";",
"if",
"(",
"$",
"dmsWriter",
"->",
"deleteDocument",
"(",
"$",
"document",
")",
")",
"{",
"$",
"arrMessages",
"[",
"'successes'",
"]",
"[",
"]",
"=",
"$",
"GLOBALS",
"[",
"'TL_LANG'",
"]",
"[",
"'DMS'",
"]",
"[",
"'SUCCESS'",
"]",
"[",
"'document_successfully_deleted'",
"]",
";",
"// delete the file",
"$",
"filePath",
"=",
"\\",
"DmsConfig",
"::",
"getDocumentFilePath",
"(",
"$",
"document",
"->",
"getFileNameVersioned",
"(",
")",
")",
";",
"if",
"(",
"file_exists",
"(",
"TL_ROOT",
".",
"'/'",
".",
"$",
"filePath",
")",
")",
"{",
"unlink",
"(",
"$",
"filePath",
")",
";",
"\\",
"Dbafs",
"::",
"deleteResource",
"(",
"$",
"filePath",
")",
";",
"$",
"arrMessages",
"[",
"'successes'",
"]",
"[",
"]",
"=",
"$",
"GLOBALS",
"[",
"'TL_LANG'",
"]",
"[",
"'DMS'",
"]",
"[",
"'SUCCESS'",
"]",
"[",
"'document_file_successfully_deleted'",
"]",
";",
"}",
"else",
"{",
"$",
"arrMessages",
"[",
"'infos'",
"]",
"[",
"]",
"=",
"$",
"GLOBALS",
"[",
"'TL_LANG'",
"]",
"[",
"'DMS'",
"]",
"[",
"'INFO'",
"]",
"[",
"'document_delete_file_not_exists'",
"]",
";",
"}",
"}",
"else",
"{",
"$",
"arrMessages",
"[",
"'errors'",
"]",
"[",
"]",
"=",
"$",
"GLOBALS",
"[",
"'TL_LANG'",
"]",
"[",
"'DMS'",
"]",
"[",
"'ERR'",
"]",
"[",
"'delete_document_failed'",
"]",
";",
"}",
"}",
"else",
"{",
"$",
"arrMessages",
"[",
"'errors'",
"]",
"[",
"]",
"=",
"$",
"GLOBALS",
"[",
"'TL_LANG'",
"]",
"[",
"'DMS'",
"]",
"[",
"'ERR'",
"]",
"[",
"'manage_document_not_found'",
"]",
";",
"}",
"$",
"this",
"->",
"manageSelectDocument",
"(",
"$",
"params",
",",
"$",
"dmsLoader",
",",
"$",
"manageCategory",
",",
"$",
"arrMessages",
",",
"$",
"blnShowStart",
")",
";",
"}",
"}"
]
| Execute unpublishing documents | [
"Execute",
"unpublishing",
"documents"
]
| dd6856ac87fdc7fc93dc6274fad678e416712059 | https://github.com/ContaoDMS/dms/blob/dd6856ac87fdc7fc93dc6274fad678e416712059/system/modules/DocumentManagementSystem/modules/ModuleDmsManagement.php#L704-L754 | train |
ContaoDMS/dms | system/modules/DocumentManagementSystem/modules/ModuleDmsManagement.php | ModuleDmsManagement.manageEditDocumentEnterProperties | private function manageEditDocumentEnterProperties(&$params, &$dmsLoader, &$manageCategory, &$arrMessages, &$blnShowStart, $documentId)
{
$params->loadRootCategory = true; // get complete path to root, for checking inherited access rights
$params->loadAccessRights = true;
$params->loadDocuments = false;
$category = $dmsLoader->loadCategory($manageCategory, $params);
if (!$category->isEditableForCurrentMember())
{
$arrMessages['errors'][] = $GLOBALS['TL_LANG']['DMS']['ERR']['manage_document_not_allowed'];
$blnShowStart = true;
}
else
{
$document = $dmsLoader->loadDocument($documentId, $params);
// load existing documents for file name
$params->loadCategory = true; // need the category of existing documents
$existingDocuments = $dmsLoader->loadDocuments($document->fileName, $document->fileType, $params);
$params->loadCategory = false;
$existingDocuments = array();
$blnCategoriesDiffer = false; // check if an existing document is in another category
foreach ($existingDocuments as $existingDocument)
{
if ($existingDocument->id != $documentId)
{
$existingDocuments[] = $existingDocument;
// will be true, if one is true (keep true status, if once set)
$blnCategoriesDiffer = $blnCategoriesDiffer || ($category->id != $existingDocument->categoryId);
}
}
if ($blnCategoriesDiffer)
{
$arrMessages['warnings'][] = $GLOBALS['TL_LANG']['DMS']['WARN']['edit_existing_document_in_another_catagory'];
}
$this->Template = new \FrontendTemplate("mod_dms_mgmt_manage_document_edit");
$this->Template->setData($this->arrData);
$this->Template->category = $category;
$this->Template->document = $document;
$this->Template->existingDocuments = $existingDocuments;
if (!$category->isPublishableForCurrentMember())
{
$arrMessages['infos'][] = $GLOBALS['TL_LANG']['DMS']['INFO']['publish_document_not_allowed'];
}
$blnShowStart = false;
}
} | php | private function manageEditDocumentEnterProperties(&$params, &$dmsLoader, &$manageCategory, &$arrMessages, &$blnShowStart, $documentId)
{
$params->loadRootCategory = true; // get complete path to root, for checking inherited access rights
$params->loadAccessRights = true;
$params->loadDocuments = false;
$category = $dmsLoader->loadCategory($manageCategory, $params);
if (!$category->isEditableForCurrentMember())
{
$arrMessages['errors'][] = $GLOBALS['TL_LANG']['DMS']['ERR']['manage_document_not_allowed'];
$blnShowStart = true;
}
else
{
$document = $dmsLoader->loadDocument($documentId, $params);
// load existing documents for file name
$params->loadCategory = true; // need the category of existing documents
$existingDocuments = $dmsLoader->loadDocuments($document->fileName, $document->fileType, $params);
$params->loadCategory = false;
$existingDocuments = array();
$blnCategoriesDiffer = false; // check if an existing document is in another category
foreach ($existingDocuments as $existingDocument)
{
if ($existingDocument->id != $documentId)
{
$existingDocuments[] = $existingDocument;
// will be true, if one is true (keep true status, if once set)
$blnCategoriesDiffer = $blnCategoriesDiffer || ($category->id != $existingDocument->categoryId);
}
}
if ($blnCategoriesDiffer)
{
$arrMessages['warnings'][] = $GLOBALS['TL_LANG']['DMS']['WARN']['edit_existing_document_in_another_catagory'];
}
$this->Template = new \FrontendTemplate("mod_dms_mgmt_manage_document_edit");
$this->Template->setData($this->arrData);
$this->Template->category = $category;
$this->Template->document = $document;
$this->Template->existingDocuments = $existingDocuments;
if (!$category->isPublishableForCurrentMember())
{
$arrMessages['infos'][] = $GLOBALS['TL_LANG']['DMS']['INFO']['publish_document_not_allowed'];
}
$blnShowStart = false;
}
} | [
"private",
"function",
"manageEditDocumentEnterProperties",
"(",
"&",
"$",
"params",
",",
"&",
"$",
"dmsLoader",
",",
"&",
"$",
"manageCategory",
",",
"&",
"$",
"arrMessages",
",",
"&",
"$",
"blnShowStart",
",",
"$",
"documentId",
")",
"{",
"$",
"params",
"->",
"loadRootCategory",
"=",
"true",
";",
"// get complete path to root, for checking inherited access rights",
"$",
"params",
"->",
"loadAccessRights",
"=",
"true",
";",
"$",
"params",
"->",
"loadDocuments",
"=",
"false",
";",
"$",
"category",
"=",
"$",
"dmsLoader",
"->",
"loadCategory",
"(",
"$",
"manageCategory",
",",
"$",
"params",
")",
";",
"if",
"(",
"!",
"$",
"category",
"->",
"isEditableForCurrentMember",
"(",
")",
")",
"{",
"$",
"arrMessages",
"[",
"'errors'",
"]",
"[",
"]",
"=",
"$",
"GLOBALS",
"[",
"'TL_LANG'",
"]",
"[",
"'DMS'",
"]",
"[",
"'ERR'",
"]",
"[",
"'manage_document_not_allowed'",
"]",
";",
"$",
"blnShowStart",
"=",
"true",
";",
"}",
"else",
"{",
"$",
"document",
"=",
"$",
"dmsLoader",
"->",
"loadDocument",
"(",
"$",
"documentId",
",",
"$",
"params",
")",
";",
"// load existing documents for file name",
"$",
"params",
"->",
"loadCategory",
"=",
"true",
";",
"// need the category of existing documents",
"$",
"existingDocuments",
"=",
"$",
"dmsLoader",
"->",
"loadDocuments",
"(",
"$",
"document",
"->",
"fileName",
",",
"$",
"document",
"->",
"fileType",
",",
"$",
"params",
")",
";",
"$",
"params",
"->",
"loadCategory",
"=",
"false",
";",
"$",
"existingDocuments",
"=",
"array",
"(",
")",
";",
"$",
"blnCategoriesDiffer",
"=",
"false",
";",
"// check if an existing document is in another category",
"foreach",
"(",
"$",
"existingDocuments",
"as",
"$",
"existingDocument",
")",
"{",
"if",
"(",
"$",
"existingDocument",
"->",
"id",
"!=",
"$",
"documentId",
")",
"{",
"$",
"existingDocuments",
"[",
"]",
"=",
"$",
"existingDocument",
";",
"// will be true, if one is true (keep true status, if once set)",
"$",
"blnCategoriesDiffer",
"=",
"$",
"blnCategoriesDiffer",
"||",
"(",
"$",
"category",
"->",
"id",
"!=",
"$",
"existingDocument",
"->",
"categoryId",
")",
";",
"}",
"}",
"if",
"(",
"$",
"blnCategoriesDiffer",
")",
"{",
"$",
"arrMessages",
"[",
"'warnings'",
"]",
"[",
"]",
"=",
"$",
"GLOBALS",
"[",
"'TL_LANG'",
"]",
"[",
"'DMS'",
"]",
"[",
"'WARN'",
"]",
"[",
"'edit_existing_document_in_another_catagory'",
"]",
";",
"}",
"$",
"this",
"->",
"Template",
"=",
"new",
"\\",
"FrontendTemplate",
"(",
"\"mod_dms_mgmt_manage_document_edit\"",
")",
";",
"$",
"this",
"->",
"Template",
"->",
"setData",
"(",
"$",
"this",
"->",
"arrData",
")",
";",
"$",
"this",
"->",
"Template",
"->",
"category",
"=",
"$",
"category",
";",
"$",
"this",
"->",
"Template",
"->",
"document",
"=",
"$",
"document",
";",
"$",
"this",
"->",
"Template",
"->",
"existingDocuments",
"=",
"$",
"existingDocuments",
";",
"if",
"(",
"!",
"$",
"category",
"->",
"isPublishableForCurrentMember",
"(",
")",
")",
"{",
"$",
"arrMessages",
"[",
"'infos'",
"]",
"[",
"]",
"=",
"$",
"GLOBALS",
"[",
"'TL_LANG'",
"]",
"[",
"'DMS'",
"]",
"[",
"'INFO'",
"]",
"[",
"'publish_document_not_allowed'",
"]",
";",
"}",
"$",
"blnShowStart",
"=",
"false",
";",
"}",
"}"
]
| Edit a document | [
"Edit",
"a",
"document"
]
| dd6856ac87fdc7fc93dc6274fad678e416712059 | https://github.com/ContaoDMS/dms/blob/dd6856ac87fdc7fc93dc6274fad678e416712059/system/modules/DocumentManagementSystem/modules/ModuleDmsManagement.php#L759-L810 | train |
ContaoDMS/dms | system/modules/DocumentManagementSystem/modules/ModuleDmsManagement.php | ModuleDmsManagement.applyAccessPermissionsToCategories | private function applyAccessPermissionsToCategories(Array $arrCategories)
{
$arrSecureCategories = $arrCategories;
foreach ($arrSecureCategories as $category)
{
if (!$category->isPublished() || ($this->dmsHideLockedCategories && (!$category->isUploadableForCurrentMember() && !$category->isManageableForCurrentMember())))
{
unset($arrSecureCategories[$category->id]);
}
else if ($category->hasSubCategories())
{
$arrSecureSubCategories = $this->applyAccessPermissionsToCategories($category->subCategories);
$category->subCategories = $arrSecureSubCategories;
}
}
return $arrSecureCategories;
} | php | private function applyAccessPermissionsToCategories(Array $arrCategories)
{
$arrSecureCategories = $arrCategories;
foreach ($arrSecureCategories as $category)
{
if (!$category->isPublished() || ($this->dmsHideLockedCategories && (!$category->isUploadableForCurrentMember() && !$category->isManageableForCurrentMember())))
{
unset($arrSecureCategories[$category->id]);
}
else if ($category->hasSubCategories())
{
$arrSecureSubCategories = $this->applyAccessPermissionsToCategories($category->subCategories);
$category->subCategories = $arrSecureSubCategories;
}
}
return $arrSecureCategories;
} | [
"private",
"function",
"applyAccessPermissionsToCategories",
"(",
"Array",
"$",
"arrCategories",
")",
"{",
"$",
"arrSecureCategories",
"=",
"$",
"arrCategories",
";",
"foreach",
"(",
"$",
"arrSecureCategories",
"as",
"$",
"category",
")",
"{",
"if",
"(",
"!",
"$",
"category",
"->",
"isPublished",
"(",
")",
"||",
"(",
"$",
"this",
"->",
"dmsHideLockedCategories",
"&&",
"(",
"!",
"$",
"category",
"->",
"isUploadableForCurrentMember",
"(",
")",
"&&",
"!",
"$",
"category",
"->",
"isManageableForCurrentMember",
"(",
")",
")",
")",
")",
"{",
"unset",
"(",
"$",
"arrSecureCategories",
"[",
"$",
"category",
"->",
"id",
"]",
")",
";",
"}",
"else",
"if",
"(",
"$",
"category",
"->",
"hasSubCategories",
"(",
")",
")",
"{",
"$",
"arrSecureSubCategories",
"=",
"$",
"this",
"->",
"applyAccessPermissionsToCategories",
"(",
"$",
"category",
"->",
"subCategories",
")",
";",
"$",
"category",
"->",
"subCategories",
"=",
"$",
"arrSecureSubCategories",
";",
"}",
"}",
"return",
"$",
"arrSecureCategories",
";",
"}"
]
| Apply the access permissions to the categories.
@param arr $arrCategories The structured array of categories.
@return array Returns a reduced array of categories (depends on the access permissions). | [
"Apply",
"the",
"access",
"permissions",
"to",
"the",
"categories",
"."
]
| dd6856ac87fdc7fc93dc6274fad678e416712059 | https://github.com/ContaoDMS/dms/blob/dd6856ac87fdc7fc93dc6274fad678e416712059/system/modules/DocumentManagementSystem/modules/ModuleDmsManagement.php#L969-L985 | train |
ContaoDMS/dms | system/modules/DocumentManagementSystem/dca/tl_dms_categories.php | tl_dms_categories.addBreadcrumb | public function addBreadcrumb(\DataContainer $dc)
{
// Set a new cat
if (isset($_GET['cat']))
{
$this->Session->set('tl_category_id', $this->Input->get('cat'));
$this->redirect(preg_replace('/&cat=[^&]*/', '', $this->Environment->request));
}
$intCategoryId = $this->Session->get('tl_category_id');
if ($intCategoryId < 1)
{
return;
}
$arrIds = array();
$arrLinks = array();
// Generate breadcrumb trail
$category = $this->getCategoryForId($intCategoryId, true, false);
if ($category == null)
{
$this->Session->set('tl_category_id', 0);
return;
}
// Add root link
$arrLinks[] = '<img src="system/modules/DocumentManagementSystem/assets/dms.png" width="16" height="16" alt=""> <a href="' . $this->addToUrl('cat=0') . '">' . $GLOBALS['TL_LANG']['MSC']['filterAll'] . '</a>';
foreach ($category->getPath(false) as $eachCategory)
{
$image = 'category.png';
if (!$eachCategory->isPublished())
{
$image = 'category_1.png';
}
if ($eachCategory->id == $intCategoryId)
{
$arrLinks[] = $this->generateImage('system/modules/DocumentManagementSystem/assets/' . $image, '', "") . ' ' . $eachCategory->name;
}
else
{
$arrLinks[] = $this->generateImage('system/modules/DocumentManagementSystem/assets/' . $image, '', "") . ' <a href="' . $this->addToUrl('cat='.$eachCategory->id) . '">' . $eachCategory->name . '</a>';
}
}
// Limit tree
$GLOBALS['TL_DCA']['tl_dms_categories']['list']['sorting']['root'] = array($intCategoryId);
// Insert breadcrumb menu
$GLOBALS['TL_DCA']['tl_dms_categories']['list']['sorting']['breadcrumb'] .= '
<ul id="tl_breadcrumb">
<li>' . implode(' > </li><li>', $arrLinks) . '</li>
</ul>';
} | php | public function addBreadcrumb(\DataContainer $dc)
{
// Set a new cat
if (isset($_GET['cat']))
{
$this->Session->set('tl_category_id', $this->Input->get('cat'));
$this->redirect(preg_replace('/&cat=[^&]*/', '', $this->Environment->request));
}
$intCategoryId = $this->Session->get('tl_category_id');
if ($intCategoryId < 1)
{
return;
}
$arrIds = array();
$arrLinks = array();
// Generate breadcrumb trail
$category = $this->getCategoryForId($intCategoryId, true, false);
if ($category == null)
{
$this->Session->set('tl_category_id', 0);
return;
}
// Add root link
$arrLinks[] = '<img src="system/modules/DocumentManagementSystem/assets/dms.png" width="16" height="16" alt=""> <a href="' . $this->addToUrl('cat=0') . '">' . $GLOBALS['TL_LANG']['MSC']['filterAll'] . '</a>';
foreach ($category->getPath(false) as $eachCategory)
{
$image = 'category.png';
if (!$eachCategory->isPublished())
{
$image = 'category_1.png';
}
if ($eachCategory->id == $intCategoryId)
{
$arrLinks[] = $this->generateImage('system/modules/DocumentManagementSystem/assets/' . $image, '', "") . ' ' . $eachCategory->name;
}
else
{
$arrLinks[] = $this->generateImage('system/modules/DocumentManagementSystem/assets/' . $image, '', "") . ' <a href="' . $this->addToUrl('cat='.$eachCategory->id) . '">' . $eachCategory->name . '</a>';
}
}
// Limit tree
$GLOBALS['TL_DCA']['tl_dms_categories']['list']['sorting']['root'] = array($intCategoryId);
// Insert breadcrumb menu
$GLOBALS['TL_DCA']['tl_dms_categories']['list']['sorting']['breadcrumb'] .= '
<ul id="tl_breadcrumb">
<li>' . implode(' > </li><li>', $arrLinks) . '</li>
</ul>';
} | [
"public",
"function",
"addBreadcrumb",
"(",
"\\",
"DataContainer",
"$",
"dc",
")",
"{",
"// Set a new cat",
"if",
"(",
"isset",
"(",
"$",
"_GET",
"[",
"'cat'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"Session",
"->",
"set",
"(",
"'tl_category_id'",
",",
"$",
"this",
"->",
"Input",
"->",
"get",
"(",
"'cat'",
")",
")",
";",
"$",
"this",
"->",
"redirect",
"(",
"preg_replace",
"(",
"'/&cat=[^&]*/'",
",",
"''",
",",
"$",
"this",
"->",
"Environment",
"->",
"request",
")",
")",
";",
"}",
"$",
"intCategoryId",
"=",
"$",
"this",
"->",
"Session",
"->",
"get",
"(",
"'tl_category_id'",
")",
";",
"if",
"(",
"$",
"intCategoryId",
"<",
"1",
")",
"{",
"return",
";",
"}",
"$",
"arrIds",
"=",
"array",
"(",
")",
";",
"$",
"arrLinks",
"=",
"array",
"(",
")",
";",
"// Generate breadcrumb trail",
"$",
"category",
"=",
"$",
"this",
"->",
"getCategoryForId",
"(",
"$",
"intCategoryId",
",",
"true",
",",
"false",
")",
";",
"if",
"(",
"$",
"category",
"==",
"null",
")",
"{",
"$",
"this",
"->",
"Session",
"->",
"set",
"(",
"'tl_category_id'",
",",
"0",
")",
";",
"return",
";",
"}",
"// Add root link",
"$",
"arrLinks",
"[",
"]",
"=",
"'<img src=\"system/modules/DocumentManagementSystem/assets/dms.png\" width=\"16\" height=\"16\" alt=\"\"> <a href=\"'",
".",
"$",
"this",
"->",
"addToUrl",
"(",
"'cat=0'",
")",
".",
"'\">'",
".",
"$",
"GLOBALS",
"[",
"'TL_LANG'",
"]",
"[",
"'MSC'",
"]",
"[",
"'filterAll'",
"]",
".",
"'</a>'",
";",
"foreach",
"(",
"$",
"category",
"->",
"getPath",
"(",
"false",
")",
"as",
"$",
"eachCategory",
")",
"{",
"$",
"image",
"=",
"'category.png'",
";",
"if",
"(",
"!",
"$",
"eachCategory",
"->",
"isPublished",
"(",
")",
")",
"{",
"$",
"image",
"=",
"'category_1.png'",
";",
"}",
"if",
"(",
"$",
"eachCategory",
"->",
"id",
"==",
"$",
"intCategoryId",
")",
"{",
"$",
"arrLinks",
"[",
"]",
"=",
"$",
"this",
"->",
"generateImage",
"(",
"'system/modules/DocumentManagementSystem/assets/'",
".",
"$",
"image",
",",
"''",
",",
"\"\"",
")",
".",
"' '",
".",
"$",
"eachCategory",
"->",
"name",
";",
"}",
"else",
"{",
"$",
"arrLinks",
"[",
"]",
"=",
"$",
"this",
"->",
"generateImage",
"(",
"'system/modules/DocumentManagementSystem/assets/'",
".",
"$",
"image",
",",
"''",
",",
"\"\"",
")",
".",
"' <a href=\"'",
".",
"$",
"this",
"->",
"addToUrl",
"(",
"'cat='",
".",
"$",
"eachCategory",
"->",
"id",
")",
".",
"'\">'",
".",
"$",
"eachCategory",
"->",
"name",
".",
"'</a>'",
";",
"}",
"}",
"// Limit tree",
"$",
"GLOBALS",
"[",
"'TL_DCA'",
"]",
"[",
"'tl_dms_categories'",
"]",
"[",
"'list'",
"]",
"[",
"'sorting'",
"]",
"[",
"'root'",
"]",
"=",
"array",
"(",
"$",
"intCategoryId",
")",
";",
"// Insert breadcrumb menu",
"$",
"GLOBALS",
"[",
"'TL_DCA'",
"]",
"[",
"'tl_dms_categories'",
"]",
"[",
"'list'",
"]",
"[",
"'sorting'",
"]",
"[",
"'breadcrumb'",
"]",
".=",
"'\n\n<ul id=\"tl_breadcrumb\">\n <li>'",
".",
"implode",
"(",
"' > </li><li>'",
",",
"$",
"arrLinks",
")",
".",
"'</li>\n</ul>'",
";",
"}"
]
| Add the breadcrumb menu | [
"Add",
"the",
"breadcrumb",
"menu"
]
| dd6856ac87fdc7fc93dc6274fad678e416712059 | https://github.com/ContaoDMS/dms/blob/dd6856ac87fdc7fc93dc6274fad678e416712059/system/modules/DocumentManagementSystem/dca/tl_dms_categories.php#L439-L495 | train |
ContaoDMS/dms | system/modules/DocumentManagementSystem/dca/tl_dms_categories.php | tl_dms_categories.checkPermission | public function checkPermission()
{
// Check current action
switch ($this->Input->get('act'))
{
case 'delete':
if (!$this->isCategoryDeletable($this->Input->get('id')))
{
$this->log('Deleting the non empty category with ID "'.$this->Input->get('id').'" is not allowed.', 'tl_dms_categories checkPermission', TL_ERROR);
$this->redirect('contao/main.php?act=error');
}
break;
}
} | php | public function checkPermission()
{
// Check current action
switch ($this->Input->get('act'))
{
case 'delete':
if (!$this->isCategoryDeletable($this->Input->get('id')))
{
$this->log('Deleting the non empty category with ID "'.$this->Input->get('id').'" is not allowed.', 'tl_dms_categories checkPermission', TL_ERROR);
$this->redirect('contao/main.php?act=error');
}
break;
}
} | [
"public",
"function",
"checkPermission",
"(",
")",
"{",
"// Check current action",
"switch",
"(",
"$",
"this",
"->",
"Input",
"->",
"get",
"(",
"'act'",
")",
")",
"{",
"case",
"'delete'",
":",
"if",
"(",
"!",
"$",
"this",
"->",
"isCategoryDeletable",
"(",
"$",
"this",
"->",
"Input",
"->",
"get",
"(",
"'id'",
")",
")",
")",
"{",
"$",
"this",
"->",
"log",
"(",
"'Deleting the non empty category with ID \"'",
".",
"$",
"this",
"->",
"Input",
"->",
"get",
"(",
"'id'",
")",
".",
"'\" is not allowed.'",
",",
"'tl_dms_categories checkPermission'",
",",
"TL_ERROR",
")",
";",
"$",
"this",
"->",
"redirect",
"(",
"'contao/main.php?act=error'",
")",
";",
"}",
"break",
";",
"}",
"}"
]
| Check permissions to avoid not allowd deleting | [
"Check",
"permissions",
"to",
"avoid",
"not",
"allowd",
"deleting"
]
| dd6856ac87fdc7fc93dc6274fad678e416712059 | https://github.com/ContaoDMS/dms/blob/dd6856ac87fdc7fc93dc6274fad678e416712059/system/modules/DocumentManagementSystem/dca/tl_dms_categories.php#L500-L513 | train |
ContaoDMS/dms | system/modules/DocumentManagementSystem/dca/tl_dms_categories.php | tl_dms_categories.getDeleteButton | public function getDeleteButton($row, $href, $label, $title, $icon, $attributes)
{
if (!$this->isCategoryDeletable($row['id']))
{
return $this->generateImage('delete_.gif', $GLOBALS['TL_LANG']['tl_dms_categories']['delete_'][0], 'title="' . sprintf($GLOBALS['TL_LANG']['tl_dms_categories']['delete_'][1], $row['id']) . '"') . " ";
}
return '<a href="'.$this->addToUrl($href.'&id='.$row['id']).'" title="'.specialchars($title).'"'.$attributes.'>'.$this->generateImage($icon, $label).'</a> ';
} | php | public function getDeleteButton($row, $href, $label, $title, $icon, $attributes)
{
if (!$this->isCategoryDeletable($row['id']))
{
return $this->generateImage('delete_.gif', $GLOBALS['TL_LANG']['tl_dms_categories']['delete_'][0], 'title="' . sprintf($GLOBALS['TL_LANG']['tl_dms_categories']['delete_'][1], $row['id']) . '"') . " ";
}
return '<a href="'.$this->addToUrl($href.'&id='.$row['id']).'" title="'.specialchars($title).'"'.$attributes.'>'.$this->generateImage($icon, $label).'</a> ';
} | [
"public",
"function",
"getDeleteButton",
"(",
"$",
"row",
",",
"$",
"href",
",",
"$",
"label",
",",
"$",
"title",
",",
"$",
"icon",
",",
"$",
"attributes",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isCategoryDeletable",
"(",
"$",
"row",
"[",
"'id'",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"generateImage",
"(",
"'delete_.gif'",
",",
"$",
"GLOBALS",
"[",
"'TL_LANG'",
"]",
"[",
"'tl_dms_categories'",
"]",
"[",
"'delete_'",
"]",
"[",
"0",
"]",
",",
"'title=\"'",
".",
"sprintf",
"(",
"$",
"GLOBALS",
"[",
"'TL_LANG'",
"]",
"[",
"'tl_dms_categories'",
"]",
"[",
"'delete_'",
"]",
"[",
"1",
"]",
",",
"$",
"row",
"[",
"'id'",
"]",
")",
".",
"'\"'",
")",
".",
"\" \"",
";",
"}",
"return",
"'<a href=\"'",
".",
"$",
"this",
"->",
"addToUrl",
"(",
"$",
"href",
".",
"'&id='",
".",
"$",
"row",
"[",
"'id'",
"]",
")",
".",
"'\" title=\"'",
".",
"specialchars",
"(",
"$",
"title",
")",
".",
"'\"'",
".",
"$",
"attributes",
".",
"'>'",
".",
"$",
"this",
"->",
"generateImage",
"(",
"$",
"icon",
",",
"$",
"label",
")",
".",
"'</a> '",
";",
"}"
]
| Return the "delete" button
@param array
@param string
@param string
@param string
@param string
@param string
@return string | [
"Return",
"the",
"delete",
"button"
]
| dd6856ac87fdc7fc93dc6274fad678e416712059 | https://github.com/ContaoDMS/dms/blob/dd6856ac87fdc7fc93dc6274fad678e416712059/system/modules/DocumentManagementSystem/dca/tl_dms_categories.php#L525-L532 | train |
ContaoDMS/dms | system/modules/DocumentManagementSystem/dca/tl_dms_categories.php | tl_dms_categories.saveFileTypes | public function saveFileTypes($varValue, DataContainer $dc)
{
if (strlen($varValue) > 0)
{
$arrFileTypes = \DmsUtils::getUniqueFileTypes($varValue);
$varValue = implode(",", $arrFileTypes);
}
return $varValue;
} | php | public function saveFileTypes($varValue, DataContainer $dc)
{
if (strlen($varValue) > 0)
{
$arrFileTypes = \DmsUtils::getUniqueFileTypes($varValue);
$varValue = implode(",", $arrFileTypes);
}
return $varValue;
} | [
"public",
"function",
"saveFileTypes",
"(",
"$",
"varValue",
",",
"DataContainer",
"$",
"dc",
")",
"{",
"if",
"(",
"strlen",
"(",
"$",
"varValue",
")",
">",
"0",
")",
"{",
"$",
"arrFileTypes",
"=",
"\\",
"DmsUtils",
"::",
"getUniqueFileTypes",
"(",
"$",
"varValue",
")",
";",
"$",
"varValue",
"=",
"implode",
"(",
"\",\"",
",",
"$",
"arrFileTypes",
")",
";",
"}",
"return",
"$",
"varValue",
";",
"}"
]
| Cleanup the files types before saving | [
"Cleanup",
"the",
"files",
"types",
"before",
"saving"
]
| dd6856ac87fdc7fc93dc6274fad678e416712059 | https://github.com/ContaoDMS/dms/blob/dd6856ac87fdc7fc93dc6274fad678e416712059/system/modules/DocumentManagementSystem/dca/tl_dms_categories.php#L576-L585 | train |
ContaoDMS/dms | system/modules/DocumentManagementSystem/dca/tl_settings.php | tl_settings_dms.getPhpUploadMaxFilesize | private function getPhpUploadMaxFilesize()
{
$param = trim(ini_get('upload_max_filesize'));
$unit = strtolower(substr($param, -1));
$val = (double) $param;
switch($unit)
{
case 'k':
$val = \Document::convertFileSize((double) substr($param, 0, - 1), \Document::FILE_SIZE_UNIT_KB, \Document::FILE_SIZE_UNIT_BYTE);
break;
case 'm':
$val = \Document::convertFileSize((double) substr($param, 0, - 1), \Document::FILE_SIZE_UNIT_MB, \Document::FILE_SIZE_UNIT_BYTE);
break;
case 'g':
$val = \Document::convertFileSize((double) substr($param, 0, - 1), \Document::FILE_SIZE_UNIT_GB, \Document::FILE_SIZE_UNIT_BYTE);
break;
}
if (!is_double($val))
{
throw new \Exception('PHP value for upload_max_filesize could not be determined.');
}
return $val;
} | php | private function getPhpUploadMaxFilesize()
{
$param = trim(ini_get('upload_max_filesize'));
$unit = strtolower(substr($param, -1));
$val = (double) $param;
switch($unit)
{
case 'k':
$val = \Document::convertFileSize((double) substr($param, 0, - 1), \Document::FILE_SIZE_UNIT_KB, \Document::FILE_SIZE_UNIT_BYTE);
break;
case 'm':
$val = \Document::convertFileSize((double) substr($param, 0, - 1), \Document::FILE_SIZE_UNIT_MB, \Document::FILE_SIZE_UNIT_BYTE);
break;
case 'g':
$val = \Document::convertFileSize((double) substr($param, 0, - 1), \Document::FILE_SIZE_UNIT_GB, \Document::FILE_SIZE_UNIT_BYTE);
break;
}
if (!is_double($val))
{
throw new \Exception('PHP value for upload_max_filesize could not be determined.');
}
return $val;
} | [
"private",
"function",
"getPhpUploadMaxFilesize",
"(",
")",
"{",
"$",
"param",
"=",
"trim",
"(",
"ini_get",
"(",
"'upload_max_filesize'",
")",
")",
";",
"$",
"unit",
"=",
"strtolower",
"(",
"substr",
"(",
"$",
"param",
",",
"-",
"1",
")",
")",
";",
"$",
"val",
"=",
"(",
"double",
")",
"$",
"param",
";",
"switch",
"(",
"$",
"unit",
")",
"{",
"case",
"'k'",
":",
"$",
"val",
"=",
"\\",
"Document",
"::",
"convertFileSize",
"(",
"(",
"double",
")",
"substr",
"(",
"$",
"param",
",",
"0",
",",
"-",
"1",
")",
",",
"\\",
"Document",
"::",
"FILE_SIZE_UNIT_KB",
",",
"\\",
"Document",
"::",
"FILE_SIZE_UNIT_BYTE",
")",
";",
"break",
";",
"case",
"'m'",
":",
"$",
"val",
"=",
"\\",
"Document",
"::",
"convertFileSize",
"(",
"(",
"double",
")",
"substr",
"(",
"$",
"param",
",",
"0",
",",
"-",
"1",
")",
",",
"\\",
"Document",
"::",
"FILE_SIZE_UNIT_MB",
",",
"\\",
"Document",
"::",
"FILE_SIZE_UNIT_BYTE",
")",
";",
"break",
";",
"case",
"'g'",
":",
"$",
"val",
"=",
"\\",
"Document",
"::",
"convertFileSize",
"(",
"(",
"double",
")",
"substr",
"(",
"$",
"param",
",",
"0",
",",
"-",
"1",
")",
",",
"\\",
"Document",
"::",
"FILE_SIZE_UNIT_GB",
",",
"\\",
"Document",
"::",
"FILE_SIZE_UNIT_BYTE",
")",
";",
"break",
";",
"}",
"if",
"(",
"!",
"is_double",
"(",
"$",
"val",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'PHP value for upload_max_filesize could not be determined.'",
")",
";",
"}",
"return",
"$",
"val",
";",
"}"
]
| Get the value of the upload_max_filesize set in PHP.
@return int The int value of the upload_max_filesize set in PHP in byte. | [
"Get",
"the",
"value",
"of",
"the",
"upload_max_filesize",
"set",
"in",
"PHP",
"."
]
| dd6856ac87fdc7fc93dc6274fad678e416712059 | https://github.com/ContaoDMS/dms/blob/dd6856ac87fdc7fc93dc6274fad678e416712059/system/modules/DocumentManagementSystem/dca/tl_settings.php#L108-L131 | train |
rephluX/laravel-pagetitle | src/PageTitle.php | PageTitle.add | public function add($item)
{
if (is_array($item)) {
return array_map([$this, 'add'], $item);
}
if (! $item | strlen(trim($item)) === 0) {
return false;
}
$this->collection[] = trim(strip_tags($item));
} | php | public function add($item)
{
if (is_array($item)) {
return array_map([$this, 'add'], $item);
}
if (! $item | strlen(trim($item)) === 0) {
return false;
}
$this->collection[] = trim(strip_tags($item));
} | [
"public",
"function",
"add",
"(",
"$",
"item",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"item",
")",
")",
"{",
"return",
"array_map",
"(",
"[",
"$",
"this",
",",
"'add'",
"]",
",",
"$",
"item",
")",
";",
"}",
"if",
"(",
"!",
"$",
"item",
"|",
"strlen",
"(",
"trim",
"(",
"$",
"item",
")",
")",
"===",
"0",
")",
"{",
"return",
"false",
";",
"}",
"$",
"this",
"->",
"collection",
"[",
"]",
"=",
"trim",
"(",
"strip_tags",
"(",
"$",
"item",
")",
")",
";",
"}"
]
| Add an item to the collection.
@param $item
@return mixed | [
"Add",
"an",
"item",
"to",
"the",
"collection",
"."
]
| 49efdb9bacb29794abc6b2c1a30629f287f9c873 | https://github.com/rephluX/laravel-pagetitle/blob/49efdb9bacb29794abc6b2c1a30629f287f9c873/src/PageTitle.php#L121-L132 | train |
rephluX/laravel-pagetitle | src/PageTitle.php | PageTitle.get | public function get($direction = 'regular')
{
if ($this->count() == 0) {
return $this->default;
}
if ($direction === 'downward') {
$this->collection = array_reverse($this->collection);
}
$this->addPageName();
if ($direction === 'reverse') {
$this->collection = array_reverse($this->collection);
}
return implode($this->getDelimeter(), $this->collection);
} | php | public function get($direction = 'regular')
{
if ($this->count() == 0) {
return $this->default;
}
if ($direction === 'downward') {
$this->collection = array_reverse($this->collection);
}
$this->addPageName();
if ($direction === 'reverse') {
$this->collection = array_reverse($this->collection);
}
return implode($this->getDelimeter(), $this->collection);
} | [
"public",
"function",
"get",
"(",
"$",
"direction",
"=",
"'regular'",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"count",
"(",
")",
"==",
"0",
")",
"{",
"return",
"$",
"this",
"->",
"default",
";",
"}",
"if",
"(",
"$",
"direction",
"===",
"'downward'",
")",
"{",
"$",
"this",
"->",
"collection",
"=",
"array_reverse",
"(",
"$",
"this",
"->",
"collection",
")",
";",
"}",
"$",
"this",
"->",
"addPageName",
"(",
")",
";",
"if",
"(",
"$",
"direction",
"===",
"'reverse'",
")",
"{",
"$",
"this",
"->",
"collection",
"=",
"array_reverse",
"(",
"$",
"this",
"->",
"collection",
")",
";",
"}",
"return",
"implode",
"(",
"$",
"this",
"->",
"getDelimeter",
"(",
")",
",",
"$",
"this",
"->",
"collection",
")",
";",
"}"
]
| Get the page title.
@param bool|string $direction
@return string | [
"Get",
"the",
"page",
"title",
"."
]
| 49efdb9bacb29794abc6b2c1a30629f287f9c873 | https://github.com/rephluX/laravel-pagetitle/blob/49efdb9bacb29794abc6b2c1a30629f287f9c873/src/PageTitle.php#L151-L168 | train |
rephluX/laravel-pagetitle | src/PageTitle.php | PageTitle.addPageName | protected function addPageName()
{
if (! empty($this->getPageName()) && ! in_array($this->getPageName(), $this->collection)) {
$this->add($this->getPageName());
}
} | php | protected function addPageName()
{
if (! empty($this->getPageName()) && ! in_array($this->getPageName(), $this->collection)) {
$this->add($this->getPageName());
}
} | [
"protected",
"function",
"addPageName",
"(",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"getPageName",
"(",
")",
")",
"&&",
"!",
"in_array",
"(",
"$",
"this",
"->",
"getPageName",
"(",
")",
",",
"$",
"this",
"->",
"collection",
")",
")",
"{",
"$",
"this",
"->",
"add",
"(",
"$",
"this",
"->",
"getPageName",
"(",
")",
")",
";",
"}",
"}"
]
| Add the page name to the collection. | [
"Add",
"the",
"page",
"name",
"to",
"the",
"collection",
"."
]
| 49efdb9bacb29794abc6b2c1a30629f287f9c873 | https://github.com/rephluX/laravel-pagetitle/blob/49efdb9bacb29794abc6b2c1a30629f287f9c873/src/PageTitle.php#L173-L178 | train |
ContaoDMS/dms | system/modules/DocumentManagementSystem/classes/pojos/AccessRight.php | AccessRight.isActive | public function isActive()
{
$time = time();
$active = ($this->active && ($this->activationStart == '' || $this->activationStart < $time) && ($this->activationStop == '' || $this->activationStop > $time));
return $active;
} | php | public function isActive()
{
$time = time();
$active = ($this->active && ($this->activationStart == '' || $this->activationStart < $time) && ($this->activationStop == '' || $this->activationStop > $time));
return $active;
} | [
"public",
"function",
"isActive",
"(",
")",
"{",
"$",
"time",
"=",
"time",
"(",
")",
";",
"$",
"active",
"=",
"(",
"$",
"this",
"->",
"active",
"&&",
"(",
"$",
"this",
"->",
"activationStart",
"==",
"''",
"||",
"$",
"this",
"->",
"activationStart",
"<",
"$",
"time",
")",
"&&",
"(",
"$",
"this",
"->",
"activationStop",
"==",
"''",
"||",
"$",
"this",
"->",
"activationStop",
">",
"$",
"time",
")",
")",
";",
"return",
"$",
"active",
";",
"}"
]
| Return if this access right is active.
@return bool True if this access right is active. | [
"Return",
"if",
"this",
"access",
"right",
"is",
"active",
"."
]
| dd6856ac87fdc7fc93dc6274fad678e416712059 | https://github.com/ContaoDMS/dms/blob/dd6856ac87fdc7fc93dc6274fad678e416712059/system/modules/DocumentManagementSystem/classes/pojos/AccessRight.php#L241-L246 | train |
FreeDSx/ASN1 | src/FreeDSx/Asn1/Type/BitStringType.php | BitStringType.toBinary | public function toBinary()
{
$bytes = '';
foreach (str_split($this->value, 8) as $piece) {
$bytes .= chr(bindec($piece));
}
return $bytes;
} | php | public function toBinary()
{
$bytes = '';
foreach (str_split($this->value, 8) as $piece) {
$bytes .= chr(bindec($piece));
}
return $bytes;
} | [
"public",
"function",
"toBinary",
"(",
")",
"{",
"$",
"bytes",
"=",
"''",
";",
"foreach",
"(",
"str_split",
"(",
"$",
"this",
"->",
"value",
",",
"8",
")",
"as",
"$",
"piece",
")",
"{",
"$",
"bytes",
".=",
"chr",
"(",
"bindec",
"(",
"$",
"piece",
")",
")",
";",
"}",
"return",
"$",
"bytes",
";",
"}"
]
| Get the packed binary representation.
@return string | [
"Get",
"the",
"packed",
"binary",
"representation",
"."
]
| 0b0a35a2fd3a8fa0c945f91e9cdcf17eaa3789e5 | https://github.com/FreeDSx/ASN1/blob/0b0a35a2fd3a8fa0c945f91e9cdcf17eaa3789e5/src/FreeDSx/Asn1/Type/BitStringType.php#L64-L73 | train |
FreeDSx/ASN1 | src/FreeDSx/Asn1/Type/BitStringType.php | BitStringType.fromBinary | public static function fromBinary($bytes, ?int $minLength = null)
{
$bitstring = '';
$length = strlen($bytes);
for ($i = 0; $i < $length; $i++) {
$bitstring .= sprintf('%08d', decbin(ord($bytes[$i])));
}
if ($minLength && strlen($bitstring) < $minLength) {
$bitstring = str_pad($bitstring, $minLength, '0');
}
return new self($bitstring);
} | php | public static function fromBinary($bytes, ?int $minLength = null)
{
$bitstring = '';
$length = strlen($bytes);
for ($i = 0; $i < $length; $i++) {
$bitstring .= sprintf('%08d', decbin(ord($bytes[$i])));
}
if ($minLength && strlen($bitstring) < $minLength) {
$bitstring = str_pad($bitstring, $minLength, '0');
}
return new self($bitstring);
} | [
"public",
"static",
"function",
"fromBinary",
"(",
"$",
"bytes",
",",
"?",
"int",
"$",
"minLength",
"=",
"null",
")",
"{",
"$",
"bitstring",
"=",
"''",
";",
"$",
"length",
"=",
"strlen",
"(",
"$",
"bytes",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"length",
";",
"$",
"i",
"++",
")",
"{",
"$",
"bitstring",
".=",
"sprintf",
"(",
"'%08d'",
",",
"decbin",
"(",
"ord",
"(",
"$",
"bytes",
"[",
"$",
"i",
"]",
")",
")",
")",
";",
"}",
"if",
"(",
"$",
"minLength",
"&&",
"strlen",
"(",
"$",
"bitstring",
")",
"<",
"$",
"minLength",
")",
"{",
"$",
"bitstring",
"=",
"str_pad",
"(",
"$",
"bitstring",
",",
"$",
"minLength",
",",
"'0'",
")",
";",
"}",
"return",
"new",
"self",
"(",
"$",
"bitstring",
")",
";",
"}"
]
| Construct the bit string from a binary string value.
@param $bytes
@param int|null $minLength
@return BitStringType | [
"Construct",
"the",
"bit",
"string",
"from",
"a",
"binary",
"string",
"value",
"."
]
| 0b0a35a2fd3a8fa0c945f91e9cdcf17eaa3789e5 | https://github.com/FreeDSx/ASN1/blob/0b0a35a2fd3a8fa0c945f91e9cdcf17eaa3789e5/src/FreeDSx/Asn1/Type/BitStringType.php#L82-L95 | train |
FreeDSx/ASN1 | src/FreeDSx/Asn1/Type/BitStringType.php | BitStringType.fromInteger | public static function fromInteger(int $int, ?int $minLength = null)
{
$pieces = str_split(decbin($int), 8);
$num = count($pieces);
if ($num === 1 && strlen($pieces[0]) !== 8) {
$pieces[0] = str_pad($pieces[0], 8, '0', STR_PAD_LEFT);
} elseif ($num > 0 && strlen($pieces[$num - 1]) !== 8) {
$pieces[$num - 1] = str_pad($pieces[$num - 1], 8, '0', STR_PAD_RIGHT);
}
$bitstring = implode('', $pieces);
if ($minLength && strlen($bitstring) < $minLength) {
$bitstring = str_pad($bitstring, $minLength, '0');
}
return new self($bitstring);
} | php | public static function fromInteger(int $int, ?int $minLength = null)
{
$pieces = str_split(decbin($int), 8);
$num = count($pieces);
if ($num === 1 && strlen($pieces[0]) !== 8) {
$pieces[0] = str_pad($pieces[0], 8, '0', STR_PAD_LEFT);
} elseif ($num > 0 && strlen($pieces[$num - 1]) !== 8) {
$pieces[$num - 1] = str_pad($pieces[$num - 1], 8, '0', STR_PAD_RIGHT);
}
$bitstring = implode('', $pieces);
if ($minLength && strlen($bitstring) < $minLength) {
$bitstring = str_pad($bitstring, $minLength, '0');
}
return new self($bitstring);
} | [
"public",
"static",
"function",
"fromInteger",
"(",
"int",
"$",
"int",
",",
"?",
"int",
"$",
"minLength",
"=",
"null",
")",
"{",
"$",
"pieces",
"=",
"str_split",
"(",
"decbin",
"(",
"$",
"int",
")",
",",
"8",
")",
";",
"$",
"num",
"=",
"count",
"(",
"$",
"pieces",
")",
";",
"if",
"(",
"$",
"num",
"===",
"1",
"&&",
"strlen",
"(",
"$",
"pieces",
"[",
"0",
"]",
")",
"!==",
"8",
")",
"{",
"$",
"pieces",
"[",
"0",
"]",
"=",
"str_pad",
"(",
"$",
"pieces",
"[",
"0",
"]",
",",
"8",
",",
"'0'",
",",
"STR_PAD_LEFT",
")",
";",
"}",
"elseif",
"(",
"$",
"num",
">",
"0",
"&&",
"strlen",
"(",
"$",
"pieces",
"[",
"$",
"num",
"-",
"1",
"]",
")",
"!==",
"8",
")",
"{",
"$",
"pieces",
"[",
"$",
"num",
"-",
"1",
"]",
"=",
"str_pad",
"(",
"$",
"pieces",
"[",
"$",
"num",
"-",
"1",
"]",
",",
"8",
",",
"'0'",
",",
"STR_PAD_RIGHT",
")",
";",
"}",
"$",
"bitstring",
"=",
"implode",
"(",
"''",
",",
"$",
"pieces",
")",
";",
"if",
"(",
"$",
"minLength",
"&&",
"strlen",
"(",
"$",
"bitstring",
")",
"<",
"$",
"minLength",
")",
"{",
"$",
"bitstring",
"=",
"str_pad",
"(",
"$",
"bitstring",
",",
"$",
"minLength",
",",
"'0'",
")",
";",
"}",
"return",
"new",
"self",
"(",
"$",
"bitstring",
")",
";",
"}"
]
| Construct the bit string from an integer.
@param int $int
@param int|null $minLength
@return BitStringType | [
"Construct",
"the",
"bit",
"string",
"from",
"an",
"integer",
"."
]
| 0b0a35a2fd3a8fa0c945f91e9cdcf17eaa3789e5 | https://github.com/FreeDSx/ASN1/blob/0b0a35a2fd3a8fa0c945f91e9cdcf17eaa3789e5/src/FreeDSx/Asn1/Type/BitStringType.php#L104-L121 | train |
ContaoDMS/dms | system/modules/DocumentManagementSystem/classes/DmsWriter.php | DmsWriter.storeDocument | public function storeDocument(\Document $document)
{
$arrSet = $this->buildDocumentDataArray($document, false);
$objDocument = $this->Database->prepare("INSERT INTO tl_dms_documents %s")->set($arrSet)->execute();
$document->id = $objDocument->insertId;
return $document;
} | php | public function storeDocument(\Document $document)
{
$arrSet = $this->buildDocumentDataArray($document, false);
$objDocument = $this->Database->prepare("INSERT INTO tl_dms_documents %s")->set($arrSet)->execute();
$document->id = $objDocument->insertId;
return $document;
} | [
"public",
"function",
"storeDocument",
"(",
"\\",
"Document",
"$",
"document",
")",
"{",
"$",
"arrSet",
"=",
"$",
"this",
"->",
"buildDocumentDataArray",
"(",
"$",
"document",
",",
"false",
")",
";",
"$",
"objDocument",
"=",
"$",
"this",
"->",
"Database",
"->",
"prepare",
"(",
"\"INSERT INTO tl_dms_documents %s\"",
")",
"->",
"set",
"(",
"$",
"arrSet",
")",
"->",
"execute",
"(",
")",
";",
"$",
"document",
"->",
"id",
"=",
"$",
"objDocument",
"->",
"insertId",
";",
"return",
"$",
"document",
";",
"}"
]
| Store the new document in the given category.
@param Document $document The document to store.
@return document Returns the document. | [
"Store",
"the",
"new",
"document",
"in",
"the",
"given",
"category",
"."
]
| dd6856ac87fdc7fc93dc6274fad678e416712059 | https://github.com/ContaoDMS/dms/blob/dd6856ac87fdc7fc93dc6274fad678e416712059/system/modules/DocumentManagementSystem/classes/DmsWriter.php#L77-L85 | train |
ContaoDMS/dms | system/modules/DocumentManagementSystem/classes/DmsWriter.php | DmsWriter.updateDocument | public function updateDocument(\Document $document)
{
$arrSet = $this->buildDocumentDataArray($document, false);
$this->Database->prepare("UPDATE tl_dms_documents %s WHERE id=?")->set($arrSet)->execute($document->id);
return $document;
} | php | public function updateDocument(\Document $document)
{
$arrSet = $this->buildDocumentDataArray($document, false);
$this->Database->prepare("UPDATE tl_dms_documents %s WHERE id=?")->set($arrSet)->execute($document->id);
return $document;
} | [
"public",
"function",
"updateDocument",
"(",
"\\",
"Document",
"$",
"document",
")",
"{",
"$",
"arrSet",
"=",
"$",
"this",
"->",
"buildDocumentDataArray",
"(",
"$",
"document",
",",
"false",
")",
";",
"$",
"this",
"->",
"Database",
"->",
"prepare",
"(",
"\"UPDATE tl_dms_documents %s WHERE id=?\"",
")",
"->",
"set",
"(",
"$",
"arrSet",
")",
"->",
"execute",
"(",
"$",
"document",
"->",
"id",
")",
";",
"return",
"$",
"document",
";",
"}"
]
| Update the document.
@param Document $document The document to update.
@return document Returns the document. | [
"Update",
"the",
"document",
"."
]
| dd6856ac87fdc7fc93dc6274fad678e416712059 | https://github.com/ContaoDMS/dms/blob/dd6856ac87fdc7fc93dc6274fad678e416712059/system/modules/DocumentManagementSystem/classes/DmsWriter.php#L93-L100 | train |
heimrichhannot/contao-encore-bundle | src/EventListener/HookListener.php | HookListener.addEncore | public function addEncore(PageModel $page, LayoutModel $layout, PageRegular $pageRegular)
{
$this->doAddEncore($page, $layout, $pageRegular);
} | php | public function addEncore(PageModel $page, LayoutModel $layout, PageRegular $pageRegular)
{
$this->doAddEncore($page, $layout, $pageRegular);
} | [
"public",
"function",
"addEncore",
"(",
"PageModel",
"$",
"page",
",",
"LayoutModel",
"$",
"layout",
",",
"PageRegular",
"$",
"pageRegular",
")",
"{",
"$",
"this",
"->",
"doAddEncore",
"(",
"$",
"page",
",",
"$",
"layout",
",",
"$",
"pageRegular",
")",
";",
"}"
]
| Modify the page object.
@param PageModel $page
@param LayoutModel $layout
@param PageRegular $pageRegular | [
"Modify",
"the",
"page",
"object",
"."
]
| 98c3a72293ebd6421e0f6d99bca5f0bd78299e01 | https://github.com/heimrichhannot/contao-encore-bundle/blob/98c3a72293ebd6421e0f6d99bca5f0bd78299e01/src/EventListener/HookListener.php#L62-L65 | train |
ContaoDMS/dms | system/modules/DocumentManagementSystem/dca/tl_dms_documents.php | tl_dms_documents.getValidFileTypesForCategory | public static function getValidFileTypesForCategory()
{
$db = \Database::getInstance();
$input = \Input::getInstance();
if($db->tableExists('tl_dms_categories') && $db->tableExists('tl_dms_documents'))
{
$objCategory = $db->prepare('SELECT cat.* FROM tl_dms_categories cat JOIN tl_dms_documents doc ON doc.pid = cat.id WHERE doc.id = ?')->execute($input->get('id'));
if ($objCategory->numRows)
{
return $objCategory->file_types;
}
}
return "";
} | php | public static function getValidFileTypesForCategory()
{
$db = \Database::getInstance();
$input = \Input::getInstance();
if($db->tableExists('tl_dms_categories') && $db->tableExists('tl_dms_documents'))
{
$objCategory = $db->prepare('SELECT cat.* FROM tl_dms_categories cat JOIN tl_dms_documents doc ON doc.pid = cat.id WHERE doc.id = ?')->execute($input->get('id'));
if ($objCategory->numRows)
{
return $objCategory->file_types;
}
}
return "";
} | [
"public",
"static",
"function",
"getValidFileTypesForCategory",
"(",
")",
"{",
"$",
"db",
"=",
"\\",
"Database",
"::",
"getInstance",
"(",
")",
";",
"$",
"input",
"=",
"\\",
"Input",
"::",
"getInstance",
"(",
")",
";",
"if",
"(",
"$",
"db",
"->",
"tableExists",
"(",
"'tl_dms_categories'",
")",
"&&",
"$",
"db",
"->",
"tableExists",
"(",
"'tl_dms_documents'",
")",
")",
"{",
"$",
"objCategory",
"=",
"$",
"db",
"->",
"prepare",
"(",
"'SELECT cat.* FROM tl_dms_categories cat JOIN tl_dms_documents doc ON doc.pid = cat.id WHERE doc.id = ?'",
")",
"->",
"execute",
"(",
"$",
"input",
"->",
"get",
"(",
"'id'",
")",
")",
";",
"if",
"(",
"$",
"objCategory",
"->",
"numRows",
")",
"{",
"return",
"$",
"objCategory",
"->",
"file_types",
";",
"}",
"}",
"return",
"\"\"",
";",
"}"
]
| Determine the valid file types for the current category | [
"Determine",
"the",
"valid",
"file",
"types",
"for",
"the",
"current",
"category"
]
| dd6856ac87fdc7fc93dc6274fad678e416712059 | https://github.com/ContaoDMS/dms/blob/dd6856ac87fdc7fc93dc6274fad678e416712059/system/modules/DocumentManagementSystem/dca/tl_dms_documents.php#L401-L414 | train |
ContaoDMS/dms | system/modules/DocumentManagementSystem/dca/tl_dms_documents.php | tl_dms_documents.resortDocuments | public function resortDocuments(\DataContainer $dc)
{
if (!$this->Input->get('act'))
{
$db = \Database::getInstance();
$stmt = "UPDATE tl_dms_documents doc, "
. " (SELECT @rownum := @rownum + 1 ROWNUM, t.id ID "
. " FROM "
. " (SELECT @rownum := 0) r, "
. " (SELECT * FROM tl_dms_documents ORDER BY pid, name, version_major, version_minor, version_patch) t) tsub "
. "SET doc.sorting = (tsub.ROWNUM *64) "
. "WHERE doc.id = tsub.ID";
$db->prepare($stmt)->execute();
}
} | php | public function resortDocuments(\DataContainer $dc)
{
if (!$this->Input->get('act'))
{
$db = \Database::getInstance();
$stmt = "UPDATE tl_dms_documents doc, "
. " (SELECT @rownum := @rownum + 1 ROWNUM, t.id ID "
. " FROM "
. " (SELECT @rownum := 0) r, "
. " (SELECT * FROM tl_dms_documents ORDER BY pid, name, version_major, version_minor, version_patch) t) tsub "
. "SET doc.sorting = (tsub.ROWNUM *64) "
. "WHERE doc.id = tsub.ID";
$db->prepare($stmt)->execute();
}
} | [
"public",
"function",
"resortDocuments",
"(",
"\\",
"DataContainer",
"$",
"dc",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"Input",
"->",
"get",
"(",
"'act'",
")",
")",
"{",
"$",
"db",
"=",
"\\",
"Database",
"::",
"getInstance",
"(",
")",
";",
"$",
"stmt",
"=",
"\"UPDATE tl_dms_documents doc, \"",
".",
"\" (SELECT @rownum := @rownum + 1 ROWNUM, t.id ID \"",
".",
"\" FROM \"",
".",
"\" (SELECT @rownum := 0) r, \"",
".",
"\" (SELECT * FROM tl_dms_documents ORDER BY pid, name, version_major, version_minor, version_patch) t) tsub \"",
".",
"\"SET doc.sorting = (tsub.ROWNUM *64) \"",
".",
"\"WHERE doc.id = tsub.ID\"",
";",
"$",
"db",
"->",
"prepare",
"(",
"$",
"stmt",
")",
"->",
"execute",
"(",
")",
";",
"}",
"}"
]
| Resort the document sorting value
@param DataContainer | [
"Resort",
"the",
"document",
"sorting",
"value"
]
| dd6856ac87fdc7fc93dc6274fad678e416712059 | https://github.com/ContaoDMS/dms/blob/dd6856ac87fdc7fc93dc6274fad678e416712059/system/modules/DocumentManagementSystem/dca/tl_dms_documents.php#L420-L434 | train |
ContaoDMS/dms | system/modules/DocumentManagementSystem/dca/tl_dms_documents.php | tl_dms_documents.pasteDocument | public function pasteDocument(\DataContainer $dc, $row, $table, $cr, $arrClipboard=null)
{
$imagePasteAfter = $this->generateImage('pasteafter.gif', sprintf($GLOBALS['TL_LANG'][$dc->table]['pasteafter'][1], $row['id']), 'class="blink"');
$imagePasteInto = $this->generateImage('pasteinto.gif', sprintf($GLOBALS['TL_LANG'][$dc->table]['pasteinto'][1], $row['id']), 'class="blink"');
if ($table == $GLOBALS['TL_DCA'][$dc->table]['config']['ptable'])
{
return ($row['type'] == 'root' || (!$this->User->isAdmin && !$this->User->isAllowed(5, $row)) || $cr) ? $this->generateImage('pasteinto_.gif', '', 'class="blink"').' ' : '<a href="'.$this->addToUrl('act='.$arrClipboard['mode'].'&mode=2&pid='.$row['id'].(!is_array($arrClipboard['id']) ? '&id='.$arrClipboard['id'] : '')).'" title="'.specialchars(sprintf($GLOBALS['TL_LANG'][$dc->table]['pasteinto'][1], $row['id'])).'" onclick="Backend.getScrollOffset()">'.$imagePasteInto.'</a> ';
}
$objPage = $this->Database->prepare("SELECT * FROM tl_page WHERE id=?")
->limit(1)
->execute($row['pid']);
return (($arrClipboard['mode'] == 'cut' && $arrClipboard['id'] == $row['id']) || ($arrClipboard['mode'] == 'cutAll' && in_array($row['id'], $arrClipboard['id'])) || (!$this->User->isAdmin && !$this->User->isAllowed(5, $objPage->row())) || $cr) ? $this->generateImage('pasteafter_.gif', '', 'class="blink"').' ' : ''; //'<a href="'.$this->addToUrl('act='.$arrClipboard['mode'].'&mode=1&pid='.$row['id'].(!is_array($arrClipboard['id']) ? '&id='.$arrClipboard['id'] : '')).'" title="'.specialchars(sprintf($GLOBALS['TL_LANG'][$dc->table]['pasteafter'][1], $row['id'])).'" onclick="Backend.getScrollOffset()">'.$imagePasteAfter.'</a> '; }
} | php | public function pasteDocument(\DataContainer $dc, $row, $table, $cr, $arrClipboard=null)
{
$imagePasteAfter = $this->generateImage('pasteafter.gif', sprintf($GLOBALS['TL_LANG'][$dc->table]['pasteafter'][1], $row['id']), 'class="blink"');
$imagePasteInto = $this->generateImage('pasteinto.gif', sprintf($GLOBALS['TL_LANG'][$dc->table]['pasteinto'][1], $row['id']), 'class="blink"');
if ($table == $GLOBALS['TL_DCA'][$dc->table]['config']['ptable'])
{
return ($row['type'] == 'root' || (!$this->User->isAdmin && !$this->User->isAllowed(5, $row)) || $cr) ? $this->generateImage('pasteinto_.gif', '', 'class="blink"').' ' : '<a href="'.$this->addToUrl('act='.$arrClipboard['mode'].'&mode=2&pid='.$row['id'].(!is_array($arrClipboard['id']) ? '&id='.$arrClipboard['id'] : '')).'" title="'.specialchars(sprintf($GLOBALS['TL_LANG'][$dc->table]['pasteinto'][1], $row['id'])).'" onclick="Backend.getScrollOffset()">'.$imagePasteInto.'</a> ';
}
$objPage = $this->Database->prepare("SELECT * FROM tl_page WHERE id=?")
->limit(1)
->execute($row['pid']);
return (($arrClipboard['mode'] == 'cut' && $arrClipboard['id'] == $row['id']) || ($arrClipboard['mode'] == 'cutAll' && in_array($row['id'], $arrClipboard['id'])) || (!$this->User->isAdmin && !$this->User->isAllowed(5, $objPage->row())) || $cr) ? $this->generateImage('pasteafter_.gif', '', 'class="blink"').' ' : ''; //'<a href="'.$this->addToUrl('act='.$arrClipboard['mode'].'&mode=1&pid='.$row['id'].(!is_array($arrClipboard['id']) ? '&id='.$arrClipboard['id'] : '')).'" title="'.specialchars(sprintf($GLOBALS['TL_LANG'][$dc->table]['pasteafter'][1], $row['id'])).'" onclick="Backend.getScrollOffset()">'.$imagePasteAfter.'</a> '; }
} | [
"public",
"function",
"pasteDocument",
"(",
"\\",
"DataContainer",
"$",
"dc",
",",
"$",
"row",
",",
"$",
"table",
",",
"$",
"cr",
",",
"$",
"arrClipboard",
"=",
"null",
")",
"{",
"$",
"imagePasteAfter",
"=",
"$",
"this",
"->",
"generateImage",
"(",
"'pasteafter.gif'",
",",
"sprintf",
"(",
"$",
"GLOBALS",
"[",
"'TL_LANG'",
"]",
"[",
"$",
"dc",
"->",
"table",
"]",
"[",
"'pasteafter'",
"]",
"[",
"1",
"]",
",",
"$",
"row",
"[",
"'id'",
"]",
")",
",",
"'class=\"blink\"'",
")",
";",
"$",
"imagePasteInto",
"=",
"$",
"this",
"->",
"generateImage",
"(",
"'pasteinto.gif'",
",",
"sprintf",
"(",
"$",
"GLOBALS",
"[",
"'TL_LANG'",
"]",
"[",
"$",
"dc",
"->",
"table",
"]",
"[",
"'pasteinto'",
"]",
"[",
"1",
"]",
",",
"$",
"row",
"[",
"'id'",
"]",
")",
",",
"'class=\"blink\"'",
")",
";",
"if",
"(",
"$",
"table",
"==",
"$",
"GLOBALS",
"[",
"'TL_DCA'",
"]",
"[",
"$",
"dc",
"->",
"table",
"]",
"[",
"'config'",
"]",
"[",
"'ptable'",
"]",
")",
"{",
"return",
"(",
"$",
"row",
"[",
"'type'",
"]",
"==",
"'root'",
"||",
"(",
"!",
"$",
"this",
"->",
"User",
"->",
"isAdmin",
"&&",
"!",
"$",
"this",
"->",
"User",
"->",
"isAllowed",
"(",
"5",
",",
"$",
"row",
")",
")",
"||",
"$",
"cr",
")",
"?",
"$",
"this",
"->",
"generateImage",
"(",
"'pasteinto_.gif'",
",",
"''",
",",
"'class=\"blink\"'",
")",
".",
"' '",
":",
"'<a href=\"'",
".",
"$",
"this",
"->",
"addToUrl",
"(",
"'act='",
".",
"$",
"arrClipboard",
"[",
"'mode'",
"]",
".",
"'&mode=2&pid='",
".",
"$",
"row",
"[",
"'id'",
"]",
".",
"(",
"!",
"is_array",
"(",
"$",
"arrClipboard",
"[",
"'id'",
"]",
")",
"?",
"'&id='",
".",
"$",
"arrClipboard",
"[",
"'id'",
"]",
":",
"''",
")",
")",
".",
"'\" title=\"'",
".",
"specialchars",
"(",
"sprintf",
"(",
"$",
"GLOBALS",
"[",
"'TL_LANG'",
"]",
"[",
"$",
"dc",
"->",
"table",
"]",
"[",
"'pasteinto'",
"]",
"[",
"1",
"]",
",",
"$",
"row",
"[",
"'id'",
"]",
")",
")",
".",
"'\" onclick=\"Backend.getScrollOffset()\">'",
".",
"$",
"imagePasteInto",
".",
"'</a> '",
";",
"}",
"$",
"objPage",
"=",
"$",
"this",
"->",
"Database",
"->",
"prepare",
"(",
"\"SELECT * FROM tl_page WHERE id=?\"",
")",
"->",
"limit",
"(",
"1",
")",
"->",
"execute",
"(",
"$",
"row",
"[",
"'pid'",
"]",
")",
";",
"return",
"(",
"(",
"$",
"arrClipboard",
"[",
"'mode'",
"]",
"==",
"'cut'",
"&&",
"$",
"arrClipboard",
"[",
"'id'",
"]",
"==",
"$",
"row",
"[",
"'id'",
"]",
")",
"||",
"(",
"$",
"arrClipboard",
"[",
"'mode'",
"]",
"==",
"'cutAll'",
"&&",
"in_array",
"(",
"$",
"row",
"[",
"'id'",
"]",
",",
"$",
"arrClipboard",
"[",
"'id'",
"]",
")",
")",
"||",
"(",
"!",
"$",
"this",
"->",
"User",
"->",
"isAdmin",
"&&",
"!",
"$",
"this",
"->",
"User",
"->",
"isAllowed",
"(",
"5",
",",
"$",
"objPage",
"->",
"row",
"(",
")",
")",
")",
"||",
"$",
"cr",
")",
"?",
"$",
"this",
"->",
"generateImage",
"(",
"'pasteafter_.gif'",
",",
"''",
",",
"'class=\"blink\"'",
")",
".",
"' '",
":",
"''",
";",
"//'<a href=\"'.$this->addToUrl('act='.$arrClipboard['mode'].'&mode=1&pid='.$row['id'].(!is_array($arrClipboard['id']) ? '&id='.$arrClipboard['id'] : '')).'\" title=\"'.specialchars(sprintf($GLOBALS['TL_LANG'][$dc->table]['pasteafter'][1], $row['id'])).'\" onclick=\"Backend.getScrollOffset()\">'.$imagePasteAfter.'</a> '; }",
"}"
]
| Return the paste document button
@param \DataContainer
@param array
@param string
@param boolean
@param array
@return string | [
"Return",
"the",
"paste",
"document",
"button"
]
| dd6856ac87fdc7fc93dc6274fad678e416712059 | https://github.com/ContaoDMS/dms/blob/dd6856ac87fdc7fc93dc6274fad678e416712059/system/modules/DocumentManagementSystem/dca/tl_dms_documents.php#L445-L460 | train |
ContaoDMS/dms | system/modules/DocumentManagementSystem/dca/tl_dms_documents.php | tl_dms_documents.deleteFile | public function deleteFile(\DataContainer $dc)
{
$filePath = TL_ROOT . '/' . $this->getFullFilePath($dc->activeRecord->data_file_name, $dc);
if (file_exists($filePath))
{
unlink($filePath);
}
} | php | public function deleteFile(\DataContainer $dc)
{
$filePath = TL_ROOT . '/' . $this->getFullFilePath($dc->activeRecord->data_file_name, $dc);
if (file_exists($filePath))
{
unlink($filePath);
}
} | [
"public",
"function",
"deleteFile",
"(",
"\\",
"DataContainer",
"$",
"dc",
")",
"{",
"$",
"filePath",
"=",
"TL_ROOT",
".",
"'/'",
".",
"$",
"this",
"->",
"getFullFilePath",
"(",
"$",
"dc",
"->",
"activeRecord",
"->",
"data_file_name",
",",
"$",
"dc",
")",
";",
"if",
"(",
"file_exists",
"(",
"$",
"filePath",
")",
")",
"{",
"unlink",
"(",
"$",
"filePath",
")",
";",
"}",
"}"
]
| Delete the file, if the document will be deleted.
@param DataContainer | [
"Delete",
"the",
"file",
"if",
"the",
"document",
"will",
"be",
"deleted",
"."
]
| dd6856ac87fdc7fc93dc6274fad678e416712059 | https://github.com/ContaoDMS/dms/blob/dd6856ac87fdc7fc93dc6274fad678e416712059/system/modules/DocumentManagementSystem/dca/tl_dms_documents.php#L560-L567 | train |
ContaoDMS/dms | system/modules/DocumentManagementSystem/classes/DmsLoader.php | DmsLoader.loadCategories | public function loadCategories(\DmsLoaderParams $params)
{
$rootCategory = null;
// if another root category is selected
if ($params->loadRootCategory && $params->rootCategoryId > 0)
{
$rootCategory = $this->loadCategory($params->rootCategoryId, $params);
$arrCategories = $this->getCategoryLevel($params->rootCategoryId, $rootCategory, $params);
if ($params->includeRootCategory)
{
$rootCategory->subCategories = $arrCategories;
$arrCategories = array();
$arrCategories[] = $rootCategory;
}
return $arrCategories;
}
return $this->getCategoryLevel($params->rootCategoryId, null, $params);
} | php | public function loadCategories(\DmsLoaderParams $params)
{
$rootCategory = null;
// if another root category is selected
if ($params->loadRootCategory && $params->rootCategoryId > 0)
{
$rootCategory = $this->loadCategory($params->rootCategoryId, $params);
$arrCategories = $this->getCategoryLevel($params->rootCategoryId, $rootCategory, $params);
if ($params->includeRootCategory)
{
$rootCategory->subCategories = $arrCategories;
$arrCategories = array();
$arrCategories[] = $rootCategory;
}
return $arrCategories;
}
return $this->getCategoryLevel($params->rootCategoryId, null, $params);
} | [
"public",
"function",
"loadCategories",
"(",
"\\",
"DmsLoaderParams",
"$",
"params",
")",
"{",
"$",
"rootCategory",
"=",
"null",
";",
"// if another root category is selected",
"if",
"(",
"$",
"params",
"->",
"loadRootCategory",
"&&",
"$",
"params",
"->",
"rootCategoryId",
">",
"0",
")",
"{",
"$",
"rootCategory",
"=",
"$",
"this",
"->",
"loadCategory",
"(",
"$",
"params",
"->",
"rootCategoryId",
",",
"$",
"params",
")",
";",
"$",
"arrCategories",
"=",
"$",
"this",
"->",
"getCategoryLevel",
"(",
"$",
"params",
"->",
"rootCategoryId",
",",
"$",
"rootCategory",
",",
"$",
"params",
")",
";",
"if",
"(",
"$",
"params",
"->",
"includeRootCategory",
")",
"{",
"$",
"rootCategory",
"->",
"subCategories",
"=",
"$",
"arrCategories",
";",
"$",
"arrCategories",
"=",
"array",
"(",
")",
";",
"$",
"arrCategories",
"[",
"]",
"=",
"$",
"rootCategory",
";",
"}",
"return",
"$",
"arrCategories",
";",
"}",
"return",
"$",
"this",
"->",
"getCategoryLevel",
"(",
"$",
"params",
"->",
"rootCategoryId",
",",
"null",
",",
"$",
"params",
")",
";",
"}"
]
| Load the categories structure without consideration of access rights.
@param DmsLoaderParams $params The configured params to use while loading.
@return array Returns the category structure. | [
"Load",
"the",
"categories",
"structure",
"without",
"consideration",
"of",
"access",
"rights",
"."
]
| dd6856ac87fdc7fc93dc6274fad678e416712059 | https://github.com/ContaoDMS/dms/blob/dd6856ac87fdc7fc93dc6274fad678e416712059/system/modules/DocumentManagementSystem/classes/DmsLoader.php#L77-L97 | train |
ContaoDMS/dms | system/modules/DocumentManagementSystem/classes/DmsLoader.php | DmsLoader.flattenCategories | public static function flattenCategories(Array $arrCategories)
{
$arrFlattend = array();
foreach ($arrCategories as $category)
{
$arrFlattend[] = $category;
if ($category->hasSubCategories())
{
$arrFlattend = array_merge($arrFlattend, \DmsLoader::flattenCategories($category->subCategories));
}
}
return $arrFlattend;
} | php | public static function flattenCategories(Array $arrCategories)
{
$arrFlattend = array();
foreach ($arrCategories as $category)
{
$arrFlattend[] = $category;
if ($category->hasSubCategories())
{
$arrFlattend = array_merge($arrFlattend, \DmsLoader::flattenCategories($category->subCategories));
}
}
return $arrFlattend;
} | [
"public",
"static",
"function",
"flattenCategories",
"(",
"Array",
"$",
"arrCategories",
")",
"{",
"$",
"arrFlattend",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"arrCategories",
"as",
"$",
"category",
")",
"{",
"$",
"arrFlattend",
"[",
"]",
"=",
"$",
"category",
";",
"if",
"(",
"$",
"category",
"->",
"hasSubCategories",
"(",
")",
")",
"{",
"$",
"arrFlattend",
"=",
"array_merge",
"(",
"$",
"arrFlattend",
",",
"\\",
"DmsLoader",
"::",
"flattenCategories",
"(",
"$",
"category",
"->",
"subCategories",
")",
")",
";",
"}",
"}",
"return",
"$",
"arrFlattend",
";",
"}"
]
| Flatten a categories structure.
@param arr $arrCategories The structured array of categories.
@return array Returns the flattened array of categories. | [
"Flatten",
"a",
"categories",
"structure",
"."
]
| dd6856ac87fdc7fc93dc6274fad678e416712059 | https://github.com/ContaoDMS/dms/blob/dd6856ac87fdc7fc93dc6274fad678e416712059/system/modules/DocumentManagementSystem/classes/DmsLoader.php#L105-L119 | train |
ContaoDMS/dms | system/modules/DocumentManagementSystem/classes/DmsLoader.php | DmsLoader.loadCategory | public function loadCategory($categoryId, \DmsLoaderParams $params)
{
$objCategory = $this->Database->prepare("SELECT * FROM tl_dms_categories WHERE id = ?")
->limit(1)
->execute($categoryId);
$category = null;
if ($objCategory->numRows)
{
$category = $this->buildCategory($objCategory);
if ($params->loadAccessRights)
{
$category->accessRights = $this->getAccessRights($category, $params);
}
if ($params->loadDocuments)
{
$category->documents = $this->getDocuments($category, $params);
}
if ($params->loadRootCategory)
{
$category->parentCategory = $this->loadCategory($category->parentCategoryId, $params);
}
}
return $category;
} | php | public function loadCategory($categoryId, \DmsLoaderParams $params)
{
$objCategory = $this->Database->prepare("SELECT * FROM tl_dms_categories WHERE id = ?")
->limit(1)
->execute($categoryId);
$category = null;
if ($objCategory->numRows)
{
$category = $this->buildCategory($objCategory);
if ($params->loadAccessRights)
{
$category->accessRights = $this->getAccessRights($category, $params);
}
if ($params->loadDocuments)
{
$category->documents = $this->getDocuments($category, $params);
}
if ($params->loadRootCategory)
{
$category->parentCategory = $this->loadCategory($category->parentCategoryId, $params);
}
}
return $category;
} | [
"public",
"function",
"loadCategory",
"(",
"$",
"categoryId",
",",
"\\",
"DmsLoaderParams",
"$",
"params",
")",
"{",
"$",
"objCategory",
"=",
"$",
"this",
"->",
"Database",
"->",
"prepare",
"(",
"\"SELECT * FROM tl_dms_categories WHERE id = ?\"",
")",
"->",
"limit",
"(",
"1",
")",
"->",
"execute",
"(",
"$",
"categoryId",
")",
";",
"$",
"category",
"=",
"null",
";",
"if",
"(",
"$",
"objCategory",
"->",
"numRows",
")",
"{",
"$",
"category",
"=",
"$",
"this",
"->",
"buildCategory",
"(",
"$",
"objCategory",
")",
";",
"if",
"(",
"$",
"params",
"->",
"loadAccessRights",
")",
"{",
"$",
"category",
"->",
"accessRights",
"=",
"$",
"this",
"->",
"getAccessRights",
"(",
"$",
"category",
",",
"$",
"params",
")",
";",
"}",
"if",
"(",
"$",
"params",
"->",
"loadDocuments",
")",
"{",
"$",
"category",
"->",
"documents",
"=",
"$",
"this",
"->",
"getDocuments",
"(",
"$",
"category",
",",
"$",
"params",
")",
";",
"}",
"if",
"(",
"$",
"params",
"->",
"loadRootCategory",
")",
"{",
"$",
"category",
"->",
"parentCategory",
"=",
"$",
"this",
"->",
"loadCategory",
"(",
"$",
"category",
"->",
"parentCategoryId",
",",
"$",
"params",
")",
";",
"}",
"}",
"return",
"$",
"category",
";",
"}"
]
| Load the category with the given id.
@param int $categoryId The id of the category to load.
@param DmsLoaderParams $params The configured params to use while loading.
@return category Returns the category. | [
"Load",
"the",
"category",
"with",
"the",
"given",
"id",
"."
]
| dd6856ac87fdc7fc93dc6274fad678e416712059 | https://github.com/ContaoDMS/dms/blob/dd6856ac87fdc7fc93dc6274fad678e416712059/system/modules/DocumentManagementSystem/classes/DmsLoader.php#L128-L153 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.