You are here

public function Project::getProjectObjects in GatherContent 7.3

Fetch projects from GatherContent.

Return value

array Associative array of projects.

File

includes/Project.inc, line 99

Class

Project

Namespace

GatherContent

Code

public function getProjectObjects() {
  if (!$this->local) {
    $account = variable_get('gathercontent_account', array());
    $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;
          }
        }
      }
    } catch (\Exception $e) {
      drupal_set_message($e
        ->getMessage(), 'error');
      watchdog('gathercontent', $e
        ->getMessage(), array(), WATCHDOG_ERROR);
    }
    return $projects;
  }
  else {
    drupal_set_message(t('Error occured, please contact your system administrator'), 'error');
    watchdog('gathercontent', 'Object Project created as local, but trying to reach remote data.', NULL, WATCHDOG_ALERT);
  }
}