Draw the children for some families

@param Collection $familyList array of families to draw the children for
@param int        $gen        number of generations to draw
@param bool       $ajax       true for an ajax call

@return string
515681
private function drawChildren(Collection $familyList, int $gen = 1, bool $ajax = false): string
    {
        $html          = '';
        $children2draw = [];
        $f2load        = [];

        foreach ($familyList as $f) {
            $children = $f->children();
            if ($children->isNotEmpty()) {
                $f2load[] = $f->xref();
                foreach ($children as $child) {
                    // Eliminate duplicates - e.g. when adopted by a step-parent
                    $children2draw[$child->xref()] = $child;
                }
            }
        }
        $tc = count($children2draw);
        if ($tc) {
            $f2load = implode(',', $f2load);
            $nbc    = 0;
            foreach ($children2draw as $child) {
                $nbc++;
                if ($tc == 1) {
                    $co = 'c'; // unique
                } elseif ($nbc == 1) {
                    $co = 't'; // first
                } elseif ($nbc == $tc) {
                    $co = 'b'; //last
                } else {
                    $co = 'h';
                }
                $html .= $this->drawPerson($child, $gen - 1, -1, null, $co, false);
            }
            if (!$ajax) {
                $html = '<td align="right"' . ($gen == 0 ? ' abbr="c' . $f2load . '"' : '') . '>' . $html . '</td>' . $this->drawHorizontalLine();
            }
        }

        return $html;
    }
915506
protected function getQueryBuilderByFamily(Request $request, FamilyInterface $family)
    {
        $term = '%'.trim($request->get('term'), '%').'%';

        return $this->dataManager->getQbForFamiliesAndLabel([$family], $term);
    }
511311
protected function getGroupLabel(FamilyInterface $family, array $groupPath, $level)
    {
        $fallBack = isset($groupPath[$level]) ? $groupPath[$level] : null;
        $fieldsetPath = $this->getFieldsetPath($groupPath, $level);
        $transKeys = [
            "eav.family.{$family->getCode()}.group.{$fieldsetPath}.label",
            "eav.group.{$fieldsetPath}.label",
        ];

        return ucfirst($this->tryTranslate($transKeys, [], $fallBack));
    }
732908
private function addFamilyAndDescendantsToCart(Family $family): void
    {
        $this->addRecordToCart($family);

        foreach ($family->spouses() as $spouse) {
            $this->addRecordToCart($spouse);
        }
        foreach ($family->children() as $child) {
            $this->addRecordToCart($child);
            foreach ($child->spouseFamilies() as $child_family) {
                $this->addFamilyAndDescendantsToCart($child_family);
            }
        }
    }
191304
private void jCheckBoxDrawFinalZeroingLinesActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jCheckBoxDrawFinalZeroingLinesActionPerformed
    {//GEN-HEADEREND:event_jCheckBoxDrawFinalZeroingLinesActionPerformed
        parent.getGraphPanelChart().getChartSettings().setDrawFinalZeroingLines(jCheckBoxDrawFinalZeroingLines.isSelected());
        refreshGraphPreview();
    }
88618
private function iterateOverCollections($children, $userId, $parent = null, $namespace = '')
    {
        $format = ('' !== $namespace ? '%s.%s' : '%s%s');
        $collections = [];
        foreach ($children as $collectionKey => $collectionItem) {
            $key = sprintf($format, $namespace, $collectionKey);
            $collections[$key] = $this->getOrCreateCollection(
                $key,
                $collectionItem['meta_title'],
                $userId,
                $parent
            )->getId();

            if (array_key_exists('collections', $collectionItem)) {
                $childCollections = $this->iterateOverCollections(
                    $collectionItem['collections'],
                    $userId,
                    $collections[$key],
                    $key
                );
                $collections = array_merge($collections, $childCollections);
            }
        }

        return $collections;
    }
