class-select-count-id.php
37 lines
| 1 | <?php |
| 2 | |
| 3 | namespace SearchRegex\Sql\Modifier; |
| 4 | |
| 5 | use SearchRegex\Sql; |
| 6 | |
| 7 | /** |
| 8 | * Perform a COUNT of a query |
| 9 | */ |
| 10 | class Select_Count_Id extends Modifier { |
| 11 | /** |
| 12 | * Column to modify |
| 13 | * |
| 14 | * @readonly |
| 15 | */ |
| 16 | private string $column; |
| 17 | |
| 18 | /** |
| 19 | * Constructor |
| 20 | * |
| 21 | * @param Sql\Value $table Table name. |
| 22 | * @param Sql\Value $table_id Table ID. |
| 23 | * @param string $alias Count alias. |
| 24 | */ |
| 25 | public function __construct( Sql\Value $table, Sql\Value $table_id, $alias = 'match_rows' ) { |
| 26 | $this->column = 'COUNT(' . $table->get_value() . '.' . $table_id->get_value() . ") AS $alias"; |
| 27 | } |
| 28 | |
| 29 | public function get_select( array $select, array $joins ) { |
| 30 | return [ $this->column ]; |
| 31 | } |
| 32 | |
| 33 | public function get_group( array $group, array $joins ) { |
| 34 | return []; |
| 35 | } |
| 36 | } |
| 37 |