Helper function for setcurrentOrganization

Change value to $newId in an array if the key is in the $keys array (as key) and value is $oldId

@param array $array
@param int $oldId
@param int $newId
@param array $keys
@return array
194464
protected function _changeIds($array, $oldId, $newId, $keys) {
        if (!is_array($array)) {
            return $array;
        }

        $matches = array_intersect_key($array, $keys);
        foreach($matches as $key => &$curId) {
            if ($curId == $oldId) {
                $array[$key] = $newId;
            }
        }

        return $array;
    }
452086
protected function mergeGroup(array $new, array $old)
    {
        $new['namespace'] = $this->formatNamespace($new, $old);

        $new['prefix'] = $this->formatPrefix($new, $old);

        foreach (['middleware', 'providers', 'scopes', 'before', 'after'] as $option) {
            $new[$option] = $this->formatArrayBasedOption($option, $new);
        }

        if (isset($new['domain'])) {
            unset($old['domain']);
        }

        if (isset($new['conditionalRequest'])) {
            unset($old['conditionalRequest']);
        }

        if (isset($new['uses'])) {
            $new['uses'] = $this->formatUses($new, $old);
        }

        $new['where'] = array_merge(Arr::get($old, 'where', []), Arr::get($new, 'where', []));

        if (isset($old['as'])) {
            $new['as'] = trim($old['as'].'.'.Arr::get($new, 'as', ''), '.');
        }

        return array_merge_recursive(array_except($old, ['namespace', 'prefix', 'where', 'as']), $new);
    }
973219
private function getIn(array $array, array $keys, $default = null)
    {
        if (!$keys) {
            return $array;
        }

        // This is a micro-optimization, it is fast for non-nested keys, but fails for null values
        if (\count($keys) === 1 && isset($array[$keys[0]])) {
            return $array[$keys[0]];
        }

        $current = $array;
        foreach ($keys as $key) {
            if (!\is_array($current) || !\array_key_exists($key, $current)) {
                return $default;
            }

            $current = $current[$key];
        }

        return $current;
    }
320386
public static function merge(array $old, array $new)
    {
        foreach ($new as $key => $value) {
            if (isset($old[$key]) && is_array($old[$key]) && is_array($value)) {
                $old[$key] = self::merge($old[$key], $value);
            } else {
                $old[$key] = $value;
            }
        }

        return $old;
    }
1075216
public function set($newvalues)
    {
        $array = $this->toArray();
        foreach ($newvalues as $key => $value) {
            $this->$key = $value;
        }
        return $this;
    }
634246
public static function remapArrayKeys(&$array, $mappingTable) {
		if (is_array($mappingTable)) {
			foreach ($mappingTable as $old => $new) {
				if ($new && isset($array[$old])) {
					$array[$new] = $array[$old];
					unset ($array[$old]);
				}
			}
		}
	}
911206
public function changeKeys($original, $new, &$array)
    {
        foreach ($array as $k => $v) {
            $res[$k === $original ? $new : $k] = $v;
        }
        return $res;
    }
125348
public function set(array $array = array(), $preserveIds = false)
    {
        if ($this->hasLimit() and ($this->_nbByPage >= 0 and count($array) > $this->_nbByPage)) {
            trigger_error(
                __CLASS__ . '::' . __FUNCTION__ . '() : Max number of elements by page reached',
                E_USER_ERROR
            );
            return false;
        }

        if ($preserveIds) {
            if ($this->_keyGetter !== null) {
                $elementsWithNewKey = array();
                foreach ($array as $element) {
                    $key = $element->{$this->_keyGetter}();
                    $elementsWithNewKey[$key] = $element;
                }
                $this->_elements = $elementsWithNewKey;
            } else {
                $this->_elements = $array;
            }
        } else {
            $this->_elements = array_values($array);
        }

        $this->_count = count($this->_elements);
    }
1174535
function only(array $keys) {
        $new = array();
        foreach($this->data as $key => $val) {
            if(\in_array($key, $keys, true)) {
                $new[$key] = $val;
            }
        }
        
        return (new self($new));
    }
462127
public static function columnToKey($array, $column, $keepOld = true)
    {
        $newArray = [];
        foreach($array as $k => $row)
        {
            $key = $row[$column];
            if(!$keepOld)
            {
                unset($row[$column]);
            }
            $newArray[$key] = $row;
        }
        return $newArray;
    }