579675
public function linkChildToFamilyAction(ServerRequestInterface $request, Tree $tree): ResponseInterface
    {
        $xref  = $request->get('xref', '');
        $famid = $request->get('famid', '');
        $PEDI  = $request->get('PEDI', '');

        $individual = Individual::getInstance($xref, $tree);
        Auth::checkIndividualAccess($individual, true);

        $family = Family::getInstance($famid, $tree);
        Auth::checkFamilyAccess($family, true);

        // Replace any existing child->family link (we may be changing the PEDI);
        $fact_id = '';
        foreach ($individual->facts(['FAMC']) as $fact) {
            if ($family === $fact->target()) {
                $fact_id = $fact->id();
                break;
            }
        }

        $gedcom = GedcomCodePedi::createNewFamcPedi($PEDI, $famid);
        $individual->updateFact($fact_id, $gedcom, true);

        // Only set the family->child link if it does not already exist
        $chil_link_exists = false;
        foreach ($family->facts(['CHIL']) as $fact) {
            if ($individual === $fact->target()) {
                $chil_link_exists = true;
                break;
            }
        }

        if (!$chil_link_exists) {
            $family->createFact('1 CHIL @' . $individual->xref() . '@', true);
        }

        return redirect($individual->url());
    }
1321101
public function reorderChildrenAction(ServerRequestInterface $request, Tree $tree): ResponseInterface
    {
        $xref   = $request->get('xref', '');
        $order  = (array) $request->get('order', []);
        $family = Family::getInstance($xref, $tree);

        Auth::checkFamilyAccess($family, true);

        $dummy_facts = ['0 @' . $family->xref() . '@ FAM'];
        $sort_facts  = [];
        $keep_facts  = [];

        // Split facts into FAMS and other
        foreach ($family->facts() as $fact) {
            if ($fact->getTag() === 'CHIL') {
                $sort_facts[$fact->id()] = $fact->gedcom();
            } else {
                $keep_facts[] = $fact->gedcom();
            }
        }

        // Sort the facts
        uksort($sort_facts, static function ($x, $y) use ($order) {
            return array_search($x, $order, true) - array_search($y, $order, true);
        });

        // Merge the facts
        $gedcom = implode("\n", array_merge($dummy_facts, $sort_facts, $keep_facts));

        $family->updateRecord($gedcom, false);

        return redirect($family->url());
    }
1144091
protected function ancestorsFamilies(Tree $tree, Collection $ancestors): ResponseInterface
    {
        $this->layout = 'layouts/ajax';

        $families = [];
        foreach ($ancestors as $individual) {
            foreach ($individual->childFamilies() as $family) {
                $families[$family->xref()] = $family;
            }
        }

        return $this->viewResponse('lists/families-table', [
            'families' => $families,
            'tree'     => $tree,
        ]);
    }
146597
public function generate(&$result,GeneratorInterface $generator)
    {
        if($this->count() === 0) {
            throw new GeneratorException('No child scopes to call must be atleast 1');
        }
        
        $repeat_x = $this->calculateRepeatQuota($generator);
        
        # rewind the current item 
        $this->rewind();
        while($repeat_x > 0) {
            
            if($this->usingAlternatingStrategy()) {
                $randomIndex = \round($generator->generate(1,($this->count())));                
                $this->get($randomIndex)->generate($result,$generator);    
                                
            } else {
                
                foreach($this as $current) {
                    $current->generate($result,$generator);    
                }    
                
            }
            
            $repeat_x = $repeat_x -1;
        }
        
        
        return $result;
    }
1005790
protected function generateTreeView($collection, $treeClass)
    {
        $content = [];
        foreach ($collection as $model) {
            /** @var ModelInterface $model */

            $toggleID = $model->getProviderName() . '_' . $treeClass . '_' . $model->getId();

            $content[] = $this->parseModel($model, $toggleID);

            if ($model->getMeta($model::HAS_CHILDREN) && $model->getMeta($model::SHOW_CHILDREN)) {
                $template = new ContaoBackendViewTemplate('widget_treepicker_child');
                $subHtml  = '';

                foreach ($model->getMeta($model::CHILD_COLLECTIONS) as $objChildCollection) {
                    $subHtml .= $this->generateTreeView($objChildCollection, $treeClass);
                }

                $template
                    ->setTranslator($this->getEnvironment()->getTranslator())
                    ->set('objParentModel', $model)
                    ->set('strToggleID', $toggleID)
                    ->set('strHTML', $subHtml)
                    ->set('strTable', $model->getProviderName());

                $content[] = $template->parse();
            }
        }

        return \implode("\n", $content);
    }
