public function loadForm()
{
$this->form = new Form('settings');
// we don't even have a auth config file yet, let the user upload it
if ($this->get('fork.settings')->get($this->getModule(), 'certificate') === null) {
$this->form->addFile('certificate');
$this->form->addtext('email');
return;
}
// we are authenticated! Let's see which account the user wants to use
if ($this->get('fork.settings')->get($this->getModule(), 'account') === null) {
$analytics = $this->get('analytics.google_analytics_service');
try {
$accounts = $analytics->management_accounts->listManagementAccounts();
} catch (Google_Service_Exception $e) {
$this->tpl->assign('email', $this->get('fork.settings')->get($this->getModule(), 'email'));
return $this->tpl->assign('noAccounts', true);
}
$accountsForDropdown = array();
foreach ($accounts->getItems() as $account) {
$accountsForDropdown[$account->getId()] = $account->getName();
}
$this->form->addDropdown('account', $accountsForDropdown);
return;
}
// we have an account, but don't know which property to track
if ($this->get('fork.settings')->get($this->getModule(), 'web_property_id') === null) {
$analytics = $this->get('analytics.google_analytics_service');
$properties = $analytics->management_webproperties->listManagementWebproperties($this->get('fork.settings')->get($this->getModule(), 'account'));
$propertiesForDropdown = array();
foreach ($properties->getItems() as $property) {
$propertiesForDropdown[$property->getId()] = $property->getName();
}
$this->form->addDropdown('web_property_id', $propertiesForDropdown);
return;
}
// we have an account, but don't know which property to track
if ($this->get('fork.settings')->get($this->getModule(), 'profile') === null) {
$analytics = $this->get('analytics.google_analytics_service');
$profiles = $analytics->management_profiles->listManagementProfiles($this->get('fork.settings')->get($this->getModule(), 'account'), $this->get('fork.settings')->get($this->getModule(), 'web_property_id'));
$profilesForDropdown = array();
foreach ($profiles->getItems() as $property) {
$profilesForDropdown[$property->getId()] = $property->getName();
}
$this->form->addDropdown('profile', $profilesForDropdown);
return;
}
}