<commit_before><?php
class ComponentModel extends Model
{
    protected $id;
    protected $subcomponents = array();
    private $component_id;
    private $basename;

    public function __construct($id, $component_id)
    {
        $this->id = $id;
        $this->component_id = $component_id;
        $this->basename = $id . '_' . $this->component_id . '.xml';
        $this->config = new Config();
        $component_file = $this->ppath() . DIRECTORY_SEPARATOR . $this->basename;
        if (file_exists($component_file)) {
          $this->xml = new SimpleXMLElement(file_get_contents($component_file));
        }
        $contents_config = $this->config->get('contents');
        foreach ($this->xpath($contents_config['component']) as $c) {
            $cattrs = $c->attributes();
            $cid = $cattrs['id'];
            $this->subcomponents[] = new ComponentModel($id, $cid);
        }
    }

    public function title()
    {
        $pieces = array();
        if (count($this->xpath('did/unitdate')) > 0) {
            $pieces = array_merge(
                $pieces,
                $this->xpath('did/unittitle'),
                $this->xpath('did/unitdate')
            );
        }
        else {
            $pieces = array_merge($pieces, $this->xpath('did/unittitle'));
        }
        $results = array();
        foreach ($pieces as $piece) {
            $results[] = dom_import_simplexml($piece)->textContent;
        }
        return implode(', ', $results);
    }

    public function container_lists()
    {
        $container_lists = array();
        $order = array();
        $containers = array();
        $contents_config = $this->config->get('contents');
        foreach ($this->xpath($contents_config['container']) as $container) {
            $attributes = $container->attributes();
            if (isset($attributes['id'])) {
                # base container
                $id = trim($attributes['id']);
                $type = strtolower($attributes['type']);
                $number = (string)$container;
                $order[] = $id;
                $containers[$id] = array(
                    'id' => $id,
                    'type' => $type,
                    'number' => $number,
                    'child' => null,
                );
            }
            elseif (isset($attributes['parent'])) {
                # subordinate container
                $parent = trim($attributes['parent']);
                $type = strtolower($attributes['type']);
                $number = (string)$container;
                $containers["child-$parent"] = array(
                    'id' => "child-$parent",
                    'type' => $type,
                    'number' => $number,
                    'child' => null,
                );
                $containers[$parent]['child'] = "child-$parent";
            }
            else {
                # unaligned container
            }
        }
        if (count($order) > 0) {
            $requests_config = $this->config->get('requests');
            $inactive = $requests_config['inactive'];
            $active = $requests_config['active'];
            foreach ($order as $id) {
                $list = array();
                $container = $containers[$id];
                $list[] = ucfirst($container['type']) . ' '  . $container['number'];
                while (isset($container['child'])) {
                    $container = $containers[$container['child']];
                    $list[] = "{$container['type']} {$container['number']}";
                    $request_target = "fa-request-target-$id";
                }<commit_msg>Check for parent attr before id in containers.<commit_after><?php
class ComponentModel extends Model
{
    protected $id;
    protected $subcomponents = array();
    private $component_id;
    private $basename;

    public function __construct($id, $component_id)
    {
        $this->id = $id;
        $this->component_id = $component_id;
        $this->basename = $id . '_' . $this->component_id . '.xml';
        $this->config = new Config();
        $component_file = $this->ppath() . DIRECTORY_SEPARATOR . $this->basename;
        if (file_exists($component_file)) {
          $this->xml = new SimpleXMLElement(file_get_contents($component_file));
        }
        $contents_config = $this->config->get('contents');
        foreach ($this->xpath($contents_config['component']) as $c) {
            $cattrs = $c->attributes();
            $cid = $cattrs['id'];
            $this->subcomponents[] = new ComponentModel($id, $cid);
        }
    }

    public function title()
    {
        $pieces = array();
        if (count($this->xpath('did/unitdate')) > 0) {
            $pieces = array_merge(
                $pieces,
                $this->xpath('did/unittitle'),
                $this->xpath('did/unitdate')
            );
        }
        else {
            $pieces = array_merge($pieces, $this->xpath('did/unittitle'));
        }
        $results = array();
        foreach ($pieces as $piece) {
            $results[] = dom_import_simplexml($piece)->textContent;
        }
        return implode(', ', $results);
    }

    public function container_lists()
    {
        $container_lists = array();
        $order = array();
        $containers = array();
        $contents_config = $this->config->get('contents');
        foreach ($this->xpath($contents_config['container']) as $container) {
            $attributes = $container->attributes();
            if (isset($attributes['parent'])) {
                # subordinate container
                $parent = trim($attributes['parent']);
                $type = strtolower($attributes['type']);
                $number = (string)$container;
                $containers["child-$parent"] = array(
                    'id' => "child-$parent",
                    'type' => $type,
                    'number' => $number,
                    'child' => null,
                );
                $containers[$parent]['child'] = "child-$parent";
            }
            elseif (isset($attributes['id'])) {
                # base container
                $id = trim($attributes['id']);
                $type = strtolower($attributes['type']);
                $number = (string)$container;
                $order[] = $id;
                $containers[$id] = array(
                    'id' => $id,
                    'type' => $type,
                    'number' => $number,
                    'child' => null,
                );
            }
            else {
                # unaligned container
            }
        }
        if (count($order) > 0) {
            $requests_config = $this->config->get('requests');
            $inactive = $requests_config['inactive'];
            $active = $requests_config['active'];
            foreach ($order as $id) {
                $list = array();
                $container = $containers[$id];
                $list[] = ucfirst($container['type']) . ' '  . $container['number'];
                while (isset($container['child'])) {
                    $container = $containers[$container['child']];
                    $list[] = "{$container['type']} {$container['number']}";
                    $request_target = "fa-request-target-$id";
                }
{'fraction_non_alphanumeric': 0.1601150527325024, 'fraction_numerical': 0.0005478701547733187, 'mean_word_length': 1.6313513513513513, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 71, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3492005', 'n_tokens_mistral': 1974, 'n_tokens_neox': 1886, 'n_words': 353}