You are here

function PMPAPIDrupalPull::pullDocs in Public Media Platform API Integration 7

Pulls docs from the PMP

Parameters

array $options: PMP query parameters

Return value

object The full PMP object.

File

pmpapi_pull/classes/PMPAPIDrupalPull.php, line 51
Contains PMPAPIDrupalPull.

Class

PMPAPIDrupalPull
Turns PMP hypermedia docs in Drupal entities.

Code

function pullDocs($options, $context = NULL) {
  $this
    ->pull($options);
  $docs = array();
  if (empty($this->errors) && !empty($this->query->results->docs)) {
    foreach ($this->query->results->docs as $doc) {

      // Only save doc if it hasn't already been pulled (or pushed).
      // pmpapi_updates module will take care of updates
      if (!pmpapi_get_eid_from_guid($doc->attributes->guid)) {
        $doc->context = $context;
        $docs[] = $doc;
      }
    }
    if (!empty($docs)) {
      drupal_alter('pmpapi_pull_docs_prepare', $docs);
      foreach ($docs as $doc) {
        $this
          ->saveEntity($doc);
      }
    }
  }
  else {
    drupal_set_message(t('No collection could be found in the PMP with this guid.'), 'warning');
  }
}