PluginProbe
Booktics – Appointment Booking Calendar for Service Businesses / 1.0.28
Booktics – Appointment Booking Calendar for Service Businesses v1.0.28
1.0.29 1.0.28 1.0.27 1.0.26 1.0.25 1.0.24 1.0.23 1.0.22 1.0.21 1.0.20 1.0.19 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.2 1.0.3 All 31 releases
← All changes | base/validation/rules/unique-rule.php +72 -72 1.0.1 → 1.0.28 View file →
@@ -1,72 +1,72 @@
1 -<?php
2 -
3 -namespace Booktics\Validation\Rules;
4 -
5 -/**
6 - * Class Unique_Rule
7 - */
8 -class Unique_Rule implements Rule {
9 -
10 - /**
11 - * Store table name
12 - *
13 - * @var string
14 - */
15 - private $table;
16 -
17 - /**
18 - * Store column name
19 - *
20 - * @var string
21 - */
22 - private $column;
23 -
24 - /**
25 - * Store except id
26 - *
27 - * @var mixed|null
28 - */
29 - private $exceptId;
30 -
31 - public function __construct( string $table, string $column, $exceptId = null ) {
32 - $this->table = $table;
33 - $this->column = $column;
34 - $this->exceptId = $exceptId;
35 - }
36 -
37 - /**
38 - * Check the rule passed or not
39 - *
40 - * @param any $field
41 - * @param any $value
42 - *
43 - * @return bool
44 - */
45 - public function passes( $field, $value ): bool {
46 - if ( $this->table === 'wp_users' ) {
47 - $existing_user = get_user_by( $field, $value );
48 -
49 - if ( ! $existing_user ) {
50 - return true;
51 - }
52 -
53 - if ( intval( $existing_user->ID ) === intval( $this->exceptId ) ) {
54 - return true;
55 - }
56 -
57 - return false;
58 - }
59 - return true;
60 - }
61 -
62 - /**
63 - * Set validation message
64 - *
65 - * @param any $field
66 - *
67 - * @return string
68 - */
69 - public function message( $field ) {
70 - return $field . ' is not unique';
71 - }
72 -}
1 +<?php
2 +
3 +namespace Booktics\Validation\Rules;
4 +
5 +/**
6 + * Class Unique_Rule
7 + */
8 +class Unique_Rule implements Rule {
9 +
10 + /**
11 + * Store table name
12 + *
13 + * @var string
14 + */
15 + private $table;
16 +
17 + /**
18 + * Store column name
19 + *
20 + * @var string
21 + */
22 + private $column;
23 +
24 + /**
25 + * Store except id
26 + *
27 + * @var mixed|null
28 + */
29 + private $except_id;
30 +
31 + public function __construct( string $table, string $column, $except_id = null ) {
32 + $this->table = $table;
33 + $this->column = $column;
34 + $this->except_id = $except_id;
35 + }
36 +
37 + /**
38 + * Check the rule passed or not
39 + *
40 + * @param any $field
41 + * @param any $value
42 + *
43 + * @return bool
44 + */
45 + public function passes( $field, $value ): bool {
46 + if ( $this->table === 'wp_users' ) {
47 + $existing_user = get_user_by( $field, $value );
48 +
49 + if ( ! $existing_user ) {
50 + return true;
51 + }
52 +
53 + if ( intval( $existing_user->ID ) === intval( $this->except_id ) ) {
54 + return true;
55 + }
56 +
57 + return false;
58 + }
59 + return true;
60 + }
61 +
62 + /**
63 + * Set validation message
64 + *
65 + * @param any $field
66 + *
67 + * @return string
68 + */
69 + public function message( $field ) {
70 + return $field . ' is not unique';
71 + }
72 +}