Create a friendly, formatted groups array

@param array $memberships Array of memberships to create a friendly array for.
@return array An array of friendly group names.
770913
protected function _cleanGroups($memberships)
    {
        $groups = [];
        foreach ($memberships as $group) {
            $parts = explode(',', $group);

            foreach ($parts as $part) {
                if (substr($part, 0, 3) == 'CN=') {
                    $groups[] = substr($part, 3);
                    break;
                }
            }
        }

        return $groups;
    }
1211487
protected function buildJoin(
        /*# string */ $prefix,
        array $settings
    )/*# : string */ {
        $string = '';
        $clause = &$this->getClause('JOIN');
        foreach ($clause as $cls) {
            $result = [];
            $prefix = $cls[1]; // join type
            $result[] = $this->buildJoinTable($cls, $settings); // join table
            if (!empty($cls[4])) {
                $result[] = $this->buildJoinOn($cls, $settings);
            }
            $string .= $this->joinClause($prefix, '', $result, $settings);
        }
        return $string;
    }
1238879
protected function getMembers() {
        if (!$this->_members) {
            $this->_members = new MemberList(
                $this->version,
                $this->solution['serviceSid'],
                $this->solution['sid']
            );
        }

        return $this->_members;
    }
699582
public function findUsersByRolesIncludingGroups(
        array $roles
    ) {
        //very slow otherwise. If we want to do it properly, the OR clause won't do it.
        //we must use UNION wich is not supported by Doctrine
        $dql = '
            SELECT u, r1, ws
            From Claroline\\CoreBundle\\Entity\\User u
            LEFT JOIN u.roles r1
            LEFT JOIN u.personalWorkspace ws
            WHERE r1 in (:roles)
            AND u.isRemoved = false
            ORDER BY u.lastName, u.firstName ASC
        ';

        $query = $this->_em->createQuery($dql);
        $query->setParameter('roles', $roles);

        $resA = $query->getResult();
        $resA = $resA ? $resA : [];

        $dql = '
            SELECT u, g, r2, ws
            From Claroline\\CoreBundle\\Entity\\User u
            LEFT JOIN u.personalWorkspace ws
            LEFT JOIN u.groups g
            LEFT JOIN g.roles r2
            WHERE r2 in (:roles)
            AND u.isRemoved = false
            ORDER BY u.lastName, u.firstName ASC
        ';

        $query = $this->_em->createQuery($dql);
        $query->setParameter('roles', $roles);

        $resB = $query->getResult();
        $resB = $resB ? $resB : [];

        return array_unique(array_merge($resA, $resB));
    }
92092
protected function buildJoinExpressions(array $joins)
	{
		$joinExpressions = array();
		foreach($joins as $joins)
		{
			$joinExpressions[] = 'LEFT JOIN ' . $joins['table'] . ' ' . $joins['tableAlias']
					. ' ON ' . $joins['onClause'];
		}
		return $joinExpressions;
	}
1226980
public static function CategorizeUsersList($users) {
        $list = array();
        if (is_array($users) && count($users) > 0) {
            foreach ($users as $user) {
                $userType = $user->user_type();
                $list[$userType][] = $user;
            }
        }
        return $list;
    }
103772
public function getAssociatedByType($types = [])
    {
        $return = [];

        $table = $this->_table();
        foreach ($table->associations()->keys() as $association) {
            $associationClass = $table->associations()->get($association);
            if (!in_array($associationClass->type(), $types)) {
                continue;
            }

            $return[$associationClass->getName()] = $associationClass;
        }

        return $return;
    }
49025
public static function create(array $tokens) {
        HashMap::assert($tokens, 'tokens');

        $columns = array_map(function($token) {
            $segments = explode('=', $token['base_expr']);
            return trim($segments[0]);
        }, $tokens['SET']);

        $values = array_map(function($token) {
            $segments = explode('=', $token['base_expr']);
            return Value::create(trim($segments[1]));
        }, $tokens['SET']);

        return array_combine($columns, $values);
    }
288308
public function niceNames($groups)
    {
        $groupNames = [];

        if (is_array($groups) && count($groups) > 0) {
            foreach ($groups as $group) {
                $explodedDn = $this->connection->explodeDn($group);

                // Assuming the zero key is the CN
                $groupNames[] = $explodedDn[0];
            }
        } elseif (is_string($groups)) {
            // If there's a single entry, groups will be a string
            $explodedDn = $this->connection->explodeDn($groups);

            $groupNames[] = $explodedDn[0];
        }

        return $groupNames;
    }
