PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 2.19.6
GiveWP – Donation Plugin and Fundraising Platform v2.19.6
4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 All 253 releases
give / src / Framework / QueryBuilder / Concerns / Aggregate.php
Aggregate.php
90 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Give\Framework\QueryBuilder\Concerns;
4
5 use Give\Framework\QueryBuilder\Clauses\RawSQL;
6
7 /**
8 * @since 2.19.0
9 */
10 trait Aggregate
11 {
12 /**
13 * Returns the number of rows returned by a query
14 *
15 * @since 2.19.0
16 * @param null|string $column
17 *
18 * @return string
19 */
20 public function count($column = null)
21 {
22 $column = ( ! $column || $column === '*') ? '1' : trim($column);
23
24 $this->selects[] = new RawSQL('SELECT COUNT(%1s) AS count', $column);
25
26 return $this->get()->count;
27 }
28
29 /**
30 * Returns the total sum in a set of values
31 *
32 * @since 2.19.0
33 * @param string $column
34 *
35 * @return string
36 */
37 public function sum($column)
38 {
39 $this->selects[] = new RawSQL('SELECT SUM(%1s) AS sum', $column);
40
41 return $this->get()->sum;
42 }
43
44
45 /**
46 * Get the average value in a set of values
47 *
48 * @since 2.19.0
49 * @param string $column
50 *
51 * @return string
52 */
53 public function avg($column)
54 {
55 $this->selects[] = new RawSQL('SELECT AVG(%1s) AS avg', $column);
56
57 return $this->get()->avg;
58 }
59
60 /**
61 * Returns the minimum value in a set of values
62 *
63 * @since 2.19.0
64 * @param string $column
65 *
66 * @return string
67 */
68 public function min($column)
69 {
70 $this->selects[] = new RawSQL('SELECT MIN(%1s) AS min', $column);
71
72 return $this->get()->min;
73 }
74
75 /**
76 * Returns the maximum value in a set of values
77 *
78 * @since 2.19.0
79 * @param string $column
80 *
81 * @return string
82 */
83 public function max($column)
84 {
85 $this->selects[] = new RawSQL('SELECT MAX(%1s) AS max', $column);
86
87 return $this->get()->max;
88 }
89 }
90