97100
private function _writeDrawings(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Worksheet $pSheet = null, $includeCharts = FALSE)
	{
		$chartCount = ($includeCharts) ? $pSheet->getChartCollection()->count() : 0;
		// If sheet contains drawings, add the relationships
		if (($pSheet->getDrawingCollection()->count() > 0) ||
			($chartCount > 0)) {
			$objWriter->startElement('drawing');
			$objWriter->writeAttribute('r:id', 'rId1');
			$objWriter->endElement();
		}
	}
596949
public function databaseDeltree($family, $key = false)
    {
        $cmd = implode(' ', array('DATABASE', 'DELTREE', '"' . $family . '"'));
        if ($key !== false) {
            $cmd .= ' "' . $key . '"';
        }
        $result = $this->send($cmd);
        if ($result->isResult(0)) {
            throw new DatabaseInvalidEntryException('Invalid family or key.');
        }
    }
679614
private function childFacts(Individual $person, Family $family, $option, $relation, Date $min_date, Date $max_date): array
    {
        $SHOW_RELATIVES_EVENTS = $person->tree()->getPreference('SHOW_RELATIVES_EVENTS');

        $facts = [];

        // Deal with recursion.
        switch ($option) {
            case '_CHIL':
                // Add grandchildren
                foreach ($family->children() as $child) {
                    foreach ($child->spouseFamilies() as $cfamily) {
                        switch ($child->sex()) {
                            case 'M':
                                foreach ($this->childFacts($person, $cfamily, '_GCHI', 'son', $min_date, $max_date) as $fact) {
                                    $facts[] = $fact;
                                }
                                break;
                            case 'F':
                                foreach ($this->childFacts($person, $cfamily, '_GCHI', 'dau', $min_date, $max_date) as $fact) {
                                    $facts[] = $fact;
                                }
                                break;
                            default:
                                foreach ($this->childFacts($person, $cfamily, '_GCHI', 'chi', $min_date, $max_date) as $fact) {
                                    $facts[] = $fact;
                                }
                                break;
                        }
                    }
                }
                break;
        }

        // For each child in the family
        foreach ($family->children() as $child) {
            if ($child->xref() === $person->xref()) {
                // We are not our own sibling!
                continue;
            }
            // add child’s birth
            if (strpos($SHOW_RELATIVES_EVENTS, '_BIRT' . str_replace('_HSIB', '_SIBL', $option)) !== false) {
                foreach ($child->facts(Gedcom::BIRTH_EVENTS) as $fact) {
                    // Always show _BIRT_CHIL, even if the dates are not known
                    if ($option === '_CHIL' || $this->includeFact($fact, $min_date, $max_date)) {
                        if ($option === '_GCHI' && $relation === 'dau') {
                            // Convert the event to a close relatives event.
                            $rela_fact = clone $fact;
                            $rela_fact->setTag('_' . $fact->getTag() . '_GCH1');
                            $facts[] = $rela_fact;
                        } elseif ($option === '_GCHI' && $relation === 'son') {
                            // Convert the event to a close relatives event.
                            $rela_fact = clone $fact;
                            $rela_fact->setTag('_' . $fact->getTag() . '_GCH2');
                            $facts[] = $rela_fact;
                        } else {
                            // Convert the event to a close relatives event.
                            $rela_fact = clone $fact;
                            $rela_fact->setTag('_' . $fact->getTag() . $option);
                            $facts[] = $rela_fact;
                        }
                    }
                }
            }
            // add child’s death
            if (strpos($SHOW_RELATIVES_EVENTS, '_DEAT' . str_replace('_HSIB', '_SIBL', $option)) !== false) {
                foreach ($child->facts(Gedcom::DEATH_EVENTS) as $fact) {
                    if ($this->includeFact($fact, $min_date, $max_date)) {
                        if ($option === '_GCHI' && $relation === 'dau') {
                            // Convert the event to a close relatives event.
                            $rela_fact = clone $fact;
                            $rela_fact->setTag('_' . $fact->getTag() . '_GCH1');
                            $facts[] = $rela_fact;
                        } elseif ($option === '_GCHI' && $relation === 'son') {
                            // Convert the event to a close relatives event.
                            $rela_fact = clone $fact;
                            $rela_fact->setTag('_' . $fact->getTag() . '_GCH2');
                            $facts[] = $rela_fact;
                        } else {
                            // Convert the event to a close relatives event.
                            $rela_fact = clone $fact;
                            $rela_fact->setTag('_' . $fact->getTag() . $option);
                            $facts[] = $rela_fact;
                        }
                    }
                }
            }
            // add child’s marriage
            if (strstr($SHOW_RELATIVES_EVENTS, '_MARR' . str_replace('_HSIB', '_SIBL', $option))) {
                foreach ($child->spouseFamilies() as $sfamily) {
                    foreach ($sfamily->facts(['MARR']) as $fact) {
                        if ($this->includeFact($fact, $min_date, $max_date)) {
                            if ($option === '_GCHI' && $relation === 'dau') {
                                // Convert the event to a close relatives event.
                                $rela_fact = clone $fact;
                                $rela_fact->setTag('_' . $fact->getTag() . '_GCH1');
                                $facts[] = $rela_fact;
                            } elseif ($option === '_GCHI' && $relation === 'son') {
                                // Convert the event to a close relatives event.
                                $rela_fact = clone $fact;
                                $rela_fact->setTag('_' . $fact->getTag() . '_GCH2');
                                $facts[] = $rela_fact;
                            } else {
                                // Convert the event to a close relatives event.
                                $rela_fact = clone $fact;
                                $rela_fact->setTag('_' . $fact->getTag() . $option);
                                $facts[] = $rela_fact;
                            }
                        }
                    }
                }
            }
        }

        return $facts;
    }