760815
public function getMembershipTypes() {
    $types = [];
    $membership_ids = $this->queryFactory->get('node')
      ->condition('type', 'membership')
      ->condition('status', 1)
      ->execute();

    if (!$membership_ids) {
      return $types;
    }

    $storage = $this->entityTypeManager->getStorage('node');
    $builder = $this->entityTypeManager->getViewBuilder('node');
    $memberships = $storage->loadMultiple($membership_ids);

    foreach ($memberships as $membership) {
      $membership_id = $membership->id();
      $types[$membership_id] = [
        'title' => $membership->title->value,
        'description' => $builder->view($membership, 'calc_preview'),
      ];
    }

    return $types;
  }
57578
public static function create_groupings($groupings) {
        global $CFG, $DB;
        require_once("$CFG->dirroot/group/lib.php");

        $params = self::validate_parameters(self::create_groupings_parameters(), array('groupings'=>$groupings));

        $transaction = $DB->start_delegated_transaction();

        $groupings = array();

        foreach ($params['groupings'] as $grouping) {
            $grouping = (object)$grouping;

            if (trim($grouping->name) == '') {
                throw new invalid_parameter_exception('Invalid grouping name');
            }
            if ($DB->count_records('groupings', array('courseid'=>$grouping->courseid, 'name'=>$grouping->name))) {
                throw new invalid_parameter_exception('Grouping with the same name already exists in the course');
            }

            // Now security checks            .
            $context = context_course::instance($grouping->courseid);
            try {
                self::validate_context($context);
            } catch (Exception $e) {
                $exceptionparam = new stdClass();
                $exceptionparam->message = $e->getMessage();
                $exceptionparam->courseid = $grouping->courseid;
                throw new moodle_exception('errorcoursecontextnotvalid' , 'webservice', '', $exceptionparam);
            }
            require_capability('moodle/course:managegroups', $context);

            $grouping->descriptionformat = external_validate_format($grouping->descriptionformat);

            // Finally create the grouping.
            $grouping->id = groups_create_grouping($grouping);
            $groupings[] = (array)$grouping;
        }

        $transaction->allow_commit();

        return $groupings;
    }
1340520
public function listMemberships($organization = '')
    {
        $contents = $this
            ->call('GET', implode('/', [self::ORGANIZATION_RESOURCE, $this->getOrganizationName($organization), 'memberships']))
            ->getBody()
            ->getContents()
        ;

        $membership = Membership::createFromJsonResponse($contents);
        if (!\is_array($membership)) {
            throw new \RuntimeException('Something went wrong, return was not array, but should be');
        }

        return $membership;
    }
111630
public function getAsGroupedArray(): array
    {
        $result = array();

        foreach ($this->_groups as $groupName => $memberKeys) {
            $members = array();

            foreach ($memberKeys as $key) {
                $members[$key] = $this->getFieldAsArray($key);
            }

            $result[$groupName] = array(
                'group_name' => $groupName,
                'group_caption' => $this->_('group_' . $groupName),
                'fields' => $members
            );
        }

        return $result;
    }
803475
public static function namesByType(array $types)
    {
        $names = array();

        foreach ($types as $type) {
            $names[] = self::nameByType($type);
        }

        return $names;
    }
336464
public function setMemberList(array $members)
    {
        $memberLists = [];
        foreach ($members as $key => $value) {
            $memberLists[] = ['Member_Account' => $key, 'Role' => $value];
        }
        $this->setParameter('MemberList', $memberLists);
        return $this;
    }
198993
protected function buildJoinOn(array $cls, array $settings)/*# : string */
    {
        $res = ['ON'];
        $on = $cls[4];
        if (is_string($on)) { // ON string
            $res[] = $on;
        } elseif (is_object($on)) { // ON is an object
            $res[] = $this->quoteItem($on, $settings);
        } else { // common on
            $res[] = $this->quote( // left
                $this->getFirstTableAlias($on[0]) . $on[0],
                $settings
            );
            $res[] = $on[1]; // operator
            $res[] = $this->quote( // right
                $this->getSecondTableAlias($cls, $on[2]) . $on[2],
                $settings
            );
        }
        return join(' ', $res);
    }
618516
public function FormatFromSettings($member = null)
    {
        if (!$member) {
            $member = Security::getCurrentUser();
        }

        // Fall back to nice
        if (!$member) {
            return $this->Nice();
        }

        // Get user format
        return $this->Format($member->getDateFormat(), $member->getLocale());
    }