You are here

public static function GatherContentPages::getPages in GatherContent 7

Get pages from GatherContent for a given project, and order them by parent.

Parameters

string $project_id: The project to fetch pages for.

Return value

array $pages The project's pages, ordered by their parent page.

1 call to GatherContentPages::getPages()
gathercontent_import_pages in ./gathercontent.module
Import wizard step 3: Import pages.

File

./gathercontent_pages.inc, line 68
Class to fetch pages from GatherContent and turn them into Drupal nodes.

Class

GatherContentPages
@file Class to fetch pages from GatherContent and turn them into Drupal nodes.

Code

public static function getPages($project_id) {
  $gathercontent_pages = gathercontent_get_command('get_pages_by_project', array(
    'id' => $project_id,
  ));
  if (!isset($project_id)) {
    drupal_set_message(t('Please select a GatherContent project <a href="/admin/config/content/gathercontent/settings">here</a> before continuing.'), 'warning');
  }
  else {
    $parents = array();
    $pages = array();

    // Populate $parents with parent pages ...
    foreach ($gathercontent_pages->pages as $page) {

      // Exclude 'meta' pages.
      if ($page->state != 'meta') {
        $parent_id = $page->parent_id;
        $parents[$parent_id][$page->id] = $page;
      }
    }

    // ... then loop through $parents[0] (since this contains all
    // the parent ids) and add child pages.
    if (isset($parents[0])) {
      foreach ($parents[0] as $id => $page) {
        $pages[$id] = $page;
        $pages[$id]->children = GatherContentPages::sortRecursive($parents, $id);
      }
    }
    return $pages;
  }
}