idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
7,200
private function deleteFileOrFolder ( Filesystem $ filesystem , string $ path ) : bool { if ( $ filesystem -> has ( $ path ) ) { try { $ metadata = $ filesystem -> getMetadata ( $ path ) ; if ( $ metadata [ 'type' ] === 'dir' ) { $ filesystem -> deleteDir ( $ path ) ; } if ( $ metadata [ 'type' ] === 'file' ) { $ filesystem -> delete ( $ path ) ; } } catch ( Exception $ ex ) { return false ; } } return true ; }
Delete a file or folder if we can .
7,201
public function setWrapWidth ( float $ wrapwidth , float $ cellwidth ) : float { $ this -> wrapWidthCell = $ cellwidth ; if ( strpos ( $ this -> text , "\n" ) !== false ) { $ this -> wrapWidthRemaining = $ cellwidth ; } else { $ this -> wrapWidthRemaining = $ wrapwidth ; } return $ this -> wrapWidthRemaining ; }
Set the width for word - wrapping .
7,202
public function chartMedia ( array $ media , string $ color_from = null , string $ color_to = null ) : string { $ chart_color1 = ( string ) $ this -> theme -> parameter ( 'distribution-chart-no-values' ) ; $ chart_color2 = ( string ) $ this -> theme -> parameter ( 'distribution-chart-high-values' ) ; $ color_from = $ color_from ?? $ chart_color1 ; $ color_to = $ color_to ?? $ chart_color2 ; $ data = [ [ I18N :: translate ( 'Type' ) , I18N :: translate ( 'Total' ) ] , ] ; foreach ( $ media as $ type => $ count ) { $ data [ ] = [ GedcomTag :: getFileFormTypeValue ( $ type ) , $ count ] ; } $ colors = $ this -> color_service -> interpolateRgb ( $ color_from , $ color_to , count ( $ data ) - 1 ) ; return view ( 'statistics/other/charts/pie' , [ 'title' => null , 'data' => $ data , 'colors' => $ colors , ] ) ; }
Create a chart of media types .
7,203
public function setEmail ( $ email ) : User { if ( $ this -> email !== $ email ) { $ this -> email = $ email ; DB :: table ( 'user' ) -> where ( 'user_id' , '=' , $ this -> user_id ) -> update ( [ 'email' => $ email , ] ) ; } return $ this ; }
Set the email address of this user .
7,204
public function setRealName ( $ real_name ) : User { if ( $ this -> real_name !== $ real_name ) { $ this -> real_name = $ real_name ; DB :: table ( 'user' ) -> where ( 'user_id' , '=' , $ this -> user_id ) -> update ( [ 'real_name' => $ real_name , ] ) ; } return $ this ; }
Set the real name of this user .
7,205
public function setUserName ( $ user_name ) : self { if ( $ this -> user_name !== $ user_name ) { $ this -> user_name = $ user_name ; DB :: table ( 'user' ) -> where ( 'user_id' , '=' , $ this -> user_id ) -> update ( [ 'user_name' => $ user_name , ] ) ; } return $ this ; }
Set the login name for this user .
7,206
public function setPreference ( string $ setting_name , string $ setting_value ) : UserInterface { if ( $ this -> user_id !== 0 && $ this -> getPreference ( $ setting_name ) !== $ setting_value ) { DB :: table ( 'user_setting' ) -> updateOrInsert ( [ 'user_id' => $ this -> user_id , 'setting_name' => $ setting_name , ] , [ 'setting_value' => $ setting_value , ] ) ; $ this -> preferences [ $ setting_name ] = $ setting_value ; } app ( 'cache.array' ) -> forget ( 'user_setting' . $ this -> user_id ) ; return $ this ; }
Update a setting for the user .
7,207
public function setPassword ( string $ password ) : User { DB :: table ( 'user' ) -> where ( 'user_id' , '=' , $ this -> user_id ) -> update ( [ 'password' => password_hash ( $ password , PASSWORD_DEFAULT ) , ] ) ; return $ this ; }
Set the password of this user .
7,208
public function checkPassword ( string $ password ) : bool { $ password_hash = DB :: table ( 'user' ) -> where ( 'user_id' , '=' , $ this -> id ( ) ) -> value ( 'password' ) ; if ( $ password_hash !== null && password_verify ( $ password , $ password_hash ) ) { if ( password_needs_rehash ( $ password_hash , PASSWORD_DEFAULT ) ) { $ this -> setPassword ( $ password ) ; } return true ; } return false ; }
Validate a supplied password
7,209
public static function rowMapper ( ) : Closure { return static function ( stdClass $ row ) : User { return new static ( ( int ) $ row -> user_id , $ row -> user_name , $ row -> real_name , $ row -> email ) ; } ; }
A closure which will create an object from a database row .
7,210
public function mediaList ( ServerRequestInterface $ request , Tree $ tree ) : ResponseInterface { $ module = $ request -> get ( 'module' ) ; $ action = $ request -> get ( 'action' ) ; $ formats = GedcomTag :: getFileFormTypes ( ) ; $ action2 = $ request -> get ( 'action2' ) ; $ page = ( int ) $ request -> get ( 'page' ) ; $ max = ( int ) $ request -> get ( 'max' , 20 ) ; $ folder = $ request -> get ( 'folder' , '' ) ; $ filter = $ request -> get ( 'filter' , '' ) ; $ subdirs = $ request -> get ( 'subdirs' , '' ) ; $ form_type = $ request -> get ( 'form_type' , '' ) ; $ folders = $ this -> allFolders ( $ tree ) ; if ( $ action2 === '1' ) { $ media_objects = $ this -> allMedia ( $ tree , $ folder , $ subdirs === '1' ? 'include' : 'exclude' , 'title' , $ filter , $ form_type ) ; } else { $ media_objects = [ ] ; } $ count = count ( $ media_objects ) ; $ pages = ( int ) ( ( $ count + $ max - 1 ) / $ max ) ; $ page = max ( min ( $ page , $ pages ) , 1 ) ; $ media_objects = array_slice ( $ media_objects , ( $ page - 1 ) * $ max , $ max ) ; return $ this -> viewResponse ( 'media-list-page' , [ 'count' => $ count , 'filter' => $ filter , 'folder' => $ folder , 'folders' => $ folders , 'formats' => $ formats , 'form_type' => $ form_type , 'max' => $ max , 'media_objects' => $ media_objects , 'page' => $ page , 'pages' => $ pages , 'subdirs' => $ subdirs , 'title' => I18N :: translate ( 'Media' ) , 'module' => $ module , 'action' => $ action , ] ) ; }
Show a list of all media records .
7,211
public function noteList ( Tree $ tree ) : ResponseInterface { $ notes = $ this -> allNotes ( $ tree ) ; return $ this -> viewResponse ( 'note-list-page' , [ 'notes' => $ notes , 'title' => I18N :: translate ( 'Shared notes' ) , ] ) ; }
Show a list of all note records .
7,212
public function repositoryList ( Tree $ tree ) : ResponseInterface { $ repositories = $ this -> allRepositories ( $ tree ) ; return $ this -> viewResponse ( 'repository-list-page' , [ 'repositories' => $ repositories , 'title' => I18N :: translate ( 'Repositories' ) , ] ) ; }
Show a list of all repository records .
7,213
public function sourceList ( Tree $ tree ) : ResponseInterface { $ sources = $ this -> allSources ( $ tree ) ; return $ this -> viewResponse ( 'source-list-page' , [ 'sources' => $ sources , 'title' => I18N :: translate ( 'Sources' ) , ] ) ; }
Show a list of all source records .
7,214
private function allFolders ( Tree $ tree ) : array { $ folders = DB :: table ( 'media_file' ) -> where ( 'm_file' , '=' , $ tree -> id ( ) ) -> where ( 'multimedia_file_refn' , 'NOT LIKE' , 'http:%' ) -> where ( 'multimedia_file_refn' , 'NOT LIKE' , 'https:%' ) -> where ( 'multimedia_file_refn' , 'LIKE' , '%/%' ) -> pluck ( 'multimedia_file_refn' , 'multimedia_file_refn' ) -> map ( static function ( string $ path ) : string { return dirname ( $ path ) ; } ) -> unique ( ) -> sort ( ) -> all ( ) ; array_unshift ( $ folders , '' ) ; return array_combine ( $ folders , $ folders ) ; }
Generate a list of all the folders in a current tree .
7,215
private function allMedia ( Tree $ tree , string $ folder , string $ subfolders , string $ sort , string $ filter , string $ form_type ) : array { $ query = DB :: table ( 'media' ) -> join ( 'media_file' , static function ( JoinClause $ join ) : void { $ join -> on ( 'media_file.m_file' , '=' , 'media.m_file' ) -> on ( 'media_file.m_id' , '=' , 'media.m_id' ) ; } ) -> where ( 'media.m_file' , '=' , $ tree -> id ( ) ) -> distinct ( ) ; $ query -> where ( static function ( Builder $ query ) use ( $ folder , $ subfolders ) : void { $ query -> where ( 'multimedia_file_refn' , 'LIKE' , 'http:%' ) -> orWhere ( 'multimedia_file_refn' , 'LIKE' , 'https:%' ) -> orWhere ( static function ( Builder $ query ) use ( $ folder , $ subfolders ) : void { $ query -> where ( 'multimedia_file_refn' , 'LIKE' , $ folder . '%' ) ; if ( $ subfolders === 'exclude' ) { $ query -> where ( 'multimedia_file_refn' , 'NOT LIKE' , $ folder . '/%/%' ) ; } } ) ; } ) ; if ( $ filter !== '' ) { $ query -> where ( static function ( Builder $ query ) use ( $ filter ) : void { $ query -> whereContains ( 'multimedia_file_refn' , $ filter ) -> whereContains ( 'descriptive_title' , $ filter , 'or' ) ; } ) ; } if ( $ form_type ) { $ query -> where ( 'source_media_type' , '=' , $ form_type ) ; } switch ( $ sort ) { case 'file' : $ query -> orderBy ( 'multimedia_file_refn' ) ; break ; case 'title' : $ query -> orderBy ( 'descriptive_title' ) ; break ; } return $ query -> get ( ) -> map ( Media :: rowMapper ( ) ) -> filter ( GedcomRecord :: accessFilter ( ) ) -> all ( ) ; }
Generate a list of all the media objects matching the criteria in a current tree .
7,216
private function allNotes ( Tree $ tree ) : Collection { return DB :: table ( 'other' ) -> where ( 'o_file' , '=' , $ tree -> id ( ) ) -> where ( 'o_type' , '=' , 'NOTE' ) -> get ( ) -> map ( Note :: rowMapper ( ) ) -> filter ( GedcomRecord :: accessFilter ( ) ) ; }
Find all the note records in a tree .
7,217
private function allRepositories ( Tree $ tree ) : Collection { return DB :: table ( 'other' ) -> where ( 'o_file' , '=' , $ tree -> id ( ) ) -> where ( 'o_type' , '=' , 'REPO' ) -> get ( ) -> map ( Repository :: rowMapper ( ) ) -> filter ( GedcomRecord :: accessFilter ( ) ) ; }
Find all the repository record in a tree .
7,218
private function allSources ( Tree $ tree ) : Collection { return DB :: table ( 'sources' ) -> where ( 's_file' , '=' , $ tree -> id ( ) ) -> get ( ) -> map ( Source :: rowMapper ( ) ) -> filter ( GedcomRecord :: accessFilter ( ) ) ; }
Find all the source records in a tree .
7,219
private function gedcomHead ( ) : array { $ title = '' ; $ version = '' ; $ source = '' ; $ head = GedcomRecord :: getInstance ( 'HEAD' , $ this -> tree ) ; if ( $ head instanceof GedcomRecord ) { $ sour = $ head -> facts ( [ 'SOUR' ] ) -> first ( ) ; if ( $ sour instanceof Fact ) { $ source = $ sour -> value ( ) ; $ title = $ sour -> attribute ( 'NAME' ) ; $ version = $ sour -> attribute ( 'VERS' ) ; } } return [ $ title , $ version , $ source , ] ; }
Get information from the GEDCOM s HEAD record .
7,220
private function changesQuery ( ServerRequestInterface $ request ) : Builder { $ from = $ request -> getQueryParams ( ) [ 'from' ] ?? '' ; $ to = $ request -> getQueryParams ( ) [ 'to' ] ?? '' ; $ type = $ request -> getQueryParams ( ) [ 'type' ] ?? '' ; $ oldged = $ request -> getQueryParams ( ) [ 'oldged' ] ?? '' ; $ newged = $ request -> getQueryParams ( ) [ 'newged' ] ?? '' ; $ xref = $ request -> getQueryParams ( ) [ 'xref' ] ?? '' ; $ username = $ request -> getQueryParams ( ) [ 'username' ] ?? '' ; $ ged = $ request -> getQueryParams ( ) [ 'ged' ] ?? '' ; $ search = $ request -> getQueryParams ( ) [ 'search' ] ?? [ ] ; $ search = $ search [ 'value' ] ?? '' ; $ query = DB :: table ( 'change' ) -> leftJoin ( 'user' , 'user.user_id' , '=' , 'change.user_id' ) -> join ( 'gedcom' , 'gedcom.gedcom_id' , '=' , 'change.gedcom_id' ) -> select ( [ 'change.*' , DB :: raw ( "COALESCE(user_name, '<none>') AS user_name" ) , 'gedcom_name' ] ) ; if ( $ search !== '' ) { $ query -> where ( static function ( Builder $ query ) use ( $ search ) : void { $ query -> whereContains ( 'old_gedcom' , $ search ) -> whereContains ( 'new_gedcom' , $ search , 'or' ) ; } ) ; } if ( $ from !== '' ) { $ query -> where ( 'change_time' , '>=' , $ from ) ; } if ( $ to !== '' ) { $ query -> where ( 'change_time' , '<' , Carbon :: make ( $ to ) -> addDay ( ) ) ; } if ( $ type !== '' ) { $ query -> where ( 'status' , '=' , $ type ) ; } if ( $ oldged !== '' ) { $ query -> whereContains ( 'old_gedcom' , $ oldged ) ; } if ( $ newged !== '' ) { $ query -> whereContains ( 'new_gedcom' , $ oldged ) ; } if ( $ xref !== '' ) { $ query -> where ( 'xref' , '=' , $ xref ) ; } if ( $ username !== '' ) { $ query -> whereContains ( 'user_name' , $ username ) ; } if ( $ ged !== '' ) { $ query -> whereContains ( 'gedcom_name' , $ ged ) ; } return $ query ; }
Generate a query for filtering the changes log .
7,221
public static function getChar ( string $ text , int $ offset ) : array { if ( $ text == '' ) { return [ 'letter' => '' , 'length' => 0 , ] ; } $ char = substr ( $ text , $ offset , 1 ) ; $ length = 1 ; if ( ( ord ( $ char ) & 0xE0 ) == 0xC0 ) { $ length = 2 ; } if ( ( ord ( $ char ) & 0xF0 ) == 0xE0 ) { $ length = 3 ; } if ( ( ord ( $ char ) & 0xF8 ) == 0xF0 ) { $ length = 4 ; } $ letter = substr ( $ text , $ offset , $ length ) ; return [ 'letter' => $ letter , 'length' => $ length , ] ; }
Get the next character from an input string
7,222
public static function beginCurrentSpan ( & $ result ) : void { if ( self :: $ currentState === 'LTR' ) { $ result .= self :: START_LTR ; } if ( self :: $ currentState === 'RTL' ) { $ result .= self :: START_RTL ; } self :: $ posSpanStart = strlen ( $ result ) ; }
Begin current span
7,223
private function applyFilter ( array $ facts , string $ filterof , string $ filtersx ) : array { $ filtered = [ ] ; $ hundred_years = Carbon :: now ( ) -> subYears ( 100 ) -> julianDay ( ) ; foreach ( $ facts as $ fact ) { $ record = $ fact -> record ( ) ; if ( $ filtersx ) { if ( $ record instanceof Individual && $ filtersx !== $ record -> sex ( ) ) { continue ; } if ( $ record instanceof Family ) { continue ; } } if ( $ filterof === 'living' ) { if ( $ record instanceof Individual && $ record -> isDead ( ) ) { continue ; } if ( $ record instanceof Family ) { $ husb = $ record -> husband ( ) ; $ wife = $ record -> wife ( ) ; if ( $ husb && $ husb -> isDead ( ) || $ wife && $ wife -> isDead ( ) ) { continue ; } } } if ( $ filterof === 'recent' && $ fact -> date ( ) -> maximumJulianDay ( ) < $ hundred_years ) { continue ; } $ filtered [ ] = $ fact ; } return $ filtered ; }
Filter a list of anniversaries
7,224
private function calendarListText ( array $ list , string $ tag1 , string $ tag2 , Tree $ tree ) : string { $ html = '' ; foreach ( $ list as $ id => $ facts ) { $ tmp = GedcomRecord :: getInstance ( $ id , $ tree ) ; $ html .= $ tag1 . '<a href="' . e ( $ tmp -> url ( ) ) . '">' . $ tmp -> fullName ( ) . '</a> ' ; $ html .= '<div class="indent">' . $ facts . '</div>' . $ tag2 ; } return $ html ; }
Format a list of facts for display
7,225
public function icon ( Fact $ fact ) : string { $ asset = 'public/css/' . $ this -> name ( ) . '/images/facts/' . $ fact -> getTag ( ) . '.png' ; if ( file_exists ( Webtrees :: ROOT_DIR . 'public' . $ asset ) ) { return '<img src="' . e ( asset ( $ asset ) ) . '" title="' . GedcomTag :: getLabel ( $ fact -> getTag ( ) ) . '">' ; } $ asset = 'public/css/' . $ this -> name ( ) . '/images/facts/NULL.png' ; if ( file_exists ( Webtrees :: ROOT_DIR . 'public' . $ asset ) ) { return '<img src="' . e ( asset ( $ asset ) ) . '">' ; } return '' ; }
Display an icon for this fact .
7,226
public function individualBoxFacts ( Individual $ individual ) : string { $ html = '' ; $ opt_tags = preg_split ( '/\W/' , $ individual -> tree ( ) -> getPreference ( 'CHART_BOX_TAGS' ) , 0 , PREG_SPLIT_NO_EMPTY ) ; foreach ( Gedcom :: BIRTH_EVENTS as $ birttag ) { if ( ! in_array ( $ birttag , $ opt_tags , true ) ) { $ event = $ individual -> facts ( [ $ birttag ] ) -> first ( ) ; if ( $ event instanceof Fact ) { $ html .= $ event -> summary ( ) ; break ; } } } foreach ( $ opt_tags as $ key => $ tag ) { if ( ! in_array ( $ tag , Gedcom :: DEATH_EVENTS , true ) ) { $ event = $ individual -> facts ( [ $ tag ] ) -> first ( ) ; if ( $ event instanceof Fact ) { $ html .= $ event -> summary ( ) ; unset ( $ opt_tags [ $ key ] ) ; } } } foreach ( Gedcom :: DEATH_EVENTS as $ deattag ) { $ event = $ individual -> facts ( [ $ deattag ] ) -> first ( ) ; if ( $ event instanceof Fact ) { $ html .= $ event -> summary ( ) ; if ( in_array ( $ deattag , $ opt_tags , true ) ) { unset ( $ opt_tags [ array_search ( $ deattag , $ opt_tags , true ) ] ) ; } break ; } } foreach ( $ opt_tags as $ tag ) { $ event = $ individual -> facts ( [ $ tag ] ) -> first ( ) ; if ( $ event instanceof Fact ) { $ html .= $ event -> summary ( ) ; } } return $ html ; }
Generate the facts for display in charts .
7,227
public function individualBoxMenu ( Individual $ individual ) : array { $ menus = array_merge ( $ this -> individualBoxMenuCharts ( $ individual ) , $ this -> individualBoxMenuFamilyLinks ( $ individual ) ) ; return $ menus ; }
Links to show in chart boxes ;
7,228
public function individualBoxMenuCharts ( Individual $ individual ) : array { $ menus = [ ] ; foreach ( app ( ModuleService :: class ) -> findByComponent ( ModuleChartInterface :: class , $ individual -> tree ( ) , Auth :: user ( ) ) as $ chart ) { $ menu = $ chart -> chartBoxMenu ( $ individual ) ; if ( $ menu ) { $ menus [ ] = $ menu ; } } usort ( $ menus , static function ( Menu $ x , Menu $ y ) { return I18N :: strcasecmp ( $ x -> getLabel ( ) , $ y -> getLabel ( ) ) ; } ) ; return $ menus ; }
Chart links to show in chart boxes ;
7,229
public function individualBoxMenuFamilyLinks ( Individual $ individual ) : array { $ menus = [ ] ; foreach ( $ individual -> spouseFamilies ( ) as $ family ) { $ menus [ ] = new Menu ( '<strong>' . I18N :: translate ( 'Family with spouse' ) . '</strong>' , $ family -> url ( ) ) ; $ spouse = $ family -> spouse ( $ individual ) ; if ( $ spouse && $ spouse -> canShowName ( ) ) { $ menus [ ] = new Menu ( $ spouse -> fullName ( ) , $ spouse -> url ( ) ) ; } foreach ( $ family -> children ( ) as $ child ) { if ( $ child -> canShowName ( ) ) { $ menus [ ] = new Menu ( $ child -> fullName ( ) , $ child -> url ( ) ) ; } } } return $ menus ; }
Family links to show in chart boxes .
7,230
public function menuControlPanel ( Tree $ tree ) : ? Menu { if ( Auth :: isAdmin ( ) ) { return new Menu ( I18N :: translate ( 'Control panel' ) , route ( 'admin-control-panel' ) , 'menu-admin' ) ; } if ( Auth :: isManager ( $ tree ) ) { return new Menu ( I18N :: translate ( 'Control panel' ) , route ( 'admin-control-panel-manager' ) , 'menu-admin' ) ; } return null ; }
Generate a menu item for the control panel .
7,231
public function menuLanguages ( ) : ? Menu { $ menu = new Menu ( I18N :: translate ( 'Language' ) , '#' , 'menu-language' ) ; foreach ( I18N :: activeLocales ( ) as $ locale ) { $ language_tag = $ locale -> languageTag ( ) ; $ class = 'menu-language-' . $ language_tag . ( WT_LOCALE === $ language_tag ? ' active' : '' ) ; $ menu -> addSubmenu ( new Menu ( $ locale -> endonym ( ) , '#' , $ class , [ 'onclick' => 'return false;' , 'data-language' => $ language_tag , ] ) ) ; } if ( count ( $ menu -> getSubmenus ( ) ) > 1 ) { return $ menu ; } return null ; }
A menu to show a list of available languages .
7,232
public function menuMyPage ( Tree $ tree ) : Menu { return new Menu ( I18N :: translate ( 'My page' ) , route ( 'user-page' , [ 'ged' => $ tree -> name ( ) ] ) , 'menu-mypage' ) ; }
A link to the user s personal home page .
7,233
public function menuMyPages ( ? Tree $ tree ) : ? Menu { if ( $ tree instanceof Tree && Auth :: id ( ) ) { return new Menu ( I18N :: translate ( 'My pages' ) , '#' , 'menu-mymenu' , [ ] , array_filter ( [ $ this -> menuMyPage ( $ tree ) , $ this -> menuMyIndividualRecord ( $ tree ) , $ this -> menuMyPedigree ( $ tree ) , $ this -> menuMyAccount ( ) , $ this -> menuControlPanel ( $ tree ) , $ this -> menuChangeBlocks ( $ tree ) , ] ) ) ; } return null ; }
A menu for the user s personal pages .
7,234
public function menuMyPedigree ( Tree $ tree ) : ? Menu { $ gedcomid = $ tree -> getUserPreference ( Auth :: user ( ) , 'gedcomid' ) ; $ pedigree_chart = app ( ModuleService :: class ) -> findByComponent ( ModuleChartInterface :: class , $ tree , Auth :: user ( ) ) -> filter ( static function ( ModuleInterface $ module ) : bool { return $ module instanceof PedigreeChartModule ; } ) ; if ( $ gedcomid !== '' && $ pedigree_chart instanceof PedigreeChartModule ) { return new Menu ( I18N :: translate ( 'My pedigree' ) , route ( 'pedigree' , [ 'xref' => $ gedcomid , 'ged' => $ tree -> name ( ) , ] ) , 'menu-mypedigree' ) ; } return null ; }
A link to the user s individual record .
7,235
public function menuPendingChanges ( ? Tree $ tree ) : ? Menu { if ( $ tree instanceof Tree && $ tree -> hasPendingEdit ( ) && Auth :: isModerator ( $ tree ) ) { $ url = route ( 'show-pending' , [ 'ged' => $ tree -> name ( ) , 'url' => app ( ServerRequestInterface :: class ) -> getUri ( ) , ] ) ; return new Menu ( I18N :: translate ( 'Pending changes' ) , $ url , 'menu-pending' ) ; } return null ; }
Create a pending changes menu .
7,236
public function menuThemes ( ) : ? Menu { $ themes = app ( ModuleService :: class ) -> findByInterface ( ModuleThemeInterface :: class , false , true ) ; $ current_theme = app ( ModuleThemeInterface :: class ) ; if ( $ themes -> count ( ) > 1 ) { $ submenus = $ themes -> map ( static function ( ModuleThemeInterface $ theme ) use ( $ current_theme ) : Menu { $ active = $ theme -> name ( ) === $ current_theme -> name ( ) ; $ class = 'menu-theme-' . $ theme -> name ( ) . ( $ active ? ' active' : '' ) ; return new Menu ( $ theme -> title ( ) , '#' , $ class , [ 'onclick' => 'return false;' , 'data-theme' => $ theme -> name ( ) , ] ) ; } ) ; return new Menu ( I18N :: translate ( 'Theme' ) , '#' , 'menu-theme' , [ ] , $ submenus -> all ( ) ) ; } return null ; }
Themes menu .
7,237
public function genealogyMenuContent ( array $ menus ) : string { return implode ( '' , array_map ( static function ( Menu $ menu ) : string { return $ menu -> bootstrap4 ( ) ; } , $ menus ) ) ; }
Create the genealogy menu .
7,238
public function userMenu ( ? Tree $ tree ) : array { return array_filter ( [ $ this -> menuPendingChanges ( $ tree ) , $ this -> menuMyPages ( $ tree ) , $ this -> menuThemes ( ) , $ this -> menuLanguages ( ) , $ this -> menuLogin ( ) , $ this -> menuLogout ( ) , ] ) ; }
Generate a list of items for the user menu .
7,239
public static function formatText ( string $ text , Tree $ tree ) : string { switch ( $ tree -> getPreference ( 'FORMAT_TEXT' ) ) { case 'markdown' : return '<div class="markdown" dir="auto">' . self :: markdown ( $ text , $ tree ) . '</div>' ; default : return '<div class="markdown" style="white-space: pre-wrap;" dir="auto">' . self :: expandUrls ( $ text , $ tree ) . '</div>' ; } }
Format block - level text such as notes or transcripts etc .
7,240
public static function expandUrls ( string $ text , Tree $ tree ) : string { $ text = preg_replace ( '/' . addcslashes ( self :: URL_REGEX , '/' ) . '/' , '<$0>' , $ text ) ; $ environment = new Environment ( ) ; $ environment -> mergeConfig ( [ 'renderer' => [ 'block_separator' => "\n" , 'inner_separator' => "\n" , 'soft_break' => "\n" , ] , 'html_input' => Environment :: HTML_INPUT_ESCAPE , 'allow_unsafe_links' => true , ] ) ; $ environment -> addBlockRenderer ( Document :: class , new DocumentRenderer ( ) ) -> addBlockRenderer ( Paragraph :: class , new ParagraphRenderer ( ) ) -> addInlineRenderer ( Text :: class , new TextRenderer ( ) ) -> addInlineRenderer ( Link :: class , new LinkRenderer ( ) ) -> addInlineParser ( new AutolinkParser ( ) ) ; $ environment -> addExtension ( new CensusTableExtension ( ) ) ; $ environment -> addExtension ( new XrefExtension ( $ tree ) ) ; $ converter = new Converter ( new DocParser ( $ environment ) , new HtmlRenderer ( $ environment ) ) ; try { return $ converter -> convertToHtml ( $ text ) ; } catch ( Throwable $ ex ) { return $ text ; } }
Format a block of text expanding URLs and XREFs .
7,241
public static function markdown ( string $ text , Tree $ tree ) : string { $ environment = Environment :: createCommonMarkEnvironment ( ) ; $ environment -> mergeConfig ( [ 'html_input' => 'escape' ] ) ; $ environment -> addExtension ( new TableExtension ( ) ) ; $ environment -> addExtension ( new CensusTableExtension ( ) ) ; $ environment -> addExtension ( new XrefExtension ( $ tree ) ) ; $ converter = new Converter ( new DocParser ( $ environment ) , new HtmlRenderer ( $ environment ) ) ; try { return $ converter -> convertToHtml ( $ text ) ; } catch ( Throwable $ ex ) { return $ text ; } }
Format a block of text using Markdown .
7,242
public function addText ( string $ t ) { $ t = trim ( $ t , "\r\n\t" ) ; $ t = str_replace ( [ '<br>' , '&nbsp;' , ] , [ "\n" , ' ' , ] , $ t ) ; $ t = strip_tags ( $ t ) ; $ t = htmlspecialchars_decode ( $ t ) ; $ this -> text .= $ t ; }
Add text .
7,243
public function findByInterface ( string $ interface , $ include_disabled = false , $ sort = false ) : Collection { $ modules = $ this -> all ( $ include_disabled ) -> filter ( $ this -> interfaceFilter ( $ interface ) ) ; switch ( $ interface ) { case ModuleFooterInterface :: class : return $ modules -> sort ( $ this -> footerSorter ( ) ) ; case ModuleMenuInterface :: class : return $ modules -> sort ( $ this -> menuSorter ( ) ) ; case ModuleSidebarInterface :: class : return $ modules -> sort ( $ this -> sidebarSorter ( ) ) ; case ModuleTabInterface :: class : return $ modules -> sort ( $ this -> tabSorter ( ) ) ; default : if ( $ sort ) { return $ modules -> sort ( $ this -> moduleSorter ( ) ) ; } return $ modules ; } }
All modules which provide a specific function .
7,244
public function all ( bool $ include_disabled = false ) : Collection { return app ( 'cache.array' ) -> rememberForever ( 'all_modules' , function ( ) : Collection { $ module_info = DB :: table ( 'module' ) -> get ( ) -> mapWithKeys ( static function ( stdClass $ row ) : array { return [ $ row -> module_name => $ row ] ; } ) ; return $ this -> coreModules ( ) -> merge ( $ this -> customModules ( ) ) -> map ( static function ( ModuleInterface $ module ) use ( $ module_info ) : ModuleInterface { $ info = $ module_info -> get ( $ module -> name ( ) ) ; if ( $ info instanceof stdClass ) { $ module -> setEnabled ( $ info -> status === 'enabled' ) ; if ( $ module instanceof ModuleFooterInterface && $ info -> footer_order !== null ) { $ module -> setFooterOrder ( ( int ) $ info -> footer_order ) ; } if ( $ module instanceof ModuleMenuInterface && $ info -> menu_order !== null ) { $ module -> setMenuOrder ( ( int ) $ info -> menu_order ) ; } if ( $ module instanceof ModuleSidebarInterface && $ info -> sidebar_order !== null ) { $ module -> setSidebarOrder ( ( int ) $ info -> sidebar_order ) ; } if ( $ module instanceof ModuleTabInterface && $ info -> tab_order !== null ) { $ module -> setTabOrder ( ( int ) $ info -> tab_order ) ; } } else { $ module -> setEnabled ( $ module -> isEnabledByDefault ( ) ) ; DB :: table ( 'module' ) -> insert ( [ 'module_name' => $ module -> name ( ) , 'status' => $ module -> isEnabled ( ) ? 'enabled' : 'disabled' , ] ) ; } return $ module ; } ) ; } ) -> filter ( $ this -> enabledFilter ( $ include_disabled ) ) ; }
All modules .
7,245
private function coreModules ( ) : Collection { return Collection :: make ( self :: CORE_MODULES ) -> map ( static function ( string $ class , string $ name ) : ModuleInterface { $ module = app ( $ class ) ; $ module -> setName ( $ name ) ; return $ module ; } ) ; }
All core modules in the system .
7,246
public function setupLanguages ( ) : Collection { return $ this -> coreModules ( ) -> filter ( static function ( ModuleInterface $ module ) { return $ module instanceof ModuleLanguageInterface && $ module -> isEnabledByDefault ( ) ; } ) -> sort ( static function ( ModuleLanguageInterface $ x , ModuleLanguageInterface $ y ) { return $ x -> locale ( ) -> endonymSortable ( ) <=> $ y -> locale ( ) -> endonymSortable ( ) ; } ) ; }
During setup we ll need access to some languages .
7,247
private function footerSorter ( ) : Closure { return static function ( ModuleFooterInterface $ x , ModuleFooterInterface $ y ) : int { return $ x -> getFooterOrder ( ) <=> $ y -> getFooterOrder ( ) ; } ; }
A function to sort footers
7,248
private function moduleSorter ( ) : Closure { return static function ( ModuleInterface $ x , ModuleInterface $ y ) : int { $ title1 = $ x instanceof ModuleLanguageInterface ? $ x -> locale ( ) -> endonymSortable ( ) : $ x -> title ( ) ; $ title2 = $ y instanceof ModuleLanguageInterface ? $ y -> locale ( ) -> endonymSortable ( ) : $ y -> title ( ) ; return I18N :: strcasecmp ( $ title1 , $ title2 ) ; } ; }
A function to sort modules by name .
7,249
public function findByName ( string $ module_name , bool $ include_disabled = false ) : ? ModuleInterface { return $ this -> all ( $ include_disabled ) -> first ( static function ( ModuleInterface $ module ) use ( $ module_name ) : bool { return $ module -> name ( ) === $ module_name ; } ) ; }
Find a specified module if it is currently active .
7,250
public function otherModules ( bool $ include_disabled = false ) : Collection { return $ this -> findByInterface ( ModuleInterface :: class , $ include_disabled , true ) -> filter ( static function ( ModuleInterface $ module ) : bool { foreach ( self :: COMPONENTS as $ interface ) { if ( $ module instanceof $ interface ) { return false ; } } return true ; } ) ; }
Configuration settings are available through the various module component pages . For modules that do not provide a component we need to list them separately .
7,251
public function deletedModules ( ) : Collection { $ database_modules = DB :: table ( 'module' ) -> pluck ( 'module_name' ) ; $ disk_modules = $ this -> all ( true ) -> map ( static function ( ModuleInterface $ module ) : string { return $ module -> name ( ) ; } ) ; return $ database_modules -> diff ( $ disk_modules ) ; }
Generate a list of module names which exist in the database but not on disk .
7,252
public static function regenerate ( bool $ destroy = false ) : void { if ( $ destroy ) { self :: clear ( ) ; } if ( session_status ( ) === PHP_SESSION_ACTIVE ) { session_regenerate_id ( $ destroy ) ; } }
After any change in authentication level we should use a new session ID .
7,253
public static function getCsrfToken ( ) : string { if ( ! self :: has ( 'CSRF_TOKEN' ) ) { self :: put ( 'CSRF_TOKEN' , Str :: random ( 32 ) ) ; } return self :: get ( 'CSRF_TOKEN' ) ; }
Cross - Site Request Forgery tokens - ensure that the user is submitting a form that was generated by the current session .
7,254
private function checkLinkMessage ( Tree $ tree , $ type1 , $ xref1 , $ type2 , $ xref2 ) : string { return I18N :: translate ( '%1$s %2$s has a %3$s link to %4$s.' , $ this -> formatType ( $ type1 ) , $ this -> checkLink ( $ tree , $ xref1 ) , $ this -> formatType ( $ type2 ) , $ this -> checkLink ( $ tree , $ xref2 ) ) ; }
Create a message linking one record to another .
7,255
private function checkLink ( Tree $ tree , string $ xref ) : string { return '<b><a href="' . e ( route ( 'record' , [ 'xref' => $ xref , 'ged' => $ tree -> name ( ) , ] ) ) . '">' . $ xref . '</a></b>' ; }
Format a link to a record .
7,256
private function countCommonXrefs ( Tree $ tree1 , Tree $ tree2 ) : int { $ subquery1 = DB :: table ( 'individuals' ) -> where ( 'i_file' , '=' , $ tree1 -> id ( ) ) -> select ( [ 'i_id AS xref' ] ) -> union ( DB :: table ( 'families' ) -> where ( 'f_file' , '=' , $ tree1 -> id ( ) ) -> select ( [ 'f_id AS xref' ] ) ) -> union ( DB :: table ( 'sources' ) -> where ( 's_file' , '=' , $ tree1 -> id ( ) ) -> select ( [ 's_id AS xref' ] ) ) -> union ( DB :: table ( 'media' ) -> where ( 'm_file' , '=' , $ tree1 -> id ( ) ) -> select ( [ 'm_id AS xref' ] ) ) -> union ( DB :: table ( 'other' ) -> where ( 'o_file' , '=' , $ tree1 -> id ( ) ) -> whereNotIn ( 'o_type' , [ 'HEAD' , 'TRLR' ] ) -> select ( [ 'o_id AS xref' ] ) ) ; $ subquery2 = DB :: table ( 'change' ) -> where ( 'gedcom_id' , '=' , $ tree2 -> id ( ) ) -> select ( [ 'xref AS other_xref' ] ) -> union ( DB :: table ( 'individuals' ) -> where ( 'i_file' , '=' , $ tree2 -> id ( ) ) -> select ( [ 'i_id AS xref' ] ) ) -> union ( DB :: table ( 'families' ) -> where ( 'f_file' , '=' , $ tree2 -> id ( ) ) -> select ( [ 'f_id AS xref' ] ) ) -> union ( DB :: table ( 'sources' ) -> where ( 's_file' , '=' , $ tree2 -> id ( ) ) -> select ( [ 's_id AS xref' ] ) ) -> union ( DB :: table ( 'media' ) -> where ( 'm_file' , '=' , $ tree2 -> id ( ) ) -> select ( [ 'm_id AS xref' ] ) ) -> union ( DB :: table ( 'other' ) -> where ( 'o_file' , '=' , $ tree2 -> id ( ) ) -> whereNotIn ( 'o_type' , [ 'HEAD' , 'TRLR' ] ) -> select ( [ 'o_id AS xref' ] ) ) ; return DB :: table ( DB :: raw ( '(' . $ subquery1 -> toSql ( ) . ') AS sub1' ) ) -> mergeBindings ( $ subquery1 ) -> joinSub ( $ subquery2 , 'sub2' , 'other_xref' , '=' , 'xref' ) -> count ( ) ; }
Count of XREFs used by two trees at the same time .
7,257
private function duplicateXrefs ( Tree $ tree ) : array { $ subquery1 = DB :: table ( 'individuals' ) -> where ( 'i_file' , '=' , $ tree -> id ( ) ) -> select ( [ 'i_id AS xref' , DB :: raw ( "'INDI' AS type" ) ] ) -> union ( DB :: table ( 'families' ) -> where ( 'f_file' , '=' , $ tree -> id ( ) ) -> select ( [ 'f_id AS xref' , DB :: raw ( "'FAM' AS type" ) ] ) ) -> union ( DB :: table ( 'sources' ) -> where ( 's_file' , '=' , $ tree -> id ( ) ) -> select ( [ 's_id AS xref' , DB :: raw ( "'SOUR' AS type" ) ] ) ) -> union ( DB :: table ( 'media' ) -> where ( 'm_file' , '=' , $ tree -> id ( ) ) -> select ( [ 'm_id AS xref' , DB :: raw ( "'OBJE' AS type" ) ] ) ) -> union ( DB :: table ( 'other' ) -> where ( 'o_file' , '=' , $ tree -> id ( ) ) -> whereNotIn ( 'o_type' , [ 'HEAD' , 'TRLR' ] ) -> select ( [ 'o_id AS xref' , 'o_type AS type' ] ) ) ; $ subquery2 = DB :: table ( 'change' ) -> where ( 'gedcom_id' , '<>' , $ tree -> id ( ) ) -> select ( [ 'xref AS other_xref' ] ) -> union ( DB :: table ( 'individuals' ) -> where ( 'i_file' , '<>' , $ tree -> id ( ) ) -> select ( [ 'i_id AS xref' ] ) ) -> union ( DB :: table ( 'families' ) -> where ( 'f_file' , '<>' , $ tree -> id ( ) ) -> select ( [ 'f_id AS xref' ] ) ) -> union ( DB :: table ( 'sources' ) -> where ( 's_file' , '<>' , $ tree -> id ( ) ) -> select ( [ 's_id AS xref' ] ) ) -> union ( DB :: table ( 'media' ) -> where ( 'm_file' , '<>' , $ tree -> id ( ) ) -> select ( [ 'm_id AS xref' ] ) ) -> union ( DB :: table ( 'other' ) -> where ( 'o_file' , '<>' , $ tree -> id ( ) ) -> whereNotIn ( 'o_type' , [ 'HEAD' , 'TRLR' ] ) -> select ( [ 'o_id AS xref' ] ) ) ; return DB :: table ( DB :: raw ( '(' . $ subquery1 -> toSql ( ) . ') AS sub1' ) ) -> mergeBindings ( $ subquery1 ) -> joinSub ( $ subquery2 , 'sub2' , 'other_xref' , '=' , 'xref' ) -> pluck ( 'type' , 'xref' ) -> all ( ) ; }
Every XREF used by this tree and also used by some other tree
7,258
private function gedcomFiles ( string $ folder ) : array { $ d = opendir ( $ folder ) ; $ files = [ ] ; while ( ( $ f = readdir ( $ d ) ) !== false ) { if ( ! is_dir ( WT_DATA_DIR . $ f ) && is_readable ( WT_DATA_DIR . $ f ) ) { $ fp = fopen ( WT_DATA_DIR . $ f , 'rb' ) ; $ header = fread ( $ fp , 64 ) ; fclose ( $ fp ) ; if ( preg_match ( '/^(' . Gedcom :: UTF8_BOM . ')?0 *HEAD/' , $ header ) ) { $ files [ ] = $ f ; } } } sort ( $ files ) ; return $ files ; }
Find a list of GEDCOM files in a folder
7,259
private function generateNewTreeName ( ) : string { $ tree_name = 'tree' ; $ tree_number = 1 ; $ existing_trees = Tree :: getNameList ( ) ; while ( array_key_exists ( $ tree_name . $ tree_number , $ existing_trees ) ) { $ tree_number ++ ; } return $ tree_name . $ tree_number ; }
Generate a unqiue name for new trees
7,260
public function treePageBlockUpdate ( ServerRequestInterface $ request , Tree $ tree , UserInterface $ user ) : ResponseInterface { $ block = $ this -> treeBlock ( $ request , $ tree , $ user ) ; $ block_id = ( int ) $ request -> get ( 'block_id' ) ; $ block -> saveBlockConfiguration ( $ request , $ block_id ) ; return redirect ( route ( 'tree-page' , [ 'ged' => $ tree -> name ( ) ] ) ) ; }
Update block config options .
7,261
private function treeBlock ( ServerRequestInterface $ request , Tree $ tree , UserInterface $ user ) : ModuleBlockInterface { $ block_id = ( int ) $ request -> get ( 'block_id' ) ; $ block = DB :: table ( 'block' ) -> where ( 'block_id' , '=' , $ block_id ) -> where ( 'gedcom_id' , '=' , $ tree -> id ( ) ) -> whereNull ( 'user_id' ) -> first ( ) ; if ( $ block === null ) { throw new NotFoundHttpException ( ) ; } $ module = $ this -> module_service -> findByName ( $ block -> module_name ) ; if ( ! $ module instanceof ModuleBlockInterface ) { throw new NotFoundHttpException ( ) ; } if ( $ block -> user_id !== $ user -> id ( ) && ! Auth :: isAdmin ( ) ) { throw new AccessDeniedHttpException ( ) ; } return $ module ; }
Load a block and check we have permission to edit it .
7,262
public function treePage ( Tree $ tree ) : ResponseInterface { $ has_blocks = DB :: table ( 'block' ) -> where ( 'gedcom_id' , '=' , $ tree -> id ( ) ) -> exists ( ) ; if ( ! $ has_blocks ) { $ this -> checkDefaultTreeBlocksExist ( ) ; ( new Builder ( DB :: connection ( ) ) ) -> from ( 'block' ) -> insertUsing ( [ 'gedcom_id' , 'location' , 'block_order' , 'module_name' ] , static function ( Builder $ query ) use ( $ tree ) : void { $ query -> select ( [ DB :: raw ( $ tree -> id ( ) ) , 'location' , 'block_order' , 'module_name' ] ) -> from ( 'block' ) -> where ( 'gedcom_id' , '=' , - 1 ) ; } ) ; } return $ this -> viewResponse ( 'tree-page' , [ 'main_blocks' => $ this -> treeBlocks ( $ tree -> id ( ) , 'main' ) , 'side_blocks' => $ this -> treeBlocks ( $ tree -> id ( ) , 'side' ) , 'title' => e ( $ tree -> title ( ) ) , 'meta_robots' => 'index,follow' , ] ) ; }
Show a tree s page .
7,263
public function treePageBlock ( ServerRequestInterface $ request , Tree $ tree ) : ResponseInterface { $ block_id = $ request -> get ( 'block_id' ) ; $ block_id = ( int ) DB :: table ( 'block' ) -> where ( 'block_id' , '=' , $ block_id ) -> where ( 'gedcom_id' , '=' , $ tree -> id ( ) ) -> value ( 'block_id' ) ; $ module = $ this -> getBlockModule ( $ tree , $ block_id ) ; $ html = view ( 'layouts/ajax' , [ 'content' => $ module -> getBlock ( $ tree , $ block_id , 'gedcom' ) , ] ) ; return response ( $ html ) ; }
Load block asynchronously .
7,264
public function treePageDefaultEdit ( ) : ResponseInterface { $ this -> checkDefaultTreeBlocksExist ( ) ; $ main_blocks = $ this -> treeBlocks ( - 1 , 'main' ) ; $ side_blocks = $ this -> treeBlocks ( - 1 , 'side' ) ; $ all_blocks = $ this -> availableTreeBlocks ( ) ; $ title = I18N :: translate ( 'Set the default blocks for new family trees' ) ; $ url_cancel = route ( 'admin-control-panel' ) ; $ url_save = route ( 'tree-page-default-update' ) ; return $ this -> viewResponse ( 'edit-blocks-page' , [ 'all_blocks' => $ all_blocks , 'can_reset' => false , 'main_blocks' => $ main_blocks , 'side_blocks' => $ side_blocks , 'title' => $ title , 'url_cancel' => $ url_cancel , 'url_save' => $ url_save , ] ) ; }
Show a form to edit the default blocks for new trees .
7,265
public function treePageDefaultUpdate ( ServerRequestInterface $ request ) : ResponseInterface { $ main_blocks = ( array ) $ request -> get ( 'main' ) ; $ side_blocks = ( array ) $ request -> get ( 'side' ) ; $ this -> updateTreeBlocks ( - 1 , $ main_blocks , $ side_blocks ) ; return redirect ( route ( 'admin-control-panel' ) ) ; }
Save updated default blocks for new trees .
7,266
public function treePageUpdate ( ServerRequestInterface $ request , Tree $ tree ) : ResponseInterface { $ defaults = ( bool ) $ request -> get ( 'defaults' ) ; if ( $ defaults ) { $ main_blocks = $ this -> treeBlocks ( - 1 , 'main' ) -> all ( ) ; $ side_blocks = $ this -> treeBlocks ( - 1 , 'side' ) -> all ( ) ; } else { $ main_blocks = ( array ) $ request -> get ( 'main' ) ; $ side_blocks = ( array ) $ request -> get ( 'side' ) ; } $ this -> updateTreeBlocks ( $ tree -> id ( ) , $ main_blocks , $ side_blocks ) ; return redirect ( route ( 'tree-page' , [ 'ged' => $ tree -> name ( ) ] ) ) ; }
Save updated blocks on a tree s page .
7,267
public function userPage ( UserInterface $ user ) : ResponseInterface { $ has_blocks = DB :: table ( 'block' ) -> where ( 'user_id' , '=' , $ user -> id ( ) ) -> exists ( ) ; if ( ! $ has_blocks ) { $ this -> checkDefaultUserBlocksExist ( ) ; ( new Builder ( DB :: connection ( ) ) ) -> from ( 'block' ) -> insertUsing ( [ 'user_id' , 'location' , 'block_order' , 'module_name' ] , static function ( Builder $ query ) use ( $ user ) : void { $ query -> select ( [ DB :: raw ( $ user -> id ( ) ) , 'location' , 'block_order' , 'module_name' ] ) -> from ( 'block' ) -> where ( 'user_id' , '=' , - 1 ) ; } ) ; } return $ this -> viewResponse ( 'user-page' , [ 'main_blocks' => $ this -> userBlocks ( $ user -> id ( ) , 'main' ) , 'side_blocks' => $ this -> userBlocks ( $ user -> id ( ) , 'side' ) , 'title' => I18N :: translate ( 'My page' ) , ] ) ; }
Show a users s page .
7,268
public function userPageDefaultEdit ( ) : ResponseInterface { $ this -> checkDefaultUserBlocksExist ( ) ; $ main_blocks = $ this -> userBlocks ( - 1 , 'main' ) ; $ side_blocks = $ this -> userBlocks ( - 1 , 'side' ) ; $ all_blocks = $ this -> availableUserBlocks ( ) ; $ title = I18N :: translate ( 'Set the default blocks for new users' ) ; $ url_cancel = route ( 'admin-users' ) ; $ url_save = route ( 'user-page-default-update' ) ; return $ this -> viewResponse ( 'edit-blocks-page' , [ 'all_blocks' => $ all_blocks , 'can_reset' => false , 'main_blocks' => $ main_blocks , 'side_blocks' => $ side_blocks , 'title' => $ title , 'url_cancel' => $ url_cancel , 'url_save' => $ url_save , ] ) ; }
Show a form to edit the default blocks for new uesrs .
7,269
public function userPageDefaultUpdate ( ServerRequestInterface $ request ) : ResponseInterface { $ main_blocks = ( array ) $ request -> get ( 'main' ) ; $ side_blocks = ( array ) $ request -> get ( 'side' ) ; $ this -> updateUserBlocks ( - 1 , $ main_blocks , $ side_blocks ) ; return redirect ( route ( 'admin-control-panel' ) ) ; }
Save the updated default blocks for new users .
7,270
public function userPageUpdate ( ServerRequestInterface $ request , Tree $ tree , UserInterface $ user ) : ResponseInterface { $ defaults = ( bool ) $ request -> get ( 'defaults' ) ; if ( $ defaults ) { $ main_blocks = $ this -> userBlocks ( - 1 , 'main' ) -> all ( ) ; $ side_blocks = $ this -> userBlocks ( - 1 , 'side' ) -> all ( ) ; } else { $ main_blocks = ( array ) $ request -> get ( 'main' ) ; $ side_blocks = ( array ) $ request -> get ( 'side' ) ; } $ this -> updateUserBlocks ( $ user -> id ( ) , $ main_blocks , $ side_blocks ) ; return redirect ( route ( 'user-page' , [ 'ged' => $ tree -> name ( ) ] ) ) ; }
Save the updted blocks on a user s page .
7,271
public function userPageUserUpdate ( ServerRequestInterface $ request ) : ResponseInterface { $ user_id = ( int ) $ request -> get ( 'user_id' ) ; $ main_blocks = ( array ) $ request -> get ( 'main' ) ; $ side_blocks = ( array ) $ request -> get ( 'side' ) ; $ this -> updateUserBlocks ( $ user_id , $ main_blocks , $ side_blocks ) ; return redirect ( route ( 'admin-control-panel' ) ) ; }
Save the updated blocks for another user s page .
7,272
private function getBlockModule ( Tree $ tree , int $ block_id ) : ModuleBlockInterface { $ active_blocks = $ this -> module_service -> findByComponent ( ModuleBlockInterface :: class , $ tree , Auth :: user ( ) ) ; $ module_name = DB :: table ( 'block' ) -> where ( 'block_id' , '=' , $ block_id ) -> value ( 'module_name' ) ; $ block = $ active_blocks -> first ( static function ( ModuleInterface $ module ) use ( $ module_name ) : bool { return $ module -> name ( ) === $ module_name ; } ) ; if ( $ block === null ) { throw new NotFoundHttpException ( 'Block not found' ) ; } return $ block ; }
Get a specific block .
7,273
private function availableTreeBlocks ( ) : Collection { return $ this -> module_service -> findByInterface ( ModuleBlockInterface :: class , false , true ) -> filter ( static function ( ModuleBlockInterface $ block ) : bool { return $ block -> isTreeBlock ( ) ; } ) -> mapWithKeys ( static function ( ModuleInterface $ block ) : array { return [ $ block -> name ( ) => $ block ] ; } ) ; }
Get all the available blocks for a tree page .
7,274
private function availableUserBlocks ( ) : Collection { return $ this -> module_service -> findByInterface ( ModuleBlockInterface :: class , false , true ) -> filter ( static function ( ModuleBlockInterface $ block ) : bool { return $ block -> isUserBlock ( ) ; } ) -> mapWithKeys ( static function ( ModuleInterface $ block ) : array { return [ $ block -> name ( ) => $ block ] ; } ) ; }
Get all the available blocks for a user page .
7,275
private function treeBlocks ( int $ tree_id , string $ location ) : Collection { $ rows = DB :: table ( 'block' ) -> where ( 'gedcom_id' , '=' , $ tree_id ) -> where ( 'location' , '=' , $ location ) -> orderBy ( 'block_order' ) -> pluck ( 'module_name' , 'block_id' ) ; return $ this -> filterActiveBlocks ( $ rows , $ this -> availableTreeBlocks ( ) ) ; }
Get the blocks for a specified tree .
7,276
private function checkDefaultTreeBlocksExist ( ) : void { $ has_blocks = DB :: table ( 'block' ) -> where ( 'gedcom_id' , '=' , - 1 ) -> exists ( ) ; if ( ! $ has_blocks ) { foreach ( [ 'main' , 'side' ] as $ location ) { foreach ( self :: DEFAULT_TREE_PAGE_BLOCKS [ $ location ] as $ block_order => $ class ) { $ module_name = $ this -> module_service -> findByInterface ( $ class ) -> first ( ) -> name ( ) ; DB :: table ( 'block' ) -> insert ( [ 'gedcom_id' => - 1 , 'location' => $ location , 'block_order' => $ block_order , 'module_name' => $ module_name , ] ) ; } } } }
Make sure that default blocks exist for a tree .
7,277
private function userBlocks ( int $ user_id , string $ location ) : Collection { $ rows = DB :: table ( 'block' ) -> where ( 'user_id' , '=' , $ user_id ) -> where ( 'location' , '=' , $ location ) -> orderBy ( 'block_order' ) -> pluck ( 'module_name' , 'block_id' ) ; return $ this -> filterActiveBlocks ( $ rows , $ this -> availableUserBlocks ( ) ) ; }
Get the blocks for a specified user .
7,278
private function updateUserBlocks ( int $ user_id , array $ main_blocks , array $ side_blocks ) : void { $ existing_block_ids = DB :: table ( 'block' ) -> where ( 'user_id' , '=' , $ user_id ) -> pluck ( 'block_id' ) ; foreach ( $ existing_block_ids as $ existing_block_id ) { if ( ! in_array ( $ existing_block_id , $ main_blocks , false ) && ! in_array ( $ existing_block_id , $ side_blocks , false ) ) { DB :: table ( 'block_setting' ) -> where ( 'block_id' , '=' , $ existing_block_id ) -> delete ( ) ; DB :: table ( 'block' ) -> where ( 'block_id' , '=' , $ existing_block_id ) -> delete ( ) ; } } $ updates = [ 'main' => $ main_blocks , 'side' => $ side_blocks , ] ; foreach ( $ updates as $ location => $ updated_blocks ) { foreach ( $ updated_blocks as $ block_order => $ block_id ) { if ( is_numeric ( $ block_id ) ) { DB :: table ( 'block' ) -> where ( 'block_id' , '=' , $ block_id ) -> update ( [ 'block_order' => $ block_order , 'location' => $ location , ] ) ; } else { DB :: table ( 'block' ) -> insert ( [ 'user_id' => $ user_id , 'location' => $ location , 'block_order' => $ block_order , 'module_name' => $ block_id , ] ) ; } } } }
Save the updated blocks for a user .
7,279
public function render ( $ renderer , $ sub = false ) { if ( ! empty ( $ this -> attrs [ 'style' ] ) ) { $ renderer -> setCurrentStyle ( $ this -> attrs [ 'style' ] ) ; } if ( ! empty ( $ this -> attrs [ 'width' ] ) ) { $ this -> attrs [ 'width' ] *= 3.9 ; } $ this -> text = $ this -> getStart ( ) . $ this -> text ; foreach ( $ this -> elements as $ element ) { if ( $ element === 'footnotetexts' ) { $ renderer -> Footnotes ( ) ; } elseif ( $ element === 'addpage' ) { $ renderer -> newPage ( ) ; } elseif ( $ element instanceof ReportBaseHtml ) { $ element -> render ( $ renderer , true ) ; } else { $ element -> render ( $ renderer ) ; } } $ this -> text .= $ this -> getEnd ( ) ; if ( $ sub ) { return $ this -> text ; } $ renderer -> writeHTML ( $ this -> text ) ; }
Render the output .
7,280
private function familyQuery ( string $ type ) : string { $ row = DB :: table ( 'families' ) -> where ( 'f_file' , '=' , $ this -> tree -> id ( ) ) -> orderBy ( 'f_numchil' , 'desc' ) -> first ( ) ; if ( $ row === null ) { return '' ; } $ family = Family :: rowMapper ( ) ( $ row ) ; if ( ! $ family -> canShow ( ) ) { return I18N :: translate ( 'This information is private and cannot be shown.' ) ; } switch ( $ type ) { default : case 'full' : return $ family -> formatList ( ) ; case 'size' : return I18N :: number ( ( int ) $ row -> f_numchil ) ; case 'name' : return '<a href="' . e ( $ family -> url ( ) ) . '">' . $ family -> fullName ( ) . '</a>' ; } }
General query on family .
7,281
private function topTenGrandFamilyQuery ( int $ total ) : array { return DB :: table ( 'families' ) -> join ( 'link AS children' , static function ( JoinClause $ join ) : void { $ join -> on ( 'children.l_from' , '=' , 'f_id' ) -> on ( 'children.l_file' , '=' , 'f_file' ) -> where ( 'children.l_type' , '=' , 'CHIL' ) ; } ) -> join ( 'link AS mchildren' , static function ( JoinClause $ join ) : void { $ join -> on ( 'mchildren.l_file' , '=' , 'children.l_file' ) -> on ( 'mchildren.l_from' , '=' , 'children.l_to' ) -> where ( 'mchildren.l_type' , '=' , 'FAMS' ) ; } ) -> join ( 'link AS gchildren' , static function ( JoinClause $ join ) : void { $ join -> on ( 'gchildren.l_file' , '=' , 'mchildren.l_file' ) -> on ( 'gchildren.l_from' , '=' , 'mchildren.l_to' ) -> where ( 'gchildren.l_type' , '=' , 'CHIL' ) ; } ) -> where ( 'f_file' , '=' , $ this -> tree -> id ( ) ) -> groupBy ( [ 'f_id' , 'f_file' ] ) -> orderBy ( DB :: raw ( 'COUNT(*)' ) , 'DESC' ) -> select ( 'families.*' ) -> limit ( $ total ) -> get ( ) -> map ( Family :: rowMapper ( ) ) -> filter ( GedcomRecord :: accessFilter ( ) ) -> map ( static function ( Family $ family ) : array { $ count = 0 ; foreach ( $ family -> children ( ) as $ child ) { foreach ( $ child -> spouseFamilies ( ) as $ spouse_family ) { $ count += $ spouse_family -> children ( ) -> count ( ) ; } } return [ 'family' => $ family , 'count' => $ count , ] ; } ) -> all ( ) ; }
Find the couple with the most grandchildren .
7,282
private function ageBetweenSiblingsQuery ( int $ total ) : array { $ prefix = DB :: connection ( ) -> getTablePrefix ( ) ; return DB :: table ( 'link AS link1' ) -> join ( 'link AS link2' , static function ( JoinClause $ join ) : void { $ join -> on ( 'link2.l_from' , '=' , 'link1.l_from' ) -> on ( 'link2.l_type' , '=' , 'link1.l_type' ) -> on ( 'link2.l_file' , '=' , 'link1.l_file' ) ; } ) -> join ( 'dates AS child1' , static function ( JoinClause $ join ) : void { $ join -> on ( 'child1.d_gid' , '=' , 'link1.l_to' ) -> on ( 'child1.d_file' , '=' , 'link1.l_file' ) -> where ( 'child1.d_fact' , '=' , 'BIRT' ) -> where ( 'child1.d_julianday1' , '<>' , 0 ) ; } ) -> join ( 'dates AS child2' , static function ( JoinClause $ join ) : void { $ join -> on ( 'child2.d_gid' , '=' , 'link2.l_to' ) -> on ( 'child2.d_file' , '=' , 'link2.l_file' ) -> where ( 'child2.d_fact' , '=' , 'BIRT' ) -> whereColumn ( 'child2.d_julianday2' , '>' , 'child1.d_julianday1' ) ; } ) -> where ( 'link1.l_type' , '=' , 'CHIL' ) -> where ( 'link1.l_file' , '=' , $ this -> tree -> id ( ) ) -> distinct ( ) -> select ( [ 'link1.l_from AS family' , 'link1.l_to AS ch1' , 'link2.l_to AS ch2' , DB :: raw ( $ prefix . 'child2.d_julianday2 - ' . $ prefix . 'child1.d_julianday1 AS age' ) ] ) -> orderBy ( 'age' , 'DESC' ) -> take ( $ total ) -> get ( ) -> all ( ) ; }
Returns the ages between siblings .
7,283
private function calculateAge ( int $ age ) : string { if ( ( int ) ( $ age / 365.25 ) > 0 ) { $ result = ( int ) ( $ age / 365.25 ) . 'y' ; } elseif ( ( int ) ( $ age / 30.4375 ) > 0 ) { $ result = ( int ) ( $ age / 30.4375 ) . 'm' ; } else { $ result = $ age . 'd' ; } return FunctionsDate :: getAgeAtEvent ( $ result ) ; }
Returns the calculated age the time of event .
7,284
public function topAgeBetweenSiblingsFullName ( int $ total = 10 ) : string { $ record = $ this -> ageBetweenSiblingsNoList ( $ total ) ; if ( empty ( $ record ) ) { return I18N :: translate ( 'This information is not available.' ) ; } return view ( 'statistics/families/top10-nolist-age' , [ 'record' => $ record , ] ) ; }
Find the name of siblings with the widest age gap .
7,285
public function topAgeBetweenSiblingsList ( int $ total = 10 , string $ one = '' ) : string { $ records = $ this -> ageBetweenSiblingsList ( $ total , ( bool ) $ one ) ; return view ( 'statistics/families/top10-list-age' , [ 'records' => $ records , ] ) ; }
Find the siblings with the widest age gaps .
7,286
public function totalChildren ( ) : string { $ total = ( int ) DB :: table ( 'families' ) -> where ( 'f_file' , '=' , $ this -> tree -> id ( ) ) -> sum ( 'f_numchil' ) ; return I18N :: number ( $ total ) ; }
Count the total children .
7,287
public function averageChildren ( ) : string { $ average = ( float ) DB :: table ( 'families' ) -> where ( 'f_file' , '=' , $ this -> tree -> id ( ) ) -> avg ( 'f_numchil' ) ; return I18N :: number ( $ average , 2 ) ; }
Find the average number of children in families .
7,288
private function topTenFamilyQuery ( int $ total ) : array { return DB :: table ( 'families' ) -> where ( 'f_file' , '=' , $ this -> tree -> id ( ) ) -> orderBy ( 'f_numchil' , 'DESC' ) -> limit ( $ total ) -> get ( ) -> map ( Family :: rowMapper ( ) ) -> filter ( GedcomRecord :: accessFilter ( ) ) -> map ( static function ( Family $ family ) : array { return [ 'family' => $ family , 'count' => $ family -> numberOfChildren ( ) , ] ; } ) -> all ( ) ; }
General query on families .
7,289
public function topTenLargestFamily ( int $ total = 10 ) : string { $ records = $ this -> topTenFamilyQuery ( $ total ) ; return view ( 'statistics/families/top10-nolist' , [ 'records' => $ records , ] ) ; }
The the families with the most children .
7,290
public function topTenLargestFamilyList ( int $ total = 10 ) : string { $ records = $ this -> topTenFamilyQuery ( $ total ) ; return view ( 'statistics/families/top10-list' , [ 'records' => $ records , ] ) ; }
Find the families with the most children .
7,291
public function totalMarriedMales ( ) : string { $ n = ( int ) DB :: table ( 'families' ) -> where ( 'f_file' , '=' , $ this -> tree -> id ( ) ) -> where ( 'f_gedcom' , 'LIKE' , "%\n1 MARR%" ) -> distinct ( ) -> count ( 'f_husb' ) ; return I18N :: number ( $ n ) ; }
Number of husbands .
7,292
private function ageBetweenSpousesQuery ( string $ age_dir , int $ total ) : array { $ prefix = DB :: connection ( ) -> getTablePrefix ( ) ; $ query = DB :: table ( 'families' ) -> where ( 'f_file' , '=' , $ this -> tree -> id ( ) ) -> join ( 'dates AS wife' , static function ( JoinClause $ join ) : void { $ join -> on ( 'wife.d_gid' , '=' , 'f_wife' ) -> on ( 'wife.d_file' , '=' , 'f_file' ) -> where ( 'wife.d_fact' , '=' , 'BIRT' ) -> where ( 'wife.d_julianday1' , '<>' , 0 ) ; } ) -> join ( 'dates AS husb' , static function ( JoinClause $ join ) : void { $ join -> on ( 'husb.d_gid' , '=' , 'f_husb' ) -> on ( 'husb.d_file' , '=' , 'f_file' ) -> where ( 'husb.d_fact' , '=' , 'BIRT' ) -> where ( 'husb.d_julianday1' , '<>' , 0 ) ; } ) ; if ( $ age_dir === 'DESC' ) { $ query -> whereColumn ( 'wife.d_julianday1' , '>=' , 'husb.d_julianday1' ) -> orderBy ( DB :: raw ( 'MIN(' . $ prefix . 'wife.d_julianday1) - MIN(' . $ prefix . 'husb.d_julianday1)' ) , 'DESC' ) ; } else { $ query -> whereColumn ( 'husb.d_julianday1' , '>=' , 'wife.d_julianday1' ) -> orderBy ( DB :: raw ( 'MIN(' . $ prefix . 'husb.d_julianday1) - MIN(' . $ prefix . 'wife.d_julianday1)' ) , 'DESC' ) ; } return $ query -> groupBy ( [ 'f_id' , 'f_file' ] ) -> select ( 'families.*' ) -> take ( $ total ) -> get ( ) -> map ( Family :: rowMapper ( ) ) -> filter ( GedcomRecord :: accessFilter ( ) ) -> map ( function ( Family $ family ) use ( $ age_dir ) : array { $ husb_birt_jd = $ family -> husband ( ) -> getBirthDate ( ) -> minimumJulianDay ( ) ; $ wife_birt_jd = $ family -> wife ( ) -> getBirthDate ( ) -> minimumJulianDay ( ) ; if ( $ age_dir === 'DESC' ) { $ diff = $ wife_birt_jd - $ husb_birt_jd ; } else { $ diff = $ husb_birt_jd - $ wife_birt_jd ; } return [ 'family' => $ family , 'age' => $ this -> calculateAge ( $ diff ) , ] ; } ) -> all ( ) ; }
Find the ages between spouses .
7,293
public function statsDiv ( string $ color_from = null , string $ color_to = null ) : string { return ( new ChartDivorce ( $ this -> tree ) ) -> chartDivorce ( $ color_from , $ color_to ) ; }
General divorce query .
7,294
public function bootstrap4 ( ) : string { if ( ! empty ( $ this -> submenus ) ) { $ submenus = '' ; foreach ( $ this -> submenus as $ submenu ) { $ attrs = '' ; foreach ( $ submenu -> attrs as $ key => $ value ) { $ attrs .= ' ' . $ key . '="' . e ( $ value ) . '"' ; } $ class = trim ( 'dropdown-item ' . $ submenu -> class ) ; $ submenus .= '<a class="' . $ class . '" href="' . e ( $ submenu -> link ) . '"' . $ attrs . '>' . $ submenu -> label . '</a>' ; } $ class = trim ( 'nav-item dropdown ' . $ this -> class ) ; return '<li class="' . $ class . '">' . '<a href="#" class="nav-link dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">' . $ this -> label . '<span class="caret"></span></a>' . '<div class="dropdown-menu" role="menu">' . $ submenus . '</div>' . '</li>' ; } $ attrs = '' ; foreach ( $ this -> attrs as $ key => $ value ) { $ attrs .= ' ' . $ key . '="' . e ( $ value ) . '"' ; } $ class = trim ( 'nav-item ' . $ this -> class ) ; return '<li class="' . $ class . '"><a class="nav-link" href="' . e ( $ this -> link ) . '"' . $ attrs . '>' . $ this -> label . '</a></li>' ; }
Render this menu using Bootstrap4 markup
7,295
public function chartUrl ( Individual $ individual , array $ parameters = [ ] ) : string { return route ( 'module' , [ 'module' => $ this -> name ( ) , 'action' => 'Chart' , 'xrefs[]' => $ individual -> xref ( ) , 'ged' => $ individual -> tree ( ) -> name ( ) , ] + $ parameters ) ; }
The URL for this chart .
7,296
protected function maxYear ( array $ individuals ) : int { $ jd = array_reduce ( $ individuals , static function ( $ carry , Individual $ item ) { return max ( $ carry , $ item -> getEstimatedDeathDate ( ) -> maximumJulianDay ( ) ) ; } , 0 ) ; $ year = $ this -> jdToYear ( $ jd ) ; return min ( $ year , ( int ) date ( 'Y' ) ) ; }
Find the latest event year for individuals
7,297
protected function minYear ( array $ individuals ) : int { $ jd = array_reduce ( $ individuals , static function ( $ carry , Individual $ item ) { return min ( $ carry , $ item -> getEstimatedBirthDate ( ) -> minimumJulianDay ( ) ) ; } , PHP_INT_MAX ) ; return $ this -> jdToYear ( $ jd ) ; }
Find the earliest event year for individuals
7,298
protected function jdToYear ( int $ jd ) : int { if ( $ jd === 0 ) { return 0 ; } $ gregorian = new GregorianCalendar ( ) ; [ $ y ] = $ gregorian -> jdToYmd ( $ jd ) ; return $ y ; }
Convert a julian day to a gregorian year
7,299
protected function closeFamily ( Individual $ individual ) : array { $ xrefs = [ ] ; foreach ( $ individual -> spouseFamilies ( ) as $ family ) { foreach ( $ family -> children ( ) as $ child ) { $ xrefs [ ] = $ child -> xref ( ) ; } foreach ( $ family -> spouses ( ) as $ spouse ) { $ xrefs [ ] = $ spouse -> xref ( ) ; } } foreach ( $ individual -> childFamilies ( ) as $ family ) { foreach ( $ family -> children ( ) as $ child ) { $ xrefs [ ] = $ child -> xref ( ) ; } foreach ( $ family -> spouses ( ) as $ spouse ) { $ xrefs [ ] = $ spouse -> xref ( ) ; } } return $ xrefs ; }
Find the close family members of an individual .