From 2f371a64e21c3fe2602e39a5eb52909d1c0c0819 Mon Sep 17 00:00:00 2001 From: michaeldchin Date: Thu, 28 Oct 2021 08:36:24 -0500 Subject: [PATCH] adding update summary field related methods --- src/Resources/Sheet.php | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/src/Resources/Sheet.php b/src/Resources/Sheet.php index 129ba83..fd81b5b 100644 --- a/src/Resources/Sheet.php +++ b/src/Resources/Sheet.php @@ -337,10 +337,10 @@ public function addColumn(array $column) return $this->addColumns([$column]); } - public function addColumns(array $column) + public function addColumns(array $columns) { return $this->client->post("sheets/$this->id/columns", [ - 'json' => $column + 'json' => $columns ]); } @@ -358,6 +358,32 @@ public function addSummaryField(String $title, String $formula, String $type = ' ); } + public function updateSummaryFieldByName(String $fieldName, array $summaryFieldDefinition) + { + $summaryField = $this->getSummaryFieldByName($fieldName); + $summaryFieldDefinition['id'] = $summaryField->id; + + return $this->updateSummaryField($summaryFieldDefinition); + } + + public function updateSummaryField(array $summaryField) + { + return $this->updateSummaryFields([$summaryField]); + } + + public function updateSummaryFields(array $summaryFields) + { + return $this->client->put("sheets/$this->id/summary/fields", + ['json' => [...$summaryFields]] + ); + } + + public function getSummaryFieldByName(String $fieldName) + { + return collect($this->getSummaryFields()->fields) + ->first(fn ($field) => $field->title == $fieldName); + } + public function getSummaryFields() { return $this->client->get("sheets/$this->id/summary");