You are here

public function Content::getContents in GatherContent 7.3

Get list of content.

Parameters

int $project_id: ID of project we want items from.

Return value

array Array with accounts.

File

includes/Content.inc, line 103
Contains GatherContent\Accont class.

Class

Content
Class Account.

Namespace

GatherContent

Code

public function getContents($project_id) {
  $accounts = array();
  try {
    $response = $this->client
      ->get('/items?project_id=' . $project_id);
    if ($response
      ->getStatusCode() === 200) {
      $data = json_decode($response
        ->getBody());
      $accounts = $data->data;
    }
    else {
      drupal_set_message(t("User with provided credentials wasn't found."), 'error');
    }
  } catch (\Exception $e) {
    if ($e instanceof RequestException) {
      $level = floor($e
        ->getResponse()
        ->getStatusCode() / 100);
      if ($level == '4' || $level == '5') {
        drupal_set_message(t('Some content could not be accessed in
        GatherContent and updated. This could be due to the Items being deleted
        in GatherContent or a change in module authentication details.'), 'error');
      }
      else {
        drupal_set_message($e
          ->getMessage(), 'error');
        watchdog('gathercontent', $e
          ->getMessage(), array(), WATCHDOG_ERROR);
      }
    }
    else {
      drupal_set_message($e
        ->getMessage(), 'error');
      watchdog('gathercontent', $e
        ->getMessage(), array(), WATCHDOG_ERROR);
    }
  }
  return $accounts;
}