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/Individual.php
|
Individual.getBirthDate
|
public function getBirthDate(): Date
{
foreach ($this->getAllBirthDates() as $date) {
if ($date->isOK()) {
return $date;
}
}
return new Date('');
}
|
php
|
public function getBirthDate(): Date
{
foreach ($this->getAllBirthDates() as $date) {
if ($date->isOK()) {
return $date;
}
}
return new Date('');
}
|
[
"public",
"function",
"getBirthDate",
"(",
")",
":",
"Date",
"{",
"foreach",
"(",
"$",
"this",
"->",
"getAllBirthDates",
"(",
")",
"as",
"$",
"date",
")",
"{",
"if",
"(",
"$",
"date",
"->",
"isOK",
"(",
")",
")",
"{",
"return",
"$",
"date",
";",
"}",
"}",
"return",
"new",
"Date",
"(",
"''",
")",
";",
"}"
] |
Get the date of birth
@return Date
|
[
"Get",
"the",
"date",
"of",
"birth"
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Individual.php#L477-L486
|
train
|
fisharebest/webtrees
|
app/Individual.php
|
Individual.getBirthPlace
|
public function getBirthPlace(): Place
{
foreach ($this->getAllBirthPlaces() as $place) {
return $place;
}
return new Place('', $this->tree);
}
|
php
|
public function getBirthPlace(): Place
{
foreach ($this->getAllBirthPlaces() as $place) {
return $place;
}
return new Place('', $this->tree);
}
|
[
"public",
"function",
"getBirthPlace",
"(",
")",
":",
"Place",
"{",
"foreach",
"(",
"$",
"this",
"->",
"getAllBirthPlaces",
"(",
")",
"as",
"$",
"place",
")",
"{",
"return",
"$",
"place",
";",
"}",
"return",
"new",
"Place",
"(",
"''",
",",
"$",
"this",
"->",
"tree",
")",
";",
"}"
] |
Get the place of birth
@return Place
|
[
"Get",
"the",
"place",
"of",
"birth"
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Individual.php#L493-L500
|
train
|
fisharebest/webtrees
|
app/Individual.php
|
Individual.getDeathDate
|
public function getDeathDate(): Date
{
foreach ($this->getAllDeathDates() as $date) {
if ($date->isOK()) {
return $date;
}
}
return new Date('');
}
|
php
|
public function getDeathDate(): Date
{
foreach ($this->getAllDeathDates() as $date) {
if ($date->isOK()) {
return $date;
}
}
return new Date('');
}
|
[
"public",
"function",
"getDeathDate",
"(",
")",
":",
"Date",
"{",
"foreach",
"(",
"$",
"this",
"->",
"getAllDeathDates",
"(",
")",
"as",
"$",
"date",
")",
"{",
"if",
"(",
"$",
"date",
"->",
"isOK",
"(",
")",
")",
"{",
"return",
"$",
"date",
";",
"}",
"}",
"return",
"new",
"Date",
"(",
"''",
")",
";",
"}"
] |
Get the date of death
@return Date
|
[
"Get",
"the",
"date",
"of",
"death"
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Individual.php#L517-L526
|
train
|
fisharebest/webtrees
|
app/Individual.php
|
Individual.getDeathPlace
|
public function getDeathPlace(): Place
{
foreach ($this->getAllDeathPlaces() as $place) {
return $place;
}
return new Place('', $this->tree);
}
|
php
|
public function getDeathPlace(): Place
{
foreach ($this->getAllDeathPlaces() as $place) {
return $place;
}
return new Place('', $this->tree);
}
|
[
"public",
"function",
"getDeathPlace",
"(",
")",
":",
"Place",
"{",
"foreach",
"(",
"$",
"this",
"->",
"getAllDeathPlaces",
"(",
")",
"as",
"$",
"place",
")",
"{",
"return",
"$",
"place",
";",
"}",
"return",
"new",
"Place",
"(",
"''",
",",
"$",
"this",
"->",
"tree",
")",
";",
"}"
] |
Get the place of death
@return Place
|
[
"Get",
"the",
"place",
"of",
"death"
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Individual.php#L533-L540
|
train
|
fisharebest/webtrees
|
app/Individual.php
|
Individual.getAllBirthDates
|
public function getAllBirthDates(): array
{
foreach (Gedcom::BIRTH_EVENTS as $event) {
$tmp = $this->getAllEventDates([$event]);
if ($tmp) {
return $tmp;
}
}
return [];
}
|
php
|
public function getAllBirthDates(): array
{
foreach (Gedcom::BIRTH_EVENTS as $event) {
$tmp = $this->getAllEventDates([$event]);
if ($tmp) {
return $tmp;
}
}
return [];
}
|
[
"public",
"function",
"getAllBirthDates",
"(",
")",
":",
"array",
"{",
"foreach",
"(",
"Gedcom",
"::",
"BIRTH_EVENTS",
"as",
"$",
"event",
")",
"{",
"$",
"tmp",
"=",
"$",
"this",
"->",
"getAllEventDates",
"(",
"[",
"$",
"event",
"]",
")",
";",
"if",
"(",
"$",
"tmp",
")",
"{",
"return",
"$",
"tmp",
";",
"}",
"}",
"return",
"[",
"]",
";",
"}"
] |
Get all the birth dates - for the individual lists.
@return Date[]
|
[
"Get",
"all",
"the",
"birth",
"dates",
"-",
"for",
"the",
"individual",
"lists",
"."
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Individual.php#L583-L593
|
train
|
fisharebest/webtrees
|
app/Individual.php
|
Individual.getAllBirthPlaces
|
public function getAllBirthPlaces(): array
{
foreach (Gedcom::BIRTH_EVENTS as $event) {
$places = $this->getAllEventPlaces([$event]);
if (!empty($places)) {
return $places;
}
}
return [];
}
|
php
|
public function getAllBirthPlaces(): array
{
foreach (Gedcom::BIRTH_EVENTS as $event) {
$places = $this->getAllEventPlaces([$event]);
if (!empty($places)) {
return $places;
}
}
return [];
}
|
[
"public",
"function",
"getAllBirthPlaces",
"(",
")",
":",
"array",
"{",
"foreach",
"(",
"Gedcom",
"::",
"BIRTH_EVENTS",
"as",
"$",
"event",
")",
"{",
"$",
"places",
"=",
"$",
"this",
"->",
"getAllEventPlaces",
"(",
"[",
"$",
"event",
"]",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"places",
")",
")",
"{",
"return",
"$",
"places",
";",
"}",
"}",
"return",
"[",
"]",
";",
"}"
] |
Gat all the birth places - for the individual lists.
@return Place[]
|
[
"Gat",
"all",
"the",
"birth",
"places",
"-",
"for",
"the",
"individual",
"lists",
"."
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Individual.php#L600-L610
|
train
|
fisharebest/webtrees
|
app/Individual.php
|
Individual.getAllDeathDates
|
public function getAllDeathDates(): array
{
foreach (Gedcom::DEATH_EVENTS as $event) {
$tmp = $this->getAllEventDates([$event]);
if ($tmp) {
return $tmp;
}
}
return [];
}
|
php
|
public function getAllDeathDates(): array
{
foreach (Gedcom::DEATH_EVENTS as $event) {
$tmp = $this->getAllEventDates([$event]);
if ($tmp) {
return $tmp;
}
}
return [];
}
|
[
"public",
"function",
"getAllDeathDates",
"(",
")",
":",
"array",
"{",
"foreach",
"(",
"Gedcom",
"::",
"DEATH_EVENTS",
"as",
"$",
"event",
")",
"{",
"$",
"tmp",
"=",
"$",
"this",
"->",
"getAllEventDates",
"(",
"[",
"$",
"event",
"]",
")",
";",
"if",
"(",
"$",
"tmp",
")",
"{",
"return",
"$",
"tmp",
";",
"}",
"}",
"return",
"[",
"]",
";",
"}"
] |
Get all the death dates - for the individual lists.
@return Date[]
|
[
"Get",
"all",
"the",
"death",
"dates",
"-",
"for",
"the",
"individual",
"lists",
"."
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Individual.php#L617-L627
|
train
|
fisharebest/webtrees
|
app/Individual.php
|
Individual.getAllDeathPlaces
|
public function getAllDeathPlaces(): array
{
foreach (Gedcom::DEATH_EVENTS as $event) {
$places = $this->getAllEventPlaces([$event]);
if (!empty($places)) {
return $places;
}
}
return [];
}
|
php
|
public function getAllDeathPlaces(): array
{
foreach (Gedcom::DEATH_EVENTS as $event) {
$places = $this->getAllEventPlaces([$event]);
if (!empty($places)) {
return $places;
}
}
return [];
}
|
[
"public",
"function",
"getAllDeathPlaces",
"(",
")",
":",
"array",
"{",
"foreach",
"(",
"Gedcom",
"::",
"DEATH_EVENTS",
"as",
"$",
"event",
")",
"{",
"$",
"places",
"=",
"$",
"this",
"->",
"getAllEventPlaces",
"(",
"[",
"$",
"event",
"]",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"places",
")",
")",
"{",
"return",
"$",
"places",
";",
"}",
"}",
"return",
"[",
"]",
";",
"}"
] |
Get all the death places - for the individual lists.
@return Place[]
|
[
"Get",
"all",
"the",
"death",
"places",
"-",
"for",
"the",
"individual",
"lists",
"."
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Individual.php#L634-L644
|
train
|
fisharebest/webtrees
|
app/Individual.php
|
Individual.getEstimatedDeathDate
|
public function getEstimatedDeathDate(): Date
{
if ($this->estimated_death_date === null) {
foreach ($this->getAllDeathDates() as $date) {
if ($date->isOK()) {
$this->estimated_death_date = $date;
break;
}
}
if ($this->estimated_death_date === null) {
if ($this->getEstimatedBirthDate()->minimumJulianDay()) {
$max_alive_age = (int) $this->tree->getPreference('MAX_ALIVE_AGE');
$this->estimated_death_date = $this->getEstimatedBirthDate()->addYears($max_alive_age, 'BEF');
} else {
$this->estimated_death_date = new Date(''); // always return a date object
}
}
}
return $this->estimated_death_date;
}
|
php
|
public function getEstimatedDeathDate(): Date
{
if ($this->estimated_death_date === null) {
foreach ($this->getAllDeathDates() as $date) {
if ($date->isOK()) {
$this->estimated_death_date = $date;
break;
}
}
if ($this->estimated_death_date === null) {
if ($this->getEstimatedBirthDate()->minimumJulianDay()) {
$max_alive_age = (int) $this->tree->getPreference('MAX_ALIVE_AGE');
$this->estimated_death_date = $this->getEstimatedBirthDate()->addYears($max_alive_age, 'BEF');
} else {
$this->estimated_death_date = new Date(''); // always return a date object
}
}
}
return $this->estimated_death_date;
}
|
[
"public",
"function",
"getEstimatedDeathDate",
"(",
")",
":",
"Date",
"{",
"if",
"(",
"$",
"this",
"->",
"estimated_death_date",
"===",
"null",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"getAllDeathDates",
"(",
")",
"as",
"$",
"date",
")",
"{",
"if",
"(",
"$",
"date",
"->",
"isOK",
"(",
")",
")",
"{",
"$",
"this",
"->",
"estimated_death_date",
"=",
"$",
"date",
";",
"break",
";",
"}",
"}",
"if",
"(",
"$",
"this",
"->",
"estimated_death_date",
"===",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"getEstimatedBirthDate",
"(",
")",
"->",
"minimumJulianDay",
"(",
")",
")",
"{",
"$",
"max_alive_age",
"=",
"(",
"int",
")",
"$",
"this",
"->",
"tree",
"->",
"getPreference",
"(",
"'MAX_ALIVE_AGE'",
")",
";",
"$",
"this",
"->",
"estimated_death_date",
"=",
"$",
"this",
"->",
"getEstimatedBirthDate",
"(",
")",
"->",
"addYears",
"(",
"$",
"max_alive_age",
",",
"'BEF'",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"estimated_death_date",
"=",
"new",
"Date",
"(",
"''",
")",
";",
"// always return a date object",
"}",
"}",
"}",
"return",
"$",
"this",
"->",
"estimated_death_date",
";",
"}"
] |
Generate an estimated date of death.
@return Date
|
[
"Generate",
"an",
"estimated",
"date",
"of",
"death",
"."
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Individual.php#L739-L759
|
train
|
fisharebest/webtrees
|
app/Individual.php
|
Individual.getCurrentSpouse
|
public function getCurrentSpouse(): ?Individual
{
$family = $this->spouseFamilies()->last();
if ($family instanceof Family) {
return $family->spouse($this);
}
return null;
}
|
php
|
public function getCurrentSpouse(): ?Individual
{
$family = $this->spouseFamilies()->last();
if ($family instanceof Family) {
return $family->spouse($this);
}
return null;
}
|
[
"public",
"function",
"getCurrentSpouse",
"(",
")",
":",
"?",
"Individual",
"{",
"$",
"family",
"=",
"$",
"this",
"->",
"spouseFamilies",
"(",
")",
"->",
"last",
"(",
")",
";",
"if",
"(",
"$",
"family",
"instanceof",
"Family",
")",
"{",
"return",
"$",
"family",
"->",
"spouse",
"(",
"$",
"this",
")",
";",
"}",
"return",
"null",
";",
"}"
] |
Get the current spouse of this individual.
Where an individual has multiple spouses, assume they are stored
in chronological order, and take the last one found.
@return Individual|null
|
[
"Get",
"the",
"current",
"spouse",
"of",
"this",
"individual",
"."
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Individual.php#L859-L868
|
train
|
fisharebest/webtrees
|
app/Individual.php
|
Individual.numberOfChildren
|
public function numberOfChildren(): int
{
if (preg_match('/\n1 NCHI (\d+)(?:\n|$)/', $this->gedcom(), $match)) {
return (int) $match[1];
}
$children = [];
foreach ($this->spouseFamilies() as $fam) {
foreach ($fam->children() as $child) {
$children[$child->xref()] = true;
}
}
return count($children);
}
|
php
|
public function numberOfChildren(): int
{
if (preg_match('/\n1 NCHI (\d+)(?:\n|$)/', $this->gedcom(), $match)) {
return (int) $match[1];
}
$children = [];
foreach ($this->spouseFamilies() as $fam) {
foreach ($fam->children() as $child) {
$children[$child->xref()] = true;
}
}
return count($children);
}
|
[
"public",
"function",
"numberOfChildren",
"(",
")",
":",
"int",
"{",
"if",
"(",
"preg_match",
"(",
"'/\\n1 NCHI (\\d+)(?:\\n|$)/'",
",",
"$",
"this",
"->",
"gedcom",
"(",
")",
",",
"$",
"match",
")",
")",
"{",
"return",
"(",
"int",
")",
"$",
"match",
"[",
"1",
"]",
";",
"}",
"$",
"children",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"spouseFamilies",
"(",
")",
"as",
"$",
"fam",
")",
"{",
"foreach",
"(",
"$",
"fam",
"->",
"children",
"(",
")",
"as",
"$",
"child",
")",
"{",
"$",
"children",
"[",
"$",
"child",
"->",
"xref",
"(",
")",
"]",
"=",
"true",
";",
"}",
"}",
"return",
"count",
"(",
"$",
"children",
")",
";",
"}"
] |
Count the children belonging to this individual.
@return int
|
[
"Count",
"the",
"children",
"belonging",
"to",
"this",
"individual",
"."
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Individual.php#L875-L889
|
train
|
fisharebest/webtrees
|
app/Individual.php
|
Individual.primaryChildFamily
|
public function primaryChildFamily(): ?Family
{
$families = $this->childFamilies();
switch ($families->count()) {
case 0:
return null;
case 1:
return $families[0];
default:
// If there is more than one FAMC record, choose the preferred parents:
// a) records with '2 _PRIMARY'
foreach ($families as $fam) {
$famid = $fam->xref();
if (preg_match("/\n1 FAMC @{$famid}@\n(?:[2-9].*\n)*(?:2 _PRIMARY Y)/", $this->gedcom())) {
return $fam;
}
}
// b) records with '2 PEDI birt'
foreach ($families as $fam) {
$famid = $fam->xref();
if (preg_match("/\n1 FAMC @{$famid}@\n(?:[2-9].*\n)*(?:2 PEDI birth)/", $this->gedcom())) {
return $fam;
}
}
// c) records with no '2 PEDI'
foreach ($families as $fam) {
$famid = $fam->xref();
if (!preg_match("/\n1 FAMC @{$famid}@\n(?:[2-9].*\n)*(?:2 PEDI)/", $this->gedcom())) {
return $fam;
}
}
// d) any record
return $families[0];
}
}
|
php
|
public function primaryChildFamily(): ?Family
{
$families = $this->childFamilies();
switch ($families->count()) {
case 0:
return null;
case 1:
return $families[0];
default:
// If there is more than one FAMC record, choose the preferred parents:
// a) records with '2 _PRIMARY'
foreach ($families as $fam) {
$famid = $fam->xref();
if (preg_match("/\n1 FAMC @{$famid}@\n(?:[2-9].*\n)*(?:2 _PRIMARY Y)/", $this->gedcom())) {
return $fam;
}
}
// b) records with '2 PEDI birt'
foreach ($families as $fam) {
$famid = $fam->xref();
if (preg_match("/\n1 FAMC @{$famid}@\n(?:[2-9].*\n)*(?:2 PEDI birth)/", $this->gedcom())) {
return $fam;
}
}
// c) records with no '2 PEDI'
foreach ($families as $fam) {
$famid = $fam->xref();
if (!preg_match("/\n1 FAMC @{$famid}@\n(?:[2-9].*\n)*(?:2 PEDI)/", $this->gedcom())) {
return $fam;
}
}
// d) any record
return $families[0];
}
}
|
[
"public",
"function",
"primaryChildFamily",
"(",
")",
":",
"?",
"Family",
"{",
"$",
"families",
"=",
"$",
"this",
"->",
"childFamilies",
"(",
")",
";",
"switch",
"(",
"$",
"families",
"->",
"count",
"(",
")",
")",
"{",
"case",
"0",
":",
"return",
"null",
";",
"case",
"1",
":",
"return",
"$",
"families",
"[",
"0",
"]",
";",
"default",
":",
"// If there is more than one FAMC record, choose the preferred parents:",
"// a) records with '2 _PRIMARY'",
"foreach",
"(",
"$",
"families",
"as",
"$",
"fam",
")",
"{",
"$",
"famid",
"=",
"$",
"fam",
"->",
"xref",
"(",
")",
";",
"if",
"(",
"preg_match",
"(",
"\"/\\n1 FAMC @{$famid}@\\n(?:[2-9].*\\n)*(?:2 _PRIMARY Y)/\"",
",",
"$",
"this",
"->",
"gedcom",
"(",
")",
")",
")",
"{",
"return",
"$",
"fam",
";",
"}",
"}",
"// b) records with '2 PEDI birt'",
"foreach",
"(",
"$",
"families",
"as",
"$",
"fam",
")",
"{",
"$",
"famid",
"=",
"$",
"fam",
"->",
"xref",
"(",
")",
";",
"if",
"(",
"preg_match",
"(",
"\"/\\n1 FAMC @{$famid}@\\n(?:[2-9].*\\n)*(?:2 PEDI birth)/\"",
",",
"$",
"this",
"->",
"gedcom",
"(",
")",
")",
")",
"{",
"return",
"$",
"fam",
";",
"}",
"}",
"// c) records with no '2 PEDI'",
"foreach",
"(",
"$",
"families",
"as",
"$",
"fam",
")",
"{",
"$",
"famid",
"=",
"$",
"fam",
"->",
"xref",
"(",
")",
";",
"if",
"(",
"!",
"preg_match",
"(",
"\"/\\n1 FAMC @{$famid}@\\n(?:[2-9].*\\n)*(?:2 PEDI)/\"",
",",
"$",
"this",
"->",
"gedcom",
"(",
")",
")",
")",
"{",
"return",
"$",
"fam",
";",
"}",
"}",
"// d) any record",
"return",
"$",
"families",
"[",
"0",
"]",
";",
"}",
"}"
] |
Get the preferred parents for this individual.
An individual may multiple parents (e.g. birth, adopted, disputed).
The preferred family record is:
(a) the first one with an explicit tag "_PRIMARY Y"
(b) the first one with a pedigree of "birth"
(c) the first one with no pedigree (default is "birth")
(d) the first one found
@return Family|null
|
[
"Get",
"the",
"preferred",
"parents",
"for",
"this",
"individual",
"."
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Individual.php#L931-L966
|
train
|
fisharebest/webtrees
|
app/Individual.php
|
Individual.getSpouseFamilyLabel
|
public function getSpouseFamilyLabel(Family $family): string
{
$spouse = $family->spouse($this);
if ($spouse) {
/* I18N: %s is the spouse name */
return I18N::translate('Family with %s', $spouse->fullName());
}
return $family->fullName();
}
|
php
|
public function getSpouseFamilyLabel(Family $family): string
{
$spouse = $family->spouse($this);
if ($spouse) {
/* I18N: %s is the spouse name */
return I18N::translate('Family with %s', $spouse->fullName());
}
return $family->fullName();
}
|
[
"public",
"function",
"getSpouseFamilyLabel",
"(",
"Family",
"$",
"family",
")",
":",
"string",
"{",
"$",
"spouse",
"=",
"$",
"family",
"->",
"spouse",
"(",
"$",
"this",
")",
";",
"if",
"(",
"$",
"spouse",
")",
"{",
"/* I18N: %s is the spouse name */",
"return",
"I18N",
"::",
"translate",
"(",
"'Family with %s'",
",",
"$",
"spouse",
"->",
"fullName",
"(",
")",
")",
";",
"}",
"return",
"$",
"family",
"->",
"fullName",
"(",
")",
";",
"}"
] |
Get the description for the family.
For example, "XXX's family with new wife".
@param Family $family
@return string
|
[
"Get",
"the",
"description",
"for",
"the",
"family",
"."
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Individual.php#L1098-L1107
|
train
|
fisharebest/webtrees
|
app/Individual.php
|
Individual.getPrimaryParentsNames
|
public function getPrimaryParentsNames($classname = '', $display = ''): string
{
$fam = $this->primaryChildFamily();
if (!$fam) {
return '';
}
$txt = '<div';
if ($classname) {
$txt .= ' class="' . $classname . '"';
}
if ($display) {
$txt .= ' style="display:' . $display . '"';
}
$txt .= '>';
$husb = $fam->husband();
if ($husb) {
// Temporarily reset the 'prefered' display name, as we always
// want the default name, not the one selected for display on the indilist.
$primary = $husb->getPrimaryName();
$husb->setPrimaryName(null);
/* I18N: %s is the name of an individual’s father */
$txt .= I18N::translate('Father: %s', $husb->fullName()) . '<br>';
$husb->setPrimaryName($primary);
}
$wife = $fam->wife();
if ($wife) {
// Temporarily reset the 'prefered' display name, as we always
// want the default name, not the one selected for display on the indilist.
$primary = $wife->getPrimaryName();
$wife->setPrimaryName(null);
/* I18N: %s is the name of an individual’s mother */
$txt .= I18N::translate('Mother: %s', $wife->fullName());
$wife->setPrimaryName($primary);
}
$txt .= '</div>';
return $txt;
}
|
php
|
public function getPrimaryParentsNames($classname = '', $display = ''): string
{
$fam = $this->primaryChildFamily();
if (!$fam) {
return '';
}
$txt = '<div';
if ($classname) {
$txt .= ' class="' . $classname . '"';
}
if ($display) {
$txt .= ' style="display:' . $display . '"';
}
$txt .= '>';
$husb = $fam->husband();
if ($husb) {
// Temporarily reset the 'prefered' display name, as we always
// want the default name, not the one selected for display on the indilist.
$primary = $husb->getPrimaryName();
$husb->setPrimaryName(null);
/* I18N: %s is the name of an individual’s father */
$txt .= I18N::translate('Father: %s', $husb->fullName()) . '<br>';
$husb->setPrimaryName($primary);
}
$wife = $fam->wife();
if ($wife) {
// Temporarily reset the 'prefered' display name, as we always
// want the default name, not the one selected for display on the indilist.
$primary = $wife->getPrimaryName();
$wife->setPrimaryName(null);
/* I18N: %s is the name of an individual’s mother */
$txt .= I18N::translate('Mother: %s', $wife->fullName());
$wife->setPrimaryName($primary);
}
$txt .= '</div>';
return $txt;
}
|
[
"public",
"function",
"getPrimaryParentsNames",
"(",
"$",
"classname",
"=",
"''",
",",
"$",
"display",
"=",
"''",
")",
":",
"string",
"{",
"$",
"fam",
"=",
"$",
"this",
"->",
"primaryChildFamily",
"(",
")",
";",
"if",
"(",
"!",
"$",
"fam",
")",
"{",
"return",
"''",
";",
"}",
"$",
"txt",
"=",
"'<div'",
";",
"if",
"(",
"$",
"classname",
")",
"{",
"$",
"txt",
".=",
"' class=\"'",
".",
"$",
"classname",
".",
"'\"'",
";",
"}",
"if",
"(",
"$",
"display",
")",
"{",
"$",
"txt",
".=",
"' style=\"display:'",
".",
"$",
"display",
".",
"'\"'",
";",
"}",
"$",
"txt",
".=",
"'>'",
";",
"$",
"husb",
"=",
"$",
"fam",
"->",
"husband",
"(",
")",
";",
"if",
"(",
"$",
"husb",
")",
"{",
"// Temporarily reset the 'prefered' display name, as we always",
"// want the default name, not the one selected for display on the indilist.",
"$",
"primary",
"=",
"$",
"husb",
"->",
"getPrimaryName",
"(",
")",
";",
"$",
"husb",
"->",
"setPrimaryName",
"(",
"null",
")",
";",
"/* I18N: %s is the name of an individual’s father */",
"$",
"txt",
".=",
"I18N",
"::",
"translate",
"(",
"'Father: %s'",
",",
"$",
"husb",
"->",
"fullName",
"(",
")",
")",
".",
"'<br>'",
";",
"$",
"husb",
"->",
"setPrimaryName",
"(",
"$",
"primary",
")",
";",
"}",
"$",
"wife",
"=",
"$",
"fam",
"->",
"wife",
"(",
")",
";",
"if",
"(",
"$",
"wife",
")",
"{",
"// Temporarily reset the 'prefered' display name, as we always",
"// want the default name, not the one selected for display on the indilist.",
"$",
"primary",
"=",
"$",
"wife",
"->",
"getPrimaryName",
"(",
")",
";",
"$",
"wife",
"->",
"setPrimaryName",
"(",
"null",
")",
";",
"/* I18N: %s is the name of an individual’s mother */",
"$",
"txt",
".=",
"I18N",
"::",
"translate",
"(",
"'Mother: %s'",
",",
"$",
"wife",
"->",
"fullName",
"(",
")",
")",
";",
"$",
"wife",
"->",
"setPrimaryName",
"(",
"$",
"primary",
")",
";",
"}",
"$",
"txt",
".=",
"'</div>'",
";",
"return",
"$",
"txt",
";",
"}"
] |
get primary parents names for this individual
@param string $classname optional css class
@param string $display optional css style display
@return string a div block with father & mother names
|
[
"get",
"primary",
"parents",
"names",
"for",
"this",
"individual"
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Individual.php#L1117-L1154
|
train
|
fisharebest/webtrees
|
app/Individual.php
|
Individual.formatListDetails
|
public function formatListDetails(): string
{
return
$this->formatFirstMajorFact(Gedcom::BIRTH_EVENTS, 1) .
$this->formatFirstMajorFact(Gedcom::DEATH_EVENTS, 1);
}
|
php
|
public function formatListDetails(): string
{
return
$this->formatFirstMajorFact(Gedcom::BIRTH_EVENTS, 1) .
$this->formatFirstMajorFact(Gedcom::DEATH_EVENTS, 1);
}
|
[
"public",
"function",
"formatListDetails",
"(",
")",
":",
"string",
"{",
"return",
"$",
"this",
"->",
"formatFirstMajorFact",
"(",
"Gedcom",
"::",
"BIRTH_EVENTS",
",",
"1",
")",
".",
"$",
"this",
"->",
"formatFirstMajorFact",
"(",
"Gedcom",
"::",
"DEATH_EVENTS",
",",
"1",
")",
";",
"}"
] |
Extra info to display when displaying this record in a list of
selection items or favorites.
@return string
|
[
"Extra",
"info",
"to",
"display",
"when",
"displaying",
"this",
"record",
"in",
"a",
"list",
"of",
"selection",
"items",
"or",
"favorites",
"."
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Individual.php#L1362-L1367
|
train
|
fisharebest/webtrees
|
app/Http/Controllers/BranchesController.php
|
BranchesController.allAncestors
|
protected function allAncestors(Individual $individual): array
{
/** @var Individual[] $ancestors */
$ancestors = [
1 => $individual,
];
do {
$sosa = key($ancestors);
$family = $ancestors[$sosa]->primaryChildFamily();
if ($family !== null) {
if ($family->husband() !== null) {
$ancestors[$sosa * 2] = $family->husband();
}
if ($family->wife() !== null) {
$ancestors[$sosa * 2 + 1] = $family->wife();
}
}
} while (next($ancestors));
return $ancestors;
}
|
php
|
protected function allAncestors(Individual $individual): array
{
/** @var Individual[] $ancestors */
$ancestors = [
1 => $individual,
];
do {
$sosa = key($ancestors);
$family = $ancestors[$sosa]->primaryChildFamily();
if ($family !== null) {
if ($family->husband() !== null) {
$ancestors[$sosa * 2] = $family->husband();
}
if ($family->wife() !== null) {
$ancestors[$sosa * 2 + 1] = $family->wife();
}
}
} while (next($ancestors));
return $ancestors;
}
|
[
"protected",
"function",
"allAncestors",
"(",
"Individual",
"$",
"individual",
")",
":",
"array",
"{",
"/** @var Individual[] $ancestors */",
"$",
"ancestors",
"=",
"[",
"1",
"=>",
"$",
"individual",
",",
"]",
";",
"do",
"{",
"$",
"sosa",
"=",
"key",
"(",
"$",
"ancestors",
")",
";",
"$",
"family",
"=",
"$",
"ancestors",
"[",
"$",
"sosa",
"]",
"->",
"primaryChildFamily",
"(",
")",
";",
"if",
"(",
"$",
"family",
"!==",
"null",
")",
"{",
"if",
"(",
"$",
"family",
"->",
"husband",
"(",
")",
"!==",
"null",
")",
"{",
"$",
"ancestors",
"[",
"$",
"sosa",
"*",
"2",
"]",
"=",
"$",
"family",
"->",
"husband",
"(",
")",
";",
"}",
"if",
"(",
"$",
"family",
"->",
"wife",
"(",
")",
"!==",
"null",
")",
"{",
"$",
"ancestors",
"[",
"$",
"sosa",
"*",
"2",
"+",
"1",
"]",
"=",
"$",
"family",
"->",
"wife",
"(",
")",
";",
"}",
"}",
"}",
"while",
"(",
"next",
"(",
"$",
"ancestors",
")",
")",
";",
"return",
"$",
"ancestors",
";",
"}"
] |
Find all ancestors of an individual, indexed by the Sosa-Stradonitz number.
@param Individual $individual
@return Individual[]
|
[
"Find",
"all",
"ancestors",
"of",
"an",
"individual",
"indexed",
"by",
"the",
"Sosa",
"-",
"Stradonitz",
"number",
"."
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Http/Controllers/BranchesController.php#L135-L158
|
train
|
fisharebest/webtrees
|
app/Http/Controllers/BranchesController.php
|
BranchesController.loadIndividuals
|
private function loadIndividuals(Tree $tree, string $surname, bool $soundex_dm, bool $soundex_std): array
{
$individuals = DB::table('individuals')
->join('name', static function (JoinClause $join): void {
$join
->on('name.n_file', '=', 'individuals.i_file')
->on('name.n_id', '=', 'individuals.i_id');
})
->where('i_file', '=', $tree->id())
->where('n_type', '<>', '_MARNM')
->where(static function (Builder $query) use ($surname, $soundex_dm, $soundex_std): void {
$query
->where('n_surn', '=', $surname)
->orWhere('n_surname', '=', $surname);
if ($soundex_std) {
$sdx = Soundex::russell($surname);
if ($sdx !== '') {
foreach (explode(':', $sdx) as $value) {
$query->whereContains('n_soundex_surn_std', $value, 'or');
}
}
}
if ($soundex_dm) {
$sdx = Soundex::daitchMokotoff($surname);
if ($sdx !== '') {
foreach (explode(':', $sdx) as $value) {
$query->whereContains('n_soundex_surn_dm', $value, 'or');
}
}
}
})
->select(['individuals.*'])
->distinct()
->get()
->map(Individual::rowMapper())
->filter(GedcomRecord::accessFilter())
->all();
usort($individuals, Individual::birthDateComparator());
return $individuals;
}
|
php
|
private function loadIndividuals(Tree $tree, string $surname, bool $soundex_dm, bool $soundex_std): array
{
$individuals = DB::table('individuals')
->join('name', static function (JoinClause $join): void {
$join
->on('name.n_file', '=', 'individuals.i_file')
->on('name.n_id', '=', 'individuals.i_id');
})
->where('i_file', '=', $tree->id())
->where('n_type', '<>', '_MARNM')
->where(static function (Builder $query) use ($surname, $soundex_dm, $soundex_std): void {
$query
->where('n_surn', '=', $surname)
->orWhere('n_surname', '=', $surname);
if ($soundex_std) {
$sdx = Soundex::russell($surname);
if ($sdx !== '') {
foreach (explode(':', $sdx) as $value) {
$query->whereContains('n_soundex_surn_std', $value, 'or');
}
}
}
if ($soundex_dm) {
$sdx = Soundex::daitchMokotoff($surname);
if ($sdx !== '') {
foreach (explode(':', $sdx) as $value) {
$query->whereContains('n_soundex_surn_dm', $value, 'or');
}
}
}
})
->select(['individuals.*'])
->distinct()
->get()
->map(Individual::rowMapper())
->filter(GedcomRecord::accessFilter())
->all();
usort($individuals, Individual::birthDateComparator());
return $individuals;
}
|
[
"private",
"function",
"loadIndividuals",
"(",
"Tree",
"$",
"tree",
",",
"string",
"$",
"surname",
",",
"bool",
"$",
"soundex_dm",
",",
"bool",
"$",
"soundex_std",
")",
":",
"array",
"{",
"$",
"individuals",
"=",
"DB",
"::",
"table",
"(",
"'individuals'",
")",
"->",
"join",
"(",
"'name'",
",",
"static",
"function",
"(",
"JoinClause",
"$",
"join",
")",
":",
"void",
"{",
"$",
"join",
"->",
"on",
"(",
"'name.n_file'",
",",
"'='",
",",
"'individuals.i_file'",
")",
"->",
"on",
"(",
"'name.n_id'",
",",
"'='",
",",
"'individuals.i_id'",
")",
";",
"}",
")",
"->",
"where",
"(",
"'i_file'",
",",
"'='",
",",
"$",
"tree",
"->",
"id",
"(",
")",
")",
"->",
"where",
"(",
"'n_type'",
",",
"'<>'",
",",
"'_MARNM'",
")",
"->",
"where",
"(",
"static",
"function",
"(",
"Builder",
"$",
"query",
")",
"use",
"(",
"$",
"surname",
",",
"$",
"soundex_dm",
",",
"$",
"soundex_std",
")",
":",
"void",
"{",
"$",
"query",
"->",
"where",
"(",
"'n_surn'",
",",
"'='",
",",
"$",
"surname",
")",
"->",
"orWhere",
"(",
"'n_surname'",
",",
"'='",
",",
"$",
"surname",
")",
";",
"if",
"(",
"$",
"soundex_std",
")",
"{",
"$",
"sdx",
"=",
"Soundex",
"::",
"russell",
"(",
"$",
"surname",
")",
";",
"if",
"(",
"$",
"sdx",
"!==",
"''",
")",
"{",
"foreach",
"(",
"explode",
"(",
"':'",
",",
"$",
"sdx",
")",
"as",
"$",
"value",
")",
"{",
"$",
"query",
"->",
"whereContains",
"(",
"'n_soundex_surn_std'",
",",
"$",
"value",
",",
"'or'",
")",
";",
"}",
"}",
"}",
"if",
"(",
"$",
"soundex_dm",
")",
"{",
"$",
"sdx",
"=",
"Soundex",
"::",
"daitchMokotoff",
"(",
"$",
"surname",
")",
";",
"if",
"(",
"$",
"sdx",
"!==",
"''",
")",
"{",
"foreach",
"(",
"explode",
"(",
"':'",
",",
"$",
"sdx",
")",
"as",
"$",
"value",
")",
"{",
"$",
"query",
"->",
"whereContains",
"(",
"'n_soundex_surn_dm'",
",",
"$",
"value",
",",
"'or'",
")",
";",
"}",
"}",
"}",
"}",
")",
"->",
"select",
"(",
"[",
"'individuals.*'",
"]",
")",
"->",
"distinct",
"(",
")",
"->",
"get",
"(",
")",
"->",
"map",
"(",
"Individual",
"::",
"rowMapper",
"(",
")",
")",
"->",
"filter",
"(",
"GedcomRecord",
"::",
"accessFilter",
"(",
")",
")",
"->",
"all",
"(",
")",
";",
"usort",
"(",
"$",
"individuals",
",",
"Individual",
"::",
"birthDateComparator",
"(",
")",
")",
";",
"return",
"$",
"individuals",
";",
"}"
] |
Fetch all individuals with a matching surname
@param Tree $tree
@param string $surname
@param bool $soundex_dm
@param bool $soundex_std
@return Individual[]
|
[
"Fetch",
"all",
"individuals",
"with",
"a",
"matching",
"surname"
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Http/Controllers/BranchesController.php#L170-L213
|
train
|
fisharebest/webtrees
|
app/Http/Controllers/BranchesController.php
|
BranchesController.getPatriarchsHtml
|
public function getPatriarchsHtml(Tree $tree, array $individuals, array $ancestors, string $surname, bool $soundex_dm, bool $soundex_std): string
{
$html = '';
foreach ($individuals as $individual) {
foreach ($individual->childFamilies() as $family) {
foreach ($family->spouses() as $parent) {
if (in_array($parent, $individuals, true)) {
continue 3;
}
}
}
$html .= $this->getDescendantsHtml($tree, $individuals, $ancestors, $surname, $soundex_dm, $soundex_std, $individual, null);
}
return $html;
}
|
php
|
public function getPatriarchsHtml(Tree $tree, array $individuals, array $ancestors, string $surname, bool $soundex_dm, bool $soundex_std): string
{
$html = '';
foreach ($individuals as $individual) {
foreach ($individual->childFamilies() as $family) {
foreach ($family->spouses() as $parent) {
if (in_array($parent, $individuals, true)) {
continue 3;
}
}
}
$html .= $this->getDescendantsHtml($tree, $individuals, $ancestors, $surname, $soundex_dm, $soundex_std, $individual, null);
}
return $html;
}
|
[
"public",
"function",
"getPatriarchsHtml",
"(",
"Tree",
"$",
"tree",
",",
"array",
"$",
"individuals",
",",
"array",
"$",
"ancestors",
",",
"string",
"$",
"surname",
",",
"bool",
"$",
"soundex_dm",
",",
"bool",
"$",
"soundex_std",
")",
":",
"string",
"{",
"$",
"html",
"=",
"''",
";",
"foreach",
"(",
"$",
"individuals",
"as",
"$",
"individual",
")",
"{",
"foreach",
"(",
"$",
"individual",
"->",
"childFamilies",
"(",
")",
"as",
"$",
"family",
")",
"{",
"foreach",
"(",
"$",
"family",
"->",
"spouses",
"(",
")",
"as",
"$",
"parent",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"parent",
",",
"$",
"individuals",
",",
"true",
")",
")",
"{",
"continue",
"3",
";",
"}",
"}",
"}",
"$",
"html",
".=",
"$",
"this",
"->",
"getDescendantsHtml",
"(",
"$",
"tree",
",",
"$",
"individuals",
",",
"$",
"ancestors",
",",
"$",
"surname",
",",
"$",
"soundex_dm",
",",
"$",
"soundex_std",
",",
"$",
"individual",
",",
"null",
")",
";",
"}",
"return",
"$",
"html",
";",
"}"
] |
For each individual with no ancestors, list their descendants.
@param Tree $tree
@param Individual[] $individuals
@param Individual[] $ancestors
@param string $surname
@param bool $soundex_dm
@param bool $soundex_std
@return string
|
[
"For",
"each",
"individual",
"with",
"no",
"ancestors",
"list",
"their",
"descendants",
"."
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Http/Controllers/BranchesController.php#L227-L242
|
train
|
fisharebest/webtrees
|
app/Module/ModuleHistoricEventsTrait.php
|
ModuleHistoricEventsTrait.historicEventsForIndividual
|
public function historicEventsForIndividual(Individual $individual): Collection
{
$min_date = $individual->getEstimatedBirthDate();
$max_date = $individual->getEstimatedDeathDate();
return (new Collection($this->historicEventsAll()))
->map(static function (string $gedcom) use ($individual): Fact {
return new Fact($gedcom, $individual, 'histo');
})
->filter(static function (Fact $fact) use ($min_date, $max_date): bool {
return Date::compare($fact->date(), $min_date) >= 0 && Date::compare($fact->date(), $max_date) <= 0;
});
}
|
php
|
public function historicEventsForIndividual(Individual $individual): Collection
{
$min_date = $individual->getEstimatedBirthDate();
$max_date = $individual->getEstimatedDeathDate();
return (new Collection($this->historicEventsAll()))
->map(static function (string $gedcom) use ($individual): Fact {
return new Fact($gedcom, $individual, 'histo');
})
->filter(static function (Fact $fact) use ($min_date, $max_date): bool {
return Date::compare($fact->date(), $min_date) >= 0 && Date::compare($fact->date(), $max_date) <= 0;
});
}
|
[
"public",
"function",
"historicEventsForIndividual",
"(",
"Individual",
"$",
"individual",
")",
":",
"Collection",
"{",
"$",
"min_date",
"=",
"$",
"individual",
"->",
"getEstimatedBirthDate",
"(",
")",
";",
"$",
"max_date",
"=",
"$",
"individual",
"->",
"getEstimatedDeathDate",
"(",
")",
";",
"return",
"(",
"new",
"Collection",
"(",
"$",
"this",
"->",
"historicEventsAll",
"(",
")",
")",
")",
"->",
"map",
"(",
"static",
"function",
"(",
"string",
"$",
"gedcom",
")",
"use",
"(",
"$",
"individual",
")",
":",
"Fact",
"{",
"return",
"new",
"Fact",
"(",
"$",
"gedcom",
",",
"$",
"individual",
",",
"'histo'",
")",
";",
"}",
")",
"->",
"filter",
"(",
"static",
"function",
"(",
"Fact",
"$",
"fact",
")",
"use",
"(",
"$",
"min_date",
",",
"$",
"max_date",
")",
":",
"bool",
"{",
"return",
"Date",
"::",
"compare",
"(",
"$",
"fact",
"->",
"date",
"(",
")",
",",
"$",
"min_date",
")",
">=",
"0",
"&&",
"Date",
"::",
"compare",
"(",
"$",
"fact",
"->",
"date",
"(",
")",
",",
"$",
"max_date",
")",
"<=",
"0",
";",
"}",
")",
";",
"}"
] |
Which events should we show for an individual?
@param Individual $individual
@return Collection
|
[
"Which",
"events",
"should",
"we",
"show",
"for",
"an",
"individual?"
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Module/ModuleHistoricEventsTrait.php#L60-L72
|
train
|
fisharebest/webtrees
|
app/Statistics/Repository/HitCountRepository.php
|
HitCountRepository.hitCountQuery
|
private function hitCountQuery($page_name, string $page_parameter = ''): string
{
if ($page_name === '') {
// index.php?ctype=gedcom
$page_name = 'index.php';
$page_parameter = 'gedcom:' . $this->tree->id();
} elseif ($page_name === 'index.php') {
// index.php?ctype=user
$user = $this->user_service->findByIdentifier($page_parameter);
$page_parameter = 'user:' . ($user ? $user->id() : Auth::id());
}
$count = (int) DB::table('hit_counter')
->where('gedcom_id', '=', $this->tree->id())
->where('page_name', '=', $page_name)
->where('page_parameter', '=', $page_parameter)
->value('page_count');
return view(
'statistics/hit-count',
[
'count' => $count,
]
);
}
|
php
|
private function hitCountQuery($page_name, string $page_parameter = ''): string
{
if ($page_name === '') {
// index.php?ctype=gedcom
$page_name = 'index.php';
$page_parameter = 'gedcom:' . $this->tree->id();
} elseif ($page_name === 'index.php') {
// index.php?ctype=user
$user = $this->user_service->findByIdentifier($page_parameter);
$page_parameter = 'user:' . ($user ? $user->id() : Auth::id());
}
$count = (int) DB::table('hit_counter')
->where('gedcom_id', '=', $this->tree->id())
->where('page_name', '=', $page_name)
->where('page_parameter', '=', $page_parameter)
->value('page_count');
return view(
'statistics/hit-count',
[
'count' => $count,
]
);
}
|
[
"private",
"function",
"hitCountQuery",
"(",
"$",
"page_name",
",",
"string",
"$",
"page_parameter",
"=",
"''",
")",
":",
"string",
"{",
"if",
"(",
"$",
"page_name",
"===",
"''",
")",
"{",
"// index.php?ctype=gedcom",
"$",
"page_name",
"=",
"'index.php'",
";",
"$",
"page_parameter",
"=",
"'gedcom:'",
".",
"$",
"this",
"->",
"tree",
"->",
"id",
"(",
")",
";",
"}",
"elseif",
"(",
"$",
"page_name",
"===",
"'index.php'",
")",
"{",
"// index.php?ctype=user",
"$",
"user",
"=",
"$",
"this",
"->",
"user_service",
"->",
"findByIdentifier",
"(",
"$",
"page_parameter",
")",
";",
"$",
"page_parameter",
"=",
"'user:'",
".",
"(",
"$",
"user",
"?",
"$",
"user",
"->",
"id",
"(",
")",
":",
"Auth",
"::",
"id",
"(",
")",
")",
";",
"}",
"$",
"count",
"=",
"(",
"int",
")",
"DB",
"::",
"table",
"(",
"'hit_counter'",
")",
"->",
"where",
"(",
"'gedcom_id'",
",",
"'='",
",",
"$",
"this",
"->",
"tree",
"->",
"id",
"(",
")",
")",
"->",
"where",
"(",
"'page_name'",
",",
"'='",
",",
"$",
"page_name",
")",
"->",
"where",
"(",
"'page_parameter'",
",",
"'='",
",",
"$",
"page_parameter",
")",
"->",
"value",
"(",
"'page_count'",
")",
";",
"return",
"view",
"(",
"'statistics/hit-count'",
",",
"[",
"'count'",
"=>",
"$",
"count",
",",
"]",
")",
";",
"}"
] |
These functions provide access to hitcounter for use in the HTML block.
@param string $page_name
@param string $page_parameter
@return string
|
[
"These",
"functions",
"provide",
"access",
"to",
"hitcounter",
"for",
"use",
"in",
"the",
"HTML",
"block",
"."
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Statistics/Repository/HitCountRepository.php#L60-L84
|
train
|
fisharebest/webtrees
|
app/Http/Controllers/Admin/LocationController.php
|
LocationController.getPlaceListLocation
|
private function getPlaceListLocation(int $id): array
{
// We know the id of the place in the placelocation table,
// now get the id of the same place in the places table
if ($id === 0) {
$fqpn = '';
} else {
$hierarchy = $this->getHierarchy($id);
$fqpn = ', ' . $hierarchy[0]->fqpn;
}
$rows = DB::table('placelocation')
->where('pl_parent_id', '=', $id)
->orderBy('pl_place')
->get();
$list = [];
foreach ($rows as $row) {
// Find/count places without co-ordinates
$children = $this->childLocationStatus((int) $row->pl_id);
$active = $this->isLocationActive($row->pl_place . $fqpn);
if (!$active) {
$badge = 'danger';
} elseif ((int) $children->no_coord > 0) {
$badge = 'warning';
} elseif ((int) $children->child_count > 0) {
$badge = 'info';
} else {
$badge = 'secondary';
}
$row->child_count = (int) $children->child_count;
$row->badge = $badge;
$list[] = $row;
}
return $list;
}
|
php
|
private function getPlaceListLocation(int $id): array
{
// We know the id of the place in the placelocation table,
// now get the id of the same place in the places table
if ($id === 0) {
$fqpn = '';
} else {
$hierarchy = $this->getHierarchy($id);
$fqpn = ', ' . $hierarchy[0]->fqpn;
}
$rows = DB::table('placelocation')
->where('pl_parent_id', '=', $id)
->orderBy('pl_place')
->get();
$list = [];
foreach ($rows as $row) {
// Find/count places without co-ordinates
$children = $this->childLocationStatus((int) $row->pl_id);
$active = $this->isLocationActive($row->pl_place . $fqpn);
if (!$active) {
$badge = 'danger';
} elseif ((int) $children->no_coord > 0) {
$badge = 'warning';
} elseif ((int) $children->child_count > 0) {
$badge = 'info';
} else {
$badge = 'secondary';
}
$row->child_count = (int) $children->child_count;
$row->badge = $badge;
$list[] = $row;
}
return $list;
}
|
[
"private",
"function",
"getPlaceListLocation",
"(",
"int",
"$",
"id",
")",
":",
"array",
"{",
"// We know the id of the place in the placelocation table,",
"// now get the id of the same place in the places table",
"if",
"(",
"$",
"id",
"===",
"0",
")",
"{",
"$",
"fqpn",
"=",
"''",
";",
"}",
"else",
"{",
"$",
"hierarchy",
"=",
"$",
"this",
"->",
"getHierarchy",
"(",
"$",
"id",
")",
";",
"$",
"fqpn",
"=",
"', '",
".",
"$",
"hierarchy",
"[",
"0",
"]",
"->",
"fqpn",
";",
"}",
"$",
"rows",
"=",
"DB",
"::",
"table",
"(",
"'placelocation'",
")",
"->",
"where",
"(",
"'pl_parent_id'",
",",
"'='",
",",
"$",
"id",
")",
"->",
"orderBy",
"(",
"'pl_place'",
")",
"->",
"get",
"(",
")",
";",
"$",
"list",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"rows",
"as",
"$",
"row",
")",
"{",
"// Find/count places without co-ordinates",
"$",
"children",
"=",
"$",
"this",
"->",
"childLocationStatus",
"(",
"(",
"int",
")",
"$",
"row",
"->",
"pl_id",
")",
";",
"$",
"active",
"=",
"$",
"this",
"->",
"isLocationActive",
"(",
"$",
"row",
"->",
"pl_place",
".",
"$",
"fqpn",
")",
";",
"if",
"(",
"!",
"$",
"active",
")",
"{",
"$",
"badge",
"=",
"'danger'",
";",
"}",
"elseif",
"(",
"(",
"int",
")",
"$",
"children",
"->",
"no_coord",
">",
"0",
")",
"{",
"$",
"badge",
"=",
"'warning'",
";",
"}",
"elseif",
"(",
"(",
"int",
")",
"$",
"children",
"->",
"child_count",
">",
"0",
")",
"{",
"$",
"badge",
"=",
"'info'",
";",
"}",
"else",
"{",
"$",
"badge",
"=",
"'secondary'",
";",
"}",
"$",
"row",
"->",
"child_count",
"=",
"(",
"int",
")",
"$",
"children",
"->",
"child_count",
";",
"$",
"row",
"->",
"badge",
"=",
"$",
"badge",
";",
"$",
"list",
"[",
"]",
"=",
"$",
"row",
";",
"}",
"return",
"$",
"list",
";",
"}"
] |
Find all of the places in the hierarchy
@param int $id
@return stdClass[]
|
[
"Find",
"all",
"of",
"the",
"places",
"in",
"the",
"hierarchy"
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Http/Controllers/Admin/LocationController.php#L120-L159
|
train
|
fisharebest/webtrees
|
app/Http/Controllers/Admin/LocationController.php
|
LocationController.childLocationStatus
|
private function childLocationStatus(int $parent_id): stdClass
{
$prefix = DB::connection()->getTablePrefix();
$expression =
$prefix . 'p0.pl_place IS NOT NULL AND ' . $prefix . 'p0.pl_lati IS NULL OR ' .
$prefix . 'p1.pl_place IS NOT NULL AND ' . $prefix . 'p1.pl_lati IS NULL OR ' .
$prefix . 'p2.pl_place IS NOT NULL AND ' . $prefix . 'p2.pl_lati IS NULL OR ' .
$prefix . 'p3.pl_place IS NOT NULL AND ' . $prefix . 'p3.pl_lati IS NULL OR ' .
$prefix . 'p4.pl_place IS NOT NULL AND ' . $prefix . 'p4.pl_lati IS NULL OR ' .
$prefix . 'p5.pl_place IS NOT NULL AND ' . $prefix . 'p5.pl_lati IS NULL OR ' .
$prefix . 'p6.pl_place IS NOT NULL AND ' . $prefix . 'p6.pl_lati IS NULL OR ' .
$prefix . 'p7.pl_place IS NOT NULL AND ' . $prefix . 'p7.pl_lati IS NULL OR ' .
$prefix . 'p8.pl_place IS NOT NULL AND ' . $prefix . 'p8.pl_lati IS NULL OR ' .
$prefix . 'p9.pl_place IS NOT NULL AND ' . $prefix . 'p9.pl_lati IS NULL';
return DB::table('placelocation AS p0')
->leftJoin('placelocation AS p1', 'p1.pl_parent_id', '=', 'p0.pl_id')
->leftJoin('placelocation AS p2', 'p2.pl_parent_id', '=', 'p1.pl_id')
->leftJoin('placelocation AS p3', 'p3.pl_parent_id', '=', 'p2.pl_id')
->leftJoin('placelocation AS p4', 'p4.pl_parent_id', '=', 'p3.pl_id')
->leftJoin('placelocation AS p5', 'p5.pl_parent_id', '=', 'p4.pl_id')
->leftJoin('placelocation AS p6', 'p6.pl_parent_id', '=', 'p5.pl_id')
->leftJoin('placelocation AS p7', 'p7.pl_parent_id', '=', 'p6.pl_id')
->leftJoin('placelocation AS p8', 'p8.pl_parent_id', '=', 'p7.pl_id')
->leftJoin('placelocation AS p9', 'p9.pl_parent_id', '=', 'p8.pl_id')
->where('p0.pl_parent_id', '=', $parent_id)
->select([DB::raw('COUNT(*) AS child_count'), DB::raw('SUM(' . $expression . ') AS no_coord')])
->first();
}
|
php
|
private function childLocationStatus(int $parent_id): stdClass
{
$prefix = DB::connection()->getTablePrefix();
$expression =
$prefix . 'p0.pl_place IS NOT NULL AND ' . $prefix . 'p0.pl_lati IS NULL OR ' .
$prefix . 'p1.pl_place IS NOT NULL AND ' . $prefix . 'p1.pl_lati IS NULL OR ' .
$prefix . 'p2.pl_place IS NOT NULL AND ' . $prefix . 'p2.pl_lati IS NULL OR ' .
$prefix . 'p3.pl_place IS NOT NULL AND ' . $prefix . 'p3.pl_lati IS NULL OR ' .
$prefix . 'p4.pl_place IS NOT NULL AND ' . $prefix . 'p4.pl_lati IS NULL OR ' .
$prefix . 'p5.pl_place IS NOT NULL AND ' . $prefix . 'p5.pl_lati IS NULL OR ' .
$prefix . 'p6.pl_place IS NOT NULL AND ' . $prefix . 'p6.pl_lati IS NULL OR ' .
$prefix . 'p7.pl_place IS NOT NULL AND ' . $prefix . 'p7.pl_lati IS NULL OR ' .
$prefix . 'p8.pl_place IS NOT NULL AND ' . $prefix . 'p8.pl_lati IS NULL OR ' .
$prefix . 'p9.pl_place IS NOT NULL AND ' . $prefix . 'p9.pl_lati IS NULL';
return DB::table('placelocation AS p0')
->leftJoin('placelocation AS p1', 'p1.pl_parent_id', '=', 'p0.pl_id')
->leftJoin('placelocation AS p2', 'p2.pl_parent_id', '=', 'p1.pl_id')
->leftJoin('placelocation AS p3', 'p3.pl_parent_id', '=', 'p2.pl_id')
->leftJoin('placelocation AS p4', 'p4.pl_parent_id', '=', 'p3.pl_id')
->leftJoin('placelocation AS p5', 'p5.pl_parent_id', '=', 'p4.pl_id')
->leftJoin('placelocation AS p6', 'p6.pl_parent_id', '=', 'p5.pl_id')
->leftJoin('placelocation AS p7', 'p7.pl_parent_id', '=', 'p6.pl_id')
->leftJoin('placelocation AS p8', 'p8.pl_parent_id', '=', 'p7.pl_id')
->leftJoin('placelocation AS p9', 'p9.pl_parent_id', '=', 'p8.pl_id')
->where('p0.pl_parent_id', '=', $parent_id)
->select([DB::raw('COUNT(*) AS child_count'), DB::raw('SUM(' . $expression . ') AS no_coord')])
->first();
}
|
[
"private",
"function",
"childLocationStatus",
"(",
"int",
"$",
"parent_id",
")",
":",
"stdClass",
"{",
"$",
"prefix",
"=",
"DB",
"::",
"connection",
"(",
")",
"->",
"getTablePrefix",
"(",
")",
";",
"$",
"expression",
"=",
"$",
"prefix",
".",
"'p0.pl_place IS NOT NULL AND '",
".",
"$",
"prefix",
".",
"'p0.pl_lati IS NULL OR '",
".",
"$",
"prefix",
".",
"'p1.pl_place IS NOT NULL AND '",
".",
"$",
"prefix",
".",
"'p1.pl_lati IS NULL OR '",
".",
"$",
"prefix",
".",
"'p2.pl_place IS NOT NULL AND '",
".",
"$",
"prefix",
".",
"'p2.pl_lati IS NULL OR '",
".",
"$",
"prefix",
".",
"'p3.pl_place IS NOT NULL AND '",
".",
"$",
"prefix",
".",
"'p3.pl_lati IS NULL OR '",
".",
"$",
"prefix",
".",
"'p4.pl_place IS NOT NULL AND '",
".",
"$",
"prefix",
".",
"'p4.pl_lati IS NULL OR '",
".",
"$",
"prefix",
".",
"'p5.pl_place IS NOT NULL AND '",
".",
"$",
"prefix",
".",
"'p5.pl_lati IS NULL OR '",
".",
"$",
"prefix",
".",
"'p6.pl_place IS NOT NULL AND '",
".",
"$",
"prefix",
".",
"'p6.pl_lati IS NULL OR '",
".",
"$",
"prefix",
".",
"'p7.pl_place IS NOT NULL AND '",
".",
"$",
"prefix",
".",
"'p7.pl_lati IS NULL OR '",
".",
"$",
"prefix",
".",
"'p8.pl_place IS NOT NULL AND '",
".",
"$",
"prefix",
".",
"'p8.pl_lati IS NULL OR '",
".",
"$",
"prefix",
".",
"'p9.pl_place IS NOT NULL AND '",
".",
"$",
"prefix",
".",
"'p9.pl_lati IS NULL'",
";",
"return",
"DB",
"::",
"table",
"(",
"'placelocation AS p0'",
")",
"->",
"leftJoin",
"(",
"'placelocation AS p1'",
",",
"'p1.pl_parent_id'",
",",
"'='",
",",
"'p0.pl_id'",
")",
"->",
"leftJoin",
"(",
"'placelocation AS p2'",
",",
"'p2.pl_parent_id'",
",",
"'='",
",",
"'p1.pl_id'",
")",
"->",
"leftJoin",
"(",
"'placelocation AS p3'",
",",
"'p3.pl_parent_id'",
",",
"'='",
",",
"'p2.pl_id'",
")",
"->",
"leftJoin",
"(",
"'placelocation AS p4'",
",",
"'p4.pl_parent_id'",
",",
"'='",
",",
"'p3.pl_id'",
")",
"->",
"leftJoin",
"(",
"'placelocation AS p5'",
",",
"'p5.pl_parent_id'",
",",
"'='",
",",
"'p4.pl_id'",
")",
"->",
"leftJoin",
"(",
"'placelocation AS p6'",
",",
"'p6.pl_parent_id'",
",",
"'='",
",",
"'p5.pl_id'",
")",
"->",
"leftJoin",
"(",
"'placelocation AS p7'",
",",
"'p7.pl_parent_id'",
",",
"'='",
",",
"'p6.pl_id'",
")",
"->",
"leftJoin",
"(",
"'placelocation AS p8'",
",",
"'p8.pl_parent_id'",
",",
"'='",
",",
"'p7.pl_id'",
")",
"->",
"leftJoin",
"(",
"'placelocation AS p9'",
",",
"'p9.pl_parent_id'",
",",
"'='",
",",
"'p8.pl_id'",
")",
"->",
"where",
"(",
"'p0.pl_parent_id'",
",",
"'='",
",",
"$",
"parent_id",
")",
"->",
"select",
"(",
"[",
"DB",
"::",
"raw",
"(",
"'COUNT(*) AS child_count'",
")",
",",
"DB",
"::",
"raw",
"(",
"'SUM('",
".",
"$",
"expression",
".",
"') AS no_coord'",
")",
"]",
")",
"->",
"first",
"(",
")",
";",
"}"
] |
How many children does place have? How many have co-ordinates?
@param int $parent_id
@return stdClass
|
[
"How",
"many",
"children",
"does",
"place",
"have?",
"How",
"many",
"have",
"co",
"-",
"ordinates?"
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Http/Controllers/Admin/LocationController.php#L168-L197
|
train
|
fisharebest/webtrees
|
app/Http/Controllers/Admin/LocationController.php
|
LocationController.isLocationActive
|
private function isLocationActive(string $place_name): bool
{
$places = explode(Gedcom::PLACE_SEPARATOR, $place_name);
$query = DB::table('places AS p0')
->where('p0.p_place', '=', $places[0])
->select(['pl0.*']);
array_shift($places);
foreach ($places as $n => $place) {
$query->join('places AS p' . ($n + 1), static function (JoinClause $join) use ($n, $place): void {
$join
->on('p' . ($n + 1) . '.p_id', '=', 'p' . $n . '.p_parent_id')
->where('p' . ($n + 1) . '.p_place', '=', $place);
});
}
return $query->exists();
}
|
php
|
private function isLocationActive(string $place_name): bool
{
$places = explode(Gedcom::PLACE_SEPARATOR, $place_name);
$query = DB::table('places AS p0')
->where('p0.p_place', '=', $places[0])
->select(['pl0.*']);
array_shift($places);
foreach ($places as $n => $place) {
$query->join('places AS p' . ($n + 1), static function (JoinClause $join) use ($n, $place): void {
$join
->on('p' . ($n + 1) . '.p_id', '=', 'p' . $n . '.p_parent_id')
->where('p' . ($n + 1) . '.p_place', '=', $place);
});
}
return $query->exists();
}
|
[
"private",
"function",
"isLocationActive",
"(",
"string",
"$",
"place_name",
")",
":",
"bool",
"{",
"$",
"places",
"=",
"explode",
"(",
"Gedcom",
"::",
"PLACE_SEPARATOR",
",",
"$",
"place_name",
")",
";",
"$",
"query",
"=",
"DB",
"::",
"table",
"(",
"'places AS p0'",
")",
"->",
"where",
"(",
"'p0.p_place'",
",",
"'='",
",",
"$",
"places",
"[",
"0",
"]",
")",
"->",
"select",
"(",
"[",
"'pl0.*'",
"]",
")",
";",
"array_shift",
"(",
"$",
"places",
")",
";",
"foreach",
"(",
"$",
"places",
"as",
"$",
"n",
"=>",
"$",
"place",
")",
"{",
"$",
"query",
"->",
"join",
"(",
"'places AS p'",
".",
"(",
"$",
"n",
"+",
"1",
")",
",",
"static",
"function",
"(",
"JoinClause",
"$",
"join",
")",
"use",
"(",
"$",
"n",
",",
"$",
"place",
")",
":",
"void",
"{",
"$",
"join",
"->",
"on",
"(",
"'p'",
".",
"(",
"$",
"n",
"+",
"1",
")",
".",
"'.p_id'",
",",
"'='",
",",
"'p'",
".",
"$",
"n",
".",
"'.p_parent_id'",
")",
"->",
"where",
"(",
"'p'",
".",
"(",
"$",
"n",
"+",
"1",
")",
".",
"'.p_place'",
",",
"'='",
",",
"$",
"place",
")",
";",
"}",
")",
";",
"}",
"return",
"$",
"query",
"->",
"exists",
"(",
")",
";",
"}"
] |
Is a place name used in any tree?
@param string $place_name
@return bool
|
[
"Is",
"a",
"place",
"name",
"used",
"in",
"any",
"tree?"
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Http/Controllers/Admin/LocationController.php#L206-L225
|
train
|
fisharebest/webtrees
|
app/Webtrees.php
|
Webtrees.createServerRequest
|
public function createServerRequest(): ServerRequestInterface
{
$server_request_creator = new ServerRequestCreator(
app(ServerRequestFactoryInterface::class),
app(UriFactoryInterface::class),
app(UploadedFileFactoryInterface::class),
app(StreamFactoryInterface::class)
);
// Until all the code is rewritten to use PSR-7 requests, we still need our hybrid request.
if (class_exists(Request::class)) {
return Request::createFromGlobals();
}
return $server_request_creator->fromGlobals();
}
|
php
|
public function createServerRequest(): ServerRequestInterface
{
$server_request_creator = new ServerRequestCreator(
app(ServerRequestFactoryInterface::class),
app(UriFactoryInterface::class),
app(UploadedFileFactoryInterface::class),
app(StreamFactoryInterface::class)
);
// Until all the code is rewritten to use PSR-7 requests, we still need our hybrid request.
if (class_exists(Request::class)) {
return Request::createFromGlobals();
}
return $server_request_creator->fromGlobals();
}
|
[
"public",
"function",
"createServerRequest",
"(",
")",
":",
"ServerRequestInterface",
"{",
"$",
"server_request_creator",
"=",
"new",
"ServerRequestCreator",
"(",
"app",
"(",
"ServerRequestFactoryInterface",
"::",
"class",
")",
",",
"app",
"(",
"UriFactoryInterface",
"::",
"class",
")",
",",
"app",
"(",
"UploadedFileFactoryInterface",
"::",
"class",
")",
",",
"app",
"(",
"StreamFactoryInterface",
"::",
"class",
")",
")",
";",
"// Until all the code is rewritten to use PSR-7 requests, we still need our hybrid request.",
"if",
"(",
"class_exists",
"(",
"Request",
"::",
"class",
")",
")",
"{",
"return",
"Request",
"::",
"createFromGlobals",
"(",
")",
";",
"}",
"return",
"$",
"server_request_creator",
"->",
"fromGlobals",
"(",
")",
";",
"}"
] |
We can use any PSR-7 compatible requests.
@return ServerRequestInterface
|
[
"We",
"can",
"use",
"any",
"PSR",
"-",
"7",
"compatible",
"requests",
"."
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Webtrees.php#L174-L189
|
train
|
fisharebest/webtrees
|
app/Webtrees.php
|
Webtrees.middleware
|
public function middleware(): array
{
return [
PhpEnvironment::class,
EmitResponse::class,
HandleExceptions::class,
ReadConfigIni::class,
UseDatabase::class,
UseDebugbar::class,
UpdateDatabaseSchema::class,
UseCache::class,
UseFilesystem::class,
UseSession::class,
UseTree::class,
UseLocale::class,
CheckForMaintenanceMode::class,
UseTheme::class,
DoHousekeeping::class,
CheckCsrf::class,
UseTransaction::class,
BootModules::class,
ModuleMiddleware::class,
RequestRouter::class,
NoRouteFound::class,
];
}
|
php
|
public function middleware(): array
{
return [
PhpEnvironment::class,
EmitResponse::class,
HandleExceptions::class,
ReadConfigIni::class,
UseDatabase::class,
UseDebugbar::class,
UpdateDatabaseSchema::class,
UseCache::class,
UseFilesystem::class,
UseSession::class,
UseTree::class,
UseLocale::class,
CheckForMaintenanceMode::class,
UseTheme::class,
DoHousekeeping::class,
CheckCsrf::class,
UseTransaction::class,
BootModules::class,
ModuleMiddleware::class,
RequestRouter::class,
NoRouteFound::class,
];
}
|
[
"public",
"function",
"middleware",
"(",
")",
":",
"array",
"{",
"return",
"[",
"PhpEnvironment",
"::",
"class",
",",
"EmitResponse",
"::",
"class",
",",
"HandleExceptions",
"::",
"class",
",",
"ReadConfigIni",
"::",
"class",
",",
"UseDatabase",
"::",
"class",
",",
"UseDebugbar",
"::",
"class",
",",
"UpdateDatabaseSchema",
"::",
"class",
",",
"UseCache",
"::",
"class",
",",
"UseFilesystem",
"::",
"class",
",",
"UseSession",
"::",
"class",
",",
"UseTree",
"::",
"class",
",",
"UseLocale",
"::",
"class",
",",
"CheckForMaintenanceMode",
"::",
"class",
",",
"UseTheme",
"::",
"class",
",",
"DoHousekeeping",
"::",
"class",
",",
"CheckCsrf",
"::",
"class",
",",
"UseTransaction",
"::",
"class",
",",
"BootModules",
"::",
"class",
",",
"ModuleMiddleware",
"::",
"class",
",",
"RequestRouter",
"::",
"class",
",",
"NoRouteFound",
"::",
"class",
",",
"]",
";",
"}"
] |
The webtrees application is built from middleware.
@return string[]
|
[
"The",
"webtrees",
"application",
"is",
"built",
"from",
"middleware",
"."
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Webtrees.php#L196-L221
|
train
|
fisharebest/webtrees
|
app/Http/Controllers/AdminController.php
|
AdminController.privacyRestrictions
|
private function privacyRestrictions(Tree $tree): array
{
return DB::table('default_resn')
->where('gedcom_id', '=', $tree->id())
->get()
->map(static function (stdClass $row) use ($tree): stdClass {
$row->record = null;
$row->label = '';
if ($row->xref !== null) {
$row->record = GedcomRecord::getInstance($row->xref, $tree);
}
if ($row->tag_type) {
$row->tag_label = GedcomTag::getLabel($row->tag_type);
} else {
$row->tag_label = '';
}
return $row;
})
->sort(static function (stdClass $x, stdClass $y): int {
return I18N::strcasecmp($x->tag_label, $y->tag_label);
})
->all();
}
|
php
|
private function privacyRestrictions(Tree $tree): array
{
return DB::table('default_resn')
->where('gedcom_id', '=', $tree->id())
->get()
->map(static function (stdClass $row) use ($tree): stdClass {
$row->record = null;
$row->label = '';
if ($row->xref !== null) {
$row->record = GedcomRecord::getInstance($row->xref, $tree);
}
if ($row->tag_type) {
$row->tag_label = GedcomTag::getLabel($row->tag_type);
} else {
$row->tag_label = '';
}
return $row;
})
->sort(static function (stdClass $x, stdClass $y): int {
return I18N::strcasecmp($x->tag_label, $y->tag_label);
})
->all();
}
|
[
"private",
"function",
"privacyRestrictions",
"(",
"Tree",
"$",
"tree",
")",
":",
"array",
"{",
"return",
"DB",
"::",
"table",
"(",
"'default_resn'",
")",
"->",
"where",
"(",
"'gedcom_id'",
",",
"'='",
",",
"$",
"tree",
"->",
"id",
"(",
")",
")",
"->",
"get",
"(",
")",
"->",
"map",
"(",
"static",
"function",
"(",
"stdClass",
"$",
"row",
")",
"use",
"(",
"$",
"tree",
")",
":",
"stdClass",
"{",
"$",
"row",
"->",
"record",
"=",
"null",
";",
"$",
"row",
"->",
"label",
"=",
"''",
";",
"if",
"(",
"$",
"row",
"->",
"xref",
"!==",
"null",
")",
"{",
"$",
"row",
"->",
"record",
"=",
"GedcomRecord",
"::",
"getInstance",
"(",
"$",
"row",
"->",
"xref",
",",
"$",
"tree",
")",
";",
"}",
"if",
"(",
"$",
"row",
"->",
"tag_type",
")",
"{",
"$",
"row",
"->",
"tag_label",
"=",
"GedcomTag",
"::",
"getLabel",
"(",
"$",
"row",
"->",
"tag_type",
")",
";",
"}",
"else",
"{",
"$",
"row",
"->",
"tag_label",
"=",
"''",
";",
"}",
"return",
"$",
"row",
";",
"}",
")",
"->",
"sort",
"(",
"static",
"function",
"(",
"stdClass",
"$",
"x",
",",
"stdClass",
"$",
"y",
")",
":",
"int",
"{",
"return",
"I18N",
"::",
"strcasecmp",
"(",
"$",
"x",
"->",
"tag_label",
",",
"$",
"y",
"->",
"tag_label",
")",
";",
"}",
")",
"->",
"all",
"(",
")",
";",
"}"
] |
The current privacy restrictions for a tree.
@param Tree $tree
@return array
|
[
"The",
"current",
"privacy",
"restrictions",
"for",
"a",
"tree",
"."
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Http/Controllers/AdminController.php#L380-L405
|
train
|
fisharebest/webtrees
|
app/Http/Controllers/AdminController.php
|
AdminController.tagsForPrivacy
|
private function tagsForPrivacy(Tree $tree): array
{
$tags = array_unique(array_merge(
explode(',', $tree->getPreference('INDI_FACTS_ADD')),
explode(',', $tree->getPreference('INDI_FACTS_UNIQUE')),
explode(',', $tree->getPreference('FAM_FACTS_ADD')),
explode(',', $tree->getPreference('FAM_FACTS_UNIQUE')),
explode(',', $tree->getPreference('NOTE_FACTS_ADD')),
explode(',', $tree->getPreference('NOTE_FACTS_UNIQUE')),
explode(',', $tree->getPreference('SOUR_FACTS_ADD')),
explode(',', $tree->getPreference('SOUR_FACTS_UNIQUE')),
explode(',', $tree->getPreference('REPO_FACTS_ADD')),
explode(',', $tree->getPreference('REPO_FACTS_UNIQUE')),
[
'SOUR',
'REPO',
'OBJE',
'_PRIM',
'NOTE',
'SUBM',
'SUBN',
'_UID',
'CHAN',
]
));
$all_tags = [];
foreach ($tags as $tag) {
if ($tag) {
$all_tags[$tag] = GedcomTag::getLabel($tag);
}
}
uasort($all_tags, '\Fisharebest\Webtrees\I18N::strcasecmp');
return array_merge(
['' => I18N::translate('All facts and events')],
$all_tags
);
}
|
php
|
private function tagsForPrivacy(Tree $tree): array
{
$tags = array_unique(array_merge(
explode(',', $tree->getPreference('INDI_FACTS_ADD')),
explode(',', $tree->getPreference('INDI_FACTS_UNIQUE')),
explode(',', $tree->getPreference('FAM_FACTS_ADD')),
explode(',', $tree->getPreference('FAM_FACTS_UNIQUE')),
explode(',', $tree->getPreference('NOTE_FACTS_ADD')),
explode(',', $tree->getPreference('NOTE_FACTS_UNIQUE')),
explode(',', $tree->getPreference('SOUR_FACTS_ADD')),
explode(',', $tree->getPreference('SOUR_FACTS_UNIQUE')),
explode(',', $tree->getPreference('REPO_FACTS_ADD')),
explode(',', $tree->getPreference('REPO_FACTS_UNIQUE')),
[
'SOUR',
'REPO',
'OBJE',
'_PRIM',
'NOTE',
'SUBM',
'SUBN',
'_UID',
'CHAN',
]
));
$all_tags = [];
foreach ($tags as $tag) {
if ($tag) {
$all_tags[$tag] = GedcomTag::getLabel($tag);
}
}
uasort($all_tags, '\Fisharebest\Webtrees\I18N::strcasecmp');
return array_merge(
['' => I18N::translate('All facts and events')],
$all_tags
);
}
|
[
"private",
"function",
"tagsForPrivacy",
"(",
"Tree",
"$",
"tree",
")",
":",
"array",
"{",
"$",
"tags",
"=",
"array_unique",
"(",
"array_merge",
"(",
"explode",
"(",
"','",
",",
"$",
"tree",
"->",
"getPreference",
"(",
"'INDI_FACTS_ADD'",
")",
")",
",",
"explode",
"(",
"','",
",",
"$",
"tree",
"->",
"getPreference",
"(",
"'INDI_FACTS_UNIQUE'",
")",
")",
",",
"explode",
"(",
"','",
",",
"$",
"tree",
"->",
"getPreference",
"(",
"'FAM_FACTS_ADD'",
")",
")",
",",
"explode",
"(",
"','",
",",
"$",
"tree",
"->",
"getPreference",
"(",
"'FAM_FACTS_UNIQUE'",
")",
")",
",",
"explode",
"(",
"','",
",",
"$",
"tree",
"->",
"getPreference",
"(",
"'NOTE_FACTS_ADD'",
")",
")",
",",
"explode",
"(",
"','",
",",
"$",
"tree",
"->",
"getPreference",
"(",
"'NOTE_FACTS_UNIQUE'",
")",
")",
",",
"explode",
"(",
"','",
",",
"$",
"tree",
"->",
"getPreference",
"(",
"'SOUR_FACTS_ADD'",
")",
")",
",",
"explode",
"(",
"','",
",",
"$",
"tree",
"->",
"getPreference",
"(",
"'SOUR_FACTS_UNIQUE'",
")",
")",
",",
"explode",
"(",
"','",
",",
"$",
"tree",
"->",
"getPreference",
"(",
"'REPO_FACTS_ADD'",
")",
")",
",",
"explode",
"(",
"','",
",",
"$",
"tree",
"->",
"getPreference",
"(",
"'REPO_FACTS_UNIQUE'",
")",
")",
",",
"[",
"'SOUR'",
",",
"'REPO'",
",",
"'OBJE'",
",",
"'_PRIM'",
",",
"'NOTE'",
",",
"'SUBM'",
",",
"'SUBN'",
",",
"'_UID'",
",",
"'CHAN'",
",",
"]",
")",
")",
";",
"$",
"all_tags",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"tags",
"as",
"$",
"tag",
")",
"{",
"if",
"(",
"$",
"tag",
")",
"{",
"$",
"all_tags",
"[",
"$",
"tag",
"]",
"=",
"GedcomTag",
"::",
"getLabel",
"(",
"$",
"tag",
")",
";",
"}",
"}",
"uasort",
"(",
"$",
"all_tags",
",",
"'\\Fisharebest\\Webtrees\\I18N::strcasecmp'",
")",
";",
"return",
"array_merge",
"(",
"[",
"''",
"=>",
"I18N",
"::",
"translate",
"(",
"'All facts and events'",
")",
"]",
",",
"$",
"all_tags",
")",
";",
"}"
] |
Generate a list of potential problems with the server.
@param Tree $tree
@return string[]
|
[
"Generate",
"a",
"list",
"of",
"potential",
"problems",
"with",
"the",
"server",
"."
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Http/Controllers/AdminController.php#L414-L454
|
train
|
fisharebest/webtrees
|
app/Services/ServerCheckService.php
|
ServerCheckService.serverErrors
|
public function serverErrors($driver = ''): Collection
{
$errors = Collection::make([
$this->databaseDriverErrors($driver),
$this->checkPhpExtension('mbstring'),
$this->checkPhpExtension('iconv'),
$this->checkPhpExtension('pcre'),
$this->checkPhpExtension('session'),
$this->checkPhpExtension('xml'),
$this->checkPhpFunction('parse_ini_file'),
]);
return $errors
->flatten()
->filter();
}
|
php
|
public function serverErrors($driver = ''): Collection
{
$errors = Collection::make([
$this->databaseDriverErrors($driver),
$this->checkPhpExtension('mbstring'),
$this->checkPhpExtension('iconv'),
$this->checkPhpExtension('pcre'),
$this->checkPhpExtension('session'),
$this->checkPhpExtension('xml'),
$this->checkPhpFunction('parse_ini_file'),
]);
return $errors
->flatten()
->filter();
}
|
[
"public",
"function",
"serverErrors",
"(",
"$",
"driver",
"=",
"''",
")",
":",
"Collection",
"{",
"$",
"errors",
"=",
"Collection",
"::",
"make",
"(",
"[",
"$",
"this",
"->",
"databaseDriverErrors",
"(",
"$",
"driver",
")",
",",
"$",
"this",
"->",
"checkPhpExtension",
"(",
"'mbstring'",
")",
",",
"$",
"this",
"->",
"checkPhpExtension",
"(",
"'iconv'",
")",
",",
"$",
"this",
"->",
"checkPhpExtension",
"(",
"'pcre'",
")",
",",
"$",
"this",
"->",
"checkPhpExtension",
"(",
"'session'",
")",
",",
"$",
"this",
"->",
"checkPhpExtension",
"(",
"'xml'",
")",
",",
"$",
"this",
"->",
"checkPhpFunction",
"(",
"'parse_ini_file'",
")",
",",
"]",
")",
";",
"return",
"$",
"errors",
"->",
"flatten",
"(",
")",
"->",
"filter",
"(",
")",
";",
"}"
] |
Things that may cause webtrees to break.
@param string $driver
@return Collection
@return string[]
|
[
"Things",
"that",
"may",
"cause",
"webtrees",
"to",
"break",
"."
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Services/ServerCheckService.php#L60-L75
|
train
|
fisharebest/webtrees
|
app/Services/ServerCheckService.php
|
ServerCheckService.serverWarnings
|
public function serverWarnings($driver = ''): Collection
{
$warnings = Collection::make([
$this->databaseDriverWarnings($driver),
$this->checkPhpExtension('curl'),
$this->checkPhpExtension('gd'),
$this->checkPhpExtension('simplexml'),
$this->checkPhpIni('file_uploads', true),
$this->checkSystemTemporaryFolder(),
$this->checkPhpVersion(),
]);
return $warnings
->flatten()
->filter();
}
|
php
|
public function serverWarnings($driver = ''): Collection
{
$warnings = Collection::make([
$this->databaseDriverWarnings($driver),
$this->checkPhpExtension('curl'),
$this->checkPhpExtension('gd'),
$this->checkPhpExtension('simplexml'),
$this->checkPhpIni('file_uploads', true),
$this->checkSystemTemporaryFolder(),
$this->checkPhpVersion(),
]);
return $warnings
->flatten()
->filter();
}
|
[
"public",
"function",
"serverWarnings",
"(",
"$",
"driver",
"=",
"''",
")",
":",
"Collection",
"{",
"$",
"warnings",
"=",
"Collection",
"::",
"make",
"(",
"[",
"$",
"this",
"->",
"databaseDriverWarnings",
"(",
"$",
"driver",
")",
",",
"$",
"this",
"->",
"checkPhpExtension",
"(",
"'curl'",
")",
",",
"$",
"this",
"->",
"checkPhpExtension",
"(",
"'gd'",
")",
",",
"$",
"this",
"->",
"checkPhpExtension",
"(",
"'simplexml'",
")",
",",
"$",
"this",
"->",
"checkPhpIni",
"(",
"'file_uploads'",
",",
"true",
")",
",",
"$",
"this",
"->",
"checkSystemTemporaryFolder",
"(",
")",
",",
"$",
"this",
"->",
"checkPhpVersion",
"(",
")",
",",
"]",
")",
";",
"return",
"$",
"warnings",
"->",
"flatten",
"(",
")",
"->",
"filter",
"(",
")",
";",
"}"
] |
Things that should be fixed, but which won't stop completely webtrees from running.
@param string $driver
@return Collection
@return string[]
|
[
"Things",
"that",
"should",
"be",
"fixed",
"but",
"which",
"won",
"t",
"stop",
"completely",
"webtrees",
"from",
"running",
"."
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Services/ServerCheckService.php#L85-L100
|
train
|
fisharebest/webtrees
|
app/Services/ServerCheckService.php
|
ServerCheckService.isFunctionDisabled
|
public function isFunctionDisabled(string $function): bool
{
$disable_functions = explode(',', ini_get('disable_functions'));
$disable_functions = array_map(static function (string $func): string {
return strtolower(trim($func));
}, $disable_functions);
$function = strtolower($function);
return in_array($function, $disable_functions, true) || !function_exists($function);
}
|
php
|
public function isFunctionDisabled(string $function): bool
{
$disable_functions = explode(',', ini_get('disable_functions'));
$disable_functions = array_map(static function (string $func): string {
return strtolower(trim($func));
}, $disable_functions);
$function = strtolower($function);
return in_array($function, $disable_functions, true) || !function_exists($function);
}
|
[
"public",
"function",
"isFunctionDisabled",
"(",
"string",
"$",
"function",
")",
":",
"bool",
"{",
"$",
"disable_functions",
"=",
"explode",
"(",
"','",
",",
"ini_get",
"(",
"'disable_functions'",
")",
")",
";",
"$",
"disable_functions",
"=",
"array_map",
"(",
"static",
"function",
"(",
"string",
"$",
"func",
")",
":",
"string",
"{",
"return",
"strtolower",
"(",
"trim",
"(",
"$",
"func",
")",
")",
";",
"}",
",",
"$",
"disable_functions",
")",
";",
"$",
"function",
"=",
"strtolower",
"(",
"$",
"function",
")",
";",
"return",
"in_array",
"(",
"$",
"function",
",",
"$",
"disable_functions",
",",
"true",
")",
"||",
"!",
"function_exists",
"(",
"$",
"function",
")",
";",
"}"
] |
Check if a PHP function is in the list of disabled functions.
@param string $function
@return bool
|
[
"Check",
"if",
"a",
"PHP",
"function",
"is",
"in",
"the",
"list",
"of",
"disabled",
"functions",
"."
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Services/ServerCheckService.php#L148-L158
|
train
|
fisharebest/webtrees
|
app/Module/ModuleAnalyticsTrait.php
|
ModuleAnalyticsTrait.analyticsCanShow
|
public function analyticsCanShow(): bool
{
$request = app(ServerRequestInterface::class);
// If the browser sets the DNT header, then we won't use analytics.
$dnt = $request->getServerParams()['HTTP_DNT'] ?? '';
if ($dnt === '1') {
return false;
}
foreach ($this->analyticsParameters() as $parameter) {
if ($parameter === '') {
return false;
}
}
return true;
}
|
php
|
public function analyticsCanShow(): bool
{
$request = app(ServerRequestInterface::class);
// If the browser sets the DNT header, then we won't use analytics.
$dnt = $request->getServerParams()['HTTP_DNT'] ?? '';
if ($dnt === '1') {
return false;
}
foreach ($this->analyticsParameters() as $parameter) {
if ($parameter === '') {
return false;
}
}
return true;
}
|
[
"public",
"function",
"analyticsCanShow",
"(",
")",
":",
"bool",
"{",
"$",
"request",
"=",
"app",
"(",
"ServerRequestInterface",
"::",
"class",
")",
";",
"// If the browser sets the DNT header, then we won't use analytics.",
"$",
"dnt",
"=",
"$",
"request",
"->",
"getServerParams",
"(",
")",
"[",
"'HTTP_DNT'",
"]",
"??",
"''",
";",
"if",
"(",
"$",
"dnt",
"===",
"'1'",
")",
"{",
"return",
"false",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"analyticsParameters",
"(",
")",
"as",
"$",
"parameter",
")",
"{",
"if",
"(",
"$",
"parameter",
"===",
"''",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] |
Should we add this tracker?
@return bool
|
[
"Should",
"we",
"add",
"this",
"tracker?"
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Module/ModuleAnalyticsTrait.php#L36-L54
|
train
|
fisharebest/webtrees
|
app/Http/Controllers/MessageController.php
|
MessageController.contactPage
|
public function contactPage(ServerRequestInterface $request, Tree $tree): ResponseInterface
{
$referer = $request->getHeaderLine('referer');
$body = $request->get('body', '');
$from_email = $request->get('from_email', '');
$from_name = $request->get('from_name', '');
$subject = $request->get('subject', '');
$to = $request->get('to', '');
$url = $request->get('url', $referer);
$to_user = $this->user_service->findByUserName($to);
if (!in_array($to_user, $this->validContacts($tree), false)) {
throw new AccessDeniedHttpException('Invalid contact user id');
}
$to_name = $to_user->realName();
$title = I18N::translate('Send a message');
return $this->viewResponse('contact-page', [
'body' => $body,
'from_email' => $from_email,
'from_name' => $from_name,
'subject' => $subject,
'title' => $title,
'to' => $to,
'to_name' => $to_name,
'url' => $url,
]);
}
|
php
|
public function contactPage(ServerRequestInterface $request, Tree $tree): ResponseInterface
{
$referer = $request->getHeaderLine('referer');
$body = $request->get('body', '');
$from_email = $request->get('from_email', '');
$from_name = $request->get('from_name', '');
$subject = $request->get('subject', '');
$to = $request->get('to', '');
$url = $request->get('url', $referer);
$to_user = $this->user_service->findByUserName($to);
if (!in_array($to_user, $this->validContacts($tree), false)) {
throw new AccessDeniedHttpException('Invalid contact user id');
}
$to_name = $to_user->realName();
$title = I18N::translate('Send a message');
return $this->viewResponse('contact-page', [
'body' => $body,
'from_email' => $from_email,
'from_name' => $from_name,
'subject' => $subject,
'title' => $title,
'to' => $to,
'to_name' => $to_name,
'url' => $url,
]);
}
|
[
"public",
"function",
"contactPage",
"(",
"ServerRequestInterface",
"$",
"request",
",",
"Tree",
"$",
"tree",
")",
":",
"ResponseInterface",
"{",
"$",
"referer",
"=",
"$",
"request",
"->",
"getHeaderLine",
"(",
"'referer'",
")",
";",
"$",
"body",
"=",
"$",
"request",
"->",
"get",
"(",
"'body'",
",",
"''",
")",
";",
"$",
"from_email",
"=",
"$",
"request",
"->",
"get",
"(",
"'from_email'",
",",
"''",
")",
";",
"$",
"from_name",
"=",
"$",
"request",
"->",
"get",
"(",
"'from_name'",
",",
"''",
")",
";",
"$",
"subject",
"=",
"$",
"request",
"->",
"get",
"(",
"'subject'",
",",
"''",
")",
";",
"$",
"to",
"=",
"$",
"request",
"->",
"get",
"(",
"'to'",
",",
"''",
")",
";",
"$",
"url",
"=",
"$",
"request",
"->",
"get",
"(",
"'url'",
",",
"$",
"referer",
")",
";",
"$",
"to_user",
"=",
"$",
"this",
"->",
"user_service",
"->",
"findByUserName",
"(",
"$",
"to",
")",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"to_user",
",",
"$",
"this",
"->",
"validContacts",
"(",
"$",
"tree",
")",
",",
"false",
")",
")",
"{",
"throw",
"new",
"AccessDeniedHttpException",
"(",
"'Invalid contact user id'",
")",
";",
"}",
"$",
"to_name",
"=",
"$",
"to_user",
"->",
"realName",
"(",
")",
";",
"$",
"title",
"=",
"I18N",
"::",
"translate",
"(",
"'Send a message'",
")",
";",
"return",
"$",
"this",
"->",
"viewResponse",
"(",
"'contact-page'",
",",
"[",
"'body'",
"=>",
"$",
"body",
",",
"'from_email'",
"=>",
"$",
"from_email",
",",
"'from_name'",
"=>",
"$",
"from_name",
",",
"'subject'",
"=>",
"$",
"subject",
",",
"'title'",
"=>",
"$",
"title",
",",
"'to'",
"=>",
"$",
"to",
",",
"'to_name'",
"=>",
"$",
"to_name",
",",
"'url'",
"=>",
"$",
"url",
",",
"]",
")",
";",
"}"
] |
A form to compose a message from a visitor.
@param ServerRequestInterface $request
@param Tree $tree
@return ResponseInterface
|
[
"A",
"form",
"to",
"compose",
"a",
"message",
"from",
"a",
"visitor",
"."
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Http/Controllers/MessageController.php#L148-L179
|
train
|
fisharebest/webtrees
|
app/Http/Controllers/MessageController.php
|
MessageController.validContacts
|
private function validContacts(Tree $tree): array
{
$contacts = [
$this->user_service->find((int) $tree->getPreference('CONTACT_USER_ID')),
$this->user_service->find((int) $tree->getPreference('WEBMASTER_USER_ID')),
];
return array_filter($contacts);
}
|
php
|
private function validContacts(Tree $tree): array
{
$contacts = [
$this->user_service->find((int) $tree->getPreference('CONTACT_USER_ID')),
$this->user_service->find((int) $tree->getPreference('WEBMASTER_USER_ID')),
];
return array_filter($contacts);
}
|
[
"private",
"function",
"validContacts",
"(",
"Tree",
"$",
"tree",
")",
":",
"array",
"{",
"$",
"contacts",
"=",
"[",
"$",
"this",
"->",
"user_service",
"->",
"find",
"(",
"(",
"int",
")",
"$",
"tree",
"->",
"getPreference",
"(",
"'CONTACT_USER_ID'",
")",
")",
",",
"$",
"this",
"->",
"user_service",
"->",
"find",
"(",
"(",
"int",
")",
"$",
"tree",
"->",
"getPreference",
"(",
"'WEBMASTER_USER_ID'",
")",
")",
",",
"]",
";",
"return",
"array_filter",
"(",
"$",
"contacts",
")",
";",
"}"
] |
Contact messages can only be sent to the designated contacts
@param Tree $tree
@return UserInterface[]
|
[
"Contact",
"messages",
"can",
"only",
"be",
"sent",
"to",
"the",
"designated",
"contacts"
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Http/Controllers/MessageController.php#L353-L361
|
train
|
fisharebest/webtrees
|
app/Http/Controllers/MessageController.php
|
MessageController.deliverMessage
|
private function deliverMessage(Tree $tree, UserInterface $sender, UserInterface $recipient, string $subject, string $body, string $url, string $ip): bool
{
$success = true;
// Temporarily switch to the recipient's language
I18N::init($recipient->getPreference('language'));
$body_text = view('emails/message-user-text', [
'sender' => $sender,
'recipient' => $recipient,
'message' => $body,
'url' => $url,
]);
$body_html = view('emails/message-user-html', [
'sender' => $sender,
'recipient' => $recipient,
'message' => $body,
'url' => $url,
]);
// Send via the internal messaging system.
if ($this->sendInternalMessage($recipient)) {
DB::table('message')->insert([
'sender' => Auth::check() ? Auth::user()->email() : $sender->email(),
'ip_address' => $ip,
'user_id' => $recipient->id(),
'subject' => $subject,
'body' => $body_text,
]);
}
// Send via email
if ($this->sendEmail($recipient)) {
$success = Mail::send(
new TreeUser($tree),
$recipient,
$sender,
I18N::translate('webtrees message') . ' - ' . $subject,
$body_text,
$body_html
);
}
I18N::init(WT_LOCALE);
return $success;
}
|
php
|
private function deliverMessage(Tree $tree, UserInterface $sender, UserInterface $recipient, string $subject, string $body, string $url, string $ip): bool
{
$success = true;
// Temporarily switch to the recipient's language
I18N::init($recipient->getPreference('language'));
$body_text = view('emails/message-user-text', [
'sender' => $sender,
'recipient' => $recipient,
'message' => $body,
'url' => $url,
]);
$body_html = view('emails/message-user-html', [
'sender' => $sender,
'recipient' => $recipient,
'message' => $body,
'url' => $url,
]);
// Send via the internal messaging system.
if ($this->sendInternalMessage($recipient)) {
DB::table('message')->insert([
'sender' => Auth::check() ? Auth::user()->email() : $sender->email(),
'ip_address' => $ip,
'user_id' => $recipient->id(),
'subject' => $subject,
'body' => $body_text,
]);
}
// Send via email
if ($this->sendEmail($recipient)) {
$success = Mail::send(
new TreeUser($tree),
$recipient,
$sender,
I18N::translate('webtrees message') . ' - ' . $subject,
$body_text,
$body_html
);
}
I18N::init(WT_LOCALE);
return $success;
}
|
[
"private",
"function",
"deliverMessage",
"(",
"Tree",
"$",
"tree",
",",
"UserInterface",
"$",
"sender",
",",
"UserInterface",
"$",
"recipient",
",",
"string",
"$",
"subject",
",",
"string",
"$",
"body",
",",
"string",
"$",
"url",
",",
"string",
"$",
"ip",
")",
":",
"bool",
"{",
"$",
"success",
"=",
"true",
";",
"// Temporarily switch to the recipient's language",
"I18N",
"::",
"init",
"(",
"$",
"recipient",
"->",
"getPreference",
"(",
"'language'",
")",
")",
";",
"$",
"body_text",
"=",
"view",
"(",
"'emails/message-user-text'",
",",
"[",
"'sender'",
"=>",
"$",
"sender",
",",
"'recipient'",
"=>",
"$",
"recipient",
",",
"'message'",
"=>",
"$",
"body",
",",
"'url'",
"=>",
"$",
"url",
",",
"]",
")",
";",
"$",
"body_html",
"=",
"view",
"(",
"'emails/message-user-html'",
",",
"[",
"'sender'",
"=>",
"$",
"sender",
",",
"'recipient'",
"=>",
"$",
"recipient",
",",
"'message'",
"=>",
"$",
"body",
",",
"'url'",
"=>",
"$",
"url",
",",
"]",
")",
";",
"// Send via the internal messaging system.",
"if",
"(",
"$",
"this",
"->",
"sendInternalMessage",
"(",
"$",
"recipient",
")",
")",
"{",
"DB",
"::",
"table",
"(",
"'message'",
")",
"->",
"insert",
"(",
"[",
"'sender'",
"=>",
"Auth",
"::",
"check",
"(",
")",
"?",
"Auth",
"::",
"user",
"(",
")",
"->",
"email",
"(",
")",
":",
"$",
"sender",
"->",
"email",
"(",
")",
",",
"'ip_address'",
"=>",
"$",
"ip",
",",
"'user_id'",
"=>",
"$",
"recipient",
"->",
"id",
"(",
")",
",",
"'subject'",
"=>",
"$",
"subject",
",",
"'body'",
"=>",
"$",
"body_text",
",",
"]",
")",
";",
"}",
"// Send via email",
"if",
"(",
"$",
"this",
"->",
"sendEmail",
"(",
"$",
"recipient",
")",
")",
"{",
"$",
"success",
"=",
"Mail",
"::",
"send",
"(",
"new",
"TreeUser",
"(",
"$",
"tree",
")",
",",
"$",
"recipient",
",",
"$",
"sender",
",",
"I18N",
"::",
"translate",
"(",
"'webtrees message'",
")",
".",
"' - '",
".",
"$",
"subject",
",",
"$",
"body_text",
",",
"$",
"body_html",
")",
";",
"}",
"I18N",
"::",
"init",
"(",
"WT_LOCALE",
")",
";",
"return",
"$",
"success",
";",
"}"
] |
Add a message to a user's inbox, send it to them via email, or both.
@param Tree $tree
@param UserInterface $sender
@param UserInterface $recipient
@param string $subject
@param string $body
@param string $url
@param string $ip
@return bool
|
[
"Add",
"a",
"message",
"to",
"a",
"user",
"s",
"inbox",
"send",
"it",
"to",
"them",
"via",
"email",
"or",
"both",
"."
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Http/Controllers/MessageController.php#L376-L423
|
train
|
fisharebest/webtrees
|
app/Services/SearchService.php
|
SearchService.searchFamilyNames
|
public function searchFamilyNames(array $trees, array $search, int $offset = 0, int $limit = PHP_INT_MAX): Collection
{
$query = DB::table('families')
->leftJoin('name AS husb_name', static function (JoinClause $join): void {
$join
->on('husb_name.n_file', '=', 'families.f_file')
->on('husb_name.n_id', '=', 'families.f_husb')
->where('husb_name.n_type', '<>', '_MARNM');
})
->leftJoin('name AS wife_name', static function (JoinClause $join): void {
$join
->on('wife_name.n_file', '=', 'families.f_file')
->on('wife_name.n_id', '=', 'families.f_wife')
->where('wife_name.n_type', '<>', '_MARNM');
});
$prefix = DB::connection()->getTablePrefix();
$field = DB::raw('COALESCE(' . $prefix . "husb_name.n_full, '') || COALESCE(" . $prefix . "wife_name.n_full, '')");
$this->whereTrees($query, 'f_file', $trees);
$this->whereSearch($query, $field, $search);
$query
->orderBy('husb_name.n_sort')
->orderBy('wife_name.n_sort')
->select(['families.*', 'husb_name.n_sort', 'wife_name.n_sort'])
->distinct();
return $this->paginateQuery($query, Family::rowMapper(), GedcomRecord::accessFilter(), $offset, $limit);
}
|
php
|
public function searchFamilyNames(array $trees, array $search, int $offset = 0, int $limit = PHP_INT_MAX): Collection
{
$query = DB::table('families')
->leftJoin('name AS husb_name', static function (JoinClause $join): void {
$join
->on('husb_name.n_file', '=', 'families.f_file')
->on('husb_name.n_id', '=', 'families.f_husb')
->where('husb_name.n_type', '<>', '_MARNM');
})
->leftJoin('name AS wife_name', static function (JoinClause $join): void {
$join
->on('wife_name.n_file', '=', 'families.f_file')
->on('wife_name.n_id', '=', 'families.f_wife')
->where('wife_name.n_type', '<>', '_MARNM');
});
$prefix = DB::connection()->getTablePrefix();
$field = DB::raw('COALESCE(' . $prefix . "husb_name.n_full, '') || COALESCE(" . $prefix . "wife_name.n_full, '')");
$this->whereTrees($query, 'f_file', $trees);
$this->whereSearch($query, $field, $search);
$query
->orderBy('husb_name.n_sort')
->orderBy('wife_name.n_sort')
->select(['families.*', 'husb_name.n_sort', 'wife_name.n_sort'])
->distinct();
return $this->paginateQuery($query, Family::rowMapper(), GedcomRecord::accessFilter(), $offset, $limit);
}
|
[
"public",
"function",
"searchFamilyNames",
"(",
"array",
"$",
"trees",
",",
"array",
"$",
"search",
",",
"int",
"$",
"offset",
"=",
"0",
",",
"int",
"$",
"limit",
"=",
"PHP_INT_MAX",
")",
":",
"Collection",
"{",
"$",
"query",
"=",
"DB",
"::",
"table",
"(",
"'families'",
")",
"->",
"leftJoin",
"(",
"'name AS husb_name'",
",",
"static",
"function",
"(",
"JoinClause",
"$",
"join",
")",
":",
"void",
"{",
"$",
"join",
"->",
"on",
"(",
"'husb_name.n_file'",
",",
"'='",
",",
"'families.f_file'",
")",
"->",
"on",
"(",
"'husb_name.n_id'",
",",
"'='",
",",
"'families.f_husb'",
")",
"->",
"where",
"(",
"'husb_name.n_type'",
",",
"'<>'",
",",
"'_MARNM'",
")",
";",
"}",
")",
"->",
"leftJoin",
"(",
"'name AS wife_name'",
",",
"static",
"function",
"(",
"JoinClause",
"$",
"join",
")",
":",
"void",
"{",
"$",
"join",
"->",
"on",
"(",
"'wife_name.n_file'",
",",
"'='",
",",
"'families.f_file'",
")",
"->",
"on",
"(",
"'wife_name.n_id'",
",",
"'='",
",",
"'families.f_wife'",
")",
"->",
"where",
"(",
"'wife_name.n_type'",
",",
"'<>'",
",",
"'_MARNM'",
")",
";",
"}",
")",
";",
"$",
"prefix",
"=",
"DB",
"::",
"connection",
"(",
")",
"->",
"getTablePrefix",
"(",
")",
";",
"$",
"field",
"=",
"DB",
"::",
"raw",
"(",
"'COALESCE('",
".",
"$",
"prefix",
".",
"\"husb_name.n_full, '') || COALESCE(\"",
".",
"$",
"prefix",
".",
"\"wife_name.n_full, '')\"",
")",
";",
"$",
"this",
"->",
"whereTrees",
"(",
"$",
"query",
",",
"'f_file'",
",",
"$",
"trees",
")",
";",
"$",
"this",
"->",
"whereSearch",
"(",
"$",
"query",
",",
"$",
"field",
",",
"$",
"search",
")",
";",
"$",
"query",
"->",
"orderBy",
"(",
"'husb_name.n_sort'",
")",
"->",
"orderBy",
"(",
"'wife_name.n_sort'",
")",
"->",
"select",
"(",
"[",
"'families.*'",
",",
"'husb_name.n_sort'",
",",
"'wife_name.n_sort'",
"]",
")",
"->",
"distinct",
"(",
")",
";",
"return",
"$",
"this",
"->",
"paginateQuery",
"(",
"$",
"query",
",",
"Family",
"::",
"rowMapper",
"(",
")",
",",
"GedcomRecord",
"::",
"accessFilter",
"(",
")",
",",
"$",
"offset",
",",
"$",
"limit",
")",
";",
"}"
] |
Search for families by name.
@param Tree[] $trees
@param string[] $search
@param int $offset
@param int $limit
@return Collection
@return Family[]
|
[
"Search",
"for",
"families",
"by",
"name",
"."
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Services/SearchService.php#L81-L110
|
train
|
fisharebest/webtrees
|
app/Services/SearchService.php
|
SearchService.searchIndividualNames
|
public function searchIndividualNames(array $trees, array $search, int $offset = 0, int $limit = PHP_INT_MAX): Collection
{
$query = DB::table('individuals')
->join('name', static function (JoinClause $join): void {
$join
->on('name.n_file', '=', 'individuals.i_file')
->on('name.n_id', '=', 'individuals.i_id');
})
->orderBy('n_sort')
->select(['individuals.*', 'n_num']);
$this->whereTrees($query, 'i_file', $trees);
$this->whereSearch($query, 'n_full', $search);
return $this->paginateQuery($query, Individual::rowMapper(), GedcomRecord::accessFilter(), $offset, $limit);
}
|
php
|
public function searchIndividualNames(array $trees, array $search, int $offset = 0, int $limit = PHP_INT_MAX): Collection
{
$query = DB::table('individuals')
->join('name', static function (JoinClause $join): void {
$join
->on('name.n_file', '=', 'individuals.i_file')
->on('name.n_id', '=', 'individuals.i_id');
})
->orderBy('n_sort')
->select(['individuals.*', 'n_num']);
$this->whereTrees($query, 'i_file', $trees);
$this->whereSearch($query, 'n_full', $search);
return $this->paginateQuery($query, Individual::rowMapper(), GedcomRecord::accessFilter(), $offset, $limit);
}
|
[
"public",
"function",
"searchIndividualNames",
"(",
"array",
"$",
"trees",
",",
"array",
"$",
"search",
",",
"int",
"$",
"offset",
"=",
"0",
",",
"int",
"$",
"limit",
"=",
"PHP_INT_MAX",
")",
":",
"Collection",
"{",
"$",
"query",
"=",
"DB",
"::",
"table",
"(",
"'individuals'",
")",
"->",
"join",
"(",
"'name'",
",",
"static",
"function",
"(",
"JoinClause",
"$",
"join",
")",
":",
"void",
"{",
"$",
"join",
"->",
"on",
"(",
"'name.n_file'",
",",
"'='",
",",
"'individuals.i_file'",
")",
"->",
"on",
"(",
"'name.n_id'",
",",
"'='",
",",
"'individuals.i_id'",
")",
";",
"}",
")",
"->",
"orderBy",
"(",
"'n_sort'",
")",
"->",
"select",
"(",
"[",
"'individuals.*'",
",",
"'n_num'",
"]",
")",
";",
"$",
"this",
"->",
"whereTrees",
"(",
"$",
"query",
",",
"'i_file'",
",",
"$",
"trees",
")",
";",
"$",
"this",
"->",
"whereSearch",
"(",
"$",
"query",
",",
"'n_full'",
",",
"$",
"search",
")",
";",
"return",
"$",
"this",
"->",
"paginateQuery",
"(",
"$",
"query",
",",
"Individual",
"::",
"rowMapper",
"(",
")",
",",
"GedcomRecord",
"::",
"accessFilter",
"(",
")",
",",
"$",
"offset",
",",
"$",
"limit",
")",
";",
"}"
] |
Search for individuals by name.
@param Tree[] $trees
@param string[] $search
@param int $offset
@param int $limit
@return Collection
@return Individual[]
|
[
"Search",
"for",
"individuals",
"by",
"name",
"."
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Services/SearchService.php#L145-L160
|
train
|
fisharebest/webtrees
|
app/Services/SearchService.php
|
SearchService.searchMedia
|
public function searchMedia(array $trees, array $search, int $offset = 0, int $limit = PHP_INT_MAX): Collection
{
$query = DB::table('media');
$this->whereTrees($query, 'media.m_file', $trees);
$this->whereSearch($query, 'm_gedcom', $search);
return $this->paginateQuery($query, Media::rowMapper(), GedcomRecord::accessFilter(), $offset, $limit);
}
|
php
|
public function searchMedia(array $trees, array $search, int $offset = 0, int $limit = PHP_INT_MAX): Collection
{
$query = DB::table('media');
$this->whereTrees($query, 'media.m_file', $trees);
$this->whereSearch($query, 'm_gedcom', $search);
return $this->paginateQuery($query, Media::rowMapper(), GedcomRecord::accessFilter(), $offset, $limit);
}
|
[
"public",
"function",
"searchMedia",
"(",
"array",
"$",
"trees",
",",
"array",
"$",
"search",
",",
"int",
"$",
"offset",
"=",
"0",
",",
"int",
"$",
"limit",
"=",
"PHP_INT_MAX",
")",
":",
"Collection",
"{",
"$",
"query",
"=",
"DB",
"::",
"table",
"(",
"'media'",
")",
";",
"$",
"this",
"->",
"whereTrees",
"(",
"$",
"query",
",",
"'media.m_file'",
",",
"$",
"trees",
")",
";",
"$",
"this",
"->",
"whereSearch",
"(",
"$",
"query",
",",
"'m_gedcom'",
",",
"$",
"search",
")",
";",
"return",
"$",
"this",
"->",
"paginateQuery",
"(",
"$",
"query",
",",
"Media",
"::",
"rowMapper",
"(",
")",
",",
"GedcomRecord",
"::",
"accessFilter",
"(",
")",
",",
"$",
"offset",
",",
"$",
"limit",
")",
";",
"}"
] |
Search for media objects.
@param Tree[] $trees
@param string[] $search
@param int $offset
@param int $limit
@return Collection
@return Media[]
|
[
"Search",
"for",
"media",
"objects",
"."
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Services/SearchService.php#L173-L181
|
train
|
fisharebest/webtrees
|
app/Services/SearchService.php
|
SearchService.searchPlaces
|
public function searchPlaces(Tree $tree, string $search, int $offset = 0, int $limit = PHP_INT_MAX): Collection
{
$query = DB::table('places AS p0')
->where('p0.p_file', '=', $tree->id())
->leftJoin('places AS p1', 'p1.p_id', '=', 'p0.p_parent_id')
->leftJoin('places AS p2', 'p2.p_id', '=', 'p1.p_parent_id')
->leftJoin('places AS p3', 'p3.p_id', '=', 'p2.p_parent_id')
->leftJoin('places AS p4', 'p4.p_id', '=', 'p3.p_parent_id')
->leftJoin('places AS p5', 'p5.p_id', '=', 'p4.p_parent_id')
->leftJoin('places AS p6', 'p6.p_id', '=', 'p5.p_parent_id')
->leftJoin('places AS p7', 'p7.p_id', '=', 'p6.p_parent_id')
->leftJoin('places AS p8', 'p8.p_id', '=', 'p7.p_parent_id')
->orderBy('p0.p_place')
->orderBy('p1.p_place')
->orderBy('p2.p_place')
->orderBy('p3.p_place')
->orderBy('p4.p_place')
->orderBy('p5.p_place')
->orderBy('p6.p_place')
->orderBy('p7.p_place')
->orderBy('p8.p_place')
->select([
'p0.p_place AS place0',
'p1.p_place AS place1',
'p2.p_place AS place2',
'p3.p_place AS place3',
'p4.p_place AS place4',
'p5.p_place AS place5',
'p6.p_place AS place6',
'p7.p_place AS place7',
'p8.p_place AS place8',
]);
// Filter each level of the hierarchy.
foreach (explode(',', $search, 9) as $level => $string) {
$query->whereContains('p' . $level . '.p_place', $string);
}
$row_mapper = static function (stdClass $row) use ($tree): Place {
$place = implode(', ', array_filter((array) $row));
return new Place($place, $tree);
};
$filter = static function (): bool {
return true;
};
return $this->paginateQuery($query, $row_mapper, $filter, $offset, $limit);
}
|
php
|
public function searchPlaces(Tree $tree, string $search, int $offset = 0, int $limit = PHP_INT_MAX): Collection
{
$query = DB::table('places AS p0')
->where('p0.p_file', '=', $tree->id())
->leftJoin('places AS p1', 'p1.p_id', '=', 'p0.p_parent_id')
->leftJoin('places AS p2', 'p2.p_id', '=', 'p1.p_parent_id')
->leftJoin('places AS p3', 'p3.p_id', '=', 'p2.p_parent_id')
->leftJoin('places AS p4', 'p4.p_id', '=', 'p3.p_parent_id')
->leftJoin('places AS p5', 'p5.p_id', '=', 'p4.p_parent_id')
->leftJoin('places AS p6', 'p6.p_id', '=', 'p5.p_parent_id')
->leftJoin('places AS p7', 'p7.p_id', '=', 'p6.p_parent_id')
->leftJoin('places AS p8', 'p8.p_id', '=', 'p7.p_parent_id')
->orderBy('p0.p_place')
->orderBy('p1.p_place')
->orderBy('p2.p_place')
->orderBy('p3.p_place')
->orderBy('p4.p_place')
->orderBy('p5.p_place')
->orderBy('p6.p_place')
->orderBy('p7.p_place')
->orderBy('p8.p_place')
->select([
'p0.p_place AS place0',
'p1.p_place AS place1',
'p2.p_place AS place2',
'p3.p_place AS place3',
'p4.p_place AS place4',
'p5.p_place AS place5',
'p6.p_place AS place6',
'p7.p_place AS place7',
'p8.p_place AS place8',
]);
// Filter each level of the hierarchy.
foreach (explode(',', $search, 9) as $level => $string) {
$query->whereContains('p' . $level . '.p_place', $string);
}
$row_mapper = static function (stdClass $row) use ($tree): Place {
$place = implode(', ', array_filter((array) $row));
return new Place($place, $tree);
};
$filter = static function (): bool {
return true;
};
return $this->paginateQuery($query, $row_mapper, $filter, $offset, $limit);
}
|
[
"public",
"function",
"searchPlaces",
"(",
"Tree",
"$",
"tree",
",",
"string",
"$",
"search",
",",
"int",
"$",
"offset",
"=",
"0",
",",
"int",
"$",
"limit",
"=",
"PHP_INT_MAX",
")",
":",
"Collection",
"{",
"$",
"query",
"=",
"DB",
"::",
"table",
"(",
"'places AS p0'",
")",
"->",
"where",
"(",
"'p0.p_file'",
",",
"'='",
",",
"$",
"tree",
"->",
"id",
"(",
")",
")",
"->",
"leftJoin",
"(",
"'places AS p1'",
",",
"'p1.p_id'",
",",
"'='",
",",
"'p0.p_parent_id'",
")",
"->",
"leftJoin",
"(",
"'places AS p2'",
",",
"'p2.p_id'",
",",
"'='",
",",
"'p1.p_parent_id'",
")",
"->",
"leftJoin",
"(",
"'places AS p3'",
",",
"'p3.p_id'",
",",
"'='",
",",
"'p2.p_parent_id'",
")",
"->",
"leftJoin",
"(",
"'places AS p4'",
",",
"'p4.p_id'",
",",
"'='",
",",
"'p3.p_parent_id'",
")",
"->",
"leftJoin",
"(",
"'places AS p5'",
",",
"'p5.p_id'",
",",
"'='",
",",
"'p4.p_parent_id'",
")",
"->",
"leftJoin",
"(",
"'places AS p6'",
",",
"'p6.p_id'",
",",
"'='",
",",
"'p5.p_parent_id'",
")",
"->",
"leftJoin",
"(",
"'places AS p7'",
",",
"'p7.p_id'",
",",
"'='",
",",
"'p6.p_parent_id'",
")",
"->",
"leftJoin",
"(",
"'places AS p8'",
",",
"'p8.p_id'",
",",
"'='",
",",
"'p7.p_parent_id'",
")",
"->",
"orderBy",
"(",
"'p0.p_place'",
")",
"->",
"orderBy",
"(",
"'p1.p_place'",
")",
"->",
"orderBy",
"(",
"'p2.p_place'",
")",
"->",
"orderBy",
"(",
"'p3.p_place'",
")",
"->",
"orderBy",
"(",
"'p4.p_place'",
")",
"->",
"orderBy",
"(",
"'p5.p_place'",
")",
"->",
"orderBy",
"(",
"'p6.p_place'",
")",
"->",
"orderBy",
"(",
"'p7.p_place'",
")",
"->",
"orderBy",
"(",
"'p8.p_place'",
")",
"->",
"select",
"(",
"[",
"'p0.p_place AS place0'",
",",
"'p1.p_place AS place1'",
",",
"'p2.p_place AS place2'",
",",
"'p3.p_place AS place3'",
",",
"'p4.p_place AS place4'",
",",
"'p5.p_place AS place5'",
",",
"'p6.p_place AS place6'",
",",
"'p7.p_place AS place7'",
",",
"'p8.p_place AS place8'",
",",
"]",
")",
";",
"// Filter each level of the hierarchy.",
"foreach",
"(",
"explode",
"(",
"','",
",",
"$",
"search",
",",
"9",
")",
"as",
"$",
"level",
"=>",
"$",
"string",
")",
"{",
"$",
"query",
"->",
"whereContains",
"(",
"'p'",
".",
"$",
"level",
".",
"'.p_place'",
",",
"$",
"string",
")",
";",
"}",
"$",
"row_mapper",
"=",
"static",
"function",
"(",
"stdClass",
"$",
"row",
")",
"use",
"(",
"$",
"tree",
")",
":",
"Place",
"{",
"$",
"place",
"=",
"implode",
"(",
"', '",
",",
"array_filter",
"(",
"(",
"array",
")",
"$",
"row",
")",
")",
";",
"return",
"new",
"Place",
"(",
"$",
"place",
",",
"$",
"tree",
")",
";",
"}",
";",
"$",
"filter",
"=",
"static",
"function",
"(",
")",
":",
"bool",
"{",
"return",
"true",
";",
"}",
";",
"return",
"$",
"this",
"->",
"paginateQuery",
"(",
"$",
"query",
",",
"$",
"row_mapper",
",",
"$",
"filter",
",",
"$",
"offset",
",",
"$",
"limit",
")",
";",
"}"
] |
Search for places.
@param Tree $tree
@param string $search
@param int $offset
@param int $limit
@return Collection
@return Place[]
|
[
"Search",
"for",
"places",
"."
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Services/SearchService.php#L303-L352
|
train
|
fisharebest/webtrees
|
app/Services/SearchService.php
|
SearchService.paginateQuery
|
private function paginateQuery(Builder $query, Closure $row_mapper, Closure $row_filter, int $offset, int $limit): Collection
{
$collection = new Collection();
foreach ($query->cursor() as $row) {
$record = $row_mapper($row);
// If the object has a method "canShow()", then use it to filter for privacy.
if ($row_filter($record)) {
if ($offset > 0) {
$offset--;
} else {
if ($limit > 0) {
$collection->push($record);
}
$limit--;
if ($limit === 0) {
break;
}
}
}
}
return $collection;
}
|
php
|
private function paginateQuery(Builder $query, Closure $row_mapper, Closure $row_filter, int $offset, int $limit): Collection
{
$collection = new Collection();
foreach ($query->cursor() as $row) {
$record = $row_mapper($row);
// If the object has a method "canShow()", then use it to filter for privacy.
if ($row_filter($record)) {
if ($offset > 0) {
$offset--;
} else {
if ($limit > 0) {
$collection->push($record);
}
$limit--;
if ($limit === 0) {
break;
}
}
}
}
return $collection;
}
|
[
"private",
"function",
"paginateQuery",
"(",
"Builder",
"$",
"query",
",",
"Closure",
"$",
"row_mapper",
",",
"Closure",
"$",
"row_filter",
",",
"int",
"$",
"offset",
",",
"int",
"$",
"limit",
")",
":",
"Collection",
"{",
"$",
"collection",
"=",
"new",
"Collection",
"(",
")",
";",
"foreach",
"(",
"$",
"query",
"->",
"cursor",
"(",
")",
"as",
"$",
"row",
")",
"{",
"$",
"record",
"=",
"$",
"row_mapper",
"(",
"$",
"row",
")",
";",
"// If the object has a method \"canShow()\", then use it to filter for privacy.",
"if",
"(",
"$",
"row_filter",
"(",
"$",
"record",
")",
")",
"{",
"if",
"(",
"$",
"offset",
">",
"0",
")",
"{",
"$",
"offset",
"--",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"limit",
">",
"0",
")",
"{",
"$",
"collection",
"->",
"push",
"(",
"$",
"record",
")",
";",
"}",
"$",
"limit",
"--",
";",
"if",
"(",
"$",
"limit",
"===",
"0",
")",
"{",
"break",
";",
"}",
"}",
"}",
"}",
"return",
"$",
"collection",
";",
"}"
] |
Paginate a search query.
@param Builder $query Searches the database for the desired records.
@param Closure $row_mapper Converts a row from the query into a record.
@param Closure $row_filter
@param int $offset Skip this many rows.
@param int $limit Take this many rows.
@return Collection
|
[
"Paginate",
"a",
"search",
"query",
"."
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Services/SearchService.php#L853-L879
|
train
|
fisharebest/webtrees
|
app/Services/SearchService.php
|
SearchService.whereSearch
|
private function whereSearch(Builder $query, $field, array $search_terms): void
{
if ($field instanceof Expression) {
$field = $field->getValue();
}
foreach ($search_terms as $search_term) {
$query->whereContains(DB::raw($field), $search_term);
}
}
|
php
|
private function whereSearch(Builder $query, $field, array $search_terms): void
{
if ($field instanceof Expression) {
$field = $field->getValue();
}
foreach ($search_terms as $search_term) {
$query->whereContains(DB::raw($field), $search_term);
}
}
|
[
"private",
"function",
"whereSearch",
"(",
"Builder",
"$",
"query",
",",
"$",
"field",
",",
"array",
"$",
"search_terms",
")",
":",
"void",
"{",
"if",
"(",
"$",
"field",
"instanceof",
"Expression",
")",
"{",
"$",
"field",
"=",
"$",
"field",
"->",
"getValue",
"(",
")",
";",
"}",
"foreach",
"(",
"$",
"search_terms",
"as",
"$",
"search_term",
")",
"{",
"$",
"query",
"->",
"whereContains",
"(",
"DB",
"::",
"raw",
"(",
"$",
"field",
")",
",",
"$",
"search_term",
")",
";",
"}",
"}"
] |
Apply search filters to a SQL query column. Apply collation rules to MySQL.
@param Builder $query
@param Expression|string $field
@param string[] $search_terms
|
[
"Apply",
"search",
"filters",
"to",
"a",
"SQL",
"query",
"column",
".",
"Apply",
"collation",
"rules",
"to",
"MySQL",
"."
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Services/SearchService.php#L888-L897
|
train
|
fisharebest/webtrees
|
app/Services/SearchService.php
|
SearchService.wherePhonetic
|
private function wherePhonetic(Builder $query, $field, string $soundex): void
{
if ($soundex !== '') {
$query->where(static function (Builder $query) use ($soundex, $field): void {
foreach (explode(':', $soundex) as $sdx) {
$query->orWhere($field, 'LIKE', '%' . $sdx . '%');
}
});
}
}
|
php
|
private function wherePhonetic(Builder $query, $field, string $soundex): void
{
if ($soundex !== '') {
$query->where(static function (Builder $query) use ($soundex, $field): void {
foreach (explode(':', $soundex) as $sdx) {
$query->orWhere($field, 'LIKE', '%' . $sdx . '%');
}
});
}
}
|
[
"private",
"function",
"wherePhonetic",
"(",
"Builder",
"$",
"query",
",",
"$",
"field",
",",
"string",
"$",
"soundex",
")",
":",
"void",
"{",
"if",
"(",
"$",
"soundex",
"!==",
"''",
")",
"{",
"$",
"query",
"->",
"where",
"(",
"static",
"function",
"(",
"Builder",
"$",
"query",
")",
"use",
"(",
"$",
"soundex",
",",
"$",
"field",
")",
":",
"void",
"{",
"foreach",
"(",
"explode",
"(",
"':'",
",",
"$",
"soundex",
")",
"as",
"$",
"sdx",
")",
"{",
"$",
"query",
"->",
"orWhere",
"(",
"$",
"field",
",",
"'LIKE'",
",",
"'%'",
".",
"$",
"sdx",
".",
"'%'",
")",
";",
"}",
"}",
")",
";",
"}",
"}"
] |
Apply soundex search filters to a SQL query column.
@param Builder $query
@param Expression|string $field
@param string $soundex
|
[
"Apply",
"soundex",
"search",
"filters",
"to",
"a",
"SQL",
"query",
"column",
"."
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Services/SearchService.php#L906-L915
|
train
|
fisharebest/webtrees
|
app/Services/SearchService.php
|
SearchService.rawGedcomFilter
|
private function rawGedcomFilter(array $search_terms): Closure
{
return static function (GedcomRecord $record) use ($search_terms): bool {
// Ignore non-genealogy fields
$gedcom = preg_replace('/\n\d (?:_UID) .*/', '', $record->gedcom());
// Ignore matches in links
$gedcom = preg_replace('/\n\d ' . Gedcom::REGEX_TAG . '( @' . Gedcom::REGEX_XREF . '@)?/', '', $gedcom);
// Re-apply the filtering
foreach ($search_terms as $search_term) {
if (mb_stripos($gedcom, $search_term) === false) {
return false;
}
}
return true;
};
}
|
php
|
private function rawGedcomFilter(array $search_terms): Closure
{
return static function (GedcomRecord $record) use ($search_terms): bool {
// Ignore non-genealogy fields
$gedcom = preg_replace('/\n\d (?:_UID) .*/', '', $record->gedcom());
// Ignore matches in links
$gedcom = preg_replace('/\n\d ' . Gedcom::REGEX_TAG . '( @' . Gedcom::REGEX_XREF . '@)?/', '', $gedcom);
// Re-apply the filtering
foreach ($search_terms as $search_term) {
if (mb_stripos($gedcom, $search_term) === false) {
return false;
}
}
return true;
};
}
|
[
"private",
"function",
"rawGedcomFilter",
"(",
"array",
"$",
"search_terms",
")",
":",
"Closure",
"{",
"return",
"static",
"function",
"(",
"GedcomRecord",
"$",
"record",
")",
"use",
"(",
"$",
"search_terms",
")",
":",
"bool",
"{",
"// Ignore non-genealogy fields",
"$",
"gedcom",
"=",
"preg_replace",
"(",
"'/\\n\\d (?:_UID) .*/'",
",",
"''",
",",
"$",
"record",
"->",
"gedcom",
"(",
")",
")",
";",
"// Ignore matches in links",
"$",
"gedcom",
"=",
"preg_replace",
"(",
"'/\\n\\d '",
".",
"Gedcom",
"::",
"REGEX_TAG",
".",
"'( @'",
".",
"Gedcom",
"::",
"REGEX_XREF",
".",
"'@)?/'",
",",
"''",
",",
"$",
"gedcom",
")",
";",
"// Re-apply the filtering",
"foreach",
"(",
"$",
"search_terms",
"as",
"$",
"search_term",
")",
"{",
"if",
"(",
"mb_stripos",
"(",
"$",
"gedcom",
",",
"$",
"search_term",
")",
"===",
"false",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}",
";",
"}"
] |
A closure to filter records by privacy-filtered GEDCOM data.
@param array $search_terms
@return Closure
|
[
"A",
"closure",
"to",
"filter",
"records",
"by",
"privacy",
"-",
"filtered",
"GEDCOM",
"data",
"."
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Services/SearchService.php#L938-L956
|
train
|
fisharebest/webtrees
|
app/Services/SearchService.php
|
SearchService.rowLimiter
|
private function rowLimiter(int $limit = 1000): Closure
{
return static function () use ($limit): void {
static $n = 0;
if (++$n > $limit) {
$message = I18N::translate('The search returned too many results.');
throw new InternalServerErrorException($message);
}
};
}
|
php
|
private function rowLimiter(int $limit = 1000): Closure
{
return static function () use ($limit): void {
static $n = 0;
if (++$n > $limit) {
$message = I18N::translate('The search returned too many results.');
throw new InternalServerErrorException($message);
}
};
}
|
[
"private",
"function",
"rowLimiter",
"(",
"int",
"$",
"limit",
"=",
"1000",
")",
":",
"Closure",
"{",
"return",
"static",
"function",
"(",
")",
"use",
"(",
"$",
"limit",
")",
":",
"void",
"{",
"static",
"$",
"n",
"=",
"0",
";",
"if",
"(",
"++",
"$",
"n",
">",
"$",
"limit",
")",
"{",
"$",
"message",
"=",
"I18N",
"::",
"translate",
"(",
"'The search returned too many results.'",
")",
";",
"throw",
"new",
"InternalServerErrorException",
"(",
"$",
"message",
")",
";",
"}",
"}",
";",
"}"
] |
Searching for short or common text can give more results than the system can process.
@param int $limit
@return Closure
|
[
"Searching",
"for",
"short",
"or",
"common",
"text",
"can",
"give",
"more",
"results",
"than",
"the",
"system",
"can",
"process",
"."
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Services/SearchService.php#L965-L976
|
train
|
fisharebest/webtrees
|
app/Http/Controllers/MediaFileController.php
|
MediaFileController.mediaDownload
|
public function mediaDownload(ServerRequestInterface $request, Tree $tree): ResponseInterface
{
$xref = $request->get('xref', '');
$fact_id = $request->get('fact_id');
$media = Media::getInstance($xref, $tree);
if ($media === null) {
throw new MediaNotFoundException();
}
if (!$media->canShow()) {
throw new AccessDeniedHttpException();
}
foreach ($media->mediaFiles() as $media_file) {
if ($media_file->factId() === $fact_id) {
if ($media_file->isExternal()) {
return redirect($media_file->filename());
}
if (!$media_file->isImage() && $media_file->fileExists()) {
$data = file_get_contents($media_file->getServerFilename());
return response($data, StatusCodeInterface::STATUS_OK, [
'Content-Type' => $media_file->mimeType(),
'Content-Disposition' => 'attachment; filename="' . addcslashes($media_file->filename(), '"') . '"',
]);
}
}
}
throw new NotFoundHttpException();
}
|
php
|
public function mediaDownload(ServerRequestInterface $request, Tree $tree): ResponseInterface
{
$xref = $request->get('xref', '');
$fact_id = $request->get('fact_id');
$media = Media::getInstance($xref, $tree);
if ($media === null) {
throw new MediaNotFoundException();
}
if (!$media->canShow()) {
throw new AccessDeniedHttpException();
}
foreach ($media->mediaFiles() as $media_file) {
if ($media_file->factId() === $fact_id) {
if ($media_file->isExternal()) {
return redirect($media_file->filename());
}
if (!$media_file->isImage() && $media_file->fileExists()) {
$data = file_get_contents($media_file->getServerFilename());
return response($data, StatusCodeInterface::STATUS_OK, [
'Content-Type' => $media_file->mimeType(),
'Content-Disposition' => 'attachment; filename="' . addcslashes($media_file->filename(), '"') . '"',
]);
}
}
}
throw new NotFoundHttpException();
}
|
[
"public",
"function",
"mediaDownload",
"(",
"ServerRequestInterface",
"$",
"request",
",",
"Tree",
"$",
"tree",
")",
":",
"ResponseInterface",
"{",
"$",
"xref",
"=",
"$",
"request",
"->",
"get",
"(",
"'xref'",
",",
"''",
")",
";",
"$",
"fact_id",
"=",
"$",
"request",
"->",
"get",
"(",
"'fact_id'",
")",
";",
"$",
"media",
"=",
"Media",
"::",
"getInstance",
"(",
"$",
"xref",
",",
"$",
"tree",
")",
";",
"if",
"(",
"$",
"media",
"===",
"null",
")",
"{",
"throw",
"new",
"MediaNotFoundException",
"(",
")",
";",
"}",
"if",
"(",
"!",
"$",
"media",
"->",
"canShow",
"(",
")",
")",
"{",
"throw",
"new",
"AccessDeniedHttpException",
"(",
")",
";",
"}",
"foreach",
"(",
"$",
"media",
"->",
"mediaFiles",
"(",
")",
"as",
"$",
"media_file",
")",
"{",
"if",
"(",
"$",
"media_file",
"->",
"factId",
"(",
")",
"===",
"$",
"fact_id",
")",
"{",
"if",
"(",
"$",
"media_file",
"->",
"isExternal",
"(",
")",
")",
"{",
"return",
"redirect",
"(",
"$",
"media_file",
"->",
"filename",
"(",
")",
")",
";",
"}",
"if",
"(",
"!",
"$",
"media_file",
"->",
"isImage",
"(",
")",
"&&",
"$",
"media_file",
"->",
"fileExists",
"(",
")",
")",
"{",
"$",
"data",
"=",
"file_get_contents",
"(",
"$",
"media_file",
"->",
"getServerFilename",
"(",
")",
")",
";",
"return",
"response",
"(",
"$",
"data",
",",
"StatusCodeInterface",
"::",
"STATUS_OK",
",",
"[",
"'Content-Type'",
"=>",
"$",
"media_file",
"->",
"mimeType",
"(",
")",
",",
"'Content-Disposition'",
"=>",
"'attachment; filename=\"'",
".",
"addcslashes",
"(",
"$",
"media_file",
"->",
"filename",
"(",
")",
",",
"'\"'",
")",
".",
"'\"'",
",",
"]",
")",
";",
"}",
"}",
"}",
"throw",
"new",
"NotFoundHttpException",
"(",
")",
";",
"}"
] |
Download a non-image media file.
@param ServerRequestInterface $request
@param Tree $tree
@return ResponseInterface
|
[
"Download",
"a",
"non",
"-",
"image",
"media",
"file",
"."
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Http/Controllers/MediaFileController.php#L60-L92
|
train
|
fisharebest/webtrees
|
app/Http/Controllers/MediaFileController.php
|
MediaFileController.generateImage
|
private function generateImage(MediaFile $media_file, array $params): ResponseInterface
{
try {
// Validate HTTP signature
$signature = $this->glideSignature();
$signature->validateRequest(parse_url(WT_BASE_URL . 'index.php', PHP_URL_PATH), $params);
$server = $this->glideServer($media_file->folder());
$path = $server->makeImage($media_file->filename(), $params);
return response($server->getCache()->read($path), StatusCodeInterface::STATUS_OK, [
'Content-Type' => $server->getCache()->getMimetype($path),
'Content-Length' => $server->getCache()->getSize($path),
'Cache-Control' => 'max-age=31536000, public',
'Expires' => date_create('+1 years')->format('D, d M Y H:i:s') . ' GMT',
]);
} catch (SignatureException $ex) {
return $this->httpStatusAsImage(StatusCodeInterface::STATUS_FORBIDDEN);
} catch (FileNotFoundException $ex) {
return $this->httpStatusAsImage(StatusCodeInterface::STATUS_NOT_FOUND);
} catch (Throwable $ex) {
Log::addErrorLog('Cannot create thumbnail ' . $ex->getMessage());
return $this->httpStatusAsImage(StatusCodeInterface::STATUS_INTERNAL_SERVER_ERROR);
}
}
|
php
|
private function generateImage(MediaFile $media_file, array $params): ResponseInterface
{
try {
// Validate HTTP signature
$signature = $this->glideSignature();
$signature->validateRequest(parse_url(WT_BASE_URL . 'index.php', PHP_URL_PATH), $params);
$server = $this->glideServer($media_file->folder());
$path = $server->makeImage($media_file->filename(), $params);
return response($server->getCache()->read($path), StatusCodeInterface::STATUS_OK, [
'Content-Type' => $server->getCache()->getMimetype($path),
'Content-Length' => $server->getCache()->getSize($path),
'Cache-Control' => 'max-age=31536000, public',
'Expires' => date_create('+1 years')->format('D, d M Y H:i:s') . ' GMT',
]);
} catch (SignatureException $ex) {
return $this->httpStatusAsImage(StatusCodeInterface::STATUS_FORBIDDEN);
} catch (FileNotFoundException $ex) {
return $this->httpStatusAsImage(StatusCodeInterface::STATUS_NOT_FOUND);
} catch (Throwable $ex) {
Log::addErrorLog('Cannot create thumbnail ' . $ex->getMessage());
return $this->httpStatusAsImage(StatusCodeInterface::STATUS_INTERNAL_SERVER_ERROR);
}
}
|
[
"private",
"function",
"generateImage",
"(",
"MediaFile",
"$",
"media_file",
",",
"array",
"$",
"params",
")",
":",
"ResponseInterface",
"{",
"try",
"{",
"// Validate HTTP signature",
"$",
"signature",
"=",
"$",
"this",
"->",
"glideSignature",
"(",
")",
";",
"$",
"signature",
"->",
"validateRequest",
"(",
"parse_url",
"(",
"WT_BASE_URL",
".",
"'index.php'",
",",
"PHP_URL_PATH",
")",
",",
"$",
"params",
")",
";",
"$",
"server",
"=",
"$",
"this",
"->",
"glideServer",
"(",
"$",
"media_file",
"->",
"folder",
"(",
")",
")",
";",
"$",
"path",
"=",
"$",
"server",
"->",
"makeImage",
"(",
"$",
"media_file",
"->",
"filename",
"(",
")",
",",
"$",
"params",
")",
";",
"return",
"response",
"(",
"$",
"server",
"->",
"getCache",
"(",
")",
"->",
"read",
"(",
"$",
"path",
")",
",",
"StatusCodeInterface",
"::",
"STATUS_OK",
",",
"[",
"'Content-Type'",
"=>",
"$",
"server",
"->",
"getCache",
"(",
")",
"->",
"getMimetype",
"(",
"$",
"path",
")",
",",
"'Content-Length'",
"=>",
"$",
"server",
"->",
"getCache",
"(",
")",
"->",
"getSize",
"(",
"$",
"path",
")",
",",
"'Cache-Control'",
"=>",
"'max-age=31536000, public'",
",",
"'Expires'",
"=>",
"date_create",
"(",
"'+1 years'",
")",
"->",
"format",
"(",
"'D, d M Y H:i:s'",
")",
".",
"' GMT'",
",",
"]",
")",
";",
"}",
"catch",
"(",
"SignatureException",
"$",
"ex",
")",
"{",
"return",
"$",
"this",
"->",
"httpStatusAsImage",
"(",
"StatusCodeInterface",
"::",
"STATUS_FORBIDDEN",
")",
";",
"}",
"catch",
"(",
"FileNotFoundException",
"$",
"ex",
")",
"{",
"return",
"$",
"this",
"->",
"httpStatusAsImage",
"(",
"StatusCodeInterface",
"::",
"STATUS_NOT_FOUND",
")",
";",
"}",
"catch",
"(",
"Throwable",
"$",
"ex",
")",
"{",
"Log",
"::",
"addErrorLog",
"(",
"'Cannot create thumbnail '",
".",
"$",
"ex",
"->",
"getMessage",
"(",
")",
")",
";",
"return",
"$",
"this",
"->",
"httpStatusAsImage",
"(",
"StatusCodeInterface",
"::",
"STATUS_INTERNAL_SERVER_ERROR",
")",
";",
"}",
"}"
] |
Generate a thumbnail image for a file.
@param MediaFile $media_file
@param array $params
@return ResponseInterface
|
[
"Generate",
"a",
"thumbnail",
"image",
"for",
"a",
"file",
"."
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Http/Controllers/MediaFileController.php#L172-L198
|
train
|
fisharebest/webtrees
|
app/Http/Controllers/MediaFileController.php
|
MediaFileController.httpStatusAsImage
|
private function httpStatusAsImage(int $status): ResponseInterface
{
$svg = '<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100"><rect width="100" height="100" fill="#F88" /><text x="5" y="55" font-family="Verdana" font-size="35">' . $status . '</text></svg>';
// We can't use the actual status code, as browser's won't show images with 4xx/5xx
return response($svg, StatusCodeInterface::STATUS_OK, [
'Content-Type' => 'image/svg+xml',
'Content-Length' => strlen($svg),
]);
}
|
php
|
private function httpStatusAsImage(int $status): ResponseInterface
{
$svg = '<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100"><rect width="100" height="100" fill="#F88" /><text x="5" y="55" font-family="Verdana" font-size="35">' . $status . '</text></svg>';
// We can't use the actual status code, as browser's won't show images with 4xx/5xx
return response($svg, StatusCodeInterface::STATUS_OK, [
'Content-Type' => 'image/svg+xml',
'Content-Length' => strlen($svg),
]);
}
|
[
"private",
"function",
"httpStatusAsImage",
"(",
"int",
"$",
"status",
")",
":",
"ResponseInterface",
"{",
"$",
"svg",
"=",
"'<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"100\" height=\"100\"><rect width=\"100\" height=\"100\" fill=\"#F88\" /><text x=\"5\" y=\"55\" font-family=\"Verdana\" font-size=\"35\">'",
".",
"$",
"status",
".",
"'</text></svg>'",
";",
"// We can't use the actual status code, as browser's won't show images with 4xx/5xx",
"return",
"response",
"(",
"$",
"svg",
",",
"StatusCodeInterface",
"::",
"STATUS_OK",
",",
"[",
"'Content-Type'",
"=>",
"'image/svg+xml'",
",",
"'Content-Length'",
"=>",
"strlen",
"(",
"$",
"svg",
")",
",",
"]",
")",
";",
"}"
] |
Send a dummy image, to replace one that could not be found or created.
@param int $status HTTP status code
@return ResponseInterface
|
[
"Send",
"a",
"dummy",
"image",
"to",
"replace",
"one",
"that",
"could",
"not",
"be",
"found",
"or",
"created",
"."
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Http/Controllers/MediaFileController.php#L259-L268
|
train
|
fisharebest/webtrees
|
app/Http/Controllers/MediaFileController.php
|
MediaFileController.fileExtensionAsImage
|
private function fileExtensionAsImage(string $extension): ResponseInterface
{
$extension = '.' . strtolower($extension);
$svg = '<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100"><rect width="100" height="100" fill="#88F" /><text x="5" y="60" font-family="Verdana" font-size="30">' . $extension . '</text></svg>';
return response($svg, StatusCodeInterface::STATUS_OK, [
'Content-Type' => 'image/svg+xml',
'Content-Length' => strlen($svg),
]);
}
|
php
|
private function fileExtensionAsImage(string $extension): ResponseInterface
{
$extension = '.' . strtolower($extension);
$svg = '<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100"><rect width="100" height="100" fill="#88F" /><text x="5" y="60" font-family="Verdana" font-size="30">' . $extension . '</text></svg>';
return response($svg, StatusCodeInterface::STATUS_OK, [
'Content-Type' => 'image/svg+xml',
'Content-Length' => strlen($svg),
]);
}
|
[
"private",
"function",
"fileExtensionAsImage",
"(",
"string",
"$",
"extension",
")",
":",
"ResponseInterface",
"{",
"$",
"extension",
"=",
"'.'",
".",
"strtolower",
"(",
"$",
"extension",
")",
";",
"$",
"svg",
"=",
"'<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"100\" height=\"100\"><rect width=\"100\" height=\"100\" fill=\"#88F\" /><text x=\"5\" y=\"60\" font-family=\"Verdana\" font-size=\"30\">'",
".",
"$",
"extension",
".",
"'</text></svg>'",
";",
"return",
"response",
"(",
"$",
"svg",
",",
"StatusCodeInterface",
"::",
"STATUS_OK",
",",
"[",
"'Content-Type'",
"=>",
"'image/svg+xml'",
",",
"'Content-Length'",
"=>",
"strlen",
"(",
"$",
"svg",
")",
",",
"]",
")",
";",
"}"
] |
Send a dummy image, to replace a non-image file.
@param string $extension
@return ResponseInterface
|
[
"Send",
"a",
"dummy",
"image",
"to",
"replace",
"a",
"non",
"-",
"image",
"file",
"."
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Http/Controllers/MediaFileController.php#L277-L287
|
train
|
fisharebest/webtrees
|
app/Services/DatatablesService.php
|
DatatablesService.handle
|
public function handle(ServerRequestInterface $request, Builder $query, array $search_columns, array $sort_columns, Closure $callback): ResponseInterface
{
$search = $request->getQueryParams()['search']['value'] ?? '';
$start = (int) ($request->getQueryParams()['start'] ?? 0);
$length = (int) ($request->getQueryParams()['length'] ?? 0);
$order = $request->getQueryParams()['order'] ?? [];
$draw = (int) ($request->getQueryParams()['draw'] ?? 0);
// Count unfiltered records
$recordsTotal = (clone $query)->count();
// Filtering
if ($search !== '') {
$query->where(static function (Builder $query) use ($search, $search_columns): void {
foreach ($search_columns as $search_column) {
$query->whereContains($search_column, $search, 'or');
}
});
}
// Sorting
if (!empty($order)) {
foreach ($order as $value) {
// Columns in datatables are numbered from zero.
// Columns in MySQL are numbered starting with one.
// If not specified, the Nth table column maps onto the Nth query column.
$sort_column = $sort_columns[$value['column']] ?? DB::raw(1 + $value['column']);
$query->orderBy($sort_column, $value['dir']);
}
} else {
$query->orderBy(DB::raw(1));
}
// Paginating
if ($length > 0) {
$recordsFiltered = (clone $query)->count();
$query->skip($start)->limit($length);
$data = $query->get();
} else {
$data = $query->get();
$recordsFiltered = $data->count();
}
$data = $data->map($callback)->all();
return response([
'draw' => $draw,
'recordsTotal' => $recordsTotal,
'recordsFiltered' => $recordsFiltered,
'data' => $data,
]);
}
|
php
|
public function handle(ServerRequestInterface $request, Builder $query, array $search_columns, array $sort_columns, Closure $callback): ResponseInterface
{
$search = $request->getQueryParams()['search']['value'] ?? '';
$start = (int) ($request->getQueryParams()['start'] ?? 0);
$length = (int) ($request->getQueryParams()['length'] ?? 0);
$order = $request->getQueryParams()['order'] ?? [];
$draw = (int) ($request->getQueryParams()['draw'] ?? 0);
// Count unfiltered records
$recordsTotal = (clone $query)->count();
// Filtering
if ($search !== '') {
$query->where(static function (Builder $query) use ($search, $search_columns): void {
foreach ($search_columns as $search_column) {
$query->whereContains($search_column, $search, 'or');
}
});
}
// Sorting
if (!empty($order)) {
foreach ($order as $value) {
// Columns in datatables are numbered from zero.
// Columns in MySQL are numbered starting with one.
// If not specified, the Nth table column maps onto the Nth query column.
$sort_column = $sort_columns[$value['column']] ?? DB::raw(1 + $value['column']);
$query->orderBy($sort_column, $value['dir']);
}
} else {
$query->orderBy(DB::raw(1));
}
// Paginating
if ($length > 0) {
$recordsFiltered = (clone $query)->count();
$query->skip($start)->limit($length);
$data = $query->get();
} else {
$data = $query->get();
$recordsFiltered = $data->count();
}
$data = $data->map($callback)->all();
return response([
'draw' => $draw,
'recordsTotal' => $recordsTotal,
'recordsFiltered' => $recordsFiltered,
'data' => $data,
]);
}
|
[
"public",
"function",
"handle",
"(",
"ServerRequestInterface",
"$",
"request",
",",
"Builder",
"$",
"query",
",",
"array",
"$",
"search_columns",
",",
"array",
"$",
"sort_columns",
",",
"Closure",
"$",
"callback",
")",
":",
"ResponseInterface",
"{",
"$",
"search",
"=",
"$",
"request",
"->",
"getQueryParams",
"(",
")",
"[",
"'search'",
"]",
"[",
"'value'",
"]",
"??",
"''",
";",
"$",
"start",
"=",
"(",
"int",
")",
"(",
"$",
"request",
"->",
"getQueryParams",
"(",
")",
"[",
"'start'",
"]",
"??",
"0",
")",
";",
"$",
"length",
"=",
"(",
"int",
")",
"(",
"$",
"request",
"->",
"getQueryParams",
"(",
")",
"[",
"'length'",
"]",
"??",
"0",
")",
";",
"$",
"order",
"=",
"$",
"request",
"->",
"getQueryParams",
"(",
")",
"[",
"'order'",
"]",
"??",
"[",
"]",
";",
"$",
"draw",
"=",
"(",
"int",
")",
"(",
"$",
"request",
"->",
"getQueryParams",
"(",
")",
"[",
"'draw'",
"]",
"??",
"0",
")",
";",
"// Count unfiltered records",
"$",
"recordsTotal",
"=",
"(",
"clone",
"$",
"query",
")",
"->",
"count",
"(",
")",
";",
"// Filtering",
"if",
"(",
"$",
"search",
"!==",
"''",
")",
"{",
"$",
"query",
"->",
"where",
"(",
"static",
"function",
"(",
"Builder",
"$",
"query",
")",
"use",
"(",
"$",
"search",
",",
"$",
"search_columns",
")",
":",
"void",
"{",
"foreach",
"(",
"$",
"search_columns",
"as",
"$",
"search_column",
")",
"{",
"$",
"query",
"->",
"whereContains",
"(",
"$",
"search_column",
",",
"$",
"search",
",",
"'or'",
")",
";",
"}",
"}",
")",
";",
"}",
"// Sorting",
"if",
"(",
"!",
"empty",
"(",
"$",
"order",
")",
")",
"{",
"foreach",
"(",
"$",
"order",
"as",
"$",
"value",
")",
"{",
"// Columns in datatables are numbered from zero.",
"// Columns in MySQL are numbered starting with one.",
"// If not specified, the Nth table column maps onto the Nth query column.",
"$",
"sort_column",
"=",
"$",
"sort_columns",
"[",
"$",
"value",
"[",
"'column'",
"]",
"]",
"??",
"DB",
"::",
"raw",
"(",
"1",
"+",
"$",
"value",
"[",
"'column'",
"]",
")",
";",
"$",
"query",
"->",
"orderBy",
"(",
"$",
"sort_column",
",",
"$",
"value",
"[",
"'dir'",
"]",
")",
";",
"}",
"}",
"else",
"{",
"$",
"query",
"->",
"orderBy",
"(",
"DB",
"::",
"raw",
"(",
"1",
")",
")",
";",
"}",
"// Paginating",
"if",
"(",
"$",
"length",
">",
"0",
")",
"{",
"$",
"recordsFiltered",
"=",
"(",
"clone",
"$",
"query",
")",
"->",
"count",
"(",
")",
";",
"$",
"query",
"->",
"skip",
"(",
"$",
"start",
")",
"->",
"limit",
"(",
"$",
"length",
")",
";",
"$",
"data",
"=",
"$",
"query",
"->",
"get",
"(",
")",
";",
"}",
"else",
"{",
"$",
"data",
"=",
"$",
"query",
"->",
"get",
"(",
")",
";",
"$",
"recordsFiltered",
"=",
"$",
"data",
"->",
"count",
"(",
")",
";",
"}",
"$",
"data",
"=",
"$",
"data",
"->",
"map",
"(",
"$",
"callback",
")",
"->",
"all",
"(",
")",
";",
"return",
"response",
"(",
"[",
"'draw'",
"=>",
"$",
"draw",
",",
"'recordsTotal'",
"=>",
"$",
"recordsTotal",
",",
"'recordsFiltered'",
"=>",
"$",
"recordsFiltered",
",",
"'data'",
"=>",
"$",
"data",
",",
"]",
")",
";",
"}"
] |
Apply filtering and pagination to a query, and generate a response suitable for datatables.
@link http://www.datatables.net/usage/server-side
@param ServerRequestInterface $request Includes the datatables request parameters.
@param Builder $query A query to fetch the unfiltered rows and columns.
@param string[] $search_columns The names of searchable columns.
@param string[] $sort_columns How to sort columns.
@param Closure $callback Converts a row-object to an array-of-columns.
@return ResponseInterface
|
[
"Apply",
"filtering",
"and",
"pagination",
"to",
"a",
"query",
"and",
"generate",
"a",
"response",
"suitable",
"for",
"datatables",
"."
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Services/DatatablesService.php#L44-L98
|
train
|
fisharebest/webtrees
|
app/Report/ReportParserBase.php
|
ReportParserBase.endElement
|
protected function endElement($parser, string $name): void
{
$method = $name . 'EndHandler';
if (method_exists($this, $method)) {
$this->$method();
}
}
|
php
|
protected function endElement($parser, string $name): void
{
$method = $name . 'EndHandler';
if (method_exists($this, $method)) {
$this->$method();
}
}
|
[
"protected",
"function",
"endElement",
"(",
"$",
"parser",
",",
"string",
"$",
"name",
")",
":",
"void",
"{",
"$",
"method",
"=",
"$",
"name",
".",
"'EndHandler'",
";",
"if",
"(",
"method_exists",
"(",
"$",
"this",
",",
"$",
"method",
")",
")",
"{",
"$",
"this",
"->",
"$",
"method",
"(",
")",
";",
"}",
"}"
] |
XML handler for a closing tag.
@param resource $parser the resource handler for the xml parser
@param string $name the name of the xml element parsed
@return void
|
[
"XML",
"handler",
"for",
"a",
"closing",
"tag",
"."
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Report/ReportParserBase.php#L111-L118
|
train
|
fisharebest/webtrees
|
app/Http/Controllers/EditIndividualController.php
|
EditIndividualController.addUnlinked
|
public function addUnlinked(Tree $tree): ResponseInterface
{
return $this->viewResponse('edit/new-individual', [
'tree' => $tree,
'title' => I18N::translate('Create an individual'),
'nextaction' => 'add_unlinked_indi_action',
'individual' => null,
'family' => null,
'name_fact' => null,
'famtag' => '',
'gender' => 'U',
]);
}
|
php
|
public function addUnlinked(Tree $tree): ResponseInterface
{
return $this->viewResponse('edit/new-individual', [
'tree' => $tree,
'title' => I18N::translate('Create an individual'),
'nextaction' => 'add_unlinked_indi_action',
'individual' => null,
'family' => null,
'name_fact' => null,
'famtag' => '',
'gender' => 'U',
]);
}
|
[
"public",
"function",
"addUnlinked",
"(",
"Tree",
"$",
"tree",
")",
":",
"ResponseInterface",
"{",
"return",
"$",
"this",
"->",
"viewResponse",
"(",
"'edit/new-individual'",
",",
"[",
"'tree'",
"=>",
"$",
"tree",
",",
"'title'",
"=>",
"I18N",
"::",
"translate",
"(",
"'Create an individual'",
")",
",",
"'nextaction'",
"=>",
"'add_unlinked_indi_action'",
",",
"'individual'",
"=>",
"null",
",",
"'family'",
"=>",
"null",
",",
"'name_fact'",
"=>",
"null",
",",
"'famtag'",
"=>",
"''",
",",
"'gender'",
"=>",
"'U'",
",",
"]",
")",
";",
"}"
] |
Add an unlinked individual
@param Tree $tree
@return ResponseInterface
|
[
"Add",
"an",
"unlinked",
"individual"
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Http/Controllers/EditIndividualController.php#L519-L531
|
train
|
fisharebest/webtrees
|
app/Http/Controllers/EditIndividualController.php
|
EditIndividualController.editName
|
public function editName(ServerRequestInterface $request, Tree $tree): ResponseInterface
{
$fact_id = $request->get('fact_id', '');
$xref = $request->get('xref', '');
$individual = Individual::getInstance($xref, $tree);
Auth::checkIndividualAccess($individual, true);
// Find the fact to edit
foreach ($individual->facts() as $fact) {
if ($fact->id() === $fact_id && $fact->canEdit()) {
return $this->viewResponse('edit/new-individual', [
'tree' => $tree,
'title' => I18N::translate('Edit the name'),
'nextaction' => 'update',
'individual' => $individual,
'family' => null,
'name_fact' => $fact,
'famtag' => '',
'gender' => $individual->sex(),
]);
}
}
throw new NotFoundHttpException();
}
|
php
|
public function editName(ServerRequestInterface $request, Tree $tree): ResponseInterface
{
$fact_id = $request->get('fact_id', '');
$xref = $request->get('xref', '');
$individual = Individual::getInstance($xref, $tree);
Auth::checkIndividualAccess($individual, true);
// Find the fact to edit
foreach ($individual->facts() as $fact) {
if ($fact->id() === $fact_id && $fact->canEdit()) {
return $this->viewResponse('edit/new-individual', [
'tree' => $tree,
'title' => I18N::translate('Edit the name'),
'nextaction' => 'update',
'individual' => $individual,
'family' => null,
'name_fact' => $fact,
'famtag' => '',
'gender' => $individual->sex(),
]);
}
}
throw new NotFoundHttpException();
}
|
[
"public",
"function",
"editName",
"(",
"ServerRequestInterface",
"$",
"request",
",",
"Tree",
"$",
"tree",
")",
":",
"ResponseInterface",
"{",
"$",
"fact_id",
"=",
"$",
"request",
"->",
"get",
"(",
"'fact_id'",
",",
"''",
")",
";",
"$",
"xref",
"=",
"$",
"request",
"->",
"get",
"(",
"'xref'",
",",
"''",
")",
";",
"$",
"individual",
"=",
"Individual",
"::",
"getInstance",
"(",
"$",
"xref",
",",
"$",
"tree",
")",
";",
"Auth",
"::",
"checkIndividualAccess",
"(",
"$",
"individual",
",",
"true",
")",
";",
"// Find the fact to edit",
"foreach",
"(",
"$",
"individual",
"->",
"facts",
"(",
")",
"as",
"$",
"fact",
")",
"{",
"if",
"(",
"$",
"fact",
"->",
"id",
"(",
")",
"===",
"$",
"fact_id",
"&&",
"$",
"fact",
"->",
"canEdit",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"viewResponse",
"(",
"'edit/new-individual'",
",",
"[",
"'tree'",
"=>",
"$",
"tree",
",",
"'title'",
"=>",
"I18N",
"::",
"translate",
"(",
"'Edit the name'",
")",
",",
"'nextaction'",
"=>",
"'update'",
",",
"'individual'",
"=>",
"$",
"individual",
",",
"'family'",
"=>",
"null",
",",
"'name_fact'",
"=>",
"$",
"fact",
",",
"'famtag'",
"=>",
"''",
",",
"'gender'",
"=>",
"$",
"individual",
"->",
"sex",
"(",
")",
",",
"]",
")",
";",
"}",
"}",
"throw",
"new",
"NotFoundHttpException",
"(",
")",
";",
"}"
] |
Edit a name record.
@param ServerRequestInterface $request
@param Tree $tree
@return ResponseInterface
|
[
"Edit",
"a",
"name",
"record",
"."
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Http/Controllers/EditIndividualController.php#L578-L604
|
train
|
fisharebest/webtrees
|
app/Date/JewishDate.php
|
JewishDate.formatDay
|
protected function formatDay(): string
{
$locale = app(LocaleInterface::class)->language()->code();
if ($locale === 'he' || $locale === 'yi') {
return (new JewishCalendar())->numberToHebrewNumerals($this->day, true);
}
return parent::formatDay();
}
|
php
|
protected function formatDay(): string
{
$locale = app(LocaleInterface::class)->language()->code();
if ($locale === 'he' || $locale === 'yi') {
return (new JewishCalendar())->numberToHebrewNumerals($this->day, true);
}
return parent::formatDay();
}
|
[
"protected",
"function",
"formatDay",
"(",
")",
":",
"string",
"{",
"$",
"locale",
"=",
"app",
"(",
"LocaleInterface",
"::",
"class",
")",
"->",
"language",
"(",
")",
"->",
"code",
"(",
")",
";",
"if",
"(",
"$",
"locale",
"===",
"'he'",
"||",
"$",
"locale",
"===",
"'yi'",
")",
"{",
"return",
"(",
"new",
"JewishCalendar",
"(",
")",
")",
"->",
"numberToHebrewNumerals",
"(",
"$",
"this",
"->",
"day",
",",
"true",
")",
";",
"}",
"return",
"parent",
"::",
"formatDay",
"(",
")",
";",
"}"
] |
Generate the %j format for a date.
@return string
|
[
"Generate",
"the",
"%j",
"format",
"for",
"a",
"date",
"."
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Date/JewishDate.php#L69-L78
|
train
|
fisharebest/webtrees
|
app/Date/JewishDate.php
|
JewishDate.formatShortYear
|
protected function formatShortYear(): string
{
$locale = app(LocaleInterface::class)->language()->code();
if ($locale === 'he' || $locale === 'yi') {
return (new JewishCalendar())->numberToHebrewNumerals($this->year, false);
}
return parent::formatLongYear();
}
|
php
|
protected function formatShortYear(): string
{
$locale = app(LocaleInterface::class)->language()->code();
if ($locale === 'he' || $locale === 'yi') {
return (new JewishCalendar())->numberToHebrewNumerals($this->year, false);
}
return parent::formatLongYear();
}
|
[
"protected",
"function",
"formatShortYear",
"(",
")",
":",
"string",
"{",
"$",
"locale",
"=",
"app",
"(",
"LocaleInterface",
"::",
"class",
")",
"->",
"language",
"(",
")",
"->",
"code",
"(",
")",
";",
"if",
"(",
"$",
"locale",
"===",
"'he'",
"||",
"$",
"locale",
"===",
"'yi'",
")",
"{",
"return",
"(",
"new",
"JewishCalendar",
"(",
")",
")",
"->",
"numberToHebrewNumerals",
"(",
"$",
"this",
"->",
"year",
",",
"false",
")",
";",
"}",
"return",
"parent",
"::",
"formatLongYear",
"(",
")",
";",
"}"
] |
Generate the %y format for a date.
NOTE Short year is NOT a 2-digit year. It is for calendars such as hebrew
which have a 3-digit form of 4-digit years.
@return string
|
[
"Generate",
"the",
"%y",
"format",
"for",
"a",
"date",
"."
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Date/JewishDate.php#L88-L97
|
train
|
fisharebest/webtrees
|
app/Date/JewishDate.php
|
JewishDate.monthNameNominativeCase
|
protected function monthNameNominativeCase(int $month, bool $leap_year): string
{
static $translated_month_names;
if ($translated_month_names === null) {
$translated_month_names = [
0 => '',
/* I18N: a month in the Jewish calendar */
1 => I18N::translateContext('NOMINATIVE', 'Tishrei'),
/* I18N: a month in the Jewish calendar */
2 => I18N::translateContext('NOMINATIVE', 'Heshvan'),
/* I18N: a month in the Jewish calendar */
3 => I18N::translateContext('NOMINATIVE', 'Kislev'),
/* I18N: a month in the Jewish calendar */
4 => I18N::translateContext('NOMINATIVE', 'Tevet'),
/* I18N: a month in the Jewish calendar */
5 => I18N::translateContext('NOMINATIVE', 'Shevat'),
/* I18N: a month in the Jewish calendar */
6 => I18N::translateContext('NOMINATIVE', 'Adar I'),
/* I18N: a month in the Jewish calendar */
7 => I18N::translateContext('NOMINATIVE', 'Adar'),
/* I18N: a month in the Jewish calendar */
-7 => I18N::translateContext('NOMINATIVE', 'Adar II'),
/* I18N: a month in the Jewish calendar */
8 => I18N::translateContext('NOMINATIVE', 'Nissan'),
/* I18N: a month in the Jewish calendar */
9 => I18N::translateContext('NOMINATIVE', 'Iyar'),
/* I18N: a month in the Jewish calendar */
10 => I18N::translateContext('NOMINATIVE', 'Sivan'),
/* I18N: a month in the Jewish calendar */
11 => I18N::translateContext('NOMINATIVE', 'Tamuz'),
/* I18N: a month in the Jewish calendar */
12 => I18N::translateContext('NOMINATIVE', 'Av'),
/* I18N: a month in the Jewish calendar */
13 => I18N::translateContext('NOMINATIVE', 'Elul'),
];
}
if ($month === 7 && $leap_year) {
return $translated_month_names[-7];
}
return $translated_month_names[$month];
}
|
php
|
protected function monthNameNominativeCase(int $month, bool $leap_year): string
{
static $translated_month_names;
if ($translated_month_names === null) {
$translated_month_names = [
0 => '',
/* I18N: a month in the Jewish calendar */
1 => I18N::translateContext('NOMINATIVE', 'Tishrei'),
/* I18N: a month in the Jewish calendar */
2 => I18N::translateContext('NOMINATIVE', 'Heshvan'),
/* I18N: a month in the Jewish calendar */
3 => I18N::translateContext('NOMINATIVE', 'Kislev'),
/* I18N: a month in the Jewish calendar */
4 => I18N::translateContext('NOMINATIVE', 'Tevet'),
/* I18N: a month in the Jewish calendar */
5 => I18N::translateContext('NOMINATIVE', 'Shevat'),
/* I18N: a month in the Jewish calendar */
6 => I18N::translateContext('NOMINATIVE', 'Adar I'),
/* I18N: a month in the Jewish calendar */
7 => I18N::translateContext('NOMINATIVE', 'Adar'),
/* I18N: a month in the Jewish calendar */
-7 => I18N::translateContext('NOMINATIVE', 'Adar II'),
/* I18N: a month in the Jewish calendar */
8 => I18N::translateContext('NOMINATIVE', 'Nissan'),
/* I18N: a month in the Jewish calendar */
9 => I18N::translateContext('NOMINATIVE', 'Iyar'),
/* I18N: a month in the Jewish calendar */
10 => I18N::translateContext('NOMINATIVE', 'Sivan'),
/* I18N: a month in the Jewish calendar */
11 => I18N::translateContext('NOMINATIVE', 'Tamuz'),
/* I18N: a month in the Jewish calendar */
12 => I18N::translateContext('NOMINATIVE', 'Av'),
/* I18N: a month in the Jewish calendar */
13 => I18N::translateContext('NOMINATIVE', 'Elul'),
];
}
if ($month === 7 && $leap_year) {
return $translated_month_names[-7];
}
return $translated_month_names[$month];
}
|
[
"protected",
"function",
"monthNameNominativeCase",
"(",
"int",
"$",
"month",
",",
"bool",
"$",
"leap_year",
")",
":",
"string",
"{",
"static",
"$",
"translated_month_names",
";",
"if",
"(",
"$",
"translated_month_names",
"===",
"null",
")",
"{",
"$",
"translated_month_names",
"=",
"[",
"0",
"=>",
"''",
",",
"/* I18N: a month in the Jewish calendar */",
"1",
"=>",
"I18N",
"::",
"translateContext",
"(",
"'NOMINATIVE'",
",",
"'Tishrei'",
")",
",",
"/* I18N: a month in the Jewish calendar */",
"2",
"=>",
"I18N",
"::",
"translateContext",
"(",
"'NOMINATIVE'",
",",
"'Heshvan'",
")",
",",
"/* I18N: a month in the Jewish calendar */",
"3",
"=>",
"I18N",
"::",
"translateContext",
"(",
"'NOMINATIVE'",
",",
"'Kislev'",
")",
",",
"/* I18N: a month in the Jewish calendar */",
"4",
"=>",
"I18N",
"::",
"translateContext",
"(",
"'NOMINATIVE'",
",",
"'Tevet'",
")",
",",
"/* I18N: a month in the Jewish calendar */",
"5",
"=>",
"I18N",
"::",
"translateContext",
"(",
"'NOMINATIVE'",
",",
"'Shevat'",
")",
",",
"/* I18N: a month in the Jewish calendar */",
"6",
"=>",
"I18N",
"::",
"translateContext",
"(",
"'NOMINATIVE'",
",",
"'Adar I'",
")",
",",
"/* I18N: a month in the Jewish calendar */",
"7",
"=>",
"I18N",
"::",
"translateContext",
"(",
"'NOMINATIVE'",
",",
"'Adar'",
")",
",",
"/* I18N: a month in the Jewish calendar */",
"-",
"7",
"=>",
"I18N",
"::",
"translateContext",
"(",
"'NOMINATIVE'",
",",
"'Adar II'",
")",
",",
"/* I18N: a month in the Jewish calendar */",
"8",
"=>",
"I18N",
"::",
"translateContext",
"(",
"'NOMINATIVE'",
",",
"'Nissan'",
")",
",",
"/* I18N: a month in the Jewish calendar */",
"9",
"=>",
"I18N",
"::",
"translateContext",
"(",
"'NOMINATIVE'",
",",
"'Iyar'",
")",
",",
"/* I18N: a month in the Jewish calendar */",
"10",
"=>",
"I18N",
"::",
"translateContext",
"(",
"'NOMINATIVE'",
",",
"'Sivan'",
")",
",",
"/* I18N: a month in the Jewish calendar */",
"11",
"=>",
"I18N",
"::",
"translateContext",
"(",
"'NOMINATIVE'",
",",
"'Tamuz'",
")",
",",
"/* I18N: a month in the Jewish calendar */",
"12",
"=>",
"I18N",
"::",
"translateContext",
"(",
"'NOMINATIVE'",
",",
"'Av'",
")",
",",
"/* I18N: a month in the Jewish calendar */",
"13",
"=>",
"I18N",
"::",
"translateContext",
"(",
"'NOMINATIVE'",
",",
"'Elul'",
")",
",",
"]",
";",
"}",
"if",
"(",
"$",
"month",
"===",
"7",
"&&",
"$",
"leap_year",
")",
"{",
"return",
"$",
"translated_month_names",
"[",
"-",
"7",
"]",
";",
"}",
"return",
"$",
"translated_month_names",
"[",
"$",
"month",
"]",
";",
"}"
] |
Full month name in nominative case.
@param int $month
@param bool $leap_year Some calendars use leap months
@return string
|
[
"Full",
"month",
"name",
"in",
"nominative",
"case",
"."
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Date/JewishDate.php#L123-L166
|
train
|
fisharebest/webtrees
|
app/Date/JewishDate.php
|
JewishDate.monthNameAbbreviated
|
protected function monthNameAbbreviated(int $month, bool $leap_year): string
{
return $this->monthNameNominativeCase($month, $leap_year);
}
|
php
|
protected function monthNameAbbreviated(int $month, bool $leap_year): string
{
return $this->monthNameNominativeCase($month, $leap_year);
}
|
[
"protected",
"function",
"monthNameAbbreviated",
"(",
"int",
"$",
"month",
",",
"bool",
"$",
"leap_year",
")",
":",
"string",
"{",
"return",
"$",
"this",
"->",
"monthNameNominativeCase",
"(",
"$",
"month",
",",
"$",
"leap_year",
")",
";",
"}"
] |
Abbreviated month name
@param int $month
@param bool $leap_year Some calendars use leap months
@return string
|
[
"Abbreviated",
"month",
"name"
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Date/JewishDate.php#L335-L338
|
train
|
fisharebest/webtrees
|
app/Date/AbstractCalendarDate.php
|
AbstractCalendarDate.dayNames
|
public function dayNames(int $day_number): string
{
static $translated_day_names;
if ($translated_day_names === null) {
$translated_day_names = [
0 => I18N::translate('Monday'),
1 => I18N::translate('Tuesday'),
2 => I18N::translate('Wednesday'),
3 => I18N::translate('Thursday'),
4 => I18N::translate('Friday'),
5 => I18N::translate('Saturday'),
6 => I18N::translate('Sunday'),
];
}
return $translated_day_names[$day_number];
}
|
php
|
public function dayNames(int $day_number): string
{
static $translated_day_names;
if ($translated_day_names === null) {
$translated_day_names = [
0 => I18N::translate('Monday'),
1 => I18N::translate('Tuesday'),
2 => I18N::translate('Wednesday'),
3 => I18N::translate('Thursday'),
4 => I18N::translate('Friday'),
5 => I18N::translate('Saturday'),
6 => I18N::translate('Sunday'),
];
}
return $translated_day_names[$day_number];
}
|
[
"public",
"function",
"dayNames",
"(",
"int",
"$",
"day_number",
")",
":",
"string",
"{",
"static",
"$",
"translated_day_names",
";",
"if",
"(",
"$",
"translated_day_names",
"===",
"null",
")",
"{",
"$",
"translated_day_names",
"=",
"[",
"0",
"=>",
"I18N",
"::",
"translate",
"(",
"'Monday'",
")",
",",
"1",
"=>",
"I18N",
"::",
"translate",
"(",
"'Tuesday'",
")",
",",
"2",
"=>",
"I18N",
"::",
"translate",
"(",
"'Wednesday'",
")",
",",
"3",
"=>",
"I18N",
"::",
"translate",
"(",
"'Thursday'",
")",
",",
"4",
"=>",
"I18N",
"::",
"translate",
"(",
"'Friday'",
")",
",",
"5",
"=>",
"I18N",
"::",
"translate",
"(",
"'Saturday'",
")",
",",
"6",
"=>",
"I18N",
"::",
"translate",
"(",
"'Sunday'",
")",
",",
"]",
";",
"}",
"return",
"$",
"translated_day_names",
"[",
"$",
"day_number",
"]",
";",
"}"
] |
Full day of the week
@param int $day_number
@return string
|
[
"Full",
"day",
"of",
"the",
"week"
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Date/AbstractCalendarDate.php#L230-L247
|
train
|
fisharebest/webtrees
|
app/Date/AbstractCalendarDate.php
|
AbstractCalendarDate.dayNamesAbbreviated
|
protected function dayNamesAbbreviated(int $day_number): string
{
static $translated_day_names;
if ($translated_day_names === null) {
$translated_day_names = [
/* I18N: abbreviation for Monday */
0 => I18N::translate('Mon'),
/* I18N: abbreviation for Tuesday */
1 => I18N::translate('Tue'),
/* I18N: abbreviation for Wednesday */
2 => I18N::translate('Wed'),
/* I18N: abbreviation for Thursday */
3 => I18N::translate('Thu'),
/* I18N: abbreviation for Friday */
4 => I18N::translate('Fri'),
/* I18N: abbreviation for Saturday */
5 => I18N::translate('Sat'),
/* I18N: abbreviation for Sunday */
6 => I18N::translate('Sun'),
];
}
return $translated_day_names[$day_number];
}
|
php
|
protected function dayNamesAbbreviated(int $day_number): string
{
static $translated_day_names;
if ($translated_day_names === null) {
$translated_day_names = [
/* I18N: abbreviation for Monday */
0 => I18N::translate('Mon'),
/* I18N: abbreviation for Tuesday */
1 => I18N::translate('Tue'),
/* I18N: abbreviation for Wednesday */
2 => I18N::translate('Wed'),
/* I18N: abbreviation for Thursday */
3 => I18N::translate('Thu'),
/* I18N: abbreviation for Friday */
4 => I18N::translate('Fri'),
/* I18N: abbreviation for Saturday */
5 => I18N::translate('Sat'),
/* I18N: abbreviation for Sunday */
6 => I18N::translate('Sun'),
];
}
return $translated_day_names[$day_number];
}
|
[
"protected",
"function",
"dayNamesAbbreviated",
"(",
"int",
"$",
"day_number",
")",
":",
"string",
"{",
"static",
"$",
"translated_day_names",
";",
"if",
"(",
"$",
"translated_day_names",
"===",
"null",
")",
"{",
"$",
"translated_day_names",
"=",
"[",
"/* I18N: abbreviation for Monday */",
"0",
"=>",
"I18N",
"::",
"translate",
"(",
"'Mon'",
")",
",",
"/* I18N: abbreviation for Tuesday */",
"1",
"=>",
"I18N",
"::",
"translate",
"(",
"'Tue'",
")",
",",
"/* I18N: abbreviation for Wednesday */",
"2",
"=>",
"I18N",
"::",
"translate",
"(",
"'Wed'",
")",
",",
"/* I18N: abbreviation for Thursday */",
"3",
"=>",
"I18N",
"::",
"translate",
"(",
"'Thu'",
")",
",",
"/* I18N: abbreviation for Friday */",
"4",
"=>",
"I18N",
"::",
"translate",
"(",
"'Fri'",
")",
",",
"/* I18N: abbreviation for Saturday */",
"5",
"=>",
"I18N",
"::",
"translate",
"(",
"'Sat'",
")",
",",
"/* I18N: abbreviation for Sunday */",
"6",
"=>",
"I18N",
"::",
"translate",
"(",
"'Sun'",
")",
",",
"]",
";",
"}",
"return",
"$",
"translated_day_names",
"[",
"$",
"day_number",
"]",
";",
"}"
] |
Abbreviated day of the week
@param int $day_number
@return string
|
[
"Abbreviated",
"day",
"of",
"the",
"week"
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Date/AbstractCalendarDate.php#L256-L280
|
train
|
fisharebest/webtrees
|
app/Date/AbstractCalendarDate.php
|
AbstractCalendarDate.compare
|
public static function compare(AbstractCalendarDate $d1, AbstractCalendarDate $d2): int
{
if ($d1->maximum_julian_day < $d2->minimum_julian_day) {
return -1;
}
if ($d2->maximum_julian_day < $d1->minimum_julian_day) {
return 1;
}
return 0;
}
|
php
|
public static function compare(AbstractCalendarDate $d1, AbstractCalendarDate $d2): int
{
if ($d1->maximum_julian_day < $d2->minimum_julian_day) {
return -1;
}
if ($d2->maximum_julian_day < $d1->minimum_julian_day) {
return 1;
}
return 0;
}
|
[
"public",
"static",
"function",
"compare",
"(",
"AbstractCalendarDate",
"$",
"d1",
",",
"AbstractCalendarDate",
"$",
"d2",
")",
":",
"int",
"{",
"if",
"(",
"$",
"d1",
"->",
"maximum_julian_day",
"<",
"$",
"d2",
"->",
"minimum_julian_day",
")",
"{",
"return",
"-",
"1",
";",
"}",
"if",
"(",
"$",
"d2",
"->",
"maximum_julian_day",
"<",
"$",
"d1",
"->",
"minimum_julian_day",
")",
"{",
"return",
"1",
";",
"}",
"return",
"0",
";",
"}"
] |
Compare two dates, for sorting
@param AbstractCalendarDate $d1
@param AbstractCalendarDate $d2
@return int
|
[
"Compare",
"two",
"dates",
"for",
"sorting"
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Date/AbstractCalendarDate.php#L314-L325
|
train
|
fisharebest/webtrees
|
app/Date/AbstractCalendarDate.php
|
AbstractCalendarDate.getAge
|
public function getAge(int $jd): int
{
if ($this->year === 0 || $jd === 0) {
return 0;
}
if ($this->minimum_julian_day < $jd && $this->maximum_julian_day > $jd) {
return 0;
}
if ($this->minimum_julian_day === $jd) {
return 0;
}
[$y, $m, $d] = $this->calendar->jdToYmd($jd);
$dy = $y - $this->year;
$dm = $m - max($this->month, 1);
$dd = $d - max($this->day, 1);
if ($dd < 0) {
$dm--;
}
if ($dm < 0) {
$dy--;
}
// Not a full age? Then just the years
return $dy;
}
|
php
|
public function getAge(int $jd): int
{
if ($this->year === 0 || $jd === 0) {
return 0;
}
if ($this->minimum_julian_day < $jd && $this->maximum_julian_day > $jd) {
return 0;
}
if ($this->minimum_julian_day === $jd) {
return 0;
}
[$y, $m, $d] = $this->calendar->jdToYmd($jd);
$dy = $y - $this->year;
$dm = $m - max($this->month, 1);
$dd = $d - max($this->day, 1);
if ($dd < 0) {
$dm--;
}
if ($dm < 0) {
$dy--;
}
// Not a full age? Then just the years
return $dy;
}
|
[
"public",
"function",
"getAge",
"(",
"int",
"$",
"jd",
")",
":",
"int",
"{",
"if",
"(",
"$",
"this",
"->",
"year",
"===",
"0",
"||",
"$",
"jd",
"===",
"0",
")",
"{",
"return",
"0",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"minimum_julian_day",
"<",
"$",
"jd",
"&&",
"$",
"this",
"->",
"maximum_julian_day",
">",
"$",
"jd",
")",
"{",
"return",
"0",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"minimum_julian_day",
"===",
"$",
"jd",
")",
"{",
"return",
"0",
";",
"}",
"[",
"$",
"y",
",",
"$",
"m",
",",
"$",
"d",
"]",
"=",
"$",
"this",
"->",
"calendar",
"->",
"jdToYmd",
"(",
"$",
"jd",
")",
";",
"$",
"dy",
"=",
"$",
"y",
"-",
"$",
"this",
"->",
"year",
";",
"$",
"dm",
"=",
"$",
"m",
"-",
"max",
"(",
"$",
"this",
"->",
"month",
",",
"1",
")",
";",
"$",
"dd",
"=",
"$",
"d",
"-",
"max",
"(",
"$",
"this",
"->",
"day",
",",
"1",
")",
";",
"if",
"(",
"$",
"dd",
"<",
"0",
")",
"{",
"$",
"dm",
"--",
";",
"}",
"if",
"(",
"$",
"dm",
"<",
"0",
")",
"{",
"$",
"dy",
"--",
";",
"}",
"// Not a full age? Then just the years",
"return",
"$",
"dy",
";",
"}"
] |
How long between an event and a given julian day
Return result as a number of years.
@param int $jd date for calculation
@return int
|
[
"How",
"long",
"between",
"an",
"event",
"and",
"a",
"given",
"julian",
"day",
"Return",
"result",
"as",
"a",
"number",
"of",
"years",
"."
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Date/AbstractCalendarDate.php#L378-L402
|
train
|
fisharebest/webtrees
|
app/Date/AbstractCalendarDate.php
|
AbstractCalendarDate.getAgeFull
|
public function getAgeFull(int $jd): string
{
if ($this->year === 0 || $jd === 0) {
return '';
}
if ($this->minimum_julian_day < $jd && $this->maximum_julian_day > $jd) {
return '';
}
if ($this->minimum_julian_day === $jd) {
return '';
}
if ($jd < $this->minimum_julian_day) {
return view('icons/warning');
}
[$y, $m, $d] = $this->calendar->jdToYmd($jd);
$dy = $y - $this->year;
$dm = $m - max($this->month, 1);
$dd = $d - max($this->day, 1);
if ($dd < 0) {
$dm--;
}
if ($dm < 0) {
$dm += $this->calendar->monthsInYear();
$dy--;
}
// Age in years?
if ($dy > 1) {
return $dy . 'y';
}
$dm += $dy * $this->calendar->monthsInYear();
// Age in months?
if ($dm > 1) {
return $dm . 'm';
}
// Age in days?
return ($jd - $this->minimum_julian_day) . 'd';
}
|
php
|
public function getAgeFull(int $jd): string
{
if ($this->year === 0 || $jd === 0) {
return '';
}
if ($this->minimum_julian_day < $jd && $this->maximum_julian_day > $jd) {
return '';
}
if ($this->minimum_julian_day === $jd) {
return '';
}
if ($jd < $this->minimum_julian_day) {
return view('icons/warning');
}
[$y, $m, $d] = $this->calendar->jdToYmd($jd);
$dy = $y - $this->year;
$dm = $m - max($this->month, 1);
$dd = $d - max($this->day, 1);
if ($dd < 0) {
$dm--;
}
if ($dm < 0) {
$dm += $this->calendar->monthsInYear();
$dy--;
}
// Age in years?
if ($dy > 1) {
return $dy . 'y';
}
$dm += $dy * $this->calendar->monthsInYear();
// Age in months?
if ($dm > 1) {
return $dm . 'm';
}
// Age in days?
return ($jd - $this->minimum_julian_day) . 'd';
}
|
[
"public",
"function",
"getAgeFull",
"(",
"int",
"$",
"jd",
")",
":",
"string",
"{",
"if",
"(",
"$",
"this",
"->",
"year",
"===",
"0",
"||",
"$",
"jd",
"===",
"0",
")",
"{",
"return",
"''",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"minimum_julian_day",
"<",
"$",
"jd",
"&&",
"$",
"this",
"->",
"maximum_julian_day",
">",
"$",
"jd",
")",
"{",
"return",
"''",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"minimum_julian_day",
"===",
"$",
"jd",
")",
"{",
"return",
"''",
";",
"}",
"if",
"(",
"$",
"jd",
"<",
"$",
"this",
"->",
"minimum_julian_day",
")",
"{",
"return",
"view",
"(",
"'icons/warning'",
")",
";",
"}",
"[",
"$",
"y",
",",
"$",
"m",
",",
"$",
"d",
"]",
"=",
"$",
"this",
"->",
"calendar",
"->",
"jdToYmd",
"(",
"$",
"jd",
")",
";",
"$",
"dy",
"=",
"$",
"y",
"-",
"$",
"this",
"->",
"year",
";",
"$",
"dm",
"=",
"$",
"m",
"-",
"max",
"(",
"$",
"this",
"->",
"month",
",",
"1",
")",
";",
"$",
"dd",
"=",
"$",
"d",
"-",
"max",
"(",
"$",
"this",
"->",
"day",
",",
"1",
")",
";",
"if",
"(",
"$",
"dd",
"<",
"0",
")",
"{",
"$",
"dm",
"--",
";",
"}",
"if",
"(",
"$",
"dm",
"<",
"0",
")",
"{",
"$",
"dm",
"+=",
"$",
"this",
"->",
"calendar",
"->",
"monthsInYear",
"(",
")",
";",
"$",
"dy",
"--",
";",
"}",
"// Age in years?",
"if",
"(",
"$",
"dy",
">",
"1",
")",
"{",
"return",
"$",
"dy",
".",
"'y'",
";",
"}",
"$",
"dm",
"+=",
"$",
"dy",
"*",
"$",
"this",
"->",
"calendar",
"->",
"monthsInYear",
"(",
")",
";",
"// Age in months?",
"if",
"(",
"$",
"dm",
">",
"1",
")",
"{",
"return",
"$",
"dm",
".",
"'m'",
";",
"}",
"// Age in days?",
"return",
"(",
"$",
"jd",
"-",
"$",
"this",
"->",
"minimum_julian_day",
")",
".",
"'d'",
";",
"}"
] |
How long between an event and a given julian day
Return result as a gedcom-style age string.
@param int $jd date for calculation
@return string
|
[
"How",
"long",
"between",
"an",
"event",
"and",
"a",
"given",
"julian",
"day",
"Return",
"result",
"as",
"a",
"gedcom",
"-",
"style",
"age",
"string",
"."
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Date/AbstractCalendarDate.php#L412-L449
|
train
|
fisharebest/webtrees
|
app/Date/AbstractCalendarDate.php
|
AbstractCalendarDate.convertToCalendar
|
public function convertToCalendar(string $calendar): AbstractCalendarDate
{
switch ($calendar) {
case 'gregorian':
return new GregorianDate($this);
case 'julian':
return new JulianDate($this);
case 'jewish':
return new JewishDate($this);
case 'french':
return new FrenchDate($this);
case 'hijri':
return new HijriDate($this);
case 'jalali':
return new JalaliDate($this);
default:
return $this;
}
}
|
php
|
public function convertToCalendar(string $calendar): AbstractCalendarDate
{
switch ($calendar) {
case 'gregorian':
return new GregorianDate($this);
case 'julian':
return new JulianDate($this);
case 'jewish':
return new JewishDate($this);
case 'french':
return new FrenchDate($this);
case 'hijri':
return new HijriDate($this);
case 'jalali':
return new JalaliDate($this);
default:
return $this;
}
}
|
[
"public",
"function",
"convertToCalendar",
"(",
"string",
"$",
"calendar",
")",
":",
"AbstractCalendarDate",
"{",
"switch",
"(",
"$",
"calendar",
")",
"{",
"case",
"'gregorian'",
":",
"return",
"new",
"GregorianDate",
"(",
"$",
"this",
")",
";",
"case",
"'julian'",
":",
"return",
"new",
"JulianDate",
"(",
"$",
"this",
")",
";",
"case",
"'jewish'",
":",
"return",
"new",
"JewishDate",
"(",
"$",
"this",
")",
";",
"case",
"'french'",
":",
"return",
"new",
"FrenchDate",
"(",
"$",
"this",
")",
";",
"case",
"'hijri'",
":",
"return",
"new",
"HijriDate",
"(",
"$",
"this",
")",
";",
"case",
"'jalali'",
":",
"return",
"new",
"JalaliDate",
"(",
"$",
"this",
")",
";",
"default",
":",
"return",
"$",
"this",
";",
"}",
"}"
] |
Convert a date from one calendar to another.
@param string $calendar
@return AbstractCalendarDate
|
[
"Convert",
"a",
"date",
"from",
"one",
"calendar",
"to",
"another",
"."
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Date/AbstractCalendarDate.php#L458-L476
|
train
|
fisharebest/webtrees
|
app/Date/AbstractCalendarDate.php
|
AbstractCalendarDate.inValidRange
|
public function inValidRange(): bool
{
return $this->minimum_julian_day >= $this->calendar->jdStart() && $this->maximum_julian_day <= $this->calendar->jdEnd();
}
|
php
|
public function inValidRange(): bool
{
return $this->minimum_julian_day >= $this->calendar->jdStart() && $this->maximum_julian_day <= $this->calendar->jdEnd();
}
|
[
"public",
"function",
"inValidRange",
"(",
")",
":",
"bool",
"{",
"return",
"$",
"this",
"->",
"minimum_julian_day",
">=",
"$",
"this",
"->",
"calendar",
"->",
"jdStart",
"(",
")",
"&&",
"$",
"this",
"->",
"maximum_julian_day",
"<=",
"$",
"this",
"->",
"calendar",
"->",
"jdEnd",
"(",
")",
";",
"}"
] |
Is this date within the valid range of the calendar
@return bool
|
[
"Is",
"this",
"date",
"within",
"the",
"valid",
"range",
"of",
"the",
"calendar"
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Date/AbstractCalendarDate.php#L483-L486
|
train
|
fisharebest/webtrees
|
app/Date/AbstractCalendarDate.php
|
AbstractCalendarDate.daysInMonth
|
public function daysInMonth(): int
{
try {
return $this->calendar->daysInMonth($this->year, $this->month);
} catch (InvalidArgumentException $ex) {
// calendar.php calls this with "DD MMM" dates, for which we cannot calculate
// the length of a month. Should we validate this before calling this function?
return 0;
}
}
|
php
|
public function daysInMonth(): int
{
try {
return $this->calendar->daysInMonth($this->year, $this->month);
} catch (InvalidArgumentException $ex) {
// calendar.php calls this with "DD MMM" dates, for which we cannot calculate
// the length of a month. Should we validate this before calling this function?
return 0;
}
}
|
[
"public",
"function",
"daysInMonth",
"(",
")",
":",
"int",
"{",
"try",
"{",
"return",
"$",
"this",
"->",
"calendar",
"->",
"daysInMonth",
"(",
"$",
"this",
"->",
"year",
",",
"$",
"this",
"->",
"month",
")",
";",
"}",
"catch",
"(",
"InvalidArgumentException",
"$",
"ex",
")",
"{",
"// calendar.php calls this with \"DD MMM\" dates, for which we cannot calculate",
"// the length of a month. Should we validate this before calling this function?",
"return",
"0",
";",
"}",
"}"
] |
How many days in the current month
@return int
|
[
"How",
"many",
"days",
"in",
"the",
"current",
"month"
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Date/AbstractCalendarDate.php#L503-L512
|
train
|
fisharebest/webtrees
|
app/Date/AbstractCalendarDate.php
|
AbstractCalendarDate.formatDayZeros
|
protected function formatDayZeros(): string
{
if ($this->day > 9) {
return I18N::digits($this->day);
}
return I18N::digits('0' . $this->day);
}
|
php
|
protected function formatDayZeros(): string
{
if ($this->day > 9) {
return I18N::digits($this->day);
}
return I18N::digits('0' . $this->day);
}
|
[
"protected",
"function",
"formatDayZeros",
"(",
")",
":",
"string",
"{",
"if",
"(",
"$",
"this",
"->",
"day",
">",
"9",
")",
"{",
"return",
"I18N",
"::",
"digits",
"(",
"$",
"this",
"->",
"day",
")",
";",
"}",
"return",
"I18N",
"::",
"digits",
"(",
"'0'",
".",
"$",
"this",
"->",
"day",
")",
";",
"}"
] |
Generate the %d format for a date.
@return string
|
[
"Generate",
"the",
"%d",
"format",
"for",
"a",
"date",
"."
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Date/AbstractCalendarDate.php#L661-L668
|
train
|
fisharebest/webtrees
|
app/Date/AbstractCalendarDate.php
|
AbstractCalendarDate.formatDayOfYear
|
protected function formatDayOfYear(): string
{
return I18N::digits($this->minimum_julian_day - $this->calendar->ymdToJd($this->year, 1, 1));
}
|
php
|
protected function formatDayOfYear(): string
{
return I18N::digits($this->minimum_julian_day - $this->calendar->ymdToJd($this->year, 1, 1));
}
|
[
"protected",
"function",
"formatDayOfYear",
"(",
")",
":",
"string",
"{",
"return",
"I18N",
"::",
"digits",
"(",
"$",
"this",
"->",
"minimum_julian_day",
"-",
"$",
"this",
"->",
"calendar",
"->",
"ymdToJd",
"(",
"$",
"this",
"->",
"year",
",",
"1",
",",
"1",
")",
")",
";",
"}"
] |
Generate the %z format for a date.
@return string
|
[
"Generate",
"the",
"%z",
"format",
"for",
"a",
"date",
"."
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Date/AbstractCalendarDate.php#L725-L728
|
train
|
fisharebest/webtrees
|
app/Date/AbstractCalendarDate.php
|
AbstractCalendarDate.formatMonthZeros
|
protected function formatMonthZeros(): string
{
if ($this->month > 9) {
return I18N::digits($this->month);
}
return I18N::digits('0' . $this->month);
}
|
php
|
protected function formatMonthZeros(): string
{
if ($this->month > 9) {
return I18N::digits($this->month);
}
return I18N::digits('0' . $this->month);
}
|
[
"protected",
"function",
"formatMonthZeros",
"(",
")",
":",
"string",
"{",
"if",
"(",
"$",
"this",
"->",
"month",
">",
"9",
")",
"{",
"return",
"I18N",
"::",
"digits",
"(",
"$",
"this",
"->",
"month",
")",
";",
"}",
"return",
"I18N",
"::",
"digits",
"(",
"'0'",
".",
"$",
"this",
"->",
"month",
")",
";",
"}"
] |
Generate the %m format for a date.
@return string
|
[
"Generate",
"the",
"%m",
"format",
"for",
"a",
"date",
"."
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Date/AbstractCalendarDate.php#L745-L752
|
train
|
fisharebest/webtrees
|
app/Date/AbstractCalendarDate.php
|
AbstractCalendarDate.formatLongMonth
|
protected function formatLongMonth($case = 'NOMINATIVE'): string
{
switch ($case) {
case 'GENITIVE':
return $this->monthNameGenitiveCase($this->month, $this->isLeapYear());
case 'NOMINATIVE':
return $this->monthNameNominativeCase($this->month, $this->isLeapYear());
case 'LOCATIVE':
return $this->monthNameLocativeCase($this->month, $this->isLeapYear());
case 'INSTRUMENTAL':
return $this->monthNameInstrumentalCase($this->month, $this->isLeapYear());
default:
throw new InvalidArgumentException($case);
}
}
|
php
|
protected function formatLongMonth($case = 'NOMINATIVE'): string
{
switch ($case) {
case 'GENITIVE':
return $this->monthNameGenitiveCase($this->month, $this->isLeapYear());
case 'NOMINATIVE':
return $this->monthNameNominativeCase($this->month, $this->isLeapYear());
case 'LOCATIVE':
return $this->monthNameLocativeCase($this->month, $this->isLeapYear());
case 'INSTRUMENTAL':
return $this->monthNameInstrumentalCase($this->month, $this->isLeapYear());
default:
throw new InvalidArgumentException($case);
}
}
|
[
"protected",
"function",
"formatLongMonth",
"(",
"$",
"case",
"=",
"'NOMINATIVE'",
")",
":",
"string",
"{",
"switch",
"(",
"$",
"case",
")",
"{",
"case",
"'GENITIVE'",
":",
"return",
"$",
"this",
"->",
"monthNameGenitiveCase",
"(",
"$",
"this",
"->",
"month",
",",
"$",
"this",
"->",
"isLeapYear",
"(",
")",
")",
";",
"case",
"'NOMINATIVE'",
":",
"return",
"$",
"this",
"->",
"monthNameNominativeCase",
"(",
"$",
"this",
"->",
"month",
",",
"$",
"this",
"->",
"isLeapYear",
"(",
")",
")",
";",
"case",
"'LOCATIVE'",
":",
"return",
"$",
"this",
"->",
"monthNameLocativeCase",
"(",
"$",
"this",
"->",
"month",
",",
"$",
"this",
"->",
"isLeapYear",
"(",
")",
")",
";",
"case",
"'INSTRUMENTAL'",
":",
"return",
"$",
"this",
"->",
"monthNameInstrumentalCase",
"(",
"$",
"this",
"->",
"month",
",",
"$",
"this",
"->",
"isLeapYear",
"(",
")",
")",
";",
"default",
":",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"case",
")",
";",
"}",
"}"
] |
Generate the %F format for a date.
@param string $case Which grammatical case shall we use
@return string
|
[
"Generate",
"the",
"%F",
"format",
"for",
"a",
"date",
"."
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Date/AbstractCalendarDate.php#L761-L775
|
train
|
fisharebest/webtrees
|
app/Date/AbstractCalendarDate.php
|
AbstractCalendarDate.formatGedcomMonth
|
protected function formatGedcomMonth(): string
{
// Our simple lookup table doesn't work correctly for Adar on leap years
if ($this->month === 7 && $this->calendar instanceof JewishCalendar && !$this->calendar->isLeapYear($this->year)) {
return 'ADR';
}
return array_search($this->month, static::MONTH_ABBREVIATIONS, true);
}
|
php
|
protected function formatGedcomMonth(): string
{
// Our simple lookup table doesn't work correctly for Adar on leap years
if ($this->month === 7 && $this->calendar instanceof JewishCalendar && !$this->calendar->isLeapYear($this->year)) {
return 'ADR';
}
return array_search($this->month, static::MONTH_ABBREVIATIONS, true);
}
|
[
"protected",
"function",
"formatGedcomMonth",
"(",
")",
":",
"string",
"{",
"// Our simple lookup table doesn't work correctly for Adar on leap years",
"if",
"(",
"$",
"this",
"->",
"month",
"===",
"7",
"&&",
"$",
"this",
"->",
"calendar",
"instanceof",
"JewishCalendar",
"&&",
"!",
"$",
"this",
"->",
"calendar",
"->",
"isLeapYear",
"(",
"$",
"this",
"->",
"year",
")",
")",
"{",
"return",
"'ADR'",
";",
"}",
"return",
"array_search",
"(",
"$",
"this",
"->",
"month",
",",
"static",
"::",
"MONTH_ABBREVIATIONS",
",",
"true",
")",
";",
"}"
] |
Generate the %O format for a date.
@return string
|
[
"Generate",
"the",
"%O",
"format",
"for",
"a",
"date",
"."
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Date/AbstractCalendarDate.php#L868-L876
|
train
|
fisharebest/webtrees
|
app/Date/AbstractCalendarDate.php
|
AbstractCalendarDate.calendarUrl
|
public function calendarUrl(string $date_format, Tree $tree): string
{
if ($this->day !== 0 && strpbrk($date_format, 'dDj')) {
// If the format includes a day, and the date also includes a day, then use the day view
$view = 'day';
} elseif ($this->month !== 0 && strpbrk($date_format, 'FMmn')) {
// If the format includes a month, and the date also includes a month, then use the month view
$view = 'month';
} else {
// Use the year view
$view = 'year';
}
return route('calendar', [
'cal' => $this->calendar->gedcomCalendarEscape(),
'year' => $this->formatGedcomYear(),
'month' => $this->formatGedcomMonth(),
'day' => $this->formatGedcomDay(),
'view' => $view,
'ged' => $tree->name(),
]);
}
|
php
|
public function calendarUrl(string $date_format, Tree $tree): string
{
if ($this->day !== 0 && strpbrk($date_format, 'dDj')) {
// If the format includes a day, and the date also includes a day, then use the day view
$view = 'day';
} elseif ($this->month !== 0 && strpbrk($date_format, 'FMmn')) {
// If the format includes a month, and the date also includes a month, then use the month view
$view = 'month';
} else {
// Use the year view
$view = 'year';
}
return route('calendar', [
'cal' => $this->calendar->gedcomCalendarEscape(),
'year' => $this->formatGedcomYear(),
'month' => $this->formatGedcomMonth(),
'day' => $this->formatGedcomDay(),
'view' => $view,
'ged' => $tree->name(),
]);
}
|
[
"public",
"function",
"calendarUrl",
"(",
"string",
"$",
"date_format",
",",
"Tree",
"$",
"tree",
")",
":",
"string",
"{",
"if",
"(",
"$",
"this",
"->",
"day",
"!==",
"0",
"&&",
"strpbrk",
"(",
"$",
"date_format",
",",
"'dDj'",
")",
")",
"{",
"// If the format includes a day, and the date also includes a day, then use the day view",
"$",
"view",
"=",
"'day'",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"month",
"!==",
"0",
"&&",
"strpbrk",
"(",
"$",
"date_format",
",",
"'FMmn'",
")",
")",
"{",
"// If the format includes a month, and the date also includes a month, then use the month view",
"$",
"view",
"=",
"'month'",
";",
"}",
"else",
"{",
"// Use the year view",
"$",
"view",
"=",
"'year'",
";",
"}",
"return",
"route",
"(",
"'calendar'",
",",
"[",
"'cal'",
"=>",
"$",
"this",
"->",
"calendar",
"->",
"gedcomCalendarEscape",
"(",
")",
",",
"'year'",
"=>",
"$",
"this",
"->",
"formatGedcomYear",
"(",
")",
",",
"'month'",
"=>",
"$",
"this",
"->",
"formatGedcomMonth",
"(",
")",
",",
"'day'",
"=>",
"$",
"this",
"->",
"formatGedcomDay",
"(",
")",
",",
"'view'",
"=>",
"$",
"view",
",",
"'ged'",
"=>",
"$",
"tree",
"->",
"name",
"(",
")",
",",
"]",
")",
";",
"}"
] |
Create a URL that links this date to the WT calendar
@param string $date_format
@param Tree $tree
@return string
|
[
"Create",
"a",
"URL",
"that",
"links",
"this",
"date",
"to",
"the",
"WT",
"calendar"
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Date/AbstractCalendarDate.php#L960-L981
|
train
|
fisharebest/webtrees
|
app/View.php
|
View.endpushunique
|
public static function endpushunique(): void
{
$content = ob_get_clean();
self::$stacks[self::$stack][sha1($content)] = $content;
}
|
php
|
public static function endpushunique(): void
{
$content = ob_get_clean();
self::$stacks[self::$stack][sha1($content)] = $content;
}
|
[
"public",
"static",
"function",
"endpushunique",
"(",
")",
":",
"void",
"{",
"$",
"content",
"=",
"ob_get_clean",
"(",
")",
";",
"self",
"::",
"$",
"stacks",
"[",
"self",
"::",
"$",
"stack",
"]",
"[",
"sha1",
"(",
"$",
"content",
")",
"]",
"=",
"$",
"content",
";",
"}"
] |
Variant of push that will only add one copy of each item.
@return void
|
[
"Variant",
"of",
"push",
"that",
"will",
"only",
"add",
"one",
"copy",
"of",
"each",
"item",
"."
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/View.php#L153-L158
|
train
|
fisharebest/webtrees
|
app/View.php
|
View.stack
|
public static function stack(string $stack): string
{
$content = implode('', self::$stacks[$stack] ?? []);
self::$stacks[$stack] = [];
return $content;
}
|
php
|
public static function stack(string $stack): string
{
$content = implode('', self::$stacks[$stack] ?? []);
self::$stacks[$stack] = [];
return $content;
}
|
[
"public",
"static",
"function",
"stack",
"(",
"string",
"$",
"stack",
")",
":",
"string",
"{",
"$",
"content",
"=",
"implode",
"(",
"''",
",",
"self",
"::",
"$",
"stacks",
"[",
"$",
"stack",
"]",
"??",
"[",
"]",
")",
";",
"self",
"::",
"$",
"stacks",
"[",
"$",
"stack",
"]",
"=",
"[",
"]",
";",
"return",
"$",
"content",
";",
"}"
] |
Implementation of Blade "stacks".
@param string $stack
@return string
|
[
"Implementation",
"of",
"Blade",
"stacks",
"."
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/View.php#L167-L174
|
train
|
fisharebest/webtrees
|
app/View.php
|
View.getFilenameForView
|
public function getFilenameForView(string $view_name): string
{
// If we request "::view", then use it explicityly. Don't allow replacements.
$explicit = Str::startsWith($view_name, self::NAMESPACE_SEPARATOR);
if (!Str::contains($view_name, self::NAMESPACE_SEPARATOR)) {
$view_name = self::NAMESPACE_SEPARATOR . $view_name;
}
// Apply replacements / customisations
while (!$explicit && array_key_exists($view_name, self::$replacements)) {
$view_name = self::$replacements[$view_name];
}
[$namespace, $view_name] = explode(self::NAMESPACE_SEPARATOR, $view_name, 2);
if ((self::$namespaces[$namespace] ?? null) === null) {
throw new RuntimeException('Namespace "' . e($namespace) . '" not found.');
}
$view_file = self::$namespaces[$namespace] . $view_name . self::TEMPLATE_EXTENSION;
if (!is_file($view_file)) {
throw new RuntimeException('View file not found: ' . e($view_file));
}
return $view_file;
}
|
php
|
public function getFilenameForView(string $view_name): string
{
// If we request "::view", then use it explicityly. Don't allow replacements.
$explicit = Str::startsWith($view_name, self::NAMESPACE_SEPARATOR);
if (!Str::contains($view_name, self::NAMESPACE_SEPARATOR)) {
$view_name = self::NAMESPACE_SEPARATOR . $view_name;
}
// Apply replacements / customisations
while (!$explicit && array_key_exists($view_name, self::$replacements)) {
$view_name = self::$replacements[$view_name];
}
[$namespace, $view_name] = explode(self::NAMESPACE_SEPARATOR, $view_name, 2);
if ((self::$namespaces[$namespace] ?? null) === null) {
throw new RuntimeException('Namespace "' . e($namespace) . '" not found.');
}
$view_file = self::$namespaces[$namespace] . $view_name . self::TEMPLATE_EXTENSION;
if (!is_file($view_file)) {
throw new RuntimeException('View file not found: ' . e($view_file));
}
return $view_file;
}
|
[
"public",
"function",
"getFilenameForView",
"(",
"string",
"$",
"view_name",
")",
":",
"string",
"{",
"// If we request \"::view\", then use it explicityly. Don't allow replacements.",
"$",
"explicit",
"=",
"Str",
"::",
"startsWith",
"(",
"$",
"view_name",
",",
"self",
"::",
"NAMESPACE_SEPARATOR",
")",
";",
"if",
"(",
"!",
"Str",
"::",
"contains",
"(",
"$",
"view_name",
",",
"self",
"::",
"NAMESPACE_SEPARATOR",
")",
")",
"{",
"$",
"view_name",
"=",
"self",
"::",
"NAMESPACE_SEPARATOR",
".",
"$",
"view_name",
";",
"}",
"// Apply replacements / customisations",
"while",
"(",
"!",
"$",
"explicit",
"&&",
"array_key_exists",
"(",
"$",
"view_name",
",",
"self",
"::",
"$",
"replacements",
")",
")",
"{",
"$",
"view_name",
"=",
"self",
"::",
"$",
"replacements",
"[",
"$",
"view_name",
"]",
";",
"}",
"[",
"$",
"namespace",
",",
"$",
"view_name",
"]",
"=",
"explode",
"(",
"self",
"::",
"NAMESPACE_SEPARATOR",
",",
"$",
"view_name",
",",
"2",
")",
";",
"if",
"(",
"(",
"self",
"::",
"$",
"namespaces",
"[",
"$",
"namespace",
"]",
"??",
"null",
")",
"===",
"null",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"'Namespace \"'",
".",
"e",
"(",
"$",
"namespace",
")",
".",
"'\" not found.'",
")",
";",
"}",
"$",
"view_file",
"=",
"self",
"::",
"$",
"namespaces",
"[",
"$",
"namespace",
"]",
".",
"$",
"view_name",
".",
"self",
"::",
"TEMPLATE_EXTENSION",
";",
"if",
"(",
"!",
"is_file",
"(",
"$",
"view_file",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"'View file not found: '",
".",
"e",
"(",
"$",
"view_file",
")",
")",
";",
"}",
"return",
"$",
"view_file",
";",
"}"
] |
Find the file for a view.
@param string $view_name
@return string
@throws Exception
|
[
"Find",
"the",
"file",
"for",
"a",
"view",
"."
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/View.php#L241-L268
|
train
|
fisharebest/webtrees
|
app/View.php
|
View.make
|
public static function make($name, $data = []): string
{
$view = new static($name, $data);
DebugBar::addView($name, $data);
return $view->render();
}
|
php
|
public static function make($name, $data = []): string
{
$view = new static($name, $data);
DebugBar::addView($name, $data);
return $view->render();
}
|
[
"public",
"static",
"function",
"make",
"(",
"$",
"name",
",",
"$",
"data",
"=",
"[",
"]",
")",
":",
"string",
"{",
"$",
"view",
"=",
"new",
"static",
"(",
"$",
"name",
",",
"$",
"data",
")",
";",
"DebugBar",
"::",
"addView",
"(",
"$",
"name",
",",
"$",
"data",
")",
";",
"return",
"$",
"view",
"->",
"render",
"(",
")",
";",
"}"
] |
Cerate and render a view in a single operation.
@param string $name
@param mixed[] $data
@return string
|
[
"Cerate",
"and",
"render",
"a",
"view",
"in",
"a",
"single",
"operation",
"."
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/View.php#L278-L285
|
train
|
fisharebest/webtrees
|
app/Services/ClipboardService.php
|
ClipboardService.pasteFact
|
public function pasteFact(string $fact_id, GedcomRecord $record): bool
{
$clipboard = Session::get('clipboard');
$record_type = $record::RECORD_TYPE;
if (isset($clipboard[$record_type][$fact_id])) {
$record->createFact($clipboard[$record_type][$fact_id]['factrec'], true);
return true;
}
return false;
}
|
php
|
public function pasteFact(string $fact_id, GedcomRecord $record): bool
{
$clipboard = Session::get('clipboard');
$record_type = $record::RECORD_TYPE;
if (isset($clipboard[$record_type][$fact_id])) {
$record->createFact($clipboard[$record_type][$fact_id]['factrec'], true);
return true;
}
return false;
}
|
[
"public",
"function",
"pasteFact",
"(",
"string",
"$",
"fact_id",
",",
"GedcomRecord",
"$",
"record",
")",
":",
"bool",
"{",
"$",
"clipboard",
"=",
"Session",
"::",
"get",
"(",
"'clipboard'",
")",
";",
"$",
"record_type",
"=",
"$",
"record",
"::",
"RECORD_TYPE",
";",
"if",
"(",
"isset",
"(",
"$",
"clipboard",
"[",
"$",
"record_type",
"]",
"[",
"$",
"fact_id",
"]",
")",
")",
"{",
"$",
"record",
"->",
"createFact",
"(",
"$",
"clipboard",
"[",
"$",
"record_type",
"]",
"[",
"$",
"fact_id",
"]",
"[",
"'factrec'",
"]",
",",
"true",
")",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] |
Copy a fact from the clipboard to a record.
@param string $fact_id
@param GedcomRecord $record
@return bool
|
[
"Copy",
"a",
"fact",
"from",
"the",
"clipboard",
"to",
"a",
"record",
"."
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Services/ClipboardService.php#L66-L79
|
train
|
fisharebest/webtrees
|
app/Services/ClipboardService.php
|
ClipboardService.pastableFacts
|
public function pastableFacts(GedcomRecord $record, Collection $exclude_types): Collection
{
// The facts are stored in the session.
return (new Collection(Session::get('clipboard', [])[$record::RECORD_TYPE] ?? []))
// Put the most recently copied fact at the top of the list.
->reverse()
// Create facts for the record.
->map(static function (array $clipping) use ($record): Fact {
return new Fact($clipping['factrec'], $record, md5($clipping['factrec']));
})->filter(static function (Fact $fact) use ($exclude_types): bool {
return $exclude_types->isEmpty() || !$exclude_types->contains($fact->getTag());
});
}
|
php
|
public function pastableFacts(GedcomRecord $record, Collection $exclude_types): Collection
{
// The facts are stored in the session.
return (new Collection(Session::get('clipboard', [])[$record::RECORD_TYPE] ?? []))
// Put the most recently copied fact at the top of the list.
->reverse()
// Create facts for the record.
->map(static function (array $clipping) use ($record): Fact {
return new Fact($clipping['factrec'], $record, md5($clipping['factrec']));
})->filter(static function (Fact $fact) use ($exclude_types): bool {
return $exclude_types->isEmpty() || !$exclude_types->contains($fact->getTag());
});
}
|
[
"public",
"function",
"pastableFacts",
"(",
"GedcomRecord",
"$",
"record",
",",
"Collection",
"$",
"exclude_types",
")",
":",
"Collection",
"{",
"// The facts are stored in the session.",
"return",
"(",
"new",
"Collection",
"(",
"Session",
"::",
"get",
"(",
"'clipboard'",
",",
"[",
"]",
")",
"[",
"$",
"record",
"::",
"RECORD_TYPE",
"]",
"??",
"[",
"]",
")",
")",
"// Put the most recently copied fact at the top of the list.",
"->",
"reverse",
"(",
")",
"// Create facts for the record.",
"->",
"map",
"(",
"static",
"function",
"(",
"array",
"$",
"clipping",
")",
"use",
"(",
"$",
"record",
")",
":",
"Fact",
"{",
"return",
"new",
"Fact",
"(",
"$",
"clipping",
"[",
"'factrec'",
"]",
",",
"$",
"record",
",",
"md5",
"(",
"$",
"clipping",
"[",
"'factrec'",
"]",
")",
")",
";",
"}",
")",
"->",
"filter",
"(",
"static",
"function",
"(",
"Fact",
"$",
"fact",
")",
"use",
"(",
"$",
"exclude_types",
")",
":",
"bool",
"{",
"return",
"$",
"exclude_types",
"->",
"isEmpty",
"(",
")",
"||",
"!",
"$",
"exclude_types",
"->",
"contains",
"(",
"$",
"fact",
"->",
"getTag",
"(",
")",
")",
";",
"}",
")",
";",
"}"
] |
Create a list of facts that can be pasted into a given record
@param GedcomRecord $record
@param Collection $exclude_types
@return Collection
@return Fact[]
|
[
"Create",
"a",
"list",
"of",
"facts",
"that",
"can",
"be",
"pasted",
"into",
"a",
"given",
"record"
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Services/ClipboardService.php#L90-L102
|
train
|
fisharebest/webtrees
|
app/Services/ClipboardService.php
|
ClipboardService.pastableFactsOfType
|
public function pastableFactsOfType(GedcomRecord $record, Collection $types): Collection
{
// The facts are stored in the session.
return (new Collection(Session::get('clipboard', [])))
->flatten(1)
->reverse()
->map(static function (array $clipping) use ($record): Fact {
return new Fact($clipping['factrec'], $record, md5($clipping['factrec']));
})
->filter(static function (Fact $fact) use ($types): bool {
return $types->contains($fact->getTag());
});
}
|
php
|
public function pastableFactsOfType(GedcomRecord $record, Collection $types): Collection
{
// The facts are stored in the session.
return (new Collection(Session::get('clipboard', [])))
->flatten(1)
->reverse()
->map(static function (array $clipping) use ($record): Fact {
return new Fact($clipping['factrec'], $record, md5($clipping['factrec']));
})
->filter(static function (Fact $fact) use ($types): bool {
return $types->contains($fact->getTag());
});
}
|
[
"public",
"function",
"pastableFactsOfType",
"(",
"GedcomRecord",
"$",
"record",
",",
"Collection",
"$",
"types",
")",
":",
"Collection",
"{",
"// The facts are stored in the session.",
"return",
"(",
"new",
"Collection",
"(",
"Session",
"::",
"get",
"(",
"'clipboard'",
",",
"[",
"]",
")",
")",
")",
"->",
"flatten",
"(",
"1",
")",
"->",
"reverse",
"(",
")",
"->",
"map",
"(",
"static",
"function",
"(",
"array",
"$",
"clipping",
")",
"use",
"(",
"$",
"record",
")",
":",
"Fact",
"{",
"return",
"new",
"Fact",
"(",
"$",
"clipping",
"[",
"'factrec'",
"]",
",",
"$",
"record",
",",
"md5",
"(",
"$",
"clipping",
"[",
"'factrec'",
"]",
")",
")",
";",
"}",
")",
"->",
"filter",
"(",
"static",
"function",
"(",
"Fact",
"$",
"fact",
")",
"use",
"(",
"$",
"types",
")",
":",
"bool",
"{",
"return",
"$",
"types",
"->",
"contains",
"(",
"$",
"fact",
"->",
"getTag",
"(",
")",
")",
";",
"}",
")",
";",
"}"
] |
Find facts of a given type, from all records.
@param GedcomRecord $record
@param Collection $types
@return Collection
@return Fact[]
|
[
"Find",
"facts",
"of",
"a",
"given",
"type",
"from",
"all",
"records",
"."
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Services/ClipboardService.php#L113-L125
|
train
|
fisharebest/webtrees
|
app/Tree.php
|
Tree.getAll
|
public static function getAll(): array
{
if (empty(self::$trees)) {
self::$trees = self::all()->all();
}
return self::$trees;
}
|
php
|
public static function getAll(): array
{
if (empty(self::$trees)) {
self::$trees = self::all()->all();
}
return self::$trees;
}
|
[
"public",
"static",
"function",
"getAll",
"(",
")",
":",
"array",
"{",
"if",
"(",
"empty",
"(",
"self",
"::",
"$",
"trees",
")",
")",
"{",
"self",
"::",
"$",
"trees",
"=",
"self",
"::",
"all",
"(",
")",
"->",
"all",
"(",
")",
";",
"}",
"return",
"self",
"::",
"$",
"trees",
";",
"}"
] |
Fetch all the trees that we have permission to access.
@return Tree[]
|
[
"Fetch",
"all",
"the",
"trees",
"that",
"we",
"have",
"permission",
"to",
"access",
"."
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Tree.php#L118-L125
|
train
|
fisharebest/webtrees
|
app/Tree.php
|
Tree.all
|
public static function all(): Collection
{
return app('cache.array')->rememberForever(__CLASS__, static function (): Collection {
// Admins see all trees
$query = DB::table('gedcom')
->leftJoin('gedcom_setting', static function (JoinClause $join): void {
$join->on('gedcom_setting.gedcom_id', '=', 'gedcom.gedcom_id')
->where('gedcom_setting.setting_name', '=', 'title');
})
->where('gedcom.gedcom_id', '>', 0)
->select([
'gedcom.gedcom_id AS tree_id',
'gedcom.gedcom_name AS tree_name',
'gedcom_setting.setting_value AS tree_title',
])
->orderBy('gedcom.sort_order')
->orderBy('gedcom_setting.setting_value');
// Non-admins may not see all trees
if (!Auth::isAdmin()) {
$query
->join('gedcom_setting AS gs2', static function (JoinClause $join): void {
$join->on('gs2.gedcom_id', '=', 'gedcom.gedcom_id')
->where('gs2.setting_name', '=', 'imported');
})
->join('gedcom_setting AS gs3', static function (JoinClause $join): void {
$join->on('gs3.gedcom_id', '=', 'gedcom.gedcom_id')
->where('gs3.setting_name', '=', 'REQUIRE_AUTHENTICATION');
})
->leftJoin('user_gedcom_setting', static function (JoinClause $join): void {
$join->on('user_gedcom_setting.gedcom_id', '=', 'gedcom.gedcom_id')
->where('user_gedcom_setting.user_id', '=', Auth::id())
->where('user_gedcom_setting.setting_name', '=', 'canedit');
})
->where(static function (Builder $query): void {
$query
// Managers
->where('user_gedcom_setting.setting_value', '=', 'admin')
// Members
->orWhere(static function (Builder $query): void {
$query
->where('gs2.setting_value', '=', '1')
->where('gs3.setting_value', '=', '1')
->where('user_gedcom_setting.setting_value', '<>', 'none');
})
// Public trees
->orWhere(static function (Builder $query): void {
$query
->where('gs2.setting_value', '=', '1')
->where('gs3.setting_value', '<>', '1');
});
});
}
return $query
->get()
->mapWithKeys(static function (stdClass $row): array {
return [$row->tree_id => new self((int) $row->tree_id, $row->tree_name, $row->tree_title)];
});
});
}
|
php
|
public static function all(): Collection
{
return app('cache.array')->rememberForever(__CLASS__, static function (): Collection {
// Admins see all trees
$query = DB::table('gedcom')
->leftJoin('gedcom_setting', static function (JoinClause $join): void {
$join->on('gedcom_setting.gedcom_id', '=', 'gedcom.gedcom_id')
->where('gedcom_setting.setting_name', '=', 'title');
})
->where('gedcom.gedcom_id', '>', 0)
->select([
'gedcom.gedcom_id AS tree_id',
'gedcom.gedcom_name AS tree_name',
'gedcom_setting.setting_value AS tree_title',
])
->orderBy('gedcom.sort_order')
->orderBy('gedcom_setting.setting_value');
// Non-admins may not see all trees
if (!Auth::isAdmin()) {
$query
->join('gedcom_setting AS gs2', static function (JoinClause $join): void {
$join->on('gs2.gedcom_id', '=', 'gedcom.gedcom_id')
->where('gs2.setting_name', '=', 'imported');
})
->join('gedcom_setting AS gs3', static function (JoinClause $join): void {
$join->on('gs3.gedcom_id', '=', 'gedcom.gedcom_id')
->where('gs3.setting_name', '=', 'REQUIRE_AUTHENTICATION');
})
->leftJoin('user_gedcom_setting', static function (JoinClause $join): void {
$join->on('user_gedcom_setting.gedcom_id', '=', 'gedcom.gedcom_id')
->where('user_gedcom_setting.user_id', '=', Auth::id())
->where('user_gedcom_setting.setting_name', '=', 'canedit');
})
->where(static function (Builder $query): void {
$query
// Managers
->where('user_gedcom_setting.setting_value', '=', 'admin')
// Members
->orWhere(static function (Builder $query): void {
$query
->where('gs2.setting_value', '=', '1')
->where('gs3.setting_value', '=', '1')
->where('user_gedcom_setting.setting_value', '<>', 'none');
})
// Public trees
->orWhere(static function (Builder $query): void {
$query
->where('gs2.setting_value', '=', '1')
->where('gs3.setting_value', '<>', '1');
});
});
}
return $query
->get()
->mapWithKeys(static function (stdClass $row): array {
return [$row->tree_id => new self((int) $row->tree_id, $row->tree_name, $row->tree_title)];
});
});
}
|
[
"public",
"static",
"function",
"all",
"(",
")",
":",
"Collection",
"{",
"return",
"app",
"(",
"'cache.array'",
")",
"->",
"rememberForever",
"(",
"__CLASS__",
",",
"static",
"function",
"(",
")",
":",
"Collection",
"{",
"// Admins see all trees",
"$",
"query",
"=",
"DB",
"::",
"table",
"(",
"'gedcom'",
")",
"->",
"leftJoin",
"(",
"'gedcom_setting'",
",",
"static",
"function",
"(",
"JoinClause",
"$",
"join",
")",
":",
"void",
"{",
"$",
"join",
"->",
"on",
"(",
"'gedcom_setting.gedcom_id'",
",",
"'='",
",",
"'gedcom.gedcom_id'",
")",
"->",
"where",
"(",
"'gedcom_setting.setting_name'",
",",
"'='",
",",
"'title'",
")",
";",
"}",
")",
"->",
"where",
"(",
"'gedcom.gedcom_id'",
",",
"'>'",
",",
"0",
")",
"->",
"select",
"(",
"[",
"'gedcom.gedcom_id AS tree_id'",
",",
"'gedcom.gedcom_name AS tree_name'",
",",
"'gedcom_setting.setting_value AS tree_title'",
",",
"]",
")",
"->",
"orderBy",
"(",
"'gedcom.sort_order'",
")",
"->",
"orderBy",
"(",
"'gedcom_setting.setting_value'",
")",
";",
"// Non-admins may not see all trees",
"if",
"(",
"!",
"Auth",
"::",
"isAdmin",
"(",
")",
")",
"{",
"$",
"query",
"->",
"join",
"(",
"'gedcom_setting AS gs2'",
",",
"static",
"function",
"(",
"JoinClause",
"$",
"join",
")",
":",
"void",
"{",
"$",
"join",
"->",
"on",
"(",
"'gs2.gedcom_id'",
",",
"'='",
",",
"'gedcom.gedcom_id'",
")",
"->",
"where",
"(",
"'gs2.setting_name'",
",",
"'='",
",",
"'imported'",
")",
";",
"}",
")",
"->",
"join",
"(",
"'gedcom_setting AS gs3'",
",",
"static",
"function",
"(",
"JoinClause",
"$",
"join",
")",
":",
"void",
"{",
"$",
"join",
"->",
"on",
"(",
"'gs3.gedcom_id'",
",",
"'='",
",",
"'gedcom.gedcom_id'",
")",
"->",
"where",
"(",
"'gs3.setting_name'",
",",
"'='",
",",
"'REQUIRE_AUTHENTICATION'",
")",
";",
"}",
")",
"->",
"leftJoin",
"(",
"'user_gedcom_setting'",
",",
"static",
"function",
"(",
"JoinClause",
"$",
"join",
")",
":",
"void",
"{",
"$",
"join",
"->",
"on",
"(",
"'user_gedcom_setting.gedcom_id'",
",",
"'='",
",",
"'gedcom.gedcom_id'",
")",
"->",
"where",
"(",
"'user_gedcom_setting.user_id'",
",",
"'='",
",",
"Auth",
"::",
"id",
"(",
")",
")",
"->",
"where",
"(",
"'user_gedcom_setting.setting_name'",
",",
"'='",
",",
"'canedit'",
")",
";",
"}",
")",
"->",
"where",
"(",
"static",
"function",
"(",
"Builder",
"$",
"query",
")",
":",
"void",
"{",
"$",
"query",
"// Managers",
"->",
"where",
"(",
"'user_gedcom_setting.setting_value'",
",",
"'='",
",",
"'admin'",
")",
"// Members",
"->",
"orWhere",
"(",
"static",
"function",
"(",
"Builder",
"$",
"query",
")",
":",
"void",
"{",
"$",
"query",
"->",
"where",
"(",
"'gs2.setting_value'",
",",
"'='",
",",
"'1'",
")",
"->",
"where",
"(",
"'gs3.setting_value'",
",",
"'='",
",",
"'1'",
")",
"->",
"where",
"(",
"'user_gedcom_setting.setting_value'",
",",
"'<>'",
",",
"'none'",
")",
";",
"}",
")",
"// Public trees",
"->",
"orWhere",
"(",
"static",
"function",
"(",
"Builder",
"$",
"query",
")",
":",
"void",
"{",
"$",
"query",
"->",
"where",
"(",
"'gs2.setting_value'",
",",
"'='",
",",
"'1'",
")",
"->",
"where",
"(",
"'gs3.setting_value'",
",",
"'<>'",
",",
"'1'",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}",
"return",
"$",
"query",
"->",
"get",
"(",
")",
"->",
"mapWithKeys",
"(",
"static",
"function",
"(",
"stdClass",
"$",
"row",
")",
":",
"array",
"{",
"return",
"[",
"$",
"row",
"->",
"tree_id",
"=>",
"new",
"self",
"(",
"(",
"int",
")",
"$",
"row",
"->",
"tree_id",
",",
"$",
"row",
"->",
"tree_name",
",",
"$",
"row",
"->",
"tree_title",
")",
"]",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] |
All the trees that we have permission to access.
@return Collection
@return Tree[]
|
[
"All",
"the",
"trees",
"that",
"we",
"have",
"permission",
"to",
"access",
"."
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Tree.php#L133-L193
|
train
|
fisharebest/webtrees
|
app/Tree.php
|
Tree.create
|
public static function create(string $tree_name, string $tree_title): Tree
{
try {
// Create a new tree
DB::table('gedcom')->insert([
'gedcom_name' => $tree_name,
]);
$tree_id = (int) DB::connection()->getPdo()->lastInsertId();
$tree = new self($tree_id, $tree_name, $tree_title);
} catch (PDOException $ex) {
// A tree with that name already exists?
return self::findByName($tree_name);
}
$tree->setPreference('imported', '0');
$tree->setPreference('title', $tree_title);
// Set preferences from default tree
(new Builder(DB::connection()))->from('gedcom_setting')->insertUsing(
['gedcom_id', 'setting_name', 'setting_value'],
static function (Builder $query) use ($tree_id): void {
$query
->select([DB::raw($tree_id), 'setting_name', 'setting_value'])
->from('gedcom_setting')
->where('gedcom_id', '=', -1);
}
);
(new Builder(DB::connection()))->from('default_resn')->insertUsing(
['gedcom_id', 'tag_type', 'resn'],
static function (Builder $query) use ($tree_id): void {
$query
->select([DB::raw($tree_id), 'tag_type', 'resn'])
->from('default_resn')
->where('gedcom_id', '=', -1);
}
);
// Gedcom and privacy settings
$tree->setPreference('CONTACT_USER_ID', (string) Auth::id());
$tree->setPreference('WEBMASTER_USER_ID', (string) Auth::id());
$tree->setPreference('LANGUAGE', WT_LOCALE); // Default to the current admin’s language
switch (WT_LOCALE) {
case 'es':
$tree->setPreference('SURNAME_TRADITION', 'spanish');
break;
case 'is':
$tree->setPreference('SURNAME_TRADITION', 'icelandic');
break;
case 'lt':
$tree->setPreference('SURNAME_TRADITION', 'lithuanian');
break;
case 'pl':
$tree->setPreference('SURNAME_TRADITION', 'polish');
break;
case 'pt':
case 'pt-BR':
$tree->setPreference('SURNAME_TRADITION', 'portuguese');
break;
default:
$tree->setPreference('SURNAME_TRADITION', 'paternal');
break;
}
// Genealogy data
// It is simpler to create a temporary/unimported GEDCOM than to populate all the tables...
/* I18N: This should be a common/default/placeholder name of an individual. Put slashes around the surname. */
$john_doe = I18N::translate('John /DOE/');
$note = I18N::translate('Edit this individual and replace their details with your own.');
$gedcom = "0 HEAD\n1 CHAR UTF-8\n0 @X1@ INDI\n1 NAME {$john_doe}\n1 SEX M\n1 BIRT\n2 DATE 01 JAN 1850\n2 NOTE {$note}\n0 TRLR\n";
DB::table('gedcom_chunk')->insert([
'gedcom_id' => $tree_id,
'chunk_data' => $gedcom,
]);
// Update our cache
self::$trees[$tree->id] = $tree;
return $tree;
}
|
php
|
public static function create(string $tree_name, string $tree_title): Tree
{
try {
// Create a new tree
DB::table('gedcom')->insert([
'gedcom_name' => $tree_name,
]);
$tree_id = (int) DB::connection()->getPdo()->lastInsertId();
$tree = new self($tree_id, $tree_name, $tree_title);
} catch (PDOException $ex) {
// A tree with that name already exists?
return self::findByName($tree_name);
}
$tree->setPreference('imported', '0');
$tree->setPreference('title', $tree_title);
// Set preferences from default tree
(new Builder(DB::connection()))->from('gedcom_setting')->insertUsing(
['gedcom_id', 'setting_name', 'setting_value'],
static function (Builder $query) use ($tree_id): void {
$query
->select([DB::raw($tree_id), 'setting_name', 'setting_value'])
->from('gedcom_setting')
->where('gedcom_id', '=', -1);
}
);
(new Builder(DB::connection()))->from('default_resn')->insertUsing(
['gedcom_id', 'tag_type', 'resn'],
static function (Builder $query) use ($tree_id): void {
$query
->select([DB::raw($tree_id), 'tag_type', 'resn'])
->from('default_resn')
->where('gedcom_id', '=', -1);
}
);
// Gedcom and privacy settings
$tree->setPreference('CONTACT_USER_ID', (string) Auth::id());
$tree->setPreference('WEBMASTER_USER_ID', (string) Auth::id());
$tree->setPreference('LANGUAGE', WT_LOCALE); // Default to the current admin’s language
switch (WT_LOCALE) {
case 'es':
$tree->setPreference('SURNAME_TRADITION', 'spanish');
break;
case 'is':
$tree->setPreference('SURNAME_TRADITION', 'icelandic');
break;
case 'lt':
$tree->setPreference('SURNAME_TRADITION', 'lithuanian');
break;
case 'pl':
$tree->setPreference('SURNAME_TRADITION', 'polish');
break;
case 'pt':
case 'pt-BR':
$tree->setPreference('SURNAME_TRADITION', 'portuguese');
break;
default:
$tree->setPreference('SURNAME_TRADITION', 'paternal');
break;
}
// Genealogy data
// It is simpler to create a temporary/unimported GEDCOM than to populate all the tables...
/* I18N: This should be a common/default/placeholder name of an individual. Put slashes around the surname. */
$john_doe = I18N::translate('John /DOE/');
$note = I18N::translate('Edit this individual and replace their details with your own.');
$gedcom = "0 HEAD\n1 CHAR UTF-8\n0 @X1@ INDI\n1 NAME {$john_doe}\n1 SEX M\n1 BIRT\n2 DATE 01 JAN 1850\n2 NOTE {$note}\n0 TRLR\n";
DB::table('gedcom_chunk')->insert([
'gedcom_id' => $tree_id,
'chunk_data' => $gedcom,
]);
// Update our cache
self::$trees[$tree->id] = $tree;
return $tree;
}
|
[
"public",
"static",
"function",
"create",
"(",
"string",
"$",
"tree_name",
",",
"string",
"$",
"tree_title",
")",
":",
"Tree",
"{",
"try",
"{",
"// Create a new tree",
"DB",
"::",
"table",
"(",
"'gedcom'",
")",
"->",
"insert",
"(",
"[",
"'gedcom_name'",
"=>",
"$",
"tree_name",
",",
"]",
")",
";",
"$",
"tree_id",
"=",
"(",
"int",
")",
"DB",
"::",
"connection",
"(",
")",
"->",
"getPdo",
"(",
")",
"->",
"lastInsertId",
"(",
")",
";",
"$",
"tree",
"=",
"new",
"self",
"(",
"$",
"tree_id",
",",
"$",
"tree_name",
",",
"$",
"tree_title",
")",
";",
"}",
"catch",
"(",
"PDOException",
"$",
"ex",
")",
"{",
"// A tree with that name already exists?",
"return",
"self",
"::",
"findByName",
"(",
"$",
"tree_name",
")",
";",
"}",
"$",
"tree",
"->",
"setPreference",
"(",
"'imported'",
",",
"'0'",
")",
";",
"$",
"tree",
"->",
"setPreference",
"(",
"'title'",
",",
"$",
"tree_title",
")",
";",
"// Set preferences from default tree",
"(",
"new",
"Builder",
"(",
"DB",
"::",
"connection",
"(",
")",
")",
")",
"->",
"from",
"(",
"'gedcom_setting'",
")",
"->",
"insertUsing",
"(",
"[",
"'gedcom_id'",
",",
"'setting_name'",
",",
"'setting_value'",
"]",
",",
"static",
"function",
"(",
"Builder",
"$",
"query",
")",
"use",
"(",
"$",
"tree_id",
")",
":",
"void",
"{",
"$",
"query",
"->",
"select",
"(",
"[",
"DB",
"::",
"raw",
"(",
"$",
"tree_id",
")",
",",
"'setting_name'",
",",
"'setting_value'",
"]",
")",
"->",
"from",
"(",
"'gedcom_setting'",
")",
"->",
"where",
"(",
"'gedcom_id'",
",",
"'='",
",",
"-",
"1",
")",
";",
"}",
")",
";",
"(",
"new",
"Builder",
"(",
"DB",
"::",
"connection",
"(",
")",
")",
")",
"->",
"from",
"(",
"'default_resn'",
")",
"->",
"insertUsing",
"(",
"[",
"'gedcom_id'",
",",
"'tag_type'",
",",
"'resn'",
"]",
",",
"static",
"function",
"(",
"Builder",
"$",
"query",
")",
"use",
"(",
"$",
"tree_id",
")",
":",
"void",
"{",
"$",
"query",
"->",
"select",
"(",
"[",
"DB",
"::",
"raw",
"(",
"$",
"tree_id",
")",
",",
"'tag_type'",
",",
"'resn'",
"]",
")",
"->",
"from",
"(",
"'default_resn'",
")",
"->",
"where",
"(",
"'gedcom_id'",
",",
"'='",
",",
"-",
"1",
")",
";",
"}",
")",
";",
"// Gedcom and privacy settings",
"$",
"tree",
"->",
"setPreference",
"(",
"'CONTACT_USER_ID'",
",",
"(",
"string",
")",
"Auth",
"::",
"id",
"(",
")",
")",
";",
"$",
"tree",
"->",
"setPreference",
"(",
"'WEBMASTER_USER_ID'",
",",
"(",
"string",
")",
"Auth",
"::",
"id",
"(",
")",
")",
";",
"$",
"tree",
"->",
"setPreference",
"(",
"'LANGUAGE'",
",",
"WT_LOCALE",
")",
";",
"// Default to the current admin’s language",
"switch",
"(",
"WT_LOCALE",
")",
"{",
"case",
"'es'",
":",
"$",
"tree",
"->",
"setPreference",
"(",
"'SURNAME_TRADITION'",
",",
"'spanish'",
")",
";",
"break",
";",
"case",
"'is'",
":",
"$",
"tree",
"->",
"setPreference",
"(",
"'SURNAME_TRADITION'",
",",
"'icelandic'",
")",
";",
"break",
";",
"case",
"'lt'",
":",
"$",
"tree",
"->",
"setPreference",
"(",
"'SURNAME_TRADITION'",
",",
"'lithuanian'",
")",
";",
"break",
";",
"case",
"'pl'",
":",
"$",
"tree",
"->",
"setPreference",
"(",
"'SURNAME_TRADITION'",
",",
"'polish'",
")",
";",
"break",
";",
"case",
"'pt'",
":",
"case",
"'pt-BR'",
":",
"$",
"tree",
"->",
"setPreference",
"(",
"'SURNAME_TRADITION'",
",",
"'portuguese'",
")",
";",
"break",
";",
"default",
":",
"$",
"tree",
"->",
"setPreference",
"(",
"'SURNAME_TRADITION'",
",",
"'paternal'",
")",
";",
"break",
";",
"}",
"// Genealogy data",
"// It is simpler to create a temporary/unimported GEDCOM than to populate all the tables...",
"/* I18N: This should be a common/default/placeholder name of an individual. Put slashes around the surname. */",
"$",
"john_doe",
"=",
"I18N",
"::",
"translate",
"(",
"'John /DOE/'",
")",
";",
"$",
"note",
"=",
"I18N",
"::",
"translate",
"(",
"'Edit this individual and replace their details with your own.'",
")",
";",
"$",
"gedcom",
"=",
"\"0 HEAD\\n1 CHAR UTF-8\\n0 @X1@ INDI\\n1 NAME {$john_doe}\\n1 SEX M\\n1 BIRT\\n2 DATE 01 JAN 1850\\n2 NOTE {$note}\\n0 TRLR\\n\"",
";",
"DB",
"::",
"table",
"(",
"'gedcom_chunk'",
")",
"->",
"insert",
"(",
"[",
"'gedcom_id'",
"=>",
"$",
"tree_id",
",",
"'chunk_data'",
"=>",
"$",
"gedcom",
",",
"]",
")",
";",
"// Update our cache",
"self",
"::",
"$",
"trees",
"[",
"$",
"tree",
"->",
"id",
"]",
"=",
"$",
"tree",
";",
"return",
"$",
"tree",
";",
"}"
] |
Create a new tree
@param string $tree_name
@param string $tree_title
@return Tree
|
[
"Create",
"a",
"new",
"tree"
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Tree.php#L235-L318
|
train
|
fisharebest/webtrees
|
app/Tree.php
|
Tree.findByName
|
public static function findByName($tree_name): ?Tree
{
foreach (self::getAll() as $tree) {
if ($tree->name === $tree_name) {
return $tree;
}
}
return null;
}
|
php
|
public static function findByName($tree_name): ?Tree
{
foreach (self::getAll() as $tree) {
if ($tree->name === $tree_name) {
return $tree;
}
}
return null;
}
|
[
"public",
"static",
"function",
"findByName",
"(",
"$",
"tree_name",
")",
":",
"?",
"Tree",
"{",
"foreach",
"(",
"self",
"::",
"getAll",
"(",
")",
"as",
"$",
"tree",
")",
"{",
"if",
"(",
"$",
"tree",
"->",
"name",
"===",
"$",
"tree_name",
")",
"{",
"return",
"$",
"tree",
";",
"}",
"}",
"return",
"null",
";",
"}"
] |
Find the tree with a specific name.
@param string $tree_name
@return Tree|null
|
[
"Find",
"the",
"tree",
"with",
"a",
"specific",
"name",
"."
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Tree.php#L327-L336
|
train
|
fisharebest/webtrees
|
app/Tree.php
|
Tree.delete
|
public function delete(): void
{
// If this is the default tree, then unset it
if (Site::getPreference('DEFAULT_GEDCOM') === $this->name) {
Site::setPreference('DEFAULT_GEDCOM', '');
}
$this->deleteGenealogyData(false);
DB::table('block_setting')
->join('block', 'block.block_id', '=', 'block_setting.block_id')
->where('gedcom_id', '=', $this->id)
->delete();
DB::table('block')->where('gedcom_id', '=', $this->id)->delete();
DB::table('user_gedcom_setting')->where('gedcom_id', '=', $this->id)->delete();
DB::table('gedcom_setting')->where('gedcom_id', '=', $this->id)->delete();
DB::table('module_privacy')->where('gedcom_id', '=', $this->id)->delete();
DB::table('hit_counter')->where('gedcom_id', '=', $this->id)->delete();
DB::table('default_resn')->where('gedcom_id', '=', $this->id)->delete();
DB::table('gedcom_chunk')->where('gedcom_id', '=', $this->id)->delete();
DB::table('log')->where('gedcom_id', '=', $this->id)->delete();
DB::table('gedcom')->where('gedcom_id', '=', $this->id)->delete();
// After updating the database, we need to fetch a new (sorted) copy
self::$trees = [];
}
|
php
|
public function delete(): void
{
// If this is the default tree, then unset it
if (Site::getPreference('DEFAULT_GEDCOM') === $this->name) {
Site::setPreference('DEFAULT_GEDCOM', '');
}
$this->deleteGenealogyData(false);
DB::table('block_setting')
->join('block', 'block.block_id', '=', 'block_setting.block_id')
->where('gedcom_id', '=', $this->id)
->delete();
DB::table('block')->where('gedcom_id', '=', $this->id)->delete();
DB::table('user_gedcom_setting')->where('gedcom_id', '=', $this->id)->delete();
DB::table('gedcom_setting')->where('gedcom_id', '=', $this->id)->delete();
DB::table('module_privacy')->where('gedcom_id', '=', $this->id)->delete();
DB::table('hit_counter')->where('gedcom_id', '=', $this->id)->delete();
DB::table('default_resn')->where('gedcom_id', '=', $this->id)->delete();
DB::table('gedcom_chunk')->where('gedcom_id', '=', $this->id)->delete();
DB::table('log')->where('gedcom_id', '=', $this->id)->delete();
DB::table('gedcom')->where('gedcom_id', '=', $this->id)->delete();
// After updating the database, we need to fetch a new (sorted) copy
self::$trees = [];
}
|
[
"public",
"function",
"delete",
"(",
")",
":",
"void",
"{",
"// If this is the default tree, then unset it",
"if",
"(",
"Site",
"::",
"getPreference",
"(",
"'DEFAULT_GEDCOM'",
")",
"===",
"$",
"this",
"->",
"name",
")",
"{",
"Site",
"::",
"setPreference",
"(",
"'DEFAULT_GEDCOM'",
",",
"''",
")",
";",
"}",
"$",
"this",
"->",
"deleteGenealogyData",
"(",
"false",
")",
";",
"DB",
"::",
"table",
"(",
"'block_setting'",
")",
"->",
"join",
"(",
"'block'",
",",
"'block.block_id'",
",",
"'='",
",",
"'block_setting.block_id'",
")",
"->",
"where",
"(",
"'gedcom_id'",
",",
"'='",
",",
"$",
"this",
"->",
"id",
")",
"->",
"delete",
"(",
")",
";",
"DB",
"::",
"table",
"(",
"'block'",
")",
"->",
"where",
"(",
"'gedcom_id'",
",",
"'='",
",",
"$",
"this",
"->",
"id",
")",
"->",
"delete",
"(",
")",
";",
"DB",
"::",
"table",
"(",
"'user_gedcom_setting'",
")",
"->",
"where",
"(",
"'gedcom_id'",
",",
"'='",
",",
"$",
"this",
"->",
"id",
")",
"->",
"delete",
"(",
")",
";",
"DB",
"::",
"table",
"(",
"'gedcom_setting'",
")",
"->",
"where",
"(",
"'gedcom_id'",
",",
"'='",
",",
"$",
"this",
"->",
"id",
")",
"->",
"delete",
"(",
")",
";",
"DB",
"::",
"table",
"(",
"'module_privacy'",
")",
"->",
"where",
"(",
"'gedcom_id'",
",",
"'='",
",",
"$",
"this",
"->",
"id",
")",
"->",
"delete",
"(",
")",
";",
"DB",
"::",
"table",
"(",
"'hit_counter'",
")",
"->",
"where",
"(",
"'gedcom_id'",
",",
"'='",
",",
"$",
"this",
"->",
"id",
")",
"->",
"delete",
"(",
")",
";",
"DB",
"::",
"table",
"(",
"'default_resn'",
")",
"->",
"where",
"(",
"'gedcom_id'",
",",
"'='",
",",
"$",
"this",
"->",
"id",
")",
"->",
"delete",
"(",
")",
";",
"DB",
"::",
"table",
"(",
"'gedcom_chunk'",
")",
"->",
"where",
"(",
"'gedcom_id'",
",",
"'='",
",",
"$",
"this",
"->",
"id",
")",
"->",
"delete",
"(",
")",
";",
"DB",
"::",
"table",
"(",
"'log'",
")",
"->",
"where",
"(",
"'gedcom_id'",
",",
"'='",
",",
"$",
"this",
"->",
"id",
")",
"->",
"delete",
"(",
")",
";",
"DB",
"::",
"table",
"(",
"'gedcom'",
")",
"->",
"where",
"(",
"'gedcom_id'",
",",
"'='",
",",
"$",
"this",
"->",
"id",
")",
"->",
"delete",
"(",
")",
";",
"// After updating the database, we need to fetch a new (sorted) copy",
"self",
"::",
"$",
"trees",
"=",
"[",
"]",
";",
"}"
] |
Delete everything relating to a tree
@return void
|
[
"Delete",
"everything",
"relating",
"to",
"a",
"tree"
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Tree.php#L528-L553
|
train
|
fisharebest/webtrees
|
app/Tree.php
|
Tree.exportGedcom
|
public function exportGedcom($stream): void
{
$buffer = FunctionsExport::reformatRecord(FunctionsExport::gedcomHeader($this, 'UTF-8'));
$union_families = DB::table('families')
->where('f_file', '=', $this->id)
->select(['f_gedcom AS gedcom', 'f_id AS xref', DB::raw('LENGTH(f_id) AS len'), DB::raw('2 AS n')]);
$union_sources = DB::table('sources')
->where('s_file', '=', $this->id)
->select(['s_gedcom AS gedcom', 's_id AS xref', DB::raw('LENGTH(s_id) AS len'), DB::raw('3 AS n')]);
$union_other = DB::table('other')
->where('o_file', '=', $this->id)
->whereNotIn('o_type', ['HEAD', 'TRLR'])
->select(['o_gedcom AS gedcom', 'o_id AS xref', DB::raw('LENGTH(o_id) AS len'), DB::raw('4 AS n')]);
$union_media = DB::table('media')
->where('m_file', '=', $this->id)
->select(['m_gedcom AS gedcom', 'm_id AS xref', DB::raw('LENGTH(m_id) AS len'), DB::raw('5 AS n')]);
DB::table('individuals')
->where('i_file', '=', $this->id)
->select(['i_gedcom AS gedcom', 'i_id AS xref', DB::raw('LENGTH(i_id) AS len'), DB::raw('1 AS n')])
->union($union_families)
->union($union_sources)
->union($union_other)
->union($union_media)
->orderBy('n')
->orderBy('len')
->orderBy('xref')
->chunk(100, static function (Collection $rows) use ($stream, &$buffer): void {
foreach ($rows as $row) {
$buffer .= FunctionsExport::reformatRecord($row->gedcom);
if (strlen($buffer) > 65535) {
fwrite($stream, $buffer);
$buffer = '';
}
}
});
fwrite($stream, $buffer . '0 TRLR' . Gedcom::EOL);
}
|
php
|
public function exportGedcom($stream): void
{
$buffer = FunctionsExport::reformatRecord(FunctionsExport::gedcomHeader($this, 'UTF-8'));
$union_families = DB::table('families')
->where('f_file', '=', $this->id)
->select(['f_gedcom AS gedcom', 'f_id AS xref', DB::raw('LENGTH(f_id) AS len'), DB::raw('2 AS n')]);
$union_sources = DB::table('sources')
->where('s_file', '=', $this->id)
->select(['s_gedcom AS gedcom', 's_id AS xref', DB::raw('LENGTH(s_id) AS len'), DB::raw('3 AS n')]);
$union_other = DB::table('other')
->where('o_file', '=', $this->id)
->whereNotIn('o_type', ['HEAD', 'TRLR'])
->select(['o_gedcom AS gedcom', 'o_id AS xref', DB::raw('LENGTH(o_id) AS len'), DB::raw('4 AS n')]);
$union_media = DB::table('media')
->where('m_file', '=', $this->id)
->select(['m_gedcom AS gedcom', 'm_id AS xref', DB::raw('LENGTH(m_id) AS len'), DB::raw('5 AS n')]);
DB::table('individuals')
->where('i_file', '=', $this->id)
->select(['i_gedcom AS gedcom', 'i_id AS xref', DB::raw('LENGTH(i_id) AS len'), DB::raw('1 AS n')])
->union($union_families)
->union($union_sources)
->union($union_other)
->union($union_media)
->orderBy('n')
->orderBy('len')
->orderBy('xref')
->chunk(100, static function (Collection $rows) use ($stream, &$buffer): void {
foreach ($rows as $row) {
$buffer .= FunctionsExport::reformatRecord($row->gedcom);
if (strlen($buffer) > 65535) {
fwrite($stream, $buffer);
$buffer = '';
}
}
});
fwrite($stream, $buffer . '0 TRLR' . Gedcom::EOL);
}
|
[
"public",
"function",
"exportGedcom",
"(",
"$",
"stream",
")",
":",
"void",
"{",
"$",
"buffer",
"=",
"FunctionsExport",
"::",
"reformatRecord",
"(",
"FunctionsExport",
"::",
"gedcomHeader",
"(",
"$",
"this",
",",
"'UTF-8'",
")",
")",
";",
"$",
"union_families",
"=",
"DB",
"::",
"table",
"(",
"'families'",
")",
"->",
"where",
"(",
"'f_file'",
",",
"'='",
",",
"$",
"this",
"->",
"id",
")",
"->",
"select",
"(",
"[",
"'f_gedcom AS gedcom'",
",",
"'f_id AS xref'",
",",
"DB",
"::",
"raw",
"(",
"'LENGTH(f_id) AS len'",
")",
",",
"DB",
"::",
"raw",
"(",
"'2 AS n'",
")",
"]",
")",
";",
"$",
"union_sources",
"=",
"DB",
"::",
"table",
"(",
"'sources'",
")",
"->",
"where",
"(",
"'s_file'",
",",
"'='",
",",
"$",
"this",
"->",
"id",
")",
"->",
"select",
"(",
"[",
"'s_gedcom AS gedcom'",
",",
"'s_id AS xref'",
",",
"DB",
"::",
"raw",
"(",
"'LENGTH(s_id) AS len'",
")",
",",
"DB",
"::",
"raw",
"(",
"'3 AS n'",
")",
"]",
")",
";",
"$",
"union_other",
"=",
"DB",
"::",
"table",
"(",
"'other'",
")",
"->",
"where",
"(",
"'o_file'",
",",
"'='",
",",
"$",
"this",
"->",
"id",
")",
"->",
"whereNotIn",
"(",
"'o_type'",
",",
"[",
"'HEAD'",
",",
"'TRLR'",
"]",
")",
"->",
"select",
"(",
"[",
"'o_gedcom AS gedcom'",
",",
"'o_id AS xref'",
",",
"DB",
"::",
"raw",
"(",
"'LENGTH(o_id) AS len'",
")",
",",
"DB",
"::",
"raw",
"(",
"'4 AS n'",
")",
"]",
")",
";",
"$",
"union_media",
"=",
"DB",
"::",
"table",
"(",
"'media'",
")",
"->",
"where",
"(",
"'m_file'",
",",
"'='",
",",
"$",
"this",
"->",
"id",
")",
"->",
"select",
"(",
"[",
"'m_gedcom AS gedcom'",
",",
"'m_id AS xref'",
",",
"DB",
"::",
"raw",
"(",
"'LENGTH(m_id) AS len'",
")",
",",
"DB",
"::",
"raw",
"(",
"'5 AS n'",
")",
"]",
")",
";",
"DB",
"::",
"table",
"(",
"'individuals'",
")",
"->",
"where",
"(",
"'i_file'",
",",
"'='",
",",
"$",
"this",
"->",
"id",
")",
"->",
"select",
"(",
"[",
"'i_gedcom AS gedcom'",
",",
"'i_id AS xref'",
",",
"DB",
"::",
"raw",
"(",
"'LENGTH(i_id) AS len'",
")",
",",
"DB",
"::",
"raw",
"(",
"'1 AS n'",
")",
"]",
")",
"->",
"union",
"(",
"$",
"union_families",
")",
"->",
"union",
"(",
"$",
"union_sources",
")",
"->",
"union",
"(",
"$",
"union_other",
")",
"->",
"union",
"(",
"$",
"union_media",
")",
"->",
"orderBy",
"(",
"'n'",
")",
"->",
"orderBy",
"(",
"'len'",
")",
"->",
"orderBy",
"(",
"'xref'",
")",
"->",
"chunk",
"(",
"100",
",",
"static",
"function",
"(",
"Collection",
"$",
"rows",
")",
"use",
"(",
"$",
"stream",
",",
"&",
"$",
"buffer",
")",
":",
"void",
"{",
"foreach",
"(",
"$",
"rows",
"as",
"$",
"row",
")",
"{",
"$",
"buffer",
".=",
"FunctionsExport",
"::",
"reformatRecord",
"(",
"$",
"row",
"->",
"gedcom",
")",
";",
"if",
"(",
"strlen",
"(",
"$",
"buffer",
")",
">",
"65535",
")",
"{",
"fwrite",
"(",
"$",
"stream",
",",
"$",
"buffer",
")",
";",
"$",
"buffer",
"=",
"''",
";",
"}",
"}",
"}",
")",
";",
"fwrite",
"(",
"$",
"stream",
",",
"$",
"buffer",
".",
"'0 TRLR'",
".",
"Gedcom",
"::",
"EOL",
")",
";",
"}"
] |
Export the tree to a GEDCOM file
@param resource $stream
@return void
|
[
"Export",
"the",
"tree",
"to",
"a",
"GEDCOM",
"file"
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Tree.php#L596-L638
|
train
|
fisharebest/webtrees
|
app/Tree.php
|
Tree.importGedcomFile
|
public function importGedcomFile(StreamInterface $stream, string $filename): void
{
// Read the file in blocks of roughly 64K. Ensure that each block
// contains complete gedcom records. This will ensure we don’t split
// multi-byte characters, as well as simplifying the code to import
// each block.
$file_data = '';
$this->deleteGenealogyData((bool) $this->getPreference('keep_media'));
$this->setPreference('gedcom_filename', $filename);
$this->setPreference('imported', '0');
while (!$stream->eof()) {
$file_data .= $stream->read(65536);
// There is no strrpos() function that searches for substrings :-(
for ($pos = strlen($file_data) - 1; $pos > 0; --$pos) {
if ($file_data[$pos] === '0' && ($file_data[$pos - 1] === "\n" || $file_data[$pos - 1] === "\r")) {
// We’ve found the last record boundary in this chunk of data
break;
}
}
if ($pos) {
DB::table('gedcom_chunk')->insert([
'gedcom_id' => $this->id,
'chunk_data' => substr($file_data, 0, $pos),
]);
$file_data = substr($file_data, $pos);
}
}
DB::table('gedcom_chunk')->insert([
'gedcom_id' => $this->id,
'chunk_data' => $file_data,
]);
$stream->close();
}
|
php
|
public function importGedcomFile(StreamInterface $stream, string $filename): void
{
// Read the file in blocks of roughly 64K. Ensure that each block
// contains complete gedcom records. This will ensure we don’t split
// multi-byte characters, as well as simplifying the code to import
// each block.
$file_data = '';
$this->deleteGenealogyData((bool) $this->getPreference('keep_media'));
$this->setPreference('gedcom_filename', $filename);
$this->setPreference('imported', '0');
while (!$stream->eof()) {
$file_data .= $stream->read(65536);
// There is no strrpos() function that searches for substrings :-(
for ($pos = strlen($file_data) - 1; $pos > 0; --$pos) {
if ($file_data[$pos] === '0' && ($file_data[$pos - 1] === "\n" || $file_data[$pos - 1] === "\r")) {
// We’ve found the last record boundary in this chunk of data
break;
}
}
if ($pos) {
DB::table('gedcom_chunk')->insert([
'gedcom_id' => $this->id,
'chunk_data' => substr($file_data, 0, $pos),
]);
$file_data = substr($file_data, $pos);
}
}
DB::table('gedcom_chunk')->insert([
'gedcom_id' => $this->id,
'chunk_data' => $file_data,
]);
$stream->close();
}
|
[
"public",
"function",
"importGedcomFile",
"(",
"StreamInterface",
"$",
"stream",
",",
"string",
"$",
"filename",
")",
":",
"void",
"{",
"// Read the file in blocks of roughly 64K. Ensure that each block",
"// contains complete gedcom records. This will ensure we don’t split",
"// multi-byte characters, as well as simplifying the code to import",
"// each block.",
"$",
"file_data",
"=",
"''",
";",
"$",
"this",
"->",
"deleteGenealogyData",
"(",
"(",
"bool",
")",
"$",
"this",
"->",
"getPreference",
"(",
"'keep_media'",
")",
")",
";",
"$",
"this",
"->",
"setPreference",
"(",
"'gedcom_filename'",
",",
"$",
"filename",
")",
";",
"$",
"this",
"->",
"setPreference",
"(",
"'imported'",
",",
"'0'",
")",
";",
"while",
"(",
"!",
"$",
"stream",
"->",
"eof",
"(",
")",
")",
"{",
"$",
"file_data",
".=",
"$",
"stream",
"->",
"read",
"(",
"65536",
")",
";",
"// There is no strrpos() function that searches for substrings :-(",
"for",
"(",
"$",
"pos",
"=",
"strlen",
"(",
"$",
"file_data",
")",
"-",
"1",
";",
"$",
"pos",
">",
"0",
";",
"--",
"$",
"pos",
")",
"{",
"if",
"(",
"$",
"file_data",
"[",
"$",
"pos",
"]",
"===",
"'0'",
"&&",
"(",
"$",
"file_data",
"[",
"$",
"pos",
"-",
"1",
"]",
"===",
"\"\\n\"",
"||",
"$",
"file_data",
"[",
"$",
"pos",
"-",
"1",
"]",
"===",
"\"\\r\"",
")",
")",
"{",
"// We’ve found the last record boundary in this chunk of data",
"break",
";",
"}",
"}",
"if",
"(",
"$",
"pos",
")",
"{",
"DB",
"::",
"table",
"(",
"'gedcom_chunk'",
")",
"->",
"insert",
"(",
"[",
"'gedcom_id'",
"=>",
"$",
"this",
"->",
"id",
",",
"'chunk_data'",
"=>",
"substr",
"(",
"$",
"file_data",
",",
"0",
",",
"$",
"pos",
")",
",",
"]",
")",
";",
"$",
"file_data",
"=",
"substr",
"(",
"$",
"file_data",
",",
"$",
"pos",
")",
";",
"}",
"}",
"DB",
"::",
"table",
"(",
"'gedcom_chunk'",
")",
"->",
"insert",
"(",
"[",
"'gedcom_id'",
"=>",
"$",
"this",
"->",
"id",
",",
"'chunk_data'",
"=>",
"$",
"file_data",
",",
"]",
")",
";",
"$",
"stream",
"->",
"close",
"(",
")",
";",
"}"
] |
Import data from a gedcom file into this tree.
@param StreamInterface $stream The GEDCOM file.
@param string $filename The preferred filename, for export/download.
@return void
|
[
"Import",
"data",
"from",
"a",
"gedcom",
"file",
"into",
"this",
"tree",
"."
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Tree.php#L648-L685
|
train
|
fisharebest/webtrees
|
app/Tree.php
|
Tree.createRecord
|
public function createRecord(string $gedcom): GedcomRecord
{
if (!Str::startsWith($gedcom, '0 @@ ')) {
throw new InvalidArgumentException('GedcomRecord::createRecord(' . $gedcom . ') does not begin 0 @@');
}
$xref = $this->getNewXref();
$gedcom = '0 @' . $xref . '@ ' . Str::after($gedcom, '0 @@ ');
// Create a change record
$gedcom .= "\n1 CHAN\n2 DATE " . date('d M Y') . "\n3 TIME " . date('H:i:s') . "\n2 _WT_USER " . Auth::user()->userName();
// Create a pending change
DB::table('change')->insert([
'gedcom_id' => $this->id,
'xref' => $xref,
'old_gedcom' => '',
'new_gedcom' => $gedcom,
'user_id' => Auth::id(),
]);
// Accept this pending change
if (Auth::user()->getPreference('auto_accept')) {
FunctionsImport::acceptAllChanges($xref, $this);
return new GedcomRecord($xref, $gedcom, null, $this);
}
return GedcomRecord::getInstance($xref, $this, $gedcom);
}
|
php
|
public function createRecord(string $gedcom): GedcomRecord
{
if (!Str::startsWith($gedcom, '0 @@ ')) {
throw new InvalidArgumentException('GedcomRecord::createRecord(' . $gedcom . ') does not begin 0 @@');
}
$xref = $this->getNewXref();
$gedcom = '0 @' . $xref . '@ ' . Str::after($gedcom, '0 @@ ');
// Create a change record
$gedcom .= "\n1 CHAN\n2 DATE " . date('d M Y') . "\n3 TIME " . date('H:i:s') . "\n2 _WT_USER " . Auth::user()->userName();
// Create a pending change
DB::table('change')->insert([
'gedcom_id' => $this->id,
'xref' => $xref,
'old_gedcom' => '',
'new_gedcom' => $gedcom,
'user_id' => Auth::id(),
]);
// Accept this pending change
if (Auth::user()->getPreference('auto_accept')) {
FunctionsImport::acceptAllChanges($xref, $this);
return new GedcomRecord($xref, $gedcom, null, $this);
}
return GedcomRecord::getInstance($xref, $this, $gedcom);
}
|
[
"public",
"function",
"createRecord",
"(",
"string",
"$",
"gedcom",
")",
":",
"GedcomRecord",
"{",
"if",
"(",
"!",
"Str",
"::",
"startsWith",
"(",
"$",
"gedcom",
",",
"'0 @@ '",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'GedcomRecord::createRecord('",
".",
"$",
"gedcom",
".",
"') does not begin 0 @@'",
")",
";",
"}",
"$",
"xref",
"=",
"$",
"this",
"->",
"getNewXref",
"(",
")",
";",
"$",
"gedcom",
"=",
"'0 @'",
".",
"$",
"xref",
".",
"'@ '",
".",
"Str",
"::",
"after",
"(",
"$",
"gedcom",
",",
"'0 @@ '",
")",
";",
"// Create a change record",
"$",
"gedcom",
".=",
"\"\\n1 CHAN\\n2 DATE \"",
".",
"date",
"(",
"'d M Y'",
")",
".",
"\"\\n3 TIME \"",
".",
"date",
"(",
"'H:i:s'",
")",
".",
"\"\\n2 _WT_USER \"",
".",
"Auth",
"::",
"user",
"(",
")",
"->",
"userName",
"(",
")",
";",
"// Create a pending change",
"DB",
"::",
"table",
"(",
"'change'",
")",
"->",
"insert",
"(",
"[",
"'gedcom_id'",
"=>",
"$",
"this",
"->",
"id",
",",
"'xref'",
"=>",
"$",
"xref",
",",
"'old_gedcom'",
"=>",
"''",
",",
"'new_gedcom'",
"=>",
"$",
"gedcom",
",",
"'user_id'",
"=>",
"Auth",
"::",
"id",
"(",
")",
",",
"]",
")",
";",
"// Accept this pending change",
"if",
"(",
"Auth",
"::",
"user",
"(",
")",
"->",
"getPreference",
"(",
"'auto_accept'",
")",
")",
"{",
"FunctionsImport",
"::",
"acceptAllChanges",
"(",
"$",
"xref",
",",
"$",
"this",
")",
";",
"return",
"new",
"GedcomRecord",
"(",
"$",
"xref",
",",
"$",
"gedcom",
",",
"null",
",",
"$",
"this",
")",
";",
"}",
"return",
"GedcomRecord",
"::",
"getInstance",
"(",
"$",
"xref",
",",
"$",
"this",
",",
"$",
"gedcom",
")",
";",
"}"
] |
Create a new record from GEDCOM data.
@param string $gedcom
@return GedcomRecord|Individual|Family|Note|Source|Repository|Media
@throws InvalidArgumentException
|
[
"Create",
"a",
"new",
"record",
"from",
"GEDCOM",
"data",
"."
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Tree.php#L695-L724
|
train
|
fisharebest/webtrees
|
app/Tree.php
|
Tree.getNewXref
|
public function getNewXref(): string
{
// Lock the row, so that only one new XREF may be generated at a time.
DB::table('site_setting')
->where('setting_name', '=', 'next_xref')
->lockForUpdate()
->get();
$prefix = 'X';
$increment = 1.0;
do {
$num = (int) Site::getPreference('next_xref') + (int) $increment;
// This exponential increment allows us to scan over large blocks of
// existing data in a reasonable time.
$increment *= 1.01;
$xref = $prefix . $num;
// Records may already exist with this sequence number.
$already_used =
DB::table('individuals')->where('i_id', '=', $xref)->exists() ||
DB::table('families')->where('f_id', '=', $xref)->exists() ||
DB::table('sources')->where('s_id', '=', $xref)->exists() ||
DB::table('media')->where('m_id', '=', $xref)->exists() ||
DB::table('other')->where('o_id', '=', $xref)->exists() ||
DB::table('change')->where('xref', '=', $xref)->exists();
} while ($already_used);
Site::setPreference('next_xref', (string) $num);
return $xref;
}
|
php
|
public function getNewXref(): string
{
// Lock the row, so that only one new XREF may be generated at a time.
DB::table('site_setting')
->where('setting_name', '=', 'next_xref')
->lockForUpdate()
->get();
$prefix = 'X';
$increment = 1.0;
do {
$num = (int) Site::getPreference('next_xref') + (int) $increment;
// This exponential increment allows us to scan over large blocks of
// existing data in a reasonable time.
$increment *= 1.01;
$xref = $prefix . $num;
// Records may already exist with this sequence number.
$already_used =
DB::table('individuals')->where('i_id', '=', $xref)->exists() ||
DB::table('families')->where('f_id', '=', $xref)->exists() ||
DB::table('sources')->where('s_id', '=', $xref)->exists() ||
DB::table('media')->where('m_id', '=', $xref)->exists() ||
DB::table('other')->where('o_id', '=', $xref)->exists() ||
DB::table('change')->where('xref', '=', $xref)->exists();
} while ($already_used);
Site::setPreference('next_xref', (string) $num);
return $xref;
}
|
[
"public",
"function",
"getNewXref",
"(",
")",
":",
"string",
"{",
"// Lock the row, so that only one new XREF may be generated at a time.",
"DB",
"::",
"table",
"(",
"'site_setting'",
")",
"->",
"where",
"(",
"'setting_name'",
",",
"'='",
",",
"'next_xref'",
")",
"->",
"lockForUpdate",
"(",
")",
"->",
"get",
"(",
")",
";",
"$",
"prefix",
"=",
"'X'",
";",
"$",
"increment",
"=",
"1.0",
";",
"do",
"{",
"$",
"num",
"=",
"(",
"int",
")",
"Site",
"::",
"getPreference",
"(",
"'next_xref'",
")",
"+",
"(",
"int",
")",
"$",
"increment",
";",
"// This exponential increment allows us to scan over large blocks of",
"// existing data in a reasonable time.",
"$",
"increment",
"*=",
"1.01",
";",
"$",
"xref",
"=",
"$",
"prefix",
".",
"$",
"num",
";",
"// Records may already exist with this sequence number.",
"$",
"already_used",
"=",
"DB",
"::",
"table",
"(",
"'individuals'",
")",
"->",
"where",
"(",
"'i_id'",
",",
"'='",
",",
"$",
"xref",
")",
"->",
"exists",
"(",
")",
"||",
"DB",
"::",
"table",
"(",
"'families'",
")",
"->",
"where",
"(",
"'f_id'",
",",
"'='",
",",
"$",
"xref",
")",
"->",
"exists",
"(",
")",
"||",
"DB",
"::",
"table",
"(",
"'sources'",
")",
"->",
"where",
"(",
"'s_id'",
",",
"'='",
",",
"$",
"xref",
")",
"->",
"exists",
"(",
")",
"||",
"DB",
"::",
"table",
"(",
"'media'",
")",
"->",
"where",
"(",
"'m_id'",
",",
"'='",
",",
"$",
"xref",
")",
"->",
"exists",
"(",
")",
"||",
"DB",
"::",
"table",
"(",
"'other'",
")",
"->",
"where",
"(",
"'o_id'",
",",
"'='",
",",
"$",
"xref",
")",
"->",
"exists",
"(",
")",
"||",
"DB",
"::",
"table",
"(",
"'change'",
")",
"->",
"where",
"(",
"'xref'",
",",
"'='",
",",
"$",
"xref",
")",
"->",
"exists",
"(",
")",
";",
"}",
"while",
"(",
"$",
"already_used",
")",
";",
"Site",
"::",
"setPreference",
"(",
"'next_xref'",
",",
"(",
"string",
")",
"$",
"num",
")",
";",
"return",
"$",
"xref",
";",
"}"
] |
Generate a new XREF, unique across all family trees
@return string
|
[
"Generate",
"a",
"new",
"XREF",
"unique",
"across",
"all",
"family",
"trees"
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Tree.php#L731-L764
|
train
|
fisharebest/webtrees
|
app/Tree.php
|
Tree.significantIndividual
|
public function significantIndividual(UserInterface $user): Individual
{
$individual = null;
if ($this->getUserPreference($user, 'rootid') !== '') {
$individual = Individual::getInstance($this->getUserPreference($user, 'rootid'), $this);
}
if ($individual === null && $this->getUserPreference($user, 'gedcomid') !== '') {
$individual = Individual::getInstance($this->getUserPreference($user, 'gedcomid'), $this);
}
if ($individual === null && $this->getPreference('PEDIGREE_ROOT_ID') !== '') {
$individual = Individual::getInstance($this->getPreference('PEDIGREE_ROOT_ID'), $this);
}
if ($individual === null) {
$xref = (string) DB::table('individuals')
->where('i_file', '=', $this->id())
->min('i_id');
$individual = Individual::getInstance($xref, $this);
}
if ($individual === null) {
// always return a record
$individual = new Individual('I', '0 @I@ INDI', null, $this);
}
return $individual;
}
|
php
|
public function significantIndividual(UserInterface $user): Individual
{
$individual = null;
if ($this->getUserPreference($user, 'rootid') !== '') {
$individual = Individual::getInstance($this->getUserPreference($user, 'rootid'), $this);
}
if ($individual === null && $this->getUserPreference($user, 'gedcomid') !== '') {
$individual = Individual::getInstance($this->getUserPreference($user, 'gedcomid'), $this);
}
if ($individual === null && $this->getPreference('PEDIGREE_ROOT_ID') !== '') {
$individual = Individual::getInstance($this->getPreference('PEDIGREE_ROOT_ID'), $this);
}
if ($individual === null) {
$xref = (string) DB::table('individuals')
->where('i_file', '=', $this->id())
->min('i_id');
$individual = Individual::getInstance($xref, $this);
}
if ($individual === null) {
// always return a record
$individual = new Individual('I', '0 @I@ INDI', null, $this);
}
return $individual;
}
|
[
"public",
"function",
"significantIndividual",
"(",
"UserInterface",
"$",
"user",
")",
":",
"Individual",
"{",
"$",
"individual",
"=",
"null",
";",
"if",
"(",
"$",
"this",
"->",
"getUserPreference",
"(",
"$",
"user",
",",
"'rootid'",
")",
"!==",
"''",
")",
"{",
"$",
"individual",
"=",
"Individual",
"::",
"getInstance",
"(",
"$",
"this",
"->",
"getUserPreference",
"(",
"$",
"user",
",",
"'rootid'",
")",
",",
"$",
"this",
")",
";",
"}",
"if",
"(",
"$",
"individual",
"===",
"null",
"&&",
"$",
"this",
"->",
"getUserPreference",
"(",
"$",
"user",
",",
"'gedcomid'",
")",
"!==",
"''",
")",
"{",
"$",
"individual",
"=",
"Individual",
"::",
"getInstance",
"(",
"$",
"this",
"->",
"getUserPreference",
"(",
"$",
"user",
",",
"'gedcomid'",
")",
",",
"$",
"this",
")",
";",
"}",
"if",
"(",
"$",
"individual",
"===",
"null",
"&&",
"$",
"this",
"->",
"getPreference",
"(",
"'PEDIGREE_ROOT_ID'",
")",
"!==",
"''",
")",
"{",
"$",
"individual",
"=",
"Individual",
"::",
"getInstance",
"(",
"$",
"this",
"->",
"getPreference",
"(",
"'PEDIGREE_ROOT_ID'",
")",
",",
"$",
"this",
")",
";",
"}",
"if",
"(",
"$",
"individual",
"===",
"null",
")",
"{",
"$",
"xref",
"=",
"(",
"string",
")",
"DB",
"::",
"table",
"(",
"'individuals'",
")",
"->",
"where",
"(",
"'i_file'",
",",
"'='",
",",
"$",
"this",
"->",
"id",
"(",
")",
")",
"->",
"min",
"(",
"'i_id'",
")",
";",
"$",
"individual",
"=",
"Individual",
"::",
"getInstance",
"(",
"$",
"xref",
",",
"$",
"this",
")",
";",
"}",
"if",
"(",
"$",
"individual",
"===",
"null",
")",
"{",
"// always return a record",
"$",
"individual",
"=",
"new",
"Individual",
"(",
"'I'",
",",
"'0 @I@ INDI'",
",",
"null",
",",
"$",
"this",
")",
";",
"}",
"return",
"$",
"individual",
";",
"}"
] |
What is the most significant individual in this tree.
@param UserInterface $user
@return Individual
|
[
"What",
"is",
"the",
"most",
"significant",
"individual",
"in",
"this",
"tree",
"."
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Tree.php#L890-L918
|
train
|
fisharebest/webtrees
|
app/Http/Controllers/SetupController.php
|
SetupController.setup
|
public function setup(ServerRequestInterface $request): ResponseInterface
{
// Mini "bootstrap"
define('WT_DATA_DIR', 'data/');
app()->instance(ServerRequestInterface::class, $request);
app()->instance('cache.array', new Repository(new ArrayStore()));
$data = $this->userData($request);
$step = (int) ($request->getParsedBody()['step'] ?? '1');
$lang = $request->getParsedBody()['lang'] ?? $data['lang'];
$data['lang'] = I18N::init($lang, null, true);
$data['cpu_limit'] = $this->maxExecutionTime();
$data['locales'] = $this->setupLocales();
$data['memory_limit'] = $this->memoryLimit();
// Only show database errors after the user has chosen a driver.
if ($step >= 4) {
$data['errors'] = $this->server_check_service->serverErrors($data['dbtype']);
$data['warnings'] = $this->server_check_service->serverWarnings($data['dbtype']);
} else {
$data['errors'] = $this->server_check_service->serverErrors();
$data['warnings'] = $this->server_check_service->serverWarnings();
}
if (!$this->checkFolderIsWritable(WT_DATA_DIR)) {
$data['errors']->push(
'<code>' . e(realpath(WT_DATA_DIR)) . '</code><br>' .
I18N::translate('Oops! webtrees was unable to create files in this folder.') . ' ' .
I18N::translate('This usually means that you need to change the folder permissions to 777.')
);
}
define('WT_LOCALE', $data['lang']);
switch ($step) {
default:
case 1:
return $this->step1Language($data);
case 2:
return $this->step2CheckServer($data);
case 3:
return $this->step3DatabaseType($data);
case 4:
return $this->step4DatabaseConnection($data);
case 5:
return $this->step5Administrator($data);
case 6:
return $this->step6Install($data);
}
}
|
php
|
public function setup(ServerRequestInterface $request): ResponseInterface
{
// Mini "bootstrap"
define('WT_DATA_DIR', 'data/');
app()->instance(ServerRequestInterface::class, $request);
app()->instance('cache.array', new Repository(new ArrayStore()));
$data = $this->userData($request);
$step = (int) ($request->getParsedBody()['step'] ?? '1');
$lang = $request->getParsedBody()['lang'] ?? $data['lang'];
$data['lang'] = I18N::init($lang, null, true);
$data['cpu_limit'] = $this->maxExecutionTime();
$data['locales'] = $this->setupLocales();
$data['memory_limit'] = $this->memoryLimit();
// Only show database errors after the user has chosen a driver.
if ($step >= 4) {
$data['errors'] = $this->server_check_service->serverErrors($data['dbtype']);
$data['warnings'] = $this->server_check_service->serverWarnings($data['dbtype']);
} else {
$data['errors'] = $this->server_check_service->serverErrors();
$data['warnings'] = $this->server_check_service->serverWarnings();
}
if (!$this->checkFolderIsWritable(WT_DATA_DIR)) {
$data['errors']->push(
'<code>' . e(realpath(WT_DATA_DIR)) . '</code><br>' .
I18N::translate('Oops! webtrees was unable to create files in this folder.') . ' ' .
I18N::translate('This usually means that you need to change the folder permissions to 777.')
);
}
define('WT_LOCALE', $data['lang']);
switch ($step) {
default:
case 1:
return $this->step1Language($data);
case 2:
return $this->step2CheckServer($data);
case 3:
return $this->step3DatabaseType($data);
case 4:
return $this->step4DatabaseConnection($data);
case 5:
return $this->step5Administrator($data);
case 6:
return $this->step6Install($data);
}
}
|
[
"public",
"function",
"setup",
"(",
"ServerRequestInterface",
"$",
"request",
")",
":",
"ResponseInterface",
"{",
"// Mini \"bootstrap\"",
"define",
"(",
"'WT_DATA_DIR'",
",",
"'data/'",
")",
";",
"app",
"(",
")",
"->",
"instance",
"(",
"ServerRequestInterface",
"::",
"class",
",",
"$",
"request",
")",
";",
"app",
"(",
")",
"->",
"instance",
"(",
"'cache.array'",
",",
"new",
"Repository",
"(",
"new",
"ArrayStore",
"(",
")",
")",
")",
";",
"$",
"data",
"=",
"$",
"this",
"->",
"userData",
"(",
"$",
"request",
")",
";",
"$",
"step",
"=",
"(",
"int",
")",
"(",
"$",
"request",
"->",
"getParsedBody",
"(",
")",
"[",
"'step'",
"]",
"??",
"'1'",
")",
";",
"$",
"lang",
"=",
"$",
"request",
"->",
"getParsedBody",
"(",
")",
"[",
"'lang'",
"]",
"??",
"$",
"data",
"[",
"'lang'",
"]",
";",
"$",
"data",
"[",
"'lang'",
"]",
"=",
"I18N",
"::",
"init",
"(",
"$",
"lang",
",",
"null",
",",
"true",
")",
";",
"$",
"data",
"[",
"'cpu_limit'",
"]",
"=",
"$",
"this",
"->",
"maxExecutionTime",
"(",
")",
";",
"$",
"data",
"[",
"'locales'",
"]",
"=",
"$",
"this",
"->",
"setupLocales",
"(",
")",
";",
"$",
"data",
"[",
"'memory_limit'",
"]",
"=",
"$",
"this",
"->",
"memoryLimit",
"(",
")",
";",
"// Only show database errors after the user has chosen a driver.",
"if",
"(",
"$",
"step",
">=",
"4",
")",
"{",
"$",
"data",
"[",
"'errors'",
"]",
"=",
"$",
"this",
"->",
"server_check_service",
"->",
"serverErrors",
"(",
"$",
"data",
"[",
"'dbtype'",
"]",
")",
";",
"$",
"data",
"[",
"'warnings'",
"]",
"=",
"$",
"this",
"->",
"server_check_service",
"->",
"serverWarnings",
"(",
"$",
"data",
"[",
"'dbtype'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"data",
"[",
"'errors'",
"]",
"=",
"$",
"this",
"->",
"server_check_service",
"->",
"serverErrors",
"(",
")",
";",
"$",
"data",
"[",
"'warnings'",
"]",
"=",
"$",
"this",
"->",
"server_check_service",
"->",
"serverWarnings",
"(",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"checkFolderIsWritable",
"(",
"WT_DATA_DIR",
")",
")",
"{",
"$",
"data",
"[",
"'errors'",
"]",
"->",
"push",
"(",
"'<code>'",
".",
"e",
"(",
"realpath",
"(",
"WT_DATA_DIR",
")",
")",
".",
"'</code><br>'",
".",
"I18N",
"::",
"translate",
"(",
"'Oops! webtrees was unable to create files in this folder.'",
")",
".",
"' '",
".",
"I18N",
"::",
"translate",
"(",
"'This usually means that you need to change the folder permissions to 777.'",
")",
")",
";",
"}",
"define",
"(",
"'WT_LOCALE'",
",",
"$",
"data",
"[",
"'lang'",
"]",
")",
";",
"switch",
"(",
"$",
"step",
")",
"{",
"default",
":",
"case",
"1",
":",
"return",
"$",
"this",
"->",
"step1Language",
"(",
"$",
"data",
")",
";",
"case",
"2",
":",
"return",
"$",
"this",
"->",
"step2CheckServer",
"(",
"$",
"data",
")",
";",
"case",
"3",
":",
"return",
"$",
"this",
"->",
"step3DatabaseType",
"(",
"$",
"data",
")",
";",
"case",
"4",
":",
"return",
"$",
"this",
"->",
"step4DatabaseConnection",
"(",
"$",
"data",
")",
";",
"case",
"5",
":",
"return",
"$",
"this",
"->",
"step5Administrator",
"(",
"$",
"data",
")",
";",
"case",
"6",
":",
"return",
"$",
"this",
"->",
"step6Install",
"(",
"$",
"data",
")",
";",
"}",
"}"
] |
Installation wizard - check user input and proceed to the next step.
@param ServerRequestInterface $request
@return ResponseInterface
|
[
"Installation",
"wizard",
"-",
"check",
"user",
"input",
"and",
"proceed",
"to",
"the",
"next",
"step",
"."
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Http/Controllers/SetupController.php#L103-L154
|
train
|
fisharebest/webtrees
|
app/Http/Controllers/SetupController.php
|
SetupController.setupLocales
|
private function setupLocales(): array
{
return app(ModuleService::class)
->setupLanguages()
->map(static function (ModuleLanguageInterface $module): LocaleInterface {
return $module->locale();
})
->all();
}
|
php
|
private function setupLocales(): array
{
return app(ModuleService::class)
->setupLanguages()
->map(static function (ModuleLanguageInterface $module): LocaleInterface {
return $module->locale();
})
->all();
}
|
[
"private",
"function",
"setupLocales",
"(",
")",
":",
"array",
"{",
"return",
"app",
"(",
"ModuleService",
"::",
"class",
")",
"->",
"setupLanguages",
"(",
")",
"->",
"map",
"(",
"static",
"function",
"(",
"ModuleLanguageInterface",
"$",
"module",
")",
":",
"LocaleInterface",
"{",
"return",
"$",
"module",
"->",
"locale",
"(",
")",
";",
"}",
")",
"->",
"all",
"(",
")",
";",
"}"
] |
Which languages are available during the installation.
@return LocaleInterface[]
|
[
"Which",
"languages",
"are",
"available",
"during",
"the",
"installation",
"."
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Http/Controllers/SetupController.php#L187-L195
|
train
|
fisharebest/webtrees
|
app/Http/Controllers/SetupController.php
|
SetupController.checkFolderIsWritable
|
private function checkFolderIsWritable(string $data_dir): bool
{
$text1 = random_bytes(32);
try {
file_put_contents($data_dir . 'test.txt', $text1);
$text2 = file_get_contents(WT_DATA_DIR . 'test.txt');
unlink(WT_DATA_DIR . 'test.txt');
} catch (Exception $ex) {
return false;
}
return $text1 === $text2;
}
|
php
|
private function checkFolderIsWritable(string $data_dir): bool
{
$text1 = random_bytes(32);
try {
file_put_contents($data_dir . 'test.txt', $text1);
$text2 = file_get_contents(WT_DATA_DIR . 'test.txt');
unlink(WT_DATA_DIR . 'test.txt');
} catch (Exception $ex) {
return false;
}
return $text1 === $text2;
}
|
[
"private",
"function",
"checkFolderIsWritable",
"(",
"string",
"$",
"data_dir",
")",
":",
"bool",
"{",
"$",
"text1",
"=",
"random_bytes",
"(",
"32",
")",
";",
"try",
"{",
"file_put_contents",
"(",
"$",
"data_dir",
".",
"'test.txt'",
",",
"$",
"text1",
")",
";",
"$",
"text2",
"=",
"file_get_contents",
"(",
"WT_DATA_DIR",
".",
"'test.txt'",
")",
";",
"unlink",
"(",
"WT_DATA_DIR",
".",
"'test.txt'",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"ex",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"text1",
"===",
"$",
"text2",
";",
"}"
] |
Check we can write to the data folder.
@param string $data_dir
@return bool
|
[
"Check",
"we",
"can",
"write",
"to",
"the",
"data",
"folder",
"."
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Http/Controllers/SetupController.php#L237-L250
|
train
|
fisharebest/webtrees
|
app/Statistics/Google/ChartBirth.php
|
ChartBirth.chartBirth
|
public function chartBirth(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('Century'),
I18N::translate('Total')
],
];
foreach ($this->queryRecords() as $record) {
$data[] = [
$this->century_service->centuryName((int) $record->century),
$record->total
];
}
$colors = $this->color_service->interpolateRgb($color_from, $color_to, count($data) - 1);
return view(
'statistics/other/charts/pie',
[
'title' => I18N::translate('Births by century'),
'data' => $data,
'colors' => $colors,
]
);
}
|
php
|
public function chartBirth(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('Century'),
I18N::translate('Total')
],
];
foreach ($this->queryRecords() as $record) {
$data[] = [
$this->century_service->centuryName((int) $record->century),
$record->total
];
}
$colors = $this->color_service->interpolateRgb($color_from, $color_to, count($data) - 1);
return view(
'statistics/other/charts/pie',
[
'title' => I18N::translate('Births by century'),
'data' => $data,
'colors' => $colors,
]
);
}
|
[
"public",
"function",
"chartBirth",
"(",
"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",
"(",
"'Century'",
")",
",",
"I18N",
"::",
"translate",
"(",
"'Total'",
")",
"]",
",",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"queryRecords",
"(",
")",
"as",
"$",
"record",
")",
"{",
"$",
"data",
"[",
"]",
"=",
"[",
"$",
"this",
"->",
"century_service",
"->",
"centuryName",
"(",
"(",
"int",
")",
"$",
"record",
"->",
"century",
")",
",",
"$",
"record",
"->",
"total",
"]",
";",
"}",
"$",
"colors",
"=",
"$",
"this",
"->",
"color_service",
"->",
"interpolateRgb",
"(",
"$",
"color_from",
",",
"$",
"color_to",
",",
"count",
"(",
"$",
"data",
")",
"-",
"1",
")",
";",
"return",
"view",
"(",
"'statistics/other/charts/pie'",
",",
"[",
"'title'",
"=>",
"I18N",
"::",
"translate",
"(",
"'Births by century'",
")",
",",
"'data'",
"=>",
"$",
"data",
",",
"'colors'",
"=>",
"$",
"colors",
",",
"]",
")",
";",
"}"
] |
Create a chart of birth places.
@param string|null $color_from
@param string|null $color_to
@return string
|
[
"Create",
"a",
"chart",
"of",
"birth",
"places",
"."
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Statistics/Google/ChartBirth.php#L95-L126
|
train
|
fisharebest/webtrees
|
app/Statistics/Service/CountryService.php
|
CountryService.mapTwoLetterToName
|
public function mapTwoLetterToName(string $twoLetterCode): string
{
$threeLetterCode = array_search($twoLetterCode, $this->iso3166(), true);
$threeLetterCode = $threeLetterCode ?: '???';
return $this->getAllCountries()[$threeLetterCode];
}
|
php
|
public function mapTwoLetterToName(string $twoLetterCode): string
{
$threeLetterCode = array_search($twoLetterCode, $this->iso3166(), true);
$threeLetterCode = $threeLetterCode ?: '???';
return $this->getAllCountries()[$threeLetterCode];
}
|
[
"public",
"function",
"mapTwoLetterToName",
"(",
"string",
"$",
"twoLetterCode",
")",
":",
"string",
"{",
"$",
"threeLetterCode",
"=",
"array_search",
"(",
"$",
"twoLetterCode",
",",
"$",
"this",
"->",
"iso3166",
"(",
")",
",",
"true",
")",
";",
"$",
"threeLetterCode",
"=",
"$",
"threeLetterCode",
"?",
":",
"'???'",
";",
"return",
"$",
"this",
"->",
"getAllCountries",
"(",
")",
"[",
"$",
"threeLetterCode",
"]",
";",
"}"
] |
Returns the translated country name based on the given two letter country code.
@param string $twoLetterCode The two letter country code
@return string
|
[
"Returns",
"the",
"translated",
"country",
"name",
"based",
"on",
"the",
"given",
"two",
"letter",
"country",
"code",
"."
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Statistics/Service/CountryService.php#L810-L816
|
train
|
fisharebest/webtrees
|
app/Http/Controllers/GedcomRecordController.php
|
GedcomRecordController.show
|
public function show(ServerRequestInterface $request, Tree $tree): ResponseInterface
{
$xref = $request->get('xref', '');
$record = GedcomRecord::getInstance($xref, $tree);
Auth::checkRecordAccess($record);
if ($this->hasCustomPage($record)) {
return redirect($record->url());
}
return $this->viewResponse('gedcom-record-page', [
'facts' => $record->facts(),
'families' => $record->linkedFamilies($record::RECORD_TYPE),
'individuals' => $record->linkedIndividuals($record::RECORD_TYPE),
'meta_robots' => 'index,follow',
'notes' => $record->linkedNotes($record::RECORD_TYPE),
'media_objects' => $record->linkedMedia($record::RECORD_TYPE),
'record' => $record,
'sources' => $record->linkedSources($record::RECORD_TYPE),
'title' => $record->fullName(),
]);
}
|
php
|
public function show(ServerRequestInterface $request, Tree $tree): ResponseInterface
{
$xref = $request->get('xref', '');
$record = GedcomRecord::getInstance($xref, $tree);
Auth::checkRecordAccess($record);
if ($this->hasCustomPage($record)) {
return redirect($record->url());
}
return $this->viewResponse('gedcom-record-page', [
'facts' => $record->facts(),
'families' => $record->linkedFamilies($record::RECORD_TYPE),
'individuals' => $record->linkedIndividuals($record::RECORD_TYPE),
'meta_robots' => 'index,follow',
'notes' => $record->linkedNotes($record::RECORD_TYPE),
'media_objects' => $record->linkedMedia($record::RECORD_TYPE),
'record' => $record,
'sources' => $record->linkedSources($record::RECORD_TYPE),
'title' => $record->fullName(),
]);
}
|
[
"public",
"function",
"show",
"(",
"ServerRequestInterface",
"$",
"request",
",",
"Tree",
"$",
"tree",
")",
":",
"ResponseInterface",
"{",
"$",
"xref",
"=",
"$",
"request",
"->",
"get",
"(",
"'xref'",
",",
"''",
")",
";",
"$",
"record",
"=",
"GedcomRecord",
"::",
"getInstance",
"(",
"$",
"xref",
",",
"$",
"tree",
")",
";",
"Auth",
"::",
"checkRecordAccess",
"(",
"$",
"record",
")",
";",
"if",
"(",
"$",
"this",
"->",
"hasCustomPage",
"(",
"$",
"record",
")",
")",
"{",
"return",
"redirect",
"(",
"$",
"record",
"->",
"url",
"(",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"viewResponse",
"(",
"'gedcom-record-page'",
",",
"[",
"'facts'",
"=>",
"$",
"record",
"->",
"facts",
"(",
")",
",",
"'families'",
"=>",
"$",
"record",
"->",
"linkedFamilies",
"(",
"$",
"record",
"::",
"RECORD_TYPE",
")",
",",
"'individuals'",
"=>",
"$",
"record",
"->",
"linkedIndividuals",
"(",
"$",
"record",
"::",
"RECORD_TYPE",
")",
",",
"'meta_robots'",
"=>",
"'index,follow'",
",",
"'notes'",
"=>",
"$",
"record",
"->",
"linkedNotes",
"(",
"$",
"record",
"::",
"RECORD_TYPE",
")",
",",
"'media_objects'",
"=>",
"$",
"record",
"->",
"linkedMedia",
"(",
"$",
"record",
"::",
"RECORD_TYPE",
")",
",",
"'record'",
"=>",
"$",
"record",
",",
"'sources'",
"=>",
"$",
"record",
"->",
"linkedSources",
"(",
"$",
"record",
"::",
"RECORD_TYPE",
")",
",",
"'title'",
"=>",
"$",
"record",
"->",
"fullName",
"(",
")",
",",
"]",
")",
";",
"}"
] |
Show a gedcom record's page.
@param ServerRequestInterface $request
@param Tree $tree
@return ResponseInterface
|
[
"Show",
"a",
"gedcom",
"record",
"s",
"page",
"."
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Http/Controllers/GedcomRecordController.php#L45-L67
|
train
|
fisharebest/webtrees
|
app/Http/Controllers/GedcomRecordController.php
|
GedcomRecordController.hasCustomPage
|
private function hasCustomPage(GedcomRecord $record): bool
{
return
$record instanceof Individual ||
$record instanceof Family ||
$record instanceof Source ||
$record instanceof Repository ||
$record instanceof Note ||
$record instanceof Media;
}
|
php
|
private function hasCustomPage(GedcomRecord $record): bool
{
return
$record instanceof Individual ||
$record instanceof Family ||
$record instanceof Source ||
$record instanceof Repository ||
$record instanceof Note ||
$record instanceof Media;
}
|
[
"private",
"function",
"hasCustomPage",
"(",
"GedcomRecord",
"$",
"record",
")",
":",
"bool",
"{",
"return",
"$",
"record",
"instanceof",
"Individual",
"||",
"$",
"record",
"instanceof",
"Family",
"||",
"$",
"record",
"instanceof",
"Source",
"||",
"$",
"record",
"instanceof",
"Repository",
"||",
"$",
"record",
"instanceof",
"Note",
"||",
"$",
"record",
"instanceof",
"Media",
";",
"}"
] |
Is there a better place to display this record?
@param GedcomRecord $record
@return bool
|
[
"Is",
"there",
"a",
"better",
"place",
"to",
"display",
"this",
"record?"
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Http/Controllers/GedcomRecordController.php#L76-L85
|
train
|
fisharebest/webtrees
|
app/Services/GedcomService.php
|
GedcomService.canonicalTag
|
public function canonicalTag(string $tag): string
{
$tag = strtoupper($tag);
$tag = self::TAG_NAMES[$tag] ?? self::TAG_SYNONYMS[$tag] ?? $tag;
return $tag;
}
|
php
|
public function canonicalTag(string $tag): string
{
$tag = strtoupper($tag);
$tag = self::TAG_NAMES[$tag] ?? self::TAG_SYNONYMS[$tag] ?? $tag;
return $tag;
}
|
[
"public",
"function",
"canonicalTag",
"(",
"string",
"$",
"tag",
")",
":",
"string",
"{",
"$",
"tag",
"=",
"strtoupper",
"(",
"$",
"tag",
")",
";",
"$",
"tag",
"=",
"self",
"::",
"TAG_NAMES",
"[",
"$",
"tag",
"]",
"??",
"self",
"::",
"TAG_SYNONYMS",
"[",
"$",
"tag",
"]",
"??",
"$",
"tag",
";",
"return",
"$",
"tag",
";",
"}"
] |
Convert a GEDCOM tag to a canonical form.
@param string $tag
@return string
|
[
"Convert",
"a",
"GEDCOM",
"tag",
"to",
"a",
"canonical",
"form",
"."
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Services/GedcomService.php#L205-L212
|
train
|
fisharebest/webtrees
|
app/Services/GedcomService.php
|
GedcomService.readSex
|
public function readSex(string $text): string
{
$text = strtoupper($text);
if ($text !== self::SEX_MALE && $text !== self::SEX_FEMALE) {
$text = self::SEX_UNKNOWN;
}
return $text;
}
|
php
|
public function readSex(string $text): string
{
$text = strtoupper($text);
if ($text !== self::SEX_MALE && $text !== self::SEX_FEMALE) {
$text = self::SEX_UNKNOWN;
}
return $text;
}
|
[
"public",
"function",
"readSex",
"(",
"string",
"$",
"text",
")",
":",
"string",
"{",
"$",
"text",
"=",
"strtoupper",
"(",
"$",
"text",
")",
";",
"if",
"(",
"$",
"text",
"!==",
"self",
"::",
"SEX_MALE",
"&&",
"$",
"text",
"!==",
"self",
"::",
"SEX_FEMALE",
")",
"{",
"$",
"text",
"=",
"self",
"::",
"SEX_UNKNOWN",
";",
"}",
"return",
"$",
"text",
";",
"}"
] |
Some applications use non-standard values for unknown.
@param string $text
@return string
|
[
"Some",
"applications",
"use",
"non",
"-",
"standard",
"values",
"for",
"unknown",
"."
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Services/GedcomService.php#L349-L358
|
train
|
fisharebest/webtrees
|
app/Module/ModuleCustomTrait.php
|
ModuleCustomTrait.assetUrl
|
public function assetUrl(string $asset): string
{
$file = $this->resourcesFolder() . $asset;
// Add the file's modification time to the URL, so we can set long expiry cache headers.
$hash = filemtime($file);
return route('module', [
'module' => $this->name(),
'action' => 'asset',
'asset' => $asset,
'hash' => $hash,
]);
}
|
php
|
public function assetUrl(string $asset): string
{
$file = $this->resourcesFolder() . $asset;
// Add the file's modification time to the URL, so we can set long expiry cache headers.
$hash = filemtime($file);
return route('module', [
'module' => $this->name(),
'action' => 'asset',
'asset' => $asset,
'hash' => $hash,
]);
}
|
[
"public",
"function",
"assetUrl",
"(",
"string",
"$",
"asset",
")",
":",
"string",
"{",
"$",
"file",
"=",
"$",
"this",
"->",
"resourcesFolder",
"(",
")",
".",
"$",
"asset",
";",
"// Add the file's modification time to the URL, so we can set long expiry cache headers.",
"$",
"hash",
"=",
"filemtime",
"(",
"$",
"file",
")",
";",
"return",
"route",
"(",
"'module'",
",",
"[",
"'module'",
"=>",
"$",
"this",
"->",
"name",
"(",
")",
",",
"'action'",
"=>",
"'asset'",
",",
"'asset'",
"=>",
"$",
"asset",
",",
"'hash'",
"=>",
"$",
"hash",
",",
"]",
")",
";",
"}"
] |
Create a URL for an asset.
@param string $asset e.g. "css/theme.css" or "img/banner.png"
@return string
|
[
"Create",
"a",
"URL",
"for",
"an",
"asset",
"."
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Module/ModuleCustomTrait.php#L106-L119
|
train
|
fisharebest/webtrees
|
app/Report/ReportHtmlFootnote.php
|
ReportHtmlFootnote.render
|
public function render($renderer)
{
$renderer->setCurrentStyle('footnotenum');
echo '<a href="#footnote', $this->num, '"><sup>';
$renderer->write($renderer->entityRTL . $this->num);
echo "</sup></a>\n";
}
|
php
|
public function render($renderer)
{
$renderer->setCurrentStyle('footnotenum');
echo '<a href="#footnote', $this->num, '"><sup>';
$renderer->write($renderer->entityRTL . $this->num);
echo "</sup></a>\n";
}
|
[
"public",
"function",
"render",
"(",
"$",
"renderer",
")",
"{",
"$",
"renderer",
"->",
"setCurrentStyle",
"(",
"'footnotenum'",
")",
";",
"echo",
"'<a href=\"#footnote'",
",",
"$",
"this",
"->",
"num",
",",
"'\"><sup>'",
";",
"$",
"renderer",
"->",
"write",
"(",
"$",
"renderer",
"->",
"entityRTL",
".",
"$",
"this",
"->",
"num",
")",
";",
"echo",
"\"</sup></a>\\n\"",
";",
"}"
] |
HTML Footnotes number renderer
@param ReportHtml $renderer
@return void
|
[
"HTML",
"Footnotes",
"number",
"renderer"
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Report/ReportHtmlFootnote.php#L32-L38
|
train
|
fisharebest/webtrees
|
app/Report/ReportHtmlFootnote.php
|
ReportHtmlFootnote.getFootnoteHeight
|
public function getFootnoteHeight($html, float $cellWidth = 0): float
{
if ($html->getCurrentStyle() != $this->styleName) {
$html->setCurrentStyle($this->styleName);
}
if ($cellWidth > 0) {
$this->text = $html->textWrap($this->text, $cellWidth);
}
$this->text .= "\n\n";
$ct = substr_count($this->text, "\n");
$fsize = $html->getCurrentStyleHeight();
return ($fsize * $ct) * $html->cellHeightRatio;
}
|
php
|
public function getFootnoteHeight($html, float $cellWidth = 0): float
{
if ($html->getCurrentStyle() != $this->styleName) {
$html->setCurrentStyle($this->styleName);
}
if ($cellWidth > 0) {
$this->text = $html->textWrap($this->text, $cellWidth);
}
$this->text .= "\n\n";
$ct = substr_count($this->text, "\n");
$fsize = $html->getCurrentStyleHeight();
return ($fsize * $ct) * $html->cellHeightRatio;
}
|
[
"public",
"function",
"getFootnoteHeight",
"(",
"$",
"html",
",",
"float",
"$",
"cellWidth",
"=",
"0",
")",
":",
"float",
"{",
"if",
"(",
"$",
"html",
"->",
"getCurrentStyle",
"(",
")",
"!=",
"$",
"this",
"->",
"styleName",
")",
"{",
"$",
"html",
"->",
"setCurrentStyle",
"(",
"$",
"this",
"->",
"styleName",
")",
";",
"}",
"if",
"(",
"$",
"cellWidth",
">",
"0",
")",
"{",
"$",
"this",
"->",
"text",
"=",
"$",
"html",
"->",
"textWrap",
"(",
"$",
"this",
"->",
"text",
",",
"$",
"cellWidth",
")",
";",
"}",
"$",
"this",
"->",
"text",
".=",
"\"\\n\\n\"",
";",
"$",
"ct",
"=",
"substr_count",
"(",
"$",
"this",
"->",
"text",
",",
"\"\\n\"",
")",
";",
"$",
"fsize",
"=",
"$",
"html",
"->",
"getCurrentStyleHeight",
"(",
")",
";",
"return",
"(",
"$",
"fsize",
"*",
"$",
"ct",
")",
"*",
"$",
"html",
"->",
"cellHeightRatio",
";",
"}"
] |
Calculates the Footnotes height
@param ReportHtml $html
@param float $cellWidth The width of the cell to use it for text wraping
@return float Footnote height in points
|
[
"Calculates",
"the",
"Footnotes",
"height"
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Report/ReportHtmlFootnote.php#L78-L93
|
train
|
fisharebest/webtrees
|
app/Statistics/Service/ColorService.php
|
ColorService.interpolateRgb
|
public function interpolateRgb(string $startColor, string $endColor, int $steps): array
{
if (!$steps) {
return [];
}
$s = $this->hexToRgb($startColor);
$e = $this->hexToRgb($endColor);
$colors = [];
$factorR = ($e[0] - $s[0]) / $steps;
$factorG = ($e[1] - $s[1]) / $steps;
$factorB = ($e[2] - $s[2]) / $steps;
for ($x = 1; $x < $steps; ++$x) {
$colors[] = $this->rgbToHex(
(int) round($s[0] + ($factorR * $x)),
(int) round($s[1] + ($factorG * $x)),
(int) round($s[2] + ($factorB * $x))
);
}
$colors[] = $this->rgbToHex($e[0], $e[1], $e[2]);
return $colors;
}
|
php
|
public function interpolateRgb(string $startColor, string $endColor, int $steps): array
{
if (!$steps) {
return [];
}
$s = $this->hexToRgb($startColor);
$e = $this->hexToRgb($endColor);
$colors = [];
$factorR = ($e[0] - $s[0]) / $steps;
$factorG = ($e[1] - $s[1]) / $steps;
$factorB = ($e[2] - $s[2]) / $steps;
for ($x = 1; $x < $steps; ++$x) {
$colors[] = $this->rgbToHex(
(int) round($s[0] + ($factorR * $x)),
(int) round($s[1] + ($factorG * $x)),
(int) round($s[2] + ($factorB * $x))
);
}
$colors[] = $this->rgbToHex($e[0], $e[1], $e[2]);
return $colors;
}
|
[
"public",
"function",
"interpolateRgb",
"(",
"string",
"$",
"startColor",
",",
"string",
"$",
"endColor",
",",
"int",
"$",
"steps",
")",
":",
"array",
"{",
"if",
"(",
"!",
"$",
"steps",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"s",
"=",
"$",
"this",
"->",
"hexToRgb",
"(",
"$",
"startColor",
")",
";",
"$",
"e",
"=",
"$",
"this",
"->",
"hexToRgb",
"(",
"$",
"endColor",
")",
";",
"$",
"colors",
"=",
"[",
"]",
";",
"$",
"factorR",
"=",
"(",
"$",
"e",
"[",
"0",
"]",
"-",
"$",
"s",
"[",
"0",
"]",
")",
"/",
"$",
"steps",
";",
"$",
"factorG",
"=",
"(",
"$",
"e",
"[",
"1",
"]",
"-",
"$",
"s",
"[",
"1",
"]",
")",
"/",
"$",
"steps",
";",
"$",
"factorB",
"=",
"(",
"$",
"e",
"[",
"2",
"]",
"-",
"$",
"s",
"[",
"2",
"]",
")",
"/",
"$",
"steps",
";",
"for",
"(",
"$",
"x",
"=",
"1",
";",
"$",
"x",
"<",
"$",
"steps",
";",
"++",
"$",
"x",
")",
"{",
"$",
"colors",
"[",
"]",
"=",
"$",
"this",
"->",
"rgbToHex",
"(",
"(",
"int",
")",
"round",
"(",
"$",
"s",
"[",
"0",
"]",
"+",
"(",
"$",
"factorR",
"*",
"$",
"x",
")",
")",
",",
"(",
"int",
")",
"round",
"(",
"$",
"s",
"[",
"1",
"]",
"+",
"(",
"$",
"factorG",
"*",
"$",
"x",
")",
")",
",",
"(",
"int",
")",
"round",
"(",
"$",
"s",
"[",
"2",
"]",
"+",
"(",
"$",
"factorB",
"*",
"$",
"x",
")",
")",
")",
";",
"}",
"$",
"colors",
"[",
"]",
"=",
"$",
"this",
"->",
"rgbToHex",
"(",
"$",
"e",
"[",
"0",
"]",
",",
"$",
"e",
"[",
"1",
"]",
",",
"$",
"e",
"[",
"2",
"]",
")",
";",
"return",
"$",
"colors",
";",
"}"
] |
Interpolates the number of color steps between a given start and end color.
@param string $startColor The start color
@param string $endColor The end color
@param int $steps The number of steps to interpolate
@return array
|
[
"Interpolates",
"the",
"number",
"of",
"color",
"steps",
"between",
"a",
"given",
"start",
"and",
"end",
"color",
"."
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Statistics/Service/ColorService.php#L34-L58
|
train
|
fisharebest/webtrees
|
app/Statistics/Service/ColorService.php
|
ColorService.rgbToHex
|
private function rgbToHex(int $r, int $g, int $b): string
{
return sprintf('#%02x%02x%02x', $r, $g, $b);
}
|
php
|
private function rgbToHex(int $r, int $g, int $b): string
{
return sprintf('#%02x%02x%02x', $r, $g, $b);
}
|
[
"private",
"function",
"rgbToHex",
"(",
"int",
"$",
"r",
",",
"int",
"$",
"g",
",",
"int",
"$",
"b",
")",
":",
"string",
"{",
"return",
"sprintf",
"(",
"'#%02x%02x%02x'",
",",
"$",
"r",
",",
"$",
"g",
",",
"$",
"b",
")",
";",
"}"
] |
Converts the color values to the HTML hex representation.
@param int $r The red color value
@param int $g The green color value
@param int $b The blue color value
@return string
|
[
"Converts",
"the",
"color",
"values",
"to",
"the",
"HTML",
"hex",
"representation",
"."
] |
840bd0d721dc479520ec24a065996bc6becb8348
|
https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Statistics/Service/ColorService.php#L69-L72
|
train
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.