PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 1.2.20
Booking for Appointments and Events Calendar – Amelia v1.2.20
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 1 year ago ProviderRepository.php 1 year ago UserRepository.php 1 year ago WPUserRepository.php 4 years ago
WPUserRepository.php
106 lines
1 <?php
2
3 namespace AmeliaBooking\Infrastructure\Repository\User;
4
5 use AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException;
6 use AmeliaBooking\Infrastructure\Connection;
7 use AmeliaBooking\Infrastructure\WP\InstallActions\DB\User\UsersTable;
8
9 /**
10 * Class WPUserRepository
11 *
12 * @package AmeliaBooking\Infrastructure\Repository\User
13 */
14 class WPUserRepository
15 {
16 /** @var \PDO */
17 protected $connection;
18
19 /** @var string */
20 protected $table;
21
22 /** @var string */
23 protected $metaTable;
24
25 /** @var string */
26 protected $prefix;
27
28 /**
29 * WPUserRepository constructor.
30 *
31 * @param Connection $connection
32 * @param $table
33 * @param $metaTable
34 * @param $prefix
35 */
36 public function __construct(Connection $connection, $table, $metaTable, $prefix)
37 {
38 $this->connection = $connection();
39 $this->table = $table;
40 $this->metaTable = $metaTable;
41 $this->prefix = $prefix;
42 }
43
44 /**
45 * @param array $params
46 * @param array $excludeUserIds
47 *
48 * @return array
49 * @throws QueryExecutionException
50 */
51 public function getAllNonRelatedWPUsers($params, $excludeUserIds)
52 {
53 $excludeIdParams = [];
54
55 try {
56 $params = [
57 ':id' => $params['id'],
58 ':role' => '%wpamelia-' . $params['role'] . '%',
59 ];
60
61 foreach ((array)$excludeUserIds as $key => $id) {
62 $excludeIdParams[":id$key"] = $id;
63 }
64
65 $whereExcludeIds = $excludeIdParams ?
66 ' AND wp_user.ID NOT IN (' . implode(',', $excludeIdParams) . ')' : '';
67
68 $usersTable = UsersTable::getTableName();
69
70 global $wpdb;
71
72 $statement = $this->connection->prepare(
73 "SELECT wp_user.ID AS value, wp_user.display_name AS label
74 FROM {$this->table} AS wp_user
75 INNER JOIN {$this->metaTable} AS wp_usermeta
76 ON wp_user.ID = wp_usermeta.user_id
77 WHERE
78 wp_user.ID NOT IN (
79 SELECT externalId
80 FROM $usersTable
81 WHERE externalId IS NOT NULL
82 AND externalId != :id
83 )
84 {$whereExcludeIds}
85 AND wp_usermeta.meta_key = '{$wpdb->prefix}capabilities'
86 AND wp_usermeta.meta_value LIKE :role
87 GROUP BY wp_user.ID"
88 );
89
90 $statement->execute($params);
91
92 $rows = $statement->fetchAll();
93 } catch (\Exception $e) {
94 throw new QueryExecutionException('Unable to get data from ' . __CLASS__, $e->getCode(), $e);
95 }
96
97 $items = [];
98 foreach ($rows as $row) {
99 $row['value'] = (int)$row['value'];
100 $items[] = $row;
101 }
102
103 return $items;
104 }
105 }
106