684137
private function recursiveCallChild(\DOMNodeList $nodeList, callable $fct)
    {
        /**
         * @var \DOMNode $domNode
         */
        foreach ($nodeList as $domNode) {
            $fct(new GlHtmlNode($domNode));
            if ($domNode->hasChildNodes()) {
                $this->recursiveCallChild($domNode->childNodes, $fct);
            }
        }
    }
838517
public static function getChildrenList( ezpContentCriteria $c, ezpRestRequest $currentRequest, array $responseGroups = array() )
    {
        $aRetData = array();
        $aChildren = ezpContentRepository::query( $c );

        foreach ( $aChildren as $childNode )
        {
            $childEntry = self::getMetadataByContent( $childNode );
            $childEntry = array_merge( $childEntry, self::getMetadataByLocation( $childNode->locations ) );

            // Add fields with their values if requested
            if ( in_array( ezpRestContentController::VIEWLIST_RESPONSEGROUP_FIELDS, $responseGroups ) )
            {
                $childEntry['fields'] = array();
                foreach ( $childNode->fields as $fieldName => $field )
                {
                    $childEntry['fields'][$fieldName] = self::attributeOutputData( $field );
                }
            }

            $aRetData[] = $childEntry;
        }

        return $aRetData;
    }
564880
public function editAction(Request $request, DataInterface $data, FamilyInterface $family = null)
    {
        $this->initDataFamily($data, $family);
        $form = $this->getForm($request, $data, $family->getFormOptions());

        $form->handleRequest($request);
        if ($form->isSubmitted() && $form->isValid()) {
            $this->saveEntity($data);

            $parameters = $request->query->all();
            $parameters['success'] = 1;

            return $this->redirectToEntity($data, 'edit', $parameters);
        }

        return $this->renderAction($this->getViewParameters($request, $form, $data));
    }