function pof_importer_suggestionsdriveimport_run($fileId, $saveToDataBase = false) { $service = pof_importer_get_google_service(); try { $file = $service->files->get($fileId); echo '<table cellpadding="2" cellspacing="2" border="2">'; echo '<tr>'; echo '<th>Otsikko</th>'; echo '<td>' . $file->getTitle() . '</td>'; echo '</tr>'; echo '<tr>'; echo '<th>Avaa drivessä</th>'; echo '<td><a href="' . $file->getAlternateLink() . '" target="_blank">' . $file->getAlternateLink() . '</a></td>'; echo '</tr>'; echo '<tr>'; echo '<th>Kuvaus</th>'; echo '<td>' . $file->getDescription() . '</td>'; echo '</tr>'; echo '<tr>'; echo '<th>Viimeksi muokattu</th>'; $fileLastModified = strtotime($file->getModifiedDate()); echo '<td>' . date('d.m.Y', $fileLastModified) . '</td>'; echo '</tr>'; echo '<tr>'; echo '<th>Muokkaaja</th>'; echo '<td>' . $file->getLastModifyingUserName() . '</td>'; echo '</tr>'; echo '</table>'; $filepath = pof_importer_download_drive_file($service, $file); $objReader = pof_imported_get_phpExcel_objReader(); $objPHPExcel = $objReader->load($filepath); $sheetData = $objPHPExcel->getActiveSheet()->toArray(null, true, true, true); if (pof_importer_tasksdriveimport_checkThatHeadersMatchSuggestions($sheetData[1])) { $headers = $sheetData[1]; $i = 0; foreach ($sheetData as $sheetDataRow) { $i++; if ($i < 2) { continue; } pof_importer_suggestionssdriveimport_importRow($sheetDataRow, $i, $saveToDataBase); } } else { echo "<h1>Unvalid excel, or failed to read excel at all.</h1>"; } } catch (Exception $e) { echo "An error occurred: " . $e->getMessage(); } }
function pof_importer_suggestionsdriveimport_run2($fileId, $agegroup_id, $saveToDataBase = false) { $service = pof_importer_get_google_service(); $agegroups = pof_taxonomy_translate_get_agegroups(); $agegroup = new stdClass(); foreach ($agegroups as $agegroup_tmp) { if ($agegroup_tmp->id == $agegroup_id) { $agegroup = $agegroup_tmp; break; } } try { $file = $service->files->get($fileId); $lang = substr($file->getTitle(), -2, 2); echo '<table cellpadding="2" cellspacing="2" border="2">'; echo '<tr>'; echo '<th>Otsikko</th>'; echo '<td>' . $file->getTitle() . '</td>'; echo '</tr>'; echo '<tr>'; echo '<th>Kieli</th>'; echo '<td>' . $lang . '</td>'; echo '</tr>'; echo '<tr>'; echo '<th>Avaa drivessä</th>'; echo '<td><a href="' . $file->getAlternateLink() . '" target="_blank">' . $file->getAlternateLink() . '</a></td>'; echo '</tr>'; echo '<tr>'; echo '<th>Ikäkausi</th>'; echo '<td>' . $agegroup->title . '</td>'; echo '</tr>'; echo '<tr>'; echo '<th>Kirjoittaja</th>'; echo '<td>Suomen partiolaiset</td>'; echo '</tr>'; echo '<tr>'; echo '<th>Kuvaus</th>'; echo '<td>' . $file->getDescription() . '</td>'; echo '</tr>'; echo '<tr>'; echo '<th>Viimeksi muokattu</th>'; $fileLastModified = strtotime($file->getModifiedDate()); echo '<td>' . date('d.m.Y', $fileLastModified) . '</td>'; echo '</tr>'; echo '<tr>'; echo '<th>Muokkaaja</th>'; echo '<td>' . $file->getLastModifyingUserName() . '</td>'; echo '</tr>'; echo '</table>'; $filepath = pof_importer_download_drive_file($service, $file); $objReader = pof_imported_get_phpExcel_objReader(); $objPHPExcel = $objReader->load($filepath); $sheetData = $objPHPExcel->getActiveSheet()->toArray(null, true, true, true); if (pof_importer_tasksdriveimport_checkThatHeadersMatchSuggestions2($sheetData[1])) { $headers = $sheetData[1]; $i = 0; foreach ($sheetData as $sheetDataRow) { $i++; if ($i < 2) { continue; } if (trim($sheetDataRow['A']) == '') { continue; } pof_importer_suggestionssdriveimport_importRow2($sheetDataRow, $i, $agegroup_id, $lang, $saveToDataBase); } } else { echo "<h1>Unvalid excel, or failed to read excel at all.</h1>"; } } catch (Exception $e) { echo "An error occurred: " . $e->getMessage(); } }