<commit_before><?php
    class DistributionGraphTool
    {
        private $__user = false;
        private $__json = array();
        private $__eventModel = false;

        public function construct($eventModel, $servers, $user, $extended_view=0)
        {
            $this->__eventModel = $eventModel;
            $this->__serverList = $servers;
            $this->__organisationModel = $eventModel->Orgc;
            $this->__user = $user;
            $this->__json = array();
            $this->__extended_view = $extended_view;

            // construct distribution info
            $this->__json['distributionInfo'] = array();
            $sgs = $this->__eventModel->SharingGroup->fetchAllAuthorised($this->__user, 'simplified', 1);
            $this->__json['allSharingGroup'] = h($sgs);
            $distributionLevels = $this->__eventModel->distributionLevels;
            foreach ($distributionLevels as $key => $value) {
                $this->__json['distributionInfo'][$key] = array('key' => h($value), 'desc' => h($this->__eventModel->distributionDescriptions[$key]['formdesc']), 'value' => h($key));
            }
            $this->__json['distributionInfo'][5] = ""; // inherit event. Will be deleted afterward

            return true;
        }

        private function __extract_sharing_groups_names($sharingArray)
        {
            return $sharingArray['name'];
        }

        private function __fetchAndAddDistributionInfo($elem)
        {
            $distributionLevel = $elem['distribution'];

            if ($distributionLevel == 5) { // inherit -> convert it to the event distribution level
                $elem['distribution'] = $this->__eventDistribution;
                $this->__fetchAndAddDistributionInfo($elem);
            } elseif ($distributionLevel == 4) { // sharing group
                if (isset($elem['SharingGroup'])) {
                    $sg_name = $this->__extract_sharing_groups_names($elem['SharingGroup']);
                    $this->__addAdditionalDistributionInfo($distributionLevel, $sg_name);
                } elseif ($this->__eventDistribution == 4) { // event is distributed for sg
                    $sg_name = $this->__eventSharingGroupName;
                    $this->__addAdditionalDistributionInfo($distributionLevel, $sg_name);
                }
            } else {
                return false;
            }
            return true;
        }

        private function __addAdditionalDistributionInfo($distributionLevel, $data)
        {
            if (empty($this->__json['additionalDistributionInfo'][$distributionLevel])) {
                $this->__json['additionalDistributionInfo'][$distributionLevel] = array();
            }
            $this->__json['additionalDistributionInfo'][$distributionLevel][h($data)] = 0; // set-alike
            if ($distributionLevel == 4) {
                if (!isset($this->__json['sharingGroupRepartition'][h($data)])) {
                    $this->__json['sharingGroupRepartition'][h($data)] = 0;
                }
                $this->__json['sharingGroupRepartition'][h($data)]++;
            }
        }

        private function __addOtherDistributionInfo()
        {
            // all comm
            $this->__addAdditionalDistributionInfo(3, "This community"); // add current community
            $this->__addAdditionalDistributionInfo(3, "All other communities"); // add current community

            // connected
            $servers = $this->__serverList;
            $this->__addAdditionalDistributionInfo(2, "This community"); // add current community
            foreach ($servers as $server) {
                $this->__addAdditionalDistributionInfo(2, $server);
            }

            // community
            $orgs = $this->__organisationModel->find('list', array(
                'fields' => array('name'),
            ));
            $thisOrg = $this->__user['Organisation']['name'];
            $this->__addAdditionalDistributionInfo(1, $thisOrg); // add current community
            foreach ($orgs as $org) {
                if ($thisOrg != $org) {
                    $this->__addAdditionalDistributionInfo(1, $org);
                }
            }

            // org only
            $thisOrg = $this->__user['Organisation']['name'];
            $this->__addAdditionalDistributionInfo(0, $thisOrg); // add current community
        }

        private function __get_event($id)
        {
            $fullevent = $this->__eventModel->fetchEvent($this->__user, array('eventid' => $id, 'flatten' => 0, 'includeTagRelations' => 1, 'extended' => $this->__extended_view));
            $event = array();
            if (empty($fullevent)) {
                return $event;<commit_msg>chg: [distributionNetwork] Filter out organisations not being marked as local. Fix #4568<commit_after><?php
    class DistributionGraphTool
    {
        private $__user = false;
        private $__json = array();
        private $__eventModel = false;

        public function construct($eventModel, $servers, $user, $extended_view=0)
        {
            $this->__eventModel = $eventModel;
            $this->__serverList = $servers;
            $this->__organisationModel = $eventModel->Orgc;
            $this->__user = $user;
            $this->__json = array();
            $this->__extended_view = $extended_view;

            // construct distribution info
            $this->__json['distributionInfo'] = array();
            $sgs = $this->__eventModel->SharingGroup->fetchAllAuthorised($this->__user, 'simplified', 1);
            $this->__json['allSharingGroup'] = h($sgs);
            $distributionLevels = $this->__eventModel->distributionLevels;
            foreach ($distributionLevels as $key => $value) {
                $this->__json['distributionInfo'][$key] = array('key' => h($value), 'desc' => h($this->__eventModel->distributionDescriptions[$key]['formdesc']), 'value' => h($key));
            }
            $this->__json['distributionInfo'][5] = ""; // inherit event. Will be deleted afterward

            return true;
        }

        private function __extract_sharing_groups_names($sharingArray)
        {
            return $sharingArray['name'];
        }

        private function __fetchAndAddDistributionInfo($elem)
        {
            $distributionLevel = $elem['distribution'];

            if ($distributionLevel == 5) { // inherit -> convert it to the event distribution level
                $elem['distribution'] = $this->__eventDistribution;
                $this->__fetchAndAddDistributionInfo($elem);
            } elseif ($distributionLevel == 4) { // sharing group
                if (isset($elem['SharingGroup'])) {
                    $sg_name = $this->__extract_sharing_groups_names($elem['SharingGroup']);
                    $this->__addAdditionalDistributionInfo($distributionLevel, $sg_name);
                } elseif ($this->__eventDistribution == 4) { // event is distributed for sg
                    $sg_name = $this->__eventSharingGroupName;
                    $this->__addAdditionalDistributionInfo($distributionLevel, $sg_name);
                }
            } else {
                return false;
            }
            return true;
        }

        private function __addAdditionalDistributionInfo($distributionLevel, $data)
        {
            if (empty($this->__json['additionalDistributionInfo'][$distributionLevel])) {
                $this->__json['additionalDistributionInfo'][$distributionLevel] = array();
            }
            $this->__json['additionalDistributionInfo'][$distributionLevel][h($data)] = 0; // set-alike
            if ($distributionLevel == 4) {
                if (!isset($this->__json['sharingGroupRepartition'][h($data)])) {
                    $this->__json['sharingGroupRepartition'][h($data)] = 0;
                }
                $this->__json['sharingGroupRepartition'][h($data)]++;
            }
        }

        private function __addOtherDistributionInfo()
        {
            // all comm
            $this->__addAdditionalDistributionInfo(3, "This community"); // add current community
            $this->__addAdditionalDistributionInfo(3, "All other communities"); // add current community

            // connected
            $servers = $this->__serverList;
            $this->__addAdditionalDistributionInfo(2, "This community"); // add current community
            foreach ($servers as $server) {
                $this->__addAdditionalDistributionInfo(2, $server);
            }

            // community
            $orgs = $this->__organisationModel->find('list', array(
                'fields' => array('name'),
                'conditions' => array('local' => true)
            ));
            $thisOrg = $this->__user['Organisation']['name'];
            $this->__addAdditionalDistributionInfo(1, $thisOrg); // add current community
            foreach ($orgs as $org) {
                if ($thisOrg != $org) {
                    $this->__addAdditionalDistributionInfo(1, $org);
                }
            }

            // org only
            $thisOrg = $this->__user['Organisation']['name'];
            $this->__addAdditionalDistributionInfo(0, $thisOrg); // add current community
        }

        private function __get_event($id)
        {
            $fullevent = $this->__eventModel->fetchEvent($this->__user, array('eventid' => $id, 'flatten' => 0, 'includeTagRelations' => 1, 'extended' => $this->__extended_view));
            $event = array();
            if (empty($fullevent)) {
                return $event;
{'fraction_non_alphanumeric': 0.13607924921793535, 'fraction_numerical': 0.004171011470281543, 'mean_word_length': 2.10589378238342, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 121, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '4877811', 'n_tokens_mistral': 2584, 'n_tokens_neox': 2369, 'n_words': 449}