Get profiles grouped by account and webproperty

TODO Handle "(403) User does not have any Google Analytics account."

@return array
35
protected function getGroupedProfiles()
    {
        $this->analytics->requireAuthentication();

        $groupedProfiles = [];
        $accounts = $this->analytics->management_accounts->listManagementAccounts();
        foreach ($accounts as $account) {
            $groupedProfiles[$account->getId()]['label'] = $account->getName();
            $groupedProfiles[$account->getId()]['items'] = [];
        }
        $webproperties = $this->analytics->management_webproperties->listManagementWebproperties('~all');
        $webpropertiesById = [];
        foreach ($webproperties as $webproperty) {
            $webpropertiesById[$webproperty->getId()] = $webproperty;
        }
        $profiles = $this->analytics->management_profiles->listManagementProfiles('~all', '~all');
        foreach ($profiles as $profile) {
            if (isset($webpropertiesById[$profile->getWebpropertyId()])) {
                $webproperty = $webpropertiesById[$profile->getWebpropertyId()];
                $groupedProfiles[$profile->getAccountId()]['items'][$profile->getId()] = ['label' => $webproperty->getName() . ' > ' . $profile->getName(), 'value' => $profile->getId()];
            }
        }

        return $groupedProfiles;
    }
372601
public function getCustomerGroups()
    {
        $groups = [];

        /** @var GroupInterface $customerGroup */
        foreach ($this->customerGroupCollection->getItems() as $customerGroup) {
            $group               = [];
            $group['id']         = $customerGroup->getId();
            $group['name']       = $customerGroup->getCode();
            $group['is_default'] = intval($customerGroup->getId() == GroupInterface::NOT_LOGGED_IN_ID);

            $matchingTaxClasses =
                $this->taxCollection->getItemsByColumnValue('class_id', $customerGroup->getTaxClassId());

            if (count($matchingTaxClasses)) {
                $group['customer_tax_class_key'] = array_pop($matchingTaxClasses)->getClassName();
            }

            $groups[] = $group;
        }

        return $groups;
    }
787682
public function getAccountsTypes()
  {
    //Is Group: Further accounts can be made under Groups, but entries can be made against non-Groups
    $accountTypes = array();

    $this->AccountType->byOrganization($this->AuthenticationManager->getCurrentUserOrganizationId())->each(function($AccountType) use (&$accountTypes)
    {
      array_push($accountTypes, array('label'=> $AccountType->name, 'value'=>$AccountType->id));
    });

    return $accountTypes;
  }
64783
public function get_groups() {
		$groups = array(
			array(
				'id'   => 'actions',
				'name' => __( 'Actions', 'icon-picker' ),
			),
			array(
				'id'   => 'currency',
				'name' => __( 'Currency', 'icon-picker' ),
			),
			array(
				'id'   => 'media',
				'name' => __( 'Media', 'icon-picker' ),
			),
			array(
				'id'   => 'misc',
				'name' => __( 'Misc.', 'icon-picker' ),
			),
			array(
				'id'   => 'places',
				'name' => __( 'Places', 'icon-picker' ),
			),
			array(
				'id'   => 'social',
				'name' => __( 'Social', 'icon-picker' ),
			),
		);

		/**
		 * Filter genericon groups
		 *
		 * @since 0.1.0
		 * @param array $groups Icon groups.
		 */
		$groups = apply_filters( 'icon_picker_genericon_groups', $groups );

		return $groups;
	}
732336
public function getUsersAge()
    {
        $period = $this->analyticsDuration();

        $data = Analytics::performQuery($period, 'ga:sessions',
            ['dimensions' => 'ga:userAgeBracket']);

        $labels = [];
        $datasets = [];
        $rows = $data->rows;
        if (is_null($rows)) {
            return ['labels' => [], 'datasets' => []];
        }
        foreach ($rows as $k => $item) {
            $labels[] = ucfirst($item[0]);
            $datasets[] = $item[1];
        }

        $datasets = [$this->getDataSet('Ages', $datasets, 0)];

        return ['labels' => $labels, 'datasets' => $datasets];
    }
480014
public function getAssignedMembers()
    {
        $members = $this->Users();
        $groups  = $this->Groups();

        // Can't merge instances of DataList so convert to something where we can
        $_members = ArrayList::create();
        $members->each(function ($item) use ($_members) {
            $_members->push($item);
        });

        $_groups = ArrayList::create();
        $groups->each(function ($item) use ($_groups) {
            $_groups->push($item);
        });

        foreach ($_groups as $group) {
            $_members->merge($group->Members());
        }

        $_members->removeDuplicates();
        return $_members;
    }
549033
function getUserProfile()
    {
        $this->api->curl_header = array(
            'Authorization: OAuth oauth_token='.$this->api->access_token,
        );
        $data = $this->api->get( "admin/rest/v1/me" );

        if ( ! isset( $data->key ) ){
            throw new Exception( "User profile request failed! {$this->providerId} returned an invalid response.", 6 );
        }

        $this->user->profile->identifier  = @ $data->key;
        $this->user->profile->firstName = @ $data->firstName;
        $this->user->profile->firstName = @ $data->firstName;
        $this->user->profile->displayName = @ $data->firstName.' '.$data->lastName;
        $this->user->profile->email = @ $data->email;

        $this->userAccounts = $data->accounts;

        return $this->user->profile;
    }
