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/Http/Controllers/Admin/FixLevel0MediaController.php | FixLevel0MediaController.fixLevel0MediaAction | public function fixLevel0MediaAction(ServerRequestInterface $request): ResponseInterface
{
$fact_id = $request->getParsedBody()['fact_id'];
$indi_xref = $request->getParsedBody()['indi_xref'];
$obje_xref = $request->getParsedBody()['obje_xref'];
$tree_id = (int) $request->getParsedBody()['tree_id'];
$tree = Tree::findById($tree_id);
$individual = Individual::getInstance($indi_xref, $tree);
$media = Media::getInstance($obje_xref, $tree);
if ($individual !== null && $media !== null) {
foreach ($individual->facts() as $fact1) {
if ($fact1->id() === $fact_id) {
$individual->updateFact($fact_id, $fact1->gedcom() . "\n2 OBJE @" . $obje_xref . '@', false);
foreach ($individual->facts(['OBJE']) as $fact2) {
if ($fact2->target() === $media) {
$individual->deleteFact($fact2->id(), false);
}
}
break;
}
}
}
return response();
} | php | public function fixLevel0MediaAction(ServerRequestInterface $request): ResponseInterface
{
$fact_id = $request->getParsedBody()['fact_id'];
$indi_xref = $request->getParsedBody()['indi_xref'];
$obje_xref = $request->getParsedBody()['obje_xref'];
$tree_id = (int) $request->getParsedBody()['tree_id'];
$tree = Tree::findById($tree_id);
$individual = Individual::getInstance($indi_xref, $tree);
$media = Media::getInstance($obje_xref, $tree);
if ($individual !== null && $media !== null) {
foreach ($individual->facts() as $fact1) {
if ($fact1->id() === $fact_id) {
$individual->updateFact($fact_id, $fact1->gedcom() . "\n2 OBJE @" . $obje_xref . '@', false);
foreach ($individual->facts(['OBJE']) as $fact2) {
if ($fact2->target() === $media) {
$individual->deleteFact($fact2->id(), false);
}
}
break;
}
}
}
return response();
} | [
"public",
"function",
"fixLevel0MediaAction",
"(",
"ServerRequestInterface",
"$",
"request",
")",
":",
"ResponseInterface",
"{",
"$",
"fact_id",
"=",
"$",
"request",
"->",
"getParsedBody",
"(",
")",
"[",
"'fact_id'",
"]",
";",
"$",
"indi_xref",
"=",
"$",
"request",
"->",
"getParsedBody",
"(",
")",
"[",
"'indi_xref'",
"]",
";",
"$",
"obje_xref",
"=",
"$",
"request",
"->",
"getParsedBody",
"(",
")",
"[",
"'obje_xref'",
"]",
";",
"$",
"tree_id",
"=",
"(",
"int",
")",
"$",
"request",
"->",
"getParsedBody",
"(",
")",
"[",
"'tree_id'",
"]",
";",
"$",
"tree",
"=",
"Tree",
"::",
"findById",
"(",
"$",
"tree_id",
")",
";",
"$",
"individual",
"=",
"Individual",
"::",
"getInstance",
"(",
"$",
"indi_xref",
",",
"$",
"tree",
")",
";",
"$",
"media",
"=",
"Media",
"::",
"getInstance",
"(",
"$",
"obje_xref",
",",
"$",
"tree",
")",
";",
"if",
"(",
"$",
"individual",
"!==",
"null",
"&&",
"$",
"media",
"!==",
"null",
")",
"{",
"foreach",
"(",
"$",
"individual",
"->",
"facts",
"(",
")",
"as",
"$",
"fact1",
")",
"{",
"if",
"(",
"$",
"fact1",
"->",
"id",
"(",
")",
"===",
"$",
"fact_id",
")",
"{",
"$",
"individual",
"->",
"updateFact",
"(",
"$",
"fact_id",
",",
"$",
"fact1",
"->",
"gedcom",
"(",
")",
".",
"\"\\n2 OBJE @\"",
".",
"$",
"obje_xref",
".",
"'@'",
",",
"false",
")",
";",
"foreach",
"(",
"$",
"individual",
"->",
"facts",
"(",
"[",
"'OBJE'",
"]",
")",
"as",
"$",
"fact2",
")",
"{",
"if",
"(",
"$",
"fact2",
"->",
"target",
"(",
")",
"===",
"$",
"media",
")",
"{",
"$",
"individual",
"->",
"deleteFact",
"(",
"$",
"fact2",
"->",
"id",
"(",
")",
",",
"false",
")",
";",
"}",
"}",
"break",
";",
"}",
"}",
"}",
"return",
"response",
"(",
")",
";",
"}"
] | Move a link to a media object from a level 0 record to a level 1 record.
@param ServerRequestInterface $request
@return ResponseInterface | [
"Move",
"a",
"link",
"to",
"a",
"media",
"object",
"from",
"a",
"level",
"0",
"record",
"to",
"a",
"level",
"1",
"record",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Http/Controllers/Admin/FixLevel0MediaController.php#L57-L83 | train |
fisharebest/webtrees | app/Module/PedigreeMapModule.php | PedigreeMapModule.getSosaName | private function getSosaName(int $sosa): string
{
$path = '';
while ($sosa > 1) {
if ($sosa % 2 === 1) {
$path = 'mot' . $path;
} else {
$path = 'fat' . $path;
}
$sosa = intdiv($sosa, 2);
}
return Functions::getRelationshipNameFromPath($path);
} | php | private function getSosaName(int $sosa): string
{
$path = '';
while ($sosa > 1) {
if ($sosa % 2 === 1) {
$path = 'mot' . $path;
} else {
$path = 'fat' . $path;
}
$sosa = intdiv($sosa, 2);
}
return Functions::getRelationshipNameFromPath($path);
} | [
"private",
"function",
"getSosaName",
"(",
"int",
"$",
"sosa",
")",
":",
"string",
"{",
"$",
"path",
"=",
"''",
";",
"while",
"(",
"$",
"sosa",
">",
"1",
")",
"{",
"if",
"(",
"$",
"sosa",
"%",
"2",
"===",
"1",
")",
"{",
"$",
"path",
"=",
"'mot'",
".",
"$",
"path",
";",
"}",
"else",
"{",
"$",
"path",
"=",
"'fat'",
".",
"$",
"path",
";",
"}",
"$",
"sosa",
"=",
"intdiv",
"(",
"$",
"sosa",
",",
"2",
")",
";",
"}",
"return",
"Functions",
"::",
"getRelationshipNameFromPath",
"(",
"$",
"path",
")",
";",
"}"
] | builds and returns sosa relationship name in the active language
@param int $sosa Sosa number
@return string | [
"builds",
"and",
"returns",
"sosa",
"relationship",
"name",
"in",
"the",
"active",
"language"
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Module/PedigreeMapModule.php#L439-L453 | train |
fisharebest/webtrees | app/Functions/FunctionsPrint.php | FunctionsPrint.printFactNotes | public static function printFactNotes(Tree $tree, $factrec, $level): string
{
$data = '';
$previous_spos = 0;
$nlevel = $level + 1;
$ct = preg_match_all("/$level NOTE (.*)/", $factrec, $match, PREG_SET_ORDER);
for ($j = 0; $j < $ct; $j++) {
$spos1 = strpos($factrec, $match[$j][0], $previous_spos);
$spos2 = strpos($factrec . "\n$level", "\n$level", $spos1 + 1);
if (!$spos2) {
$spos2 = strlen($factrec);
}
$previous_spos = $spos2;
$nrec = substr($factrec, $spos1, $spos2 - $spos1);
if (!isset($match[$j][1])) {
$match[$j][1] = '';
}
if (!preg_match('/^@(' . Gedcom::REGEX_XREF . ')@$/', $match[$j][1], $nmatch)) {
$data .= self::printNoteRecord($tree, $match[$j][1], $nlevel, $nrec);
} else {
$note = Note::getInstance($nmatch[1], $tree);
if ($note) {
if ($note->canShow()) {
$noterec = $note->gedcom();
$nt = preg_match("/0 @$nmatch[1]@ NOTE (.*)/", $noterec, $n1match);
$data .= self::printNoteRecord($tree, ($nt > 0) ? $n1match[1] : '', 1, $noterec);
}
} else {
$data = '<div class="fact_NOTE"><span class="label">' . I18N::translate('Note') . '</span>: <span class="field error">' . $nmatch[1] . '</span></div>';
}
}
}
return $data;
} | php | public static function printFactNotes(Tree $tree, $factrec, $level): string
{
$data = '';
$previous_spos = 0;
$nlevel = $level + 1;
$ct = preg_match_all("/$level NOTE (.*)/", $factrec, $match, PREG_SET_ORDER);
for ($j = 0; $j < $ct; $j++) {
$spos1 = strpos($factrec, $match[$j][0], $previous_spos);
$spos2 = strpos($factrec . "\n$level", "\n$level", $spos1 + 1);
if (!$spos2) {
$spos2 = strlen($factrec);
}
$previous_spos = $spos2;
$nrec = substr($factrec, $spos1, $spos2 - $spos1);
if (!isset($match[$j][1])) {
$match[$j][1] = '';
}
if (!preg_match('/^@(' . Gedcom::REGEX_XREF . ')@$/', $match[$j][1], $nmatch)) {
$data .= self::printNoteRecord($tree, $match[$j][1], $nlevel, $nrec);
} else {
$note = Note::getInstance($nmatch[1], $tree);
if ($note) {
if ($note->canShow()) {
$noterec = $note->gedcom();
$nt = preg_match("/0 @$nmatch[1]@ NOTE (.*)/", $noterec, $n1match);
$data .= self::printNoteRecord($tree, ($nt > 0) ? $n1match[1] : '', 1, $noterec);
}
} else {
$data = '<div class="fact_NOTE"><span class="label">' . I18N::translate('Note') . '</span>: <span class="field error">' . $nmatch[1] . '</span></div>';
}
}
}
return $data;
} | [
"public",
"static",
"function",
"printFactNotes",
"(",
"Tree",
"$",
"tree",
",",
"$",
"factrec",
",",
"$",
"level",
")",
":",
"string",
"{",
"$",
"data",
"=",
"''",
";",
"$",
"previous_spos",
"=",
"0",
";",
"$",
"nlevel",
"=",
"$",
"level",
"+",
"1",
";",
"$",
"ct",
"=",
"preg_match_all",
"(",
"\"/$level NOTE (.*)/\"",
",",
"$",
"factrec",
",",
"$",
"match",
",",
"PREG_SET_ORDER",
")",
";",
"for",
"(",
"$",
"j",
"=",
"0",
";",
"$",
"j",
"<",
"$",
"ct",
";",
"$",
"j",
"++",
")",
"{",
"$",
"spos1",
"=",
"strpos",
"(",
"$",
"factrec",
",",
"$",
"match",
"[",
"$",
"j",
"]",
"[",
"0",
"]",
",",
"$",
"previous_spos",
")",
";",
"$",
"spos2",
"=",
"strpos",
"(",
"$",
"factrec",
".",
"\"\\n$level\"",
",",
"\"\\n$level\"",
",",
"$",
"spos1",
"+",
"1",
")",
";",
"if",
"(",
"!",
"$",
"spos2",
")",
"{",
"$",
"spos2",
"=",
"strlen",
"(",
"$",
"factrec",
")",
";",
"}",
"$",
"previous_spos",
"=",
"$",
"spos2",
";",
"$",
"nrec",
"=",
"substr",
"(",
"$",
"factrec",
",",
"$",
"spos1",
",",
"$",
"spos2",
"-",
"$",
"spos1",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"match",
"[",
"$",
"j",
"]",
"[",
"1",
"]",
")",
")",
"{",
"$",
"match",
"[",
"$",
"j",
"]",
"[",
"1",
"]",
"=",
"''",
";",
"}",
"if",
"(",
"!",
"preg_match",
"(",
"'/^@('",
".",
"Gedcom",
"::",
"REGEX_XREF",
".",
"')@$/'",
",",
"$",
"match",
"[",
"$",
"j",
"]",
"[",
"1",
"]",
",",
"$",
"nmatch",
")",
")",
"{",
"$",
"data",
".=",
"self",
"::",
"printNoteRecord",
"(",
"$",
"tree",
",",
"$",
"match",
"[",
"$",
"j",
"]",
"[",
"1",
"]",
",",
"$",
"nlevel",
",",
"$",
"nrec",
")",
";",
"}",
"else",
"{",
"$",
"note",
"=",
"Note",
"::",
"getInstance",
"(",
"$",
"nmatch",
"[",
"1",
"]",
",",
"$",
"tree",
")",
";",
"if",
"(",
"$",
"note",
")",
"{",
"if",
"(",
"$",
"note",
"->",
"canShow",
"(",
")",
")",
"{",
"$",
"noterec",
"=",
"$",
"note",
"->",
"gedcom",
"(",
")",
";",
"$",
"nt",
"=",
"preg_match",
"(",
"\"/0 @$nmatch[1]@ NOTE (.*)/\"",
",",
"$",
"noterec",
",",
"$",
"n1match",
")",
";",
"$",
"data",
".=",
"self",
"::",
"printNoteRecord",
"(",
"$",
"tree",
",",
"(",
"$",
"nt",
">",
"0",
")",
"?",
"$",
"n1match",
"[",
"1",
"]",
":",
"''",
",",
"1",
",",
"$",
"noterec",
")",
";",
"}",
"}",
"else",
"{",
"$",
"data",
"=",
"'<div class=\"fact_NOTE\"><span class=\"label\">'",
".",
"I18N",
"::",
"translate",
"(",
"'Note'",
")",
".",
"'</span>: <span class=\"field error\">'",
".",
"$",
"nmatch",
"[",
"1",
"]",
".",
"'</span></div>'",
";",
"}",
"}",
"}",
"return",
"$",
"data",
";",
"}"
] | Print all of the notes in this fact record
@param Tree $tree
@param string $factrec The factrecord to print the notes from
@param int $level The level of the factrecord
@return string HTML | [
"Print",
"all",
"of",
"the",
"notes",
"in",
"this",
"fact",
"record"
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Functions/FunctionsPrint.php#L104-L138 | train |
fisharebest/webtrees | app/Functions/FunctionsPrint.php | FunctionsPrint.helpLink | public static function helpLink($topic): string
{
return
'<a href="#" data-toggle="modal" data-target="#wt-ajax-modal" data-href="' . e(route('help-text', ['topic' => $topic])) . '" title="' . I18N::translate('Help') . '">' .
view('icons/help') .
'<span class="sr-only">' . I18N::translate('Help') . '</span>' .
'</a>';
} | php | public static function helpLink($topic): string
{
return
'<a href="#" data-toggle="modal" data-target="#wt-ajax-modal" data-href="' . e(route('help-text', ['topic' => $topic])) . '" title="' . I18N::translate('Help') . '">' .
view('icons/help') .
'<span class="sr-only">' . I18N::translate('Help') . '</span>' .
'</a>';
} | [
"public",
"static",
"function",
"helpLink",
"(",
"$",
"topic",
")",
":",
"string",
"{",
"return",
"'<a href=\"#\" data-toggle=\"modal\" data-target=\"#wt-ajax-modal\" data-href=\"'",
".",
"e",
"(",
"route",
"(",
"'help-text'",
",",
"[",
"'topic'",
"=>",
"$",
"topic",
"]",
")",
")",
".",
"'\" title=\"'",
".",
"I18N",
"::",
"translate",
"(",
"'Help'",
")",
".",
"'\">'",
".",
"view",
"(",
"'icons/help'",
")",
".",
"'<span class=\"sr-only\">'",
".",
"I18N",
"::",
"translate",
"(",
"'Help'",
")",
".",
"'</span>'",
".",
"'</a>'",
";",
"}"
] | Print a link for a popup help window.
@param string $topic
@return string | [
"Print",
"a",
"link",
"for",
"a",
"popup",
"help",
"window",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Functions/FunctionsPrint.php#L147-L154 | train |
fisharebest/webtrees | app/Functions/FunctionsPrint.php | FunctionsPrint.checkFactUnique | public static function checkFactUnique(array $uniquefacts, Collection $recfacts): array
{
foreach ($recfacts as $factarray) {
$fact = $factarray->getTag();
$key = array_search($fact, $uniquefacts, true);
if ($key !== false) {
unset($uniquefacts[$key]);
}
}
return $uniquefacts;
} | php | public static function checkFactUnique(array $uniquefacts, Collection $recfacts): array
{
foreach ($recfacts as $factarray) {
$fact = $factarray->getTag();
$key = array_search($fact, $uniquefacts, true);
if ($key !== false) {
unset($uniquefacts[$key]);
}
}
return $uniquefacts;
} | [
"public",
"static",
"function",
"checkFactUnique",
"(",
"array",
"$",
"uniquefacts",
",",
"Collection",
"$",
"recfacts",
")",
":",
"array",
"{",
"foreach",
"(",
"$",
"recfacts",
"as",
"$",
"factarray",
")",
"{",
"$",
"fact",
"=",
"$",
"factarray",
"->",
"getTag",
"(",
")",
";",
"$",
"key",
"=",
"array_search",
"(",
"$",
"fact",
",",
"$",
"uniquefacts",
",",
"true",
")",
";",
"if",
"(",
"$",
"key",
"!==",
"false",
")",
"{",
"unset",
"(",
"$",
"uniquefacts",
"[",
"$",
"key",
"]",
")",
";",
"}",
"}",
"return",
"$",
"uniquefacts",
";",
"}"
] | Check for facts that may exist only once for a certain record type.
If the fact already exists in the second array, delete it from the first one.
@param string[] $uniquefacts
@param Collection $recfacts
@return string[] | [
"Check",
"for",
"facts",
"that",
"may",
"exist",
"only",
"once",
"for",
"a",
"certain",
"record",
"type",
".",
"If",
"the",
"fact",
"already",
"exists",
"in",
"the",
"second",
"array",
"delete",
"it",
"from",
"the",
"first",
"one",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Functions/FunctionsPrint.php#L407-L419 | train |
fisharebest/webtrees | app/Http/Middleware/UseTheme.php | UseTheme.themes | private function themes(): Generator
{
$themes = $this->module_service->findByInterface(ModuleThemeInterface::class);
// Last theme used
yield $themes->get(Session::get('theme', ''));
// Default for tree
$tree = app(Tree::class);
if ($tree instanceof Tree) {
yield $themes->get($tree->getPreference('THEME_DIR'));
}
// Default for site
yield $themes->get(Site::getPreference('THEME_DIR'));
// Default for application
yield app(WebtreesTheme::class);
} | php | private function themes(): Generator
{
$themes = $this->module_service->findByInterface(ModuleThemeInterface::class);
// Last theme used
yield $themes->get(Session::get('theme', ''));
// Default for tree
$tree = app(Tree::class);
if ($tree instanceof Tree) {
yield $themes->get($tree->getPreference('THEME_DIR'));
}
// Default for site
yield $themes->get(Site::getPreference('THEME_DIR'));
// Default for application
yield app(WebtreesTheme::class);
} | [
"private",
"function",
"themes",
"(",
")",
":",
"Generator",
"{",
"$",
"themes",
"=",
"$",
"this",
"->",
"module_service",
"->",
"findByInterface",
"(",
"ModuleThemeInterface",
"::",
"class",
")",
";",
"// Last theme used",
"yield",
"$",
"themes",
"->",
"get",
"(",
"Session",
"::",
"get",
"(",
"'theme'",
",",
"''",
")",
")",
";",
"// Default for tree",
"$",
"tree",
"=",
"app",
"(",
"Tree",
"::",
"class",
")",
";",
"if",
"(",
"$",
"tree",
"instanceof",
"Tree",
")",
"{",
"yield",
"$",
"themes",
"->",
"get",
"(",
"$",
"tree",
"->",
"getPreference",
"(",
"'THEME_DIR'",
")",
")",
";",
"}",
"// Default for site",
"yield",
"$",
"themes",
"->",
"get",
"(",
"Site",
"::",
"getPreference",
"(",
"'THEME_DIR'",
")",
")",
";",
"// Default for application",
"yield",
"app",
"(",
"WebtreesTheme",
"::",
"class",
")",
";",
"}"
] | The theme can be chosen in various ways.
@return Generator | [
"The",
"theme",
"can",
"be",
"chosen",
"in",
"various",
"ways",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Http/Middleware/UseTheme.php#L78-L97 | train |
fisharebest/webtrees | app/Services/MigrationService.php | MigrationService.updateSchema | public function updateSchema($namespace, $schema_name, $target_version): bool
{
try {
$current_version = (int) Site::getPreference($schema_name);
} catch (PDOException $ex) {
// During initial installation, the site_preference table won’t exist.
$current_version = 0;
}
$updates_applied = false;
// Update the schema, one version at a time.
while ($current_version < $target_version) {
$class = $namespace . '\\Migration' . $current_version;
/** @var MigrationInterface $migration */
$migration = new $class();
$migration->upgrade();
$current_version++;
Site::setPreference($schema_name, (string) $current_version);
$updates_applied = true;
}
return $updates_applied;
} | php | public function updateSchema($namespace, $schema_name, $target_version): bool
{
try {
$current_version = (int) Site::getPreference($schema_name);
} catch (PDOException $ex) {
// During initial installation, the site_preference table won’t exist.
$current_version = 0;
}
$updates_applied = false;
// Update the schema, one version at a time.
while ($current_version < $target_version) {
$class = $namespace . '\\Migration' . $current_version;
/** @var MigrationInterface $migration */
$migration = new $class();
$migration->upgrade();
$current_version++;
Site::setPreference($schema_name, (string) $current_version);
$updates_applied = true;
}
return $updates_applied;
} | [
"public",
"function",
"updateSchema",
"(",
"$",
"namespace",
",",
"$",
"schema_name",
",",
"$",
"target_version",
")",
":",
"bool",
"{",
"try",
"{",
"$",
"current_version",
"=",
"(",
"int",
")",
"Site",
"::",
"getPreference",
"(",
"$",
"schema_name",
")",
";",
"}",
"catch",
"(",
"PDOException",
"$",
"ex",
")",
"{",
"// During initial installation, the site_preference table won’t exist.",
"$",
"current_version",
"=",
"0",
";",
"}",
"$",
"updates_applied",
"=",
"false",
";",
"// Update the schema, one version at a time.",
"while",
"(",
"$",
"current_version",
"<",
"$",
"target_version",
")",
"{",
"$",
"class",
"=",
"$",
"namespace",
".",
"'\\\\Migration'",
".",
"$",
"current_version",
";",
"/** @var MigrationInterface $migration */",
"$",
"migration",
"=",
"new",
"$",
"class",
"(",
")",
";",
"$",
"migration",
"->",
"upgrade",
"(",
")",
";",
"$",
"current_version",
"++",
";",
"Site",
"::",
"setPreference",
"(",
"$",
"schema_name",
",",
"(",
"string",
")",
"$",
"current_version",
")",
";",
"$",
"updates_applied",
"=",
"true",
";",
"}",
"return",
"$",
"updates_applied",
";",
"}"
] | Run a series of scripts to bring the database schema up to date.
@param string $namespace Where to find our MigrationXXX classes
@param string $schema_name Which schema to update.
@param int $target_version Updade to this version
@throws PDOException
@return bool Were any updates applied | [
"Run",
"a",
"series",
"of",
"scripts",
"to",
"bring",
"the",
"database",
"schema",
"up",
"to",
"date",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Services/MigrationService.php#L44-L67 | train |
fisharebest/webtrees | app/Services/MigrationService.php | MigrationService.seedDatabase | public function seedDatabase(): void
{
(new SeedSiteSettingTable())->run();
(new SeedUserTable())->run();
(new SeedGedcomTable())->run();
(new SeedGedcomSettingTable())->run();
(new SeedDefaultResnTable())->run();
} | php | public function seedDatabase(): void
{
(new SeedSiteSettingTable())->run();
(new SeedUserTable())->run();
(new SeedGedcomTable())->run();
(new SeedGedcomSettingTable())->run();
(new SeedDefaultResnTable())->run();
} | [
"public",
"function",
"seedDatabase",
"(",
")",
":",
"void",
"{",
"(",
"new",
"SeedSiteSettingTable",
"(",
")",
")",
"->",
"run",
"(",
")",
";",
"(",
"new",
"SeedUserTable",
"(",
")",
")",
"->",
"run",
"(",
")",
";",
"(",
"new",
"SeedGedcomTable",
"(",
")",
")",
"->",
"run",
"(",
")",
";",
"(",
"new",
"SeedGedcomSettingTable",
"(",
")",
")",
"->",
"run",
"(",
")",
";",
"(",
"new",
"SeedDefaultResnTable",
"(",
")",
")",
"->",
"run",
"(",
")",
";",
"}"
] | Write default data to the database.
@return void | [
"Write",
"default",
"data",
"to",
"the",
"database",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Services/MigrationService.php#L74-L81 | train |
fisharebest/webtrees | app/Application.php | Application.dispatch | public function dispatch($object, string $method)
{
$reflector = new ReflectionMethod($object, $method);
$parameters = $this->makeParameters($reflector->getParameters());
return $reflector->invoke($object, ...$parameters);
} | php | public function dispatch($object, string $method)
{
$reflector = new ReflectionMethod($object, $method);
$parameters = $this->makeParameters($reflector->getParameters());
return $reflector->invoke($object, ...$parameters);
} | [
"public",
"function",
"dispatch",
"(",
"$",
"object",
",",
"string",
"$",
"method",
")",
"{",
"$",
"reflector",
"=",
"new",
"ReflectionMethod",
"(",
"$",
"object",
",",
"$",
"method",
")",
";",
"$",
"parameters",
"=",
"$",
"this",
"->",
"makeParameters",
"(",
"$",
"reflector",
"->",
"getParameters",
"(",
")",
")",
";",
"return",
"$",
"reflector",
"->",
"invoke",
"(",
"$",
"object",
",",
"...",
"$",
"parameters",
")",
";",
"}"
] | Call an object's method, injecting all its dependencies.
@param object $object
@param string $method
@return mixed | [
"Call",
"an",
"object",
"s",
"method",
"injecting",
"all",
"its",
"dependencies",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Application.php#L39-L46 | train |
fisharebest/webtrees | app/MediaFile.php | MediaFile.fileSizeKB | public function fileSizeKB(): string
{
$size = $this->fileSizeBytes();
$size = intdiv($size + 1023, 1024);
/* I18N: size of file in KB */
return I18N::translate('%s KB', I18N::number($size));
} | php | public function fileSizeKB(): string
{
$size = $this->fileSizeBytes();
$size = intdiv($size + 1023, 1024);
/* I18N: size of file in KB */
return I18N::translate('%s KB', I18N::number($size));
} | [
"public",
"function",
"fileSizeKB",
"(",
")",
":",
"string",
"{",
"$",
"size",
"=",
"$",
"this",
"->",
"fileSizeBytes",
"(",
")",
";",
"$",
"size",
"=",
"intdiv",
"(",
"$",
"size",
"+",
"1023",
",",
"1024",
")",
";",
"/* I18N: size of file in KB */",
"return",
"I18N",
"::",
"translate",
"(",
"'%s KB'",
",",
"I18N",
"::",
"number",
"(",
"$",
"size",
")",
")",
";",
"}"
] | get the media file size in KB
@return string | [
"get",
"the",
"media",
"file",
"size",
"in",
"KB"
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/MediaFile.php#L340-L347 | train |
fisharebest/webtrees | app/MediaFile.php | MediaFile.downloadUrl | public function downloadUrl(): string
{
return route('media-download', [
'xref' => $this->media->xref(),
'ged' => $this->media->tree()->name(),
'fact_id' => $this->fact_id,
]);
} | php | public function downloadUrl(): string
{
return route('media-download', [
'xref' => $this->media->xref(),
'ged' => $this->media->tree()->name(),
'fact_id' => $this->fact_id,
]);
} | [
"public",
"function",
"downloadUrl",
"(",
")",
":",
"string",
"{",
"return",
"route",
"(",
"'media-download'",
",",
"[",
"'xref'",
"=>",
"$",
"this",
"->",
"media",
"->",
"xref",
"(",
")",
",",
"'ged'",
"=>",
"$",
"this",
"->",
"media",
"->",
"tree",
"(",
")",
"->",
"name",
"(",
")",
",",
"'fact_id'",
"=>",
"$",
"this",
"->",
"fact_id",
",",
"]",
")",
";",
"}"
] | Generate a URL to download a non-image media file.
@return string | [
"Generate",
"a",
"URL",
"to",
"download",
"a",
"non",
"-",
"image",
"media",
"file",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/MediaFile.php#L373-L380 | train |
fisharebest/webtrees | app/MediaFile.php | MediaFile.imageUrl | public function imageUrl($width, $height, $fit): string
{
// Sign the URL, to protect against mass-resize attacks.
$glide_key = Site::getPreference('glide-key');
if (empty($glide_key)) {
$glide_key = bin2hex(random_bytes(128));
Site::setPreference('glide-key', $glide_key);
}
if (Auth::accessLevel($this->media->tree()) > $this->media->tree()->getPreference('SHOW_NO_WATERMARK')) {
$mark = 'watermark.png';
} else {
$mark = '';
}
$url_builder = UrlBuilderFactory::create(WT_BASE_URL, $glide_key);
$url = $url_builder->getUrl('index.php', [
'route' => 'media-thumbnail',
'xref' => $this->media->xref(),
'ged' => $this->media->tree()->name(),
'fact_id' => $this->fact_id,
'w' => $width,
'h' => $height,
'fit' => $fit,
'mark' => $mark,
'markh' => '100h',
'markw' => '100w',
'markalpha' => 25,
'or' => 0,
// Intervention uses exif_read_data() which is very buggy.
]);
return $url;
} | php | public function imageUrl($width, $height, $fit): string
{
// Sign the URL, to protect against mass-resize attacks.
$glide_key = Site::getPreference('glide-key');
if (empty($glide_key)) {
$glide_key = bin2hex(random_bytes(128));
Site::setPreference('glide-key', $glide_key);
}
if (Auth::accessLevel($this->media->tree()) > $this->media->tree()->getPreference('SHOW_NO_WATERMARK')) {
$mark = 'watermark.png';
} else {
$mark = '';
}
$url_builder = UrlBuilderFactory::create(WT_BASE_URL, $glide_key);
$url = $url_builder->getUrl('index.php', [
'route' => 'media-thumbnail',
'xref' => $this->media->xref(),
'ged' => $this->media->tree()->name(),
'fact_id' => $this->fact_id,
'w' => $width,
'h' => $height,
'fit' => $fit,
'mark' => $mark,
'markh' => '100h',
'markw' => '100w',
'markalpha' => 25,
'or' => 0,
// Intervention uses exif_read_data() which is very buggy.
]);
return $url;
} | [
"public",
"function",
"imageUrl",
"(",
"$",
"width",
",",
"$",
"height",
",",
"$",
"fit",
")",
":",
"string",
"{",
"// Sign the URL, to protect against mass-resize attacks.",
"$",
"glide_key",
"=",
"Site",
"::",
"getPreference",
"(",
"'glide-key'",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"glide_key",
")",
")",
"{",
"$",
"glide_key",
"=",
"bin2hex",
"(",
"random_bytes",
"(",
"128",
")",
")",
";",
"Site",
"::",
"setPreference",
"(",
"'glide-key'",
",",
"$",
"glide_key",
")",
";",
"}",
"if",
"(",
"Auth",
"::",
"accessLevel",
"(",
"$",
"this",
"->",
"media",
"->",
"tree",
"(",
")",
")",
">",
"$",
"this",
"->",
"media",
"->",
"tree",
"(",
")",
"->",
"getPreference",
"(",
"'SHOW_NO_WATERMARK'",
")",
")",
"{",
"$",
"mark",
"=",
"'watermark.png'",
";",
"}",
"else",
"{",
"$",
"mark",
"=",
"''",
";",
"}",
"$",
"url_builder",
"=",
"UrlBuilderFactory",
"::",
"create",
"(",
"WT_BASE_URL",
",",
"$",
"glide_key",
")",
";",
"$",
"url",
"=",
"$",
"url_builder",
"->",
"getUrl",
"(",
"'index.php'",
",",
"[",
"'route'",
"=>",
"'media-thumbnail'",
",",
"'xref'",
"=>",
"$",
"this",
"->",
"media",
"->",
"xref",
"(",
")",
",",
"'ged'",
"=>",
"$",
"this",
"->",
"media",
"->",
"tree",
"(",
")",
"->",
"name",
"(",
")",
",",
"'fact_id'",
"=>",
"$",
"this",
"->",
"fact_id",
",",
"'w'",
"=>",
"$",
"width",
",",
"'h'",
"=>",
"$",
"height",
",",
"'fit'",
"=>",
"$",
"fit",
",",
"'mark'",
"=>",
"$",
"mark",
",",
"'markh'",
"=>",
"'100h'",
",",
"'markw'",
"=>",
"'100w'",
",",
"'markalpha'",
"=>",
"25",
",",
"'or'",
"=>",
"0",
",",
"// Intervention uses exif_read_data() which is very buggy.",
"]",
")",
";",
"return",
"$",
"url",
";",
"}"
] | Generate a URL for an image.
@param int $width Maximum width in pixels
@param int $height Maximum height in pixels
@param string $fit "crop" or "contain"
@return string | [
"Generate",
"a",
"URL",
"for",
"an",
"image",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/MediaFile.php#L391-L425 | train |
fisharebest/webtrees | app/Statistics.php | Statistics.getAllTagsTable | public function getAllTagsTable(): string
{
$examples = [];
foreach (get_class_methods($this) as $method) {
$reflection = new ReflectionMethod($this, $method);
if ($reflection->isPublic() && !in_array($method, self::$public_but_not_allowed, true) && (string) $reflection->getReturnType() !== Builder::class) {
$examples[$method] = $this->$method();
}
}
ksort($examples);
$html = '';
foreach ($examples as $tag => $value) {
$html .= '<dt>#' . $tag . '#</dt>';
$html .= '<dd>' . $value . '</dd>';
}
return '<dl>' . $html . '</dl>';
} | php | public function getAllTagsTable(): string
{
$examples = [];
foreach (get_class_methods($this) as $method) {
$reflection = new ReflectionMethod($this, $method);
if ($reflection->isPublic() && !in_array($method, self::$public_but_not_allowed, true) && (string) $reflection->getReturnType() !== Builder::class) {
$examples[$method] = $this->$method();
}
}
ksort($examples);
$html = '';
foreach ($examples as $tag => $value) {
$html .= '<dt>#' . $tag . '#</dt>';
$html .= '<dd>' . $value . '</dd>';
}
return '<dl>' . $html . '</dl>';
} | [
"public",
"function",
"getAllTagsTable",
"(",
")",
":",
"string",
"{",
"$",
"examples",
"=",
"[",
"]",
";",
"foreach",
"(",
"get_class_methods",
"(",
"$",
"this",
")",
"as",
"$",
"method",
")",
"{",
"$",
"reflection",
"=",
"new",
"ReflectionMethod",
"(",
"$",
"this",
",",
"$",
"method",
")",
";",
"if",
"(",
"$",
"reflection",
"->",
"isPublic",
"(",
")",
"&&",
"!",
"in_array",
"(",
"$",
"method",
",",
"self",
"::",
"$",
"public_but_not_allowed",
",",
"true",
")",
"&&",
"(",
"string",
")",
"$",
"reflection",
"->",
"getReturnType",
"(",
")",
"!==",
"Builder",
"::",
"class",
")",
"{",
"$",
"examples",
"[",
"$",
"method",
"]",
"=",
"$",
"this",
"->",
"$",
"method",
"(",
")",
";",
"}",
"}",
"ksort",
"(",
"$",
"examples",
")",
";",
"$",
"html",
"=",
"''",
";",
"foreach",
"(",
"$",
"examples",
"as",
"$",
"tag",
"=>",
"$",
"value",
")",
"{",
"$",
"html",
".=",
"'<dt>#'",
".",
"$",
"tag",
".",
"'#</dt>'",
";",
"$",
"html",
".=",
"'<dd>'",
".",
"$",
"value",
".",
"'</dd>'",
";",
"}",
"return",
"'<dl>'",
".",
"$",
"html",
".",
"'</dl>'",
";",
"}"
] | Return a string of all supported tags and an example of its output in table row form.
@return string | [
"Return",
"a",
"string",
"of",
"all",
"supported",
"tags",
"and",
"an",
"example",
"of",
"its",
"output",
"in",
"table",
"row",
"form",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Statistics.php#L229-L249 | train |
fisharebest/webtrees | app/Statistics.php | Statistics.getAllTagsText | public function getAllTagsText(): string
{
$examples = [];
foreach (get_class_methods($this) as $method) {
$reflection = new ReflectionMethod($this, $method);
if ($reflection->isPublic() && !in_array($method, self::$public_but_not_allowed, true) && (string) $reflection->getReturnType() !== Builder::class) {
$examples[$method] = $method;
}
}
ksort($examples);
return implode('<br>', $examples);
} | php | public function getAllTagsText(): string
{
$examples = [];
foreach (get_class_methods($this) as $method) {
$reflection = new ReflectionMethod($this, $method);
if ($reflection->isPublic() && !in_array($method, self::$public_but_not_allowed, true) && (string) $reflection->getReturnType() !== Builder::class) {
$examples[$method] = $method;
}
}
ksort($examples);
return implode('<br>', $examples);
} | [
"public",
"function",
"getAllTagsText",
"(",
")",
":",
"string",
"{",
"$",
"examples",
"=",
"[",
"]",
";",
"foreach",
"(",
"get_class_methods",
"(",
"$",
"this",
")",
"as",
"$",
"method",
")",
"{",
"$",
"reflection",
"=",
"new",
"ReflectionMethod",
"(",
"$",
"this",
",",
"$",
"method",
")",
";",
"if",
"(",
"$",
"reflection",
"->",
"isPublic",
"(",
")",
"&&",
"!",
"in_array",
"(",
"$",
"method",
",",
"self",
"::",
"$",
"public_but_not_allowed",
",",
"true",
")",
"&&",
"(",
"string",
")",
"$",
"reflection",
"->",
"getReturnType",
"(",
")",
"!==",
"Builder",
"::",
"class",
")",
"{",
"$",
"examples",
"[",
"$",
"method",
"]",
"=",
"$",
"method",
";",
"}",
"}",
"ksort",
"(",
"$",
"examples",
")",
";",
"return",
"implode",
"(",
"'<br>'",
",",
"$",
"examples",
")",
";",
"}"
] | Return a string of all supported tags in plain text.
@return string | [
"Return",
"a",
"string",
"of",
"all",
"supported",
"tags",
"in",
"plain",
"text",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Statistics.php#L256-L270 | train |
fisharebest/webtrees | app/Statistics.php | Statistics.getTags | private function getTags(string $text): array
{
$tags = [];
$matches = [];
preg_match_all('/#([^#]+)#/', $text, $matches, PREG_SET_ORDER);
foreach ($matches as $match) {
$params = explode(':', $match[1]);
$method = array_shift($params);
if (method_exists($this, $method)) {
$tags[$match[0]] = $this->$method(...$params);
}
}
return $tags;
} | php | private function getTags(string $text): array
{
$tags = [];
$matches = [];
preg_match_all('/#([^#]+)#/', $text, $matches, PREG_SET_ORDER);
foreach ($matches as $match) {
$params = explode(':', $match[1]);
$method = array_shift($params);
if (method_exists($this, $method)) {
$tags[$match[0]] = $this->$method(...$params);
}
}
return $tags;
} | [
"private",
"function",
"getTags",
"(",
"string",
"$",
"text",
")",
":",
"array",
"{",
"$",
"tags",
"=",
"[",
"]",
";",
"$",
"matches",
"=",
"[",
"]",
";",
"preg_match_all",
"(",
"'/#([^#]+)#/'",
",",
"$",
"text",
",",
"$",
"matches",
",",
"PREG_SET_ORDER",
")",
";",
"foreach",
"(",
"$",
"matches",
"as",
"$",
"match",
")",
"{",
"$",
"params",
"=",
"explode",
"(",
"':'",
",",
"$",
"match",
"[",
"1",
"]",
")",
";",
"$",
"method",
"=",
"array_shift",
"(",
"$",
"params",
")",
";",
"if",
"(",
"method_exists",
"(",
"$",
"this",
",",
"$",
"method",
")",
")",
"{",
"$",
"tags",
"[",
"$",
"match",
"[",
"0",
"]",
"]",
"=",
"$",
"this",
"->",
"$",
"method",
"(",
"...",
"$",
"params",
")",
";",
"}",
"}",
"return",
"$",
"tags",
";",
"}"
] | Get tags and their parsed results.
@param string $text
@return string[] | [
"Get",
"tags",
"and",
"their",
"parsed",
"results",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Statistics.php#L279-L296 | train |
fisharebest/webtrees | app/Statistics.php | Statistics.embedTags | public function embedTags(string $text): string
{
if (strpos($text, '#') !== false) {
$text = strtr($text, $this->getTags($text));
}
return $text;
} | php | public function embedTags(string $text): string
{
if (strpos($text, '#') !== false) {
$text = strtr($text, $this->getTags($text));
}
return $text;
} | [
"public",
"function",
"embedTags",
"(",
"string",
"$",
"text",
")",
":",
"string",
"{",
"if",
"(",
"strpos",
"(",
"$",
"text",
",",
"'#'",
")",
"!==",
"false",
")",
"{",
"$",
"text",
"=",
"strtr",
"(",
"$",
"text",
",",
"$",
"this",
"->",
"getTags",
"(",
"$",
"text",
")",
")",
";",
"}",
"return",
"$",
"text",
";",
"}"
] | Embed tags in text
@param string $text
@return string | [
"Embed",
"tags",
"in",
"text"
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Statistics.php#L305-L312 | train |
fisharebest/webtrees | app/Module/RecentChangesModule.php | RecentChangesModule.getRecentChanges | private function getRecentChanges(Tree $tree, int $days): array
{
return DB::table('change')
->where('gedcom_id', '=', $tree->id())
->where('status', '=', 'accepted')
->where('new_gedcom', '<>', '')
->where('change_time', '>', Carbon::now()->subDays($days))
->groupBy('xref')
->pluck('xref')
->map(static function (string $xref) use ($tree): ?GedcomRecord {
return GedcomRecord::getInstance($xref, $tree);
})
->filter(static function (?GedcomRecord $record): bool {
return $record instanceof GedcomRecord && $record->canShow();
})
->all();
} | php | private function getRecentChanges(Tree $tree, int $days): array
{
return DB::table('change')
->where('gedcom_id', '=', $tree->id())
->where('status', '=', 'accepted')
->where('new_gedcom', '<>', '')
->where('change_time', '>', Carbon::now()->subDays($days))
->groupBy('xref')
->pluck('xref')
->map(static function (string $xref) use ($tree): ?GedcomRecord {
return GedcomRecord::getInstance($xref, $tree);
})
->filter(static function (?GedcomRecord $record): bool {
return $record instanceof GedcomRecord && $record->canShow();
})
->all();
} | [
"private",
"function",
"getRecentChanges",
"(",
"Tree",
"$",
"tree",
",",
"int",
"$",
"days",
")",
":",
"array",
"{",
"return",
"DB",
"::",
"table",
"(",
"'change'",
")",
"->",
"where",
"(",
"'gedcom_id'",
",",
"'='",
",",
"$",
"tree",
"->",
"id",
"(",
")",
")",
"->",
"where",
"(",
"'status'",
",",
"'='",
",",
"'accepted'",
")",
"->",
"where",
"(",
"'new_gedcom'",
",",
"'<>'",
",",
"''",
")",
"->",
"where",
"(",
"'change_time'",
",",
"'>'",
",",
"Carbon",
"::",
"now",
"(",
")",
"->",
"subDays",
"(",
"$",
"days",
")",
")",
"->",
"groupBy",
"(",
"'xref'",
")",
"->",
"pluck",
"(",
"'xref'",
")",
"->",
"map",
"(",
"static",
"function",
"(",
"string",
"$",
"xref",
")",
"use",
"(",
"$",
"tree",
")",
":",
"?",
"GedcomRecord",
"{",
"return",
"GedcomRecord",
"::",
"getInstance",
"(",
"$",
"xref",
",",
"$",
"tree",
")",
";",
"}",
")",
"->",
"filter",
"(",
"static",
"function",
"(",
"?",
"GedcomRecord",
"$",
"record",
")",
":",
"bool",
"{",
"return",
"$",
"record",
"instanceof",
"GedcomRecord",
"&&",
"$",
"record",
"->",
"canShow",
"(",
")",
";",
"}",
")",
"->",
"all",
"(",
")",
";",
"}"
] | Find records that have changed since a given julian day
@param Tree $tree Changes for which tree
@param int $days Number of days
@return GedcomRecord[] List of records with changes | [
"Find",
"records",
"that",
"have",
"changed",
"since",
"a",
"given",
"julian",
"day"
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Module/RecentChangesModule.php#L220-L236 | train |
fisharebest/webtrees | app/Http/Controllers/HelpTextController.php | HelpTextController.formatDates | private function formatDates(array $gedcom_dates): array
{
$dates = [];
foreach ($gedcom_dates as $gedcom_date) {
// PHP converts numeric array keys ('1900') to integers (1900), so reverse this.
$gedcom_date = (string) $gedcom_date;
$date = new Date($gedcom_date);
$dates[$gedcom_date] = strip_tags($date->display(false, null, false));
}
return $dates;
} | php | private function formatDates(array $gedcom_dates): array
{
$dates = [];
foreach ($gedcom_dates as $gedcom_date) {
// PHP converts numeric array keys ('1900') to integers (1900), so reverse this.
$gedcom_date = (string) $gedcom_date;
$date = new Date($gedcom_date);
$dates[$gedcom_date] = strip_tags($date->display(false, null, false));
}
return $dates;
} | [
"private",
"function",
"formatDates",
"(",
"array",
"$",
"gedcom_dates",
")",
":",
"array",
"{",
"$",
"dates",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"gedcom_dates",
"as",
"$",
"gedcom_date",
")",
"{",
"// PHP converts numeric array keys ('1900') to integers (1900), so reverse this.",
"$",
"gedcom_date",
"=",
"(",
"string",
")",
"$",
"gedcom_date",
";",
"$",
"date",
"=",
"new",
"Date",
"(",
"$",
"gedcom_date",
")",
";",
"$",
"dates",
"[",
"$",
"gedcom_date",
"]",
"=",
"strip_tags",
"(",
"$",
"date",
"->",
"display",
"(",
"false",
",",
"null",
",",
"false",
")",
")",
";",
"}",
"return",
"$",
"dates",
";",
"}"
] | Format GEDCOM dates in the local language.
@param string[] $gedcom_dates
@return string[] | [
"Format",
"GEDCOM",
"dates",
"in",
"the",
"local",
"language",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Http/Controllers/HelpTextController.php#L277-L290 | train |
fisharebest/webtrees | app/Module/UserMessagesModule.php | UserMessagesModule.postDeleteMessageAction | public function postDeleteMessageAction(ServerRequestInterface $request, Tree $tree): ResponseInterface
{
$message_ids = (array) $request->get('message_id', []);
DB::table('message')
->where('user_id', '=', Auth::id())
->whereIn('message_id', $message_ids)
->delete();
if ($request->get('ctype') === 'user') {
$url = route('user-page', ['ged' => $tree->name()]);
} else {
$url = route('tree-page', ['ged' => $tree->name()]);
}
return redirect($url);
} | php | public function postDeleteMessageAction(ServerRequestInterface $request, Tree $tree): ResponseInterface
{
$message_ids = (array) $request->get('message_id', []);
DB::table('message')
->where('user_id', '=', Auth::id())
->whereIn('message_id', $message_ids)
->delete();
if ($request->get('ctype') === 'user') {
$url = route('user-page', ['ged' => $tree->name()]);
} else {
$url = route('tree-page', ['ged' => $tree->name()]);
}
return redirect($url);
} | [
"public",
"function",
"postDeleteMessageAction",
"(",
"ServerRequestInterface",
"$",
"request",
",",
"Tree",
"$",
"tree",
")",
":",
"ResponseInterface",
"{",
"$",
"message_ids",
"=",
"(",
"array",
")",
"$",
"request",
"->",
"get",
"(",
"'message_id'",
",",
"[",
"]",
")",
";",
"DB",
"::",
"table",
"(",
"'message'",
")",
"->",
"where",
"(",
"'user_id'",
",",
"'='",
",",
"Auth",
"::",
"id",
"(",
")",
")",
"->",
"whereIn",
"(",
"'message_id'",
",",
"$",
"message_ids",
")",
"->",
"delete",
"(",
")",
";",
"if",
"(",
"$",
"request",
"->",
"get",
"(",
"'ctype'",
")",
"===",
"'user'",
")",
"{",
"$",
"url",
"=",
"route",
"(",
"'user-page'",
",",
"[",
"'ged'",
"=>",
"$",
"tree",
"->",
"name",
"(",
")",
"]",
")",
";",
"}",
"else",
"{",
"$",
"url",
"=",
"route",
"(",
"'tree-page'",
",",
"[",
"'ged'",
"=>",
"$",
"tree",
"->",
"name",
"(",
")",
"]",
")",
";",
"}",
"return",
"redirect",
"(",
"$",
"url",
")",
";",
"}"
] | Delete one or messages belonging to a user.
@param ServerRequestInterface $request
@param Tree $tree
@return ResponseInterface | [
"Delete",
"one",
"or",
"messages",
"belonging",
"to",
"a",
"user",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Module/UserMessagesModule.php#L86-L102 | train |
fisharebest/webtrees | app/Module/AlbumModule.php | AlbumModule.getMedia | private function getMedia(Individual $individual): array
{
if ($this->media_list === null) {
// Use facts from this individual and all their spouses
$facts = $individual->facts();
foreach ($individual->spouseFamilies() as $family) {
foreach ($family->facts() as $fact) {
$facts->push($fact);
}
}
// Use all media from each fact
$this->media_list = [];
foreach ($facts as $fact) {
// Don't show pending edits, as the user just sees duplicates
if (!$fact->isPendingDeletion()) {
preg_match_all('/(?:^1|\n\d) OBJE @(' . Gedcom::REGEX_XREF . ')@/', $fact->gedcom(), $matches);
foreach ($matches[1] as $match) {
$media = Media::getInstance($match, $individual->tree());
if ($media && $media->canShow()) {
$this->media_list[] = $media;
}
}
}
}
// If a media object is linked twice, only show it once
$this->media_list = array_unique($this->media_list);
// Sort these using _WT_OBJE_SORT
$wt_obje_sort = [];
foreach ($individual->facts(['_WT_OBJE_SORT']) as $fact) {
$wt_obje_sort[] = trim($fact->value(), '@');
}
usort($this->media_list, static function (Media $x, Media $y) use ($wt_obje_sort): int {
return array_search($x->xref(), $wt_obje_sort, true) - array_search($y->xref(), $wt_obje_sort, true);
});
}
return $this->media_list;
} | php | private function getMedia(Individual $individual): array
{
if ($this->media_list === null) {
// Use facts from this individual and all their spouses
$facts = $individual->facts();
foreach ($individual->spouseFamilies() as $family) {
foreach ($family->facts() as $fact) {
$facts->push($fact);
}
}
// Use all media from each fact
$this->media_list = [];
foreach ($facts as $fact) {
// Don't show pending edits, as the user just sees duplicates
if (!$fact->isPendingDeletion()) {
preg_match_all('/(?:^1|\n\d) OBJE @(' . Gedcom::REGEX_XREF . ')@/', $fact->gedcom(), $matches);
foreach ($matches[1] as $match) {
$media = Media::getInstance($match, $individual->tree());
if ($media && $media->canShow()) {
$this->media_list[] = $media;
}
}
}
}
// If a media object is linked twice, only show it once
$this->media_list = array_unique($this->media_list);
// Sort these using _WT_OBJE_SORT
$wt_obje_sort = [];
foreach ($individual->facts(['_WT_OBJE_SORT']) as $fact) {
$wt_obje_sort[] = trim($fact->value(), '@');
}
usort($this->media_list, static function (Media $x, Media $y) use ($wt_obje_sort): int {
return array_search($x->xref(), $wt_obje_sort, true) - array_search($y->xref(), $wt_obje_sort, true);
});
}
return $this->media_list;
} | [
"private",
"function",
"getMedia",
"(",
"Individual",
"$",
"individual",
")",
":",
"array",
"{",
"if",
"(",
"$",
"this",
"->",
"media_list",
"===",
"null",
")",
"{",
"// Use facts from this individual and all their spouses",
"$",
"facts",
"=",
"$",
"individual",
"->",
"facts",
"(",
")",
";",
"foreach",
"(",
"$",
"individual",
"->",
"spouseFamilies",
"(",
")",
"as",
"$",
"family",
")",
"{",
"foreach",
"(",
"$",
"family",
"->",
"facts",
"(",
")",
"as",
"$",
"fact",
")",
"{",
"$",
"facts",
"->",
"push",
"(",
"$",
"fact",
")",
";",
"}",
"}",
"// Use all media from each fact",
"$",
"this",
"->",
"media_list",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"facts",
"as",
"$",
"fact",
")",
"{",
"// Don't show pending edits, as the user just sees duplicates",
"if",
"(",
"!",
"$",
"fact",
"->",
"isPendingDeletion",
"(",
")",
")",
"{",
"preg_match_all",
"(",
"'/(?:^1|\\n\\d) OBJE @('",
".",
"Gedcom",
"::",
"REGEX_XREF",
".",
"')@/'",
",",
"$",
"fact",
"->",
"gedcom",
"(",
")",
",",
"$",
"matches",
")",
";",
"foreach",
"(",
"$",
"matches",
"[",
"1",
"]",
"as",
"$",
"match",
")",
"{",
"$",
"media",
"=",
"Media",
"::",
"getInstance",
"(",
"$",
"match",
",",
"$",
"individual",
"->",
"tree",
"(",
")",
")",
";",
"if",
"(",
"$",
"media",
"&&",
"$",
"media",
"->",
"canShow",
"(",
")",
")",
"{",
"$",
"this",
"->",
"media_list",
"[",
"]",
"=",
"$",
"media",
";",
"}",
"}",
"}",
"}",
"// If a media object is linked twice, only show it once",
"$",
"this",
"->",
"media_list",
"=",
"array_unique",
"(",
"$",
"this",
"->",
"media_list",
")",
";",
"// Sort these using _WT_OBJE_SORT",
"$",
"wt_obje_sort",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"individual",
"->",
"facts",
"(",
"[",
"'_WT_OBJE_SORT'",
"]",
")",
"as",
"$",
"fact",
")",
"{",
"$",
"wt_obje_sort",
"[",
"]",
"=",
"trim",
"(",
"$",
"fact",
"->",
"value",
"(",
")",
",",
"'@'",
")",
";",
"}",
"usort",
"(",
"$",
"this",
"->",
"media_list",
",",
"static",
"function",
"(",
"Media",
"$",
"x",
",",
"Media",
"$",
"y",
")",
"use",
"(",
"$",
"wt_obje_sort",
")",
":",
"int",
"{",
"return",
"array_search",
"(",
"$",
"x",
"->",
"xref",
"(",
")",
",",
"$",
"wt_obje_sort",
",",
"true",
")",
"-",
"array_search",
"(",
"$",
"y",
"->",
"xref",
"(",
")",
",",
"$",
"wt_obje_sort",
",",
"true",
")",
";",
"}",
")",
";",
"}",
"return",
"$",
"this",
"->",
"media_list",
";",
"}"
] | Get all facts containing media links for this person and their spouse-family records
@param Individual $individual
@return Media[] | [
"Get",
"all",
"facts",
"containing",
"media",
"links",
"for",
"this",
"person",
"and",
"their",
"spouse",
"-",
"family",
"records"
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Module/AlbumModule.php#L113-L150 | train |
fisharebest/webtrees | app/Module/StatisticsChartModule.php | StatisticsChartModule.axisMonths | private function axisMonths(): array
{
return [
'JAN' => I18N::translateContext('NOMINATIVE', 'January'),
'FEB' => I18N::translateContext('NOMINATIVE', 'February'),
'MAR' => I18N::translateContext('NOMINATIVE', 'March'),
'APR' => I18N::translateContext('NOMINATIVE', 'April'),
'MAY' => I18N::translateContext('NOMINATIVE', 'May'),
'JUN' => I18N::translateContext('NOMINATIVE', 'June'),
'JUL' => I18N::translateContext('NOMINATIVE', 'July'),
'AUG' => I18N::translateContext('NOMINATIVE', 'August'),
'SEP' => I18N::translateContext('NOMINATIVE', 'September'),
'OCT' => I18N::translateContext('NOMINATIVE', 'October'),
'NOV' => I18N::translateContext('NOMINATIVE', 'November'),
'DEC' => I18N::translateContext('NOMINATIVE', 'December'),
];
} | php | private function axisMonths(): array
{
return [
'JAN' => I18N::translateContext('NOMINATIVE', 'January'),
'FEB' => I18N::translateContext('NOMINATIVE', 'February'),
'MAR' => I18N::translateContext('NOMINATIVE', 'March'),
'APR' => I18N::translateContext('NOMINATIVE', 'April'),
'MAY' => I18N::translateContext('NOMINATIVE', 'May'),
'JUN' => I18N::translateContext('NOMINATIVE', 'June'),
'JUL' => I18N::translateContext('NOMINATIVE', 'July'),
'AUG' => I18N::translateContext('NOMINATIVE', 'August'),
'SEP' => I18N::translateContext('NOMINATIVE', 'September'),
'OCT' => I18N::translateContext('NOMINATIVE', 'October'),
'NOV' => I18N::translateContext('NOMINATIVE', 'November'),
'DEC' => I18N::translateContext('NOMINATIVE', 'December'),
];
} | [
"private",
"function",
"axisMonths",
"(",
")",
":",
"array",
"{",
"return",
"[",
"'JAN'",
"=>",
"I18N",
"::",
"translateContext",
"(",
"'NOMINATIVE'",
",",
"'January'",
")",
",",
"'FEB'",
"=>",
"I18N",
"::",
"translateContext",
"(",
"'NOMINATIVE'",
",",
"'February'",
")",
",",
"'MAR'",
"=>",
"I18N",
"::",
"translateContext",
"(",
"'NOMINATIVE'",
",",
"'March'",
")",
",",
"'APR'",
"=>",
"I18N",
"::",
"translateContext",
"(",
"'NOMINATIVE'",
",",
"'April'",
")",
",",
"'MAY'",
"=>",
"I18N",
"::",
"translateContext",
"(",
"'NOMINATIVE'",
",",
"'May'",
")",
",",
"'JUN'",
"=>",
"I18N",
"::",
"translateContext",
"(",
"'NOMINATIVE'",
",",
"'June'",
")",
",",
"'JUL'",
"=>",
"I18N",
"::",
"translateContext",
"(",
"'NOMINATIVE'",
",",
"'July'",
")",
",",
"'AUG'",
"=>",
"I18N",
"::",
"translateContext",
"(",
"'NOMINATIVE'",
",",
"'August'",
")",
",",
"'SEP'",
"=>",
"I18N",
"::",
"translateContext",
"(",
"'NOMINATIVE'",
",",
"'September'",
")",
",",
"'OCT'",
"=>",
"I18N",
"::",
"translateContext",
"(",
"'NOMINATIVE'",
",",
"'October'",
")",
",",
"'NOV'",
"=>",
"I18N",
"::",
"translateContext",
"(",
"'NOMINATIVE'",
",",
"'November'",
")",
",",
"'DEC'",
"=>",
"I18N",
"::",
"translateContext",
"(",
"'NOMINATIVE'",
",",
"'December'",
")",
",",
"]",
";",
"}"
] | Labels for the X axis
@return string[] | [
"Labels",
"for",
"the",
"X",
"axis"
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Module/StatisticsChartModule.php#L783-L799 | train |
fisharebest/webtrees | app/Module/StatisticsChartModule.php | StatisticsChartModule.axisYears | private function axisYears(string $boundaries_csv): array
{
$boundaries = explode(',', $boundaries_csv);
$axis = [];
foreach ($boundaries as $n => $boundary) {
if ($n === 0) {
$date = new Date('BEF ' . $boundary);
} else {
$date = new Date('BET ' . $boundaries[$n - 1] . ' AND ' . ($boundary - 1));
}
$axis[$boundary - 1] = strip_tags($date->display());
}
$date = new Date('AFT ' . $boundaries[count($boundaries) - 1]);
$axis[PHP_INT_MAX] = strip_tags($date->display());
return $axis;
} | php | private function axisYears(string $boundaries_csv): array
{
$boundaries = explode(',', $boundaries_csv);
$axis = [];
foreach ($boundaries as $n => $boundary) {
if ($n === 0) {
$date = new Date('BEF ' . $boundary);
} else {
$date = new Date('BET ' . $boundaries[$n - 1] . ' AND ' . ($boundary - 1));
}
$axis[$boundary - 1] = strip_tags($date->display());
}
$date = new Date('AFT ' . $boundaries[count($boundaries) - 1]);
$axis[PHP_INT_MAX] = strip_tags($date->display());
return $axis;
} | [
"private",
"function",
"axisYears",
"(",
"string",
"$",
"boundaries_csv",
")",
":",
"array",
"{",
"$",
"boundaries",
"=",
"explode",
"(",
"','",
",",
"$",
"boundaries_csv",
")",
";",
"$",
"axis",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"boundaries",
"as",
"$",
"n",
"=>",
"$",
"boundary",
")",
"{",
"if",
"(",
"$",
"n",
"===",
"0",
")",
"{",
"$",
"date",
"=",
"new",
"Date",
"(",
"'BEF '",
".",
"$",
"boundary",
")",
";",
"}",
"else",
"{",
"$",
"date",
"=",
"new",
"Date",
"(",
"'BET '",
".",
"$",
"boundaries",
"[",
"$",
"n",
"-",
"1",
"]",
".",
"' AND '",
".",
"(",
"$",
"boundary",
"-",
"1",
")",
")",
";",
"}",
"$",
"axis",
"[",
"$",
"boundary",
"-",
"1",
"]",
"=",
"strip_tags",
"(",
"$",
"date",
"->",
"display",
"(",
")",
")",
";",
"}",
"$",
"date",
"=",
"new",
"Date",
"(",
"'AFT '",
".",
"$",
"boundaries",
"[",
"count",
"(",
"$",
"boundaries",
")",
"-",
"1",
"]",
")",
";",
"$",
"axis",
"[",
"PHP_INT_MAX",
"]",
"=",
"strip_tags",
"(",
"$",
"date",
"->",
"display",
"(",
")",
")",
";",
"return",
"$",
"axis",
";",
"}"
] | Convert a list of N year-boundaries into N+1 year-ranges for the z-axis.
@param string $boundaries_csv
@return string[] | [
"Convert",
"a",
"list",
"of",
"N",
"year",
"-",
"boundaries",
"into",
"N",
"+",
"1",
"year",
"-",
"ranges",
"for",
"the",
"z",
"-",
"axis",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Module/StatisticsChartModule.php#L808-L826 | train |
fisharebest/webtrees | app/Module/StatisticsChartModule.php | StatisticsChartModule.fillYData | private function fillYData($x, $z, $value, array $x_axis, array $z_axis, array &$ydata): void
{
$x = $this->findAxisEntry($x, $x_axis);
$z = $this->findAxisEntry($z, $z_axis);
if (!array_key_exists($z, $z_axis)) {
foreach (array_keys($z_axis) as $key) {
if ($value <= $key) {
$z = $key;
break;
}
}
}
// Add the value to the appropriate data point.
$ydata[$z][$x] = ($ydata[$z][$x] ?? 0) + $value;
} | php | private function fillYData($x, $z, $value, array $x_axis, array $z_axis, array &$ydata): void
{
$x = $this->findAxisEntry($x, $x_axis);
$z = $this->findAxisEntry($z, $z_axis);
if (!array_key_exists($z, $z_axis)) {
foreach (array_keys($z_axis) as $key) {
if ($value <= $key) {
$z = $key;
break;
}
}
}
// Add the value to the appropriate data point.
$ydata[$z][$x] = ($ydata[$z][$x] ?? 0) + $value;
} | [
"private",
"function",
"fillYData",
"(",
"$",
"x",
",",
"$",
"z",
",",
"$",
"value",
",",
"array",
"$",
"x_axis",
",",
"array",
"$",
"z_axis",
",",
"array",
"&",
"$",
"ydata",
")",
":",
"void",
"{",
"$",
"x",
"=",
"$",
"this",
"->",
"findAxisEntry",
"(",
"$",
"x",
",",
"$",
"x_axis",
")",
";",
"$",
"z",
"=",
"$",
"this",
"->",
"findAxisEntry",
"(",
"$",
"z",
",",
"$",
"z_axis",
")",
";",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"z",
",",
"$",
"z_axis",
")",
")",
"{",
"foreach",
"(",
"array_keys",
"(",
"$",
"z_axis",
")",
"as",
"$",
"key",
")",
"{",
"if",
"(",
"$",
"value",
"<=",
"$",
"key",
")",
"{",
"$",
"z",
"=",
"$",
"key",
";",
"break",
";",
"}",
"}",
"}",
"// Add the value to the appropriate data point.",
"$",
"ydata",
"[",
"$",
"z",
"]",
"[",
"$",
"x",
"]",
"=",
"(",
"$",
"ydata",
"[",
"$",
"z",
"]",
"[",
"$",
"x",
"]",
"??",
"0",
")",
"+",
"$",
"value",
";",
"}"
] | Calculate the Y axis.
@param int|string $x
@param int|string $z
@param int|string $value
@param array $x_axis
@param array $z_axis
@param int[][] $ydata
@return void | [
"Calculate",
"the",
"Y",
"axis",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Module/StatisticsChartModule.php#L878-L894 | train |
fisharebest/webtrees | app/Module/StatisticsChartModule.php | StatisticsChartModule.myPlot | private function myPlot(
string $chart_title,
array $x_axis,
string $x_axis_title,
array $ydata,
string $y_axis_title,
array $z_axis,
int $y_axis_type
): string {
if (!count($ydata)) {
return I18N::translate('This information is not available.');
}
// Colors for z-axis
$colors = [];
$index = 0;
while (count($colors) < count($ydata)) {
$colors[] = self::Z_AXIS_COLORS[$index];
$index = ($index + 1) % count(self::Z_AXIS_COLORS);
}
// Convert our sparse dataset into a fixed-size array
$tmp = [];
foreach (array_keys($z_axis) as $z) {
foreach (array_keys($x_axis) as $x) {
$tmp[$z][$x] = $ydata[$z][$x] ?? 0;
}
}
$ydata = $tmp;
// Convert the chart data to percentage
if ($y_axis_type === self::Y_AXIS_PERCENT) {
// Normalise each (non-zero!) set of data to total 100%
array_walk($ydata, static function (array &$x) {
$sum = array_sum($x);
if ($sum > 0) {
$x = array_map(static function ($y) use ($sum) {
return $y * 100.0 / $sum;
}, $x);
}
});
}
$data = [
array_merge(
[ I18N::translate('Century') ],
array_values($z_axis)
)
];
$intermediate = [];
foreach ($ydata as $century => $months) {
foreach ($months as $month => $value) {
$intermediate[$month][] = [
'v' => $value,
'f' => ($y_axis_type === self::Y_AXIS_PERCENT) ? sprintf('%.1f%%', $value) : $value,
];
}
}
foreach ($intermediate as $key => $values) {
$data[] = array_merge(
[ $x_axis[$key] ],
$values
);
}
$chart_options = [
'title' => '',
'subtitle' => '',
'height' => 400,
'width' => '100%',
'legend' => [
'position' => count($z_axis) > 1 ? 'right' : 'none',
'alignment' => 'center',
],
'tooltip' => [
'format' => '\'%\'',
],
'vAxis' => [
'title' => $y_axis_title ?? '',
],
'hAxis' => [
'title' => $x_axis_title ?? '',
],
'colors' => $colors,
];
return view(
'statistics/other/charts/custom',
[
'data' => $data,
'chart_options' => $chart_options,
'chart_title' => $chart_title,
]
);
} | php | private function myPlot(
string $chart_title,
array $x_axis,
string $x_axis_title,
array $ydata,
string $y_axis_title,
array $z_axis,
int $y_axis_type
): string {
if (!count($ydata)) {
return I18N::translate('This information is not available.');
}
// Colors for z-axis
$colors = [];
$index = 0;
while (count($colors) < count($ydata)) {
$colors[] = self::Z_AXIS_COLORS[$index];
$index = ($index + 1) % count(self::Z_AXIS_COLORS);
}
// Convert our sparse dataset into a fixed-size array
$tmp = [];
foreach (array_keys($z_axis) as $z) {
foreach (array_keys($x_axis) as $x) {
$tmp[$z][$x] = $ydata[$z][$x] ?? 0;
}
}
$ydata = $tmp;
// Convert the chart data to percentage
if ($y_axis_type === self::Y_AXIS_PERCENT) {
// Normalise each (non-zero!) set of data to total 100%
array_walk($ydata, static function (array &$x) {
$sum = array_sum($x);
if ($sum > 0) {
$x = array_map(static function ($y) use ($sum) {
return $y * 100.0 / $sum;
}, $x);
}
});
}
$data = [
array_merge(
[ I18N::translate('Century') ],
array_values($z_axis)
)
];
$intermediate = [];
foreach ($ydata as $century => $months) {
foreach ($months as $month => $value) {
$intermediate[$month][] = [
'v' => $value,
'f' => ($y_axis_type === self::Y_AXIS_PERCENT) ? sprintf('%.1f%%', $value) : $value,
];
}
}
foreach ($intermediate as $key => $values) {
$data[] = array_merge(
[ $x_axis[$key] ],
$values
);
}
$chart_options = [
'title' => '',
'subtitle' => '',
'height' => 400,
'width' => '100%',
'legend' => [
'position' => count($z_axis) > 1 ? 'right' : 'none',
'alignment' => 'center',
],
'tooltip' => [
'format' => '\'%\'',
],
'vAxis' => [
'title' => $y_axis_title ?? '',
],
'hAxis' => [
'title' => $x_axis_title ?? '',
],
'colors' => $colors,
];
return view(
'statistics/other/charts/custom',
[
'data' => $data,
'chart_options' => $chart_options,
'chart_title' => $chart_title,
]
);
} | [
"private",
"function",
"myPlot",
"(",
"string",
"$",
"chart_title",
",",
"array",
"$",
"x_axis",
",",
"string",
"$",
"x_axis_title",
",",
"array",
"$",
"ydata",
",",
"string",
"$",
"y_axis_title",
",",
"array",
"$",
"z_axis",
",",
"int",
"$",
"y_axis_type",
")",
":",
"string",
"{",
"if",
"(",
"!",
"count",
"(",
"$",
"ydata",
")",
")",
"{",
"return",
"I18N",
"::",
"translate",
"(",
"'This information is not available.'",
")",
";",
"}",
"// Colors for z-axis",
"$",
"colors",
"=",
"[",
"]",
";",
"$",
"index",
"=",
"0",
";",
"while",
"(",
"count",
"(",
"$",
"colors",
")",
"<",
"count",
"(",
"$",
"ydata",
")",
")",
"{",
"$",
"colors",
"[",
"]",
"=",
"self",
"::",
"Z_AXIS_COLORS",
"[",
"$",
"index",
"]",
";",
"$",
"index",
"=",
"(",
"$",
"index",
"+",
"1",
")",
"%",
"count",
"(",
"self",
"::",
"Z_AXIS_COLORS",
")",
";",
"}",
"// Convert our sparse dataset into a fixed-size array",
"$",
"tmp",
"=",
"[",
"]",
";",
"foreach",
"(",
"array_keys",
"(",
"$",
"z_axis",
")",
"as",
"$",
"z",
")",
"{",
"foreach",
"(",
"array_keys",
"(",
"$",
"x_axis",
")",
"as",
"$",
"x",
")",
"{",
"$",
"tmp",
"[",
"$",
"z",
"]",
"[",
"$",
"x",
"]",
"=",
"$",
"ydata",
"[",
"$",
"z",
"]",
"[",
"$",
"x",
"]",
"??",
"0",
";",
"}",
"}",
"$",
"ydata",
"=",
"$",
"tmp",
";",
"// Convert the chart data to percentage",
"if",
"(",
"$",
"y_axis_type",
"===",
"self",
"::",
"Y_AXIS_PERCENT",
")",
"{",
"// Normalise each (non-zero!) set of data to total 100%",
"array_walk",
"(",
"$",
"ydata",
",",
"static",
"function",
"(",
"array",
"&",
"$",
"x",
")",
"{",
"$",
"sum",
"=",
"array_sum",
"(",
"$",
"x",
")",
";",
"if",
"(",
"$",
"sum",
">",
"0",
")",
"{",
"$",
"x",
"=",
"array_map",
"(",
"static",
"function",
"(",
"$",
"y",
")",
"use",
"(",
"$",
"sum",
")",
"{",
"return",
"$",
"y",
"*",
"100.0",
"/",
"$",
"sum",
";",
"}",
",",
"$",
"x",
")",
";",
"}",
"}",
")",
";",
"}",
"$",
"data",
"=",
"[",
"array_merge",
"(",
"[",
"I18N",
"::",
"translate",
"(",
"'Century'",
")",
"]",
",",
"array_values",
"(",
"$",
"z_axis",
")",
")",
"]",
";",
"$",
"intermediate",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"ydata",
"as",
"$",
"century",
"=>",
"$",
"months",
")",
"{",
"foreach",
"(",
"$",
"months",
"as",
"$",
"month",
"=>",
"$",
"value",
")",
"{",
"$",
"intermediate",
"[",
"$",
"month",
"]",
"[",
"]",
"=",
"[",
"'v'",
"=>",
"$",
"value",
",",
"'f'",
"=>",
"(",
"$",
"y_axis_type",
"===",
"self",
"::",
"Y_AXIS_PERCENT",
")",
"?",
"sprintf",
"(",
"'%.1f%%'",
",",
"$",
"value",
")",
":",
"$",
"value",
",",
"]",
";",
"}",
"}",
"foreach",
"(",
"$",
"intermediate",
"as",
"$",
"key",
"=>",
"$",
"values",
")",
"{",
"$",
"data",
"[",
"]",
"=",
"array_merge",
"(",
"[",
"$",
"x_axis",
"[",
"$",
"key",
"]",
"]",
",",
"$",
"values",
")",
";",
"}",
"$",
"chart_options",
"=",
"[",
"'title'",
"=>",
"''",
",",
"'subtitle'",
"=>",
"''",
",",
"'height'",
"=>",
"400",
",",
"'width'",
"=>",
"'100%'",
",",
"'legend'",
"=>",
"[",
"'position'",
"=>",
"count",
"(",
"$",
"z_axis",
")",
">",
"1",
"?",
"'right'",
":",
"'none'",
",",
"'alignment'",
"=>",
"'center'",
",",
"]",
",",
"'tooltip'",
"=>",
"[",
"'format'",
"=>",
"'\\'%\\''",
",",
"]",
",",
"'vAxis'",
"=>",
"[",
"'title'",
"=>",
"$",
"y_axis_title",
"??",
"''",
",",
"]",
",",
"'hAxis'",
"=>",
"[",
"'title'",
"=>",
"$",
"x_axis_title",
"??",
"''",
",",
"]",
",",
"'colors'",
"=>",
"$",
"colors",
",",
"]",
";",
"return",
"view",
"(",
"'statistics/other/charts/custom'",
",",
"[",
"'data'",
"=>",
"$",
"data",
",",
"'chart_options'",
"=>",
"$",
"chart_options",
",",
"'chart_title'",
"=>",
"$",
"chart_title",
",",
"]",
")",
";",
"}"
] | Plot the data.
@param string $chart_title
@param string[] $x_axis
@param string $x_axis_title
@param int[][] $ydata
@param string $y_axis_title
@param string[] $z_axis
@param int $y_axis_type
@return string | [
"Plot",
"the",
"data",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Module/StatisticsChartModule.php#L937-L1033 | train |
fisharebest/webtrees | app/Functions/FunctionsImport.php | FunctionsImport.updatePlaces | public static function updatePlaces(string $xref, Tree $tree, string $gedrec): void
{
preg_match_all('/^[2-9] PLAC (.+)/m', $gedrec, $matches);
$places = array_unique($matches[1]);
foreach ($places as $place_name) {
$place = new Place($place_name, $tree);
// Calling Place::id() will create the entry in the database, if it doesn't already exist.
// Link the place to the record
while ($place->id() !== 0) {
try {
DB::table('placelinks')->insert([
'pl_p_id' => $place->id(),
'pl_gid' => $xref,
'pl_file' => $tree->id(),
]);
} catch (PDOException $ex) {
// Already linked this place - so presumably also any parent places.
break;
}
$place = $place->parent();
}
}
} | php | public static function updatePlaces(string $xref, Tree $tree, string $gedrec): void
{
preg_match_all('/^[2-9] PLAC (.+)/m', $gedrec, $matches);
$places = array_unique($matches[1]);
foreach ($places as $place_name) {
$place = new Place($place_name, $tree);
// Calling Place::id() will create the entry in the database, if it doesn't already exist.
// Link the place to the record
while ($place->id() !== 0) {
try {
DB::table('placelinks')->insert([
'pl_p_id' => $place->id(),
'pl_gid' => $xref,
'pl_file' => $tree->id(),
]);
} catch (PDOException $ex) {
// Already linked this place - so presumably also any parent places.
break;
}
$place = $place->parent();
}
}
} | [
"public",
"static",
"function",
"updatePlaces",
"(",
"string",
"$",
"xref",
",",
"Tree",
"$",
"tree",
",",
"string",
"$",
"gedrec",
")",
":",
"void",
"{",
"preg_match_all",
"(",
"'/^[2-9] PLAC (.+)/m'",
",",
"$",
"gedrec",
",",
"$",
"matches",
")",
";",
"$",
"places",
"=",
"array_unique",
"(",
"$",
"matches",
"[",
"1",
"]",
")",
";",
"foreach",
"(",
"$",
"places",
"as",
"$",
"place_name",
")",
"{",
"$",
"place",
"=",
"new",
"Place",
"(",
"$",
"place_name",
",",
"$",
"tree",
")",
";",
"// Calling Place::id() will create the entry in the database, if it doesn't already exist.",
"// Link the place to the record",
"while",
"(",
"$",
"place",
"->",
"id",
"(",
")",
"!==",
"0",
")",
"{",
"try",
"{",
"DB",
"::",
"table",
"(",
"'placelinks'",
")",
"->",
"insert",
"(",
"[",
"'pl_p_id'",
"=>",
"$",
"place",
"->",
"id",
"(",
")",
",",
"'pl_gid'",
"=>",
"$",
"xref",
",",
"'pl_file'",
"=>",
"$",
"tree",
"->",
"id",
"(",
")",
",",
"]",
")",
";",
"}",
"catch",
"(",
"PDOException",
"$",
"ex",
")",
"{",
"// Already linked this place - so presumably also any parent places.",
"break",
";",
"}",
"$",
"place",
"=",
"$",
"place",
"->",
"parent",
"(",
")",
";",
"}",
"}",
"}"
] | Extract all level 2 places from the given record and insert them into the places table
@param string $xref
@param Tree $tree
@param string $gedrec
@return void | [
"Extract",
"all",
"level",
"2",
"places",
"from",
"the",
"given",
"record",
"and",
"insert",
"them",
"into",
"the",
"places",
"table"
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Functions/FunctionsImport.php#L813-L839 | train |
fisharebest/webtrees | app/Functions/FunctionsImport.php | FunctionsImport.updateDates | public static function updateDates($xref, $ged_id, $gedrec): void
{
if (strpos($gedrec, '2 DATE ') && preg_match_all("/\n1 (\w+).*(?:\n[2-9].*)*(?:\n2 DATE (.+))(?:\n[2-9].*)*/", $gedrec, $matches, PREG_SET_ORDER)) {
foreach ($matches as $match) {
$fact = $match[1];
if (($fact === 'FACT' || $fact === 'EVEN') && preg_match("/\n2 TYPE ([A-Z]{3,5})/", $match[0], $tmatch)) {
$fact = $tmatch[1];
}
$date = new Date($match[2]);
DB::table('dates')->insert([
'd_day' => $date->minimumDate()->day,
'd_month' => $date->minimumDate()->format('%O'),
'd_mon' => $date->minimumDate()->month,
'd_year' => $date->minimumDate()->year,
'd_julianday1' => $date->minimumDate()->minimumJulianDay(),
'd_julianday2' => $date->minimumDate()->maximumJulianDay(),
'd_fact' => $fact,
'd_gid' => $xref,
'd_file' => $ged_id,
'd_type' => $date->minimumDate()->format('%@'),
]);
if ($date->minimumDate() !== $date->maximumDate()) {
DB::table('dates')->insert([
'd_day' => $date->maximumDate()->day,
'd_month' => $date->maximumDate()->format('%O'),
'd_mon' => $date->maximumDate()->month,
'd_year' => $date->maximumDate()->year,
'd_julianday1' => $date->maximumDate()->minimumJulianDay(),
'd_julianday2' => $date->maximumDate()->maximumJulianDay(),
'd_fact' => $fact,
'd_gid' => $xref,
'd_file' => $ged_id,
'd_type' => $date->minimumDate()->format('%@'),
]);
}
}
}
} | php | public static function updateDates($xref, $ged_id, $gedrec): void
{
if (strpos($gedrec, '2 DATE ') && preg_match_all("/\n1 (\w+).*(?:\n[2-9].*)*(?:\n2 DATE (.+))(?:\n[2-9].*)*/", $gedrec, $matches, PREG_SET_ORDER)) {
foreach ($matches as $match) {
$fact = $match[1];
if (($fact === 'FACT' || $fact === 'EVEN') && preg_match("/\n2 TYPE ([A-Z]{3,5})/", $match[0], $tmatch)) {
$fact = $tmatch[1];
}
$date = new Date($match[2]);
DB::table('dates')->insert([
'd_day' => $date->minimumDate()->day,
'd_month' => $date->minimumDate()->format('%O'),
'd_mon' => $date->minimumDate()->month,
'd_year' => $date->minimumDate()->year,
'd_julianday1' => $date->minimumDate()->minimumJulianDay(),
'd_julianday2' => $date->minimumDate()->maximumJulianDay(),
'd_fact' => $fact,
'd_gid' => $xref,
'd_file' => $ged_id,
'd_type' => $date->minimumDate()->format('%@'),
]);
if ($date->minimumDate() !== $date->maximumDate()) {
DB::table('dates')->insert([
'd_day' => $date->maximumDate()->day,
'd_month' => $date->maximumDate()->format('%O'),
'd_mon' => $date->maximumDate()->month,
'd_year' => $date->maximumDate()->year,
'd_julianday1' => $date->maximumDate()->minimumJulianDay(),
'd_julianday2' => $date->maximumDate()->maximumJulianDay(),
'd_fact' => $fact,
'd_gid' => $xref,
'd_file' => $ged_id,
'd_type' => $date->minimumDate()->format('%@'),
]);
}
}
}
} | [
"public",
"static",
"function",
"updateDates",
"(",
"$",
"xref",
",",
"$",
"ged_id",
",",
"$",
"gedrec",
")",
":",
"void",
"{",
"if",
"(",
"strpos",
"(",
"$",
"gedrec",
",",
"'2 DATE '",
")",
"&&",
"preg_match_all",
"(",
"\"/\\n1 (\\w+).*(?:\\n[2-9].*)*(?:\\n2 DATE (.+))(?:\\n[2-9].*)*/\"",
",",
"$",
"gedrec",
",",
"$",
"matches",
",",
"PREG_SET_ORDER",
")",
")",
"{",
"foreach",
"(",
"$",
"matches",
"as",
"$",
"match",
")",
"{",
"$",
"fact",
"=",
"$",
"match",
"[",
"1",
"]",
";",
"if",
"(",
"(",
"$",
"fact",
"===",
"'FACT'",
"||",
"$",
"fact",
"===",
"'EVEN'",
")",
"&&",
"preg_match",
"(",
"\"/\\n2 TYPE ([A-Z]{3,5})/\"",
",",
"$",
"match",
"[",
"0",
"]",
",",
"$",
"tmatch",
")",
")",
"{",
"$",
"fact",
"=",
"$",
"tmatch",
"[",
"1",
"]",
";",
"}",
"$",
"date",
"=",
"new",
"Date",
"(",
"$",
"match",
"[",
"2",
"]",
")",
";",
"DB",
"::",
"table",
"(",
"'dates'",
")",
"->",
"insert",
"(",
"[",
"'d_day'",
"=>",
"$",
"date",
"->",
"minimumDate",
"(",
")",
"->",
"day",
",",
"'d_month'",
"=>",
"$",
"date",
"->",
"minimumDate",
"(",
")",
"->",
"format",
"(",
"'%O'",
")",
",",
"'d_mon'",
"=>",
"$",
"date",
"->",
"minimumDate",
"(",
")",
"->",
"month",
",",
"'d_year'",
"=>",
"$",
"date",
"->",
"minimumDate",
"(",
")",
"->",
"year",
",",
"'d_julianday1'",
"=>",
"$",
"date",
"->",
"minimumDate",
"(",
")",
"->",
"minimumJulianDay",
"(",
")",
",",
"'d_julianday2'",
"=>",
"$",
"date",
"->",
"minimumDate",
"(",
")",
"->",
"maximumJulianDay",
"(",
")",
",",
"'d_fact'",
"=>",
"$",
"fact",
",",
"'d_gid'",
"=>",
"$",
"xref",
",",
"'d_file'",
"=>",
"$",
"ged_id",
",",
"'d_type'",
"=>",
"$",
"date",
"->",
"minimumDate",
"(",
")",
"->",
"format",
"(",
"'%@'",
")",
",",
"]",
")",
";",
"if",
"(",
"$",
"date",
"->",
"minimumDate",
"(",
")",
"!==",
"$",
"date",
"->",
"maximumDate",
"(",
")",
")",
"{",
"DB",
"::",
"table",
"(",
"'dates'",
")",
"->",
"insert",
"(",
"[",
"'d_day'",
"=>",
"$",
"date",
"->",
"maximumDate",
"(",
")",
"->",
"day",
",",
"'d_month'",
"=>",
"$",
"date",
"->",
"maximumDate",
"(",
")",
"->",
"format",
"(",
"'%O'",
")",
",",
"'d_mon'",
"=>",
"$",
"date",
"->",
"maximumDate",
"(",
")",
"->",
"month",
",",
"'d_year'",
"=>",
"$",
"date",
"->",
"maximumDate",
"(",
")",
"->",
"year",
",",
"'d_julianday1'",
"=>",
"$",
"date",
"->",
"maximumDate",
"(",
")",
"->",
"minimumJulianDay",
"(",
")",
",",
"'d_julianday2'",
"=>",
"$",
"date",
"->",
"maximumDate",
"(",
")",
"->",
"maximumJulianDay",
"(",
")",
",",
"'d_fact'",
"=>",
"$",
"fact",
",",
"'d_gid'",
"=>",
"$",
"xref",
",",
"'d_file'",
"=>",
"$",
"ged_id",
",",
"'d_type'",
"=>",
"$",
"date",
"->",
"minimumDate",
"(",
")",
"->",
"format",
"(",
"'%@'",
")",
",",
"]",
")",
";",
"}",
"}",
"}",
"}"
] | Extract all the dates from the given record and insert them into the database.
@param string $xref
@param int $ged_id
@param string $gedrec
@return void | [
"Extract",
"all",
"the",
"dates",
"from",
"the",
"given",
"record",
"and",
"insert",
"them",
"into",
"the",
"database",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Functions/FunctionsImport.php#L850-L888 | train |
fisharebest/webtrees | app/Functions/FunctionsImport.php | FunctionsImport.updateLinks | public static function updateLinks($xref, $ged_id, $gedrec): void
{
if (preg_match_all('/^\d+ (' . Gedcom::REGEX_TAG . ') @(' . Gedcom::REGEX_XREF . ')@/m', $gedrec, $matches, PREG_SET_ORDER)) {
$data = [];
foreach ($matches as $match) {
// Include each link once only.
if (!in_array($match[1] . $match[2], $data, true)) {
$data[] = $match[1] . $match[2];
try {
DB::table('link')->insert([
'l_from' => $xref,
'l_to' => $match[2],
'l_type' => $match[1],
'l_file' => $ged_id,
]);
} catch (PDOException $ex) {
// Ignore any errors, which may be caused by "duplicates" that differ on case/collation, e.g. "S1" and "s1"
}
}
}
}
} | php | public static function updateLinks($xref, $ged_id, $gedrec): void
{
if (preg_match_all('/^\d+ (' . Gedcom::REGEX_TAG . ') @(' . Gedcom::REGEX_XREF . ')@/m', $gedrec, $matches, PREG_SET_ORDER)) {
$data = [];
foreach ($matches as $match) {
// Include each link once only.
if (!in_array($match[1] . $match[2], $data, true)) {
$data[] = $match[1] . $match[2];
try {
DB::table('link')->insert([
'l_from' => $xref,
'l_to' => $match[2],
'l_type' => $match[1],
'l_file' => $ged_id,
]);
} catch (PDOException $ex) {
// Ignore any errors, which may be caused by "duplicates" that differ on case/collation, e.g. "S1" and "s1"
}
}
}
}
} | [
"public",
"static",
"function",
"updateLinks",
"(",
"$",
"xref",
",",
"$",
"ged_id",
",",
"$",
"gedrec",
")",
":",
"void",
"{",
"if",
"(",
"preg_match_all",
"(",
"'/^\\d+ ('",
".",
"Gedcom",
"::",
"REGEX_TAG",
".",
"') @('",
".",
"Gedcom",
"::",
"REGEX_XREF",
".",
"')@/m'",
",",
"$",
"gedrec",
",",
"$",
"matches",
",",
"PREG_SET_ORDER",
")",
")",
"{",
"$",
"data",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"matches",
"as",
"$",
"match",
")",
"{",
"// Include each link once only.",
"if",
"(",
"!",
"in_array",
"(",
"$",
"match",
"[",
"1",
"]",
".",
"$",
"match",
"[",
"2",
"]",
",",
"$",
"data",
",",
"true",
")",
")",
"{",
"$",
"data",
"[",
"]",
"=",
"$",
"match",
"[",
"1",
"]",
".",
"$",
"match",
"[",
"2",
"]",
";",
"try",
"{",
"DB",
"::",
"table",
"(",
"'link'",
")",
"->",
"insert",
"(",
"[",
"'l_from'",
"=>",
"$",
"xref",
",",
"'l_to'",
"=>",
"$",
"match",
"[",
"2",
"]",
",",
"'l_type'",
"=>",
"$",
"match",
"[",
"1",
"]",
",",
"'l_file'",
"=>",
"$",
"ged_id",
",",
"]",
")",
";",
"}",
"catch",
"(",
"PDOException",
"$",
"ex",
")",
"{",
"// Ignore any errors, which may be caused by \"duplicates\" that differ on case/collation, e.g. \"S1\" and \"s1\"",
"}",
"}",
"}",
"}",
"}"
] | Extract all the links from the given record and insert them into the database
@param string $xref
@param int $ged_id
@param string $gedrec
@return void | [
"Extract",
"all",
"the",
"links",
"from",
"the",
"given",
"record",
"and",
"insert",
"them",
"into",
"the",
"database"
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Functions/FunctionsImport.php#L899-L920 | train |
fisharebest/webtrees | app/Functions/FunctionsImport.php | FunctionsImport.updateNames | public static function updateNames($xref, $ged_id, GedcomRecord $record): void
{
foreach ($record->getAllNames() as $n => $name) {
if ($record instanceof Individual) {
if ($name['givn'] === '@P.N.') {
$soundex_givn_std = null;
$soundex_givn_dm = null;
} else {
$soundex_givn_std = Soundex::russell($name['givn']);
$soundex_givn_dm = Soundex::daitchMokotoff($name['givn']);
}
if ($name['surn'] === '@N.N.') {
$soundex_surn_std = null;
$soundex_surn_dm = null;
} else {
$soundex_surn_std = Soundex::russell($name['surname']);
$soundex_surn_dm = Soundex::daitchMokotoff($name['surname']);
}
DB::table('name')->insert([
'n_file' => $ged_id,
'n_id' => $xref,
'n_num' => $n,
'n_type' => $name['type'],
'n_sort' => mb_substr($name['sort'], 0, 255),
'n_full' => mb_substr($name['fullNN'], 0, 255),
'n_surname' => mb_substr($name['surname'], 0, 255),
'n_surn' => mb_substr($name['surn'], 0, 255),
'n_givn' => mb_substr($name['givn'], 0, 255),
'n_soundex_givn_std' => $soundex_givn_std,
'n_soundex_surn_std' => $soundex_surn_std,
'n_soundex_givn_dm' => $soundex_givn_dm,
'n_soundex_surn_dm' => $soundex_surn_dm,
]);
} else {
DB::table('name')->insert([
'n_file' => $ged_id,
'n_id' => $xref,
'n_num' => $n,
'n_type' => $name['type'],
'n_sort' => mb_substr($name['sort'], 0, 255),
'n_full' => mb_substr($name['fullNN'], 0, 255),
]);
}
}
} | php | public static function updateNames($xref, $ged_id, GedcomRecord $record): void
{
foreach ($record->getAllNames() as $n => $name) {
if ($record instanceof Individual) {
if ($name['givn'] === '@P.N.') {
$soundex_givn_std = null;
$soundex_givn_dm = null;
} else {
$soundex_givn_std = Soundex::russell($name['givn']);
$soundex_givn_dm = Soundex::daitchMokotoff($name['givn']);
}
if ($name['surn'] === '@N.N.') {
$soundex_surn_std = null;
$soundex_surn_dm = null;
} else {
$soundex_surn_std = Soundex::russell($name['surname']);
$soundex_surn_dm = Soundex::daitchMokotoff($name['surname']);
}
DB::table('name')->insert([
'n_file' => $ged_id,
'n_id' => $xref,
'n_num' => $n,
'n_type' => $name['type'],
'n_sort' => mb_substr($name['sort'], 0, 255),
'n_full' => mb_substr($name['fullNN'], 0, 255),
'n_surname' => mb_substr($name['surname'], 0, 255),
'n_surn' => mb_substr($name['surn'], 0, 255),
'n_givn' => mb_substr($name['givn'], 0, 255),
'n_soundex_givn_std' => $soundex_givn_std,
'n_soundex_surn_std' => $soundex_surn_std,
'n_soundex_givn_dm' => $soundex_givn_dm,
'n_soundex_surn_dm' => $soundex_surn_dm,
]);
} else {
DB::table('name')->insert([
'n_file' => $ged_id,
'n_id' => $xref,
'n_num' => $n,
'n_type' => $name['type'],
'n_sort' => mb_substr($name['sort'], 0, 255),
'n_full' => mb_substr($name['fullNN'], 0, 255),
]);
}
}
} | [
"public",
"static",
"function",
"updateNames",
"(",
"$",
"xref",
",",
"$",
"ged_id",
",",
"GedcomRecord",
"$",
"record",
")",
":",
"void",
"{",
"foreach",
"(",
"$",
"record",
"->",
"getAllNames",
"(",
")",
"as",
"$",
"n",
"=>",
"$",
"name",
")",
"{",
"if",
"(",
"$",
"record",
"instanceof",
"Individual",
")",
"{",
"if",
"(",
"$",
"name",
"[",
"'givn'",
"]",
"===",
"'@P.N.'",
")",
"{",
"$",
"soundex_givn_std",
"=",
"null",
";",
"$",
"soundex_givn_dm",
"=",
"null",
";",
"}",
"else",
"{",
"$",
"soundex_givn_std",
"=",
"Soundex",
"::",
"russell",
"(",
"$",
"name",
"[",
"'givn'",
"]",
")",
";",
"$",
"soundex_givn_dm",
"=",
"Soundex",
"::",
"daitchMokotoff",
"(",
"$",
"name",
"[",
"'givn'",
"]",
")",
";",
"}",
"if",
"(",
"$",
"name",
"[",
"'surn'",
"]",
"===",
"'@N.N.'",
")",
"{",
"$",
"soundex_surn_std",
"=",
"null",
";",
"$",
"soundex_surn_dm",
"=",
"null",
";",
"}",
"else",
"{",
"$",
"soundex_surn_std",
"=",
"Soundex",
"::",
"russell",
"(",
"$",
"name",
"[",
"'surname'",
"]",
")",
";",
"$",
"soundex_surn_dm",
"=",
"Soundex",
"::",
"daitchMokotoff",
"(",
"$",
"name",
"[",
"'surname'",
"]",
")",
";",
"}",
"DB",
"::",
"table",
"(",
"'name'",
")",
"->",
"insert",
"(",
"[",
"'n_file'",
"=>",
"$",
"ged_id",
",",
"'n_id'",
"=>",
"$",
"xref",
",",
"'n_num'",
"=>",
"$",
"n",
",",
"'n_type'",
"=>",
"$",
"name",
"[",
"'type'",
"]",
",",
"'n_sort'",
"=>",
"mb_substr",
"(",
"$",
"name",
"[",
"'sort'",
"]",
",",
"0",
",",
"255",
")",
",",
"'n_full'",
"=>",
"mb_substr",
"(",
"$",
"name",
"[",
"'fullNN'",
"]",
",",
"0",
",",
"255",
")",
",",
"'n_surname'",
"=>",
"mb_substr",
"(",
"$",
"name",
"[",
"'surname'",
"]",
",",
"0",
",",
"255",
")",
",",
"'n_surn'",
"=>",
"mb_substr",
"(",
"$",
"name",
"[",
"'surn'",
"]",
",",
"0",
",",
"255",
")",
",",
"'n_givn'",
"=>",
"mb_substr",
"(",
"$",
"name",
"[",
"'givn'",
"]",
",",
"0",
",",
"255",
")",
",",
"'n_soundex_givn_std'",
"=>",
"$",
"soundex_givn_std",
",",
"'n_soundex_surn_std'",
"=>",
"$",
"soundex_surn_std",
",",
"'n_soundex_givn_dm'",
"=>",
"$",
"soundex_givn_dm",
",",
"'n_soundex_surn_dm'",
"=>",
"$",
"soundex_surn_dm",
",",
"]",
")",
";",
"}",
"else",
"{",
"DB",
"::",
"table",
"(",
"'name'",
")",
"->",
"insert",
"(",
"[",
"'n_file'",
"=>",
"$",
"ged_id",
",",
"'n_id'",
"=>",
"$",
"xref",
",",
"'n_num'",
"=>",
"$",
"n",
",",
"'n_type'",
"=>",
"$",
"name",
"[",
"'type'",
"]",
",",
"'n_sort'",
"=>",
"mb_substr",
"(",
"$",
"name",
"[",
"'sort'",
"]",
",",
"0",
",",
"255",
")",
",",
"'n_full'",
"=>",
"mb_substr",
"(",
"$",
"name",
"[",
"'fullNN'",
"]",
",",
"0",
",",
"255",
")",
",",
"]",
")",
";",
"}",
"}",
"}"
] | Extract all the names from the given record and insert them into the database.
@param string $xref
@param int $ged_id
@param GedcomRecord $record
@return void | [
"Extract",
"all",
"the",
"names",
"from",
"the",
"given",
"record",
"and",
"insert",
"them",
"into",
"the",
"database",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Functions/FunctionsImport.php#L931-L975 | train |
fisharebest/webtrees | app/Functions/FunctionsImport.php | FunctionsImport.convertInlineMedia | public static function convertInlineMedia(Tree $tree, $gedrec): string
{
while (preg_match('/\n1 OBJE(?:\n[2-9].+)+/', $gedrec, $match)) {
$gedrec = str_replace($match[0], self::createMediaObject(1, $match[0], $tree), $gedrec);
}
while (preg_match('/\n2 OBJE(?:\n[3-9].+)+/', $gedrec, $match)) {
$gedrec = str_replace($match[0], self::createMediaObject(2, $match[0], $tree), $gedrec);
}
while (preg_match('/\n3 OBJE(?:\n[4-9].+)+/', $gedrec, $match)) {
$gedrec = str_replace($match[0], self::createMediaObject(3, $match[0], $tree), $gedrec);
}
return $gedrec;
} | php | public static function convertInlineMedia(Tree $tree, $gedrec): string
{
while (preg_match('/\n1 OBJE(?:\n[2-9].+)+/', $gedrec, $match)) {
$gedrec = str_replace($match[0], self::createMediaObject(1, $match[0], $tree), $gedrec);
}
while (preg_match('/\n2 OBJE(?:\n[3-9].+)+/', $gedrec, $match)) {
$gedrec = str_replace($match[0], self::createMediaObject(2, $match[0], $tree), $gedrec);
}
while (preg_match('/\n3 OBJE(?:\n[4-9].+)+/', $gedrec, $match)) {
$gedrec = str_replace($match[0], self::createMediaObject(3, $match[0], $tree), $gedrec);
}
return $gedrec;
} | [
"public",
"static",
"function",
"convertInlineMedia",
"(",
"Tree",
"$",
"tree",
",",
"$",
"gedrec",
")",
":",
"string",
"{",
"while",
"(",
"preg_match",
"(",
"'/\\n1 OBJE(?:\\n[2-9].+)+/'",
",",
"$",
"gedrec",
",",
"$",
"match",
")",
")",
"{",
"$",
"gedrec",
"=",
"str_replace",
"(",
"$",
"match",
"[",
"0",
"]",
",",
"self",
"::",
"createMediaObject",
"(",
"1",
",",
"$",
"match",
"[",
"0",
"]",
",",
"$",
"tree",
")",
",",
"$",
"gedrec",
")",
";",
"}",
"while",
"(",
"preg_match",
"(",
"'/\\n2 OBJE(?:\\n[3-9].+)+/'",
",",
"$",
"gedrec",
",",
"$",
"match",
")",
")",
"{",
"$",
"gedrec",
"=",
"str_replace",
"(",
"$",
"match",
"[",
"0",
"]",
",",
"self",
"::",
"createMediaObject",
"(",
"2",
",",
"$",
"match",
"[",
"0",
"]",
",",
"$",
"tree",
")",
",",
"$",
"gedrec",
")",
";",
"}",
"while",
"(",
"preg_match",
"(",
"'/\\n3 OBJE(?:\\n[4-9].+)+/'",
",",
"$",
"gedrec",
",",
"$",
"match",
")",
")",
"{",
"$",
"gedrec",
"=",
"str_replace",
"(",
"$",
"match",
"[",
"0",
"]",
",",
"self",
"::",
"createMediaObject",
"(",
"3",
",",
"$",
"match",
"[",
"0",
"]",
",",
"$",
"tree",
")",
",",
"$",
"gedrec",
")",
";",
"}",
"return",
"$",
"gedrec",
";",
"}"
] | Extract inline media data, and convert to media objects.
@param Tree $tree
@param string $gedrec
@return string | [
"Extract",
"inline",
"media",
"data",
"and",
"convert",
"to",
"media",
"objects",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Functions/FunctionsImport.php#L985-L998 | train |
fisharebest/webtrees | app/Functions/FunctionsImport.php | FunctionsImport.createMediaObject | public static function createMediaObject($level, $gedrec, Tree $tree): string
{
if (preg_match('/\n\d FILE (.+)/', $gedrec, $file_match)) {
$file = $file_match[1];
} else {
$file = '';
}
if (preg_match('/\n\d TITL (.+)/', $gedrec, $file_match)) {
$titl = $file_match[1];
} else {
$titl = '';
}
// Have we already created a media object with the same title/filename?
$xref = DB::table('media_file')
->where('m_file', '=', $tree->id())
->where('descriptive_title', '=', $titl)
->where('multimedia_file_refn', '=', mb_substr($file, 0, 248))
->value('m_id');
if (!$xref) {
$xref = $tree->getNewXref();
// renumber the lines
$gedrec = preg_replace_callback('/\n(\d+)/', static function (array $m) use ($level): string {
return "\n" . ($m[1] - $level);
}, $gedrec);
// convert to an object
$gedrec = str_replace("\n0 OBJE\n", '0 @' . $xref . "@ OBJE\n", $gedrec);
// Fix Legacy GEDCOMS
$gedrec = preg_replace('/\n1 FORM (.+)\n1 FILE (.+)\n1 TITL (.+)/', "\n1 FILE $2\n2 FORM $1\n2 TITL $3", $gedrec);
// Fix FTB GEDCOMS
$gedrec = preg_replace('/\n1 FORM (.+)\n1 TITL (.+)\n1 FILE (.+)/', "\n1 FILE $3\n2 FORM $1\n2 TITL $2", $gedrec);
// Fix RM7 GEDCOMS
$gedrec = preg_replace('/\n1 FILE (.+)\n1 FORM (.+)\n1 TITL (.+)/', "\n1 FILE $1\n2 FORM $2\n2 TITL $3", $gedrec);
// Create new record
$record = new Media($xref, $gedrec, null, $tree);
DB::table('media')->insert([
'm_id' => $xref,
'm_file' => $tree->id(),
'm_gedcom' => $gedrec,
]);
foreach ($record->mediaFiles() as $media_file) {
DB::table('media_file')->insert([
'm_id' => $xref,
'm_file' => $tree->id(),
'multimedia_file_refn' => mb_substr($media_file->filename(), 0, 248),
'multimedia_format' => mb_substr($media_file->format(), 0, 4),
'source_media_type' => mb_substr($media_file->type(), 0, 15),
'descriptive_title' => mb_substr($media_file->title(), 0, 248),
]);
}
}
return "\n" . $level . ' OBJE @' . $xref . '@';
} | php | public static function createMediaObject($level, $gedrec, Tree $tree): string
{
if (preg_match('/\n\d FILE (.+)/', $gedrec, $file_match)) {
$file = $file_match[1];
} else {
$file = '';
}
if (preg_match('/\n\d TITL (.+)/', $gedrec, $file_match)) {
$titl = $file_match[1];
} else {
$titl = '';
}
// Have we already created a media object with the same title/filename?
$xref = DB::table('media_file')
->where('m_file', '=', $tree->id())
->where('descriptive_title', '=', $titl)
->where('multimedia_file_refn', '=', mb_substr($file, 0, 248))
->value('m_id');
if (!$xref) {
$xref = $tree->getNewXref();
// renumber the lines
$gedrec = preg_replace_callback('/\n(\d+)/', static function (array $m) use ($level): string {
return "\n" . ($m[1] - $level);
}, $gedrec);
// convert to an object
$gedrec = str_replace("\n0 OBJE\n", '0 @' . $xref . "@ OBJE\n", $gedrec);
// Fix Legacy GEDCOMS
$gedrec = preg_replace('/\n1 FORM (.+)\n1 FILE (.+)\n1 TITL (.+)/', "\n1 FILE $2\n2 FORM $1\n2 TITL $3", $gedrec);
// Fix FTB GEDCOMS
$gedrec = preg_replace('/\n1 FORM (.+)\n1 TITL (.+)\n1 FILE (.+)/', "\n1 FILE $3\n2 FORM $1\n2 TITL $2", $gedrec);
// Fix RM7 GEDCOMS
$gedrec = preg_replace('/\n1 FILE (.+)\n1 FORM (.+)\n1 TITL (.+)/', "\n1 FILE $1\n2 FORM $2\n2 TITL $3", $gedrec);
// Create new record
$record = new Media($xref, $gedrec, null, $tree);
DB::table('media')->insert([
'm_id' => $xref,
'm_file' => $tree->id(),
'm_gedcom' => $gedrec,
]);
foreach ($record->mediaFiles() as $media_file) {
DB::table('media_file')->insert([
'm_id' => $xref,
'm_file' => $tree->id(),
'multimedia_file_refn' => mb_substr($media_file->filename(), 0, 248),
'multimedia_format' => mb_substr($media_file->format(), 0, 4),
'source_media_type' => mb_substr($media_file->type(), 0, 15),
'descriptive_title' => mb_substr($media_file->title(), 0, 248),
]);
}
}
return "\n" . $level . ' OBJE @' . $xref . '@';
} | [
"public",
"static",
"function",
"createMediaObject",
"(",
"$",
"level",
",",
"$",
"gedrec",
",",
"Tree",
"$",
"tree",
")",
":",
"string",
"{",
"if",
"(",
"preg_match",
"(",
"'/\\n\\d FILE (.+)/'",
",",
"$",
"gedrec",
",",
"$",
"file_match",
")",
")",
"{",
"$",
"file",
"=",
"$",
"file_match",
"[",
"1",
"]",
";",
"}",
"else",
"{",
"$",
"file",
"=",
"''",
";",
"}",
"if",
"(",
"preg_match",
"(",
"'/\\n\\d TITL (.+)/'",
",",
"$",
"gedrec",
",",
"$",
"file_match",
")",
")",
"{",
"$",
"titl",
"=",
"$",
"file_match",
"[",
"1",
"]",
";",
"}",
"else",
"{",
"$",
"titl",
"=",
"''",
";",
"}",
"// Have we already created a media object with the same title/filename?",
"$",
"xref",
"=",
"DB",
"::",
"table",
"(",
"'media_file'",
")",
"->",
"where",
"(",
"'m_file'",
",",
"'='",
",",
"$",
"tree",
"->",
"id",
"(",
")",
")",
"->",
"where",
"(",
"'descriptive_title'",
",",
"'='",
",",
"$",
"titl",
")",
"->",
"where",
"(",
"'multimedia_file_refn'",
",",
"'='",
",",
"mb_substr",
"(",
"$",
"file",
",",
"0",
",",
"248",
")",
")",
"->",
"value",
"(",
"'m_id'",
")",
";",
"if",
"(",
"!",
"$",
"xref",
")",
"{",
"$",
"xref",
"=",
"$",
"tree",
"->",
"getNewXref",
"(",
")",
";",
"// renumber the lines",
"$",
"gedrec",
"=",
"preg_replace_callback",
"(",
"'/\\n(\\d+)/'",
",",
"static",
"function",
"(",
"array",
"$",
"m",
")",
"use",
"(",
"$",
"level",
")",
":",
"string",
"{",
"return",
"\"\\n\"",
".",
"(",
"$",
"m",
"[",
"1",
"]",
"-",
"$",
"level",
")",
";",
"}",
",",
"$",
"gedrec",
")",
";",
"// convert to an object",
"$",
"gedrec",
"=",
"str_replace",
"(",
"\"\\n0 OBJE\\n\"",
",",
"'0 @'",
".",
"$",
"xref",
".",
"\"@ OBJE\\n\"",
",",
"$",
"gedrec",
")",
";",
"// Fix Legacy GEDCOMS",
"$",
"gedrec",
"=",
"preg_replace",
"(",
"'/\\n1 FORM (.+)\\n1 FILE (.+)\\n1 TITL (.+)/'",
",",
"\"\\n1 FILE $2\\n2 FORM $1\\n2 TITL $3\"",
",",
"$",
"gedrec",
")",
";",
"// Fix FTB GEDCOMS",
"$",
"gedrec",
"=",
"preg_replace",
"(",
"'/\\n1 FORM (.+)\\n1 TITL (.+)\\n1 FILE (.+)/'",
",",
"\"\\n1 FILE $3\\n2 FORM $1\\n2 TITL $2\"",
",",
"$",
"gedrec",
")",
";",
"// Fix RM7 GEDCOMS",
"$",
"gedrec",
"=",
"preg_replace",
"(",
"'/\\n1 FILE (.+)\\n1 FORM (.+)\\n1 TITL (.+)/'",
",",
"\"\\n1 FILE $1\\n2 FORM $2\\n2 TITL $3\"",
",",
"$",
"gedrec",
")",
";",
"// Create new record",
"$",
"record",
"=",
"new",
"Media",
"(",
"$",
"xref",
",",
"$",
"gedrec",
",",
"null",
",",
"$",
"tree",
")",
";",
"DB",
"::",
"table",
"(",
"'media'",
")",
"->",
"insert",
"(",
"[",
"'m_id'",
"=>",
"$",
"xref",
",",
"'m_file'",
"=>",
"$",
"tree",
"->",
"id",
"(",
")",
",",
"'m_gedcom'",
"=>",
"$",
"gedrec",
",",
"]",
")",
";",
"foreach",
"(",
"$",
"record",
"->",
"mediaFiles",
"(",
")",
"as",
"$",
"media_file",
")",
"{",
"DB",
"::",
"table",
"(",
"'media_file'",
")",
"->",
"insert",
"(",
"[",
"'m_id'",
"=>",
"$",
"xref",
",",
"'m_file'",
"=>",
"$",
"tree",
"->",
"id",
"(",
")",
",",
"'multimedia_file_refn'",
"=>",
"mb_substr",
"(",
"$",
"media_file",
"->",
"filename",
"(",
")",
",",
"0",
",",
"248",
")",
",",
"'multimedia_format'",
"=>",
"mb_substr",
"(",
"$",
"media_file",
"->",
"format",
"(",
")",
",",
"0",
",",
"4",
")",
",",
"'source_media_type'",
"=>",
"mb_substr",
"(",
"$",
"media_file",
"->",
"type",
"(",
")",
",",
"0",
",",
"15",
")",
",",
"'descriptive_title'",
"=>",
"mb_substr",
"(",
"$",
"media_file",
"->",
"title",
"(",
")",
",",
"0",
",",
"248",
")",
",",
"]",
")",
";",
"}",
"}",
"return",
"\"\\n\"",
".",
"$",
"level",
".",
"' OBJE @'",
".",
"$",
"xref",
".",
"'@'",
";",
"}"
] | Create a new media object, from inline media data.
@param int $level
@param string $gedrec
@param Tree $tree
@return string | [
"Create",
"a",
"new",
"media",
"object",
"from",
"inline",
"media",
"data",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Functions/FunctionsImport.php#L1009-L1070 | train |
fisharebest/webtrees | app/Functions/FunctionsImport.php | FunctionsImport.acceptAllChanges | public static function acceptAllChanges($xref, Tree $tree): void
{
$changes = DB::table('change')
->join('gedcom', 'change.gedcom_id', '=', 'gedcom.gedcom_id')
->where('status', '=', 'pending')
->where('xref', '=', $xref)
->where('gedcom.gedcom_id', '=', $tree->id())
->orderBy('change_id')
->select(['change_id', 'gedcom_name', 'old_gedcom', 'new_gedcom'])
->get();
foreach ($changes as $change) {
if (empty($change->new_gedcom)) {
// delete
self::updateRecord($change->old_gedcom, $tree, true);
} else {
// add/update
self::updateRecord($change->new_gedcom, $tree, false);
}
DB::table('change')
->where('change_id', '=', $change->change_id)
->update(['status' => 'accepted']);
Log::addEditLog("Accepted change {$change->change_id} for {$xref} / {$change->gedcom_name} into database", $tree);
}
} | php | public static function acceptAllChanges($xref, Tree $tree): void
{
$changes = DB::table('change')
->join('gedcom', 'change.gedcom_id', '=', 'gedcom.gedcom_id')
->where('status', '=', 'pending')
->where('xref', '=', $xref)
->where('gedcom.gedcom_id', '=', $tree->id())
->orderBy('change_id')
->select(['change_id', 'gedcom_name', 'old_gedcom', 'new_gedcom'])
->get();
foreach ($changes as $change) {
if (empty($change->new_gedcom)) {
// delete
self::updateRecord($change->old_gedcom, $tree, true);
} else {
// add/update
self::updateRecord($change->new_gedcom, $tree, false);
}
DB::table('change')
->where('change_id', '=', $change->change_id)
->update(['status' => 'accepted']);
Log::addEditLog("Accepted change {$change->change_id} for {$xref} / {$change->gedcom_name} into database", $tree);
}
} | [
"public",
"static",
"function",
"acceptAllChanges",
"(",
"$",
"xref",
",",
"Tree",
"$",
"tree",
")",
":",
"void",
"{",
"$",
"changes",
"=",
"DB",
"::",
"table",
"(",
"'change'",
")",
"->",
"join",
"(",
"'gedcom'",
",",
"'change.gedcom_id'",
",",
"'='",
",",
"'gedcom.gedcom_id'",
")",
"->",
"where",
"(",
"'status'",
",",
"'='",
",",
"'pending'",
")",
"->",
"where",
"(",
"'xref'",
",",
"'='",
",",
"$",
"xref",
")",
"->",
"where",
"(",
"'gedcom.gedcom_id'",
",",
"'='",
",",
"$",
"tree",
"->",
"id",
"(",
")",
")",
"->",
"orderBy",
"(",
"'change_id'",
")",
"->",
"select",
"(",
"[",
"'change_id'",
",",
"'gedcom_name'",
",",
"'old_gedcom'",
",",
"'new_gedcom'",
"]",
")",
"->",
"get",
"(",
")",
";",
"foreach",
"(",
"$",
"changes",
"as",
"$",
"change",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"change",
"->",
"new_gedcom",
")",
")",
"{",
"// delete",
"self",
"::",
"updateRecord",
"(",
"$",
"change",
"->",
"old_gedcom",
",",
"$",
"tree",
",",
"true",
")",
";",
"}",
"else",
"{",
"// add/update",
"self",
"::",
"updateRecord",
"(",
"$",
"change",
"->",
"new_gedcom",
",",
"$",
"tree",
",",
"false",
")",
";",
"}",
"DB",
"::",
"table",
"(",
"'change'",
")",
"->",
"where",
"(",
"'change_id'",
",",
"'='",
",",
"$",
"change",
"->",
"change_id",
")",
"->",
"update",
"(",
"[",
"'status'",
"=>",
"'accepted'",
"]",
")",
";",
"Log",
"::",
"addEditLog",
"(",
"\"Accepted change {$change->change_id} for {$xref} / {$change->gedcom_name} into database\"",
",",
"$",
"tree",
")",
";",
"}",
"}"
] | Accept all pending changes for a specified record.
@param string $xref
@param Tree $tree
@return void | [
"Accept",
"all",
"pending",
"changes",
"for",
"a",
"specified",
"record",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Functions/FunctionsImport.php#L1080-L1106 | train |
fisharebest/webtrees | app/Http/Controllers/NoteController.php | NoteController.show | public function show(ServerRequestInterface $request, Tree $tree, ClipboardService $clipboard_service): ResponseInterface
{
$xref = $request->get('xref', '');
$record = Note::getInstance($xref, $tree);
Auth::checkNoteAccess($record, false);
return $this->viewResponse('note-page', [
'clipboard_facts' => $clipboard_service->pastableFacts($record, new Collection()),
'facts' => $this->facts($record),
'families' => $record->linkedFamilies('NOTE'),
'individuals' => $record->linkedIndividuals('NOTE'),
'note' => $record,
'notes' => [],
'media_objects' => $record->linkedMedia('NOTE'),
'meta_robots' => 'index,follow',
'sources' => $record->linkedSources('NOTE'),
'text' => Filter::formatText($record->getNote(), $tree),
'title' => $record->fullName(),
]);
} | php | public function show(ServerRequestInterface $request, Tree $tree, ClipboardService $clipboard_service): ResponseInterface
{
$xref = $request->get('xref', '');
$record = Note::getInstance($xref, $tree);
Auth::checkNoteAccess($record, false);
return $this->viewResponse('note-page', [
'clipboard_facts' => $clipboard_service->pastableFacts($record, new Collection()),
'facts' => $this->facts($record),
'families' => $record->linkedFamilies('NOTE'),
'individuals' => $record->linkedIndividuals('NOTE'),
'note' => $record,
'notes' => [],
'media_objects' => $record->linkedMedia('NOTE'),
'meta_robots' => 'index,follow',
'sources' => $record->linkedSources('NOTE'),
'text' => Filter::formatText($record->getNote(), $tree),
'title' => $record->fullName(),
]);
} | [
"public",
"function",
"show",
"(",
"ServerRequestInterface",
"$",
"request",
",",
"Tree",
"$",
"tree",
",",
"ClipboardService",
"$",
"clipboard_service",
")",
":",
"ResponseInterface",
"{",
"$",
"xref",
"=",
"$",
"request",
"->",
"get",
"(",
"'xref'",
",",
"''",
")",
";",
"$",
"record",
"=",
"Note",
"::",
"getInstance",
"(",
"$",
"xref",
",",
"$",
"tree",
")",
";",
"Auth",
"::",
"checkNoteAccess",
"(",
"$",
"record",
",",
"false",
")",
";",
"return",
"$",
"this",
"->",
"viewResponse",
"(",
"'note-page'",
",",
"[",
"'clipboard_facts'",
"=>",
"$",
"clipboard_service",
"->",
"pastableFacts",
"(",
"$",
"record",
",",
"new",
"Collection",
"(",
")",
")",
",",
"'facts'",
"=>",
"$",
"this",
"->",
"facts",
"(",
"$",
"record",
")",
",",
"'families'",
"=>",
"$",
"record",
"->",
"linkedFamilies",
"(",
"'NOTE'",
")",
",",
"'individuals'",
"=>",
"$",
"record",
"->",
"linkedIndividuals",
"(",
"'NOTE'",
")",
",",
"'note'",
"=>",
"$",
"record",
",",
"'notes'",
"=>",
"[",
"]",
",",
"'media_objects'",
"=>",
"$",
"record",
"->",
"linkedMedia",
"(",
"'NOTE'",
")",
",",
"'meta_robots'",
"=>",
"'index,follow'",
",",
"'sources'",
"=>",
"$",
"record",
"->",
"linkedSources",
"(",
"'NOTE'",
")",
",",
"'text'",
"=>",
"Filter",
"::",
"formatText",
"(",
"$",
"record",
"->",
"getNote",
"(",
")",
",",
"$",
"tree",
")",
",",
"'title'",
"=>",
"$",
"record",
"->",
"fullName",
"(",
")",
",",
"]",
")",
";",
"}"
] | Show a note's page.
@param ServerRequestInterface $request
@param Tree $tree
@param ClipboardService $clipboard_service
@return ResponseInterface | [
"Show",
"a",
"note",
"s",
"page",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Http/Controllers/NoteController.php#L44-L64 | train |
fisharebest/webtrees | app/Module/GoogleAnalyticsModule.php | GoogleAnalyticsModule.analyticsSnippet | public function analyticsSnippet(array $parameters): string
{
// Add extra dimensions (i.e. filtering categories)
$tree = app(Tree::class);
$user = app(UserInterface::class);
$parameters['dimensions'] = (object) [
'dimension1' => $tree instanceof Tree ? $tree->name() : '-',
'dimension2' => $tree instanceof Tree ? Auth::accessLevel($tree, $user) : '-',
];
return view('modules/google-analytics/snippet', $parameters);
} | php | public function analyticsSnippet(array $parameters): string
{
// Add extra dimensions (i.e. filtering categories)
$tree = app(Tree::class);
$user = app(UserInterface::class);
$parameters['dimensions'] = (object) [
'dimension1' => $tree instanceof Tree ? $tree->name() : '-',
'dimension2' => $tree instanceof Tree ? Auth::accessLevel($tree, $user) : '-',
];
return view('modules/google-analytics/snippet', $parameters);
} | [
"public",
"function",
"analyticsSnippet",
"(",
"array",
"$",
"parameters",
")",
":",
"string",
"{",
"// Add extra dimensions (i.e. filtering categories)",
"$",
"tree",
"=",
"app",
"(",
"Tree",
"::",
"class",
")",
";",
"$",
"user",
"=",
"app",
"(",
"UserInterface",
"::",
"class",
")",
";",
"$",
"parameters",
"[",
"'dimensions'",
"]",
"=",
"(",
"object",
")",
"[",
"'dimension1'",
"=>",
"$",
"tree",
"instanceof",
"Tree",
"?",
"$",
"tree",
"->",
"name",
"(",
")",
":",
"'-'",
",",
"'dimension2'",
"=>",
"$",
"tree",
"instanceof",
"Tree",
"?",
"Auth",
"::",
"accessLevel",
"(",
"$",
"tree",
",",
"$",
"user",
")",
":",
"'-'",
",",
"]",
";",
"return",
"view",
"(",
"'modules/google-analytics/snippet'",
",",
"$",
"parameters",
")",
";",
"}"
] | Embed placeholders in the snippet.
@param string[] $parameters
@return string | [
"Embed",
"placeholders",
"in",
"the",
"snippet",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Module/GoogleAnalyticsModule.php#L93-L105 | train |
fisharebest/webtrees | app/GedcomCode/GedcomCodeStat.php | GedcomCodeStat.statusName | public static function statusName(string $status_code): string
{
switch ($status_code) {
case 'BIC':
/* I18N: LDS sealing status; see http://en.wikipedia.org/wiki/Sealing_(Latter_Day_Saints) */
return I18N::translate('Born in the covenant');
case 'CANCELED':
/* I18N: LDS sealing status; see http://en.wikipedia.org/wiki/Sealing_(Latter_Day_Saints) */
return I18N::translate('Sealing canceled (divorce)');
case 'CHILD':
/* I18N: LDS sealing status; see http://en.wikipedia.org/wiki/Sealing_(Latter_Day_Saints) */
return I18N::translate('Died as a child: exempt');
case 'CLEARED':
// This status appears in PhpGedView, but not in the GEDCOM 5.5.1 specification.
/* I18N: LDS sealing status; see http://en.wikipedia.org/wiki/Sealing_(Latter_Day_Saints) */
return I18N::translate('Cleared but not yet completed');
case 'COMPLETED':
/* I18N: LDS sealing status; see http://en.wikipedia.org/wiki/Sealing_(Latter_Day_Saints) */
return I18N::translate('Completed; date unknown');
case 'DNS':
/* I18N: LDS sealing status; see http://en.wikipedia.org/wiki/Sealing_(Latter_Day_Saints) */
return I18N::translate('Do not seal: unauthorized');
case 'DNS/CAN':
/* I18N: LDS sealing status; see http://en.wikipedia.org/wiki/Sealing_(Latter_Day_Saints) */
return I18N::translate('Do not seal, previous sealing canceled');
case 'EXCLUDED':
/* I18N: LDS sealing status; see http://en.wikipedia.org/wiki/Sealing_(Latter_Day_Saints) */
return I18N::translate('Excluded from this submission');
case 'INFANT':
/* I18N: LDS sealing status; see http://en.wikipedia.org/wiki/Sealing_(Latter_Day_Saints) */
return I18N::translate('Died as an infant: exempt');
case 'PRE-1970':
/* I18N: LDS sealing status; see http://en.wikipedia.org/wiki/Sealing_(Latter_Day_Saints) */
return I18N::translate('Completed before 1970; date not available');
case 'STILLBORN':
/* I18N: LDS sealing status; see http://en.wikipedia.org/wiki/Sealing_(Latter_Day_Saints) */
return I18N::translate('Stillborn: exempt');
case 'SUBMITTED':
/* I18N: LDS sealing status; see http://en.wikipedia.org/wiki/Sealing_(Latter_Day_Saints) */
return I18N::translate('Submitted but not yet cleared');
case 'UNCLEARED':
/* I18N: LDS sealing status; see http://en.wikipedia.org/wiki/Sealing_(Latter_Day_Saints) */
return I18N::translate('Uncleared: insufficient data');
default:
return $status_code;
}
} | php | public static function statusName(string $status_code): string
{
switch ($status_code) {
case 'BIC':
/* I18N: LDS sealing status; see http://en.wikipedia.org/wiki/Sealing_(Latter_Day_Saints) */
return I18N::translate('Born in the covenant');
case 'CANCELED':
/* I18N: LDS sealing status; see http://en.wikipedia.org/wiki/Sealing_(Latter_Day_Saints) */
return I18N::translate('Sealing canceled (divorce)');
case 'CHILD':
/* I18N: LDS sealing status; see http://en.wikipedia.org/wiki/Sealing_(Latter_Day_Saints) */
return I18N::translate('Died as a child: exempt');
case 'CLEARED':
// This status appears in PhpGedView, but not in the GEDCOM 5.5.1 specification.
/* I18N: LDS sealing status; see http://en.wikipedia.org/wiki/Sealing_(Latter_Day_Saints) */
return I18N::translate('Cleared but not yet completed');
case 'COMPLETED':
/* I18N: LDS sealing status; see http://en.wikipedia.org/wiki/Sealing_(Latter_Day_Saints) */
return I18N::translate('Completed; date unknown');
case 'DNS':
/* I18N: LDS sealing status; see http://en.wikipedia.org/wiki/Sealing_(Latter_Day_Saints) */
return I18N::translate('Do not seal: unauthorized');
case 'DNS/CAN':
/* I18N: LDS sealing status; see http://en.wikipedia.org/wiki/Sealing_(Latter_Day_Saints) */
return I18N::translate('Do not seal, previous sealing canceled');
case 'EXCLUDED':
/* I18N: LDS sealing status; see http://en.wikipedia.org/wiki/Sealing_(Latter_Day_Saints) */
return I18N::translate('Excluded from this submission');
case 'INFANT':
/* I18N: LDS sealing status; see http://en.wikipedia.org/wiki/Sealing_(Latter_Day_Saints) */
return I18N::translate('Died as an infant: exempt');
case 'PRE-1970':
/* I18N: LDS sealing status; see http://en.wikipedia.org/wiki/Sealing_(Latter_Day_Saints) */
return I18N::translate('Completed before 1970; date not available');
case 'STILLBORN':
/* I18N: LDS sealing status; see http://en.wikipedia.org/wiki/Sealing_(Latter_Day_Saints) */
return I18N::translate('Stillborn: exempt');
case 'SUBMITTED':
/* I18N: LDS sealing status; see http://en.wikipedia.org/wiki/Sealing_(Latter_Day_Saints) */
return I18N::translate('Submitted but not yet cleared');
case 'UNCLEARED':
/* I18N: LDS sealing status; see http://en.wikipedia.org/wiki/Sealing_(Latter_Day_Saints) */
return I18N::translate('Uncleared: insufficient data');
default:
return $status_code;
}
} | [
"public",
"static",
"function",
"statusName",
"(",
"string",
"$",
"status_code",
")",
":",
"string",
"{",
"switch",
"(",
"$",
"status_code",
")",
"{",
"case",
"'BIC'",
":",
"/* I18N: LDS sealing status; see http://en.wikipedia.org/wiki/Sealing_(Latter_Day_Saints) */",
"return",
"I18N",
"::",
"translate",
"(",
"'Born in the covenant'",
")",
";",
"case",
"'CANCELED'",
":",
"/* I18N: LDS sealing status; see http://en.wikipedia.org/wiki/Sealing_(Latter_Day_Saints) */",
"return",
"I18N",
"::",
"translate",
"(",
"'Sealing canceled (divorce)'",
")",
";",
"case",
"'CHILD'",
":",
"/* I18N: LDS sealing status; see http://en.wikipedia.org/wiki/Sealing_(Latter_Day_Saints) */",
"return",
"I18N",
"::",
"translate",
"(",
"'Died as a child: exempt'",
")",
";",
"case",
"'CLEARED'",
":",
"// This status appears in PhpGedView, but not in the GEDCOM 5.5.1 specification.",
"/* I18N: LDS sealing status; see http://en.wikipedia.org/wiki/Sealing_(Latter_Day_Saints) */",
"return",
"I18N",
"::",
"translate",
"(",
"'Cleared but not yet completed'",
")",
";",
"case",
"'COMPLETED'",
":",
"/* I18N: LDS sealing status; see http://en.wikipedia.org/wiki/Sealing_(Latter_Day_Saints) */",
"return",
"I18N",
"::",
"translate",
"(",
"'Completed; date unknown'",
")",
";",
"case",
"'DNS'",
":",
"/* I18N: LDS sealing status; see http://en.wikipedia.org/wiki/Sealing_(Latter_Day_Saints) */",
"return",
"I18N",
"::",
"translate",
"(",
"'Do not seal: unauthorized'",
")",
";",
"case",
"'DNS/CAN'",
":",
"/* I18N: LDS sealing status; see http://en.wikipedia.org/wiki/Sealing_(Latter_Day_Saints) */",
"return",
"I18N",
"::",
"translate",
"(",
"'Do not seal, previous sealing canceled'",
")",
";",
"case",
"'EXCLUDED'",
":",
"/* I18N: LDS sealing status; see http://en.wikipedia.org/wiki/Sealing_(Latter_Day_Saints) */",
"return",
"I18N",
"::",
"translate",
"(",
"'Excluded from this submission'",
")",
";",
"case",
"'INFANT'",
":",
"/* I18N: LDS sealing status; see http://en.wikipedia.org/wiki/Sealing_(Latter_Day_Saints) */",
"return",
"I18N",
"::",
"translate",
"(",
"'Died as an infant: exempt'",
")",
";",
"case",
"'PRE-1970'",
":",
"/* I18N: LDS sealing status; see http://en.wikipedia.org/wiki/Sealing_(Latter_Day_Saints) */",
"return",
"I18N",
"::",
"translate",
"(",
"'Completed before 1970; date not available'",
")",
";",
"case",
"'STILLBORN'",
":",
"/* I18N: LDS sealing status; see http://en.wikipedia.org/wiki/Sealing_(Latter_Day_Saints) */",
"return",
"I18N",
"::",
"translate",
"(",
"'Stillborn: exempt'",
")",
";",
"case",
"'SUBMITTED'",
":",
"/* I18N: LDS sealing status; see http://en.wikipedia.org/wiki/Sealing_(Latter_Day_Saints) */",
"return",
"I18N",
"::",
"translate",
"(",
"'Submitted but not yet cleared'",
")",
";",
"case",
"'UNCLEARED'",
":",
"/* I18N: LDS sealing status; see http://en.wikipedia.org/wiki/Sealing_(Latter_Day_Saints) */",
"return",
"I18N",
"::",
"translate",
"(",
"'Uncleared: insufficient data'",
")",
";",
"default",
":",
"return",
"$",
"status_code",
";",
"}",
"}"
] | Get the localized name for a status code
@param string $status_code
@return string | [
"Get",
"the",
"localized",
"name",
"for",
"a",
"status",
"code"
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/GedcomCode/GedcomCodeStat.php#L98-L144 | train |
fisharebest/webtrees | app/GedcomCode/GedcomCodeStat.php | GedcomCodeStat.statusNames | public static function statusNames(string $tag): array
{
$status_names = [];
foreach (self::statusCodes($tag) as $status_code) {
$status_names[$status_code] = self::statusName($status_code);
}
uasort($status_names, '\Fisharebest\Webtrees\I18N::strcasecmp');
return $status_names;
} | php | public static function statusNames(string $tag): array
{
$status_names = [];
foreach (self::statusCodes($tag) as $status_code) {
$status_names[$status_code] = self::statusName($status_code);
}
uasort($status_names, '\Fisharebest\Webtrees\I18N::strcasecmp');
return $status_names;
} | [
"public",
"static",
"function",
"statusNames",
"(",
"string",
"$",
"tag",
")",
":",
"array",
"{",
"$",
"status_names",
"=",
"[",
"]",
";",
"foreach",
"(",
"self",
"::",
"statusCodes",
"(",
"$",
"tag",
")",
"as",
"$",
"status_code",
")",
"{",
"$",
"status_names",
"[",
"$",
"status_code",
"]",
"=",
"self",
"::",
"statusName",
"(",
"$",
"status_code",
")",
";",
"}",
"uasort",
"(",
"$",
"status_names",
",",
"'\\Fisharebest\\Webtrees\\I18N::strcasecmp'",
")",
";",
"return",
"$",
"status_names",
";",
"}"
] | A sorted list of all status names, for a given GEDCOM tag
@param string $tag
@return string[] | [
"A",
"sorted",
"list",
"of",
"all",
"status",
"names",
"for",
"a",
"given",
"GEDCOM",
"tag"
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/GedcomCode/GedcomCodeStat.php#L153-L162 | train |
fisharebest/webtrees | app/Http/Controllers/AbstractEditController.php | AbstractEditController.addNewFact | protected function addNewFact(ServerRequestInterface $request, Tree $tree, $fact): string
{
$FACT = $request->get($fact, '');
$DATE = $request->get($fact . '_DATE', '');
$PLAC = $request->get($fact . '_PLAC', '');
if ($DATE !== '' || $PLAC !== '' || $FACT !== '' && $FACT !== 'Y') {
if ($FACT !== '' && $FACT !== 'Y') {
$gedrec = "\n1 " . $fact . ' ' . $FACT;
} else {
$gedrec = "\n1 " . $fact;
}
if ($DATE) {
$gedrec .= "\n2 DATE " . $DATE;
}
if ($PLAC) {
$gedrec .= "\n2 PLAC " . $PLAC;
if (preg_match_all('/(' . Gedcom::REGEX_TAG . ')/', $tree->getPreference('ADVANCED_PLAC_FACTS'), $match)) {
foreach ($match[1] as $tag) {
$TAG = $request->get($fact . '_' . $tag, '');
if ($TAG !== '') {
$gedrec .= "\n3 " . $tag . ' ' . $TAG;
}
}
}
$LATI = $request->get($fact . '_LATI', '');
$LONG = $request->get($fact . '_LONG', '');
if ($LATI !== '' || $LONG !== '') {
$gedrec .= "\n3 MAP\n4 LATI " . $LATI . "\n4 LONG " . $LONG;
}
}
if ((bool) $request->get('SOUR_' . $fact)) {
return $this->updateSource($gedrec, 2);
}
return $gedrec;
}
if ($FACT === 'Y') {
if ((bool) $request->get('SOUR_' . $fact)) {
return $this->updateSource("\n1 " . $fact . ' Y', 2);
}
return "\n1 " . $fact . ' Y';
}
return '';
} | php | protected function addNewFact(ServerRequestInterface $request, Tree $tree, $fact): string
{
$FACT = $request->get($fact, '');
$DATE = $request->get($fact . '_DATE', '');
$PLAC = $request->get($fact . '_PLAC', '');
if ($DATE !== '' || $PLAC !== '' || $FACT !== '' && $FACT !== 'Y') {
if ($FACT !== '' && $FACT !== 'Y') {
$gedrec = "\n1 " . $fact . ' ' . $FACT;
} else {
$gedrec = "\n1 " . $fact;
}
if ($DATE) {
$gedrec .= "\n2 DATE " . $DATE;
}
if ($PLAC) {
$gedrec .= "\n2 PLAC " . $PLAC;
if (preg_match_all('/(' . Gedcom::REGEX_TAG . ')/', $tree->getPreference('ADVANCED_PLAC_FACTS'), $match)) {
foreach ($match[1] as $tag) {
$TAG = $request->get($fact . '_' . $tag, '');
if ($TAG !== '') {
$gedrec .= "\n3 " . $tag . ' ' . $TAG;
}
}
}
$LATI = $request->get($fact . '_LATI', '');
$LONG = $request->get($fact . '_LONG', '');
if ($LATI !== '' || $LONG !== '') {
$gedrec .= "\n3 MAP\n4 LATI " . $LATI . "\n4 LONG " . $LONG;
}
}
if ((bool) $request->get('SOUR_' . $fact)) {
return $this->updateSource($gedrec, 2);
}
return $gedrec;
}
if ($FACT === 'Y') {
if ((bool) $request->get('SOUR_' . $fact)) {
return $this->updateSource("\n1 " . $fact . ' Y', 2);
}
return "\n1 " . $fact . ' Y';
}
return '';
} | [
"protected",
"function",
"addNewFact",
"(",
"ServerRequestInterface",
"$",
"request",
",",
"Tree",
"$",
"tree",
",",
"$",
"fact",
")",
":",
"string",
"{",
"$",
"FACT",
"=",
"$",
"request",
"->",
"get",
"(",
"$",
"fact",
",",
"''",
")",
";",
"$",
"DATE",
"=",
"$",
"request",
"->",
"get",
"(",
"$",
"fact",
".",
"'_DATE'",
",",
"''",
")",
";",
"$",
"PLAC",
"=",
"$",
"request",
"->",
"get",
"(",
"$",
"fact",
".",
"'_PLAC'",
",",
"''",
")",
";",
"if",
"(",
"$",
"DATE",
"!==",
"''",
"||",
"$",
"PLAC",
"!==",
"''",
"||",
"$",
"FACT",
"!==",
"''",
"&&",
"$",
"FACT",
"!==",
"'Y'",
")",
"{",
"if",
"(",
"$",
"FACT",
"!==",
"''",
"&&",
"$",
"FACT",
"!==",
"'Y'",
")",
"{",
"$",
"gedrec",
"=",
"\"\\n1 \"",
".",
"$",
"fact",
".",
"' '",
".",
"$",
"FACT",
";",
"}",
"else",
"{",
"$",
"gedrec",
"=",
"\"\\n1 \"",
".",
"$",
"fact",
";",
"}",
"if",
"(",
"$",
"DATE",
")",
"{",
"$",
"gedrec",
".=",
"\"\\n2 DATE \"",
".",
"$",
"DATE",
";",
"}",
"if",
"(",
"$",
"PLAC",
")",
"{",
"$",
"gedrec",
".=",
"\"\\n2 PLAC \"",
".",
"$",
"PLAC",
";",
"if",
"(",
"preg_match_all",
"(",
"'/('",
".",
"Gedcom",
"::",
"REGEX_TAG",
".",
"')/'",
",",
"$",
"tree",
"->",
"getPreference",
"(",
"'ADVANCED_PLAC_FACTS'",
")",
",",
"$",
"match",
")",
")",
"{",
"foreach",
"(",
"$",
"match",
"[",
"1",
"]",
"as",
"$",
"tag",
")",
"{",
"$",
"TAG",
"=",
"$",
"request",
"->",
"get",
"(",
"$",
"fact",
".",
"'_'",
".",
"$",
"tag",
",",
"''",
")",
";",
"if",
"(",
"$",
"TAG",
"!==",
"''",
")",
"{",
"$",
"gedrec",
".=",
"\"\\n3 \"",
".",
"$",
"tag",
".",
"' '",
".",
"$",
"TAG",
";",
"}",
"}",
"}",
"$",
"LATI",
"=",
"$",
"request",
"->",
"get",
"(",
"$",
"fact",
".",
"'_LATI'",
",",
"''",
")",
";",
"$",
"LONG",
"=",
"$",
"request",
"->",
"get",
"(",
"$",
"fact",
".",
"'_LONG'",
",",
"''",
")",
";",
"if",
"(",
"$",
"LATI",
"!==",
"''",
"||",
"$",
"LONG",
"!==",
"''",
")",
"{",
"$",
"gedrec",
".=",
"\"\\n3 MAP\\n4 LATI \"",
".",
"$",
"LATI",
".",
"\"\\n4 LONG \"",
".",
"$",
"LONG",
";",
"}",
"}",
"if",
"(",
"(",
"bool",
")",
"$",
"request",
"->",
"get",
"(",
"'SOUR_'",
".",
"$",
"fact",
")",
")",
"{",
"return",
"$",
"this",
"->",
"updateSource",
"(",
"$",
"gedrec",
",",
"2",
")",
";",
"}",
"return",
"$",
"gedrec",
";",
"}",
"if",
"(",
"$",
"FACT",
"===",
"'Y'",
")",
"{",
"if",
"(",
"(",
"bool",
")",
"$",
"request",
"->",
"get",
"(",
"'SOUR_'",
".",
"$",
"fact",
")",
")",
"{",
"return",
"$",
"this",
"->",
"updateSource",
"(",
"\"\\n1 \"",
".",
"$",
"fact",
".",
"' Y'",
",",
"2",
")",
";",
"}",
"return",
"\"\\n1 \"",
".",
"$",
"fact",
".",
"' Y'",
";",
"}",
"return",
"''",
";",
"}"
] | Create a form to add a new fact.
@param ServerRequestInterface $request
@param Tree $tree
@param string $fact
@return string | [
"Create",
"a",
"form",
"to",
"add",
"a",
"new",
"fact",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Http/Controllers/AbstractEditController.php#L271-L318 | train |
fisharebest/webtrees | app/Http/Controllers/AbstractEditController.php | AbstractEditController.addNewName | protected function addNewName(ServerRequestInterface $request, Tree $tree): string
{
$gedrec = "\n1 NAME " . $request->get('NAME', '');
$tags = [
'NPFX',
'GIVN',
'SPFX',
'SURN',
'NSFX',
];
if (preg_match_all('/(' . Gedcom::REGEX_TAG . ')/', $tree->getPreference('ADVANCED_NAME_FACTS'), $match)) {
$tags = array_merge($tags, $match[1]);
}
// Paternal and Polish and Lithuanian surname traditions can also create a _MARNM
$SURNAME_TRADITION = $tree->getPreference('SURNAME_TRADITION');
if ($SURNAME_TRADITION === 'paternal' || $SURNAME_TRADITION === 'polish' || $SURNAME_TRADITION === 'lithuanian') {
$tags[] = '_MARNM';
}
foreach (array_unique($tags) as $tag) {
$TAG = $request->get($tag, '');
if ($TAG !== '') {
$gedrec .= "\n2 {$tag} {$TAG}";
}
}
return $gedrec;
} | php | protected function addNewName(ServerRequestInterface $request, Tree $tree): string
{
$gedrec = "\n1 NAME " . $request->get('NAME', '');
$tags = [
'NPFX',
'GIVN',
'SPFX',
'SURN',
'NSFX',
];
if (preg_match_all('/(' . Gedcom::REGEX_TAG . ')/', $tree->getPreference('ADVANCED_NAME_FACTS'), $match)) {
$tags = array_merge($tags, $match[1]);
}
// Paternal and Polish and Lithuanian surname traditions can also create a _MARNM
$SURNAME_TRADITION = $tree->getPreference('SURNAME_TRADITION');
if ($SURNAME_TRADITION === 'paternal' || $SURNAME_TRADITION === 'polish' || $SURNAME_TRADITION === 'lithuanian') {
$tags[] = '_MARNM';
}
foreach (array_unique($tags) as $tag) {
$TAG = $request->get($tag, '');
if ($TAG !== '') {
$gedrec .= "\n2 {$tag} {$TAG}";
}
}
return $gedrec;
} | [
"protected",
"function",
"addNewName",
"(",
"ServerRequestInterface",
"$",
"request",
",",
"Tree",
"$",
"tree",
")",
":",
"string",
"{",
"$",
"gedrec",
"=",
"\"\\n1 NAME \"",
".",
"$",
"request",
"->",
"get",
"(",
"'NAME'",
",",
"''",
")",
";",
"$",
"tags",
"=",
"[",
"'NPFX'",
",",
"'GIVN'",
",",
"'SPFX'",
",",
"'SURN'",
",",
"'NSFX'",
",",
"]",
";",
"if",
"(",
"preg_match_all",
"(",
"'/('",
".",
"Gedcom",
"::",
"REGEX_TAG",
".",
"')/'",
",",
"$",
"tree",
"->",
"getPreference",
"(",
"'ADVANCED_NAME_FACTS'",
")",
",",
"$",
"match",
")",
")",
"{",
"$",
"tags",
"=",
"array_merge",
"(",
"$",
"tags",
",",
"$",
"match",
"[",
"1",
"]",
")",
";",
"}",
"// Paternal and Polish and Lithuanian surname traditions can also create a _MARNM",
"$",
"SURNAME_TRADITION",
"=",
"$",
"tree",
"->",
"getPreference",
"(",
"'SURNAME_TRADITION'",
")",
";",
"if",
"(",
"$",
"SURNAME_TRADITION",
"===",
"'paternal'",
"||",
"$",
"SURNAME_TRADITION",
"===",
"'polish'",
"||",
"$",
"SURNAME_TRADITION",
"===",
"'lithuanian'",
")",
"{",
"$",
"tags",
"[",
"]",
"=",
"'_MARNM'",
";",
"}",
"foreach",
"(",
"array_unique",
"(",
"$",
"tags",
")",
"as",
"$",
"tag",
")",
"{",
"$",
"TAG",
"=",
"$",
"request",
"->",
"get",
"(",
"$",
"tag",
",",
"''",
")",
";",
"if",
"(",
"$",
"TAG",
"!==",
"''",
")",
"{",
"$",
"gedrec",
".=",
"\"\\n2 {$tag} {$TAG}\"",
";",
"}",
"}",
"return",
"$",
"gedrec",
";",
"}"
] | Assemble the pieces of a newly created record into gedcom
@param ServerRequestInterface $request
@param Tree $tree
@return string | [
"Assemble",
"the",
"pieces",
"of",
"a",
"newly",
"created",
"record",
"into",
"gedcom"
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Http/Controllers/AbstractEditController.php#L385-L415 | train |
fisharebest/webtrees | app/Http/RequestHandlers/ModuleAction.php | ModuleAction.handle | public function handle(ServerRequestInterface $request): ResponseInterface
{
$module_name = $request->getQueryParams()['module'] ?? $request->getParsedBody()['module'] ?? '';
$action = $request->getQueryParams()['action'] ?? $request->getParsedBody()['action'] ?? '';
// Check that the module is enabled.
// The module itself will need to check any tree-level access,
// which may be different for each component (tab, menu, etc.) of the module.
$module = $this->module_service->findByName($module_name);
if ($module === null) {
throw new NotFoundHttpException('Module ' . $module_name . ' does not exist');
}
// We'll call a function such as Module::getFooBarAction()
$verb = strtolower($request->getMethod());
$method = $verb . $action . 'Action';
// Actions with "Admin" in the name are for administrators only.
if (strpos($action, 'Admin') !== false && !Auth::isAdmin($this->user)) {
throw new AccessDeniedHttpException('Admin only action');
}
if (!method_exists($module, $method)) {
throw new NotFoundHttpException('Method ' . $method . '() not found in ' . $module_name);
}
return app()->dispatch($module, $method);
} | php | public function handle(ServerRequestInterface $request): ResponseInterface
{
$module_name = $request->getQueryParams()['module'] ?? $request->getParsedBody()['module'] ?? '';
$action = $request->getQueryParams()['action'] ?? $request->getParsedBody()['action'] ?? '';
// Check that the module is enabled.
// The module itself will need to check any tree-level access,
// which may be different for each component (tab, menu, etc.) of the module.
$module = $this->module_service->findByName($module_name);
if ($module === null) {
throw new NotFoundHttpException('Module ' . $module_name . ' does not exist');
}
// We'll call a function such as Module::getFooBarAction()
$verb = strtolower($request->getMethod());
$method = $verb . $action . 'Action';
// Actions with "Admin" in the name are for administrators only.
if (strpos($action, 'Admin') !== false && !Auth::isAdmin($this->user)) {
throw new AccessDeniedHttpException('Admin only action');
}
if (!method_exists($module, $method)) {
throw new NotFoundHttpException('Method ' . $method . '() not found in ' . $module_name);
}
return app()->dispatch($module, $method);
} | [
"public",
"function",
"handle",
"(",
"ServerRequestInterface",
"$",
"request",
")",
":",
"ResponseInterface",
"{",
"$",
"module_name",
"=",
"$",
"request",
"->",
"getQueryParams",
"(",
")",
"[",
"'module'",
"]",
"??",
"$",
"request",
"->",
"getParsedBody",
"(",
")",
"[",
"'module'",
"]",
"??",
"''",
";",
"$",
"action",
"=",
"$",
"request",
"->",
"getQueryParams",
"(",
")",
"[",
"'action'",
"]",
"??",
"$",
"request",
"->",
"getParsedBody",
"(",
")",
"[",
"'action'",
"]",
"??",
"''",
";",
"// Check that the module is enabled.",
"// The module itself will need to check any tree-level access,",
"// which may be different for each component (tab, menu, etc.) of the module.",
"$",
"module",
"=",
"$",
"this",
"->",
"module_service",
"->",
"findByName",
"(",
"$",
"module_name",
")",
";",
"if",
"(",
"$",
"module",
"===",
"null",
")",
"{",
"throw",
"new",
"NotFoundHttpException",
"(",
"'Module '",
".",
"$",
"module_name",
".",
"' does not exist'",
")",
";",
"}",
"// We'll call a function such as Module::getFooBarAction()",
"$",
"verb",
"=",
"strtolower",
"(",
"$",
"request",
"->",
"getMethod",
"(",
")",
")",
";",
"$",
"method",
"=",
"$",
"verb",
".",
"$",
"action",
".",
"'Action'",
";",
"// Actions with \"Admin\" in the name are for administrators only.",
"if",
"(",
"strpos",
"(",
"$",
"action",
",",
"'Admin'",
")",
"!==",
"false",
"&&",
"!",
"Auth",
"::",
"isAdmin",
"(",
"$",
"this",
"->",
"user",
")",
")",
"{",
"throw",
"new",
"AccessDeniedHttpException",
"(",
"'Admin only action'",
")",
";",
"}",
"if",
"(",
"!",
"method_exists",
"(",
"$",
"module",
",",
"$",
"method",
")",
")",
"{",
"throw",
"new",
"NotFoundHttpException",
"(",
"'Method '",
".",
"$",
"method",
".",
"'() not found in '",
".",
"$",
"module_name",
")",
";",
"}",
"return",
"app",
"(",
")",
"->",
"dispatch",
"(",
"$",
"module",
",",
"$",
"method",
")",
";",
"}"
] | Perform an HTTP action for one of the modules.
@param ServerRequestInterface $request
@return ResponseInterface | [
"Perform",
"an",
"HTTP",
"action",
"for",
"one",
"of",
"the",
"modules",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Http/RequestHandlers/ModuleAction.php#L63-L91 | train |
fisharebest/webtrees | app/Module/MediaTabModule.php | MediaTabModule.getFactsWithMedia | private function getFactsWithMedia(Individual $individual): Collection
{
if ($this->facts === null) {
$facts = $individual->facts();
foreach ($individual->spouseFamilies() as $family) {
if ($family->canShow()) {
foreach ($family->facts() as $fact) {
$facts->push($fact);
}
}
}
$this->facts = new Collection();
foreach ($facts as $fact) {
if (preg_match('/(?:^1|\n\d) OBJE @' . Gedcom::REGEX_XREF . '@/', $fact->gedcom())) {
$this->facts->push($fact);
}
}
$this->facts = Fact::sortFacts($this->facts);
}
return $this->facts;
} | php | private function getFactsWithMedia(Individual $individual): Collection
{
if ($this->facts === null) {
$facts = $individual->facts();
foreach ($individual->spouseFamilies() as $family) {
if ($family->canShow()) {
foreach ($family->facts() as $fact) {
$facts->push($fact);
}
}
}
$this->facts = new Collection();
foreach ($facts as $fact) {
if (preg_match('/(?:^1|\n\d) OBJE @' . Gedcom::REGEX_XREF . '@/', $fact->gedcom())) {
$this->facts->push($fact);
}
}
$this->facts = Fact::sortFacts($this->facts);
}
return $this->facts;
} | [
"private",
"function",
"getFactsWithMedia",
"(",
"Individual",
"$",
"individual",
")",
":",
"Collection",
"{",
"if",
"(",
"$",
"this",
"->",
"facts",
"===",
"null",
")",
"{",
"$",
"facts",
"=",
"$",
"individual",
"->",
"facts",
"(",
")",
";",
"foreach",
"(",
"$",
"individual",
"->",
"spouseFamilies",
"(",
")",
"as",
"$",
"family",
")",
"{",
"if",
"(",
"$",
"family",
"->",
"canShow",
"(",
")",
")",
"{",
"foreach",
"(",
"$",
"family",
"->",
"facts",
"(",
")",
"as",
"$",
"fact",
")",
"{",
"$",
"facts",
"->",
"push",
"(",
"$",
"fact",
")",
";",
"}",
"}",
"}",
"$",
"this",
"->",
"facts",
"=",
"new",
"Collection",
"(",
")",
";",
"foreach",
"(",
"$",
"facts",
"as",
"$",
"fact",
")",
"{",
"if",
"(",
"preg_match",
"(",
"'/(?:^1|\\n\\d) OBJE @'",
".",
"Gedcom",
"::",
"REGEX_XREF",
".",
"'@/'",
",",
"$",
"fact",
"->",
"gedcom",
"(",
")",
")",
")",
"{",
"$",
"this",
"->",
"facts",
"->",
"push",
"(",
"$",
"fact",
")",
";",
"}",
"}",
"$",
"this",
"->",
"facts",
"=",
"Fact",
"::",
"sortFacts",
"(",
"$",
"this",
"->",
"facts",
")",
";",
"}",
"return",
"$",
"this",
"->",
"facts",
";",
"}"
] | Get all the facts for an individual which contain media objects.
@param Individual $individual
@return Collection
@return Fact[] | [
"Get",
"all",
"the",
"facts",
"for",
"an",
"individual",
"which",
"contain",
"media",
"objects",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Module/MediaTabModule.php#L113-L136 | train |
fisharebest/webtrees | app/Census/AbstractCensusColumn.php | AbstractCensusColumn.father | public function father(Individual $individual): ?Individual
{
$family = $individual->primaryChildFamily();
if ($family) {
return $family->husband();
}
return null;
} | php | public function father(Individual $individual): ?Individual
{
$family = $individual->primaryChildFamily();
if ($family) {
return $family->husband();
}
return null;
} | [
"public",
"function",
"father",
"(",
"Individual",
"$",
"individual",
")",
":",
"?",
"Individual",
"{",
"$",
"family",
"=",
"$",
"individual",
"->",
"primaryChildFamily",
"(",
")",
";",
"if",
"(",
"$",
"family",
")",
"{",
"return",
"$",
"family",
"->",
"husband",
"(",
")",
";",
"}",
"return",
"null",
";",
"}"
] | Find the father of an individual
@param Individual $individual
@return Individual|null | [
"Find",
"the",
"father",
"of",
"an",
"individual"
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Census/AbstractCensusColumn.php#L69-L78 | train |
fisharebest/webtrees | app/Census/AbstractCensusColumn.php | AbstractCensusColumn.mother | public function mother(Individual $individual): ?Individual
{
$family = $individual->primaryChildFamily();
if ($family) {
return $family->wife();
}
return null;
} | php | public function mother(Individual $individual): ?Individual
{
$family = $individual->primaryChildFamily();
if ($family) {
return $family->wife();
}
return null;
} | [
"public",
"function",
"mother",
"(",
"Individual",
"$",
"individual",
")",
":",
"?",
"Individual",
"{",
"$",
"family",
"=",
"$",
"individual",
"->",
"primaryChildFamily",
"(",
")",
";",
"if",
"(",
"$",
"family",
")",
"{",
"return",
"$",
"family",
"->",
"wife",
"(",
")",
";",
"}",
"return",
"null",
";",
"}"
] | Find the mother of an individual
@param Individual $individual
@return Individual|null | [
"Find",
"the",
"mother",
"of",
"an",
"individual"
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Census/AbstractCensusColumn.php#L87-L96 | train |
fisharebest/webtrees | app/Census/AbstractCensusColumn.php | AbstractCensusColumn.spouseFamily | public function spouseFamily(Individual $individual): ?Family
{
// Exclude families that were created after this census date
$families = [];
foreach ($individual->spouseFamilies() as $family) {
if (Date::compare($family->getMarriageDate(), $this->date()) <= 0) {
$families[] = $family;
}
}
if (empty($families)) {
return null;
}
usort($families, static function (Family $x, Family $y): int {
return Date::compare($x->getMarriageDate(), $y->getMarriageDate());
});
return end($families);
} | php | public function spouseFamily(Individual $individual): ?Family
{
// Exclude families that were created after this census date
$families = [];
foreach ($individual->spouseFamilies() as $family) {
if (Date::compare($family->getMarriageDate(), $this->date()) <= 0) {
$families[] = $family;
}
}
if (empty($families)) {
return null;
}
usort($families, static function (Family $x, Family $y): int {
return Date::compare($x->getMarriageDate(), $y->getMarriageDate());
});
return end($families);
} | [
"public",
"function",
"spouseFamily",
"(",
"Individual",
"$",
"individual",
")",
":",
"?",
"Family",
"{",
"// Exclude families that were created after this census date",
"$",
"families",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"individual",
"->",
"spouseFamilies",
"(",
")",
"as",
"$",
"family",
")",
"{",
"if",
"(",
"Date",
"::",
"compare",
"(",
"$",
"family",
"->",
"getMarriageDate",
"(",
")",
",",
"$",
"this",
"->",
"date",
"(",
")",
")",
"<=",
"0",
")",
"{",
"$",
"families",
"[",
"]",
"=",
"$",
"family",
";",
"}",
"}",
"if",
"(",
"empty",
"(",
"$",
"families",
")",
")",
"{",
"return",
"null",
";",
"}",
"usort",
"(",
"$",
"families",
",",
"static",
"function",
"(",
"Family",
"$",
"x",
",",
"Family",
"$",
"y",
")",
":",
"int",
"{",
"return",
"Date",
"::",
"compare",
"(",
"$",
"x",
"->",
"getMarriageDate",
"(",
")",
",",
"$",
"y",
"->",
"getMarriageDate",
"(",
")",
")",
";",
"}",
")",
";",
"return",
"end",
"(",
"$",
"families",
")",
";",
"}"
] | Find the current spouse family of an individual
@param Individual $individual
@return Family|null | [
"Find",
"the",
"current",
"spouse",
"family",
"of",
"an",
"individual"
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Census/AbstractCensusColumn.php#L105-L124 | train |
fisharebest/webtrees | app/Census/AbstractCensusColumn.php | AbstractCensusColumn.notCountry | protected function notCountry(string $place): string
{
$parts = explode(', ', $place);
if (end($parts) === $this->place()) {
return implode(', ', array_slice($parts, 0, -1));
}
return $place;
} | php | protected function notCountry(string $place): string
{
$parts = explode(', ', $place);
if (end($parts) === $this->place()) {
return implode(', ', array_slice($parts, 0, -1));
}
return $place;
} | [
"protected",
"function",
"notCountry",
"(",
"string",
"$",
"place",
")",
":",
"string",
"{",
"$",
"parts",
"=",
"explode",
"(",
"', '",
",",
"$",
"place",
")",
";",
"if",
"(",
"end",
"(",
"$",
"parts",
")",
"===",
"$",
"this",
"->",
"place",
"(",
")",
")",
"{",
"return",
"implode",
"(",
"', '",
",",
"array_slice",
"(",
"$",
"parts",
",",
"0",
",",
"-",
"1",
")",
")",
";",
"}",
"return",
"$",
"place",
";",
"}"
] | Remove the country of a place name, where it is the same as the census place
@param string $place - e.g. "London, England"
@return string - e.g. "London" (for census of England) and "London, England" elsewhere | [
"Remove",
"the",
"country",
"of",
"a",
"place",
"name",
"where",
"it",
"is",
"the",
"same",
"as",
"the",
"census",
"place"
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Census/AbstractCensusColumn.php#L167-L176 | train |
fisharebest/webtrees | app/Services/LocalizationService.php | LocalizationService.alphabet | public function alphabet(): array
{
$locale = $this->locale->languageTag();
$script = $this->locale->script()->code();
return self::ALPHABETS_FOR_LOCALE[$locale] ?? self::ALPHABETS_FOR_SCRIPT[$script] ?? self::LATIN_ALPHABET;
} | php | public function alphabet(): array
{
$locale = $this->locale->languageTag();
$script = $this->locale->script()->code();
return self::ALPHABETS_FOR_LOCALE[$locale] ?? self::ALPHABETS_FOR_SCRIPT[$script] ?? self::LATIN_ALPHABET;
} | [
"public",
"function",
"alphabet",
"(",
")",
":",
"array",
"{",
"$",
"locale",
"=",
"$",
"this",
"->",
"locale",
"->",
"languageTag",
"(",
")",
";",
"$",
"script",
"=",
"$",
"this",
"->",
"locale",
"->",
"script",
"(",
")",
"->",
"code",
"(",
")",
";",
"return",
"self",
"::",
"ALPHABETS_FOR_LOCALE",
"[",
"$",
"locale",
"]",
"??",
"self",
"::",
"ALPHABETS_FOR_SCRIPT",
"[",
"$",
"script",
"]",
"??",
"self",
"::",
"LATIN_ALPHABET",
";",
"}"
] | Which alphabet is used in a locale?
@return array | [
"Which",
"alphabet",
"is",
"used",
"in",
"a",
"locale?"
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Services/LocalizationService.php#L112-L118 | train |
fisharebest/webtrees | app/Services/LocalizationService.php | LocalizationService.calendar | public function calendar(): CalendarInterface
{
$non_gregorian_calendars = [
'ar' => new ArabicCalendar(),
'fa' => new PersianCalendar(),
'he' => new JewishCalendar(),
'yi' => new JewishCalendar(),
];
return $non_gregorian_calendars[$this->locale->languageTag()] ?? new GregorianCalendar();
} | php | public function calendar(): CalendarInterface
{
$non_gregorian_calendars = [
'ar' => new ArabicCalendar(),
'fa' => new PersianCalendar(),
'he' => new JewishCalendar(),
'yi' => new JewishCalendar(),
];
return $non_gregorian_calendars[$this->locale->languageTag()] ?? new GregorianCalendar();
} | [
"public",
"function",
"calendar",
"(",
")",
":",
"CalendarInterface",
"{",
"$",
"non_gregorian_calendars",
"=",
"[",
"'ar'",
"=>",
"new",
"ArabicCalendar",
"(",
")",
",",
"'fa'",
"=>",
"new",
"PersianCalendar",
"(",
")",
",",
"'he'",
"=>",
"new",
"JewishCalendar",
"(",
")",
",",
"'yi'",
"=>",
"new",
"JewishCalendar",
"(",
")",
",",
"]",
";",
"return",
"$",
"non_gregorian_calendars",
"[",
"$",
"this",
"->",
"locale",
"->",
"languageTag",
"(",
")",
"]",
"??",
"new",
"GregorianCalendar",
"(",
")",
";",
"}"
] | Which calendar is used in a locale?
@return CalendarInterface | [
"Which",
"calendar",
"is",
"used",
"in",
"a",
"locale?"
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Services/LocalizationService.php#L125-L135 | train |
fisharebest/webtrees | app/Http/Controllers/Auth/LoginController.php | LoginController.loginPage | public function loginPage(ServerRequestInterface $request, ?Tree $tree): ResponseInterface
{
// Already logged in?
if (Auth::check()) {
$ged = $tree !== null ? $tree->name() : '';
return redirect(route('user-page', ['ged' => $ged]));
}
$error = $request->get('error', '');
$url = $request->get('url', '');
$username = $request->get('username', '');
$title = I18N::translate('Sign in');
switch (Site::getPreference('WELCOME_TEXT_AUTH_MODE')) {
case 1:
default:
$welcome = I18N::translate('Anyone with a user account can access this website.');
break;
case 2:
$welcome = I18N::translate('You need to be an authorized user to access this website.');
break;
case 3:
$welcome = I18N::translate('You need to be a family member to access this website.');
break;
case 4:
$welcome = Site::getPreference('WELCOME_TEXT_AUTH_MODE_' . WT_LOCALE);
break;
}
if (Site::getPreference('USE_REGISTRATION_MODULE') === '1') {
$welcome .= ' ' . I18N::translate('You can apply for an account using the link below.');
}
$can_register = Site::getPreference('USE_REGISTRATION_MODULE') === '1';
return $this->viewResponse('login-page', [
'can_register' => $can_register,
'error' => $error,
'title' => $title,
'url' => $url,
'username' => $username,
'welcome' => $welcome,
]);
} | php | public function loginPage(ServerRequestInterface $request, ?Tree $tree): ResponseInterface
{
// Already logged in?
if (Auth::check()) {
$ged = $tree !== null ? $tree->name() : '';
return redirect(route('user-page', ['ged' => $ged]));
}
$error = $request->get('error', '');
$url = $request->get('url', '');
$username = $request->get('username', '');
$title = I18N::translate('Sign in');
switch (Site::getPreference('WELCOME_TEXT_AUTH_MODE')) {
case 1:
default:
$welcome = I18N::translate('Anyone with a user account can access this website.');
break;
case 2:
$welcome = I18N::translate('You need to be an authorized user to access this website.');
break;
case 3:
$welcome = I18N::translate('You need to be a family member to access this website.');
break;
case 4:
$welcome = Site::getPreference('WELCOME_TEXT_AUTH_MODE_' . WT_LOCALE);
break;
}
if (Site::getPreference('USE_REGISTRATION_MODULE') === '1') {
$welcome .= ' ' . I18N::translate('You can apply for an account using the link below.');
}
$can_register = Site::getPreference('USE_REGISTRATION_MODULE') === '1';
return $this->viewResponse('login-page', [
'can_register' => $can_register,
'error' => $error,
'title' => $title,
'url' => $url,
'username' => $username,
'welcome' => $welcome,
]);
} | [
"public",
"function",
"loginPage",
"(",
"ServerRequestInterface",
"$",
"request",
",",
"?",
"Tree",
"$",
"tree",
")",
":",
"ResponseInterface",
"{",
"// Already logged in?",
"if",
"(",
"Auth",
"::",
"check",
"(",
")",
")",
"{",
"$",
"ged",
"=",
"$",
"tree",
"!==",
"null",
"?",
"$",
"tree",
"->",
"name",
"(",
")",
":",
"''",
";",
"return",
"redirect",
"(",
"route",
"(",
"'user-page'",
",",
"[",
"'ged'",
"=>",
"$",
"ged",
"]",
")",
")",
";",
"}",
"$",
"error",
"=",
"$",
"request",
"->",
"get",
"(",
"'error'",
",",
"''",
")",
";",
"$",
"url",
"=",
"$",
"request",
"->",
"get",
"(",
"'url'",
",",
"''",
")",
";",
"$",
"username",
"=",
"$",
"request",
"->",
"get",
"(",
"'username'",
",",
"''",
")",
";",
"$",
"title",
"=",
"I18N",
"::",
"translate",
"(",
"'Sign in'",
")",
";",
"switch",
"(",
"Site",
"::",
"getPreference",
"(",
"'WELCOME_TEXT_AUTH_MODE'",
")",
")",
"{",
"case",
"1",
":",
"default",
":",
"$",
"welcome",
"=",
"I18N",
"::",
"translate",
"(",
"'Anyone with a user account can access this website.'",
")",
";",
"break",
";",
"case",
"2",
":",
"$",
"welcome",
"=",
"I18N",
"::",
"translate",
"(",
"'You need to be an authorized user to access this website.'",
")",
";",
"break",
";",
"case",
"3",
":",
"$",
"welcome",
"=",
"I18N",
"::",
"translate",
"(",
"'You need to be a family member to access this website.'",
")",
";",
"break",
";",
"case",
"4",
":",
"$",
"welcome",
"=",
"Site",
"::",
"getPreference",
"(",
"'WELCOME_TEXT_AUTH_MODE_'",
".",
"WT_LOCALE",
")",
";",
"break",
";",
"}",
"if",
"(",
"Site",
"::",
"getPreference",
"(",
"'USE_REGISTRATION_MODULE'",
")",
"===",
"'1'",
")",
"{",
"$",
"welcome",
".=",
"' '",
".",
"I18N",
"::",
"translate",
"(",
"'You can apply for an account using the link below.'",
")",
";",
"}",
"$",
"can_register",
"=",
"Site",
"::",
"getPreference",
"(",
"'USE_REGISTRATION_MODULE'",
")",
"===",
"'1'",
";",
"return",
"$",
"this",
"->",
"viewResponse",
"(",
"'login-page'",
",",
"[",
"'can_register'",
"=>",
"$",
"can_register",
",",
"'error'",
"=>",
"$",
"error",
",",
"'title'",
"=>",
"$",
"title",
",",
"'url'",
"=>",
"$",
"url",
",",
"'username'",
"=>",
"$",
"username",
",",
"'welcome'",
"=>",
"$",
"welcome",
",",
"]",
")",
";",
"}"
] | Show a login page.
@param ServerRequestInterface $request
@param Tree|null $tree
@return ResponseInterface | [
"Show",
"a",
"login",
"page",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Http/Controllers/Auth/LoginController.php#L64-L109 | train |
fisharebest/webtrees | app/Http/Controllers/Auth/LoginController.php | LoginController.loginAction | public function loginAction(ServerRequestInterface $request, UpgradeService $upgrade_service): ResponseInterface
{
$username = $request->get('username', '');
$password = $request->get('password', '');
$url = $request->get('url', '');
try {
$this->doLogin($username, $password);
if (Auth::isAdmin() && $upgrade_service->isUpgradeAvailable()) {
FlashMessages::addMessage(I18N::translate('A new version of webtrees is available.') . ' <a class="alert-link" href="' . e(route('upgrade')) . '">' . I18N::translate('Upgrade to webtrees %s.', '<span dir="ltr">' . $upgrade_service->latestVersion() . '</span>') . '</a>');
}
// If there was no referring page, redirect to "my page".
if ($url === '') {
// Switch to a tree where we have a genealogy record (or keep to the current/default).
$ged = (string) DB::table('gedcom')
->join('user_gedcom_setting', 'gedcom.gedcom_id', '=', 'user_gedcom_setting.gedcom_id')
->where('user_id', '=', Auth::id())
->value('gedcom_name');
$url = route('tree-page', ['ged' => $ged]);
}
// Redirect to the target URL
return redirect($url);
} catch (Exception $ex) {
// Failed to log in.
return redirect(route('login', [
'username' => $username,
'url' => $url,
'error' => $ex->getMessage(),
]));
}
} | php | public function loginAction(ServerRequestInterface $request, UpgradeService $upgrade_service): ResponseInterface
{
$username = $request->get('username', '');
$password = $request->get('password', '');
$url = $request->get('url', '');
try {
$this->doLogin($username, $password);
if (Auth::isAdmin() && $upgrade_service->isUpgradeAvailable()) {
FlashMessages::addMessage(I18N::translate('A new version of webtrees is available.') . ' <a class="alert-link" href="' . e(route('upgrade')) . '">' . I18N::translate('Upgrade to webtrees %s.', '<span dir="ltr">' . $upgrade_service->latestVersion() . '</span>') . '</a>');
}
// If there was no referring page, redirect to "my page".
if ($url === '') {
// Switch to a tree where we have a genealogy record (or keep to the current/default).
$ged = (string) DB::table('gedcom')
->join('user_gedcom_setting', 'gedcom.gedcom_id', '=', 'user_gedcom_setting.gedcom_id')
->where('user_id', '=', Auth::id())
->value('gedcom_name');
$url = route('tree-page', ['ged' => $ged]);
}
// Redirect to the target URL
return redirect($url);
} catch (Exception $ex) {
// Failed to log in.
return redirect(route('login', [
'username' => $username,
'url' => $url,
'error' => $ex->getMessage(),
]));
}
} | [
"public",
"function",
"loginAction",
"(",
"ServerRequestInterface",
"$",
"request",
",",
"UpgradeService",
"$",
"upgrade_service",
")",
":",
"ResponseInterface",
"{",
"$",
"username",
"=",
"$",
"request",
"->",
"get",
"(",
"'username'",
",",
"''",
")",
";",
"$",
"password",
"=",
"$",
"request",
"->",
"get",
"(",
"'password'",
",",
"''",
")",
";",
"$",
"url",
"=",
"$",
"request",
"->",
"get",
"(",
"'url'",
",",
"''",
")",
";",
"try",
"{",
"$",
"this",
"->",
"doLogin",
"(",
"$",
"username",
",",
"$",
"password",
")",
";",
"if",
"(",
"Auth",
"::",
"isAdmin",
"(",
")",
"&&",
"$",
"upgrade_service",
"->",
"isUpgradeAvailable",
"(",
")",
")",
"{",
"FlashMessages",
"::",
"addMessage",
"(",
"I18N",
"::",
"translate",
"(",
"'A new version of webtrees is available.'",
")",
".",
"' <a class=\"alert-link\" href=\"'",
".",
"e",
"(",
"route",
"(",
"'upgrade'",
")",
")",
".",
"'\">'",
".",
"I18N",
"::",
"translate",
"(",
"'Upgrade to webtrees %s.'",
",",
"'<span dir=\"ltr\">'",
".",
"$",
"upgrade_service",
"->",
"latestVersion",
"(",
")",
".",
"'</span>'",
")",
".",
"'</a>'",
")",
";",
"}",
"// If there was no referring page, redirect to \"my page\".",
"if",
"(",
"$",
"url",
"===",
"''",
")",
"{",
"// Switch to a tree where we have a genealogy record (or keep to the current/default).",
"$",
"ged",
"=",
"(",
"string",
")",
"DB",
"::",
"table",
"(",
"'gedcom'",
")",
"->",
"join",
"(",
"'user_gedcom_setting'",
",",
"'gedcom.gedcom_id'",
",",
"'='",
",",
"'user_gedcom_setting.gedcom_id'",
")",
"->",
"where",
"(",
"'user_id'",
",",
"'='",
",",
"Auth",
"::",
"id",
"(",
")",
")",
"->",
"value",
"(",
"'gedcom_name'",
")",
";",
"$",
"url",
"=",
"route",
"(",
"'tree-page'",
",",
"[",
"'ged'",
"=>",
"$",
"ged",
"]",
")",
";",
"}",
"// Redirect to the target URL",
"return",
"redirect",
"(",
"$",
"url",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"ex",
")",
"{",
"// Failed to log in.",
"return",
"redirect",
"(",
"route",
"(",
"'login'",
",",
"[",
"'username'",
"=>",
"$",
"username",
",",
"'url'",
"=>",
"$",
"url",
",",
"'error'",
"=>",
"$",
"ex",
"->",
"getMessage",
"(",
")",
",",
"]",
")",
")",
";",
"}",
"}"
] | Perform a login.
@param ServerRequestInterface $request
@param UpgradeService $upgrade_service
@return ResponseInterface | [
"Perform",
"a",
"login",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Http/Controllers/Auth/LoginController.php#L119-L153 | train |
fisharebest/webtrees | app/Http/Controllers/Auth/LoginController.php | LoginController.doLogin | private function doLogin(string $username, string $password): void
{
if (!$_COOKIE) {
Log::addAuthenticationLog('Login failed (no session cookies): ' . $username);
throw new Exception(I18N::translate('You cannot sign in because your browser does not accept cookies.'));
}
$user = $this->user_service->findByIdentifier($username);
if ($user === null) {
Log::addAuthenticationLog('Login failed (no such user/email): ' . $username);
throw new Exception(I18N::translate('The username or password is incorrect.'));
}
if (!$user->checkPassword($password)) {
Log::addAuthenticationLog('Login failed (incorrect password): ' . $username);
throw new Exception(I18N::translate('The username or password is incorrect.'));
}
if (!$user->getPreference('verified')) {
Log::addAuthenticationLog('Login failed (not verified by user): ' . $username);
throw new Exception(I18N::translate('This account has not been verified. Please check your email for a verification message.'));
}
if (!$user->getPreference('verified_by_admin')) {
Log::addAuthenticationLog('Login failed (not approved by admin): ' . $username);
throw new Exception(I18N::translate('This account has not been approved. Please wait for an administrator to approve it.'));
}
Auth::login($user);
Log::addAuthenticationLog('Login: ' . Auth::user()->userName() . '/' . Auth::user()->realName());
Auth::user()->setPreference('sessiontime', (string) Carbon::now()->unix());
Session::put('language', Auth::user()->getPreference('language'));
Session::put('theme', Auth::user()->getPreference('theme'));
I18N::init(Auth::user()->getPreference('language'));
} | php | private function doLogin(string $username, string $password): void
{
if (!$_COOKIE) {
Log::addAuthenticationLog('Login failed (no session cookies): ' . $username);
throw new Exception(I18N::translate('You cannot sign in because your browser does not accept cookies.'));
}
$user = $this->user_service->findByIdentifier($username);
if ($user === null) {
Log::addAuthenticationLog('Login failed (no such user/email): ' . $username);
throw new Exception(I18N::translate('The username or password is incorrect.'));
}
if (!$user->checkPassword($password)) {
Log::addAuthenticationLog('Login failed (incorrect password): ' . $username);
throw new Exception(I18N::translate('The username or password is incorrect.'));
}
if (!$user->getPreference('verified')) {
Log::addAuthenticationLog('Login failed (not verified by user): ' . $username);
throw new Exception(I18N::translate('This account has not been verified. Please check your email for a verification message.'));
}
if (!$user->getPreference('verified_by_admin')) {
Log::addAuthenticationLog('Login failed (not approved by admin): ' . $username);
throw new Exception(I18N::translate('This account has not been approved. Please wait for an administrator to approve it.'));
}
Auth::login($user);
Log::addAuthenticationLog('Login: ' . Auth::user()->userName() . '/' . Auth::user()->realName());
Auth::user()->setPreference('sessiontime', (string) Carbon::now()->unix());
Session::put('language', Auth::user()->getPreference('language'));
Session::put('theme', Auth::user()->getPreference('theme'));
I18N::init(Auth::user()->getPreference('language'));
} | [
"private",
"function",
"doLogin",
"(",
"string",
"$",
"username",
",",
"string",
"$",
"password",
")",
":",
"void",
"{",
"if",
"(",
"!",
"$",
"_COOKIE",
")",
"{",
"Log",
"::",
"addAuthenticationLog",
"(",
"'Login failed (no session cookies): '",
".",
"$",
"username",
")",
";",
"throw",
"new",
"Exception",
"(",
"I18N",
"::",
"translate",
"(",
"'You cannot sign in because your browser does not accept cookies.'",
")",
")",
";",
"}",
"$",
"user",
"=",
"$",
"this",
"->",
"user_service",
"->",
"findByIdentifier",
"(",
"$",
"username",
")",
";",
"if",
"(",
"$",
"user",
"===",
"null",
")",
"{",
"Log",
"::",
"addAuthenticationLog",
"(",
"'Login failed (no such user/email): '",
".",
"$",
"username",
")",
";",
"throw",
"new",
"Exception",
"(",
"I18N",
"::",
"translate",
"(",
"'The username or password is incorrect.'",
")",
")",
";",
"}",
"if",
"(",
"!",
"$",
"user",
"->",
"checkPassword",
"(",
"$",
"password",
")",
")",
"{",
"Log",
"::",
"addAuthenticationLog",
"(",
"'Login failed (incorrect password): '",
".",
"$",
"username",
")",
";",
"throw",
"new",
"Exception",
"(",
"I18N",
"::",
"translate",
"(",
"'The username or password is incorrect.'",
")",
")",
";",
"}",
"if",
"(",
"!",
"$",
"user",
"->",
"getPreference",
"(",
"'verified'",
")",
")",
"{",
"Log",
"::",
"addAuthenticationLog",
"(",
"'Login failed (not verified by user): '",
".",
"$",
"username",
")",
";",
"throw",
"new",
"Exception",
"(",
"I18N",
"::",
"translate",
"(",
"'This account has not been verified. Please check your email for a verification message.'",
")",
")",
";",
"}",
"if",
"(",
"!",
"$",
"user",
"->",
"getPreference",
"(",
"'verified_by_admin'",
")",
")",
"{",
"Log",
"::",
"addAuthenticationLog",
"(",
"'Login failed (not approved by admin): '",
".",
"$",
"username",
")",
";",
"throw",
"new",
"Exception",
"(",
"I18N",
"::",
"translate",
"(",
"'This account has not been approved. Please wait for an administrator to approve it.'",
")",
")",
";",
"}",
"Auth",
"::",
"login",
"(",
"$",
"user",
")",
";",
"Log",
"::",
"addAuthenticationLog",
"(",
"'Login: '",
".",
"Auth",
"::",
"user",
"(",
")",
"->",
"userName",
"(",
")",
".",
"'/'",
".",
"Auth",
"::",
"user",
"(",
")",
"->",
"realName",
"(",
")",
")",
";",
"Auth",
"::",
"user",
"(",
")",
"->",
"setPreference",
"(",
"'sessiontime'",
",",
"(",
"string",
")",
"Carbon",
"::",
"now",
"(",
")",
"->",
"unix",
"(",
")",
")",
";",
"Session",
"::",
"put",
"(",
"'language'",
",",
"Auth",
"::",
"user",
"(",
")",
"->",
"getPreference",
"(",
"'language'",
")",
")",
";",
"Session",
"::",
"put",
"(",
"'theme'",
",",
"Auth",
"::",
"user",
"(",
")",
"->",
"getPreference",
"(",
"'theme'",
")",
")",
";",
"I18N",
"::",
"init",
"(",
"Auth",
"::",
"user",
"(",
")",
"->",
"getPreference",
"(",
"'language'",
")",
")",
";",
"}"
] | Log in, if we can. Throw an exception, if we can't.
@param string $username
@param string $password
@return void
@throws Exception | [
"Log",
"in",
"if",
"we",
"can",
".",
"Throw",
"an",
"exception",
"if",
"we",
"can",
"t",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Http/Controllers/Auth/LoginController.php#L164-L200 | train |
fisharebest/webtrees | app/Http/Controllers/Auth/LoginController.php | LoginController.logoutAction | public function logoutAction(Tree $tree = null): ResponseInterface
{
if (Auth::check()) {
Log::addAuthenticationLog('Logout: ' . Auth::user()->userName() . '/' . Auth::user()->realName());
Auth::logout();
FlashMessages::addMessage(I18N::translate('You have signed out.'), 'info');
}
if ($tree === null) {
return redirect(route('tree-page'));
}
return redirect(route('tree-page', ['ged' => $tree->name()]));
} | php | public function logoutAction(Tree $tree = null): ResponseInterface
{
if (Auth::check()) {
Log::addAuthenticationLog('Logout: ' . Auth::user()->userName() . '/' . Auth::user()->realName());
Auth::logout();
FlashMessages::addMessage(I18N::translate('You have signed out.'), 'info');
}
if ($tree === null) {
return redirect(route('tree-page'));
}
return redirect(route('tree-page', ['ged' => $tree->name()]));
} | [
"public",
"function",
"logoutAction",
"(",
"Tree",
"$",
"tree",
"=",
"null",
")",
":",
"ResponseInterface",
"{",
"if",
"(",
"Auth",
"::",
"check",
"(",
")",
")",
"{",
"Log",
"::",
"addAuthenticationLog",
"(",
"'Logout: '",
".",
"Auth",
"::",
"user",
"(",
")",
"->",
"userName",
"(",
")",
".",
"'/'",
".",
"Auth",
"::",
"user",
"(",
")",
"->",
"realName",
"(",
")",
")",
";",
"Auth",
"::",
"logout",
"(",
")",
";",
"FlashMessages",
"::",
"addMessage",
"(",
"I18N",
"::",
"translate",
"(",
"'You have signed out.'",
")",
",",
"'info'",
")",
";",
"}",
"if",
"(",
"$",
"tree",
"===",
"null",
")",
"{",
"return",
"redirect",
"(",
"route",
"(",
"'tree-page'",
")",
")",
";",
"}",
"return",
"redirect",
"(",
"route",
"(",
"'tree-page'",
",",
"[",
"'ged'",
"=>",
"$",
"tree",
"->",
"name",
"(",
")",
"]",
")",
")",
";",
"}"
] | Perform a logout.
@param Tree|null $tree
@return ResponseInterface | [
"Perform",
"a",
"logout",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Http/Controllers/Auth/LoginController.php#L209-L222 | train |
fisharebest/webtrees | app/Services/ChartService.php | ChartService.sosaStradonitzAncestors | public function sosaStradonitzAncestors(Individual $individual, int $generations): Collection
{
$ancestors = [1 => $individual];
$queue = [1];
$max = 2 ** ($generations - 1);
while (!empty($queue)) {
$sosa_stradonitz_number = array_shift($queue);
if ($sosa_stradonitz_number >= $max) {
break;
}
$family = $ancestors[$sosa_stradonitz_number]->primaryChildFamily();
if ($family instanceof Family) {
if ($family->husband() instanceof Individual) {
$ancestors[$sosa_stradonitz_number * 2] = $family->husband();
$queue[] = $sosa_stradonitz_number * 2;
}
if ($family->wife() instanceof Individual) {
$ancestors[$sosa_stradonitz_number * 2 + 1] = $family->wife();
$queue[] = $sosa_stradonitz_number * 2 + 1;
}
}
}
return new Collection($ancestors);
} | php | public function sosaStradonitzAncestors(Individual $individual, int $generations): Collection
{
$ancestors = [1 => $individual];
$queue = [1];
$max = 2 ** ($generations - 1);
while (!empty($queue)) {
$sosa_stradonitz_number = array_shift($queue);
if ($sosa_stradonitz_number >= $max) {
break;
}
$family = $ancestors[$sosa_stradonitz_number]->primaryChildFamily();
if ($family instanceof Family) {
if ($family->husband() instanceof Individual) {
$ancestors[$sosa_stradonitz_number * 2] = $family->husband();
$queue[] = $sosa_stradonitz_number * 2;
}
if ($family->wife() instanceof Individual) {
$ancestors[$sosa_stradonitz_number * 2 + 1] = $family->wife();
$queue[] = $sosa_stradonitz_number * 2 + 1;
}
}
}
return new Collection($ancestors);
} | [
"public",
"function",
"sosaStradonitzAncestors",
"(",
"Individual",
"$",
"individual",
",",
"int",
"$",
"generations",
")",
":",
"Collection",
"{",
"$",
"ancestors",
"=",
"[",
"1",
"=>",
"$",
"individual",
"]",
";",
"$",
"queue",
"=",
"[",
"1",
"]",
";",
"$",
"max",
"=",
"2",
"**",
"(",
"$",
"generations",
"-",
"1",
")",
";",
"while",
"(",
"!",
"empty",
"(",
"$",
"queue",
")",
")",
"{",
"$",
"sosa_stradonitz_number",
"=",
"array_shift",
"(",
"$",
"queue",
")",
";",
"if",
"(",
"$",
"sosa_stradonitz_number",
">=",
"$",
"max",
")",
"{",
"break",
";",
"}",
"$",
"family",
"=",
"$",
"ancestors",
"[",
"$",
"sosa_stradonitz_number",
"]",
"->",
"primaryChildFamily",
"(",
")",
";",
"if",
"(",
"$",
"family",
"instanceof",
"Family",
")",
"{",
"if",
"(",
"$",
"family",
"->",
"husband",
"(",
")",
"instanceof",
"Individual",
")",
"{",
"$",
"ancestors",
"[",
"$",
"sosa_stradonitz_number",
"*",
"2",
"]",
"=",
"$",
"family",
"->",
"husband",
"(",
")",
";",
"$",
"queue",
"[",
"]",
"=",
"$",
"sosa_stradonitz_number",
"*",
"2",
";",
"}",
"if",
"(",
"$",
"family",
"->",
"wife",
"(",
")",
"instanceof",
"Individual",
")",
"{",
"$",
"ancestors",
"[",
"$",
"sosa_stradonitz_number",
"*",
"2",
"+",
"1",
"]",
"=",
"$",
"family",
"->",
"wife",
"(",
")",
";",
"$",
"queue",
"[",
"]",
"=",
"$",
"sosa_stradonitz_number",
"*",
"2",
"+",
"1",
";",
"}",
"}",
"}",
"return",
"new",
"Collection",
"(",
"$",
"ancestors",
")",
";",
"}"
] | Find the ancestors of an individual, indexed by their Sosa-Stradonitz number.
@param Individual $individual Start with this individual
@param int $generations Fetch this number of generations
@return Collection
@return Individual[] | [
"Find",
"the",
"ancestors",
"of",
"an",
"individual",
"indexed",
"by",
"their",
"Sosa",
"-",
"Stradonitz",
"number",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Services/ChartService.php#L38-L69 | train |
fisharebest/webtrees | app/Services/ChartService.php | ChartService.descendants | public function descendants(Individual $individual, int $generations): Collection
{
$descendants = new Collection([$individual]);
if ($generations > 0) {
foreach ($individual->spouseFamilies() as $family) {
foreach ($family->children() as $child) {
$descendants = $descendants->merge($this->descendants($child, $generations - 1));
}
}
}
return $descendants;
} | php | public function descendants(Individual $individual, int $generations): Collection
{
$descendants = new Collection([$individual]);
if ($generations > 0) {
foreach ($individual->spouseFamilies() as $family) {
foreach ($family->children() as $child) {
$descendants = $descendants->merge($this->descendants($child, $generations - 1));
}
}
}
return $descendants;
} | [
"public",
"function",
"descendants",
"(",
"Individual",
"$",
"individual",
",",
"int",
"$",
"generations",
")",
":",
"Collection",
"{",
"$",
"descendants",
"=",
"new",
"Collection",
"(",
"[",
"$",
"individual",
"]",
")",
";",
"if",
"(",
"$",
"generations",
">",
"0",
")",
"{",
"foreach",
"(",
"$",
"individual",
"->",
"spouseFamilies",
"(",
")",
"as",
"$",
"family",
")",
"{",
"foreach",
"(",
"$",
"family",
"->",
"children",
"(",
")",
"as",
"$",
"child",
")",
"{",
"$",
"descendants",
"=",
"$",
"descendants",
"->",
"merge",
"(",
"$",
"this",
"->",
"descendants",
"(",
"$",
"child",
",",
"$",
"generations",
"-",
"1",
")",
")",
";",
"}",
"}",
"}",
"return",
"$",
"descendants",
";",
"}"
] | Find the descendants of an individual.
@param Individual $individual Start with this individual
@param int $generations Fetch this number of generations
@return Collection
@return Individual[] | [
"Find",
"the",
"descendants",
"of",
"an",
"individual",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Services/ChartService.php#L80-L93 | train |
fisharebest/webtrees | app/Statistics/Service/CenturyService.php | CenturyService.centuryName | public function centuryName(int $century): string
{
if ($century < 0) {
return I18N::translate('%s BCE', $this->centuryName(-$century));
}
// The current chart engine (Google charts) can't handle <sup></sup> markup
switch ($century) {
case 21:
return strip_tags(I18N::translateContext('CENTURY', '21st'));
case 20:
return strip_tags(I18N::translateContext('CENTURY', '20th'));
case 19:
return strip_tags(I18N::translateContext('CENTURY', '19th'));
case 18:
return strip_tags(I18N::translateContext('CENTURY', '18th'));
case 17:
return strip_tags(I18N::translateContext('CENTURY', '17th'));
case 16:
return strip_tags(I18N::translateContext('CENTURY', '16th'));
case 15:
return strip_tags(I18N::translateContext('CENTURY', '15th'));
case 14:
return strip_tags(I18N::translateContext('CENTURY', '14th'));
case 13:
return strip_tags(I18N::translateContext('CENTURY', '13th'));
case 12:
return strip_tags(I18N::translateContext('CENTURY', '12th'));
case 11:
return strip_tags(I18N::translateContext('CENTURY', '11th'));
case 10:
return strip_tags(I18N::translateContext('CENTURY', '10th'));
case 9:
return strip_tags(I18N::translateContext('CENTURY', '9th'));
case 8:
return strip_tags(I18N::translateContext('CENTURY', '8th'));
case 7:
return strip_tags(I18N::translateContext('CENTURY', '7th'));
case 6:
return strip_tags(I18N::translateContext('CENTURY', '6th'));
case 5:
return strip_tags(I18N::translateContext('CENTURY', '5th'));
case 4:
return strip_tags(I18N::translateContext('CENTURY', '4th'));
case 3:
return strip_tags(I18N::translateContext('CENTURY', '3rd'));
case 2:
return strip_tags(I18N::translateContext('CENTURY', '2nd'));
case 1:
return strip_tags(I18N::translateContext('CENTURY', '1st'));
default:
return ($century - 1) . '01-' . $century . '00';
}
} | php | public function centuryName(int $century): string
{
if ($century < 0) {
return I18N::translate('%s BCE', $this->centuryName(-$century));
}
// The current chart engine (Google charts) can't handle <sup></sup> markup
switch ($century) {
case 21:
return strip_tags(I18N::translateContext('CENTURY', '21st'));
case 20:
return strip_tags(I18N::translateContext('CENTURY', '20th'));
case 19:
return strip_tags(I18N::translateContext('CENTURY', '19th'));
case 18:
return strip_tags(I18N::translateContext('CENTURY', '18th'));
case 17:
return strip_tags(I18N::translateContext('CENTURY', '17th'));
case 16:
return strip_tags(I18N::translateContext('CENTURY', '16th'));
case 15:
return strip_tags(I18N::translateContext('CENTURY', '15th'));
case 14:
return strip_tags(I18N::translateContext('CENTURY', '14th'));
case 13:
return strip_tags(I18N::translateContext('CENTURY', '13th'));
case 12:
return strip_tags(I18N::translateContext('CENTURY', '12th'));
case 11:
return strip_tags(I18N::translateContext('CENTURY', '11th'));
case 10:
return strip_tags(I18N::translateContext('CENTURY', '10th'));
case 9:
return strip_tags(I18N::translateContext('CENTURY', '9th'));
case 8:
return strip_tags(I18N::translateContext('CENTURY', '8th'));
case 7:
return strip_tags(I18N::translateContext('CENTURY', '7th'));
case 6:
return strip_tags(I18N::translateContext('CENTURY', '6th'));
case 5:
return strip_tags(I18N::translateContext('CENTURY', '5th'));
case 4:
return strip_tags(I18N::translateContext('CENTURY', '4th'));
case 3:
return strip_tags(I18N::translateContext('CENTURY', '3rd'));
case 2:
return strip_tags(I18N::translateContext('CENTURY', '2nd'));
case 1:
return strip_tags(I18N::translateContext('CENTURY', '1st'));
default:
return ($century - 1) . '01-' . $century . '00';
}
} | [
"public",
"function",
"centuryName",
"(",
"int",
"$",
"century",
")",
":",
"string",
"{",
"if",
"(",
"$",
"century",
"<",
"0",
")",
"{",
"return",
"I18N",
"::",
"translate",
"(",
"'%s BCE'",
",",
"$",
"this",
"->",
"centuryName",
"(",
"-",
"$",
"century",
")",
")",
";",
"}",
"// The current chart engine (Google charts) can't handle <sup></sup> markup",
"switch",
"(",
"$",
"century",
")",
"{",
"case",
"21",
":",
"return",
"strip_tags",
"(",
"I18N",
"::",
"translateContext",
"(",
"'CENTURY'",
",",
"'21st'",
")",
")",
";",
"case",
"20",
":",
"return",
"strip_tags",
"(",
"I18N",
"::",
"translateContext",
"(",
"'CENTURY'",
",",
"'20th'",
")",
")",
";",
"case",
"19",
":",
"return",
"strip_tags",
"(",
"I18N",
"::",
"translateContext",
"(",
"'CENTURY'",
",",
"'19th'",
")",
")",
";",
"case",
"18",
":",
"return",
"strip_tags",
"(",
"I18N",
"::",
"translateContext",
"(",
"'CENTURY'",
",",
"'18th'",
")",
")",
";",
"case",
"17",
":",
"return",
"strip_tags",
"(",
"I18N",
"::",
"translateContext",
"(",
"'CENTURY'",
",",
"'17th'",
")",
")",
";",
"case",
"16",
":",
"return",
"strip_tags",
"(",
"I18N",
"::",
"translateContext",
"(",
"'CENTURY'",
",",
"'16th'",
")",
")",
";",
"case",
"15",
":",
"return",
"strip_tags",
"(",
"I18N",
"::",
"translateContext",
"(",
"'CENTURY'",
",",
"'15th'",
")",
")",
";",
"case",
"14",
":",
"return",
"strip_tags",
"(",
"I18N",
"::",
"translateContext",
"(",
"'CENTURY'",
",",
"'14th'",
")",
")",
";",
"case",
"13",
":",
"return",
"strip_tags",
"(",
"I18N",
"::",
"translateContext",
"(",
"'CENTURY'",
",",
"'13th'",
")",
")",
";",
"case",
"12",
":",
"return",
"strip_tags",
"(",
"I18N",
"::",
"translateContext",
"(",
"'CENTURY'",
",",
"'12th'",
")",
")",
";",
"case",
"11",
":",
"return",
"strip_tags",
"(",
"I18N",
"::",
"translateContext",
"(",
"'CENTURY'",
",",
"'11th'",
")",
")",
";",
"case",
"10",
":",
"return",
"strip_tags",
"(",
"I18N",
"::",
"translateContext",
"(",
"'CENTURY'",
",",
"'10th'",
")",
")",
";",
"case",
"9",
":",
"return",
"strip_tags",
"(",
"I18N",
"::",
"translateContext",
"(",
"'CENTURY'",
",",
"'9th'",
")",
")",
";",
"case",
"8",
":",
"return",
"strip_tags",
"(",
"I18N",
"::",
"translateContext",
"(",
"'CENTURY'",
",",
"'8th'",
")",
")",
";",
"case",
"7",
":",
"return",
"strip_tags",
"(",
"I18N",
"::",
"translateContext",
"(",
"'CENTURY'",
",",
"'7th'",
")",
")",
";",
"case",
"6",
":",
"return",
"strip_tags",
"(",
"I18N",
"::",
"translateContext",
"(",
"'CENTURY'",
",",
"'6th'",
")",
")",
";",
"case",
"5",
":",
"return",
"strip_tags",
"(",
"I18N",
"::",
"translateContext",
"(",
"'CENTURY'",
",",
"'5th'",
")",
")",
";",
"case",
"4",
":",
"return",
"strip_tags",
"(",
"I18N",
"::",
"translateContext",
"(",
"'CENTURY'",
",",
"'4th'",
")",
")",
";",
"case",
"3",
":",
"return",
"strip_tags",
"(",
"I18N",
"::",
"translateContext",
"(",
"'CENTURY'",
",",
"'3rd'",
")",
")",
";",
"case",
"2",
":",
"return",
"strip_tags",
"(",
"I18N",
"::",
"translateContext",
"(",
"'CENTURY'",
",",
"'2nd'",
")",
")",
";",
"case",
"1",
":",
"return",
"strip_tags",
"(",
"I18N",
"::",
"translateContext",
"(",
"'CENTURY'",
",",
"'1st'",
")",
")",
";",
"default",
":",
"return",
"(",
"$",
"century",
"-",
"1",
")",
".",
"'01-'",
".",
"$",
"century",
".",
"'00'",
";",
"}",
"}"
] | Century name, English => 21st, Polish => XXI, etc.
@param int $century
@return string | [
"Century",
"name",
"English",
"=",
">",
"21st",
"Polish",
"=",
">",
"XXI",
"etc",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Statistics/Service/CenturyService.php#L34-L87 | train |
fisharebest/webtrees | app/DebugBar.php | DebugBar.enable | public static function enable(): void
{
self::$debugbar = new StandardDebugBar();
self::$debugbar->addCollector(new ViewCollector());
self::$renderer = self::$debugbar->getJavascriptRenderer('./vendor/maximebf/debugbar/src/DebugBar/Resources/');
} | php | public static function enable(): void
{
self::$debugbar = new StandardDebugBar();
self::$debugbar->addCollector(new ViewCollector());
self::$renderer = self::$debugbar->getJavascriptRenderer('./vendor/maximebf/debugbar/src/DebugBar/Resources/');
} | [
"public",
"static",
"function",
"enable",
"(",
")",
":",
"void",
"{",
"self",
"::",
"$",
"debugbar",
"=",
"new",
"StandardDebugBar",
"(",
")",
";",
"self",
"::",
"$",
"debugbar",
"->",
"addCollector",
"(",
"new",
"ViewCollector",
"(",
")",
")",
";",
"self",
"::",
"$",
"renderer",
"=",
"self",
"::",
"$",
"debugbar",
"->",
"getJavascriptRenderer",
"(",
"'./vendor/maximebf/debugbar/src/DebugBar/Resources/'",
")",
";",
"}"
] | Initialize the Debugbar.
@return void | [
"Initialize",
"the",
"Debugbar",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/DebugBar.php#L47-L53 | train |
fisharebest/webtrees | app/DebugBar.php | DebugBar.initPDO | public static function initPDO(PDO $pdo): PDO
{
if (self::$debugbar instanceof StandardDebugBar) {
$traceable_pdo = new TraceablePDO($pdo);
self::$debugbar->addCollector(new PDOCollector($traceable_pdo));
}
return $pdo;
} | php | public static function initPDO(PDO $pdo): PDO
{
if (self::$debugbar instanceof StandardDebugBar) {
$traceable_pdo = new TraceablePDO($pdo);
self::$debugbar->addCollector(new PDOCollector($traceable_pdo));
}
return $pdo;
} | [
"public",
"static",
"function",
"initPDO",
"(",
"PDO",
"$",
"pdo",
")",
":",
"PDO",
"{",
"if",
"(",
"self",
"::",
"$",
"debugbar",
"instanceof",
"StandardDebugBar",
")",
"{",
"$",
"traceable_pdo",
"=",
"new",
"TraceablePDO",
"(",
"$",
"pdo",
")",
";",
"self",
"::",
"$",
"debugbar",
"->",
"addCollector",
"(",
"new",
"PDOCollector",
"(",
"$",
"traceable_pdo",
")",
")",
";",
"}",
"return",
"$",
"pdo",
";",
"}"
] | Initialize the PDO collector.
@param PDO $pdo
@return PDO | [
"Initialize",
"the",
"PDO",
"collector",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/DebugBar.php#L62-L70 | train |
fisharebest/webtrees | app/DebugBar.php | DebugBar.stopMeasure | public static function stopMeasure($name): void
{
if (self::$debugbar instanceof StandardDebugBar) {
$collector = self::$debugbar->getCollector('time');
if ($collector instanceof TimeDataCollector) {
$collector->stopMeasure($name);
}
}
} | php | public static function stopMeasure($name): void
{
if (self::$debugbar instanceof StandardDebugBar) {
$collector = self::$debugbar->getCollector('time');
if ($collector instanceof TimeDataCollector) {
$collector->stopMeasure($name);
}
}
} | [
"public",
"static",
"function",
"stopMeasure",
"(",
"$",
"name",
")",
":",
"void",
"{",
"if",
"(",
"self",
"::",
"$",
"debugbar",
"instanceof",
"StandardDebugBar",
")",
"{",
"$",
"collector",
"=",
"self",
"::",
"$",
"debugbar",
"->",
"getCollector",
"(",
"'time'",
")",
";",
"if",
"(",
"$",
"collector",
"instanceof",
"TimeDataCollector",
")",
"{",
"$",
"collector",
"->",
"stopMeasure",
"(",
"$",
"name",
")",
";",
"}",
"}",
"}"
] | Stop a timer.
@param string $name
@return void | [
"Stop",
"a",
"timer",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/DebugBar.php#L169-L178 | train |
fisharebest/webtrees | app/DebugBar/ViewCollector.php | ViewCollector.addView | public function addView(string $view, array $data): void
{
$num = count($this->views) + 1;
$key = '#' . $num . ' ' . $view;
$this->views[$key] = $this->getDataFormatter()->formatVar($data);
} | php | public function addView(string $view, array $data): void
{
$num = count($this->views) + 1;
$key = '#' . $num . ' ' . $view;
$this->views[$key] = $this->getDataFormatter()->formatVar($data);
} | [
"public",
"function",
"addView",
"(",
"string",
"$",
"view",
",",
"array",
"$",
"data",
")",
":",
"void",
"{",
"$",
"num",
"=",
"count",
"(",
"$",
"this",
"->",
"views",
")",
"+",
"1",
";",
"$",
"key",
"=",
"'#'",
".",
"$",
"num",
".",
"' '",
".",
"$",
"view",
";",
"$",
"this",
"->",
"views",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"getDataFormatter",
"(",
")",
"->",
"formatVar",
"(",
"$",
"data",
")",
";",
"}"
] | Add details about a view
@param string $view
@param array $data
@return void | [
"Add",
"details",
"about",
"a",
"view"
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/DebugBar/ViewCollector.php#L40-L46 | train |
fisharebest/webtrees | app/Http/Controllers/EditMediaController.php | EditMediaController.editMediaFile | public function editMediaFile(ServerRequestInterface $request, Tree $tree): ResponseInterface
{
$xref = $request->get('xref', '');
$fact_id = $request->get('fact_id', '');
$media = Media::getInstance($xref, $tree);
try {
Auth::checkMediaAccess($media);
} catch (Exception $ex) {
return response(view('modals/error', [
'title' => I18N::translate('Edit a media file'),
'error' => $ex->getMessage(),
]), StatusCodeInterface::STATUS_FORBIDDEN);
}
foreach ($media->mediaFiles() as $media_file) {
if ($media_file->factId() === $fact_id) {
return response(view('modals/edit-media-file', [
'media_file' => $media_file,
'max_upload_size' => $this->maxUploadFilesize(),
'media' => $media,
'media_types' => $this->mediaTypes(),
'unused_files' => $this->unusedFiles($tree),
]));
}
}
return response('', StatusCodeInterface::STATUS_NOT_FOUND);
} | php | public function editMediaFile(ServerRequestInterface $request, Tree $tree): ResponseInterface
{
$xref = $request->get('xref', '');
$fact_id = $request->get('fact_id', '');
$media = Media::getInstance($xref, $tree);
try {
Auth::checkMediaAccess($media);
} catch (Exception $ex) {
return response(view('modals/error', [
'title' => I18N::translate('Edit a media file'),
'error' => $ex->getMessage(),
]), StatusCodeInterface::STATUS_FORBIDDEN);
}
foreach ($media->mediaFiles() as $media_file) {
if ($media_file->factId() === $fact_id) {
return response(view('modals/edit-media-file', [
'media_file' => $media_file,
'max_upload_size' => $this->maxUploadFilesize(),
'media' => $media,
'media_types' => $this->mediaTypes(),
'unused_files' => $this->unusedFiles($tree),
]));
}
}
return response('', StatusCodeInterface::STATUS_NOT_FOUND);
} | [
"public",
"function",
"editMediaFile",
"(",
"ServerRequestInterface",
"$",
"request",
",",
"Tree",
"$",
"tree",
")",
":",
"ResponseInterface",
"{",
"$",
"xref",
"=",
"$",
"request",
"->",
"get",
"(",
"'xref'",
",",
"''",
")",
";",
"$",
"fact_id",
"=",
"$",
"request",
"->",
"get",
"(",
"'fact_id'",
",",
"''",
")",
";",
"$",
"media",
"=",
"Media",
"::",
"getInstance",
"(",
"$",
"xref",
",",
"$",
"tree",
")",
";",
"try",
"{",
"Auth",
"::",
"checkMediaAccess",
"(",
"$",
"media",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"ex",
")",
"{",
"return",
"response",
"(",
"view",
"(",
"'modals/error'",
",",
"[",
"'title'",
"=>",
"I18N",
"::",
"translate",
"(",
"'Edit a media file'",
")",
",",
"'error'",
"=>",
"$",
"ex",
"->",
"getMessage",
"(",
")",
",",
"]",
")",
",",
"StatusCodeInterface",
"::",
"STATUS_FORBIDDEN",
")",
";",
"}",
"foreach",
"(",
"$",
"media",
"->",
"mediaFiles",
"(",
")",
"as",
"$",
"media_file",
")",
"{",
"if",
"(",
"$",
"media_file",
"->",
"factId",
"(",
")",
"===",
"$",
"fact_id",
")",
"{",
"return",
"response",
"(",
"view",
"(",
"'modals/edit-media-file'",
",",
"[",
"'media_file'",
"=>",
"$",
"media_file",
",",
"'max_upload_size'",
"=>",
"$",
"this",
"->",
"maxUploadFilesize",
"(",
")",
",",
"'media'",
"=>",
"$",
"media",
",",
"'media_types'",
"=>",
"$",
"this",
"->",
"mediaTypes",
"(",
")",
",",
"'unused_files'",
"=>",
"$",
"this",
"->",
"unusedFiles",
"(",
"$",
"tree",
")",
",",
"]",
")",
")",
";",
"}",
"}",
"return",
"response",
"(",
"''",
",",
"StatusCodeInterface",
"::",
"STATUS_NOT_FOUND",
")",
";",
"}"
] | Edit an existing media file.
@param ServerRequestInterface $request
@param Tree $tree
@return ResponseInterface | [
"Edit",
"an",
"existing",
"media",
"file",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Http/Controllers/EditMediaController.php#L147-L175 | train |
fisharebest/webtrees | app/Http/Controllers/EditMediaController.php | EditMediaController.createMediaObject | public function createMediaObject(Tree $tree): ResponseInterface
{
return response(view('modals/create-media-object', [
'max_upload_size' => $this->maxUploadFilesize(),
'media_types' => $this->mediaTypes(),
'unused_files' => $this->unusedFiles($tree),
]));
} | php | public function createMediaObject(Tree $tree): ResponseInterface
{
return response(view('modals/create-media-object', [
'max_upload_size' => $this->maxUploadFilesize(),
'media_types' => $this->mediaTypes(),
'unused_files' => $this->unusedFiles($tree),
]));
} | [
"public",
"function",
"createMediaObject",
"(",
"Tree",
"$",
"tree",
")",
":",
"ResponseInterface",
"{",
"return",
"response",
"(",
"view",
"(",
"'modals/create-media-object'",
",",
"[",
"'max_upload_size'",
"=>",
"$",
"this",
"->",
"maxUploadFilesize",
"(",
")",
",",
"'media_types'",
"=>",
"$",
"this",
"->",
"mediaTypes",
"(",
")",
",",
"'unused_files'",
"=>",
"$",
"this",
"->",
"unusedFiles",
"(",
"$",
"tree",
")",
",",
"]",
")",
")",
";",
"}"
] | Show a form to create a new media object.
@param Tree $tree
@return ResponseInterface | [
"Show",
"a",
"form",
"to",
"create",
"a",
"new",
"media",
"object",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Http/Controllers/EditMediaController.php#L287-L294 | train |
fisharebest/webtrees | app/Http/Controllers/EditMediaController.php | EditMediaController.createMediaObjectAction | public function createMediaObjectAction(ServerRequestInterface $request, Tree $tree): ResponseInterface
{
$note = $request->get('note');
$title = $request->get('title');
$type = $request->get('type');
$privacy_restriction = $request->get('privacy-restriction', '');
$edit_restriction = $request->get('edit-restriction', '');
// Tidy whitespace
$type = trim(preg_replace('/\s+/', ' ', $type));
$title = trim(preg_replace('/\s+/', ' ', $title));
// Convert line endings to GEDDCOM continuations
$note = str_replace([
"\r\n",
"\r",
"\n",
], "\n1 CONT ", $note);
$file = $this->uploadFile($request, $tree);
if ($file === '') {
return response(['error_message' => I18N::translate('There was an error uploading your file.')], 406);
}
$gedcom = "0 @@ OBJE\n" . $this->createMediaFileGedcom($file, $type, $title);
if ($note !== '') {
$gedcom .= "\n1 NOTE " . preg_replace('/\r?\n/', "\n2 CONT ", $note);
}
if (in_array($privacy_restriction, self::PRIVACY_RESTRICTIONS, true)) {
$gedcom .= "\n1 RESN " . $privacy_restriction;
}
if (in_array($edit_restriction, self::EDIT_RESTRICTIONS, true)) {
$gedcom .= "\n1 RESN " . $edit_restriction;
}
$record = $tree->createMediaObject($gedcom);
// Accept the new record to keep the filesystem synchronized with the genealogy.
FunctionsImport::acceptAllChanges($record->xref(), $record->tree());
return response([
'id' => $record->xref(),
'text' => view('selects/media', [
'media' => $record,
]),
'html' => view('modals/record-created', [
'title' => I18N::translate('The media object has been created'),
'name' => $record->fullName(),
'url' => $record->url(),
]),
]);
} | php | public function createMediaObjectAction(ServerRequestInterface $request, Tree $tree): ResponseInterface
{
$note = $request->get('note');
$title = $request->get('title');
$type = $request->get('type');
$privacy_restriction = $request->get('privacy-restriction', '');
$edit_restriction = $request->get('edit-restriction', '');
// Tidy whitespace
$type = trim(preg_replace('/\s+/', ' ', $type));
$title = trim(preg_replace('/\s+/', ' ', $title));
// Convert line endings to GEDDCOM continuations
$note = str_replace([
"\r\n",
"\r",
"\n",
], "\n1 CONT ", $note);
$file = $this->uploadFile($request, $tree);
if ($file === '') {
return response(['error_message' => I18N::translate('There was an error uploading your file.')], 406);
}
$gedcom = "0 @@ OBJE\n" . $this->createMediaFileGedcom($file, $type, $title);
if ($note !== '') {
$gedcom .= "\n1 NOTE " . preg_replace('/\r?\n/', "\n2 CONT ", $note);
}
if (in_array($privacy_restriction, self::PRIVACY_RESTRICTIONS, true)) {
$gedcom .= "\n1 RESN " . $privacy_restriction;
}
if (in_array($edit_restriction, self::EDIT_RESTRICTIONS, true)) {
$gedcom .= "\n1 RESN " . $edit_restriction;
}
$record = $tree->createMediaObject($gedcom);
// Accept the new record to keep the filesystem synchronized with the genealogy.
FunctionsImport::acceptAllChanges($record->xref(), $record->tree());
return response([
'id' => $record->xref(),
'text' => view('selects/media', [
'media' => $record,
]),
'html' => view('modals/record-created', [
'title' => I18N::translate('The media object has been created'),
'name' => $record->fullName(),
'url' => $record->url(),
]),
]);
} | [
"public",
"function",
"createMediaObjectAction",
"(",
"ServerRequestInterface",
"$",
"request",
",",
"Tree",
"$",
"tree",
")",
":",
"ResponseInterface",
"{",
"$",
"note",
"=",
"$",
"request",
"->",
"get",
"(",
"'note'",
")",
";",
"$",
"title",
"=",
"$",
"request",
"->",
"get",
"(",
"'title'",
")",
";",
"$",
"type",
"=",
"$",
"request",
"->",
"get",
"(",
"'type'",
")",
";",
"$",
"privacy_restriction",
"=",
"$",
"request",
"->",
"get",
"(",
"'privacy-restriction'",
",",
"''",
")",
";",
"$",
"edit_restriction",
"=",
"$",
"request",
"->",
"get",
"(",
"'edit-restriction'",
",",
"''",
")",
";",
"// Tidy whitespace",
"$",
"type",
"=",
"trim",
"(",
"preg_replace",
"(",
"'/\\s+/'",
",",
"' '",
",",
"$",
"type",
")",
")",
";",
"$",
"title",
"=",
"trim",
"(",
"preg_replace",
"(",
"'/\\s+/'",
",",
"' '",
",",
"$",
"title",
")",
")",
";",
"// Convert line endings to GEDDCOM continuations",
"$",
"note",
"=",
"str_replace",
"(",
"[",
"\"\\r\\n\"",
",",
"\"\\r\"",
",",
"\"\\n\"",
",",
"]",
",",
"\"\\n1 CONT \"",
",",
"$",
"note",
")",
";",
"$",
"file",
"=",
"$",
"this",
"->",
"uploadFile",
"(",
"$",
"request",
",",
"$",
"tree",
")",
";",
"if",
"(",
"$",
"file",
"===",
"''",
")",
"{",
"return",
"response",
"(",
"[",
"'error_message'",
"=>",
"I18N",
"::",
"translate",
"(",
"'There was an error uploading your file.'",
")",
"]",
",",
"406",
")",
";",
"}",
"$",
"gedcom",
"=",
"\"0 @@ OBJE\\n\"",
".",
"$",
"this",
"->",
"createMediaFileGedcom",
"(",
"$",
"file",
",",
"$",
"type",
",",
"$",
"title",
")",
";",
"if",
"(",
"$",
"note",
"!==",
"''",
")",
"{",
"$",
"gedcom",
".=",
"\"\\n1 NOTE \"",
".",
"preg_replace",
"(",
"'/\\r?\\n/'",
",",
"\"\\n2 CONT \"",
",",
"$",
"note",
")",
";",
"}",
"if",
"(",
"in_array",
"(",
"$",
"privacy_restriction",
",",
"self",
"::",
"PRIVACY_RESTRICTIONS",
",",
"true",
")",
")",
"{",
"$",
"gedcom",
".=",
"\"\\n1 RESN \"",
".",
"$",
"privacy_restriction",
";",
"}",
"if",
"(",
"in_array",
"(",
"$",
"edit_restriction",
",",
"self",
"::",
"EDIT_RESTRICTIONS",
",",
"true",
")",
")",
"{",
"$",
"gedcom",
".=",
"\"\\n1 RESN \"",
".",
"$",
"edit_restriction",
";",
"}",
"$",
"record",
"=",
"$",
"tree",
"->",
"createMediaObject",
"(",
"$",
"gedcom",
")",
";",
"// Accept the new record to keep the filesystem synchronized with the genealogy.",
"FunctionsImport",
"::",
"acceptAllChanges",
"(",
"$",
"record",
"->",
"xref",
"(",
")",
",",
"$",
"record",
"->",
"tree",
"(",
")",
")",
";",
"return",
"response",
"(",
"[",
"'id'",
"=>",
"$",
"record",
"->",
"xref",
"(",
")",
",",
"'text'",
"=>",
"view",
"(",
"'selects/media'",
",",
"[",
"'media'",
"=>",
"$",
"record",
",",
"]",
")",
",",
"'html'",
"=>",
"view",
"(",
"'modals/record-created'",
",",
"[",
"'title'",
"=>",
"I18N",
"::",
"translate",
"(",
"'The media object has been created'",
")",
",",
"'name'",
"=>",
"$",
"record",
"->",
"fullName",
"(",
")",
",",
"'url'",
"=>",
"$",
"record",
"->",
"url",
"(",
")",
",",
"]",
")",
",",
"]",
")",
";",
"}"
] | Process a form to create a new media object.
@param ServerRequestInterface $request
@param Tree $tree
@return ResponseInterface | [
"Process",
"a",
"form",
"to",
"create",
"a",
"new",
"media",
"object",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Http/Controllers/EditMediaController.php#L344-L399 | train |
fisharebest/webtrees | app/Http/Controllers/EditMediaController.php | EditMediaController.createMediaFileGedcom | private function createMediaFileGedcom(string $file, string $type, string $title): string
{
if (preg_match('/\.([a-z0-9]+)/i', $file, $match)) {
$extension = strtolower($match[1]);
$extension = str_replace('jpg', 'jpeg', $extension);
$extension = ' ' . $extension;
} else {
$extension = '';
}
$gedcom = '1 FILE ' . $file;
if ($type !== '') {
$gedcom .= "\n2 FORM" . $extension . "\n3 TYPE " . $type;
}
if ($title !== '') {
$gedcom .= "\n2 TITL " . $title;
}
return $gedcom;
} | php | private function createMediaFileGedcom(string $file, string $type, string $title): string
{
if (preg_match('/\.([a-z0-9]+)/i', $file, $match)) {
$extension = strtolower($match[1]);
$extension = str_replace('jpg', 'jpeg', $extension);
$extension = ' ' . $extension;
} else {
$extension = '';
}
$gedcom = '1 FILE ' . $file;
if ($type !== '') {
$gedcom .= "\n2 FORM" . $extension . "\n3 TYPE " . $type;
}
if ($title !== '') {
$gedcom .= "\n2 TITL " . $title;
}
return $gedcom;
} | [
"private",
"function",
"createMediaFileGedcom",
"(",
"string",
"$",
"file",
",",
"string",
"$",
"type",
",",
"string",
"$",
"title",
")",
":",
"string",
"{",
"if",
"(",
"preg_match",
"(",
"'/\\.([a-z0-9]+)/i'",
",",
"$",
"file",
",",
"$",
"match",
")",
")",
"{",
"$",
"extension",
"=",
"strtolower",
"(",
"$",
"match",
"[",
"1",
"]",
")",
";",
"$",
"extension",
"=",
"str_replace",
"(",
"'jpg'",
",",
"'jpeg'",
",",
"$",
"extension",
")",
";",
"$",
"extension",
"=",
"' '",
".",
"$",
"extension",
";",
"}",
"else",
"{",
"$",
"extension",
"=",
"''",
";",
"}",
"$",
"gedcom",
"=",
"'1 FILE '",
".",
"$",
"file",
";",
"if",
"(",
"$",
"type",
"!==",
"''",
")",
"{",
"$",
"gedcom",
".=",
"\"\\n2 FORM\"",
".",
"$",
"extension",
".",
"\"\\n3 TYPE \"",
".",
"$",
"type",
";",
"}",
"if",
"(",
"$",
"title",
"!==",
"''",
")",
"{",
"$",
"gedcom",
".=",
"\"\\n2 TITL \"",
".",
"$",
"title",
";",
"}",
"return",
"$",
"gedcom",
";",
"}"
] | Convert the media file attributes into GEDCOM format.
@param string $file
@param string $type
@param string $title
@return string | [
"Convert",
"the",
"media",
"file",
"attributes",
"into",
"GEDCOM",
"format",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Http/Controllers/EditMediaController.php#L483-L502 | train |
fisharebest/webtrees | app/Http/Controllers/EditMediaController.php | EditMediaController.maxUploadFilesize | private function maxUploadFilesize(): string
{
$bytes = UploadedFile::getMaxFilesize();
$kb = intdiv($bytes + 1023, 1024);
return I18N::translate('%s KB', I18N::number($kb));
} | php | private function maxUploadFilesize(): string
{
$bytes = UploadedFile::getMaxFilesize();
$kb = intdiv($bytes + 1023, 1024);
return I18N::translate('%s KB', I18N::number($kb));
} | [
"private",
"function",
"maxUploadFilesize",
"(",
")",
":",
"string",
"{",
"$",
"bytes",
"=",
"UploadedFile",
"::",
"getMaxFilesize",
"(",
")",
";",
"$",
"kb",
"=",
"intdiv",
"(",
"$",
"bytes",
"+",
"1023",
",",
"1024",
")",
";",
"return",
"I18N",
"::",
"translate",
"(",
"'%s KB'",
",",
"I18N",
"::",
"number",
"(",
"$",
"kb",
")",
")",
";",
"}"
] | What is the largest file a user may upload? | [
"What",
"is",
"the",
"largest",
"file",
"a",
"user",
"may",
"upload?"
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Http/Controllers/EditMediaController.php#L507-L513 | train |
fisharebest/webtrees | app/Http/Controllers/EditMediaController.php | EditMediaController.unusedFiles | private function unusedFiles(Tree $tree): array
{
$used_files = DB::table('media_file')
->where('m_file', '=', $tree->id())
->where('multimedia_file_refn', 'NOT LIKE', 'http://%')
->where('multimedia_file_refn', 'NOT LIKE', 'https://%')
->pluck('multimedia_file_refn')
->all();
$disk_files = [];
$media_dir = WT_DATA_DIR . $tree->getPreference('MEDIA_DIRECTORY', 'media/');
$iter = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($media_dir, FilesystemIterator::FOLLOW_SYMLINKS));
foreach ($iter as $file) {
if ($file->isFile()) {
$filename = substr($file->getPathname(), strlen($media_dir));
// Older versions of webtrees used a couple of special folders.
if (strpos($filename, 'thumbs/') !== 0 && strpos($filename, 'watermarks/') !== 0) {
$disk_files[] = $filename;
}
}
}
$unused_files = array_diff($disk_files, $used_files);
sort($unused_files);
return array_combine($unused_files, $unused_files);
} | php | private function unusedFiles(Tree $tree): array
{
$used_files = DB::table('media_file')
->where('m_file', '=', $tree->id())
->where('multimedia_file_refn', 'NOT LIKE', 'http://%')
->where('multimedia_file_refn', 'NOT LIKE', 'https://%')
->pluck('multimedia_file_refn')
->all();
$disk_files = [];
$media_dir = WT_DATA_DIR . $tree->getPreference('MEDIA_DIRECTORY', 'media/');
$iter = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($media_dir, FilesystemIterator::FOLLOW_SYMLINKS));
foreach ($iter as $file) {
if ($file->isFile()) {
$filename = substr($file->getPathname(), strlen($media_dir));
// Older versions of webtrees used a couple of special folders.
if (strpos($filename, 'thumbs/') !== 0 && strpos($filename, 'watermarks/') !== 0) {
$disk_files[] = $filename;
}
}
}
$unused_files = array_diff($disk_files, $used_files);
sort($unused_files);
return array_combine($unused_files, $unused_files);
} | [
"private",
"function",
"unusedFiles",
"(",
"Tree",
"$",
"tree",
")",
":",
"array",
"{",
"$",
"used_files",
"=",
"DB",
"::",
"table",
"(",
"'media_file'",
")",
"->",
"where",
"(",
"'m_file'",
",",
"'='",
",",
"$",
"tree",
"->",
"id",
"(",
")",
")",
"->",
"where",
"(",
"'multimedia_file_refn'",
",",
"'NOT LIKE'",
",",
"'http://%'",
")",
"->",
"where",
"(",
"'multimedia_file_refn'",
",",
"'NOT LIKE'",
",",
"'https://%'",
")",
"->",
"pluck",
"(",
"'multimedia_file_refn'",
")",
"->",
"all",
"(",
")",
";",
"$",
"disk_files",
"=",
"[",
"]",
";",
"$",
"media_dir",
"=",
"WT_DATA_DIR",
".",
"$",
"tree",
"->",
"getPreference",
"(",
"'MEDIA_DIRECTORY'",
",",
"'media/'",
")",
";",
"$",
"iter",
"=",
"new",
"RecursiveIteratorIterator",
"(",
"new",
"RecursiveDirectoryIterator",
"(",
"$",
"media_dir",
",",
"FilesystemIterator",
"::",
"FOLLOW_SYMLINKS",
")",
")",
";",
"foreach",
"(",
"$",
"iter",
"as",
"$",
"file",
")",
"{",
"if",
"(",
"$",
"file",
"->",
"isFile",
"(",
")",
")",
"{",
"$",
"filename",
"=",
"substr",
"(",
"$",
"file",
"->",
"getPathname",
"(",
")",
",",
"strlen",
"(",
"$",
"media_dir",
")",
")",
";",
"// Older versions of webtrees used a couple of special folders.",
"if",
"(",
"strpos",
"(",
"$",
"filename",
",",
"'thumbs/'",
")",
"!==",
"0",
"&&",
"strpos",
"(",
"$",
"filename",
",",
"'watermarks/'",
")",
"!==",
"0",
")",
"{",
"$",
"disk_files",
"[",
"]",
"=",
"$",
"filename",
";",
"}",
"}",
"}",
"$",
"unused_files",
"=",
"array_diff",
"(",
"$",
"disk_files",
",",
"$",
"used_files",
")",
";",
"sort",
"(",
"$",
"unused_files",
")",
";",
"return",
"array_combine",
"(",
"$",
"unused_files",
",",
"$",
"unused_files",
")",
";",
"}"
] | A list of media files not already linked to a media object.
@param Tree $tree
@return array | [
"A",
"list",
"of",
"media",
"files",
"not",
"already",
"linked",
"to",
"a",
"media",
"object",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Http/Controllers/EditMediaController.php#L623-L651 | train |
fisharebest/webtrees | app/Report/ReportPdf.php | ReportPdf.setup | public function setup(): void
{
parent::setup();
// Setup the PDF class with custom size pages because WT supports more page sizes. If WT sends an unknown size name then the default would be A4
$this->pdf = new ReportTcpdf($this->orientation, parent::UNITS, [
$this->page_width,
$this->page_height,
], self::UNICODE, 'UTF-8', self::DISK_CACHE);
// Setup the PDF margins
$this->pdf->SetMargins($this->left_margin, $this->top_margin, $this->right_margin);
$this->pdf->setHeaderMargin($this->header_margin);
$this->pdf->setFooterMargin($this->footer_margin);
//Set auto page breaks
$this->pdf->SetAutoPageBreak(true, $this->bottom_margin);
// Set font subsetting
$this->pdf->setFontSubsetting(self::SUBSETTING);
// Setup PDF compression
$this->pdf->SetCompression(self::COMPRESSION);
// Setup RTL support
$this->pdf->setRTL($this->rtl);
// Set the document information
$this->pdf->SetCreator(Webtrees::NAME . ' ' . Webtrees::VERSION);
$this->pdf->SetAuthor($this->rauthor);
$this->pdf->SetTitle($this->title);
$this->pdf->SetSubject($this->rsubject);
$this->pdf->SetKeywords($this->rkeywords);
$this->pdf->setReport($this);
if ($this->show_generated_by) {
// The default style name for Generated by.... is 'genby'
$element = new ReportPdfCell(0, 10, 0, 'C', '', 'genby', 1, ReportBaseElement::CURRENT_POSITION, ReportBaseElement::CURRENT_POSITION, 0, 0, '', '', true);
$element->addText($this->generated_by);
$element->setUrl(Webtrees::NAME . ' ' . Webtrees::VERSION);
$this->pdf->addFooter($element);
}
} | php | public function setup(): void
{
parent::setup();
// Setup the PDF class with custom size pages because WT supports more page sizes. If WT sends an unknown size name then the default would be A4
$this->pdf = new ReportTcpdf($this->orientation, parent::UNITS, [
$this->page_width,
$this->page_height,
], self::UNICODE, 'UTF-8', self::DISK_CACHE);
// Setup the PDF margins
$this->pdf->SetMargins($this->left_margin, $this->top_margin, $this->right_margin);
$this->pdf->setHeaderMargin($this->header_margin);
$this->pdf->setFooterMargin($this->footer_margin);
//Set auto page breaks
$this->pdf->SetAutoPageBreak(true, $this->bottom_margin);
// Set font subsetting
$this->pdf->setFontSubsetting(self::SUBSETTING);
// Setup PDF compression
$this->pdf->SetCompression(self::COMPRESSION);
// Setup RTL support
$this->pdf->setRTL($this->rtl);
// Set the document information
$this->pdf->SetCreator(Webtrees::NAME . ' ' . Webtrees::VERSION);
$this->pdf->SetAuthor($this->rauthor);
$this->pdf->SetTitle($this->title);
$this->pdf->SetSubject($this->rsubject);
$this->pdf->SetKeywords($this->rkeywords);
$this->pdf->setReport($this);
if ($this->show_generated_by) {
// The default style name for Generated by.... is 'genby'
$element = new ReportPdfCell(0, 10, 0, 'C', '', 'genby', 1, ReportBaseElement::CURRENT_POSITION, ReportBaseElement::CURRENT_POSITION, 0, 0, '', '', true);
$element->addText($this->generated_by);
$element->setUrl(Webtrees::NAME . ' ' . Webtrees::VERSION);
$this->pdf->addFooter($element);
}
} | [
"public",
"function",
"setup",
"(",
")",
":",
"void",
"{",
"parent",
"::",
"setup",
"(",
")",
";",
"// Setup the PDF class with custom size pages because WT supports more page sizes. If WT sends an unknown size name then the default would be A4",
"$",
"this",
"->",
"pdf",
"=",
"new",
"ReportTcpdf",
"(",
"$",
"this",
"->",
"orientation",
",",
"parent",
"::",
"UNITS",
",",
"[",
"$",
"this",
"->",
"page_width",
",",
"$",
"this",
"->",
"page_height",
",",
"]",
",",
"self",
"::",
"UNICODE",
",",
"'UTF-8'",
",",
"self",
"::",
"DISK_CACHE",
")",
";",
"// Setup the PDF margins",
"$",
"this",
"->",
"pdf",
"->",
"SetMargins",
"(",
"$",
"this",
"->",
"left_margin",
",",
"$",
"this",
"->",
"top_margin",
",",
"$",
"this",
"->",
"right_margin",
")",
";",
"$",
"this",
"->",
"pdf",
"->",
"setHeaderMargin",
"(",
"$",
"this",
"->",
"header_margin",
")",
";",
"$",
"this",
"->",
"pdf",
"->",
"setFooterMargin",
"(",
"$",
"this",
"->",
"footer_margin",
")",
";",
"//Set auto page breaks",
"$",
"this",
"->",
"pdf",
"->",
"SetAutoPageBreak",
"(",
"true",
",",
"$",
"this",
"->",
"bottom_margin",
")",
";",
"// Set font subsetting",
"$",
"this",
"->",
"pdf",
"->",
"setFontSubsetting",
"(",
"self",
"::",
"SUBSETTING",
")",
";",
"// Setup PDF compression",
"$",
"this",
"->",
"pdf",
"->",
"SetCompression",
"(",
"self",
"::",
"COMPRESSION",
")",
";",
"// Setup RTL support",
"$",
"this",
"->",
"pdf",
"->",
"setRTL",
"(",
"$",
"this",
"->",
"rtl",
")",
";",
"// Set the document information",
"$",
"this",
"->",
"pdf",
"->",
"SetCreator",
"(",
"Webtrees",
"::",
"NAME",
".",
"' '",
".",
"Webtrees",
"::",
"VERSION",
")",
";",
"$",
"this",
"->",
"pdf",
"->",
"SetAuthor",
"(",
"$",
"this",
"->",
"rauthor",
")",
";",
"$",
"this",
"->",
"pdf",
"->",
"SetTitle",
"(",
"$",
"this",
"->",
"title",
")",
";",
"$",
"this",
"->",
"pdf",
"->",
"SetSubject",
"(",
"$",
"this",
"->",
"rsubject",
")",
";",
"$",
"this",
"->",
"pdf",
"->",
"SetKeywords",
"(",
"$",
"this",
"->",
"rkeywords",
")",
";",
"$",
"this",
"->",
"pdf",
"->",
"setReport",
"(",
"$",
"this",
")",
";",
"if",
"(",
"$",
"this",
"->",
"show_generated_by",
")",
"{",
"// The default style name for Generated by.... is 'genby'",
"$",
"element",
"=",
"new",
"ReportPdfCell",
"(",
"0",
",",
"10",
",",
"0",
",",
"'C'",
",",
"''",
",",
"'genby'",
",",
"1",
",",
"ReportBaseElement",
"::",
"CURRENT_POSITION",
",",
"ReportBaseElement",
"::",
"CURRENT_POSITION",
",",
"0",
",",
"0",
",",
"''",
",",
"''",
",",
"true",
")",
";",
"$",
"element",
"->",
"addText",
"(",
"$",
"this",
"->",
"generated_by",
")",
";",
"$",
"element",
"->",
"setUrl",
"(",
"Webtrees",
"::",
"NAME",
".",
"' '",
".",
"Webtrees",
"::",
"VERSION",
")",
";",
"$",
"this",
"->",
"pdf",
"->",
"addFooter",
"(",
"$",
"element",
")",
";",
"}",
"}"
] | PDF Setup - ReportPdf
@return void | [
"PDF",
"Setup",
"-",
"ReportPdf"
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Report/ReportPdf.php#L69-L107 | train |
fisharebest/webtrees | app/Report/ReportPdf.php | ReportPdf.createImage | public function createImage(string $file, float $x, float $y, float $w, float $h, string $align, string $ln): ReportBaseImage
{
return new ReportPdfImage($file, $x, $y, $w, $h, $align, $ln);
} | php | public function createImage(string $file, float $x, float $y, float $w, float $h, string $align, string $ln): ReportBaseImage
{
return new ReportPdfImage($file, $x, $y, $w, $h, $align, $ln);
} | [
"public",
"function",
"createImage",
"(",
"string",
"$",
"file",
",",
"float",
"$",
"x",
",",
"float",
"$",
"y",
",",
"float",
"$",
"w",
",",
"float",
"$",
"h",
",",
"string",
"$",
"align",
",",
"string",
"$",
"ln",
")",
":",
"ReportBaseImage",
"{",
"return",
"new",
"ReportPdfImage",
"(",
"$",
"file",
",",
"$",
"x",
",",
"$",
"y",
",",
"$",
"w",
",",
"$",
"h",
",",
"$",
"align",
",",
"$",
"ln",
")",
";",
"}"
] | Create a new image object.
@param string $file Filename
@param float $x
@param float $y
@param float $w Image width
@param float $h Image height
@param string $align L:left, C:center, R:right or empty to use x/y
@param string $ln T:same line, N:next line
@return ReportBaseImage | [
"Create",
"a",
"new",
"image",
"object",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Report/ReportPdf.php#L276-L279 | train |
fisharebest/webtrees | app/Html.php | Html.url | public static function url($path, array $data): string
{
$path = str_replace(' ', '%20', $path);
return $path . '?' . http_build_query($data, '', '&', PHP_QUERY_RFC3986);
} | php | public static function url($path, array $data): string
{
$path = str_replace(' ', '%20', $path);
return $path . '?' . http_build_query($data, '', '&', PHP_QUERY_RFC3986);
} | [
"public",
"static",
"function",
"url",
"(",
"$",
"path",
",",
"array",
"$",
"data",
")",
":",
"string",
"{",
"$",
"path",
"=",
"str_replace",
"(",
"' '",
",",
"'%20'",
",",
"$",
"path",
")",
";",
"return",
"$",
"path",
".",
"'?'",
".",
"http_build_query",
"(",
"$",
"data",
",",
"''",
",",
"'&'",
",",
"PHP_QUERY_RFC3986",
")",
";",
"}"
] | Encode a URL.
@param string $path
@param array $data
@return string | [
"Encode",
"a",
"URL",
"."
] | 840bd0d721dc479520ec24a065996bc6becb8348 | https://github.com/fisharebest/webtrees/blob/840bd0d721dc479520ec24a065996bc6becb8348/app/Html.php#L56-L61 | train |
leafo/scssphp | src/Compiler.php | Compiler.findScopeSelectors | protected function findScopeSelectors($scope, $depth)
{
if ($scope->depth === $depth && $scope->selectors) {
return $scope->selectors;
}
if ($scope->children) {
foreach (array_reverse($scope->children) as $c) {
if ($s = $this->findScopeSelectors($c, $depth)) {
return $s;
}
}
}
return [];
} | php | protected function findScopeSelectors($scope, $depth)
{
if ($scope->depth === $depth && $scope->selectors) {
return $scope->selectors;
}
if ($scope->children) {
foreach (array_reverse($scope->children) as $c) {
if ($s = $this->findScopeSelectors($c, $depth)) {
return $s;
}
}
}
return [];
} | [
"protected",
"function",
"findScopeSelectors",
"(",
"$",
"scope",
",",
"$",
"depth",
")",
"{",
"if",
"(",
"$",
"scope",
"->",
"depth",
"===",
"$",
"depth",
"&&",
"$",
"scope",
"->",
"selectors",
")",
"{",
"return",
"$",
"scope",
"->",
"selectors",
";",
"}",
"if",
"(",
"$",
"scope",
"->",
"children",
")",
"{",
"foreach",
"(",
"array_reverse",
"(",
"$",
"scope",
"->",
"children",
")",
"as",
"$",
"c",
")",
"{",
"if",
"(",
"$",
"s",
"=",
"$",
"this",
"->",
"findScopeSelectors",
"(",
"$",
"c",
",",
"$",
"depth",
")",
")",
"{",
"return",
"$",
"s",
";",
"}",
"}",
"}",
"return",
"[",
"]",
";",
"}"
] | Find a selector by the depth node in the scope
@param \Leafo\ScssPhp\Formatter\OutputBlock $scope
@param integer $depth
@return array | [
"Find",
"a",
"selector",
"by",
"the",
"depth",
"node",
"in",
"the",
"scope"
] | 71720fac3374e61cdf3cf4acc724ec2a47031aff | https://github.com/leafo/scssphp/blob/71720fac3374e61cdf3cf4acc724ec2a47031aff/src/Compiler.php#L927-L942 | train |
leafo/scssphp | src/Compiler.php | Compiler.compileChildren | protected function compileChildren($stms, OutputBlock $out)
{
foreach ($stms as $stm) {
$ret = $this->compileChild($stm, $out);
if (isset($ret)) {
return $ret;
}
}
return null;
} | php | protected function compileChildren($stms, OutputBlock $out)
{
foreach ($stms as $stm) {
$ret = $this->compileChild($stm, $out);
if (isset($ret)) {
return $ret;
}
}
return null;
} | [
"protected",
"function",
"compileChildren",
"(",
"$",
"stms",
",",
"OutputBlock",
"$",
"out",
")",
"{",
"foreach",
"(",
"$",
"stms",
"as",
"$",
"stm",
")",
"{",
"$",
"ret",
"=",
"$",
"this",
"->",
"compileChild",
"(",
"$",
"stm",
",",
"$",
"out",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"ret",
")",
")",
"{",
"return",
"$",
"ret",
";",
"}",
"}",
"return",
"null",
";",
"}"
] | Compile children and return result
@param array $stms
@param \Leafo\ScssPhp\Formatter\OutputBlock $out
@return array|null | [
"Compile",
"children",
"and",
"return",
"result"
] | 71720fac3374e61cdf3cf4acc724ec2a47031aff | https://github.com/leafo/scssphp/blob/71720fac3374e61cdf3cf4acc724ec2a47031aff/src/Compiler.php#L1424-L1435 | train |
leafo/scssphp | src/Compiler.php | Compiler.joinSelectors | protected function joinSelectors($parent, $child, $selfParentSelectors = null)
{
$setSelf = false;
$out = [];
foreach ($child as $part) {
$newPart = [];
foreach ($part as $p) {
if ($p === static::$selfSelector) {
$setSelf = true;
if (is_null($selfParentSelectors)) {
$selfParentSelectors = $parent;
}
foreach ($selfParentSelectors as $i => $parentPart) {
if ($i > 0) {
$out[] = $newPart;
$newPart = [];
}
foreach ($parentPart as $pp) {
if (is_array($pp)) {
$flatten = [];
array_walk_recursive($pp, function ($a) use (&$flatten) {
$flatten[] = $a;
});
$pp = implode($flatten);
}
$newPart[] = $pp;
}
}
} else {
$newPart[] = $p;
}
}
$out[] = $newPart;
}
return $setSelf ? $out : array_merge($parent, $child);
} | php | protected function joinSelectors($parent, $child, $selfParentSelectors = null)
{
$setSelf = false;
$out = [];
foreach ($child as $part) {
$newPart = [];
foreach ($part as $p) {
if ($p === static::$selfSelector) {
$setSelf = true;
if (is_null($selfParentSelectors)) {
$selfParentSelectors = $parent;
}
foreach ($selfParentSelectors as $i => $parentPart) {
if ($i > 0) {
$out[] = $newPart;
$newPart = [];
}
foreach ($parentPart as $pp) {
if (is_array($pp)) {
$flatten = [];
array_walk_recursive($pp, function ($a) use (&$flatten) {
$flatten[] = $a;
});
$pp = implode($flatten);
}
$newPart[] = $pp;
}
}
} else {
$newPart[] = $p;
}
}
$out[] = $newPart;
}
return $setSelf ? $out : array_merge($parent, $child);
} | [
"protected",
"function",
"joinSelectors",
"(",
"$",
"parent",
",",
"$",
"child",
",",
"$",
"selfParentSelectors",
"=",
"null",
")",
"{",
"$",
"setSelf",
"=",
"false",
";",
"$",
"out",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"child",
"as",
"$",
"part",
")",
"{",
"$",
"newPart",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"part",
"as",
"$",
"p",
")",
"{",
"if",
"(",
"$",
"p",
"===",
"static",
"::",
"$",
"selfSelector",
")",
"{",
"$",
"setSelf",
"=",
"true",
";",
"if",
"(",
"is_null",
"(",
"$",
"selfParentSelectors",
")",
")",
"{",
"$",
"selfParentSelectors",
"=",
"$",
"parent",
";",
"}",
"foreach",
"(",
"$",
"selfParentSelectors",
"as",
"$",
"i",
"=>",
"$",
"parentPart",
")",
"{",
"if",
"(",
"$",
"i",
">",
"0",
")",
"{",
"$",
"out",
"[",
"]",
"=",
"$",
"newPart",
";",
"$",
"newPart",
"=",
"[",
"]",
";",
"}",
"foreach",
"(",
"$",
"parentPart",
"as",
"$",
"pp",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"pp",
")",
")",
"{",
"$",
"flatten",
"=",
"[",
"]",
";",
"array_walk_recursive",
"(",
"$",
"pp",
",",
"function",
"(",
"$",
"a",
")",
"use",
"(",
"&",
"$",
"flatten",
")",
"{",
"$",
"flatten",
"[",
"]",
"=",
"$",
"a",
";",
"}",
")",
";",
"$",
"pp",
"=",
"implode",
"(",
"$",
"flatten",
")",
";",
"}",
"$",
"newPart",
"[",
"]",
"=",
"$",
"pp",
";",
"}",
"}",
"}",
"else",
"{",
"$",
"newPart",
"[",
"]",
"=",
"$",
"p",
";",
"}",
"}",
"$",
"out",
"[",
"]",
"=",
"$",
"newPart",
";",
"}",
"return",
"$",
"setSelf",
"?",
"$",
"out",
":",
"array_merge",
"(",
"$",
"parent",
",",
"$",
"child",
")",
";",
"}"
] | Join selectors; looks for & to replace, or append parent before child
@param array $parent
@param array $child
@param array $selfParentSelectors
@return array | [
"Join",
"selectors",
";",
"looks",
"for",
"&",
"to",
"replace",
"or",
"append",
"parent",
"before",
"child"
] | 71720fac3374e61cdf3cf4acc724ec2a47031aff | https://github.com/leafo/scssphp/blob/71720fac3374e61cdf3cf4acc724ec2a47031aff/src/Compiler.php#L3132-L3174 | train |
leafo/scssphp | src/Compiler.php | Compiler.extractEnv | protected function extractEnv($envs)
{
for ($env = null; $e = array_pop($envs);) {
$e->parent = $env;
$env = $e;
}
return $env;
} | php | protected function extractEnv($envs)
{
for ($env = null; $e = array_pop($envs);) {
$e->parent = $env;
$env = $e;
}
return $env;
} | [
"protected",
"function",
"extractEnv",
"(",
"$",
"envs",
")",
"{",
"for",
"(",
"$",
"env",
"=",
"null",
";",
"$",
"e",
"=",
"array_pop",
"(",
"$",
"envs",
")",
";",
")",
"{",
"$",
"e",
"->",
"parent",
"=",
"$",
"env",
";",
"$",
"env",
"=",
"$",
"e",
";",
"}",
"return",
"$",
"env",
";",
"}"
] | Convert env stack to singly linked list
@param array $envs
@return \Leafo\ScssPhp\Compiler\Environment | [
"Convert",
"env",
"stack",
"to",
"singly",
"linked",
"list"
] | 71720fac3374e61cdf3cf4acc724ec2a47031aff | https://github.com/leafo/scssphp/blob/71720fac3374e61cdf3cf4acc724ec2a47031aff/src/Compiler.php#L3240-L3248 | train |
leafo/scssphp | src/Compiler.php | Compiler.setExisting | protected function setExisting($name, $value, Environment $env, $valueUnreduced = null)
{
$storeEnv = $env;
$hasNamespace = $name[0] === '^' || $name[0] === '@' || $name[0] === '%';
for (;;) {
if (array_key_exists($name, $env->store)) {
break;
}
if (! $hasNamespace && isset($env->marker)) {
$env = $storeEnv;
break;
}
if (! isset($env->parent)) {
$env = $storeEnv;
break;
}
$env = $env->parent;
}
$env->store[$name] = $value;
if ($valueUnreduced) {
$env->storeUnreduced[$name] = $valueUnreduced;
}
} | php | protected function setExisting($name, $value, Environment $env, $valueUnreduced = null)
{
$storeEnv = $env;
$hasNamespace = $name[0] === '^' || $name[0] === '@' || $name[0] === '%';
for (;;) {
if (array_key_exists($name, $env->store)) {
break;
}
if (! $hasNamespace && isset($env->marker)) {
$env = $storeEnv;
break;
}
if (! isset($env->parent)) {
$env = $storeEnv;
break;
}
$env = $env->parent;
}
$env->store[$name] = $value;
if ($valueUnreduced) {
$env->storeUnreduced[$name] = $valueUnreduced;
}
} | [
"protected",
"function",
"setExisting",
"(",
"$",
"name",
",",
"$",
"value",
",",
"Environment",
"$",
"env",
",",
"$",
"valueUnreduced",
"=",
"null",
")",
"{",
"$",
"storeEnv",
"=",
"$",
"env",
";",
"$",
"hasNamespace",
"=",
"$",
"name",
"[",
"0",
"]",
"===",
"'^'",
"||",
"$",
"name",
"[",
"0",
"]",
"===",
"'@'",
"||",
"$",
"name",
"[",
"0",
"]",
"===",
"'%'",
";",
"for",
"(",
";",
";",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"name",
",",
"$",
"env",
"->",
"store",
")",
")",
"{",
"break",
";",
"}",
"if",
"(",
"!",
"$",
"hasNamespace",
"&&",
"isset",
"(",
"$",
"env",
"->",
"marker",
")",
")",
"{",
"$",
"env",
"=",
"$",
"storeEnv",
";",
"break",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"env",
"->",
"parent",
")",
")",
"{",
"$",
"env",
"=",
"$",
"storeEnv",
";",
"break",
";",
"}",
"$",
"env",
"=",
"$",
"env",
"->",
"parent",
";",
"}",
"$",
"env",
"->",
"store",
"[",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"if",
"(",
"$",
"valueUnreduced",
")",
"{",
"$",
"env",
"->",
"storeUnreduced",
"[",
"$",
"name",
"]",
"=",
"$",
"valueUnreduced",
";",
"}",
"}"
] | Set existing variable
@param string $name
@param mixed $value
@param \Leafo\ScssPhp\Compiler\Environment $env
@param mixed $valueUnreduced | [
"Set",
"existing",
"variable"
] | 71720fac3374e61cdf3cf4acc724ec2a47031aff | https://github.com/leafo/scssphp/blob/71720fac3374e61cdf3cf4acc724ec2a47031aff/src/Compiler.php#L3320-L3349 | train |
leafo/scssphp | src/Compiler.php | Compiler.setRaw | protected function setRaw($name, $value, Environment $env, $valueUnreduced = null)
{
$env->store[$name] = $value;
if ($valueUnreduced) {
$env->storeUnreduced[$name] = $valueUnreduced;
}
} | php | protected function setRaw($name, $value, Environment $env, $valueUnreduced = null)
{
$env->store[$name] = $value;
if ($valueUnreduced) {
$env->storeUnreduced[$name] = $valueUnreduced;
}
} | [
"protected",
"function",
"setRaw",
"(",
"$",
"name",
",",
"$",
"value",
",",
"Environment",
"$",
"env",
",",
"$",
"valueUnreduced",
"=",
"null",
")",
"{",
"$",
"env",
"->",
"store",
"[",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"if",
"(",
"$",
"valueUnreduced",
")",
"{",
"$",
"env",
"->",
"storeUnreduced",
"[",
"$",
"name",
"]",
"=",
"$",
"valueUnreduced",
";",
"}",
"}"
] | Set raw variable
@param string $name
@param mixed $value
@param \Leafo\ScssPhp\Compiler\Environment $env
@param mixed $valueUnreduced | [
"Set",
"raw",
"variable"
] | 71720fac3374e61cdf3cf4acc724ec2a47031aff | https://github.com/leafo/scssphp/blob/71720fac3374e61cdf3cf4acc724ec2a47031aff/src/Compiler.php#L3359-L3366 | train |
leafo/scssphp | src/Compiler.php | Compiler.sortArgs | protected function sortArgs($prototype, $args)
{
$keyArgs = [];
$posArgs = [];
// separate positional and keyword arguments
foreach ($args as $arg) {
list($key, $value) = $arg;
$key = $key[1];
if (empty($key)) {
$posArgs[] = empty($arg[2]) ? $value : $arg;
} else {
$keyArgs[$key] = $value;
}
}
if (! isset($prototype)) {
return [$posArgs, $keyArgs];
}
// copy positional args
$finalArgs = array_pad($posArgs, count($prototype), null);
// overwrite positional args with keyword args
foreach ($prototype as $i => $names) {
foreach ((array) $names as $name) {
if (isset($keyArgs[$name])) {
$finalArgs[$i] = $keyArgs[$name];
}
}
}
return [$finalArgs, $keyArgs];
} | php | protected function sortArgs($prototype, $args)
{
$keyArgs = [];
$posArgs = [];
// separate positional and keyword arguments
foreach ($args as $arg) {
list($key, $value) = $arg;
$key = $key[1];
if (empty($key)) {
$posArgs[] = empty($arg[2]) ? $value : $arg;
} else {
$keyArgs[$key] = $value;
}
}
if (! isset($prototype)) {
return [$posArgs, $keyArgs];
}
// copy positional args
$finalArgs = array_pad($posArgs, count($prototype), null);
// overwrite positional args with keyword args
foreach ($prototype as $i => $names) {
foreach ((array) $names as $name) {
if (isset($keyArgs[$name])) {
$finalArgs[$i] = $keyArgs[$name];
}
}
}
return [$finalArgs, $keyArgs];
} | [
"protected",
"function",
"sortArgs",
"(",
"$",
"prototype",
",",
"$",
"args",
")",
"{",
"$",
"keyArgs",
"=",
"[",
"]",
";",
"$",
"posArgs",
"=",
"[",
"]",
";",
"// separate positional and keyword arguments",
"foreach",
"(",
"$",
"args",
"as",
"$",
"arg",
")",
"{",
"list",
"(",
"$",
"key",
",",
"$",
"value",
")",
"=",
"$",
"arg",
";",
"$",
"key",
"=",
"$",
"key",
"[",
"1",
"]",
";",
"if",
"(",
"empty",
"(",
"$",
"key",
")",
")",
"{",
"$",
"posArgs",
"[",
"]",
"=",
"empty",
"(",
"$",
"arg",
"[",
"2",
"]",
")",
"?",
"$",
"value",
":",
"$",
"arg",
";",
"}",
"else",
"{",
"$",
"keyArgs",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"prototype",
")",
")",
"{",
"return",
"[",
"$",
"posArgs",
",",
"$",
"keyArgs",
"]",
";",
"}",
"// copy positional args",
"$",
"finalArgs",
"=",
"array_pad",
"(",
"$",
"posArgs",
",",
"count",
"(",
"$",
"prototype",
")",
",",
"null",
")",
";",
"// overwrite positional args with keyword args",
"foreach",
"(",
"$",
"prototype",
"as",
"$",
"i",
"=>",
"$",
"names",
")",
"{",
"foreach",
"(",
"(",
"array",
")",
"$",
"names",
"as",
"$",
"name",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"keyArgs",
"[",
"$",
"name",
"]",
")",
")",
"{",
"$",
"finalArgs",
"[",
"$",
"i",
"]",
"=",
"$",
"keyArgs",
"[",
"$",
"name",
"]",
";",
"}",
"}",
"}",
"return",
"[",
"$",
"finalArgs",
",",
"$",
"keyArgs",
"]",
";",
"}"
] | Sorts keyword arguments
@param array $prototype
@param array $args
@return array | [
"Sorts",
"keyword",
"arguments"
] | 71720fac3374e61cdf3cf4acc724ec2a47031aff | https://github.com/leafo/scssphp/blob/71720fac3374e61cdf3cf4acc724ec2a47031aff/src/Compiler.php#L3946-L3981 | train |
leafo/scssphp | src/Compiler.php | Compiler.coerceValue | protected function coerceValue($value)
{
if (is_array($value) || $value instanceof \ArrayAccess) {
return $value;
}
if (is_bool($value)) {
return $this->toBool($value);
}
if ($value === null) {
return static::$null;
}
if (is_numeric($value)) {
return new Node\Number($value, '');
}
if ($value === '') {
return static::$emptyString;
}
if (preg_match('/^(#([0-9a-f]{6})|#([0-9a-f]{3}))$/i', $value, $m)) {
$color = [Type::T_COLOR];
if (isset($m[3])) {
$num = hexdec($m[3]);
foreach ([3, 2, 1] as $i) {
$t = $num & 0xf;
$color[$i] = $t << 4 | $t;
$num >>= 4;
}
} else {
$num = hexdec($m[2]);
foreach ([3, 2, 1] as $i) {
$color[$i] = $num & 0xff;
$num >>= 8;
}
}
return $color;
}
return [Type::T_KEYWORD, $value];
} | php | protected function coerceValue($value)
{
if (is_array($value) || $value instanceof \ArrayAccess) {
return $value;
}
if (is_bool($value)) {
return $this->toBool($value);
}
if ($value === null) {
return static::$null;
}
if (is_numeric($value)) {
return new Node\Number($value, '');
}
if ($value === '') {
return static::$emptyString;
}
if (preg_match('/^(#([0-9a-f]{6})|#([0-9a-f]{3}))$/i', $value, $m)) {
$color = [Type::T_COLOR];
if (isset($m[3])) {
$num = hexdec($m[3]);
foreach ([3, 2, 1] as $i) {
$t = $num & 0xf;
$color[$i] = $t << 4 | $t;
$num >>= 4;
}
} else {
$num = hexdec($m[2]);
foreach ([3, 2, 1] as $i) {
$color[$i] = $num & 0xff;
$num >>= 8;
}
}
return $color;
}
return [Type::T_KEYWORD, $value];
} | [
"protected",
"function",
"coerceValue",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
"||",
"$",
"value",
"instanceof",
"\\",
"ArrayAccess",
")",
"{",
"return",
"$",
"value",
";",
"}",
"if",
"(",
"is_bool",
"(",
"$",
"value",
")",
")",
"{",
"return",
"$",
"this",
"->",
"toBool",
"(",
"$",
"value",
")",
";",
"}",
"if",
"(",
"$",
"value",
"===",
"null",
")",
"{",
"return",
"static",
"::",
"$",
"null",
";",
"}",
"if",
"(",
"is_numeric",
"(",
"$",
"value",
")",
")",
"{",
"return",
"new",
"Node",
"\\",
"Number",
"(",
"$",
"value",
",",
"''",
")",
";",
"}",
"if",
"(",
"$",
"value",
"===",
"''",
")",
"{",
"return",
"static",
"::",
"$",
"emptyString",
";",
"}",
"if",
"(",
"preg_match",
"(",
"'/^(#([0-9a-f]{6})|#([0-9a-f]{3}))$/i'",
",",
"$",
"value",
",",
"$",
"m",
")",
")",
"{",
"$",
"color",
"=",
"[",
"Type",
"::",
"T_COLOR",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"m",
"[",
"3",
"]",
")",
")",
"{",
"$",
"num",
"=",
"hexdec",
"(",
"$",
"m",
"[",
"3",
"]",
")",
";",
"foreach",
"(",
"[",
"3",
",",
"2",
",",
"1",
"]",
"as",
"$",
"i",
")",
"{",
"$",
"t",
"=",
"$",
"num",
"&",
"0xf",
";",
"$",
"color",
"[",
"$",
"i",
"]",
"=",
"$",
"t",
"<<",
"4",
"|",
"$",
"t",
";",
"$",
"num",
">>=",
"4",
";",
"}",
"}",
"else",
"{",
"$",
"num",
"=",
"hexdec",
"(",
"$",
"m",
"[",
"2",
"]",
")",
";",
"foreach",
"(",
"[",
"3",
",",
"2",
",",
"1",
"]",
"as",
"$",
"i",
")",
"{",
"$",
"color",
"[",
"$",
"i",
"]",
"=",
"$",
"num",
"&",
"0xff",
";",
"$",
"num",
">>=",
"8",
";",
"}",
"}",
"return",
"$",
"color",
";",
"}",
"return",
"[",
"Type",
"::",
"T_KEYWORD",
",",
"$",
"value",
"]",
";",
"}"
] | Coerce a php value into a scss one
@param mixed $value
@return array|\Leafo\ScssPhp\Node\Number | [
"Coerce",
"a",
"php",
"value",
"into",
"a",
"scss",
"one"
] | 71720fac3374e61cdf3cf4acc724ec2a47031aff | https://github.com/leafo/scssphp/blob/71720fac3374e61cdf3cf4acc724ec2a47031aff/src/Compiler.php#L4108-L4154 | train |
leafo/scssphp | src/Compiler.php | Compiler.assertMap | public function assertMap($value)
{
$value = $this->coerceMap($value);
if ($value[0] !== Type::T_MAP) {
$this->throwError('expecting map, %s received', $value[0]);
}
return $value;
} | php | public function assertMap($value)
{
$value = $this->coerceMap($value);
if ($value[0] !== Type::T_MAP) {
$this->throwError('expecting map, %s received', $value[0]);
}
return $value;
} | [
"public",
"function",
"assertMap",
"(",
"$",
"value",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"coerceMap",
"(",
"$",
"value",
")",
";",
"if",
"(",
"$",
"value",
"[",
"0",
"]",
"!==",
"Type",
"::",
"T_MAP",
")",
"{",
"$",
"this",
"->",
"throwError",
"(",
"'expecting map, %s received'",
",",
"$",
"value",
"[",
"0",
"]",
")",
";",
"}",
"return",
"$",
"value",
";",
"}"
] | Assert value is a map
@api
@param array $value
@return array
@throws \Exception | [
"Assert",
"value",
"is",
"a",
"map"
] | 71720fac3374e61cdf3cf4acc724ec2a47031aff | https://github.com/leafo/scssphp/blob/71720fac3374e61cdf3cf4acc724ec2a47031aff/src/Compiler.php#L4305-L4314 | train |
leafo/scssphp | src/Compiler.php | Compiler.assertColor | public function assertColor($value)
{
if ($color = $this->coerceColor($value)) {
return $color;
}
$this->throwError('expecting color, %s received', $value[0]);
} | php | public function assertColor($value)
{
if ($color = $this->coerceColor($value)) {
return $color;
}
$this->throwError('expecting color, %s received', $value[0]);
} | [
"public",
"function",
"assertColor",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"color",
"=",
"$",
"this",
"->",
"coerceColor",
"(",
"$",
"value",
")",
")",
"{",
"return",
"$",
"color",
";",
"}",
"$",
"this",
"->",
"throwError",
"(",
"'expecting color, %s received'",
",",
"$",
"value",
"[",
"0",
"]",
")",
";",
"}"
] | Assert value is a color
@api
@param array $value
@return array
@throws \Exception | [
"Assert",
"value",
"is",
"a",
"color"
] | 71720fac3374e61cdf3cf4acc724ec2a47031aff | https://github.com/leafo/scssphp/blob/71720fac3374e61cdf3cf4acc724ec2a47031aff/src/Compiler.php#L4347-L4354 | train |
leafo/scssphp | src/Compiler.php | Compiler.hueToRGB | protected function hueToRGB($m1, $m2, $h)
{
if ($h < 0) {
$h += 1;
} elseif ($h > 1) {
$h -= 1;
}
if ($h * 6 < 1) {
return $m1 + ($m2 - $m1) * $h * 6;
}
if ($h * 2 < 1) {
return $m2;
}
if ($h * 3 < 2) {
return $m1 + ($m2 - $m1) * (2/3 - $h) * 6;
}
return $m1;
} | php | protected function hueToRGB($m1, $m2, $h)
{
if ($h < 0) {
$h += 1;
} elseif ($h > 1) {
$h -= 1;
}
if ($h * 6 < 1) {
return $m1 + ($m2 - $m1) * $h * 6;
}
if ($h * 2 < 1) {
return $m2;
}
if ($h * 3 < 2) {
return $m1 + ($m2 - $m1) * (2/3 - $h) * 6;
}
return $m1;
} | [
"protected",
"function",
"hueToRGB",
"(",
"$",
"m1",
",",
"$",
"m2",
",",
"$",
"h",
")",
"{",
"if",
"(",
"$",
"h",
"<",
"0",
")",
"{",
"$",
"h",
"+=",
"1",
";",
"}",
"elseif",
"(",
"$",
"h",
">",
"1",
")",
"{",
"$",
"h",
"-=",
"1",
";",
"}",
"if",
"(",
"$",
"h",
"*",
"6",
"<",
"1",
")",
"{",
"return",
"$",
"m1",
"+",
"(",
"$",
"m2",
"-",
"$",
"m1",
")",
"*",
"$",
"h",
"*",
"6",
";",
"}",
"if",
"(",
"$",
"h",
"*",
"2",
"<",
"1",
")",
"{",
"return",
"$",
"m2",
";",
"}",
"if",
"(",
"$",
"h",
"*",
"3",
"<",
"2",
")",
"{",
"return",
"$",
"m1",
"+",
"(",
"$",
"m2",
"-",
"$",
"m1",
")",
"*",
"(",
"2",
"/",
"3",
"-",
"$",
"h",
")",
"*",
"6",
";",
"}",
"return",
"$",
"m1",
";",
"}"
] | Hue to RGB helper
@param float $m1
@param float $m2
@param float $h
@return float | [
"Hue",
"to",
"RGB",
"helper"
] | 71720fac3374e61cdf3cf4acc724ec2a47031aff | https://github.com/leafo/scssphp/blob/71720fac3374e61cdf3cf4acc724ec2a47031aff/src/Compiler.php#L4447-L4468 | train |
leafo/scssphp | example/Server.php | Server.inputName | protected function inputName()
{
switch (true) {
case isset($_GET['p']):
return $_GET['p'];
case isset($_SERVER['PATH_INFO']):
return $_SERVER['PATH_INFO'];
case isset($_SERVER['DOCUMENT_URI']):
return substr($_SERVER['DOCUMENT_URI'], strlen($_SERVER['SCRIPT_NAME']));
}
} | php | protected function inputName()
{
switch (true) {
case isset($_GET['p']):
return $_GET['p'];
case isset($_SERVER['PATH_INFO']):
return $_SERVER['PATH_INFO'];
case isset($_SERVER['DOCUMENT_URI']):
return substr($_SERVER['DOCUMENT_URI'], strlen($_SERVER['SCRIPT_NAME']));
}
} | [
"protected",
"function",
"inputName",
"(",
")",
"{",
"switch",
"(",
"true",
")",
"{",
"case",
"isset",
"(",
"$",
"_GET",
"[",
"'p'",
"]",
")",
":",
"return",
"$",
"_GET",
"[",
"'p'",
"]",
";",
"case",
"isset",
"(",
"$",
"_SERVER",
"[",
"'PATH_INFO'",
"]",
")",
":",
"return",
"$",
"_SERVER",
"[",
"'PATH_INFO'",
"]",
";",
"case",
"isset",
"(",
"$",
"_SERVER",
"[",
"'DOCUMENT_URI'",
"]",
")",
":",
"return",
"substr",
"(",
"$",
"_SERVER",
"[",
"'DOCUMENT_URI'",
"]",
",",
"strlen",
"(",
"$",
"_SERVER",
"[",
"'SCRIPT_NAME'",
"]",
")",
")",
";",
"}",
"}"
] | Get name of requested .scss file
@return string|null | [
"Get",
"name",
"of",
"requested",
".",
"scss",
"file"
] | 71720fac3374e61cdf3cf4acc724ec2a47031aff | https://github.com/leafo/scssphp/blob/71720fac3374e61cdf3cf4acc724ec2a47031aff/example/Server.php#L63-L73 | train |
leafo/scssphp | example/Server.php | Server.findInput | protected function findInput()
{
if (($input = $this->inputName())
&& strpos($input, '..') === false
&& substr($input, -5) === '.scss'
) {
$name = $this->join($this->dir, $input);
if (is_file($name) && is_readable($name)) {
return $name;
}
}
return false;
} | php | protected function findInput()
{
if (($input = $this->inputName())
&& strpos($input, '..') === false
&& substr($input, -5) === '.scss'
) {
$name = $this->join($this->dir, $input);
if (is_file($name) && is_readable($name)) {
return $name;
}
}
return false;
} | [
"protected",
"function",
"findInput",
"(",
")",
"{",
"if",
"(",
"(",
"$",
"input",
"=",
"$",
"this",
"->",
"inputName",
"(",
")",
")",
"&&",
"strpos",
"(",
"$",
"input",
",",
"'..'",
")",
"===",
"false",
"&&",
"substr",
"(",
"$",
"input",
",",
"-",
"5",
")",
"===",
"'.scss'",
")",
"{",
"$",
"name",
"=",
"$",
"this",
"->",
"join",
"(",
"$",
"this",
"->",
"dir",
",",
"$",
"input",
")",
";",
"if",
"(",
"is_file",
"(",
"$",
"name",
")",
"&&",
"is_readable",
"(",
"$",
"name",
")",
")",
"{",
"return",
"$",
"name",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Get path to requested .scss file
@return string | [
"Get",
"path",
"to",
"requested",
".",
"scss",
"file"
] | 71720fac3374e61cdf3cf4acc724ec2a47031aff | https://github.com/leafo/scssphp/blob/71720fac3374e61cdf3cf4acc724ec2a47031aff/example/Server.php#L80-L94 | train |
leafo/scssphp | example/Server.php | Server.getIfModifiedSinceHeader | protected function getIfModifiedSinceHeader()
{
$modifiedSince = null;
if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
$modifiedSince = $_SERVER['HTTP_IF_MODIFIED_SINCE'];
if (false !== ($semicolonPos = strpos($modifiedSince, ';'))) {
$modifiedSince = substr($modifiedSince, 0, $semicolonPos);
}
}
return $modifiedSince;
} | php | protected function getIfModifiedSinceHeader()
{
$modifiedSince = null;
if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
$modifiedSince = $_SERVER['HTTP_IF_MODIFIED_SINCE'];
if (false !== ($semicolonPos = strpos($modifiedSince, ';'))) {
$modifiedSince = substr($modifiedSince, 0, $semicolonPos);
}
}
return $modifiedSince;
} | [
"protected",
"function",
"getIfModifiedSinceHeader",
"(",
")",
"{",
"$",
"modifiedSince",
"=",
"null",
";",
"if",
"(",
"isset",
"(",
"$",
"_SERVER",
"[",
"'HTTP_IF_MODIFIED_SINCE'",
"]",
")",
")",
"{",
"$",
"modifiedSince",
"=",
"$",
"_SERVER",
"[",
"'HTTP_IF_MODIFIED_SINCE'",
"]",
";",
"if",
"(",
"false",
"!==",
"(",
"$",
"semicolonPos",
"=",
"strpos",
"(",
"$",
"modifiedSince",
",",
"';'",
")",
")",
")",
"{",
"$",
"modifiedSince",
"=",
"substr",
"(",
"$",
"modifiedSince",
",",
"0",
",",
"$",
"semicolonPos",
")",
";",
"}",
"}",
"return",
"$",
"modifiedSince",
";",
"}"
] | Get If-Modified-Since header from client request
@return string|null | [
"Get",
"If",
"-",
"Modified",
"-",
"Since",
"header",
"from",
"client",
"request"
] | 71720fac3374e61cdf3cf4acc724ec2a47031aff | https://github.com/leafo/scssphp/blob/71720fac3374e61cdf3cf4acc724ec2a47031aff/example/Server.php#L164-L177 | train |
leafo/scssphp | example/Server.php | Server.checkedCompile | public function checkedCompile($in, $out)
{
if (! is_file($out) || filemtime($in) > filemtime($out)) {
$this->compileFile($in, $out);
return true;
}
return false;
} | php | public function checkedCompile($in, $out)
{
if (! is_file($out) || filemtime($in) > filemtime($out)) {
$this->compileFile($in, $out);
return true;
}
return false;
} | [
"public",
"function",
"checkedCompile",
"(",
"$",
"in",
",",
"$",
"out",
")",
"{",
"if",
"(",
"!",
"is_file",
"(",
"$",
"out",
")",
"||",
"filemtime",
"(",
"$",
"in",
")",
">",
"filemtime",
"(",
"$",
"out",
")",
")",
"{",
"$",
"this",
"->",
"compileFile",
"(",
"$",
"in",
",",
"$",
"out",
")",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Check if file need compiling
@param string $in Input file (.scss)
@param string $out Output file (.css)
@return bool | [
"Check",
"if",
"file",
"need",
"compiling"
] | 71720fac3374e61cdf3cf4acc724ec2a47031aff | https://github.com/leafo/scssphp/blob/71720fac3374e61cdf3cf4acc724ec2a47031aff/example/Server.php#L302-L311 | train |
leafo/scssphp | example/Server.php | Server.cachedCompile | public function cachedCompile($in, $force = false)
{
// assume no root
$root = null;
if (is_string($in)) {
$root = $in;
} elseif (is_array($in) and isset($in['root'])) {
if ($force or ! isset($in['files'])) {
// If we are forcing a recompile or if for some reason the
// structure does not contain any file information we should
// specify the root to trigger a rebuild.
$root = $in['root'];
} elseif (isset($in['files']) and is_array($in['files'])) {
foreach ($in['files'] as $fname => $ftime) {
if (! file_exists($fname) or filemtime($fname) > $ftime) {
// One of the files we knew about previously has changed
// so we should look at our incoming root again.
$root = $in['root'];
break;
}
}
}
} else {
// TODO: Throw an exception? We got neither a string nor something
// that looks like a compatible lessphp cache structure.
return null;
}
if ($root !== null) {
// If we have a root value which means we should rebuild.
$out = [];
$out['root'] = $root;
$out['compiled'] = $this->compileFile($root);
$out['files'] = $this->scss->getParsedFiles();
$out['updated'] = time();
return $out;
} else {
// No changes, pass back the structure
// we were given initially.
return $in;
}
} | php | public function cachedCompile($in, $force = false)
{
// assume no root
$root = null;
if (is_string($in)) {
$root = $in;
} elseif (is_array($in) and isset($in['root'])) {
if ($force or ! isset($in['files'])) {
// If we are forcing a recompile or if for some reason the
// structure does not contain any file information we should
// specify the root to trigger a rebuild.
$root = $in['root'];
} elseif (isset($in['files']) and is_array($in['files'])) {
foreach ($in['files'] as $fname => $ftime) {
if (! file_exists($fname) or filemtime($fname) > $ftime) {
// One of the files we knew about previously has changed
// so we should look at our incoming root again.
$root = $in['root'];
break;
}
}
}
} else {
// TODO: Throw an exception? We got neither a string nor something
// that looks like a compatible lessphp cache structure.
return null;
}
if ($root !== null) {
// If we have a root value which means we should rebuild.
$out = [];
$out['root'] = $root;
$out['compiled'] = $this->compileFile($root);
$out['files'] = $this->scss->getParsedFiles();
$out['updated'] = time();
return $out;
} else {
// No changes, pass back the structure
// we were given initially.
return $in;
}
} | [
"public",
"function",
"cachedCompile",
"(",
"$",
"in",
",",
"$",
"force",
"=",
"false",
")",
"{",
"// assume no root",
"$",
"root",
"=",
"null",
";",
"if",
"(",
"is_string",
"(",
"$",
"in",
")",
")",
"{",
"$",
"root",
"=",
"$",
"in",
";",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"in",
")",
"and",
"isset",
"(",
"$",
"in",
"[",
"'root'",
"]",
")",
")",
"{",
"if",
"(",
"$",
"force",
"or",
"!",
"isset",
"(",
"$",
"in",
"[",
"'files'",
"]",
")",
")",
"{",
"// If we are forcing a recompile or if for some reason the",
"// structure does not contain any file information we should",
"// specify the root to trigger a rebuild.",
"$",
"root",
"=",
"$",
"in",
"[",
"'root'",
"]",
";",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"in",
"[",
"'files'",
"]",
")",
"and",
"is_array",
"(",
"$",
"in",
"[",
"'files'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"in",
"[",
"'files'",
"]",
"as",
"$",
"fname",
"=>",
"$",
"ftime",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"fname",
")",
"or",
"filemtime",
"(",
"$",
"fname",
")",
">",
"$",
"ftime",
")",
"{",
"// One of the files we knew about previously has changed",
"// so we should look at our incoming root again.",
"$",
"root",
"=",
"$",
"in",
"[",
"'root'",
"]",
";",
"break",
";",
"}",
"}",
"}",
"}",
"else",
"{",
"// TODO: Throw an exception? We got neither a string nor something",
"// that looks like a compatible lessphp cache structure.",
"return",
"null",
";",
"}",
"if",
"(",
"$",
"root",
"!==",
"null",
")",
"{",
"// If we have a root value which means we should rebuild.",
"$",
"out",
"=",
"[",
"]",
";",
"$",
"out",
"[",
"'root'",
"]",
"=",
"$",
"root",
";",
"$",
"out",
"[",
"'compiled'",
"]",
"=",
"$",
"this",
"->",
"compileFile",
"(",
"$",
"root",
")",
";",
"$",
"out",
"[",
"'files'",
"]",
"=",
"$",
"this",
"->",
"scss",
"->",
"getParsedFiles",
"(",
")",
";",
"$",
"out",
"[",
"'updated'",
"]",
"=",
"time",
"(",
")",
";",
"return",
"$",
"out",
";",
"}",
"else",
"{",
"// No changes, pass back the structure",
"// we were given initially.",
"return",
"$",
"in",
";",
"}",
"}"
] | Execute scssphp on a .scss file or a scssphp cache structure
The scssphp cache structure contains information about a specific
scss file having been parsed. It can be used as a hint for future
calls to determine whether or not a rebuild is required.
The cache structure contains two important keys that may be used
externally:
compiled: The final compiled CSS
updated: The time (in seconds) the CSS was last compiled
The cache structure is a plain-ol' PHP associative array and can
be serialized and unserialized without a hitch.
@param mixed $in Input
@param boolean $force Force rebuild?
@return array scssphp cache structure | [
"Execute",
"scssphp",
"on",
"a",
".",
"scss",
"file",
"or",
"a",
"scssphp",
"cache",
"structure"
] | 71720fac3374e61cdf3cf4acc724ec2a47031aff | https://github.com/leafo/scssphp/blob/71720fac3374e61cdf3cf4acc724ec2a47031aff/example/Server.php#L440-L482 | train |
leafo/scssphp | src/Parser.php | Parser.match | protected function match($regex, &$out, $eatWhitespace = null)
{
$r = '/' . $regex . '/' . $this->patternModifiers;
if (! preg_match($r, $this->buffer, $out, null, $this->count)) {
return false;
}
$this->count += strlen($out[0]);
if (! isset($eatWhitespace)) {
$eatWhitespace = $this->eatWhiteDefault;
}
if ($eatWhitespace) {
$this->whitespace();
}
return true;
} | php | protected function match($regex, &$out, $eatWhitespace = null)
{
$r = '/' . $regex . '/' . $this->patternModifiers;
if (! preg_match($r, $this->buffer, $out, null, $this->count)) {
return false;
}
$this->count += strlen($out[0]);
if (! isset($eatWhitespace)) {
$eatWhitespace = $this->eatWhiteDefault;
}
if ($eatWhitespace) {
$this->whitespace();
}
return true;
} | [
"protected",
"function",
"match",
"(",
"$",
"regex",
",",
"&",
"$",
"out",
",",
"$",
"eatWhitespace",
"=",
"null",
")",
"{",
"$",
"r",
"=",
"'/'",
".",
"$",
"regex",
".",
"'/'",
".",
"$",
"this",
"->",
"patternModifiers",
";",
"if",
"(",
"!",
"preg_match",
"(",
"$",
"r",
",",
"$",
"this",
"->",
"buffer",
",",
"$",
"out",
",",
"null",
",",
"$",
"this",
"->",
"count",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"this",
"->",
"count",
"+=",
"strlen",
"(",
"$",
"out",
"[",
"0",
"]",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"eatWhitespace",
")",
")",
"{",
"$",
"eatWhitespace",
"=",
"$",
"this",
"->",
"eatWhiteDefault",
";",
"}",
"if",
"(",
"$",
"eatWhitespace",
")",
"{",
"$",
"this",
"->",
"whitespace",
"(",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Try to match something on head of buffer
@param string $regex
@param array $out
@param boolean $eatWhitespace
@return boolean | [
"Try",
"to",
"match",
"something",
"on",
"head",
"of",
"buffer"
] | 71720fac3374e61cdf3cf4acc724ec2a47031aff | https://github.com/leafo/scssphp/blob/71720fac3374e61cdf3cf4acc724ec2a47031aff/src/Parser.php#L867-L886 | train |
leafo/scssphp | src/Parser.php | Parser.matchChar | protected function matchChar($char, $eatWhitespace = null)
{
if (! isset($this->buffer[$this->count]) || $this->buffer[$this->count] !== $char) {
return false;
}
$this->count++;
if (! isset($eatWhitespace)) {
$eatWhitespace = $this->eatWhiteDefault;
}
if ($eatWhitespace) {
$this->whitespace();
}
return true;
} | php | protected function matchChar($char, $eatWhitespace = null)
{
if (! isset($this->buffer[$this->count]) || $this->buffer[$this->count] !== $char) {
return false;
}
$this->count++;
if (! isset($eatWhitespace)) {
$eatWhitespace = $this->eatWhiteDefault;
}
if ($eatWhitespace) {
$this->whitespace();
}
return true;
} | [
"protected",
"function",
"matchChar",
"(",
"$",
"char",
",",
"$",
"eatWhitespace",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"buffer",
"[",
"$",
"this",
"->",
"count",
"]",
")",
"||",
"$",
"this",
"->",
"buffer",
"[",
"$",
"this",
"->",
"count",
"]",
"!==",
"$",
"char",
")",
"{",
"return",
"false",
";",
"}",
"$",
"this",
"->",
"count",
"++",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"eatWhitespace",
")",
")",
"{",
"$",
"eatWhitespace",
"=",
"$",
"this",
"->",
"eatWhiteDefault",
";",
"}",
"if",
"(",
"$",
"eatWhitespace",
")",
"{",
"$",
"this",
"->",
"whitespace",
"(",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Match a single string
@param string $char
@param boolean $eatWhitespace
@return boolean | [
"Match",
"a",
"single",
"string"
] | 71720fac3374e61cdf3cf4acc724ec2a47031aff | https://github.com/leafo/scssphp/blob/71720fac3374e61cdf3cf4acc724ec2a47031aff/src/Parser.php#L896-L912 | train |
leafo/scssphp | src/Parser.php | Parser.mediaQuery | protected function mediaQuery(&$out)
{
$expressions = null;
$parts = [];
if (($this->literal('only', 4) && ($only = true) || $this->literal('not', 3) && ($not = true) || true) &&
$this->mixedKeyword($mediaType)
) {
$prop = [Type::T_MEDIA_TYPE];
if (isset($only)) {
$prop[] = [Type::T_KEYWORD, 'only'];
}
if (isset($not)) {
$prop[] = [Type::T_KEYWORD, 'not'];
}
$media = [Type::T_LIST, '', []];
foreach ((array) $mediaType as $type) {
if (is_array($type)) {
$media[2][] = $type;
} else {
$media[2][] = [Type::T_KEYWORD, $type];
}
}
$prop[] = $media;
$parts[] = $prop;
}
if (empty($parts) || $this->literal('and', 3)) {
$this->genericList($expressions, 'mediaExpression', 'and', false);
if (is_array($expressions)) {
$parts = array_merge($parts, $expressions[2]);
}
}
$out = $parts;
return true;
} | php | protected function mediaQuery(&$out)
{
$expressions = null;
$parts = [];
if (($this->literal('only', 4) && ($only = true) || $this->literal('not', 3) && ($not = true) || true) &&
$this->mixedKeyword($mediaType)
) {
$prop = [Type::T_MEDIA_TYPE];
if (isset($only)) {
$prop[] = [Type::T_KEYWORD, 'only'];
}
if (isset($not)) {
$prop[] = [Type::T_KEYWORD, 'not'];
}
$media = [Type::T_LIST, '', []];
foreach ((array) $mediaType as $type) {
if (is_array($type)) {
$media[2][] = $type;
} else {
$media[2][] = [Type::T_KEYWORD, $type];
}
}
$prop[] = $media;
$parts[] = $prop;
}
if (empty($parts) || $this->literal('and', 3)) {
$this->genericList($expressions, 'mediaExpression', 'and', false);
if (is_array($expressions)) {
$parts = array_merge($parts, $expressions[2]);
}
}
$out = $parts;
return true;
} | [
"protected",
"function",
"mediaQuery",
"(",
"&",
"$",
"out",
")",
"{",
"$",
"expressions",
"=",
"null",
";",
"$",
"parts",
"=",
"[",
"]",
";",
"if",
"(",
"(",
"$",
"this",
"->",
"literal",
"(",
"'only'",
",",
"4",
")",
"&&",
"(",
"$",
"only",
"=",
"true",
")",
"||",
"$",
"this",
"->",
"literal",
"(",
"'not'",
",",
"3",
")",
"&&",
"(",
"$",
"not",
"=",
"true",
")",
"||",
"true",
")",
"&&",
"$",
"this",
"->",
"mixedKeyword",
"(",
"$",
"mediaType",
")",
")",
"{",
"$",
"prop",
"=",
"[",
"Type",
"::",
"T_MEDIA_TYPE",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"only",
")",
")",
"{",
"$",
"prop",
"[",
"]",
"=",
"[",
"Type",
"::",
"T_KEYWORD",
",",
"'only'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"not",
")",
")",
"{",
"$",
"prop",
"[",
"]",
"=",
"[",
"Type",
"::",
"T_KEYWORD",
",",
"'not'",
"]",
";",
"}",
"$",
"media",
"=",
"[",
"Type",
"::",
"T_LIST",
",",
"''",
",",
"[",
"]",
"]",
";",
"foreach",
"(",
"(",
"array",
")",
"$",
"mediaType",
"as",
"$",
"type",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"type",
")",
")",
"{",
"$",
"media",
"[",
"2",
"]",
"[",
"]",
"=",
"$",
"type",
";",
"}",
"else",
"{",
"$",
"media",
"[",
"2",
"]",
"[",
"]",
"=",
"[",
"Type",
"::",
"T_KEYWORD",
",",
"$",
"type",
"]",
";",
"}",
"}",
"$",
"prop",
"[",
"]",
"=",
"$",
"media",
";",
"$",
"parts",
"[",
"]",
"=",
"$",
"prop",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"parts",
")",
"||",
"$",
"this",
"->",
"literal",
"(",
"'and'",
",",
"3",
")",
")",
"{",
"$",
"this",
"->",
"genericList",
"(",
"$",
"expressions",
",",
"'mediaExpression'",
",",
"'and'",
",",
"false",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"expressions",
")",
")",
"{",
"$",
"parts",
"=",
"array_merge",
"(",
"$",
"parts",
",",
"$",
"expressions",
"[",
"2",
"]",
")",
";",
"}",
"}",
"$",
"out",
"=",
"$",
"parts",
";",
"return",
"true",
";",
"}"
] | Parse media query
@param array $out
@return boolean | [
"Parse",
"media",
"query"
] | 71720fac3374e61cdf3cf4acc724ec2a47031aff | https://github.com/leafo/scssphp/blob/71720fac3374e61cdf3cf4acc724ec2a47031aff/src/Parser.php#L1036-L1079 | train |
leafo/scssphp | src/Parser.php | Parser.argValue | protected function argValue(&$out)
{
$s = $this->count;
$keyword = null;
if (! $this->variable($keyword) || ! $this->matchChar(':')) {
$this->seek($s);
$keyword = null;
}
if ($this->genericList($value, 'expression')) {
$out = [$keyword, $value, false];
$s = $this->count;
if ($this->literal('...', 3)) {
$out[2] = true;
} else {
$this->seek($s);
}
return true;
}
return false;
} | php | protected function argValue(&$out)
{
$s = $this->count;
$keyword = null;
if (! $this->variable($keyword) || ! $this->matchChar(':')) {
$this->seek($s);
$keyword = null;
}
if ($this->genericList($value, 'expression')) {
$out = [$keyword, $value, false];
$s = $this->count;
if ($this->literal('...', 3)) {
$out[2] = true;
} else {
$this->seek($s);
}
return true;
}
return false;
} | [
"protected",
"function",
"argValue",
"(",
"&",
"$",
"out",
")",
"{",
"$",
"s",
"=",
"$",
"this",
"->",
"count",
";",
"$",
"keyword",
"=",
"null",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"variable",
"(",
"$",
"keyword",
")",
"||",
"!",
"$",
"this",
"->",
"matchChar",
"(",
"':'",
")",
")",
"{",
"$",
"this",
"->",
"seek",
"(",
"$",
"s",
")",
";",
"$",
"keyword",
"=",
"null",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"genericList",
"(",
"$",
"value",
",",
"'expression'",
")",
")",
"{",
"$",
"out",
"=",
"[",
"$",
"keyword",
",",
"$",
"value",
",",
"false",
"]",
";",
"$",
"s",
"=",
"$",
"this",
"->",
"count",
";",
"if",
"(",
"$",
"this",
"->",
"literal",
"(",
"'...'",
",",
"3",
")",
")",
"{",
"$",
"out",
"[",
"2",
"]",
"=",
"true",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"seek",
"(",
"$",
"s",
")",
";",
"}",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Parse argument value
@param array $out
@return boolean | [
"Parse",
"argument",
"value"
] | 71720fac3374e61cdf3cf4acc724ec2a47031aff | https://github.com/leafo/scssphp/blob/71720fac3374e61cdf3cf4acc724ec2a47031aff/src/Parser.php#L1137-L1162 | train |
leafo/scssphp | src/Parser.php | Parser.func | protected function func($name, &$func)
{
$s = $this->count;
if ($this->matchChar('(')) {
if ($name === 'alpha' && $this->argumentList($args)) {
$func = [Type::T_FUNCTION, $name, [Type::T_STRING, '', $args]];
return true;
}
if ($name !== 'expression' && ! preg_match('/^(-[a-z]+-)?calc$/', $name)) {
$ss = $this->count;
if ($this->argValues($args) && $this->matchChar(')')) {
$func = [Type::T_FUNCTION_CALL, $name, $args];
return true;
}
$this->seek($ss);
}
if (($this->openString(')', $str, '(') || true) &&
$this->matchChar(')')
) {
$args = [];
if (! empty($str)) {
$args[] = [null, [Type::T_STRING, '', [$str]]];
}
$func = [Type::T_FUNCTION_CALL, $name, $args];
return true;
}
}
$this->seek($s);
return false;
} | php | protected function func($name, &$func)
{
$s = $this->count;
if ($this->matchChar('(')) {
if ($name === 'alpha' && $this->argumentList($args)) {
$func = [Type::T_FUNCTION, $name, [Type::T_STRING, '', $args]];
return true;
}
if ($name !== 'expression' && ! preg_match('/^(-[a-z]+-)?calc$/', $name)) {
$ss = $this->count;
if ($this->argValues($args) && $this->matchChar(')')) {
$func = [Type::T_FUNCTION_CALL, $name, $args];
return true;
}
$this->seek($ss);
}
if (($this->openString(')', $str, '(') || true) &&
$this->matchChar(')')
) {
$args = [];
if (! empty($str)) {
$args[] = [null, [Type::T_STRING, '', [$str]]];
}
$func = [Type::T_FUNCTION_CALL, $name, $args];
return true;
}
}
$this->seek($s);
return false;
} | [
"protected",
"function",
"func",
"(",
"$",
"name",
",",
"&",
"$",
"func",
")",
"{",
"$",
"s",
"=",
"$",
"this",
"->",
"count",
";",
"if",
"(",
"$",
"this",
"->",
"matchChar",
"(",
"'('",
")",
")",
"{",
"if",
"(",
"$",
"name",
"===",
"'alpha'",
"&&",
"$",
"this",
"->",
"argumentList",
"(",
"$",
"args",
")",
")",
"{",
"$",
"func",
"=",
"[",
"Type",
"::",
"T_FUNCTION",
",",
"$",
"name",
",",
"[",
"Type",
"::",
"T_STRING",
",",
"''",
",",
"$",
"args",
"]",
"]",
";",
"return",
"true",
";",
"}",
"if",
"(",
"$",
"name",
"!==",
"'expression'",
"&&",
"!",
"preg_match",
"(",
"'/^(-[a-z]+-)?calc$/'",
",",
"$",
"name",
")",
")",
"{",
"$",
"ss",
"=",
"$",
"this",
"->",
"count",
";",
"if",
"(",
"$",
"this",
"->",
"argValues",
"(",
"$",
"args",
")",
"&&",
"$",
"this",
"->",
"matchChar",
"(",
"')'",
")",
")",
"{",
"$",
"func",
"=",
"[",
"Type",
"::",
"T_FUNCTION_CALL",
",",
"$",
"name",
",",
"$",
"args",
"]",
";",
"return",
"true",
";",
"}",
"$",
"this",
"->",
"seek",
"(",
"$",
"ss",
")",
";",
"}",
"if",
"(",
"(",
"$",
"this",
"->",
"openString",
"(",
"')'",
",",
"$",
"str",
",",
"'('",
")",
"||",
"true",
")",
"&&",
"$",
"this",
"->",
"matchChar",
"(",
"')'",
")",
")",
"{",
"$",
"args",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"str",
")",
")",
"{",
"$",
"args",
"[",
"]",
"=",
"[",
"null",
",",
"[",
"Type",
"::",
"T_STRING",
",",
"''",
",",
"[",
"$",
"str",
"]",
"]",
"]",
";",
"}",
"$",
"func",
"=",
"[",
"Type",
"::",
"T_FUNCTION_CALL",
",",
"$",
"name",
",",
"$",
"args",
"]",
";",
"return",
"true",
";",
"}",
"}",
"$",
"this",
"->",
"seek",
"(",
"$",
"s",
")",
";",
"return",
"false",
";",
"}"
] | Parse function call
@param string $name
@param array $out
@return boolean | [
"Parse",
"function",
"call"
] | 71720fac3374e61cdf3cf4acc724ec2a47031aff | https://github.com/leafo/scssphp/blob/71720fac3374e61cdf3cf4acc724ec2a47031aff/src/Parser.php#L1521-L1562 | train |
leafo/scssphp | src/Parser.php | Parser.argumentList | protected function argumentList(&$out)
{
$s = $this->count;
$this->matchChar('(');
$args = [];
while ($this->keyword($var)) {
if ($this->matchChar('=') && $this->expression($exp)) {
$args[] = [Type::T_STRING, '', [$var . '=']];
$arg = $exp;
} else {
break;
}
$args[] = $arg;
if (! $this->matchChar(',')) {
break;
}
$args[] = [Type::T_STRING, '', [', ']];
}
if (! $this->matchChar(')') || !$args) {
$this->seek($s);
return false;
}
$out = $args;
return true;
} | php | protected function argumentList(&$out)
{
$s = $this->count;
$this->matchChar('(');
$args = [];
while ($this->keyword($var)) {
if ($this->matchChar('=') && $this->expression($exp)) {
$args[] = [Type::T_STRING, '', [$var . '=']];
$arg = $exp;
} else {
break;
}
$args[] = $arg;
if (! $this->matchChar(',')) {
break;
}
$args[] = [Type::T_STRING, '', [', ']];
}
if (! $this->matchChar(')') || !$args) {
$this->seek($s);
return false;
}
$out = $args;
return true;
} | [
"protected",
"function",
"argumentList",
"(",
"&",
"$",
"out",
")",
"{",
"$",
"s",
"=",
"$",
"this",
"->",
"count",
";",
"$",
"this",
"->",
"matchChar",
"(",
"'('",
")",
";",
"$",
"args",
"=",
"[",
"]",
";",
"while",
"(",
"$",
"this",
"->",
"keyword",
"(",
"$",
"var",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"matchChar",
"(",
"'='",
")",
"&&",
"$",
"this",
"->",
"expression",
"(",
"$",
"exp",
")",
")",
"{",
"$",
"args",
"[",
"]",
"=",
"[",
"Type",
"::",
"T_STRING",
",",
"''",
",",
"[",
"$",
"var",
".",
"'='",
"]",
"]",
";",
"$",
"arg",
"=",
"$",
"exp",
";",
"}",
"else",
"{",
"break",
";",
"}",
"$",
"args",
"[",
"]",
"=",
"$",
"arg",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"matchChar",
"(",
"','",
")",
")",
"{",
"break",
";",
"}",
"$",
"args",
"[",
"]",
"=",
"[",
"Type",
"::",
"T_STRING",
",",
"''",
",",
"[",
"', '",
"]",
"]",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"matchChar",
"(",
"')'",
")",
"||",
"!",
"$",
"args",
")",
"{",
"$",
"this",
"->",
"seek",
"(",
"$",
"s",
")",
";",
"return",
"false",
";",
"}",
"$",
"out",
"=",
"$",
"args",
";",
"return",
"true",
";",
"}"
] | Parse function call argument list
@param array $out
@return boolean | [
"Parse",
"function",
"call",
"argument",
"list"
] | 71720fac3374e61cdf3cf4acc724ec2a47031aff | https://github.com/leafo/scssphp/blob/71720fac3374e61cdf3cf4acc724ec2a47031aff/src/Parser.php#L1571-L1604 | train |
leafo/scssphp | src/Parser.php | Parser.mixedKeyword | protected function mixedKeyword(&$out)
{
$parts = [];
$oldWhite = $this->eatWhiteDefault;
$this->eatWhiteDefault = false;
for (;;) {
if ($this->keyword($key)) {
$parts[] = $key;
continue;
}
if ($this->interpolation($inter)) {
$parts[] = $inter;
continue;
}
break;
}
$this->eatWhiteDefault = $oldWhite;
if (!$parts) {
return false;
}
if ($this->eatWhiteDefault) {
$this->whitespace();
}
$out = $parts;
return true;
} | php | protected function mixedKeyword(&$out)
{
$parts = [];
$oldWhite = $this->eatWhiteDefault;
$this->eatWhiteDefault = false;
for (;;) {
if ($this->keyword($key)) {
$parts[] = $key;
continue;
}
if ($this->interpolation($inter)) {
$parts[] = $inter;
continue;
}
break;
}
$this->eatWhiteDefault = $oldWhite;
if (!$parts) {
return false;
}
if ($this->eatWhiteDefault) {
$this->whitespace();
}
$out = $parts;
return true;
} | [
"protected",
"function",
"mixedKeyword",
"(",
"&",
"$",
"out",
")",
"{",
"$",
"parts",
"=",
"[",
"]",
";",
"$",
"oldWhite",
"=",
"$",
"this",
"->",
"eatWhiteDefault",
";",
"$",
"this",
"->",
"eatWhiteDefault",
"=",
"false",
";",
"for",
"(",
";",
";",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"keyword",
"(",
"$",
"key",
")",
")",
"{",
"$",
"parts",
"[",
"]",
"=",
"$",
"key",
";",
"continue",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"interpolation",
"(",
"$",
"inter",
")",
")",
"{",
"$",
"parts",
"[",
"]",
"=",
"$",
"inter",
";",
"continue",
";",
"}",
"break",
";",
"}",
"$",
"this",
"->",
"eatWhiteDefault",
"=",
"$",
"oldWhite",
";",
"if",
"(",
"!",
"$",
"parts",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"eatWhiteDefault",
")",
"{",
"$",
"this",
"->",
"whitespace",
"(",
")",
";",
"}",
"$",
"out",
"=",
"$",
"parts",
";",
"return",
"true",
";",
"}"
] | Parse keyword or interpolation
@param array $out
@return boolean | [
"Parse",
"keyword",
"or",
"interpolation"
] | 71720fac3374e61cdf3cf4acc724ec2a47031aff | https://github.com/leafo/scssphp/blob/71720fac3374e61cdf3cf4acc724ec2a47031aff/src/Parser.php#L1880-L1914 | train |
leafo/scssphp | src/Parser.php | Parser.variable | protected function variable(&$out)
{
$s = $this->count;
if ($this->matchChar('$', false) && $this->keyword($name)) {
$out = [Type::T_VARIABLE, $name];
return true;
}
$this->seek($s);
return false;
} | php | protected function variable(&$out)
{
$s = $this->count;
if ($this->matchChar('$', false) && $this->keyword($name)) {
$out = [Type::T_VARIABLE, $name];
return true;
}
$this->seek($s);
return false;
} | [
"protected",
"function",
"variable",
"(",
"&",
"$",
"out",
")",
"{",
"$",
"s",
"=",
"$",
"this",
"->",
"count",
";",
"if",
"(",
"$",
"this",
"->",
"matchChar",
"(",
"'$'",
",",
"false",
")",
"&&",
"$",
"this",
"->",
"keyword",
"(",
"$",
"name",
")",
")",
"{",
"$",
"out",
"=",
"[",
"Type",
"::",
"T_VARIABLE",
",",
"$",
"name",
"]",
";",
"return",
"true",
";",
"}",
"$",
"this",
"->",
"seek",
"(",
"$",
"s",
")",
";",
"return",
"false",
";",
"}"
] | Parse a variable
@param array $out
@return boolean | [
"Parse",
"a",
"variable"
] | 71720fac3374e61cdf3cf4acc724ec2a47031aff | https://github.com/leafo/scssphp/blob/71720fac3374e61cdf3cf4acc724ec2a47031aff/src/Parser.php#L2332-L2345 | train |
leafo/scssphp | src/Parser.php | Parser.end | protected function end()
{
if ($this->matchChar(';')) {
return true;
}
if ($this->count === strlen($this->buffer) || $this->buffer[$this->count] === '}') {
// if there is end of file or a closing block next then we don't need a ;
return true;
}
return false;
} | php | protected function end()
{
if ($this->matchChar(';')) {
return true;
}
if ($this->count === strlen($this->buffer) || $this->buffer[$this->count] === '}') {
// if there is end of file or a closing block next then we don't need a ;
return true;
}
return false;
} | [
"protected",
"function",
"end",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"matchChar",
"(",
"';'",
")",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"count",
"===",
"strlen",
"(",
"$",
"this",
"->",
"buffer",
")",
"||",
"$",
"this",
"->",
"buffer",
"[",
"$",
"this",
"->",
"count",
"]",
"===",
"'}'",
")",
"{",
"// if there is end of file or a closing block next then we don't need a ;",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Consume an end of statement delimiter
@return boolean | [
"Consume",
"an",
"end",
"of",
"statement",
"delimiter"
] | 71720fac3374e61cdf3cf4acc724ec2a47031aff | https://github.com/leafo/scssphp/blob/71720fac3374e61cdf3cf4acc724ec2a47031aff/src/Parser.php#L2418-L2430 | train |
leafo/scssphp | src/SourceMap/Base64VLQ.php | Base64VLQ.encode | public static function encode($value)
{
$encoded = '';
$vlq = self::toVLQSigned($value);
do {
$digit = $vlq & self::VLQ_BASE_MASK;
$vlq >>= self::VLQ_BASE_SHIFT;
if ($vlq > 0) {
$digit |= self::VLQ_CONTINUATION_BIT;
}
$encoded .= Base64::encode($digit);
} while ($vlq > 0);
return $encoded;
} | php | public static function encode($value)
{
$encoded = '';
$vlq = self::toVLQSigned($value);
do {
$digit = $vlq & self::VLQ_BASE_MASK;
$vlq >>= self::VLQ_BASE_SHIFT;
if ($vlq > 0) {
$digit |= self::VLQ_CONTINUATION_BIT;
}
$encoded .= Base64::encode($digit);
} while ($vlq > 0);
return $encoded;
} | [
"public",
"static",
"function",
"encode",
"(",
"$",
"value",
")",
"{",
"$",
"encoded",
"=",
"''",
";",
"$",
"vlq",
"=",
"self",
"::",
"toVLQSigned",
"(",
"$",
"value",
")",
";",
"do",
"{",
"$",
"digit",
"=",
"$",
"vlq",
"&",
"self",
"::",
"VLQ_BASE_MASK",
";",
"$",
"vlq",
">>=",
"self",
"::",
"VLQ_BASE_SHIFT",
";",
"if",
"(",
"$",
"vlq",
">",
"0",
")",
"{",
"$",
"digit",
"|=",
"self",
"::",
"VLQ_CONTINUATION_BIT",
";",
"}",
"$",
"encoded",
".=",
"Base64",
"::",
"encode",
"(",
"$",
"digit",
")",
";",
"}",
"while",
"(",
"$",
"vlq",
">",
"0",
")",
";",
"return",
"$",
"encoded",
";",
"}"
] | Returns the VLQ encoded value.
@param integer $value
@return string | [
"Returns",
"the",
"VLQ",
"encoded",
"value",
"."
] | 71720fac3374e61cdf3cf4acc724ec2a47031aff | https://github.com/leafo/scssphp/blob/71720fac3374e61cdf3cf4acc724ec2a47031aff/src/SourceMap/Base64VLQ.php#L57-L74 | train |
leafo/scssphp | src/SourceMap/Base64VLQ.php | Base64VLQ.decode | public static function decode($str, &$index)
{
$result = 0;
$shift = 0;
do {
$c = $str[$index++];
$digit = Base64::decode($c);
$continuation = ($digit & self::VLQ_CONTINUATION_BIT) != 0;
$digit &= self::VLQ_BASE_MASK;
$result = $result + ($digit << $shift);
$shift = $shift + self::VLQ_BASE_SHIFT;
} while ($continuation);
return self::fromVLQSigned($result);
} | php | public static function decode($str, &$index)
{
$result = 0;
$shift = 0;
do {
$c = $str[$index++];
$digit = Base64::decode($c);
$continuation = ($digit & self::VLQ_CONTINUATION_BIT) != 0;
$digit &= self::VLQ_BASE_MASK;
$result = $result + ($digit << $shift);
$shift = $shift + self::VLQ_BASE_SHIFT;
} while ($continuation);
return self::fromVLQSigned($result);
} | [
"public",
"static",
"function",
"decode",
"(",
"$",
"str",
",",
"&",
"$",
"index",
")",
"{",
"$",
"result",
"=",
"0",
";",
"$",
"shift",
"=",
"0",
";",
"do",
"{",
"$",
"c",
"=",
"$",
"str",
"[",
"$",
"index",
"++",
"]",
";",
"$",
"digit",
"=",
"Base64",
"::",
"decode",
"(",
"$",
"c",
")",
";",
"$",
"continuation",
"=",
"(",
"$",
"digit",
"&",
"self",
"::",
"VLQ_CONTINUATION_BIT",
")",
"!=",
"0",
";",
"$",
"digit",
"&=",
"self",
"::",
"VLQ_BASE_MASK",
";",
"$",
"result",
"=",
"$",
"result",
"+",
"(",
"$",
"digit",
"<<",
"$",
"shift",
")",
";",
"$",
"shift",
"=",
"$",
"shift",
"+",
"self",
"::",
"VLQ_BASE_SHIFT",
";",
"}",
"while",
"(",
"$",
"continuation",
")",
";",
"return",
"self",
"::",
"fromVLQSigned",
"(",
"$",
"result",
")",
";",
"}"
] | Decodes VLQValue.
@param string $str
@param integer $index
@return integer | [
"Decodes",
"VLQValue",
"."
] | 71720fac3374e61cdf3cf4acc724ec2a47031aff | https://github.com/leafo/scssphp/blob/71720fac3374e61cdf3cf4acc724ec2a47031aff/src/SourceMap/Base64VLQ.php#L84-L99 | train |
thekordy/ticketit | src/Models/Agent.php | Agent.scopeAdmins | public function scopeAdmins($query, $paginate = false)
{
if ($paginate) {
return $query->where('ticketit_admin', '1')->paginate($paginate, ['*'], 'admins_page');
} else {
return $query->where('ticketit_admin', '1')->get();
}
} | php | public function scopeAdmins($query, $paginate = false)
{
if ($paginate) {
return $query->where('ticketit_admin', '1')->paginate($paginate, ['*'], 'admins_page');
} else {
return $query->where('ticketit_admin', '1')->get();
}
} | [
"public",
"function",
"scopeAdmins",
"(",
"$",
"query",
",",
"$",
"paginate",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"paginate",
")",
"{",
"return",
"$",
"query",
"->",
"where",
"(",
"'ticketit_admin'",
",",
"'1'",
")",
"->",
"paginate",
"(",
"$",
"paginate",
",",
"[",
"'*'",
"]",
",",
"'admins_page'",
")",
";",
"}",
"else",
"{",
"return",
"$",
"query",
"->",
"where",
"(",
"'ticketit_admin'",
",",
"'1'",
")",
"->",
"get",
"(",
")",
";",
"}",
"}"
] | list of all admins and returning collection.
@param $query
@param bool $paginate
@return bool
@internal param int $cat_id | [
"list",
"of",
"all",
"admins",
"and",
"returning",
"collection",
"."
] | 55fc54152a2e9d941e114f8c242b7db209c2a47e | https://github.com/thekordy/ticketit/blob/55fc54152a2e9d941e114f8c242b7db209c2a47e/src/Models/Agent.php#L41-L48 | train |
thekordy/ticketit | src/Models/Agent.php | Agent.scopeAgentsLists | public function scopeAgentsLists($query)
{
if (version_compare(app()->version(), '5.2.0', '>=')) {
return $query->where('ticketit_agent', '1')->pluck('name', 'id')->toArray();
} else { // if Laravel 5.1
return $query->where('ticketit_agent', '1')->lists('name', 'id')->toArray();
}
} | php | public function scopeAgentsLists($query)
{
if (version_compare(app()->version(), '5.2.0', '>=')) {
return $query->where('ticketit_agent', '1')->pluck('name', 'id')->toArray();
} else { // if Laravel 5.1
return $query->where('ticketit_agent', '1')->lists('name', 'id')->toArray();
}
} | [
"public",
"function",
"scopeAgentsLists",
"(",
"$",
"query",
")",
"{",
"if",
"(",
"version_compare",
"(",
"app",
"(",
")",
"->",
"version",
"(",
")",
",",
"'5.2.0'",
",",
"'>='",
")",
")",
"{",
"return",
"$",
"query",
"->",
"where",
"(",
"'ticketit_agent'",
",",
"'1'",
")",
"->",
"pluck",
"(",
"'name'",
",",
"'id'",
")",
"->",
"toArray",
"(",
")",
";",
"}",
"else",
"{",
"// if Laravel 5.1",
"return",
"$",
"query",
"->",
"where",
"(",
"'ticketit_agent'",
",",
"'1'",
")",
"->",
"lists",
"(",
"'name'",
",",
"'id'",
")",
"->",
"toArray",
"(",
")",
";",
"}",
"}"
] | list of all agents and returning lists array of id and name.
@param $query
@return bool
@internal param int $cat_id | [
"list",
"of",
"all",
"agents",
"and",
"returning",
"lists",
"array",
"of",
"id",
"and",
"name",
"."
] | 55fc54152a2e9d941e114f8c242b7db209c2a47e | https://github.com/thekordy/ticketit/blob/55fc54152a2e9d941e114f8c242b7db209c2a47e/src/Models/Agent.php#L78-L85 | train |
thekordy/ticketit | src/Models/Agent.php | Agent.isAgent | public static function isAgent($id = null)
{
if (isset($id)) {
$user = User::find($id);
if ($user->ticketit_agent) {
return true;
}
return false;
}
if (auth()->check()) {
if (auth()->user()->ticketit_agent) {
return true;
}
}
} | php | public static function isAgent($id = null)
{
if (isset($id)) {
$user = User::find($id);
if ($user->ticketit_agent) {
return true;
}
return false;
}
if (auth()->check()) {
if (auth()->user()->ticketit_agent) {
return true;
}
}
} | [
"public",
"static",
"function",
"isAgent",
"(",
"$",
"id",
"=",
"null",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"id",
")",
")",
"{",
"$",
"user",
"=",
"User",
"::",
"find",
"(",
"$",
"id",
")",
";",
"if",
"(",
"$",
"user",
"->",
"ticketit_agent",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}",
"if",
"(",
"auth",
"(",
")",
"->",
"check",
"(",
")",
")",
"{",
"if",
"(",
"auth",
"(",
")",
"->",
"user",
"(",
")",
"->",
"ticketit_agent",
")",
"{",
"return",
"true",
";",
"}",
"}",
"}"
] | Check if user is agent.
@return bool | [
"Check",
"if",
"user",
"is",
"agent",
"."
] | 55fc54152a2e9d941e114f8c242b7db209c2a47e | https://github.com/thekordy/ticketit/blob/55fc54152a2e9d941e114f8c242b7db209c2a47e/src/Models/Agent.php#L92-L107 | train |
thekordy/ticketit | src/Models/Agent.php | Agent.isAssignedAgent | public static function isAssignedAgent($id)
{
if (auth()->check() && Auth::user()->ticketit_agent) {
if (Auth::user()->id == Ticket::find($id)->agent->id) {
return true;
}
}
} | php | public static function isAssignedAgent($id)
{
if (auth()->check() && Auth::user()->ticketit_agent) {
if (Auth::user()->id == Ticket::find($id)->agent->id) {
return true;
}
}
} | [
"public",
"static",
"function",
"isAssignedAgent",
"(",
"$",
"id",
")",
"{",
"if",
"(",
"auth",
"(",
")",
"->",
"check",
"(",
")",
"&&",
"Auth",
"::",
"user",
"(",
")",
"->",
"ticketit_agent",
")",
"{",
"if",
"(",
"Auth",
"::",
"user",
"(",
")",
"->",
"id",
"==",
"Ticket",
"::",
"find",
"(",
"$",
"id",
")",
"->",
"agent",
"->",
"id",
")",
"{",
"return",
"true",
";",
"}",
"}",
"}"
] | Check if user is the assigned agent for a ticket.
@param int $id ticket id
@return bool | [
"Check",
"if",
"user",
"is",
"the",
"assigned",
"agent",
"for",
"a",
"ticket",
"."
] | 55fc54152a2e9d941e114f8c242b7db209c2a47e | https://github.com/thekordy/ticketit/blob/55fc54152a2e9d941e114f8c242b7db209c2a47e/src/Models/Agent.php#L126-L133 | train |
thekordy/ticketit | src/Models/Agent.php | Agent.isTicketOwner | public static function isTicketOwner($id)
{
if (auth()->check()) {
if (auth()->user()->id == Ticket::find($id)->user->id) {
return true;
}
}
} | php | public static function isTicketOwner($id)
{
if (auth()->check()) {
if (auth()->user()->id == Ticket::find($id)->user->id) {
return true;
}
}
} | [
"public",
"static",
"function",
"isTicketOwner",
"(",
"$",
"id",
")",
"{",
"if",
"(",
"auth",
"(",
")",
"->",
"check",
"(",
")",
")",
"{",
"if",
"(",
"auth",
"(",
")",
"->",
"user",
"(",
")",
"->",
"id",
"==",
"Ticket",
"::",
"find",
"(",
"$",
"id",
")",
"->",
"user",
"->",
"id",
")",
"{",
"return",
"true",
";",
"}",
"}",
"}"
] | Check if user is the owner for a ticket.
@param int $id ticket id
@return bool | [
"Check",
"if",
"user",
"is",
"the",
"owner",
"for",
"a",
"ticket",
"."
] | 55fc54152a2e9d941e114f8c242b7db209c2a47e | https://github.com/thekordy/ticketit/blob/55fc54152a2e9d941e114f8c242b7db209c2a47e/src/Models/Agent.php#L142-L149 | train |
thekordy/ticketit | src/Controllers/AgentsController.php | AgentsController.addAgents | public function addAgents($user_ids)
{
$users = Agent::find($user_ids);
foreach ($users as $user) {
$user->ticketit_agent = true;
$user->save();
$users_list[] = $user->name;
}
return $users_list;
} | php | public function addAgents($user_ids)
{
$users = Agent::find($user_ids);
foreach ($users as $user) {
$user->ticketit_agent = true;
$user->save();
$users_list[] = $user->name;
}
return $users_list;
} | [
"public",
"function",
"addAgents",
"(",
"$",
"user_ids",
")",
"{",
"$",
"users",
"=",
"Agent",
"::",
"find",
"(",
"$",
"user_ids",
")",
";",
"foreach",
"(",
"$",
"users",
"as",
"$",
"user",
")",
"{",
"$",
"user",
"->",
"ticketit_agent",
"=",
"true",
";",
"$",
"user",
"->",
"save",
"(",
")",
";",
"$",
"users_list",
"[",
"]",
"=",
"$",
"user",
"->",
"name",
";",
"}",
"return",
"$",
"users_list",
";",
"}"
] | Assign users as agents.
@param $user_ids
@return array | [
"Assign",
"users",
"as",
"agents",
"."
] | 55fc54152a2e9d941e114f8c242b7db209c2a47e | https://github.com/thekordy/ticketit/blob/55fc54152a2e9d941e114f8c242b7db209c2a47e/src/Controllers/AgentsController.php#L73-L83 | train |
thekordy/ticketit | src/Controllers/AgentsController.php | AgentsController.removeAgent | public function removeAgent($id)
{
$agent = Agent::find($id);
$agent->ticketit_agent = false;
$agent->save();
// Remove him from tickets categories as well
if (version_compare(app()->version(), '5.2.0', '>=')) {
$agent_cats = $agent->categories->pluck('id')->toArray();
} else { // if Laravel 5.1
$agent_cats = $agent->categories->lists('id')->toArray();
}
$agent->categories()->detach($agent_cats);
return $agent;
} | php | public function removeAgent($id)
{
$agent = Agent::find($id);
$agent->ticketit_agent = false;
$agent->save();
// Remove him from tickets categories as well
if (version_compare(app()->version(), '5.2.0', '>=')) {
$agent_cats = $agent->categories->pluck('id')->toArray();
} else { // if Laravel 5.1
$agent_cats = $agent->categories->lists('id')->toArray();
}
$agent->categories()->detach($agent_cats);
return $agent;
} | [
"public",
"function",
"removeAgent",
"(",
"$",
"id",
")",
"{",
"$",
"agent",
"=",
"Agent",
"::",
"find",
"(",
"$",
"id",
")",
";",
"$",
"agent",
"->",
"ticketit_agent",
"=",
"false",
";",
"$",
"agent",
"->",
"save",
"(",
")",
";",
"// Remove him from tickets categories as well",
"if",
"(",
"version_compare",
"(",
"app",
"(",
")",
"->",
"version",
"(",
")",
",",
"'5.2.0'",
",",
"'>='",
")",
")",
"{",
"$",
"agent_cats",
"=",
"$",
"agent",
"->",
"categories",
"->",
"pluck",
"(",
"'id'",
")",
"->",
"toArray",
"(",
")",
";",
"}",
"else",
"{",
"// if Laravel 5.1",
"$",
"agent_cats",
"=",
"$",
"agent",
"->",
"categories",
"->",
"lists",
"(",
"'id'",
")",
"->",
"toArray",
"(",
")",
";",
"}",
"$",
"agent",
"->",
"categories",
"(",
")",
"->",
"detach",
"(",
"$",
"agent_cats",
")",
";",
"return",
"$",
"agent",
";",
"}"
] | Remove user from the agents.
@param $id
@return mixed | [
"Remove",
"user",
"from",
"the",
"agents",
"."
] | 55fc54152a2e9d941e114f8c242b7db209c2a47e | https://github.com/thekordy/ticketit/blob/55fc54152a2e9d941e114f8c242b7db209c2a47e/src/Controllers/AgentsController.php#L92-L108 | train |
thekordy/ticketit | src/Controllers/AgentsController.php | AgentsController.syncAgentCategories | public function syncAgentCategories($id, Request $request)
{
$form_cats = ($request->input('agent_cats') == null) ? [] : $request->input('agent_cats');
$agent = Agent::find($id);
$agent->categories()->sync($form_cats);
} | php | public function syncAgentCategories($id, Request $request)
{
$form_cats = ($request->input('agent_cats') == null) ? [] : $request->input('agent_cats');
$agent = Agent::find($id);
$agent->categories()->sync($form_cats);
} | [
"public",
"function",
"syncAgentCategories",
"(",
"$",
"id",
",",
"Request",
"$",
"request",
")",
"{",
"$",
"form_cats",
"=",
"(",
"$",
"request",
"->",
"input",
"(",
"'agent_cats'",
")",
"==",
"null",
")",
"?",
"[",
"]",
":",
"$",
"request",
"->",
"input",
"(",
"'agent_cats'",
")",
";",
"$",
"agent",
"=",
"Agent",
"::",
"find",
"(",
"$",
"id",
")",
";",
"$",
"agent",
"->",
"categories",
"(",
")",
"->",
"sync",
"(",
"$",
"form_cats",
")",
";",
"}"
] | Sync Agent categories with the selected categories got from update form.
@param $id
@param Request $request | [
"Sync",
"Agent",
"categories",
"with",
"the",
"selected",
"categories",
"got",
"from",
"update",
"form",
"."
] | 55fc54152a2e9d941e114f8c242b7db209c2a47e | https://github.com/thekordy/ticketit/blob/55fc54152a2e9d941e114f8c242b7db209c2a47e/src/Controllers/AgentsController.php#L116-L121 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.