PluginProbe ʕ •ᴥ•ʔ
Hostinger Reach – AI-Powered Email Marketing for WordPress / 1.7.2
Hostinger Reach – AI-Powered Email Marketing for WordPress v1.7.2
1.7.2 1.7.1 1.7.0 1.6.0 1.5.9 1.5.8 1.5.7 1.5.6 1.5.5 1.5.4 1.5.3 1.5.2 1.5.1 1.5.0 1.4.12 1.4.11 1.4.10 1.4.9 1.4.8 1.4.7 trunk 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6
hostinger-reach / src / Repositories / Repository.php
hostinger-reach / src / Repositories Last commit date
CartRepository.php 9 months ago ContactListRepository.php 10 months ago FormRepository.php 10 months ago Repository.php 10 months ago RepositoryInterface.php 10 months ago
Repository.php
50 lines
1 <?php
2 namespace Hostinger\Reach\Repositories;
3
4 use Hostinger\Reach\Admin\Database\DatabaseInterface;
5 use wpdb;
6
7 if ( ! DEFINED( 'ABSPATH' ) ) {
8 exit;
9 }
10
11 abstract class Repository implements RepositoryInterface {
12 protected DatabaseInterface $table;
13 protected wpdb $db;
14
15 public function __construct( wpdb $db ) {
16 $this->db = $db;
17 }
18
19 abstract public function all( array $where = array() ): array;
20 abstract public function exists( string $id ): bool;
21 abstract public function get( string $id ): array;
22 abstract public function insert( array $fields ): bool;
23 abstract public function update( array $fields ): bool;
24 protected function build_query( array $where = array(), int $limit = 100, int $offset = 0 ): string {
25 $sql = 'SELECT * FROM %i';
26 $params = array( $this->table->table_name() );
27
28 if ( ! empty( $where ) ) {
29 $where_conditions = array();
30 foreach ( $where as $column => $value ) {
31 if ( is_array( $value ) && isset( $value['operator'], $value['value'] ) ) {
32 $operator = $value['operator'];
33 $where_conditions[] = $column . ' ' . $operator . ' %s';
34 $params[] = $value['value'];
35 } else {
36 $where_conditions[] = $column . ' = %s';
37 $params[] = $value;
38 }
39 }
40 $sql .= ' WHERE ' . implode( ' AND ', $where_conditions );
41 }
42
43 $sql .= ' LIMIT ' . $limit;
44 if ( $offset ) {
45 $sql .= ' OFFSET ' . $offset;
46 }
47 return $this->db->prepare( $sql, ...$params );
48 }
49 }
50