384773
public function getAllProfiles()
    {
        $profiles = [];

        $search = $this->repo->createSearch();
        $filter = new BoolQuery();
        $filter->add(new TermQuery('type', 'experiment'), BoolQuery::MUST_NOT);
        $topHitsAgg = new TopHitsAggregation('documents', 20);
        $termAgg = new TermsAggregation('profiles', 'profile.profile');
        $filterAgg = new FilterAggregation('filter', $filter);
        $termAgg->addAggregation($topHitsAgg);
        $filterAgg->addAggregation($termAgg);
        $search->addAggregation($filterAgg);

        $result = $this->repo->findDocuments($search);

        /** @var Setting $activeProfiles */
        $activeProfiles = $this->getValue($this->activeProfilesSettingName, []);

        /** @var AggregationValue $agg */
        foreach ($result->getAggregation('filter')->getAggregation('profiles') as $agg) {
            $settings = [];
            $docs = $agg->getAggregation('documents');
            foreach ($docs['hits']['hits'] as $doc) {
                $settings[] = $doc['_source']['name'];
            }
            $name = $agg->getValue('key');
            $profiles[] = [
                'active' => $activeProfiles ? in_array($agg->getValue('key'), (array)$activeProfiles) : false,
                'name' => $name,
                'settings' => implode(', ', $settings),
            ];
        }

        return $profiles;
    }
195849
public function getAccounts()
    {
        $connected = [];
        /** @var Social[] $accounts */
        $accounts = $this->hasMany(Social::className(), ['user_id' => 'id'])->all();
        /**
         * @var Social $account
         */
        foreach ($accounts as $account) {
            $connected[$account->provider] = $account;
        }

        return $connected;
    }
140271
public function getAccounts()
    {
        $accounts = [];
        $groups   = $this->rpc->query("listAccounts", [0]);
        foreach($groups as $account => $balance) {
            $accounts[] = $account;
        }
        
        return $accounts;
    }
107462
private function getInstagramProfile() : array
    {
        if (isset($this->cache->entry_data->ProfilePage[0]->graphql->user)) {
            $user = $this->cache->entry_data->ProfilePage[0]->graphql->user;
            return array(
                'name' => $user->full_name,
                'user_name' => $user->username,
                'profilepic_sd' => $user->profile_pic_url,
                'profilepic' => $user->profile_pic_url_hd,
                'biography' => $user->biography,
            );
        }
        return array();
    }
1079663
public function getMyProfiles() {
      $response = $this->client->request('get', 'getMyProfiles');
      return [
         'statusCode' => $response->getStatusCode(),
         'body' => $response->getBody()->getContents(),
      ];
   }
967929
public function getProfileSegments()
    {
        $profileSegments = $this
                    ->serviceHelper
                    ->getService()
                    ->management_segments
                    ->listManagementSegments()
                    ->items;

        $builtin = array();
        $own = array();
        foreach ($profileSegments as $segment) {
            if ($segment->type == 'BUILT_IN') {
                $builtin[] = array(
                        'name' => $segment->name,
                        'query' => $segment->segmentId,
                    );
            } else {
                $own[] = array(
                        'name' => $segment->name,
                        'query' => $segment->segmentId,
                    );
            }
        }

        return array('builtin' => $builtin, 'own' => $own);
    }
1177608
public function indexAction($user)
    {
        try {
            $profileUser = $this->repository->findOneByIdOrPublicUrl($user);
            $serializedUser = $this->userSerializer->serialize($profileUser, [Options::SERIALIZE_FACET]);

            return [
                'user' => $serializedUser,
                'facets' => $this->profileSerializer->serialize(),
                'parameters' => $this->parametersSerializer->serialize()['profile'],
            ];
        } catch (NoResultException $e) {
            throw new NotFoundHttpException('Page not found');
        }
    }
1114775
public function listProfiles() {
    $dirs = $this->config['profile.dirs'];
    $profiles = array();
    foreach ($dirs as $dir) {
      if (!is_dir($dir) || !is_readable($dir)) {
        continue;
      }
      $files = scandir($dir);
      foreach ($files as $file) {
        if (preg_match('/(.*)\.profile$/', $file, $m)) {
           $profiles[] = $m[1];
        }
      }
    }
    return $profiles;
  }
264964
public function getAllAccounts()
    {
        $accounts = array_merge($this->getAllUsers(), $this->getResellers(), $this->getAdmins());
        ksort($accounts);
        return $accounts;
    }
678488
public function getAdAccounts()
    {
        //Authentication
        $data = array(
            'username' => AD_BULK_IMPORT_USER,
            'password' => AD_BULK_IMPORT_PASSWORD
        );

        //Fetch index
        $index = $this->curl->request('POST', rtrim(AD_INTEGRATION_URL, "/") . '/user/index', $data, 'json',
            array('Content-Type: application/json'));

        //Validate json response
        if ($this->response::isJsonError($index) || !json_decode($index)) {
            return false;
        }

        //Check that no errors occured
        if (json_last_error() != JSON_ERROR_NONE) {
            error_log("Ad integration: Could not read index due to the fact that the response wasen't a valid json string.");
            exit;
        }

        //Return
        return array_map('strtolower', json_decode($index));
    }