948870
public static function set(array &$array, string $key, $value)
    {
        foreach (\explode('.', $key) as $k) {
            if (!isset($array[$k]) || !\is_array($array[$k])) {
                $array[$k] = [];
            }
            $array = &$array[$k];
        }

        $array = $value;
    }
14889
public function set(array $array, $keys, $value)
    {
        $keys = $this->parseKeys($keys);

        if ($keys) {
            $key = array_shift($keys);

            // This is the last key we've shifted
            if (!$keys) {
                $array[$key] = $value;
            } else {
                // There are more keys so this should be an array
                if (!isset($array[$key]) || !is_array($array[$key])) {
                    $array[$key] = array();
                }
                $array[$key] = $this->set(
                    $array[$key], $keys, $value
                );
            }
        }

        return $array;
    }
407663
private function arrayReplaceRecursiveValue(&$array, $parameters) {
        foreach ($array as $key => $value) {
            // create new key in $array, if it is empty or not an array
            if (!isset($array[$key]) || (isset($array[$key]) && !is_array($array[$key]))) {
                $array[$key] = array();
            }

            // overwrite the value in the base array
            if (is_array($value)) {
                $value = $this->arrayReplaceRecursiveValue($array[$key], $parameters);
            } else {
                $value = $this->parseParameter($value, $parameters);
            }
            $array[$key] = $value;
        }
        return $array;
    }
854059
protected function auditUpdatedAttributes(array &$old, array &$new)
    {
        foreach ($this->getDirty() as $attribute => $value) {
            if ($this->isAttributeAuditable($attribute)) {
                $old[$attribute] = array_get($this->original, $attribute);
                $new[$attribute] = array_get($this->attributes, $attribute);
            }
        }

        if ($this->shouldDynamicTableExist()) {
            foreach ($this->properties->getDirty() as $attribute => $value) {
                if (! in_array($attribute, $this->auditableExclusions)) {
                    $old[$this->type->identifier][$attribute] = array_get($this->properties->getOriginal(), $attribute);
                    $new[$this->type->identifier][$attribute] = array_get($this->properties->getAttributes(), $attribute);
                }
            }
        }
    }
1062762
public function setCurrentOrganization($organization)
    {
        if (!($organization instanceof \Gems_User_Organization)) {
            $organization = $this->userLoader->getOrganization($organization);
        }

        $organizationId    = $organization->getId();
        $oldOrganizationId = $this->getCurrentOrganizationId();

        if ($organizationId != $oldOrganizationId) {
            $this->_setVar('user_organization_id', $organizationId);

            if ($this->isCurrentUser()) {
                $this->getCurrentOrganization()->setAsCurrentOrganization();

                if ($organization->canHaveRespondents()) {
                    $usedOrganizationId = $organizationId;
                } else {
                    $usedOrganizationId = null;
                }

                // Now update the requestcache to change the oldOrgId to the new orgId
                // Don't do it when the oldOrgId doesn't match
                $keysArray = array_flip($this->possibleOrgIds);
                $requestCache = $this->session->requestCache;
                if ($requestCache) {
                    foreach ($requestCache as $key => &$elements) {
                        $elements = $this->_changeIds($elements, $oldOrganizationId, $usedOrganizationId, $keysArray);
                    }
                    $this->session->requestCache = $requestCache;
                }

                // $searchSession &= $_SESSION['ModelSnippetActionAbstract_getSearchData'];
                $searchSession = new \Zend_Session_Namespace('ModelSnippetActionAbstract_getSearchData');
                foreach ($searchSession as $id => $data) {
                    $searchSession->$id = $this->_changeIds($data, $oldOrganizationId, $usedOrganizationId, $keysArray);
                }
            }
        }

        return $this;
    }
406596
protected function remapRecursively(&$data, $oldKey, $newKey)
    {
        $data->loopThrough(function ($index, $value) use ($data, $oldKey, $newKey) {
            $matches = $this->checkRegexRecursively($value, $oldKey, $index);
            foreach ($matches as $match) {
                $this->remap($data, $match[0], $this->getRegexProperty($match, $newKey));
            }
        });
    }
253006
public final function setIds(array $ids): void
    {
        foreach ($ids as $id) {
            $this->ids[] = (int) $id;
        }
    }