PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / trunk
Booking for Appointments and Events Calendar – Amelia vtrunk
2.4.3 2.4.2 2.4.1 2.4 trunk 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.15 1.2.16 1.2.17 1.2.18 1.2.19 1.2.2 1.2.20 1.2.21 1.2.22 1.2.23 1.2.24 1.2.25 1.2.26 1.2.27 1.2.28 1.2.29 1.2.3 1.2.30 1.2.31 1.2.32 1.2.33 1.2.34 1.2.35 1.2.36 1.2.37 1.2.38 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.1.3 2.2 2.2.1 2.3
ameliabooking / src / Infrastructure / Repository / User / WPUserRepository.php
ameliabooking / src / Infrastructure / Repository / User Last commit date
CustomerRepository.php 2 weeks ago ProviderRepository.php 4 weeks ago UserRepository.php 2 months ago WPUserRepository.php 3 months ago
WPUserRepository.php
107 lines
1 <?php
2
3 namespace AmeliaBooking\Infrastructure\Repository\User;
4
5 use AmeliaBooking\Domain\Services\Database\ConnectionInterface;
6 use AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException;
7 use AmeliaBooking\Infrastructure\Connection;
8 use AmeliaBooking\Infrastructure\WP\InstallActions\DB\User\UsersTable;
9
10 /**
11 * Class WPUserRepository
12 *
13 * @package AmeliaBooking\Infrastructure\Repository\User
14 */
15 class WPUserRepository
16 {
17 /** @var ConnectionInterface */
18 protected $connection;
19
20 /** @var string */
21 protected $table;
22
23 /** @var string */
24 protected $metaTable;
25
26 /** @var string */
27 protected $prefix;
28
29 /**
30 * WPUserRepository constructor.
31 *
32 * @param Connection $connection
33 * @param $table
34 * @param $metaTable
35 * @param $prefix
36 */
37 public function __construct(Connection $connection, $table, $metaTable, $prefix)
38 {
39 $this->connection = $connection();
40 $this->table = $table;
41 $this->metaTable = $metaTable;
42 $this->prefix = $prefix;
43 }
44
45 /**
46 * @param array $params
47 * @param array $excludeUserIds
48 *
49 * @return array
50 * @throws QueryExecutionException
51 */
52 public function getAllNonRelatedWPUsers($params, $excludeUserIds)
53 {
54 $excludeIdParams = [];
55
56 try {
57 $params = [
58 ':id' => $params['id'],
59 ':role' => '%wpamelia-' . $params['role'] . '%',
60 ];
61
62 foreach ((array)$excludeUserIds as $key => $id) {
63 $excludeIdParams[":id$key"] = $id;
64 }
65
66 $whereExcludeIds = $excludeIdParams ?
67 ' AND wp_user.ID NOT IN (' . implode(',', $excludeIdParams) . ')' : '';
68
69 $usersTable = UsersTable::getTableName();
70
71 global $wpdb;
72
73 $statement = $this->connection->prepare(
74 "SELECT wp_user.ID AS value, wp_user.display_name AS label
75 FROM {$this->table} AS wp_user
76 INNER JOIN {$this->metaTable} AS wp_usermeta
77 ON wp_user.ID = wp_usermeta.user_id
78 WHERE
79 wp_user.ID NOT IN (
80 SELECT externalId
81 FROM $usersTable
82 WHERE externalId IS NOT NULL
83 AND externalId != :id
84 )
85 {$whereExcludeIds}
86 AND wp_usermeta.meta_key = '{$wpdb->prefix}capabilities'
87 AND wp_usermeta.meta_value LIKE :role
88 GROUP BY wp_user.ID"
89 );
90
91 $statement->execute($params);
92
93 $rows = $statement->fetchAll();
94 } catch (\Exception $e) {
95 throw new QueryExecutionException('Unable to get data from ' . __CLASS__ . '. ' . $e->getMessage(), $e->getCode(), $e);
96 }
97
98 $items = [];
99 foreach ($rows as $row) {
100 $row['value'] = (int)$row['value'];
101 $items[] = $row;
102 }
103
104 return $items;
105 }
106 }
107