You are here

function pmpapi_query_tools_execute_queries in Public Media Platform API Integration 7

Executes all saved queries.

1 call to pmpapi_query_tools_execute_queries()
pmpapi_query_tools_cron in pmpapi_query_tools/pmpapi_query_tools.module
Implements hook_cron().

File

pmpapi_query_tools/pmpapi_query_tools.module, line 142
Allows admins to build, save, and execute PMP queries

Code

function pmpapi_query_tools_execute_queries() {
  foreach (pmpapi_query_tools_get_queries() as $query => $options) {

    // Prep options as PMP query parameters
    // See https://github.com/publicmediaplatform/pmpdocs/wiki/Querying-the-API
    // ; = boolean OR
    // : = boolean AND
    // creator
    $creators = array();
    foreach ($options['creator'] as $i => $creator) {
      if ($creator) {
        $creators[] = $i;
      }
    }
    if ($creators) {
      $options['creator'] = implode(';', $creators);
    }

    // profile
    $profiles = array();
    foreach ($options['profile'] as $i => $profile) {
      if ($profile) {
        $profiles[] = $i;
      }
    }
    if ($profiles) {
      $options['profile'] = implode(';', $profiles);
    }

    // tag
    if (!empty($options['tag'])) {
      $tags = explode(' ', $options['tag']);
      $options['tag'] = implode(';', $tags);
    }

    // clear out empty values
    foreach ($options as $i => $value) {
      if (!$value) {
        unset($options[$i]);
      }
    }
    drupal_alter('pmpapi_query_tools_query_pre_execute', $options, $query);
    $context = array(
      'pmpapi_query_tools_query' => $query,
    );
    $pmp = new PMPAPIDrupalPull(FALSE);
    $pmp
      ->pullDocs($options, $context);
  }
}