Skip to content

Commit eda4c5e

Browse files
authored
Tidy ComponentUtilities, Migrate ColumnSelectQueryString (rappasoft#2135)
* Tidy ComponentUtilities, Migrate ColumnSelectQueryString * Fix styling --------- Co-authored-by: lrljoe <[email protected]>
1 parent ab35e6c commit eda4c5e

18 files changed

+576
-523
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 & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,6 @@
44

55
trait ComponentConfiguration
66
{
7-
public function setPrimaryKey(?string $key): self
8-
{
9-
$this->primaryKey = $key;
10-
11-
return $this;
12-
}
13-
147
/**
158
* Set the empty message
169
*/
@@ -42,117 +35,13 @@ public function setOfflineIndicatorDisabled(): self
4235
return $this;
4336
}
4437

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-
9338
public function setDataTableFingerprint(string $dataTableFingerprint): self
9439
{
9540
$this->dataTableFingerprint = $dataTableFingerprint;
9641

9742
return $this;
9843
}
9944

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

src/Traits/Configuration/QueryStringConfiguration.php

Lines changed: 25 additions & 7 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()) {
@@ -41,4 +34,29 @@ public function setQueryStringDisabled(): self
4134

4235
return $this;
4336
}
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+
}
4462
}

src/Traits/Core/QueryStrings/HasQueryString.php

Lines changed: 0 additions & 59 deletions
This file was deleted.

0 commit comments

Comments
 (0)