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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
fisharebest/webtrees | app/Services/HousekeepingService.php | HousekeepingService.deleteFileOrFolder | private function deleteFileOrFolder(Filesystem $filesystem, string $path): bool
{
if ($filesystem->has($path)) {
try {
$metadata = $filesystem->getMetadata($path);
if ($metadata['type'] === 'dir') {
$filesystem->deleteDir($path);
}
if ($metadata['type'] === 'file') {
$filesystem->delete($path);
}
} catch (Exception $ex) {
return false;
}
}
return true;
} | php | private function deleteFileOrFolder(Filesystem $filesystem, string $path): bool
{
if ($filesystem->has($path)) {
try {
$metadata = $filesystem->getMetadata($path);
if ($metadata['type'] === 'dir') {
$filesystem->deleteDir($path);
}
if ($metadata['type'] === 'file') {
$filesystem->delete($path);
}
} catch (Exception $ex) {
return false;
}
}
return true;
} | [
"private",
"function",
"deleteFileOrFolder",
"(",
"Filesystem",
"$",
"filesystem",
",",
"string",
"$",
"path",
")",
":",
"bool",
"{",
"if",
"(",
"$",
"filesystem",
"->",
"has",
"(",
"$",
"path",
")",
")",
"{",
"try",
"{",
"$",
"metadata",
"=",
"$",
"filesystem",
"->",
"getMetadata",
"(",
"$",
"path",
")",
";",
"if",
"(",
"$",
"metadata",
"[",
"'type'",
"]",
"===",
"'dir'",
")",
"{",
"$",
"filesystem",
"->",
"deleteDir",
"(",
"$",
"path",
")",
";",
"}",
"if",
"(",
"$",
"metadata",
"[",
"'type'",
"]",
"===",
"'file'",
")",
"{",
"$",
"filesystem",
"->",
"delete",
"(",
"$",
"path",
")",
";",
"}",
"}",
"catch",
"(",
"Exception",
"$",
"ex",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Delete a file or folder, if we can.
@param Filesystem $filesystem
@param string $path
@return bool | [
"Delete",
"a",
"file",
"or",
"folder",
"if",
"we",
"can",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Services/HousekeepingService.php#L454-L473 | train |
fisharebest/webtrees | app/Report/ReportBaseText.php | ReportBaseText.setWrapWidth | public function setWrapWidth(float $wrapwidth, float $cellwidth): float
{
$this->wrapWidthCell = $cellwidth;
if (strpos($this->text, "\n") !== false) {
$this->wrapWidthRemaining = $cellwidth;
} else {
$this->wrapWidthRemaining = $wrapwidth;
}
return $this->wrapWidthRemaining;
} | php | public function setWrapWidth(float $wrapwidth, float $cellwidth): float
{
$this->wrapWidthCell = $cellwidth;
if (strpos($this->text, "\n") !== false) {
$this->wrapWidthRemaining = $cellwidth;
} else {
$this->wrapWidthRemaining = $wrapwidth;
}
return $this->wrapWidthRemaining;
} | [
"public",
"function",
"setWrapWidth",
"(",
"float",
"$",
"wrapwidth",
",",
"float",
"$",
"cellwidth",
")",
":",
"float",
"{",
"$",
"this",
"->",
"wrapWidthCell",
"=",
"$",
"cellwidth",
";",
"if",
"(",
"strpos",
"(",
"$",
"this",
"->",
"text",
",",
"\"\\n\"",
")",
"!==",
"false",
")",
"{",
"$",
"this",
"->",
"wrapWidthRemaining",
"=",
"$",
"cellwidth",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"wrapWidthRemaining",
"=",
"$",
"wrapwidth",
";",
"}",
"return",
"$",
"this",
"->",
"wrapWidthRemaining",
";",
"}"
] | Set the width for word-wrapping.
@param float $wrapwidth
@param float $cellwidth
@return float | [
"Set",
"the",
"width",
"for",
"word",
"-",
"wrapping",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Report/ReportBaseText.php#L72-L82 | train |
fisharebest/webtrees | app/Statistics/Google/ChartMedia.php | ChartMedia.chartMedia | public function chartMedia(
array $media,
string $color_from = null,
string $color_to = null
): string {
$chart_color1 = (string) $this->theme->parameter('distribution-chart-no-values');
$chart_color2 = (string) $this->theme->parameter('distribution-chart-high-values');
$color_from = $color_from ?? $chart_color1;
$color_to = $color_to ?? $chart_color2;
$data = [
[
I18N::translate('Type'),
I18N::translate('Total')
],
];
foreach ($media as $type => $count) {
$data[] = [
GedcomTag::getFileFormTypeValue($type),
$count
];
}
$colors = $this->color_service->interpolateRgb($color_from, $color_to, count($data) - 1);
return view(
'statistics/other/charts/pie',
[
'title' => null,
'data' => $data,
'colors' => $colors,
]
);
} | php | public function chartMedia(
array $media,
string $color_from = null,
string $color_to = null
): string {
$chart_color1 = (string) $this->theme->parameter('distribution-chart-no-values');
$chart_color2 = (string) $this->theme->parameter('distribution-chart-high-values');
$color_from = $color_from ?? $chart_color1;
$color_to = $color_to ?? $chart_color2;
$data = [
[
I18N::translate('Type'),
I18N::translate('Total')
],
];
foreach ($media as $type => $count) {
$data[] = [
GedcomTag::getFileFormTypeValue($type),
$count
];
}
$colors = $this->color_service->interpolateRgb($color_from, $color_to, count($data) - 1);
return view(
'statistics/other/charts/pie',
[
'title' => null,
'data' => $data,
'colors' => $colors,
]
);
} | [
"public",
"function",
"chartMedia",
"(",
"array",
"$",
"media",
",",
"string",
"$",
"color_from",
"=",
"null",
",",
"string",
"$",
"color_to",
"=",
"null",
")",
":",
"string",
"{",
"$",
"chart_color1",
"=",
"(",
"string",
")",
"$",
"this",
"->",
"theme",
"->",
"parameter",
"(",
"'distribution-chart-no-values'",
")",
";",
"$",
"chart_color2",
"=",
"(",
"string",
")",
"$",
"this",
"->",
"theme",
"->",
"parameter",
"(",
"'distribution-chart-high-values'",
")",
";",
"$",
"color_from",
"=",
"$",
"color_from",
"??",
"$",
"chart_color1",
";",
"$",
"color_to",
"=",
"$",
"color_to",
"??",
"$",
"chart_color2",
";",
"$",
"data",
"=",
"[",
"[",
"I18N",
"::",
"translate",
"(",
"'Type'",
")",
",",
"I18N",
"::",
"translate",
"(",
"'Total'",
")",
"]",
",",
"]",
";",
"foreach",
"(",
"$",
"media",
"as",
"$",
"type",
"=>",
"$",
"count",
")",
"{",
"$",
"data",
"[",
"]",
"=",
"[",
"GedcomTag",
"::",
"getFileFormTypeValue",
"(",
"$",
"type",
")",
",",
"$",
"count",
"]",
";",
"}",
"$",
"colors",
"=",
"$",
"this",
"->",
"color_service",
"->",
"interpolateRgb",
"(",
"$",
"color_from",
",",
"$",
"color_to",
",",
"count",
"(",
"$",
"data",
")",
"-",
"1",
")",
";",
"return",
"view",
"(",
"'statistics/other/charts/pie'",
",",
"[",
"'title'",
"=>",
"null",
",",
"'data'",
"=>",
"$",
"data",
",",
"'colors'",
"=>",
"$",
"colors",
",",
"]",
")",
";",
"}"
] | Create a chart of media types.
@param array $media The list of media types to display
@param string|null $color_from
@param string|null $color_to
@return string | [
"Create",
"a",
"chart",
"of",
"media",
"types",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Statistics/Google/ChartMedia.php#L59-L93 | train |
fisharebest/webtrees | app/User.php | User.setEmail | public function setEmail($email): User
{
if ($this->email !== $email) {
$this->email = $email;
DB::table('user')
->where('user_id', '=', $this->user_id)
->update([
'email' => $email,
]);
}
return $this;
} | php | public function setEmail($email): User
{
if ($this->email !== $email) {
$this->email = $email;
DB::table('user')
->where('user_id', '=', $this->user_id)
->update([
'email' => $email,
]);
}
return $this;
} | [
"public",
"function",
"setEmail",
"(",
"$",
"email",
")",
":",
"User",
"{",
"if",
"(",
"$",
"this",
"->",
"email",
"!==",
"$",
"email",
")",
"{",
"$",
"this",
"->",
"email",
"=",
"$",
"email",
";",
"DB",
"::",
"table",
"(",
"'user'",
")",
"->",
"where",
"(",
"'user_id'",
",",
"'='",
",",
"$",
"this",
"->",
"user_id",
")",
"->",
"update",
"(",
"[",
"'email'",
"=>",
"$",
"email",
",",
"]",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Set the email address of this user.
@param string $email
@return User | [
"Set",
"the",
"email",
"address",
"of",
"this",
"user",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/User.php#L89-L102 | train |
fisharebest/webtrees | app/User.php | User.setRealName | public function setRealName($real_name): User
{
if ($this->real_name !== $real_name) {
$this->real_name = $real_name;
DB::table('user')
->where('user_id', '=', $this->user_id)
->update([
'real_name' => $real_name,
]);
}
return $this;
} | php | public function setRealName($real_name): User
{
if ($this->real_name !== $real_name) {
$this->real_name = $real_name;
DB::table('user')
->where('user_id', '=', $this->user_id)
->update([
'real_name' => $real_name,
]);
}
return $this;
} | [
"public",
"function",
"setRealName",
"(",
"$",
"real_name",
")",
":",
"User",
"{",
"if",
"(",
"$",
"this",
"->",
"real_name",
"!==",
"$",
"real_name",
")",
"{",
"$",
"this",
"->",
"real_name",
"=",
"$",
"real_name",
";",
"DB",
"::",
"table",
"(",
"'user'",
")",
"->",
"where",
"(",
"'user_id'",
",",
"'='",
",",
"$",
"this",
"->",
"user_id",
")",
"->",
"update",
"(",
"[",
"'real_name'",
"=>",
"$",
"real_name",
",",
"]",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Set the real name of this user.
@param string $real_name
@return User | [
"Set",
"the",
"real",
"name",
"of",
"this",
"user",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/User.php#L121-L134 | train |
fisharebest/webtrees | app/User.php | User.setUserName | public function setUserName($user_name): self
{
if ($this->user_name !== $user_name) {
$this->user_name = $user_name;
DB::table('user')
->where('user_id', '=', $this->user_id)
->update([
'user_name' => $user_name,
]);
}
return $this;
} | php | public function setUserName($user_name): self
{
if ($this->user_name !== $user_name) {
$this->user_name = $user_name;
DB::table('user')
->where('user_id', '=', $this->user_id)
->update([
'user_name' => $user_name,
]);
}
return $this;
} | [
"public",
"function",
"setUserName",
"(",
"$",
"user_name",
")",
":",
"self",
"{",
"if",
"(",
"$",
"this",
"->",
"user_name",
"!==",
"$",
"user_name",
")",
"{",
"$",
"this",
"->",
"user_name",
"=",
"$",
"user_name",
";",
"DB",
"::",
"table",
"(",
"'user'",
")",
"->",
"where",
"(",
"'user_id'",
",",
"'='",
",",
"$",
"this",
"->",
"user_id",
")",
"->",
"update",
"(",
"[",
"'user_name'",
"=>",
"$",
"user_name",
",",
"]",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Set the login name for this user.
@param string $user_name
@return $this | [
"Set",
"the",
"login",
"name",
"for",
"this",
"user",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/User.php#L153-L166 | train |
fisharebest/webtrees | app/User.php | User.setPreference | public function setPreference(string $setting_name, string $setting_value): UserInterface
{
if ($this->user_id !== 0 && $this->getPreference($setting_name) !== $setting_value) {
DB::table('user_setting')->updateOrInsert([
'user_id' => $this->user_id,
'setting_name' => $setting_name,
], [
'setting_value' => $setting_value,
]);
$this->preferences[$setting_name] = $setting_value;
}
app('cache.array')->forget('user_setting' . $this->user_id);
return $this;
} | php | public function setPreference(string $setting_name, string $setting_value): UserInterface
{
if ($this->user_id !== 0 && $this->getPreference($setting_name) !== $setting_value) {
DB::table('user_setting')->updateOrInsert([
'user_id' => $this->user_id,
'setting_name' => $setting_name,
], [
'setting_value' => $setting_value,
]);
$this->preferences[$setting_name] = $setting_value;
}
app('cache.array')->forget('user_setting' . $this->user_id);
return $this;
} | [
"public",
"function",
"setPreference",
"(",
"string",
"$",
"setting_name",
",",
"string",
"$",
"setting_value",
")",
":",
"UserInterface",
"{",
"if",
"(",
"$",
"this",
"->",
"user_id",
"!==",
"0",
"&&",
"$",
"this",
"->",
"getPreference",
"(",
"$",
"setting_name",
")",
"!==",
"$",
"setting_value",
")",
"{",
"DB",
"::",
"table",
"(",
"'user_setting'",
")",
"->",
"updateOrInsert",
"(",
"[",
"'user_id'",
"=>",
"$",
"this",
"->",
"user_id",
",",
"'setting_name'",
"=>",
"$",
"setting_name",
",",
"]",
",",
"[",
"'setting_value'",
"=>",
"$",
"setting_value",
",",
"]",
")",
";",
"$",
"this",
"->",
"preferences",
"[",
"$",
"setting_name",
"]",
"=",
"$",
"setting_value",
";",
"}",
"app",
"(",
"'cache.array'",
")",
"->",
"forget",
"(",
"'user_setting'",
".",
"$",
"this",
"->",
"user_id",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Update a setting for the user.
@param string $setting_name
@param string $setting_value
@return UserInterface | [
"Update",
"a",
"setting",
"for",
"the",
"user",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/User.php#L201-L217 | train |
fisharebest/webtrees | app/User.php | User.setPassword | public function setPassword(string $password): User
{
DB::table('user')
->where('user_id', '=', $this->user_id)
->update([
'password' => password_hash($password, PASSWORD_DEFAULT),
]);
return $this;
} | php | public function setPassword(string $password): User
{
DB::table('user')
->where('user_id', '=', $this->user_id)
->update([
'password' => password_hash($password, PASSWORD_DEFAULT),
]);
return $this;
} | [
"public",
"function",
"setPassword",
"(",
"string",
"$",
"password",
")",
":",
"User",
"{",
"DB",
"::",
"table",
"(",
"'user'",
")",
"->",
"where",
"(",
"'user_id'",
",",
"'='",
",",
"$",
"this",
"->",
"user_id",
")",
"->",
"update",
"(",
"[",
"'password'",
"=>",
"password_hash",
"(",
"$",
"password",
",",
"PASSWORD_DEFAULT",
")",
",",
"]",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Set the password of this user.
@param string $password
@return User | [
"Set",
"the",
"password",
"of",
"this",
"user",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/User.php#L226-L235 | train |
fisharebest/webtrees | app/User.php | User.checkPassword | public function checkPassword(string $password): bool
{
$password_hash = DB::table('user')
->where('user_id', '=', $this->id())
->value('password');
if ($password_hash !== null && password_verify($password, $password_hash)) {
if (password_needs_rehash($password_hash, PASSWORD_DEFAULT)) {
$this->setPassword($password);
}
return true;
}
return false;
} | php | public function checkPassword(string $password): bool
{
$password_hash = DB::table('user')
->where('user_id', '=', $this->id())
->value('password');
if ($password_hash !== null && password_verify($password, $password_hash)) {
if (password_needs_rehash($password_hash, PASSWORD_DEFAULT)) {
$this->setPassword($password);
}
return true;
}
return false;
} | [
"public",
"function",
"checkPassword",
"(",
"string",
"$",
"password",
")",
":",
"bool",
"{",
"$",
"password_hash",
"=",
"DB",
"::",
"table",
"(",
"'user'",
")",
"->",
"where",
"(",
"'user_id'",
",",
"'='",
",",
"$",
"this",
"->",
"id",
"(",
")",
")",
"->",
"value",
"(",
"'password'",
")",
";",
"if",
"(",
"$",
"password_hash",
"!==",
"null",
"&&",
"password_verify",
"(",
"$",
"password",
",",
"$",
"password_hash",
")",
")",
"{",
"if",
"(",
"password_needs_rehash",
"(",
"$",
"password_hash",
",",
"PASSWORD_DEFAULT",
")",
")",
"{",
"$",
"this",
"->",
"setPassword",
"(",
"$",
"password",
")",
";",
"}",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Validate a supplied password
@param string $password
@return bool | [
"Validate",
"a",
"supplied",
"password"
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/User.php#L245-L260 | train |
fisharebest/webtrees | app/User.php | User.rowMapper | public static function rowMapper(): Closure
{
return static function (stdClass $row): User {
return new static((int) $row->user_id, $row->user_name, $row->real_name, $row->email);
};
} | php | public static function rowMapper(): Closure
{
return static function (stdClass $row): User {
return new static((int) $row->user_id, $row->user_name, $row->real_name, $row->email);
};
} | [
"public",
"static",
"function",
"rowMapper",
"(",
")",
":",
"Closure",
"{",
"return",
"static",
"function",
"(",
"stdClass",
"$",
"row",
")",
":",
"User",
"{",
"return",
"new",
"static",
"(",
"(",
"int",
")",
"$",
"row",
"->",
"user_id",
",",
"$",
"row",
"->",
"user_name",
",",
"$",
"row",
"->",
"real_name",
",",
"$",
"row",
"->",
"email",
")",
";",
"}",
";",
"}"
] | A closure which will create an object from a database row.
@return Closure | [
"A",
"closure",
"which",
"will",
"create",
"an",
"object",
"from",
"a",
"database",
"row",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/User.php#L267-L272 | train |
fisharebest/webtrees | app/Http/Controllers/ListController.php | ListController.mediaList | public function mediaList(ServerRequestInterface $request, Tree $tree): ResponseInterface
{
//route is assumed to be 'module'
$module = $request->get('module');
$action = $request->get('action');
$formats = GedcomTag::getFileFormTypes();
$action2 = $request->get('action2');
$page = (int) $request->get('page');
$max = (int) $request->get('max', 20);
$folder = $request->get('folder', '');
$filter = $request->get('filter', '');
$subdirs = $request->get('subdirs', '');
$form_type = $request->get('form_type', '');
$folders = $this->allFolders($tree);
if ($action2 === '1') {
$media_objects = $this->allMedia(
$tree,
$folder,
$subdirs === '1' ? 'include' : 'exclude',
'title',
$filter,
$form_type
);
} else {
$media_objects = [];
}
// Pagination
$count = count($media_objects);
$pages = (int) (($count + $max - 1) / $max);
$page = max(min($page, $pages), 1);
$media_objects = array_slice($media_objects, ($page - 1) * $max, $max);
return $this->viewResponse('media-list-page', [
'count' => $count,
'filter' => $filter,
'folder' => $folder,
'folders' => $folders,
'formats' => $formats,
'form_type' => $form_type,
'max' => $max,
'media_objects' => $media_objects,
'page' => $page,
'pages' => $pages,
'subdirs' => $subdirs,
'title' => I18N::translate('Media'),
'module' => $module,
'action' => $action,
]);
} | php | public function mediaList(ServerRequestInterface $request, Tree $tree): ResponseInterface
{
//route is assumed to be 'module'
$module = $request->get('module');
$action = $request->get('action');
$formats = GedcomTag::getFileFormTypes();
$action2 = $request->get('action2');
$page = (int) $request->get('page');
$max = (int) $request->get('max', 20);
$folder = $request->get('folder', '');
$filter = $request->get('filter', '');
$subdirs = $request->get('subdirs', '');
$form_type = $request->get('form_type', '');
$folders = $this->allFolders($tree);
if ($action2 === '1') {
$media_objects = $this->allMedia(
$tree,
$folder,
$subdirs === '1' ? 'include' : 'exclude',
'title',
$filter,
$form_type
);
} else {
$media_objects = [];
}
// Pagination
$count = count($media_objects);
$pages = (int) (($count + $max - 1) / $max);
$page = max(min($page, $pages), 1);
$media_objects = array_slice($media_objects, ($page - 1) * $max, $max);
return $this->viewResponse('media-list-page', [
'count' => $count,
'filter' => $filter,
'folder' => $folder,
'folders' => $folders,
'formats' => $formats,
'form_type' => $form_type,
'max' => $max,
'media_objects' => $media_objects,
'page' => $page,
'pages' => $pages,
'subdirs' => $subdirs,
'title' => I18N::translate('Media'),
'module' => $module,
'action' => $action,
]);
} | [
"public",
"function",
"mediaList",
"(",
"ServerRequestInterface",
"$",
"request",
",",
"Tree",
"$",
"tree",
")",
":",
"ResponseInterface",
"{",
"//route is assumed to be 'module'",
"$",
"module",
"=",
"$",
"request",
"->",
"get",
"(",
"'module'",
")",
";",
"$",
"action",
"=",
"$",
"request",
"->",
"get",
"(",
"'action'",
")",
";",
"$",
"formats",
"=",
"GedcomTag",
"::",
"getFileFormTypes",
"(",
")",
";",
"$",
"action2",
"=",
"$",
"request",
"->",
"get",
"(",
"'action2'",
")",
";",
"$",
"page",
"=",
"(",
"int",
")",
"$",
"request",
"->",
"get",
"(",
"'page'",
")",
";",
"$",
"max",
"=",
"(",
"int",
")",
"$",
"request",
"->",
"get",
"(",
"'max'",
",",
"20",
")",
";",
"$",
"folder",
"=",
"$",
"request",
"->",
"get",
"(",
"'folder'",
",",
"''",
")",
";",
"$",
"filter",
"=",
"$",
"request",
"->",
"get",
"(",
"'filter'",
",",
"''",
")",
";",
"$",
"subdirs",
"=",
"$",
"request",
"->",
"get",
"(",
"'subdirs'",
",",
"''",
")",
";",
"$",
"form_type",
"=",
"$",
"request",
"->",
"get",
"(",
"'form_type'",
",",
"''",
")",
";",
"$",
"folders",
"=",
"$",
"this",
"->",
"allFolders",
"(",
"$",
"tree",
")",
";",
"if",
"(",
"$",
"action2",
"===",
"'1'",
")",
"{",
"$",
"media_objects",
"=",
"$",
"this",
"->",
"allMedia",
"(",
"$",
"tree",
",",
"$",
"folder",
",",
"$",
"subdirs",
"===",
"'1'",
"?",
"'include'",
":",
"'exclude'",
",",
"'title'",
",",
"$",
"filter",
",",
"$",
"form_type",
")",
";",
"}",
"else",
"{",
"$",
"media_objects",
"=",
"[",
"]",
";",
"}",
"// Pagination",
"$",
"count",
"=",
"count",
"(",
"$",
"media_objects",
")",
";",
"$",
"pages",
"=",
"(",
"int",
")",
"(",
"(",
"$",
"count",
"+",
"$",
"max",
"-",
"1",
")",
"/",
"$",
"max",
")",
";",
"$",
"page",
"=",
"max",
"(",
"min",
"(",
"$",
"page",
",",
"$",
"pages",
")",
",",
"1",
")",
";",
"$",
"media_objects",
"=",
"array_slice",
"(",
"$",
"media_objects",
",",
"(",
"$",
"page",
"-",
"1",
")",
"*",
"$",
"max",
",",
"$",
"max",
")",
";",
"return",
"$",
"this",
"->",
"viewResponse",
"(",
"'media-list-page'",
",",
"[",
"'count'",
"=>",
"$",
"count",
",",
"'filter'",
"=>",
"$",
"filter",
",",
"'folder'",
"=>",
"$",
"folder",
",",
"'folders'",
"=>",
"$",
"folders",
",",
"'formats'",
"=>",
"$",
"formats",
",",
"'form_type'",
"=>",
"$",
"form_type",
",",
"'max'",
"=>",
"$",
"max",
",",
"'media_objects'",
"=>",
"$",
"media_objects",
",",
"'page'",
"=>",
"$",
"page",
",",
"'pages'",
"=>",
"$",
"pages",
",",
"'subdirs'",
"=>",
"$",
"subdirs",
",",
"'title'",
"=>",
"I18N",
"::",
"translate",
"(",
"'Media'",
")",
",",
"'module'",
"=>",
"$",
"module",
",",
"'action'",
"=>",
"$",
"action",
",",
"]",
")",
";",
"}"
] | Show a list of all media records.
@param ServerRequestInterface $request
@param Tree $tree
@return ResponseInterface | [
"Show",
"a",
"list",
"of",
"all",
"media",
"records",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Http/Controllers/ListController.php#L403-L457 | train |
fisharebest/webtrees | app/Http/Controllers/ListController.php | ListController.noteList | public function noteList(Tree $tree): ResponseInterface
{
$notes = $this->allNotes($tree);
return $this->viewResponse('note-list-page', [
'notes' => $notes,
'title' => I18N::translate('Shared notes'),
]);
} | php | public function noteList(Tree $tree): ResponseInterface
{
$notes = $this->allNotes($tree);
return $this->viewResponse('note-list-page', [
'notes' => $notes,
'title' => I18N::translate('Shared notes'),
]);
} | [
"public",
"function",
"noteList",
"(",
"Tree",
"$",
"tree",
")",
":",
"ResponseInterface",
"{",
"$",
"notes",
"=",
"$",
"this",
"->",
"allNotes",
"(",
"$",
"tree",
")",
";",
"return",
"$",
"this",
"->",
"viewResponse",
"(",
"'note-list-page'",
",",
"[",
"'notes'",
"=>",
"$",
"notes",
",",
"'title'",
"=>",
"I18N",
"::",
"translate",
"(",
"'Shared notes'",
")",
",",
"]",
")",
";",
"}"
] | Show a list of all note records.
@param Tree $tree
@return ResponseInterface | [
"Show",
"a",
"list",
"of",
"all",
"note",
"records",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Http/Controllers/ListController.php#L466-L474 | train |
fisharebest/webtrees | app/Http/Controllers/ListController.php | ListController.repositoryList | public function repositoryList(Tree $tree): ResponseInterface
{
$repositories = $this->allRepositories($tree);
return $this->viewResponse('repository-list-page', [
'repositories' => $repositories,
'title' => I18N::translate('Repositories'),
]);
} | php | public function repositoryList(Tree $tree): ResponseInterface
{
$repositories = $this->allRepositories($tree);
return $this->viewResponse('repository-list-page', [
'repositories' => $repositories,
'title' => I18N::translate('Repositories'),
]);
} | [
"public",
"function",
"repositoryList",
"(",
"Tree",
"$",
"tree",
")",
":",
"ResponseInterface",
"{",
"$",
"repositories",
"=",
"$",
"this",
"->",
"allRepositories",
"(",
"$",
"tree",
")",
";",
"return",
"$",
"this",
"->",
"viewResponse",
"(",
"'repository-list-page'",
",",
"[",
"'repositories'",
"=>",
"$",
"repositories",
",",
"'title'",
"=>",
"I18N",
"::",
"translate",
"(",
"'Repositories'",
")",
",",
"]",
")",
";",
"}"
] | Show a list of all repository records.
@param Tree $tree
@return ResponseInterface | [
"Show",
"a",
"list",
"of",
"all",
"repository",
"records",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Http/Controllers/ListController.php#L483-L491 | train |
fisharebest/webtrees | app/Http/Controllers/ListController.php | ListController.sourceList | public function sourceList(Tree $tree): ResponseInterface
{
$sources = $this->allSources($tree);
return $this->viewResponse('source-list-page', [
'sources' => $sources,
'title' => I18N::translate('Sources'),
]);
} | php | public function sourceList(Tree $tree): ResponseInterface
{
$sources = $this->allSources($tree);
return $this->viewResponse('source-list-page', [
'sources' => $sources,
'title' => I18N::translate('Sources'),
]);
} | [
"public",
"function",
"sourceList",
"(",
"Tree",
"$",
"tree",
")",
":",
"ResponseInterface",
"{",
"$",
"sources",
"=",
"$",
"this",
"->",
"allSources",
"(",
"$",
"tree",
")",
";",
"return",
"$",
"this",
"->",
"viewResponse",
"(",
"'source-list-page'",
",",
"[",
"'sources'",
"=>",
"$",
"sources",
",",
"'title'",
"=>",
"I18N",
"::",
"translate",
"(",
"'Sources'",
")",
",",
"]",
")",
";",
"}"
] | Show a list of all source records.
@param Tree $tree
@return ResponseInterface | [
"Show",
"a",
"list",
"of",
"all",
"source",
"records",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Http/Controllers/ListController.php#L500-L508 | train |
fisharebest/webtrees | app/Http/Controllers/ListController.php | ListController.allFolders | private function allFolders(Tree $tree): array
{
$folders = DB::table('media_file')
->where('m_file', '=', $tree->id())
->where('multimedia_file_refn', 'NOT LIKE', 'http:%')
->where('multimedia_file_refn', 'NOT LIKE', 'https:%')
->where('multimedia_file_refn', 'LIKE', '%/%')
->pluck('multimedia_file_refn', 'multimedia_file_refn')
->map(static function (string $path): string {
return dirname($path);
})
->unique()
->sort()
->all();
// Ensure we have an empty (top level) folder.
array_unshift($folders, '');
return array_combine($folders, $folders);
} | php | private function allFolders(Tree $tree): array
{
$folders = DB::table('media_file')
->where('m_file', '=', $tree->id())
->where('multimedia_file_refn', 'NOT LIKE', 'http:%')
->where('multimedia_file_refn', 'NOT LIKE', 'https:%')
->where('multimedia_file_refn', 'LIKE', '%/%')
->pluck('multimedia_file_refn', 'multimedia_file_refn')
->map(static function (string $path): string {
return dirname($path);
})
->unique()
->sort()
->all();
// Ensure we have an empty (top level) folder.
array_unshift($folders, '');
return array_combine($folders, $folders);
} | [
"private",
"function",
"allFolders",
"(",
"Tree",
"$",
"tree",
")",
":",
"array",
"{",
"$",
"folders",
"=",
"DB",
"::",
"table",
"(",
"'media_file'",
")",
"->",
"where",
"(",
"'m_file'",
",",
"'='",
",",
"$",
"tree",
"->",
"id",
"(",
")",
")",
"->",
"where",
"(",
"'multimedia_file_refn'",
",",
"'NOT LIKE'",
",",
"'http:%'",
")",
"->",
"where",
"(",
"'multimedia_file_refn'",
",",
"'NOT LIKE'",
",",
"'https:%'",
")",
"->",
"where",
"(",
"'multimedia_file_refn'",
",",
"'LIKE'",
",",
"'%/%'",
")",
"->",
"pluck",
"(",
"'multimedia_file_refn'",
",",
"'multimedia_file_refn'",
")",
"->",
"map",
"(",
"static",
"function",
"(",
"string",
"$",
"path",
")",
":",
"string",
"{",
"return",
"dirname",
"(",
"$",
"path",
")",
";",
"}",
")",
"->",
"unique",
"(",
")",
"->",
"sort",
"(",
")",
"->",
"all",
"(",
")",
";",
"// Ensure we have an empty (top level) folder.",
"array_unshift",
"(",
"$",
"folders",
",",
"''",
")",
";",
"return",
"array_combine",
"(",
"$",
"folders",
",",
"$",
"folders",
")",
";",
"}"
] | Generate a list of all the folders in a current tree.
@param Tree $tree
@return string[] | [
"Generate",
"a",
"list",
"of",
"all",
"the",
"folders",
"in",
"a",
"current",
"tree",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Http/Controllers/ListController.php#L517-L536 | train |
fisharebest/webtrees | app/Http/Controllers/ListController.php | ListController.allMedia | private function allMedia(Tree $tree, string $folder, string $subfolders, string $sort, string $filter, string $form_type): array
{
$query = DB::table('media')
->join('media_file', static function (JoinClause $join): void {
$join
->on('media_file.m_file', '=', 'media.m_file')
->on('media_file.m_id', '=', 'media.m_id');
})
->where('media.m_file', '=', $tree->id())
->distinct();
// Match all external files, and whatever folders were specified
$query->where(static function (Builder $query) use ($folder, $subfolders): void {
$query
->where('multimedia_file_refn', 'LIKE', 'http:%')
->orWhere('multimedia_file_refn', 'LIKE', 'https:%')
->orWhere(static function (Builder $query) use ($folder, $subfolders): void {
$query->where('multimedia_file_refn', 'LIKE', $folder . '%');
if ($subfolders === 'exclude') {
$query->where('multimedia_file_refn', 'NOT LIKE', $folder . '/%/%');
}
});
});
// Apply search terms
if ($filter !== '') {
$query->where(static function (Builder $query) use ($filter): void {
$query
->whereContains('multimedia_file_refn', $filter)
->whereContains('descriptive_title', $filter, 'or');
});
}
if ($form_type) {
$query->where('source_media_type', '=', $form_type);
}
switch ($sort) {
case 'file':
$query->orderBy('multimedia_file_refn');
break;
case 'title':
$query->orderBy('descriptive_title');
break;
}
return $query
->get()
->map(Media::rowMapper())
->filter(GedcomRecord::accessFilter())
->all();
} | php | private function allMedia(Tree $tree, string $folder, string $subfolders, string $sort, string $filter, string $form_type): array
{
$query = DB::table('media')
->join('media_file', static function (JoinClause $join): void {
$join
->on('media_file.m_file', '=', 'media.m_file')
->on('media_file.m_id', '=', 'media.m_id');
})
->where('media.m_file', '=', $tree->id())
->distinct();
// Match all external files, and whatever folders were specified
$query->where(static function (Builder $query) use ($folder, $subfolders): void {
$query
->where('multimedia_file_refn', 'LIKE', 'http:%')
->orWhere('multimedia_file_refn', 'LIKE', 'https:%')
->orWhere(static function (Builder $query) use ($folder, $subfolders): void {
$query->where('multimedia_file_refn', 'LIKE', $folder . '%');
if ($subfolders === 'exclude') {
$query->where('multimedia_file_refn', 'NOT LIKE', $folder . '/%/%');
}
});
});
// Apply search terms
if ($filter !== '') {
$query->where(static function (Builder $query) use ($filter): void {
$query
->whereContains('multimedia_file_refn', $filter)
->whereContains('descriptive_title', $filter, 'or');
});
}
if ($form_type) {
$query->where('source_media_type', '=', $form_type);
}
switch ($sort) {
case 'file':
$query->orderBy('multimedia_file_refn');
break;
case 'title':
$query->orderBy('descriptive_title');
break;
}
return $query
->get()
->map(Media::rowMapper())
->filter(GedcomRecord::accessFilter())
->all();
} | [
"private",
"function",
"allMedia",
"(",
"Tree",
"$",
"tree",
",",
"string",
"$",
"folder",
",",
"string",
"$",
"subfolders",
",",
"string",
"$",
"sort",
",",
"string",
"$",
"filter",
",",
"string",
"$",
"form_type",
")",
":",
"array",
"{",
"$",
"query",
"=",
"DB",
"::",
"table",
"(",
"'media'",
")",
"->",
"join",
"(",
"'media_file'",
",",
"static",
"function",
"(",
"JoinClause",
"$",
"join",
")",
":",
"void",
"{",
"$",
"join",
"->",
"on",
"(",
"'media_file.m_file'",
",",
"'='",
",",
"'media.m_file'",
")",
"->",
"on",
"(",
"'media_file.m_id'",
",",
"'='",
",",
"'media.m_id'",
")",
";",
"}",
")",
"->",
"where",
"(",
"'media.m_file'",
",",
"'='",
",",
"$",
"tree",
"->",
"id",
"(",
")",
")",
"->",
"distinct",
"(",
")",
";",
"// Match all external files, and whatever folders were specified",
"$",
"query",
"->",
"where",
"(",
"static",
"function",
"(",
"Builder",
"$",
"query",
")",
"use",
"(",
"$",
"folder",
",",
"$",
"subfolders",
")",
":",
"void",
"{",
"$",
"query",
"->",
"where",
"(",
"'multimedia_file_refn'",
",",
"'LIKE'",
",",
"'http:%'",
")",
"->",
"orWhere",
"(",
"'multimedia_file_refn'",
",",
"'LIKE'",
",",
"'https:%'",
")",
"->",
"orWhere",
"(",
"static",
"function",
"(",
"Builder",
"$",
"query",
")",
"use",
"(",
"$",
"folder",
",",
"$",
"subfolders",
")",
":",
"void",
"{",
"$",
"query",
"->",
"where",
"(",
"'multimedia_file_refn'",
",",
"'LIKE'",
",",
"$",
"folder",
".",
"'%'",
")",
";",
"if",
"(",
"$",
"subfolders",
"===",
"'exclude'",
")",
"{",
"$",
"query",
"->",
"where",
"(",
"'multimedia_file_refn'",
",",
"'NOT LIKE'",
",",
"$",
"folder",
".",
"'/%/%'",
")",
";",
"}",
"}",
")",
";",
"}",
")",
";",
"// Apply search terms",
"if",
"(",
"$",
"filter",
"!==",
"''",
")",
"{",
"$",
"query",
"->",
"where",
"(",
"static",
"function",
"(",
"Builder",
"$",
"query",
")",
"use",
"(",
"$",
"filter",
")",
":",
"void",
"{",
"$",
"query",
"->",
"whereContains",
"(",
"'multimedia_file_refn'",
",",
"$",
"filter",
")",
"->",
"whereContains",
"(",
"'descriptive_title'",
",",
"$",
"filter",
",",
"'or'",
")",
";",
"}",
")",
";",
"}",
"if",
"(",
"$",
"form_type",
")",
"{",
"$",
"query",
"->",
"where",
"(",
"'source_media_type'",
",",
"'='",
",",
"$",
"form_type",
")",
";",
"}",
"switch",
"(",
"$",
"sort",
")",
"{",
"case",
"'file'",
":",
"$",
"query",
"->",
"orderBy",
"(",
"'multimedia_file_refn'",
")",
";",
"break",
";",
"case",
"'title'",
":",
"$",
"query",
"->",
"orderBy",
"(",
"'descriptive_title'",
")",
";",
"break",
";",
"}",
"return",
"$",
"query",
"->",
"get",
"(",
")",
"->",
"map",
"(",
"Media",
"::",
"rowMapper",
"(",
")",
")",
"->",
"filter",
"(",
"GedcomRecord",
"::",
"accessFilter",
"(",
")",
")",
"->",
"all",
"(",
")",
";",
"}"
] | Generate a list of all the media objects matching the criteria in a current tree.
@param Tree $tree find media in this tree
@param string $folder folder to search
@param string $subfolders either "include" or "exclude"
@param string $sort either "file" or "title"
@param string $filter optional search string
@param string $form_type option OBJE/FILE/FORM/TYPE
@return Media[] | [
"Generate",
"a",
"list",
"of",
"all",
"the",
"media",
"objects",
"matching",
"the",
"criteria",
"in",
"a",
"current",
"tree",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Http/Controllers/ListController.php#L550-L601 | train |
fisharebest/webtrees | app/Http/Controllers/ListController.php | ListController.allNotes | private function allNotes(Tree $tree): Collection
{
return DB::table('other')
->where('o_file', '=', $tree->id())
->where('o_type', '=', 'NOTE')
->get()
->map(Note::rowMapper())
->filter(GedcomRecord::accessFilter());
} | php | private function allNotes(Tree $tree): Collection
{
return DB::table('other')
->where('o_file', '=', $tree->id())
->where('o_type', '=', 'NOTE')
->get()
->map(Note::rowMapper())
->filter(GedcomRecord::accessFilter());
} | [
"private",
"function",
"allNotes",
"(",
"Tree",
"$",
"tree",
")",
":",
"Collection",
"{",
"return",
"DB",
"::",
"table",
"(",
"'other'",
")",
"->",
"where",
"(",
"'o_file'",
",",
"'='",
",",
"$",
"tree",
"->",
"id",
"(",
")",
")",
"->",
"where",
"(",
"'o_type'",
",",
"'='",
",",
"'NOTE'",
")",
"->",
"get",
"(",
")",
"->",
"map",
"(",
"Note",
"::",
"rowMapper",
"(",
")",
")",
"->",
"filter",
"(",
"GedcomRecord",
"::",
"accessFilter",
"(",
")",
")",
";",
"}"
] | Find all the note records in a tree.
@param Tree $tree
@return Collection
@return Note[] | [
"Find",
"all",
"the",
"note",
"records",
"in",
"a",
"tree",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Http/Controllers/ListController.php#L611-L619 | train |
fisharebest/webtrees | app/Http/Controllers/ListController.php | ListController.allRepositories | private function allRepositories(Tree $tree): Collection
{
return DB::table('other')
->where('o_file', '=', $tree->id())
->where('o_type', '=', 'REPO')
->get()
->map(Repository::rowMapper())
->filter(GedcomRecord::accessFilter());
} | php | private function allRepositories(Tree $tree): Collection
{
return DB::table('other')
->where('o_file', '=', $tree->id())
->where('o_type', '=', 'REPO')
->get()
->map(Repository::rowMapper())
->filter(GedcomRecord::accessFilter());
} | [
"private",
"function",
"allRepositories",
"(",
"Tree",
"$",
"tree",
")",
":",
"Collection",
"{",
"return",
"DB",
"::",
"table",
"(",
"'other'",
")",
"->",
"where",
"(",
"'o_file'",
",",
"'='",
",",
"$",
"tree",
"->",
"id",
"(",
")",
")",
"->",
"where",
"(",
"'o_type'",
",",
"'='",
",",
"'REPO'",
")",
"->",
"get",
"(",
")",
"->",
"map",
"(",
"Repository",
"::",
"rowMapper",
"(",
")",
")",
"->",
"filter",
"(",
"GedcomRecord",
"::",
"accessFilter",
"(",
")",
")",
";",
"}"
] | Find all the repository record in a tree.
@param Tree $tree
@return Collection
@return Repository[] | [
"Find",
"all",
"the",
"repository",
"record",
"in",
"a",
"tree",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Http/Controllers/ListController.php#L629-L637 | train |
fisharebest/webtrees | app/Http/Controllers/ListController.php | ListController.allSources | private function allSources(Tree $tree): Collection
{
return DB::table('sources')
->where('s_file', '=', $tree->id())
->get()
->map(Source::rowMapper())
->filter(GedcomRecord::accessFilter());
} | php | private function allSources(Tree $tree): Collection
{
return DB::table('sources')
->where('s_file', '=', $tree->id())
->get()
->map(Source::rowMapper())
->filter(GedcomRecord::accessFilter());
} | [
"private",
"function",
"allSources",
"(",
"Tree",
"$",
"tree",
")",
":",
"Collection",
"{",
"return",
"DB",
"::",
"table",
"(",
"'sources'",
")",
"->",
"where",
"(",
"'s_file'",
",",
"'='",
",",
"$",
"tree",
"->",
"id",
"(",
")",
")",
"->",
"get",
"(",
")",
"->",
"map",
"(",
"Source",
"::",
"rowMapper",
"(",
")",
")",
"->",
"filter",
"(",
"GedcomRecord",
"::",
"accessFilter",
"(",
")",
")",
";",
"}"
] | Find all the source records in a tree.
@param Tree $tree
@return Collection
@return Source[] | [
"Find",
"all",
"the",
"source",
"records",
"in",
"a",
"tree",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Http/Controllers/ListController.php#L647-L654 | train |
fisharebest/webtrees | app/Statistics/Repository/GedcomRepository.php | GedcomRepository.gedcomHead | private function gedcomHead(): array
{
$title = '';
$version = '';
$source = '';
$head = GedcomRecord::getInstance('HEAD', $this->tree);
if ($head instanceof GedcomRecord) {
$sour = $head->facts(['SOUR'])->first();
if ($sour instanceof Fact) {
$source = $sour->value();
$title = $sour->attribute('NAME');
$version = $sour->attribute('VERS');
}
}
return [
$title,
$version,
$source,
];
} | php | private function gedcomHead(): array
{
$title = '';
$version = '';
$source = '';
$head = GedcomRecord::getInstance('HEAD', $this->tree);
if ($head instanceof GedcomRecord) {
$sour = $head->facts(['SOUR'])->first();
if ($sour instanceof Fact) {
$source = $sour->value();
$title = $sour->attribute('NAME');
$version = $sour->attribute('VERS');
}
}
return [
$title,
$version,
$source,
];
} | [
"private",
"function",
"gedcomHead",
"(",
")",
":",
"array",
"{",
"$",
"title",
"=",
"''",
";",
"$",
"version",
"=",
"''",
";",
"$",
"source",
"=",
"''",
";",
"$",
"head",
"=",
"GedcomRecord",
"::",
"getInstance",
"(",
"'HEAD'",
",",
"$",
"this",
"->",
"tree",
")",
";",
"if",
"(",
"$",
"head",
"instanceof",
"GedcomRecord",
")",
"{",
"$",
"sour",
"=",
"$",
"head",
"->",
"facts",
"(",
"[",
"'SOUR'",
"]",
")",
"->",
"first",
"(",
")",
";",
"if",
"(",
"$",
"sour",
"instanceof",
"Fact",
")",
"{",
"$",
"source",
"=",
"$",
"sour",
"->",
"value",
"(",
")",
";",
"$",
"title",
"=",
"$",
"sour",
"->",
"attribute",
"(",
"'NAME'",
")",
";",
"$",
"version",
"=",
"$",
"sour",
"->",
"attribute",
"(",
"'VERS'",
")",
";",
"}",
"}",
"return",
"[",
"$",
"title",
",",
"$",
"version",
",",
"$",
"source",
",",
"]",
";",
"}"
] | Get information from the GEDCOM's HEAD record.
@return string[] | [
"Get",
"information",
"from",
"the",
"GEDCOM",
"s",
"HEAD",
"record",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Statistics/Repository/GedcomRepository.php#L53-L76 | train |
fisharebest/webtrees | app/Http/Controllers/Admin/ChangesLogController.php | ChangesLogController.changesQuery | private function changesQuery(ServerRequestInterface $request): Builder
{
$from = $request->getQueryParams()['from'] ?? '';
$to = $request->getQueryParams()['to'] ?? '';
$type = $request->getQueryParams()['type'] ?? '';
$oldged = $request->getQueryParams()['oldged'] ?? '';
$newged = $request->getQueryParams()['newged'] ?? '';
$xref = $request->getQueryParams()['xref'] ?? '';
$username = $request->getQueryParams()['username'] ?? '';
$ged = $request->getQueryParams()['ged'] ?? '';
$search = $request->getQueryParams()['search'] ?? [];
$search = $search['value'] ?? '';
$query = DB::table('change')
->leftJoin('user', 'user.user_id', '=', 'change.user_id')
->join('gedcom', 'gedcom.gedcom_id', '=', 'change.gedcom_id')
->select(['change.*', DB::raw("COALESCE(user_name, '<none>') AS user_name"), 'gedcom_name']);
if ($search !== '') {
$query->where(static function (Builder $query) use ($search): void {
$query
->whereContains('old_gedcom', $search)
->whereContains('new_gedcom', $search, 'or');
});
}
if ($from !== '') {
$query->where('change_time', '>=', $from);
}
if ($to !== '') {
// before end of the day
$query->where('change_time', '<', Carbon::make($to)->addDay());
}
if ($type !== '') {
$query->where('status', '=', $type);
}
if ($oldged !== '') {
$query->whereContains('old_gedcom', $oldged);
}
if ($newged !== '') {
$query->whereContains('new_gedcom', $oldged);
}
if ($xref !== '') {
$query->where('xref', '=', $xref);
}
if ($username !== '') {
$query->whereContains('user_name', $username);
}
if ($ged !== '') {
$query->whereContains('gedcom_name', $ged);
}
return $query;
} | php | private function changesQuery(ServerRequestInterface $request): Builder
{
$from = $request->getQueryParams()['from'] ?? '';
$to = $request->getQueryParams()['to'] ?? '';
$type = $request->getQueryParams()['type'] ?? '';
$oldged = $request->getQueryParams()['oldged'] ?? '';
$newged = $request->getQueryParams()['newged'] ?? '';
$xref = $request->getQueryParams()['xref'] ?? '';
$username = $request->getQueryParams()['username'] ?? '';
$ged = $request->getQueryParams()['ged'] ?? '';
$search = $request->getQueryParams()['search'] ?? [];
$search = $search['value'] ?? '';
$query = DB::table('change')
->leftJoin('user', 'user.user_id', '=', 'change.user_id')
->join('gedcom', 'gedcom.gedcom_id', '=', 'change.gedcom_id')
->select(['change.*', DB::raw("COALESCE(user_name, '<none>') AS user_name"), 'gedcom_name']);
if ($search !== '') {
$query->where(static function (Builder $query) use ($search): void {
$query
->whereContains('old_gedcom', $search)
->whereContains('new_gedcom', $search, 'or');
});
}
if ($from !== '') {
$query->where('change_time', '>=', $from);
}
if ($to !== '') {
// before end of the day
$query->where('change_time', '<', Carbon::make($to)->addDay());
}
if ($type !== '') {
$query->where('status', '=', $type);
}
if ($oldged !== '') {
$query->whereContains('old_gedcom', $oldged);
}
if ($newged !== '') {
$query->whereContains('new_gedcom', $oldged);
}
if ($xref !== '') {
$query->where('xref', '=', $xref);
}
if ($username !== '') {
$query->whereContains('user_name', $username);
}
if ($ged !== '') {
$query->whereContains('gedcom_name', $ged);
}
return $query;
} | [
"private",
"function",
"changesQuery",
"(",
"ServerRequestInterface",
"$",
"request",
")",
":",
"Builder",
"{",
"$",
"from",
"=",
"$",
"request",
"->",
"getQueryParams",
"(",
")",
"[",
"'from'",
"]",
"??",
"''",
";",
"$",
"to",
"=",
"$",
"request",
"->",
"getQueryParams",
"(",
")",
"[",
"'to'",
"]",
"??",
"''",
";",
"$",
"type",
"=",
"$",
"request",
"->",
"getQueryParams",
"(",
")",
"[",
"'type'",
"]",
"??",
"''",
";",
"$",
"oldged",
"=",
"$",
"request",
"->",
"getQueryParams",
"(",
")",
"[",
"'oldged'",
"]",
"??",
"''",
";",
"$",
"newged",
"=",
"$",
"request",
"->",
"getQueryParams",
"(",
")",
"[",
"'newged'",
"]",
"??",
"''",
";",
"$",
"xref",
"=",
"$",
"request",
"->",
"getQueryParams",
"(",
")",
"[",
"'xref'",
"]",
"??",
"''",
";",
"$",
"username",
"=",
"$",
"request",
"->",
"getQueryParams",
"(",
")",
"[",
"'username'",
"]",
"??",
"''",
";",
"$",
"ged",
"=",
"$",
"request",
"->",
"getQueryParams",
"(",
")",
"[",
"'ged'",
"]",
"??",
"''",
";",
"$",
"search",
"=",
"$",
"request",
"->",
"getQueryParams",
"(",
")",
"[",
"'search'",
"]",
"??",
"[",
"]",
";",
"$",
"search",
"=",
"$",
"search",
"[",
"'value'",
"]",
"??",
"''",
";",
"$",
"query",
"=",
"DB",
"::",
"table",
"(",
"'change'",
")",
"->",
"leftJoin",
"(",
"'user'",
",",
"'user.user_id'",
",",
"'='",
",",
"'change.user_id'",
")",
"->",
"join",
"(",
"'gedcom'",
",",
"'gedcom.gedcom_id'",
",",
"'='",
",",
"'change.gedcom_id'",
")",
"->",
"select",
"(",
"[",
"'change.*'",
",",
"DB",
"::",
"raw",
"(",
"\"COALESCE(user_name, '<none>') AS user_name\"",
")",
",",
"'gedcom_name'",
"]",
")",
";",
"if",
"(",
"$",
"search",
"!==",
"''",
")",
"{",
"$",
"query",
"->",
"where",
"(",
"static",
"function",
"(",
"Builder",
"$",
"query",
")",
"use",
"(",
"$",
"search",
")",
":",
"void",
"{",
"$",
"query",
"->",
"whereContains",
"(",
"'old_gedcom'",
",",
"$",
"search",
")",
"->",
"whereContains",
"(",
"'new_gedcom'",
",",
"$",
"search",
",",
"'or'",
")",
";",
"}",
")",
";",
"}",
"if",
"(",
"$",
"from",
"!==",
"''",
")",
"{",
"$",
"query",
"->",
"where",
"(",
"'change_time'",
",",
"'>='",
",",
"$",
"from",
")",
";",
"}",
"if",
"(",
"$",
"to",
"!==",
"''",
")",
"{",
"// before end of the day",
"$",
"query",
"->",
"where",
"(",
"'change_time'",
",",
"'<'",
",",
"Carbon",
"::",
"make",
"(",
"$",
"to",
")",
"->",
"addDay",
"(",
")",
")",
";",
"}",
"if",
"(",
"$",
"type",
"!==",
"''",
")",
"{",
"$",
"query",
"->",
"where",
"(",
"'status'",
",",
"'='",
",",
"$",
"type",
")",
";",
"}",
"if",
"(",
"$",
"oldged",
"!==",
"''",
")",
"{",
"$",
"query",
"->",
"whereContains",
"(",
"'old_gedcom'",
",",
"$",
"oldged",
")",
";",
"}",
"if",
"(",
"$",
"newged",
"!==",
"''",
")",
"{",
"$",
"query",
"->",
"whereContains",
"(",
"'new_gedcom'",
",",
"$",
"oldged",
")",
";",
"}",
"if",
"(",
"$",
"xref",
"!==",
"''",
")",
"{",
"$",
"query",
"->",
"where",
"(",
"'xref'",
",",
"'='",
",",
"$",
"xref",
")",
";",
"}",
"if",
"(",
"$",
"username",
"!==",
"''",
")",
"{",
"$",
"query",
"->",
"whereContains",
"(",
"'user_name'",
",",
"$",
"username",
")",
";",
"}",
"if",
"(",
"$",
"ged",
"!==",
"''",
")",
"{",
"$",
"query",
"->",
"whereContains",
"(",
"'gedcom_name'",
",",
"$",
"ged",
")",
";",
"}",
"return",
"$",
"query",
";",
"}"
] | Generate a query for filtering the changes log.
@param ServerRequestInterface $request
@return Builder | [
"Generate",
"a",
"query",
"for",
"filtering",
"the",
"changes",
"log",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Http/Controllers/Admin/ChangesLogController.php#L228-L288 | train |
fisharebest/webtrees | app/Functions/FunctionsRtl.php | FunctionsRtl.getChar | public static function getChar(string $text, int $offset): array
{
if ($text == '') {
return [
'letter' => '',
'length' => 0,
];
}
$char = substr($text, $offset, 1);
$length = 1;
if ((ord($char) & 0xE0) == 0xC0) {
$length = 2;
}
if ((ord($char) & 0xF0) == 0xE0) {
$length = 3;
}
if ((ord($char) & 0xF8) == 0xF0) {
$length = 4;
}
$letter = substr($text, $offset, $length);
return [
'letter' => $letter,
'length' => $length,
];
} | php | public static function getChar(string $text, int $offset): array
{
if ($text == '') {
return [
'letter' => '',
'length' => 0,
];
}
$char = substr($text, $offset, 1);
$length = 1;
if ((ord($char) & 0xE0) == 0xC0) {
$length = 2;
}
if ((ord($char) & 0xF0) == 0xE0) {
$length = 3;
}
if ((ord($char) & 0xF8) == 0xF0) {
$length = 4;
}
$letter = substr($text, $offset, $length);
return [
'letter' => $letter,
'length' => $length,
];
} | [
"public",
"static",
"function",
"getChar",
"(",
"string",
"$",
"text",
",",
"int",
"$",
"offset",
")",
":",
"array",
"{",
"if",
"(",
"$",
"text",
"==",
"''",
")",
"{",
"return",
"[",
"'letter'",
"=>",
"''",
",",
"'length'",
"=>",
"0",
",",
"]",
";",
"}",
"$",
"char",
"=",
"substr",
"(",
"$",
"text",
",",
"$",
"offset",
",",
"1",
")",
";",
"$",
"length",
"=",
"1",
";",
"if",
"(",
"(",
"ord",
"(",
"$",
"char",
")",
"&",
"0xE0",
")",
"==",
"0xC0",
")",
"{",
"$",
"length",
"=",
"2",
";",
"}",
"if",
"(",
"(",
"ord",
"(",
"$",
"char",
")",
"&",
"0xF0",
")",
"==",
"0xE0",
")",
"{",
"$",
"length",
"=",
"3",
";",
"}",
"if",
"(",
"(",
"ord",
"(",
"$",
"char",
")",
"&",
"0xF8",
")",
"==",
"0xF0",
")",
"{",
"$",
"length",
"=",
"4",
";",
"}",
"$",
"letter",
"=",
"substr",
"(",
"$",
"text",
",",
"$",
"offset",
",",
"$",
"length",
")",
";",
"return",
"[",
"'letter'",
"=>",
"$",
"letter",
",",
"'length'",
"=>",
"$",
"length",
",",
"]",
";",
"}"
] | Get the next character from an input string
@param string $text
@param int $offset
@return array | [
"Get",
"the",
"next",
"character",
"from",
"an",
"input",
"string"
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Functions/FunctionsRtl.php#L560-L586 | train |
fisharebest/webtrees | app/Functions/FunctionsRtl.php | FunctionsRtl.beginCurrentSpan | public static function beginCurrentSpan(&$result): void
{
if (self::$currentState === 'LTR') {
$result .= self::START_LTR;
}
if (self::$currentState === 'RTL') {
$result .= self::START_RTL;
}
self::$posSpanStart = strlen($result);
} | php | public static function beginCurrentSpan(&$result): void
{
if (self::$currentState === 'LTR') {
$result .= self::START_LTR;
}
if (self::$currentState === 'RTL') {
$result .= self::START_RTL;
}
self::$posSpanStart = strlen($result);
} | [
"public",
"static",
"function",
"beginCurrentSpan",
"(",
"&",
"$",
"result",
")",
":",
"void",
"{",
"if",
"(",
"self",
"::",
"$",
"currentState",
"===",
"'LTR'",
")",
"{",
"$",
"result",
".=",
"self",
"::",
"START_LTR",
";",
"}",
"if",
"(",
"self",
"::",
"$",
"currentState",
"===",
"'RTL'",
")",
"{",
"$",
"result",
".=",
"self",
"::",
"START_RTL",
";",
"}",
"self",
"::",
"$",
"posSpanStart",
"=",
"strlen",
"(",
"$",
"result",
")",
";",
"}"
] | Begin current span
@param string $result
@return void | [
"Begin",
"current",
"span"
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Functions/FunctionsRtl.php#L612-L622 | train |
fisharebest/webtrees | app/Http/Controllers/CalendarController.php | CalendarController.applyFilter | private function applyFilter(array $facts, string $filterof, string $filtersx): array
{
$filtered = [];
$hundred_years = Carbon::now()->subYears(100)->julianDay();
foreach ($facts as $fact) {
$record = $fact->record();
if ($filtersx) {
// Filter on sex
if ($record instanceof Individual && $filtersx !== $record->sex()) {
continue;
}
// Can't display families if the sex filter is on.
if ($record instanceof Family) {
continue;
}
}
// Filter living individuals
if ($filterof === 'living') {
if ($record instanceof Individual && $record->isDead()) {
continue;
}
if ($record instanceof Family) {
$husb = $record->husband();
$wife = $record->wife();
if ($husb && $husb->isDead() || $wife && $wife->isDead()) {
continue;
}
}
}
// Filter on recent events
if ($filterof === 'recent' && $fact->date()->maximumJulianDay() < $hundred_years) {
continue;
}
$filtered[] = $fact;
}
return $filtered;
} | php | private function applyFilter(array $facts, string $filterof, string $filtersx): array
{
$filtered = [];
$hundred_years = Carbon::now()->subYears(100)->julianDay();
foreach ($facts as $fact) {
$record = $fact->record();
if ($filtersx) {
// Filter on sex
if ($record instanceof Individual && $filtersx !== $record->sex()) {
continue;
}
// Can't display families if the sex filter is on.
if ($record instanceof Family) {
continue;
}
}
// Filter living individuals
if ($filterof === 'living') {
if ($record instanceof Individual && $record->isDead()) {
continue;
}
if ($record instanceof Family) {
$husb = $record->husband();
$wife = $record->wife();
if ($husb && $husb->isDead() || $wife && $wife->isDead()) {
continue;
}
}
}
// Filter on recent events
if ($filterof === 'recent' && $fact->date()->maximumJulianDay() < $hundred_years) {
continue;
}
$filtered[] = $fact;
}
return $filtered;
} | [
"private",
"function",
"applyFilter",
"(",
"array",
"$",
"facts",
",",
"string",
"$",
"filterof",
",",
"string",
"$",
"filtersx",
")",
":",
"array",
"{",
"$",
"filtered",
"=",
"[",
"]",
";",
"$",
"hundred_years",
"=",
"Carbon",
"::",
"now",
"(",
")",
"->",
"subYears",
"(",
"100",
")",
"->",
"julianDay",
"(",
")",
";",
"foreach",
"(",
"$",
"facts",
"as",
"$",
"fact",
")",
"{",
"$",
"record",
"=",
"$",
"fact",
"->",
"record",
"(",
")",
";",
"if",
"(",
"$",
"filtersx",
")",
"{",
"// Filter on sex",
"if",
"(",
"$",
"record",
"instanceof",
"Individual",
"&&",
"$",
"filtersx",
"!==",
"$",
"record",
"->",
"sex",
"(",
")",
")",
"{",
"continue",
";",
"}",
"// Can't display families if the sex filter is on.",
"if",
"(",
"$",
"record",
"instanceof",
"Family",
")",
"{",
"continue",
";",
"}",
"}",
"// Filter living individuals",
"if",
"(",
"$",
"filterof",
"===",
"'living'",
")",
"{",
"if",
"(",
"$",
"record",
"instanceof",
"Individual",
"&&",
"$",
"record",
"->",
"isDead",
"(",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"$",
"record",
"instanceof",
"Family",
")",
"{",
"$",
"husb",
"=",
"$",
"record",
"->",
"husband",
"(",
")",
";",
"$",
"wife",
"=",
"$",
"record",
"->",
"wife",
"(",
")",
";",
"if",
"(",
"$",
"husb",
"&&",
"$",
"husb",
"->",
"isDead",
"(",
")",
"||",
"$",
"wife",
"&&",
"$",
"wife",
"->",
"isDead",
"(",
")",
")",
"{",
"continue",
";",
"}",
"}",
"}",
"// Filter on recent events",
"if",
"(",
"$",
"filterof",
"===",
"'recent'",
"&&",
"$",
"fact",
"->",
"date",
"(",
")",
"->",
"maximumJulianDay",
"(",
")",
"<",
"$",
"hundred_years",
")",
"{",
"continue",
";",
"}",
"$",
"filtered",
"[",
"]",
"=",
"$",
"fact",
";",
"}",
"return",
"$",
"filtered",
";",
"}"
] | Filter a list of anniversaries
@param Fact[] $facts
@param string $filterof
@param string $filtersx
@return Fact[] | [
"Filter",
"a",
"list",
"of",
"anniversaries"
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Http/Controllers/CalendarController.php#L477-L514 | train |
fisharebest/webtrees | app/Http/Controllers/CalendarController.php | CalendarController.calendarListText | private function calendarListText(array $list, string $tag1, string $tag2, Tree $tree): string
{
$html = '';
foreach ($list as $id => $facts) {
$tmp = GedcomRecord::getInstance($id, $tree);
$html .= $tag1 . '<a href="' . e($tmp->url()) . '">' . $tmp->fullName() . '</a> ';
$html .= '<div class="indent">' . $facts . '</div>' . $tag2;
}
return $html;
} | php | private function calendarListText(array $list, string $tag1, string $tag2, Tree $tree): string
{
$html = '';
foreach ($list as $id => $facts) {
$tmp = GedcomRecord::getInstance($id, $tree);
$html .= $tag1 . '<a href="' . e($tmp->url()) . '">' . $tmp->fullName() . '</a> ';
$html .= '<div class="indent">' . $facts . '</div>' . $tag2;
}
return $html;
} | [
"private",
"function",
"calendarListText",
"(",
"array",
"$",
"list",
",",
"string",
"$",
"tag1",
",",
"string",
"$",
"tag2",
",",
"Tree",
"$",
"tree",
")",
":",
"string",
"{",
"$",
"html",
"=",
"''",
";",
"foreach",
"(",
"$",
"list",
"as",
"$",
"id",
"=>",
"$",
"facts",
")",
"{",
"$",
"tmp",
"=",
"GedcomRecord",
"::",
"getInstance",
"(",
"$",
"id",
",",
"$",
"tree",
")",
";",
"$",
"html",
".=",
"$",
"tag1",
".",
"'<a href=\"'",
".",
"e",
"(",
"$",
"tmp",
"->",
"url",
"(",
")",
")",
".",
"'\">'",
".",
"$",
"tmp",
"->",
"fullName",
"(",
")",
".",
"'</a> '",
";",
"$",
"html",
".=",
"'<div class=\"indent\">'",
".",
"$",
"facts",
".",
"'</div>'",
".",
"$",
"tag2",
";",
"}",
"return",
"$",
"html",
";",
"}"
] | Format a list of facts for display
@param Fact[] $list
@param string $tag1
@param string $tag2
@param Tree $tree
@return string | [
"Format",
"a",
"list",
"of",
"facts",
"for",
"display"
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Http/Controllers/CalendarController.php#L547-L558 | train |
fisharebest/webtrees | app/Module/ModuleThemeTrait.php | ModuleThemeTrait.icon | public function icon(Fact $fact): string
{
$asset = 'public/css/' . $this->name() . '/images/facts/' . $fact->getTag() . '.png';
if (file_exists(Webtrees::ROOT_DIR . 'public' . $asset)) {
return '<img src="' . e(asset($asset)) . '" title="' . GedcomTag::getLabel($fact->getTag()) . '">';
}
// Spacer image - for alignment - until we move to a sprite.
$asset = 'public/css/' . $this->name() . '/images/facts/NULL.png';
if (file_exists(Webtrees::ROOT_DIR . 'public' . $asset)) {
return '<img src="' . e(asset($asset)) . '">';
}
return '';
} | php | public function icon(Fact $fact): string
{
$asset = 'public/css/' . $this->name() . '/images/facts/' . $fact->getTag() . '.png';
if (file_exists(Webtrees::ROOT_DIR . 'public' . $asset)) {
return '<img src="' . e(asset($asset)) . '" title="' . GedcomTag::getLabel($fact->getTag()) . '">';
}
// Spacer image - for alignment - until we move to a sprite.
$asset = 'public/css/' . $this->name() . '/images/facts/NULL.png';
if (file_exists(Webtrees::ROOT_DIR . 'public' . $asset)) {
return '<img src="' . e(asset($asset)) . '">';
}
return '';
} | [
"public",
"function",
"icon",
"(",
"Fact",
"$",
"fact",
")",
":",
"string",
"{",
"$",
"asset",
"=",
"'public/css/'",
".",
"$",
"this",
"->",
"name",
"(",
")",
".",
"'/images/facts/'",
".",
"$",
"fact",
"->",
"getTag",
"(",
")",
".",
"'.png'",
";",
"if",
"(",
"file_exists",
"(",
"Webtrees",
"::",
"ROOT_DIR",
".",
"'public'",
".",
"$",
"asset",
")",
")",
"{",
"return",
"'<img src=\"'",
".",
"e",
"(",
"asset",
"(",
"$",
"asset",
")",
")",
".",
"'\" title=\"'",
".",
"GedcomTag",
"::",
"getLabel",
"(",
"$",
"fact",
"->",
"getTag",
"(",
")",
")",
".",
"'\">'",
";",
"}",
"// Spacer image - for alignment - until we move to a sprite.",
"$",
"asset",
"=",
"'public/css/'",
".",
"$",
"this",
"->",
"name",
"(",
")",
".",
"'/images/facts/NULL.png'",
";",
"if",
"(",
"file_exists",
"(",
"Webtrees",
"::",
"ROOT_DIR",
".",
"'public'",
".",
"$",
"asset",
")",
")",
"{",
"return",
"'<img src=\"'",
".",
"e",
"(",
"asset",
"(",
"$",
"asset",
")",
")",
".",
"'\">'",
";",
"}",
"return",
"''",
";",
"}"
] | Display an icon for this fact.
@TODO use CSS for this
@param Fact $fact
@return string | [
"Display",
"an",
"icon",
"for",
"this",
"fact",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Module/ModuleThemeTrait.php#L47-L61 | train |
fisharebest/webtrees | app/Module/ModuleThemeTrait.php | ModuleThemeTrait.individualBoxFacts | public function individualBoxFacts(Individual $individual): string
{
$html = '';
$opt_tags = preg_split('/\W/', $individual->tree()->getPreference('CHART_BOX_TAGS'), 0, PREG_SPLIT_NO_EMPTY);
// Show BIRT or equivalent event
foreach (Gedcom::BIRTH_EVENTS as $birttag) {
if (!in_array($birttag, $opt_tags, true)) {
$event = $individual->facts([$birttag])->first();
if ($event instanceof Fact) {
$html .= $event->summary();
break;
}
}
}
// Show optional events (before death)
foreach ($opt_tags as $key => $tag) {
if (!in_array($tag, Gedcom::DEATH_EVENTS, true)) {
$event = $individual->facts([$tag])->first();
if ($event instanceof Fact) {
$html .= $event->summary();
unset($opt_tags[$key]);
}
}
}
// Show DEAT or equivalent event
foreach (Gedcom::DEATH_EVENTS as $deattag) {
$event = $individual->facts([$deattag])->first();
if ($event instanceof Fact) {
$html .= $event->summary();
if (in_array($deattag, $opt_tags, true)) {
unset($opt_tags[array_search($deattag, $opt_tags, true)]);
}
break;
}
}
// Show remaining optional events (after death)
foreach ($opt_tags as $tag) {
$event = $individual->facts([$tag])->first();
if ($event instanceof Fact) {
$html .= $event->summary();
}
}
return $html;
} | php | public function individualBoxFacts(Individual $individual): string
{
$html = '';
$opt_tags = preg_split('/\W/', $individual->tree()->getPreference('CHART_BOX_TAGS'), 0, PREG_SPLIT_NO_EMPTY);
// Show BIRT or equivalent event
foreach (Gedcom::BIRTH_EVENTS as $birttag) {
if (!in_array($birttag, $opt_tags, true)) {
$event = $individual->facts([$birttag])->first();
if ($event instanceof Fact) {
$html .= $event->summary();
break;
}
}
}
// Show optional events (before death)
foreach ($opt_tags as $key => $tag) {
if (!in_array($tag, Gedcom::DEATH_EVENTS, true)) {
$event = $individual->facts([$tag])->first();
if ($event instanceof Fact) {
$html .= $event->summary();
unset($opt_tags[$key]);
}
}
}
// Show DEAT or equivalent event
foreach (Gedcom::DEATH_EVENTS as $deattag) {
$event = $individual->facts([$deattag])->first();
if ($event instanceof Fact) {
$html .= $event->summary();
if (in_array($deattag, $opt_tags, true)) {
unset($opt_tags[array_search($deattag, $opt_tags, true)]);
}
break;
}
}
// Show remaining optional events (after death)
foreach ($opt_tags as $tag) {
$event = $individual->facts([$tag])->first();
if ($event instanceof Fact) {
$html .= $event->summary();
}
}
return $html;
} | [
"public",
"function",
"individualBoxFacts",
"(",
"Individual",
"$",
"individual",
")",
":",
"string",
"{",
"$",
"html",
"=",
"''",
";",
"$",
"opt_tags",
"=",
"preg_split",
"(",
"'/\\W/'",
",",
"$",
"individual",
"->",
"tree",
"(",
")",
"->",
"getPreference",
"(",
"'CHART_BOX_TAGS'",
")",
",",
"0",
",",
"PREG_SPLIT_NO_EMPTY",
")",
";",
"// Show BIRT or equivalent event",
"foreach",
"(",
"Gedcom",
"::",
"BIRTH_EVENTS",
"as",
"$",
"birttag",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"birttag",
",",
"$",
"opt_tags",
",",
"true",
")",
")",
"{",
"$",
"event",
"=",
"$",
"individual",
"->",
"facts",
"(",
"[",
"$",
"birttag",
"]",
")",
"->",
"first",
"(",
")",
";",
"if",
"(",
"$",
"event",
"instanceof",
"Fact",
")",
"{",
"$",
"html",
".=",
"$",
"event",
"->",
"summary",
"(",
")",
";",
"break",
";",
"}",
"}",
"}",
"// Show optional events (before death)",
"foreach",
"(",
"$",
"opt_tags",
"as",
"$",
"key",
"=>",
"$",
"tag",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"tag",
",",
"Gedcom",
"::",
"DEATH_EVENTS",
",",
"true",
")",
")",
"{",
"$",
"event",
"=",
"$",
"individual",
"->",
"facts",
"(",
"[",
"$",
"tag",
"]",
")",
"->",
"first",
"(",
")",
";",
"if",
"(",
"$",
"event",
"instanceof",
"Fact",
")",
"{",
"$",
"html",
".=",
"$",
"event",
"->",
"summary",
"(",
")",
";",
"unset",
"(",
"$",
"opt_tags",
"[",
"$",
"key",
"]",
")",
";",
"}",
"}",
"}",
"// Show DEAT or equivalent event",
"foreach",
"(",
"Gedcom",
"::",
"DEATH_EVENTS",
"as",
"$",
"deattag",
")",
"{",
"$",
"event",
"=",
"$",
"individual",
"->",
"facts",
"(",
"[",
"$",
"deattag",
"]",
")",
"->",
"first",
"(",
")",
";",
"if",
"(",
"$",
"event",
"instanceof",
"Fact",
")",
"{",
"$",
"html",
".=",
"$",
"event",
"->",
"summary",
"(",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"deattag",
",",
"$",
"opt_tags",
",",
"true",
")",
")",
"{",
"unset",
"(",
"$",
"opt_tags",
"[",
"array_search",
"(",
"$",
"deattag",
",",
"$",
"opt_tags",
",",
"true",
")",
"]",
")",
";",
"}",
"break",
";",
"}",
"}",
"// Show remaining optional events (after death)",
"foreach",
"(",
"$",
"opt_tags",
"as",
"$",
"tag",
")",
"{",
"$",
"event",
"=",
"$",
"individual",
"->",
"facts",
"(",
"[",
"$",
"tag",
"]",
")",
"->",
"first",
"(",
")",
";",
"if",
"(",
"$",
"event",
"instanceof",
"Fact",
")",
"{",
"$",
"html",
".=",
"$",
"event",
"->",
"summary",
"(",
")",
";",
"}",
"}",
"return",
"$",
"html",
";",
"}"
] | Generate the facts, for display in charts.
@param Individual $individual
@return string | [
"Generate",
"the",
"facts",
"for",
"display",
"in",
"charts",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Module/ModuleThemeTrait.php#L70-L115 | train |
fisharebest/webtrees | app/Module/ModuleThemeTrait.php | ModuleThemeTrait.individualBoxMenu | public function individualBoxMenu(Individual $individual): array
{
$menus = array_merge(
$this->individualBoxMenuCharts($individual),
$this->individualBoxMenuFamilyLinks($individual)
);
return $menus;
} | php | public function individualBoxMenu(Individual $individual): array
{
$menus = array_merge(
$this->individualBoxMenuCharts($individual),
$this->individualBoxMenuFamilyLinks($individual)
);
return $menus;
} | [
"public",
"function",
"individualBoxMenu",
"(",
"Individual",
"$",
"individual",
")",
":",
"array",
"{",
"$",
"menus",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"individualBoxMenuCharts",
"(",
"$",
"individual",
")",
",",
"$",
"this",
"->",
"individualBoxMenuFamilyLinks",
"(",
"$",
"individual",
")",
")",
";",
"return",
"$",
"menus",
";",
"}"
] | Links, to show in chart boxes;
@param Individual $individual
@return Menu[] | [
"Links",
"to",
"show",
"in",
"chart",
"boxes",
";"
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Module/ModuleThemeTrait.php#L124-L132 | train |
fisharebest/webtrees | app/Module/ModuleThemeTrait.php | ModuleThemeTrait.individualBoxMenuCharts | public function individualBoxMenuCharts(Individual $individual): array
{
$menus = [];
foreach (app(ModuleService::class)->findByComponent(ModuleChartInterface::class, $individual->tree(), Auth::user()) as $chart) {
$menu = $chart->chartBoxMenu($individual);
if ($menu) {
$menus[] = $menu;
}
}
usort($menus, static function (Menu $x, Menu $y) {
return I18N::strcasecmp($x->getLabel(), $y->getLabel());
});
return $menus;
} | php | public function individualBoxMenuCharts(Individual $individual): array
{
$menus = [];
foreach (app(ModuleService::class)->findByComponent(ModuleChartInterface::class, $individual->tree(), Auth::user()) as $chart) {
$menu = $chart->chartBoxMenu($individual);
if ($menu) {
$menus[] = $menu;
}
}
usort($menus, static function (Menu $x, Menu $y) {
return I18N::strcasecmp($x->getLabel(), $y->getLabel());
});
return $menus;
} | [
"public",
"function",
"individualBoxMenuCharts",
"(",
"Individual",
"$",
"individual",
")",
":",
"array",
"{",
"$",
"menus",
"=",
"[",
"]",
";",
"foreach",
"(",
"app",
"(",
"ModuleService",
"::",
"class",
")",
"->",
"findByComponent",
"(",
"ModuleChartInterface",
"::",
"class",
",",
"$",
"individual",
"->",
"tree",
"(",
")",
",",
"Auth",
"::",
"user",
"(",
")",
")",
"as",
"$",
"chart",
")",
"{",
"$",
"menu",
"=",
"$",
"chart",
"->",
"chartBoxMenu",
"(",
"$",
"individual",
")",
";",
"if",
"(",
"$",
"menu",
")",
"{",
"$",
"menus",
"[",
"]",
"=",
"$",
"menu",
";",
"}",
"}",
"usort",
"(",
"$",
"menus",
",",
"static",
"function",
"(",
"Menu",
"$",
"x",
",",
"Menu",
"$",
"y",
")",
"{",
"return",
"I18N",
"::",
"strcasecmp",
"(",
"$",
"x",
"->",
"getLabel",
"(",
")",
",",
"$",
"y",
"->",
"getLabel",
"(",
")",
")",
";",
"}",
")",
";",
"return",
"$",
"menus",
";",
"}"
] | Chart links, to show in chart boxes;
@param Individual $individual
@return Menu[] | [
"Chart",
"links",
"to",
"show",
"in",
"chart",
"boxes",
";"
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Module/ModuleThemeTrait.php#L141-L156 | train |
fisharebest/webtrees | app/Module/ModuleThemeTrait.php | ModuleThemeTrait.individualBoxMenuFamilyLinks | public function individualBoxMenuFamilyLinks(Individual $individual): array
{
$menus = [];
foreach ($individual->spouseFamilies() as $family) {
$menus[] = new Menu('<strong>' . I18N::translate('Family with spouse') . '</strong>', $family->url());
$spouse = $family->spouse($individual);
if ($spouse && $spouse->canShowName()) {
$menus[] = new Menu($spouse->fullName(), $spouse->url());
}
foreach ($family->children() as $child) {
if ($child->canShowName()) {
$menus[] = new Menu($child->fullName(), $child->url());
}
}
}
return $menus;
} | php | public function individualBoxMenuFamilyLinks(Individual $individual): array
{
$menus = [];
foreach ($individual->spouseFamilies() as $family) {
$menus[] = new Menu('<strong>' . I18N::translate('Family with spouse') . '</strong>', $family->url());
$spouse = $family->spouse($individual);
if ($spouse && $spouse->canShowName()) {
$menus[] = new Menu($spouse->fullName(), $spouse->url());
}
foreach ($family->children() as $child) {
if ($child->canShowName()) {
$menus[] = new Menu($child->fullName(), $child->url());
}
}
}
return $menus;
} | [
"public",
"function",
"individualBoxMenuFamilyLinks",
"(",
"Individual",
"$",
"individual",
")",
":",
"array",
"{",
"$",
"menus",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"individual",
"->",
"spouseFamilies",
"(",
")",
"as",
"$",
"family",
")",
"{",
"$",
"menus",
"[",
"]",
"=",
"new",
"Menu",
"(",
"'<strong>'",
".",
"I18N",
"::",
"translate",
"(",
"'Family with spouse'",
")",
".",
"'</strong>'",
",",
"$",
"family",
"->",
"url",
"(",
")",
")",
";",
"$",
"spouse",
"=",
"$",
"family",
"->",
"spouse",
"(",
"$",
"individual",
")",
";",
"if",
"(",
"$",
"spouse",
"&&",
"$",
"spouse",
"->",
"canShowName",
"(",
")",
")",
"{",
"$",
"menus",
"[",
"]",
"=",
"new",
"Menu",
"(",
"$",
"spouse",
"->",
"fullName",
"(",
")",
",",
"$",
"spouse",
"->",
"url",
"(",
")",
")",
";",
"}",
"foreach",
"(",
"$",
"family",
"->",
"children",
"(",
")",
"as",
"$",
"child",
")",
"{",
"if",
"(",
"$",
"child",
"->",
"canShowName",
"(",
")",
")",
"{",
"$",
"menus",
"[",
"]",
"=",
"new",
"Menu",
"(",
"$",
"child",
"->",
"fullName",
"(",
")",
",",
"$",
"child",
"->",
"url",
"(",
")",
")",
";",
"}",
"}",
"}",
"return",
"$",
"menus",
";",
"}"
] | Family links, to show in chart boxes.
@param Individual $individual
@return Menu[] | [
"Family",
"links",
"to",
"show",
"in",
"chart",
"boxes",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Module/ModuleThemeTrait.php#L165-L183 | train |
fisharebest/webtrees | app/Module/ModuleThemeTrait.php | ModuleThemeTrait.menuControlPanel | public function menuControlPanel(Tree $tree): ?Menu
{
if (Auth::isAdmin()) {
return new Menu(I18N::translate('Control panel'), route('admin-control-panel'), 'menu-admin');
}
if (Auth::isManager($tree)) {
return new Menu(I18N::translate('Control panel'), route('admin-control-panel-manager'), 'menu-admin');
}
return null;
} | php | public function menuControlPanel(Tree $tree): ?Menu
{
if (Auth::isAdmin()) {
return new Menu(I18N::translate('Control panel'), route('admin-control-panel'), 'menu-admin');
}
if (Auth::isManager($tree)) {
return new Menu(I18N::translate('Control panel'), route('admin-control-panel-manager'), 'menu-admin');
}
return null;
} | [
"public",
"function",
"menuControlPanel",
"(",
"Tree",
"$",
"tree",
")",
":",
"?",
"Menu",
"{",
"if",
"(",
"Auth",
"::",
"isAdmin",
"(",
")",
")",
"{",
"return",
"new",
"Menu",
"(",
"I18N",
"::",
"translate",
"(",
"'Control panel'",
")",
",",
"route",
"(",
"'admin-control-panel'",
")",
",",
"'menu-admin'",
")",
";",
"}",
"if",
"(",
"Auth",
"::",
"isManager",
"(",
"$",
"tree",
")",
")",
"{",
"return",
"new",
"Menu",
"(",
"I18N",
"::",
"translate",
"(",
"'Control panel'",
")",
",",
"route",
"(",
"'admin-control-panel-manager'",
")",
",",
"'menu-admin'",
")",
";",
"}",
"return",
"null",
";",
"}"
] | Generate a menu item for the control panel.
@param Tree $tree
@return Menu|null | [
"Generate",
"a",
"menu",
"item",
"for",
"the",
"control",
"panel",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Module/ModuleThemeTrait.php#L214-L225 | train |
fisharebest/webtrees | app/Module/ModuleThemeTrait.php | ModuleThemeTrait.menuLanguages | public function menuLanguages(): ?Menu
{
$menu = new Menu(I18N::translate('Language'), '#', 'menu-language');
foreach (I18N::activeLocales() as $locale) {
$language_tag = $locale->languageTag();
$class = 'menu-language-' . $language_tag . (WT_LOCALE === $language_tag ? ' active' : '');
$menu->addSubmenu(new Menu($locale->endonym(), '#', $class, [
'onclick' => 'return false;',
'data-language' => $language_tag,
]));
}
if (count($menu->getSubmenus()) > 1) {
return $menu;
}
return null;
} | php | public function menuLanguages(): ?Menu
{
$menu = new Menu(I18N::translate('Language'), '#', 'menu-language');
foreach (I18N::activeLocales() as $locale) {
$language_tag = $locale->languageTag();
$class = 'menu-language-' . $language_tag . (WT_LOCALE === $language_tag ? ' active' : '');
$menu->addSubmenu(new Menu($locale->endonym(), '#', $class, [
'onclick' => 'return false;',
'data-language' => $language_tag,
]));
}
if (count($menu->getSubmenus()) > 1) {
return $menu;
}
return null;
} | [
"public",
"function",
"menuLanguages",
"(",
")",
":",
"?",
"Menu",
"{",
"$",
"menu",
"=",
"new",
"Menu",
"(",
"I18N",
"::",
"translate",
"(",
"'Language'",
")",
",",
"'#'",
",",
"'menu-language'",
")",
";",
"foreach",
"(",
"I18N",
"::",
"activeLocales",
"(",
")",
"as",
"$",
"locale",
")",
"{",
"$",
"language_tag",
"=",
"$",
"locale",
"->",
"languageTag",
"(",
")",
";",
"$",
"class",
"=",
"'menu-language-'",
".",
"$",
"language_tag",
".",
"(",
"WT_LOCALE",
"===",
"$",
"language_tag",
"?",
"' active'",
":",
"''",
")",
";",
"$",
"menu",
"->",
"addSubmenu",
"(",
"new",
"Menu",
"(",
"$",
"locale",
"->",
"endonym",
"(",
")",
",",
"'#'",
",",
"$",
"class",
",",
"[",
"'onclick'",
"=>",
"'return false;'",
",",
"'data-language'",
"=>",
"$",
"language_tag",
",",
"]",
")",
")",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"menu",
"->",
"getSubmenus",
"(",
")",
")",
">",
"1",
")",
"{",
"return",
"$",
"menu",
";",
"}",
"return",
"null",
";",
"}"
] | A menu to show a list of available languages.
@return Menu|null | [
"A",
"menu",
"to",
"show",
"a",
"list",
"of",
"available",
"languages",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Module/ModuleThemeTrait.php#L232-L250 | train |
fisharebest/webtrees | app/Module/ModuleThemeTrait.php | ModuleThemeTrait.menuMyPage | public function menuMyPage(Tree $tree): Menu
{
return new Menu(I18N::translate('My page'), route('user-page', ['ged' => $tree->name()]), 'menu-mypage');
} | php | public function menuMyPage(Tree $tree): Menu
{
return new Menu(I18N::translate('My page'), route('user-page', ['ged' => $tree->name()]), 'menu-mypage');
} | [
"public",
"function",
"menuMyPage",
"(",
"Tree",
"$",
"tree",
")",
":",
"Menu",
"{",
"return",
"new",
"Menu",
"(",
"I18N",
"::",
"translate",
"(",
"'My page'",
")",
",",
"route",
"(",
"'user-page'",
",",
"[",
"'ged'",
"=>",
"$",
"tree",
"->",
"name",
"(",
")",
"]",
")",
",",
"'menu-mypage'",
")",
";",
"}"
] | A link to the user's personal home page.
@param Tree $tree
@return Menu | [
"A",
"link",
"to",
"the",
"user",
"s",
"personal",
"home",
"page",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Module/ModuleThemeTrait.php#L325-L328 | train |
fisharebest/webtrees | app/Module/ModuleThemeTrait.php | ModuleThemeTrait.menuMyPages | public function menuMyPages(?Tree $tree): ?Menu
{
if ($tree instanceof Tree && Auth::id()) {
return new Menu(I18N::translate('My pages'), '#', 'menu-mymenu', [], array_filter([
$this->menuMyPage($tree),
$this->menuMyIndividualRecord($tree),
$this->menuMyPedigree($tree),
$this->menuMyAccount(),
$this->menuControlPanel($tree),
$this->menuChangeBlocks($tree),
]));
}
return null;
} | php | public function menuMyPages(?Tree $tree): ?Menu
{
if ($tree instanceof Tree && Auth::id()) {
return new Menu(I18N::translate('My pages'), '#', 'menu-mymenu', [], array_filter([
$this->menuMyPage($tree),
$this->menuMyIndividualRecord($tree),
$this->menuMyPedigree($tree),
$this->menuMyAccount(),
$this->menuControlPanel($tree),
$this->menuChangeBlocks($tree),
]));
}
return null;
} | [
"public",
"function",
"menuMyPages",
"(",
"?",
"Tree",
"$",
"tree",
")",
":",
"?",
"Menu",
"{",
"if",
"(",
"$",
"tree",
"instanceof",
"Tree",
"&&",
"Auth",
"::",
"id",
"(",
")",
")",
"{",
"return",
"new",
"Menu",
"(",
"I18N",
"::",
"translate",
"(",
"'My pages'",
")",
",",
"'#'",
",",
"'menu-mymenu'",
",",
"[",
"]",
",",
"array_filter",
"(",
"[",
"$",
"this",
"->",
"menuMyPage",
"(",
"$",
"tree",
")",
",",
"$",
"this",
"->",
"menuMyIndividualRecord",
"(",
"$",
"tree",
")",
",",
"$",
"this",
"->",
"menuMyPedigree",
"(",
"$",
"tree",
")",
",",
"$",
"this",
"->",
"menuMyAccount",
"(",
")",
",",
"$",
"this",
"->",
"menuControlPanel",
"(",
"$",
"tree",
")",
",",
"$",
"this",
"->",
"menuChangeBlocks",
"(",
"$",
"tree",
")",
",",
"]",
")",
")",
";",
"}",
"return",
"null",
";",
"}"
] | A menu for the user's personal pages.
@param Tree|null $tree
@return Menu|null | [
"A",
"menu",
"for",
"the",
"user",
"s",
"personal",
"pages",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Module/ModuleThemeTrait.php#L337-L351 | train |
fisharebest/webtrees | app/Module/ModuleThemeTrait.php | ModuleThemeTrait.menuMyPedigree | public function menuMyPedigree(Tree $tree): ?Menu
{
$gedcomid = $tree->getUserPreference(Auth::user(), 'gedcomid');
$pedigree_chart = app(ModuleService::class)->findByComponent(ModuleChartInterface::class, $tree, Auth::user())
->filter(static function (ModuleInterface $module): bool {
return $module instanceof PedigreeChartModule;
});
if ($gedcomid !== '' && $pedigree_chart instanceof PedigreeChartModule) {
return new Menu(
I18N::translate('My pedigree'),
route('pedigree', [
'xref' => $gedcomid,
'ged' => $tree->name(),
]),
'menu-mypedigree'
);
}
return null;
} | php | public function menuMyPedigree(Tree $tree): ?Menu
{
$gedcomid = $tree->getUserPreference(Auth::user(), 'gedcomid');
$pedigree_chart = app(ModuleService::class)->findByComponent(ModuleChartInterface::class, $tree, Auth::user())
->filter(static function (ModuleInterface $module): bool {
return $module instanceof PedigreeChartModule;
});
if ($gedcomid !== '' && $pedigree_chart instanceof PedigreeChartModule) {
return new Menu(
I18N::translate('My pedigree'),
route('pedigree', [
'xref' => $gedcomid,
'ged' => $tree->name(),
]),
'menu-mypedigree'
);
}
return null;
} | [
"public",
"function",
"menuMyPedigree",
"(",
"Tree",
"$",
"tree",
")",
":",
"?",
"Menu",
"{",
"$",
"gedcomid",
"=",
"$",
"tree",
"->",
"getUserPreference",
"(",
"Auth",
"::",
"user",
"(",
")",
",",
"'gedcomid'",
")",
";",
"$",
"pedigree_chart",
"=",
"app",
"(",
"ModuleService",
"::",
"class",
")",
"->",
"findByComponent",
"(",
"ModuleChartInterface",
"::",
"class",
",",
"$",
"tree",
",",
"Auth",
"::",
"user",
"(",
")",
")",
"->",
"filter",
"(",
"static",
"function",
"(",
"ModuleInterface",
"$",
"module",
")",
":",
"bool",
"{",
"return",
"$",
"module",
"instanceof",
"PedigreeChartModule",
";",
"}",
")",
";",
"if",
"(",
"$",
"gedcomid",
"!==",
"''",
"&&",
"$",
"pedigree_chart",
"instanceof",
"PedigreeChartModule",
")",
"{",
"return",
"new",
"Menu",
"(",
"I18N",
"::",
"translate",
"(",
"'My pedigree'",
")",
",",
"route",
"(",
"'pedigree'",
",",
"[",
"'xref'",
"=>",
"$",
"gedcomid",
",",
"'ged'",
"=>",
"$",
"tree",
"->",
"name",
"(",
")",
",",
"]",
")",
",",
"'menu-mypedigree'",
")",
";",
"}",
"return",
"null",
";",
"}"
] | A link to the user's individual record.
@param Tree $tree
@return Menu|null | [
"A",
"link",
"to",
"the",
"user",
"s",
"individual",
"record",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Module/ModuleThemeTrait.php#L360-L381 | train |
fisharebest/webtrees | app/Module/ModuleThemeTrait.php | ModuleThemeTrait.menuPendingChanges | public function menuPendingChanges(?Tree $tree): ?Menu
{
if ($tree instanceof Tree && $tree->hasPendingEdit() && Auth::isModerator($tree)) {
$url = route('show-pending', [
'ged' => $tree->name(),
'url' => app(ServerRequestInterface::class)->getUri(),
]);
return new Menu(I18N::translate('Pending changes'), $url, 'menu-pending');
}
return null;
} | php | public function menuPendingChanges(?Tree $tree): ?Menu
{
if ($tree instanceof Tree && $tree->hasPendingEdit() && Auth::isModerator($tree)) {
$url = route('show-pending', [
'ged' => $tree->name(),
'url' => app(ServerRequestInterface::class)->getUri(),
]);
return new Menu(I18N::translate('Pending changes'), $url, 'menu-pending');
}
return null;
} | [
"public",
"function",
"menuPendingChanges",
"(",
"?",
"Tree",
"$",
"tree",
")",
":",
"?",
"Menu",
"{",
"if",
"(",
"$",
"tree",
"instanceof",
"Tree",
"&&",
"$",
"tree",
"->",
"hasPendingEdit",
"(",
")",
"&&",
"Auth",
"::",
"isModerator",
"(",
"$",
"tree",
")",
")",
"{",
"$",
"url",
"=",
"route",
"(",
"'show-pending'",
",",
"[",
"'ged'",
"=>",
"$",
"tree",
"->",
"name",
"(",
")",
",",
"'url'",
"=>",
"app",
"(",
"ServerRequestInterface",
"::",
"class",
")",
"->",
"getUri",
"(",
")",
",",
"]",
")",
";",
"return",
"new",
"Menu",
"(",
"I18N",
"::",
"translate",
"(",
"'Pending changes'",
")",
",",
"$",
"url",
",",
"'menu-pending'",
")",
";",
"}",
"return",
"null",
";",
"}"
] | Create a pending changes menu.
@param Tree|null $tree
@return Menu|null | [
"Create",
"a",
"pending",
"changes",
"menu",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Module/ModuleThemeTrait.php#L390-L402 | train |
fisharebest/webtrees | app/Module/ModuleThemeTrait.php | ModuleThemeTrait.menuThemes | public function menuThemes(): ?Menu
{
$themes = app(ModuleService::class)->findByInterface(ModuleThemeInterface::class, false, true);
$current_theme = app(ModuleThemeInterface::class);
if ($themes->count() > 1) {
$submenus = $themes->map(static function (ModuleThemeInterface $theme) use ($current_theme): Menu {
$active = $theme->name() === $current_theme->name();
$class = 'menu-theme-' . $theme->name() . ($active ? ' active' : '');
return new Menu($theme->title(), '#', $class, [
'onclick' => 'return false;',
'data-theme' => $theme->name(),
]);
});
return new Menu(I18N::translate('Theme'), '#', 'menu-theme', [], $submenus->all());
}
return null;
} | php | public function menuThemes(): ?Menu
{
$themes = app(ModuleService::class)->findByInterface(ModuleThemeInterface::class, false, true);
$current_theme = app(ModuleThemeInterface::class);
if ($themes->count() > 1) {
$submenus = $themes->map(static function (ModuleThemeInterface $theme) use ($current_theme): Menu {
$active = $theme->name() === $current_theme->name();
$class = 'menu-theme-' . $theme->name() . ($active ? ' active' : '');
return new Menu($theme->title(), '#', $class, [
'onclick' => 'return false;',
'data-theme' => $theme->name(),
]);
});
return new Menu(I18N::translate('Theme'), '#', 'menu-theme', [], $submenus->all());
}
return null;
} | [
"public",
"function",
"menuThemes",
"(",
")",
":",
"?",
"Menu",
"{",
"$",
"themes",
"=",
"app",
"(",
"ModuleService",
"::",
"class",
")",
"->",
"findByInterface",
"(",
"ModuleThemeInterface",
"::",
"class",
",",
"false",
",",
"true",
")",
";",
"$",
"current_theme",
"=",
"app",
"(",
"ModuleThemeInterface",
"::",
"class",
")",
";",
"if",
"(",
"$",
"themes",
"->",
"count",
"(",
")",
">",
"1",
")",
"{",
"$",
"submenus",
"=",
"$",
"themes",
"->",
"map",
"(",
"static",
"function",
"(",
"ModuleThemeInterface",
"$",
"theme",
")",
"use",
"(",
"$",
"current_theme",
")",
":",
"Menu",
"{",
"$",
"active",
"=",
"$",
"theme",
"->",
"name",
"(",
")",
"===",
"$",
"current_theme",
"->",
"name",
"(",
")",
";",
"$",
"class",
"=",
"'menu-theme-'",
".",
"$",
"theme",
"->",
"name",
"(",
")",
".",
"(",
"$",
"active",
"?",
"' active'",
":",
"''",
")",
";",
"return",
"new",
"Menu",
"(",
"$",
"theme",
"->",
"title",
"(",
")",
",",
"'#'",
",",
"$",
"class",
",",
"[",
"'onclick'",
"=>",
"'return false;'",
",",
"'data-theme'",
"=>",
"$",
"theme",
"->",
"name",
"(",
")",
",",
"]",
")",
";",
"}",
")",
";",
"return",
"new",
"Menu",
"(",
"I18N",
"::",
"translate",
"(",
"'Theme'",
")",
",",
"'#'",
",",
"'menu-theme'",
",",
"[",
"]",
",",
"$",
"submenus",
"->",
"all",
"(",
")",
")",
";",
"}",
"return",
"null",
";",
"}"
] | Themes menu.
@return Menu|null | [
"Themes",
"menu",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Module/ModuleThemeTrait.php#L409-L430 | train |
fisharebest/webtrees | app/Module/ModuleThemeTrait.php | ModuleThemeTrait.genealogyMenuContent | public function genealogyMenuContent(array $menus): string
{
return implode('', array_map(static function (Menu $menu): string {
return $menu->bootstrap4();
}, $menus));
} | php | public function genealogyMenuContent(array $menus): string
{
return implode('', array_map(static function (Menu $menu): string {
return $menu->bootstrap4();
}, $menus));
} | [
"public",
"function",
"genealogyMenuContent",
"(",
"array",
"$",
"menus",
")",
":",
"string",
"{",
"return",
"implode",
"(",
"''",
",",
"array_map",
"(",
"static",
"function",
"(",
"Menu",
"$",
"menu",
")",
":",
"string",
"{",
"return",
"$",
"menu",
"->",
"bootstrap4",
"(",
")",
";",
"}",
",",
"$",
"menus",
")",
")",
";",
"}"
] | Create the genealogy menu.
@param Menu[] $menus
@return string | [
"Create",
"the",
"genealogy",
"menu",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Module/ModuleThemeTrait.php#L472-L477 | train |
fisharebest/webtrees | app/Module/ModuleThemeTrait.php | ModuleThemeTrait.userMenu | public function userMenu(?Tree $tree): array
{
return array_filter([
$this->menuPendingChanges($tree),
$this->menuMyPages($tree),
$this->menuThemes(),
$this->menuLanguages(),
$this->menuLogin(),
$this->menuLogout(),
]);
} | php | public function userMenu(?Tree $tree): array
{
return array_filter([
$this->menuPendingChanges($tree),
$this->menuMyPages($tree),
$this->menuThemes(),
$this->menuLanguages(),
$this->menuLogin(),
$this->menuLogout(),
]);
} | [
"public",
"function",
"userMenu",
"(",
"?",
"Tree",
"$",
"tree",
")",
":",
"array",
"{",
"return",
"array_filter",
"(",
"[",
"$",
"this",
"->",
"menuPendingChanges",
"(",
"$",
"tree",
")",
",",
"$",
"this",
"->",
"menuMyPages",
"(",
"$",
"tree",
")",
",",
"$",
"this",
"->",
"menuThemes",
"(",
")",
",",
"$",
"this",
"->",
"menuLanguages",
"(",
")",
",",
"$",
"this",
"->",
"menuLogin",
"(",
")",
",",
"$",
"this",
"->",
"menuLogout",
"(",
")",
",",
"]",
")",
";",
"}"
] | Generate a list of items for the user menu.
@param Tree|null $tree
@return Menu[] | [
"Generate",
"a",
"list",
"of",
"items",
"for",
"the",
"user",
"menu",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Module/ModuleThemeTrait.php#L486-L496 | train |
fisharebest/webtrees | app/Filter.php | Filter.formatText | public static function formatText(string $text, Tree $tree): string
{
switch ($tree->getPreference('FORMAT_TEXT')) {
case 'markdown':
return '<div class="markdown" dir="auto">' . self::markdown($text, $tree) . '</div>';
default:
return '<div class="markdown" style="white-space: pre-wrap;" dir="auto">' . self::expandUrls($text, $tree) . '</div>';
}
} | php | public static function formatText(string $text, Tree $tree): string
{
switch ($tree->getPreference('FORMAT_TEXT')) {
case 'markdown':
return '<div class="markdown" dir="auto">' . self::markdown($text, $tree) . '</div>';
default:
return '<div class="markdown" style="white-space: pre-wrap;" dir="auto">' . self::expandUrls($text, $tree) . '</div>';
}
} | [
"public",
"static",
"function",
"formatText",
"(",
"string",
"$",
"text",
",",
"Tree",
"$",
"tree",
")",
":",
"string",
"{",
"switch",
"(",
"$",
"tree",
"->",
"getPreference",
"(",
"'FORMAT_TEXT'",
")",
")",
"{",
"case",
"'markdown'",
":",
"return",
"'<div class=\"markdown\" dir=\"auto\">'",
".",
"self",
"::",
"markdown",
"(",
"$",
"text",
",",
"$",
"tree",
")",
".",
"'</div>'",
";",
"default",
":",
"return",
"'<div class=\"markdown\" style=\"white-space: pre-wrap;\" dir=\"auto\">'",
".",
"self",
"::",
"expandUrls",
"(",
"$",
"text",
",",
"$",
"tree",
")",
".",
"'</div>'",
";",
"}",
"}"
] | Format block-level text such as notes or transcripts, etc.
@param string $text
@param Tree $tree
@return string | [
"Format",
"block",
"-",
"level",
"text",
"such",
"as",
"notes",
"or",
"transcripts",
"etc",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Filter.php#L58-L66 | train |
fisharebest/webtrees | app/Filter.php | Filter.expandUrls | public static function expandUrls(string $text, Tree $tree): string
{
// If it looks like a URL, turn it into a markdown autolink.
$text = preg_replace('/' . addcslashes(self::URL_REGEX, '/') . '/', '<$0>', $text);
// Create a minimal commonmark processor - just add support for autolinks.
$environment = new Environment();
$environment->mergeConfig([
'renderer' => [
'block_separator' => "\n",
'inner_separator' => "\n",
'soft_break' => "\n",
],
'html_input' => Environment::HTML_INPUT_ESCAPE,
'allow_unsafe_links' => true,
]);
$environment
->addBlockRenderer(Document::class, new DocumentRenderer())
->addBlockRenderer(Paragraph::class, new ParagraphRenderer())
->addInlineRenderer(Text::class, new TextRenderer())
->addInlineRenderer(Link::class, new LinkRenderer())
->addInlineParser(new AutolinkParser());
$environment->addExtension(new CensusTableExtension());
$environment->addExtension(new XrefExtension($tree));
$converter = new Converter(new DocParser($environment), new HtmlRenderer($environment));
try {
return $converter->convertToHtml($text);
} catch (Throwable $ex) {
// See issue #1824
return $text;
}
} | php | public static function expandUrls(string $text, Tree $tree): string
{
// If it looks like a URL, turn it into a markdown autolink.
$text = preg_replace('/' . addcslashes(self::URL_REGEX, '/') . '/', '<$0>', $text);
// Create a minimal commonmark processor - just add support for autolinks.
$environment = new Environment();
$environment->mergeConfig([
'renderer' => [
'block_separator' => "\n",
'inner_separator' => "\n",
'soft_break' => "\n",
],
'html_input' => Environment::HTML_INPUT_ESCAPE,
'allow_unsafe_links' => true,
]);
$environment
->addBlockRenderer(Document::class, new DocumentRenderer())
->addBlockRenderer(Paragraph::class, new ParagraphRenderer())
->addInlineRenderer(Text::class, new TextRenderer())
->addInlineRenderer(Link::class, new LinkRenderer())
->addInlineParser(new AutolinkParser());
$environment->addExtension(new CensusTableExtension());
$environment->addExtension(new XrefExtension($tree));
$converter = new Converter(new DocParser($environment), new HtmlRenderer($environment));
try {
return $converter->convertToHtml($text);
} catch (Throwable $ex) {
// See issue #1824
return $text;
}
} | [
"public",
"static",
"function",
"expandUrls",
"(",
"string",
"$",
"text",
",",
"Tree",
"$",
"tree",
")",
":",
"string",
"{",
"// If it looks like a URL, turn it into a markdown autolink.",
"$",
"text",
"=",
"preg_replace",
"(",
"'/'",
".",
"addcslashes",
"(",
"self",
"::",
"URL_REGEX",
",",
"'/'",
")",
".",
"'/'",
",",
"'<$0>'",
",",
"$",
"text",
")",
";",
"// Create a minimal commonmark processor - just add support for autolinks.",
"$",
"environment",
"=",
"new",
"Environment",
"(",
")",
";",
"$",
"environment",
"->",
"mergeConfig",
"(",
"[",
"'renderer'",
"=>",
"[",
"'block_separator'",
"=>",
"\"\\n\"",
",",
"'inner_separator'",
"=>",
"\"\\n\"",
",",
"'soft_break'",
"=>",
"\"\\n\"",
",",
"]",
",",
"'html_input'",
"=>",
"Environment",
"::",
"HTML_INPUT_ESCAPE",
",",
"'allow_unsafe_links'",
"=>",
"true",
",",
"]",
")",
";",
"$",
"environment",
"->",
"addBlockRenderer",
"(",
"Document",
"::",
"class",
",",
"new",
"DocumentRenderer",
"(",
")",
")",
"->",
"addBlockRenderer",
"(",
"Paragraph",
"::",
"class",
",",
"new",
"ParagraphRenderer",
"(",
")",
")",
"->",
"addInlineRenderer",
"(",
"Text",
"::",
"class",
",",
"new",
"TextRenderer",
"(",
")",
")",
"->",
"addInlineRenderer",
"(",
"Link",
"::",
"class",
",",
"new",
"LinkRenderer",
"(",
")",
")",
"->",
"addInlineParser",
"(",
"new",
"AutolinkParser",
"(",
")",
")",
";",
"$",
"environment",
"->",
"addExtension",
"(",
"new",
"CensusTableExtension",
"(",
")",
")",
";",
"$",
"environment",
"->",
"addExtension",
"(",
"new",
"XrefExtension",
"(",
"$",
"tree",
")",
")",
";",
"$",
"converter",
"=",
"new",
"Converter",
"(",
"new",
"DocParser",
"(",
"$",
"environment",
")",
",",
"new",
"HtmlRenderer",
"(",
"$",
"environment",
")",
")",
";",
"try",
"{",
"return",
"$",
"converter",
"->",
"convertToHtml",
"(",
"$",
"text",
")",
";",
"}",
"catch",
"(",
"Throwable",
"$",
"ex",
")",
"{",
"// See issue #1824",
"return",
"$",
"text",
";",
"}",
"}"
] | Format a block of text, expanding URLs and XREFs.
@param string $text
@param Tree $tree
@return string | [
"Format",
"a",
"block",
"of",
"text",
"expanding",
"URLs",
"and",
"XREFs",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Filter.php#L76-L111 | train |
fisharebest/webtrees | app/Filter.php | Filter.markdown | public static function markdown(string $text, Tree $tree): string
{
$environment = Environment::createCommonMarkEnvironment();
$environment->mergeConfig(['html_input' => 'escape']);
$environment->addExtension(new TableExtension());
$environment->addExtension(new CensusTableExtension());
$environment->addExtension(new XrefExtension($tree));
$converter = new Converter(new DocParser($environment), new HtmlRenderer($environment));
try {
return $converter->convertToHtml($text);
} catch (Throwable $ex) {
// See issue #1824
return $text;
}
} | php | public static function markdown(string $text, Tree $tree): string
{
$environment = Environment::createCommonMarkEnvironment();
$environment->mergeConfig(['html_input' => 'escape']);
$environment->addExtension(new TableExtension());
$environment->addExtension(new CensusTableExtension());
$environment->addExtension(new XrefExtension($tree));
$converter = new Converter(new DocParser($environment), new HtmlRenderer($environment));
try {
return $converter->convertToHtml($text);
} catch (Throwable $ex) {
// See issue #1824
return $text;
}
} | [
"public",
"static",
"function",
"markdown",
"(",
"string",
"$",
"text",
",",
"Tree",
"$",
"tree",
")",
":",
"string",
"{",
"$",
"environment",
"=",
"Environment",
"::",
"createCommonMarkEnvironment",
"(",
")",
";",
"$",
"environment",
"->",
"mergeConfig",
"(",
"[",
"'html_input'",
"=>",
"'escape'",
"]",
")",
";",
"$",
"environment",
"->",
"addExtension",
"(",
"new",
"TableExtension",
"(",
")",
")",
";",
"$",
"environment",
"->",
"addExtension",
"(",
"new",
"CensusTableExtension",
"(",
")",
")",
";",
"$",
"environment",
"->",
"addExtension",
"(",
"new",
"XrefExtension",
"(",
"$",
"tree",
")",
")",
";",
"$",
"converter",
"=",
"new",
"Converter",
"(",
"new",
"DocParser",
"(",
"$",
"environment",
")",
",",
"new",
"HtmlRenderer",
"(",
"$",
"environment",
")",
")",
";",
"try",
"{",
"return",
"$",
"converter",
"->",
"convertToHtml",
"(",
"$",
"text",
")",
";",
"}",
"catch",
"(",
"Throwable",
"$",
"ex",
")",
"{",
"// See issue #1824",
"return",
"$",
"text",
";",
"}",
"}"
] | Format a block of text, using "Markdown".
@param string $text
@param Tree $tree
@return string | [
"Format",
"a",
"block",
"of",
"text",
"using",
"Markdown",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Filter.php#L121-L137 | train |
fisharebest/webtrees | app/Report/ReportBaseFootnote.php | ReportBaseFootnote.addText | public function addText(string $t)
{
$t = trim($t, "\r\n\t");
$t = str_replace([
'<br>',
' ',
], [
"\n",
' ',
], $t);
$t = strip_tags($t);
$t = htmlspecialchars_decode($t);
$this->text .= $t;
} | php | public function addText(string $t)
{
$t = trim($t, "\r\n\t");
$t = str_replace([
'<br>',
' ',
], [
"\n",
' ',
], $t);
$t = strip_tags($t);
$t = htmlspecialchars_decode($t);
$this->text .= $t;
} | [
"public",
"function",
"addText",
"(",
"string",
"$",
"t",
")",
"{",
"$",
"t",
"=",
"trim",
"(",
"$",
"t",
",",
"\"\\r\\n\\t\"",
")",
";",
"$",
"t",
"=",
"str_replace",
"(",
"[",
"'<br>'",
",",
"' '",
",",
"]",
",",
"[",
"\"\\n\"",
",",
"' '",
",",
"]",
",",
"$",
"t",
")",
";",
"$",
"t",
"=",
"strip_tags",
"(",
"$",
"t",
")",
";",
"$",
"t",
"=",
"htmlspecialchars_decode",
"(",
"$",
"t",
")",
";",
"$",
"this",
"->",
"text",
".=",
"$",
"t",
";",
"}"
] | Add text.
@param string $t
@return void | [
"Add",
"text",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Report/ReportBaseFootnote.php#L85-L98 | train |
fisharebest/webtrees | app/Services/ModuleService.php | ModuleService.findByInterface | public function findByInterface(string $interface, $include_disabled = false, $sort = false): Collection
{
$modules = $this->all($include_disabled)
->filter($this->interfaceFilter($interface));
switch ($interface) {
case ModuleFooterInterface::class:
return $modules->sort($this->footerSorter());
case ModuleMenuInterface::class:
return $modules->sort($this->menuSorter());
case ModuleSidebarInterface::class:
return $modules->sort($this->sidebarSorter());
case ModuleTabInterface::class:
return $modules->sort($this->tabSorter());
default:
if ($sort) {
return $modules->sort($this->moduleSorter());
}
return $modules;
}
} | php | public function findByInterface(string $interface, $include_disabled = false, $sort = false): Collection
{
$modules = $this->all($include_disabled)
->filter($this->interfaceFilter($interface));
switch ($interface) {
case ModuleFooterInterface::class:
return $modules->sort($this->footerSorter());
case ModuleMenuInterface::class:
return $modules->sort($this->menuSorter());
case ModuleSidebarInterface::class:
return $modules->sort($this->sidebarSorter());
case ModuleTabInterface::class:
return $modules->sort($this->tabSorter());
default:
if ($sort) {
return $modules->sort($this->moduleSorter());
}
return $modules;
}
} | [
"public",
"function",
"findByInterface",
"(",
"string",
"$",
"interface",
",",
"$",
"include_disabled",
"=",
"false",
",",
"$",
"sort",
"=",
"false",
")",
":",
"Collection",
"{",
"$",
"modules",
"=",
"$",
"this",
"->",
"all",
"(",
"$",
"include_disabled",
")",
"->",
"filter",
"(",
"$",
"this",
"->",
"interfaceFilter",
"(",
"$",
"interface",
")",
")",
";",
"switch",
"(",
"$",
"interface",
")",
"{",
"case",
"ModuleFooterInterface",
"::",
"class",
":",
"return",
"$",
"modules",
"->",
"sort",
"(",
"$",
"this",
"->",
"footerSorter",
"(",
")",
")",
";",
"case",
"ModuleMenuInterface",
"::",
"class",
":",
"return",
"$",
"modules",
"->",
"sort",
"(",
"$",
"this",
"->",
"menuSorter",
"(",
")",
")",
";",
"case",
"ModuleSidebarInterface",
"::",
"class",
":",
"return",
"$",
"modules",
"->",
"sort",
"(",
"$",
"this",
"->",
"sidebarSorter",
"(",
")",
")",
";",
"case",
"ModuleTabInterface",
"::",
"class",
":",
"return",
"$",
"modules",
"->",
"sort",
"(",
"$",
"this",
"->",
"tabSorter",
"(",
")",
")",
";",
"default",
":",
"if",
"(",
"$",
"sort",
")",
"{",
"return",
"$",
"modules",
"->",
"sort",
"(",
"$",
"this",
"->",
"moduleSorter",
"(",
")",
")",
";",
"}",
"return",
"$",
"modules",
";",
"}",
"}"
] | All modules which provide a specific function.
@param string $interface
@param bool $include_disabled
@param bool $sort
@return Collection
@return ModuleInterface[] | [
"All",
"modules",
"which",
"provide",
"a",
"specific",
"function",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Services/ModuleService.php#L448-L473 | train |
fisharebest/webtrees | app/Services/ModuleService.php | ModuleService.all | public function all(bool $include_disabled = false): Collection
{
return app('cache.array')->rememberForever('all_modules', function (): Collection {
// Modules have a default status, order etc.
// We can override these from database settings.
$module_info = DB::table('module')
->get()
->mapWithKeys(static function (stdClass $row): array {
return [$row->module_name => $row];
});
return $this->coreModules()
->merge($this->customModules())
->map(static function (ModuleInterface $module) use ($module_info): ModuleInterface {
$info = $module_info->get($module->name());
if ($info instanceof stdClass) {
$module->setEnabled($info->status === 'enabled');
if ($module instanceof ModuleFooterInterface && $info->footer_order !== null) {
$module->setFooterOrder((int) $info->footer_order);
}
if ($module instanceof ModuleMenuInterface && $info->menu_order !== null) {
$module->setMenuOrder((int) $info->menu_order);
}
if ($module instanceof ModuleSidebarInterface && $info->sidebar_order !== null) {
$module->setSidebarOrder((int) $info->sidebar_order);
}
if ($module instanceof ModuleTabInterface && $info->tab_order !== null) {
$module->setTabOrder((int) $info->tab_order);
}
} else {
$module->setEnabled($module->isEnabledByDefault());
DB::table('module')->insert([
'module_name' => $module->name(),
'status' => $module->isEnabled() ? 'enabled' : 'disabled',
]);
}
return $module;
});
})->filter($this->enabledFilter($include_disabled));
} | php | public function all(bool $include_disabled = false): Collection
{
return app('cache.array')->rememberForever('all_modules', function (): Collection {
// Modules have a default status, order etc.
// We can override these from database settings.
$module_info = DB::table('module')
->get()
->mapWithKeys(static function (stdClass $row): array {
return [$row->module_name => $row];
});
return $this->coreModules()
->merge($this->customModules())
->map(static function (ModuleInterface $module) use ($module_info): ModuleInterface {
$info = $module_info->get($module->name());
if ($info instanceof stdClass) {
$module->setEnabled($info->status === 'enabled');
if ($module instanceof ModuleFooterInterface && $info->footer_order !== null) {
$module->setFooterOrder((int) $info->footer_order);
}
if ($module instanceof ModuleMenuInterface && $info->menu_order !== null) {
$module->setMenuOrder((int) $info->menu_order);
}
if ($module instanceof ModuleSidebarInterface && $info->sidebar_order !== null) {
$module->setSidebarOrder((int) $info->sidebar_order);
}
if ($module instanceof ModuleTabInterface && $info->tab_order !== null) {
$module->setTabOrder((int) $info->tab_order);
}
} else {
$module->setEnabled($module->isEnabledByDefault());
DB::table('module')->insert([
'module_name' => $module->name(),
'status' => $module->isEnabled() ? 'enabled' : 'disabled',
]);
}
return $module;
});
})->filter($this->enabledFilter($include_disabled));
} | [
"public",
"function",
"all",
"(",
"bool",
"$",
"include_disabled",
"=",
"false",
")",
":",
"Collection",
"{",
"return",
"app",
"(",
"'cache.array'",
")",
"->",
"rememberForever",
"(",
"'all_modules'",
",",
"function",
"(",
")",
":",
"Collection",
"{",
"// Modules have a default status, order etc.",
"// We can override these from database settings.",
"$",
"module_info",
"=",
"DB",
"::",
"table",
"(",
"'module'",
")",
"->",
"get",
"(",
")",
"->",
"mapWithKeys",
"(",
"static",
"function",
"(",
"stdClass",
"$",
"row",
")",
":",
"array",
"{",
"return",
"[",
"$",
"row",
"->",
"module_name",
"=>",
"$",
"row",
"]",
";",
"}",
")",
";",
"return",
"$",
"this",
"->",
"coreModules",
"(",
")",
"->",
"merge",
"(",
"$",
"this",
"->",
"customModules",
"(",
")",
")",
"->",
"map",
"(",
"static",
"function",
"(",
"ModuleInterface",
"$",
"module",
")",
"use",
"(",
"$",
"module_info",
")",
":",
"ModuleInterface",
"{",
"$",
"info",
"=",
"$",
"module_info",
"->",
"get",
"(",
"$",
"module",
"->",
"name",
"(",
")",
")",
";",
"if",
"(",
"$",
"info",
"instanceof",
"stdClass",
")",
"{",
"$",
"module",
"->",
"setEnabled",
"(",
"$",
"info",
"->",
"status",
"===",
"'enabled'",
")",
";",
"if",
"(",
"$",
"module",
"instanceof",
"ModuleFooterInterface",
"&&",
"$",
"info",
"->",
"footer_order",
"!==",
"null",
")",
"{",
"$",
"module",
"->",
"setFooterOrder",
"(",
"(",
"int",
")",
"$",
"info",
"->",
"footer_order",
")",
";",
"}",
"if",
"(",
"$",
"module",
"instanceof",
"ModuleMenuInterface",
"&&",
"$",
"info",
"->",
"menu_order",
"!==",
"null",
")",
"{",
"$",
"module",
"->",
"setMenuOrder",
"(",
"(",
"int",
")",
"$",
"info",
"->",
"menu_order",
")",
";",
"}",
"if",
"(",
"$",
"module",
"instanceof",
"ModuleSidebarInterface",
"&&",
"$",
"info",
"->",
"sidebar_order",
"!==",
"null",
")",
"{",
"$",
"module",
"->",
"setSidebarOrder",
"(",
"(",
"int",
")",
"$",
"info",
"->",
"sidebar_order",
")",
";",
"}",
"if",
"(",
"$",
"module",
"instanceof",
"ModuleTabInterface",
"&&",
"$",
"info",
"->",
"tab_order",
"!==",
"null",
")",
"{",
"$",
"module",
"->",
"setTabOrder",
"(",
"(",
"int",
")",
"$",
"info",
"->",
"tab_order",
")",
";",
"}",
"}",
"else",
"{",
"$",
"module",
"->",
"setEnabled",
"(",
"$",
"module",
"->",
"isEnabledByDefault",
"(",
")",
")",
";",
"DB",
"::",
"table",
"(",
"'module'",
")",
"->",
"insert",
"(",
"[",
"'module_name'",
"=>",
"$",
"module",
"->",
"name",
"(",
")",
",",
"'status'",
"=>",
"$",
"module",
"->",
"isEnabled",
"(",
")",
"?",
"'enabled'",
":",
"'disabled'",
",",
"]",
")",
";",
"}",
"return",
"$",
"module",
";",
"}",
")",
";",
"}",
")",
"->",
"filter",
"(",
"$",
"this",
"->",
"enabledFilter",
"(",
"$",
"include_disabled",
")",
")",
";",
"}"
] | All modules.
@param bool $include_disabled
@return Collection
@return ModuleInterface[] | [
"All",
"modules",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Services/ModuleService.php#L483-L529 | train |
fisharebest/webtrees | app/Services/ModuleService.php | ModuleService.coreModules | private function coreModules(): Collection
{
return Collection::make(self::CORE_MODULES)
->map(static function (string $class, string $name): ModuleInterface {
$module = app($class);
$module->setName($name);
return $module;
});
} | php | private function coreModules(): Collection
{
return Collection::make(self::CORE_MODULES)
->map(static function (string $class, string $name): ModuleInterface {
$module = app($class);
$module->setName($name);
return $module;
});
} | [
"private",
"function",
"coreModules",
"(",
")",
":",
"Collection",
"{",
"return",
"Collection",
"::",
"make",
"(",
"self",
"::",
"CORE_MODULES",
")",
"->",
"map",
"(",
"static",
"function",
"(",
"string",
"$",
"class",
",",
"string",
"$",
"name",
")",
":",
"ModuleInterface",
"{",
"$",
"module",
"=",
"app",
"(",
"$",
"class",
")",
";",
"$",
"module",
"->",
"setName",
"(",
"$",
"name",
")",
";",
"return",
"$",
"module",
";",
"}",
")",
";",
"}"
] | All core modules in the system.
@return Collection | [
"All",
"core",
"modules",
"in",
"the",
"system",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Services/ModuleService.php#L536-L546 | train |
fisharebest/webtrees | app/Services/ModuleService.php | ModuleService.setupLanguages | public function setupLanguages(): Collection
{
return $this->coreModules()
->filter(static function (ModuleInterface $module) {
return $module instanceof ModuleLanguageInterface && $module->isEnabledByDefault();
})
->sort(static function (ModuleLanguageInterface $x, ModuleLanguageInterface $y) {
return $x->locale()->endonymSortable() <=> $y->locale()->endonymSortable();
});
} | php | public function setupLanguages(): Collection
{
return $this->coreModules()
->filter(static function (ModuleInterface $module) {
return $module instanceof ModuleLanguageInterface && $module->isEnabledByDefault();
})
->sort(static function (ModuleLanguageInterface $x, ModuleLanguageInterface $y) {
return $x->locale()->endonymSortable() <=> $y->locale()->endonymSortable();
});
} | [
"public",
"function",
"setupLanguages",
"(",
")",
":",
"Collection",
"{",
"return",
"$",
"this",
"->",
"coreModules",
"(",
")",
"->",
"filter",
"(",
"static",
"function",
"(",
"ModuleInterface",
"$",
"module",
")",
"{",
"return",
"$",
"module",
"instanceof",
"ModuleLanguageInterface",
"&&",
"$",
"module",
"->",
"isEnabledByDefault",
"(",
")",
";",
"}",
")",
"->",
"sort",
"(",
"static",
"function",
"(",
"ModuleLanguageInterface",
"$",
"x",
",",
"ModuleLanguageInterface",
"$",
"y",
")",
"{",
"return",
"$",
"x",
"->",
"locale",
"(",
")",
"->",
"endonymSortable",
"(",
")",
"<=>",
"$",
"y",
"->",
"locale",
"(",
")",
"->",
"endonymSortable",
"(",
")",
";",
"}",
")",
";",
"}"
] | During setup, we'll need access to some languages.
@return Collection | [
"During",
"setup",
"we",
"ll",
"need",
"access",
"to",
"some",
"languages",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Services/ModuleService.php#L596-L605 | train |
fisharebest/webtrees | app/Services/ModuleService.php | ModuleService.footerSorter | private function footerSorter(): Closure
{
return static function (ModuleFooterInterface $x, ModuleFooterInterface $y): int {
return $x->getFooterOrder() <=> $y->getFooterOrder();
};
} | php | private function footerSorter(): Closure
{
return static function (ModuleFooterInterface $x, ModuleFooterInterface $y): int {
return $x->getFooterOrder() <=> $y->getFooterOrder();
};
} | [
"private",
"function",
"footerSorter",
"(",
")",
":",
"Closure",
"{",
"return",
"static",
"function",
"(",
"ModuleFooterInterface",
"$",
"x",
",",
"ModuleFooterInterface",
"$",
"y",
")",
":",
"int",
"{",
"return",
"$",
"x",
"->",
"getFooterOrder",
"(",
")",
"<=>",
"$",
"y",
"->",
"getFooterOrder",
"(",
")",
";",
"}",
";",
"}"
] | A function to sort footers
@return Closure | [
"A",
"function",
"to",
"sort",
"footers"
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Services/ModuleService.php#L652-L657 | train |
fisharebest/webtrees | app/Services/ModuleService.php | ModuleService.moduleSorter | private function moduleSorter(): Closure
{
return static function (ModuleInterface $x, ModuleInterface $y): int {
$title1 = $x instanceof ModuleLanguageInterface ? $x->locale()->endonymSortable() : $x->title();
$title2 = $y instanceof ModuleLanguageInterface ? $y->locale()->endonymSortable() : $y->title();
return I18N::strcasecmp($title1, $title2);
};
} | php | private function moduleSorter(): Closure
{
return static function (ModuleInterface $x, ModuleInterface $y): int {
$title1 = $x instanceof ModuleLanguageInterface ? $x->locale()->endonymSortable() : $x->title();
$title2 = $y instanceof ModuleLanguageInterface ? $y->locale()->endonymSortable() : $y->title();
return I18N::strcasecmp($title1, $title2);
};
} | [
"private",
"function",
"moduleSorter",
"(",
")",
":",
"Closure",
"{",
"return",
"static",
"function",
"(",
"ModuleInterface",
"$",
"x",
",",
"ModuleInterface",
"$",
"y",
")",
":",
"int",
"{",
"$",
"title1",
"=",
"$",
"x",
"instanceof",
"ModuleLanguageInterface",
"?",
"$",
"x",
"->",
"locale",
"(",
")",
"->",
"endonymSortable",
"(",
")",
":",
"$",
"x",
"->",
"title",
"(",
")",
";",
"$",
"title2",
"=",
"$",
"y",
"instanceof",
"ModuleLanguageInterface",
"?",
"$",
"y",
"->",
"locale",
"(",
")",
"->",
"endonymSortable",
"(",
")",
":",
"$",
"y",
"->",
"title",
"(",
")",
";",
"return",
"I18N",
"::",
"strcasecmp",
"(",
"$",
"title1",
",",
"$",
"title2",
")",
";",
"}",
";",
"}"
] | A function to sort modules by name.
Languages have a "sortable" name, so that "British English" sorts as "English, British".
This provides a more natural order in the language menu.
@return Closure | [
"A",
"function",
"to",
"sort",
"modules",
"by",
"name",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Services/ModuleService.php#L703-L711 | train |
fisharebest/webtrees | app/Services/ModuleService.php | ModuleService.findByName | public function findByName(string $module_name, bool $include_disabled = false): ?ModuleInterface
{
return $this->all($include_disabled)
->first(static function (ModuleInterface $module) use ($module_name): bool {
return $module->name() === $module_name;
});
} | php | public function findByName(string $module_name, bool $include_disabled = false): ?ModuleInterface
{
return $this->all($include_disabled)
->first(static function (ModuleInterface $module) use ($module_name): bool {
return $module->name() === $module_name;
});
} | [
"public",
"function",
"findByName",
"(",
"string",
"$",
"module_name",
",",
"bool",
"$",
"include_disabled",
"=",
"false",
")",
":",
"?",
"ModuleInterface",
"{",
"return",
"$",
"this",
"->",
"all",
"(",
"$",
"include_disabled",
")",
"->",
"first",
"(",
"static",
"function",
"(",
"ModuleInterface",
"$",
"module",
")",
"use",
"(",
"$",
"module_name",
")",
":",
"bool",
"{",
"return",
"$",
"module",
"->",
"name",
"(",
")",
"===",
"$",
"module_name",
";",
"}",
")",
";",
"}"
] | Find a specified module, if it is currently active.
@param string $module_name
@param bool $include_disabled
@return ModuleInterface|null | [
"Find",
"a",
"specified",
"module",
"if",
"it",
"is",
"currently",
"active",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Services/ModuleService.php#L721-L727 | train |
fisharebest/webtrees | app/Services/ModuleService.php | ModuleService.otherModules | public function otherModules(bool $include_disabled = false): Collection
{
return $this->findByInterface(ModuleInterface::class, $include_disabled, true)
->filter(static function (ModuleInterface $module): bool {
foreach (self::COMPONENTS as $interface) {
if ($module instanceof $interface) {
return false;
}
}
return true;
});
} | php | public function otherModules(bool $include_disabled = false): Collection
{
return $this->findByInterface(ModuleInterface::class, $include_disabled, true)
->filter(static function (ModuleInterface $module): bool {
foreach (self::COMPONENTS as $interface) {
if ($module instanceof $interface) {
return false;
}
}
return true;
});
} | [
"public",
"function",
"otherModules",
"(",
"bool",
"$",
"include_disabled",
"=",
"false",
")",
":",
"Collection",
"{",
"return",
"$",
"this",
"->",
"findByInterface",
"(",
"ModuleInterface",
"::",
"class",
",",
"$",
"include_disabled",
",",
"true",
")",
"->",
"filter",
"(",
"static",
"function",
"(",
"ModuleInterface",
"$",
"module",
")",
":",
"bool",
"{",
"foreach",
"(",
"self",
"::",
"COMPONENTS",
"as",
"$",
"interface",
")",
"{",
"if",
"(",
"$",
"module",
"instanceof",
"$",
"interface",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}",
")",
";",
"}"
] | Configuration settings are available through the various "module component" pages.
For modules that do not provide a component, we need to list them separately.
@param bool $include_disabled
@return Collection
@return ModuleConfigInterface[] | [
"Configuration",
"settings",
"are",
"available",
"through",
"the",
"various",
"module",
"component",
"pages",
".",
"For",
"modules",
"that",
"do",
"not",
"provide",
"a",
"component",
"we",
"need",
"to",
"list",
"them",
"separately",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Services/ModuleService.php#L738-L750 | train |
fisharebest/webtrees | app/Services/ModuleService.php | ModuleService.deletedModules | public function deletedModules(): Collection
{
$database_modules = DB::table('module')->pluck('module_name');
$disk_modules = $this->all(true)
->map(static function (ModuleInterface $module): string {
return $module->name();
});
return $database_modules->diff($disk_modules);
} | php | public function deletedModules(): Collection
{
$database_modules = DB::table('module')->pluck('module_name');
$disk_modules = $this->all(true)
->map(static function (ModuleInterface $module): string {
return $module->name();
});
return $database_modules->diff($disk_modules);
} | [
"public",
"function",
"deletedModules",
"(",
")",
":",
"Collection",
"{",
"$",
"database_modules",
"=",
"DB",
"::",
"table",
"(",
"'module'",
")",
"->",
"pluck",
"(",
"'module_name'",
")",
";",
"$",
"disk_modules",
"=",
"$",
"this",
"->",
"all",
"(",
"true",
")",
"->",
"map",
"(",
"static",
"function",
"(",
"ModuleInterface",
"$",
"module",
")",
":",
"string",
"{",
"return",
"$",
"module",
"->",
"name",
"(",
")",
";",
"}",
")",
";",
"return",
"$",
"database_modules",
"->",
"diff",
"(",
"$",
"disk_modules",
")",
";",
"}"
] | Generate a list of module names which exist in the database but not on disk.
@return Collection
@return string[] | [
"Generate",
"a",
"list",
"of",
"module",
"names",
"which",
"exist",
"in",
"the",
"database",
"but",
"not",
"on",
"disk",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Services/ModuleService.php#L758-L768 | train |
fisharebest/webtrees | app/Session.php | Session.regenerate | public static function regenerate(bool $destroy = false): void
{
if ($destroy) {
self::clear();
}
if (session_status() === PHP_SESSION_ACTIVE) {
session_regenerate_id($destroy);
}
} | php | public static function regenerate(bool $destroy = false): void
{
if ($destroy) {
self::clear();
}
if (session_status() === PHP_SESSION_ACTIVE) {
session_regenerate_id($destroy);
}
} | [
"public",
"static",
"function",
"regenerate",
"(",
"bool",
"$",
"destroy",
"=",
"false",
")",
":",
"void",
"{",
"if",
"(",
"$",
"destroy",
")",
"{",
"self",
"::",
"clear",
"(",
")",
";",
"}",
"if",
"(",
"session_status",
"(",
")",
"===",
"PHP_SESSION_ACTIVE",
")",
"{",
"session_regenerate_id",
"(",
"$",
"destroy",
")",
";",
"}",
"}"
] | After any change in authentication level, we should use a new session ID.
@param bool $destroy
@return void | [
"After",
"any",
"change",
"in",
"authentication",
"level",
"we",
"should",
"use",
"a",
"new",
"session",
"ID",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Session.php#L94-L103 | train |
fisharebest/webtrees | app/Session.php | Session.getCsrfToken | public static function getCsrfToken(): string
{
if (!self::has('CSRF_TOKEN')) {
self::put('CSRF_TOKEN', Str::random(32));
}
return self::get('CSRF_TOKEN');
} | php | public static function getCsrfToken(): string
{
if (!self::has('CSRF_TOKEN')) {
self::put('CSRF_TOKEN', Str::random(32));
}
return self::get('CSRF_TOKEN');
} | [
"public",
"static",
"function",
"getCsrfToken",
"(",
")",
":",
"string",
"{",
"if",
"(",
"!",
"self",
"::",
"has",
"(",
"'CSRF_TOKEN'",
")",
")",
"{",
"self",
"::",
"put",
"(",
"'CSRF_TOKEN'",
",",
"Str",
"::",
"random",
"(",
"32",
")",
")",
";",
"}",
"return",
"self",
"::",
"get",
"(",
"'CSRF_TOKEN'",
")",
";",
"}"
] | Cross-Site Request Forgery tokens - ensure that the user is submitting
a form that was generated by the current session.
@return string | [
"Cross",
"-",
"Site",
"Request",
"Forgery",
"tokens",
"-",
"ensure",
"that",
"the",
"user",
"is",
"submitting",
"a",
"form",
"that",
"was",
"generated",
"by",
"the",
"current",
"session",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Session.php#L146-L153 | train |
fisharebest/webtrees | app/Http/Controllers/AdminTreesController.php | AdminTreesController.checkLinkMessage | private function checkLinkMessage(Tree $tree, $type1, $xref1, $type2, $xref2): string
{
/* I18N: The placeholders are GEDCOM XREFs and tags. e.g. “INDI I123 contains a FAMC link to F234.” */
return I18N::translate(
'%1$s %2$s has a %3$s link to %4$s.',
$this->formatType($type1),
$this->checkLink($tree, $xref1),
$this->formatType($type2),
$this->checkLink($tree, $xref2)
);
} | php | private function checkLinkMessage(Tree $tree, $type1, $xref1, $type2, $xref2): string
{
/* I18N: The placeholders are GEDCOM XREFs and tags. e.g. “INDI I123 contains a FAMC link to F234.” */
return I18N::translate(
'%1$s %2$s has a %3$s link to %4$s.',
$this->formatType($type1),
$this->checkLink($tree, $xref1),
$this->formatType($type2),
$this->checkLink($tree, $xref2)
);
} | [
"private",
"function",
"checkLinkMessage",
"(",
"Tree",
"$",
"tree",
",",
"$",
"type1",
",",
"$",
"xref1",
",",
"$",
"type2",
",",
"$",
"xref2",
")",
":",
"string",
"{",
"/* I18N: The placeholders are GEDCOM XREFs and tags. e.g. “INDI I123 contains a FAMC link to F234.” */",
"return",
"I18N",
"::",
"translate",
"(",
"'%1$s %2$s has a %3$s link to %4$s.'",
",",
"$",
"this",
"->",
"formatType",
"(",
"$",
"type1",
")",
",",
"$",
"this",
"->",
"checkLink",
"(",
"$",
"tree",
",",
"$",
"xref1",
")",
",",
"$",
"this",
"->",
"formatType",
"(",
"$",
"type2",
")",
",",
"$",
"this",
"->",
"checkLink",
"(",
"$",
"tree",
",",
"$",
"xref2",
")",
")",
";",
"}"
] | Create a message linking one record to another.
@param Tree $tree
@param string $type1
@param string $xref1
@param string $type2
@param string $xref2
@return string | [
"Create",
"a",
"message",
"linking",
"one",
"record",
"to",
"another",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Http/Controllers/AdminTreesController.php#L315-L325 | train |
fisharebest/webtrees | app/Http/Controllers/AdminTreesController.php | AdminTreesController.checkLink | private function checkLink(Tree $tree, string $xref): string
{
return '<b><a href="' . e(route('record', [
'xref' => $xref,
'ged' => $tree->name(),
])) . '">' . $xref . '</a></b>';
} | php | private function checkLink(Tree $tree, string $xref): string
{
return '<b><a href="' . e(route('record', [
'xref' => $xref,
'ged' => $tree->name(),
])) . '">' . $xref . '</a></b>';
} | [
"private",
"function",
"checkLink",
"(",
"Tree",
"$",
"tree",
",",
"string",
"$",
"xref",
")",
":",
"string",
"{",
"return",
"'<b><a href=\"'",
".",
"e",
"(",
"route",
"(",
"'record'",
",",
"[",
"'xref'",
"=>",
"$",
"xref",
",",
"'ged'",
"=>",
"$",
"tree",
"->",
"name",
"(",
")",
",",
"]",
")",
")",
".",
"'\">'",
".",
"$",
"xref",
".",
"'</a></b>'",
";",
"}"
] | Format a link to a record.
@param Tree $tree
@param string $xref
@return string | [
"Format",
"a",
"link",
"to",
"a",
"record",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Http/Controllers/AdminTreesController.php#L335-L341 | train |
fisharebest/webtrees | app/Http/Controllers/AdminTreesController.php | AdminTreesController.countCommonXrefs | private function countCommonXrefs(Tree $tree1, Tree $tree2): int
{
$subquery1 = DB::table('individuals')
->where('i_file', '=', $tree1->id())
->select(['i_id AS xref'])
->union(DB::table('families')
->where('f_file', '=', $tree1->id())
->select(['f_id AS xref']))
->union(DB::table('sources')
->where('s_file', '=', $tree1->id())
->select(['s_id AS xref']))
->union(DB::table('media')
->where('m_file', '=', $tree1->id())
->select(['m_id AS xref']))
->union(DB::table('other')
->where('o_file', '=', $tree1->id())
->whereNotIn('o_type', ['HEAD', 'TRLR'])
->select(['o_id AS xref']));
$subquery2 = DB::table('change')
->where('gedcom_id', '=', $tree2->id())
->select(['xref AS other_xref'])
->union(DB::table('individuals')
->where('i_file', '=', $tree2->id())
->select(['i_id AS xref']))
->union(DB::table('families')
->where('f_file', '=', $tree2->id())
->select(['f_id AS xref']))
->union(DB::table('sources')
->where('s_file', '=', $tree2->id())
->select(['s_id AS xref']))
->union(DB::table('media')
->where('m_file', '=', $tree2->id())
->select(['m_id AS xref']))
->union(DB::table('other')
->where('o_file', '=', $tree2->id())
->whereNotIn('o_type', ['HEAD', 'TRLR'])
->select(['o_id AS xref']));
return DB::table(DB::raw('(' . $subquery1->toSql() . ') AS sub1'))
->mergeBindings($subquery1)
->joinSub($subquery2, 'sub2', 'other_xref', '=', 'xref')
->count();
} | php | private function countCommonXrefs(Tree $tree1, Tree $tree2): int
{
$subquery1 = DB::table('individuals')
->where('i_file', '=', $tree1->id())
->select(['i_id AS xref'])
->union(DB::table('families')
->where('f_file', '=', $tree1->id())
->select(['f_id AS xref']))
->union(DB::table('sources')
->where('s_file', '=', $tree1->id())
->select(['s_id AS xref']))
->union(DB::table('media')
->where('m_file', '=', $tree1->id())
->select(['m_id AS xref']))
->union(DB::table('other')
->where('o_file', '=', $tree1->id())
->whereNotIn('o_type', ['HEAD', 'TRLR'])
->select(['o_id AS xref']));
$subquery2 = DB::table('change')
->where('gedcom_id', '=', $tree2->id())
->select(['xref AS other_xref'])
->union(DB::table('individuals')
->where('i_file', '=', $tree2->id())
->select(['i_id AS xref']))
->union(DB::table('families')
->where('f_file', '=', $tree2->id())
->select(['f_id AS xref']))
->union(DB::table('sources')
->where('s_file', '=', $tree2->id())
->select(['s_id AS xref']))
->union(DB::table('media')
->where('m_file', '=', $tree2->id())
->select(['m_id AS xref']))
->union(DB::table('other')
->where('o_file', '=', $tree2->id())
->whereNotIn('o_type', ['HEAD', 'TRLR'])
->select(['o_id AS xref']));
return DB::table(DB::raw('(' . $subquery1->toSql() . ') AS sub1'))
->mergeBindings($subquery1)
->joinSub($subquery2, 'sub2', 'other_xref', '=', 'xref')
->count();
} | [
"private",
"function",
"countCommonXrefs",
"(",
"Tree",
"$",
"tree1",
",",
"Tree",
"$",
"tree2",
")",
":",
"int",
"{",
"$",
"subquery1",
"=",
"DB",
"::",
"table",
"(",
"'individuals'",
")",
"->",
"where",
"(",
"'i_file'",
",",
"'='",
",",
"$",
"tree1",
"->",
"id",
"(",
")",
")",
"->",
"select",
"(",
"[",
"'i_id AS xref'",
"]",
")",
"->",
"union",
"(",
"DB",
"::",
"table",
"(",
"'families'",
")",
"->",
"where",
"(",
"'f_file'",
",",
"'='",
",",
"$",
"tree1",
"->",
"id",
"(",
")",
")",
"->",
"select",
"(",
"[",
"'f_id AS xref'",
"]",
")",
")",
"->",
"union",
"(",
"DB",
"::",
"table",
"(",
"'sources'",
")",
"->",
"where",
"(",
"'s_file'",
",",
"'='",
",",
"$",
"tree1",
"->",
"id",
"(",
")",
")",
"->",
"select",
"(",
"[",
"'s_id AS xref'",
"]",
")",
")",
"->",
"union",
"(",
"DB",
"::",
"table",
"(",
"'media'",
")",
"->",
"where",
"(",
"'m_file'",
",",
"'='",
",",
"$",
"tree1",
"->",
"id",
"(",
")",
")",
"->",
"select",
"(",
"[",
"'m_id AS xref'",
"]",
")",
")",
"->",
"union",
"(",
"DB",
"::",
"table",
"(",
"'other'",
")",
"->",
"where",
"(",
"'o_file'",
",",
"'='",
",",
"$",
"tree1",
"->",
"id",
"(",
")",
")",
"->",
"whereNotIn",
"(",
"'o_type'",
",",
"[",
"'HEAD'",
",",
"'TRLR'",
"]",
")",
"->",
"select",
"(",
"[",
"'o_id AS xref'",
"]",
")",
")",
";",
"$",
"subquery2",
"=",
"DB",
"::",
"table",
"(",
"'change'",
")",
"->",
"where",
"(",
"'gedcom_id'",
",",
"'='",
",",
"$",
"tree2",
"->",
"id",
"(",
")",
")",
"->",
"select",
"(",
"[",
"'xref AS other_xref'",
"]",
")",
"->",
"union",
"(",
"DB",
"::",
"table",
"(",
"'individuals'",
")",
"->",
"where",
"(",
"'i_file'",
",",
"'='",
",",
"$",
"tree2",
"->",
"id",
"(",
")",
")",
"->",
"select",
"(",
"[",
"'i_id AS xref'",
"]",
")",
")",
"->",
"union",
"(",
"DB",
"::",
"table",
"(",
"'families'",
")",
"->",
"where",
"(",
"'f_file'",
",",
"'='",
",",
"$",
"tree2",
"->",
"id",
"(",
")",
")",
"->",
"select",
"(",
"[",
"'f_id AS xref'",
"]",
")",
")",
"->",
"union",
"(",
"DB",
"::",
"table",
"(",
"'sources'",
")",
"->",
"where",
"(",
"'s_file'",
",",
"'='",
",",
"$",
"tree2",
"->",
"id",
"(",
")",
")",
"->",
"select",
"(",
"[",
"'s_id AS xref'",
"]",
")",
")",
"->",
"union",
"(",
"DB",
"::",
"table",
"(",
"'media'",
")",
"->",
"where",
"(",
"'m_file'",
",",
"'='",
",",
"$",
"tree2",
"->",
"id",
"(",
")",
")",
"->",
"select",
"(",
"[",
"'m_id AS xref'",
"]",
")",
")",
"->",
"union",
"(",
"DB",
"::",
"table",
"(",
"'other'",
")",
"->",
"where",
"(",
"'o_file'",
",",
"'='",
",",
"$",
"tree2",
"->",
"id",
"(",
")",
")",
"->",
"whereNotIn",
"(",
"'o_type'",
",",
"[",
"'HEAD'",
",",
"'TRLR'",
"]",
")",
"->",
"select",
"(",
"[",
"'o_id AS xref'",
"]",
")",
")",
";",
"return",
"DB",
"::",
"table",
"(",
"DB",
"::",
"raw",
"(",
"'('",
".",
"$",
"subquery1",
"->",
"toSql",
"(",
")",
".",
"') AS sub1'",
")",
")",
"->",
"mergeBindings",
"(",
"$",
"subquery1",
")",
"->",
"joinSub",
"(",
"$",
"subquery2",
",",
"'sub2'",
",",
"'other_xref'",
",",
"'='",
",",
"'xref'",
")",
"->",
"count",
"(",
")",
";",
"}"
] | Count of XREFs used by two trees at the same time.
@param Tree $tree1
@param Tree $tree2
@return int | [
"Count",
"of",
"XREFs",
"used",
"by",
"two",
"trees",
"at",
"the",
"same",
"time",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Http/Controllers/AdminTreesController.php#L1927-L1970 | train |
fisharebest/webtrees | app/Http/Controllers/AdminTreesController.php | AdminTreesController.duplicateXrefs | private function duplicateXrefs(Tree $tree): array
{
$subquery1 = DB::table('individuals')
->where('i_file', '=', $tree->id())
->select(['i_id AS xref', DB::raw("'INDI' AS type")])
->union(DB::table('families')
->where('f_file', '=', $tree->id())
->select(['f_id AS xref', DB::raw("'FAM' AS type")]))
->union(DB::table('sources')
->where('s_file', '=', $tree->id())
->select(['s_id AS xref', DB::raw("'SOUR' AS type")]))
->union(DB::table('media')
->where('m_file', '=', $tree->id())
->select(['m_id AS xref', DB::raw("'OBJE' AS type")]))
->union(DB::table('other')
->where('o_file', '=', $tree->id())
->whereNotIn('o_type', ['HEAD', 'TRLR'])
->select(['o_id AS xref', 'o_type AS type']));
$subquery2 = DB::table('change')
->where('gedcom_id', '<>', $tree->id())
->select(['xref AS other_xref'])
->union(DB::table('individuals')
->where('i_file', '<>', $tree->id())
->select(['i_id AS xref']))
->union(DB::table('families')
->where('f_file', '<>', $tree->id())
->select(['f_id AS xref']))
->union(DB::table('sources')
->where('s_file', '<>', $tree->id())
->select(['s_id AS xref']))
->union(DB::table('media')
->where('m_file', '<>', $tree->id())
->select(['m_id AS xref']))
->union(DB::table('other')
->where('o_file', '<>', $tree->id())
->whereNotIn('o_type', ['HEAD', 'TRLR'])
->select(['o_id AS xref']));
return DB::table(DB::raw('(' . $subquery1->toSql() . ') AS sub1'))
->mergeBindings($subquery1)
->joinSub($subquery2, 'sub2', 'other_xref', '=', 'xref')
->pluck('type', 'xref')
->all();
} | php | private function duplicateXrefs(Tree $tree): array
{
$subquery1 = DB::table('individuals')
->where('i_file', '=', $tree->id())
->select(['i_id AS xref', DB::raw("'INDI' AS type")])
->union(DB::table('families')
->where('f_file', '=', $tree->id())
->select(['f_id AS xref', DB::raw("'FAM' AS type")]))
->union(DB::table('sources')
->where('s_file', '=', $tree->id())
->select(['s_id AS xref', DB::raw("'SOUR' AS type")]))
->union(DB::table('media')
->where('m_file', '=', $tree->id())
->select(['m_id AS xref', DB::raw("'OBJE' AS type")]))
->union(DB::table('other')
->where('o_file', '=', $tree->id())
->whereNotIn('o_type', ['HEAD', 'TRLR'])
->select(['o_id AS xref', 'o_type AS type']));
$subquery2 = DB::table('change')
->where('gedcom_id', '<>', $tree->id())
->select(['xref AS other_xref'])
->union(DB::table('individuals')
->where('i_file', '<>', $tree->id())
->select(['i_id AS xref']))
->union(DB::table('families')
->where('f_file', '<>', $tree->id())
->select(['f_id AS xref']))
->union(DB::table('sources')
->where('s_file', '<>', $tree->id())
->select(['s_id AS xref']))
->union(DB::table('media')
->where('m_file', '<>', $tree->id())
->select(['m_id AS xref']))
->union(DB::table('other')
->where('o_file', '<>', $tree->id())
->whereNotIn('o_type', ['HEAD', 'TRLR'])
->select(['o_id AS xref']));
return DB::table(DB::raw('(' . $subquery1->toSql() . ') AS sub1'))
->mergeBindings($subquery1)
->joinSub($subquery2, 'sub2', 'other_xref', '=', 'xref')
->pluck('type', 'xref')
->all();
} | [
"private",
"function",
"duplicateXrefs",
"(",
"Tree",
"$",
"tree",
")",
":",
"array",
"{",
"$",
"subquery1",
"=",
"DB",
"::",
"table",
"(",
"'individuals'",
")",
"->",
"where",
"(",
"'i_file'",
",",
"'='",
",",
"$",
"tree",
"->",
"id",
"(",
")",
")",
"->",
"select",
"(",
"[",
"'i_id AS xref'",
",",
"DB",
"::",
"raw",
"(",
"\"'INDI' AS type\"",
")",
"]",
")",
"->",
"union",
"(",
"DB",
"::",
"table",
"(",
"'families'",
")",
"->",
"where",
"(",
"'f_file'",
",",
"'='",
",",
"$",
"tree",
"->",
"id",
"(",
")",
")",
"->",
"select",
"(",
"[",
"'f_id AS xref'",
",",
"DB",
"::",
"raw",
"(",
"\"'FAM' AS type\"",
")",
"]",
")",
")",
"->",
"union",
"(",
"DB",
"::",
"table",
"(",
"'sources'",
")",
"->",
"where",
"(",
"'s_file'",
",",
"'='",
",",
"$",
"tree",
"->",
"id",
"(",
")",
")",
"->",
"select",
"(",
"[",
"'s_id AS xref'",
",",
"DB",
"::",
"raw",
"(",
"\"'SOUR' AS type\"",
")",
"]",
")",
")",
"->",
"union",
"(",
"DB",
"::",
"table",
"(",
"'media'",
")",
"->",
"where",
"(",
"'m_file'",
",",
"'='",
",",
"$",
"tree",
"->",
"id",
"(",
")",
")",
"->",
"select",
"(",
"[",
"'m_id AS xref'",
",",
"DB",
"::",
"raw",
"(",
"\"'OBJE' AS type\"",
")",
"]",
")",
")",
"->",
"union",
"(",
"DB",
"::",
"table",
"(",
"'other'",
")",
"->",
"where",
"(",
"'o_file'",
",",
"'='",
",",
"$",
"tree",
"->",
"id",
"(",
")",
")",
"->",
"whereNotIn",
"(",
"'o_type'",
",",
"[",
"'HEAD'",
",",
"'TRLR'",
"]",
")",
"->",
"select",
"(",
"[",
"'o_id AS xref'",
",",
"'o_type AS type'",
"]",
")",
")",
";",
"$",
"subquery2",
"=",
"DB",
"::",
"table",
"(",
"'change'",
")",
"->",
"where",
"(",
"'gedcom_id'",
",",
"'<>'",
",",
"$",
"tree",
"->",
"id",
"(",
")",
")",
"->",
"select",
"(",
"[",
"'xref AS other_xref'",
"]",
")",
"->",
"union",
"(",
"DB",
"::",
"table",
"(",
"'individuals'",
")",
"->",
"where",
"(",
"'i_file'",
",",
"'<>'",
",",
"$",
"tree",
"->",
"id",
"(",
")",
")",
"->",
"select",
"(",
"[",
"'i_id AS xref'",
"]",
")",
")",
"->",
"union",
"(",
"DB",
"::",
"table",
"(",
"'families'",
")",
"->",
"where",
"(",
"'f_file'",
",",
"'<>'",
",",
"$",
"tree",
"->",
"id",
"(",
")",
")",
"->",
"select",
"(",
"[",
"'f_id AS xref'",
"]",
")",
")",
"->",
"union",
"(",
"DB",
"::",
"table",
"(",
"'sources'",
")",
"->",
"where",
"(",
"'s_file'",
",",
"'<>'",
",",
"$",
"tree",
"->",
"id",
"(",
")",
")",
"->",
"select",
"(",
"[",
"'s_id AS xref'",
"]",
")",
")",
"->",
"union",
"(",
"DB",
"::",
"table",
"(",
"'media'",
")",
"->",
"where",
"(",
"'m_file'",
",",
"'<>'",
",",
"$",
"tree",
"->",
"id",
"(",
")",
")",
"->",
"select",
"(",
"[",
"'m_id AS xref'",
"]",
")",
")",
"->",
"union",
"(",
"DB",
"::",
"table",
"(",
"'other'",
")",
"->",
"where",
"(",
"'o_file'",
",",
"'<>'",
",",
"$",
"tree",
"->",
"id",
"(",
")",
")",
"->",
"whereNotIn",
"(",
"'o_type'",
",",
"[",
"'HEAD'",
",",
"'TRLR'",
"]",
")",
"->",
"select",
"(",
"[",
"'o_id AS xref'",
"]",
")",
")",
";",
"return",
"DB",
"::",
"table",
"(",
"DB",
"::",
"raw",
"(",
"'('",
".",
"$",
"subquery1",
"->",
"toSql",
"(",
")",
".",
"') AS sub1'",
")",
")",
"->",
"mergeBindings",
"(",
"$",
"subquery1",
")",
"->",
"joinSub",
"(",
"$",
"subquery2",
",",
"'sub2'",
",",
"'other_xref'",
",",
"'='",
",",
"'xref'",
")",
"->",
"pluck",
"(",
"'type'",
",",
"'xref'",
")",
"->",
"all",
"(",
")",
";",
"}"
] | Every XREF used by this tree and also used by some other tree
@param Tree $tree
@return string[] | [
"Every",
"XREF",
"used",
"by",
"this",
"tree",
"and",
"also",
"used",
"by",
"some",
"other",
"tree"
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Http/Controllers/AdminTreesController.php#L2065-L2109 | train |
fisharebest/webtrees | app/Http/Controllers/AdminTreesController.php | AdminTreesController.gedcomFiles | private function gedcomFiles(string $folder): array
{
$d = opendir($folder);
$files = [];
while (($f = readdir($d)) !== false) {
if (!is_dir(WT_DATA_DIR . $f) && is_readable(WT_DATA_DIR . $f)) {
$fp = fopen(WT_DATA_DIR . $f, 'rb');
$header = fread($fp, 64);
fclose($fp);
if (preg_match('/^(' . Gedcom::UTF8_BOM . ')?0 *HEAD/', $header)) {
$files[] = $f;
}
}
}
sort($files);
return $files;
} | php | private function gedcomFiles(string $folder): array
{
$d = opendir($folder);
$files = [];
while (($f = readdir($d)) !== false) {
if (!is_dir(WT_DATA_DIR . $f) && is_readable(WT_DATA_DIR . $f)) {
$fp = fopen(WT_DATA_DIR . $f, 'rb');
$header = fread($fp, 64);
fclose($fp);
if (preg_match('/^(' . Gedcom::UTF8_BOM . ')?0 *HEAD/', $header)) {
$files[] = $f;
}
}
}
sort($files);
return $files;
} | [
"private",
"function",
"gedcomFiles",
"(",
"string",
"$",
"folder",
")",
":",
"array",
"{",
"$",
"d",
"=",
"opendir",
"(",
"$",
"folder",
")",
";",
"$",
"files",
"=",
"[",
"]",
";",
"while",
"(",
"(",
"$",
"f",
"=",
"readdir",
"(",
"$",
"d",
")",
")",
"!==",
"false",
")",
"{",
"if",
"(",
"!",
"is_dir",
"(",
"WT_DATA_DIR",
".",
"$",
"f",
")",
"&&",
"is_readable",
"(",
"WT_DATA_DIR",
".",
"$",
"f",
")",
")",
"{",
"$",
"fp",
"=",
"fopen",
"(",
"WT_DATA_DIR",
".",
"$",
"f",
",",
"'rb'",
")",
";",
"$",
"header",
"=",
"fread",
"(",
"$",
"fp",
",",
"64",
")",
";",
"fclose",
"(",
"$",
"fp",
")",
";",
"if",
"(",
"preg_match",
"(",
"'/^('",
".",
"Gedcom",
"::",
"UTF8_BOM",
".",
"')?0 *HEAD/'",
",",
"$",
"header",
")",
")",
"{",
"$",
"files",
"[",
"]",
"=",
"$",
"f",
";",
"}",
"}",
"}",
"sort",
"(",
"$",
"files",
")",
";",
"return",
"$",
"files",
";",
"}"
] | Find a list of GEDCOM files in a folder
@param string $folder
@return array | [
"Find",
"a",
"list",
"of",
"GEDCOM",
"files",
"in",
"a",
"folder"
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Http/Controllers/AdminTreesController.php#L2118-L2135 | train |
fisharebest/webtrees | app/Http/Controllers/AdminTreesController.php | AdminTreesController.generateNewTreeName | private function generateNewTreeName(): string
{
$tree_name = 'tree';
$tree_number = 1;
$existing_trees = Tree::getNameList();
while (array_key_exists($tree_name . $tree_number, $existing_trees)) {
$tree_number++;
}
return $tree_name . $tree_number;
} | php | private function generateNewTreeName(): string
{
$tree_name = 'tree';
$tree_number = 1;
$existing_trees = Tree::getNameList();
while (array_key_exists($tree_name . $tree_number, $existing_trees)) {
$tree_number++;
}
return $tree_name . $tree_number;
} | [
"private",
"function",
"generateNewTreeName",
"(",
")",
":",
"string",
"{",
"$",
"tree_name",
"=",
"'tree'",
";",
"$",
"tree_number",
"=",
"1",
";",
"$",
"existing_trees",
"=",
"Tree",
"::",
"getNameList",
"(",
")",
";",
"while",
"(",
"array_key_exists",
"(",
"$",
"tree_name",
".",
"$",
"tree_number",
",",
"$",
"existing_trees",
")",
")",
"{",
"$",
"tree_number",
"++",
";",
"}",
"return",
"$",
"tree_name",
".",
"$",
"tree_number",
";",
"}"
] | Generate a unqiue name for new trees
@return string | [
"Generate",
"a",
"unqiue",
"name",
"for",
"new",
"trees"
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Http/Controllers/AdminTreesController.php#L2142-L2153 | train |
fisharebest/webtrees | app/Http/Controllers/HomePageController.php | HomePageController.treePageBlockUpdate | public function treePageBlockUpdate(ServerRequestInterface $request, Tree $tree, UserInterface $user): ResponseInterface
{
$block = $this->treeBlock($request, $tree, $user);
$block_id = (int) $request->get('block_id');
$block->saveBlockConfiguration($request, $block_id);
return redirect(route('tree-page', ['ged' => $tree->name()]));
} | php | public function treePageBlockUpdate(ServerRequestInterface $request, Tree $tree, UserInterface $user): ResponseInterface
{
$block = $this->treeBlock($request, $tree, $user);
$block_id = (int) $request->get('block_id');
$block->saveBlockConfiguration($request, $block_id);
return redirect(route('tree-page', ['ged' => $tree->name()]));
} | [
"public",
"function",
"treePageBlockUpdate",
"(",
"ServerRequestInterface",
"$",
"request",
",",
"Tree",
"$",
"tree",
",",
"UserInterface",
"$",
"user",
")",
":",
"ResponseInterface",
"{",
"$",
"block",
"=",
"$",
"this",
"->",
"treeBlock",
"(",
"$",
"request",
",",
"$",
"tree",
",",
"$",
"user",
")",
";",
"$",
"block_id",
"=",
"(",
"int",
")",
"$",
"request",
"->",
"get",
"(",
"'block_id'",
")",
";",
"$",
"block",
"->",
"saveBlockConfiguration",
"(",
"$",
"request",
",",
"$",
"block_id",
")",
";",
"return",
"redirect",
"(",
"route",
"(",
"'tree-page'",
",",
"[",
"'ged'",
"=>",
"$",
"tree",
"->",
"name",
"(",
")",
"]",
")",
")",
";",
"}"
] | Update block config options.
@param ServerRequestInterface $request
@param Tree $tree
@param UserInterface $user
@return ResponseInterface | [
"Update",
"block",
"config",
"options",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Http/Controllers/HomePageController.php#L137-L145 | train |
fisharebest/webtrees | app/Http/Controllers/HomePageController.php | HomePageController.treeBlock | private function treeBlock(ServerRequestInterface $request, Tree $tree, UserInterface $user): ModuleBlockInterface
{
$block_id = (int) $request->get('block_id');
$block = DB::table('block')
->where('block_id', '=', $block_id)
->where('gedcom_id', '=', $tree->id())
->whereNull('user_id')
->first();
if ($block === null) {
throw new NotFoundHttpException();
}
$module = $this->module_service->findByName($block->module_name);
if (!$module instanceof ModuleBlockInterface) {
throw new NotFoundHttpException();
}
if ($block->user_id !== $user->id() && !Auth::isAdmin()) {
throw new AccessDeniedHttpException();
}
return $module;
} | php | private function treeBlock(ServerRequestInterface $request, Tree $tree, UserInterface $user): ModuleBlockInterface
{
$block_id = (int) $request->get('block_id');
$block = DB::table('block')
->where('block_id', '=', $block_id)
->where('gedcom_id', '=', $tree->id())
->whereNull('user_id')
->first();
if ($block === null) {
throw new NotFoundHttpException();
}
$module = $this->module_service->findByName($block->module_name);
if (!$module instanceof ModuleBlockInterface) {
throw new NotFoundHttpException();
}
if ($block->user_id !== $user->id() && !Auth::isAdmin()) {
throw new AccessDeniedHttpException();
}
return $module;
} | [
"private",
"function",
"treeBlock",
"(",
"ServerRequestInterface",
"$",
"request",
",",
"Tree",
"$",
"tree",
",",
"UserInterface",
"$",
"user",
")",
":",
"ModuleBlockInterface",
"{",
"$",
"block_id",
"=",
"(",
"int",
")",
"$",
"request",
"->",
"get",
"(",
"'block_id'",
")",
";",
"$",
"block",
"=",
"DB",
"::",
"table",
"(",
"'block'",
")",
"->",
"where",
"(",
"'block_id'",
",",
"'='",
",",
"$",
"block_id",
")",
"->",
"where",
"(",
"'gedcom_id'",
",",
"'='",
",",
"$",
"tree",
"->",
"id",
"(",
")",
")",
"->",
"whereNull",
"(",
"'user_id'",
")",
"->",
"first",
"(",
")",
";",
"if",
"(",
"$",
"block",
"===",
"null",
")",
"{",
"throw",
"new",
"NotFoundHttpException",
"(",
")",
";",
"}",
"$",
"module",
"=",
"$",
"this",
"->",
"module_service",
"->",
"findByName",
"(",
"$",
"block",
"->",
"module_name",
")",
";",
"if",
"(",
"!",
"$",
"module",
"instanceof",
"ModuleBlockInterface",
")",
"{",
"throw",
"new",
"NotFoundHttpException",
"(",
")",
";",
"}",
"if",
"(",
"$",
"block",
"->",
"user_id",
"!==",
"$",
"user",
"->",
"id",
"(",
")",
"&&",
"!",
"Auth",
"::",
"isAdmin",
"(",
")",
")",
"{",
"throw",
"new",
"AccessDeniedHttpException",
"(",
")",
";",
"}",
"return",
"$",
"module",
";",
"}"
] | Load a block and check we have permission to edit it.
@param ServerRequestInterface $request
@param Tree $tree
@param UserInterface $user
@return ModuleBlockInterface | [
"Load",
"a",
"block",
"and",
"check",
"we",
"have",
"permission",
"to",
"edit",
"it",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Http/Controllers/HomePageController.php#L156-L181 | train |
fisharebest/webtrees | app/Http/Controllers/HomePageController.php | HomePageController.treePage | public function treePage(Tree $tree): ResponseInterface
{
$has_blocks = DB::table('block')
->where('gedcom_id', '=', $tree->id())
->exists();
if (!$has_blocks) {
$this->checkDefaultTreeBlocksExist();
// Copy the defaults
(new Builder(DB::connection()))->from('block')->insertUsing(
['gedcom_id', 'location', 'block_order', 'module_name'],
static function (Builder $query) use ($tree): void {
$query
->select([DB::raw($tree->id()), 'location', 'block_order', 'module_name'])
->from('block')
->where('gedcom_id', '=', -1);
}
);
}
return $this->viewResponse('tree-page', [
'main_blocks' => $this->treeBlocks($tree->id(), 'main'),
'side_blocks' => $this->treeBlocks($tree->id(), 'side'),
'title' => e($tree->title()),
'meta_robots' => 'index,follow',
]);
} | php | public function treePage(Tree $tree): ResponseInterface
{
$has_blocks = DB::table('block')
->where('gedcom_id', '=', $tree->id())
->exists();
if (!$has_blocks) {
$this->checkDefaultTreeBlocksExist();
// Copy the defaults
(new Builder(DB::connection()))->from('block')->insertUsing(
['gedcom_id', 'location', 'block_order', 'module_name'],
static function (Builder $query) use ($tree): void {
$query
->select([DB::raw($tree->id()), 'location', 'block_order', 'module_name'])
->from('block')
->where('gedcom_id', '=', -1);
}
);
}
return $this->viewResponse('tree-page', [
'main_blocks' => $this->treeBlocks($tree->id(), 'main'),
'side_blocks' => $this->treeBlocks($tree->id(), 'side'),
'title' => e($tree->title()),
'meta_robots' => 'index,follow',
]);
} | [
"public",
"function",
"treePage",
"(",
"Tree",
"$",
"tree",
")",
":",
"ResponseInterface",
"{",
"$",
"has_blocks",
"=",
"DB",
"::",
"table",
"(",
"'block'",
")",
"->",
"where",
"(",
"'gedcom_id'",
",",
"'='",
",",
"$",
"tree",
"->",
"id",
"(",
")",
")",
"->",
"exists",
"(",
")",
";",
"if",
"(",
"!",
"$",
"has_blocks",
")",
"{",
"$",
"this",
"->",
"checkDefaultTreeBlocksExist",
"(",
")",
";",
"// Copy the defaults",
"(",
"new",
"Builder",
"(",
"DB",
"::",
"connection",
"(",
")",
")",
")",
"->",
"from",
"(",
"'block'",
")",
"->",
"insertUsing",
"(",
"[",
"'gedcom_id'",
",",
"'location'",
",",
"'block_order'",
",",
"'module_name'",
"]",
",",
"static",
"function",
"(",
"Builder",
"$",
"query",
")",
"use",
"(",
"$",
"tree",
")",
":",
"void",
"{",
"$",
"query",
"->",
"select",
"(",
"[",
"DB",
"::",
"raw",
"(",
"$",
"tree",
"->",
"id",
"(",
")",
")",
",",
"'location'",
",",
"'block_order'",
",",
"'module_name'",
"]",
")",
"->",
"from",
"(",
"'block'",
")",
"->",
"where",
"(",
"'gedcom_id'",
",",
"'='",
",",
"-",
"1",
")",
";",
"}",
")",
";",
"}",
"return",
"$",
"this",
"->",
"viewResponse",
"(",
"'tree-page'",
",",
"[",
"'main_blocks'",
"=>",
"$",
"this",
"->",
"treeBlocks",
"(",
"$",
"tree",
"->",
"id",
"(",
")",
",",
"'main'",
")",
",",
"'side_blocks'",
"=>",
"$",
"this",
"->",
"treeBlocks",
"(",
"$",
"tree",
"->",
"id",
"(",
")",
",",
"'side'",
")",
",",
"'title'",
"=>",
"e",
"(",
"$",
"tree",
"->",
"title",
"(",
")",
")",
",",
"'meta_robots'",
"=>",
"'index,follow'",
",",
"]",
")",
";",
"}"
] | Show a tree's page.
@param Tree $tree
@return ResponseInterface | [
"Show",
"a",
"tree",
"s",
"page",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Http/Controllers/HomePageController.php#L270-L297 | train |
fisharebest/webtrees | app/Http/Controllers/HomePageController.php | HomePageController.treePageBlock | public function treePageBlock(ServerRequestInterface $request, Tree $tree): ResponseInterface
{
$block_id = $request->get('block_id');
$block_id = (int) DB::table('block')
->where('block_id', '=', $block_id)
->where('gedcom_id', '=', $tree->id())
->value('block_id');
$module = $this->getBlockModule($tree, $block_id);
$html = view('layouts/ajax', [
'content' => $module->getBlock($tree, $block_id, 'gedcom'),
]);
return response($html);
} | php | public function treePageBlock(ServerRequestInterface $request, Tree $tree): ResponseInterface
{
$block_id = $request->get('block_id');
$block_id = (int) DB::table('block')
->where('block_id', '=', $block_id)
->where('gedcom_id', '=', $tree->id())
->value('block_id');
$module = $this->getBlockModule($tree, $block_id);
$html = view('layouts/ajax', [
'content' => $module->getBlock($tree, $block_id, 'gedcom'),
]);
return response($html);
} | [
"public",
"function",
"treePageBlock",
"(",
"ServerRequestInterface",
"$",
"request",
",",
"Tree",
"$",
"tree",
")",
":",
"ResponseInterface",
"{",
"$",
"block_id",
"=",
"$",
"request",
"->",
"get",
"(",
"'block_id'",
")",
";",
"$",
"block_id",
"=",
"(",
"int",
")",
"DB",
"::",
"table",
"(",
"'block'",
")",
"->",
"where",
"(",
"'block_id'",
",",
"'='",
",",
"$",
"block_id",
")",
"->",
"where",
"(",
"'gedcom_id'",
",",
"'='",
",",
"$",
"tree",
"->",
"id",
"(",
")",
")",
"->",
"value",
"(",
"'block_id'",
")",
";",
"$",
"module",
"=",
"$",
"this",
"->",
"getBlockModule",
"(",
"$",
"tree",
",",
"$",
"block_id",
")",
";",
"$",
"html",
"=",
"view",
"(",
"'layouts/ajax'",
",",
"[",
"'content'",
"=>",
"$",
"module",
"->",
"getBlock",
"(",
"$",
"tree",
",",
"$",
"block_id",
",",
"'gedcom'",
")",
",",
"]",
")",
";",
"return",
"response",
"(",
"$",
"html",
")",
";",
"}"
] | Load block asynchronously.
@param ServerRequestInterface $request
@param Tree $tree
@return ResponseInterface | [
"Load",
"block",
"asynchronously",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Http/Controllers/HomePageController.php#L307-L323 | train |
fisharebest/webtrees | app/Http/Controllers/HomePageController.php | HomePageController.treePageDefaultEdit | public function treePageDefaultEdit(): ResponseInterface
{
$this->checkDefaultTreeBlocksExist();
$main_blocks = $this->treeBlocks(-1, 'main');
$side_blocks = $this->treeBlocks(-1, 'side');
$all_blocks = $this->availableTreeBlocks();
$title = I18N::translate('Set the default blocks for new family trees');
$url_cancel = route('admin-control-panel');
$url_save = route('tree-page-default-update');
return $this->viewResponse('edit-blocks-page', [
'all_blocks' => $all_blocks,
'can_reset' => false,
'main_blocks' => $main_blocks,
'side_blocks' => $side_blocks,
'title' => $title,
'url_cancel' => $url_cancel,
'url_save' => $url_save,
]);
} | php | public function treePageDefaultEdit(): ResponseInterface
{
$this->checkDefaultTreeBlocksExist();
$main_blocks = $this->treeBlocks(-1, 'main');
$side_blocks = $this->treeBlocks(-1, 'side');
$all_blocks = $this->availableTreeBlocks();
$title = I18N::translate('Set the default blocks for new family trees');
$url_cancel = route('admin-control-panel');
$url_save = route('tree-page-default-update');
return $this->viewResponse('edit-blocks-page', [
'all_blocks' => $all_blocks,
'can_reset' => false,
'main_blocks' => $main_blocks,
'side_blocks' => $side_blocks,
'title' => $title,
'url_cancel' => $url_cancel,
'url_save' => $url_save,
]);
} | [
"public",
"function",
"treePageDefaultEdit",
"(",
")",
":",
"ResponseInterface",
"{",
"$",
"this",
"->",
"checkDefaultTreeBlocksExist",
"(",
")",
";",
"$",
"main_blocks",
"=",
"$",
"this",
"->",
"treeBlocks",
"(",
"-",
"1",
",",
"'main'",
")",
";",
"$",
"side_blocks",
"=",
"$",
"this",
"->",
"treeBlocks",
"(",
"-",
"1",
",",
"'side'",
")",
";",
"$",
"all_blocks",
"=",
"$",
"this",
"->",
"availableTreeBlocks",
"(",
")",
";",
"$",
"title",
"=",
"I18N",
"::",
"translate",
"(",
"'Set the default blocks for new family trees'",
")",
";",
"$",
"url_cancel",
"=",
"route",
"(",
"'admin-control-panel'",
")",
";",
"$",
"url_save",
"=",
"route",
"(",
"'tree-page-default-update'",
")",
";",
"return",
"$",
"this",
"->",
"viewResponse",
"(",
"'edit-blocks-page'",
",",
"[",
"'all_blocks'",
"=>",
"$",
"all_blocks",
",",
"'can_reset'",
"=>",
"false",
",",
"'main_blocks'",
"=>",
"$",
"main_blocks",
",",
"'side_blocks'",
"=>",
"$",
"side_blocks",
",",
"'title'",
"=>",
"$",
"title",
",",
"'url_cancel'",
"=>",
"$",
"url_cancel",
",",
"'url_save'",
"=>",
"$",
"url_save",
",",
"]",
")",
";",
"}"
] | Show a form to edit the default blocks for new trees.
@return ResponseInterface | [
"Show",
"a",
"form",
"to",
"edit",
"the",
"default",
"blocks",
"for",
"new",
"trees",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Http/Controllers/HomePageController.php#L330-L351 | train |
fisharebest/webtrees | app/Http/Controllers/HomePageController.php | HomePageController.treePageDefaultUpdate | public function treePageDefaultUpdate(ServerRequestInterface $request): ResponseInterface
{
$main_blocks = (array) $request->get('main');
$side_blocks = (array) $request->get('side');
$this->updateTreeBlocks(-1, $main_blocks, $side_blocks);
return redirect(route('admin-control-panel'));
} | php | public function treePageDefaultUpdate(ServerRequestInterface $request): ResponseInterface
{
$main_blocks = (array) $request->get('main');
$side_blocks = (array) $request->get('side');
$this->updateTreeBlocks(-1, $main_blocks, $side_blocks);
return redirect(route('admin-control-panel'));
} | [
"public",
"function",
"treePageDefaultUpdate",
"(",
"ServerRequestInterface",
"$",
"request",
")",
":",
"ResponseInterface",
"{",
"$",
"main_blocks",
"=",
"(",
"array",
")",
"$",
"request",
"->",
"get",
"(",
"'main'",
")",
";",
"$",
"side_blocks",
"=",
"(",
"array",
")",
"$",
"request",
"->",
"get",
"(",
"'side'",
")",
";",
"$",
"this",
"->",
"updateTreeBlocks",
"(",
"-",
"1",
",",
"$",
"main_blocks",
",",
"$",
"side_blocks",
")",
";",
"return",
"redirect",
"(",
"route",
"(",
"'admin-control-panel'",
")",
")",
";",
"}"
] | Save updated default blocks for new trees.
@param ServerRequestInterface $request
@return ResponseInterface | [
"Save",
"updated",
"default",
"blocks",
"for",
"new",
"trees",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Http/Controllers/HomePageController.php#L360-L368 | train |
fisharebest/webtrees | app/Http/Controllers/HomePageController.php | HomePageController.treePageUpdate | public function treePageUpdate(ServerRequestInterface $request, Tree $tree): ResponseInterface
{
$defaults = (bool) $request->get('defaults');
if ($defaults) {
$main_blocks = $this->treeBlocks(-1, 'main')->all();
$side_blocks = $this->treeBlocks(-1, 'side')->all();
} else {
$main_blocks = (array) $request->get('main');
$side_blocks = (array) $request->get('side');
}
$this->updateTreeBlocks($tree->id(), $main_blocks, $side_blocks);
return redirect(route('tree-page', ['ged' => $tree->name()]));
} | php | public function treePageUpdate(ServerRequestInterface $request, Tree $tree): ResponseInterface
{
$defaults = (bool) $request->get('defaults');
if ($defaults) {
$main_blocks = $this->treeBlocks(-1, 'main')->all();
$side_blocks = $this->treeBlocks(-1, 'side')->all();
} else {
$main_blocks = (array) $request->get('main');
$side_blocks = (array) $request->get('side');
}
$this->updateTreeBlocks($tree->id(), $main_blocks, $side_blocks);
return redirect(route('tree-page', ['ged' => $tree->name()]));
} | [
"public",
"function",
"treePageUpdate",
"(",
"ServerRequestInterface",
"$",
"request",
",",
"Tree",
"$",
"tree",
")",
":",
"ResponseInterface",
"{",
"$",
"defaults",
"=",
"(",
"bool",
")",
"$",
"request",
"->",
"get",
"(",
"'defaults'",
")",
";",
"if",
"(",
"$",
"defaults",
")",
"{",
"$",
"main_blocks",
"=",
"$",
"this",
"->",
"treeBlocks",
"(",
"-",
"1",
",",
"'main'",
")",
"->",
"all",
"(",
")",
";",
"$",
"side_blocks",
"=",
"$",
"this",
"->",
"treeBlocks",
"(",
"-",
"1",
",",
"'side'",
")",
"->",
"all",
"(",
")",
";",
"}",
"else",
"{",
"$",
"main_blocks",
"=",
"(",
"array",
")",
"$",
"request",
"->",
"get",
"(",
"'main'",
")",
";",
"$",
"side_blocks",
"=",
"(",
"array",
")",
"$",
"request",
"->",
"get",
"(",
"'side'",
")",
";",
"}",
"$",
"this",
"->",
"updateTreeBlocks",
"(",
"$",
"tree",
"->",
"id",
"(",
")",
",",
"$",
"main_blocks",
",",
"$",
"side_blocks",
")",
";",
"return",
"redirect",
"(",
"route",
"(",
"'tree-page'",
",",
"[",
"'ged'",
"=>",
"$",
"tree",
"->",
"name",
"(",
")",
"]",
")",
")",
";",
"}"
] | Save updated blocks on a tree's page.
@param ServerRequestInterface $request
@param Tree $tree
@return ResponseInterface | [
"Save",
"updated",
"blocks",
"on",
"a",
"tree",
"s",
"page",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Http/Controllers/HomePageController.php#L406-L421 | train |
fisharebest/webtrees | app/Http/Controllers/HomePageController.php | HomePageController.userPage | public function userPage(UserInterface $user): ResponseInterface
{
$has_blocks = DB::table('block')
->where('user_id', '=', $user->id())
->exists();
if (!$has_blocks) {
$this->checkDefaultUserBlocksExist();
// Copy the defaults
(new Builder(DB::connection()))->from('block')->insertUsing(
['user_id', 'location', 'block_order', 'module_name'],
static function (Builder $query) use ($user): void {
$query
->select([DB::raw($user->id()), 'location', 'block_order', 'module_name'])
->from('block')
->where('user_id', '=', -1);
}
);
}
return $this->viewResponse('user-page', [
'main_blocks' => $this->userBlocks($user->id(), 'main'),
'side_blocks' => $this->userBlocks($user->id(), 'side'),
'title' => I18N::translate('My page'),
]);
} | php | public function userPage(UserInterface $user): ResponseInterface
{
$has_blocks = DB::table('block')
->where('user_id', '=', $user->id())
->exists();
if (!$has_blocks) {
$this->checkDefaultUserBlocksExist();
// Copy the defaults
(new Builder(DB::connection()))->from('block')->insertUsing(
['user_id', 'location', 'block_order', 'module_name'],
static function (Builder $query) use ($user): void {
$query
->select([DB::raw($user->id()), 'location', 'block_order', 'module_name'])
->from('block')
->where('user_id', '=', -1);
}
);
}
return $this->viewResponse('user-page', [
'main_blocks' => $this->userBlocks($user->id(), 'main'),
'side_blocks' => $this->userBlocks($user->id(), 'side'),
'title' => I18N::translate('My page'),
]);
} | [
"public",
"function",
"userPage",
"(",
"UserInterface",
"$",
"user",
")",
":",
"ResponseInterface",
"{",
"$",
"has_blocks",
"=",
"DB",
"::",
"table",
"(",
"'block'",
")",
"->",
"where",
"(",
"'user_id'",
",",
"'='",
",",
"$",
"user",
"->",
"id",
"(",
")",
")",
"->",
"exists",
"(",
")",
";",
"if",
"(",
"!",
"$",
"has_blocks",
")",
"{",
"$",
"this",
"->",
"checkDefaultUserBlocksExist",
"(",
")",
";",
"// Copy the defaults",
"(",
"new",
"Builder",
"(",
"DB",
"::",
"connection",
"(",
")",
")",
")",
"->",
"from",
"(",
"'block'",
")",
"->",
"insertUsing",
"(",
"[",
"'user_id'",
",",
"'location'",
",",
"'block_order'",
",",
"'module_name'",
"]",
",",
"static",
"function",
"(",
"Builder",
"$",
"query",
")",
"use",
"(",
"$",
"user",
")",
":",
"void",
"{",
"$",
"query",
"->",
"select",
"(",
"[",
"DB",
"::",
"raw",
"(",
"$",
"user",
"->",
"id",
"(",
")",
")",
",",
"'location'",
",",
"'block_order'",
",",
"'module_name'",
"]",
")",
"->",
"from",
"(",
"'block'",
")",
"->",
"where",
"(",
"'user_id'",
",",
"'='",
",",
"-",
"1",
")",
";",
"}",
")",
";",
"}",
"return",
"$",
"this",
"->",
"viewResponse",
"(",
"'user-page'",
",",
"[",
"'main_blocks'",
"=>",
"$",
"this",
"->",
"userBlocks",
"(",
"$",
"user",
"->",
"id",
"(",
")",
",",
"'main'",
")",
",",
"'side_blocks'",
"=>",
"$",
"this",
"->",
"userBlocks",
"(",
"$",
"user",
"->",
"id",
"(",
")",
",",
"'side'",
")",
",",
"'title'",
"=>",
"I18N",
"::",
"translate",
"(",
"'My page'",
")",
",",
"]",
")",
";",
"}"
] | Show a users's page.
@param UserInterface $user
@return ResponseInterface | [
"Show",
"a",
"users",
"s",
"page",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Http/Controllers/HomePageController.php#L430-L456 | train |
fisharebest/webtrees | app/Http/Controllers/HomePageController.php | HomePageController.userPageDefaultEdit | public function userPageDefaultEdit(): ResponseInterface
{
$this->checkDefaultUserBlocksExist();
$main_blocks = $this->userBlocks(-1, 'main');
$side_blocks = $this->userBlocks(-1, 'side');
$all_blocks = $this->availableUserBlocks();
$title = I18N::translate('Set the default blocks for new users');
$url_cancel = route('admin-users');
$url_save = route('user-page-default-update');
return $this->viewResponse('edit-blocks-page', [
'all_blocks' => $all_blocks,
'can_reset' => false,
'main_blocks' => $main_blocks,
'side_blocks' => $side_blocks,
'title' => $title,
'url_cancel' => $url_cancel,
'url_save' => $url_save,
]);
} | php | public function userPageDefaultEdit(): ResponseInterface
{
$this->checkDefaultUserBlocksExist();
$main_blocks = $this->userBlocks(-1, 'main');
$side_blocks = $this->userBlocks(-1, 'side');
$all_blocks = $this->availableUserBlocks();
$title = I18N::translate('Set the default blocks for new users');
$url_cancel = route('admin-users');
$url_save = route('user-page-default-update');
return $this->viewResponse('edit-blocks-page', [
'all_blocks' => $all_blocks,
'can_reset' => false,
'main_blocks' => $main_blocks,
'side_blocks' => $side_blocks,
'title' => $title,
'url_cancel' => $url_cancel,
'url_save' => $url_save,
]);
} | [
"public",
"function",
"userPageDefaultEdit",
"(",
")",
":",
"ResponseInterface",
"{",
"$",
"this",
"->",
"checkDefaultUserBlocksExist",
"(",
")",
";",
"$",
"main_blocks",
"=",
"$",
"this",
"->",
"userBlocks",
"(",
"-",
"1",
",",
"'main'",
")",
";",
"$",
"side_blocks",
"=",
"$",
"this",
"->",
"userBlocks",
"(",
"-",
"1",
",",
"'side'",
")",
";",
"$",
"all_blocks",
"=",
"$",
"this",
"->",
"availableUserBlocks",
"(",
")",
";",
"$",
"title",
"=",
"I18N",
"::",
"translate",
"(",
"'Set the default blocks for new users'",
")",
";",
"$",
"url_cancel",
"=",
"route",
"(",
"'admin-users'",
")",
";",
"$",
"url_save",
"=",
"route",
"(",
"'user-page-default-update'",
")",
";",
"return",
"$",
"this",
"->",
"viewResponse",
"(",
"'edit-blocks-page'",
",",
"[",
"'all_blocks'",
"=>",
"$",
"all_blocks",
",",
"'can_reset'",
"=>",
"false",
",",
"'main_blocks'",
"=>",
"$",
"main_blocks",
",",
"'side_blocks'",
"=>",
"$",
"side_blocks",
",",
"'title'",
"=>",
"$",
"title",
",",
"'url_cancel'",
"=>",
"$",
"url_cancel",
",",
"'url_save'",
"=>",
"$",
"url_save",
",",
"]",
")",
";",
"}"
] | Show a form to edit the default blocks for new uesrs.
@return ResponseInterface | [
"Show",
"a",
"form",
"to",
"edit",
"the",
"default",
"blocks",
"for",
"new",
"uesrs",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Http/Controllers/HomePageController.php#L490-L510 | train |
fisharebest/webtrees | app/Http/Controllers/HomePageController.php | HomePageController.userPageDefaultUpdate | public function userPageDefaultUpdate(ServerRequestInterface $request): ResponseInterface
{
$main_blocks = (array) $request->get('main');
$side_blocks = (array) $request->get('side');
$this->updateUserBlocks(-1, $main_blocks, $side_blocks);
return redirect(route('admin-control-panel'));
} | php | public function userPageDefaultUpdate(ServerRequestInterface $request): ResponseInterface
{
$main_blocks = (array) $request->get('main');
$side_blocks = (array) $request->get('side');
$this->updateUserBlocks(-1, $main_blocks, $side_blocks);
return redirect(route('admin-control-panel'));
} | [
"public",
"function",
"userPageDefaultUpdate",
"(",
"ServerRequestInterface",
"$",
"request",
")",
":",
"ResponseInterface",
"{",
"$",
"main_blocks",
"=",
"(",
"array",
")",
"$",
"request",
"->",
"get",
"(",
"'main'",
")",
";",
"$",
"side_blocks",
"=",
"(",
"array",
")",
"$",
"request",
"->",
"get",
"(",
"'side'",
")",
";",
"$",
"this",
"->",
"updateUserBlocks",
"(",
"-",
"1",
",",
"$",
"main_blocks",
",",
"$",
"side_blocks",
")",
";",
"return",
"redirect",
"(",
"route",
"(",
"'admin-control-panel'",
")",
")",
";",
"}"
] | Save the updated default blocks for new users.
@param ServerRequestInterface $request
@return ResponseInterface | [
"Save",
"the",
"updated",
"default",
"blocks",
"for",
"new",
"users",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Http/Controllers/HomePageController.php#L519-L527 | train |
fisharebest/webtrees | app/Http/Controllers/HomePageController.php | HomePageController.userPageUpdate | public function userPageUpdate(ServerRequestInterface $request, Tree $tree, UserInterface $user): ResponseInterface
{
$defaults = (bool) $request->get('defaults');
if ($defaults) {
$main_blocks = $this->userBlocks(-1, 'main')->all();
$side_blocks = $this->userBlocks(-1, 'side')->all();
} else {
$main_blocks = (array) $request->get('main');
$side_blocks = (array) $request->get('side');
}
$this->updateUserBlocks($user->id(), $main_blocks, $side_blocks);
return redirect(route('user-page', ['ged' => $tree->name()]));
} | php | public function userPageUpdate(ServerRequestInterface $request, Tree $tree, UserInterface $user): ResponseInterface
{
$defaults = (bool) $request->get('defaults');
if ($defaults) {
$main_blocks = $this->userBlocks(-1, 'main')->all();
$side_blocks = $this->userBlocks(-1, 'side')->all();
} else {
$main_blocks = (array) $request->get('main');
$side_blocks = (array) $request->get('side');
}
$this->updateUserBlocks($user->id(), $main_blocks, $side_blocks);
return redirect(route('user-page', ['ged' => $tree->name()]));
} | [
"public",
"function",
"userPageUpdate",
"(",
"ServerRequestInterface",
"$",
"request",
",",
"Tree",
"$",
"tree",
",",
"UserInterface",
"$",
"user",
")",
":",
"ResponseInterface",
"{",
"$",
"defaults",
"=",
"(",
"bool",
")",
"$",
"request",
"->",
"get",
"(",
"'defaults'",
")",
";",
"if",
"(",
"$",
"defaults",
")",
"{",
"$",
"main_blocks",
"=",
"$",
"this",
"->",
"userBlocks",
"(",
"-",
"1",
",",
"'main'",
")",
"->",
"all",
"(",
")",
";",
"$",
"side_blocks",
"=",
"$",
"this",
"->",
"userBlocks",
"(",
"-",
"1",
",",
"'side'",
")",
"->",
"all",
"(",
")",
";",
"}",
"else",
"{",
"$",
"main_blocks",
"=",
"(",
"array",
")",
"$",
"request",
"->",
"get",
"(",
"'main'",
")",
";",
"$",
"side_blocks",
"=",
"(",
"array",
")",
"$",
"request",
"->",
"get",
"(",
"'side'",
")",
";",
"}",
"$",
"this",
"->",
"updateUserBlocks",
"(",
"$",
"user",
"->",
"id",
"(",
")",
",",
"$",
"main_blocks",
",",
"$",
"side_blocks",
")",
";",
"return",
"redirect",
"(",
"route",
"(",
"'user-page'",
",",
"[",
"'ged'",
"=>",
"$",
"tree",
"->",
"name",
"(",
")",
"]",
")",
")",
";",
"}"
] | Save the updted blocks on a user's page.
@param ServerRequestInterface $request
@param Tree $tree
@param UserInterface $user
@return ResponseInterface | [
"Save",
"the",
"updted",
"blocks",
"on",
"a",
"user",
"s",
"page",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Http/Controllers/HomePageController.php#L566-L581 | train |
fisharebest/webtrees | app/Http/Controllers/HomePageController.php | HomePageController.userPageUserUpdate | public function userPageUserUpdate(ServerRequestInterface $request): ResponseInterface
{
$user_id = (int) $request->get('user_id');
$main_blocks = (array) $request->get('main');
$side_blocks = (array) $request->get('side');
$this->updateUserBlocks($user_id, $main_blocks, $side_blocks);
return redirect(route('admin-control-panel'));
} | php | public function userPageUserUpdate(ServerRequestInterface $request): ResponseInterface
{
$user_id = (int) $request->get('user_id');
$main_blocks = (array) $request->get('main');
$side_blocks = (array) $request->get('side');
$this->updateUserBlocks($user_id, $main_blocks, $side_blocks);
return redirect(route('admin-control-panel'));
} | [
"public",
"function",
"userPageUserUpdate",
"(",
"ServerRequestInterface",
"$",
"request",
")",
":",
"ResponseInterface",
"{",
"$",
"user_id",
"=",
"(",
"int",
")",
"$",
"request",
"->",
"get",
"(",
"'user_id'",
")",
";",
"$",
"main_blocks",
"=",
"(",
"array",
")",
"$",
"request",
"->",
"get",
"(",
"'main'",
")",
";",
"$",
"side_blocks",
"=",
"(",
"array",
")",
"$",
"request",
"->",
"get",
"(",
"'side'",
")",
";",
"$",
"this",
"->",
"updateUserBlocks",
"(",
"$",
"user_id",
",",
"$",
"main_blocks",
",",
"$",
"side_blocks",
")",
";",
"return",
"redirect",
"(",
"route",
"(",
"'admin-control-panel'",
")",
")",
";",
"}"
] | Save the updated blocks for another user's page.
@param ServerRequestInterface $request
@return ResponseInterface | [
"Save",
"the",
"updated",
"blocks",
"for",
"another",
"user",
"s",
"page",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Http/Controllers/HomePageController.php#L619-L628 | train |
fisharebest/webtrees | app/Http/Controllers/HomePageController.php | HomePageController.getBlockModule | private function getBlockModule(Tree $tree, int $block_id): ModuleBlockInterface
{
$active_blocks = $this->module_service->findByComponent(ModuleBlockInterface::class, $tree, Auth::user());
$module_name = DB::table('block')
->where('block_id', '=', $block_id)
->value('module_name');
$block = $active_blocks->first(static function (ModuleInterface $module) use ($module_name): bool {
return $module->name() === $module_name;
});
if ($block === null) {
throw new NotFoundHttpException('Block not found');
}
return $block;
} | php | private function getBlockModule(Tree $tree, int $block_id): ModuleBlockInterface
{
$active_blocks = $this->module_service->findByComponent(ModuleBlockInterface::class, $tree, Auth::user());
$module_name = DB::table('block')
->where('block_id', '=', $block_id)
->value('module_name');
$block = $active_blocks->first(static function (ModuleInterface $module) use ($module_name): bool {
return $module->name() === $module_name;
});
if ($block === null) {
throw new NotFoundHttpException('Block not found');
}
return $block;
} | [
"private",
"function",
"getBlockModule",
"(",
"Tree",
"$",
"tree",
",",
"int",
"$",
"block_id",
")",
":",
"ModuleBlockInterface",
"{",
"$",
"active_blocks",
"=",
"$",
"this",
"->",
"module_service",
"->",
"findByComponent",
"(",
"ModuleBlockInterface",
"::",
"class",
",",
"$",
"tree",
",",
"Auth",
"::",
"user",
"(",
")",
")",
";",
"$",
"module_name",
"=",
"DB",
"::",
"table",
"(",
"'block'",
")",
"->",
"where",
"(",
"'block_id'",
",",
"'='",
",",
"$",
"block_id",
")",
"->",
"value",
"(",
"'module_name'",
")",
";",
"$",
"block",
"=",
"$",
"active_blocks",
"->",
"first",
"(",
"static",
"function",
"(",
"ModuleInterface",
"$",
"module",
")",
"use",
"(",
"$",
"module_name",
")",
":",
"bool",
"{",
"return",
"$",
"module",
"->",
"name",
"(",
")",
"===",
"$",
"module_name",
";",
"}",
")",
";",
"if",
"(",
"$",
"block",
"===",
"null",
")",
"{",
"throw",
"new",
"NotFoundHttpException",
"(",
"'Block not found'",
")",
";",
"}",
"return",
"$",
"block",
";",
"}"
] | Get a specific block.
@param Tree $tree
@param int $block_id
@return ModuleBlockInterface
@throws NotFoundHttpException | [
"Get",
"a",
"specific",
"block",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Http/Controllers/HomePageController.php#L639-L656 | train |
fisharebest/webtrees | app/Http/Controllers/HomePageController.php | HomePageController.availableTreeBlocks | private function availableTreeBlocks(): Collection
{
return $this->module_service->findByInterface(ModuleBlockInterface::class, false, true)
->filter(static function (ModuleBlockInterface $block): bool {
return $block->isTreeBlock();
})
->mapWithKeys(static function (ModuleInterface $block): array {
return [$block->name() => $block];
});
} | php | private function availableTreeBlocks(): Collection
{
return $this->module_service->findByInterface(ModuleBlockInterface::class, false, true)
->filter(static function (ModuleBlockInterface $block): bool {
return $block->isTreeBlock();
})
->mapWithKeys(static function (ModuleInterface $block): array {
return [$block->name() => $block];
});
} | [
"private",
"function",
"availableTreeBlocks",
"(",
")",
":",
"Collection",
"{",
"return",
"$",
"this",
"->",
"module_service",
"->",
"findByInterface",
"(",
"ModuleBlockInterface",
"::",
"class",
",",
"false",
",",
"true",
")",
"->",
"filter",
"(",
"static",
"function",
"(",
"ModuleBlockInterface",
"$",
"block",
")",
":",
"bool",
"{",
"return",
"$",
"block",
"->",
"isTreeBlock",
"(",
")",
";",
"}",
")",
"->",
"mapWithKeys",
"(",
"static",
"function",
"(",
"ModuleInterface",
"$",
"block",
")",
":",
"array",
"{",
"return",
"[",
"$",
"block",
"->",
"name",
"(",
")",
"=>",
"$",
"block",
"]",
";",
"}",
")",
";",
"}"
] | Get all the available blocks for a tree page.
@return Collection
@return ModuleBlockInterface[] | [
"Get",
"all",
"the",
"available",
"blocks",
"for",
"a",
"tree",
"page",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Http/Controllers/HomePageController.php#L664-L673 | train |
fisharebest/webtrees | app/Http/Controllers/HomePageController.php | HomePageController.availableUserBlocks | private function availableUserBlocks(): Collection
{
return $this->module_service->findByInterface(ModuleBlockInterface::class, false, true)
->filter(static function (ModuleBlockInterface $block): bool {
return $block->isUserBlock();
})
->mapWithKeys(static function (ModuleInterface $block): array {
return [$block->name() => $block];
});
} | php | private function availableUserBlocks(): Collection
{
return $this->module_service->findByInterface(ModuleBlockInterface::class, false, true)
->filter(static function (ModuleBlockInterface $block): bool {
return $block->isUserBlock();
})
->mapWithKeys(static function (ModuleInterface $block): array {
return [$block->name() => $block];
});
} | [
"private",
"function",
"availableUserBlocks",
"(",
")",
":",
"Collection",
"{",
"return",
"$",
"this",
"->",
"module_service",
"->",
"findByInterface",
"(",
"ModuleBlockInterface",
"::",
"class",
",",
"false",
",",
"true",
")",
"->",
"filter",
"(",
"static",
"function",
"(",
"ModuleBlockInterface",
"$",
"block",
")",
":",
"bool",
"{",
"return",
"$",
"block",
"->",
"isUserBlock",
"(",
")",
";",
"}",
")",
"->",
"mapWithKeys",
"(",
"static",
"function",
"(",
"ModuleInterface",
"$",
"block",
")",
":",
"array",
"{",
"return",
"[",
"$",
"block",
"->",
"name",
"(",
")",
"=>",
"$",
"block",
"]",
";",
"}",
")",
";",
"}"
] | Get all the available blocks for a user page.
@return Collection
@return ModuleBlockInterface[] | [
"Get",
"all",
"the",
"available",
"blocks",
"for",
"a",
"user",
"page",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Http/Controllers/HomePageController.php#L681-L690 | train |
fisharebest/webtrees | app/Http/Controllers/HomePageController.php | HomePageController.treeBlocks | private function treeBlocks(int $tree_id, string $location): Collection
{
$rows = DB::table('block')
->where('gedcom_id', '=', $tree_id)
->where('location', '=', $location)
->orderBy('block_order')
->pluck('module_name', 'block_id');
return $this->filterActiveBlocks($rows, $this->availableTreeBlocks());
} | php | private function treeBlocks(int $tree_id, string $location): Collection
{
$rows = DB::table('block')
->where('gedcom_id', '=', $tree_id)
->where('location', '=', $location)
->orderBy('block_order')
->pluck('module_name', 'block_id');
return $this->filterActiveBlocks($rows, $this->availableTreeBlocks());
} | [
"private",
"function",
"treeBlocks",
"(",
"int",
"$",
"tree_id",
",",
"string",
"$",
"location",
")",
":",
"Collection",
"{",
"$",
"rows",
"=",
"DB",
"::",
"table",
"(",
"'block'",
")",
"->",
"where",
"(",
"'gedcom_id'",
",",
"'='",
",",
"$",
"tree_id",
")",
"->",
"where",
"(",
"'location'",
",",
"'='",
",",
"$",
"location",
")",
"->",
"orderBy",
"(",
"'block_order'",
")",
"->",
"pluck",
"(",
"'module_name'",
",",
"'block_id'",
")",
";",
"return",
"$",
"this",
"->",
"filterActiveBlocks",
"(",
"$",
"rows",
",",
"$",
"this",
"->",
"availableTreeBlocks",
"(",
")",
")",
";",
"}"
] | Get the blocks for a specified tree.
@param int $tree_id
@param string $location "main" or "side"
@return Collection
@return ModuleBlockInterface[] | [
"Get",
"the",
"blocks",
"for",
"a",
"specified",
"tree",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Http/Controllers/HomePageController.php#L701-L710 | train |
fisharebest/webtrees | app/Http/Controllers/HomePageController.php | HomePageController.checkDefaultTreeBlocksExist | private function checkDefaultTreeBlocksExist(): void
{
$has_blocks = DB::table('block')
->where('gedcom_id', '=', -1)
->exists();
// No default settings? Create them.
if (!$has_blocks) {
foreach (['main', 'side'] as $location) {
foreach (self::DEFAULT_TREE_PAGE_BLOCKS[$location] as $block_order => $class) {
$module_name = $this->module_service->findByInterface($class)->first()->name();
DB::table('block')->insert([
'gedcom_id' => -1,
'location' => $location,
'block_order' => $block_order,
'module_name' => $module_name,
]);
}
}
}
} | php | private function checkDefaultTreeBlocksExist(): void
{
$has_blocks = DB::table('block')
->where('gedcom_id', '=', -1)
->exists();
// No default settings? Create them.
if (!$has_blocks) {
foreach (['main', 'side'] as $location) {
foreach (self::DEFAULT_TREE_PAGE_BLOCKS[$location] as $block_order => $class) {
$module_name = $this->module_service->findByInterface($class)->first()->name();
DB::table('block')->insert([
'gedcom_id' => -1,
'location' => $location,
'block_order' => $block_order,
'module_name' => $module_name,
]);
}
}
}
} | [
"private",
"function",
"checkDefaultTreeBlocksExist",
"(",
")",
":",
"void",
"{",
"$",
"has_blocks",
"=",
"DB",
"::",
"table",
"(",
"'block'",
")",
"->",
"where",
"(",
"'gedcom_id'",
",",
"'='",
",",
"-",
"1",
")",
"->",
"exists",
"(",
")",
";",
"// No default settings? Create them.",
"if",
"(",
"!",
"$",
"has_blocks",
")",
"{",
"foreach",
"(",
"[",
"'main'",
",",
"'side'",
"]",
"as",
"$",
"location",
")",
"{",
"foreach",
"(",
"self",
"::",
"DEFAULT_TREE_PAGE_BLOCKS",
"[",
"$",
"location",
"]",
"as",
"$",
"block_order",
"=>",
"$",
"class",
")",
"{",
"$",
"module_name",
"=",
"$",
"this",
"->",
"module_service",
"->",
"findByInterface",
"(",
"$",
"class",
")",
"->",
"first",
"(",
")",
"->",
"name",
"(",
")",
";",
"DB",
"::",
"table",
"(",
"'block'",
")",
"->",
"insert",
"(",
"[",
"'gedcom_id'",
"=>",
"-",
"1",
",",
"'location'",
"=>",
"$",
"location",
",",
"'block_order'",
"=>",
"$",
"block_order",
",",
"'module_name'",
"=>",
"$",
"module_name",
",",
"]",
")",
";",
"}",
"}",
"}",
"}"
] | Make sure that default blocks exist for a tree.
@return void | [
"Make",
"sure",
"that",
"default",
"blocks",
"exist",
"for",
"a",
"tree",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Http/Controllers/HomePageController.php#L717-L738 | train |
fisharebest/webtrees | app/Http/Controllers/HomePageController.php | HomePageController.userBlocks | private function userBlocks(int $user_id, string $location): Collection
{
$rows = DB::table('block')
->where('user_id', '=', $user_id)
->where('location', '=', $location)
->orderBy('block_order')
->pluck('module_name', 'block_id');
return $this->filterActiveBlocks($rows, $this->availableUserBlocks());
} | php | private function userBlocks(int $user_id, string $location): Collection
{
$rows = DB::table('block')
->where('user_id', '=', $user_id)
->where('location', '=', $location)
->orderBy('block_order')
->pluck('module_name', 'block_id');
return $this->filterActiveBlocks($rows, $this->availableUserBlocks());
} | [
"private",
"function",
"userBlocks",
"(",
"int",
"$",
"user_id",
",",
"string",
"$",
"location",
")",
":",
"Collection",
"{",
"$",
"rows",
"=",
"DB",
"::",
"table",
"(",
"'block'",
")",
"->",
"where",
"(",
"'user_id'",
",",
"'='",
",",
"$",
"user_id",
")",
"->",
"where",
"(",
"'location'",
",",
"'='",
",",
"$",
"location",
")",
"->",
"orderBy",
"(",
"'block_order'",
")",
"->",
"pluck",
"(",
"'module_name'",
",",
"'block_id'",
")",
";",
"return",
"$",
"this",
"->",
"filterActiveBlocks",
"(",
"$",
"rows",
",",
"$",
"this",
"->",
"availableUserBlocks",
"(",
")",
")",
";",
"}"
] | Get the blocks for a specified user.
@param int $user_id
@param string $location "main" or "side"
@return Collection
@return ModuleBlockInterface[] | [
"Get",
"the",
"blocks",
"for",
"a",
"specified",
"user",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Http/Controllers/HomePageController.php#L749-L758 | train |
fisharebest/webtrees | app/Http/Controllers/HomePageController.php | HomePageController.updateUserBlocks | private function updateUserBlocks(int $user_id, array $main_blocks, array $side_blocks): void
{
$existing_block_ids = DB::table('block')
->where('user_id', '=', $user_id)
->pluck('block_id');
// Deleted blocks
foreach ($existing_block_ids as $existing_block_id) {
if (!in_array($existing_block_id, $main_blocks, false) && !in_array($existing_block_id, $side_blocks, false)) {
DB::table('block_setting')
->where('block_id', '=', $existing_block_id)
->delete();
DB::table('block')
->where('block_id', '=', $existing_block_id)
->delete();
}
}
$updates = [
'main' => $main_blocks,
'side' => $side_blocks,
];
foreach ($updates as $location => $updated_blocks) {
foreach ($updated_blocks as $block_order => $block_id) {
if (is_numeric($block_id)) {
// Updated block
DB::table('block')
->where('block_id', '=', $block_id)
->update([
'block_order' => $block_order,
'location' => $location,
]);
} else {
// New block
DB::table('block')->insert([
'user_id' => $user_id,
'location' => $location,
'block_order' => $block_order,
'module_name' => $block_id,
]);
}
}
}
} | php | private function updateUserBlocks(int $user_id, array $main_blocks, array $side_blocks): void
{
$existing_block_ids = DB::table('block')
->where('user_id', '=', $user_id)
->pluck('block_id');
// Deleted blocks
foreach ($existing_block_ids as $existing_block_id) {
if (!in_array($existing_block_id, $main_blocks, false) && !in_array($existing_block_id, $side_blocks, false)) {
DB::table('block_setting')
->where('block_id', '=', $existing_block_id)
->delete();
DB::table('block')
->where('block_id', '=', $existing_block_id)
->delete();
}
}
$updates = [
'main' => $main_blocks,
'side' => $side_blocks,
];
foreach ($updates as $location => $updated_blocks) {
foreach ($updated_blocks as $block_order => $block_id) {
if (is_numeric($block_id)) {
// Updated block
DB::table('block')
->where('block_id', '=', $block_id)
->update([
'block_order' => $block_order,
'location' => $location,
]);
} else {
// New block
DB::table('block')->insert([
'user_id' => $user_id,
'location' => $location,
'block_order' => $block_order,
'module_name' => $block_id,
]);
}
}
}
} | [
"private",
"function",
"updateUserBlocks",
"(",
"int",
"$",
"user_id",
",",
"array",
"$",
"main_blocks",
",",
"array",
"$",
"side_blocks",
")",
":",
"void",
"{",
"$",
"existing_block_ids",
"=",
"DB",
"::",
"table",
"(",
"'block'",
")",
"->",
"where",
"(",
"'user_id'",
",",
"'='",
",",
"$",
"user_id",
")",
"->",
"pluck",
"(",
"'block_id'",
")",
";",
"// Deleted blocks",
"foreach",
"(",
"$",
"existing_block_ids",
"as",
"$",
"existing_block_id",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"existing_block_id",
",",
"$",
"main_blocks",
",",
"false",
")",
"&&",
"!",
"in_array",
"(",
"$",
"existing_block_id",
",",
"$",
"side_blocks",
",",
"false",
")",
")",
"{",
"DB",
"::",
"table",
"(",
"'block_setting'",
")",
"->",
"where",
"(",
"'block_id'",
",",
"'='",
",",
"$",
"existing_block_id",
")",
"->",
"delete",
"(",
")",
";",
"DB",
"::",
"table",
"(",
"'block'",
")",
"->",
"where",
"(",
"'block_id'",
",",
"'='",
",",
"$",
"existing_block_id",
")",
"->",
"delete",
"(",
")",
";",
"}",
"}",
"$",
"updates",
"=",
"[",
"'main'",
"=>",
"$",
"main_blocks",
",",
"'side'",
"=>",
"$",
"side_blocks",
",",
"]",
";",
"foreach",
"(",
"$",
"updates",
"as",
"$",
"location",
"=>",
"$",
"updated_blocks",
")",
"{",
"foreach",
"(",
"$",
"updated_blocks",
"as",
"$",
"block_order",
"=>",
"$",
"block_id",
")",
"{",
"if",
"(",
"is_numeric",
"(",
"$",
"block_id",
")",
")",
"{",
"// Updated block",
"DB",
"::",
"table",
"(",
"'block'",
")",
"->",
"where",
"(",
"'block_id'",
",",
"'='",
",",
"$",
"block_id",
")",
"->",
"update",
"(",
"[",
"'block_order'",
"=>",
"$",
"block_order",
",",
"'location'",
"=>",
"$",
"location",
",",
"]",
")",
";",
"}",
"else",
"{",
"// New block",
"DB",
"::",
"table",
"(",
"'block'",
")",
"->",
"insert",
"(",
"[",
"'user_id'",
"=>",
"$",
"user_id",
",",
"'location'",
"=>",
"$",
"location",
",",
"'block_order'",
"=>",
"$",
"block_order",
",",
"'module_name'",
"=>",
"$",
"block_id",
",",
"]",
")",
";",
"}",
"}",
"}",
"}"
] | Save the updated blocks for a user.
@param int $user_id
@param array $main_blocks
@param array $side_blocks
@return void | [
"Save",
"the",
"updated",
"blocks",
"for",
"a",
"user",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Http/Controllers/HomePageController.php#L797-L842 | train |
fisharebest/webtrees | app/Report/ReportPdfHtml.php | ReportPdfHtml.render | public function render($renderer, $sub = false)
{
if (!empty($this->attrs['style'])) {
$renderer->setCurrentStyle($this->attrs['style']);
}
if (!empty($this->attrs['width'])) {
$this->attrs['width'] *= 3.9;
}
$this->text = $this->getStart() . $this->text;
foreach ($this->elements as $element) {
if ($element === 'footnotetexts') {
$renderer->Footnotes();
} elseif ($element === 'addpage') {
$renderer->newPage();
} elseif ($element instanceof ReportBaseHtml) {
$element->render($renderer, true);
} else {
$element->render($renderer);
}
}
$this->text .= $this->getEnd();
if ($sub) {
return $this->text;
}
$renderer->writeHTML($this->text); //prints 2 empty cells in the Expanded Relatives report
} | php | public function render($renderer, $sub = false)
{
if (!empty($this->attrs['style'])) {
$renderer->setCurrentStyle($this->attrs['style']);
}
if (!empty($this->attrs['width'])) {
$this->attrs['width'] *= 3.9;
}
$this->text = $this->getStart() . $this->text;
foreach ($this->elements as $element) {
if ($element === 'footnotetexts') {
$renderer->Footnotes();
} elseif ($element === 'addpage') {
$renderer->newPage();
} elseif ($element instanceof ReportBaseHtml) {
$element->render($renderer, true);
} else {
$element->render($renderer);
}
}
$this->text .= $this->getEnd();
if ($sub) {
return $this->text;
}
$renderer->writeHTML($this->text); //prints 2 empty cells in the Expanded Relatives report
} | [
"public",
"function",
"render",
"(",
"$",
"renderer",
",",
"$",
"sub",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"attrs",
"[",
"'style'",
"]",
")",
")",
"{",
"$",
"renderer",
"->",
"setCurrentStyle",
"(",
"$",
"this",
"->",
"attrs",
"[",
"'style'",
"]",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"attrs",
"[",
"'width'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"attrs",
"[",
"'width'",
"]",
"*=",
"3.9",
";",
"}",
"$",
"this",
"->",
"text",
"=",
"$",
"this",
"->",
"getStart",
"(",
")",
".",
"$",
"this",
"->",
"text",
";",
"foreach",
"(",
"$",
"this",
"->",
"elements",
"as",
"$",
"element",
")",
"{",
"if",
"(",
"$",
"element",
"===",
"'footnotetexts'",
")",
"{",
"$",
"renderer",
"->",
"Footnotes",
"(",
")",
";",
"}",
"elseif",
"(",
"$",
"element",
"===",
"'addpage'",
")",
"{",
"$",
"renderer",
"->",
"newPage",
"(",
")",
";",
"}",
"elseif",
"(",
"$",
"element",
"instanceof",
"ReportBaseHtml",
")",
"{",
"$",
"element",
"->",
"render",
"(",
"$",
"renderer",
",",
"true",
")",
";",
"}",
"else",
"{",
"$",
"element",
"->",
"render",
"(",
"$",
"renderer",
")",
";",
"}",
"}",
"$",
"this",
"->",
"text",
".=",
"$",
"this",
"->",
"getEnd",
"(",
")",
";",
"if",
"(",
"$",
"sub",
")",
"{",
"return",
"$",
"this",
"->",
"text",
";",
"}",
"$",
"renderer",
"->",
"writeHTML",
"(",
"$",
"this",
"->",
"text",
")",
";",
"//prints 2 empty cells in the Expanded Relatives report",
"}"
] | Render the output.
@param $renderer
@param bool $sub
@return string|void | [
"Render",
"the",
"output",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Report/ReportPdfHtml.php#L33-L59 | train |
fisharebest/webtrees | app/Statistics/Repository/FamilyRepository.php | FamilyRepository.familyQuery | private function familyQuery(string $type): string
{
$row = DB::table('families')
->where('f_file', '=', $this->tree->id())
->orderBy('f_numchil', 'desc')
->first();
if ($row === null) {
return '';
}
/** @var Family $family */
$family = Family::rowMapper()($row);
if (!$family->canShow()) {
return I18N::translate('This information is private and cannot be shown.');
}
switch ($type) {
default:
case 'full':
return $family->formatList();
case 'size':
return I18N::number((int) $row->f_numchil);
case 'name':
return '<a href="' . e($family->url()) . '">' . $family->fullName() . '</a>';
}
} | php | private function familyQuery(string $type): string
{
$row = DB::table('families')
->where('f_file', '=', $this->tree->id())
->orderBy('f_numchil', 'desc')
->first();
if ($row === null) {
return '';
}
/** @var Family $family */
$family = Family::rowMapper()($row);
if (!$family->canShow()) {
return I18N::translate('This information is private and cannot be shown.');
}
switch ($type) {
default:
case 'full':
return $family->formatList();
case 'size':
return I18N::number((int) $row->f_numchil);
case 'name':
return '<a href="' . e($family->url()) . '">' . $family->fullName() . '</a>';
}
} | [
"private",
"function",
"familyQuery",
"(",
"string",
"$",
"type",
")",
":",
"string",
"{",
"$",
"row",
"=",
"DB",
"::",
"table",
"(",
"'families'",
")",
"->",
"where",
"(",
"'f_file'",
",",
"'='",
",",
"$",
"this",
"->",
"tree",
"->",
"id",
"(",
")",
")",
"->",
"orderBy",
"(",
"'f_numchil'",
",",
"'desc'",
")",
"->",
"first",
"(",
")",
";",
"if",
"(",
"$",
"row",
"===",
"null",
")",
"{",
"return",
"''",
";",
"}",
"/** @var Family $family */",
"$",
"family",
"=",
"Family",
"::",
"rowMapper",
"(",
")",
"(",
"$",
"row",
")",
";",
"if",
"(",
"!",
"$",
"family",
"->",
"canShow",
"(",
")",
")",
"{",
"return",
"I18N",
"::",
"translate",
"(",
"'This information is private and cannot be shown.'",
")",
";",
"}",
"switch",
"(",
"$",
"type",
")",
"{",
"default",
":",
"case",
"'full'",
":",
"return",
"$",
"family",
"->",
"formatList",
"(",
")",
";",
"case",
"'size'",
":",
"return",
"I18N",
"::",
"number",
"(",
"(",
"int",
")",
"$",
"row",
"->",
"f_numchil",
")",
";",
"case",
"'name'",
":",
"return",
"'<a href=\"'",
".",
"e",
"(",
"$",
"family",
"->",
"url",
"(",
")",
")",
".",
"'\">'",
".",
"$",
"family",
"->",
"fullName",
"(",
")",
".",
"'</a>'",
";",
"}",
"}"
] | General query on family.
@param string $type
@return string | [
"General",
"query",
"on",
"family",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Statistics/Repository/FamilyRepository.php#L66-L95 | train |
fisharebest/webtrees | app/Statistics/Repository/FamilyRepository.php | FamilyRepository.topTenGrandFamilyQuery | private function topTenGrandFamilyQuery(int $total): array
{
return DB::table('families')
->join('link AS children', static function (JoinClause $join): void {
$join
->on('children.l_from', '=', 'f_id')
->on('children.l_file', '=', 'f_file')
->where('children.l_type', '=', 'CHIL');
})->join('link AS mchildren', static function (JoinClause $join): void {
$join
->on('mchildren.l_file', '=', 'children.l_file')
->on('mchildren.l_from', '=', 'children.l_to')
->where('mchildren.l_type', '=', 'FAMS');
})->join('link AS gchildren', static function (JoinClause $join): void {
$join
->on('gchildren.l_file', '=', 'mchildren.l_file')
->on('gchildren.l_from', '=', 'mchildren.l_to')
->where('gchildren.l_type', '=', 'CHIL');
})
->where('f_file', '=', $this->tree->id())
->groupBy(['f_id', 'f_file'])
->orderBy(DB::raw('COUNT(*)'), 'DESC')
->select('families.*')
->limit($total)
->get()
->map(Family::rowMapper())
->filter(GedcomRecord::accessFilter())
->map(static function (Family $family): array {
$count = 0;
foreach ($family->children() as $child) {
foreach ($child->spouseFamilies() as $spouse_family) {
$count += $spouse_family->children()->count();
}
}
return [
'family' => $family,
'count' => $count,
];
})
->all();
} | php | private function topTenGrandFamilyQuery(int $total): array
{
return DB::table('families')
->join('link AS children', static function (JoinClause $join): void {
$join
->on('children.l_from', '=', 'f_id')
->on('children.l_file', '=', 'f_file')
->where('children.l_type', '=', 'CHIL');
})->join('link AS mchildren', static function (JoinClause $join): void {
$join
->on('mchildren.l_file', '=', 'children.l_file')
->on('mchildren.l_from', '=', 'children.l_to')
->where('mchildren.l_type', '=', 'FAMS');
})->join('link AS gchildren', static function (JoinClause $join): void {
$join
->on('gchildren.l_file', '=', 'mchildren.l_file')
->on('gchildren.l_from', '=', 'mchildren.l_to')
->where('gchildren.l_type', '=', 'CHIL');
})
->where('f_file', '=', $this->tree->id())
->groupBy(['f_id', 'f_file'])
->orderBy(DB::raw('COUNT(*)'), 'DESC')
->select('families.*')
->limit($total)
->get()
->map(Family::rowMapper())
->filter(GedcomRecord::accessFilter())
->map(static function (Family $family): array {
$count = 0;
foreach ($family->children() as $child) {
foreach ($child->spouseFamilies() as $spouse_family) {
$count += $spouse_family->children()->count();
}
}
return [
'family' => $family,
'count' => $count,
];
})
->all();
} | [
"private",
"function",
"topTenGrandFamilyQuery",
"(",
"int",
"$",
"total",
")",
":",
"array",
"{",
"return",
"DB",
"::",
"table",
"(",
"'families'",
")",
"->",
"join",
"(",
"'link AS children'",
",",
"static",
"function",
"(",
"JoinClause",
"$",
"join",
")",
":",
"void",
"{",
"$",
"join",
"->",
"on",
"(",
"'children.l_from'",
",",
"'='",
",",
"'f_id'",
")",
"->",
"on",
"(",
"'children.l_file'",
",",
"'='",
",",
"'f_file'",
")",
"->",
"where",
"(",
"'children.l_type'",
",",
"'='",
",",
"'CHIL'",
")",
";",
"}",
")",
"->",
"join",
"(",
"'link AS mchildren'",
",",
"static",
"function",
"(",
"JoinClause",
"$",
"join",
")",
":",
"void",
"{",
"$",
"join",
"->",
"on",
"(",
"'mchildren.l_file'",
",",
"'='",
",",
"'children.l_file'",
")",
"->",
"on",
"(",
"'mchildren.l_from'",
",",
"'='",
",",
"'children.l_to'",
")",
"->",
"where",
"(",
"'mchildren.l_type'",
",",
"'='",
",",
"'FAMS'",
")",
";",
"}",
")",
"->",
"join",
"(",
"'link AS gchildren'",
",",
"static",
"function",
"(",
"JoinClause",
"$",
"join",
")",
":",
"void",
"{",
"$",
"join",
"->",
"on",
"(",
"'gchildren.l_file'",
",",
"'='",
",",
"'mchildren.l_file'",
")",
"->",
"on",
"(",
"'gchildren.l_from'",
",",
"'='",
",",
"'mchildren.l_to'",
")",
"->",
"where",
"(",
"'gchildren.l_type'",
",",
"'='",
",",
"'CHIL'",
")",
";",
"}",
")",
"->",
"where",
"(",
"'f_file'",
",",
"'='",
",",
"$",
"this",
"->",
"tree",
"->",
"id",
"(",
")",
")",
"->",
"groupBy",
"(",
"[",
"'f_id'",
",",
"'f_file'",
"]",
")",
"->",
"orderBy",
"(",
"DB",
"::",
"raw",
"(",
"'COUNT(*)'",
")",
",",
"'DESC'",
")",
"->",
"select",
"(",
"'families.*'",
")",
"->",
"limit",
"(",
"$",
"total",
")",
"->",
"get",
"(",
")",
"->",
"map",
"(",
"Family",
"::",
"rowMapper",
"(",
")",
")",
"->",
"filter",
"(",
"GedcomRecord",
"::",
"accessFilter",
"(",
")",
")",
"->",
"map",
"(",
"static",
"function",
"(",
"Family",
"$",
"family",
")",
":",
"array",
"{",
"$",
"count",
"=",
"0",
";",
"foreach",
"(",
"$",
"family",
"->",
"children",
"(",
")",
"as",
"$",
"child",
")",
"{",
"foreach",
"(",
"$",
"child",
"->",
"spouseFamilies",
"(",
")",
"as",
"$",
"spouse_family",
")",
"{",
"$",
"count",
"+=",
"$",
"spouse_family",
"->",
"children",
"(",
")",
"->",
"count",
"(",
")",
";",
"}",
"}",
"return",
"[",
"'family'",
"=>",
"$",
"family",
",",
"'count'",
"=>",
"$",
"count",
",",
"]",
";",
"}",
")",
"->",
"all",
"(",
")",
";",
"}"
] | Find the couple with the most grandchildren.
@param int $total
@return array | [
"Find",
"the",
"couple",
"with",
"the",
"most",
"grandchildren",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Statistics/Repository/FamilyRepository.php#L134-L175 | train |
fisharebest/webtrees | app/Statistics/Repository/FamilyRepository.php | FamilyRepository.ageBetweenSiblingsQuery | private function ageBetweenSiblingsQuery(int $total): array
{
$prefix = DB::connection()->getTablePrefix();
return DB::table('link AS link1')
->join('link AS link2', static function (JoinClause $join): void {
$join
->on('link2.l_from', '=', 'link1.l_from')
->on('link2.l_type', '=', 'link1.l_type')
->on('link2.l_file', '=', 'link1.l_file');
})
->join('dates AS child1', static function (JoinClause $join): void {
$join
->on('child1.d_gid', '=', 'link1.l_to')
->on('child1.d_file', '=', 'link1.l_file')
->where('child1.d_fact', '=', 'BIRT')
->where('child1.d_julianday1', '<>', 0);
})
->join('dates AS child2', static function (JoinClause $join): void {
$join
->on('child2.d_gid', '=', 'link2.l_to')
->on('child2.d_file', '=', 'link2.l_file')
->where('child2.d_fact', '=', 'BIRT')
->whereColumn('child2.d_julianday2', '>', 'child1.d_julianday1');
})
->where('link1.l_type', '=', 'CHIL')
->where('link1.l_file', '=', $this->tree->id())
->distinct()
->select(['link1.l_from AS family', 'link1.l_to AS ch1', 'link2.l_to AS ch2', DB::raw($prefix . 'child2.d_julianday2 - ' . $prefix . 'child1.d_julianday1 AS age')])
->orderBy('age', 'DESC')
->take($total)
->get()
->all();
} | php | private function ageBetweenSiblingsQuery(int $total): array
{
$prefix = DB::connection()->getTablePrefix();
return DB::table('link AS link1')
->join('link AS link2', static function (JoinClause $join): void {
$join
->on('link2.l_from', '=', 'link1.l_from')
->on('link2.l_type', '=', 'link1.l_type')
->on('link2.l_file', '=', 'link1.l_file');
})
->join('dates AS child1', static function (JoinClause $join): void {
$join
->on('child1.d_gid', '=', 'link1.l_to')
->on('child1.d_file', '=', 'link1.l_file')
->where('child1.d_fact', '=', 'BIRT')
->where('child1.d_julianday1', '<>', 0);
})
->join('dates AS child2', static function (JoinClause $join): void {
$join
->on('child2.d_gid', '=', 'link2.l_to')
->on('child2.d_file', '=', 'link2.l_file')
->where('child2.d_fact', '=', 'BIRT')
->whereColumn('child2.d_julianday2', '>', 'child1.d_julianday1');
})
->where('link1.l_type', '=', 'CHIL')
->where('link1.l_file', '=', $this->tree->id())
->distinct()
->select(['link1.l_from AS family', 'link1.l_to AS ch1', 'link2.l_to AS ch2', DB::raw($prefix . 'child2.d_julianday2 - ' . $prefix . 'child1.d_julianday1 AS age')])
->orderBy('age', 'DESC')
->take($total)
->get()
->all();
} | [
"private",
"function",
"ageBetweenSiblingsQuery",
"(",
"int",
"$",
"total",
")",
":",
"array",
"{",
"$",
"prefix",
"=",
"DB",
"::",
"connection",
"(",
")",
"->",
"getTablePrefix",
"(",
")",
";",
"return",
"DB",
"::",
"table",
"(",
"'link AS link1'",
")",
"->",
"join",
"(",
"'link AS link2'",
",",
"static",
"function",
"(",
"JoinClause",
"$",
"join",
")",
":",
"void",
"{",
"$",
"join",
"->",
"on",
"(",
"'link2.l_from'",
",",
"'='",
",",
"'link1.l_from'",
")",
"->",
"on",
"(",
"'link2.l_type'",
",",
"'='",
",",
"'link1.l_type'",
")",
"->",
"on",
"(",
"'link2.l_file'",
",",
"'='",
",",
"'link1.l_file'",
")",
";",
"}",
")",
"->",
"join",
"(",
"'dates AS child1'",
",",
"static",
"function",
"(",
"JoinClause",
"$",
"join",
")",
":",
"void",
"{",
"$",
"join",
"->",
"on",
"(",
"'child1.d_gid'",
",",
"'='",
",",
"'link1.l_to'",
")",
"->",
"on",
"(",
"'child1.d_file'",
",",
"'='",
",",
"'link1.l_file'",
")",
"->",
"where",
"(",
"'child1.d_fact'",
",",
"'='",
",",
"'BIRT'",
")",
"->",
"where",
"(",
"'child1.d_julianday1'",
",",
"'<>'",
",",
"0",
")",
";",
"}",
")",
"->",
"join",
"(",
"'dates AS child2'",
",",
"static",
"function",
"(",
"JoinClause",
"$",
"join",
")",
":",
"void",
"{",
"$",
"join",
"->",
"on",
"(",
"'child2.d_gid'",
",",
"'='",
",",
"'link2.l_to'",
")",
"->",
"on",
"(",
"'child2.d_file'",
",",
"'='",
",",
"'link2.l_file'",
")",
"->",
"where",
"(",
"'child2.d_fact'",
",",
"'='",
",",
"'BIRT'",
")",
"->",
"whereColumn",
"(",
"'child2.d_julianday2'",
",",
"'>'",
",",
"'child1.d_julianday1'",
")",
";",
"}",
")",
"->",
"where",
"(",
"'link1.l_type'",
",",
"'='",
",",
"'CHIL'",
")",
"->",
"where",
"(",
"'link1.l_file'",
",",
"'='",
",",
"$",
"this",
"->",
"tree",
"->",
"id",
"(",
")",
")",
"->",
"distinct",
"(",
")",
"->",
"select",
"(",
"[",
"'link1.l_from AS family'",
",",
"'link1.l_to AS ch1'",
",",
"'link2.l_to AS ch2'",
",",
"DB",
"::",
"raw",
"(",
"$",
"prefix",
".",
"'child2.d_julianday2 - '",
".",
"$",
"prefix",
".",
"'child1.d_julianday1 AS age'",
")",
"]",
")",
"->",
"orderBy",
"(",
"'age'",
",",
"'DESC'",
")",
"->",
"take",
"(",
"$",
"total",
")",
"->",
"get",
"(",
")",
"->",
"all",
"(",
")",
";",
"}"
] | Returns the ages between siblings.
@param int $total The total number of records to query
@return array | [
"Returns",
"the",
"ages",
"between",
"siblings",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Statistics/Repository/FamilyRepository.php#L292-L325 | train |
fisharebest/webtrees | app/Statistics/Repository/FamilyRepository.php | FamilyRepository.calculateAge | private function calculateAge(int $age): string
{
if ((int) ($age / 365.25) > 0) {
$result = (int) ($age / 365.25) . 'y';
} elseif ((int) ($age / 30.4375) > 0) {
$result = (int) ($age / 30.4375) . 'm';
} else {
$result = $age . 'd';
}
return FunctionsDate::getAgeAtEvent($result);
} | php | private function calculateAge(int $age): string
{
if ((int) ($age / 365.25) > 0) {
$result = (int) ($age / 365.25) . 'y';
} elseif ((int) ($age / 30.4375) > 0) {
$result = (int) ($age / 30.4375) . 'm';
} else {
$result = $age . 'd';
}
return FunctionsDate::getAgeAtEvent($result);
} | [
"private",
"function",
"calculateAge",
"(",
"int",
"$",
"age",
")",
":",
"string",
"{",
"if",
"(",
"(",
"int",
")",
"(",
"$",
"age",
"/",
"365.25",
")",
">",
"0",
")",
"{",
"$",
"result",
"=",
"(",
"int",
")",
"(",
"$",
"age",
"/",
"365.25",
")",
".",
"'y'",
";",
"}",
"elseif",
"(",
"(",
"int",
")",
"(",
"$",
"age",
"/",
"30.4375",
")",
">",
"0",
")",
"{",
"$",
"result",
"=",
"(",
"int",
")",
"(",
"$",
"age",
"/",
"30.4375",
")",
".",
"'m'",
";",
"}",
"else",
"{",
"$",
"result",
"=",
"$",
"age",
".",
"'d'",
";",
"}",
"return",
"FunctionsDate",
"::",
"getAgeAtEvent",
"(",
"$",
"result",
")",
";",
"}"
] | Returns the calculated age the time of event.
@param int $age The age from the database record
@return string | [
"Returns",
"the",
"calculated",
"age",
"the",
"time",
"of",
"event",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Statistics/Repository/FamilyRepository.php#L334-L345 | train |
fisharebest/webtrees | app/Statistics/Repository/FamilyRepository.php | FamilyRepository.topAgeBetweenSiblingsFullName | public function topAgeBetweenSiblingsFullName(int $total = 10): string
{
$record = $this->ageBetweenSiblingsNoList($total);
if (empty($record)) {
return I18N::translate('This information is not available.');
}
return view('statistics/families/top10-nolist-age', [
'record' => $record,
]);
} | php | public function topAgeBetweenSiblingsFullName(int $total = 10): string
{
$record = $this->ageBetweenSiblingsNoList($total);
if (empty($record)) {
return I18N::translate('This information is not available.');
}
return view('statistics/families/top10-nolist-age', [
'record' => $record,
]);
} | [
"public",
"function",
"topAgeBetweenSiblingsFullName",
"(",
"int",
"$",
"total",
"=",
"10",
")",
":",
"string",
"{",
"$",
"record",
"=",
"$",
"this",
"->",
"ageBetweenSiblingsNoList",
"(",
"$",
"total",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"record",
")",
")",
"{",
"return",
"I18N",
"::",
"translate",
"(",
"'This information is not available.'",
")",
";",
"}",
"return",
"view",
"(",
"'statistics/families/top10-nolist-age'",
",",
"[",
"'record'",
"=>",
"$",
"record",
",",
"]",
")",
";",
"}"
] | Find the name of siblings with the widest age gap.
@param int $total
@return string | [
"Find",
"the",
"name",
"of",
"siblings",
"with",
"the",
"widest",
"age",
"gap",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Statistics/Repository/FamilyRepository.php#L505-L516 | train |
fisharebest/webtrees | app/Statistics/Repository/FamilyRepository.php | FamilyRepository.topAgeBetweenSiblingsList | public function topAgeBetweenSiblingsList(int $total = 10, string $one = ''): string
{
$records = $this->ageBetweenSiblingsList($total, (bool) $one);
return view('statistics/families/top10-list-age', [
'records' => $records,
]);
} | php | public function topAgeBetweenSiblingsList(int $total = 10, string $one = ''): string
{
$records = $this->ageBetweenSiblingsList($total, (bool) $one);
return view('statistics/families/top10-list-age', [
'records' => $records,
]);
} | [
"public",
"function",
"topAgeBetweenSiblingsList",
"(",
"int",
"$",
"total",
"=",
"10",
",",
"string",
"$",
"one",
"=",
"''",
")",
":",
"string",
"{",
"$",
"records",
"=",
"$",
"this",
"->",
"ageBetweenSiblingsList",
"(",
"$",
"total",
",",
"(",
"bool",
")",
"$",
"one",
")",
";",
"return",
"view",
"(",
"'statistics/families/top10-list-age'",
",",
"[",
"'records'",
"=>",
"$",
"records",
",",
"]",
")",
";",
"}"
] | Find the siblings with the widest age gaps.
@param int $total
@param string $one
@return string | [
"Find",
"the",
"siblings",
"with",
"the",
"widest",
"age",
"gaps",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Statistics/Repository/FamilyRepository.php#L526-L533 | train |
fisharebest/webtrees | app/Statistics/Repository/FamilyRepository.php | FamilyRepository.totalChildren | public function totalChildren(): string
{
$total = (int) DB::table('families')
->where('f_file', '=', $this->tree->id())
->sum('f_numchil');
return I18N::number($total);
} | php | public function totalChildren(): string
{
$total = (int) DB::table('families')
->where('f_file', '=', $this->tree->id())
->sum('f_numchil');
return I18N::number($total);
} | [
"public",
"function",
"totalChildren",
"(",
")",
":",
"string",
"{",
"$",
"total",
"=",
"(",
"int",
")",
"DB",
"::",
"table",
"(",
"'families'",
")",
"->",
"where",
"(",
"'f_file'",
",",
"'='",
",",
"$",
"this",
"->",
"tree",
"->",
"id",
"(",
")",
")",
"->",
"sum",
"(",
"'f_numchil'",
")",
";",
"return",
"I18N",
"::",
"number",
"(",
"$",
"total",
")",
";",
"}"
] | Count the total children.
@return string | [
"Count",
"the",
"total",
"children",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Statistics/Repository/FamilyRepository.php#L581-L588 | train |
fisharebest/webtrees | app/Statistics/Repository/FamilyRepository.php | FamilyRepository.averageChildren | public function averageChildren(): string
{
$average = (float) DB::table('families')
->where('f_file', '=', $this->tree->id())
->avg('f_numchil');
return I18N::number($average, 2);
} | php | public function averageChildren(): string
{
$average = (float) DB::table('families')
->where('f_file', '=', $this->tree->id())
->avg('f_numchil');
return I18N::number($average, 2);
} | [
"public",
"function",
"averageChildren",
"(",
")",
":",
"string",
"{",
"$",
"average",
"=",
"(",
"float",
")",
"DB",
"::",
"table",
"(",
"'families'",
")",
"->",
"where",
"(",
"'f_file'",
",",
"'='",
",",
"$",
"this",
"->",
"tree",
"->",
"id",
"(",
")",
")",
"->",
"avg",
"(",
"'f_numchil'",
")",
";",
"return",
"I18N",
"::",
"number",
"(",
"$",
"average",
",",
"2",
")",
";",
"}"
] | Find the average number of children in families.
@return string | [
"Find",
"the",
"average",
"number",
"of",
"children",
"in",
"families",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Statistics/Repository/FamilyRepository.php#L595-L602 | train |
fisharebest/webtrees | app/Statistics/Repository/FamilyRepository.php | FamilyRepository.topTenFamilyQuery | private function topTenFamilyQuery(int $total): array
{
return DB::table('families')
->where('f_file', '=', $this->tree->id())
->orderBy('f_numchil', 'DESC')
->limit($total)
->get()
->map(Family::rowMapper())
->filter(GedcomRecord::accessFilter())
->map(static function (Family $family): array {
return [
'family' => $family,
'count' => $family->numberOfChildren(),
];
})
->all();
} | php | private function topTenFamilyQuery(int $total): array
{
return DB::table('families')
->where('f_file', '=', $this->tree->id())
->orderBy('f_numchil', 'DESC')
->limit($total)
->get()
->map(Family::rowMapper())
->filter(GedcomRecord::accessFilter())
->map(static function (Family $family): array {
return [
'family' => $family,
'count' => $family->numberOfChildren(),
];
})
->all();
} | [
"private",
"function",
"topTenFamilyQuery",
"(",
"int",
"$",
"total",
")",
":",
"array",
"{",
"return",
"DB",
"::",
"table",
"(",
"'families'",
")",
"->",
"where",
"(",
"'f_file'",
",",
"'='",
",",
"$",
"this",
"->",
"tree",
"->",
"id",
"(",
")",
")",
"->",
"orderBy",
"(",
"'f_numchil'",
",",
"'DESC'",
")",
"->",
"limit",
"(",
"$",
"total",
")",
"->",
"get",
"(",
")",
"->",
"map",
"(",
"Family",
"::",
"rowMapper",
"(",
")",
")",
"->",
"filter",
"(",
"GedcomRecord",
"::",
"accessFilter",
"(",
")",
")",
"->",
"map",
"(",
"static",
"function",
"(",
"Family",
"$",
"family",
")",
":",
"array",
"{",
"return",
"[",
"'family'",
"=>",
"$",
"family",
",",
"'count'",
"=>",
"$",
"family",
"->",
"numberOfChildren",
"(",
")",
",",
"]",
";",
"}",
")",
"->",
"all",
"(",
")",
";",
"}"
] | General query on families.
@param int $total
@return array | [
"General",
"query",
"on",
"families",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Statistics/Repository/FamilyRepository.php#L611-L627 | train |
fisharebest/webtrees | app/Statistics/Repository/FamilyRepository.php | FamilyRepository.topTenLargestFamily | public function topTenLargestFamily(int $total = 10): string
{
$records = $this->topTenFamilyQuery($total);
return view('statistics/families/top10-nolist', [
'records' => $records,
]);
} | php | public function topTenLargestFamily(int $total = 10): string
{
$records = $this->topTenFamilyQuery($total);
return view('statistics/families/top10-nolist', [
'records' => $records,
]);
} | [
"public",
"function",
"topTenLargestFamily",
"(",
"int",
"$",
"total",
"=",
"10",
")",
":",
"string",
"{",
"$",
"records",
"=",
"$",
"this",
"->",
"topTenFamilyQuery",
"(",
"$",
"total",
")",
";",
"return",
"view",
"(",
"'statistics/families/top10-nolist'",
",",
"[",
"'records'",
"=>",
"$",
"records",
",",
"]",
")",
";",
"}"
] | The the families with the most children.
@param int $total
@return string | [
"The",
"the",
"families",
"with",
"the",
"most",
"children",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Statistics/Repository/FamilyRepository.php#L636-L643 | train |
fisharebest/webtrees | app/Statistics/Repository/FamilyRepository.php | FamilyRepository.topTenLargestFamilyList | public function topTenLargestFamilyList(int $total = 10): string
{
$records = $this->topTenFamilyQuery($total);
return view('statistics/families/top10-list', [
'records' => $records,
]);
} | php | public function topTenLargestFamilyList(int $total = 10): string
{
$records = $this->topTenFamilyQuery($total);
return view('statistics/families/top10-list', [
'records' => $records,
]);
} | [
"public",
"function",
"topTenLargestFamilyList",
"(",
"int",
"$",
"total",
"=",
"10",
")",
":",
"string",
"{",
"$",
"records",
"=",
"$",
"this",
"->",
"topTenFamilyQuery",
"(",
"$",
"total",
")",
";",
"return",
"view",
"(",
"'statistics/families/top10-list'",
",",
"[",
"'records'",
"=>",
"$",
"records",
",",
"]",
")",
";",
"}"
] | Find the families with the most children.
@param int $total
@return string | [
"Find",
"the",
"families",
"with",
"the",
"most",
"children",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Statistics/Repository/FamilyRepository.php#L652-L659 | train |
fisharebest/webtrees | app/Statistics/Repository/FamilyRepository.php | FamilyRepository.totalMarriedMales | public function totalMarriedMales(): string
{
$n = (int) DB::table('families')
->where('f_file', '=', $this->tree->id())
->where('f_gedcom', 'LIKE', "%\n1 MARR%")
->distinct()
->count('f_husb');
return I18N::number($n);
} | php | public function totalMarriedMales(): string
{
$n = (int) DB::table('families')
->where('f_file', '=', $this->tree->id())
->where('f_gedcom', 'LIKE', "%\n1 MARR%")
->distinct()
->count('f_husb');
return I18N::number($n);
} | [
"public",
"function",
"totalMarriedMales",
"(",
")",
":",
"string",
"{",
"$",
"n",
"=",
"(",
"int",
")",
"DB",
"::",
"table",
"(",
"'families'",
")",
"->",
"where",
"(",
"'f_file'",
",",
"'='",
",",
"$",
"this",
"->",
"tree",
"->",
"id",
"(",
")",
")",
"->",
"where",
"(",
"'f_gedcom'",
",",
"'LIKE'",
",",
"\"%\\n1 MARR%\"",
")",
"->",
"distinct",
"(",
")",
"->",
"count",
"(",
"'f_husb'",
")",
";",
"return",
"I18N",
"::",
"number",
"(",
"$",
"n",
")",
";",
"}"
] | Number of husbands.
@return string | [
"Number",
"of",
"husbands",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Statistics/Repository/FamilyRepository.php#L750-L759 | train |
fisharebest/webtrees | app/Statistics/Repository/FamilyRepository.php | FamilyRepository.ageBetweenSpousesQuery | private function ageBetweenSpousesQuery(string $age_dir, int $total): array
{
$prefix = DB::connection()->getTablePrefix();
$query = DB::table('families')
->where('f_file', '=', $this->tree->id())
->join('dates AS wife', static function (JoinClause $join): void {
$join
->on('wife.d_gid', '=', 'f_wife')
->on('wife.d_file', '=', 'f_file')
->where('wife.d_fact', '=', 'BIRT')
->where('wife.d_julianday1', '<>', 0);
})
->join('dates AS husb', static function (JoinClause $join): void {
$join
->on('husb.d_gid', '=', 'f_husb')
->on('husb.d_file', '=', 'f_file')
->where('husb.d_fact', '=', 'BIRT')
->where('husb.d_julianday1', '<>', 0);
});
if ($age_dir === 'DESC') {
$query
->whereColumn('wife.d_julianday1', '>=', 'husb.d_julianday1')
->orderBy(DB::raw('MIN(' . $prefix . 'wife.d_julianday1) - MIN(' . $prefix . 'husb.d_julianday1)'), 'DESC');
} else {
$query
->whereColumn('husb.d_julianday1', '>=', 'wife.d_julianday1')
->orderBy(DB::raw('MIN(' . $prefix . 'husb.d_julianday1) - MIN(' . $prefix . 'wife.d_julianday1)'), 'DESC');
}
return $query
->groupBy(['f_id', 'f_file'])
->select('families.*')
->take($total)
->get()
->map(Family::rowMapper())
->filter(GedcomRecord::accessFilter())
->map(function (Family $family) use ($age_dir): array {
$husb_birt_jd = $family->husband()->getBirthDate()->minimumJulianDay();
$wife_birt_jd = $family->wife()->getBirthDate()->minimumJulianDay();
if ($age_dir === 'DESC') {
$diff = $wife_birt_jd - $husb_birt_jd;
} else {
$diff = $husb_birt_jd - $wife_birt_jd;
}
return [
'family' => $family,
'age' => $this->calculateAge($diff),
];
})
->all();
} | php | private function ageBetweenSpousesQuery(string $age_dir, int $total): array
{
$prefix = DB::connection()->getTablePrefix();
$query = DB::table('families')
->where('f_file', '=', $this->tree->id())
->join('dates AS wife', static function (JoinClause $join): void {
$join
->on('wife.d_gid', '=', 'f_wife')
->on('wife.d_file', '=', 'f_file')
->where('wife.d_fact', '=', 'BIRT')
->where('wife.d_julianday1', '<>', 0);
})
->join('dates AS husb', static function (JoinClause $join): void {
$join
->on('husb.d_gid', '=', 'f_husb')
->on('husb.d_file', '=', 'f_file')
->where('husb.d_fact', '=', 'BIRT')
->where('husb.d_julianday1', '<>', 0);
});
if ($age_dir === 'DESC') {
$query
->whereColumn('wife.d_julianday1', '>=', 'husb.d_julianday1')
->orderBy(DB::raw('MIN(' . $prefix . 'wife.d_julianday1) - MIN(' . $prefix . 'husb.d_julianday1)'), 'DESC');
} else {
$query
->whereColumn('husb.d_julianday1', '>=', 'wife.d_julianday1')
->orderBy(DB::raw('MIN(' . $prefix . 'husb.d_julianday1) - MIN(' . $prefix . 'wife.d_julianday1)'), 'DESC');
}
return $query
->groupBy(['f_id', 'f_file'])
->select('families.*')
->take($total)
->get()
->map(Family::rowMapper())
->filter(GedcomRecord::accessFilter())
->map(function (Family $family) use ($age_dir): array {
$husb_birt_jd = $family->husband()->getBirthDate()->minimumJulianDay();
$wife_birt_jd = $family->wife()->getBirthDate()->minimumJulianDay();
if ($age_dir === 'DESC') {
$diff = $wife_birt_jd - $husb_birt_jd;
} else {
$diff = $husb_birt_jd - $wife_birt_jd;
}
return [
'family' => $family,
'age' => $this->calculateAge($diff),
];
})
->all();
} | [
"private",
"function",
"ageBetweenSpousesQuery",
"(",
"string",
"$",
"age_dir",
",",
"int",
"$",
"total",
")",
":",
"array",
"{",
"$",
"prefix",
"=",
"DB",
"::",
"connection",
"(",
")",
"->",
"getTablePrefix",
"(",
")",
";",
"$",
"query",
"=",
"DB",
"::",
"table",
"(",
"'families'",
")",
"->",
"where",
"(",
"'f_file'",
",",
"'='",
",",
"$",
"this",
"->",
"tree",
"->",
"id",
"(",
")",
")",
"->",
"join",
"(",
"'dates AS wife'",
",",
"static",
"function",
"(",
"JoinClause",
"$",
"join",
")",
":",
"void",
"{",
"$",
"join",
"->",
"on",
"(",
"'wife.d_gid'",
",",
"'='",
",",
"'f_wife'",
")",
"->",
"on",
"(",
"'wife.d_file'",
",",
"'='",
",",
"'f_file'",
")",
"->",
"where",
"(",
"'wife.d_fact'",
",",
"'='",
",",
"'BIRT'",
")",
"->",
"where",
"(",
"'wife.d_julianday1'",
",",
"'<>'",
",",
"0",
")",
";",
"}",
")",
"->",
"join",
"(",
"'dates AS husb'",
",",
"static",
"function",
"(",
"JoinClause",
"$",
"join",
")",
":",
"void",
"{",
"$",
"join",
"->",
"on",
"(",
"'husb.d_gid'",
",",
"'='",
",",
"'f_husb'",
")",
"->",
"on",
"(",
"'husb.d_file'",
",",
"'='",
",",
"'f_file'",
")",
"->",
"where",
"(",
"'husb.d_fact'",
",",
"'='",
",",
"'BIRT'",
")",
"->",
"where",
"(",
"'husb.d_julianday1'",
",",
"'<>'",
",",
"0",
")",
";",
"}",
")",
";",
"if",
"(",
"$",
"age_dir",
"===",
"'DESC'",
")",
"{",
"$",
"query",
"->",
"whereColumn",
"(",
"'wife.d_julianday1'",
",",
"'>='",
",",
"'husb.d_julianday1'",
")",
"->",
"orderBy",
"(",
"DB",
"::",
"raw",
"(",
"'MIN('",
".",
"$",
"prefix",
".",
"'wife.d_julianday1) - MIN('",
".",
"$",
"prefix",
".",
"'husb.d_julianday1)'",
")",
",",
"'DESC'",
")",
";",
"}",
"else",
"{",
"$",
"query",
"->",
"whereColumn",
"(",
"'husb.d_julianday1'",
",",
"'>='",
",",
"'wife.d_julianday1'",
")",
"->",
"orderBy",
"(",
"DB",
"::",
"raw",
"(",
"'MIN('",
".",
"$",
"prefix",
".",
"'husb.d_julianday1) - MIN('",
".",
"$",
"prefix",
".",
"'wife.d_julianday1)'",
")",
",",
"'DESC'",
")",
";",
"}",
"return",
"$",
"query",
"->",
"groupBy",
"(",
"[",
"'f_id'",
",",
"'f_file'",
"]",
")",
"->",
"select",
"(",
"'families.*'",
")",
"->",
"take",
"(",
"$",
"total",
")",
"->",
"get",
"(",
")",
"->",
"map",
"(",
"Family",
"::",
"rowMapper",
"(",
")",
")",
"->",
"filter",
"(",
"GedcomRecord",
"::",
"accessFilter",
"(",
")",
")",
"->",
"map",
"(",
"function",
"(",
"Family",
"$",
"family",
")",
"use",
"(",
"$",
"age_dir",
")",
":",
"array",
"{",
"$",
"husb_birt_jd",
"=",
"$",
"family",
"->",
"husband",
"(",
")",
"->",
"getBirthDate",
"(",
")",
"->",
"minimumJulianDay",
"(",
")",
";",
"$",
"wife_birt_jd",
"=",
"$",
"family",
"->",
"wife",
"(",
")",
"->",
"getBirthDate",
"(",
")",
"->",
"minimumJulianDay",
"(",
")",
";",
"if",
"(",
"$",
"age_dir",
"===",
"'DESC'",
")",
"{",
"$",
"diff",
"=",
"$",
"wife_birt_jd",
"-",
"$",
"husb_birt_jd",
";",
"}",
"else",
"{",
"$",
"diff",
"=",
"$",
"husb_birt_jd",
"-",
"$",
"wife_birt_jd",
";",
"}",
"return",
"[",
"'family'",
"=>",
"$",
"family",
",",
"'age'",
"=>",
"$",
"this",
"->",
"calculateAge",
"(",
"$",
"diff",
")",
",",
"]",
";",
"}",
")",
"->",
"all",
"(",
")",
";",
"}"
] | Find the ages between spouses.
@param string $age_dir
@param int $total
@return array | [
"Find",
"the",
"ages",
"between",
"spouses",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Statistics/Repository/FamilyRepository.php#L1252-L1306 | train |
fisharebest/webtrees | app/Statistics/Repository/FamilyRepository.php | FamilyRepository.statsDiv | public function statsDiv(string $color_from = null, string $color_to = null): string
{
return (new ChartDivorce($this->tree))
->chartDivorce($color_from, $color_to);
} | php | public function statsDiv(string $color_from = null, string $color_to = null): string
{
return (new ChartDivorce($this->tree))
->chartDivorce($color_from, $color_to);
} | [
"public",
"function",
"statsDiv",
"(",
"string",
"$",
"color_from",
"=",
"null",
",",
"string",
"$",
"color_to",
"=",
"null",
")",
":",
"string",
"{",
"return",
"(",
"new",
"ChartDivorce",
"(",
"$",
"this",
"->",
"tree",
")",
")",
"->",
"chartDivorce",
"(",
"$",
"color_from",
",",
"$",
"color_to",
")",
";",
"}"
] | General divorce query.
@param string|null $color_from
@param string|null $color_to
@return string | [
"General",
"divorce",
"query",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Statistics/Repository/FamilyRepository.php#L1731-L1735 | train |
fisharebest/webtrees | app/Menu.php | Menu.bootstrap4 | public function bootstrap4(): string
{
if (!empty($this->submenus)) {
$submenus = '';
foreach ($this->submenus as $submenu) {
$attrs = '';
foreach ($submenu->attrs as $key => $value) {
$attrs .= ' ' . $key . '="' . e($value) . '"';
}
$class = trim('dropdown-item ' . $submenu->class);
$submenus .= '<a class="' . $class . '" href="' . e($submenu->link) . '"' . $attrs . '>' . $submenu->label . '</a>';
}
$class = trim('nav-item dropdown ' . $this->class);
return
'<li class="' . $class . '">' .
'<a href="#" class="nav-link dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">' .
$this->label .
'<span class="caret"></span></a>' .
'<div class="dropdown-menu" role="menu">' .
$submenus .
'</div>' .
'</li>';
}
$attrs = '';
foreach ($this->attrs as $key => $value) {
$attrs .= ' ' . $key . '="' . e($value) . '"';
}
$class = trim('nav-item ' . $this->class);
return '<li class="' . $class . '"><a class="nav-link" href="' . e($this->link) . '"' . $attrs . '>' . $this->label . '</a></li>';
} | php | public function bootstrap4(): string
{
if (!empty($this->submenus)) {
$submenus = '';
foreach ($this->submenus as $submenu) {
$attrs = '';
foreach ($submenu->attrs as $key => $value) {
$attrs .= ' ' . $key . '="' . e($value) . '"';
}
$class = trim('dropdown-item ' . $submenu->class);
$submenus .= '<a class="' . $class . '" href="' . e($submenu->link) . '"' . $attrs . '>' . $submenu->label . '</a>';
}
$class = trim('nav-item dropdown ' . $this->class);
return
'<li class="' . $class . '">' .
'<a href="#" class="nav-link dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">' .
$this->label .
'<span class="caret"></span></a>' .
'<div class="dropdown-menu" role="menu">' .
$submenus .
'</div>' .
'</li>';
}
$attrs = '';
foreach ($this->attrs as $key => $value) {
$attrs .= ' ' . $key . '="' . e($value) . '"';
}
$class = trim('nav-item ' . $this->class);
return '<li class="' . $class . '"><a class="nav-link" href="' . e($this->link) . '"' . $attrs . '>' . $this->label . '</a></li>';
} | [
"public",
"function",
"bootstrap4",
"(",
")",
":",
"string",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"submenus",
")",
")",
"{",
"$",
"submenus",
"=",
"''",
";",
"foreach",
"(",
"$",
"this",
"->",
"submenus",
"as",
"$",
"submenu",
")",
"{",
"$",
"attrs",
"=",
"''",
";",
"foreach",
"(",
"$",
"submenu",
"->",
"attrs",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"attrs",
".=",
"' '",
".",
"$",
"key",
".",
"'=\"'",
".",
"e",
"(",
"$",
"value",
")",
".",
"'\"'",
";",
"}",
"$",
"class",
"=",
"trim",
"(",
"'dropdown-item '",
".",
"$",
"submenu",
"->",
"class",
")",
";",
"$",
"submenus",
".=",
"'<a class=\"'",
".",
"$",
"class",
".",
"'\" href=\"'",
".",
"e",
"(",
"$",
"submenu",
"->",
"link",
")",
".",
"'\"'",
".",
"$",
"attrs",
".",
"'>'",
".",
"$",
"submenu",
"->",
"label",
".",
"'</a>'",
";",
"}",
"$",
"class",
"=",
"trim",
"(",
"'nav-item dropdown '",
".",
"$",
"this",
"->",
"class",
")",
";",
"return",
"'<li class=\"'",
".",
"$",
"class",
".",
"'\">'",
".",
"'<a href=\"#\" class=\"nav-link dropdown-toggle\" data-toggle=\"dropdown\" role=\"button\" aria-expanded=\"false\">'",
".",
"$",
"this",
"->",
"label",
".",
"'<span class=\"caret\"></span></a>'",
".",
"'<div class=\"dropdown-menu\" role=\"menu\">'",
".",
"$",
"submenus",
".",
"'</div>'",
".",
"'</li>'",
";",
"}",
"$",
"attrs",
"=",
"''",
";",
"foreach",
"(",
"$",
"this",
"->",
"attrs",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"attrs",
".=",
"' '",
".",
"$",
"key",
".",
"'=\"'",
".",
"e",
"(",
"$",
"value",
")",
".",
"'\"'",
";",
"}",
"$",
"class",
"=",
"trim",
"(",
"'nav-item '",
".",
"$",
"this",
"->",
"class",
")",
";",
"return",
"'<li class=\"'",
".",
"$",
"class",
".",
"'\"><a class=\"nav-link\" href=\"'",
".",
"e",
"(",
"$",
"this",
"->",
"link",
")",
".",
"'\"'",
".",
"$",
"attrs",
".",
"'>'",
".",
"$",
"this",
"->",
"label",
".",
"'</a></li>'",
";",
"}"
] | Render this menu using Bootstrap4 markup
@return string | [
"Render",
"this",
"menu",
"using",
"Bootstrap4",
"markup"
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Menu.php#L64-L99 | train |
fisharebest/webtrees | app/Module/LifespansChartModule.php | LifespansChartModule.chartUrl | public function chartUrl(Individual $individual, array $parameters = []): string
{
return route('module', [
'module' => $this->name(),
'action' => 'Chart',
'xrefs[]' => $individual->xref(),
'ged' => $individual->tree()->name(),
] + $parameters);
} | php | public function chartUrl(Individual $individual, array $parameters = []): string
{
return route('module', [
'module' => $this->name(),
'action' => 'Chart',
'xrefs[]' => $individual->xref(),
'ged' => $individual->tree()->name(),
] + $parameters);
} | [
"public",
"function",
"chartUrl",
"(",
"Individual",
"$",
"individual",
",",
"array",
"$",
"parameters",
"=",
"[",
"]",
")",
":",
"string",
"{",
"return",
"route",
"(",
"'module'",
",",
"[",
"'module'",
"=>",
"$",
"this",
"->",
"name",
"(",
")",
",",
"'action'",
"=>",
"'Chart'",
",",
"'xrefs[]'",
"=>",
"$",
"individual",
"->",
"xref",
"(",
")",
",",
"'ged'",
"=>",
"$",
"individual",
"->",
"tree",
"(",
")",
"->",
"name",
"(",
")",
",",
"]",
"+",
"$",
"parameters",
")",
";",
"}"
] | The URL for this chart.
@param Individual $individual
@param string[] $parameters
@return string | [
"The",
"URL",
"for",
"this",
"chart",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Module/LifespansChartModule.php#L88-L96 | train |
fisharebest/webtrees | app/Module/LifespansChartModule.php | LifespansChartModule.maxYear | protected function maxYear(array $individuals): int
{
$jd = array_reduce($individuals, static function ($carry, Individual $item) {
return max($carry, $item->getEstimatedDeathDate()->maximumJulianDay());
}, 0);
$year = $this->jdToYear($jd);
// Don't show future dates
return min($year, (int) date('Y'));
} | php | protected function maxYear(array $individuals): int
{
$jd = array_reduce($individuals, static function ($carry, Individual $item) {
return max($carry, $item->getEstimatedDeathDate()->maximumJulianDay());
}, 0);
$year = $this->jdToYear($jd);
// Don't show future dates
return min($year, (int) date('Y'));
} | [
"protected",
"function",
"maxYear",
"(",
"array",
"$",
"individuals",
")",
":",
"int",
"{",
"$",
"jd",
"=",
"array_reduce",
"(",
"$",
"individuals",
",",
"static",
"function",
"(",
"$",
"carry",
",",
"Individual",
"$",
"item",
")",
"{",
"return",
"max",
"(",
"$",
"carry",
",",
"$",
"item",
"->",
"getEstimatedDeathDate",
"(",
")",
"->",
"maximumJulianDay",
"(",
")",
")",
";",
"}",
",",
"0",
")",
";",
"$",
"year",
"=",
"$",
"this",
"->",
"jdToYear",
"(",
"$",
"jd",
")",
";",
"// Don't show future dates",
"return",
"min",
"(",
"$",
"year",
",",
"(",
"int",
")",
"date",
"(",
"'Y'",
")",
")",
";",
"}"
] | Find the latest event year for individuals
@param array $individuals
@return int | [
"Find",
"the",
"latest",
"event",
"year",
"for",
"individuals"
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Module/LifespansChartModule.php#L292-L302 | train |
fisharebest/webtrees | app/Module/LifespansChartModule.php | LifespansChartModule.minYear | protected function minYear(array $individuals): int
{
$jd = array_reduce($individuals, static function ($carry, Individual $item) {
return min($carry, $item->getEstimatedBirthDate()->minimumJulianDay());
}, PHP_INT_MAX);
return $this->jdToYear($jd);
} | php | protected function minYear(array $individuals): int
{
$jd = array_reduce($individuals, static function ($carry, Individual $item) {
return min($carry, $item->getEstimatedBirthDate()->minimumJulianDay());
}, PHP_INT_MAX);
return $this->jdToYear($jd);
} | [
"protected",
"function",
"minYear",
"(",
"array",
"$",
"individuals",
")",
":",
"int",
"{",
"$",
"jd",
"=",
"array_reduce",
"(",
"$",
"individuals",
",",
"static",
"function",
"(",
"$",
"carry",
",",
"Individual",
"$",
"item",
")",
"{",
"return",
"min",
"(",
"$",
"carry",
",",
"$",
"item",
"->",
"getEstimatedBirthDate",
"(",
")",
"->",
"minimumJulianDay",
"(",
")",
")",
";",
"}",
",",
"PHP_INT_MAX",
")",
";",
"return",
"$",
"this",
"->",
"jdToYear",
"(",
"$",
"jd",
")",
";",
"}"
] | Find the earliest event year for individuals
@param array $individuals
@return int | [
"Find",
"the",
"earliest",
"event",
"year",
"for",
"individuals"
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Module/LifespansChartModule.php#L311-L318 | train |
fisharebest/webtrees | app/Module/LifespansChartModule.php | LifespansChartModule.jdToYear | protected function jdToYear(int $jd): int
{
if ($jd === 0) {
return 0;
}
$gregorian = new GregorianCalendar();
[$y] = $gregorian->jdToYmd($jd);
return $y;
} | php | protected function jdToYear(int $jd): int
{
if ($jd === 0) {
return 0;
}
$gregorian = new GregorianCalendar();
[$y] = $gregorian->jdToYmd($jd);
return $y;
} | [
"protected",
"function",
"jdToYear",
"(",
"int",
"$",
"jd",
")",
":",
"int",
"{",
"if",
"(",
"$",
"jd",
"===",
"0",
")",
"{",
"return",
"0",
";",
"}",
"$",
"gregorian",
"=",
"new",
"GregorianCalendar",
"(",
")",
";",
"[",
"$",
"y",
"]",
"=",
"$",
"gregorian",
"->",
"jdToYmd",
"(",
"$",
"jd",
")",
";",
"return",
"$",
"y",
";",
"}"
] | Convert a julian day to a gregorian year
@param int $jd
@return int | [
"Convert",
"a",
"julian",
"day",
"to",
"a",
"gregorian",
"year"
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Module/LifespansChartModule.php#L327-L337 | train |
fisharebest/webtrees | app/Module/LifespansChartModule.php | LifespansChartModule.closeFamily | protected function closeFamily(Individual $individual): array
{
$xrefs = [];
foreach ($individual->spouseFamilies() as $family) {
foreach ($family->children() as $child) {
$xrefs[] = $child->xref();
}
foreach ($family->spouses() as $spouse) {
$xrefs[] = $spouse->xref();
}
}
foreach ($individual->childFamilies() as $family) {
foreach ($family->children() as $child) {
$xrefs[] = $child->xref();
}
foreach ($family->spouses() as $spouse) {
$xrefs[] = $spouse->xref();
}
}
return $xrefs;
} | php | protected function closeFamily(Individual $individual): array
{
$xrefs = [];
foreach ($individual->spouseFamilies() as $family) {
foreach ($family->children() as $child) {
$xrefs[] = $child->xref();
}
foreach ($family->spouses() as $spouse) {
$xrefs[] = $spouse->xref();
}
}
foreach ($individual->childFamilies() as $family) {
foreach ($family->children() as $child) {
$xrefs[] = $child->xref();
}
foreach ($family->spouses() as $spouse) {
$xrefs[] = $spouse->xref();
}
}
return $xrefs;
} | [
"protected",
"function",
"closeFamily",
"(",
"Individual",
"$",
"individual",
")",
":",
"array",
"{",
"$",
"xrefs",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"individual",
"->",
"spouseFamilies",
"(",
")",
"as",
"$",
"family",
")",
"{",
"foreach",
"(",
"$",
"family",
"->",
"children",
"(",
")",
"as",
"$",
"child",
")",
"{",
"$",
"xrefs",
"[",
"]",
"=",
"$",
"child",
"->",
"xref",
"(",
")",
";",
"}",
"foreach",
"(",
"$",
"family",
"->",
"spouses",
"(",
")",
"as",
"$",
"spouse",
")",
"{",
"$",
"xrefs",
"[",
"]",
"=",
"$",
"spouse",
"->",
"xref",
"(",
")",
";",
"}",
"}",
"foreach",
"(",
"$",
"individual",
"->",
"childFamilies",
"(",
")",
"as",
"$",
"family",
")",
"{",
"foreach",
"(",
"$",
"family",
"->",
"children",
"(",
")",
"as",
"$",
"child",
")",
"{",
"$",
"xrefs",
"[",
"]",
"=",
"$",
"child",
"->",
"xref",
"(",
")",
";",
"}",
"foreach",
"(",
"$",
"family",
"->",
"spouses",
"(",
")",
"as",
"$",
"spouse",
")",
"{",
"$",
"xrefs",
"[",
"]",
"=",
"$",
"spouse",
"->",
"xref",
"(",
")",
";",
"}",
"}",
"return",
"$",
"xrefs",
";",
"}"
] | Find the close family members of an individual.
@param Individual $individual
@return string[] | [
"Find",
"the",
"close",
"family",
"members",
"of",
"an",
"individual",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Module/LifespansChartModule.php#L389-L414 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.