Skip to content

Commit bd1599e

Browse files
committed
Tidy ComponentUtilities, Migrate ColumnSelectQueryString
1 parent ab35e6c commit bd1599e

18 files changed

+589
-521
lines changed

src/Traits/ComponentUtilities.php

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,8 @@ trait ComponentUtilities
1515

1616
public array $table = [];
1717

18-
protected Builder $builder;
19-
2018
protected $model;
2119

22-
protected ?string $primaryKey;
23-
24-
protected array $relationships = [];
25-
2620
#[Locked]
2721
public string $tableName = 'table';
2822

@@ -31,20 +25,8 @@ trait ComponentUtilities
3125

3226
protected bool $offlineIndicatorStatus = true;
3327

34-
protected bool $eagerLoadAllRelationsStatus = false;
35-
3628
protected string $emptyMessage = 'No items found, try to broaden your search';
3729

38-
protected array $additionalSelects = [];
39-
40-
protected array $extraWiths = [];
41-
42-
protected array $extraWithCounts = [];
43-
44-
protected array $extraWithSums = [];
45-
46-
protected array $extraWithAvgs = [];
47-
4830
protected bool $useComputedProperties = true;
4931

5032
protected bool $hasRunConfigure = false;

src/Traits/Configuration/ComponentConfiguration.php

Lines changed: 0 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,6 @@
44

