public function addEntry($lead) { $serviceRequest = new DefaultServiceRequest($this->token); ServiceRequestFactory::setInstance($serviceRequest); $spreadsheetService = new SpreadsheetService(); $spreadsheetFeed = $spreadsheetService->getSpreadsheetById($this->spreadsheetId); $worksheetFeed = $spreadsheetFeed->getWorksheets(); $worksheet = $worksheetFeed->getByTitle($this->tabTitle); $listFeed = $worksheet->getListFeed(); $result = $listFeed->insert($lead); return $result; }
/** * Single worksheet */ public function singleWorksheet(Request $request, $spreadsheet_id, $id) { $access_token = $request->session()->get('access_token'); $serviceRequest = new DefaultServiceRequest($access_token); ServiceRequestFactory::setInstance($serviceRequest); //retrieve list of worksheets $spreadsheetService = new SpreadsheetService(); $spreadsheet = $spreadsheetService->getSpreadsheetById($spreadsheet_id); $data['spreadsheet_title'] = $spreadsheet->getTitle(); $data['spreadsheet_id'] = $spreadsheet_id; $worksheets = $spreadsheet->getWorksheets(); $i = $id - 1; $worksheet = $worksheets[$i]; $data['worksheet_title'] = $worksheet->getTitle(); //get content $listFeed = $worksheet->getListFeed(); $entries = $listFeed->getEntries(); //get column names $column_names = array(); foreach ($entries as $entry) { $keys = array_keys($entry->getValues()); foreach ($keys as $key) { if (!in_array($key, $column_names)) { $column_names[] = $key; } } } //column names in 'create table' string format $formatted_names = ""; foreach ($column_names as $column_name) { $column_name = str_replace(".", "_", $column_name); $formatted_names .= " `{$column_name}` TEXT NULL,"; } //generate table name $table_name = $this->generateRandomString(); $sql = "CREATE TABLE `{$table_name}` ( `id` INT NOT NULL AUTO_INCREMENT ,{$formatted_names} PRIMARY KEY (`id`))"; if (DB::statement($sql)) { /*//insert values foreach ($entries as $entry) { DB::table($table_name)->insert($entry->getValues()); }*/ foreach ($entries as $entry) { $insert_kv = array(); foreach ($entry->getValues() as $k => $v) { $k = str_replace(".", "_", $k); $insert_kv[$k] = $v; } DB::table($table_name)->insert($insert_kv); } } $data['table'] = $table_name; return View::make('add_tracker_details')->with("data", $data); }