You are here

function _sheetnode_google_import_fetch in Sheetnode 7.2

Same name and namespace in other branches
  1. 6 modules/sheetnode_google/sheetnode_google.import.inc \_sheetnode_google_import_fetch()
  2. 7 modules/sheetnode_google/sheetnode_google.import.inc \_sheetnode_google_import_fetch()

Internal google import fetch.

1 string reference to '_sheetnode_google_import_fetch'
_sheetnode_google_import_form in modules/sheetnode_google/sheetnode_google.import.inc
Helper function for import form.

File

modules/sheetnode_google/sheetnode_google.import.inc, line 45
Extension to sheetnode for importing from Google sheets.

Code

function _sheetnode_google_import_fetch($form, $form_state) {
  $options = array();
  if (!empty($form_state['values'])) {
    try {
      $service = Zend_Gdata_Spreadsheets::AUTH_SERVICE_NAME;
      $client = Zend_Gdata_ClientLogin::getHttpClient($form_state['values']['username'], $form_state['values']['password'], $service);
      $spreadsheetService = new Zend_Gdata_Spreadsheets($client);
      $feed = $spreadsheetService
        ->getSpreadsheetFeed();
      foreach ($feed->entries as $entry) {
        $id = array_pop(explode('/', $entry->id->text));
        $options[$id] = $entry->title->text;
      }
    } catch (Exception $e) {
      form_set_error('username', $e
        ->getMessage());
      $options = array(
        0 => t('- No spreadsheets found -'),
      );
    }
  }
  $element = $form['key'];
  $element['#options'] = $options;
  $element['#validated'] = TRUE;
  return $element;
}