public function testGetListFeedWithQuery() { $feedUrl = "https://spreadsheets.google.com/feeds/list/tA3TdJ0RIVEem3xQZhG2Ceg/od8/private/full?reverse=true&sq=age+%3E+45"; $mockServiceRequest = $this->getMockBuilder('Google\\Spreadsheet\\DefaultServiceRequest')->setMethods(array("get"))->disableOriginalConstructor()->getMock(); $mockServiceRequest->expects($this->once())->method('get')->with($this->equalTo($feedUrl))->willReturn(file_get_contents(__DIR__ . '/xml/list-feed.xml')); ServiceRequestFactory::setInstance($mockServiceRequest); $worksheet = new Worksheet(new SimpleXMLElement(file_get_contents(__DIR__ . '/xml/worksheet.xml'))); $worksheet->getListFeed(array("reverse" => "true", "sq" => "age > 45")); }
public function testGetListFeed() { $feedUrl = "https://spreadsheets.google.com/feeds/list/tA3TdJ0RIVEem3xQZhG2Ceg/od8/private/full"; $mockServiceRequest = $this->getMockBuilder(DefaultServiceRequest::class)->setMethods(["get"])->disableOriginalConstructor()->getMock(); $mockServiceRequest->expects($this->once())->method("get")->with($this->equalTo($feedUrl))->willReturn(file_get_contents(__DIR__ . "/xml/list-feed.xml")); ServiceRequestFactory::setInstance($mockServiceRequest); $worksheet = new Worksheet($this->getSimpleXMLElement("worksheet")); $this->assertTrue($worksheet->getListFeed() instanceof ListFeed); }
/** * Get a worksheet by title (name) * * @param string $title name of the worksheet * * @return \Google\Spreadsheet\Worksheet */ public function getByTitle($title) { foreach ($this->xml->entry as $entry) { if ($entry->title->__toString() == $title) { $worksheet = new Worksheet($entry); $worksheet->setPostUrl($this->getPostUrl()); return $worksheet; } } return null; }
private function importWorksheet(Worksheet $worksheet) { $this->info(sprintf('Importing worksheet %s', $worksheet->getTitle())); $listFeed = $worksheet->getListFeed(); foreach ($listFeed->getEntries() as $entry) { $values = $entry->getValues(); try { $this->validate($values); $this->output($values); } catch (\RuntimeException $ex) { $this->error(sprintf("%s\n", $ex->getMessage())); } } }
protected function _save_row(\Google\Spreadsheet\Worksheet $worksheet, array $row) { echo "<pre>"; var_dump($row); $list_feed = $worksheet->getListFeed(); $list_feed->insert($row); }
public function testGetTitle() { $xml = file_get_contents(__DIR__ . '/xml/worksheet.xml'); $worksheet = new Worksheet(new SimpleXMLElement($xml)); $this->assertEquals('Test', $worksheet->getTitle()); }
protected function readTableDefinition(Worksheet $worksheet) { $checks = Config::get('laravel-migrate-build::build.available_sheet_check'); $cellFeed = $worksheet->getCellFeed(); if ($this->getCellString($cellFeed, $checks['row'], $checks['col']) != $checks['value']) { return false; } $definition = []; $definition['tableName'] = $this->getCellString($cellFeed, 2, 15); $definition['increments'] = $this->getCellFlag($cellFeed, 4, 5); $definition['timestamps'] = $this->getCellFlag($cellFeed, 4, 10); $definition['publishes'] = $this->getCellFlag($cellFeed, 4, 15); $definition['softDeletes'] = $this->getCellFlag($cellFeed, 4, 20); $definition['engine'] = $this->getCellString($cellFeed, 4, 29); $definition['rowFormat'] = $this->getCellString($cellFeed, 4, 43); $columns = []; foreach (range(7, $worksheet->getRowCount()) as $row) { $no = $this->getCellNumber($cellFeed, $row, 1); if ($no == 0) { break; } $ignore = $this->getCellFlag($cellFeed, $row, 37); if ($ignore) { continue; } $columns[] = ['label' => $this->getCellString($cellFeed, $row, 3), 'name' => $this->getCellString($cellFeed, $row, 12), 'type' => $this->getCellString($cellFeed, $row, 21), 'size' => $this->getCellNumber($cellFeed, $row, 26, null), 'default' => $this->getCellValue($cellFeed, $row, 28), 'index' => $this->getCellFlag($cellFeed, $row, 31), 'unique' => $this->getCellFlag($cellFeed, $row, 33), 'nullable' => $this->getCellFlag($cellFeed, $row, 35)]; } $definition['columns'] = $columns; $definition['keyName'] = sprintf("create_%s_table", $definition['tableName']); $definition['className'] = sprintf("Create%sTable", studly_case($definition['tableName'])); return $definition; }
protected function syncGroupWorksheet(Worksheet $worksheet, array $messages) { $listFeed = $worksheet->getListFeed(); $worksheetFileKeyMapping = $this->buildFileKeyMapping($listFeed); foreach ($messages as $file => $keys) { foreach ($keys as $key => $langs) { if (!isset($worksheetFileKeyMapping[$file]) || !isset($worksheetFileKeyMapping[$file][$key])) { $entity = ['file' => $file, 'key' => $key]; foreach (LaravelLang::getDefaultLangs() as $lang) { $message = isset($langs[$lang]) ? $langs[$lang] : ""; array_set($worksheetFileKeyMapping, "{$file}.{$key}.{$lang}", $message); $entity[$lang] = str_replace(["\n", "\r"], ' ', $message); } printf("Insert row {$file}:{$key}\n"); $listFeed->insert($entity); } } } }