55
trait ComponentConfiguration
66
{
7-
public function setPrimaryKey(?string $key): self
8-
{
9-
$this->primaryKey = $key;
10-
11-
return $this;
12-
}
137

148
/**
159
* Set the empty message
@@ -42,116 +36,13 @@ public function setOfflineIndicatorDisabled(): self
4236
return $this;
4337
}
4438

45-
public function setEagerLoadAllRelationsStatus(bool $status): self
46-
{
47-
$this->eagerLoadAllRelationsStatus = $status;
48-
49-
return $this;
50-
}
51-
52-
public function setEagerLoadAllRelationsEnabled(): self
53-
{
54-
$this->setEagerLoadAllRelationsStatus(true);
55-
56-
return $this;
57-
}
58-
59-
public function setEagerLoadAllRelationsDisabled(): self
60-
{
61-
$this->setEagerLoadAllRelationsStatus(false);
62-
63-
return $this;
64-
}
65-
66-
/**
67-
* Allows adding a single set of additional selects to the query
68-
*/
69-
public function setAdditionalSelects(string|array $selects): self
70-
{
71-
if (! is_array($selects)) {
72-
$selects = [$selects];
73-
}
74-
75-
$this->additionalSelects = $selects;
76-
77-
return $this;
78-
}
79-
80-
/**
81-
* Allows appending more additional selects
82-
*/
83-
public function addAdditionalSelects(string|array $selects): self
84-
{
85-
if (! is_array($selects)) {
86-
$selects = [$selects];
87-
}
88-
$this->additionalSelects = [...$this->additionalSelects, ...$selects];
89-
90-
return $this;
91-
}
92-
9339
public function setDataTableFingerprint(string $dataTableFingerprint): self
9440
{
9541
$this->dataTableFingerprint = $dataTableFingerprint;
9642

9743
return $this;
9844
}
9945

100-
public function setExtraWiths(array $extraWiths): self
101-
{
102-
$this->extraWiths = $extraWiths;
103-
104-
return $this;
105-
}
106-
107-
public function addExtraWith(string $extraWith): self
108-
{
109-
$this->extraWiths[] = $extraWith;
110-
111-
return $this;
112-
}
113-
114-
public function addExtraWiths(array $extraWiths): self
115-
{
116-
$this->extraWiths = [...$this->extraWiths, ...$extraWiths];
117-
118-
return $this;
119-
}
120-
121-
public function setExtraWithCounts(array $extraWithCounts): self
122-
{
123-
$this->extraWithCounts = $extraWithCounts;
124-
125-
return $this;
126-
}
127-
128-
public function addExtraWithCount(string $extraWithCount): self
129-
{
130-
$this->extraWithCounts[] = $extraWithCount;
131-
132-
return $this;
133-
}
134-
135-
public function addExtraWithCounts(array $extraWithCounts): self
136-
{
137-
$this->extraWithCounts = [...$this->extraWithCounts, ...$extraWithCounts];
138-
139-
return $this;
140-
}
141-
142-
public function addExtraWithSum(string $relationship, string $column): self
143-
{
144-
$this->extraWithSums[] = ['table' => $relationship, 'field' => $column];
145-
146-
return $this;
147-
}
148-
149-
public function addExtraWithAvg(string $relationship, string $column): self
150-
{
151-
$this->extraWithAvgs[] = ['table' => $relationship, 'field' => $column];
152-
153-
return $this;
154-
}
15546

15647
public function useComputedPropertiesEnabled(): self
15748
{
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
<?php
2+
3+
namespace Rappasoft\LaravelLivewireTables\Traits\Configuration;
4+
5+
use Illuminate\Database\Eloquent\Builder;
6+
7+
trait QueryConfiguration
8+
{
9+
10+
public function setBuilder(Builder $builder): void
11+
{
12+
$this->builder = $builder;
13+
}
14+
15+
public function setPrimaryKey(?string $key): self
16+
{
17+
$this->primaryKey = $key;
18+
19+
return $this;
20+
}
21+
22+
/**
23+
* Allows adding a single set of additional selects to the query
24+
*/
25+
public function setAdditionalSelects(string|array $selects): self
26+
{
27+
if (! is_array($selects)) {
28+
$selects = [$selects];
29+
}
30+
31+
$this->additionalSelects = $selects;
32+
33+
return $this;
34+
}
35+
36+
/**
37+
* Allows appending more additional selects
38+
*/
39+
public function addAdditionalSelects(string|array $selects): self
40+
{
41+
if (! is_array($selects)) {
42+
$selects = [$selects];
43+
}
44+
$this->additionalSelects = [...$this->additionalSelects, ...$selects];
45+
46+
return $this;
47+
}
48+
49+
public function setExtraWiths(array $extraWiths): self
50+
{
51+
$this->extraWiths = $extraWiths;
52+
53+
return $this;
54+
}
55+
56+
public function addExtraWith(string $extraWith): self
57+
{
58+
$this->extraWiths[] = $extraWith;
59+
60+
return $this;
61+
}
62+
63+
public function addExtraWiths(array $extraWiths): self
64+
{
65+
$this->extraWiths = [...$this->extraWiths, ...$extraWiths];
66+
67+
return $this;
68+
}
69+
70+
public function setExtraWithCounts(array $extraWithCounts): self
71+
{
72+
$this->extraWithCounts = $extraWithCounts;
73+
74+
return $this;
75+
}
76+
77+
public function addExtraWithCount(string $extraWithCount): self
78+
{
79+
$this->extraWithCounts[] = $extraWithCount;
80+
81+
return $this;
82+
}
83+
84+
public function addExtraWithCounts(array $extraWithCounts): self
85+
{
86+
$this->extraWithCounts = [...$this->extraWithCounts, ...$extraWithCounts];
87+
88+
return $this;
89+
}
90+
91+
public function addExtraWithSum(string $relationship, string $column): self
92+
{
93+
$this->extraWithSums[] = ['table' => $relationship, 'field' => $column];
94+
95+
return $this;
96+
}
97+
98+
public function addExtraWithAvg(string $relationship, string $column): self
99+
{
100+
$this->extraWithAvgs[] = ['table' => $relationship, 'field' => $column];
101+
102+
return $this;
103+
}
104+
105+
public function setEagerLoadAllRelationsStatus(bool $status): self
106+
{
107+
$this->eagerLoadAllRelationsStatus = $status;
108+
109+
return $this;
110+
}
111+
112+
public function setEagerLoadAllRelationsEnabled(): self
113+
{
114+
$this->setEagerLoadAllRelationsStatus(true);
115+
116+
return $this;
117+
}
118+
119+
public function setEagerLoadAllRelationsDisabled(): self
120+
{
121+
$this->setEagerLoadAllRelationsStatus(false);
122+
123+
return $this;
124+
}
125+
126+
}

src/Traits/Configuration/QueryStringConfiguration.php

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,6 @@
44

55
trait QueryStringConfiguration
66
{
7-
public function setQueryStringAlias(string $queryStringAlias): self
8-
{
9-
$this->queryStringAlias = $queryStringAlias;
10-
11-
return $this;
12-
}
13-
147
public function setupQueryStringStatus(): void
158
{
169
if (! $this->hasQueryStringStatus()) {
@@ -20,7 +13,7 @@ public function setupQueryStringStatus(): void
2013
}
2114
}
2215
}
23-
16+
2417
public function setQueryStringStatus(bool $status): self
2518
{
2619
$this->queryStringStatus = $status;
@@ -41,4 +34,30 @@ public function setQueryStringDisabled(): self
4134

4235
return $this;
4336
}
44-
}
37+
38+
public function setQueryStringAlias(string $queryStringAlias): self
39+
{
40+
$this->queryStringAlias = $queryStringAlias;
41+
42+
return $this;
43+
}
44+
45+
protected function setQueryStringConfig(string $type, array $config): self
46+
{
47+
$this->queryStringConfig[$type] = array_merge($this->getQueryStringConfig($type), $config);
48+
49+
return $this;
50+
}
51+
52+
protected function setQueryStringConfigStatus(string $type, bool $status): self
53+
{
54+
return $this->setQueryStringConfig($type, ['status' => $status]);
55+
56+
}
57+
58+
protected function setQueryStringConfigAlias(string $type, string $alias): self
59+
{
60+
return $this->setQueryStringConfig($type, ['alias' => $alias]);
61+
}
62+
63+
}

0 commit comments

Comments
 (0)