idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
7,000
public function getBirthDate ( ) : Date { foreach ( $ this -> getAllBirthDates ( ) as $ date ) { if ( $ date -> isOK ( ) ) { return $ date ; } } return new Date ( '' ) ; }
Get the date of birth
7,001
public function getBirthPlace ( ) : Place { foreach ( $ this -> getAllBirthPlaces ( ) as $ place ) { return $ place ; } return new Place ( '' , $ this -> tree ) ; }
Get the place of birth
7,002
public function getDeathDate ( ) : Date { foreach ( $ this -> getAllDeathDates ( ) as $ date ) { if ( $ date -> isOK ( ) ) { return $ date ; } } return new Date ( '' ) ; }
Get the date of death
7,003
public function getDeathPlace ( ) : Place { foreach ( $ this -> getAllDeathPlaces ( ) as $ place ) { return $ place ; } return new Place ( '' , $ this -> tree ) ; }
Get the place of death
7,004
public function getAllBirthDates ( ) : array { foreach ( Gedcom :: BIRTH_EVENTS as $ event ) { $ tmp = $ this -> getAllEventDates ( [ $ event ] ) ; if ( $ tmp ) { return $ tmp ; } } return [ ] ; }
Get all the birth dates - for the individual lists .
7,005
public function getAllBirthPlaces ( ) : array { foreach ( Gedcom :: BIRTH_EVENTS as $ event ) { $ places = $ this -> getAllEventPlaces ( [ $ event ] ) ; if ( ! empty ( $ places ) ) { return $ places ; } } return [ ] ; }
Gat all the birth places - for the individual lists .
7,006
public function getAllDeathDates ( ) : array { foreach ( Gedcom :: DEATH_EVENTS as $ event ) { $ tmp = $ this -> getAllEventDates ( [ $ event ] ) ; if ( $ tmp ) { return $ tmp ; } } return [ ] ; }
Get all the death dates - for the individual lists .
7,007
public function getAllDeathPlaces ( ) : array { foreach ( Gedcom :: DEATH_EVENTS as $ event ) { $ places = $ this -> getAllEventPlaces ( [ $ event ] ) ; if ( ! empty ( $ places ) ) { return $ places ; } } return [ ] ; }
Get all the death places - for the individual lists .
7,008
public function getEstimatedDeathDate ( ) : Date { if ( $ this -> estimated_death_date === null ) { foreach ( $ this -> getAllDeathDates ( ) as $ date ) { if ( $ date -> isOK ( ) ) { $ this -> estimated_death_date = $ date ; break ; } } if ( $ this -> estimated_death_date === null ) { if ( $ this -> getEstimatedBirthDate ( ) -> minimumJulianDay ( ) ) { $ max_alive_age = ( int ) $ this -> tree -> getPreference ( 'MAX_ALIVE_AGE' ) ; $ this -> estimated_death_date = $ this -> getEstimatedBirthDate ( ) -> addYears ( $ max_alive_age , 'BEF' ) ; } else { $ this -> estimated_death_date = new Date ( '' ) ; } } } return $ this -> estimated_death_date ; }
Generate an estimated date of death .
7,009
public function getCurrentSpouse ( ) : ? Individual { $ family = $ this -> spouseFamilies ( ) -> last ( ) ; if ( $ family instanceof Family ) { return $ family -> spouse ( $ this ) ; } return null ; }
Get the current spouse of this individual .
7,010
public function numberOfChildren ( ) : int { if ( preg_match ( '/\n1 NCHI (\d+)(?:\n|$)/' , $ this -> gedcom ( ) , $ match ) ) { return ( int ) $ match [ 1 ] ; } $ children = [ ] ; foreach ( $ this -> spouseFamilies ( ) as $ fam ) { foreach ( $ fam -> children ( ) as $ child ) { $ children [ $ child -> xref ( ) ] = true ; } } return count ( $ children ) ; }
Count the children belonging to this individual .
7,011
public function primaryChildFamily ( ) : ? Family { $ families = $ this -> childFamilies ( ) ; switch ( $ families -> count ( ) ) { case 0 : return null ; case 1 : return $ families [ 0 ] ; default : foreach ( $ families as $ fam ) { $ famid = $ fam -> xref ( ) ; if ( preg_match ( "/\n1 FAMC @{$famid}@\n(?:[2-9].*\n)*(?:2 _PRIMARY Y)/" , $ this -> gedcom ( ) ) ) { return $ fam ; } } foreach ( $ families as $ fam ) { $ famid = $ fam -> xref ( ) ; if ( preg_match ( "/\n1 FAMC @{$famid}@\n(?:[2-9].*\n)*(?:2 PEDI birth)/" , $ this -> gedcom ( ) ) ) { return $ fam ; } } foreach ( $ families as $ fam ) { $ famid = $ fam -> xref ( ) ; if ( ! preg_match ( "/\n1 FAMC @{$famid}@\n(?:[2-9].*\n)*(?:2 PEDI)/" , $ this -> gedcom ( ) ) ) { return $ fam ; } } return $ families [ 0 ] ; } }
Get the preferred parents for this individual .
7,012
public function getSpouseFamilyLabel ( Family $ family ) : string { $ spouse = $ family -> spouse ( $ this ) ; if ( $ spouse ) { return I18N :: translate ( 'Family with %s' , $ spouse -> fullName ( ) ) ; } return $ family -> fullName ( ) ; }
Get the description for the family .
7,013
public function getPrimaryParentsNames ( $ classname = '' , $ display = '' ) : string { $ fam = $ this -> primaryChildFamily ( ) ; if ( ! $ fam ) { return '' ; } $ txt = '<div' ; if ( $ classname ) { $ txt .= ' class="' . $ classname . '"' ; } if ( $ display ) { $ txt .= ' style="display:' . $ display . '"' ; } $ txt .= '>' ; $ husb = $ fam -> husband ( ) ; if ( $ husb ) { $ primary = $ husb -> getPrimaryName ( ) ; $ husb -> setPrimaryName ( null ) ; $ txt .= I18N :: translate ( 'Father: %s' , $ husb -> fullName ( ) ) . '<br>' ; $ husb -> setPrimaryName ( $ primary ) ; } $ wife = $ fam -> wife ( ) ; if ( $ wife ) { $ primary = $ wife -> getPrimaryName ( ) ; $ wife -> setPrimaryName ( null ) ; $ txt .= I18N :: translate ( 'Mother: %s' , $ wife -> fullName ( ) ) ; $ wife -> setPrimaryName ( $ primary ) ; } $ txt .= '</div>' ; return $ txt ; }
get primary parents names for this individual
7,014
public function formatListDetails ( ) : string { return $ this -> formatFirstMajorFact ( Gedcom :: BIRTH_EVENTS , 1 ) . $ this -> formatFirstMajorFact ( Gedcom :: DEATH_EVENTS , 1 ) ; }
Extra info to display when displaying this record in a list of selection items or favorites .
7,015
protected function allAncestors ( Individual $ individual ) : array { $ ancestors = [ 1 => $ individual , ] ; do { $ sosa = key ( $ ancestors ) ; $ family = $ ancestors [ $ sosa ] -> primaryChildFamily ( ) ; if ( $ family !== null ) { if ( $ family -> husband ( ) !== null ) { $ ancestors [ $ sosa * 2 ] = $ family -> husband ( ) ; } if ( $ family -> wife ( ) !== null ) { $ ancestors [ $ sosa * 2 + 1 ] = $ family -> wife ( ) ; } } } while ( next ( $ ancestors ) ) ; return $ ancestors ; }
Find all ancestors of an individual indexed by the Sosa - Stradonitz number .
7,016
private function loadIndividuals ( Tree $ tree , string $ surname , bool $ soundex_dm , bool $ soundex_std ) : array { $ individuals = DB :: table ( 'individuals' ) -> join ( 'name' , static function ( JoinClause $ join ) : void { $ join -> on ( 'name.n_file' , '=' , 'individuals.i_file' ) -> on ( 'name.n_id' , '=' , 'individuals.i_id' ) ; } ) -> where ( 'i_file' , '=' , $ tree -> id ( ) ) -> where ( 'n_type' , '<>' , '_MARNM' ) -> where ( static function ( Builder $ query ) use ( $ surname , $ soundex_dm , $ soundex_std ) : void { $ query -> where ( 'n_surn' , '=' , $ surname ) -> orWhere ( 'n_surname' , '=' , $ surname ) ; if ( $ soundex_std ) { $ sdx = Soundex :: russell ( $ surname ) ; if ( $ sdx !== '' ) { foreach ( explode ( ':' , $ sdx ) as $ value ) { $ query -> whereContains ( 'n_soundex_surn_std' , $ value , 'or' ) ; } } } if ( $ soundex_dm ) { $ sdx = Soundex :: daitchMokotoff ( $ surname ) ; if ( $ sdx !== '' ) { foreach ( explode ( ':' , $ sdx ) as $ value ) { $ query -> whereContains ( 'n_soundex_surn_dm' , $ value , 'or' ) ; } } } } ) -> select ( [ 'individuals.*' ] ) -> distinct ( ) -> get ( ) -> map ( Individual :: rowMapper ( ) ) -> filter ( GedcomRecord :: accessFilter ( ) ) -> all ( ) ; usort ( $ individuals , Individual :: birthDateComparator ( ) ) ; return $ individuals ; }
Fetch all individuals with a matching surname
7,017
public function getPatriarchsHtml ( Tree $ tree , array $ individuals , array $ ancestors , string $ surname , bool $ soundex_dm , bool $ soundex_std ) : string { $ html = '' ; foreach ( $ individuals as $ individual ) { foreach ( $ individual -> childFamilies ( ) as $ family ) { foreach ( $ family -> spouses ( ) as $ parent ) { if ( in_array ( $ parent , $ individuals , true ) ) { continue 3 ; } } } $ html .= $ this -> getDescendantsHtml ( $ tree , $ individuals , $ ancestors , $ surname , $ soundex_dm , $ soundex_std , $ individual , null ) ; } return $ html ; }
For each individual with no ancestors list their descendants .
7,018
public function historicEventsForIndividual ( Individual $ individual ) : Collection { $ min_date = $ individual -> getEstimatedBirthDate ( ) ; $ max_date = $ individual -> getEstimatedDeathDate ( ) ; return ( new Collection ( $ this -> historicEventsAll ( ) ) ) -> map ( static function ( string $ gedcom ) use ( $ individual ) : Fact { return new Fact ( $ gedcom , $ individual , 'histo' ) ; } ) -> filter ( static function ( Fact $ fact ) use ( $ min_date , $ max_date ) : bool { return Date :: compare ( $ fact -> date ( ) , $ min_date ) >= 0 && Date :: compare ( $ fact -> date ( ) , $ max_date ) <= 0 ; } ) ; }
Which events should we show for an individual?
7,019
private function hitCountQuery ( $ page_name , string $ page_parameter = '' ) : string { if ( $ page_name === '' ) { $ page_name = 'index.php' ; $ page_parameter = 'gedcom:' . $ this -> tree -> id ( ) ; } elseif ( $ page_name === 'index.php' ) { $ user = $ this -> user_service -> findByIdentifier ( $ page_parameter ) ; $ page_parameter = 'user:' . ( $ user ? $ user -> id ( ) : Auth :: id ( ) ) ; } $ count = ( int ) DB :: table ( 'hit_counter' ) -> where ( 'gedcom_id' , '=' , $ this -> tree -> id ( ) ) -> where ( 'page_name' , '=' , $ page_name ) -> where ( 'page_parameter' , '=' , $ page_parameter ) -> value ( 'page_count' ) ; return view ( 'statistics/hit-count' , [ 'count' => $ count , ] ) ; }
These functions provide access to hitcounter for use in the HTML block .
7,020
private function getPlaceListLocation ( int $ id ) : array { if ( $ id === 0 ) { $ fqpn = '' ; } else { $ hierarchy = $ this -> getHierarchy ( $ id ) ; $ fqpn = ', ' . $ hierarchy [ 0 ] -> fqpn ; } $ rows = DB :: table ( 'placelocation' ) -> where ( 'pl_parent_id' , '=' , $ id ) -> orderBy ( 'pl_place' ) -> get ( ) ; $ list = [ ] ; foreach ( $ rows as $ row ) { $ children = $ this -> childLocationStatus ( ( int ) $ row -> pl_id ) ; $ active = $ this -> isLocationActive ( $ row -> pl_place . $ fqpn ) ; if ( ! $ active ) { $ badge = 'danger' ; } elseif ( ( int ) $ children -> no_coord > 0 ) { $ badge = 'warning' ; } elseif ( ( int ) $ children -> child_count > 0 ) { $ badge = 'info' ; } else { $ badge = 'secondary' ; } $ row -> child_count = ( int ) $ children -> child_count ; $ row -> badge = $ badge ; $ list [ ] = $ row ; } return $ list ; }
Find all of the places in the hierarchy
7,021
private function childLocationStatus ( int $ parent_id ) : stdClass { $ prefix = DB :: connection ( ) -> getTablePrefix ( ) ; $ expression = $ prefix . 'p0.pl_place IS NOT NULL AND ' . $ prefix . 'p0.pl_lati IS NULL OR ' . $ prefix . 'p1.pl_place IS NOT NULL AND ' . $ prefix . 'p1.pl_lati IS NULL OR ' . $ prefix . 'p2.pl_place IS NOT NULL AND ' . $ prefix . 'p2.pl_lati IS NULL OR ' . $ prefix . 'p3.pl_place IS NOT NULL AND ' . $ prefix . 'p3.pl_lati IS NULL OR ' . $ prefix . 'p4.pl_place IS NOT NULL AND ' . $ prefix . 'p4.pl_lati IS NULL OR ' . $ prefix . 'p5.pl_place IS NOT NULL AND ' . $ prefix . 'p5.pl_lati IS NULL OR ' . $ prefix . 'p6.pl_place IS NOT NULL AND ' . $ prefix . 'p6.pl_lati IS NULL OR ' . $ prefix . 'p7.pl_place IS NOT NULL AND ' . $ prefix . 'p7.pl_lati IS NULL OR ' . $ prefix . 'p8.pl_place IS NOT NULL AND ' . $ prefix . 'p8.pl_lati IS NULL OR ' . $ prefix . 'p9.pl_place IS NOT NULL AND ' . $ prefix . 'p9.pl_lati IS NULL' ; return DB :: table ( 'placelocation AS p0' ) -> leftJoin ( 'placelocation AS p1' , 'p1.pl_parent_id' , '=' , 'p0.pl_id' ) -> leftJoin ( 'placelocation AS p2' , 'p2.pl_parent_id' , '=' , 'p1.pl_id' ) -> leftJoin ( 'placelocation AS p3' , 'p3.pl_parent_id' , '=' , 'p2.pl_id' ) -> leftJoin ( 'placelocation AS p4' , 'p4.pl_parent_id' , '=' , 'p3.pl_id' ) -> leftJoin ( 'placelocation AS p5' , 'p5.pl_parent_id' , '=' , 'p4.pl_id' ) -> leftJoin ( 'placelocation AS p6' , 'p6.pl_parent_id' , '=' , 'p5.pl_id' ) -> leftJoin ( 'placelocation AS p7' , 'p7.pl_parent_id' , '=' , 'p6.pl_id' ) -> leftJoin ( 'placelocation AS p8' , 'p8.pl_parent_id' , '=' , 'p7.pl_id' ) -> leftJoin ( 'placelocation AS p9' , 'p9.pl_parent_id' , '=' , 'p8.pl_id' ) -> where ( 'p0.pl_parent_id' , '=' , $ parent_id ) -> select ( [ DB :: raw ( 'COUNT(*) AS child_count' ) , DB :: raw ( 'SUM(' . $ expression . ') AS no_coord' ) ] ) -> first ( ) ; }
How many children does place have? How many have co - ordinates?
7,022
private function isLocationActive ( string $ place_name ) : bool { $ places = explode ( Gedcom :: PLACE_SEPARATOR , $ place_name ) ; $ query = DB :: table ( 'places AS p0' ) -> where ( 'p0.p_place' , '=' , $ places [ 0 ] ) -> select ( [ 'pl0.*' ] ) ; array_shift ( $ places ) ; foreach ( $ places as $ n => $ place ) { $ query -> join ( 'places AS p' . ( $ n + 1 ) , static function ( JoinClause $ join ) use ( $ n , $ place ) : void { $ join -> on ( 'p' . ( $ n + 1 ) . '.p_id' , '=' , 'p' . $ n . '.p_parent_id' ) -> where ( 'p' . ( $ n + 1 ) . '.p_place' , '=' , $ place ) ; } ) ; } return $ query -> exists ( ) ; }
Is a place name used in any tree?
7,023
public function createServerRequest ( ) : ServerRequestInterface { $ server_request_creator = new ServerRequestCreator ( app ( ServerRequestFactoryInterface :: class ) , app ( UriFactoryInterface :: class ) , app ( UploadedFileFactoryInterface :: class ) , app ( StreamFactoryInterface :: class ) ) ; if ( class_exists ( Request :: class ) ) { return Request :: createFromGlobals ( ) ; } return $ server_request_creator -> fromGlobals ( ) ; }
We can use any PSR - 7 compatible requests .
7,024
public function middleware ( ) : array { return [ PhpEnvironment :: class , EmitResponse :: class , HandleExceptions :: class , ReadConfigIni :: class , UseDatabase :: class , UseDebugbar :: class , UpdateDatabaseSchema :: class , UseCache :: class , UseFilesystem :: class , UseSession :: class , UseTree :: class , UseLocale :: class , CheckForMaintenanceMode :: class , UseTheme :: class , DoHousekeeping :: class , CheckCsrf :: class , UseTransaction :: class , BootModules :: class , ModuleMiddleware :: class , RequestRouter :: class , NoRouteFound :: class , ] ; }
The webtrees application is built from middleware .
7,025
private function privacyRestrictions ( Tree $ tree ) : array { return DB :: table ( 'default_resn' ) -> where ( 'gedcom_id' , '=' , $ tree -> id ( ) ) -> get ( ) -> map ( static function ( stdClass $ row ) use ( $ tree ) : stdClass { $ row -> record = null ; $ row -> label = '' ; if ( $ row -> xref !== null ) { $ row -> record = GedcomRecord :: getInstance ( $ row -> xref , $ tree ) ; } if ( $ row -> tag_type ) { $ row -> tag_label = GedcomTag :: getLabel ( $ row -> tag_type ) ; } else { $ row -> tag_label = '' ; } return $ row ; } ) -> sort ( static function ( stdClass $ x , stdClass $ y ) : int { return I18N :: strcasecmp ( $ x -> tag_label , $ y -> tag_label ) ; } ) -> all ( ) ; }
The current privacy restrictions for a tree .
7,026
private function tagsForPrivacy ( Tree $ tree ) : array { $ tags = array_unique ( array_merge ( explode ( ',' , $ tree -> getPreference ( 'INDI_FACTS_ADD' ) ) , explode ( ',' , $ tree -> getPreference ( 'INDI_FACTS_UNIQUE' ) ) , explode ( ',' , $ tree -> getPreference ( 'FAM_FACTS_ADD' ) ) , explode ( ',' , $ tree -> getPreference ( 'FAM_FACTS_UNIQUE' ) ) , explode ( ',' , $ tree -> getPreference ( 'NOTE_FACTS_ADD' ) ) , explode ( ',' , $ tree -> getPreference ( 'NOTE_FACTS_UNIQUE' ) ) , explode ( ',' , $ tree -> getPreference ( 'SOUR_FACTS_ADD' ) ) , explode ( ',' , $ tree -> getPreference ( 'SOUR_FACTS_UNIQUE' ) ) , explode ( ',' , $ tree -> getPreference ( 'REPO_FACTS_ADD' ) ) , explode ( ',' , $ tree -> getPreference ( 'REPO_FACTS_UNIQUE' ) ) , [ 'SOUR' , 'REPO' , 'OBJE' , '_PRIM' , 'NOTE' , 'SUBM' , 'SUBN' , '_UID' , 'CHAN' , ] ) ) ; $ all_tags = [ ] ; foreach ( $ tags as $ tag ) { if ( $ tag ) { $ all_tags [ $ tag ] = GedcomTag :: getLabel ( $ tag ) ; } } uasort ( $ all_tags , '\Fisharebest\Webtrees\I18N::strcasecmp' ) ; return array_merge ( [ '' => I18N :: translate ( 'All facts and events' ) ] , $ all_tags ) ; }
Generate a list of potential problems with the server .
7,027
public function serverErrors ( $ driver = '' ) : Collection { $ errors = Collection :: make ( [ $ this -> databaseDriverErrors ( $ driver ) , $ this -> checkPhpExtension ( 'mbstring' ) , $ this -> checkPhpExtension ( 'iconv' ) , $ this -> checkPhpExtension ( 'pcre' ) , $ this -> checkPhpExtension ( 'session' ) , $ this -> checkPhpExtension ( 'xml' ) , $ this -> checkPhpFunction ( 'parse_ini_file' ) , ] ) ; return $ errors -> flatten ( ) -> filter ( ) ; }
Things that may cause webtrees to break .
7,028
public function serverWarnings ( $ driver = '' ) : Collection { $ warnings = Collection :: make ( [ $ this -> databaseDriverWarnings ( $ driver ) , $ this -> checkPhpExtension ( 'curl' ) , $ this -> checkPhpExtension ( 'gd' ) , $ this -> checkPhpExtension ( 'simplexml' ) , $ this -> checkPhpIni ( 'file_uploads' , true ) , $ this -> checkSystemTemporaryFolder ( ) , $ this -> checkPhpVersion ( ) , ] ) ; return $ warnings -> flatten ( ) -> filter ( ) ; }
Things that should be fixed but which won t stop completely webtrees from running .
7,029
public function isFunctionDisabled ( string $ function ) : bool { $ disable_functions = explode ( ',' , ini_get ( 'disable_functions' ) ) ; $ disable_functions = array_map ( static function ( string $ func ) : string { return strtolower ( trim ( $ func ) ) ; } , $ disable_functions ) ; $ function = strtolower ( $ function ) ; return in_array ( $ function , $ disable_functions , true ) || ! function_exists ( $ function ) ; }
Check if a PHP function is in the list of disabled functions .
7,030
public function analyticsCanShow ( ) : bool { $ request = app ( ServerRequestInterface :: class ) ; $ dnt = $ request -> getServerParams ( ) [ 'HTTP_DNT' ] ?? '' ; if ( $ dnt === '1' ) { return false ; } foreach ( $ this -> analyticsParameters ( ) as $ parameter ) { if ( $ parameter === '' ) { return false ; } } return true ; }
Should we add this tracker?
7,031
public function contactPage ( ServerRequestInterface $ request , Tree $ tree ) : ResponseInterface { $ referer = $ request -> getHeaderLine ( 'referer' ) ; $ body = $ request -> get ( 'body' , '' ) ; $ from_email = $ request -> get ( 'from_email' , '' ) ; $ from_name = $ request -> get ( 'from_name' , '' ) ; $ subject = $ request -> get ( 'subject' , '' ) ; $ to = $ request -> get ( 'to' , '' ) ; $ url = $ request -> get ( 'url' , $ referer ) ; $ to_user = $ this -> user_service -> findByUserName ( $ to ) ; if ( ! in_array ( $ to_user , $ this -> validContacts ( $ tree ) , false ) ) { throw new AccessDeniedHttpException ( 'Invalid contact user id' ) ; } $ to_name = $ to_user -> realName ( ) ; $ title = I18N :: translate ( 'Send a message' ) ; return $ this -> viewResponse ( 'contact-page' , [ 'body' => $ body , 'from_email' => $ from_email , 'from_name' => $ from_name , 'subject' => $ subject , 'title' => $ title , 'to' => $ to , 'to_name' => $ to_name , 'url' => $ url , ] ) ; }
A form to compose a message from a visitor .
7,032
private function validContacts ( Tree $ tree ) : array { $ contacts = [ $ this -> user_service -> find ( ( int ) $ tree -> getPreference ( 'CONTACT_USER_ID' ) ) , $ this -> user_service -> find ( ( int ) $ tree -> getPreference ( 'WEBMASTER_USER_ID' ) ) , ] ; return array_filter ( $ contacts ) ; }
Contact messages can only be sent to the designated contacts
7,033
private function deliverMessage ( Tree $ tree , UserInterface $ sender , UserInterface $ recipient , string $ subject , string $ body , string $ url , string $ ip ) : bool { $ success = true ; I18N :: init ( $ recipient -> getPreference ( 'language' ) ) ; $ body_text = view ( 'emails/message-user-text' , [ 'sender' => $ sender , 'recipient' => $ recipient , 'message' => $ body , 'url' => $ url , ] ) ; $ body_html = view ( 'emails/message-user-html' , [ 'sender' => $ sender , 'recipient' => $ recipient , 'message' => $ body , 'url' => $ url , ] ) ; if ( $ this -> sendInternalMessage ( $ recipient ) ) { DB :: table ( 'message' ) -> insert ( [ 'sender' => Auth :: check ( ) ? Auth :: user ( ) -> email ( ) : $ sender -> email ( ) , 'ip_address' => $ ip , 'user_id' => $ recipient -> id ( ) , 'subject' => $ subject , 'body' => $ body_text , ] ) ; } if ( $ this -> sendEmail ( $ recipient ) ) { $ success = Mail :: send ( new TreeUser ( $ tree ) , $ recipient , $ sender , I18N :: translate ( 'webtrees message' ) . ' - ' . $ subject , $ body_text , $ body_html ) ; } I18N :: init ( WT_LOCALE ) ; return $ success ; }
Add a message to a user s inbox send it to them via email or both .
7,034
public function searchFamilyNames ( array $ trees , array $ search , int $ offset = 0 , int $ limit = PHP_INT_MAX ) : Collection { $ query = DB :: table ( 'families' ) -> leftJoin ( 'name AS husb_name' , static function ( JoinClause $ join ) : void { $ join -> on ( 'husb_name.n_file' , '=' , 'families.f_file' ) -> on ( 'husb_name.n_id' , '=' , 'families.f_husb' ) -> where ( 'husb_name.n_type' , '<>' , '_MARNM' ) ; } ) -> leftJoin ( 'name AS wife_name' , static function ( JoinClause $ join ) : void { $ join -> on ( 'wife_name.n_file' , '=' , 'families.f_file' ) -> on ( 'wife_name.n_id' , '=' , 'families.f_wife' ) -> where ( 'wife_name.n_type' , '<>' , '_MARNM' ) ; } ) ; $ prefix = DB :: connection ( ) -> getTablePrefix ( ) ; $ field = DB :: raw ( 'COALESCE(' . $ prefix . "husb_name.n_full, '') || COALESCE(" . $ prefix . "wife_name.n_full, '')" ) ; $ this -> whereTrees ( $ query , 'f_file' , $ trees ) ; $ this -> whereSearch ( $ query , $ field , $ search ) ; $ query -> orderBy ( 'husb_name.n_sort' ) -> orderBy ( 'wife_name.n_sort' ) -> select ( [ 'families.*' , 'husb_name.n_sort' , 'wife_name.n_sort' ] ) -> distinct ( ) ; return $ this -> paginateQuery ( $ query , Family :: rowMapper ( ) , GedcomRecord :: accessFilter ( ) , $ offset , $ limit ) ; }
Search for families by name .
7,035
public function searchIndividualNames ( array $ trees , array $ search , int $ offset = 0 , int $ limit = PHP_INT_MAX ) : Collection { $ query = DB :: table ( 'individuals' ) -> join ( 'name' , static function ( JoinClause $ join ) : void { $ join -> on ( 'name.n_file' , '=' , 'individuals.i_file' ) -> on ( 'name.n_id' , '=' , 'individuals.i_id' ) ; } ) -> orderBy ( 'n_sort' ) -> select ( [ 'individuals.*' , 'n_num' ] ) ; $ this -> whereTrees ( $ query , 'i_file' , $ trees ) ; $ this -> whereSearch ( $ query , 'n_full' , $ search ) ; return $ this -> paginateQuery ( $ query , Individual :: rowMapper ( ) , GedcomRecord :: accessFilter ( ) , $ offset , $ limit ) ; }
Search for individuals by name .
7,036
public function searchMedia ( array $ trees , array $ search , int $ offset = 0 , int $ limit = PHP_INT_MAX ) : Collection { $ query = DB :: table ( 'media' ) ; $ this -> whereTrees ( $ query , 'media.m_file' , $ trees ) ; $ this -> whereSearch ( $ query , 'm_gedcom' , $ search ) ; return $ this -> paginateQuery ( $ query , Media :: rowMapper ( ) , GedcomRecord :: accessFilter ( ) , $ offset , $ limit ) ; }
Search for media objects .
7,037
public function searchPlaces ( Tree $ tree , string $ search , int $ offset = 0 , int $ limit = PHP_INT_MAX ) : Collection { $ query = DB :: table ( 'places AS p0' ) -> where ( 'p0.p_file' , '=' , $ tree -> id ( ) ) -> leftJoin ( 'places AS p1' , 'p1.p_id' , '=' , 'p0.p_parent_id' ) -> leftJoin ( 'places AS p2' , 'p2.p_id' , '=' , 'p1.p_parent_id' ) -> leftJoin ( 'places AS p3' , 'p3.p_id' , '=' , 'p2.p_parent_id' ) -> leftJoin ( 'places AS p4' , 'p4.p_id' , '=' , 'p3.p_parent_id' ) -> leftJoin ( 'places AS p5' , 'p5.p_id' , '=' , 'p4.p_parent_id' ) -> leftJoin ( 'places AS p6' , 'p6.p_id' , '=' , 'p5.p_parent_id' ) -> leftJoin ( 'places AS p7' , 'p7.p_id' , '=' , 'p6.p_parent_id' ) -> leftJoin ( 'places AS p8' , 'p8.p_id' , '=' , 'p7.p_parent_id' ) -> orderBy ( 'p0.p_place' ) -> orderBy ( 'p1.p_place' ) -> orderBy ( 'p2.p_place' ) -> orderBy ( 'p3.p_place' ) -> orderBy ( 'p4.p_place' ) -> orderBy ( 'p5.p_place' ) -> orderBy ( 'p6.p_place' ) -> orderBy ( 'p7.p_place' ) -> orderBy ( 'p8.p_place' ) -> select ( [ 'p0.p_place AS place0' , 'p1.p_place AS place1' , 'p2.p_place AS place2' , 'p3.p_place AS place3' , 'p4.p_place AS place4' , 'p5.p_place AS place5' , 'p6.p_place AS place6' , 'p7.p_place AS place7' , 'p8.p_place AS place8' , ] ) ; foreach ( explode ( ',' , $ search , 9 ) as $ level => $ string ) { $ query -> whereContains ( 'p' . $ level . '.p_place' , $ string ) ; } $ row_mapper = static function ( stdClass $ row ) use ( $ tree ) : Place { $ place = implode ( ', ' , array_filter ( ( array ) $ row ) ) ; return new Place ( $ place , $ tree ) ; } ; $ filter = static function ( ) : bool { return true ; } ; return $ this -> paginateQuery ( $ query , $ row_mapper , $ filter , $ offset , $ limit ) ; }
Search for places .
7,038
private function paginateQuery ( Builder $ query , Closure $ row_mapper , Closure $ row_filter , int $ offset , int $ limit ) : Collection { $ collection = new Collection ( ) ; foreach ( $ query -> cursor ( ) as $ row ) { $ record = $ row_mapper ( $ row ) ; if ( $ row_filter ( $ record ) ) { if ( $ offset > 0 ) { $ offset -- ; } else { if ( $ limit > 0 ) { $ collection -> push ( $ record ) ; } $ limit -- ; if ( $ limit === 0 ) { break ; } } } } return $ collection ; }
Paginate a search query .
7,039
private function whereSearch ( Builder $ query , $ field , array $ search_terms ) : void { if ( $ field instanceof Expression ) { $ field = $ field -> getValue ( ) ; } foreach ( $ search_terms as $ search_term ) { $ query -> whereContains ( DB :: raw ( $ field ) , $ search_term ) ; } }
Apply search filters to a SQL query column . Apply collation rules to MySQL .
7,040
private function wherePhonetic ( Builder $ query , $ field , string $ soundex ) : void { if ( $ soundex !== '' ) { $ query -> where ( static function ( Builder $ query ) use ( $ soundex , $ field ) : void { foreach ( explode ( ':' , $ soundex ) as $ sdx ) { $ query -> orWhere ( $ field , 'LIKE' , '%' . $ sdx . '%' ) ; } } ) ; } }
Apply soundex search filters to a SQL query column .
7,041
private function rawGedcomFilter ( array $ search_terms ) : Closure { return static function ( GedcomRecord $ record ) use ( $ search_terms ) : bool { $ gedcom = preg_replace ( '/\n\d (?:_UID) .*/' , '' , $ record -> gedcom ( ) ) ; $ gedcom = preg_replace ( '/\n\d ' . Gedcom :: REGEX_TAG . '( @' . Gedcom :: REGEX_XREF . '@)?/' , '' , $ gedcom ) ; foreach ( $ search_terms as $ search_term ) { if ( mb_stripos ( $ gedcom , $ search_term ) === false ) { return false ; } } return true ; } ; }
A closure to filter records by privacy - filtered GEDCOM data .
7,042
private function rowLimiter ( int $ limit = 1000 ) : Closure { return static function ( ) use ( $ limit ) : void { static $ n = 0 ; if ( ++ $ n > $ limit ) { $ message = I18N :: translate ( 'The search returned too many results.' ) ; throw new InternalServerErrorException ( $ message ) ; } } ; }
Searching for short or common text can give more results than the system can process .
7,043
public function mediaDownload ( ServerRequestInterface $ request , Tree $ tree ) : ResponseInterface { $ xref = $ request -> get ( 'xref' , '' ) ; $ fact_id = $ request -> get ( 'fact_id' ) ; $ media = Media :: getInstance ( $ xref , $ tree ) ; if ( $ media === null ) { throw new MediaNotFoundException ( ) ; } if ( ! $ media -> canShow ( ) ) { throw new AccessDeniedHttpException ( ) ; } foreach ( $ media -> mediaFiles ( ) as $ media_file ) { if ( $ media_file -> factId ( ) === $ fact_id ) { if ( $ media_file -> isExternal ( ) ) { return redirect ( $ media_file -> filename ( ) ) ; } if ( ! $ media_file -> isImage ( ) && $ media_file -> fileExists ( ) ) { $ data = file_get_contents ( $ media_file -> getServerFilename ( ) ) ; return response ( $ data , StatusCodeInterface :: STATUS_OK , [ 'Content-Type' => $ media_file -> mimeType ( ) , 'Content-Disposition' => 'attachment; filename="' . addcslashes ( $ media_file -> filename ( ) , '"' ) . '"' , ] ) ; } } } throw new NotFoundHttpException ( ) ; }
Download a non - image media file .
7,044
private function generateImage ( MediaFile $ media_file , array $ params ) : ResponseInterface { try { $ signature = $ this -> glideSignature ( ) ; $ signature -> validateRequest ( parse_url ( WT_BASE_URL . 'index.php' , PHP_URL_PATH ) , $ params ) ; $ server = $ this -> glideServer ( $ media_file -> folder ( ) ) ; $ path = $ server -> makeImage ( $ media_file -> filename ( ) , $ params ) ; return response ( $ server -> getCache ( ) -> read ( $ path ) , StatusCodeInterface :: STATUS_OK , [ 'Content-Type' => $ server -> getCache ( ) -> getMimetype ( $ path ) , 'Content-Length' => $ server -> getCache ( ) -> getSize ( $ path ) , 'Cache-Control' => 'max-age=31536000, public' , 'Expires' => date_create ( '+1 years' ) -> format ( 'D, d M Y H:i:s' ) . ' GMT' , ] ) ; } catch ( SignatureException $ ex ) { return $ this -> httpStatusAsImage ( StatusCodeInterface :: STATUS_FORBIDDEN ) ; } catch ( FileNotFoundException $ ex ) { return $ this -> httpStatusAsImage ( StatusCodeInterface :: STATUS_NOT_FOUND ) ; } catch ( Throwable $ ex ) { Log :: addErrorLog ( 'Cannot create thumbnail ' . $ ex -> getMessage ( ) ) ; return $ this -> httpStatusAsImage ( StatusCodeInterface :: STATUS_INTERNAL_SERVER_ERROR ) ; } }
Generate a thumbnail image for a file .
7,045
private function httpStatusAsImage ( int $ status ) : ResponseInterface { $ svg = '<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100"><rect width="100" height="100" fill="#F88" /><text x="5" y="55" font-family="Verdana" font-size="35">' . $ status . '</text></svg>' ; return response ( $ svg , StatusCodeInterface :: STATUS_OK , [ 'Content-Type' => 'image/svg+xml' , 'Content-Length' => strlen ( $ svg ) , ] ) ; }
Send a dummy image to replace one that could not be found or created .
7,046
private function fileExtensionAsImage ( string $ extension ) : ResponseInterface { $ extension = '.' . strtolower ( $ extension ) ; $ svg = '<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100"><rect width="100" height="100" fill="#88F" /><text x="5" y="60" font-family="Verdana" font-size="30">' . $ extension . '</text></svg>' ; return response ( $ svg , StatusCodeInterface :: STATUS_OK , [ 'Content-Type' => 'image/svg+xml' , 'Content-Length' => strlen ( $ svg ) , ] ) ; }
Send a dummy image to replace a non - image file .
7,047
public function handle ( ServerRequestInterface $ request , Builder $ query , array $ search_columns , array $ sort_columns , Closure $ callback ) : ResponseInterface { $ search = $ request -> getQueryParams ( ) [ 'search' ] [ 'value' ] ?? '' ; $ start = ( int ) ( $ request -> getQueryParams ( ) [ 'start' ] ?? 0 ) ; $ length = ( int ) ( $ request -> getQueryParams ( ) [ 'length' ] ?? 0 ) ; $ order = $ request -> getQueryParams ( ) [ 'order' ] ?? [ ] ; $ draw = ( int ) ( $ request -> getQueryParams ( ) [ 'draw' ] ?? 0 ) ; $ recordsTotal = ( clone $ query ) -> count ( ) ; if ( $ search !== '' ) { $ query -> where ( static function ( Builder $ query ) use ( $ search , $ search_columns ) : void { foreach ( $ search_columns as $ search_column ) { $ query -> whereContains ( $ search_column , $ search , 'or' ) ; } } ) ; } if ( ! empty ( $ order ) ) { foreach ( $ order as $ value ) { $ sort_column = $ sort_columns [ $ value [ 'column' ] ] ?? DB :: raw ( 1 + $ value [ 'column' ] ) ; $ query -> orderBy ( $ sort_column , $ value [ 'dir' ] ) ; } } else { $ query -> orderBy ( DB :: raw ( 1 ) ) ; } if ( $ length > 0 ) { $ recordsFiltered = ( clone $ query ) -> count ( ) ; $ query -> skip ( $ start ) -> limit ( $ length ) ; $ data = $ query -> get ( ) ; } else { $ data = $ query -> get ( ) ; $ recordsFiltered = $ data -> count ( ) ; } $ data = $ data -> map ( $ callback ) -> all ( ) ; return response ( [ 'draw' => $ draw , 'recordsTotal' => $ recordsTotal , 'recordsFiltered' => $ recordsFiltered , 'data' => $ data , ] ) ; }
Apply filtering and pagination to a query and generate a response suitable for datatables .
7,048
protected function endElement ( $ parser , string $ name ) : void { $ method = $ name . 'EndHandler' ; if ( method_exists ( $ this , $ method ) ) { $ this -> $ method ( ) ; } }
XML handler for a closing tag .
7,049
public function addUnlinked ( Tree $ tree ) : ResponseInterface { return $ this -> viewResponse ( 'edit/new-individual' , [ 'tree' => $ tree , 'title' => I18N :: translate ( 'Create an individual' ) , 'nextaction' => 'add_unlinked_indi_action' , 'individual' => null , 'family' => null , 'name_fact' => null , 'famtag' => '' , 'gender' => 'U' , ] ) ; }
Add an unlinked individual
7,050
public function editName ( ServerRequestInterface $ request , Tree $ tree ) : ResponseInterface { $ fact_id = $ request -> get ( 'fact_id' , '' ) ; $ xref = $ request -> get ( 'xref' , '' ) ; $ individual = Individual :: getInstance ( $ xref , $ tree ) ; Auth :: checkIndividualAccess ( $ individual , true ) ; foreach ( $ individual -> facts ( ) as $ fact ) { if ( $ fact -> id ( ) === $ fact_id && $ fact -> canEdit ( ) ) { return $ this -> viewResponse ( 'edit/new-individual' , [ 'tree' => $ tree , 'title' => I18N :: translate ( 'Edit the name' ) , 'nextaction' => 'update' , 'individual' => $ individual , 'family' => null , 'name_fact' => $ fact , 'famtag' => '' , 'gender' => $ individual -> sex ( ) , ] ) ; } } throw new NotFoundHttpException ( ) ; }
Edit a name record .
7,051
protected function formatDay ( ) : string { $ locale = app ( LocaleInterface :: class ) -> language ( ) -> code ( ) ; if ( $ locale === 'he' || $ locale === 'yi' ) { return ( new JewishCalendar ( ) ) -> numberToHebrewNumerals ( $ this -> day , true ) ; } return parent :: formatDay ( ) ; }
Generate the %j format for a date .
7,052
protected function formatShortYear ( ) : string { $ locale = app ( LocaleInterface :: class ) -> language ( ) -> code ( ) ; if ( $ locale === 'he' || $ locale === 'yi' ) { return ( new JewishCalendar ( ) ) -> numberToHebrewNumerals ( $ this -> year , false ) ; } return parent :: formatLongYear ( ) ; }
Generate the %y format for a date .
7,053
protected function monthNameNominativeCase ( int $ month , bool $ leap_year ) : string { static $ translated_month_names ; if ( $ translated_month_names === null ) { $ translated_month_names = [ 0 => '' , 1 => I18N :: translateContext ( 'NOMINATIVE' , 'Tishrei' ) , 2 => I18N :: translateContext ( 'NOMINATIVE' , 'Heshvan' ) , 3 => I18N :: translateContext ( 'NOMINATIVE' , 'Kislev' ) , 4 => I18N :: translateContext ( 'NOMINATIVE' , 'Tevet' ) , 5 => I18N :: translateContext ( 'NOMINATIVE' , 'Shevat' ) , 6 => I18N :: translateContext ( 'NOMINATIVE' , 'Adar I' ) , 7 => I18N :: translateContext ( 'NOMINATIVE' , 'Adar' ) , - 7 => I18N :: translateContext ( 'NOMINATIVE' , 'Adar II' ) , 8 => I18N :: translateContext ( 'NOMINATIVE' , 'Nissan' ) , 9 => I18N :: translateContext ( 'NOMINATIVE' , 'Iyar' ) , 10 => I18N :: translateContext ( 'NOMINATIVE' , 'Sivan' ) , 11 => I18N :: translateContext ( 'NOMINATIVE' , 'Tamuz' ) , 12 => I18N :: translateContext ( 'NOMINATIVE' , 'Av' ) , 13 => I18N :: translateContext ( 'NOMINATIVE' , 'Elul' ) , ] ; } if ( $ month === 7 && $ leap_year ) { return $ translated_month_names [ - 7 ] ; } return $ translated_month_names [ $ month ] ; }
Full month name in nominative case .
7,054
protected function monthNameAbbreviated ( int $ month , bool $ leap_year ) : string { return $ this -> monthNameNominativeCase ( $ month , $ leap_year ) ; }
Abbreviated month name
7,055
public function dayNames ( int $ day_number ) : string { static $ translated_day_names ; if ( $ translated_day_names === null ) { $ translated_day_names = [ 0 => I18N :: translate ( 'Monday' ) , 1 => I18N :: translate ( 'Tuesday' ) , 2 => I18N :: translate ( 'Wednesday' ) , 3 => I18N :: translate ( 'Thursday' ) , 4 => I18N :: translate ( 'Friday' ) , 5 => I18N :: translate ( 'Saturday' ) , 6 => I18N :: translate ( 'Sunday' ) , ] ; } return $ translated_day_names [ $ day_number ] ; }
Full day of the week
7,056
protected function dayNamesAbbreviated ( int $ day_number ) : string { static $ translated_day_names ; if ( $ translated_day_names === null ) { $ translated_day_names = [ 0 => I18N :: translate ( 'Mon' ) , 1 => I18N :: translate ( 'Tue' ) , 2 => I18N :: translate ( 'Wed' ) , 3 => I18N :: translate ( 'Thu' ) , 4 => I18N :: translate ( 'Fri' ) , 5 => I18N :: translate ( 'Sat' ) , 6 => I18N :: translate ( 'Sun' ) , ] ; } return $ translated_day_names [ $ day_number ] ; }
Abbreviated day of the week
7,057
public static function compare ( AbstractCalendarDate $ d1 , AbstractCalendarDate $ d2 ) : int { if ( $ d1 -> maximum_julian_day < $ d2 -> minimum_julian_day ) { return - 1 ; } if ( $ d2 -> maximum_julian_day < $ d1 -> minimum_julian_day ) { return 1 ; } return 0 ; }
Compare two dates for sorting
7,058
public function getAge ( int $ jd ) : int { if ( $ this -> year === 0 || $ jd === 0 ) { return 0 ; } if ( $ this -> minimum_julian_day < $ jd && $ this -> maximum_julian_day > $ jd ) { return 0 ; } if ( $ this -> minimum_julian_day === $ jd ) { return 0 ; } [ $ y , $ m , $ d ] = $ this -> calendar -> jdToYmd ( $ jd ) ; $ dy = $ y - $ this -> year ; $ dm = $ m - max ( $ this -> month , 1 ) ; $ dd = $ d - max ( $ this -> day , 1 ) ; if ( $ dd < 0 ) { $ dm -- ; } if ( $ dm < 0 ) { $ dy -- ; } return $ dy ; }
How long between an event and a given julian day Return result as a number of years .
7,059
public function getAgeFull ( int $ jd ) : string { if ( $ this -> year === 0 || $ jd === 0 ) { return '' ; } if ( $ this -> minimum_julian_day < $ jd && $ this -> maximum_julian_day > $ jd ) { return '' ; } if ( $ this -> minimum_julian_day === $ jd ) { return '' ; } if ( $ jd < $ this -> minimum_julian_day ) { return view ( 'icons/warning' ) ; } [ $ y , $ m , $ d ] = $ this -> calendar -> jdToYmd ( $ jd ) ; $ dy = $ y - $ this -> year ; $ dm = $ m - max ( $ this -> month , 1 ) ; $ dd = $ d - max ( $ this -> day , 1 ) ; if ( $ dd < 0 ) { $ dm -- ; } if ( $ dm < 0 ) { $ dm += $ this -> calendar -> monthsInYear ( ) ; $ dy -- ; } if ( $ dy > 1 ) { return $ dy . 'y' ; } $ dm += $ dy * $ this -> calendar -> monthsInYear ( ) ; if ( $ dm > 1 ) { return $ dm . 'm' ; } return ( $ jd - $ this -> minimum_julian_day ) . 'd' ; }
How long between an event and a given julian day Return result as a gedcom - style age string .
7,060
public function convertToCalendar ( string $ calendar ) : AbstractCalendarDate { switch ( $ calendar ) { case 'gregorian' : return new GregorianDate ( $ this ) ; case 'julian' : return new JulianDate ( $ this ) ; case 'jewish' : return new JewishDate ( $ this ) ; case 'french' : return new FrenchDate ( $ this ) ; case 'hijri' : return new HijriDate ( $ this ) ; case 'jalali' : return new JalaliDate ( $ this ) ; default : return $ this ; } }
Convert a date from one calendar to another .
7,061
public function inValidRange ( ) : bool { return $ this -> minimum_julian_day >= $ this -> calendar -> jdStart ( ) && $ this -> maximum_julian_day <= $ this -> calendar -> jdEnd ( ) ; }
Is this date within the valid range of the calendar
7,062
public function daysInMonth ( ) : int { try { return $ this -> calendar -> daysInMonth ( $ this -> year , $ this -> month ) ; } catch ( InvalidArgumentException $ ex ) { return 0 ; } }
How many days in the current month
7,063
protected function formatDayZeros ( ) : string { if ( $ this -> day > 9 ) { return I18N :: digits ( $ this -> day ) ; } return I18N :: digits ( '0' . $ this -> day ) ; }
Generate the %d format for a date .
7,064
protected function formatDayOfYear ( ) : string { return I18N :: digits ( $ this -> minimum_julian_day - $ this -> calendar -> ymdToJd ( $ this -> year , 1 , 1 ) ) ; }
Generate the %z format for a date .
7,065
protected function formatMonthZeros ( ) : string { if ( $ this -> month > 9 ) { return I18N :: digits ( $ this -> month ) ; } return I18N :: digits ( '0' . $ this -> month ) ; }
Generate the %m format for a date .
7,066
protected function formatLongMonth ( $ case = 'NOMINATIVE' ) : string { switch ( $ case ) { case 'GENITIVE' : return $ this -> monthNameGenitiveCase ( $ this -> month , $ this -> isLeapYear ( ) ) ; case 'NOMINATIVE' : return $ this -> monthNameNominativeCase ( $ this -> month , $ this -> isLeapYear ( ) ) ; case 'LOCATIVE' : return $ this -> monthNameLocativeCase ( $ this -> month , $ this -> isLeapYear ( ) ) ; case 'INSTRUMENTAL' : return $ this -> monthNameInstrumentalCase ( $ this -> month , $ this -> isLeapYear ( ) ) ; default : throw new InvalidArgumentException ( $ case ) ; } }
Generate the %F format for a date .
7,067
protected function formatGedcomMonth ( ) : string { if ( $ this -> month === 7 && $ this -> calendar instanceof JewishCalendar && ! $ this -> calendar -> isLeapYear ( $ this -> year ) ) { return 'ADR' ; } return array_search ( $ this -> month , static :: MONTH_ABBREVIATIONS , true ) ; }
Generate the %O format for a date .
7,068
public function calendarUrl ( string $ date_format , Tree $ tree ) : string { if ( $ this -> day !== 0 && strpbrk ( $ date_format , 'dDj' ) ) { $ view = 'day' ; } elseif ( $ this -> month !== 0 && strpbrk ( $ date_format , 'FMmn' ) ) { $ view = 'month' ; } else { $ view = 'year' ; } return route ( 'calendar' , [ 'cal' => $ this -> calendar -> gedcomCalendarEscape ( ) , 'year' => $ this -> formatGedcomYear ( ) , 'month' => $ this -> formatGedcomMonth ( ) , 'day' => $ this -> formatGedcomDay ( ) , 'view' => $ view , 'ged' => $ tree -> name ( ) , ] ) ; }
Create a URL that links this date to the WT calendar
7,069
public static function endpushunique ( ) : void { $ content = ob_get_clean ( ) ; self :: $ stacks [ self :: $ stack ] [ sha1 ( $ content ) ] = $ content ; }
Variant of push that will only add one copy of each item .
7,070
public static function stack ( string $ stack ) : string { $ content = implode ( '' , self :: $ stacks [ $ stack ] ?? [ ] ) ; self :: $ stacks [ $ stack ] = [ ] ; return $ content ; }
Implementation of Blade stacks .
7,071
public function getFilenameForView ( string $ view_name ) : string { $ explicit = Str :: startsWith ( $ view_name , self :: NAMESPACE_SEPARATOR ) ; if ( ! Str :: contains ( $ view_name , self :: NAMESPACE_SEPARATOR ) ) { $ view_name = self :: NAMESPACE_SEPARATOR . $ view_name ; } while ( ! $ explicit && array_key_exists ( $ view_name , self :: $ replacements ) ) { $ view_name = self :: $ replacements [ $ view_name ] ; } [ $ namespace , $ view_name ] = explode ( self :: NAMESPACE_SEPARATOR , $ view_name , 2 ) ; if ( ( self :: $ namespaces [ $ namespace ] ?? null ) === null ) { throw new RuntimeException ( 'Namespace "' . e ( $ namespace ) . '" not found.' ) ; } $ view_file = self :: $ namespaces [ $ namespace ] . $ view_name . self :: TEMPLATE_EXTENSION ; if ( ! is_file ( $ view_file ) ) { throw new RuntimeException ( 'View file not found: ' . e ( $ view_file ) ) ; } return $ view_file ; }
Find the file for a view .
7,072
public static function make ( $ name , $ data = [ ] ) : string { $ view = new static ( $ name , $ data ) ; DebugBar :: addView ( $ name , $ data ) ; return $ view -> render ( ) ; }
Cerate and render a view in a single operation .
7,073
public function pasteFact ( string $ fact_id , GedcomRecord $ record ) : bool { $ clipboard = Session :: get ( 'clipboard' ) ; $ record_type = $ record :: RECORD_TYPE ; if ( isset ( $ clipboard [ $ record_type ] [ $ fact_id ] ) ) { $ record -> createFact ( $ clipboard [ $ record_type ] [ $ fact_id ] [ 'factrec' ] , true ) ; return true ; } return false ; }
Copy a fact from the clipboard to a record .
7,074
public function pastableFacts ( GedcomRecord $ record , Collection $ exclude_types ) : Collection { return ( new Collection ( Session :: get ( 'clipboard' , [ ] ) [ $ record :: RECORD_TYPE ] ?? [ ] ) ) -> reverse ( ) -> map ( static function ( array $ clipping ) use ( $ record ) : Fact { return new Fact ( $ clipping [ 'factrec' ] , $ record , md5 ( $ clipping [ 'factrec' ] ) ) ; } ) -> filter ( static function ( Fact $ fact ) use ( $ exclude_types ) : bool { return $ exclude_types -> isEmpty ( ) || ! $ exclude_types -> contains ( $ fact -> getTag ( ) ) ; } ) ; }
Create a list of facts that can be pasted into a given record
7,075
public function pastableFactsOfType ( GedcomRecord $ record , Collection $ types ) : Collection { return ( new Collection ( Session :: get ( 'clipboard' , [ ] ) ) ) -> flatten ( 1 ) -> reverse ( ) -> map ( static function ( array $ clipping ) use ( $ record ) : Fact { return new Fact ( $ clipping [ 'factrec' ] , $ record , md5 ( $ clipping [ 'factrec' ] ) ) ; } ) -> filter ( static function ( Fact $ fact ) use ( $ types ) : bool { return $ types -> contains ( $ fact -> getTag ( ) ) ; } ) ; }
Find facts of a given type from all records .
7,076
public static function getAll ( ) : array { if ( empty ( self :: $ trees ) ) { self :: $ trees = self :: all ( ) -> all ( ) ; } return self :: $ trees ; }
Fetch all the trees that we have permission to access .
7,077
public static function all ( ) : Collection { return app ( 'cache.array' ) -> rememberForever ( __CLASS__ , static function ( ) : Collection { $ query = DB :: table ( 'gedcom' ) -> leftJoin ( 'gedcom_setting' , static function ( JoinClause $ join ) : void { $ join -> on ( 'gedcom_setting.gedcom_id' , '=' , 'gedcom.gedcom_id' ) -> where ( 'gedcom_setting.setting_name' , '=' , 'title' ) ; } ) -> where ( 'gedcom.gedcom_id' , '>' , 0 ) -> select ( [ 'gedcom.gedcom_id AS tree_id' , 'gedcom.gedcom_name AS tree_name' , 'gedcom_setting.setting_value AS tree_title' , ] ) -> orderBy ( 'gedcom.sort_order' ) -> orderBy ( 'gedcom_setting.setting_value' ) ; if ( ! Auth :: isAdmin ( ) ) { $ query -> join ( 'gedcom_setting AS gs2' , static function ( JoinClause $ join ) : void { $ join -> on ( 'gs2.gedcom_id' , '=' , 'gedcom.gedcom_id' ) -> where ( 'gs2.setting_name' , '=' , 'imported' ) ; } ) -> join ( 'gedcom_setting AS gs3' , static function ( JoinClause $ join ) : void { $ join -> on ( 'gs3.gedcom_id' , '=' , 'gedcom.gedcom_id' ) -> where ( 'gs3.setting_name' , '=' , 'REQUIRE_AUTHENTICATION' ) ; } ) -> leftJoin ( 'user_gedcom_setting' , static function ( JoinClause $ join ) : void { $ join -> on ( 'user_gedcom_setting.gedcom_id' , '=' , 'gedcom.gedcom_id' ) -> where ( 'user_gedcom_setting.user_id' , '=' , Auth :: id ( ) ) -> where ( 'user_gedcom_setting.setting_name' , '=' , 'canedit' ) ; } ) -> where ( static function ( Builder $ query ) : void { $ query -> where ( 'user_gedcom_setting.setting_value' , '=' , 'admin' ) -> orWhere ( static function ( Builder $ query ) : void { $ query -> where ( 'gs2.setting_value' , '=' , '1' ) -> where ( 'gs3.setting_value' , '=' , '1' ) -> where ( 'user_gedcom_setting.setting_value' , '<>' , 'none' ) ; } ) -> orWhere ( static function ( Builder $ query ) : void { $ query -> where ( 'gs2.setting_value' , '=' , '1' ) -> where ( 'gs3.setting_value' , '<>' , '1' ) ; } ) ; } ) ; } return $ query -> get ( ) -> mapWithKeys ( static function ( stdClass $ row ) : array { return [ $ row -> tree_id => new self ( ( int ) $ row -> tree_id , $ row -> tree_name , $ row -> tree_title ) ] ; } ) ; } ) ; }
All the trees that we have permission to access .
7,078
public static function create ( string $ tree_name , string $ tree_title ) : Tree { try { DB :: table ( 'gedcom' ) -> insert ( [ 'gedcom_name' => $ tree_name , ] ) ; $ tree_id = ( int ) DB :: connection ( ) -> getPdo ( ) -> lastInsertId ( ) ; $ tree = new self ( $ tree_id , $ tree_name , $ tree_title ) ; } catch ( PDOException $ ex ) { return self :: findByName ( $ tree_name ) ; } $ tree -> setPreference ( 'imported' , '0' ) ; $ tree -> setPreference ( 'title' , $ tree_title ) ; ( new Builder ( DB :: connection ( ) ) ) -> from ( 'gedcom_setting' ) -> insertUsing ( [ 'gedcom_id' , 'setting_name' , 'setting_value' ] , static function ( Builder $ query ) use ( $ tree_id ) : void { $ query -> select ( [ DB :: raw ( $ tree_id ) , 'setting_name' , 'setting_value' ] ) -> from ( 'gedcom_setting' ) -> where ( 'gedcom_id' , '=' , - 1 ) ; } ) ; ( new Builder ( DB :: connection ( ) ) ) -> from ( 'default_resn' ) -> insertUsing ( [ 'gedcom_id' , 'tag_type' , 'resn' ] , static function ( Builder $ query ) use ( $ tree_id ) : void { $ query -> select ( [ DB :: raw ( $ tree_id ) , 'tag_type' , 'resn' ] ) -> from ( 'default_resn' ) -> where ( 'gedcom_id' , '=' , - 1 ) ; } ) ; $ tree -> setPreference ( 'CONTACT_USER_ID' , ( string ) Auth :: id ( ) ) ; $ tree -> setPreference ( 'WEBMASTER_USER_ID' , ( string ) Auth :: id ( ) ) ; $ tree -> setPreference ( 'LANGUAGE' , WT_LOCALE ) ; switch ( WT_LOCALE ) { case 'es' : $ tree -> setPreference ( 'SURNAME_TRADITION' , 'spanish' ) ; break ; case 'is' : $ tree -> setPreference ( 'SURNAME_TRADITION' , 'icelandic' ) ; break ; case 'lt' : $ tree -> setPreference ( 'SURNAME_TRADITION' , 'lithuanian' ) ; break ; case 'pl' : $ tree -> setPreference ( 'SURNAME_TRADITION' , 'polish' ) ; break ; case 'pt' : case 'pt-BR' : $ tree -> setPreference ( 'SURNAME_TRADITION' , 'portuguese' ) ; break ; default : $ tree -> setPreference ( 'SURNAME_TRADITION' , 'paternal' ) ; break ; } $ john_doe = I18N :: translate ( 'John /DOE/' ) ; $ note = I18N :: translate ( 'Edit this individual and replace their details with your own.' ) ; $ gedcom = "0 HEAD\n1 CHAR UTF-8\n0 @X1@ INDI\n1 NAME {$john_doe}\n1 SEX M\n1 BIRT\n2 DATE 01 JAN 1850\n2 NOTE {$note}\n0 TRLR\n" ; DB :: table ( 'gedcom_chunk' ) -> insert ( [ 'gedcom_id' => $ tree_id , 'chunk_data' => $ gedcom , ] ) ; self :: $ trees [ $ tree -> id ] = $ tree ; return $ tree ; }
Create a new tree
7,079
public static function findByName ( $ tree_name ) : ? Tree { foreach ( self :: getAll ( ) as $ tree ) { if ( $ tree -> name === $ tree_name ) { return $ tree ; } } return null ; }
Find the tree with a specific name .
7,080
public function delete ( ) : void { if ( Site :: getPreference ( 'DEFAULT_GEDCOM' ) === $ this -> name ) { Site :: setPreference ( 'DEFAULT_GEDCOM' , '' ) ; } $ this -> deleteGenealogyData ( false ) ; DB :: table ( 'block_setting' ) -> join ( 'block' , 'block.block_id' , '=' , 'block_setting.block_id' ) -> where ( 'gedcom_id' , '=' , $ this -> id ) -> delete ( ) ; DB :: table ( 'block' ) -> where ( 'gedcom_id' , '=' , $ this -> id ) -> delete ( ) ; DB :: table ( 'user_gedcom_setting' ) -> where ( 'gedcom_id' , '=' , $ this -> id ) -> delete ( ) ; DB :: table ( 'gedcom_setting' ) -> where ( 'gedcom_id' , '=' , $ this -> id ) -> delete ( ) ; DB :: table ( 'module_privacy' ) -> where ( 'gedcom_id' , '=' , $ this -> id ) -> delete ( ) ; DB :: table ( 'hit_counter' ) -> where ( 'gedcom_id' , '=' , $ this -> id ) -> delete ( ) ; DB :: table ( 'default_resn' ) -> where ( 'gedcom_id' , '=' , $ this -> id ) -> delete ( ) ; DB :: table ( 'gedcom_chunk' ) -> where ( 'gedcom_id' , '=' , $ this -> id ) -> delete ( ) ; DB :: table ( 'log' ) -> where ( 'gedcom_id' , '=' , $ this -> id ) -> delete ( ) ; DB :: table ( 'gedcom' ) -> where ( 'gedcom_id' , '=' , $ this -> id ) -> delete ( ) ; self :: $ trees = [ ] ; }
Delete everything relating to a tree
7,081
public function exportGedcom ( $ stream ) : void { $ buffer = FunctionsExport :: reformatRecord ( FunctionsExport :: gedcomHeader ( $ this , 'UTF-8' ) ) ; $ union_families = DB :: table ( 'families' ) -> where ( 'f_file' , '=' , $ this -> id ) -> select ( [ 'f_gedcom AS gedcom' , 'f_id AS xref' , DB :: raw ( 'LENGTH(f_id) AS len' ) , DB :: raw ( '2 AS n' ) ] ) ; $ union_sources = DB :: table ( 'sources' ) -> where ( 's_file' , '=' , $ this -> id ) -> select ( [ 's_gedcom AS gedcom' , 's_id AS xref' , DB :: raw ( 'LENGTH(s_id) AS len' ) , DB :: raw ( '3 AS n' ) ] ) ; $ union_other = DB :: table ( 'other' ) -> where ( 'o_file' , '=' , $ this -> id ) -> whereNotIn ( 'o_type' , [ 'HEAD' , 'TRLR' ] ) -> select ( [ 'o_gedcom AS gedcom' , 'o_id AS xref' , DB :: raw ( 'LENGTH(o_id) AS len' ) , DB :: raw ( '4 AS n' ) ] ) ; $ union_media = DB :: table ( 'media' ) -> where ( 'm_file' , '=' , $ this -> id ) -> select ( [ 'm_gedcom AS gedcom' , 'm_id AS xref' , DB :: raw ( 'LENGTH(m_id) AS len' ) , DB :: raw ( '5 AS n' ) ] ) ; DB :: table ( 'individuals' ) -> where ( 'i_file' , '=' , $ this -> id ) -> select ( [ 'i_gedcom AS gedcom' , 'i_id AS xref' , DB :: raw ( 'LENGTH(i_id) AS len' ) , DB :: raw ( '1 AS n' ) ] ) -> union ( $ union_families ) -> union ( $ union_sources ) -> union ( $ union_other ) -> union ( $ union_media ) -> orderBy ( 'n' ) -> orderBy ( 'len' ) -> orderBy ( 'xref' ) -> chunk ( 100 , static function ( Collection $ rows ) use ( $ stream , & $ buffer ) : void { foreach ( $ rows as $ row ) { $ buffer .= FunctionsExport :: reformatRecord ( $ row -> gedcom ) ; if ( strlen ( $ buffer ) > 65535 ) { fwrite ( $ stream , $ buffer ) ; $ buffer = '' ; } } } ) ; fwrite ( $ stream , $ buffer . '0 TRLR' . Gedcom :: EOL ) ; }
Export the tree to a GEDCOM file
7,082
public function importGedcomFile ( StreamInterface $ stream , string $ filename ) : void { $ file_data = '' ; $ this -> deleteGenealogyData ( ( bool ) $ this -> getPreference ( 'keep_media' ) ) ; $ this -> setPreference ( 'gedcom_filename' , $ filename ) ; $ this -> setPreference ( 'imported' , '0' ) ; while ( ! $ stream -> eof ( ) ) { $ file_data .= $ stream -> read ( 65536 ) ; for ( $ pos = strlen ( $ file_data ) - 1 ; $ pos > 0 ; -- $ pos ) { if ( $ file_data [ $ pos ] === '0' && ( $ file_data [ $ pos - 1 ] === "\n" || $ file_data [ $ pos - 1 ] === "\r" ) ) { break ; } } if ( $ pos ) { DB :: table ( 'gedcom_chunk' ) -> insert ( [ 'gedcom_id' => $ this -> id , 'chunk_data' => substr ( $ file_data , 0 , $ pos ) , ] ) ; $ file_data = substr ( $ file_data , $ pos ) ; } } DB :: table ( 'gedcom_chunk' ) -> insert ( [ 'gedcom_id' => $ this -> id , 'chunk_data' => $ file_data , ] ) ; $ stream -> close ( ) ; }
Import data from a gedcom file into this tree .
7,083
public function createRecord ( string $ gedcom ) : GedcomRecord { if ( ! Str :: startsWith ( $ gedcom , '0 @@ ' ) ) { throw new InvalidArgumentException ( 'GedcomRecord::createRecord(' . $ gedcom . ') does not begin 0 @@' ) ; } $ xref = $ this -> getNewXref ( ) ; $ gedcom = '0 @' . $ xref . '@ ' . Str :: after ( $ gedcom , '0 @@ ' ) ; $ gedcom .= "\n1 CHAN\n2 DATE " . date ( 'd M Y' ) . "\n3 TIME " . date ( 'H:i:s' ) . "\n2 _WT_USER " . Auth :: user ( ) -> userName ( ) ; DB :: table ( 'change' ) -> insert ( [ 'gedcom_id' => $ this -> id , 'xref' => $ xref , 'old_gedcom' => '' , 'new_gedcom' => $ gedcom , 'user_id' => Auth :: id ( ) , ] ) ; if ( Auth :: user ( ) -> getPreference ( 'auto_accept' ) ) { FunctionsImport :: acceptAllChanges ( $ xref , $ this ) ; return new GedcomRecord ( $ xref , $ gedcom , null , $ this ) ; } return GedcomRecord :: getInstance ( $ xref , $ this , $ gedcom ) ; }
Create a new record from GEDCOM data .
7,084
public function getNewXref ( ) : string { DB :: table ( 'site_setting' ) -> where ( 'setting_name' , '=' , 'next_xref' ) -> lockForUpdate ( ) -> get ( ) ; $ prefix = 'X' ; $ increment = 1.0 ; do { $ num = ( int ) Site :: getPreference ( 'next_xref' ) + ( int ) $ increment ; $ increment *= 1.01 ; $ xref = $ prefix . $ num ; $ already_used = DB :: table ( 'individuals' ) -> where ( 'i_id' , '=' , $ xref ) -> exists ( ) || DB :: table ( 'families' ) -> where ( 'f_id' , '=' , $ xref ) -> exists ( ) || DB :: table ( 'sources' ) -> where ( 's_id' , '=' , $ xref ) -> exists ( ) || DB :: table ( 'media' ) -> where ( 'm_id' , '=' , $ xref ) -> exists ( ) || DB :: table ( 'other' ) -> where ( 'o_id' , '=' , $ xref ) -> exists ( ) || DB :: table ( 'change' ) -> where ( 'xref' , '=' , $ xref ) -> exists ( ) ; } while ( $ already_used ) ; Site :: setPreference ( 'next_xref' , ( string ) $ num ) ; return $ xref ; }
Generate a new XREF unique across all family trees
7,085
public function significantIndividual ( UserInterface $ user ) : Individual { $ individual = null ; if ( $ this -> getUserPreference ( $ user , 'rootid' ) !== '' ) { $ individual = Individual :: getInstance ( $ this -> getUserPreference ( $ user , 'rootid' ) , $ this ) ; } if ( $ individual === null && $ this -> getUserPreference ( $ user , 'gedcomid' ) !== '' ) { $ individual = Individual :: getInstance ( $ this -> getUserPreference ( $ user , 'gedcomid' ) , $ this ) ; } if ( $ individual === null && $ this -> getPreference ( 'PEDIGREE_ROOT_ID' ) !== '' ) { $ individual = Individual :: getInstance ( $ this -> getPreference ( 'PEDIGREE_ROOT_ID' ) , $ this ) ; } if ( $ individual === null ) { $ xref = ( string ) DB :: table ( 'individuals' ) -> where ( 'i_file' , '=' , $ this -> id ( ) ) -> min ( 'i_id' ) ; $ individual = Individual :: getInstance ( $ xref , $ this ) ; } if ( $ individual === null ) { $ individual = new Individual ( 'I' , '0 @I@ INDI' , null , $ this ) ; } return $ individual ; }
What is the most significant individual in this tree .
7,086
public function setup ( ServerRequestInterface $ request ) : ResponseInterface { define ( 'WT_DATA_DIR' , 'data/' ) ; app ( ) -> instance ( ServerRequestInterface :: class , $ request ) ; app ( ) -> instance ( 'cache.array' , new Repository ( new ArrayStore ( ) ) ) ; $ data = $ this -> userData ( $ request ) ; $ step = ( int ) ( $ request -> getParsedBody ( ) [ 'step' ] ?? '1' ) ; $ lang = $ request -> getParsedBody ( ) [ 'lang' ] ?? $ data [ 'lang' ] ; $ data [ 'lang' ] = I18N :: init ( $ lang , null , true ) ; $ data [ 'cpu_limit' ] = $ this -> maxExecutionTime ( ) ; $ data [ 'locales' ] = $ this -> setupLocales ( ) ; $ data [ 'memory_limit' ] = $ this -> memoryLimit ( ) ; if ( $ step >= 4 ) { $ data [ 'errors' ] = $ this -> server_check_service -> serverErrors ( $ data [ 'dbtype' ] ) ; $ data [ 'warnings' ] = $ this -> server_check_service -> serverWarnings ( $ data [ 'dbtype' ] ) ; } else { $ data [ 'errors' ] = $ this -> server_check_service -> serverErrors ( ) ; $ data [ 'warnings' ] = $ this -> server_check_service -> serverWarnings ( ) ; } if ( ! $ this -> checkFolderIsWritable ( WT_DATA_DIR ) ) { $ data [ 'errors' ] -> push ( '<code>' . e ( realpath ( WT_DATA_DIR ) ) . '</code><br>' . I18N :: translate ( 'Oops! webtrees was unable to create files in this folder.' ) . ' ' . I18N :: translate ( 'This usually means that you need to change the folder permissions to 777.' ) ) ; } define ( 'WT_LOCALE' , $ data [ 'lang' ] ) ; switch ( $ step ) { default : case 1 : return $ this -> step1Language ( $ data ) ; case 2 : return $ this -> step2CheckServer ( $ data ) ; case 3 : return $ this -> step3DatabaseType ( $ data ) ; case 4 : return $ this -> step4DatabaseConnection ( $ data ) ; case 5 : return $ this -> step5Administrator ( $ data ) ; case 6 : return $ this -> step6Install ( $ data ) ; } }
Installation wizard - check user input and proceed to the next step .
7,087
private function setupLocales ( ) : array { return app ( ModuleService :: class ) -> setupLanguages ( ) -> map ( static function ( ModuleLanguageInterface $ module ) : LocaleInterface { return $ module -> locale ( ) ; } ) -> all ( ) ; }
Which languages are available during the installation .
7,088
private function checkFolderIsWritable ( string $ data_dir ) : bool { $ text1 = random_bytes ( 32 ) ; try { file_put_contents ( $ data_dir . 'test.txt' , $ text1 ) ; $ text2 = file_get_contents ( WT_DATA_DIR . 'test.txt' ) ; unlink ( WT_DATA_DIR . 'test.txt' ) ; } catch ( Exception $ ex ) { return false ; } return $ text1 === $ text2 ; }
Check we can write to the data folder .
7,089
public function chartBirth ( string $ color_from = null , string $ color_to = null ) : string { $ chart_color1 = ( string ) $ this -> theme -> parameter ( 'distribution-chart-no-values' ) ; $ chart_color2 = ( string ) $ this -> theme -> parameter ( 'distribution-chart-high-values' ) ; $ color_from = $ color_from ?? $ chart_color1 ; $ color_to = $ color_to ?? $ chart_color2 ; $ data = [ [ I18N :: translate ( 'Century' ) , I18N :: translate ( 'Total' ) ] , ] ; foreach ( $ this -> queryRecords ( ) as $ record ) { $ data [ ] = [ $ this -> century_service -> centuryName ( ( int ) $ record -> century ) , $ record -> total ] ; } $ colors = $ this -> color_service -> interpolateRgb ( $ color_from , $ color_to , count ( $ data ) - 1 ) ; return view ( 'statistics/other/charts/pie' , [ 'title' => I18N :: translate ( 'Births by century' ) , 'data' => $ data , 'colors' => $ colors , ] ) ; }
Create a chart of birth places .
7,090
public function mapTwoLetterToName ( string $ twoLetterCode ) : string { $ threeLetterCode = array_search ( $ twoLetterCode , $ this -> iso3166 ( ) , true ) ; $ threeLetterCode = $ threeLetterCode ? : '???' ; return $ this -> getAllCountries ( ) [ $ threeLetterCode ] ; }
Returns the translated country name based on the given two letter country code .
7,091
public function show ( ServerRequestInterface $ request , Tree $ tree ) : ResponseInterface { $ xref = $ request -> get ( 'xref' , '' ) ; $ record = GedcomRecord :: getInstance ( $ xref , $ tree ) ; Auth :: checkRecordAccess ( $ record ) ; if ( $ this -> hasCustomPage ( $ record ) ) { return redirect ( $ record -> url ( ) ) ; } return $ this -> viewResponse ( 'gedcom-record-page' , [ 'facts' => $ record -> facts ( ) , 'families' => $ record -> linkedFamilies ( $ record :: RECORD_TYPE ) , 'individuals' => $ record -> linkedIndividuals ( $ record :: RECORD_TYPE ) , 'meta_robots' => 'index,follow' , 'notes' => $ record -> linkedNotes ( $ record :: RECORD_TYPE ) , 'media_objects' => $ record -> linkedMedia ( $ record :: RECORD_TYPE ) , 'record' => $ record , 'sources' => $ record -> linkedSources ( $ record :: RECORD_TYPE ) , 'title' => $ record -> fullName ( ) , ] ) ; }
Show a gedcom record s page .
7,092
private function hasCustomPage ( GedcomRecord $ record ) : bool { return $ record instanceof Individual || $ record instanceof Family || $ record instanceof Source || $ record instanceof Repository || $ record instanceof Note || $ record instanceof Media ; }
Is there a better place to display this record?
7,093
public function canonicalTag ( string $ tag ) : string { $ tag = strtoupper ( $ tag ) ; $ tag = self :: TAG_NAMES [ $ tag ] ?? self :: TAG_SYNONYMS [ $ tag ] ?? $ tag ; return $ tag ; }
Convert a GEDCOM tag to a canonical form .
7,094
public function readSex ( string $ text ) : string { $ text = strtoupper ( $ text ) ; if ( $ text !== self :: SEX_MALE && $ text !== self :: SEX_FEMALE ) { $ text = self :: SEX_UNKNOWN ; } return $ text ; }
Some applications use non - standard values for unknown .
7,095
public function assetUrl ( string $ asset ) : string { $ file = $ this -> resourcesFolder ( ) . $ asset ; $ hash = filemtime ( $ file ) ; return route ( 'module' , [ 'module' => $ this -> name ( ) , 'action' => 'asset' , 'asset' => $ asset , 'hash' => $ hash , ] ) ; }
Create a URL for an asset .
7,096
public function render ( $ renderer ) { $ renderer -> setCurrentStyle ( 'footnotenum' ) ; echo '<a href="#footnote' , $ this -> num , '"><sup>' ; $ renderer -> write ( $ renderer -> entityRTL . $ this -> num ) ; echo "</sup></a>\n" ; }
HTML Footnotes number renderer
7,097
public function getFootnoteHeight ( $ html , float $ cellWidth = 0 ) : float { if ( $ html -> getCurrentStyle ( ) != $ this -> styleName ) { $ html -> setCurrentStyle ( $ this -> styleName ) ; } if ( $ cellWidth > 0 ) { $ this -> text = $ html -> textWrap ( $ this -> text , $ cellWidth ) ; } $ this -> text .= "\n\n" ; $ ct = substr_count ( $ this -> text , "\n" ) ; $ fsize = $ html -> getCurrentStyleHeight ( ) ; return ( $ fsize * $ ct ) * $ html -> cellHeightRatio ; }
Calculates the Footnotes height
7,098
public function interpolateRgb ( string $ startColor , string $ endColor , int $ steps ) : array { if ( ! $ steps ) { return [ ] ; } $ s = $ this -> hexToRgb ( $ startColor ) ; $ e = $ this -> hexToRgb ( $ endColor ) ; $ colors = [ ] ; $ factorR = ( $ e [ 0 ] - $ s [ 0 ] ) / $ steps ; $ factorG = ( $ e [ 1 ] - $ s [ 1 ] ) / $ steps ; $ factorB = ( $ e [ 2 ] - $ s [ 2 ] ) / $ steps ; for ( $ x = 1 ; $ x < $ steps ; ++ $ x ) { $ colors [ ] = $ this -> rgbToHex ( ( int ) round ( $ s [ 0 ] + ( $ factorR * $ x ) ) , ( int ) round ( $ s [ 1 ] + ( $ factorG * $ x ) ) , ( int ) round ( $ s [ 2 ] + ( $ factorB * $ x ) ) ) ; } $ colors [ ] = $ this -> rgbToHex ( $ e [ 0 ] , $ e [ 1 ] , $ e [ 2 ] ) ; return $ colors ; }
Interpolates the number of color steps between a given start and end color .
7,099
private function rgbToHex ( int $ r , int $ g , int $ b ) : string { return sprintf ( '#%02x%02x%02x' , $ r , $ g , $ b ) ; }
Converts the color values to the HTML hex representation .