public function Project::getProjects in GatherContent 8
Same name and namespace in other branches
- 8.3 src/DAO/Project.php \Drupal\gathercontent\DAO\Project::getProjects()
Fetch projects from GatherContent.
Return value
array Associative array of projects.
File
- src/
DAO/ Project.php, line 62
Class
Namespace
Drupal\gathercontent\DAOCode
public function getProjects() {
if (!$this->local) {
// @FIXME
$account = \Drupal::config('gathercontent.settings')
->get('gathercontent_account');
$account = unserialize($account);
$projects = array();
reset($account);
$account_id = key($account);
try {
$response = $this->client
->get('/projects?account_id=' . $account_id);
if ($response
->getStatusCode() === 200) {
$data = json_decode($response
->getBody());
foreach ($data->data as $project) {
if ($project->active) {
$projects[$project->id] = $project->name;
}
}
}
} catch (\Exception $e) {
drupal_set_message($e
->getMessage(), 'error');
\Drupal::logger('gathercontent')
->error($e
->getMessage(), array());
}
return $projects;
}
else {
drupal_set_message(t('Error occured, please contact your system administrator'), 'error');
\Drupal::logger('gathercontent')
->alert('Object Project created as local, but trying to reach remote data.', []);
}
}